@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.
package/dist/index.cjs CHANGED
@@ -221,7 +221,7 @@ async function readErrorEnvelope(error) {
221
221
  }
222
222
 
223
223
  // src/version.ts
224
- var VERSION = "0.8.0";
224
+ var VERSION = "0.9.0";
225
225
 
226
226
  // src/chat.tsx
227
227
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -870,9 +870,181 @@ function GeminaChat(props) {
870
870
  }
871
871
 
872
872
  // src/verification/index.tsx
873
- var import_react4 = require("react");
873
+ var import_react5 = require("react");
874
874
  var import_sdk2 = require("@gemina/sdk");
875
875
 
876
+ // src/verification/field-types.ts
877
+ var ISO_4217_CODES = [
878
+ "AED",
879
+ "ARS",
880
+ "AUD",
881
+ "BGN",
882
+ "BRL",
883
+ "CAD",
884
+ "CHF",
885
+ "CLP",
886
+ "CNY",
887
+ "COP",
888
+ "CZK",
889
+ "DKK",
890
+ "EGP",
891
+ "EUR",
892
+ "GBP",
893
+ "HKD",
894
+ "HRK",
895
+ "HUF",
896
+ "IDR",
897
+ "ILS",
898
+ "INR",
899
+ "ISK",
900
+ "JPY",
901
+ "KRW",
902
+ "MAD",
903
+ "MXN",
904
+ "MYR",
905
+ "NGN",
906
+ "NOK",
907
+ "NZD",
908
+ "PEN",
909
+ "PHP",
910
+ "PLN",
911
+ "RON",
912
+ "RSD",
913
+ "RUB",
914
+ "SAR",
915
+ "SEK",
916
+ "SGD",
917
+ "THB",
918
+ "TRY",
919
+ "TWD",
920
+ "UAH",
921
+ "USD",
922
+ "VND",
923
+ "ZAR"
924
+ ];
925
+ var ISO_4217_SHAPE = /^[A-Za-z]{3}$/;
926
+ var DATE_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
927
+ var NUMERIC_SHAPE = /^[+-]?[\d,_]*\.?\d+$/;
928
+ function toNumber(value) {
929
+ if (!NUMERIC_SHAPE.test(value)) {
930
+ return null;
931
+ }
932
+ const parsed = Number(value.replace(/[,_]/g, ""));
933
+ return Number.isFinite(parsed) ? parsed : null;
934
+ }
935
+ function validateInput(value, field) {
936
+ const trimmed = value.trim();
937
+ if (trimmed === "" || !field) {
938
+ return null;
939
+ }
940
+ if (field.enum && field.enum.length > 0) {
941
+ return field.enum.includes(trimmed) ? null : `Choose one of: ${field.enum.join(", ")}`;
942
+ }
943
+ if (field.format === "iso4217") {
944
+ return ISO_4217_SHAPE.test(trimmed) ? null : "Use a 3-letter ISO 4217 code, e.g. USD";
945
+ }
946
+ switch (field.type) {
947
+ case "number":
948
+ return toNumber(trimmed) === null ? "Enter a number" : null;
949
+ case "integer": {
950
+ const parsed = toNumber(trimmed);
951
+ if (parsed === null || !Number.isInteger(parsed)) {
952
+ return "Enter a whole number";
953
+ }
954
+ return null;
955
+ }
956
+ case "date": {
957
+ if (!DATE_SHAPE.test(trimmed)) {
958
+ return "Enter a date as YYYY-MM-DD";
959
+ }
960
+ const [year, month, day] = trimmed.split("-").map(Number);
961
+ const date = new Date(Date.UTC(year, month - 1, day));
962
+ const survives = date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
963
+ return survives ? null : "Enter a date as YYYY-MM-DD";
964
+ }
965
+ default:
966
+ return null;
967
+ }
968
+ }
969
+ function readRowMutableTables(raw) {
970
+ if (!Array.isArray(raw)) {
971
+ return [];
972
+ }
973
+ const out = [];
974
+ for (const item of raw) {
975
+ if (item === null || typeof item !== "object") {
976
+ continue;
977
+ }
978
+ const source = item;
979
+ if (typeof source.pointer !== "string" || typeof source.keyTemplate !== "string") {
980
+ continue;
981
+ }
982
+ out.push({
983
+ pointer: source.pointer,
984
+ keyTemplate: source.keyTemplate,
985
+ // Columns are descriptors keyed by `name` rather than `key`, so they get
986
+ // the same treatment with the name standing in as the identity.
987
+ columns: readDescriptors(
988
+ (Array.isArray(source.columns) ? source.columns : []).map((column) => {
989
+ const record = column ?? {};
990
+ return { ...record, key: record.name };
991
+ })
992
+ )
993
+ });
994
+ }
995
+ return out;
996
+ }
997
+ function cellSchemaKey(template, index, field) {
998
+ return template.replace(/\{index\}/g, String(index)).replace(/\{field\}/g, field);
999
+ }
1000
+ function coerceInput(value, field) {
1001
+ if (!field) {
1002
+ return value;
1003
+ }
1004
+ switch (field.type) {
1005
+ case "number":
1006
+ case "integer": {
1007
+ const parsed = toNumber(value);
1008
+ return parsed === null ? value : parsed;
1009
+ }
1010
+ case "boolean": {
1011
+ const lowered = value.trim().toLowerCase();
1012
+ if (lowered === "true") return true;
1013
+ if (lowered === "false") return false;
1014
+ return value;
1015
+ }
1016
+ // `date` stays a string: the wire format IS the ISO string, and a Date
1017
+ // object would serialise with a time component the extraction never had.
1018
+ default:
1019
+ return value;
1020
+ }
1021
+ }
1022
+ function readDescriptors(raw) {
1023
+ if (!Array.isArray(raw)) {
1024
+ return [];
1025
+ }
1026
+ const out = [];
1027
+ for (const item of raw) {
1028
+ if (item === null || typeof item !== "object") {
1029
+ continue;
1030
+ }
1031
+ const source = item;
1032
+ if (typeof source.key !== "string") {
1033
+ continue;
1034
+ }
1035
+ const roster = source._enum ?? source.enum;
1036
+ out.push({
1037
+ key: source.key,
1038
+ label: typeof source.label === "string" ? source.label : void 0,
1039
+ type: typeof source.type === "string" ? source.type : void 0,
1040
+ enum: Array.isArray(roster) ? roster.map(String) : null,
1041
+ format: typeof source.format === "string" ? source.format : null,
1042
+ description: typeof source.description === "string" ? source.description : null
1043
+ });
1044
+ }
1045
+ return out;
1046
+ }
1047
+
876
1048
  // src/verification/classify.ts
877
1049
  var ACRONYMS = /* @__PURE__ */ new Set(["ID", "VAT", "OCR", "PDF", "URL", "API", "HTML", "CSS", "JSON", "XML", "UUID"]);
