Nightly Build / build (push) Successful in 7m59s
On iOS the file viewer showed only the first page of a PDF, with no way to scroll to the rest — the document had to be downloaded and opened in another app. The cause was not ours: WebKit refuses to mount its PDF viewer inside an <iframe>/<object>/<embed> and paints a static first-page thumbnail instead. That hits Safari on iOS and every WKWebView, so the native shell too. The full viewer only exists for a top-level navigation. The desktop browsers do mount a viewer, but each mounts its own — Chrome's toolbar, Safari's page-index sidebar — so the same document also looked different on every machine. Both are answered by drawing the pages ourselves. New <pdf-view> (web/components/shared/pdf-view.js) renders a continuous scroll of canvas pages on the vendored pdf.js, with a zoom control and a page counter, and replaces the iframe for both native .pdf files and server-compiled LaTeX. Three properties are load-bearing: - pdf.js is imported lazily (~450 KB + a 1.2 MB worker), so a session that never opens a PDF never pays for it. - Canvases are created and destroyed as pages scroll. iOS caps the total canvas backing store a page may hold and silently blanks canvases past it, so an eager render would come out empty on exactly the platform this was written for. Off-screen pages keep only a correctly-sized box, which is also what keeps the scrollbar honest. - The text layer (selection, in-page find) is best-effort: it is transparent DOM over the pixels, so its failures are swallowed rather than surfaced. Vendored from pdfjs-dist 6.2.108: pdf.min.mjs, pdf.worker.min.mjs, the standard-font data (needed by PDFs that reference Helvetica/Times without embedding them) and the .textLayer block of pdf_viewer.css. CJK cmaps are deliberately left out. pdf.js 6 needs Safari/iOS 17.4+. Verified in headless Chromium against both a synthetic 12-page PDF using non-embedded Helvetica and a real 14-page paper with embedded fonts and figures: all pages present, last page renders after scrolling, page 1 released off-screen, text layer populated, zoom re-renders at the new scale, no JS errors.
454 lines
12 KiB
CSS
454 lines
12 KiB
CSS
/* ── File viewer page ───────────────────────────────────────────────────────── */
|
|
|
|
.fv-page {
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
}
|
|
|
|
.fv-title {
|
|
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
font-size: 0.95rem;
|
|
font-weight: 500;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
opacity: 0.9;
|
|
margin: 0;
|
|
/* RTL flips the ellipsis to the *start*, so a long path keeps its tail (the
|
|
filename) visible — `<bdi>` around the path preserves left-to-right order. */
|
|
direction: rtl;
|
|
text-align: left;
|
|
flex: 1 1 auto;
|
|
min-width: 0;
|
|
}
|
|
|
|
.fv-download-btn {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 32px;
|
|
height: 32px;
|
|
padding: 0 !important;
|
|
border-radius: 6px !important;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.fv-body {
|
|
flex: 1 1 auto;
|
|
overflow: auto;
|
|
position: relative;
|
|
min-height: 0;
|
|
}
|
|
|
|
.fv-state {
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
text-align: center;
|
|
padding: 2rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* ── Markdown preview ────────────────────────────────────────────────────────── */
|
|
|
|
.fv-md-wrap {
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 100%;
|
|
}
|
|
|
|
/* View | Edit tab bar — shown only when the caller can write the file. */
|
|
.fv-md-tabs {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.15rem;
|
|
padding: 0.4rem 1rem 0;
|
|
border-bottom: 1px solid var(--bs-border-color);
|
|
flex-shrink: 0;
|
|
}
|
|
.fv-md-tab {
|
|
appearance: none;
|
|
background: none;
|
|
border: none;
|
|
border-bottom: 2px solid transparent;
|
|
padding: 0.35rem 0.85rem;
|
|
margin-bottom: -1px;
|
|
font-size: 0.85rem;
|
|
color: var(--bs-secondary-color);
|
|
cursor: pointer;
|
|
border-radius: 4px 4px 0 0;
|
|
}
|
|
.fv-md-tab:hover { color: var(--bs-body-color); }
|
|
.fv-md-tab.active {
|
|
color: var(--bs-body-color);
|
|
border-bottom-color: var(--accent);
|
|
font-weight: 600;
|
|
}
|
|
.fv-md-dirty-dot {
|
|
width: 7px;
|
|
height: 7px;
|
|
border-radius: 50%;
|
|
background: var(--accent);
|
|
margin-left: 0.35rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
/* ── Source editor (Edit tab) ───────────────────────────────────────────────── */
|
|
|
|
.fv-edit {
|
|
flex: 1 1 auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
padding: 0.75rem 1rem 1rem;
|
|
gap: 0.5rem;
|
|
}
|
|
.fv-edit-textarea {
|
|
flex: 1 1 auto;
|
|
min-height: 50vh;
|
|
width: 100%;
|
|
resize: vertical;
|
|
padding: 0.85rem 1rem;
|
|
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
font-size: 0.85rem;
|
|
line-height: 1.55;
|
|
tab-size: 4;
|
|
color: var(--bs-body-color);
|
|
background: var(--bs-secondary-bg);
|
|
border: 1px solid var(--bs-border-color);
|
|
border-radius: 6px;
|
|
white-space: pre;
|
|
overflow-wrap: normal;
|
|
overflow: auto;
|
|
}
|
|
.fv-edit-textarea:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
|
|
}
|
|
.fv-edit-toolbar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
flex-shrink: 0;
|
|
}
|
|
.fv-edit-hint {
|
|
font-size: 0.78rem;
|
|
color: var(--bs-secondary-color);
|
|
margin-left: auto;
|
|
}
|
|
|
|
/* ── Conflict banner (remote changed while editing) ─────────────────────────── */
|
|
|
|
.fv-conflict-banner {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 0.6rem;
|
|
padding: 0.6rem 0.85rem;
|
|
background: var(--bs-warning-bg-subtle, #fff3cd);
|
|
border: 1px solid var(--bs-warning-border-subtle, #ffe69c);
|
|
color: var(--bs-emphasis-color, inherit);
|
|
border-radius: 6px;
|
|
flex-shrink: 0;
|
|
}
|
|
.fv-conflict-banner > .bi {
|
|
color: var(--bs-warning-text-emphasis, #664d03);
|
|
font-size: 1.05rem;
|
|
flex-shrink: 0;
|
|
}
|
|
.fv-conflict-text {
|
|
flex: 1 1 200px;
|
|
font-size: 0.82rem;
|
|
min-width: 0;
|
|
}
|
|
.fv-conflict-actions {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.4rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.fv-md {
|
|
max-width: 100%;
|
|
padding: 1.5rem 2rem;
|
|
line-height: 1.6;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.fv-md > *:first-child { margin-top: 0; }
|
|
.fv-md > *:last-child { margin-bottom: 0; }
|
|
|
|
.fv-md h1,
|
|
.fv-md h2,
|
|
.fv-md h3,
|
|
.fv-md h4 { margin: 1.2rem 0 0.5rem; line-height: 1.3; }
|
|
.fv-md h1 { font-size: 1.5em; }
|
|
.fv-md h2 { font-size: 1.3em; }
|
|
.fv-md h3 { font-size: 1.15em; }
|
|
.fv-md h4 { font-size: 1em; }
|
|
|
|
.fv-md p { margin: 0.5rem 0; }
|
|
.fv-md ul,
|
|
.fv-md ol { margin: 0.5rem 0; padding-left: 1.5rem; }
|
|
.fv-md li { margin: 0.2rem 0; }
|
|
|
|
.fv-md code {
|
|
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
font-size: 0.85em;
|
|
background: var(--bs-secondary-bg);
|
|
padding: 0.1rem 0.35rem;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.fv-md pre {
|
|
background: var(--bs-secondary-bg);
|
|
padding: 0.85rem 1rem;
|
|
border-radius: 6px;
|
|
overflow: auto;
|
|
margin: 0.75rem 0;
|
|
}
|
|
.fv-md pre code { background: none; padding: 0; font-size: inherit; }
|
|
|
|
.fv-md blockquote {
|
|
border-left: 3px solid var(--bs-border-color);
|
|
margin: 0.75rem 0;
|
|
padding: 0.25rem 0 0.25rem 1rem;
|
|
color: var(--bs-secondary-color);
|
|
}
|
|
|
|
.fv-md hr { border: none; border-top: 1px solid var(--bs-border-color); margin: 1.25rem 0; }
|
|
.fv-md a { color: var(--accent); text-decoration: underline; }
|
|
.fv-md strong { font-weight: 700; }
|
|
.fv-md em { font-style: italic; }
|
|
|
|
.fv-md img { max-width: 100%; border-radius: 4px; }
|
|
|
|
.fv-md table {
|
|
border-collapse: collapse;
|
|
margin: 0.75rem 0;
|
|
}
|
|
.fv-md th,
|
|
.fv-md td {
|
|
border: 1px solid var(--bs-border-color);
|
|
padding: 0.4rem 0.6rem;
|
|
}
|
|
|
|
/* ── Code/text preview ───────────────────────────────────────────────────────── */
|
|
|
|
.fv-code {
|
|
margin: 0;
|
|
padding: 1.25rem 1.5rem;
|
|
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
font-size: 0.85rem;
|
|
line-height: 1.55;
|
|
white-space: pre;
|
|
overflow: auto;
|
|
background: var(--bs-secondary-bg);
|
|
color: var(--bs-body-color);
|
|
min-height: 100%;
|
|
tab-size: 4;
|
|
}
|
|
|
|
/* Header action buttons (mode toggle + download) sit in one row. */
|
|
.fv-header-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
/* ── PDF preview ─────────────────────────────────────────────────────────────── */
|
|
|
|
/* PDFs are drawn by <pdf-view> (web/components/shared/pdf-view.js) on canvas, not
|
|
handed to the browser's built-in viewer: WebKit paints only a static first page
|
|
inside a frame — which is why iOS showed page 1 and nothing else — and the
|
|
desktop browsers each mount a different viewer chrome. `.fv-pdf` is the block
|
|
the viewer body gives it; everything below is that component's own layout. */
|
|
.fv-pdf {
|
|
display: block;
|
|
width: 100%;
|
|
height: 100%;
|
|
min-height: 0;
|
|
}
|
|
|
|
.pdfv {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
min-height: 0;
|
|
}
|
|
|
|
.pdfv-toolbar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.35rem 0.6rem;
|
|
border-bottom: 1px solid var(--bs-border-color);
|
|
background: var(--bs-tertiary-bg);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.pdfv-btn {
|
|
border: 1px solid var(--bs-border-color);
|
|
background: var(--bs-body-bg);
|
|
color: var(--bs-body-color);
|
|
border-radius: var(--radius-sm);
|
|
padding: 0.15rem 0.5rem;
|
|
line-height: 1.4;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.pdfv-btn:hover:not(:disabled) { background: var(--bs-secondary-bg); }
|
|
.pdfv-btn:disabled { opacity: 0.4; cursor: default; }
|
|
|
|
.pdfv-zoom {
|
|
min-width: 3.5rem;
|
|
text-align: center;
|
|
font-size: 0.85rem;
|
|
color: var(--bs-secondary-color);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
.pdfv-pageno {
|
|
margin-left: auto;
|
|
font-size: 0.85rem;
|
|
color: var(--bs-secondary-color);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
/* The scroll root. `position: relative` makes it the offsetParent of every page
|
|
box, which is what lets the component compare `offsetTop` against `scrollTop`
|
|
when it decides which pages hold pixels. */
|
|
.pdfv-scroll {
|
|
position: relative;
|
|
flex: 1;
|
|
min-height: 0;
|
|
overflow: auto;
|
|
overscroll-behavior: contain;
|
|
-webkit-overflow-scrolling: touch;
|
|
background: var(--bs-secondary-bg);
|
|
}
|
|
|
|
/* `width: max-content` + `min-width: 100%` is what makes zoom usable: with a
|
|
plain `align-items: center`, a page wider than the scroll box overflows on
|
|
*both* sides and the left half becomes unreachable — centring happens before
|
|
scrolling exists. Growing this box to the widest page instead gives an honest
|
|
horizontal scroll range, while min-width keeps pages centred when they fit. */
|
|
.pdfv-pages {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
width: max-content;
|
|
min-width: 100%;
|
|
gap: 0.6rem;
|
|
padding: 0.6rem;
|
|
}
|
|
|
|
/* A page box is sized before it is drawn, so the scrollbar is honest from the
|
|
start and a page that is currently released leaves no gap. The pdf.js text
|
|
layer positions itself against these CSS variables. */
|
|
.pdfv-page {
|
|
position: relative;
|
|
background: #fff;
|
|
box-shadow: 0 1px 6px rgb(0 0 0 / 0.35);
|
|
overflow: hidden;
|
|
--user-unit: 1;
|
|
--total-scale-factor: calc(var(--scale-factor) * var(--user-unit));
|
|
--scale-round-x: 1px;
|
|
--scale-round-y: 1px;
|
|
}
|
|
|
|
.pdfv-canvas {
|
|
display: block;
|
|
}
|
|
|
|
.pdfv-page-failed::after {
|
|
content: "!";
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--bs-danger, #b91c1c);
|
|
font-size: 2rem;
|
|
}
|
|
|
|
.pdfv-error-detail {
|
|
margin-top: 0.4rem;
|
|
font-size: 0.8rem;
|
|
opacity: 0.75;
|
|
word-break: break-word;
|
|
}
|
|
|
|
/* ── HTML live preview ───────────────────────────────────────────────────────── */
|
|
|
|
/* Rendered in an origin-isolated iframe (srcdoc + sandbox="allow-scripts").
|
|
White canvas so pages that don't set their own background stay legible. */
|
|
.fv-html {
|
|
width: 100%;
|
|
height: 100%;
|
|
border: none;
|
|
display: block;
|
|
background: #fff;
|
|
}
|
|
|
|
/* ── LaTeX compile-error banner (shown above the source fallback) ─────────────── */
|
|
|
|
.fv-compile-error {
|
|
margin: 0;
|
|
padding: 0.5rem 1.5rem;
|
|
background: var(--bs-warning-bg-subtle, #fff3cd);
|
|
border-bottom: 1px solid var(--bs-border-color);
|
|
font-size: 0.85rem;
|
|
}
|
|
.fv-compile-error > summary {
|
|
cursor: pointer;
|
|
user-select: none;
|
|
padding: 0.25rem 0;
|
|
}
|
|
.fv-compile-error > pre {
|
|
margin: 0.5rem 0 0.75rem;
|
|
padding: 0.75rem 1rem;
|
|
max-height: 40vh;
|
|
overflow: auto;
|
|
background: var(--bs-secondary-bg);
|
|
border-radius: 6px;
|
|
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
font-size: 0.8rem;
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
}
|
|
|
|
/* ── Image preview ───────────────────────────────────────────────────────────── */
|
|
|
|
.fv-image-wrap {
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 1rem;
|
|
background: var(--bs-secondary-bg);
|
|
}
|
|
|
|
.fv-image {
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
object-fit: contain;
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
|
|
}
|
|
|
|
/* SVG renders in a sandboxed iframe; the SVG root fills the iframe viewport and
|
|
scales to its viewBox. White canvas so light-on-transparent SVGs stay legible. */
|
|
.fv-svg {
|
|
width: 100%;
|
|
height: 100%;
|
|
border: none;
|
|
background: #fff;
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
|
|
}
|