diff --git a/package.json b/package.json index 778fde6..c254683 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "npm run build:ts:dev && npm run build:css" }, "dependencies": { - "@bookhoard/foliate-js": "git+https://github.com/john-okeefe/foliate-js.git#aba68d8", + "@bookhoard/foliate-js": "git+https://github.com/john-okeefe/foliate-js.git#1c0ebf3", "alpinejs": "^3.15.8", "chart.js": "^4.5.1", "highlight.js": "^11.11.1", diff --git a/web/src/reader/reader.ts b/web/src/reader/reader.ts index ce1e89d..20ce2b1 100644 --- a/web/src/reader/reader.ts +++ b/web/src/reader/reader.ts @@ -576,9 +576,6 @@ document.addEventListener("alpine:init", () => { this.book.dir = "rtl"; } this.isPDF = (this.renderer as any).isPDF; - if (this.isPDF) { - this.renderer.setAttribute("interaction-mode", this.interactionMode); - } // Click on a PDF/fixed-layout highlight rect → edit popover. this.renderer.addEventListener( "show-rect-annotation", @@ -671,7 +668,10 @@ document.addEventListener("alpine:init", () => { ); } // PDF textLayer selection → rect-fraction highlight popover. - if (this.isPDF) { + // Detected structurally: renderer.isPDF isn't set until the first + // spread renders (during view.init), which is after this listener + // attaches — the stale copy here would always be falsy. + if (this.isFixedLayout && doc.querySelector(".textLayer")) { const checkPDFSelection = () => { const sel = doc.getSelection(); if (!sel || sel.isCollapsed || !sel.rangeCount) return; @@ -816,6 +816,14 @@ document.addEventListener("alpine:init", () => { } else { await this.view.init({}) } + // The renderer only knows it's a PDF once frames exist (they carry + // pdf.js onZoom), i.e. after init has rendered the first spread. + // Read it now and apply the saved pointer mode — this also makes the + // Smart|Pan|Text control appear for PDFs. + this.isPDF = !!this.renderer?.isPDF; + if (this.isPDF) { + this.renderer.setAttribute("interaction-mode", this.interactionMode); + } this.initTime = Date.now(); this.fetchReadingSpeed(); this.refreshAnnotations();