@claritylabs/cl-sdk 3.1.11 → 3.1.12

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.mjs CHANGED
@@ -10923,6 +10923,42 @@ function columnLabelStartIndex(rows) {
10923
10923
  );
10924
10924
  return headerIndex >= 0 ? headerIndex : 0;
10925
10925
  }
10926
+ function startsNewVisualTableItem(cells) {
10927
+ const firstText = tableCellText(cells[0]);
10928
+ return /^(?:item\s+\d+\b|[A-Z][.)]\s+|coverage\s+part\b|endorsement\s+(?:no\.?|number|#|\d+)\b)/i.test(firstText);
10929
+ }
10930
+ function rowMatchesColumnLabels(cells, columnLabels) {
10931
+ if (columnLabels.size === 0 || cells.length < columnLabels.size) return false;
10932
+ return cells.every((cell, index) => {
10933
+ const label = columnLabels.get(tableCellColumnIndex(cell, index));
10934
+ return !label || tableCellText(cell).toLowerCase() === label.toLowerCase();
10935
+ });
10936
+ }
10937
+ function implicitContinuationRows(rows, columnLabels, firstLabelRowIndex) {
10938
+ const continuations = [];
10939
+ let targetRowId;
10940
+ const targetColumnLabel = columnLabels.get(1);
10941
+ for (const [rowIndex, { row, cells }] of rows.entries()) {
10942
+ if (rowIndex < firstLabelRowIndex) continue;
10943
+ if (rowIndex === firstLabelRowIndex && rowMatchesColumnLabels(cells, columnLabels)) continue;
10944
+ if (startsNewVisualTableItem(cells)) {
10945
+ targetRowId = row.id;
10946
+ continue;
10947
+ }
10948
+ if (!targetRowId || cells.length === 0) continue;
10949
+ const isSpuriousHeader = isSourceTreeHeaderRow(row) && !rowMatchesColumnLabels(cells, columnLabels);
10950
+ const isShortContinuation = !isSourceTreeHeaderRow(row) && cells.length < Math.max(2, columnLabels.size);
10951
+ if (!isSpuriousHeader && !isShortContinuation) continue;
10952
+ continuations.push({
10953
+ sourceRowNodeId: row.id,
10954
+ targetRowNodeId: targetRowId,
10955
+ targetColumnIndex: 1,
10956
+ targetColumnLabel,
10957
+ reason: "Continuation row inferred from repaired table header."
10958
+ });
10959
+ }
10960
+ return continuations;
10961
+ }
10926
10962
  function metadataWithColumnLabel(metadata, label) {
10927
10963
  const next = {
10928
10964
  ...metadata ?? {},
@@ -10963,8 +10999,8 @@ function applyVisualTableRepair(sourceTree, repair) {
10963
10999
  const normalized = normalizedRepairLabel(label.label);
10964
11000
  if (normalized) columnLabels.set(label.columnIndex, normalized);
10965
11001
  }
11002
+ const firstLabelRowIndex = columnLabelStartIndex(rows);
10966
11003
  if (columnLabels.size > 0) {
10967
- const firstLabelRowIndex = columnLabelStartIndex(rows);
10968
11004
  const normalizedLabels = new Set([...columnLabels.values()].map((label) => label.toLowerCase()));
10969
11005
  for (const [rowIndex, { row, cells }] of rows.entries()) {
10970
11006
  if (removeIds.has(row.id)) continue;
@@ -11002,7 +11038,15 @@ function applyVisualTableRepair(sourceTree, repair) {
11002
11038
  if (cells.length > 0) rowsToRebuildText.add(row.id);
11003
11039
  }
11004
11040
  }
11005
- for (const continuation of tableRepair.continuationRows) {
11041
+ const continuationRows = [
11042
+ ...tableRepair.continuationRows,
11043
+ ...implicitContinuationRows(rows, columnLabels, firstLabelRowIndex)
11044
+ ];
11045
+ const seenContinuationRows = /* @__PURE__ */ new Set();
11046
+ for (const continuation of continuationRows) {
11047
+ const continuationKey = `${continuation.sourceRowNodeId}:${continuation.targetRowNodeId}`;
11048
+ if (seenContinuationRows.has(continuationKey)) continue;
11049
+ seenContinuationRows.add(continuationKey);
11006
11050
  if (!rowIds.has(continuation.sourceRowNodeId) || !rowIds.has(continuation.targetRowNodeId)) continue;
11007
11051
  if (continuation.sourceRowNodeId === continuation.targetRowNodeId) continue;
11008
11052
  const sourceIndex = rowOrder.get(continuation.sourceRowNodeId);