Skip to content

Commit 3b59b90

Browse files
committed
Fit viewer images to the window
1 parent 5bdc454 commit 3b59b90

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎src/preview.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ async function showQL(which?: Entry) {
276276
const body = ql.querySelector<HTMLElement>(".ql-body")!;
277277
const pv = e.dir ? null : await previewOf(e, true);
278278
if (my !== qlToken) return;
279-
if (pv?.el instanceof HTMLImageElement) { pv.el.classList.add("zoomable"); pv.el.title = "Click: actual size / fit"; pv.el.onclick = () => pv.el.classList.toggle("actual"); }
280279
if (pv) body.replaceChildren(pv.el);
281280
else body.innerHTML = `<div class="glyph" style="transform:scale(1.6)">${glyph(e)}</div>`;
282281
body.querySelector("video")?.play().catch(() => {});
@@ -296,7 +295,7 @@ window.addEventListener("keydown", (ev) => {
296295
showQL();
297296
}
298297
});
299-
ql.addEventListener("dblclick", (ev) => { if (!(ev.target as HTMLElement).closest(".zoomable, .pv-tools, button, .md, pre")) closeQL(); });
298+
ql.addEventListener("dblclick", (ev) => { if (!(ev.target as HTMLElement).closest(".pv-tools, button, .md, pre")) closeQL(); });
300299
/** Open the viewer on this entry if it can show it properly. */
301300
hooks.preview = (e) => { if (!previewable(e)) return false; showQL(e); return true; };
302301
hooks.keys.push((ev) => {

‎src/style.css‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ body.resizing, body.resizing * { cursor: col-resize !important; user-select: non
332332
#quicklook .ql-body .md, #quicklook .ql-body pre { width: min(1180px, 96vw); max-height: none; font-size: 1.12em; }
333333
#quicklook .ql-body img, #quicklook .ql-body video { align-self: center; }
334334
#quicklook .ql-head { font-size: 1.15em; }
335+
/* a lone picture/video fills the window, letterboxed (scaled up too), no scrollbars */
336+
#quicklook .ql-body:has(> img:only-child, > video:only-child) { display: block; overflow: hidden; }
337+
#quicklook .ql-body > img:only-child, #quicklook .ql-body > video:only-child { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; border-radius: 0; }
335338
#quicklook .ql-body iframe { width: 100%; height: 100%; border: 0; background: var(--paper); }
336339

337340
/* ---------- dialogs (separate windows) ---------- */
@@ -606,8 +609,6 @@ body.dragging #shelf.empty { display: block; }
606609

607610
/* viewer: toolbar, PDF pages, zoom, copy buttons */
608611
#quicklook .ql-head button { border: 1px solid var(--divider); background: var(--paper); color: var(--on-paper); border-radius: calc(var(--radius) * .5); padding: 3px 12px; cursor: pointer; font-weight: 400; font-size: .85em; }
609-
#quicklook .ql-body img.zoomable { cursor: zoom-in; }
610-
#quicklook .ql-body img.zoomable.actual { max-width: none; max-height: none; cursor: zoom-out; }
611612
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(1400px, 90vw); padding-bottom: 24px; }
612613
#quicklook .ql-body .pdf-pages img.pdf-page { width: 100%; max-height: none; aspect-ratio: 1 / 1.414; background: #fff; border-radius: 3px; box-shadow: 0 6px 24px -10px rgb(0 0 0 / .6); }
613614
.md pre { position: relative; }

0 commit comments

Comments
 (0)