878
1050
  function formatLabel(key) {
@@ -1194,6 +1366,9 @@ function parseSchemaKey(raw) {
1194
1366
  return { raw, label: match[1], pointer: match[2] };
1195
1367
  }
1196
1368
  var NOT_FOUND = /* @__PURE__ */ Symbol("gemina-verification-not-found");
1369
+ function snakeToCamel(segment) {
1370
+ return segment.replace(/_([a-zA-Z0-9])/g, (_unused, ch) => ch.toUpperCase());
1371
+ }
1197
1372
 
1198
1373
  // src/verification/bindings.ts
1199
1374
  function unescapeSegment(raw) {
@@ -1202,9 +1377,6 @@ function unescapeSegment(raw) {
1202
1377
  function escapeSegment2(segment) {
1203
1378
  return segment.replace(/~/g, "~0").replace(/\//g, "~1");
1204
1379
  }
1205
- function snakeToCamel(segment) {
1206
- return segment.replace(/_([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
1207
- }
1208
1380
  function camelizePointer(pointer) {
1209
1381
  if (!pointer.startsWith("/")) {
1210
1382
  return pointer;
@@ -1255,7 +1427,13 @@ function resolveCasingAware(doc, pointer) {
1255
1427
  function stripValueSuffix(pointer) {
1256
1428
  return pointer.endsWith("/value") ? pointer.slice(0, -"/value".length) : pointer;
1257
1429
  }
1258
- function buildBindings(validationSchema, values) {
1430
+ function buildBindings(validationSchema, values, fields) {
1431
+ const descriptors = /* @__PURE__ */ new Map();
1432
+ for (const descriptor of fields ?? []) {
1433
+ if (typeof descriptor?.key === "string") {
1434
+ descriptors.set(descriptor.key, descriptor);
1435
+ }
1436
+ }
1259
1437
  const bindings = [];
1260
1438
  for (const raw of validationSchema) {
1261
1439
  const key = parseSchemaKey(raw);
@@ -1270,7 +1448,8 @@ function buildBindings(validationSchema, values) {
1270
1448
  serverValue,
1271
1449
  extracted,
1272
1450
  fieldPointer: stripValueSuffix(resolvedPointer),
1273
- editable
1451
+ editable,
1452
+ field: descriptors.get(key.raw)
1274
1453
  });
1275
1454
  }
1276
1455
  return bindings;
@@ -1291,39 +1470,356 @@ function toInputString(extracted) {
1291
1470
  }
1292
1471
  return String(extracted);
1293
1472
  }
1294
- function composeSubmission(bindings, edits) {
1473
+ function composeSubmission(bindings, edits, options = {}) {
1474
+ const cells = options.cells ?? bindings.map((binding) => ({
1475
+ editKey: binding.key.raw,
1476
+ submitKey: binding.key.raw,
1477
+ column: binding.key.label,
1478
+ rowKey: binding.key.raw,
1479
+ binding,
1480
+ added: false
1481
+ }));
1295
1482
  const data = {};
1296
1483
  const byLabel = {};
1297
1484
  let confirmed = 0;
1298
1485
  let corrected = 0;
1299
- for (const binding of bindings) {
1300
- const edit = edits.get(binding.key.raw);
1486
+ for (const cell of cells) {
1487
+ const { binding } = cell;
1488
+ const label = parseSchemaKey(cell.submitKey)?.label ?? binding.key.label;
1489
+ const edit = edits.get(cell.editKey);
1301
1490
  if (edit !== void 0) {
1302
1491
  const trimmed = edit.trim();
1303
1492
  if (trimmed === "" && binding.serverValue === NOT_FOUND) {
1304
1493
  continue;
1305
1494
  }
1306
- const value = trimmed === "" ? null : trimmed;
1307
- data[binding.key.raw] = value;
1308
- byLabel[binding.key.label] = value;
1495
+ const value = trimmed === "" ? null : coerceInput(trimmed, binding.field);
1496
+ data[cell.submitKey] = value;
1497
+ byLabel[label] = value;
1309
1498
  corrected += 1;
1310
1499
  } else {
1311
1500
  if (binding.serverValue === NOT_FOUND) {
1312
1501
  continue;
1313
1502
  }
1314
- data[binding.key.raw] = binding.serverValue;
1315
- byLabel[binding.key.label] = binding.serverValue;
1503
+ data[cell.submitKey] = binding.serverValue;
1504
+ byLabel[label] = binding.serverValue;
1316
1505
  confirmed += 1;
1317
1506
  }
1318
1507
  }
1319
- return { data, byLabel, confirmed, corrected };
1508
+ return { data, byLabel, confirmed, corrected, rowSources: options.rowSources ?? [] };
1509
+ }
1510
+ function countRowsAt(values, pointer) {
1511
+ const { node } = resolveCasingAware(values, pointer);
1512
+ return Array.isArray(node) ? node.length : 0;
1513
+ }
1514
+
1515
+ // src/verification/row-plan.ts
1516
+ var addedRowCounter = 0;
1517
+ function initialRowPlan(extractedCount, scope = "") {
1518
+ return Array.from({ length: Math.max(0, extractedCount) }, (_unused, index) => ({
1519
+ // Derived from the source index, so it is stable across re-renders without
1520
+ // any state to carry — an extracted row's identity never changes.
1521
+ id: `${scope}#row-${index}`,
1522
+ source: index
1523
+ }));
1524
+ }
1525
+ function nextAddedRowId(scope = "") {
1526
+ addedRowCounter += 1;
1527
+ return `${scope}#added-${addedRowCounter}`;
1528
+ }
1529
+ function removeRow(plan, position) {
1530
+ if (position < 0 || position >= plan.length) {
1531
+ return plan;
1532
+ }
1533
+ return plan.filter((_entry, index) => index !== position);
1534
+ }
1535
+ function insertRowAfter(plan, position, id) {
1536
+ const added = { id: id ?? nextAddedRowId(), source: null };
1537
+ const at = Math.min(Math.max(position + 1, 0), plan.length);
1538
+ return [...plan.slice(0, at), added, ...plan.slice(at)];
1539
+ }
1540
+ function cellEditKey(rowId, column) {
1541
+ return `cell:${rowId}|col:${column}`;
1542
+ }
1543
+ function rowSourcesOf(plan) {
1544
+ return plan.map((entry) => entry.source);
1545
+ }
1546
+ function isIdentityPlan(plan, extractedCount) {
1547
+ return plan.length === extractedCount && plan.every((entry, index) => entry.source === index);
1548
+ }
1549
+
1550
+ // src/verification/row-cells.ts
1551
+ function syntheticBinding(submitKey, descriptor) {
1552
+ const key = parseSchemaKey(submitKey);
1553
+ if (key === null) {
1554
+ return null;
1555
+ }
1556
+ return {
1557
+ key,
1558
+ serverValue: NOT_FOUND,
1559
+ extracted: NOT_FOUND,
1560
+ // No extracted node, so nothing to point at on the document.
1561
+ fieldPointer: key.pointer,
1562
+ editable: true,
1563
+ field: descriptor
1564
+ };
1565
+ }
1566
+ function planTableCells(table, plan, columns, bindingsByRawKey) {
1567
+ const descriptors = /* @__PURE__ */ new Map();
1568
+ for (const column of table.columns) {
1569
+ if (typeof column.key === "string") {
1570
+ descriptors.set(column.key, column);
1571
+ }
1572
+ }
1573
+ return plan.map((entry, submittedIndex) => {
1574
+ const cells = [];
1575
+ for (const column of columns) {
1576
+ const submitKey = cellSchemaKey(table.keyTemplate, submittedIndex, column);
1577
+ const editKey = cellEditKey(entry.id, column);
1578
+ const extractedKey = entry.source === null ? null : cellSchemaKey(table.keyTemplate, entry.source, column);
1579
+ const existing = extractedKey === null ? void 0 : bindingsByRawKey.get(extractedKey);
1580
+ const binding = existing ?? syntheticBinding(submitKey, descriptors.get(column));
1581
+ if (binding === null) {
1582
+ continue;
1583
+ }
1584
+ cells.push({ column, editKey, submitKey, binding, added: existing === void 0 });
1585
+ }
1586
+ return { entry, cells };
1587
+ });
1588
+ }
1589
+ function displayColumns(table, classifiedColumns) {
1590
+ const declared = table.columns.map((column) => column.key).filter((name) => typeof name === "string");
1591
+ const seen = new Set(declared);
1592
+ return [...declared, ...classifiedColumns.filter((name) => !seen.has(name))];
1593
+ }
1594
+ function matchesTablePointer(serverPointer, classifiedPointer) {
1595
+ return serverPointer === classifiedPointer || snakeToCamel(serverPointer) === classifiedPointer;
1596
+ }
1597
+ function splitPointer(pointer) {
1598
+ const cut = pointer.lastIndexOf("/");
1599
+ return cut <= 0 ? null : { row: pointer.slice(0, cut), field: pointer.slice(cut + 1) };
1600
+ }
1601
+ function collectCellViews(bindings, plannedTables) {
1602
+ const views = [];
1603
+ const ownedPrefixes = [...plannedTables.keys()].map((pointer) => `${pointer}/`);
1604
+ for (const rows of plannedTables.values()) {
1605
+ for (const row of rows) {
1606
+ for (const cell of row.cells) {
1607
+ views.push({
1608
+ editKey: cell.editKey,
1609
+ submitKey: cell.submitKey,
1610
+ column: cell.column,
1611
+ rowKey: row.entry.id,
1612
+ binding: cell.binding,
1613
+ added: cell.added
1614
+ });
1615
+ }
1616
+ }
1617
+ }
1618
+ for (const binding of bindings) {
1619
+ if (ownedPrefixes.some((prefix) => binding.key.pointer.startsWith(prefix))) {
1620
+ continue;
1621
+ }
1622
+ const split = splitPointer(binding.key.pointer);
1623
+ views.push({
1624
+ // Outside a plan all three identities coincide, which is why none of
1625
+ // this was needed before row editing.
1626
+ editKey: binding.key.raw,
1627
+ submitKey: binding.key.raw,
1628
+ column: split?.field ?? binding.key.label,
1629
+ rowKey: split?.row ?? binding.key.raw,
1630
+ binding,
1631
+ added: false
1632
+ });
1633
+ }
1634
+ return views;
1635
+ }
1636
+ var UNIT_SIZE = "unit_size";
1637
+ var UNIT_SIZE_UOM = "unit_size_uom";
1638
+ var UNIT_PAIR_MESSAGE = "Enter both value and unit";
1639
+ function unitSizePairErrors(cells, edits) {
1640
+ const rows = /* @__PURE__ */ new Map();
1641
+ for (const cell of cells) {
1642
+ if (cell.column !== UNIT_SIZE && cell.column !== UNIT_SIZE_UOM) {
1643
+ continue;
1644
+ }
1645
+ const row = rows.get(cell.rowKey) ?? {};
1646
+ if (cell.column === UNIT_SIZE) {
1647
+ row.size = cell;
1648
+ } else {
1649
+ row.uom = cell;
1650
+ }
1651
+ rows.set(cell.rowKey, row);
1652
+ }
1653
+ const errors = /* @__PURE__ */ new Map();
1654
+ for (const { size, uom } of rows.values()) {
1655
+ if (!size || !uom) {
1656
+ continue;
1657
+ }
1658
+ const filled = (cell) => (edits.get(cell.editKey) ?? toInputString(cell.binding.extracted)).trim() !== "";
1659
+ if (filled(size) !== filled(uom)) {
1660
+ errors.set(size.editKey, UNIT_PAIR_MESSAGE);
1661
+ errors.set(uom.editKey, UNIT_PAIR_MESSAGE);
1662
+ }
1663
+ }
1664
+ return errors;
1665
+ }
1666
+ function pruneEmptyAddedRows(plannedTables, edits) {
1667
+ const out = /* @__PURE__ */ new Map();
1668
+ for (const [pointer, rows] of plannedTables) {
1669
+ out.set(pointer, rows.filter((row) => {
1670
+ if (row.entry.source !== null) {
1671
+ return true;
1672
+ }
1673
+ return row.cells.some((cell) => (edits.get(cell.editKey) ?? "").trim() !== "");
1674
+ }));
1675
+ }
1676
+ return out;
1320
1677
  }
1321
1678
 
1322
1679
  // src/verification/form.tsx
1323
- var import_react3 = __toESM(require("react"), 1);
1680
+ var import_react4 = __toESM(require("react"), 1);
1324
1681
 
1325
- // src/verification/viewer.tsx
1682
+ // src/verification/tip.tsx
1326
1683
  var import_react2 = require("react");
1684
+ var import_react_dom = require("react-dom");
1685
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1686
+ var GAP = 8;
1687
+ var MARGIN = 8;
1688
+ function isEmpty(content) {
1689
+ return content == null || content === "" || content === false;
1690
+ }
1691
+ function rootClassesOf(node) {
1692
+ const root = node?.closest(".gemina-verification");
1693
+ return root ? root.className : "gemina-verification";
1694
+ }
1695
+ function mergeRefs(ours, theirs) {
1696
+ return (value) => {
1697
+ ours(value);
1698
+ if (typeof theirs === "function") {
1699
+ theirs(value);
1700
+ } else if (theirs && typeof theirs === "object") {
1701
+ theirs.current = value;
1702
+ }
1703
+ };
1704
+ }
1705
+ function Tip({ content, children }) {
1706
+ const [open, setOpen] = (0, import_react2.useState)(false);
1707
+ const [position, setPosition] = (0, import_react2.useState)(null);
1708
+ const [rootClasses, setRootClasses] = (0, import_react2.useState)("gemina-verification");
1709
+ const triggerRef = (0, import_react2.useRef)(null);
1710
+ const tipRef = (0, import_react2.useRef)(null);
1711
+ const id = (0, import_react2.useId)();
1712
+ const empty = isEmpty(content);
1713
+ const show = (0, import_react2.useCallback)(() => {
1714
+ if (empty) {
1715
+ return;
1716
+ }
1717
+ setRootClasses(rootClassesOf(triggerRef.current));
1718
+ setPosition(null);
1719
+ setOpen(true);
1720
+ }, [empty]);
1721
+ const hide = (0, import_react2.useCallback)(() => setOpen(false), []);
1722
+ (0, import_react2.useLayoutEffect)(() => {
1723
+ if (!open) {
1724
+ return;
1725
+ }
1726
+ const trigger2 = triggerRef.current;
1727
+ const tip = tipRef.current;
1728
+ if (!trigger2 || !tip) {
1729
+ return;
1730
+ }
1731
+ const anchor = trigger2.getBoundingClientRect();
1732
+ const bubble = tip.getBoundingClientRect();
1733
+ const viewportWidth = window.innerWidth || 0;
1734
+ const viewportHeight = window.innerHeight || 0;
1735
+ const fitsAbove = anchor.top - bubble.height - GAP >= MARGIN;
1736
+ const fitsBelow = anchor.bottom + bubble.height + GAP <= viewportHeight - MARGIN;
1737
+ const top = fitsAbove || !fitsBelow ? anchor.top - bubble.height - GAP : anchor.bottom + GAP;
1738
+ const centred = anchor.left + anchor.width / 2 - bubble.width / 2;
1739
+ const rightLimit = Math.max(MARGIN, viewportWidth - bubble.width - MARGIN);
1740
+ const left = Math.min(Math.max(centred, MARGIN), rightLimit);
1741
+ setPosition({ top: Math.max(top, MARGIN), left });
1742
+ }, [open, content]);
1743
+ (0, import_react2.useEffect)(() => {
1744
+ if (!open) {
1745
+ return;
1746
+ }
1747
+ const onKeyDown = (event) => {
1748
+ if (event.key === "Escape") {
1749
+ hide();
1750
+ }
1751
+ };
1752
+ const onScrollOrResize = () => hide();
1753
+ document.addEventListener("keydown", onKeyDown);
1754
+ document.addEventListener("scroll", onScrollOrResize, true);
1755
+ window.addEventListener("resize", onScrollOrResize);
1756
+ return () => {
1757
+ document.removeEventListener("keydown", onKeyDown);
1758
+ document.removeEventListener("scroll", onScrollOrResize, true);
1759
+ window.removeEventListener("resize", onScrollOrResize);
1760
+ };
1761
+ }, [open, hide]);
1762
+ if (!(0, import_react2.isValidElement)(children)) {
1763
+ return children;
1764
+ }
1765
+ const childProps = children.props;
1766
+ const call = (name, event) => {
1767
+ const handler = childProps[name];
1768
+ if (typeof handler === "function") {
1769
+ handler(event);
1770
+ }
1771
+ };
1772
+ const trigger = (0, import_react2.cloneElement)(children, {
1773
+ ref: mergeRefs((node) => {
1774
+ triggerRef.current = node;
1775
+ }, children.ref),
1776
+ // The tip is a DESCRIPTION. `aria-label` stays untouched — it already
1777
+ // carries the reason into the accessible NAME, and duplicating it here
1778
+ // would have a screen reader announce it twice.
1779
+ "aria-describedby": open && !empty ? id : void 0,
1780
+ onMouseEnter: (event) => {
1781
+ call("onMouseEnter", event);
1782
+ show();
1783
+ },
1784
+ onMouseLeave: (event) => {
1785
+ call("onMouseLeave", event);
1786
+ hide();
1787
+ },
1788
+ onFocus: (event) => {
1789
+ call("onFocus", event);
1790
+ show();
1791
+ },
1792
+ onBlur: (event) => {
1793
+ call("onBlur", event);
1794
+ hide();
1795
+ }
1796
+ });
1797
+ const canPortal = typeof document !== "undefined" && document.body;
1798
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1799
+ trigger,
1800
+ open && !empty && canPortal ? (0, import_react_dom.createPortal)(
1801
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: rootClasses, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1802
+ "div",
1803
+ {
1804
+ ref: tipRef,
1805
+ id,
1806
+ role: "tooltip",
1807
+ className: "gemina-verification__tip",
1808
+ style: {
1809
+ top: position ? `${position.top}px` : "0px",
1810
+ left: position ? `${position.left}px` : "0px",
1811
+ visibility: position ? "visible" : "hidden"
1812
+ },
1813
+ children: content
1814
+ }
1815
+ ) }),
1816
+ document.body
1817
+ ) : null
1818
+ ] });
1819
+ }
1820
+
1821
+ // src/verification/viewer.tsx
1822
+ var import_react3 = require("react");
1327
1823
 
1328
1824
  // src/verification/viewer-math.ts
1329
1825
  function fitScaleFor(natural, container, rotationDeg) {
@@ -1405,9 +1901,9 @@ function flashZoomTarget(rects, natural, container, rotationDeg, fitScale) {
1405
1901
  var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
1406
1902
 
1407
1903
  // src/verification/viewer.tsx
1408
- var import_jsx_runtime2 = require("react/jsx-runtime");
1904
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1409
1905
  function IconBase({ children }) {
1410
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1906
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1411
1907
  "svg",
1412
1908
  {
1413
1909
  width: "16",
@@ -1425,56 +1921,56 @@ function IconBase({ children }) {
1425
1921
  );
1426
1922
  }
1427
1923
  function GlassBody() {
1428
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1429
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
1430
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
1924
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1925
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
1926
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
1431
1927
  ] });
1432
1928
  }
1433
1929
  function IconZoomIn() {
1434
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1435
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}),
1436
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
1437
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
1930
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1931
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(GlassBody, {}),
1932
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
1933
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
1438
1934
  ] });
1439
1935
  }
1440
1936
  function IconZoomOut() {
1441
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1442
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}),
1443
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
1937
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1938
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(GlassBody, {}),
1939
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
1444
1940
  ] });
1445
1941
  }
1446
1942
  function IconMagnifier() {
1447
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}) });
1943
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(GlassBody, {}) });
1448
1944
  }
1449
1945
  function IconActualSize() {
1450
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1451
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "2.8 6.2 4 5 4 11" }),
1452
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "10.8 6.2 12 5 12 11" }),
1453
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
1454
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
1946
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1947
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "2.8 6.2 4 5 4 11" }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "10.8 6.2 12 5 12 11" }),
1949
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
1950
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
1455
1951
  ] });
1456
1952
  }
1457
1953
  function IconFit() {
1458
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1459
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
1460
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
1461
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
1462
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
1954
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1955
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
1956
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
1957
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
1958
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
1463
1959
  ] });
1464
1960
  }
1465
1961
  function IconRotate() {
1466
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1467
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
1468
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "6 1.7 8 3 6 4.3" })
1962
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1963
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
1964
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "6 1.7 8 3 6 4.3" })
1469
1965
  ] });
1470
1966
  }
1471
1967
  function IconOverlay() {
1472
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
1968
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
1473
1969
  }
1474
1970
  function IconEye() {
1475
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
1476
- /* @__PURE__ */ (0, import_jsx_runtime2.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" }),
1477
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "8", r: "2.1" })
1971
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(IconBase, { children: [
1972
+ /* @__PURE__ */ (0, import_jsx_runtime3.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" }),
1973
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "8", cy: "8", r: "2.1" })
1478
1974
  ] });
1479
1975
  }
1480
1976
  function ToolbarButton({
@@ -1486,12 +1982,11 @@ function ToolbarButton({
1486
1982
  children
1487
1983
  }) {
1488
1984
  const active = (pressed ?? checked) === true;
1489
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1985
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: label, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1490
1986
  "button",
1491
1987
  {
1492
1988
  type: "button",
1493
1989
  className: active ? "gemina-verification__toolbar-btn gemina-verification__toolbar-btn--active" : "gemina-verification__toolbar-btn",
1494
- title: label,
1495
1990
  "aria-label": label,
1496
1991
  role: checked === void 0 ? void 0 : "switch",
1497
1992
  "aria-checked": checked,
@@ -1500,7 +1995,7 @@ function ToolbarButton({
1500
1995
  onClick,
1501
1996
  children
1502
1997
  }
1503
- );
1998
+ ) });
1504
1999
  }
1505
2000
  var ZOOM_STEP = 1.2;
1506
2001
  var IDENTITY = { scale: 1, tx: 0, ty: 0 };
