Fix 3D preview dragging and STL thumbnails
@@ -146,6 +146,7 @@
146
146
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading (both file thumbnails and folder icons); retries missing cache thumbnails during incremental refresh.
147
147
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
148
148
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images and videos, text snapshots for text files, and badges for other files; marks image/video icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
149
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, videos, and supported 3D model files; text files still use text snapshots and badges remain the fallback when no thumbnail strategy exists.
149
150
- observeFolderIcon(iconEl) - Registers a folder icon element with IntersectionObserver for lazy loading.
150
151
- loadOneFolderIcon(iconEl) - Fetches /api/files/folder-icon then the thumbnail blob and overlays it inside the folder SVG; no-op if no icon available.
151
152
- applyFolderThumbnail(iconEl, srcUrl) - Injects an SVG <image> element clipped to the folder outline path into the folder's icon SVG.
@@ -160,6 +161,7 @@
160
161
- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, and releases the backend stream session on close/unload.
161
162
- modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
162
163
- loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
164
- modelThumbnailDataUrl(item, blob) - Builds a blue SVG thumbnail for STL/OBJ files by parsing their geometry client-side; falls back to a badge when parsing fails.
163
165
- buildModelObjectFromBlob(blob, type, modules) - Parses STL/OBJ blobs and produces a geometry-only model using the standard blue material.
164
166
- renderModelPreview(item, blob, targetEl) - Renders interactive STL/OBJ previews (drag rotate + scroll zoom) with WebGL fallback messaging when unavailable.
165
167
- closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
@@ -146,6 +146,7 @@146
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading (both file thumbnails and folder icons); retries missing cache thumbnails during incremental refresh.
146
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading (both file thumbnails and folder icons); retries missing cache thumbnails during incremental refresh.
147
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
147
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
148
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images and videos, text snapshots for text files, and badges for other files; marks image/video icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
148
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images and videos, text snapshots for text files, and badges for other files; marks image/video icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
149
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, videos, and supported 3D model files; text files still use text snapshots and badges remain the fallback when no thumbnail strategy exists.
149
- observeFolderIcon(iconEl) - Registers a folder icon element with IntersectionObserver for lazy loading.
150
- observeFolderIcon(iconEl) - Registers a folder icon element with IntersectionObserver for lazy loading.
150
- loadOneFolderIcon(iconEl) - Fetches /api/files/folder-icon then the thumbnail blob and overlays it inside the folder SVG; no-op if no icon available.
151
- loadOneFolderIcon(iconEl) - Fetches /api/files/folder-icon then the thumbnail blob and overlays it inside the folder SVG; no-op if no icon available.
151
- applyFolderThumbnail(iconEl, srcUrl) - Injects an SVG <image> element clipped to the folder outline path into the folder's icon SVG.
152
- applyFolderThumbnail(iconEl, srcUrl) - Injects an SVG <image> element clipped to the folder outline path into the folder's icon SVG.
@@ -160,6 +161,7 @@160
- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, and releases the backend stream session on close/unload.
161
- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, and releases the backend stream session on close/unload.
161
- modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
162
- modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
162
- loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
163
- loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
164
- modelThumbnailDataUrl(item, blob) - Builds a blue SVG thumbnail for STL/OBJ files by parsing their geometry client-side; falls back to a badge when parsing fails.
163
- buildModelObjectFromBlob(blob, type, modules) - Parses STL/OBJ blobs and produces a geometry-only model using the standard blue material.
165
- buildModelObjectFromBlob(blob, type, modules) - Parses STL/OBJ blobs and produces a geometry-only model using the standard blue material.
164
- renderModelPreview(item, blob, targetEl) - Renders interactive STL/OBJ previews (drag rotate + scroll zoom) with WebGL fallback messaging when unavailable.
166
- renderModelPreview(item, blob, targetEl) - Renders interactive STL/OBJ previews (drag rotate + scroll zoom) with WebGL fallback messaging when unavailable.
165
- closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
167
- closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
@@ -1573,6 +1573,7 @@ function makeFileItem (item)
1573
1573
el.addEventListener('click', (e) =>
1574
1574
{
1575
1575
e.stopPropagation();
1576
if (el.classList.contains('file-item--preview')) return;
1576
1577
if (isMobileViewport())
1577
1578
{
1578
1579
if (el.dataset.longPressTriggered === '1')
@@ -1598,6 +1599,7 @@ function makeFileItem (item)
1598
1599
el.addEventListener('dblclick', (e) =>
1599
1600
{
1600
1601
e.stopPropagation();
1602
if (el.classList.contains('file-item--preview')) return;
1601
1603
if (item.isDir)
1602
1604
{
1603
1605
navigateTo(item.path, item._root || STATE.currentRoot);
@@ -2658,6 +2660,7 @@ function isInlinePreviewableBlob (blob, name)
2658
2660
const ext = extOf(name || '');
2659
2661
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext) || AUDIO_EXTS.has(ext)) return true;
2660
2662
if (MODEL_EXTS.has(ext)) return true;
2663
if (MODEL_EXTS.has(ext)) return true;
2661
2664
if (CODE_EXTS.has(ext)) return true;
2662
2665
return false;
2663
2666
}
@@ -3391,10 +3394,10 @@ async function loadThreePreviewModules ()
3391
3394
if (!threePreviewModulesPromise)
3392
3395
{
3393
3396
threePreviewModulesPromise = Promise.all([
3394
import('three'),
3395
import('three/addons/controls/OrbitControls.js'),
3396
import('three/addons/loaders/STLLoader.js'),
3397
import('three/addons/loaders/OBJLoader.js'),
3397
import('/vendor/three/three.module.js'),
3398
import('/vendor/three/addons/controls/OrbitControls.js'),
3399
import('/vendor/three/addons/loaders/STLLoader.js'),
3400
import('/vendor/three/addons/loaders/OBJLoader.js'),
3398
3401
]).then(([THREE, controlsMod, stlMod, objMod]) =>
3399
3402
{
3400
3403
return {
@@ -3493,6 +3496,7 @@ async function renderModelPreview (item, blob, targetEl)
3493
3496
3494
3497
const canvas = document.createElement('canvas');
3495
3498
canvas.className = 'preview-model-canvas';
3499
canvas.style.touchAction = 'none';
3496
3500
wrap.appendChild(canvas);
3497
3501
3498
3502
const hint = document.createElement('p');
@@ -4600,6 +4604,7 @@ function getThumbnailKind (name)
4600
4604
{
4601
4605
const ext = extOf(name || '');
4602
4606
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext)) return 'image';
4607
if (MODEL_EXTS.has(ext)) return 'model';
4603
4608
if (CODE_EXTS.has(ext)) return 'text';
4604
4609
return 'badge';
4605
4610
}
@@ -4607,6 +4612,7 @@ function getThumbnailKind (name)
4607
4612
function maxThumbBytesForKind (kind)
4608
4613
{
4609
4614
if (kind === 'image') return 15 * 1024 * 1024;
4615
if (kind === 'model') return 15 * 1024 * 1024;
4610
4616
if (kind === 'text') return 1024 * 1024;
4611
4617
return 0;
4612
4618
}
@@ -4706,9 +4712,271 @@ function badgeThumbnailDataUrl (name, kind)
4706
4712
async function buildThumbnailSource (item, blob, kind)
4707
4713
{
4708
4714
if (kind === 'text') return textThumbnailDataUrl(await blob.text());
4715
if (kind === 'model') return await modelThumbnailDataUrl(item, blob);
4709
4716
return badgeThumbnailDataUrl(item.name, kind);
4710
4717
}
4711
4718
4719
function createModelSvgFromPolygons (polygons)
4720
{
4721
const width = 160;
4722
const height = 200;
4723
const pad = 12;
4724
4725
let minX = Infinity;
4726
let minY = Infinity;
4727
let maxX = -Infinity;
4728
let maxY = -Infinity;
4729
4730
for (const poly of polygons)
4731
{
4732
for (const point of poly.points)
4733
{
4734
minX = Math.min(minX, point.x);
4735
minY = Math.min(minY, point.y);
4736
maxX = Math.max(maxX, point.x);
4737
maxY = Math.max(maxY, point.y);
4738
}
4739
}
4740
4741
if (!Number.isFinite(minX) || !Number.isFinite(minY) || !Number.isFinite(maxX) || !Number.isFinite(maxY))
4742
{
4743
return null;
4744
}
4745
4746
const boxW = Math.max(1, maxX - minX);
4747
const boxH = Math.max(1, maxY - minY);
4748
const scale = Math.min((width - pad * 2) / boxW, (height - pad * 2 - 18) / boxH);
4749
const cx = (minX + maxX) / 2;
4750
const cy = (minY + maxY) / 2;
4751
4752
const svgPolys = polygons.map((poly) =>
4753
{
4754
const pts = poly.points.map((point) =>
4755
{
4756
const x = width / 2 + (point.x - cx) * scale;
4757
const y = 18 + height / 2 + (point.y - cy) * scale;
4758
return `${x.toFixed(1)},${y.toFixed(1)}`;
4759
}).join(' ');
4760
4761
return `<polygon points="${pts}" fill="rgba(47,109,255,0.28)" stroke="#7ea2ff" stroke-width="0.9" stroke-linejoin="round"/>`;
4762
}).join('');
4763
4764
return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`
4765
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
4766
<defs>
4767
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
4768
<stop offset="0%" stop-color="#111826"/>
4769
<stop offset="100%" stop-color="#0d111a"/>
4770
</linearGradient>
4771
</defs>
4772
<rect width="${width}" height="${height}" rx="10" fill="url(#bg)"/>
4773
<rect x="0" y="0" width="${width}" height="28" fill="#2f6dff"/>
4774
<text x="80" y="17" font-family="sans-serif" font-size="12" text-anchor="middle" fill="#ffffff" font-weight="700">3D</text>
4775
${svgPolys}
4776
</svg>
4777
`)}`;
4778
}
4779
4780
function projectModelVector (vector)
4781
{
4782
const x = vector.x;
4783
const y = vector.y;
4784
const z = vector.z;
4785
const ry = Math.PI / 4;
4786
const rx = -Math.PI / 5;
4787
4788
const x1 = x * Math.cos(ry) + z * Math.sin(ry);
4789
const z1 = -x * Math.sin(ry) + z * Math.cos(ry);
4790
const y2 = y * Math.cos(rx) - z1 * Math.sin(rx);
4791
const z2 = y * Math.sin(rx) + z1 * Math.cos(rx);
4792
4793
return { x: x1, y: y2, z: z2 };
4794
}
4795
4796
function resolveObjIndex (token, vertexCount)
4797
{
4798
const raw = Number.parseInt(String(token || '').split('/')[0], 10);
4799
if (!Number.isFinite(raw) || raw === 0) return null;
4800
const index = raw < 0 ? vertexCount + raw : raw - 1;
4801
if (index < 0 || index >= vertexCount) return null;
4802
return index;
4803
}
4804
4805
function parseObjPolygons (text)
4806
{
4807
const vertices = [];
4808
const faces = [];
4809
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n');
4810
4811
for (const lineRaw of lines)
4812
{
4813
const line = lineRaw.trim();
4814
if (!line || line.startsWith('#')) continue;
4815
4816
if (/^v\s+/i.test(line))
4817
{
4818
const parts = line.split(/\s+/);
4819
if (parts.length >= 4)
4820
{
4821
const x = Number(parts[1]);
4822
const y = Number(parts[2]);
4823
const z = Number(parts[3]);
4824
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))
4825
{
4826
vertices.push({ x, y, z });
4827
}
4828
}
4829
continue;
4830
}
4831
4832
if (/^f\s+/i.test(line))
4833
{
4834
const parts = line.split(/\s+/).slice(1);
4835
if (parts.length >= 3) faces.push(parts);
4836
}
4837
}
4838
4839
const polygons = [];
4840
for (const face of faces)
4841
{
4842
const indices = face
4843
.map((token) => resolveObjIndex(token, vertices.length))
4844
.filter((index) => index != null);
4845
4846
if (indices.length < 3) continue;
4847
const anchor = vertices[indices[0]];
4848
for (let i = 1; i < indices.length - 1; i++)
4849
{
4850
const b = vertices[indices[i]];
4851
const c = vertices[indices[i + 1]];
4852
if (anchor && b && c)
4853
{
4854
polygons.push({ points: [anchor, b, c] });
4855
}
4856
}
4857
}
4858
4859
return polygons;
4860
}
4861
4862
function parseAsciiStlPolygons (text)
4863
{
4864
const polygons = [];
4865
const vertices = [];
4866
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n');
4867
4868
for (const lineRaw of lines)
4869
{
4870
const line = lineRaw.trim();
4871
if (!/^vertex\s+/i.test(line)) continue;
4872
const parts = line.split(/\s+/);
4873
if (parts.length < 4) continue;
4874
const x = Number(parts[1]);
4875
const y = Number(parts[2]);
4876
const z = Number(parts[3]);
4877
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))
4878
{
4879
vertices.push({ x, y, z });
4880
}
4881
}
4882
4883
for (let i = 0; i + 2 < vertices.length; i += 3)
4884
{
4885
polygons.push({ points: [vertices[i], vertices[i + 1], vertices[i + 2]] });
4886
}
4887
4888
return polygons;
4889
}
4890
4891
function parseBinaryStlPolygons (buffer)
4892
{
4893
const polygons = [];
4894
if (!buffer || buffer.byteLength < 84) return polygons;
4895
4896
const view = new DataView(buffer);
4897
const triCount = view.getUint32(80, true);
4898
let offset = 84;
4899
4900
for (let i = 0; i < triCount; i++)
4901
{
4902
if (offset + 50 > buffer.byteLength) break;
4903
offset += 12; // normal
4904
const points = [];
4905
for (let v = 0; v < 3; v++)
4906
{
4907
const x = view.getFloat32(offset, true);
4908
const y = view.getFloat32(offset + 4, true);
4909
const z = view.getFloat32(offset + 8, true);
4910
points.push({ x, y, z });
4911
offset += 12;
4912
}
4913
offset += 2; // attribute byte count
4914
polygons.push({ points });
4915
}
4916
4917
return polygons;
4918
}
4919
4920
async function parseModelPolygonsFromBlob (blob, type)
4921
{
4922
const extType = String(type || '').toLowerCase();
4923
if (extType === 'obj')
4924
{
4925
return parseObjPolygons(await blob.text());
4926
}
4927
4928
if (extType === 'stl')
4929
{
4930
const text = await blob.text();
4931
if (/\bvertex\s+/i.test(text) && /\bfacet\s+/i.test(text))
4932
{
4933
return parseAsciiStlPolygons(text);
4934
}
4935
4936
try
4937
{
4938
return parseBinaryStlPolygons(await blob.arrayBuffer());
4939
} catch
4940
{
4941
return [];
4942
}
4943
}
4944
4945
return [];
4946
}
4947
4948
async function modelThumbnailDataUrl (item, blob)
4949
{
4950
const type = modelPreviewType(item && item.name);
4951
if (!type) return badgeThumbnailDataUrl(item.name, 'badge');
4952
4953
let modelPolygons;
4954
try
4955
{
4956
modelPolygons = await parseModelPolygonsFromBlob(blob, type);
4957
} catch
4958
{
4959
return badgeThumbnailDataUrl(item.name, 'badge');
4960
}
4961
4962
if (!modelPolygons.length) return badgeThumbnailDataUrl(item.name, 'badge');
4963
4964
const polygons = [];
4965
for (const poly of modelPolygons)
4966
{
4967
const projectedPoints = poly.points.map((point) => projectModelVector(point));
4968
polygons.push({
4969
points: projectedPoints.map((point) => ({ x: point.x, y: point.y })),
4970
depth: projectedPoints.reduce((sum, point) => sum + point.z, 0) / projectedPoints.length,
4971
});
4972
}
4973
4974
polygons.sort((a, b) => a.depth - b.depth);
4975
const svgUrl = createModelSvgFromPolygons(polygons);
4976
if (svgUrl) return svgUrl;
4977
return badgeThumbnailDataUrl(item.name, 'badge');
4978
}
4979
4712
4980
function observeThumbnailIcon (iconEl)
4713
4981
{
4714
4982
if (!iconEl || !iconEl.isConnected) return;
@@ -1573,6 +1573,7 @@ function makeFileItem (item)1573
el.addEventListener('click', (e) =>1573
el.addEventListener('click', (e) =>1574
{1574
{1575
e.stopPropagation();1575
e.stopPropagation();1576
if (el.classList.contains('file-item--preview')) return;1576
if (isMobileViewport())1577
if (isMobileViewport())1577
{1578
{1578
if (el.dataset.longPressTriggered === '1')1579
if (el.dataset.longPressTriggered === '1')@@ -1598,6 +1599,7 @@ function makeFileItem (item)1598
el.addEventListener('dblclick', (e) =>1599
el.addEventListener('dblclick', (e) =>1599
{1600
{1600
e.stopPropagation();1601
e.stopPropagation();1602
if (el.classList.contains('file-item--preview')) return;1601
if (item.isDir)1603
if (item.isDir)1602
{1604
{1603
navigateTo(item.path, item._root || STATE.currentRoot);1605
navigateTo(item.path, item._root || STATE.currentRoot);@@ -2658,6 +2660,7 @@ function isInlinePreviewableBlob (blob, name)2658
const ext = extOf(name || '');2660
const ext = extOf(name || '');2659
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext) || AUDIO_EXTS.has(ext)) return true;2661
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext) || AUDIO_EXTS.has(ext)) return true;2660
if (MODEL_EXTS.has(ext)) return true;2662
if (MODEL_EXTS.has(ext)) return true;2663
if (MODEL_EXTS.has(ext)) return true;2661
if (CODE_EXTS.has(ext)) return true;2664
if (CODE_EXTS.has(ext)) return true;2662
return false;2665
return false;2663
}2666
}@@ -3391,10 +3394,10 @@ async function loadThreePreviewModules ()3391
if (!threePreviewModulesPromise)3394
if (!threePreviewModulesPromise)3392
{3395
{3393
threePreviewModulesPromise = Promise.all([3396
threePreviewModulesPromise = Promise.all([3394
import('three'),3397
import('/vendor/three/three.module.js'),3395
import('three/addons/controls/OrbitControls.js'),3398
import('/vendor/three/addons/controls/OrbitControls.js'),3396
import('three/addons/loaders/STLLoader.js'),3399
import('/vendor/three/addons/loaders/STLLoader.js'),3397
import('three/addons/loaders/OBJLoader.js'),3400
import('/vendor/three/addons/loaders/OBJLoader.js'),3398
]).then(([THREE, controlsMod, stlMod, objMod]) =>3401
]).then(([THREE, controlsMod, stlMod, objMod]) =>3399
{3402
{3400
return {3403
return {@@ -3493,6 +3496,7 @@ async function renderModelPreview (item, blob, targetEl)3493
3496
3494
const canvas = document.createElement('canvas');3497
const canvas = document.createElement('canvas');3495
canvas.className = 'preview-model-canvas';3498
canvas.className = 'preview-model-canvas';3499
canvas.style.touchAction = 'none';3496
wrap.appendChild(canvas);3500
wrap.appendChild(canvas);3497
3501
3498
const hint = document.createElement('p');3502
const hint = document.createElement('p');@@ -4600,6 +4604,7 @@ function getThumbnailKind (name)4600
{4604
{4601
const ext = extOf(name || '');4605
const ext = extOf(name || '');4602
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext)) return 'image';4606
if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext)) return 'image';4607
if (MODEL_EXTS.has(ext)) return 'model';4603
if (CODE_EXTS.has(ext)) return 'text';4608
if (CODE_EXTS.has(ext)) return 'text';4604
return 'badge';4609
return 'badge';4605
}4610
}@@ -4607,6 +4612,7 @@ function getThumbnailKind (name)4607
function maxThumbBytesForKind (kind)4612
function maxThumbBytesForKind (kind)4608
{4613
{4609
if (kind === 'image') return 15 * 1024 * 1024;4614
if (kind === 'image') return 15 * 1024 * 1024;4615
if (kind === 'model') return 15 * 1024 * 1024;4610
if (kind === 'text') return 1024 * 1024;4616
if (kind === 'text') return 1024 * 1024;4611
return 0;4617
return 0;4612
}4618
}@@ -4706,9 +4712,271 @@ function badgeThumbnailDataUrl (name, kind)4706
async function buildThumbnailSource (item, blob, kind)4712
async function buildThumbnailSource (item, blob, kind)4707
{4713
{4708
if (kind === 'text') return textThumbnailDataUrl(await blob.text());4714
if (kind === 'text') return textThumbnailDataUrl(await blob.text());4715
if (kind === 'model') return await modelThumbnailDataUrl(item, blob);4709
return badgeThumbnailDataUrl(item.name, kind);4716
return badgeThumbnailDataUrl(item.name, kind);4710
}4717
}4711
4718
4719
function createModelSvgFromPolygons (polygons)4720
{4721
const width = 160;4722
const height = 200;4723
const pad = 12;4724
4725
let minX = Infinity;4726
let minY = Infinity;4727
let maxX = -Infinity;4728
let maxY = -Infinity;4729
4730
for (const poly of polygons)4731
{4732
for (const point of poly.points)4733
{4734
minX = Math.min(minX, point.x);4735
minY = Math.min(minY, point.y);4736
maxX = Math.max(maxX, point.x);4737
maxY = Math.max(maxY, point.y);4738
}4739
}4740
4741
if (!Number.isFinite(minX) || !Number.isFinite(minY) || !Number.isFinite(maxX) || !Number.isFinite(maxY))4742
{4743
return null;4744
}4745
4746
const boxW = Math.max(1, maxX - minX);4747
const boxH = Math.max(1, maxY - minY);4748
const scale = Math.min((width - pad * 2) / boxW, (height - pad * 2 - 18) / boxH);4749
const cx = (minX + maxX) / 2;4750
const cy = (minY + maxY) / 2;4751
4752
const svgPolys = polygons.map((poly) =>4753
{4754
const pts = poly.points.map((point) =>4755
{4756
const x = width / 2 + (point.x - cx) * scale;4757
const y = 18 + height / 2 + (point.y - cy) * scale;4758
return `${x.toFixed(1)},${y.toFixed(1)}`;4759
}).join(' ');4760
4761
return `<polygon points="${pts}" fill="rgba(47,109,255,0.28)" stroke="#7ea2ff" stroke-width="0.9" stroke-linejoin="round"/>`;4762
}).join('');4763
4764
return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`4765
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">4766
<defs>4767
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">4768
<stop offset="0%" stop-color="#111826"/>4769
<stop offset="100%" stop-color="#0d111a"/>4770
</linearGradient>4771
</defs>4772
<rect width="${width}" height="${height}" rx="10" fill="url(#bg)"/>4773
<rect x="0" y="0" width="${width}" height="28" fill="#2f6dff"/>4774
<text x="80" y="17" font-family="sans-serif" font-size="12" text-anchor="middle" fill="#ffffff" font-weight="700">3D</text>4775
${svgPolys}4776
</svg>4777
`)}`;4778
}4779
4780
function projectModelVector (vector)4781
{4782
const x = vector.x;4783
const y = vector.y;4784
const z = vector.z;4785
const ry = Math.PI / 4;4786
const rx = -Math.PI / 5;4787
4788
const x1 = x * Math.cos(ry) + z * Math.sin(ry);4789
const z1 = -x * Math.sin(ry) + z * Math.cos(ry);4790
const y2 = y * Math.cos(rx) - z1 * Math.sin(rx);4791
const z2 = y * Math.sin(rx) + z1 * Math.cos(rx);4792
4793
return { x: x1, y: y2, z: z2 };4794
}4795
4796
function resolveObjIndex (token, vertexCount)4797
{4798
const raw = Number.parseInt(String(token || '').split('/')[0], 10);4799
if (!Number.isFinite(raw) || raw === 0) return null;4800
const index = raw < 0 ? vertexCount + raw : raw - 1;4801
if (index < 0 || index >= vertexCount) return null;4802
return index;4803
}4804
4805
function parseObjPolygons (text)4806
{4807
const vertices = [];4808
const faces = [];4809
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n');4810
4811
for (const lineRaw of lines)4812
{4813
const line = lineRaw.trim();4814
if (!line || line.startsWith('#')) continue;4815
4816
if (/^v\s+/i.test(line))4817
{4818
const parts = line.split(/\s+/);4819
if (parts.length >= 4)4820
{4821
const x = Number(parts[1]);4822
const y = Number(parts[2]);4823
const z = Number(parts[3]);4824
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))4825
{4826
vertices.push({ x, y, z });4827
}4828
}4829
continue;4830
}4831
4832
if (/^f\s+/i.test(line))4833
{4834
const parts = line.split(/\s+/).slice(1);4835
if (parts.length >= 3) faces.push(parts);4836
}4837
}4838
4839
const polygons = [];4840
for (const face of faces)4841
{4842
const indices = face4843
.map((token) => resolveObjIndex(token, vertices.length))4844
.filter((index) => index != null);4845
4846
if (indices.length < 3) continue;4847
const anchor = vertices[indices[0]];4848
for (let i = 1; i < indices.length - 1; i++)4849
{4850
const b = vertices[indices[i]];4851
const c = vertices[indices[i + 1]];4852
if (anchor && b && c)4853
{4854
polygons.push({ points: [anchor, b, c] });4855
}4856
}4857
}4858
4859
return polygons;4860
}4861
4862
function parseAsciiStlPolygons (text)4863
{4864
const polygons = [];4865
const vertices = [];4866
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n');4867
4868
for (const lineRaw of lines)4869
{4870
const line = lineRaw.trim();4871
if (!/^vertex\s+/i.test(line)) continue;4872
const parts = line.split(/\s+/);4873
if (parts.length < 4) continue;4874
const x = Number(parts[1]);4875
const y = Number(parts[2]);4876
const z = Number(parts[3]);4877
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))4878
{4879
vertices.push({ x, y, z });4880
}4881
}4882
4883
for (let i = 0; i + 2 < vertices.length; i += 3)4884
{4885
polygons.push({ points: [vertices[i], vertices[i + 1], vertices[i + 2]] });4886
}4887
4888
return polygons;4889
}4890
4891
function parseBinaryStlPolygons (buffer)4892
{4893
const polygons = [];4894
if (!buffer || buffer.byteLength < 84) return polygons;4895
4896
const view = new DataView(buffer);4897
const triCount = view.getUint32(80, true);4898
let offset = 84;4899
4900
for (let i = 0; i < triCount; i++)4901
{4902
if (offset + 50 > buffer.byteLength) break;4903
offset += 12; // normal4904
const points = [];4905
for (let v = 0; v < 3; v++)4906
{4907
const x = view.getFloat32(offset, true);4908
const y = view.getFloat32(offset + 4, true);4909
const z = view.getFloat32(offset + 8, true);4910
points.push({ x, y, z });4911
offset += 12;4912
}4913
offset += 2; // attribute byte count4914
polygons.push({ points });4915
}4916
4917
return polygons;4918
}4919
4920
async function parseModelPolygonsFromBlob (blob, type)4921
{4922
const extType = String(type || '').toLowerCase();4923
if (extType === 'obj')4924
{4925
return parseObjPolygons(await blob.text());4926
}4927
4928
if (extType === 'stl')4929
{4930
const text = await blob.text();4931
if (/\bvertex\s+/i.test(text) && /\bfacet\s+/i.test(text))4932
{4933
return parseAsciiStlPolygons(text);4934
}4935
4936
try4937
{4938
return parseBinaryStlPolygons(await blob.arrayBuffer());4939
} catch4940
{4941
return [];4942
}4943
}4944
4945
return [];4946
}4947
4948
async function modelThumbnailDataUrl (item, blob)4949
{4950
const type = modelPreviewType(item && item.name);4951
if (!type) return badgeThumbnailDataUrl(item.name, 'badge');4952
4953
let modelPolygons;4954
try4955
{4956
modelPolygons = await parseModelPolygonsFromBlob(blob, type);4957
} catch4958
{4959
return badgeThumbnailDataUrl(item.name, 'badge');4960
}4961
4962
if (!modelPolygons.length) return badgeThumbnailDataUrl(item.name, 'badge');4963
4964
const polygons = [];4965
for (const poly of modelPolygons)4966
{4967
const projectedPoints = poly.points.map((point) => projectModelVector(point));4968
polygons.push({4969
points: projectedPoints.map((point) => ({ x: point.x, y: point.y })),4970
depth: projectedPoints.reduce((sum, point) => sum + point.z, 0) / projectedPoints.length,4971
});4972
}4973
4974
polygons.sort((a, b) => a.depth - b.depth);4975
const svgUrl = createModelSvgFromPolygons(polygons);4976
if (svgUrl) return svgUrl;4977
return badgeThumbnailDataUrl(item.name, 'badge');4978
}4979
4712
function observeThumbnailIcon (iconEl)4980
function observeThumbnailIcon (iconEl)4713
{4981
{4714
if (!iconEl || !iconEl.isConnected) return;4982
if (!iconEl || !iconEl.isConnected) return;@@ -15,6 +15,7 @@ function makeDraggable (el, item)
15
15
{
16
16
el.addEventListener('pointerdown', (e) =>
17
17
{
18
if (el.classList.contains('file-item--preview')) return;
18
19
if (e.button !== undefined && e.button !== 0) return;
19
20
_dragStart(e, el, item);
20
21
});
@@ -15,6 +15,7 @@ function makeDraggable (el, item)15
{15
{16
el.addEventListener('pointerdown', (e) =>16
el.addEventListener('pointerdown', (e) =>17
{17
{18
if (el.classList.contains('file-item--preview')) return;18
if (e.button !== undefined && e.button !== 0) return;19
if (e.button !== undefined && e.button !== 0) return;19
_dragStart(e, el, item);20
_dragStart(e, el, item);20
});21
});@@ -659,7 +659,7 @@ describe('page load smoke test', () =>
659
659
660
660
const fileTile = dom.window.document.querySelector('.file-item[data-path="/personal/tester/private.txt"]');
661
661
fileTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
662
await new Promise(resolve => dom.window.setTimeout(resolve, 40));
662
await waitFor(dom, () => dom.window.document.querySelectorAll('#sidebar-actions button').length >= 4);
663
663
664
664
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
665
665
expect(actionButtons).toContain('Share');
@@ -781,7 +781,7 @@ describe('page load smoke test', () =>
781
781
await new Promise(resolve => dom.window.setTimeout(resolve, 10));
782
782
secondTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
783
783
784
await new Promise(resolve => dom.window.setTimeout(resolve, 220));
784
await waitFor(dom, () => Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent).join('|') === 'View / Download|Share');
785
785
786
786
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
787
787
expect(actionButtons).toEqual(['View / Download', 'Share']);
@@ -908,6 +908,38 @@ describe('page load smoke test', () =>
908
908
dom.window.close();
909
909
});
910
910
911
test('stl tiles use a model thumbnail instead of a badge', async () =>
912
{
913
listFixture = {
914
'/data': [
915
{
916
name: 'part.stl',
917
path: '/data/part.stl',
918
isDir: false,
919
size: 256,
920
mtime: Date.now(),
921
},
922
],
923
};
924
downloadFixture['/data/part.stl'] = {
925
type: 'model/stl',
926
body: 'solid part\nfacet normal 0 0 1\n outer loop\n vertex 0 0 0\n vertex 1 0 0\n vertex 0 1 0\n endloop\nendfacet\nendsolid part\n',
927
};
928
929
const { dom, runtimeErrors } = await bootClient();
930
expect(runtimeErrors).toEqual([]);
931
932
await waitFor(dom, () => !!dom.window.document.querySelector('.icon[data-preview-path="/data/part.stl"] image'));
933
934
const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/part.stl"]');
935
expect(icon).toBeTruthy();
936
expect(icon.classList.contains('thumb-pending')).toBe(false);
937
expect(icon.dataset.thumbReady).toBe('1');
938
expect(String(icon.querySelector('image').getAttribute('href') || '')).toMatch(/^data:image\/svg\+xml/);
939
940
dom.window.close();
941
});
942
911
943
test('expanded file preview shows a Share button next to Download', async () =>
912
944
{
913
945
downloadFixture['/data/readme.txt'] = {
@@ -972,6 +1004,50 @@ describe('page load smoke test', () =>
972
1004
dom.window.close();
973
1005
});
974
1006
1007
test('expanded STL preview does not start file drag when dragging over the preview', async () =>
1008
{
1009
listFixture['/data'] = [
1010
{
1011
name: 'part.stl',
1012
path: '/data/part.stl',
1013
isDir: false,
1014
size: 128,
1015
mtime: Date.now(),
1016
},
1017
];
1018
downloadFixture['/data/part.stl'] = {
1019
type: 'model/stl',
1020
body: 'solid part\nendsolid part\n',
1021
};
1022
1023
const { dom, runtimeErrors } = await bootClient();
1024
expect(runtimeErrors).toEqual([]);
1025
1026
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/part.stl"]'));
1027
1028
const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/part.stl"]');
1029
fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
1030
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item--preview'));
1031
1032
const previewTile = dom.window.document.querySelector('.file-item--preview');
1033
previewTile.dispatchEvent(new dom.window.MouseEvent('pointerdown', {
1034
bubbles: true,
1035
button: 0,
1036
clientX: 100,
1037
clientY: 100,
1038
}));
1039
dom.window.document.dispatchEvent(new dom.window.MouseEvent('pointermove', {
1040
bubbles: true,
1041
clientX: 140,
1042
clientY: 140,
1043
}));
1044
1045
await new Promise(resolve => dom.window.setTimeout(resolve, 40));
1046
expect(previewTile.classList.contains('dragging')).toBe(false);
1047
1048
dom.window.close();
1049
});
1050
975
1051
test('expanded video preview uses a stream session and video.js', async () =>
976
1052
{
977
1053
listFixture['/data'] = [
@@ -659,7 +659,7 @@ describe('page load smoke test', () =>659
659
660
const fileTile = dom.window.document.querySelector('.file-item[data-path="/personal/tester/private.txt"]');
660
const fileTile = dom.window.document.querySelector('.file-item[data-path="/personal/tester/private.txt"]');
661
fileTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
661
fileTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
662
await new Promise(resolve => dom.window.setTimeout(resolve, 40));
662
await waitFor(dom, () => dom.window.document.querySelectorAll('#sidebar-actions button').length >= 4);
663
663
664
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
664
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
665
expect(actionButtons).toContain('Share');
665
expect(actionButtons).toContain('Share');
@@ -781,7 +781,7 @@ describe('page load smoke test', () =>781
await new Promise(resolve => dom.window.setTimeout(resolve, 10));
781
await new Promise(resolve => dom.window.setTimeout(resolve, 10));
782
secondTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
782
secondTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
783
783
784
await new Promise(resolve => dom.window.setTimeout(resolve, 220));
784
await waitFor(dom, () => Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent).join('|') === 'View / Download|Share');
785
785
786
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
786
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
787
expect(actionButtons).toEqual(['View / Download', 'Share']);
787
expect(actionButtons).toEqual(['View / Download', 'Share']);
@@ -908,6 +908,38 @@ describe('page load smoke test', () =>908
dom.window.close();
908
dom.window.close();
909
});
909
});
910
910
911
test('stl tiles use a model thumbnail instead of a badge', async () =>
912
{
913
listFixture = {
914
'/data': [
915
{
916
name: 'part.stl',
917
path: '/data/part.stl',
918
isDir: false,
919
size: 256,
920
mtime: Date.now(),
921
},
922
],
923
};
924
downloadFixture['/data/part.stl'] = {
925
type: 'model/stl',
926
body: 'solid part\nfacet normal 0 0 1\n outer loop\n vertex 0 0 0\n vertex 1 0 0\n vertex 0 1 0\n endloop\nendfacet\nendsolid part\n',
927
};
928
929
const { dom, runtimeErrors } = await bootClient();
930
expect(runtimeErrors).toEqual([]);
931
932
await waitFor(dom, () => !!dom.window.document.querySelector('.icon[data-preview-path="/data/part.stl"] image'));
933
934
const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/part.stl"]');
935
expect(icon).toBeTruthy();
936
expect(icon.classList.contains('thumb-pending')).toBe(false);
937
expect(icon.dataset.thumbReady).toBe('1');
938
expect(String(icon.querySelector('image').getAttribute('href') || '')).toMatch(/^data:image\/svg\+xml/);
939
940
dom.window.close();
941
});
942
911
test('expanded file preview shows a Share button next to Download', async () =>
943
test('expanded file preview shows a Share button next to Download', async () =>
912
{
944
{
913
downloadFixture['/data/readme.txt'] = {
945
downloadFixture['/data/readme.txt'] = {
@@ -972,6 +1004,50 @@ describe('page load smoke test', () =>972
dom.window.close();
1004
dom.window.close();
973
});
1005
});
974
1006
1007
test('expanded STL preview does not start file drag when dragging over the preview', async () =>
1008
{
1009
listFixture['/data'] = [
1010
{
1011
name: 'part.stl',
1012
path: '/data/part.stl',
1013
isDir: false,
1014
size: 128,
1015
mtime: Date.now(),
1016
},
1017
];
1018
downloadFixture['/data/part.stl'] = {
1019
type: 'model/stl',
1020
body: 'solid part\nendsolid part\n',
1021
};
1022
1023
const { dom, runtimeErrors } = await bootClient();
1024
expect(runtimeErrors).toEqual([]);
1025
1026
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/part.stl"]'));
1027
1028
const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/part.stl"]');
1029
fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
1030
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item--preview'));
1031
1032
const previewTile = dom.window.document.querySelector('.file-item--preview');
1033
previewTile.dispatchEvent(new dom.window.MouseEvent('pointerdown', {
1034
bubbles: true,
1035
button: 0,
1036
clientX: 100,
1037
clientY: 100,
1038
}));
1039
dom.window.document.dispatchEvent(new dom.window.MouseEvent('pointermove', {
1040
bubbles: true,
1041
clientX: 140,
1042
clientY: 140,
1043
}));
1044
1045
await new Promise(resolve => dom.window.setTimeout(resolve, 40));
1046
expect(previewTile.classList.contains('dragging')).toBe(false);
1047
1048
dom.window.close();
1049
});
1050
975
test('expanded video preview uses a stream session and video.js', async () =>
1051
test('expanded video preview uses a stream session and video.js', async () =>
976
{
1052
{
977
listFixture['/data'] = [
1053
listFixture['/data'] = [