Replace the native PDF iframe with a pdf.js viewer for row highlighting
R.1 (frontend half) of the staged review-screen plan. An <iframe> has no overlay hook, so drawing a highlight box on a flagged row's own printed position (source_page/source_bbox, shipped in the previous commit) needed real rendering control. New usePdfViewer.js (installs pdfjs-dist) renders each page to its own canvas, stacked in one scrollable column - the closest behavioral match to the iframe's own scrollable multi-page view. The browser's native PDF toolbar goes away as a direct consequence; zoom is rebuilt to match useImageZoom.js's own -/+/Fit pattern. The coordinate mapping (bbox value * zoom, no axis flip) is the exact one already verified correct against real rendered fixtures in the backend half of this work, reused here rather than re-derived. useImageZoom.js gained the same highlight/highlightStyle/showHighlight/ clearHighlight shape for an image upload, reusing its own existing zoom math. SourceDocumentPanel.vue exposes one unified showHighlight(page, bbox)/clearHighlight() routing to whichever viewer is active - not called from anywhere yet, since R.2 (the flagged-row UI that would trigger it) isn't built. R.1 only builds the capability. Verified: npm run build passes, the pdf.js worker bundles and serves correctly (curl'd directly, 200). The app container rebuilt and the served bundle confirmed to contain the new class/function names. measure.py unaffected (no backend touched this half). Not machine-verified, more consequential than usual to leave that way: canvas rendering, worker loading, zoom, and scroll all depend on real browser behavior a bundle check can't confirm - Claude-in-Chrome did not connect this session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
f65dd3fde0
commit
cac895a11f
90
CLAUDE.md
90
CLAUDE.md
|
|
@ -398,10 +398,18 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
(per-file, untouched by the batch work - the batch
|
||||
composable just prefixes its text with "Extracting N/M:
|
||||
filename —"), useRowEditing (saveEdit() now calls
|
||||
`documentsService.updateDocument`, best-effort), useImageZoom,
|
||||
useAutoGrow, useModalFocus (NEW 2026-10-13 — shared by every
|
||||
modal component below: focuses the overlay the instant it
|
||||
becomes visible, so Esc closes it immediately)
|
||||
`documentsService.updateDocument`, best-effort), useImageZoom
|
||||
(gained `highlight`/`highlightStyle`/`showHighlight`/
|
||||
`clearHighlight` 2026-10-13, for the review screen's
|
||||
row-highlighting on an image upload — reuses its own
|
||||
existing zoom math),
|
||||
useAutoGrow, useModalFocus (shared by every modal
|
||||
component below: focuses the overlay the instant it
|
||||
becomes visible, so Esc closes it immediately), usePdfViewer
|
||||
(NEW 2026-10-13 — pdf.js document loading, per-page canvas
|
||||
rendering, zoom, "scroll to page N and highlight bbox";
|
||||
parallels useImageZoom's own shape — see "Review screen"
|
||||
under Key decisions & lessons for the full record)
|
||||
/components — AppHeader (sticky top bar — brand mark, active-project
|
||||
breadcrumb, account menu with email + sign out; added
|
||||
2026-10-13, see "Enterprise app-shell redesign" under Key
|
||||
|
|
@ -427,7 +435,11 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
ConfirmModal for delete), DownloadChoiceModal (NEW
|
||||
2026-10-13 — "current document" vs. "all N documents",
|
||||
replacing a separate always-visible Download All button),
|
||||
ProcessingIndicator, SourceDocumentPanel, TransactionsTable
|
||||
ProcessingIndicator, SourceDocumentPanel (PDF path renders
|
||||
via pdf.js/usePdfViewer as of 2026-10-13, not the browser's
|
||||
native `<iframe>` — see "Review screen" under Key decisions
|
||||
& lessons; exposes `showHighlight`/`clearHighlight` for the
|
||||
review screen, not called from anywhere yet), TransactionsTable
|
||||
(now also hosts its own top bar — a Results dropdown,
|
||||
DocumentNavBar, and the Download button; this is
|
||||
ResultCard.vue's old content, merged in and that file
|
||||
|
|
@ -1354,9 +1366,53 @@ bbox exists" but "it's the right one." This is the real reason the fixture-rende
|
|||
discipline this project already uses for ground truth exists - a wrong but non-null
|
||||
bbox would have passed every other check here.
|
||||
|
||||
**Not yet built:** the frontend pdf.js-based viewer (R.1's other half) that will
|
||||
actually consume these fields to draw the highlight - this backend data has no
|
||||
consumer yet.
|
||||
**R.1 frontend half - shipped same day.** `SourceDocumentPanel.vue`'s PDF path no
|
||||
longer uses the browser's native `<iframe>` viewer - installed `pdfjs-dist` (a real npm
|
||||
dependency, same offline-build reasoning as `@fortawesome/fontawesome-free`) and built
|
||||
`usePdfViewer.js` (parallels `useImageZoom.js`'s own shape: `zoomIn`/`zoomOut`/
|
||||
`resetZoom`, fit-to-width on load). Every page renders to its own `<canvas>`, stacked
|
||||
in one scrollable column (`.pdf-pages-wrap`) - the closest behavioral match to the old
|
||||
iframe's own scrollable multi-page view, since an iframe has no hook to draw a box on a
|
||||
specific row, which is the entire reason for this change. The browser's native PDF
|
||||
toolbar (its own zoom/page-search chrome) is gone as a direct, accepted consequence -
|
||||
zoom is rebuilt here, matching the image panel's own −/+/Fit pattern exactly.
|
||||
|
||||
**Coordinate mapping confirmed correct empirically, not assumed:** `source_bbox`'s
|
||||
`x0`/`top`/`x1`/`bottom` are already in PDF points with a top-down origin (pdfplumber's
|
||||
own convention, confirmed during R.1's backend verification), the same orientation a
|
||||
canvas's own pixel space uses - so the overlay box position is just `value * zoom`
|
||||
(`zoom` here means direct points-to-pixels scale, not a 0-1 "percentage" - 1.0 = one
|
||||
point per pixel), no axis flip needed. This is the exact mapping already proven correct
|
||||
by R.1's own backend verification (rendering fixtures at a known DPI and drawing boxes
|
||||
at `value * (DPI/72)` landed on the right row every time) - reused here, not
|
||||
re-derived.
|
||||
|
||||
`useImageZoom.js` got the same `highlight`/`highlightStyle`/`showHighlight`/
|
||||
`clearHighlight` shape added (the image case is simpler - `source_bbox` is already in
|
||||
that image's own natural-pixel space, so the overlay reuses `applyZoom()`'s exact
|
||||
existing math). `SourceDocumentPanel.vue` exposes one unified `showHighlight(page,
|
||||
bbox)`/`clearHighlight()` via `defineExpose`, routing to whichever viewer (pdf.js pages
|
||||
or the image panel) is actually active for the current document - **not called from
|
||||
anywhere yet**, since R.2 (the flagged-row UI that would actually trigger a highlight)
|
||||
hasn't been built. R.1 only builds the capability, per the plan.
|
||||
|
||||
**One accepted tradeoff, worth knowing if bundle size ever becomes a real problem:**
|
||||
pdf.js's own worker file is ~2.2MB, pushing the main JS bundle past Vite's default
|
||||
500KB chunk-size warning threshold. Not code-split or lazy-loaded for this stage - this
|
||||
is an internal bookkeeping tool over a LAN-fast connection, not a public marketing
|
||||
page, so initial-load weight wasn't treated as a priority worth the added complexity of
|
||||
dynamic `import()` here; revisit if that assumption ever stops holding.
|
||||
|
||||
Verified: `npm run build` passes (the pdf.js worker bundles correctly, confirmed
|
||||
servable at its own URL - `curl`'d directly, 200 `application/javascript`); the `app`
|
||||
container rebuilt; the built JS bundle confirmed to contain the new class/function
|
||||
names (`pdf-pages-wrap`, `source-highlight-box`, `showHighlight`, `getDocument`).
|
||||
`measure.py` re-run, unaffected (no backend touched this half). **Not machine-verified
|
||||
- and more consequential than most prior UI changes this session to leave unverified:**
|
||||
canvas rendering, worker loading, zoom, and scroll behavior all depend on real browser
|
||||
behavior in a way a curl-based bundle check cannot confirm - Claude-in-Chrome still did
|
||||
not connect. This is the one piece of R.1 that most needs the user's own look before
|
||||
R.2 builds on top of it.
|
||||
|
||||
**Governing rule: never silently correct or exclude data.** This shows up in several
|
||||
concrete places, not just as an abstract principle:
|
||||
|
|
@ -1559,14 +1615,16 @@ Key current UI behaviors, each the result of an explicit, specific user request
|
|||
"simplify" these away without asking first) — implementation pointers reflect the Vue
|
||||
restructure; the behavior itself predates it and is unchanged:
|
||||
- The upload zone accepts `.pdf`, `.jpg`/`.jpeg`, and `.png` (added 2026-10-11 for OCR
|
||||
support — see "OCR / scanned statements" above). A PDF gets the browser's native viewer
|
||||
(its own zoom toolbar) in an iframe; an image gets its own dedicated zoomable/scrollable
|
||||
panel instead (added 2026-10-11, after the OCR support landed — an image in the same
|
||||
iframe has no viewer chrome at all, confirmed by testing it) — see
|
||||
`SourceDocumentPanel.vue`/`useImageZoom.js`: −/+/Fit controls, width-based zoom (not CSS
|
||||
`transform:scale`, so the panel's `overflow:auto` actually produces real scrollbars when
|
||||
zoomed in), opens at fit-width by default (the same first impression the PDF viewer's own
|
||||
`view=FitH` gives).
|
||||
support — see "OCR / scanned statements" above). A PDF renders via pdf.js as of
|
||||
2026-10-13 (`usePdfViewer.js` — one `<canvas>` per page, stacked in a scrollable
|
||||
column; the browser's own native viewer/toolbar is no longer used, since the review
|
||||
screen needs to draw a highlight box on a specific row, which an `<iframe>` has no
|
||||
hook for — see "Review screen" under Key decisions & lessons); an image gets its own
|
||||
dedicated zoomable/scrollable panel (`useImageZoom.js`) — both expose the same
|
||||
−/+/Fit controls, both open at fit-width by default, and both now support drawing a
|
||||
highlight box at a given `source_bbox` (`showHighlight`/`clearHighlight`, exposed by
|
||||
`SourceDocumentPanel.vue` — not called from anywhere yet, that's the review screen's
|
||||
still-unbuilt R.2).
|
||||
- Multiple files can be picked/dropped at once (`FileUploadZone.vue`'s file input now has
|
||||
`multiple`, added 2026-10-13), extracted SEQUENTIALLY (`useBatchExtraction.js`, one
|
||||
`/api/process` call at a time) with "Extracting N/M: filename — <phase text>" progress.
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^7.3.1",
|
||||
"pdfjs-dist": "^6.4.299",
|
||||
"pinia": "^4.0.3",
|
||||
"pocketbase": "^0.28.1",
|
||||
"vue": "^3.5.42",
|
||||
|
|
@ -119,6 +120,271 @@
|
|||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-1.0.11.tgz",
|
||||
"integrity": "sha512-vt5tog1cr+QKadIddGe+3LrcX0EmjEd0izF717Uwf92mBmgYfq2XRmL2r4bZU40spB69exxhrBn9I91HYEr/7w==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"workspaces": [
|
||||
"e2e/*"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@napi-rs/canvas-android-arm64": "1.0.11",
|
||||
"@napi-rs/canvas-darwin-arm64": "1.0.11",
|
||||
"@napi-rs/canvas-darwin-x64": "1.0.11",
|
||||
"@napi-rs/canvas-linux-arm-gnueabihf": "1.0.11",
|
||||
"@napi-rs/canvas-linux-arm64-gnu": "1.0.11",
|
||||
"@napi-rs/canvas-linux-arm64-musl": "1.0.11",
|
||||
"@napi-rs/canvas-linux-riscv64-gnu": "1.0.11",
|
||||
"@napi-rs/canvas-linux-x64-gnu": "1.0.11",
|
||||
"@napi-rs/canvas-linux-x64-musl": "1.0.11",
|
||||
"@napi-rs/canvas-win32-arm64-msvc": "1.0.11",
|
||||
"@napi-rs/canvas-win32-x64-msvc": "1.0.11"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-android-arm64": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-1.0.11.tgz",
|
||||
"integrity": "sha512-dtJS4FQEfH9OwSYLtMrEnj7T8DzBbJc/97LI/OkiWOYpW/iW5t6R/gcxVrUXS8l45gCVpwMufgucRe/pe0ISqA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-darwin-arm64": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-1.0.11.tgz",
|
||||
"integrity": "sha512-J/JylWoJTG8OQqZaiqly4IODyAxNofUlZo0wtSBJtHk6AdymbdIkPynAM1JvQaZpPaG5h+msk9QuK8y4i1ooqw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-darwin-x64": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-1.0.11.tgz",
|
||||
"integrity": "sha512-nlecCk3xy06eAGC7krZtzNDm9UNTHKuHQYK8ZYegdjzgSL8anGt/eLJZm86OWaNgZkwQwvDqfSmG8Nqe6MPZNQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-arm-gnueabihf": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-1.0.11.tgz",
|
||||
"integrity": "sha512-DKImmG+sTPolE0kGPsYPBxTtOjb3INALp32O2lW2CfSr0bAzSEKKuu+GrQbtilClyoPOahUErS3OrznFDraoWA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-arm64-gnu": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-1.0.11.tgz",
|
||||
"integrity": "sha512-55sykACGENj5j1rhj+81AO8JbR9HYgGjRZ7/H+pNr4VE1DvINKYNMTcutk8ZmWxk276jAQvUKJ3+Kdj9GXU3lQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-arm64-musl": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-1.0.11.tgz",
|
||||
"integrity": "sha512-6Jz6jys17yXydO+WdJgu7JhoB4K7/w9sWHByzzTmLjQghUx3TDMWvLv+UcCdnWhg4oprET67EMymnrETdeGNAg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-riscv64-gnu": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-1.0.11.tgz",
|
||||
"integrity": "sha512-lf2XeEebWiUYVOVEjLXxF7dfXrBBSEOBn9AqBh39VYXrPt5cDqI+1t58IFSjn8npqkg5jIOs8TQbjKABbFW1gQ==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-x64-gnu": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-1.0.11.tgz",
|
||||
"integrity": "sha512-iDapw7nFSE5tsmQxcH2+KotJhyfVPmHd6vUOQN/Em+8WNbkZJwJ/rDowlJMFnMl0SYSDSfgKCNUGi6Sn5++Smg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-linux-x64-musl": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-1.0.11.tgz",
|
||||
"integrity": "sha512-26q26AyITo3CGZX4HWFIMgBMA1lu3YN07gxzBm4tW6Hglq/OVyTP50kDrmWuKybCX6dh3m8Ly+c7YhI+sqCgCQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-win32-arm64-msvc": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-arm64-msvc/-/canvas-win32-arm64-msvc-1.0.11.tgz",
|
||||
"integrity": "sha512-cUO96IdsfvIj2S+2PNcDSkTcLhjPj8pIOEWRV1Kj70MOP4wnE9zSk7N4C1EKHlFGRcgdR5AkbnBZj0dfHK9nbQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/canvas-win32-x64-msvc": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-1.0.11.tgz",
|
||||
"integrity": "sha512-DFYp/ZQRdKunI/LPc0UkRXG1vlNjJKOJf8O8Ctb8+wm2Nt2ELg9Eamc31D2VoakkfGo8L+z0Iejz6WtFbQwyGw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
}
|
||||
},
|
||||
"node_modules/@oxc-project/types": {
|
||||
"version": "0.153.0",
|
||||
"resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.153.0.tgz",
|
||||
|
|
@ -1161,6 +1427,18 @@
|
|||
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pdfjs-dist": {
|
||||
"version": "6.4.299",
|
||||
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-6.4.299.tgz",
|
||||
"integrity": "sha512-AVl138zALtfaAPvADulE0PZThbYzCBS79nL4pOSL/6Sm/4AH5A21BD9VHt97OlCuzJuCpmeZtAtkinisF4Vb1g==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=22.13.0 || >=24"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@napi-rs/canvas": "^1.0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/perfect-debounce": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/perfect-debounce/-/perfect-debounce-2.1.0.tgz",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^7.3.1",
|
||||
"pdfjs-dist": "^6.4.299",
|
||||
"pinia": "^4.0.3",
|
||||
"pocketbase": "^0.28.1",
|
||||
"vue": "^3.5.42",
|
||||
|
|
|
|||
|
|
@ -350,9 +350,31 @@ tr.editing td{ background:rgba(37,99,235,.03); }
|
|||
display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; flex-shrink:0;
|
||||
}
|
||||
.pdf-col-head h2{ margin-bottom:0; }
|
||||
.pdf-col iframe{
|
||||
/* Replaces the old native <iframe> viewer - pdf.js renders each page to
|
||||
its own <canvas>, stacked in this one scrollable column (closest
|
||||
behavioral match to the iframe's own scrollable multi-page view). An
|
||||
iframe has no hook to draw a highlight box on a specific row, which is
|
||||
the whole reason for this change - see usePdfViewer.js. */
|
||||
.pdf-pages-wrap{
|
||||
width:100%; flex:1 1 auto; min-height:0; border:1px solid var(--border-2); border-radius:10px;
|
||||
background:var(--navy-3); display:block;
|
||||
background:var(--navy-3); overflow:auto; padding:16px 0;
|
||||
}
|
||||
.pdf-page-wrap{ position:relative; width:fit-content; margin:0 auto 16px; }
|
||||
.pdf-page-wrap:last-child{ margin-bottom:0; }
|
||||
.pdf-page-wrap canvas{
|
||||
display:block; background:var(--navy-2); box-shadow:0 2px 10px rgba(16,24,40,.12);
|
||||
}
|
||||
.pdf-pages-loading{
|
||||
display:flex; align-items:center; justify-content:center; gap:8px;
|
||||
color:var(--t4); font-size:13px; padding:20px;
|
||||
}
|
||||
/* The review screen's row-highlighting (R.2, not wired up yet - R.1 only
|
||||
builds the capability) - an absolutely-positioned box over the exact
|
||||
printed row a flagged transaction came from, same box shape used over
|
||||
both a pdf.js page and the image panel's own <img>. */
|
||||
.source-highlight-box{
|
||||
position:absolute; border:2px solid var(--amber); background:rgba(217,119,6,.12);
|
||||
border-radius:3px; pointer-events:none; transition:all .2s;
|
||||
}
|
||||
/* Images get their own zoomable/scrollable panel instead of the PDF
|
||||
iframe - a browser-native PDF viewer has its own zoom controls built
|
||||
|
|
@ -371,8 +393,8 @@ tr.editing td{ background:rgba(37,99,235,.03); }
|
|||
.img-zoom-controls button:hover{ background:rgba(37,99,235,.08); border-color:var(--blue); color:var(--blue); }
|
||||
.img-zoom-controls span{ font-size:11.5px; color:var(--t3); min-width:38px; text-align:center; font-family:var(--fm); }
|
||||
.img-preview-wrap{
|
||||
width:100%; flex:1 1 auto; min-height:0; border:1px solid var(--border-2); border-radius:10px;
|
||||
background:var(--navy-3); overflow:auto; display:block;
|
||||
position:relative; width:100%; flex:1 1 auto; min-height:0; border:1px solid var(--border-2);
|
||||
border-radius:10px; background:var(--navy-3); overflow:auto; display:block;
|
||||
}
|
||||
.img-preview-wrap img{ display:block; }
|
||||
/* Both panels are visible from the start (before any file is chosen),
|
||||
|
|
|
|||
|
|
@ -2,38 +2,77 @@
|
|||
/**
|
||||
* SourceDocumentPanel.vue
|
||||
*
|
||||
* The Source Document card: a PDF gets the browser's native viewer (with
|
||||
* its own zoom toolbar) in an iframe; an image has no such chrome, so it
|
||||
* gets its own zoomable/scrollable panel instead - see useImageZoom.js.
|
||||
* The Source Document card: a PDF renders via pdf.js (usePdfViewer.js),
|
||||
* one <canvas> per page stacked in a scrollable column - NOT the
|
||||
* browser's native <iframe> viewer anymore, which has no hook for
|
||||
* drawing a highlight box on a specific row. An image gets its own
|
||||
* zoomable/scrollable panel (useImageZoom.js), extended the same way.
|
||||
* Before any file is chosen, shows an empty-state message instead - this
|
||||
* panel is always visible (not gated on an extraction result existing),
|
||||
* so the opening/closing balance fields in TransactionsTable are
|
||||
* reachable before clicking Extract.
|
||||
*
|
||||
* Exposes showHighlight(page, bbox)/clearHighlight() for the review
|
||||
* screen (R.2) to box a flagged transaction's own printed row - routes
|
||||
* to whichever viewer (pdf.js pages or the image panel) is actually
|
||||
* active; not called from anywhere yet (R.1 only builds the capability).
|
||||
*
|
||||
* Data flow:
|
||||
* previewUrl (string|null) - blob URL for the chosen file
|
||||
* isImage (boolean) - whether to render the image panel instead of the iframe
|
||||
* isImage (boolean) - whether to render the image panel instead of the PDF viewer
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import { computed, watch } from 'vue'
|
||||
import { useImageZoom } from '../composables/useImageZoom'
|
||||
import { usePdfViewer } from '../composables/usePdfViewer'
|
||||
|
||||
const props = defineProps({
|
||||
previewUrl: { type: String, default: null },
|
||||
isImage: { type: Boolean, default: false },
|
||||
})
|
||||
|
||||
const { imgRef, wrapRef, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom } = useImageZoom()
|
||||
const {
|
||||
imgRef, wrapRef, zoomLevelText: imgZoomText, onImageLoad,
|
||||
zoomIn: imgZoomIn, zoomOut: imgZoomOut, resetZoom: imgResetZoom,
|
||||
highlight: imgHighlight, highlightStyle: imgHighlightStyle,
|
||||
showHighlight: showImgHighlight, clearHighlight: clearImgHighlight,
|
||||
} = useImageZoom()
|
||||
|
||||
// #toolbar=1 forces the browser's native PDF viewer toolbar (page nav +
|
||||
// zoom controls) on; navpanes=0 skips the thumbnails/bookmarks sidebar
|
||||
// so the toolbar isn't competing for space in a narrow column.
|
||||
const pdfSrc = computed(() => (props.previewUrl ? props.previewUrl + '#toolbar=1&navpanes=0&view=FitH' : ''))
|
||||
const {
|
||||
containerRef, setCanvasRef, setPageWrapRef, numPages, zoomLevelText: pdfZoomText,
|
||||
loading: pdfLoading, loadError: pdfLoadError,
|
||||
highlight: pdfHighlight, highlightStyle: pdfHighlightStyle,
|
||||
loadDocument, zoomIn: pdfZoomIn, zoomOut: pdfZoomOut, resetZoom: pdfResetZoom,
|
||||
showHighlight: showPdfHighlight, clearHighlight: clearPdfHighlight,
|
||||
} = usePdfViewer()
|
||||
|
||||
const zoomLevelText = computed(() => (props.isImage ? imgZoomText.value : pdfZoomText.value))
|
||||
function zoomIn() { props.isImage ? imgZoomIn() : pdfZoomIn() }
|
||||
function zoomOut() { props.isImage ? imgZoomOut() : pdfZoomOut() }
|
||||
function resetZoom() { props.isImage ? imgResetZoom() : pdfResetZoom() }
|
||||
|
||||
watch(
|
||||
() => [props.previewUrl, props.isImage],
|
||||
([url, isImage]) => {
|
||||
if (!isImage) loadDocument(url)
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function showHighlight(page, bbox) {
|
||||
if (props.isImage) showImgHighlight(bbox)
|
||||
else showPdfHighlight(page, bbox)
|
||||
}
|
||||
function clearHighlight() {
|
||||
clearImgHighlight()
|
||||
clearPdfHighlight()
|
||||
}
|
||||
defineExpose({ showHighlight, clearHighlight })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pdf-col-head">
|
||||
<h2>Source Document</h2>
|
||||
<div v-if="isImage" class="img-zoom-controls">
|
||||
<div v-if="previewUrl" class="img-zoom-controls">
|
||||
<button type="button" title="Zoom out" @click="zoomOut"><i class="fa-solid fa-magnifying-glass-minus"></i></button>
|
||||
<span>{{ zoomLevelText }}</span>
|
||||
<button type="button" title="Zoom in" @click="zoomIn"><i class="fa-solid fa-magnifying-glass-plus"></i></button>
|
||||
|
|
@ -43,8 +82,18 @@ const pdfSrc = computed(() => (props.previewUrl ? props.previewUrl + '#toolbar=1
|
|||
<div v-if="!previewUrl" class="empty-panel empty-panel-source">
|
||||
<p>No Source Document to Display.<br>Upload one to get started.</p>
|
||||
</div>
|
||||
<iframe v-else-if="!isImage" :src="pdfSrc" title="Statement PDF preview"></iframe>
|
||||
<div v-else-if="!isImage" ref="containerRef" class="pdf-pages-wrap">
|
||||
<div v-if="pdfLoadError" class="empty-panel empty-panel-source">
|
||||
<p>{{ pdfLoadError }}</p>
|
||||
</div>
|
||||
<div v-for="i in numPages" :key="i" :ref="(el) => setPageWrapRef(i - 1, el)" class="pdf-page-wrap">
|
||||
<canvas :ref="(el) => setCanvasRef(i - 1, el)"></canvas>
|
||||
<div v-if="pdfHighlight?.page === i" class="source-highlight-box" :style="pdfHighlightStyle"></div>
|
||||
</div>
|
||||
<div v-if="pdfLoading" class="pdf-pages-loading"><i class="fa-solid fa-spinner fa-spin"></i> Loading PDF…</div>
|
||||
</div>
|
||||
<div v-else ref="wrapRef" class="img-preview-wrap">
|
||||
<img ref="imgRef" :src="previewUrl" alt="Statement image preview" @load="onImageLoad">
|
||||
<div v-if="imgHighlight" class="source-highlight-box" :style="imgHighlightStyle"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -14,8 +14,25 @@ export function useImageZoom() {
|
|||
const wrapRef = ref(null)
|
||||
const zoom = ref(1)
|
||||
const fitZoom = ref(1)
|
||||
// The review screen's row-highlighting for an image upload (a raw
|
||||
// JPG/PNG, not a PDF) - source_bbox is already in this image's own
|
||||
// natural-pixel space (see table_extract.py's _line_bbox /
|
||||
// raw_ocr_extract.py), so the overlay position is just the same
|
||||
// `* zoom` math applyZoom already uses for the <img> itself, no axis
|
||||
// flip or separate coordinate system needed.
|
||||
const highlight = ref(null) // {bbox} | null
|
||||
|
||||
const zoomLevelText = computed(() => Math.round(zoom.value * 100) + '%')
|
||||
const highlightStyle = computed(() => {
|
||||
if (!highlight.value) return null
|
||||
const { x0, x1, top, bottom } = highlight.value.bbox
|
||||
return {
|
||||
left: x0 * zoom.value + 'px',
|
||||
top: top * zoom.value + 'px',
|
||||
width: (x1 - x0) * zoom.value + 'px',
|
||||
height: (bottom - top) * zoom.value + 'px',
|
||||
}
|
||||
})
|
||||
|
||||
function applyZoom(z) {
|
||||
zoom.value = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, z))
|
||||
|
|
@ -47,5 +64,21 @@ export function useImageZoom() {
|
|||
applyZoom(fitZoom.value)
|
||||
}
|
||||
|
||||
return { imgRef, wrapRef, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom }
|
||||
function showHighlight(bbox) {
|
||||
if (!bbox) return
|
||||
highlight.value = { bbox }
|
||||
wrapRef.value?.scrollTo({
|
||||
left: Math.max(0, bbox.x0 * zoom.value - wrapRef.value.clientWidth / 2),
|
||||
top: Math.max(0, bbox.top * zoom.value - wrapRef.value.clientHeight / 2),
|
||||
behavior: 'smooth',
|
||||
})
|
||||
}
|
||||
function clearHighlight() {
|
||||
highlight.value = null
|
||||
}
|
||||
|
||||
return {
|
||||
imgRef, wrapRef, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom,
|
||||
highlight, highlightStyle, showHighlight, clearHighlight,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
* pdf.js-based PDF rendering, replacing the browser's native <iframe>
|
||||
* viewer - needed because an iframe has no overlay hook, and the review
|
||||
* screen needs to draw a highlight box on a specific flagged row (see
|
||||
* backend/services/extraction/table_extract.py's source_page/source_bbox,
|
||||
* CLAUDE.md's "Review screen" entry for the full record).
|
||||
*
|
||||
* Every page renders to its own <canvas>, stacked vertically inside one
|
||||
* scrollable container - the closest behavioral match to the native
|
||||
* viewer's own scrollable multi-page view. The browser's native PDF
|
||||
* toolbar (its own zoom/page-search chrome) is gone as a direct,
|
||||
* accepted consequence of taking over rendering - zoom is rebuilt here,
|
||||
* matching useImageZoom.js's own −/+/Fit pattern for consistency.
|
||||
*
|
||||
* Coordinate system: BASE_SCALE=1 means 1 PDF point = 1 canvas pixel at
|
||||
* zoom 1 - the exact mapping verified for real against rendered fixture
|
||||
* pages during R.1's backend work (scale = render-DPI / 72, the same
|
||||
* points-to-pixels relationship). source_bbox's own x0/top/x1/bottom are
|
||||
* already in PDF points with a top-down origin (pdfplumber's own
|
||||
* convention), matching a canvas's own pixel space - so overlay position
|
||||
* is just `value * zoom`, no axis flip needed.
|
||||
*/
|
||||
import { ref, computed, shallowRef } from 'vue'
|
||||
import * as pdfjsLib from 'pdfjs-dist'
|
||||
import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url'
|
||||
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorkerUrl
|
||||
|
||||
const ZOOM_STEP = 0.1
|
||||
const ZOOM_MIN = 0.3
|
||||
const ZOOM_MAX = 3
|
||||
|
||||
export function usePdfViewer() {
|
||||
const containerRef = ref(null)
|
||||
const canvasRefs = ref([])
|
||||
const pageWrapRefs = ref([])
|
||||
const numPages = ref(0)
|
||||
const zoom = ref(1)
|
||||
const fitZoom = ref(1)
|
||||
const highlight = ref(null) // {page, bbox} | null
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
const zoomLevelText = computed(() => Math.round(zoom.value * 100) + '%')
|
||||
|
||||
// shallowRef: pdf.js's own document/page proxies aren't plain data and
|
||||
// don't need Vue's deep reactivity - they're only ever read inside
|
||||
// this composable's own functions, never rendered directly in a template.
|
||||
const pdfDoc = shallowRef(null)
|
||||
let pageViewports = [] // each page's own {width, height} at scale=1 (PDF points)
|
||||
|
||||
function setCanvasRef(i, el) {
|
||||
canvasRefs.value[i] = el
|
||||
}
|
||||
function setPageWrapRef(i, el) {
|
||||
pageWrapRefs.value[i] = el
|
||||
}
|
||||
|
||||
async function renderPage(i) {
|
||||
const canvas = canvasRefs.value[i]
|
||||
if (!canvas || !pdfDoc.value) return
|
||||
const page = await pdfDoc.value.getPage(i + 1)
|
||||
const viewport = page.getViewport({ scale: zoom.value })
|
||||
canvas.width = viewport.width
|
||||
canvas.height = viewport.height
|
||||
const ctx = canvas.getContext('2d')
|
||||
await page.render({ canvas, canvasContext: ctx, viewport }).promise
|
||||
}
|
||||
|
||||
async function renderAllPages() {
|
||||
for (let i = 0; i < numPages.value; i++) {
|
||||
await renderPage(i)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a new PDF (a fresh document selection) - destroys whatever
|
||||
* document was previously loaded first, so pdf.js's own worker-side
|
||||
* resources don't leak as the user browses between documents.
|
||||
*/
|
||||
async function loadDocument(url) {
|
||||
highlight.value = null
|
||||
loadError.value = ''
|
||||
if (pdfDoc.value) {
|
||||
pdfDoc.value.destroy()
|
||||
pdfDoc.value = null
|
||||
}
|
||||
if (!url) {
|
||||
numPages.value = 0
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const doc = await pdfjsLib.getDocument(url).promise
|
||||
pdfDoc.value = doc
|
||||
numPages.value = doc.numPages
|
||||
canvasRefs.value = new Array(doc.numPages)
|
||||
pageWrapRefs.value = new Array(doc.numPages)
|
||||
pageViewports = []
|
||||
for (let i = 1; i <= doc.numPages; i++) {
|
||||
const page = await doc.getPage(i)
|
||||
pageViewports.push(page.getViewport({ scale: 1 }))
|
||||
}
|
||||
// Fit-to-width on load, the same first impression the image panel's
|
||||
// own onImageLoad gives - the widest page sets the scale so nothing
|
||||
// overflows the container horizontally.
|
||||
const wrap = containerRef.value
|
||||
const widest = Math.max(...pageViewports.map((v) => v.width))
|
||||
fitZoom.value = wrap && widest ? Math.min(1.5, wrap.clientWidth / widest) : 1
|
||||
zoom.value = fitZoom.value
|
||||
} catch (e) {
|
||||
loadError.value = e?.message || 'Could not load this PDF.'
|
||||
numPages.value = 0
|
||||
}
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function applyZoom(z) {
|
||||
zoom.value = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, z))
|
||||
await renderAllPages()
|
||||
}
|
||||
function zoomIn() {
|
||||
applyZoom(zoom.value + ZOOM_STEP)
|
||||
}
|
||||
function zoomOut() {
|
||||
applyZoom(zoom.value - ZOOM_STEP)
|
||||
}
|
||||
function resetZoom() {
|
||||
applyZoom(fitZoom.value)
|
||||
}
|
||||
|
||||
/** Scrolls the given 1-based page into view and shows the highlight box at bbox. */
|
||||
function showHighlight(page, bbox) {
|
||||
if (!page || !bbox) return
|
||||
highlight.value = { page, bbox }
|
||||
pageWrapRefs.value[page - 1]?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}
|
||||
function clearHighlight() {
|
||||
highlight.value = null
|
||||
}
|
||||
|
||||
/** Pixel position/size for the active highlight's overlay box, at the current zoom. */
|
||||
const highlightStyle = computed(() => {
|
||||
if (!highlight.value) return null
|
||||
const { x0, x1, top, bottom } = highlight.value.bbox
|
||||
return {
|
||||
left: x0 * zoom.value + 'px',
|
||||
top: top * zoom.value + 'px',
|
||||
width: (x1 - x0) * zoom.value + 'px',
|
||||
height: (bottom - top) * zoom.value + 'px',
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
containerRef, setCanvasRef, setPageWrapRef, numPages, zoomLevelText, loading, loadError,
|
||||
highlight, highlightStyle, loadDocument, renderAllPages, zoomIn, zoomOut, resetZoom,
|
||||
showHighlight, clearHighlight,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue