Match preview sheet accent to file type and animate icon-to-preview opening
@@ -40,6 +40,8 @@
40
40
- detectCodeLanguage(name, mime) - Determines preview language for text/script files by MIME and extension.
41
41
- prettyPrintCode(raw, lang) - Best-effort formatter for JSON/markup/script previews before rendering.
42
42
- highlightCode(raw, lang) - Escapes and syntax-highlights preview text into HTML spans.
43
- fileAccentColor(name) - Returns canonical file-type accent color used by icon strokes and preview sheet outline.
44
- animatePreviewOpen(sourceSvgEl, sheetEl) - Animates a cloned file icon from its tile position into the full preview sheet.
43
45
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.
44
46
- downloadOrView(item) - Opens the in-app file-preview overlay and attaches bottom download action.
45
47
- renderPreviewBody(item, blob, objectUrl) - Renders preview content (image/video/audio/pdf/text) or unsupported message.
@@ -40,6 +40,8 @@40
- detectCodeLanguage(name, mime) - Determines preview language for text/script files by MIME and extension.40
- detectCodeLanguage(name, mime) - Determines preview language for text/script files by MIME and extension.41
- prettyPrintCode(raw, lang) - Best-effort formatter for JSON/markup/script previews before rendering.41
- prettyPrintCode(raw, lang) - Best-effort formatter for JSON/markup/script previews before rendering.42
- highlightCode(raw, lang) - Escapes and syntax-highlights preview text into HTML spans.42
- highlightCode(raw, lang) - Escapes and syntax-highlights preview text into HTML spans.43
- fileAccentColor(name) - Returns canonical file-type accent color used by icon strokes and preview sheet outline.44
- animatePreviewOpen(sourceSvgEl, sheetEl) - Animates a cloned file icon from its tile position into the full preview sheet.43
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.45
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.44
- downloadOrView(item) - Opens the in-app file-preview overlay and attaches bottom download action.46
- downloadOrView(item) - Opens the in-app file-preview overlay and attaches bottom download action.45
- renderPreviewBody(item, blob, objectUrl) - Renders preview content (image/video/audio/pdf/text) or unsupported message.47
- renderPreviewBody(item, blob, objectUrl) - Renders preview content (image/video/audio/pdf/text) or unsupported message.@@ -924,7 +924,7 @@ function makeFileItem (item)
924
924
navigateTo(item.path, STATE.currentRoot);
925
925
} else
926
926
{
927
downloadOrView(item);
927
downloadOrView(item, icon.querySelector('svg'));
928
928
}
929
929
});
930
930
@@ -975,7 +975,12 @@ async function openSidebar (item)
975
975
// View / download button
976
976
const btnDl = document.createElement('button');
977
977
btnDl.textContent = 'View / Download';
978
btnDl.addEventListener('click', () => downloadOrView(item));
978
btnDl.addEventListener('click', () =>
979
{
980
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);
981
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');
982
downloadOrView(item, source);
983
});
979
984
actions.appendChild(btnDl);
980
985
} else
981
986
{
@@ -1176,6 +1181,78 @@ function clearPreviewObjectUrl ()
1176
1181
STATE.previewObjectUrl = null;
1177
1182
}
1178
1183
1184
function fileAccentColor (name)
1185
{
1186
const ext = extOf(name || '');
1187
if (IMAGE_EXTS.has(ext)) return '#3fcf8e';
1188
if (VIDEO_EXTS.has(ext)) return '#e05c6e';
1189
if (AUDIO_EXTS.has(ext)) return '#c084fc';
1190
if (DOC_EXTS.has(ext)) return '#f97316';
1191
if (CODE_EXTS.has(ext)) return '#38bdf8';
1192
if (ARCHIVE_EXTS.has(ext)) return '#facc15';
1193
return '#7880a0';
1194
}
1195
1196
function animatePreviewOpen (sourceSvgEl, sheetEl)
1197
{
1198
if (!sourceSvgEl || !sheetEl || !sourceSvgEl.isConnected) return Promise.resolve();
1199
1200
const start = sourceSvgEl.getBoundingClientRect();
1201
const end = sheetEl.getBoundingClientRect();
1202
if (!start.width || !start.height || !end.width || !end.height) return Promise.resolve();
1203
1204
const ghost = document.createElement('div');
1205
ghost.className = 'preview-ghost';
1206
ghost.style.left = `${start.left}px`;
1207
ghost.style.top = `${start.top}px`;
1208
ghost.style.width = `${start.width}px`;
1209
ghost.style.height = `${start.height}px`;
1210
1211
const clone = sourceSvgEl.cloneNode(true);
1212
clone.style.width = '100%';
1213
clone.style.height = '100%';
1214
clone.style.display = 'block';
1215
ghost.appendChild(clone);
1216
document.body.appendChild(ghost);
1217
1218
return new Promise((resolve) =>
1219
{
1220
const anim = ghost.animate([
1221
{
1222
left: `${start.left}px`,
1223
top: `${start.top}px`,
1224
width: `${start.width}px`,
1225
height: `${start.height}px`,
1226
opacity: 1,
1227
borderRadius: '8px',
1228
},
1229
{
1230
left: `${end.left}px`,
1231
top: `${end.top}px`,
1232
width: `${end.width}px`,
1233
height: `${end.height}px`,
1234
opacity: 0.18,
1235
borderRadius: '12px',
1236
},
1237
], {
1238
duration: 260,
1239
easing: 'cubic-bezier(0.2, 0.9, 0.2, 1)',
1240
fill: 'forwards',
1241
});
1242
1243
anim.onfinish = () =>
1244
{
1245
ghost.remove();
1246
resolve();
1247
};
1248
anim.oncancel = () =>
1249
{
1250
ghost.remove();
1251
resolve();
1252
};
1253
});
1254
}
1255
1179
1256
function closePreview ()
1180
1257
{
1181
1258
const overlay = document.getElementById('preview-overlay');
@@ -1289,7 +1366,7 @@ async function renderPreviewBody (item, blob, objectUrl)
1289
1366
body.appendChild(msg);
1290
1367
}
1291
1368
1292
async function downloadOrView (item)
1369
async function downloadOrView (item, sourceSvgEl = null)
1293
1370
{
1294
1371
const blob = await fetchFileBlob(item);
1295
1372
if (!blob)
@@ -1303,13 +1380,19 @@ async function downloadOrView (item)
1303
1380
STATE.previewObjectUrl = objectUrl;
1304
1381
1305
1382
const overlay = document.getElementById('preview-overlay');
1383
const sheet = document.getElementById('preview-sheet');
1306
1384
const title = document.getElementById('preview-title');
1307
1385
const dlBtn = document.getElementById('preview-download');
1308
1386
1387
sheet.style.setProperty('--preview-accent', fileAccentColor(item.name));
1309
1388
title.textContent = item.name;
1310
1389
dlBtn.onclick = () => triggerDownload(item.name, objectUrl);
1311
1390
await renderPreviewBody(item, blob, objectUrl);
1391
1392
overlay.classList.add('preview-opening');
1312
1393
overlay.classList.remove('hidden');
1394
await animatePreviewOpen(sourceSvgEl, sheet);
1395
overlay.classList.remove('preview-opening');
1313
1396
}
1314
1397
1315
1398
// ───────────────────────────────────────────────────────────────────────────
@@ -1876,17 +1959,9 @@ function iconFolder (size = 52)
1876
1959
1877
1960
function iconFile (name, size = 52)
1878
1961
{
1879
const ext = extOf(name);
1880
let color = '#7880a0';
1962
const color = fileAccentColor(name);
1881
1963
let symbol = '';
1882
1964
1883
if (IMAGE_EXTS.has(ext)) color = '#3fcf8e';
1884
else if (VIDEO_EXTS.has(ext)) color = '#e05c6e';
1885
else if (AUDIO_EXTS.has(ext)) color = '#c084fc';
1886
else if (DOC_EXTS.has(ext)) color = '#f97316';
1887
else if (CODE_EXTS.has(ext)) color = '#38bdf8';
1888
else if (ARCHIVE_EXTS.has(ext)) color = '#facc15';
1889
1890
1965
return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none"
1891
1966
stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
1892
1967
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
@@ -924,7 +924,7 @@ function makeFileItem (item)924
navigateTo(item.path, STATE.currentRoot);924
navigateTo(item.path, STATE.currentRoot);925
} else925
} else926
{926
{927
downloadOrView(item);927
downloadOrView(item, icon.querySelector('svg'));928
}928
}929
});929
});930
930
@@ -975,7 +975,12 @@ async function openSidebar (item)975
// View / download button975
// View / download button976
const btnDl = document.createElement('button');976
const btnDl = document.createElement('button');977
btnDl.textContent = 'View / Download';977
btnDl.textContent = 'View / Download';978
btnDl.addEventListener('click', () => downloadOrView(item));978
btnDl.addEventListener('click', () =>979
{980
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);981
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');982
downloadOrView(item, source);983
});979
actions.appendChild(btnDl);984
actions.appendChild(btnDl);980
} else985
} else981
{986
{@@ -1176,6 +1181,78 @@ function clearPreviewObjectUrl ()1176
STATE.previewObjectUrl = null;1181
STATE.previewObjectUrl = null;1177
}1182
}1178
1183
1184
function fileAccentColor (name)1185
{1186
const ext = extOf(name || '');1187
if (IMAGE_EXTS.has(ext)) return '#3fcf8e';1188
if (VIDEO_EXTS.has(ext)) return '#e05c6e';1189
if (AUDIO_EXTS.has(ext)) return '#c084fc';1190
if (DOC_EXTS.has(ext)) return '#f97316';1191
if (CODE_EXTS.has(ext)) return '#38bdf8';1192
if (ARCHIVE_EXTS.has(ext)) return '#facc15';1193
return '#7880a0';1194
}1195
1196
function animatePreviewOpen (sourceSvgEl, sheetEl)1197
{1198
if (!sourceSvgEl || !sheetEl || !sourceSvgEl.isConnected) return Promise.resolve();1199
1200
const start = sourceSvgEl.getBoundingClientRect();1201
const end = sheetEl.getBoundingClientRect();1202
if (!start.width || !start.height || !end.width || !end.height) return Promise.resolve();1203
1204
const ghost = document.createElement('div');1205
ghost.className = 'preview-ghost';1206
ghost.style.left = `${start.left}px`;1207
ghost.style.top = `${start.top}px`;1208
ghost.style.width = `${start.width}px`;1209
ghost.style.height = `${start.height}px`;1210
1211
const clone = sourceSvgEl.cloneNode(true);1212
clone.style.width = '100%';1213
clone.style.height = '100%';1214
clone.style.display = 'block';1215
ghost.appendChild(clone);1216
document.body.appendChild(ghost);1217
1218
return new Promise((resolve) =>1219
{1220
const anim = ghost.animate([1221
{1222
left: `${start.left}px`,1223
top: `${start.top}px`,1224
width: `${start.width}px`,1225
height: `${start.height}px`,1226
opacity: 1,1227
borderRadius: '8px',1228
},1229
{1230
left: `${end.left}px`,1231
top: `${end.top}px`,1232
width: `${end.width}px`,1233
height: `${end.height}px`,1234
opacity: 0.18,1235
borderRadius: '12px',1236
},1237
], {1238
duration: 260,1239
easing: 'cubic-bezier(0.2, 0.9, 0.2, 1)',1240
fill: 'forwards',1241
});1242
1243
anim.onfinish = () =>1244
{1245
ghost.remove();1246
resolve();1247
};1248
anim.oncancel = () =>1249
{1250
ghost.remove();1251
resolve();1252
};1253
});1254
}1255
1179
function closePreview ()1256
function closePreview ()1180
{1257
{1181
const overlay = document.getElementById('preview-overlay');1258
const overlay = document.getElementById('preview-overlay');@@ -1289,7 +1366,7 @@ async function renderPreviewBody (item, blob, objectUrl)1289
body.appendChild(msg);1366
body.appendChild(msg);1290
}1367
}1291
1368
1292
async function downloadOrView (item)1369
async function downloadOrView (item, sourceSvgEl = null)1293
{1370
{1294
const blob = await fetchFileBlob(item);1371
const blob = await fetchFileBlob(item);1295
if (!blob)1372
if (!blob)@@ -1303,13 +1380,19 @@ async function downloadOrView (item)1303
STATE.previewObjectUrl = objectUrl;1380
STATE.previewObjectUrl = objectUrl;1304
1381
1305
const overlay = document.getElementById('preview-overlay');1382
const overlay = document.getElementById('preview-overlay');1383
const sheet = document.getElementById('preview-sheet');1306
const title = document.getElementById('preview-title');1384
const title = document.getElementById('preview-title');1307
const dlBtn = document.getElementById('preview-download');1385
const dlBtn = document.getElementById('preview-download');1308
1386
1387
sheet.style.setProperty('--preview-accent', fileAccentColor(item.name));1309
title.textContent = item.name;1388
title.textContent = item.name;1310
dlBtn.onclick = () => triggerDownload(item.name, objectUrl);1389
dlBtn.onclick = () => triggerDownload(item.name, objectUrl);1311
await renderPreviewBody(item, blob, objectUrl);1390
await renderPreviewBody(item, blob, objectUrl);1391
1392
overlay.classList.add('preview-opening');1312
overlay.classList.remove('hidden');1393
overlay.classList.remove('hidden');1394
await animatePreviewOpen(sourceSvgEl, sheet);1395
overlay.classList.remove('preview-opening');1313
}1396
}1314
1397
1315
// ───────────────────────────────────────────────────────────────────────────1398
// ───────────────────────────────────────────────────────────────────────────@@ -1876,17 +1959,9 @@ function iconFolder (size = 52)1876
1959
1877
function iconFile (name, size = 52)1960
function iconFile (name, size = 52)1878
{1961
{1879
const ext = extOf(name);1962
const color = fileAccentColor(name);1880
let color = '#7880a0';1881
let symbol = '';1963
let symbol = '';1882
1964
1883
if (IMAGE_EXTS.has(ext)) color = '#3fcf8e';1884
else if (VIDEO_EXTS.has(ext)) color = '#e05c6e';1885
else if (AUDIO_EXTS.has(ext)) color = '#c084fc';1886
else if (DOC_EXTS.has(ext)) color = '#f97316';1887
else if (CODE_EXTS.has(ext)) color = '#38bdf8';1888
else if (ARCHIVE_EXTS.has(ext)) color = '#facc15';1889
1890
return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none"1965
return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none"1891
stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">1966
stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">1892
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>1967
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>@@ -632,10 +632,11 @@ button.danger:hover {
632
632
}
633
633
634
634
.preview-sheet {
635
--preview-accent: #3fcf8e;
635
636
position: relative;
636
637
width: min(94vw, 1100px);
637
638
height: min(90vh, 860px);
638
border: 2px solid #3fcf8e;
639
border: 2px solid var(--preview-accent);
639
640
border-radius: 12px;
640
641
background: linear-gradient(180deg, #151925 0%, #111521 100%);
641
642
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
@@ -653,8 +654,19 @@ button.danger:hover {
653
654
height: 64px;
654
655
background: linear-gradient(135deg, #182135 0%, #0f1525 100%);
655
656
clip-path: polygon(100% 0, 100% 100%, 0 0);
656
border-left: 1px solid rgba(63, 207, 142, 0.45);
657
border-bottom: 1px solid rgba(63, 207, 142, 0.45);
657
border-left: 1px solid var(--preview-accent);
658
border-bottom: 1px solid var(--preview-accent);
659
}
660
661
.preview-opening .preview-sheet {
662
opacity: 0;
663
}
664
665
.preview-ghost {
666
position: fixed;
667
z-index: 130;
668
pointer-events: none;
669
display: block;
658
670
}
659
671
660
672
.preview-close {
@@ -632,10 +632,11 @@ button.danger:hover {632
}632
}633
633
634
.preview-sheet {634
.preview-sheet {635
--preview-accent: #3fcf8e;635
position: relative;636
position: relative;636
width: min(94vw, 1100px);637
width: min(94vw, 1100px);637
height: min(90vh, 860px);638
height: min(90vh, 860px);638
border: 2px solid #3fcf8e;639
border: 2px solid var(--preview-accent);639
border-radius: 12px;640
border-radius: 12px;640
background: linear-gradient(180deg, #151925 0%, #111521 100%);641
background: linear-gradient(180deg, #151925 0%, #111521 100%);641
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);642
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);@@ -653,8 +654,19 @@ button.danger:hover {653
height: 64px;654
height: 64px;654
background: linear-gradient(135deg, #182135 0%, #0f1525 100%);655
background: linear-gradient(135deg, #182135 0%, #0f1525 100%);655
clip-path: polygon(100% 0, 100% 100%, 0 0);656
clip-path: polygon(100% 0, 100% 100%, 0 0);656
border-left: 1px solid rgba(63, 207, 142, 0.45);657
border-left: 1px solid var(--preview-accent);657
border-bottom: 1px solid rgba(63, 207, 142, 0.45);658
border-bottom: 1px solid var(--preview-accent);659
}660
661
.preview-opening .preview-sheet {662
opacity: 0;663
}664
665
.preview-ghost {666
position: fixed;667
z-index: 130;668
pointer-events: none;669
display: block;658
}670
}659
671
660
.preview-close {672
.preview-close {