@@ -1510,6 +2005,7 @@ var REDUCED_MOTION_FLASH_MS = 800;
1510
2005
  var MIN_SIZE_RATIO = 8e-3;
1511
2006
  var MAG_RADIUS = 150;
1512
2007
  var MAG_ZOOM = 2.5;
2008
+ var MAG_BORDER = 2;
1513
2009
  function rectGeometry(rect, natural) {
1514
2010
  const xs = rect.points.map((point) => point[0]);
1515
2011
  const ys = rect.points.map((point) => point[1]);
@@ -1527,29 +2023,29 @@ function rectGeometry(rect, natural) {
1527
2023
  }
1528
2024
  function VerificationViewer(props) {
1529
2025
  const { src, alt, relativeRects, flashRects, onFlashComplete, onImageExpired } = props;
1530
- const canvasRef = (0, import_react2.useRef)(null);
1531
- const imgRef = (0, import_react2.useRef)(null);
1532
- const [natural, setNatural] = (0, import_react2.useState)(null);
1533
- const [container, setContainer] = (0, import_react2.useState)({ w: 0, h: 0 });
1534
- const [transform, setTransform] = (0, import_react2.useState)(IDENTITY);
1535
- const [rotation, setRotation] = (0, import_react2.useState)(0);
1536
- const [showRects, setShowRects] = (0, import_react2.useState)(false);
1537
- const [magnifierOn, setMagnifierOn] = (0, import_react2.useState)(false);
1538
- const [showMag, setShowMag] = (0, import_react2.useState)(false);
1539
- const [mousePos, setMousePos] = (0, import_react2.useState)({ x: 0, y: 0 });
1540
- const [isPanning, setIsPanning] = (0, import_react2.useState)(false);
1541
- const panStart = (0, import_react2.useRef)(null);
1542
- const [flashOpacity, setFlashOpacity] = (0, import_react2.useState)(0);
1543
- const [activeFlashRects, setActiveFlashRects] = (0, import_react2.useState)(null);
1544
- const travelRafRef = (0, import_react2.useRef)(null);
1545
- const fadeRafRef = (0, import_react2.useRef)(null);
1546
- const reducedFlashTimeoutRef = (0, import_react2.useRef)(null);
1547
- const transformRef = (0, import_react2.useRef)(transform);
2026
+ const canvasRef = (0, import_react3.useRef)(null);
2027
+ const imgRef = (0, import_react3.useRef)(null);
2028
+ const [natural, setNatural] = (0, import_react3.useState)(null);
2029
+ const [container, setContainer] = (0, import_react3.useState)({ w: 0, h: 0 });
2030
+ const [transform, setTransform] = (0, import_react3.useState)(IDENTITY);
2031
+ const [rotation, setRotation] = (0, import_react3.useState)(0);
2032
+ const [showRects, setShowRects] = (0, import_react3.useState)(false);
2033
+ const [magnifierOn, setMagnifierOn] = (0, import_react3.useState)(false);
2034
+ const [showMag, setShowMag] = (0, import_react3.useState)(false);
2035
+ const [mousePos, setMousePos] = (0, import_react3.useState)({ x: 0, y: 0 });
2036
+ const [isPanning, setIsPanning] = (0, import_react3.useState)(false);
2037
+ const panStart = (0, import_react3.useRef)(null);
2038
+ const [flashOpacity, setFlashOpacity] = (0, import_react3.useState)(0);
2039
+ const [activeFlashRects, setActiveFlashRects] = (0, import_react3.useState)(null);
2040
+ const travelRafRef = (0, import_react3.useRef)(null);
2041
+ const fadeRafRef = (0, import_react3.useRef)(null);
2042
+ const reducedFlashTimeoutRef = (0, import_react3.useRef)(null);
2043
+ const transformRef = (0, import_react3.useRef)(transform);
1548
2044
  transformRef.current = transform;
1549
- const onFlashCompleteRef = (0, import_react2.useRef)(onFlashComplete);
2045
+ const onFlashCompleteRef = (0, import_react3.useRef)(onFlashComplete);
1550
2046
  onFlashCompleteRef.current = onFlashComplete;
1551
- const hasLoadedRef = (0, import_react2.useRef)(false);
1552
- (0, import_react2.useLayoutEffect)(() => {
2047
+ const hasLoadedRef = (0, import_react3.useRef)(false);
2048
+ (0, import_react3.useLayoutEffect)(() => {
1553
2049
  const el = canvasRef.current;
1554
2050
  if (!el) return;
1555
2051
  if (typeof ResizeObserver === "undefined") {
@@ -1564,7 +2060,7 @@ function VerificationViewer(props) {
1564
2060
  ro.observe(el);
1565
2061
  return () => ro.disconnect();
1566
2062
  }, []);
1567
- const handleImgLoad = (0, import_react2.useCallback)(() => {
2063
+ const handleImgLoad = (0, import_react3.useCallback)(() => {
1568
2064
  const img = imgRef.current;
1569
2065
  if (!img) return;
1570
2066
  hasLoadedRef.current = true;
@@ -1572,19 +2068,19 @@ function VerificationViewer(props) {
1572
2068
  const h = img.naturalHeight;
1573
2069
  setNatural((prev) => prev && prev.w === w && prev.h === h ? prev : { w, h });
1574
2070
  }, []);
1575
- (0, import_react2.useEffect)(() => {
2071
+ (0, import_react3.useEffect)(() => {
1576
2072
  hasLoadedRef.current = false;
1577
2073
  }, [src]);
1578
- const handleImgError = (0, import_react2.useCallback)(() => {
2074
+ const handleImgError = (0, import_react3.useCallback)(() => {
1579
2075
  if (!hasLoadedRef.current) return;
1580
2076
  hasLoadedRef.current = false;
1581
2077
  onImageExpired?.();
1582
2078
  }, [onImageExpired]);
1583
- const currentFitScale = (0, import_react2.useCallback)(() => {
2079
+ const currentFitScale = (0, import_react3.useCallback)(() => {
1584
2080
  if (!natural || !container.w || !container.h) return 1;
1585
2081
  return fitScaleFor(natural, container, rotation);
1586
2082
  }, [natural, container, rotation]);
1587
- (0, import_react2.useEffect)(() => {
2083
+ (0, import_react3.useEffect)(() => {
1588
2084
  if (!natural || !container.w || !container.h) return;
1589
2085
  const fit = fitScaleFor(natural, container, rotation);
1590
2086
  const { tx, ty } = centeredTranslation(natural, container, fit, rotation);
@@ -1592,13 +2088,13 @@ function VerificationViewer(props) {
1592
2088
  (prev) => Math.abs(prev.scale - fit) < 1e-4 && prev.tx === tx && prev.ty === ty ? prev : { scale: fit, tx, ty }
1593
2089
  );
1594
2090
  }, [natural, container, rotation]);
1595
- const cancelFlashTravel = (0, import_react2.useCallback)(() => {
2091
+ const cancelFlashTravel = (0, import_react3.useCallback)(() => {
1596
2092
  if (travelRafRef.current !== null) {
1597
2093
  cancelAnimationFrame(travelRafRef.current);
1598
2094
  travelRafRef.current = null;
1599
2095
  }
1600
2096
  }, []);
1601
- const zoomBy = (0, import_react2.useCallback)(
2097
+ const zoomBy = (0, import_react3.useCallback)(
1602
2098
  (factor) => {
1603
2099
  const node = canvasRef.current;
1604
2100
  if (!node || !natural) return;
@@ -1611,9 +2107,9 @@ function VerificationViewer(props) {
1611
2107
  },
1612
2108
  [natural, rotation, currentFitScale, cancelFlashTravel]
1613
2109
  );
1614
- const handleZoomIn = (0, import_react2.useCallback)(() => zoomBy(ZOOM_STEP), [zoomBy]);
1615
- const handleZoomOut = (0, import_react2.useCallback)(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
1616
- const zoomAtClientPoint = (0, import_react2.useCallback)(
2110
+ const handleZoomIn = (0, import_react3.useCallback)(() => zoomBy(ZOOM_STEP), [zoomBy]);
2111
+ const handleZoomOut = (0, import_react3.useCallback)(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
2112
+ const zoomAtClientPoint = (0, import_react3.useCallback)(
1617
2113
  (factor, clientX, clientY) => {
1618
2114
  const node = canvasRef.current;
1619
2115
  if (!node || !natural) return;
@@ -1625,7 +2121,7 @@ function VerificationViewer(props) {
1625
2121
  },
1626
2122
  [natural, rotation, currentFitScale]
1627
2123
  );
1628
- const handleWheel = (0, import_react2.useCallback)(
2124
+ const handleWheel = (0, import_react3.useCallback)(
1629
2125
  (event) => {
1630
2126
  event.preventDefault();
1631
2127
  event.stopPropagation();
@@ -1635,7 +2131,7 @@ function VerificationViewer(props) {
1635
2131
  },
1636
2132
  [zoomAtClientPoint, cancelFlashTravel]
1637
2133
  );
1638
- (0, import_react2.useEffect)(() => {
2134
+ (0, import_react3.useEffect)(() => {
1639
2135
  const node = canvasRef.current;
1640
2136
  if (!node) return;
1641
2137
  const listener = (event) => handleWheel(event);
@@ -1643,7 +2139,7 @@ function VerificationViewer(props) {
1643
2139
  return () => node.removeEventListener("wheel", listener);
1644
2140
  }, [handleWheel]);
1645
2141
  const atFitScale = transform.scale <= currentFitScale() + 1e-3;
1646
- const handleMouseDown = (0, import_react2.useCallback)(
2142
+ const handleMouseDown = (0, import_react3.useCallback)(
1647
2143
  (e) => {
1648
2144
  cancelFlashTravel();
1649
2145
  if (e.button !== 0) return;
@@ -1654,7 +2150,7 @@ function VerificationViewer(props) {
1654
2150
  },
1655
2151
  [atFitScale, transform.tx, transform.ty, cancelFlashTravel]
1656
2152
  );
1657
- (0, import_react2.useEffect)(() => {
2153
+ (0, import_react3.useEffect)(() => {
1658
2154
  if (!isPanning) return;
1659
2155
  const onMove = (e) => {
1660
2156
  const start = panStart.current;
@@ -1674,8 +2170,8 @@ function VerificationViewer(props) {
1674
2170
  document.removeEventListener("mouseup", onUp);
1675
2171
  };
1676
2172
  }, [isPanning]);
1677
- const touchState = (0, import_react2.useRef)(null);
1678
- const handleTouchStart = (0, import_react2.useCallback)(
2173
+ const touchState = (0, import_react3.useRef)(null);
2174
+ const handleTouchStart = (0, import_react3.useCallback)(
1679
2175
  (e) => {
1680
2176
  cancelFlashTravel();
1681
2177
  const a = e.touches[0];
@@ -1693,7 +2189,7 @@ function VerificationViewer(props) {
1693
2189
  },
1694
2190
  [atFitScale, transform.tx, transform.ty, cancelFlashTravel]
1695
2191
  );
1696
- const handleTouchMove = (0, import_react2.useCallback)(
2192
+ const handleTouchMove = (0, import_react3.useCallback)(
1697
2193
  (e) => {
1698
2194
  const state = touchState.current;
1699
2195
  if (!state) return;
@@ -1718,19 +2214,19 @@ function VerificationViewer(props) {
1718
2214
  },
1719
2215
  [zoomAtClientPoint]
1720
2216
  );
1721
- const handleTouchEnd = (0, import_react2.useCallback)((e) => {
2217
+ const handleTouchEnd = (0, import_react3.useCallback)((e) => {
1722
2218
  if (e.touches.length === 0) touchState.current = null;
1723
2219
  }, []);
1724
- const handleCanvasMouseMove = (0, import_react2.useCallback)((e) => {
2220
+ const handleCanvasMouseMove = (0, import_react3.useCallback)((e) => {
1725
2221
  const rect = canvasRef.current?.getBoundingClientRect();
1726
2222
  if (!rect) return;
1727
2223
  setShowMag(true);
1728
2224
  setMousePos({ x: e.clientX - rect.left, y: e.clientY - rect.top });
1729
2225
  }, []);
1730
- const handleCanvasMouseLeave = (0, import_react2.useCallback)(() => {
2226
+ const handleCanvasMouseLeave = (0, import_react3.useCallback)(() => {
1731
2227
  setShowMag(false);
1732
2228
  }, []);
1733
- const handleDoubleClick = (0, import_react2.useCallback)(
2229
+ const handleDoubleClick = (0, import_react3.useCallback)(
1734
2230
  (e) => {
1735
2231
  cancelFlashTravel();
1736
2232
  if (!natural) return;
@@ -1745,26 +2241,26 @@ function VerificationViewer(props) {
1745
2241
  },
1746
2242
  [natural, container, rotation, transform.scale, currentFitScale, zoomAtClientPoint, cancelFlashTravel]
1747
2243
  );
1748
- const handleFit = (0, import_react2.useCallback)(() => {
2244
+ const handleFit = (0, import_react3.useCallback)(() => {
1749
2245
  if (!natural) return;
1750
2246
  cancelFlashTravel();
1751
2247
  const fit = currentFitScale();
1752
2248
  setTransform({ scale: fit, ...centeredTranslation(natural, container, fit, rotation) });
1753
2249
  }, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
1754
- const handleActualSize = (0, import_react2.useCallback)(() => {
2250
+ const handleActualSize = (0, import_react3.useCallback)(() => {
1755
2251
  if (!natural) return;
1756
2252
  cancelFlashTravel();
1757
2253
  const target = clampScale(1, currentFitScale());
1758
2254
  setTransform({ scale: target, ...centeredTranslation(natural, container, target, rotation) });
1759
2255
  }, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
1760
- const handleRotate = (0, import_react2.useCallback)(() => {
2256
+ const handleRotate = (0, import_react3.useCallback)(() => {
1761
2257
  setRotation((r) => (r + 90) % 360);
1762
2258
  }, []);
1763
2259
  const hasRects = relativeRects !== void 0 && relativeRects.length > 0;
1764
- (0, import_react2.useEffect)(() => {
2260
+ (0, import_react3.useEffect)(() => {
1765
2261
  if (!hasRects) setShowRects(false);
1766
2262
  }, [hasRects]);
1767
- (0, import_react2.useEffect)(() => {
2263
+ (0, import_react3.useEffect)(() => {
1768
2264
  if (!flashRects || flashRects.length === 0 || !natural || !container.w || !container.h) {
1769
2265
  setActiveFlashRects((prev) => prev === null ? prev : null);
1770
2266
  setFlashOpacity(0);
@@ -1835,71 +2331,72 @@ function VerificationViewer(props) {
1835
2331
  const dy = mousePos.y - transform.ty;
1836
2332
  const cxRaw = (cosA * dx + sinA * dy) / transform.scale;
1837
2333
  const cyRaw = (-sinA * dx + cosA * dy) / transform.scale;
1838
- const clampedX = Math.max(0, Math.min(cxRaw, natural.w));
1839
- const clampedY = Math.max(0, Math.min(cyRaw, natural.h));
2334
+ const onImage = cxRaw >= 0 && cyRaw >= 0 && cxRaw <= natural.w && cyRaw <= natural.h;
1840
2335
  const zoomScale = transform.scale * MAG_ZOOM;
1841
- const px = clampedX * zoomScale;
1842
- const py = clampedY * zoomScale;
2336
+ const px = cxRaw * zoomScale;
2337
+ const py = cyRaw * zoomScale;
1843
2338
  const rotatedX = px * cosA - py * sinA;
1844
2339
  const rotatedY = px * sinA + py * cosA;
1845
- const translateX = MAG_RADIUS - rotatedX;
1846
- const translateY = MAG_RADIUS - rotatedY;
1847
- magnifier = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1848
- "div",
1849
- {
1850
- className: "gemina-verification__magnifier",
1851
- style: {
1852
- width: MAG_RADIUS * 2,
1853
- height: MAG_RADIUS * 2,
1854
- top: mousePos.y - MAG_RADIUS,
1855
- left: mousePos.x - MAG_RADIUS
1856
- },
1857
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1858
- "img",
1859
- {
1860
- src,
1861
- alt: "",
1862
- draggable: false,
1863
- style: {
1864
- position: "absolute",
1865
- width: natural.w,
1866
- height: natural.h,
1867
- transformOrigin: "0 0",
1868
- transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
2340
+ const translateX = MAG_RADIUS - MAG_BORDER - rotatedX;
2341
+ const translateY = MAG_RADIUS - MAG_BORDER - rotatedY;
2342
+ if (onImage) {
2343
+ magnifier = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2344
+ "div",
2345
+ {
2346
+ className: "gemina-verification__magnifier",
2347
+ style: {
2348
+ width: MAG_RADIUS * 2,
2349
+ height: MAG_RADIUS * 2,
2350
+ top: mousePos.y - MAG_RADIUS,
2351
+ left: mousePos.x - MAG_RADIUS
2352
+ },
2353
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2354
+ "img",
2355
+ {
2356
+ src,
2357
+ alt: "",
2358
+ draggable: false,
2359
+ style: {
2360
+ position: "absolute",
2361
+ width: natural.w,
2362
+ height: natural.h,
2363
+ transformOrigin: "0 0",
2364
+ transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
2365
+ }
1869
2366
  }
1870
- }
1871
- )
1872
- }
1873
- );
2367
+ )
2368
+ }
2369
+ );
2370
+ }
1874
2371
  }
1875
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "gemina-verification__viewer", children: [
1876
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "gemina-verification__toolbar", children: [
1877
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconZoomOut, {}) }),
1878
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconZoomIn, {}) }),
1879
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconActualSize, {}) }),
1880
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconFit, {}) }),
1881
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconRotate, {}) }),
1882
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2372
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__viewer", children: [
2373
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__toolbar", children: [
2374
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconZoomOut, {}) }),
2375
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconZoomIn, {}) }),
2376
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconActualSize, {}) }),
2377
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconFit, {}) }),
2378
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconRotate, {}) }),
2379
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1883
2380
  ToolbarButton,
1884
2381
  {
1885
2382
  label: "Toggle detection overlays",
1886
2383
  pressed: showRects,
1887
2384
  disabled: !hasRects,
1888
2385
  onClick: () => setShowRects((prev) => !prev),
1889
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconOverlay, {})
2386
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconOverlay, {})
1890
2387
  }
1891
2388
  ),
1892
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2389
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1893
2390
  ToolbarButton,
1894
2391
  {
1895
2392
  label: "Magnifier",
1896
2393
  checked: magnifierOn,
1897
2394
  onClick: () => setMagnifierOn((prev) => !prev),
1898
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconMagnifier, {})
2395
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconMagnifier, {})
1899
2396
  }
1900
2397
  )
1901
2398
  ] }),
1902
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2399
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1903
2400
  "div",
1904
2401
  {
1905
2402
  ref: canvasRef,
@@ -1916,7 +2413,7 @@ function VerificationViewer(props) {
1916
2413
  onTouchEnd: handleTouchEnd,
1917
2414
  onTouchCancel: handleTouchEnd,
1918
2415
  children: [
1919
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2416
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1920
2417
  "div",
1921
2418
  {
1922
2419
  style: {
@@ -1928,7 +2425,7 @@ function VerificationViewer(props) {
1928
2425
  willChange: "transform,left,top"
1929
2426
  },
1930
2427
  children: [
1931
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2428
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1932
2429
  "img",
1933
2430
  {
1934
2431
  ref: imgRef,
@@ -1942,13 +2439,13 @@ function VerificationViewer(props) {
1942
2439
  showRects && natural && relativeRects?.map((rect, idx) => {
1943
2440
  const geometry = rectGeometry(rect, natural);
1944
2441
  if (!geometry) return null;
1945
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2442
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1946
2443
  "div",
1947
2444
  {
1948
2445
  className: "gemina-verification__rect",
1949
2446
  style: geometry,
1950
2447
  "aria-hidden": "true",
1951
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "gemina-verification__rect-badge", children: [
2448
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "gemina-verification__rect-badge", children: [
1952
2449
  "#",
1953
2450
  idx + 1
1954
2451
  ] })
@@ -1959,7 +2456,7 @@ function VerificationViewer(props) {
1959
2456
  activeFlashRects && natural && activeFlashRects.map((rect, idx) => {
1960
2457
  const geometry = rectGeometry(rect, natural);
1961
2458
  if (!geometry) return null;
1962
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2459
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1963
2460
  "div",
1964
2461
  {
1965
2462
  className: "gemina-verification__flash-rect",
@@ -1980,7 +2477,7 @@ function VerificationViewer(props) {
1980
2477
  }
1981
2478
 
1982
2479
  // src/verification/form.tsx
1983
- var import_jsx_runtime3 = require("react/jsx-runtime");
2480
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1984
2481
  function ConfidenceDot(props) {
1985
2482
  const { confidence } = props;
1986
2483
  if (!confidence?.level) {
@@ -2006,93 +2503,156 @@ function ConfidenceDot(props) {
2006
2503
  label = `${confidence.level} confidence`;
2007
2504
  }
2008
2505
  const reasons = confidence.reasons.map(formatLabel);
2009
- const title = [label, ...reasons].join("\n");
2010
2506
  const ariaLabel = reasons.length > 0 ? `${label}: ${reasons.join(", ")}` : label;
2011
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2507
+ const tip = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2508
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { className: "gemina-verification__tip-title", children: label }),
2509
+ reasons.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "gemina-verification__tip-list", children: reasons.map((reason) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: reason }, reason)) }) : null
2510
+ ] });
2511
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tip, { content: tip, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2012
2512
  "span",
2013
2513
  {
2014
2514
  className: `gemina-verification__dot gemina-verification__dot--${variant}`,
2015
2515
  role: "img",
2016
- "aria-label": ariaLabel,
2017
- title
2516
+ "aria-label": ariaLabel
2018
2517
  }
2019
- );
2518
+ ) });
2020
2519
  }
2021
2520
  function EyeButton(props) {
2022
2521
  const { coordinates, onFlash } = props;
2023
2522
  if (!coordinates) {
2024
2523
  return null;
2025
2524
  }
2026
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2525
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tip, { content: "Show on document", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2027
2526
  "button",
2028
2527
  {
2029
2528
  type: "button",
2030
2529
  className: "gemina-verification__eye",
2031
- title: "Show on document",
2032
2530
  "aria-label": "Show on document",
2033
2531
  onClick: (event) => {
2034
2532
  event.stopPropagation();
2035
2533
  onFlash();
2036
2534
  },
2037
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconEye, {})
2535
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconEye, {})
2038
2536
  }
2039
- );
2537
+ ) });
2040
2538
  }
2041
2539
  function FieldInput(props) {
2042
- const { binding, edit, onEdit, readOnly, ariaLabel } = props;
2043
- const editedBadgeId = import_react3.default.useId();
2540
+ const { binding, edit, onEdit, readOnly, ariaLabel, pairError } = props;
2541
+ const editKey = props.editKey ?? binding.key.raw;
2542
+ const editedBadgeId = import_react4.default.useId();
2543
+ const errorId = import_react4.default.useId();
2544
+ const currencyListId = import_react4.default.useId();
2044
2545
  if (readOnly || !binding.editable) {
2045
2546
  const display = binding.extracted === NOT_FOUND ? null : binding.extracted;
2046
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(display, binding.key.label) });
2547
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: formatValue(display, binding.key.label) });
2047
2548
  }
2048
2549
  const dirty = edit !== void 0;
2049
2550
  const missed = binding.serverValue === NOT_FOUND;
2551
+ const field = binding.field;
2552
+ const value = dirty ? edit : toInputString(binding.extracted);
2553
+ const error = pairError ?? (dirty ? validateInput(value, field) : null);
2050
2554
  const className = [
2051
2555
  "gemina-verification__input",
2052
2556
  dirty ? "gemina-verification__input--dirty" : "",
2053
- missed ? "gemina-verification__input--missed" : ""
2557
+ missed ? "gemina-verification__input--missed" : "",
2558
+ error ? "gemina-verification__input--invalid" : ""
2054
2559
  ].filter(Boolean).join(" ");
2055
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
2056
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2057
- "input",
2058
- {
2059
- type: "text",
2060
- className,
2061
- dir: "auto",
2062
- value: dirty ? edit : toInputString(binding.extracted),
2063
- onChange: (event) => onEdit(binding.key.raw, event.target.value),
2064
- placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
2065
- "aria-label": ariaLabel,
2066
- "aria-describedby": dirty ? editedBadgeId : void 0,
2067
- autoComplete: "off"
2068
- }
2069
- ),
2070
- dirty ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" }) : null
2560
+ const describedBy = [dirty ? editedBadgeId : "", error ? errorId : ""].filter(Boolean).join(" ");
2561
+ const shared = {
2562
+ className,
2563
+ "aria-label": ariaLabel,
2564
+ "aria-describedby": describedBy || void 0,
2565
+ "aria-invalid": error ? true : void 0,
2566
+ onChange: (event) => onEdit(editKey, event.target.value, binding)
2567
+ };
2568
+ const roster = field?.enum && field.enum.length > 0 ? field.enum : null;
2569
+ const offRoster = roster && value !== "" && !roster.includes(value) ? value : null;
2570
+ const control = roster ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("select", { ...shared, value, dir: "auto", children: [
2571
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: "\u2014" }),
2572
+ offRoster ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("option", { value: offRoster, children: [
2573
+ offRoster,
2574
+ " (as extracted)"
2575
+ ] }) : null,
2576
+ roster.map((option) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: option, children: option }, option))
2577
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2578
+ "input",
2579
+ {
2580
+ ...shared,
2581
+ type: field?.type === "date" ? "date" : "text",
2582
+ dir: "auto",
2583
+ value,
2584
+ inputMode: field?.type === "number" || field?.type === "integer" ? "decimal" : void 0,
2585
+ list: field?.format === "iso4217" ? currencyListId : void 0,
2586
+ placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
2587
+ autoComplete: "off"
2588
+ }
2589
+ );
2590
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2591
+ control,
2592
+ field?.format === "iso4217" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("datalist", { id: currencyListId, children: ISO_4217_CODES.map((code) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: code }, code)) }) : null,
2593
+ error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__field-error", id: errorId, role: "alert", children: error }) : null,
2594
+ dirty ? (
2595
+ // The badge is where the ORIGINAL belongs, now that the input holds
2596
+ // the edit — otherwise the extracted value is simply gone from the
2597
+ // screen the moment someone corrects it.
2598
+ //
2599
+ // Known limit: the badge is a non-focusable span, so this channel is
2600
+ // hover-only. AT is not worse off than before (nothing carried the
2601
+ // original previously), and the input's aria-describedby still names
2602
+ // the field as edited. Giving it a keyboard path needs a focusable
2603
+ // affordance, which belongs with the Phase 8 row work, not here.
2604
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2605
+ Tip,
2606
+ {
2607
+ content: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2608
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__tip-label", children: "Was: " }),
2609
+ formatValue(
2610
+ binding.extracted === NOT_FOUND ? null : binding.extracted,
2611
+ binding.key.label
2612
+ )
2613
+ ] }),
2614
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" })
2615
+ }
2616
+ )
2617
+ ) : null
2071
2618
  ] });
2072
2619
  }
2620
+ var NO_PAIR_ERRORS = /* @__PURE__ */ new Map();
2621
+ var NO_TABLES = [];
2622
+ var NO_PLANNED = /* @__PURE__ */ new Map();
2623
+ var NOOP_ROW = () => {
2624
+ };
2073
2625
  function isInteractiveTarget(target) {
2074
2626
  return target instanceof Element && target.closest("input, button, a, select, textarea") !== null;
2075
2627
  }
2628
+ function FieldLabel(props) {
2629
+ const { label, description } = props;
2630
+ if (!description) {
2631
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: label });
2632
+ }
2633
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tip, { content: description, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__label-described", tabIndex: 0, children: label }) });
2634
+ }
2076
2635
  function FieldPair(props) {
2077
2636
  const { label, ariaLabel, cell, shared } = props;
2078
2637
  const binding = shared.bindingIndex.get(cell.pointer);
2079
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
2080
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dt", { className: "gemina-verification__dt", children: [
2081
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: cell.confidence }),
2082
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: label })
2638
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2639
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("dt", { className: "gemina-verification__dt", children: [
2640
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConfidenceDot, { confidence: cell.confidence }),
2641
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldLabel, { label, description: binding?.field?.description })
2083
2642
  ] }),
