Align PDF preview with header content

Size desktop pages to HeaderBand's max-w-5xl column so
they line up with the title and toolbar. Mobile gutter is
unchanged.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-20 19:35:05 +02:00
parent f62cb82387
commit 854b405979

View File

@@ -37,18 +37,22 @@ import { pdfPreview } from "./variants";
// it from a CDN, so the viewer works under a strict trust-center CSP.
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
// Total horizontal inset (both sides) for fit-to-width at 100% zoom.
// Desktop matches HeaderBand / hero `px-8` (32px per side); mobile keeps the
// tighter phone gutter so pages stay readable.
// Fit-to-width at 100% zoom: mobile keeps a tight phone gutter; desktop pages
// match HeaderBand's inner column (`px-8` + centered `max-w-5xl`).
const PAGE_GUTTER_MOBILE_PX = 32;
const PAGE_GUTTER_DESKTOP_PX = 64;
const HEADER_PAD_DESKTOP_PX = 32; // Tailwind `px-8` per side
const HEADER_CONTENT_MAX_PX = 1024; // Tailwind `max-w-5xl`
// Tailwind `md` — same breakpoint as `max-md:px-4` on the hero band.
const DESKTOP_MEDIA_QUERY = "(min-width: 768px)";
function pageGutterPx(): number {
return window.matchMedia(DESKTOP_MEDIA_QUERY).matches
? PAGE_GUTTER_DESKTOP_PX
: PAGE_GUTTER_MOBILE_PX;
function pageWidthForWrapper(clientWidth: number): number {
if (!window.matchMedia(DESKTOP_MEDIA_QUERY).matches) {
return Math.max(clientWidth - PAGE_GUTTER_MOBILE_PX, 1);
}
return Math.max(
Math.min(clientWidth - HEADER_PAD_DESKTOP_PX * 2, HEADER_CONTENT_MAX_PX),
1,
);
}
function findCenteredPage(
@@ -121,13 +125,13 @@ export function PdfPreview({ file, scale, ref, onNumPages, onVisiblePageChange }
}
const updateWidth = () => {
setPageWidth(Math.max(wrapper.clientWidth - pageGutterPx(), 1));
setPageWidth(pageWidthForWrapper(wrapper.clientWidth));
};
updateWidth();
const observer = new ResizeObserver(updateWidth);
observer.observe(wrapper);
// Recompute when crossing the md breakpoint so the gutter tracks hero padding.
// Recompute when crossing the md breakpoint so width tracks HeaderBand.
const media = window.matchMedia(DESKTOP_MEDIA_QUERY);
media.addEventListener("change", updateWidth);
return () => {