+
+
+ {{ h.label }}
+
+
diff --git a/frontend/src/composables/useImageZoom.js b/frontend/src/composables/useImageZoom.js
index 3558159..e1d6f72 100644
--- a/frontend/src/composables/useImageZoom.js
+++ b/frontend/src/composables/useImageZoom.js
@@ -21,18 +21,25 @@ export function useImageZoom() {
// `* zoom` math applyZoom already uses for the
![]()
itself, no axis
// flip or separate coordinate system needed.
const highlight = ref(null) // {bbox} | null
+ // The layout mapper's own multi-box need (every mapped column region
+ // at once) - a parallel array alongside `highlight` above, which
+ // keeps its exact single-box shape for the review screen's own
+ // "Show on source" (R.2) call site.
+ const highlights = ref([]) // [{bbox, label?, color?}, ...]
const zoomLevelText = computed(() => Math.round(zoom.value * 100) + '%')
- const highlightStyle = computed(() => {
- if (!highlight.value) return null
- const { x0, x1, top, bottom } = highlight.value.bbox
+ /** Pixel position/size for a bbox at the current zoom - shared by the single highlight and the plural `highlights` below. */
+ function boxStyle(bbox) {
+ const { x0, x1, top, bottom } = bbox
return {
left: x0 * zoom.value + 'px',
top: top * zoom.value + 'px',
width: (x1 - x0) * zoom.value + 'px',
height: (bottom - top) * zoom.value + 'px',
}
- })
+ }
+ const highlightStyle = computed(() => (highlight.value ? boxStyle(highlight.value.bbox) : null))
+ const highlightsStyle = computed(() => highlights.value.map((h) => ({ ...h, style: boxStyle(h.bbox) })))
function applyZoom(z) {
zoom.value = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, z))
@@ -77,8 +84,17 @@ export function useImageZoom() {
highlight.value = null
}
+ /** Shows several labeled boxes at once (the layout mapper's own need) - independent of, and never clearing, the single `highlight` above. No auto-scroll, unlike showHighlight - several boxes can be spread across the whole image at once. */
+ function showHighlights(boxes) {
+ highlights.value = boxes || []
+ }
+ function clearHighlights() {
+ highlights.value = []
+ }
+
return {
- imgRef, wrapRef, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom,
- highlight, highlightStyle, showHighlight, clearHighlight,
+ imgRef, wrapRef, zoom, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom,
+ highlight, highlightStyle, highlights: highlightsStyle, showHighlight, clearHighlight,
+ showHighlights, clearHighlights,
}
}
diff --git a/frontend/src/composables/usePdfViewer.js b/frontend/src/composables/usePdfViewer.js
index 6f248f0..ed659ed 100644
--- a/frontend/src/composables/usePdfViewer.js
+++ b/frontend/src/composables/usePdfViewer.js
@@ -38,6 +38,12 @@ export function usePdfViewer() {
const zoom = ref(1)
const fitZoom = ref(1)
const highlight = ref(null) // {page, bbox} | null
+ // The layout mapper's own multi-box need (showing every mapped column
+ // region at once, or every proposed zone in the superuser review
+ // screen) - a parallel array alongside the single `highlight` above,
+ // which stays exactly as it was for the review screen's one-flag-at-
+ // a-time "Show on source" (R.2) - that call site needs zero changes.
+ const highlights = ref([]) // [{page, bbox, label?, color?}, ...]
const loading = ref(false)
const loadError = ref('')
@@ -168,21 +174,40 @@ export function usePdfViewer() {
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
+ /** Pixel position/size for a bbox at the current zoom - the shared math both the single highlight and the plural `highlights` below render with. */
+ function boxStyle(bbox) {
+ const { x0, x1, top, bottom } = bbox
return {
left: x0 * zoom.value + 'px',
top: top * zoom.value + 'px',
width: (x1 - x0) * zoom.value + 'px',
height: (bottom - top) * zoom.value + 'px',
}
- })
+ }
+
+ /** Pixel position/size for the active highlight's overlay box, at the current zoom. */
+ const highlightStyle = computed(() => (highlight.value ? boxStyle(highlight.value.bbox) : null))
+
+ /**
+ * Shows several labeled boxes at once (the layout mapper's own need -
+ * every mapped column region, or every proposed zone in the superuser
+ * review screen) - unrelated to, and never clearing, the single
+ * `highlight` above. Does NOT scroll anything into view itself (unlike
+ * showHighlight) - multiple boxes can span multiple pages at once, so
+ * there's no single "the" page to scroll to.
+ */
+ function showHighlights(boxes) {
+ highlights.value = boxes || []
+ }
+ function clearHighlights() {
+ highlights.value = []
+ }
+ /** Each highlight box's own pre-computed pixel style, for the template's v-for - {..box, style}. */
+ const highlightsStyle = computed(() => highlights.value.map((h) => ({ ...h, style: boxStyle(h.bbox) })))
return {
- containerRef, setCanvasRef, setPageWrapRef, numPages, zoomLevelText, loading, loadError,
- highlight, highlightStyle, loadDocument, renderAllPages, zoomIn, zoomOut, resetZoom,
- showHighlight, clearHighlight,
+ containerRef, setCanvasRef, setPageWrapRef, numPages, zoom, zoomLevelText, loading, loadError,
+ highlight, highlightStyle, highlights: highlightsStyle, loadDocument, renderAllPages, zoomIn, zoomOut, resetZoom,
+ showHighlight, clearHighlight, showHighlights, clearHighlights,
}
}
diff --git a/frontend/src/composables/useRegionDraw.js b/frontend/src/composables/useRegionDraw.js
new file mode 100644
index 0000000..f46e3c5
--- /dev/null
+++ b/frontend/src/composables/useRegionDraw.js
@@ -0,0 +1,79 @@
+/**
+ * Click-and-drag-to-define-a-region interaction - doesn't exist
+ * anywhere else in this app yet. Built for the layout mapper's manual
+ * mapping screen (L.6, not built yet): the user drags a box over the
+ * source document to claim a region for a column role. Owned by
+ * SourceDocumentPanel.vue (the one place that already renders both the
+ * pdf.js pages and the image panel), via its own `regionDrawMode` prop
+ * and `region-drawn` emit - see that component.
+ *
+ * `zoomRef` - a reactive ref to whichever viewer's own current zoom
+ * factor is active (pdf.js's or the image panel's - both already use
+ * the identical `value * zoom` pixel mapping for their highlight boxes,
+ * see usePdfViewer.js/useImageZoom.js's own boxStyle()) - needed to
+ * convert the drawn pixel rectangle back into PDF-point/image-pixel
+ * space, the same coordinate space source_bbox already uses everywhere
+ * else in this app.
+ *
+ * `onRegionDrawn(page, bbox)` - called once per completed drag with the
+ * final bbox in that coordinate space; `page` is whatever was passed to
+ * `handleMouseDown` (a 1-based page number for pdf.js, `null` for the
+ * single-image panel, which has no page concept at all).
+ */
+import { ref } from 'vue'
+
+// Ignores an accidental click with no real drag - avoids ever emitting
+// a zero-size (or near-zero) region nobody actually meant to draw.
+const MIN_DRAG_PX = 4
+
+export function useRegionDraw(zoomRef, onRegionDrawn) {
+ const draftRect = ref(null) // {left, top, width, height} in PIXELS, relative to whichever container drawing started in
+ const drawingPage = ref(null) // mirrors handleMouseDown's own `page` arg for the duration of one drag - lets the template show the draft box on the right page only
+
+ let origin = null // {x, y} viewport coords of that container's own top-left at drag start
+ let startX = 0
+ let startY = 0
+
+ function handleMouseMove(event) {
+ if (!origin) return
+ const x = event.clientX - origin.x
+ const y = event.clientY - origin.y
+ draftRect.value = {
+ left: Math.min(startX, x), top: Math.min(startY, y),
+ width: Math.abs(x - startX), height: Math.abs(y - startY),
+ }
+ }
+
+ function handleMouseUp() {
+ window.removeEventListener('mousemove', handleMouseMove)
+ window.removeEventListener('mouseup', handleMouseUp)
+ const rect = draftRect.value
+ const page = drawingPage.value
+ draftRect.value = null
+ drawingPage.value = null
+ origin = null
+ if (!rect || rect.width < MIN_DRAG_PX || rect.height < MIN_DRAG_PX) return
+
+ const zoom = zoomRef.value || 1
+ onRegionDrawn(page, {
+ x0: rect.left / zoom, x1: (rect.left + rect.width) / zoom,
+ top: rect.top / zoom, bottom: (rect.top + rect.height) / zoom,
+ })
+ }
+
+ /** Starts a drag on whichever element this is bound to (its own bounding box is the drawn rectangle's coordinate origin) - `page` is a 1-based page number (pdf.js) or null (the single-image panel). */
+ function handleMouseDown(event, page = null) {
+ if (event.button !== 0) return // left click only
+ const rect = event.currentTarget.getBoundingClientRect()
+ origin = { x: rect.left, y: rect.top }
+ drawingPage.value = page
+ startX = event.clientX - origin.x
+ startY = event.clientY - origin.y
+ draftRect.value = { left: startX, top: startY, width: 0, height: 0 }
+ window.addEventListener('mousemove', handleMouseMove)
+ window.addEventListener('mouseup', handleMouseUp)
+ event.preventDefault()
+ }
+
+ return { draftRect, drawingPage, handleMouseDown }
+}