2084
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dd", { className: "gemina-verification__dd", children: [
2085
- binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2643
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("dd", { className: "gemina-verification__dd", children: [
2644
+ binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2086
2645
  FieldInput,
2087
2646
  {
2088
2647
  binding,
2648
+ pairError: shared.pairErrors.get(binding.key.raw),
2089
2649
  edit: shared.edits.get(binding.key.raw),
2090
2650
  onEdit: shared.onEdit,
2091
2651
  readOnly: shared.readOnly,
2092
2652
  ariaLabel
2093
2653
  }
2094
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(cell.value, label) }),
2095
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2654
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: formatValue(cell.value, label) }),
2655
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2096
2656
  EyeButton,
2097
2657
  {
2098
2658
  coordinates: cell.coordinates,
@@ -2111,10 +2671,10 @@ function HeaderSection(props) {
2111
2671
  if (headers.length === 0 && simpleLists.length === 0) {
2112
2672
  return null;
2113
2673
  }
2114
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
2115
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Details" }),
2116
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dl", { className: "gemina-verification__dl", children: [
2117
- headers.map((field) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2674
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
2675
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__section-header", children: "Details" }),
2676
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("dl", { className: "gemina-verification__dl", children: [
2677
+ headers.map((field) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2118
2678
  FieldPair,
2119
2679
  {
2120
2680
  label: formatLabel(field.key),
@@ -2124,23 +2684,24 @@ function HeaderSection(props) {
2124
2684
  },
2125
2685
  field.pointer
2126
2686
  )),
2127
- simpleLists.map((list) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react3.default.Fragment, { children: [
2128
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatLabel(list.key) }) }),
2129
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
2687
+ simpleLists.map((list) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react4.default.Fragment, { children: [
2688
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: formatLabel(list.key) }) }),
2689
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
2130
2690
  const binding = shared.bindingIndex.get(item.pointer);
2131
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "gemina-verification__cell", children: [
2132
- binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2691
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { className: "gemina-verification__cell", children: [
2692
+ binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2133
2693
  FieldInput,
2134
2694
  {
2135
2695
  binding,
2696
+ pairError: shared.pairErrors.get(binding.key.raw),
2136
2697
  edit: shared.edits.get(binding.key.raw),
2137
2698
  onEdit: shared.onEdit,
2138
2699
  readOnly: shared.readOnly,
2139
2700
  ariaLabel: `${formatLabel(list.key)} item ${index + 1}`
2140
2701
  }
2141
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(item.value) }),
2142
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: item.confidence }),
2143
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2702
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: formatValue(item.value) }),
2703
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConfidenceDot, { confidence: item.confidence }),
2704
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2144
2705
  EyeButton,
