@gemina/elements 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,12 +2,184 @@ import {
2
2
  VERSION,
3
3
  httpStatus,
4
4
  readErrorEnvelope
5
- } from "./chunk-724KJLIY.js";
5
+ } from "./chunk-S4KBJRIP.js";
6
6
 
7
7
  // src/verification/index.tsx
8
- import { useCallback as useCallback2, useEffect as useEffect2, useId, useMemo, useRef as useRef2, useState as useState2 } from "react";
8
+ import { useCallback as useCallback3, useEffect as useEffect3, useId as useId2, useMemo, useRef as useRef3, useState as useState3 } from "react";
9
9
  import { GeminaClient } from "@gemina/sdk";
10
10
 
11
+ // src/verification/field-types.ts
12
+ var ISO_4217_CODES = [
13
+ "AED",
14
+ "ARS",
15
+ "AUD",
16
+ "BGN",
17
+ "BRL",
18
+ "CAD",
19
+ "CHF",
20
+ "CLP",
21
+ "CNY",
22
+ "COP",
23
+ "CZK",
24
+ "DKK",
25
+ "EGP",
26
+ "EUR",
27
+ "GBP",
28
+ "HKD",
29
+ "HRK",
30
+ "HUF",
31
+ "IDR",
32
+ "ILS",
33
+ "INR",
34
+ "ISK",
35
+ "JPY",
36
+ "KRW",
37
+ "MAD",
38
+ "MXN",
39
+ "MYR",
40
+ "NGN",
41
+ "NOK",
42
+ "NZD",
43
+ "PEN",
44
+ "PHP",
45
+ "PLN",
46
+ "RON",
47
+ "RSD",
48
+ "RUB",
49
+ "SAR",
50
+ "SEK",
51
+ "SGD",
52
+ "THB",
53
+ "TRY",
54
+ "TWD",
55
+ "UAH",
56
+ "USD",
57
+ "VND",
58
+ "ZAR"
59
+ ];
60
+ var ISO_4217_SHAPE = /^[A-Za-z]{3}$/;
61
+ var DATE_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
62
+ var NUMERIC_SHAPE = /^[+-]?[\d,_]*\.?\d+$/;
63
+ function toNumber(value) {
64
+ if (!NUMERIC_SHAPE.test(value)) {
65
+ return null;
66
+ }
67
+ const parsed = Number(value.replace(/[,_]/g, ""));
68
+ return Number.isFinite(parsed) ? parsed : null;
69
+ }
70
+ function validateInput(value, field) {
71
+ const trimmed = value.trim();
72
+ if (trimmed === "" || !field) {
73
+ return null;
74
+ }
75
+ if (field.enum && field.enum.length > 0) {
76
+ return field.enum.includes(trimmed) ? null : `Choose one of: ${field.enum.join(", ")}`;
77
+ }
78
+ if (field.format === "iso4217") {
79
+ return ISO_4217_SHAPE.test(trimmed) ? null : "Use a 3-letter ISO 4217 code, e.g. USD";
80
+ }
81
+ switch (field.type) {
82
+ case "number":
83
+ return toNumber(trimmed) === null ? "Enter a number" : null;
84
+ case "integer": {
85
+ const parsed = toNumber(trimmed);
86
+ if (parsed === null || !Number.isInteger(parsed)) {
87
+ return "Enter a whole number";
88
+ }
89
+ return null;
90
+ }
91
+ case "date": {
92
+ if (!DATE_SHAPE.test(trimmed)) {
93
+ return "Enter a date as YYYY-MM-DD";
94
+ }
95
+ const [year, month, day] = trimmed.split("-").map(Number);
96
+ const date = new Date(Date.UTC(year, month - 1, day));
97
+ const survives = date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
98
+ return survives ? null : "Enter a date as YYYY-MM-DD";
99
+ }
100
+ default:
101
+ return null;
102
+ }
103
+ }
104
+ function readRowMutableTables(raw) {
105
+ if (!Array.isArray(raw)) {
106
+ return [];
107
+ }
108
+ const out = [];
109
+ for (const item of raw) {
110
+ if (item === null || typeof item !== "object") {
111
+ continue;
112
+ }
113
+ const source = item;
114
+ if (typeof source.pointer !== "string" || typeof source.keyTemplate !== "string") {
115
+ continue;
116
+ }
117
+ out.push({
118
+ pointer: source.pointer,
119
+ keyTemplate: source.keyTemplate,
120
+ // Columns are descriptors keyed by `name` rather than `key`, so they get
121
+ // the same treatment with the name standing in as the identity.
122
+ columns: readDescriptors(
123
+ (Array.isArray(source.columns) ? source.columns : []).map((column) => {
124
+ const record = column ?? {};
125
+ return { ...record, key: record.name };
126
+ })
127
+ )
128
+ });
129
+ }
130
+ return out;
131
+ }
132
+ function cellSchemaKey(template, index, field) {
133
+ return template.replace(/\{index\}/g, String(index)).replace(/\{field\}/g, field);
134
+ }
135
+ function coerceInput(value, field) {
136
+ if (!field) {
137
+ return value;
138
+ }
139
+ switch (field.type) {
140
+ case "number":
141
+ case "integer": {
142
+ const parsed = toNumber(value);
143
+ return parsed === null ? value : parsed;
144
+ }
145
+ case "boolean": {
146
+ const lowered = value.trim().toLowerCase();
147
+ if (lowered === "true") return true;
148
+ if (lowered === "false") return false;
149
+ return value;
150
+ }
151
+ // `date` stays a string: the wire format IS the ISO string, and a Date
152
+ // object would serialise with a time component the extraction never had.
153
+ default:
154
+ return value;
155
+ }
156
+ }
157
+ function readDescriptors(raw) {
158
+ if (!Array.isArray(raw)) {
159
+ return [];
160
+ }
161
+ const out = [];
162
+ for (const item of raw) {
163
+ if (item === null || typeof item !== "object") {
164
+ continue;
165
+ }
166
+ const source = item;
167
+ if (typeof source.key !== "string") {
168
+ continue;
169
+ }
170
+ const roster = source._enum ?? source.enum;
171
+ out.push({
172
+ key: source.key,
173
+ label: typeof source.label === "string" ? source.label : void 0,
174
+ type: typeof source.type === "string" ? source.type : void 0,
175
+ enum: Array.isArray(roster) ? roster.map(String) : null,
176
+ format: typeof source.format === "string" ? source.format : null,
177
+ description: typeof source.description === "string" ? source.description : null
178
+ });
179
+ }
180
+ return out;
181
+ }
182
+
11
183
  // src/verification/classify.ts
12
184
  var ACRONYMS = /* @__PURE__ */ new Set(["ID", "VAT", "OCR", "PDF", "URL", "API", "HTML", "CSS", "JSON", "XML", "UUID"]);
