@claritylabs/cl-sdk 3.1.12 → 3.1.14

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
@@ -10888,7 +10888,8 @@ function appendDistinctText(base, addition) {
10888
10888
  if (!current) return next || void 0;
10889
10889
  if (!next) return current;
10890
10890
  if (current.toLowerCase().includes(next.toLowerCase())) return current;
10891
- const delimiter = /(?:[/(:;-]|,\s*)$/.test(current) ? " " : " / ";
10891
+ const joinsWithSpace = /(?:[/(:;-]|,\s*)$/.test(current) || /\b(?:part of|including|subject to|not in addition to)$/i.test(current) || /^(?:aggregate|claim|loss|proceeding|occurrence|each\s+(?:claim|loss|proceeding|occurrence)|coverage\s+part\b)/i.test(next);
10892
+ const delimiter = joinsWithSpace ? " " : " / ";
10892
10893
  return cleanText(`${current}${delimiter}${next}`, current);
10893
10894
  }
10894
10895
  function mergedBbox(nodes) {
@@ -10917,6 +10918,23 @@ function findCellForContinuation(params) {
10917
10918
  }
10918
10919
  return params.cells[1] ?? params.cells[params.cells.length - 1];
10919
10920
  }
10921
+ function bboxCenterX(node) {
10922
+ const box = node.bbox?.[0];
10923
+ if (!box) return void 0;
10924
+ return box.x + box.width / 2;
10925
+ }
10926
+ function findCellByVisualPosition(sourceCell, targetCells) {
10927
+ const sourceX = bboxCenterX(sourceCell);
10928
+ if (sourceX === void 0) return void 0;
10929
+ const positioned = targetCells.map((cell) => ({ cell, centerX: bboxCenterX(cell) })).filter(
10930
+ (entry) => entry.centerX !== void 0
10931
+ );
10932
+ if (positioned.length === 0) return void 0;
10933
+ positioned.sort(
10934
+ (left, right) => Math.abs(left.centerX - sourceX) - Math.abs(right.centerX - sourceX)
10935
+ );
10936
+ return positioned[0]?.cell;
10937
+ }
10920
10938
  function columnLabelStartIndex(rows) {
10921
10939
  const headerIndex = rows.findIndex(
10922
10940
  ({ row, cells }) => isSourceTreeHeaderRow(row) && cells.length > 1
@@ -11068,7 +11086,41 @@ function applyVisualTableRepair(sourceTree, repair) {
11068
11086
  });
11069
11087
  const sourceNodes = [sourceRow, ...sourceCells];
11070
11088
  const sourceSpanIds = sourceSpanIdsForNodes(sourceNodes);
11071
- if (targetCell) {
11089
+ let mergedIntoCells = false;
11090
+ if (sourceCells.length > 0 && targetCells.length > 0) {
11091
+ for (const sourceCell of sourceCells) {
11092
+ const cellText = tableCellValueText(sourceCell);
11093
+ if (!cellText) continue;
11094
+ const visualTargetCell = findCellByVisualPosition(sourceCell, targetCells) ?? targetCell;
11095
+ if (!visualTargetCell) continue;
11096
+ const currentTargetCell = currentNode(visualTargetCell.id) ?? visualTargetCell;
11097
+ const nextCellText = appendDistinctText(tableCellText(currentTargetCell), cellText);
11098
+ if (!nextCellText) continue;
11099
+ updates.set(visualTargetCell.id, {
11100
+ ...currentTargetCell,
11101
+ textExcerpt: nextCellText,
11102
+ description: cleanText(
11103
+ [currentTargetCell.title, nextCellText].filter(Boolean).join(" | "),
11104
+ currentTargetCell.description
11105
+ ),
11106
+ sourceSpanIds: [
11107
+ .../* @__PURE__ */ new Set([
11108
+ ...currentTargetCell.sourceSpanIds,
11109
+ ...sourceRow.sourceSpanIds,
11110
+ ...sourceCell.sourceSpanIds
11111
+ ])
11112
+ ],
11113
+ bbox: mergedBbox([currentTargetCell, sourceCell]),
11114
+ metadata: {
11115
+ ...currentTargetCell.metadata ?? {},
11116
+ visualTableRepair: "merged_continuation"
11117
+ }
11118
+ });
11119
+ mergedIntoCells = true;
11120
+ }
11121
+ if (mergedIntoCells) rowsToRebuildText.add(targetRow.id);
11122
+ }
11123
+ if (!mergedIntoCells && targetCell) {
11072
11124
  const nextCellText = appendDistinctText(tableCellText(targetCell), sourceText);
11073
11125
  if (nextCellText) {
11074
11126
  const mergedNodes = [targetCell, ...sourceNodes];
@@ -11086,11 +11138,16 @@ function applyVisualTableRepair(sourceTree, repair) {
11086
11138
  rowsToRebuildText.add(targetRow.id);
11087
11139
  }
11088
11140
  }
11089
- const nextRowText = appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
11141
+ const fallbackRowText = mergedIntoCells ? void 0 : appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
11090
11142
  updates.set(targetRow.id, {
11091
11143
  ...currentNode(targetRow.id) ?? targetRow,
11092
- textExcerpt: nextRowText,
11093
- description: cleanText([targetRow.title, nextRowText].filter(Boolean).join(" | "), targetRow.description),
11144
+ ...mergedIntoCells ? {} : {
11145
+ textExcerpt: fallbackRowText,
11146
+ description: cleanText(
11147
+ [targetRow.title, fallbackRowText].filter(Boolean).join(" | "),
11148
+ targetRow.description
11149
+ )
11150
+ },
11094
11151
  sourceSpanIds: [.../* @__PURE__ */ new Set([...targetRow.sourceSpanIds, ...sourceSpanIds])],
11095
11152
  bbox: mergedBbox([targetRow, ...sourceNodes]),
11096
11153
  metadata: {