2145
2706
  {
2146
2707
  coordinates: item.coordinates,
@@ -2161,20 +2722,20 @@ function EntitySection(props) {
2161
2722
  const { entity, shared } = props;
2162
2723
  const label = formatLabel(entity.key);
2163
2724
  const singular = label.replace(/s$/, "");
2164
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
2165
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__section-header", children: [
2725
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
2726
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__section-header", children: [
2166
2727
  label,
2167
2728
  " (",
2168
2729
  entity.items.length,
2169
2730
  ")"
2170
2731
  ] }),
2171
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card", children: [
2172
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card-header", children: [
2732
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__card", children: [
2733
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__card-header", children: [
2173
2734
  singular,
2174
2735
  " ",
2175
2736
  itemIndex + 1
2176
2737
  ] }),
2177
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2738
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2178
2739
  FieldPair,
2179
2740
  {
2180
2741
  label: formatLabel(fieldKey),
@@ -2188,18 +2749,18 @@ function EntitySection(props) {
2188
2749
  ] });
2189
2750
  }
2190
2751
  function TableRowView(props) {
2191
- const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared } = props;
2752
+ const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared, planned, tablePointer } = props;
2192
2753
  const { bindingIndex, edits, onEdit, readOnly, onFlash } = shared;
2193
- const rects = import_react3.default.useMemo(() => {
2754
+ const rects = import_react4.default.useMemo(() => {
2194
2755
  const collected = [];
2195
- for (const [key, cell] of Object.entries(row)) {
2756
+ for (const [key, cell] of Object.entries(row ?? {})) {
2196
2757
  if (key !== ROW_META_KEY && cell.coordinates) {
2197
2758
  collected.push(cell.coordinates);
2198
2759
  }
2199
2760
  }
2200
2761
  return collected;
2201
2762
  }, [row]);
2202
- const handleRowClick = import_react3.default.useCallback(
2763
+ const handleRowClick = import_react4.default.useCallback(
2203
2764
  (event) => {
2204
2765
  if (isInteractiveTarget(event.target)) {
2205
2766
  return;
@@ -2210,81 +2771,199 @@ function TableRowView(props) {
2210
2771
  },
2211
2772
  [rects, onFlash]
2212
2773
  );
2774
+ const cellFor = (column) => {
2775
+ const classified = row?.[column];
2776
+ const fromPlan = planned?.cells.find((cell) => cell.column === column);
2777
+ if (fromPlan) {
2778
+ return { classified, binding: fromPlan.binding, editKey: fromPlan.editKey };
2779
+ }
2780
+ const binding = classified === void 0 ? void 0 : bindingIndex.get(classified.pointer);
2781
+ return { classified, binding, editKey: binding?.key.raw };
2782
+ };
2213
2783
  const firstRect = rects.length > 0 ? rects[0] : null;
2214
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { onClick: handleRowClick, children: [
2215
- hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
2216
- hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: row[ROW_META_KEY]?.confidence ?? null }) }) : null,
2784
+ const showControls = planned !== void 0 && tablePointer !== void 0 && !readOnly;
2785
+ const rowLevel = (row?.[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
2786
+ const rowClass = rowLevel === "low" || rowLevel === "medium" ? `gemina-verification__row--${rowLevel}` : void 0;
2787
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("tr", { onClick: handleRowClick, className: rowClass, children: [
2788
+ hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
2789
+ hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConfidenceDot, { confidence: row?.[ROW_META_KEY]?.confidence ?? null }) }) : null,
2217
2790
  columns.map((column) => {
2218
- const cell = row[column];
2219
- const binding = cell === void 0 ? void 0 : bindingIndex.get(cell.pointer);
2220
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__cell", children: [
2221
- binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2791
+ const { classified, binding, editKey } = cellFor(column);
2792
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__cell", children: [
2793
+ binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2222
2794
  FieldInput,
2223
2795
  {
2224
2796
  binding,
2225
- edit: edits.get(binding.key.raw),
2797
+ editKey,
2798
+ pairError: editKey === void 0 ? void 0 : shared.pairErrors.get(editKey),
2799
+ edit: editKey === void 0 ? void 0 : edits.get(editKey),
2226
2800
  onEdit,
2227
2801
  readOnly,
2228
2802
  ariaLabel: `${tableLabel} row ${rowIndex + 1} \u2014 ${formatLabel(column)}`
2229
2803
  }
2230
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: cell === void 0 ? "-" : formatValue(cell.value, column) }),
2231
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: cell?.confidence ?? null })
2804
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: classified === void 0 ? "-" : formatValue(classified.value, column) }),
2805
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConfidenceDot, { confidence: classified?.confidence ?? null })
2232
2806
  ] }) }, column);
2233
- })
2807
+ }),
2808
+ showControls ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("td", { className: "gemina-verification__row-actions", children: [
2809
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tip, { content: "Insert a line below", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2810
+ "button",
2811
+ {
2812
+ type: "button",
2813
+ className: "gemina-verification__row-btn",
2814
+ "aria-label": `Insert line below line ${rowIndex + 1}`,
2815
+ onClick: () => shared.onAddRow(tablePointer, rowIndex),
2816
+ children: "+"
2817
+ }
2818
+ ) }),
2819
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tip, { content: "Remove this line", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2820
+ "button",
2821
+ {
2822
+ type: "button",
2823
+ className: "gemina-verification__row-btn",
2824
+ "aria-label": `Remove line ${rowIndex + 1}`,
2825
+ onClick: () => shared.onRemoveRow(tablePointer, rowIndex),
2826
+ children: "\xD7"
2827
+ }
2828
+ ) })
2829
+ ] }) : null
2234
2830
  ] });
2235
2831
  }
2236
2832
  function areRowPropsEqual(prev, next) {
2237
- 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) {
2833
+ 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) {
2238
2834
  return false;
2239
2835
  }
2240
2836
  if (prev.shared.edits === next.shared.edits) {
2241
2837
  return true;
2242
2838
  }
2243
2839
  for (const column of next.columns) {
2244
- const cell = next.row[column];
2245
- const binding = cell === void 0 ? void 0 : next.shared.bindingIndex.get(cell.pointer);
2246
- if (binding !== void 0 && prev.shared.edits.get(binding.key.raw) !== next.shared.edits.get(binding.key.raw)) {
2840
+ const planned = next.planned?.cells.find((cell) => cell.column === column);
2841
+ const classified = next.row?.[column];
2842
+ const editKey = planned?.editKey ?? (classified === void 0 ? void 0 : next.shared.bindingIndex.get(classified.pointer)?.key.raw);
2843
+ if (editKey === void 0) {
2844
+ continue;
2845
+ }
2846
+ if (prev.shared.edits.get(editKey) !== next.shared.edits.get(editKey) || prev.shared.pairErrors.get(editKey) !== next.shared.pairErrors.get(editKey)) {
2247
2847
  return false;
2248
2848
  }
2249
2849
  }
2250
2850
  return true;
2251
2851
  }
2252
- var TableRow = import_react3.default.memo(TableRowView, areRowPropsEqual);
2852
+ var TableRow = import_react4.default.memo(TableRowView, areRowPropsEqual);
2853
+ function withEmptyMutableTables(classified, tables) {
2854
+ if (tables.length === 0) {
2855
+ return { tables: classified.tables, suppressed: EMPTY_SUPPRESSED };
2856
+ }
2857
+ const promoted = [...classified.tables];
2858
+ const suppressed = /* @__PURE__ */ new Set();
2859
+ for (const table of tables) {
2860
+ if (classified.tables.some((candidate) => matchesTablePointer(table.pointer, candidate.pointer))) {
2861
+ continue;
2862
+ }
2863
+ const header = classified.headers.find(
2864
+ (candidate) => matchesTablePointer(table.pointer, candidate.pointer)
2865
+ );
2866
+ const empty = header !== void 0 && (header.value === null || Array.isArray(header.value) && header.value.length === 0);
2867
+ if (!empty) {
2868
+ continue;
2869
+ }
2870
+ suppressed.add(header.pointer);
2871
+ promoted.push({
2872
+ key: header.key,
2873
+ pointer: header.pointer,
2874
+ columns: [],
2875
+ rows: [],
2876
+ overallConfidence: null
2877
+ });
2878
+ }
2879
+ return { tables: promoted, suppressed };
2880
+ }
2881
+ var EMPTY_SUPPRESSED = /* @__PURE__ */ new Set();
2253
2882
  function TableSection(props) {
2254
2883
  const { table, shared } = props;
2255
2884
  const label = formatLabel(table.key);
2256
- const hasCoords = import_react3.default.useMemo(
2885
+ const mutable = import_react4.default.useMemo(
2886
+ () => shared.rowMutableTables.find((entry) => matchesTablePointer(entry.pointer, table.pointer)),
2887
+ [shared.rowMutableTables, table.pointer]
2888
+ );
2889
+ const columns = import_react4.default.useMemo(
2890
+ () => mutable ? displayColumns(mutable, table.columns) : table.columns,
2891
+ [mutable, table.columns]
2892
+ );
2893
+ const planned = mutable ? shared.plannedTables.get(mutable.pointer) : void 0;
2894
+ const hasCoords = import_react4.default.useMemo(
2257
2895
  () => table.rows.some(
2258
2896
  (row) => Object.entries(row).some(([key, cell]) => key !== ROW_META_KEY && cell.coordinates !== null)
2259
2897
  ),
2260
2898
  [table]
2261
2899
  );
2262
- const hasRowConfidence = import_react3.default.useMemo(
2900
+ const hasRowConfidence = import_react4.default.useMemo(
2263
2901
  () => table.rows.some((row) => Boolean(row[ROW_META_KEY]?.confidence?.level)),
2264
2902
  [table]
2265
2903
  );
2266
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
2267
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__section-header", children: [
2268
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
2904
+ const columnDescriptions = import_react4.default.useMemo(() => {
2905
+ const map = /* @__PURE__ */ new Map();
2906
+ for (const column of mutable?.columns ?? []) {
2907
+ if (typeof column.key === "string" && column.description) {
2908
+ map.set(column.key, column.description);
2909
+ }
2910
+ }
2911
+ return map;
2912
+ }, [mutable]);
2913
+ const rowCount = planned ? planned.length : table.rows.length;
2914
+ const needsReview = import_react4.default.useMemo(
2915
+ () => table.rows.filter((row) => {
2916
+ const level = (row[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
2917
+ return level === "low" || level === "medium";
2918
+ }).length,
2919
+ [table.rows]
2920
+ );
2921
+ const showControls = planned !== void 0 && mutable !== void 0 && !shared.readOnly;
2922
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
2923
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__section-header", children: [
2924
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
2269
2925
  label,
2270
2926
  " (",
2271
- table.rows.length,
2272
- " rows)"
2927
+ rowCount,
2928
+ " rows",
2929
+ needsReview > 0 ? ` \xB7 ${needsReview} need review` : "",
2930
+ ")"
2273
2931
  ] }),
2274
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: table.overallConfidence })
2932
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConfidenceDot, { confidence: table.overallConfidence })
2275
2933
  ] }),
2276
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { className: "gemina-verification__table", children: [
2277
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
2278
- hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { "aria-label": "Show row on document" }) : null,
2279
- hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { "aria-label": "Row confidence" }) : null,
2280
- table.columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: formatLabel(column) }, column))
2934
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("table", { className: "gemina-verification__table", children: [
2935
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("tr", { children: [
2936
+ hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { "aria-label": "Show row on document" }) : null,
2937
+ hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { "aria-label": "Row confidence" }) : null,
2938
+ columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2939
+ FieldLabel,
2940
+ {
2941
+ label: formatLabel(column),
2942
+ description: columnDescriptions.get(column)
2943
+ }
2944
+ ) }, column)),
2945
+ showControls ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { "aria-label": "Row actions" }) : null
2281
2946
  ] }) }),
