@superdoc-dev/cli 0.3.0-next.49 → 0.3.0-next.50

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.
Files changed (2) hide show
  1. package/dist/index.js +384 -72
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -148850,7 +148850,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
148850
148850
  init_remark_gfm_z_sDF4ss_es();
148851
148851
  });
148852
148852
 
148853
- // ../../packages/superdoc/dist/chunks/src-BeJRbQ1S.es.js
148853
+ // ../../packages/superdoc/dist/chunks/src-BS_QWHti.es.js
148854
148854
  function deleteProps(obj, propOrProps) {
148855
148855
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
148856
148856
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -186456,6 +186456,266 @@ function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn
186456
186456
  state.page.fragments.push(fragment2);
186457
186457
  state.cursorY += requiredHeight;
186458
186458
  }
186459
+ function describeCellRenderBlocks(cellMeasure, cellBlock, cellPadding) {
186460
+ const measuredBlocks = cellMeasure.blocks;
186461
+ const blockDataArray = cellBlock?.blocks;
186462
+ if (!measuredBlocks || measuredBlocks.length === 0) {
186463
+ if (cellMeasure.paragraph)
186464
+ return buildSingleParagraphBlock(cellMeasure.paragraph, cellBlock?.paragraph, cellPadding);
186465
+ return [];
186466
+ }
186467
+ const result = [];
186468
+ let globalLine = 0;
186469
+ const blockCount = measuredBlocks.length;
186470
+ for (let i4 = 0;i4 < blockCount; i4++) {
186471
+ const measure = measuredBlocks[i4];
186472
+ const data = i4 < (blockDataArray?.length ?? 0) ? blockDataArray[i4] : undefined;
186473
+ const isFirstBlock = i4 === 0;
186474
+ const isLastBlock = i4 === blockCount - 1;
186475
+ if (measure.kind === "paragraph") {
186476
+ const paraMeasure = measure;
186477
+ const paraData = data?.kind === "paragraph" ? data : undefined;
186478
+ const lines = paraMeasure.lines ?? [];
186479
+ const lineHeights = lines.map((l) => l.lineHeight);
186480
+ const sumLines = sumArray(lineHeights);
186481
+ const spacingBefore = effectiveTableCellSpacing(paraData?.attrs?.spacing?.before, isFirstBlock, cellPadding.top);
186482
+ const rawAfter = paraData?.attrs?.spacing?.after;
186483
+ const spacingAfter = isLastBlock ? 0 : typeof rawAfter === "number" && rawAfter > 0 ? rawAfter : 0;
186484
+ const startLine = globalLine;
186485
+ globalLine += lines.length;
186486
+ result.push({
186487
+ kind: "paragraph",
186488
+ globalStartLine: startLine,
186489
+ globalEndLine: globalLine,
186490
+ lineHeights,
186491
+ totalHeight: paraMeasure.totalHeight ?? sumLines,
186492
+ visibleHeight: sumLines,
186493
+ isFirstBlock,
186494
+ isLastBlock,
186495
+ spacingBefore,
186496
+ spacingAfter
186497
+ });
186498
+ } else if (measure.kind === "table") {
186499
+ const tableMeasure = measure;
186500
+ const lineHeights = [];
186501
+ for (const row2 of tableMeasure.rows)
186502
+ for (const seg of getEmbeddedRowLines(row2))
186503
+ lineHeights.push(seg.lineHeight);
186504
+ const startLine = globalLine;
186505
+ globalLine += lineHeights.length;
186506
+ const sumLines = sumArray(lineHeights);
186507
+ result.push({
186508
+ kind: "table",
186509
+ globalStartLine: startLine,
186510
+ globalEndLine: globalLine,
186511
+ lineHeights,
186512
+ totalHeight: sumLines,
186513
+ visibleHeight: sumLines,
186514
+ isFirstBlock,
186515
+ isLastBlock,
186516
+ spacingBefore: 0,
186517
+ spacingAfter: 0
186518
+ });
186519
+ } else {
186520
+ const blockHeight = "height" in measure ? measure.height : 0;
186521
+ if (blockHeight > 0) {
186522
+ const outOfFlow = isAnchoredOutOfFlow(data);
186523
+ const startLine = globalLine;
186524
+ globalLine += 1;
186525
+ result.push({
186526
+ kind: "other",
186527
+ globalStartLine: startLine,
186528
+ globalEndLine: globalLine,
186529
+ lineHeights: [blockHeight],
186530
+ totalHeight: outOfFlow ? 0 : blockHeight,
186531
+ visibleHeight: outOfFlow ? 0 : blockHeight,
186532
+ isFirstBlock,
186533
+ isLastBlock,
186534
+ spacingBefore: 0,
186535
+ spacingAfter: 0
186536
+ });
186537
+ }
186538
+ }
186539
+ }
186540
+ return result;
186541
+ }
186542
+ function computeCellSliceContentHeight(blocks2, fromLine, toLine) {
186543
+ let height = 0;
186544
+ for (const block of blocks2) {
186545
+ if (block.globalEndLine <= fromLine || block.globalStartLine >= toLine)
186546
+ continue;
186547
+ const localStart = Math.max(0, fromLine - block.globalStartLine);
186548
+ const localEnd = Math.min(block.lineHeights.length, toLine - block.globalStartLine);
186549
+ const rendersEntireBlock = localStart === 0 && localEnd >= block.lineHeights.length;
186550
+ if (block.kind === "paragraph") {
186551
+ if (localStart === 0)
186552
+ height += block.spacingBefore;
186553
+ let sliceLineSum = 0;
186554
+ for (let i4 = localStart;i4 < localEnd; i4++)
186555
+ sliceLineSum += block.lineHeights[i4];
186556
+ if (rendersEntireBlock) {
186557
+ height += Math.max(sliceLineSum, block.totalHeight);
186558
+ height += block.spacingAfter;
186559
+ } else
186560
+ height += sliceLineSum;
186561
+ } else {
186562
+ if (block.visibleHeight === 0)
186563
+ continue;
186564
+ for (let i4 = localStart;i4 < localEnd; i4++)
186565
+ height += block.lineHeights[i4];
186566
+ }
186567
+ }
186568
+ return height;
186569
+ }
186570
+ function createCellSliceCursor(blocks2, startLine) {
186571
+ let blockIdx = 0;
186572
+ let startedFromLine0 = false;
186573
+ let blockLineSum = 0;
186574
+ while (blockIdx < blocks2.length && blocks2[blockIdx].globalEndLine <= startLine)
186575
+ blockIdx++;
186576
+ if (blockIdx < blocks2.length) {
186577
+ const block = blocks2[blockIdx];
186578
+ startedFromLine0 = startLine <= block.globalStartLine;
186579
+ if (!startedFromLine0)
186580
+ for (let li2 = 0;li2 < startLine - block.globalStartLine; li2++)
186581
+ blockLineSum += block.lineHeights[li2] ?? 0;
186582
+ }
186583
+ return {
186584
+ advanceLine(globalLineIndex) {
186585
+ while (blockIdx < blocks2.length && blocks2[blockIdx].globalEndLine <= globalLineIndex) {
186586
+ blockIdx++;
186587
+ startedFromLine0 = true;
186588
+ blockLineSum = 0;
186589
+ }
186590
+ if (blockIdx >= blocks2.length)
186591
+ return 0;
186592
+ const block = blocks2[blockIdx];
186593
+ const localLine = globalLineIndex - block.globalStartLine;
186594
+ const lineHeight = block.lineHeights[localLine] ?? 0;
186595
+ let cost = 0;
186596
+ if (localLine === 0 && startedFromLine0 && block.kind === "paragraph")
186597
+ cost += block.spacingBefore;
186598
+ if (block.kind === "paragraph" || block.visibleHeight > 0)
186599
+ cost += lineHeight;
186600
+ blockLineSum += lineHeight;
186601
+ const isBlockComplete = localLine === block.lineHeights.length - 1;
186602
+ if (isBlockComplete && startedFromLine0 && block.kind === "paragraph") {
186603
+ cost += Math.max(0, block.totalHeight - blockLineSum);
186604
+ cost += block.spacingAfter;
186605
+ }
186606
+ if (isBlockComplete) {
186607
+ blockIdx++;
186608
+ startedFromLine0 = true;
186609
+ blockLineSum = 0;
186610
+ }
186611
+ return cost;
186612
+ },
186613
+ minSegmentCost(globalLineIndex) {
186614
+ const block = findBlockForLine(blocks2, globalLineIndex);
186615
+ if (!block)
186616
+ return 0;
186617
+ const localLine = globalLineIndex - block.globalStartLine;
186618
+ const lineHeight = block.lineHeights[localLine] ?? 0;
186619
+ let cost = 0;
186620
+ if (localLine === 0 && block.kind === "paragraph")
186621
+ cost += block.spacingBefore;
186622
+ if (block.kind === "paragraph" || block.visibleHeight > 0)
186623
+ cost += lineHeight;
186624
+ if (block.lineHeights.length === 1 && block.kind === "paragraph") {
186625
+ cost += Math.max(0, block.totalHeight - lineHeight);
186626
+ cost += block.spacingAfter;
186627
+ }
186628
+ return cost;
186629
+ }
186630
+ };
186631
+ }
186632
+ function computeFullCellContentHeight(cellMeasure, cellBlock, cellPadding) {
186633
+ const measuredBlocks = cellMeasure.blocks;
186634
+ const blockDataArray = cellBlock?.blocks;
186635
+ if (!measuredBlocks || measuredBlocks.length === 0) {
186636
+ if (cellMeasure.paragraph) {
186637
+ const pm = cellMeasure.paragraph;
186638
+ let sumLines = 0;
186639
+ for (const l of pm.lines)
186640
+ sumLines += l.lineHeight;
186641
+ const paraData = cellBlock?.paragraph;
186642
+ const spacingBefore = effectiveTableCellSpacing(paraData?.attrs?.spacing?.before, true, cellPadding.top);
186643
+ const spacingAfter = effectiveTableCellSpacing(paraData?.attrs?.spacing?.after, true, cellPadding.bottom);
186644
+ return spacingBefore + Math.max(sumLines, pm.totalHeight ?? sumLines) + spacingAfter;
186645
+ }
186646
+ return 0;
186647
+ }
186648
+ let height = 0;
186649
+ const blockCount = measuredBlocks.length;
186650
+ for (let i4 = 0;i4 < blockCount; i4++) {
186651
+ const measure = measuredBlocks[i4];
186652
+ const data = i4 < (blockDataArray?.length ?? 0) ? blockDataArray[i4] : undefined;
186653
+ const isFirstBlock = i4 === 0;
186654
+ const isLastBlock = i4 === blockCount - 1;
186655
+ if (measure.kind === "paragraph") {
186656
+ const pm = measure;
186657
+ const paraData = data?.kind === "paragraph" ? data : undefined;
186658
+ let sumLines = 0;
186659
+ for (const l of pm.lines ?? [])
186660
+ sumLines += l.lineHeight;
186661
+ height += effectiveTableCellSpacing(paraData?.attrs?.spacing?.before, isFirstBlock, cellPadding.top);
186662
+ height += Math.max(sumLines, pm.totalHeight ?? sumLines);
186663
+ if (!isLastBlock) {
186664
+ const rawAfter = paraData?.attrs?.spacing?.after;
186665
+ if (typeof rawAfter === "number" && rawAfter > 0)
186666
+ height += rawAfter;
186667
+ } else
186668
+ height += effectiveTableCellSpacing(paraData?.attrs?.spacing?.after, true, cellPadding.bottom);
186669
+ } else if (measure.kind === "table") {
186670
+ const tm = measure;
186671
+ for (const row2 of tm.rows)
186672
+ height += row2.height;
186673
+ } else {
186674
+ const blockHeight = "height" in measure ? measure.height : 0;
186675
+ if (blockHeight > 0 && !isAnchoredOutOfFlow(data))
186676
+ height += blockHeight;
186677
+ }
186678
+ }
186679
+ return height;
186680
+ }
186681
+ function buildSingleParagraphBlock(paraMeasure, paraData, cellPadding) {
186682
+ const lines = paraMeasure.lines ?? [];
186683
+ if (lines.length === 0)
186684
+ return [];
186685
+ const lineHeights = lines.map((l) => l.lineHeight);
186686
+ const sumLines = sumArray(lineHeights);
186687
+ return [{
186688
+ kind: "paragraph",
186689
+ globalStartLine: 0,
186690
+ globalEndLine: lines.length,
186691
+ lineHeights,
186692
+ totalHeight: paraMeasure.totalHeight ?? sumLines,
186693
+ visibleHeight: sumLines,
186694
+ isFirstBlock: true,
186695
+ isLastBlock: true,
186696
+ spacingBefore: effectiveTableCellSpacing(paraData?.attrs?.spacing?.before, true, cellPadding.top),
186697
+ spacingAfter: 0
186698
+ }];
186699
+ }
186700
+ function isAnchoredOutOfFlow(block) {
186701
+ if (!block || typeof block !== "object")
186702
+ return false;
186703
+ const b$1 = block;
186704
+ if (!b$1.anchor?.isAnchored)
186705
+ return false;
186706
+ return (b$1.wrap?.type ?? "Inline") !== "Inline";
186707
+ }
186708
+ function findBlockForLine(blocks2, globalLineIndex) {
186709
+ for (const block of blocks2)
186710
+ if (globalLineIndex >= block.globalStartLine && globalLineIndex < block.globalEndLine)
186711
+ return block;
186712
+ }
186713
+ function sumArray(arr) {
186714
+ let total = 0;
186715
+ for (const v of arr)
186716
+ total += v;
186717
+ return total;
186718
+ }
186459
186719
  function getTableIndentWidth(attrs) {
186460
186720
  if (!attrs)
186461
186721
  return 0;
@@ -186599,34 +186859,24 @@ function sumRowHeights(rows, fromRow, toRow) {
186599
186859
  total += rows[i4].height;
186600
186860
  return total;
186601
186861
  }
186602
- function calculateFragmentHeight(fragment2, measure, _headerCount, borderCollapse) {
186862
+ function computeFragmentHeight(measure, fromRow, toRow, repeatHeaderCount, borderCollapse, partialRow) {
186603
186863
  let height = 0;
186604
186864
  let rowCount = 0;
186605
- if (fragment2.repeatHeaderCount && fragment2.repeatHeaderCount > 0) {
186606
- height += sumRowHeights(measure.rows, 0, fragment2.repeatHeaderCount);
186607
- rowCount += fragment2.repeatHeaderCount;
186865
+ if (repeatHeaderCount > 0) {
186866
+ height += sumRowHeights(measure.rows, 0, repeatHeaderCount);
186867
+ rowCount += repeatHeaderCount;
186608
186868
  }
186609
- const bodyRowCount = fragment2.toRow - fragment2.fromRow;
186610
- height += sumRowHeights(measure.rows, fragment2.fromRow, fragment2.toRow);
186611
- rowCount += bodyRowCount;
186612
- const cellSpacingPx = measure.cellSpacingPx ?? 0;
186613
- if (rowCount > 0 && cellSpacingPx > 0)
186614
- height += (rowCount + 1) * cellSpacingPx;
186615
- if (rowCount > 0 && measure.tableBorderWidths && borderCollapse === "separate") {
186616
- const borderWidthV = measure.tableBorderWidths.top + measure.tableBorderWidths.bottom;
186617
- height += borderWidthV;
186869
+ for (let i4 = fromRow;i4 < toRow && i4 < measure.rows.length; i4++) {
186870
+ if (partialRow && partialRow.rowIndex === i4)
186871
+ height += partialRow.partialHeight;
186872
+ else
186873
+ height += measure.rows[i4].height;
186874
+ rowCount++;
186618
186875
  }
186619
- return height;
186620
- }
186621
- function calculateBodyFragmentHeight(measure, fromRow, toRow, borderCollapse) {
186622
- const rowCount = toRow - fromRow;
186623
- if (rowCount <= 0)
186624
- return 0;
186625
- let height = sumRowHeights(measure.rows, fromRow, toRow);
186626
186876
  const cellSpacingPx = measure.cellSpacingPx ?? 0;
186627
- if (cellSpacingPx > 0)
186877
+ if (rowCount > 0 && cellSpacingPx > 0)
186628
186878
  height += (rowCount + 1) * cellSpacingPx;
186629
- if (measure.tableBorderWidths && borderCollapse === "separate")
186879
+ if (rowCount > 0 && measure.tableBorderWidths && borderCollapse === "separate")
186630
186880
  height += measure.tableBorderWidths.top + measure.tableBorderWidths.bottom;
186631
186881
  return height;
186632
186882
  }
@@ -186684,8 +186934,9 @@ function getRowContentHeight(blockRow, rowMeasure) {
186684
186934
  const cell2 = rowMeasure.cells[cellIdx];
186685
186935
  const cellPadding = getCellPadding(cellIdx, blockRow);
186686
186936
  const paddingTotal = cellPadding.top + cellPadding.bottom;
186687
- const linesHeight = getCellLines(cell2).reduce((sum, line) => sum + (line.lineHeight || 0), 0);
186688
- contentHeight = Math.max(contentHeight, linesHeight + paddingTotal);
186937
+ const cellBlock = blockRow?.cells?.[cellIdx];
186938
+ const sliceHeight = computeFullCellContentHeight(cell2, cellBlock, cellPadding);
186939
+ contentHeight = Math.max(contentHeight, sliceHeight + paddingTotal);
186689
186940
  }
186690
186941
  return contentHeight;
186691
186942
  }
@@ -186807,19 +187058,21 @@ function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLin
186807
187058
  const startLine = startLines[cellIdx] || 0;
186808
187059
  const cellPadding = cellPaddings[cellIdx];
186809
187060
  const availableForLines = Math.max(0, availableHeight - (cellPadding.top + cellPadding.bottom));
187061
+ const cellBlock = blockRow?.cells?.[cellIdx];
187062
+ const cursor = createCellSliceCursor(describeCellRenderBlocks(cell2, cellBlock, cellPadding), startLine);
186810
187063
  const lines = getCellLines(cell2);
186811
187064
  let cumulativeHeight = 0;
186812
187065
  let cutLine = startLine;
186813
187066
  for (let i4 = startLine;i4 < lines.length; i4++) {
186814
- const lineHeight = lines[i4].lineHeight || 0;
186815
- if (cumulativeHeight + lineHeight > availableForLines) {
186816
- if (cumulativeHeight === 0 && i4 === startLine && availableForLines > 0 && fullPageHeight != null && lineHeight > fullPageHeight) {
186817
- cumulativeHeight += Math.min(lineHeight, availableForLines);
187067
+ const lineCost = cursor.advanceLine(i4);
187068
+ if (cumulativeHeight + lineCost > availableForLines) {
187069
+ if (cumulativeHeight === 0 && i4 === startLine && availableForLines > 0 && fullPageHeight != null && cursor.minSegmentCost(i4) > fullPageHeight) {
187070
+ cumulativeHeight += Math.min(lineCost, availableForLines);
186818
187071
  cutLine = i4 + 1;
186819
187072
  }
186820
187073
  break;
186821
187074
  }
186822
- cumulativeHeight += lineHeight;
187075
+ cumulativeHeight += lineCost;
186823
187076
  cutLine = i4 + 1;
186824
187077
  }
186825
187078
  toLineByCell.push(cutLine);
@@ -186867,12 +187120,12 @@ function findSplitPoint(block, measure, startRow, availableHeight, fullPageHeigh
186867
187120
  if (rs > 1)
186868
187121
  maxRowspanEnd = Math.max(maxRowspanEnd, i4 + rs);
186869
187122
  }
186870
- if (calculateBodyFragmentHeight(measure, startRow, i4 + 1, borderCollapse) <= availableHeight) {
187123
+ if (computeFragmentHeight(measure, startRow, i4 + 1, 0, borderCollapse) <= availableHeight) {
186871
187124
  lastFitRow = i4 + 1;
186872
187125
  if (maxRowspanEnd <= i4 + 1)
186873
187126
  lastCleanFitRow = i4 + 1;
186874
187127
  } else {
186875
- let remainingHeight = availableHeight - calculateBodyFragmentHeight(measure, startRow, lastFitRow, borderCollapse);
187128
+ let remainingHeight = availableHeight - computeFragmentHeight(measure, startRow, lastFitRow, 0, borderCollapse);
186876
187129
  if (lastFitRow === startRow) {
186877
187130
  const cellSpacingPx = measure.cellSpacingPx ?? 0;
186878
187131
  const topBorderPx = borderCollapse === "separate" && measure.tableBorderWidths ? measure.tableBorderWidths.top : 0;
@@ -186983,7 +187236,9 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
186983
187236
  return;
186984
187237
  }
186985
187238
  const headerCount = countHeaderRows(block);
186986
- const headerHeight = headerCount > 0 ? sumRowHeights(measure.rows, 0, headerCount) : 0;
187239
+ const headerPrefixHeights = [0];
187240
+ for (let i4 = 0;i4 < headerCount; i4 += 1)
187241
+ headerPrefixHeights.push(headerPrefixHeights[i4] + (measure.rows[i4]?.height ?? 0));
186987
187242
  let state = ensurePage();
186988
187243
  const availableHeight = state.contentBottom - state.cursorY;
186989
187244
  const hasPriorFragments = state.page.fragments.length > 0;
@@ -187037,30 +187292,44 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
187037
187292
  return;
187038
187293
  }
187039
187294
  const borderCollapse = block.attrs?.borderCollapse ?? (block.attrs?.cellSpacing != null ? "separate" : "collapse");
187295
+ const getRepeatedHeaderHeight = (repeatCount) => {
187296
+ return headerPrefixHeights[Math.max(0, Math.min(repeatCount, headerCount))] ?? 0;
187297
+ };
187298
+ let samePagePartialContinuation = false;
187299
+ let retryWithoutHeaders = false;
187040
187300
  while (currentRow < block.rows.length || pendingPartialRow !== null) {
187041
187301
  state = ensurePage();
187042
187302
  const availableHeight$1 = state.contentBottom - state.cursorY;
187043
187303
  let repeatHeaderCount = 0;
187044
- if (currentRow === 0 && !pendingPartialRow)
187304
+ if (retryWithoutHeaders) {
187305
+ repeatHeaderCount = 0;
187306
+ retryWithoutHeaders = false;
187307
+ } else if (currentRow === 0 && !pendingPartialRow)
187045
187308
  repeatHeaderCount = 0;
187046
- else if (headerCount > 0 && headerHeight <= availableHeight$1)
187047
- repeatHeaderCount = headerCount;
187048
- else if (headerCount > 0 && headerHeight > availableHeight$1)
187309
+ else if (samePagePartialContinuation)
187049
187310
  repeatHeaderCount = 0;
187311
+ else {
187312
+ const candidateRepeatHeaderCount = pendingPartialRow && pendingPartialRow.rowIndex < headerCount ? pendingPartialRow.rowIndex : headerCount;
187313
+ const candidateHeaderHeight = getRepeatedHeaderHeight(candidateRepeatHeaderCount);
187314
+ if (candidateRepeatHeaderCount > 0 && candidateHeaderHeight < availableHeight$1)
187315
+ repeatHeaderCount = candidateRepeatHeaderCount;
187316
+ }
187317
+ samePagePartialContinuation = false;
187050
187318
  if (repeatHeaderCount > 0 && !pendingPartialRow) {
187051
187319
  const bodyRow = block.rows[currentRow];
187052
187320
  const bodyRowHeight = measure.rows[currentRow]?.height || 0;
187053
187321
  const bodyCantSplit = bodyRow?.attrs?.tableRowProperties?.cantSplit === true;
187054
- const spaceWithHeaders = availableHeight$1 - headerHeight;
187322
+ const spaceWithHeaders = availableHeight$1 - getRepeatedHeaderHeight(repeatHeaderCount);
187055
187323
  if (bodyCantSplit && bodyRowHeight > spaceWithHeaders && bodyRowHeight <= availableHeight$1)
187056
187324
  repeatHeaderCount = 0;
187057
187325
  }
187058
- const availableForBody = repeatHeaderCount > 0 ? availableHeight$1 - headerHeight : availableHeight$1;
187059
- const fullPageHeight = state.contentBottom - (state.topMargin ?? 0);
187326
+ const repeatedHeaderHeight = getRepeatedHeaderHeight(repeatHeaderCount);
187327
+ const availableForBody = availableHeight$1 - repeatedHeaderHeight;
187328
+ const fullPageHeightForBody = state.contentBottom - (state.topMargin ?? 0) - repeatedHeaderHeight;
187060
187329
  if (pendingPartialRow !== null) {
187061
187330
  const rowIndex = pendingPartialRow.rowIndex;
187062
187331
  const fromLineByCell = pendingPartialRow.toLineByCell;
187063
- const continuationPartialRow = computePartialRow(rowIndex, block.rows[rowIndex], measure, availableForBody, fromLineByCell, fullPageHeight);
187332
+ const continuationPartialRow = computePartialRow(rowIndex, block.rows[rowIndex], measure, availableForBody, fromLineByCell, fullPageHeightForBody);
187064
187333
  const madeProgress = continuationPartialRow.toLineByCell.some((toLine, idx) => toLine > (fromLineByCell[idx] || 0));
187065
187334
  const hasRemainingLinesAfterContinuation = continuationPartialRow.toLineByCell.some((toLine, idx) => {
187066
187335
  return toLine < getCellTotalLines(measure.rows[rowIndex].cells[idx]);
@@ -187068,7 +187337,7 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
187068
187337
  const hadRemainingLinesBefore = fromLineByCell.some((fromLine, idx) => {
187069
187338
  return fromLine < getCellTotalLines(measure.rows[rowIndex].cells[idx]);
187070
187339
  });
187071
- const fragmentHeight$1 = continuationPartialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
187340
+ const fragmentHeight$1 = computeFragmentHeight(measure, rowIndex, rowIndex + 1, repeatHeaderCount, borderCollapse, continuationPartialRow);
187072
187341
  if (fragmentHeight$1 > 0 && madeProgress) {
187073
187342
  const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
187074
187343
  const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
@@ -187096,22 +187365,34 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
187096
187365
  currentRow = rowIndex + 1;
187097
187366
  pendingPartialRow = null;
187098
187367
  } else if (!madeProgress && hadRemainingLinesBefore)
187099
- state = advanceColumn(state);
187100
- else
187368
+ if (repeatHeaderCount > 0)
187369
+ retryWithoutHeaders = true;
187370
+ else
187371
+ state = advanceColumn(state);
187372
+ else {
187101
187373
  pendingPartialRow = continuationPartialRow;
187374
+ samePagePartialContinuation = true;
187375
+ }
187102
187376
  isTableContinuation = true;
187103
187377
  continue;
187104
187378
  }
187105
187379
  const bodyStartRow = currentRow;
187106
- const { endRow, partialRow, forcePageBreak } = findSplitPoint(block, measure, bodyStartRow, availableForBody, fullPageHeight);
187380
+ const { endRow, partialRow, forcePageBreak } = findSplitPoint(block, measure, bodyStartRow, availableForBody, fullPageHeightForBody);
187107
187381
  if (endRow === bodyStartRow && partialRow === null && state.page.fragments.length > 0) {
187108
187382
  state = advanceColumn(state);
187109
187383
  continue;
187110
187384
  }
187111
187385
  if (endRow === bodyStartRow && partialRow === null) {
187112
- const forcedPartialRow = computePartialRow(bodyStartRow, block.rows[bodyStartRow], measure, availableForBody, undefined, fullPageHeight);
187386
+ const forcedPartialRow = computePartialRow(bodyStartRow, block.rows[bodyStartRow], measure, availableForBody, undefined, fullPageHeightForBody);
187387
+ if (!forcedPartialRow.toLineByCell.some((cutLine) => cutLine > 0)) {
187388
+ if (repeatHeaderCount > 0)
187389
+ retryWithoutHeaders = true;
187390
+ else
187391
+ state = advanceColumn(state);
187392
+ continue;
187393
+ }
187113
187394
  const forcedEndRow = bodyStartRow + 1;
187114
- const fragmentHeight$1 = forcedPartialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
187395
+ const fragmentHeight$1 = computeFragmentHeight(measure, bodyStartRow, forcedEndRow, repeatHeaderCount, borderCollapse, forcedPartialRow);
187115
187396
  const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
187116
187397
  const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
187117
187398
  const fragment$1 = {
@@ -187134,18 +187415,11 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
187134
187415
  state.page.fragments.push(fragment$1);
187135
187416
  state.cursorY += fragmentHeight$1;
187136
187417
  pendingPartialRow = forcedPartialRow;
187418
+ samePagePartialContinuation = true;
187137
187419
  isTableContinuation = true;
187138
187420
  continue;
187139
187421
  }
187140
- let fragmentHeight;
187141
- if (partialRow)
187142
- fragmentHeight = sumRowHeights(measure.rows, bodyStartRow, endRow - 1) + partialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
187143
- else
187144
- fragmentHeight = calculateFragmentHeight({
187145
- fromRow: bodyStartRow,
187146
- toRow: endRow,
187147
- repeatHeaderCount
187148
- }, measure, headerCount, borderCollapse);
187422
+ const fragmentHeight = computeFragmentHeight(measure, bodyStartRow, endRow, repeatHeaderCount, borderCollapse, partialRow);
187149
187423
  const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
187150
187424
  const scaledWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width);
187151
187425
  const fragment2 = {
@@ -187177,6 +187451,8 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
187177
187451
  isTableContinuation = true;
187178
187452
  if (forcePageBreak && currentRow < block.rows.length)
187179
187453
  state = advanceColumn(state);
187454
+ else if (pendingPartialRow)
187455
+ samePagePartialContinuation = true;
187180
187456
  }
187181
187457
  }
187182
187458
  function createAnchoredTableFragment(block, measure, x, y$1) {
@@ -196115,22 +196391,28 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
196115
196391
  const cellX = calculateCellX(cellIdx, cellMeasure);
196116
196392
  const cellBlocks = getCellBlocks(cell2);
196117
196393
  const cellBlockMeasures = getCellMeasures(cellMeasure);
196394
+ const cellRenderBlocks = describeCellRenderBlocks(cellMeasure, cell2, padding);
196395
+ const totalCellLines = cellRenderBlocks.length > 0 ? cellRenderBlocks[cellRenderBlocks.length - 1].globalEndLine : 0;
196396
+ const cellAllowedStart = partialRowData?.fromLineByCell?.[cellIdx] ?? 0;
196397
+ const rawCellAllowedEnd = partialRowData?.toLineByCell?.[cellIdx];
196398
+ const cellAllowedEnd = rawCellAllowedEnd == null || rawCellAllowedEnd === -1 ? totalCellLines : rawCellAllowedEnd;
196118
196399
  const renderedBlocks = [];
196119
196400
  let cumulativeLine = 0;
196120
- for (let i4 = 0;i4 < Math.min(cellBlocks.length, cellBlockMeasures.length); i4 += 1) {
196401
+ const blockCount = Math.min(cellBlocks.length, cellBlockMeasures.length);
196402
+ for (let i4 = 0;i4 < blockCount; i4 += 1) {
196121
196403
  const paraBlock = cellBlocks[i4];
196122
196404
  const paraMeasure = cellBlockMeasures[i4];
196123
- if (!paraBlock || !paraMeasure || paraBlock.kind !== "paragraph" || paraMeasure.kind !== "paragraph")
196405
+ if (!paraBlock || !paraMeasure || paraBlock.kind !== "paragraph" || paraMeasure.kind !== "paragraph") {
196406
+ if (paraMeasure)
196407
+ cumulativeLine += countBlockSegments(paraMeasure);
196124
196408
  continue;
196409
+ }
196125
196410
  const lineCount = paraMeasure.lines.length;
196126
196411
  const blockStart = cumulativeLine;
196127
196412
  const blockEnd = cumulativeLine + lineCount;
196128
196413
  cumulativeLine = blockEnd;
196129
- const allowedStart = partialRowData?.fromLineByCell?.[cellIdx] ?? 0;
196130
- const rawAllowedEnd = partialRowData?.toLineByCell?.[cellIdx];
196131
- const allowedEnd = rawAllowedEnd == null || rawAllowedEnd === -1 ? cumulativeLine : rawAllowedEnd;
196132
- const renderStartGlobal = Math.max(blockStart, allowedStart);
196133
- const renderEndGlobal = Math.min(blockEnd, allowedEnd);
196414
+ const renderStartGlobal = Math.max(blockStart, cellAllowedStart);
196415
+ const renderEndGlobal = Math.min(blockEnd, cellAllowedEnd);
196134
196416
  if (renderStartGlobal >= renderEndGlobal)
196135
196417
  continue;
196136
196418
  const startLine = renderStartGlobal - blockStart;
@@ -196141,21 +196423,25 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
196141
196423
  if (typeof totalHeight === "number" && totalHeight > height)
196142
196424
  height = totalHeight;
196143
196425
  const isFirstBlock = i4 === 0;
196144
- const isLastBlock = i4 === cellBlocks.length - 1;
196145
196426
  const spacingBefore = paraBlock.attrs?.spacing?.before;
196146
196427
  height += effectiveTableCellSpacing(spacingBefore, isFirstBlock, padding.top);
196147
- const spacingAfter = paraBlock.attrs?.spacing?.after;
196148
- height += effectiveTableCellSpacing(spacingAfter, isLastBlock, padding.bottom);
196428
+ if (!(i4 === blockCount - 1)) {
196429
+ const spacingAfter = paraBlock.attrs?.spacing?.after;
196430
+ if (typeof spacingAfter === "number" && spacingAfter > 0)
196431
+ height += spacingAfter;
196432
+ }
196149
196433
  }
196150
196434
  renderedBlocks.push({
196151
196435
  block: paraBlock,
196152
196436
  measure: paraMeasure,
196153
196437
  startLine,
196154
196438
  endLine,
196155
- height
196439
+ height,
196440
+ originalBlockIndex: i4,
196441
+ globalBlockStart: blockStart
196156
196442
  });
196157
196443
  }
196158
- const contentHeight = renderedBlocks.reduce((acc, info) => acc + info.height, 0);
196444
+ const contentHeight = computeCellSliceContentHeight(cellRenderBlocks, cellAllowedStart, cellAllowedEnd);
196159
196445
  const contentAreaHeight = Math.max(0, rowHeight - (padding.top + padding.bottom));
196160
196446
  const freeSpace = Math.max(0, contentAreaHeight - contentHeight);
196161
196447
  let verticalOffset = 0;
@@ -196165,7 +196451,22 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
196165
196451
  else if (vAlign === "bottom")
196166
196452
  verticalOffset = freeSpace;
196167
196453
  let blockTopCursor = padding.top + verticalOffset;
196168
- renderedBlocks.forEach((info, blockIndex$1) => {
196454
+ let prevBlockGlobalEndLine = cellAllowedStart;
196455
+ renderedBlocks.forEach((info) => {
196456
+ for (const rb of cellRenderBlocks) {
196457
+ if (rb.kind === "paragraph")
196458
+ continue;
196459
+ if (rb.visibleHeight === 0)
196460
+ continue;
196461
+ if (rb.globalEndLine <= prevBlockGlobalEndLine)
196462
+ continue;
196463
+ if (rb.globalStartLine >= info.globalBlockStart)
196464
+ break;
196465
+ const localStart = Math.max(0, cellAllowedStart - rb.globalStartLine);
196466
+ const localEnd = Math.min(rb.lineHeights.length, cellAllowedEnd - rb.globalStartLine);
196467
+ for (let li2 = localStart;li2 < localEnd; li2++)
196468
+ blockTopCursor += rb.lineHeights[li2];
196469
+ }
196169
196470
  const paragraphMarkerWidth = info.measure.marker?.markerWidth ?? 0;
196170
196471
  const cellIsListItem = isListItem2(paragraphMarkerWidth, info.block);
196171
196472
  const alignmentOverride = cellIsListItem ? "left" : undefined;
@@ -196173,7 +196474,7 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
196173
196474
  const cellWordLayout = getWordLayoutConfig(info.block);
196174
196475
  const intersectingLines = findLinesIntersectingRange(info.block, info.measure, from$1, to);
196175
196476
  const rawSpacingBefore = info.block.attrs?.spacing?.before;
196176
- const effectiveSpacingBeforePx = info.startLine === 0 ? effectiveTableCellSpacing(rawSpacingBefore, blockIndex$1 === 0, padding.top) : 0;
196477
+ const effectiveSpacingBeforePx = info.startLine === 0 ? effectiveTableCellSpacing(rawSpacingBefore, info.originalBlockIndex === 0, padding.top) : 0;
196177
196478
  intersectingLines.forEach(({ line, index: index2 }) => {
196178
196479
  if (index2 < info.startLine || index2 >= info.endLine)
196179
196480
  return;
@@ -196212,6 +196513,7 @@ function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper)
196212
196513
  });
196213
196514
  });
196214
196515
  blockTopCursor += info.height;
196516
+ prevBlockGlobalEndLine = info.globalBlockStart + info.endLine;
196215
196517
  });
196216
196518
  }
196217
196519
  return rowOffset + rowHeight;
@@ -220568,6 +220870,16 @@ var Node$13 = class Node$14 {
220568
220870
  if (!cell2)
220569
220871
  return [];
220570
220872
  return cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
220873
+ }, countBlockSegments = (measure) => {
220874
+ if (measure.kind === "paragraph")
220875
+ return measure.lines?.length ?? 0;
220876
+ if (measure.kind === "table") {
220877
+ let count = 0;
220878
+ for (const row2 of measure.rows)
220879
+ count += getEmbeddedRowLines(row2).length;
220880
+ return count;
220881
+ }
220882
+ return (typeof measure.height === "number" ? measure.height : 0) > 0 ? 1 : 0;
220571
220883
  }, sumLineHeights = (measure, fromLine, toLine) => {
220572
220884
  let height = 0;
220573
220885
  for (let i4 = fromLine;i4 < toLine && i4 < measure.lines.length; i4 += 1)
@@ -229286,7 +229598,7 @@ var Node$13 = class Node$14 {
229286
229598
  return false;
229287
229599
  return Boolean(checker(attrs));
229288
229600
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
229289
- var init_src_BeJRbQ1S_es = __esm(() => {
229601
+ var init_src_BS_QWHti_es = __esm(() => {
229290
229602
  init_rolldown_runtime_B2q5OVn9_es();
229291
229603
  init_SuperConverter_DvkQFRg9_es();
229292
229604
  init_jszip_ChlR43oI_es();
@@ -262649,7 +262961,7 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
262649
262961
 
262650
262962
  // ../../packages/superdoc/dist/super-editor.es.js
262651
262963
  var init_super_editor_es = __esm(() => {
262652
- init_src_BeJRbQ1S_es();
262964
+ init_src_BS_QWHti_es();
262653
262965
  init_SuperConverter_DvkQFRg9_es();
262654
262966
  init_jszip_ChlR43oI_es();
262655
262967
  init_xml_js_BtmJ6bNs_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.3.0-next.49",
3
+ "version": "0.3.0-next.50",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -21,20 +21,20 @@
21
21
  "@types/node": "22.19.2",
22
22
  "typescript": "^5.9.2",
23
23
  "@superdoc/document-api": "0.0.1",
24
- "@superdoc/pm-adapter": "0.0.0",
24
+ "superdoc": "1.20.0",
25
25
  "@superdoc/super-editor": "0.0.1",
26
- "superdoc": "1.20.0"
26
+ "@superdoc/pm-adapter": "0.0.0"
27
27
  },
28
28
  "module": "src/index.ts",
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.49",
34
- "@superdoc-dev/cli-darwin-x64": "0.3.0-next.49",
35
- "@superdoc-dev/cli-linux-x64": "0.3.0-next.49",
36
- "@superdoc-dev/cli-linux-arm64": "0.3.0-next.49",
37
- "@superdoc-dev/cli-windows-x64": "0.3.0-next.49"
33
+ "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.50",
34
+ "@superdoc-dev/cli-darwin-x64": "0.3.0-next.50",
35
+ "@superdoc-dev/cli-linux-arm64": "0.3.0-next.50",
36
+ "@superdoc-dev/cli-windows-x64": "0.3.0-next.50",
37
+ "@superdoc-dev/cli-linux-x64": "0.3.0-next.50"
38
38
  },
39
39
  "scripts": {
40
40
  "predev": "node scripts/ensure-superdoc-build.js",