13
185
  function formatLabel(key) {
@@ -329,6 +501,9 @@ function parseSchemaKey(raw) {
329
501
  return { raw, label: match[1], pointer: match[2] };
330
502
  }
331
503
  var NOT_FOUND = /* @__PURE__ */ Symbol("gemina-verification-not-found");
504
+ function snakeToCamel(segment) {
505
+ return segment.replace(/_([a-zA-Z0-9])/g, (_unused, ch) => ch.toUpperCase());
506
+ }
332
507
 
333
508
  // src/verification/bindings.ts
334
509
  function unescapeSegment(raw) {
@@ -337,9 +512,6 @@ function unescapeSegment(raw) {
337
512
  function escapeSegment2(segment) {
338
513
  return segment.replace(/~/g, "~0").replace(/\//g, "~1");
339
514
  }
340
- function snakeToCamel(segment) {
341
- return segment.replace(/_([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
342
- }
343
515
  function camelizePointer(pointer) {
344
516
  if (!pointer.startsWith("/")) {
345
517
  return pointer;
@@ -390,7 +562,13 @@ function resolveCasingAware(doc, pointer) {
390
562
  function stripValueSuffix(pointer) {
391
563
  return pointer.endsWith("/value") ? pointer.slice(0, -"/value".length) : pointer;
392
564
  }
393
- function buildBindings(validationSchema, values) {
565
+ function buildBindings(validationSchema, values, fields) {
566
+ const descriptors = /* @__PURE__ */ new Map();
567
+ for (const descriptor of fields ?? []) {
568
+ if (typeof descriptor?.key === "string") {
569
+ descriptors.set(descriptor.key, descriptor);
570
+ }
571
+ }
394
572
  const bindings = [];
395
573
  for (const raw of validationSchema) {
396
574
  const key = parseSchemaKey(raw);
@@ -405,7 +583,8 @@ function buildBindings(validationSchema, values) {
405
583
  serverValue,
406
584
  extracted,
407
585
  fieldPointer: stripValueSuffix(resolvedPointer),
408
- editable
586
+ editable,
587
+ field: descriptors.get(key.raw)
409
588
  });
410
589
  }
411
590
  return bindings;
@@ -426,39 +605,365 @@ function toInputString(extracted) {
426
605
  }
427
606
  return String(extracted);
428
607
  }
429
- function composeSubmission(bindings, edits) {
608
+ function composeSubmission(bindings, edits, options = {}) {
609
+ const cells = options.cells ?? bindings.map((binding) => ({
610
+ editKey: binding.key.raw,
611
+ submitKey: binding.key.raw,
612
+ column: binding.key.label,
613
+ rowKey: binding.key.raw,
614
+ binding,
615
+ added: false
616
+ }));
430
617
  const data = {};
431
618
  const byLabel = {};
432
619
  let confirmed = 0;
433
620
  let corrected = 0;
434
- for (const binding of bindings) {
435
- const edit = edits.get(binding.key.raw);
621
+ for (const cell of cells) {
622
+ const { binding } = cell;
623
+ const label = parseSchemaKey(cell.submitKey)?.label ?? binding.key.label;
624
+ const edit = edits.get(cell.editKey);
436
625
  if (edit !== void 0) {
437
626
  const trimmed = edit.trim();
438
627
  if (trimmed === "" && binding.serverValue === NOT_FOUND) {
439
628
  continue;
440
629
  }
441
- const value = trimmed === "" ? null : trimmed;
442
- data[binding.key.raw] = value;
443
- byLabel[binding.key.label] = value;
630
+ const value = trimmed === "" ? null : coerceInput(trimmed, binding.field);
631
+ data[cell.submitKey] = value;
632
+ byLabel[label] = value;
444
633
  corrected += 1;
445
634
  } else {
446
635
  if (binding.serverValue === NOT_FOUND) {
447
636
  continue;
448
637
  }
449
- data[binding.key.raw] = binding.serverValue;
450
- byLabel[binding.key.label] = binding.serverValue;
638
+ data[cell.submitKey] = binding.serverValue;
639
+ byLabel[label] = binding.serverValue;
451
640
  confirmed += 1;
452
641
  }
453
642
  }
454
- return { data, byLabel, confirmed, corrected };
643
+ return { data, byLabel, confirmed, corrected, rowSources: options.rowSources ?? [] };
644
+ }
645
+ function countRowsAt(values, pointer) {
646
+ const { node } = resolveCasingAware(values, pointer);
647
+ return Array.isArray(node) ? node.length : 0;
648
+ }
649
+
650
+ // src/verification/row-plan.ts
651
+ var addedRowCounter = 0;
652
+ function initialRowPlan(extractedCount, scope = "") {
653
+ return Array.from({ length: Math.max(0, extractedCount) }, (_unused, index) => ({
654
+ // Derived from the source index, so it is stable across re-renders without
655
+ // any state to carry — an extracted row's identity never changes.
656
+ id: `${scope}#row-${index}`,
657
+ source: index
658
+ }));
659
+ }
660
+ function nextAddedRowId(scope = "") {
661
+ addedRowCounter += 1;
662
+ return `${scope}#added-${addedRowCounter}`;
663
+ }
664
+ function removeRow(plan, position) {
665
+ if (position < 0 || position >= plan.length) {
666
+ return plan;
667
+ }
668
+ return plan.filter((_entry, index) => index !== position);
669
+ }
670
+ function insertRowAfter(plan, position, id) {
671
+ const added = { id: id ?? nextAddedRowId(), source: null };
672
+ const at = Math.min(Math.max(position + 1, 0), plan.length);
673
+ return [...plan.slice(0, at), added, ...plan.slice(at)];
674
+ }
675
+ function cellEditKey(rowId, column) {
676
+ return `cell:${rowId}|col:${column}`;
677
+ }
678
+ function rowSourcesOf(plan) {
679
+ return plan.map((entry) => entry.source);
680
+ }
681
+ function isIdentityPlan(plan, extractedCount) {
682
+ return plan.length === extractedCount && plan.every((entry, index) => entry.source === index);
683
+ }
684
+
685
+ // src/verification/row-cells.ts
686
+ function syntheticBinding(submitKey, descriptor) {
687
+ const key = parseSchemaKey(submitKey);
688
+ if (key === null) {
689
+ return null;
690
+ }
691
+ return {
692
+ key,
693
+ serverValue: NOT_FOUND,
694
+ extracted: NOT_FOUND,
695
+ // No extracted node, so nothing to point at on the document.
696
+ fieldPointer: key.pointer,
697
+ editable: true,
698
+ field: descriptor
699
+ };
700
+ }
701
+ function planTableCells(table, plan, columns, bindingsByRawKey) {
702
+ const descriptors = /* @__PURE__ */ new Map();
703
+ for (const column of table.columns) {
704
+ if (typeof column.key === "string") {
705
+ descriptors.set(column.key, column);
706
+ }
707
+ }
708
+ return plan.map((entry, submittedIndex) => {
709
+ const cells = [];
710
+ for (const column of columns) {
711
+ const submitKey = cellSchemaKey(table.keyTemplate, submittedIndex, column);
712
+ const editKey = cellEditKey(entry.id, column);
713
+ const extractedKey = entry.source === null ? null : cellSchemaKey(table.keyTemplate, entry.source, column);
714
+ const existing = extractedKey === null ? void 0 : bindingsByRawKey.get(extractedKey);
715
+ const binding = existing ?? syntheticBinding(submitKey, descriptors.get(column));
716
+ if (binding === null) {
717
+ continue;
718
+ }
719
+ cells.push({ column, editKey, submitKey, binding, added: existing === void 0 });
720
+ }
721
+ return { entry, cells };
722
+ });
723
+ }
724
+ function displayColumns(table, classifiedColumns) {
725
+ const declared = table.columns.map((column) => column.key).filter((name) => typeof name === "string");
726
+ const seen = new Set(declared);
727
+ return [...declared, ...classifiedColumns.filter((name) => !seen.has(name))];
728
+ }
729
+ function matchesTablePointer(serverPointer, classifiedPointer) {
730
+ return serverPointer === classifiedPointer || snakeToCamel(serverPointer) === classifiedPointer;
731
+ }
732
+ function splitPointer(pointer) {
733
+ const cut = pointer.lastIndexOf("/");
734
+ return cut <= 0 ? null : { row: pointer.slice(0, cut), field: pointer.slice(cut + 1) };
735
+ }
736
+ function collectCellViews(bindings, plannedTables) {
737
+ const views = [];
738
+ const ownedPrefixes = [...plannedTables.keys()].map((pointer) => `${pointer}/`);
739
+ for (const rows of plannedTables.values()) {
740
+ for (const row of rows) {
741
+ for (const cell of row.cells) {
742
+ views.push({
743
+ editKey: cell.editKey,
744
+ submitKey: cell.submitKey,
745
+ column: cell.column,
746
+ rowKey: row.entry.id,
747
+ binding: cell.binding,
748
+ added: cell.added
749
+ });
750
+ }
751
+ }
752
+ }
753
+ for (const binding of bindings) {
754
+ if (ownedPrefixes.some((prefix) => binding.key.pointer.startsWith(prefix))) {
755
+ continue;
756
+ }
757
+ const split = splitPointer(binding.key.pointer);
758
+ views.push({
759
+ // Outside a plan all three identities coincide, which is why none of
760
+ // this was needed before row editing.
761
+ editKey: binding.key.raw,
762
+ submitKey: binding.key.raw,
763
+ column: split?.field ?? binding.key.label,
764
+ rowKey: split?.row ?? binding.key.raw,
765
+ binding,
766
+ added: false
767
+ });
768
+ }
769
+ return views;
770
+ }
771
+ var UNIT_SIZE = "unit_size";
772
+ var UNIT_SIZE_UOM = "unit_size_uom";
773
+ var UNIT_PAIR_MESSAGE = "Enter both value and unit";
774
+ function unitSizePairErrors(cells, edits) {
775
+ const rows = /* @__PURE__ */ new Map();
776
+ for (const cell of cells) {
777
+ if (cell.column !== UNIT_SIZE && cell.column !== UNIT_SIZE_UOM) {
778
+ continue;
779
+ }
780
+ const row = rows.get(cell.rowKey) ?? {};
781
+ if (cell.column === UNIT_SIZE) {
782
+ row.size = cell;
783
+ } else {
784
+ row.uom = cell;
785
+ }
786
+ rows.set(cell.rowKey, row);
787
+ }
788
+ const errors = /* @__PURE__ */ new Map();
789
+ for (const { size, uom } of rows.values()) {
790
+ if (!size || !uom) {
791
+ continue;
792
+ }
793
+ const filled = (cell) => (edits.get(cell.editKey) ?? toInputString(cell.binding.extracted)).trim() !== "";
794
+ if (filled(size) !== filled(uom)) {
795
+ errors.set(size.editKey, UNIT_PAIR_MESSAGE);
796
+ errors.set(uom.editKey, UNIT_PAIR_MESSAGE);
797
+ }
798
+ }
799
+ return errors;
800
+ }
801
+ function pruneEmptyAddedRows(plannedTables, edits) {
802
+ const out = /* @__PURE__ */ new Map();
803
+ for (const [pointer, rows] of plannedTables) {
804
+ out.set(pointer, rows.filter((row) => {
805
+ if (row.entry.source !== null) {
806
+ return true;
807
+ }
808
+ return row.cells.some((cell) => (edits.get(cell.editKey) ?? "").trim() !== "");
809
+ }));
810
+ }
811
+ return out;
455
812
  }
456
813
 
457
814
  // src/verification/form.tsx
458
815
  import React from "react";
459
816
 
817
+ // src/verification/tip.tsx
818
+ import {
819
+ cloneElement,
820
+ isValidElement,
821
+ useCallback,
822
+ useEffect,
823
+ useId,
824
+ useLayoutEffect,
825
+ useRef,
826
+ useState
827
+ } from "react";
828
+ import { createPortal } from "react-dom";
829
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
830
+ var GAP = 8;
831
+ var MARGIN = 8;
832
+ function isEmpty(content) {
833
+ return content == null || content === "" || content === false;
834
+ }
835
+ function rootClassesOf(node) {
836
+ const root = node?.closest(".gemina-verification");
837
+ return root ? root.className : "gemina-verification";
838
+ }
839
+ function mergeRefs(ours, theirs) {
840
+ return (value) => {
841
+ ours(value);
842
+ if (typeof theirs === "function") {
843
+ theirs(value);
844
+ } else if (theirs && typeof theirs === "object") {
845
+ theirs.current = value;
846
+ }
847
+ };
848
+ }
849
+ function Tip({ content, children }) {
850
+ const [open, setOpen] = useState(false);
851
+ const [position, setPosition] = useState(null);
852
+ const [rootClasses, setRootClasses] = useState("gemina-verification");
853
+ const triggerRef = useRef(null);
854
+ const tipRef = useRef(null);
855
+ const id = useId();
856
+ const empty = isEmpty(content);
857
+ const show = useCallback(() => {
858
+ if (empty) {
859
+ return;
860
+ }
861
+ setRootClasses(rootClassesOf(triggerRef.current));
862
+ setPosition(null);
863
+ setOpen(true);
864
+ }, [empty]);
865
+ const hide = useCallback(() => setOpen(false), []);
866
+ useLayoutEffect(() => {
867
+ if (!open) {
868
+ return;
869
+ }
870
+ const trigger2 = triggerRef.current;
871
+ const tip = tipRef.current;
872
+ if (!trigger2 || !tip) {
873
+ return;
874
+ }
875
+ const anchor = trigger2.getBoundingClientRect();
876
+ const bubble = tip.getBoundingClientRect();
877
+ const viewportWidth = window.innerWidth || 0;
878
+ const viewportHeight = window.innerHeight || 0;
879
+ const fitsAbove = anchor.top - bubble.height - GAP >= MARGIN;
880
+ const fitsBelow = anchor.bottom + bubble.height + GAP <= viewportHeight - MARGIN;
881
+ const top = fitsAbove || !fitsBelow ? anchor.top - bubble.height - GAP : anchor.bottom + GAP;
882
+ const centred = anchor.left + anchor.width / 2 - bubble.width / 2;
883
+ const rightLimit = Math.max(MARGIN, viewportWidth - bubble.width - MARGIN);
884
+ const left = Math.min(Math.max(centred, MARGIN), rightLimit);
885
+ setPosition({ top: Math.max(top, MARGIN), left });
886
+ }, [open, content]);
887
+ useEffect(() => {
888
+ if (!open) {
889
+ return;
890
+ }
891
+ const onKeyDown = (event) => {
892
+ if (event.key === "Escape") {
893
+ hide();
894
+ }
895
+ };
896
+ const onScrollOrResize = () => hide();
897
+ document.addEventListener("keydown", onKeyDown);
898
+ document.addEventListener("scroll", onScrollOrResize, true);
899
+ window.addEventListener("resize", onScrollOrResize);
900
+ return () => {
901
+ document.removeEventListener("keydown", onKeyDown);
902
+ document.removeEventListener("scroll", onScrollOrResize, true);
903
+ window.removeEventListener("resize", onScrollOrResize);
904
+ };
905
+ }, [open, hide]);
906
+ if (!isValidElement(children)) {
907
+ return children;
908
+ }
909
+ const childProps = children.props;
910
+ const call = (name, event) => {
911
+ const handler = childProps[name];
912
+ if (typeof handler === "function") {
913
+ handler(event);
914
+ }
915
+ };
916
+ const trigger = cloneElement(children, {
917
+ ref: mergeRefs((node) => {
918
+ triggerRef.current = node;
919
+ }, children.ref),
920
+ // The tip is a DESCRIPTION. `aria-label` stays untouched — it already
921
+ // carries the reason into the accessible NAME, and duplicating it here
922
+ // would have a screen reader announce it twice.
923
+ "aria-describedby": open && !empty ? id : void 0,
924
+ onMouseEnter: (event) => {
925
+ call("onMouseEnter", event);
926
+ show();
927
+ },
928
+ onMouseLeave: (event) => {
929
+ call("onMouseLeave", event);
930
+ hide();
931
+ },
932
+ onFocus: (event) => {
933
+ call("onFocus", event);
934
+ show();
935
+ },
936
+ onBlur: (event) => {
937
+ call("onBlur", event);
938
+ hide();
939
+ }
940
+ });
941
+ const canPortal = typeof document !== "undefined" && document.body;
942
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
943
+ trigger,
944
+ open && !empty && canPortal ? createPortal(
945
+ /* @__PURE__ */ jsx("div", { className: rootClasses, children: /* @__PURE__ */ jsx(
946
+ "div",
947
+ {
948
+ ref: tipRef,
949
+ id,
950
+ role: "tooltip",
951
+ className: "gemina-verification__tip",
952
+ style: {
953
+ top: position ? `${position.top}px` : "0px",
954
+ left: position ? `${position.left}px` : "0px",
955
+ visibility: position ? "visible" : "hidden"
956
+ },
957
+ children: content
958
+ }
959
+ ) }),
960
+ document.body
961
+ ) : null
962
+ ] });
963
+ }
964
+
460
965
  // src/verification/viewer.tsx
461
- import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
966
+ import { useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
462
967
 
463
968
  // src/verification/viewer-math.ts
464
969
  function fitScaleFor(natural, container, rotationDeg) {
@@ -540,9 +1045,9 @@ function flashZoomTarget(rects, natural, container, rotationDeg, fitScale) {
540
1045
  var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
541
1046
 
542
1047
  // src/verification/viewer.tsx
543
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1048
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
544
1049
  function IconBase({ children }) {
545
- return /* @__PURE__ */ jsx(
1050
+ return /* @__PURE__ */ jsx2(
546
1051
  "svg",
547
1052
  {
548
1053
  width: "16",
@@ -560,56 +1065,56 @@ function IconBase({ children }) {
560
1065
  );
561
1066
  }
562
1067
  function GlassBody() {
563
- return /* @__PURE__ */ jsxs(Fragment, { children: [
564
- /* @__PURE__ */ jsx("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
565
- /* @__PURE__ */ jsx("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
1068
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1069
+ /* @__PURE__ */ jsx2("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
1070
+ /* @__PURE__ */ jsx2("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
566
1071
  ] });
567
1072
  }
568
1073
  function IconZoomIn() {
569
- return /* @__PURE__ */ jsxs(IconBase, { children: [
570
- /* @__PURE__ */ jsx(GlassBody, {}),
571
- /* @__PURE__ */ jsx("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
572
- /* @__PURE__ */ jsx("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
1074
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1075
+ /* @__PURE__ */ jsx2(GlassBody, {}),
1076
+ /* @__PURE__ */ jsx2("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
1077
+ /* @__PURE__ */ jsx2("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
573
1078
  ] });
574
1079
  }
575
1080
  function IconZoomOut() {
576
- return /* @__PURE__ */ jsxs(IconBase, { children: [
577
- /* @__PURE__ */ jsx(GlassBody, {}),
578
- /* @__PURE__ */ jsx("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
1081
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1082
+ /* @__PURE__ */ jsx2(GlassBody, {}),
1083
+ /* @__PURE__ */ jsx2("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
579
1084
  ] });
580
1085
  }
581
1086
  function IconMagnifier() {
582
- return /* @__PURE__ */ jsx(IconBase, { children: /* @__PURE__ */ jsx(GlassBody, {}) });
1087
+ return /* @__PURE__ */ jsx2(IconBase, { children: /* @__PURE__ */ jsx2(GlassBody, {}) });
583
1088
  }
584
1089
  function IconActualSize() {
585
- return /* @__PURE__ */ jsxs(IconBase, { children: [
586
- /* @__PURE__ */ jsx("polyline", { points: "2.8 6.2 4 5 4 11" }),
587
- /* @__PURE__ */ jsx("polyline", { points: "10.8 6.2 12 5 12 11" }),
588
- /* @__PURE__ */ jsx("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
589
- /* @__PURE__ */ jsx("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
1090
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1091
+ /* @__PURE__ */ jsx2("polyline", { points: "2.8 6.2 4 5 4 11" }),
1092
+ /* @__PURE__ */ jsx2("polyline", { points: "10.8 6.2 12 5 12 11" }),
1093
+ /* @__PURE__ */ jsx2("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
1094
+ /* @__PURE__ */ jsx2("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
590
1095
  ] });
591
1096
  }
592
1097
  function IconFit() {
593
- return /* @__PURE__ */ jsxs(IconBase, { children: [
594
- /* @__PURE__ */ jsx("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
595
- /* @__PURE__ */ jsx("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
596
- /* @__PURE__ */ jsx("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
597
- /* @__PURE__ */ jsx("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
1098
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1099
+ /* @__PURE__ */ jsx2("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
1100
+ /* @__PURE__ */ jsx2("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
1101
+ /* @__PURE__ */ jsx2("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
1102
+ /* @__PURE__ */ jsx2("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
598
1103
  ] });
599
1104
  }
600
1105
  function IconRotate() {
601
- return /* @__PURE__ */ jsxs(IconBase, { children: [
602
- /* @__PURE__ */ jsx("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
603
- /* @__PURE__ */ jsx("polyline", { points: "6 1.7 8 3 6 4.3" })
1106
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1107
+ /* @__PURE__ */ jsx2("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
1108
+ /* @__PURE__ */ jsx2("polyline", { points: "6 1.7 8 3 6 4.3" })
604
1109
  ] });
605
1110
  }
606
1111
  function IconOverlay() {
607
- return /* @__PURE__ */ jsx(IconBase, { children: /* @__PURE__ */ jsx("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
1112
+ return /* @__PURE__ */ jsx2(IconBase, { children: /* @__PURE__ */ jsx2("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
608
1113
  }
609
1114
  function IconEye() {
610
- return /* @__PURE__ */ jsxs(IconBase, { children: [
611
- /* @__PURE__ */ jsx("path", { d: "M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8s-2.4 4.5-6.5 4.5S1.5 8 1.5 8z" }),
612
- /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "2.1" })
1115
+ return /* @__PURE__ */ jsxs2(IconBase, { children: [
1116
+ /* @__PURE__ */ jsx2("path", { d: "M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8s-2.4 4.5-6.5 4.5S1.5 8 1.5 8z" }),
1117
+ /* @__PURE__ */ jsx2("circle", { cx: "8", cy: "8", r: "2.1" })
613
1118
  ] });
614
1119
  }
615
1120
  function ToolbarButton({
@@ -621,12 +1126,11 @@ function ToolbarButton({
621
1126
  children
622
1127
  }) {
623
1128
  const active = (pressed ?? checked) === true;
624
- return /* @__PURE__ */ jsx(
1129
+ return /* @__PURE__ */ jsx2(Tip, { content: label, children: /* @__PURE__ */ jsx2(
625
1130
  "button",
626
1131
  {
627
1132
  type: "button",
628
1133
  className: active ? "gemina-verification__toolbar-btn gemina-verification__toolbar-btn--active" : "gemina-verification__toolbar-btn",
629
- title: label,
630
1134
  "aria-label": label,
631
1135
  role: checked === void 0 ? void 0 : "switch",
632
1136
  "aria-checked": checked,
@@ -635,7 +1139,7 @@ function ToolbarButton({
635
1139
  onClick,
636
1140
  children
637
1141
  }
638
- );
1142
+ ) });
639
1143
  }
640
1144
  var ZOOM_STEP = 1.2;
641
1145
  var IDENTITY = { scale: 1, tx: 0, ty: 0 };
@@ -645,6 +1149,7 @@ var REDUCED_MOTION_FLASH_MS = 800;
645
1149
  var MIN_SIZE_RATIO = 8e-3;
646
1150
  var MAG_RADIUS = 150;
647
1151
  var MAG_ZOOM = 2.5;
1152
+ var MAG_BORDER = 2;
648
1153
  function rectGeometry(rect, natural) {
649
1154
  const xs = rect.points.map((point) => point[0]);
650
1155
  const ys = rect.points.map((point) => point[1]);
@@ -662,29 +1167,29 @@ function rectGeometry(rect, natural) {
662
1167
  }
663
1168
  function VerificationViewer(props) {
664
1169
  const { src, alt, relativeRects, flashRects, onFlashComplete, onImageExpired } = props;
665
- const canvasRef = useRef(null);
666
- const imgRef = useRef(null);
667
- const [natural, setNatural] = useState(null);
668
- const [container, setContainer] = useState({ w: 0, h: 0 });
669
- const [transform, setTransform] = useState(IDENTITY);
670
- const [rotation, setRotation] = useState(0);
671
- const [showRects, setShowRects] = useState(false);
672
- const [magnifierOn, setMagnifierOn] = useState(false);
673
- const [showMag, setShowMag] = useState(false);
674
- const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
675
- const [isPanning, setIsPanning] = useState(false);
676
- const panStart = useRef(null);
677
- const [flashOpacity, setFlashOpacity] = useState(0);
678
- const [activeFlashRects, setActiveFlashRects] = useState(null);
679
- const travelRafRef = useRef(null);
680
- const fadeRafRef = useRef(null);
681
- const reducedFlashTimeoutRef = useRef(null);
682
- const transformRef = useRef(transform);
1170
+ const canvasRef = useRef2(null);
1171
+ const imgRef = useRef2(null);
1172
+ const [natural, setNatural] = useState2(null);
1173
+ const [container, setContainer] = useState2({ w: 0, h: 0 });
1174
+ const [transform, setTransform] = useState2(IDENTITY);
1175
+ const [rotation, setRotation] = useState2(0);
1176
+ const [showRects, setShowRects] = useState2(false);
1177
+ const [magnifierOn, setMagnifierOn] = useState2(false);
1178
+ const [showMag, setShowMag] = useState2(false);
1179
+ const [mousePos, setMousePos] = useState2({ x: 0, y: 0 });
1180
+ const [isPanning, setIsPanning] = useState2(false);
1181
+ const panStart = useRef2(null);
1182
+ const [flashOpacity, setFlashOpacity] = useState2(0);
1183
+ const [activeFlashRects, setActiveFlashRects] = useState2(null);
1184
+ const travelRafRef = useRef2(null);
1185
+ const fadeRafRef = useRef2(null);
1186
+ const reducedFlashTimeoutRef = useRef2(null);
1187
+ const transformRef = useRef2(transform);
683
1188
  transformRef.current = transform;
684
- const onFlashCompleteRef = useRef(onFlashComplete);
1189
+ const onFlashCompleteRef = useRef2(onFlashComplete);
685
1190
  onFlashCompleteRef.current = onFlashComplete;
686
- const hasLoadedRef = useRef(false);
687
- useLayoutEffect(() => {
1191
+ const hasLoadedRef = useRef2(false);
1192
+ useLayoutEffect2(() => {
688
1193
  const el = canvasRef.current;
689
1194
  if (!el) return;
690
1195
  if (typeof ResizeObserver === "undefined") {
@@ -699,7 +1204,7 @@ function VerificationViewer(props) {
699
1204
  ro.observe(el);
700
1205
  return () => ro.disconnect();
701
1206
  }, []);
702
- const handleImgLoad = useCallback(() => {
1207
+ const handleImgLoad = useCallback2(() => {
703
1208
  const img = imgRef.current;
704
1209
  if (!img) return;
705
1210
  hasLoadedRef.current = true;
@@ -707,19 +1212,19 @@ function VerificationViewer(props) {
707
1212
  const h = img.naturalHeight;
708
1213
  setNatural((prev) => prev && prev.w === w && prev.h === h ? prev : { w, h });
709
1214
  }, []);
710
- useEffect(() => {
1215
+ useEffect2(() => {
711
1216
  hasLoadedRef.current = false;
712
1217
  }, [src]);
713
- const handleImgError = useCallback(() => {
1218
+ const handleImgError = useCallback2(() => {
714
1219
  if (!hasLoadedRef.current) return;
715
1220
  hasLoadedRef.current = false;
716
1221
  onImageExpired?.();
717
1222
  }, [onImageExpired]);
718
- const currentFitScale = useCallback(() => {
1223
+ const currentFitScale = useCallback2(() => {
719
1224
  if (!natural || !container.w || !container.h) return 1;
720
1225
  return fitScaleFor(natural, container, rotation);
721
1226
  }, [natural, container, rotation]);
722
- useEffect(() => {
1227
+ useEffect2(() => {
723
1228
  if (!natural || !container.w || !container.h) return;
724
1229
  const fit = fitScaleFor(natural, container, rotation);
725
1230
  const { tx, ty } = centeredTranslation(natural, container, fit, rotation);
@@ -727,13 +1232,13 @@ function VerificationViewer(props) {
727
1232
  (prev) => Math.abs(prev.scale - fit) < 1e-4 && prev.tx === tx && prev.ty === ty ? prev : { scale: fit, tx, ty }
728
1233
  );
729
1234
  }, [natural, container, rotation]);
730
- const cancelFlashTravel = useCallback(() => {
1235
+ const cancelFlashTravel = useCallback2(() => {
731
1236
  if (travelRafRef.current !== null) {
732
1237
  cancelAnimationFrame(travelRafRef.current);
733
1238
  travelRafRef.current = null;
734
1239
  }
735
1240
  }, []);
736
- const zoomBy = useCallback(
1241
+ const zoomBy = useCallback2(
737
1242
  (factor) => {
738
1243
  const node = canvasRef.current;
739
1244
  if (!node || !natural) return;
@@ -746,9 +1251,9 @@ function VerificationViewer(props) {
746
1251
  },
747
1252
  [natural, rotation, currentFitScale, cancelFlashTravel]
748
1253
  );
749
- const handleZoomIn = useCallback(() => zoomBy(ZOOM_STEP), [zoomBy]);
750
- const handleZoomOut = useCallback(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
751
- const zoomAtClientPoint = useCallback(
1254
+ const handleZoomIn = useCallback2(() => zoomBy(ZOOM_STEP), [zoomBy]);
1255
+ const handleZoomOut = useCallback2(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
1256
+ const zoomAtClientPoint = useCallback2(
752
1257
  (factor, clientX, clientY) => {
753
1258
  const node = canvasRef.current;
754
1259
  if (!node || !natural) return;
@@ -760,7 +1265,7 @@ function VerificationViewer(props) {
760
1265
  },
761
1266
  [natural, rotation, currentFitScale]
762
1267
  );
763
- const handleWheel = useCallback(
1268
+ const handleWheel = useCallback2(
764
1269
  (event) => {
765
1270
  event.preventDefault();
766
1271
  event.stopPropagation();
@@ -770,7 +1275,7 @@ function VerificationViewer(props) {
770
1275
  },
771
1276
  [zoomAtClientPoint, cancelFlashTravel]
772
1277
  );
773
- useEffect(() => {
1278
+ useEffect2(() => {
774
1279
  const node = canvasRef.current;
775
1280
  if (!node) return;
776
1281
  const listener = (event) => handleWheel(event);
@@ -778,7 +1283,7 @@ function VerificationViewer(props) {
778
1283
  return () => node.removeEventListener("wheel", listener);
779
1284
  }, [handleWheel]);
780
1285
  const atFitScale = transform.scale <= currentFitScale() + 1e-3;
781
- const handleMouseDown = useCallback(
1286
+ const handleMouseDown = useCallback2(
782
1287
  (e) => {
783
1288
  cancelFlashTravel();
784
1289
  if (e.button !== 0) return;
@@ -789,7 +1294,7 @@ function VerificationViewer(props) {
789
1294
  },
790
1295
  [atFitScale, transform.tx, transform.ty, cancelFlashTravel]
791
1296
  );
792
- useEffect(() => {
1297
+ useEffect2(() => {
793
1298
  if (!isPanning) return;
794
1299
  const onMove = (e) => {
795
1300
  const start = panStart.current;
@@ -809,8 +1314,8 @@ function VerificationViewer(props) {
809
1314
  document.removeEventListener("mouseup", onUp);
810
1315
  };
811
1316
  }, [isPanning]);
812
- const touchState = useRef(null);
813
- const handleTouchStart = useCallback(
1317
+ const touchState = useRef2(null);
1318
+ const handleTouchStart = useCallback2(
814
1319
  (e) => {
815
1320
  cancelFlashTravel();
816
1321
  const a = e.touches[0];
@@ -828,7 +1333,7 @@ function VerificationViewer(props) {
828
1333
  },
829
1334
  [atFitScale, transform.tx, transform.ty, cancelFlashTravel]
830
1335
  );
831
- const handleTouchMove = useCallback(
1336
+ const handleTouchMove = useCallback2(
832
1337
  (e) => {
833
1338
  const state = touchState.current;
834
1339
  if (!state) return;
@@ -853,19 +1358,19 @@ function VerificationViewer(props) {
853
1358
  },
854
1359
  [zoomAtClientPoint]
855
1360
  );
856
- const handleTouchEnd = useCallback((e) => {
1361
+ const handleTouchEnd = useCallback2((e) => {
857
1362
  if (e.touches.length === 0) touchState.current = null;
858
1363
  }, []);
859
- const handleCanvasMouseMove = useCallback((e) => {
1364
+ const handleCanvasMouseMove = useCallback2((e) => {
860
1365
  const rect = canvasRef.current?.getBoundingClientRect();
861
1366
  if (!rect) return;
862
1367
  setShowMag(true);
863
1368
  setMousePos({ x: e.clientX - rect.left, y: e.clientY - rect.top });
864
1369
  }, []);
865
- const handleCanvasMouseLeave = useCallback(() => {
1370
+ const handleCanvasMouseLeave = useCallback2(() => {
866
1371
  setShowMag(false);
867
1372
  }, []);
868
- const handleDoubleClick = useCallback(
1373
+ const handleDoubleClick = useCallback2(
869
1374
  (e) => {
870
1375
  cancelFlashTravel();
871
1376
  if (!natural) return;
@@ -880,26 +1385,26 @@ function VerificationViewer(props) {
880
1385
  },
881
1386
  [natural, container, rotation, transform.scale, currentFitScale, zoomAtClientPoint, cancelFlashTravel]
882
1387
  );
883
- const handleFit = useCallback(() => {
1388
+ const handleFit = useCallback2(() => {
884
1389
  if (!natural) return;
885
1390
  cancelFlashTravel();
886
1391
  const fit = currentFitScale();
887
1392
  setTransform({ scale: fit, ...centeredTranslation(natural, container, fit, rotation) });
888
1393
  }, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
889
- const handleActualSize = useCallback(() => {
1394
+ const handleActualSize = useCallback2(() => {
890
1395
  if (!natural) return;
891
1396
  cancelFlashTravel();
892
1397
  const target = clampScale(1, currentFitScale());
893
1398
  setTransform({ scale: target, ...centeredTranslation(natural, container, target, rotation) });
894
1399
  }, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
895
- const handleRotate = useCallback(() => {
1400
+ const handleRotate = useCallback2(() => {
896
1401
  setRotation((r) => (r + 90) % 360);
897
1402
  }, []);
898
1403
  const hasRects = relativeRects !== void 0 && relativeRects.length > 0;
899
- useEffect(() => {
1404
+ useEffect2(() => {
900
1405
  if (!hasRects) setShowRects(false);
901
1406
  }, [hasRects]);
902
- useEffect(() => {
1407
+ useEffect2(() => {
903
1408
  if (!flashRects || flashRects.length === 0 || !natural || !container.w || !container.h) {
904
1409
  setActiveFlashRects((prev) => prev === null ? prev : null);
905
1410
  setFlashOpacity(0);
@@ -970,71 +1475,72 @@ function VerificationViewer(props) {
970
1475
  const dy = mousePos.y - transform.ty;
971
1476
  const cxRaw = (cosA * dx + sinA * dy) / transform.scale;
972
1477
  const cyRaw = (-sinA * dx + cosA * dy) / transform.scale;
973
- const clampedX = Math.max(0, Math.min(cxRaw, natural.w));
974
- const clampedY = Math.max(0, Math.min(cyRaw, natural.h));
1478
+ const onImage = cxRaw >= 0 && cyRaw >= 0 && cxRaw <= natural.w && cyRaw <= natural.h;
975
1479
  const zoomScale = transform.scale * MAG_ZOOM;
976
- const px = clampedX * zoomScale;
977
- const py = clampedY * zoomScale;
1480
+ const px = cxRaw * zoomScale;
1481
+ const py = cyRaw * zoomScale;
978
1482
  const rotatedX = px * cosA - py * sinA;
979
1483
  const rotatedY = px * sinA + py * cosA;
980
- const translateX = MAG_RADIUS - rotatedX;
981
- const translateY = MAG_RADIUS - rotatedY;
982
- magnifier = /* @__PURE__ */ jsx(
983
- "div",
984
- {
985
- className: "gemina-verification__magnifier",
986
- style: {
987
- width: MAG_RADIUS * 2,
988
- height: MAG_RADIUS * 2,
989
- top: mousePos.y - MAG_RADIUS,
990
- left: mousePos.x - MAG_RADIUS
991
- },
992
- children: /* @__PURE__ */ jsx(
993
- "img",
994
- {
995
- src,
996
- alt: "",
997
- draggable: false,
998
- style: {
999
- position: "absolute",
1000
- width: natural.w,
1001
- height: natural.h,
1002
- transformOrigin: "0 0",
1003
- transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
1484
+ const translateX = MAG_RADIUS - MAG_BORDER - rotatedX;
1485
+ const translateY = MAG_RADIUS - MAG_BORDER - rotatedY;
1486
+ if (onImage) {
1487
+ magnifier = /* @__PURE__ */ jsx2(
1488
+ "div",
1489
+ {
1490
+ className: "gemina-verification__magnifier",
1491
+ style: {
1492
+ width: MAG_RADIUS * 2,
1493
+ height: MAG_RADIUS * 2,
1494
+ top: mousePos.y - MAG_RADIUS,
1495
+ left: mousePos.x - MAG_RADIUS
1496
+ },
1497
+ children: /* @__PURE__ */ jsx2(
1498
+ "img",
1499
+ {
1500
+ src,
1501
+ alt: "",
1502
+ draggable: false,
1503
+ style: {
1504
+ position: "absolute",
1505
+ width: natural.w,
1506
+ height: natural.h,
1507
+ transformOrigin: "0 0",
1508
+ transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
1509
+ }
1004
1510
  }
1005
- }
1006
- )
1007
- }
1008
- );
1511
+ )
1512
+ }
1513
+ );
1514
+ }
1009
1515
  }
1010
- return /* @__PURE__ */ jsxs("div", { className: "gemina-verification__viewer", children: [
1011
- /* @__PURE__ */ jsxs("div", { className: "gemina-verification__toolbar", children: [
1012
- /* @__PURE__ */ jsx(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ jsx(IconZoomOut, {}) }),
1013
- /* @__PURE__ */ jsx(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ jsx(IconZoomIn, {}) }),
1014
- /* @__PURE__ */ jsx(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ jsx(IconActualSize, {}) }),
1015
- /* @__PURE__ */ jsx(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ jsx(IconFit, {}) }),
1016
- /* @__PURE__ */ jsx(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ jsx(IconRotate, {}) }),
1017
- /* @__PURE__ */ jsx(
1516
+ return /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__viewer", children: [
1517
+ /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__toolbar", children: [
1518
+ /* @__PURE__ */ jsx2(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ jsx2(IconZoomOut, {}) }),
1519
+ /* @__PURE__ */ jsx2(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ jsx2(IconZoomIn, {}) }),
1520
+ /* @__PURE__ */ jsx2(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ jsx2(IconActualSize, {}) }),
1521
+ /* @__PURE__ */ jsx2(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ jsx2(IconFit, {}) }),
1522
+ /* @__PURE__ */ jsx2(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ jsx2(IconRotate, {}) }),
1523
+ /* @__PURE__ */ jsx2(
1018
1524
  ToolbarButton,
1019
1525
  {
1020
1526
  label: "Toggle detection overlays",
1021
1527
  pressed: showRects,
1022
1528
  disabled: !hasRects,
1023
1529
  onClick: () => setShowRects((prev) => !prev),
1024
- children: /* @__PURE__ */ jsx(IconOverlay, {})
1530
+ children: /* @__PURE__ */ jsx2(IconOverlay, {})
1025
1531
  }
1026
1532
  ),
1027
- /* @__PURE__ */ jsx(
1533
+ /* @__PURE__ */ jsx2(
1028
1534
  ToolbarButton,
1029
1535
  {
1030
1536
  label: "Magnifier",
1031
1537
  checked: magnifierOn,
1032
1538
  onClick: () => setMagnifierOn((prev) => !prev),
1033
- children: /* @__PURE__ */ jsx(IconMagnifier, {})
1539
+ children: /* @__PURE__ */ jsx2(IconMagnifier, {})
1034
1540
  }
1035
1541
  )
1036
1542
  ] }),
1037
- /* @__PURE__ */ jsxs(
1543
+ /* @__PURE__ */ jsxs2(
1038
1544
  "div",
1039
1545
  {
1040
1546
  ref: canvasRef,
@@ -1051,7 +1557,7 @@ function VerificationViewer(props) {
1051
1557
  onTouchEnd: handleTouchEnd,
1052
1558
  onTouchCancel: handleTouchEnd,
1053
1559
  children: [
1054
- /* @__PURE__ */ jsxs(
1560
+ /* @__PURE__ */ jsxs2(
1055
1561
  "div",
1056
1562
  {
1057
1563
  style: {
@@ -1063,7 +1569,7 @@ function VerificationViewer(props) {
1063
1569
  willChange: "transform,left,top"
1064
1570
  },
1065
1571
  children: [
1066
- /* @__PURE__ */ jsx(
1572
+ /* @__PURE__ */ jsx2(
1067
1573
  "img",
1068
1574
  {
1069
1575
  ref: imgRef,
@@ -1077,13 +1583,13 @@ function VerificationViewer(props) {
1077
1583
  showRects && natural && relativeRects?.map((rect, idx) => {
1078
1584
  const geometry = rectGeometry(rect, natural);
1079
1585
  if (!geometry) return null;
1080
- return /* @__PURE__ */ jsx(
1586
+ return /* @__PURE__ */ jsx2(
1081
1587
  "div",
1082
1588
  {
1083
1589
  className: "gemina-verification__rect",
1084
1590
  style: geometry,
1085
1591
  "aria-hidden": "true",
1086
- children: /* @__PURE__ */ jsxs("span", { className: "gemina-verification__rect-badge", children: [
1592
+ children: /* @__PURE__ */ jsxs2("span", { className: "gemina-verification__rect-badge", children: [
1087
1593
  "#",
1088
1594
  idx + 1
1089
1595
  ] })
@@ -1094,7 +1600,7 @@ function VerificationViewer(props) {
1094
1600
  activeFlashRects && natural && activeFlashRects.map((rect, idx) => {
1095
1601
  const geometry = rectGeometry(rect, natural);
1096
1602
  if (!geometry) return null;
1097
- return /* @__PURE__ */ jsx(
1603
+ return /* @__PURE__ */ jsx2(
1098
1604
  "div",
1099
1605
  {
1100
1606
  className: "gemina-verification__flash-rect",
@@ -1115,7 +1621,7 @@ function VerificationViewer(props) {
1115
1621
  }
1116
1622
 
1117
1623
  // src/verification/form.tsx
1118
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1624
+ import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1119
1625
  function ConfidenceDot(props) {
1120
1626
  const { confidence } = props;
1121
1627
  if (!confidence?.level) {
@@ -1141,93 +1647,156 @@ function ConfidenceDot(props) {
1141
1647
  label = `${confidence.level} confidence`;
1142
1648
  }
1143
1649
  const reasons = confidence.reasons.map(formatLabel);
1144
- const title = [label, ...reasons].join("\n");
1145
1650
  const ariaLabel = reasons.length > 0 ? `${label}: ${reasons.join(", ")}` : label;
1146
- return /* @__PURE__ */ jsx2(
1651
+ const tip = /* @__PURE__ */ jsxs3(Fragment3, { children: [
1652
+ /* @__PURE__ */ jsx3("strong", { className: "gemina-verification__tip-title", children: label }),
1653
+ reasons.length > 0 ? /* @__PURE__ */ jsx3("ul", { className: "gemina-verification__tip-list", children: reasons.map((reason) => /* @__PURE__ */ jsx3("li", { children: reason }, reason)) }) : null
1654
+ ] });
1655
+ return /* @__PURE__ */ jsx3(Tip, { content: tip, children: /* @__PURE__ */ jsx3(
1147
1656
  "span",
1148
1657
  {
1149
1658
  className: `gemina-verification__dot gemina-verification__dot--${variant}`,
1150
1659
  role: "img",
1151
- "aria-label": ariaLabel,
1152
- title
1660
+ "aria-label": ariaLabel
1153
1661
  }
1154
- );
1662
+ ) });
1155
1663
  }
1156
1664
  function EyeButton(props) {
1157
1665
  const { coordinates, onFlash } = props;
1158
1666
  if (!coordinates) {
1159
1667
  return null;
1160
1668
  }
1161
- return /* @__PURE__ */ jsx2(
1669
+ return /* @__PURE__ */ jsx3(Tip, { content: "Show on document", children: /* @__PURE__ */ jsx3(
1162
1670
  "button",
1163
1671
  {
1164
1672
  type: "button",
1165
1673
  className: "gemina-verification__eye",
1166
- title: "Show on document",
1167
1674
  "aria-label": "Show on document",
1168
1675
  onClick: (event) => {
1169
1676
  event.stopPropagation();
1170
1677
  onFlash();
1171
1678
  },
1172
- children: /* @__PURE__ */ jsx2(IconEye, {})
1679
+ children: /* @__PURE__ */ jsx3(IconEye, {})
1173
1680
  }
1174
- );
1681
+ ) });
1175
1682
  }
1176
1683
  function FieldInput(props) {
1177
- const { binding, edit, onEdit, readOnly, ariaLabel } = props;
1684
+ const { binding, edit, onEdit, readOnly, ariaLabel, pairError } = props;
1685
+ const editKey = props.editKey ?? binding.key.raw;
1178
1686
  const editedBadgeId = React.useId();
1687
+ const errorId = React.useId();
1688
+ const currencyListId = React.useId();
1179
1689
  if (readOnly || !binding.editable) {
1180
1690
  const display = binding.extracted === NOT_FOUND ? null : binding.extracted;
1181
- return /* @__PURE__ */ jsx2("span", { children: formatValue(display, binding.key.label) });
1691
+ return /* @__PURE__ */ jsx3("span", { children: formatValue(display, binding.key.label) });
1182
1692
  }
1183
1693
  const dirty = edit !== void 0;
1184
1694
  const missed = binding.serverValue === NOT_FOUND;
1695
+ const field = binding.field;
1696
+ const value = dirty ? edit : toInputString(binding.extracted);
1697
+ const error = pairError ?? (dirty ? validateInput(value, field) : null);
1185
1698
  const className = [
1186
1699
  "gemina-verification__input",
1187
1700
  dirty ? "gemina-verification__input--dirty" : "",
1188
- missed ? "gemina-verification__input--missed" : ""
1701
+ missed ? "gemina-verification__input--missed" : "",
1702
+ error ? "gemina-verification__input--invalid" : ""
1189
1703
  ].filter(Boolean).join(" ");
1190
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1191
- /* @__PURE__ */ jsx2(
1192
- "input",
1193
- {
1194
- type: "text",
1195
- className,
1196
- dir: "auto",
1197
- value: dirty ? edit : toInputString(binding.extracted),
1198
- onChange: (event) => onEdit(binding.key.raw, event.target.value),
1199
- placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
1200
- "aria-label": ariaLabel,
1201
- "aria-describedby": dirty ? editedBadgeId : void 0,
1202
- autoComplete: "off"
1203
- }
1204
- ),
1205
- dirty ? /* @__PURE__ */ jsx2("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" }) : null
1704
+ const describedBy = [dirty ? editedBadgeId : "", error ? errorId : ""].filter(Boolean).join(" ");
1705
+ const shared = {
1706
+ className,
1707
+ "aria-label": ariaLabel,
1708
+ "aria-describedby": describedBy || void 0,
1709
+ "aria-invalid": error ? true : void 0,
1710
+ onChange: (event) => onEdit(editKey, event.target.value, binding)
1711
+ };
1712
+ const roster = field?.enum && field.enum.length > 0 ? field.enum : null;
1713
+ const offRoster = roster && value !== "" && !roster.includes(value) ? value : null;
1714
+ const control = roster ? /* @__PURE__ */ jsxs3("select", { ...shared, value, dir: "auto", children: [
1715
+ /* @__PURE__ */ jsx3("option", { value: "", children: "\u2014" }),
1716
+ offRoster ? /* @__PURE__ */ jsxs3("option", { value: offRoster, children: [
1717
+ offRoster,
1718
+ " (as extracted)"
1719
+ ] }) : null,
1720
+ roster.map((option) => /* @__PURE__ */ jsx3("option", { value: option, children: option }, option))
1721
+ ] }) : /* @__PURE__ */ jsx3(
1722
+ "input",
1723
+ {
1724
+ ...shared,
1725
+ type: field?.type === "date" ? "date" : "text",
1726
+ dir: "auto",
1727
+ value,
1728
+ inputMode: field?.type === "number" || field?.type === "integer" ? "decimal" : void 0,
1729
+ list: field?.format === "iso4217" ? currencyListId : void 0,
1730
+ placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
1731
+ autoComplete: "off"
1732
+ }
1733
+ );
1734
+ return /* @__PURE__ */ jsxs3(Fragment3, { children: [
1735
+ control,
1736
+ field?.format === "iso4217" ? /* @__PURE__ */ jsx3("datalist", { id: currencyListId, children: ISO_4217_CODES.map((code) => /* @__PURE__ */ jsx3("option", { value: code }, code)) }) : null,
1737
+ error ? /* @__PURE__ */ jsx3("span", { className: "gemina-verification__field-error", id: errorId, role: "alert", children: error }) : null,
1738
+ dirty ? (
1739
+ // The badge is where the ORIGINAL belongs, now that the input holds
1740
+ // the edit — otherwise the extracted value is simply gone from the
1741
+ // screen the moment someone corrects it.
1742
+ //
1743
+ // Known limit: the badge is a non-focusable span, so this channel is
1744
+ // hover-only. AT is not worse off than before (nothing carried the
1745
+ // original previously), and the input's aria-describedby still names
1746
+ // the field as edited. Giving it a keyboard path needs a focusable
1747
+ // affordance, which belongs with the Phase 8 row work, not here.
1748
+ /* @__PURE__ */ jsx3(
1749
+ Tip,
1750
+ {
1751
+ content: /* @__PURE__ */ jsxs3(Fragment3, { children: [
1752
+ /* @__PURE__ */ jsx3("span", { className: "gemina-verification__tip-label", children: "Was: " }),
1753
+ formatValue(
1754
+ binding.extracted === NOT_FOUND ? null : binding.extracted,
1755
+ binding.key.label
1756
+ )
1757
+ ] }),
1758
+ children: /* @__PURE__ */ jsx3("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" })
1759
+ }
1760
+ )
1761
+ ) : null
1206
1762
  ] });
1207
1763
  }
1764
+ var NO_PAIR_ERRORS = /* @__PURE__ */ new Map();
1765
+ var NO_TABLES = [];
1766
+ var NO_PLANNED = /* @__PURE__ */ new Map();
1767
+ var NOOP_ROW = () => {
1768
+ };
1208
1769
  function isInteractiveTarget(target) {
1209
1770
  return target instanceof Element && target.closest("input, button, a, select, textarea") !== null;
1210
1771
  }
1772
+ function FieldLabel(props) {
1773
+ const { label, description } = props;
1774
+ if (!description) {
1775
+ return /* @__PURE__ */ jsx3("span", { children: label });
1776
+ }
1777
+ return /* @__PURE__ */ jsx3(Tip, { content: description, children: /* @__PURE__ */ jsx3("span", { className: "gemina-verification__label-described", tabIndex: 0, children: label }) });
1778
+ }
1211
1779
  function FieldPair(props) {
1212
1780
  const { label, ariaLabel, cell, shared } = props;
1213
1781
  const binding = shared.bindingIndex.get(cell.pointer);
1214
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1215
- /* @__PURE__ */ jsxs2("dt", { className: "gemina-verification__dt", children: [
1216
- /* @__PURE__ */ jsx2(ConfidenceDot, { confidence: cell.confidence }),
1217
- /* @__PURE__ */ jsx2("span", { children: label })
1782
+ return /* @__PURE__ */ jsxs3(Fragment3, { children: [
1783
+ /* @__PURE__ */ jsxs3("dt", { className: "gemina-verification__dt", children: [
1784
+ /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: cell.confidence }),
1785
+ /* @__PURE__ */ jsx3(FieldLabel, { label, description: binding?.field?.description })
1218
1786
  ] }),
1219
- /* @__PURE__ */ jsxs2("dd", { className: "gemina-verification__dd", children: [
1220
- binding !== void 0 ? /* @__PURE__ */ jsx2(
1787
+ /* @__PURE__ */ jsxs3("dd", { className: "gemina-verification__dd", children: [
1788
+ binding !== void 0 ? /* @__PURE__ */ jsx3(
1221
1789
  FieldInput,
1222
1790
  {
1223
1791
  binding,
1792
+ pairError: shared.pairErrors.get(binding.key.raw),
1224
1793
  edit: shared.edits.get(binding.key.raw),
1225
1794
  onEdit: shared.onEdit,
1226
1795
  readOnly: shared.readOnly,
1227
1796
  ariaLabel
1228
1797
  }
1229
- ) : /* @__PURE__ */ jsx2("span", { children: formatValue(cell.value, label) }),
1230
- /* @__PURE__ */ jsx2(
1798
+ ) : /* @__PURE__ */ jsx3("span", { children: formatValue(cell.value, label) }),
1799
+ /* @__PURE__ */ jsx3(
1231
1800
  EyeButton,
1232
1801
  {
1233
1802
  coordinates: cell.coordinates,
@@ -1246,10 +1815,10 @@ function HeaderSection(props) {
1246
1815
  if (headers.length === 0 && simpleLists.length === 0) {
1247
1816
  return null;
1248
1817
  }
1249
- return /* @__PURE__ */ jsxs2("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
1250
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__section-header", children: "Details" }),
1251
- /* @__PURE__ */ jsxs2("dl", { className: "gemina-verification__dl", children: [
1252
- headers.map((field) => /* @__PURE__ */ jsx2(
1818
+ return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
1819
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Details" }),
1820
+ /* @__PURE__ */ jsxs3("dl", { className: "gemina-verification__dl", children: [
1821
+ headers.map((field) => /* @__PURE__ */ jsx3(
1253
1822
  FieldPair,
1254
1823
  {
1255
1824
  label: formatLabel(field.key),
@@ -1259,23 +1828,24 @@ function HeaderSection(props) {
1259
1828
  },
1260
1829
  field.pointer
1261
1830
  )),
1262
- simpleLists.map((list) => /* @__PURE__ */ jsxs2(React.Fragment, { children: [
1263
- /* @__PURE__ */ jsx2("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx2("span", { children: formatLabel(list.key) }) }),
1264
- /* @__PURE__ */ jsx2("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx2("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
1831
+ simpleLists.map((list) => /* @__PURE__ */ jsxs3(React.Fragment, { children: [
1832
+ /* @__PURE__ */ jsx3("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx3("span", { children: formatLabel(list.key) }) }),
1833
+ /* @__PURE__ */ jsx3("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx3("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
1265
1834
  const binding = shared.bindingIndex.get(item.pointer);
1266
- return /* @__PURE__ */ jsxs2("li", { className: "gemina-verification__cell", children: [
1267
- binding !== void 0 ? /* @__PURE__ */ jsx2(
1835
+ return /* @__PURE__ */ jsxs3("li", { className: "gemina-verification__cell", children: [
1836
+ binding !== void 0 ? /* @__PURE__ */ jsx3(
1268
1837
  FieldInput,
1269
1838
  {
1270
1839
  binding,
1840
+ pairError: shared.pairErrors.get(binding.key.raw),
1271
1841
  edit: shared.edits.get(binding.key.raw),
1272
1842
  onEdit: shared.onEdit,
1273
1843
  readOnly: shared.readOnly,
1274
1844
  ariaLabel: `${formatLabel(list.key)} item ${index + 1}`
1275
1845
  }
1276
- ) : /* @__PURE__ */ jsx2("span", { children: formatValue(item.value) }),
1277
- /* @__PURE__ */ jsx2(ConfidenceDot, { confidence: item.confidence }),
1278
- /* @__PURE__ */ jsx2(
1846
+ ) : /* @__PURE__ */ jsx3("span", { children: formatValue(item.value) }),
1847
+ /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: item.confidence }),
1848
+ /* @__PURE__ */ jsx3(
1279
1849
  EyeButton,
1280
1850
  {
1281
1851
  coordinates: item.coordinates,
@@ -1296,20 +1866,20 @@ function EntitySection(props) {
1296
1866
  const { entity, shared } = props;
1297
1867
  const label = formatLabel(entity.key);
1298
1868
  const singular = label.replace(/s$/, "");
1299
- return /* @__PURE__ */ jsxs2("section", { className: "gemina-verification__section", "aria-label": label, children: [
1300
- /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__section-header", children: [
1869
+ return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": label, children: [
1870
+ /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__section-header", children: [
1301
1871
  label,
1302
1872
  " (",
1303
1873
  entity.items.length,
1304
1874
  ")"
1305
1875
  ] }),
1306
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__card", children: [
1307
- /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__card-header", children: [
1876
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__card", children: [
1877
+ /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__card-header", children: [
1308
1878
  singular,
1309
1879
  " ",
1310
1880
  itemIndex + 1
1311
1881
  ] }),
1312
- /* @__PURE__ */ jsx2("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ jsx2(
1882
+ /* @__PURE__ */ jsx3("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ jsx3(
1313
1883
  FieldPair,
1314
1884
  {
1315
1885
  label: formatLabel(fieldKey),
@@ -1323,11 +1893,11 @@ function EntitySection(props) {
1323
1893
  ] });
1324
1894
  }
1325
1895
  function TableRowView(props) {
1326
- const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared } = props;
1896
+ const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared, planned, tablePointer } = props;
1327
1897
  const { bindingIndex, edits, onEdit, readOnly, onFlash } = shared;
1328
1898
  const rects = React.useMemo(() => {
1329
1899
  const collected = [];
1330
- for (const [key, cell] of Object.entries(row)) {
1900
+ for (const [key, cell] of Object.entries(row ?? {})) {
1331
1901
  if (key !== ROW_META_KEY && cell.coordinates) {
1332
1902
  collected.push(cell.coordinates);
1333
1903
  }
@@ -1345,49 +1915,126 @@ function TableRowView(props) {
1345
1915
  },
1346
1916
  [rects, onFlash]
1347
1917
  );
1918
+ const cellFor = (column) => {
1919
+ const classified = row?.[column];
1920
+ const fromPlan = planned?.cells.find((cell) => cell.column === column);
1921
+ if (fromPlan) {
1922
+ return { classified, binding: fromPlan.binding, editKey: fromPlan.editKey };
1923
+ }
1924
+ const binding = classified === void 0 ? void 0 : bindingIndex.get(classified.pointer);
1925
+ return { classified, binding, editKey: binding?.key.raw };
1926
+ };
1348
1927
  const firstRect = rects.length > 0 ? rects[0] : null;
1349
- return /* @__PURE__ */ jsxs2("tr", { onClick: handleRowClick, children: [
1350
- hasCoords ? /* @__PURE__ */ jsx2("td", { children: /* @__PURE__ */ jsx2(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
1351
- hasRowConfidence ? /* @__PURE__ */ jsx2("td", { children: /* @__PURE__ */ jsx2(ConfidenceDot, { confidence: row[ROW_META_KEY]?.confidence ?? null }) }) : null,
1928
+ const showControls = planned !== void 0 && tablePointer !== void 0 && !readOnly;
1929
+ const rowLevel = (row?.[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
1930
+ const rowClass = rowLevel === "low" || rowLevel === "medium" ? `gemina-verification__row--${rowLevel}` : void 0;
1931
+ return /* @__PURE__ */ jsxs3("tr", { onClick: handleRowClick, className: rowClass, children: [
1932
+ hasCoords ? /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsx3(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
1933
+ hasRowConfidence ? /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: row?.[ROW_META_KEY]?.confidence ?? null }) }) : null,
1352
1934
  columns.map((column) => {
1353
- const cell = row[column];
1354
- const binding = cell === void 0 ? void 0 : bindingIndex.get(cell.pointer);
1355
- return /* @__PURE__ */ jsx2("td", { children: /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__cell", children: [
1356
- binding !== void 0 ? /* @__PURE__ */ jsx2(
1935
+ const { classified, binding, editKey } = cellFor(column);
1936
+ return /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__cell", children: [
1937
+ binding !== void 0 ? /* @__PURE__ */ jsx3(
1357
1938
  FieldInput,
1358
1939
  {
1359
1940
  binding,
1360
- edit: edits.get(binding.key.raw),
1941
+ editKey,
1942
+ pairError: editKey === void 0 ? void 0 : shared.pairErrors.get(editKey),
1943
+ edit: editKey === void 0 ? void 0 : edits.get(editKey),
1361
1944
  onEdit,
1362
1945
  readOnly,
1363
1946
  ariaLabel: `${tableLabel} row ${rowIndex + 1} \u2014 ${formatLabel(column)}`
1364
1947
  }
1365
- ) : /* @__PURE__ */ jsx2("span", { children: cell === void 0 ? "-" : formatValue(cell.value, column) }),
1366
- /* @__PURE__ */ jsx2(ConfidenceDot, { confidence: cell?.confidence ?? null })
1948
+ ) : /* @__PURE__ */ jsx3("span", { children: classified === void 0 ? "-" : formatValue(classified.value, column) }),
1949
+ /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: classified?.confidence ?? null })
1367
1950
  ] }) }, column);
1368
- })
1951
+ }),
1952
+ showControls ? /* @__PURE__ */ jsxs3("td", { className: "gemina-verification__row-actions", children: [
1953
+ /* @__PURE__ */ jsx3(Tip, { content: "Insert a line below", children: /* @__PURE__ */ jsx3(
1954
+ "button",
1955
+ {
1956
+ type: "button",
1957
+ className: "gemina-verification__row-btn",
1958
+ "aria-label": `Insert line below line ${rowIndex + 1}`,
1959
+ onClick: () => shared.onAddRow(tablePointer, rowIndex),
1960
+ children: "+"
1961
+ }
1962
+ ) }),
1963
+ /* @__PURE__ */ jsx3(Tip, { content: "Remove this line", children: /* @__PURE__ */ jsx3(
1964
+ "button",
1965
+ {
1966
+ type: "button",
1967
+ className: "gemina-verification__row-btn",
1968
+ "aria-label": `Remove line ${rowIndex + 1}`,
1969
+ onClick: () => shared.onRemoveRow(tablePointer, rowIndex),
1970
+ children: "\xD7"
1971
+ }
1972
+ ) })
1973
+ ] }) : null
1369
1974
  ] });
1370
1975
  }
1371
1976
  function areRowPropsEqual(prev, next) {
1372
- if (prev.row !== next.row || prev.rowIndex !== next.rowIndex || prev.columns !== next.columns || prev.tableLabel !== next.tableLabel || prev.hasCoords !== next.hasCoords || prev.hasRowConfidence !== next.hasRowConfidence || prev.shared.bindingIndex !== next.shared.bindingIndex || prev.shared.onEdit !== next.shared.onEdit || prev.shared.onFlash !== next.shared.onFlash || prev.shared.readOnly !== next.shared.readOnly) {
1977
+ if (prev.row !== next.row || prev.rowIndex !== next.rowIndex || prev.columns !== next.columns || prev.tableLabel !== next.tableLabel || prev.hasCoords !== next.hasCoords || prev.hasRowConfidence !== next.hasRowConfidence || prev.planned !== next.planned || prev.tablePointer !== next.tablePointer || prev.shared.bindingIndex !== next.shared.bindingIndex || prev.shared.onEdit !== next.shared.onEdit || prev.shared.onFlash !== next.shared.onFlash || prev.shared.readOnly !== next.shared.readOnly) {
1373
1978
  return false;
1374
1979
  }
1375
1980
  if (prev.shared.edits === next.shared.edits) {
1376
1981
  return true;
1377
1982
  }
1378
1983
  for (const column of next.columns) {
1379
- const cell = next.row[column];
1380
- const binding = cell === void 0 ? void 0 : next.shared.bindingIndex.get(cell.pointer);
1381
- if (binding !== void 0 && prev.shared.edits.get(binding.key.raw) !== next.shared.edits.get(binding.key.raw)) {
1984
+ const planned = next.planned?.cells.find((cell) => cell.column === column);
1985
+ const classified = next.row?.[column];
1986
+ const editKey = planned?.editKey ?? (classified === void 0 ? void 0 : next.shared.bindingIndex.get(classified.pointer)?.key.raw);
1987
+ if (editKey === void 0) {
1988
+ continue;
1989
+ }
1990
+ if (prev.shared.edits.get(editKey) !== next.shared.edits.get(editKey) || prev.shared.pairErrors.get(editKey) !== next.shared.pairErrors.get(editKey)) {
1382
1991
  return false;
1383
1992
  }
1384
1993
  }
1385
1994
  return true;
1386
1995
  }
1387
1996
  var TableRow = React.memo(TableRowView, areRowPropsEqual);
1997
+ function withEmptyMutableTables(classified, tables) {
1998
+ if (tables.length === 0) {
1999
+ return { tables: classified.tables, suppressed: EMPTY_SUPPRESSED };
2000
+ }
2001
+ const promoted = [...classified.tables];
2002
+ const suppressed = /* @__PURE__ */ new Set();
2003
+ for (const table of tables) {
2004
+ if (classified.tables.some((candidate) => matchesTablePointer(table.pointer, candidate.pointer))) {
2005
+ continue;
2006
+ }
2007
+ const header = classified.headers.find(
2008
+ (candidate) => matchesTablePointer(table.pointer, candidate.pointer)
2009
+ );
2010
+ const empty = header !== void 0 && (header.value === null || Array.isArray(header.value) && header.value.length === 0);
2011
+ if (!empty) {
2012
+ continue;
2013
+ }
2014
+ suppressed.add(header.pointer);
2015
+ promoted.push({
2016
+ key: header.key,
2017
+ pointer: header.pointer,
2018
+ columns: [],
2019
+ rows: [],
2020
+ overallConfidence: null
2021
+ });
2022
+ }
2023
+ return { tables: promoted, suppressed };
2024
+ }
2025
+ var EMPTY_SUPPRESSED = /* @__PURE__ */ new Set();
1388
2026
  function TableSection(props) {
1389
2027
  const { table, shared } = props;
1390
2028
  const label = formatLabel(table.key);
2029
+ const mutable = React.useMemo(
2030
+ () => shared.rowMutableTables.find((entry) => matchesTablePointer(entry.pointer, table.pointer)),
2031
+ [shared.rowMutableTables, table.pointer]
2032
+ );
2033
+ const columns = React.useMemo(
2034
+ () => mutable ? displayColumns(mutable, table.columns) : table.columns,
2035
+ [mutable, table.columns]
2036
+ );
2037
+ const planned = mutable ? shared.plannedTables.get(mutable.pointer) : void 0;
1391
2038
  const hasCoords = React.useMemo(
1392
2039
  () => table.rows.some(
1393
2040
  (row) => Object.entries(row).some(([key, cell]) => key !== ROW_META_KEY && cell.coordinates !== null)
@@ -1398,28 +2045,69 @@ function TableSection(props) {
1398
2045
  () => table.rows.some((row) => Boolean(row[ROW_META_KEY]?.confidence?.level)),
1399
2046
  [table]
1400
2047
  );
1401
- return /* @__PURE__ */ jsxs2("section", { className: "gemina-verification__section", "aria-label": label, children: [
1402
- /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__section-header", children: [
1403
- /* @__PURE__ */ jsxs2("span", { children: [
2048
+ const columnDescriptions = React.useMemo(() => {
2049
+ const map = /* @__PURE__ */ new Map();
2050
+ for (const column of mutable?.columns ?? []) {
2051
+ if (typeof column.key === "string" && column.description) {
2052
+ map.set(column.key, column.description);
2053
+ }
2054
+ }
2055
+ return map;
2056
+ }, [mutable]);
2057
+ const rowCount = planned ? planned.length : table.rows.length;
2058
+ const needsReview = React.useMemo(
2059
+ () => table.rows.filter((row) => {
2060
+ const level = (row[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
2061
+ return level === "low" || level === "medium";
2062
+ }).length,
2063
+ [table.rows]
2064
+ );
2065
+ const showControls = planned !== void 0 && mutable !== void 0 && !shared.readOnly;
2066
+ return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": label, children: [
2067
+ /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__section-header", children: [
2068
+ /* @__PURE__ */ jsxs3("span", { children: [
1404
2069
  label,
1405
2070
  " (",
1406
- table.rows.length,
1407
- " rows)"
2071
+ rowCount,
2072
+ " rows",
2073
+ needsReview > 0 ? ` \xB7 ${needsReview} need review` : "",
2074
+ ")"
1408
2075
  ] }),
1409
- /* @__PURE__ */ jsx2(ConfidenceDot, { confidence: table.overallConfidence })
2076
+ /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: table.overallConfidence })
1410
2077
  ] }),
1411
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ jsxs2("table", { className: "gemina-verification__table", children: [
1412
- /* @__PURE__ */ jsx2("thead", { children: /* @__PURE__ */ jsxs2("tr", { children: [
1413
- hasCoords ? /* @__PURE__ */ jsx2("th", { "aria-label": "Show row on document" }) : null,
1414
- hasRowConfidence ? /* @__PURE__ */ jsx2("th", { "aria-label": "Row confidence" }) : null,
1415
- table.columns.map((column) => /* @__PURE__ */ jsx2("th", { children: formatLabel(column) }, column))
2078
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ jsxs3("table", { className: "gemina-verification__table", children: [
2079
+ /* @__PURE__ */ jsx3("thead", { children: /* @__PURE__ */ jsxs3("tr", { children: [
2080
+ hasCoords ? /* @__PURE__ */ jsx3("th", { "aria-label": "Show row on document" }) : null,
2081
+ hasRowConfidence ? /* @__PURE__ */ jsx3("th", { "aria-label": "Row confidence" }) : null,
2082
+ columns.map((column) => /* @__PURE__ */ jsx3("th", { children: /* @__PURE__ */ jsx3(
2083
+ FieldLabel,
2084
+ {
2085
+ label: formatLabel(column),
2086
+ description: columnDescriptions.get(column)
2087
+ }
2088
+ ) }, column)),
2089
+ showControls ? /* @__PURE__ */ jsx3("th", { "aria-label": "Row actions" }) : null
1416
2090
  ] }) }),
1417
- /* @__PURE__ */ jsx2("tbody", { children: table.rows.map((row, rowIndex) => /* @__PURE__ */ jsx2(
2091
+ /* @__PURE__ */ jsx3("tbody", { children: planned ? planned.map((plannedRow, position) => /* @__PURE__ */ jsx3(
2092
+ TableRow,
2093
+ {
2094
+ row: plannedRow.entry.source === null ? void 0 : table.rows[plannedRow.entry.source],
2095
+ rowIndex: position,
2096
+ columns,
2097
+ tableLabel: label,
2098
+ hasCoords,
2099
+ hasRowConfidence,
2100
+ shared,
2101
+ planned: plannedRow,
2102
+ tablePointer: mutable.pointer
2103
+ },
2104
+ plannedRow.entry.id
2105
+ )) : table.rows.map((row, rowIndex) => /* @__PURE__ */ jsx3(
1418
2106
  TableRow,
1419
2107
  {
1420
2108
  row,
1421
2109
  rowIndex,
1422
- columns: table.columns,
2110
+ columns,
1423
2111
  tableLabel: label,
1424
2112
  hasCoords,
1425
2113
  hasRowConfidence,
@@ -1427,7 +2115,16 @@ function TableSection(props) {
1427
2115
  },
1428
2116
  rowIndex
1429
2117
  )) })
1430
- ] }) })
2118
+ ] }) }),
2119
+ showControls ? /* @__PURE__ */ jsx3("div", { className: "gemina-verification__table-footer", children: /* @__PURE__ */ jsx3(
2120
+ "button",
2121
+ {
2122
+ type: "button",
2123
+ className: "gemina-verification__add-row",
2124
+ onClick: () => shared.onAddRow(mutable.pointer, rowCount - 1),
2125
+ children: "Add line"
2126
+ }
2127
+ ) }) : null
1431
2128
  ] });
1432
2129
  }
1433
2130
  var FallbackSection = React.memo(function FallbackSection2(props) {
@@ -1435,11 +2132,11 @@ var FallbackSection = React.memo(function FallbackSection2(props) {
1435
2132
  if (fallback.length === 0) {
1436
2133
  return null;
1437
2134
  }
1438
- return /* @__PURE__ */ jsxs2("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
1439
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
1440
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ jsxs2("details", { className: "gemina-verification__fallback", children: [
1441
- /* @__PURE__ */ jsx2("summary", { children: formatLabel(item.key) }),
1442
- /* @__PURE__ */ jsx2("pre", { children: JSON.stringify(item.data, null, 2) })
2135
+ return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
2136
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
2137
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ jsxs3("details", { className: "gemina-verification__fallback", children: [
2138
+ /* @__PURE__ */ jsx3("summary", { children: formatLabel(item.key) }),
2139
+ /* @__PURE__ */ jsx3("pre", { children: JSON.stringify(item.data, null, 2) })
1443
2140
  ] }, item.key)) })
1444
2141
  ] });
1445
2142
  });
@@ -1448,14 +2145,15 @@ function UnmatchedSection(props) {
1448
2145
  if (unmatched.length === 0) {
1449
2146
  return null;
1450
2147
  }
1451
- return /* @__PURE__ */ jsxs2("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
1452
- /* @__PURE__ */ jsx2("div", { className: "gemina-verification__section-header", children: "Not detected" }),
1453
- /* @__PURE__ */ jsx2("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ jsxs2(React.Fragment, { children: [
1454
- /* @__PURE__ */ jsx2("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx2("span", { children: binding.key.label }) }),
1455
- /* @__PURE__ */ jsx2("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx2(
2148
+ return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
2149
+ /* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Not detected" }),
2150
+ /* @__PURE__ */ jsx3("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ jsxs3(React.Fragment, { children: [
2151
+ /* @__PURE__ */ jsx3("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx3("span", { children: binding.key.label }) }),
2152
+ /* @__PURE__ */ jsx3("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx3(
1456
2153
  FieldInput,
1457
2154
  {
1458
2155
  binding,
2156
+ pairError: shared.pairErrors.get(binding.key.raw),
1459
2157
  edit: shared.edits.get(binding.key.raw),
1460
2158
  onEdit: shared.onEdit,
1461
2159
  readOnly: shared.readOnly,
@@ -1466,26 +2164,61 @@ function UnmatchedSection(props) {
1466
2164
  ] });
1467
2165
  }
1468
2166
  function VerificationForm(props) {
1469
- const { classified, unmatched, bindingIndex, edits, onEdit, readOnly, onFlash } = props;
1470
- const shared = { bindingIndex, edits, onEdit, readOnly, onFlash };
2167
+ const {
2168
+ classified,
2169
+ unmatched,
2170
+ bindingIndex,
2171
+ edits,
2172
+ onEdit,
2173
+ readOnly,
2174
+ onFlash,
2175
+ pairErrors,
2176
+ rowMutableTables,
2177
+ plannedTables,
2178
+ onAddRow,
2179
+ onRemoveRow
2180
+ } = props;
2181
+ const { tables: promotedTables, suppressed } = React.useMemo(
2182
+ () => withEmptyMutableTables(classified, rowMutableTables ?? NO_TABLES),
2183
+ [classified, rowMutableTables]
2184
+ );
2185
+ const shared = {
2186
+ bindingIndex,
2187
+ edits,
2188
+ onEdit,
2189
+ readOnly,
2190
+ onFlash,
2191
+ pairErrors: pairErrors ?? NO_PAIR_ERRORS,
2192
+ rowMutableTables: rowMutableTables ?? NO_TABLES,
2193
+ plannedTables: plannedTables ?? NO_PLANNED,
2194
+ onAddRow: onAddRow ?? NOOP_ROW,
2195
+ onRemoveRow: onRemoveRow ?? NOOP_ROW
2196
+ };
1471
2197
  return (
1472
2198
  // A real, labeled <form> (role "form" landmark): AT users can jump
1473
2199
  // straight to the editable fields. Submission is owned by the root's
1474
2200
  // footer button, never by the form element itself — preventDefault stops
1475
2201
  // implicit submission (Enter in a payload with exactly one input would
1476
2202
  // otherwise navigate).
1477
- /* @__PURE__ */ jsxs2(
2203
+ /* @__PURE__ */ jsxs3(
1478
2204
  "form",
1479
2205
  {
1480
2206
  className: "gemina-verification__form",
1481
2207
  "aria-label": "Extraction fields",
1482
2208
  onSubmit: (event) => event.preventDefault(),
1483
2209
  children: [
1484
- /* @__PURE__ */ jsx2(HeaderSection, { headers: classified.headers, simpleLists: classified.simpleLists, shared }),
1485
- classified.entities.map((entity) => /* @__PURE__ */ jsx2(EntitySection, { entity, shared }, entity.pointer)),
1486
- classified.tables.map((table) => /* @__PURE__ */ jsx2(TableSection, { table, shared }, table.pointer)),
1487
- /* @__PURE__ */ jsx2(FallbackSection, { fallback: classified.fallback }),
1488
- /* @__PURE__ */ jsx2(UnmatchedSection, { unmatched, shared })
2210
+ /* @__PURE__ */ jsx3(
2211
+ HeaderSection,
2212
+ {
2213
+ headers: classified.headers.filter((header) => !suppressed.has(header.pointer)),
2214
+ simpleLists: classified.simpleLists,
2215
+ shared
2216
+ }
2217
+ ),
2218
+ classified.entities.map((entity) => /* @__PURE__ */ jsx3(EntitySection, { entity, shared }, entity.pointer)),
2219
+ promotedTables.map((table) => /* @__PURE__ */ jsx3(TableSection, { table, shared }, table.pointer)),
2220
+ /* @__PURE__ */ jsx3(FallbackSection, { fallback: classified.fallback }),
2221
+ /* @__PURE__ */ jsx3(UnmatchedSection, { unmatched, shared })
1489
2222
  ]
1490
2223
  }
1491
2224
  )
@@ -1749,6 +2482,10 @@ var VERIFICATION_CSS = `
1749
2482
  }
1750
2483
  .gemina-verification__dd {
1751
2484
  display: flex;
2485
+ /* Wrap so a field error takes its OWN line (it sets flex-basis:100%).
2486
+ Without this it competes with the input for width, and at 390px the
2487
+ message wrapped to one word per line while the input shrank to ~55px. */
2488
+ flex-wrap: wrap;
1752
2489
  align-items: center;
1753
2490
  gap: 6px;
1754
2491
  margin: 0; /* resets the UA's margin-inline-start on <dd> */
@@ -1823,6 +2560,7 @@ var VERIFICATION_CSS = `
1823
2560
  and list items \u2014 the fragment has no container of its own. */
1824
2561
  .gemina-verification__cell {
1825
2562
  display: flex;
2563
+ flex-wrap: wrap; /* same reason as __dd: the field error needs its own line */
1826
2564
  align-items: center;
1827
2565
  gap: 6px;
1828
2566
  min-width: 0;
@@ -2083,6 +2821,157 @@ var VERIFICATION_CSS = `
2083
2821
  transition: none;
2084
2822
  }
2085
2823
  }
2824
+
2825
+ /* A label that carries a description. Dotted underline is the long-standing
2826
+ convention for "there is more here", and tabIndex makes it reachable, so the
2827
+ tooltip is not mouse-only. */
2828
+ .gemina-verification__label-described {
2829
+ text-decoration: underline dotted;
2830
+ text-underline-offset: 3px;
2831
+ cursor: help;
2832
+ }
2833
+ .gemina-verification__label-described:focus-visible {
2834
+ outline: 2px solid var(--gemina-verification-accent);
2835
+ outline-offset: 2px;
2836
+ }
2837
+
2838
+ /* Rows worth a second look. Uses the EXISTING confidence tokens \u2014 no new
2839
+ colours \u2014 as a start-edge rule, which is the one edge a reviewer scans down
2840
+ a long table. Logical property, so it lands on the right side under RTL. */
2841
+ .gemina-verification__row--low > td:first-child,
2842
+ .gemina-verification__row--medium > td:first-child {
2843
+ border-inline-start: 3px solid transparent;
2844
+ }
2845
+ .gemina-verification__row--low > td:first-child {
2846
+ border-inline-start-color: var(--gemina-verification-confidence-low);
2847
+ }
2848
+ .gemina-verification__row--medium > td:first-child {
2849
+ border-inline-start-color: var(--gemina-verification-confidence-medium);
2850
+ }
2851
+
2852
+ /* --- Row editing ----------------------------------------------------------
2853
+ Quiet by design: adding and removing lines is a correction, not the primary
2854
+ action, so the controls stay muted until hovered and the accent is left to
2855
+ Submit. */
2856
+ .gemina-verification__row-actions {
2857
+ white-space: nowrap;
2858
+ text-align: end; /* logical \u2014 RTL for free */
2859
+ }
2860
+ .gemina-verification__row-btn {
2861
+ font: inherit;
2862
+ line-height: 1;
2863
+ padding: 2px 7px;
2864
+ margin-inline-start: 4px;
2865
+ border-radius: calc(var(--gemina-verification-radius) - 5px);
2866
+ border: 1px solid var(--gemina-verification-border);
2867
+ background: transparent;
2868
+ color: var(--gemina-verification-muted);
2869
+ cursor: pointer;
2870
+ transition: border-color 120ms ease, color 120ms ease;
2871
+ }
2872
+ .gemina-verification__row-btn:hover {
2873
+ border-color: var(--gemina-verification-accent);
2874
+ color: var(--gemina-verification-fg);
2875
+ }
2876
+ .gemina-verification__table-footer {
2877
+ display: flex;
2878
+ padding: 8px 10px 0;
2879
+ }
2880
+ .gemina-verification__add-row {
2881
+ font: inherit;
2882
+ font-size: 12px;
2883
+ padding: 4px 10px;
2884
+ border-radius: calc(var(--gemina-verification-radius) - 4px);
2885
+ border: 1px dashed var(--gemina-verification-border);
2886
+ background: transparent;
2887
+ color: var(--gemina-verification-muted);
2888
+ cursor: pointer;
2889
+ }
2890
+ .gemina-verification__add-row:hover {
2891
+ border-style: solid;
2892
+ border-color: var(--gemina-verification-accent);
2893
+ color: var(--gemina-verification-fg);
2894
+ }
2895
+
2896
+ /* --- Typed controls -------------------------------------------------------
2897
+ A <select> for a closed roster must sit on the same baseline as the text
2898
+ inputs beside it in a table row, so it inherits the input's box entirely and
2899
+ only overrides what a select needs. */
2900
+ .gemina-verification__input:is(select) {
2901
+ cursor: pointer;
2902
+ /* A select's intrinsic width follows its longest option \u2014 the 24-member unit
2903
+ roster would blow out the column. */
2904
+ max-width: 100%;
2905
+ }
2906
+ /* The error border must beat --dirty and --missed: an invalid value is the
2907
+ most urgent thing true about the field, and the reviewer cannot submit
2908
+ until it is fixed. Placed after both for cascade order. */
2909
+ .gemina-verification__input--invalid,
2910
+ .gemina-verification__input--invalid:focus-visible {
2911
+ border-color: var(--gemina-verification-error);
2912
+ }
2913
+ /* Sits under the control it describes. Basis 100% breaks it onto its own line
2914
+ inside the flex row FieldInput renders into, so it never squeezes the
2915
+ input. */
2916
+ .gemina-verification__field-error {
2917
+ flex-basis: 100%;
2918
+ margin-block-start: 4px;
2919
+ color: var(--gemina-verification-error);
2920
+ font-size: 12px;
2921
+ line-height: 1.35;
2922
+ }
2923
+
2924
+ /* Replaces __progress while anything is invalid \u2014 same slot, so the footer
2925
+ never grows a second status line competing for the same attention. */
2926
+ .gemina-verification__attention {
2927
+ color: var(--gemina-verification-error);
2928
+ font-size: 13px;
2929
+ }
2930
+
2931
+ /* --- Tooltip -------------------------------------------------------------
2932
+ Renders in a portal on document.body, inside a div carrying the root's
2933
+ class list \u2014 so these rules and every --gemina-verification-* custom
2934
+ property resolve exactly as they do in the component.
2935
+
2936
+ Quieter than __confirm-dialog on purpose: an annotation, not a decision.
2937
+ Same border and shadow family, one step down in radius (the nested-element
2938
+ convention used by __chip et al), surface rather than bg so it separates
2939
+ from the panel it floats over, and a shorter shadow so it reads as sitting
2940
+ just above the page rather than over a scrim. */
2941
+ .gemina-verification__tip {
2942
+ position: fixed;
2943
+ z-index: 2147483000; /* above the host's own modal \u2014 this is the topmost layer */
2944
+ max-width: 260px; /* ~60 characters: past that a tooltip should be body copy */
2945
+ padding: 8px 10px;
2946
+ background: var(--gemina-verification-surface);
2947
+ color: var(--gemina-verification-fg);
2948
+ border: 1px solid var(--gemina-verification-border);
2949
+ border-radius: calc(var(--gemina-verification-radius) - 4px);
2950
+ box-shadow: 0 6px 16px rgba(16, 20, 24, 0.18);
2951
+ font-family: var(--gemina-verification-font);
2952
+ font-size: 12px;
2953
+ line-height: 1.45;
2954
+ text-align: start; /* logical \u2014 RTL for free */
2955
+ pointer-events: none; /* never eat the hover that opened it */
2956
+ }
2957
+ /* Structured content: a level heading over a reasons list. The list is the
2958
+ reason this exists at all \u2014 title= could only ever have been one line. */
2959
+ .gemina-verification__tip-title {
2960
+ display: block;
2961
+ font-weight: 600;
2962
+ margin-block-end: 4px;
2963
+ }
2964
+ .gemina-verification__tip-list {
2965
+ margin: 0;
2966
+ padding-inline-start: 16px;
2967
+ }
2968
+ .gemina-verification__tip-list li + li {
2969
+ margin-block-start: 2px;
2970
+ }
2971
+ /* A muted lead-in for single-fact tips ("Was:"), so the VALUE reads first. */
2972
+ .gemina-verification__tip-label {
2973
+ color: var(--gemina-verification-muted);
2974
+ }
2086
2975
  `;
2087
2976
  var STYLE_ATTR = "data-gemina-verification";
2088
2977
  function ensureVerificationStylesInjected() {
@@ -2099,7 +2988,7 @@ function ensureVerificationStylesInjected() {
2099
2988
  }
2100
2989
 
2101
2990
  // src/verification/index.tsx
2102
- import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2991
+ import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
2103
2992
  var HEBREW_RE = /[\u0590-\u05FF]/;
2104
2993
  var STACKED_BREAKPOINT = 860;
2105
2994
  var IMAGE_REFRESH_THROTTLE_MS = 6e4;
@@ -2112,11 +3001,23 @@ var PURGED_TEXT = "Document no longer available (retention policy).";
2112
3001
  var NOT_COMPLETED_TEXT = "This extraction did not complete, so there is nothing to verify.";
2113
3002
  var VERIFICATION_UNAVAILABLE_TEXT = "Verification isn't available for this extraction.";
2114
3003
  var ALREADY_VALIDATED_TEXT = "Already verified \u2014 showing the original extraction.";
2115
- var CONFIRM_TEXT = "Submit verification? This is final \u2014 feedback can be submitted only once and cannot be changed.";
3004
+ var CONFIRM_TEXT = "Submit these values? This is final \u2014 they can be submitted once and can't be changed.";
2116
3005
  var SUBMITTING_TEXT = "Submitting\u2026";
2117
3006
  var SUBMIT_FAILED_TEXT = "Submission failed \u2014 your corrections are still here.";
2118
- var DONE_TITLE_TEXT = "Feedback submitted";
3007
+ var DONE_TITLE_TEXT = "Submitted";
2119
3008
  var NO_EDITS = /* @__PURE__ */ new Map();
3009
+ var NO_ROW_PLANS = /* @__PURE__ */ new Map();
3010
+ var NO_PLANNED_TABLES = /* @__PURE__ */ new Map();
3011
+ function seedRowPlans(tables, values) {
3012
+ if (tables.length === 0) {
3013
+ return NO_ROW_PLANS;
3014
+ }
3015
+ const plans = /* @__PURE__ */ new Map();
3016
+ for (const table of tables) {
3017
+ plans.set(table.pointer, initialRowPlan(countRowsAt(values, table.pointer), table.pointer));
3018
+ }
3019
+ return plans;
3020
+ }
2120
3021
  var ALERT_REASONS = /* @__PURE__ */ new Set([
2121
3022
  "session-expired",
2122
3023
  "not-available",
@@ -2133,43 +3034,44 @@ function GeminaVerification(props) {
2133
3034
  onError,
2134
3035
  className
2135
3036
  } = props;
2136
- const [phase, setPhase] = useState2({ name: "loading" });
2137
- const [alreadyValidated, setAlreadyValidated] = useState2(false);
2138
- const [loaded, setLoaded] = useState2(null);
2139
- const [edits, setEdits] = useState2(NO_EDITS);
2140
- const [imageUrl, setImageUrl] = useState2(null);
2141
- const [flashRects, setFlashRects] = useState2(null);
2142
- const [stacked, setStacked] = useState2(false);
2143
- const rootRef = useRef2(null);
2144
- const mountedRef = useRef2(false);
2145
- const loadSeqRef = useRef2(0);
2146
- const lastImageRefreshRef = useRef2(0);
2147
- const onErrorRef = useRef2(onError);
3037
+ const [phase, setPhase] = useState3({ name: "loading" });
3038
+ const [alreadyValidated, setAlreadyValidated] = useState3(false);
3039
+ const [loaded, setLoaded] = useState3(null);
3040
+ const [rowPlans, setRowPlans] = useState3(NO_ROW_PLANS);
3041
+ const [edits, setEdits] = useState3(NO_EDITS);
3042
+ const [imageUrl, setImageUrl] = useState3(null);
3043
+ const [flashRects, setFlashRects] = useState3(null);
3044
+ const [stacked, setStacked] = useState3(false);
3045
+ const rootRef = useRef3(null);
3046
+ const mountedRef = useRef3(false);
3047
+ const loadSeqRef = useRef3(0);
3048
+ const lastImageRefreshRef = useRef3(0);
3049
+ const onErrorRef = useRef3(onError);
2148
3050
  onErrorRef.current = onError;
2149
- const onCompleteRef = useRef2(onComplete);
3051
+ const onCompleteRef = useRef3(onComplete);
2150
3052
  onCompleteRef.current = onComplete;
2151
- const completedRef = useRef2(false);
2152
- const submitInFlightRef = useRef2(false);
2153
- const restoreFocusRef = useRef2(false);
2154
- const submitButtonRef = useRef2(null);
2155
- const confirmButtonRef = useRef2(null);
2156
- const cancelButtonRef = useRef2(null);
2157
- const retrySubmitButtonRef = useRef2(null);
2158
- const doneStateRef = useRef2(null);
2159
- const enterUnavailable = useCallback2(
3053
+ const completedRef = useRef3(false);
3054
+ const submitInFlightRef = useRef3(false);
3055
+ const restoreFocusRef = useRef3(false);
3056
+ const submitButtonRef = useRef3(null);
3057
+ const confirmButtonRef = useRef3(null);
3058
+ const cancelButtonRef = useRef3(null);
3059
+ const retrySubmitButtonRef = useRef3(null);
3060
+ const doneStateRef = useRef3(null);
3061
+ const enterUnavailable = useCallback3(
2160
3062
  (reason, message, canRetry, detail) => {
2161
3063
  setPhase({ name: "unavailable", reason, message, canRetry });
2162
3064
  onErrorRef.current?.(reason, detail);
2163
3065
  },
2164
3066
  []
2165
3067
  );
2166
- const fetchOnce = useCallback2(async () => {
3068
+ const fetchOnce = useCallback3(async () => {
2167
3069
  const token = await tokenManager.getToken();
2168
3070
  return GeminaClient.withSessionToken(token, baseUrl).documents.getDocumentExtraction({
2169
3071
  documentExtractionId: extractionId
2170
3072
  });
2171
3073
  }, [tokenManager, baseUrl, extractionId]);
2172
- const fetchWithRetry = useCallback2(async () => {
3074
+ const fetchWithRetry = useCallback3(async () => {
2173
3075
  try {
2174
3076
  return await fetchOnce();
2175
3077
  } catch (error) {
@@ -2180,7 +3082,7 @@ function GeminaVerification(props) {
2180
3082
  return await fetchOnce();
2181
3083
  }
2182
3084
  }, [fetchOnce, tokenManager]);
2183
- const load = useCallback2(async () => {
3085
+ const load = useCallback3(async () => {
2184
3086
  const seq = ++loadSeqRef.current;
2185
3087
  const live = () => mountedRef.current && loadSeqRef.current === seq;
2186
3088
  setPhase({ name: "loading" });
@@ -2211,9 +3113,12 @@ function GeminaVerification(props) {
2211
3113
  const schema = view.meta.validationFeedback?.validationSchema;
2212
3114
  setLoaded({
2213
3115
  values: view.values,
2214
- schema: Array.isArray(schema) ? schema : []
3116
+ schema: Array.isArray(schema) ? schema : [],
3117
+ fields: readDescriptors(view.meta.validationFeedback?.validationFields),
3118
+ rowMutableTables: readRowMutableTables(view.meta.validationFeedback?.rowMutableTables)
2215
3119
  });
2216
3120
  setEdits(NO_EDITS);
3121
+ setRowPlans(seedRowPlans(readRowMutableTables(view.meta.validationFeedback?.rowMutableTables), view.values));
2217
3122
  const url = view.document.imageUrl;
2218
3123
  setImageUrl(typeof url === "string" && url.length > 0 ? url : null);
2219
3124
  setAlreadyValidated(validated);
@@ -2231,7 +3136,7 @@ function GeminaVerification(props) {
2231
3136
  enterReview(false);
2232
3137
  }
2233
3138
  }, [fetchWithRetry, enterUnavailable]);
2234
- useEffect2(() => {
3139
+ useEffect3(() => {
2235
3140
  mountedRef.current = true;
2236
3141
  ensureVerificationStylesInjected();
2237
3142
  void load();
@@ -2239,7 +3144,7 @@ function GeminaVerification(props) {
2239
3144
  mountedRef.current = false;
2240
3145
  };
2241
3146
  }, [load]);
2242
- useEffect2(() => {
3147
+ useEffect3(() => {
2243
3148
  const el = rootRef.current;
2244
3149
  if (el === null) {
2245
3150
  return;
@@ -2261,8 +3166,18 @@ function GeminaVerification(props) {
2261
3166
  return () => observer.disconnect();
2262
3167
  }, []);
2263
3168
  const classified = useMemo(() => classifyData(loaded?.values), [loaded]);
2264
- const bindings = useMemo(() => buildBindings(loaded?.schema ?? [], loaded?.values), [loaded]);
3169
+ const bindings = useMemo(
3170
+ () => buildBindings(loaded?.schema ?? [], loaded?.values, loaded?.fields),
3171
+ [loaded]
3172
+ );
2265
3173
  const bindingIndex = useMemo(() => indexBindingsByFieldPointer(bindings), [bindings]);
3174
+ const bindingsByRawKey = useMemo(() => {
3175
+ const map = /* @__PURE__ */ new Map();
3176
+ for (const binding of bindings) {
3177
+ map.set(binding.key.raw, binding);
3178
+ }
3179
+ return map;
3180
+ }, [bindings]);
2266
3181
  const unmatched = useMemo(() => {
2267
3182
  const rendered = /* @__PURE__ */ new Set();
2268
3183
  for (const field of classified.headers) {
@@ -2330,43 +3245,82 @@ function GeminaVerification(props) {
2330
3245
  [bindings]
2331
3246
  );
2332
3247
  const effectiveDir = dir === "auto" ? hasHebrewContent ? "rtl" : "ltr" : dir;
2333
- const bindingsByRawKey = useMemo(() => {
2334
- const map = /* @__PURE__ */ new Map();
2335
- for (const binding of bindings) {
2336
- map.set(binding.key.raw, binding);
2337
- }
2338
- return map;
2339
- }, [bindings]);
2340
- const bindingsByRawKeyRef = useRef2(bindingsByRawKey);
2341
- bindingsByRawKeyRef.current = bindingsByRawKey;
2342
- const handleEdit = useCallback2((rawKey, value) => {
2343
- const binding = bindingsByRawKeyRef.current.get(rawKey);
2344
- const pristine = binding !== void 0 && value === toInputString(binding.extracted);
3248
+ const handleEdit = useCallback3((editKey, value, binding) => {
3249
+ const pristine = value === toInputString(binding.extracted);
2345
3250
  setEdits((prev) => {
2346
3251
  if (pristine) {
2347
- if (!prev.has(rawKey)) {
3252
+ if (!prev.has(editKey)) {
2348
3253
  return prev;
2349
3254
  }
2350
3255
  const next2 = new Map(prev);
2351
- next2.delete(rawKey);
3256
+ next2.delete(editKey);
2352
3257
  return next2;
2353
3258
  }
2354
- if (prev.get(rawKey) === value) {
3259
+ if (prev.get(editKey) === value) {
2355
3260
  return prev;
2356
3261
  }
2357
3262
  const next = new Map(prev);
2358
- next.set(rawKey, value);
3263
+ next.set(editKey, value);
2359
3264
  return next;
2360
3265
  });
2361
3266
  }, []);
2362
- const submission = useMemo(() => composeSubmission(bindings, edits), [bindings, edits]);
2363
- const handleFlash = useCallback2((rects) => {
3267
+ const plannedTables = useMemo(() => {
3268
+ const tables = loaded?.rowMutableTables ?? [];
3269
+ if (tables.length === 0) {
3270
+ return NO_PLANNED_TABLES;
3271
+ }
3272
+ const out = /* @__PURE__ */ new Map();
3273
+ for (const table of tables) {
3274
+ const plan = rowPlans.get(table.pointer);
3275
+ if (plan === void 0) {
3276
+ continue;
3277
+ }
3278
+ const classifiedTable = classified.tables.find(
3279
+ (candidate) => matchesTablePointer(table.pointer, candidate.pointer)
3280
+ );
3281
+ const columns = displayColumns(table, classifiedTable?.columns ?? []);
3282
+ out.set(table.pointer, planTableCells(table, plan, columns, bindingsByRawKey));
3283
+ }
3284
+ return out;
3285
+ }, [loaded, rowPlans, classified, bindingsByRawKey]);
3286
+ const cellViews = useMemo(
3287
+ () => collectCellViews(bindings, plannedTables),
3288
+ [bindings, plannedTables]
3289
+ );
3290
+ const submissionTables = useMemo(
3291
+ () => pruneEmptyAddedRows(plannedTables, edits),
3292
+ [plannedTables, edits]
3293
+ );
3294
+ const submissionCells = useMemo(
3295
+ () => collectCellViews(bindings, submissionTables),
3296
+ [bindings, submissionTables]
3297
+ );
3298
+ const rowSources = useMemo(() => {
3299
+ const entries = [];
3300
+ for (const table of loaded?.rowMutableTables ?? []) {
3301
+ const rows = submissionTables.get(table.pointer);
3302
+ if (rows === void 0) {
3303
+ continue;
3304
+ }
3305
+ const plan = rows.map((row) => row.entry);
3306
+ if (isIdentityPlan(plan, countRowsAt(loaded?.values, table.pointer))) {
3307
+ continue;
3308
+ }
3309
+ entries.push({ table: table.pointer, sources: rowSourcesOf(plan) });
3310
+ }
3311
+ return entries;
3312
+ }, [loaded, submissionTables]);
3313
+ const submission = useMemo(
3314
+ () => composeSubmission(bindings, edits, { cells: submissionCells, rowSources }),
3315
+ [bindings, edits, submissionCells, rowSources]
3316
+ );
3317
+ const handleFlash = useCallback3((rects) => {
2364
3318
  setFlashRects(rects.map((rect) => ({ points: rect.points })));
2365
3319
  }, []);
2366
- const handleFlashComplete = useCallback2(() => {
3320
+ const handleFlashComplete = useCallback3(() => {
2367
3321
  setFlashRects(null);
2368
3322
  }, []);
2369
- const handleImageExpired = useCallback2(() => {
3323
+ const handleImageExpired = useCallback3(() => {
2370
3324
  const now = Date.now();
2371
3325
  if (now - lastImageRefreshRef.current < IMAGE_REFRESH_THROTTLE_MS) {
2372
3326
  return;
@@ -2384,10 +3338,52 @@ function GeminaVerification(props) {
2384
3338
  }).catch(() => {
2385
3339
  });
2386
3340
  }, [fetchWithRetry]);
2387
- const handleRetry = useCallback2(() => {
3341
+ const handleRetry = useCallback3(() => {
2388
3342
  void load();
2389
3343
  }, [load]);
2390
- const doSubmit = useCallback2(async () => {
3344
+ const handleAddRow = useCallback3((tablePointer, afterPosition) => {
3345
+ const id = nextAddedRowId(tablePointer);
3346
+ setRowPlans((prev) => {
3347
+ const plan = prev.get(tablePointer);
3348
+ if (plan === void 0) {
3349
+ return prev;
3350
+ }
3351
+ const next = new Map(prev);
3352
+ next.set(tablePointer, insertRowAfter(plan, afterPosition, id));
3353
+ return next;
3354
+ });
3355
+ }, []);
3356
+ const handleRemoveRow = useCallback3((tablePointer, position) => {
3357
+ setRowPlans((prev) => {
3358
+ const plan = prev.get(tablePointer);
3359
+ if (plan === void 0) {
3360
+ return prev;
3361
+ }
3362
+ const nextPlan = removeRow(plan, position);
3363
+ if (nextPlan === plan) {
3364
+ return prev;
3365
+ }
3366
+ const next = new Map(prev);
3367
+ next.set(tablePointer, nextPlan);
3368
+ return next;
3369
+ });
3370
+ }, []);
3371
+ const pairErrors = useMemo(() => unitSizePairErrors(cellViews, edits), [cellViews, edits]);
3372
+ const invalidCount = useMemo(() => {
3373
+ const rowLevel = pairErrors.size;
3374
+ if (edits.size === 0) {
3375
+ return rowLevel;
3376
+ }
3377
+ const byEditKey = new Map(cellViews.map((view) => [view.editKey, view.binding]));
3378
+ let count = 0;
3379
+ for (const [editKey, value] of edits) {
3380
+ if (!pairErrors.has(editKey) && validateInput(value, byEditKey.get(editKey)?.field) !== null) {
3381
+ count += 1;
3382
+ }
3383
+ }
3384
+ return count + rowLevel;
3385
+ }, [edits, cellViews, pairErrors]);
3386
+ const doSubmit = useCallback3(async () => {
2391
3387
  if (submitInFlightRef.current) {
2392
3388
  return;
2393
3389
  }
@@ -2400,7 +3396,13 @@ function GeminaVerification(props) {
2400
3396
  const token = await tokenManager.getToken();
2401
3397
  return GeminaClient.withSessionToken(token, baseUrl).documents.validateDocumentExtraction({
2402
3398
  targetDocumentExtractionId: extractionId,
2403
- extractionValidationInDTO: { data: body.data }
3399
+ // Conditional spread, matching the house pattern: without a row edit
3400
+ // the request body is byte-identical to what it was before this
3401
+ // feature, so nothing changes for the overwhelmingly common path.
3402
+ extractionValidationInDTO: {
3403
+ data: body.data,
3404
+ ...body.rowSources.length > 0 ? { rowSources: body.rowSources } : {}
3405
+ }
2404
3406
  });
2405
3407
  };
2406
3408
  try {
@@ -2448,20 +3450,20 @@ function GeminaVerification(props) {
2448
3450
  submitInFlightRef.current = false;
2449
3451
  }
2450
3452
  }, [submission, tokenManager, baseUrl, extractionId, load]);
2451
- const handleSubmitClick = useCallback2(() => {
3453
+ const handleSubmitClick = useCallback3(() => {
2452
3454
  setPhase({ name: "confirming" });
2453
3455
  }, []);
2454
- const handleConfirm = useCallback2(() => {
3456
+ const handleConfirm = useCallback3(() => {
2455
3457
  void doSubmit();
2456
3458
  }, [doSubmit]);
2457
- const handleCancelConfirm = useCallback2(() => {
3459
+ const handleCancelConfirm = useCallback3(() => {
2458
3460
  restoreFocusRef.current = true;
2459
3461
  setPhase({ name: "review" });
2460
3462
  }, []);
2461
- const handleRetrySubmit = useCallback2(() => {
3463
+ const handleRetrySubmit = useCallback3(() => {
2462
3464
  void doSubmit();
2463
3465
  }, [doSubmit]);
2464
- const handleConfirmKeyDown = useCallback2(
3466
+ const handleConfirmKeyDown = useCallback3(
2465
3467
  (event) => {
2466
3468
  if (phase.name !== "confirming") {
2467
3469
  return;
@@ -2492,7 +3494,7 @@ function GeminaVerification(props) {
2492
3494
  },
2493
3495
  [phase.name, handleCancelConfirm]
2494
3496
  );
2495
- useEffect2(() => {
3497
+ useEffect3(() => {
2496
3498
  if (phase.name === "confirming") {
2497
3499
  confirmButtonRef.current?.focus();
2498
3500
  } else if (phase.name === "review" && restoreFocusRef.current) {
@@ -2511,13 +3513,13 @@ function GeminaVerification(props) {
2511
3513
  stacked ? "gemina-verification--stacked" : "",
2512
3514
  className ?? ""
2513
3515
  ].filter((part) => part.length > 0).join(" ");
2514
- const dialogTextId = useId();
3516
+ const dialogTextId = useId2();
2515
3517
  const renderReview = (reviewPhase) => {
2516
3518
  const overlayUp = reviewPhase.name === "confirming" || reviewPhase.name === "submitting";
2517
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
2518
- alreadyValidated && /* @__PURE__ */ jsx3("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
2519
- /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__panes", children: [
2520
- imageUrl !== null && /* @__PURE__ */ jsx3(
3519
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
3520
+ alreadyValidated && /* @__PURE__ */ jsx4("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
3521
+ /* @__PURE__ */ jsxs4("div", { className: "gemina-verification__panes", children: [
3522
+ imageUrl !== null && /* @__PURE__ */ jsx4(
2521
3523
  VerificationViewer,
2522
3524
  {
2523
3525
  src: imageUrl,
@@ -2527,7 +3529,7 @@ function GeminaVerification(props) {
2527
3529
  onImageExpired: handleImageExpired
2528
3530
  }
2529
3531
  ),
2530
- /* @__PURE__ */ jsx3(
3532
+ /* @__PURE__ */ jsx4(
2531
3533
  VerificationForm,
2532
3534
  {
2533
3535
  classified,
@@ -2536,18 +3538,23 @@ function GeminaVerification(props) {
2536
3538
  edits,
2537
3539
  onEdit: handleEdit,
2538
3540
  readOnly: alreadyValidated,
2539
- onFlash: handleFlash
3541
+ onFlash: handleFlash,
3542
+ pairErrors,
3543
+ rowMutableTables: loaded?.rowMutableTables,
3544
+ plannedTables,
3545
+ onAddRow: handleAddRow,
3546
+ onRemoveRow: handleRemoveRow
2540
3547
  }
2541
3548
  )
2542
3549
  ] }),
2543
- reviewPhase.name === "submit-error" && /* @__PURE__ */ jsxs3(
3550
+ reviewPhase.name === "submit-error" && /* @__PURE__ */ jsxs4(
2544
3551
  "div",
2545
3552
  {
2546
3553
  className: "gemina-verification__banner gemina-verification__banner--error gemina-verification__submit-error",
2547
3554
  role: "alert",
2548
3555
  children: [
2549
- /* @__PURE__ */ jsx3("span", { children: reviewPhase.message }),
2550
- /* @__PURE__ */ jsx3(
3556
+ /* @__PURE__ */ jsx4("span", { children: reviewPhase.message }),
3557
+ /* @__PURE__ */ jsx4(
2551
3558
  "button",
2552
3559
  {
2553
3560
  type: "button",
@@ -2560,21 +3567,21 @@ function GeminaVerification(props) {
2560
3567
  ]
2561
3568
  }
2562
3569
  ),
2563
- /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__footer", children: [
2564
- !alreadyValidated && /* @__PURE__ */ jsx3("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` }),
2565
- /* @__PURE__ */ jsx3(
3570
+ /* @__PURE__ */ jsxs4("div", { className: "gemina-verification__footer", children: [
3571
+ !alreadyValidated && (invalidCount > 0 ? /* @__PURE__ */ jsx4("div", { className: "gemina-verification__attention", "aria-live": "polite", children: invalidCount === 1 ? "1 field needs attention" : `${invalidCount} fields need attention` }) : /* @__PURE__ */ jsx4("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` })),
3572
+ /* @__PURE__ */ jsx4(
2566
3573
  "button",
2567
3574
  {
2568
3575
  type: "button",
2569
3576
  ref: submitButtonRef,
2570
3577
  className: "gemina-verification__submit",
2571
- disabled: alreadyValidated || reviewPhase.name !== "review",
3578
+ disabled: alreadyValidated || reviewPhase.name !== "review" || invalidCount > 0,
2572
3579
  onClick: handleSubmitClick,
2573
- children: "Submit feedback"
3580
+ children: "Submit"
2574
3581
  }
2575
3582
  )
2576
3583
  ] }),
2577
- overlayUp && /* @__PURE__ */ jsx3(
3584
+ overlayUp && /* @__PURE__ */ jsx4(
2578
3585
  "div",
2579
3586
  {
2580
3587
  className: "gemina-verification__confirm",
@@ -2584,7 +3591,7 @@ function GeminaVerification(props) {
2584
3591
  event.preventDefault();
2585
3592
  }
2586
3593
  },
2587
- children: /* @__PURE__ */ jsxs3(
3594
+ children: /* @__PURE__ */ jsxs4(
2588
3595
  "div",
2589
3596
  {
2590
3597
  className: "gemina-verification__confirm-dialog",
@@ -2592,9 +3599,9 @@ function GeminaVerification(props) {
2592
3599
  "aria-modal": "true",
2593
3600
  "aria-labelledby": dialogTextId,
2594
3601
  children: [
2595
- /* @__PURE__ */ jsx3("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
2596
- /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__confirm-actions", children: [
2597
- /* @__PURE__ */ jsx3(
3602
+ /* @__PURE__ */ jsx4("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
3603
+ /* @__PURE__ */ jsxs4("div", { className: "gemina-verification__confirm-actions", children: [
3604
+ /* @__PURE__ */ jsx4(
2598
3605
  "button",
2599
3606
  {
2600
3607
  type: "button",
@@ -2605,7 +3612,7 @@ function GeminaVerification(props) {
2605
3612
  children: "Cancel"
2606
3613
  }
2607
3614
  ),
2608
- /* @__PURE__ */ jsx3(
3615
+ /* @__PURE__ */ jsx4(
2609
3616
  "button",
2610
3617
  {
2611
3618
  type: "button",
@@ -2627,16 +3634,16 @@ function GeminaVerification(props) {
2627
3634
  const content = (() => {
2628
3635
  switch (phase.name) {
2629
3636
  case "loading":
2630
- return /* @__PURE__ */ jsx3("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
3637
+ return /* @__PURE__ */ jsx4("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
2631
3638
  case "unavailable":
2632
- return /* @__PURE__ */ jsxs3(
3639
+ return /* @__PURE__ */ jsxs4(
2633
3640
  "div",
2634
3641
  {
2635
3642
  className: "gemina-verification__state",
2636
3643
  role: ALERT_REASONS.has(phase.reason) ? "alert" : "status",
2637
3644
  children: [
2638
- /* @__PURE__ */ jsx3("div", { children: phase.message }),
2639
- phase.canRetry && /* @__PURE__ */ jsx3("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
3645
+ /* @__PURE__ */ jsx4("div", { children: phase.message }),
3646
+ phase.canRetry && /* @__PURE__ */ jsx4("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
2640
3647
  ]
2641
3648
  }
2642
3649
  );
@@ -2646,7 +3653,7 @@ function GeminaVerification(props) {
2646
3653
  case "submit-error":
2647
3654
  return renderReview(phase);
2648
3655
  case "done":
2649
- return /* @__PURE__ */ jsxs3(
3656
+ return /* @__PURE__ */ jsxs4(
2650
3657
  "div",
2651
3658
  {
2652
3659
  ref: doneStateRef,
@@ -2654,7 +3661,7 @@ function GeminaVerification(props) {
2654
3661
  className: "gemina-verification__state gemina-verification__state--done",
2655
3662
  role: "status",
2656
3663
  children: [
2657
- /* @__PURE__ */ jsx3("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ jsx3(
3664
+ /* @__PURE__ */ jsx4("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ jsx4(
2658
3665
  "path",
2659
3666
  {
2660
3667
  d: "M4 10.5l4 4 8-9",
@@ -2664,17 +3671,17 @@ function GeminaVerification(props) {
2664
3671
  strokeLinejoin: "round"
2665
3672
  }
2666
3673
  ) }) }),
2667
- /* @__PURE__ */ jsx3("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
2668
- /* @__PURE__ */ jsx3("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
3674
+ /* @__PURE__ */ jsx4("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
3675
+ /* @__PURE__ */ jsx4("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
2669
3676
  ]
2670
3677
  }
2671
3678
  );
2672
3679
  }
2673
3680
  })();
2674
- return /* @__PURE__ */ jsx3("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
3681
+ return /* @__PURE__ */ jsx4("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
2675
3682
  }
2676
3683
 
2677
3684
  export {
2678
3685
  GeminaVerification
2679
3686
  };
2680
- //# sourceMappingURL=chunk-5T2M557X.js.map
3687
+ //# sourceMappingURL=chunk-MITACKUW.js.map