2282
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: table.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2947
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tbody", { children: planned ? planned.map((plannedRow, position) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2948
+ TableRow,
2949
+ {
2950
+ row: plannedRow.entry.source === null ? void 0 : table.rows[plannedRow.entry.source],
2951
+ rowIndex: position,
2952
+ columns,
2953
+ tableLabel: label,
2954
+ hasCoords,
2955
+ hasRowConfidence,
2956
+ shared,
2957
+ planned: plannedRow,
2958
+ tablePointer: mutable.pointer
2959
+ },
2960
+ plannedRow.entry.id
2961
+ )) : table.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2283
2962
  TableRow,
2284
2963
  {
2285
2964
  row,
2286
2965
  rowIndex,
2287
- columns: table.columns,
2966
+ columns,
2288
2967
  tableLabel: label,
2289
2968
  hasCoords,
2290
2969
  hasRowConfidence,
@@ -2292,19 +2971,28 @@ function TableSection(props) {
2292
2971
  },
2293
2972
  rowIndex
2294
2973
  )) })
2295
- ] }) })
2974
+ ] }) }),
2975
+ showControls ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__table-footer", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2976
+ "button",
2977
+ {
2978
+ type: "button",
2979
+ className: "gemina-verification__add-row",
2980
+ onClick: () => shared.onAddRow(mutable.pointer, rowCount - 1),
2981
+ children: "Add line"
2982
+ }
2983
+ ) }) : null
2296
2984
  ] });
2297
2985
  }
2298
- var FallbackSection = import_react3.default.memo(function FallbackSection2(props) {
2986
+ var FallbackSection = import_react4.default.memo(function FallbackSection2(props) {
2299
2987
  const { fallback } = props;
2300
2988
  if (fallback.length === 0) {
2301
2989
  return null;
2302
2990
  }
2303
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
2304
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
2305
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: "gemina-verification__fallback", children: [
2306
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: formatLabel(item.key) }),
2307
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { children: JSON.stringify(item.data, null, 2) })
2991
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
2992
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
2993
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: "gemina-verification__fallback", children: [
2994
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("summary", { children: formatLabel(item.key) }),
2995
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { children: JSON.stringify(item.data, null, 2) })
2308
2996
  ] }, item.key)) })
2309
2997
  ] });
2310
2998
  });
@@ -2313,14 +3001,15 @@ function UnmatchedSection(props) {
2313
3001
  if (unmatched.length === 0) {
2314
3002
  return null;
2315
3003
  }
2316
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
2317
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Not detected" }),
2318
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react3.default.Fragment, { children: [
2319
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: binding.key.label }) }),
2320
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3004
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
3005
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__section-header", children: "Not detected" }),
3006
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react4.default.Fragment, { children: [
3007
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: binding.key.label }) }),
3008
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2321
3009
  FieldInput,
2322
3010
  {
2323
3011
  binding,
3012
+ pairError: shared.pairErrors.get(binding.key.raw),
2324
3013
  edit: shared.edits.get(binding.key.raw),
2325
3014
  onEdit: shared.onEdit,
2326
3015
  readOnly: shared.readOnly,
@@ -2331,26 +3020,61 @@ function UnmatchedSection(props) {
2331
3020
  ] });
2332
3021
  }
2333
3022
  function VerificationForm(props) {
2334
- const { classified, unmatched, bindingIndex, edits, onEdit, readOnly, onFlash } = props;
2335
- const shared = { bindingIndex, edits, onEdit, readOnly, onFlash };
3023
+ const {
3024
+ classified,
3025
+ unmatched,
3026
+ bindingIndex,
3027
+ edits,
3028
+ onEdit,
3029
+ readOnly,
3030
+ onFlash,
3031
+ pairErrors,
3032
+ rowMutableTables,
3033
+ plannedTables,
3034
+ onAddRow,
3035
+ onRemoveRow
3036
+ } = props;
3037
+ const { tables: promotedTables, suppressed } = import_react4.default.useMemo(
3038
+ () => withEmptyMutableTables(classified, rowMutableTables ?? NO_TABLES),
3039
+ [classified, rowMutableTables]
3040
+ );
3041
+ const shared = {
3042
+ bindingIndex,
3043
+ edits,
3044
+ onEdit,
3045
+ readOnly,
3046
+ onFlash,
3047
+ pairErrors: pairErrors ?? NO_PAIR_ERRORS,
3048
+ rowMutableTables: rowMutableTables ?? NO_TABLES,
3049
+ plannedTables: plannedTables ?? NO_PLANNED,
3050
+ onAddRow: onAddRow ?? NOOP_ROW,
3051
+ onRemoveRow: onRemoveRow ?? NOOP_ROW
3052
+ };
2336
3053
  return (
2337
3054
  // A real, labeled <form> (role "form" landmark): AT users can jump
2338
3055
  // straight to the editable fields. Submission is owned by the root's
2339
3056
  // footer button, never by the form element itself — preventDefault stops
2340
3057
  // implicit submission (Enter in a payload with exactly one input would
2341
3058
  // otherwise navigate).
2342
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3059
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2343
3060
  "form",
2344
3061
  {
2345
3062
  className: "gemina-verification__form",
2346
3063
  "aria-label": "Extraction fields",
2347
3064
  onSubmit: (event) => event.preventDefault(),
2348
3065
  children: [
2349
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HeaderSection, { headers: classified.headers, simpleLists: classified.simpleLists, shared }),
2350
- classified.entities.map((entity) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(EntitySection, { entity, shared }, entity.pointer)),
2351
- classified.tables.map((table) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TableSection, { table, shared }, table.pointer)),
2352
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FallbackSection, { fallback: classified.fallback }),
2353
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UnmatchedSection, { unmatched, shared })
3066
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3067
+ HeaderSection,
3068
+ {
3069
+ headers: classified.headers.filter((header) => !suppressed.has(header.pointer)),
3070
+ simpleLists: classified.simpleLists,
3071
+ shared
3072
+ }
3073
+ ),
3074
+ classified.entities.map((entity) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EntitySection, { entity, shared }, entity.pointer)),
3075
+ promotedTables.map((table) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TableSection, { table, shared }, table.pointer)),
3076
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FallbackSection, { fallback: classified.fallback }),
3077
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UnmatchedSection, { unmatched, shared })
2354
3078
  ]
2355
3079
  }
2356
3080
  )
@@ -2614,6 +3338,10 @@ var VERIFICATION_CSS = `
2614
3338
  }
2615
3339
  .gemina-verification__dd {
2616
3340
  display: flex;
3341
+ /* Wrap so a field error takes its OWN line (it sets flex-basis:100%).
3342
+ Without this it competes with the input for width, and at 390px the
3343
+ message wrapped to one word per line while the input shrank to ~55px. */
3344
+ flex-wrap: wrap;
2617
3345
  align-items: center;
2618
3346
  gap: 6px;
2619
3347
  margin: 0; /* resets the UA's margin-inline-start on <dd> */
@@ -2688,6 +3416,7 @@ var VERIFICATION_CSS = `
2688
3416
  and list items \u2014 the fragment has no container of its own. */
