From cac895a11f1ba011b69ac57e039c7e649f0a2656 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 13 Oct 2026 11:26:48 -0400 Subject: [PATCH] Replace the native PDF iframe with a pdf.js viewer for row highlighting R.1 (frontend half) of the staged review-screen plan. An +
+
+

{{ pdfLoadError }}

+
+
+ +
+
+
Loading PDF…
+
Statement image preview +
diff --git a/frontend/src/composables/useImageZoom.js b/frontend/src/composables/useImageZoom.js index c2a2713..3558159 100644 --- a/frontend/src/composables/useImageZoom.js +++ b/frontend/src/composables/useImageZoom.js @@ -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 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, + } } diff --git a/frontend/src/composables/usePdfViewer.js b/frontend/src/composables/usePdfViewer.js new file mode 100644 index 0000000..bd01995 --- /dev/null +++ b/frontend/src/composables/usePdfViewer.js @@ -0,0 +1,159 @@ +/** + * pdf.js-based PDF rendering, replacing the browser's native