@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.js CHANGED
@@ -11256,7 +11256,7 @@ function appendDistinctText(base, addition) {
11256
11256
  if (!current) return next || void 0;
11257
11257
  if (!next) return current;
11258
11258
  if (current.toLowerCase().includes(next.toLowerCase())) return current;
11259
- const delimiter = /(?:[/(:;-]|,\s*)$/.test(current) ? " " : " / ";
11259
+ const delimiter = /(?:[/(:;-]|,\s*)$/.test(current) || /^[a-z]+$/i.test(next) ? " " : " / ";
11260
11260
  return cleanText(`${current}${delimiter}${next}`, current);
11261
11261
  }
11262
11262
  function mergedBbox(nodes) {
@@ -11285,6 +11285,23 @@ function findCellForContinuation(params) {
11285
11285
  }
11286
11286
  return params.cells[1] ?? params.cells[params.cells.length - 1];
11287
11287
  }
11288
+ function bboxCenterX(node) {
11289
+ const box = node.bbox?.[0];
11290
+ if (!box) return void 0;
11291
+ return box.x + box.width / 2;
11292
+ }
11293
+ function findCellByVisualPosition(sourceCell, targetCells) {
11294
+ const sourceX = bboxCenterX(sourceCell);
11295
+ if (sourceX === void 0) return void 0;
11296
+ const positioned = targetCells.map((cell) => ({ cell, centerX: bboxCenterX(cell) })).filter(
11297
+ (entry) => entry.centerX !== void 0
11298
+ );
11299
+ if (positioned.length === 0) return void 0;
11300
+ positioned.sort(
11301
+ (left, right) => Math.abs(left.centerX - sourceX) - Math.abs(right.centerX - sourceX)
11302
+ );
11303
+ return positioned[0]?.cell;
11304
+ }
11288
11305
  function columnLabelStartIndex(rows) {
11289
11306
  const headerIndex = rows.findIndex(
11290
11307
  ({ row, cells }) => isSourceTreeHeaderRow(row) && cells.length > 1
@@ -11436,7 +11453,41 @@ function applyVisualTableRepair(sourceTree, repair) {
11436
11453
  });
11437
11454
  const sourceNodes = [sourceRow, ...sourceCells];
11438
11455
  const sourceSpanIds = sourceSpanIdsForNodes(sourceNodes);
11439
- if (targetCell) {
11456
+ let mergedIntoCells = false;
11457
+ if (sourceCells.length > 0 && targetCells.length > 0) {
11458
+ for (const sourceCell of sourceCells) {
11459
+ const cellText = tableCellValueText(sourceCell);
11460
+ if (!cellText) continue;
11461
+ const visualTargetCell = findCellByVisualPosition(sourceCell, targetCells) ?? targetCell;
11462
+ if (!visualTargetCell) continue;
11463
+ const currentTargetCell = currentNode(visualTargetCell.id) ?? visualTargetCell;
11464
+ const nextCellText = appendDistinctText(tableCellText(currentTargetCell), cellText);
11465
+ if (!nextCellText) continue;
11466
+ updates.set(visualTargetCell.id, {
11467
+ ...currentTargetCell,
11468
+ textExcerpt: nextCellText,
11469
+ description: cleanText(
11470
+ [currentTargetCell.title, nextCellText].filter(Boolean).join(" | "),
11471
+ currentTargetCell.description
11472
+ ),
11473
+ sourceSpanIds: [
11474
+ .../* @__PURE__ */ new Set([
11475
+ ...currentTargetCell.sourceSpanIds,
11476
+ ...sourceRow.sourceSpanIds,
11477
+ ...sourceCell.sourceSpanIds
11478
+ ])
11479
+ ],
11480
+ bbox: mergedBbox([currentTargetCell, sourceCell]),
11481
+ metadata: {
11482
+ ...currentTargetCell.metadata ?? {},
11483
+ visualTableRepair: "merged_continuation"
11484
+ }
11485
+ });
11486
+ mergedIntoCells = true;
11487
+ }
11488
+ if (mergedIntoCells) rowsToRebuildText.add(targetRow.id);
11489
+ }
11490
+ if (!mergedIntoCells && targetCell) {
11440
11491
  const nextCellText = appendDistinctText(tableCellText(targetCell), sourceText);
11441
11492
  if (nextCellText) {
11442
11493
  const mergedNodes = [targetCell, ...sourceNodes];
@@ -11454,11 +11505,16 @@ function applyVisualTableRepair(sourceTree, repair) {
11454
11505
  rowsToRebuildText.add(targetRow.id);
11455
11506
  }
11456
11507
  }
11457
- const nextRowText = appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
11508
+ const fallbackRowText = mergedIntoCells ? void 0 : appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
11458
11509
  updates.set(targetRow.id, {
11459
11510
  ...currentNode(targetRow.id) ?? targetRow,
11460
- textExcerpt: nextRowText,
11461
- description: cleanText([targetRow.title, nextRowText].filter(Boolean).join(" | "), targetRow.description),
11511
+ ...mergedIntoCells ? {} : {
11512
+ textExcerpt: fallbackRowText,
11513
+ description: cleanText(
11514
+ [targetRow.title, fallbackRowText].filter(Boolean).join(" | "),
11515
+ targetRow.description
11516
+ )
11517
+ },
11462
11518
  sourceSpanIds: [.../* @__PURE__ */ new Set([...targetRow.sourceSpanIds, ...sourceSpanIds])],
11463
11519
  bbox: mergedBbox([targetRow, ...sourceNodes]),
11464
11520
  metadata: {