2689
3417
  .gemina-verification__cell {
2690
3418
  display: flex;
3419
+ flex-wrap: wrap; /* same reason as __dd: the field error needs its own line */
2691
3420
  align-items: center;
2692
3421
  gap: 6px;
2693
3422
  min-width: 0;
@@ -2948,6 +3677,157 @@ var VERIFICATION_CSS = `
2948
3677
  transition: none;
2949
3678
  }
2950
3679
  }
3680
+
3681
+ /* A label that carries a description. Dotted underline is the long-standing
3682
+ convention for "there is more here", and tabIndex makes it reachable, so the
3683
+ tooltip is not mouse-only. */
3684
+ .gemina-verification__label-described {
3685
+ text-decoration: underline dotted;
3686
+ text-underline-offset: 3px;
3687
+ cursor: help;
3688
+ }
3689
+ .gemina-verification__label-described:focus-visible {
3690
+ outline: 2px solid var(--gemina-verification-accent);
3691
+ outline-offset: 2px;
3692
+ }
3693
+
3694
+ /* Rows worth a second look. Uses the EXISTING confidence tokens \u2014 no new
3695
+ colours \u2014 as a start-edge rule, which is the one edge a reviewer scans down
3696
+ a long table. Logical property, so it lands on the right side under RTL. */
3697
+ .gemina-verification__row--low > td:first-child,
3698
+ .gemina-verification__row--medium > td:first-child {
3699
+ border-inline-start: 3px solid transparent;
3700
+ }
3701
+ .gemina-verification__row--low > td:first-child {
3702
+ border-inline-start-color: var(--gemina-verification-confidence-low);
3703
+ }
3704
+ .gemina-verification__row--medium > td:first-child {
3705
+ border-inline-start-color: var(--gemina-verification-confidence-medium);
3706
+ }
3707
+
3708
+ /* --- Row editing ----------------------------------------------------------
3709
+ Quiet by design: adding and removing lines is a correction, not the primary
3710
+ action, so the controls stay muted until hovered and the accent is left to
3711
+ Submit. */
3712
+ .gemina-verification__row-actions {
3713
+ white-space: nowrap;
3714
+ text-align: end; /* logical \u2014 RTL for free */
3715
+ }
3716
+ .gemina-verification__row-btn {
3717
+ font: inherit;
3718
+ line-height: 1;
3719
+ padding: 2px 7px;
3720
+ margin-inline-start: 4px;
3721
+ border-radius: calc(var(--gemina-verification-radius) - 5px);
3722
+ border: 1px solid var(--gemina-verification-border);
3723
+ background: transparent;
3724
+ color: var(--gemina-verification-muted);
3725
+ cursor: pointer;
3726
+ transition: border-color 120ms ease, color 120ms ease;
3727
+ }
3728
+ .gemina-verification__row-btn:hover {
3729
+ border-color: var(--gemina-verification-accent);
3730
+ color: var(--gemina-verification-fg);
3731
+ }
3732
+ .gemina-verification__table-footer {
3733
+ display: flex;
3734
+ padding: 8px 10px 0;
3735
+ }
3736
+ .gemina-verification__add-row {
3737
+ font: inherit;
3738
+ font-size: 12px;
3739
+ padding: 4px 10px;
3740
+ border-radius: calc(var(--gemina-verification-radius) - 4px);
3741
+ border: 1px dashed var(--gemina-verification-border);
3742
+ background: transparent;
3743
+ color: var(--gemina-verification-muted);
3744
+ cursor: pointer;
3745
+ }
3746
+ .gemina-verification__add-row:hover {
3747
+ border-style: solid;
3748
+ border-color: var(--gemina-verification-accent);
3749
+ color: var(--gemina-verification-fg);
3750
+ }
3751
+
3752
+ /* --- Typed controls -------------------------------------------------------
3753
+ A <select> for a closed roster must sit on the same baseline as the text
3754
+ inputs beside it in a table row, so it inherits the input's box entirely and
3755
+ only overrides what a select needs. */
3756
+ .gemina-verification__input:is(select) {
3757
+ cursor: pointer;
3758
+ /* A select's intrinsic width follows its longest option \u2014 the 24-member unit
3759
+ roster would blow out the column. */
3760
+ max-width: 100%;
3761
+ }
3762
+ /* The error border must beat --dirty and --missed: an invalid value is the
3763
+ most urgent thing true about the field, and the reviewer cannot submit
3764
+ until it is fixed. Placed after both for cascade order. */
3765
+ .gemina-verification__input--invalid,
3766
+ .gemina-verification__input--invalid:focus-visible {
3767
+ border-color: var(--gemina-verification-error);
3768
+ }
3769
+ /* Sits under the control it describes. Basis 100% breaks it onto its own line
3770
+ inside the flex row FieldInput renders into, so it never squeezes the
3771
+ input. */
3772
+ .gemina-verification__field-error {
3773
+ flex-basis: 100%;
3774
+ margin-block-start: 4px;
3775
+ color: var(--gemina-verification-error);
3776
+ font-size: 12px;
3777
+ line-height: 1.35;
3778
+ }
3779
+
3780
+ /* Replaces __progress while anything is invalid \u2014 same slot, so the footer
3781
+ never grows a second status line competing for the same attention. */
3782
+ .gemina-verification__attention {
3783
+ color: var(--gemina-verification-error);
3784
+ font-size: 13px;
3785
+ }
3786
+
3787
+ /* --- Tooltip -------------------------------------------------------------
3788
+ Renders in a portal on document.body, inside a div carrying the root's
3789
+ class list \u2014 so these rules and every --gemina-verification-* custom
3790
+ property resolve exactly as they do in the component.
3791
+
3792
+ Quieter than __confirm-dialog on purpose: an annotation, not a decision.
3793
+ Same border and shadow family, one step down in radius (the nested-element
3794
+ convention used by __chip et al), surface rather than bg so it separates
3795
+ from the panel it floats over, and a shorter shadow so it reads as sitting
3796
+ just above the page rather than over a scrim. */
3797
+ .gemina-verification__tip {
3798
+ position: fixed;
3799
+ z-index: 2147483000; /* above the host's own modal \u2014 this is the topmost layer */
3800
+ max-width: 260px; /* ~60 characters: past that a tooltip should be body copy */
3801
+ padding: 8px 10px;
3802
+ background: var(--gemina-verification-surface);
3803
+ color: var(--gemina-verification-fg);
3804
+ border: 1px solid var(--gemina-verification-border);
3805
+ border-radius: calc(var(--gemina-verification-radius) - 4px);
3806
+ box-shadow: 0 6px 16px rgba(16, 20, 24, 0.18);
3807
+ font-family: var(--gemina-verification-font);
3808
+ font-size: 12px;
3809
+ line-height: 1.45;
3810
+ text-align: start; /* logical \u2014 RTL for free */
3811
+ pointer-events: none; /* never eat the hover that opened it */
3812
+ }
3813
+ /* Structured content: a level heading over a reasons list. The list is the
3814
+ reason this exists at all \u2014 title= could only ever have been one line. */
3815
+ .gemina-verification__tip-title {
3816
+ display: block;
3817
+ font-weight: 600;
3818
+ margin-block-end: 4px;
3819
+ }
3820
+ .gemina-verification__tip-list {
3821
+ margin: 0;
3822
+ padding-inline-start: 16px;
3823
+ }
3824
+ .gemina-verification__tip-list li + li {
3825
+ margin-block-start: 2px;
3826
+ }
3827
+ /* A muted lead-in for single-fact tips ("Was:"), so the VALUE reads first. */
3828
+ .gemina-verification__tip-label {
3829
+ color: var(--gemina-verification-muted);
3830
+ }
2951
3831
  `;
2952
3832
  var STYLE_ATTR2 = "data-gemina-verification";
2953
3833
  function ensureVerificationStylesInjected() {
@@ -2964,7 +3844,7 @@ function ensureVerificationStylesInjected() {
2964
3844
  }
2965
3845
 
2966
3846
  // src/verification/index.tsx
2967
- var import_jsx_runtime4 = require("react/jsx-runtime");
3847
+ var import_jsx_runtime5 = require("react/jsx-runtime");
2968
3848
  var HEBREW_RE2 = /[\u0590-\u05FF]/;
2969
3849
  var STACKED_BREAKPOINT = 860;
2970
3850
  var IMAGE_REFRESH_THROTTLE_MS = 6e4;
@@ -2977,11 +3857,23 @@ var PURGED_TEXT = "Document no longer available (retention policy).";
2977
3857
  var NOT_COMPLETED_TEXT = "This extraction did not complete, so there is nothing to verify.";
2978
3858
  var VERIFICATION_UNAVAILABLE_TEXT = "Verification isn't available for this extraction.";
2979
3859
  var ALREADY_VALIDATED_TEXT = "Already verified \u2014 showing the original extraction.";
2980
- var CONFIRM_TEXT = "Submit verification? This is final \u2014 feedback can be submitted only once and cannot be changed.";
3860
+ var CONFIRM_TEXT = "Submit these values? This is final \u2014 they can be submitted once and can't be changed.";
2981
3861
  var SUBMITTING_TEXT = "Submitting\u2026";
2982
3862
  var SUBMIT_FAILED_TEXT = "Submission failed \u2014 your corrections are still here.";
2983
- var DONE_TITLE_TEXT = "Feedback submitted";
3863
+ var DONE_TITLE_TEXT = "Submitted";
2984
3864
  var NO_EDITS = /* @__PURE__ */ new Map();
3865
+ var NO_ROW_PLANS = /* @__PURE__ */ new Map();
3866
+ var NO_PLANNED_TABLES = /* @__PURE__ */ new Map();
3867
+ function seedRowPlans(tables, values) {
3868
+ if (tables.length === 0) {
3869
+ return NO_ROW_PLANS;
3870
+ }
3871
+ const plans = /* @__PURE__ */ new Map();
3872
+ for (const table of tables) {
3873
+ plans.set(table.pointer, initialRowPlan(countRowsAt(values, table.pointer), table.pointer));
3874
+ }
3875
+ return plans;
3876
+ }
2985
3877
  var ALERT_REASONS = /* @__PURE__ */ new Set([
2986
3878
  "session-expired",
2987
3879
  "not-available",
@@ -2998,43 +3890,44 @@ function GeminaVerification(props) {
2998
3890
  onError,
2999
3891
  className
3000
3892
  } = props;
3001
- const [phase, setPhase] = (0, import_react4.useState)({ name: "loading" });
3002
- const [alreadyValidated, setAlreadyValidated] = (0, import_react4.useState)(false);
3003
- const [loaded, setLoaded] = (0, import_react4.useState)(null);
3004
- const [edits, setEdits] = (0, import_react4.useState)(NO_EDITS);
3005
- const [imageUrl, setImageUrl] = (0, import_react4.useState)(null);
3006
- const [flashRects, setFlashRects] = (0, import_react4.useState)(null);
3007
- const [stacked, setStacked] = (0, import_react4.useState)(false);
3008
- const rootRef = (0, import_react4.useRef)(null);
3009
- const mountedRef = (0, import_react4.useRef)(false);
3010
- const loadSeqRef = (0, import_react4.useRef)(0);
3011
- const lastImageRefreshRef = (0, import_react4.useRef)(0);
3012
- const onErrorRef = (0, import_react4.useRef)(onError);
3893
+ const [phase, setPhase] = (0, import_react5.useState)({ name: "loading" });
3894
+ const [alreadyValidated, setAlreadyValidated] = (0, import_react5.useState)(false);
3895
+ const [loaded, setLoaded] = (0, import_react5.useState)(null);
3896
+ const [rowPlans, setRowPlans] = (0, import_react5.useState)(NO_ROW_PLANS);
3897
+ const [edits, setEdits] = (0, import_react5.useState)(NO_EDITS);
3898
+ const [imageUrl, setImageUrl] = (0, import_react5.useState)(null);
3899
+ const [flashRects, setFlashRects] = (0, import_react5.useState)(null);
3900
+ const [stacked, setStacked] = (0, import_react5.useState)(false);
3901
+ const rootRef = (0, import_react5.useRef)(null);
3902
+ const mountedRef = (0, import_react5.useRef)(false);
3903
+ const loadSeqRef = (0, import_react5.useRef)(0);
3904
+ const lastImageRefreshRef = (0, import_react5.useRef)(0);
3905
+ const onErrorRef = (0, import_react5.useRef)(onError);
3013
3906
  onErrorRef.current = onError;
3014
- const onCompleteRef = (0, import_react4.useRef)(onComplete);
3907
+ const onCompleteRef = (0, import_react5.useRef)(onComplete);
3015
3908
  onCompleteRef.current = onComplete;
3016
- const completedRef = (0, import_react4.useRef)(false);
3017
- const submitInFlightRef = (0, import_react4.useRef)(false);
3018
- const restoreFocusRef = (0, import_react4.useRef)(false);
3019
- const submitButtonRef = (0, import_react4.useRef)(null);
3020
- const confirmButtonRef = (0, import_react4.useRef)(null);
3021
- const cancelButtonRef = (0, import_react4.useRef)(null);
3022
- const retrySubmitButtonRef = (0, import_react4.useRef)(null);
3023
- const doneStateRef = (0, import_react4.useRef)(null);
3024
- const enterUnavailable = (0, import_react4.useCallback)(
3909
+ const completedRef = (0, import_react5.useRef)(false);
3910
+ const submitInFlightRef = (0, import_react5.useRef)(false);
3911
+ const restoreFocusRef = (0, import_react5.useRef)(false);
3912
+ const submitButtonRef = (0, import_react5.useRef)(null);
3913
+ const confirmButtonRef = (0, import_react5.useRef)(null);
3914
+ const cancelButtonRef = (0, import_react5.useRef)(null);
3915
+ const retrySubmitButtonRef = (0, import_react5.useRef)(null);
3916
+ const doneStateRef = (0, import_react5.useRef)(null);
3917
+ const enterUnavailable = (0, import_react5.useCallback)(
3025
3918
  (reason, message, canRetry, detail) => {
3026
3919
  setPhase({ name: "unavailable", reason, message, canRetry });
3027
3920
  onErrorRef.current?.(reason, detail);
3028
3921
  },
3029
3922
  []
3030
3923
  );
3031
- const fetchOnce = (0, import_react4.useCallback)(async () => {
3924
+ const fetchOnce = (0, import_react5.useCallback)(async () => {
3032
3925
  const token = await tokenManager.getToken();
3033
3926
  return import_sdk2.GeminaClient.withSessionToken(token, baseUrl).documents.getDocumentExtraction({
3034
3927
  documentExtractionId: extractionId
3035
3928
  });
3036
3929
  }, [tokenManager, baseUrl, extractionId]);
3037
- const fetchWithRetry = (0, import_react4.useCallback)(async () => {
3930
+ const fetchWithRetry = (0, import_react5.useCallback)(async () => {
3038
3931
  try {
3039
3932
  return await fetchOnce();
3040
3933
  } catch (error) {
@@ -3045,7 +3938,7 @@ function GeminaVerification(props) {
3045
3938
  return await fetchOnce();
3046
3939
  }
3047
3940
  }, [fetchOnce, tokenManager]);
3048
- const load = (0, import_react4.useCallback)(async () => {
3941
+ const load = (0, import_react5.useCallback)(async () => {
3049
3942
  const seq = ++loadSeqRef.current;
3050
3943
  const live = () => mountedRef.current && loadSeqRef.current === seq;
3051
3944
  setPhase({ name: "loading" });
@@ -3076,9 +3969,12 @@ function GeminaVerification(props) {
3076
3969
  const schema = view.meta.validationFeedback?.validationSchema;
3077
3970
  setLoaded({
3078
3971
  values: view.values,
3079
- schema: Array.isArray(schema) ? schema : []
3972
+ schema: Array.isArray(schema) ? schema : [],
3973
+ fields: readDescriptors(view.meta.validationFeedback?.validationFields),
3974
+ rowMutableTables: readRowMutableTables(view.meta.validationFeedback?.rowMutableTables)
3080
3975
  });
3081
3976
  setEdits(NO_EDITS);
3977
+ setRowPlans(seedRowPlans(readRowMutableTables(view.meta.validationFeedback?.rowMutableTables), view.values));
3082
3978
  const url = view.document.imageUrl;
3083
3979
  setImageUrl(typeof url === "string" && url.length > 0 ? url : null);
3084
3980
  setAlreadyValidated(validated);
@@ -3096,7 +3992,7 @@ function GeminaVerification(props) {
3096
3992
  enterReview(false);
3097
3993
  }
3098
3994
  }, [fetchWithRetry, enterUnavailable]);
3099
- (0, import_react4.useEffect)(() => {
3995
+ (0, import_react5.useEffect)(() => {
3100
3996
  mountedRef.current = true;
3101
3997
  ensureVerificationStylesInjected();
3102
3998
  void load();
@@ -3104,7 +4000,7 @@ function GeminaVerification(props) {
3104
4000
  mountedRef.current = false;
3105
4001
  };
3106
4002
  }, [load]);
3107
- (0, import_react4.useEffect)(() => {
4003
+ (0, import_react5.useEffect)(() => {
3108
4004
  const el = rootRef.current;
3109
4005
  if (el === null) {
3110
4006
  return;
@@ -3125,10 +4021,20 @@ function GeminaVerification(props) {
3125
4021
  observer.observe(el);
3126
4022
  return () => observer.disconnect();
3127
4023
  }, []);
3128
- const classified = (0, import_react4.useMemo)(() => classifyData(loaded?.values), [loaded]);
3129
- const bindings = (0, import_react4.useMemo)(() => buildBindings(loaded?.schema ?? [], loaded?.values), [loaded]);
3130
- const bindingIndex = (0, import_react4.useMemo)(() => indexBindingsByFieldPointer(bindings), [bindings]);
3131
- const unmatched = (0, import_react4.useMemo)(() => {
4024
+ const classified = (0, import_react5.useMemo)(() => classifyData(loaded?.values), [loaded]);
4025
+ const bindings = (0, import_react5.useMemo)(
4026
+ () => buildBindings(loaded?.schema ?? [], loaded?.values, loaded?.fields),
4027
+ [loaded]
4028
+ );
4029
+ const bindingIndex = (0, import_react5.useMemo)(() => indexBindingsByFieldPointer(bindings), [bindings]);
4030
+ const bindingsByRawKey = (0, import_react5.useMemo)(() => {
4031
+ const map = /* @__PURE__ */ new Map();
4032
+ for (const binding of bindings) {
4033
+ map.set(binding.key.raw, binding);
4034
+ }
4035
+ return map;
4036
+ }, [bindings]);
4037
+ const unmatched = (0, import_react5.useMemo)(() => {
3132
4038
  const rendered = /* @__PURE__ */ new Set();
3133
4039
  for (const field of classified.headers) {
3134
4040
  rendered.add(field.pointer);
@@ -3156,7 +4062,7 @@ function GeminaVerification(props) {
3156
4062
  }
3157
4063
  return bindings.filter((binding) => !rendered.has(binding.fieldPointer));
3158
4064
  }, [classified, bindings]);
3159
- const overlayRects = (0, import_react4.useMemo)(() => {
4065
+ const overlayRects = (0, import_react5.useMemo)(() => {
3160
4066
  const rects = [];
3161
4067
  for (const field of classified.headers) {
3162
4068
  if (field.coordinates) {
@@ -3190,48 +4096,87 @@ function GeminaVerification(props) {
3190
4096
  }
3191
4097
  return rects.length > 0 ? rects : void 0;
3192
4098
  }, [classified]);
3193
- const hasHebrewContent = (0, import_react4.useMemo)(
4099
+ const hasHebrewContent = (0, import_react5.useMemo)(
3194
4100
  () => bindings.some((binding) => HEBREW_RE2.test(toInputString(binding.extracted))),
3195
4101
  [bindings]
3196
4102
  );
3197
4103
  const effectiveDir = dir === "auto" ? hasHebrewContent ? "rtl" : "ltr" : dir;
3198
- const bindingsByRawKey = (0, import_react4.useMemo)(() => {
3199
- const map = /* @__PURE__ */ new Map();
3200
- for (const binding of bindings) {
3201
- map.set(binding.key.raw, binding);
3202
- }
3203
- return map;
3204
- }, [bindings]);
3205
- const bindingsByRawKeyRef = (0, import_react4.useRef)(bindingsByRawKey);
3206
- bindingsByRawKeyRef.current = bindingsByRawKey;
3207
- const handleEdit = (0, import_react4.useCallback)((rawKey, value) => {
3208
- const binding = bindingsByRawKeyRef.current.get(rawKey);
3209
- const pristine = binding !== void 0 && value === toInputString(binding.extracted);
4104
+ const handleEdit = (0, import_react5.useCallback)((editKey, value, binding) => {
4105
+ const pristine = value === toInputString(binding.extracted);
3210
4106
  setEdits((prev) => {
3211
4107
  if (pristine) {
3212
- if (!prev.has(rawKey)) {
4108
+ if (!prev.has(editKey)) {
3213
4109
  return prev;
3214
4110
  }
3215
4111
  const next2 = new Map(prev);
3216
- next2.delete(rawKey);
4112
+ next2.delete(editKey);
3217
4113
  return next2;
3218
4114
  }
3219
- if (prev.get(rawKey) === value) {
4115
+ if (prev.get(editKey) === value) {
3220
4116
  return prev;
3221
4117
  }
3222
4118
  const next = new Map(prev);
3223
- next.set(rawKey, value);
4119
+ next.set(editKey, value);
3224
4120
  return next;
3225
4121
  });
3226
4122
  }, []);
3227
- const submission = (0, import_react4.useMemo)(() => composeSubmission(bindings, edits), [bindings, edits]);
3228
- const handleFlash = (0, import_react4.useCallback)((rects) => {
4123
+ const plannedTables = (0, import_react5.useMemo)(() => {
4124
+ const tables = loaded?.rowMutableTables ?? [];
4125
+ if (tables.length === 0) {
4126
+ return NO_PLANNED_TABLES;
4127
+ }
4128
+ const out = /* @__PURE__ */ new Map();
4129
+ for (const table of tables) {
4130
+ const plan = rowPlans.get(table.pointer);
4131
+ if (plan === void 0) {
4132
+ continue;
4133
+ }
4134
+ const classifiedTable = classified.tables.find(
4135
+ (candidate) => matchesTablePointer(table.pointer, candidate.pointer)
4136
+ );
4137
+ const columns = displayColumns(table, classifiedTable?.columns ?? []);
4138
+ out.set(table.pointer, planTableCells(table, plan, columns, bindingsByRawKey));
4139
+ }
4140
+ return out;
4141
+ }, [loaded, rowPlans, classified, bindingsByRawKey]);
4142
+ const cellViews = (0, import_react5.useMemo)(
4143
+ () => collectCellViews(bindings, plannedTables),
4144
+ [bindings, plannedTables]
4145
+ );
4146
+ const submissionTables = (0, import_react5.useMemo)(
4147
+ () => pruneEmptyAddedRows(plannedTables, edits),
4148
+ [plannedTables, edits]
4149
+ );
4150
+ const submissionCells = (0, import_react5.useMemo)(
4151
+ () => collectCellViews(bindings, submissionTables),
4152
+ [bindings, submissionTables]
4153
+ );
4154
+ const rowSources = (0, import_react5.useMemo)(() => {
4155
+ const entries = [];
4156
+ for (const table of loaded?.rowMutableTables ?? []) {
4157
+ const rows = submissionTables.get(table.pointer);
4158
+ if (rows === void 0) {
4159
+ continue;
4160
+ }
4161
+ const plan = rows.map((row) => row.entry);
4162
+ if (isIdentityPlan(plan, countRowsAt(loaded?.values, table.pointer))) {
4163
+ continue;
4164
+ }
4165
+ entries.push({ table: table.pointer, sources: rowSourcesOf(plan) });
4166
+ }
4167
+ return entries;
4168
+ }, [loaded, submissionTables]);
4169
+ const submission = (0, import_react5.useMemo)(
4170
+ () => composeSubmission(bindings, edits, { cells: submissionCells, rowSources }),
4171
+ [bindings, edits, submissionCells, rowSources]
4172
+ );
4173
+ const handleFlash = (0, import_react5.useCallback)((rects) => {
3229
4174
  setFlashRects(rects.map((rect) => ({ points: rect.points })));
3230
4175
  }, []);
3231
- const handleFlashComplete = (0, import_react4.useCallback)(() => {
4176
+ const handleFlashComplete = (0, import_react5.useCallback)(() => {
3232
4177
  setFlashRects(null);
3233
4178
  }, []);
3234
- const handleImageExpired = (0, import_react4.useCallback)(() => {
4179
+ const handleImageExpired = (0, import_react5.useCallback)(() => {
3235
4180
  const now = Date.now();
3236
4181
  if (now - lastImageRefreshRef.current < IMAGE_REFRESH_THROTTLE_MS) {
3237
4182
  return;
@@ -3249,10 +4194,52 @@ function GeminaVerification(props) {
3249
4194
  }).catch(() => {
3250
4195
  });
3251
4196
  }, [fetchWithRetry]);
3252
- const handleRetry = (0, import_react4.useCallback)(() => {
4197
+ const handleRetry = (0, import_react5.useCallback)(() => {
3253
4198
  void load();
3254
4199
  }, [load]);
3255
- const doSubmit = (0, import_react4.useCallback)(async () => {
4200
+ const handleAddRow = (0, import_react5.useCallback)((tablePointer, afterPosition) => {
4201
+ const id = nextAddedRowId(tablePointer);
4202
+ setRowPlans((prev) => {
4203
+ const plan = prev.get(tablePointer);
4204
+ if (plan === void 0) {
4205
+ return prev;
4206
+ }
4207
+ const next = new Map(prev);
4208
+ next.set(tablePointer, insertRowAfter(plan, afterPosition, id));
4209
+ return next;
4210
+ });
4211
+ }, []);
4212
+ const handleRemoveRow = (0, import_react5.useCallback)((tablePointer, position) => {
4213
+ setRowPlans((prev) => {
4214
+ const plan = prev.get(tablePointer);
4215
+ if (plan === void 0) {
4216
+ return prev;
4217
+ }
4218
+ const nextPlan = removeRow(plan, position);
4219
+ if (nextPlan === plan) {
4220
+ return prev;
4221
+ }
4222
+ const next = new Map(prev);
4223
+ next.set(tablePointer, nextPlan);
4224
+ return next;
4225
+ });
4226
+ }, []);
4227
+ const pairErrors = (0, import_react5.useMemo)(() => unitSizePairErrors(cellViews, edits), [cellViews, edits]);
4228
+ const invalidCount = (0, import_react5.useMemo)(() => {
4229
+ const rowLevel = pairErrors.size;
4230
+ if (edits.size === 0) {
4231
+ return rowLevel;
4232
+ }
4233
+ const byEditKey = new Map(cellViews.map((view) => [view.editKey, view.binding]));
4234
+ let count = 0;
4235
+ for (const [editKey, value] of edits) {
4236
+ if (!pairErrors.has(editKey) && validateInput(value, byEditKey.get(editKey)?.field) !== null) {
4237
+ count += 1;
4238
+ }
4239
+ }
4240
+ return count + rowLevel;
4241
+ }, [edits, cellViews, pairErrors]);
4242
+ const doSubmit = (0, import_react5.useCallback)(async () => {
3256
4243
  if (submitInFlightRef.current) {
3257
4244
  return;
3258
4245
  }
@@ -3265,7 +4252,13 @@ function GeminaVerification(props) {
3265
4252
  const token = await tokenManager.getToken();
3266
4253
  return import_sdk2.GeminaClient.withSessionToken(token, baseUrl).documents.validateDocumentExtraction({
3267
4254
  targetDocumentExtractionId: extractionId,
3268
- extractionValidationInDTO: { data: body.data }
4255
+ // Conditional spread, matching the house pattern: without a row edit
4256
+ // the request body is byte-identical to what it was before this
4257
+ // feature, so nothing changes for the overwhelmingly common path.
4258
+ extractionValidationInDTO: {
4259
+ data: body.data,
4260
+ ...body.rowSources.length > 0 ? { rowSources: body.rowSources } : {}
4261
+ }
3269
4262
  });
3270
4263
  };
3271
4264
  try {
@@ -3313,20 +4306,20 @@ function GeminaVerification(props) {
3313
4306
  submitInFlightRef.current = false;
3314
4307
  }
3315
4308
  }, [submission, tokenManager, baseUrl, extractionId, load]);
3316
- const handleSubmitClick = (0, import_react4.useCallback)(() => {
4309
+ const handleSubmitClick = (0, import_react5.useCallback)(() => {
3317
4310
  setPhase({ name: "confirming" });
3318
4311
  }, []);
3319
- const handleConfirm = (0, import_react4.useCallback)(() => {
4312
+ const handleConfirm = (0, import_react5.useCallback)(() => {
3320
4313
  void doSubmit();
3321
4314
  }, [doSubmit]);
3322
- const handleCancelConfirm = (0, import_react4.useCallback)(() => {
4315
+ const handleCancelConfirm = (0, import_react5.useCallback)(() => {
3323
4316
  restoreFocusRef.current = true;
3324
4317
  setPhase({ name: "review" });
3325
4318
  }, []);
3326
- const handleRetrySubmit = (0, import_react4.useCallback)(() => {
4319
+ const handleRetrySubmit = (0, import_react5.useCallback)(() => {
3327
4320
  void doSubmit();
3328
4321
  }, [doSubmit]);
3329
- const handleConfirmKeyDown = (0, import_react4.useCallback)(
4322
+ const handleConfirmKeyDown = (0, import_react5.useCallback)(
3330
4323
  (event) => {
3331
4324
  if (phase.name !== "confirming") {
3332
4325
  return;
@@ -3357,7 +4350,7 @@ function GeminaVerification(props) {
3357
4350
  },
3358
4351
  [phase.name, handleCancelConfirm]
3359
4352
  );
3360
- (0, import_react4.useEffect)(() => {
4353
+ (0, import_react5.useEffect)(() => {
3361
4354
  if (phase.name === "confirming") {
3362
4355
  confirmButtonRef.current?.focus();
3363
4356
  } else if (phase.name === "review" && restoreFocusRef.current) {
@@ -3376,13 +4369,13 @@ function GeminaVerification(props) {
3376
4369
  stacked ? "gemina-verification--stacked" : "",
3377
4370
  className ?? ""
3378
4371
  ].filter((part) => part.length > 0).join(" ");
3379
- const dialogTextId = (0, import_react4.useId)();
4372
+ const dialogTextId = (0, import_react5.useId)();
3380
4373
  const renderReview = (reviewPhase) => {
3381
4374
  const overlayUp = reviewPhase.name === "confirming" || reviewPhase.name === "submitting";
3382
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
3383
- alreadyValidated && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
3384
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__panes", children: [
3385
- imageUrl !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4375
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
4376
+ alreadyValidated && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
4377
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "gemina-verification__panes", children: [
4378
+ imageUrl !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3386
4379
  VerificationViewer,
3387
4380
  {
3388
4381
  src: imageUrl,
@@ -3392,7 +4385,7 @@ function GeminaVerification(props) {
3392
4385
  onImageExpired: handleImageExpired
3393
4386
  }
3394
4387
  ),
3395
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4388
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3396
4389
  VerificationForm,
3397
4390
  {
3398
4391
  classified,
@@ -3401,18 +4394,23 @@ function GeminaVerification(props) {
3401
4394
  edits,
3402
4395
  onEdit: handleEdit,
3403
4396
  readOnly: alreadyValidated,
3404
- onFlash: handleFlash
4397
+ onFlash: handleFlash,
4398
+ pairErrors,
4399
+ rowMutableTables: loaded?.rowMutableTables,
4400
+ plannedTables,
4401
+ onAddRow: handleAddRow,
4402
+ onRemoveRow: handleRemoveRow
3405
4403
  }
3406
4404
  )
3407
4405
  ] }),
3408
- reviewPhase.name === "submit-error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
4406
+ reviewPhase.name === "submit-error" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3409
4407
  "div",
3410
4408
  {
3411
4409
  className: "gemina-verification__banner gemina-verification__banner--error gemina-verification__submit-error",
3412
4410
  role: "alert",
3413
4411
  children: [
3414
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: reviewPhase.message }),
3415
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4412
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: reviewPhase.message }),
4413
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3416
4414
  "button",
3417
4415
  {
3418
4416
  type: "button",
@@ -3425,21 +4423,21 @@ function GeminaVerification(props) {
3425
4423
  ]
3426
4424
  }
3427
4425
  ),
3428
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__footer", children: [
3429
- !alreadyValidated && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` }),
3430
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4426
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "gemina-verification__footer", children: [
4427
+ !alreadyValidated && (invalidCount > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__attention", "aria-live": "polite", children: invalidCount === 1 ? "1 field needs attention" : `${invalidCount} fields need attention` }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` })),
4428
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3431
4429
  "button",
3432
4430
  {
3433
4431
  type: "button",
3434
4432
  ref: submitButtonRef,
3435
4433
  className: "gemina-verification__submit",
3436
- disabled: alreadyValidated || reviewPhase.name !== "review",
4434
+ disabled: alreadyValidated || reviewPhase.name !== "review" || invalidCount > 0,
3437
4435
  onClick: handleSubmitClick,
3438
- children: "Submit feedback"
4436
+ children: "Submit"
3439
4437
  }
3440
4438
  )
3441
4439
  ] }),
3442
- overlayUp && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4440
+ overlayUp && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3443
4441
  "div",
3444
4442
  {
3445
4443
  className: "gemina-verification__confirm",
@@ -3449,7 +4447,7 @@ function GeminaVerification(props) {
3449
4447
  event.preventDefault();
3450
4448
  }
3451
4449
  },
3452
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
4450
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3453
4451
  "div",
3454
4452
  {
3455
4453
  className: "gemina-verification__confirm-dialog",
@@ -3457,9 +4455,9 @@ function GeminaVerification(props) {
3457
4455
  "aria-modal": "true",
3458
4456
  "aria-labelledby": dialogTextId,
3459
4457
  children: [
3460
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
3461
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__confirm-actions", children: [
3462
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4458
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
4459
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "gemina-verification__confirm-actions", children: [
4460
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3463
4461
  "button",
3464
4462
  {
3465
4463
  type: "button",
@@ -3470,7 +4468,7 @@ function GeminaVerification(props) {
3470
4468
  children: "Cancel"
3471
4469
  }
3472
4470
  ),
3473
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4471
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3474
4472
  "button",
3475
4473
  {
3476
4474
  type: "button",
@@ -3492,16 +4490,16 @@ function GeminaVerification(props) {
3492
4490
  const content = (() => {
3493
4491
  switch (phase.name) {
3494
4492
  case "loading":
3495
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
4493
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
3496
4494
  case "unavailable":
3497
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
4495
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3498
4496
  "div",
3499
4497
  {
3500
4498
  className: "gemina-verification__state",
3501
4499
  role: ALERT_REASONS.has(phase.reason) ? "alert" : "status",
3502
4500
  children: [
3503
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: phase.message }),
3504
- phase.canRetry && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
4501
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: phase.message }),
4502
+ phase.canRetry && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
3505
4503
  ]
3506
4504
  }
3507
4505
  );
@@ -3511,7 +4509,7 @@ function GeminaVerification(props) {
3511
4509
  case "submit-error":
3512
4510
  return renderReview(phase);
3513
4511
  case "done":
3514
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
4512
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3515
4513
  "div",
3516
4514
  {
3517
4515
  ref: doneStateRef,
@@ -3519,7 +4517,7 @@ function GeminaVerification(props) {
3519
4517
  className: "gemina-verification__state gemina-verification__state--done",
3520
4518
  role: "status",
3521
4519
  children: [
3522
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
4520
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3523
4521
  "path",
3524
4522
  {
3525
4523
  d: "M4 10.5l4 4 8-9",
@@ -3529,14 +4527,14 @@ function GeminaVerification(props) {
3529
4527
  strokeLinejoin: "round"
3530
4528
  }
3531
4529
  ) }) }),
3532
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
3533
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
4530
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
4531
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
3534
4532
  ]
3535
4533
  }
3536
4534
  );
3537
4535
  }
3538
4536
  })();
3539
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
4537
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
3540
4538
  }
3541
4539
  // Annotate the CommonJS export names for ESM import in node:
3542
4540
  0 && (module.exports = {