feat: consistent fit-on-open — height for paged, width for text

Unifies the default zoom across formats:
- PDF & comics fit one whole page to the window HEIGHT (new 'page-height'
  zoom option + defaultScaleOption)
- Continuous HTML docs (DOCX/RTF/MD/ODF/DOC) fit to WIDTH; BaseRenderer now
  scales the .doc-page via CSS `zoom` (reflows layout, unlike transform, so
  vertical scroll stays correct)
- EPUB unchanged (reflowable, fills its frame; zoom = font size)

PDF renderer awaits thumbnail building (guarded) so the on-open height-fit
re-render can't race pdf.js page rendering.

Verified in preview: MD fits width (zoom 1.49 → 1216px in 1264px viewport),
comic fits height (707px in 758px). PDF rendering can't be exercised in the
headless preview (pre-existing pdf.js canvas hang, confirmed on clean main),
but its fit path is the same 'page-height' math as comics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 10:18:43 +02:00
co-authored by Claude Sonnet 4.6
parent c076c481f8
commit 92aa9f360a
6 changed files with 26 additions and 6 deletions
+1
View File
@@ -83,6 +83,7 @@
<option value="auto">Auto</option>
<option value="page-fit">Page Fit</option>
<option value="page-width">Page Width</option>
<option value="page-height">Fit Height</option>
<option value="0.5">50%</option>
<option value="0.75">75%</option>
<option value="1" selected>100%</option>
+3 -1
View File
@@ -175,7 +175,7 @@ class DocumentViewer {
}
_applyScaleOption(value) {
if (value === 'auto' || value === 'page-fit' || value === 'page-width') {
if (value === 'auto' || value === 'page-fit' || value === 'page-width' || value === 'page-height') {
const vc = document.getElementById('viewerContainer')
const w = vc.clientWidth - 48
const h = vc.clientHeight - 48
@@ -185,6 +185,8 @@ class DocumentViewer {
if (value === 'page-width') {
this._setScale(w / pw)
} else if (value === 'page-height') {
this._setScale(h / ph)
} else if (value === 'page-fit') {
this._setScale(Math.min(w / pw, h / ph))
} else {
+14 -2
View File
@@ -4,6 +4,10 @@ export class BaseRenderer {
this.scale = 1.0
this.container = null
this.viewer = null
// Preferred zoom on open. HTML document renderers (DOCX/RTF/MD/ODF/DOC)
// are one continuous page, so they fit to width. Paged renderers (PDF,
// comic) override to 'page-height'; reflowable EPUB sets null (font zoom).
this.defaultScaleOption = 'page-width'
}
async load(buffer, container, viewer) {
@@ -16,9 +20,17 @@ export class BaseRenderer {
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
setScale(_scale) { this.scale = _scale }
// Default scaling for HTML document renderers: zoom the fixed-width .doc-page.
// CSS `zoom` (unlike `transform`) reflows the layout box, so the container
// grows/shrinks and vertical scrolling stays correct.
setScale(scale) {
this.scale = scale
this.container?.querySelectorAll('.doc-page').forEach(el => {
el.style.zoom = scale === 1 ? '' : scale
})
}
getPageWidth() { return null }
getPageWidth() { return 816 } // ~8.5in @96dpi, the .doc-page width
getPageHeight() { return null }
async preparePrint() {}
+2 -2
View File
@@ -27,8 +27,8 @@ export class ComicRenderer extends BaseRenderer {
this._observer = null
this._naturalW = 0
this._naturalH = 0
// Comic scans are large; default to fitting the viewer width like a reader.
this.defaultScaleOption = 'page-width'
// Fixed pages → fit one whole page to the window height, like a reader.
this.defaultScaleOption = 'page-height'
}
async load(buffer, container, viewer) {
+1
View File
@@ -21,6 +21,7 @@ export class EPUBRenderer extends BaseRenderer {
this._view = null
this._total = 1
this._onResize = null
this.defaultScaleOption = null // reflowable: fills its frame, zoom = font size
}
async load(buffer, container, viewer) {
+5 -1
View File
@@ -13,6 +13,7 @@ export class PDFRenderer extends BaseRenderer {
this._pageW = 0
this._pageH = 0
this._observer = null
this.defaultScaleOption = 'page-height' // fixed pages → fit one to the window height
}
async load(buffer, container, viewer) {
@@ -34,7 +35,10 @@ export class PDFRenderer extends BaseRenderer {
}
this._attachScrollObserver()
this._buildThumbnails()
// Await so the default-zoom re-render (page-height on open) doesn't run
// concurrently with thumbnail rendering — pdf.js cancels page renders that
// overlap. Guarded so a thumbnail failure can't abort opening the document.
try { await this._buildThumbnails() } catch (e) { console.warn('[PDF] thumbnail build failed:', e) }
}
async _renderPage(pageNum) {