@claritylabs/cl-sdk 3.1.12 → 3.1.13

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