oasis-editor 0.0.62 → 0.0.64

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.
@@ -2483,7 +2483,7 @@ function OasisEditorAppLazy(props = {}) {
2483
2483
  onCleanup(() => {
2484
2484
  cancelled = true;
2485
2485
  });
2486
- import("./OasisEditorApp-BG3tA5Y-.js").then((m) => {
2486
+ import("./OasisEditorApp-C5ryUlHF.js").then((m) => {
2487
2487
  cancelled = true;
2488
2488
  setProgress(1);
2489
2489
  setTimeout(() => setApp(() => m.OasisEditorApp), 180);
@@ -12758,6 +12758,422 @@ function projectHeaderFooterBlocks(blocks, pageIndex, totalPages, measuredHeight
12758
12758
  defaultTabStop
12759
12759
  );
12760
12760
  }
12761
+ const MAX_COLUMN_BALANCE_ITERATIONS = 100;
12762
+ function projectColumnedBlocksLayout(context2, count, runTrackLayout) {
12763
+ var _a, _b;
12764
+ const { pageSettings, maxPageHeight, pageOffset = 0, existingPages = [] } = context2;
12765
+ const colWidth = ((_a = getPageColumnRects(pageSettings)[0]) == null ? void 0 : _a.width) ?? getPageContentWidth(pageSettings);
12766
+ const runTracks = (blocks, trackHeight) => runTrackLayout({
12767
+ ...context2,
12768
+ blocks,
12769
+ maxPageHeight: trackHeight,
12770
+ contentWidthOverride: colWidth,
12771
+ pageOffset: 0,
12772
+ existingPages: [],
12773
+ reservedHeightByPageIndex: void 0
12774
+ });
12775
+ let tracks = runTracks(context2.blocks, maxPageHeight);
12776
+ if (tracks.length > 1 || tracks.length === 1 && count > 1) {
12777
+ const trailingStart = Math.floor((tracks.length - 1) / count) * count;
12778
+ const trailingTracks = tracks.slice(trailingStart);
12779
+ const firstTrailingBlock = (_b = trailingTracks[0]) == null ? void 0 : _b.blocks[0];
12780
+ const prevTrack = trailingStart > 0 ? tracks[trailingStart - 1] : void 0;
12781
+ const prevLastBlock = prevTrack == null ? void 0 : prevTrack.blocks[prevTrack.blocks.length - 1];
12782
+ const cleanBoundary = firstTrailingBlock != null && (prevLastBlock == null || prevLastBlock.globalIndex !== firstTrailingBlock.globalIndex);
12783
+ if (cleanBoundary) {
12784
+ const startIndex = firstTrailingBlock.globalIndex;
12785
+ const sourceSubset = context2.blocks.slice(startIndex);
12786
+ const sumHeight = trailingTracks.reduce(
12787
+ (sum, track) => sum + track.height,
12788
+ 0
12789
+ );
12790
+ let target = Math.max(24, Math.ceil(sumHeight / count));
12791
+ let balanced = runTracks(sourceSubset, target);
12792
+ for (let iteration = 0; balanced.length > count && target < maxPageHeight && iteration < MAX_COLUMN_BALANCE_ITERATIONS; iteration += 1) {
12793
+ target = Math.min(maxPageHeight, Math.ceil(target * 1.05) + 4);
12794
+ balanced = runTracks(sourceSubset, target);
12795
+ }
12796
+ if (balanced.length <= count) {
12797
+ tracks = [...tracks.slice(0, trailingStart), ...balanced];
12798
+ }
12799
+ }
12800
+ }
12801
+ const pages = [...existingPages];
12802
+ const startPageIndex = existingPages.length > 0 ? existingPages[existingPages.length - 1].index + 1 : pageOffset;
12803
+ const physicalPageCount = Math.ceil(tracks.length / count);
12804
+ for (let p = 0; p < physicalPageCount; p += 1) {
12805
+ const pageIndex = startPageIndex + p;
12806
+ const pageTracks = tracks.slice(p * count, p * count + count);
12807
+ const blocks = [];
12808
+ let height = 0;
12809
+ pageTracks.forEach((track, columnIndex) => {
12810
+ for (const block of track.blocks) {
12811
+ block.columnIndex = columnIndex;
12812
+ blocks.push(block);
12813
+ }
12814
+ height = Math.max(height, track.height);
12815
+ });
12816
+ pages.push({
12817
+ id: `page:${pageIndex + 1}`,
12818
+ index: pageIndex,
12819
+ height,
12820
+ maxHeight: maxPageHeight,
12821
+ blocks,
12822
+ pageSettings
12823
+ });
12824
+ }
12825
+ if (pages.length === 0) {
12826
+ pages.push({
12827
+ id: `page:${startPageIndex + 1}`,
12828
+ index: startPageIndex,
12829
+ height: 0,
12830
+ maxHeight: maxPageHeight,
12831
+ blocks: [],
12832
+ pageSettings
12833
+ });
12834
+ }
12835
+ return pages;
12836
+ }
12837
+ class PaginationTrack {
12838
+ constructor(pageOffset, maxPageHeight, reservedHeightByPageIndex, pageSettings, existingPages) {
12839
+ __publicField(this, "pages");
12840
+ __publicField(this, "blocks");
12841
+ __publicField(this, "height");
12842
+ this.pageOffset = pageOffset;
12843
+ this.maxPageHeight = maxPageHeight;
12844
+ this.reservedHeightByPageIndex = reservedHeightByPageIndex;
12845
+ this.pageSettings = pageSettings;
12846
+ this.pages = [...existingPages];
12847
+ const currentPage = this.pages[this.pages.length - 1];
12848
+ this.blocks = currentPage ? [...currentPage.blocks] : [];
12849
+ this.height = currentPage ? currentPage.height : 0;
12850
+ if (currentPage) {
12851
+ this.pages.pop();
12852
+ }
12853
+ }
12854
+ /** Index of the track currently being filled. */
12855
+ get pageIndex() {
12856
+ return this.pageOffset + this.pages.length;
12857
+ }
12858
+ /** Usable height of a given page, net of any reserved (e.g. footnote) space. */
12859
+ maxHeightForPage(pageIndex) {
12860
+ var _a;
12861
+ return Math.max(
12862
+ 24,
12863
+ this.maxPageHeight - (((_a = this.reservedHeightByPageIndex) == null ? void 0 : _a.get(pageIndex)) ?? 0)
12864
+ );
12865
+ }
12866
+ /** Usable height of the track currently being filled. */
12867
+ get currentMaxHeight() {
12868
+ return this.maxHeightForPage(this.pageIndex);
12869
+ }
12870
+ /** Seals the current track into a page and starts a fresh, empty track. */
12871
+ flush() {
12872
+ if (this.blocks.length === 0 && this.pages.length > 0) {
12873
+ return;
12874
+ }
12875
+ const pageIndex = this.pageIndex;
12876
+ this.pages.push({
12877
+ id: `page:${pageIndex + 1}`,
12878
+ index: pageIndex,
12879
+ height: this.height,
12880
+ maxHeight: this.maxHeightForPage(pageIndex),
12881
+ blocks: this.blocks,
12882
+ pageSettings: this.pageSettings
12883
+ });
12884
+ this.blocks = [];
12885
+ this.height = 0;
12886
+ }
12887
+ /** Flushes the trailing track and guarantees at least one page exists. */
12888
+ finalize() {
12889
+ this.flush();
12890
+ if (this.pages.length === 0) {
12891
+ const pageIndex = this.pageOffset;
12892
+ this.pages.push({
12893
+ id: `page:${pageIndex + 1}`,
12894
+ index: pageIndex,
12895
+ height: 0,
12896
+ maxHeight: this.maxHeightForPage(pageIndex),
12897
+ blocks: [],
12898
+ pageSettings: this.pageSettings
12899
+ });
12900
+ }
12901
+ return this.pages;
12902
+ }
12903
+ }
12904
+ const TEXT_BOX_AUTOFIT_SAFETY_PX$1 = 2;
12905
+ function estimateTextBoxAutoFitHeight(textBox, styles, measurer, pageIndex, totalPages, defaultTabStop) {
12906
+ var _a, _b, _c, _d, _e;
12907
+ if (!((_a = textBox.body) == null ? void 0 : _a.autoFit)) {
12908
+ return textBox.height;
12909
+ }
12910
+ const padding = {
12911
+ left: ((_b = textBox.body) == null ? void 0 : _b.paddingLeft) ?? 0,
12912
+ top: ((_c = textBox.body) == null ? void 0 : _c.paddingTop) ?? 0,
12913
+ right: ((_d = textBox.body) == null ? void 0 : _d.paddingRight) ?? 0,
12914
+ bottom: ((_e = textBox.body) == null ? void 0 : _e.paddingBottom) ?? 0
12915
+ };
12916
+ const innerWidth = Math.max(1, textBox.width - padding.left - padding.right);
12917
+ const contentHeight = textBox.blocks.reduce((sum, block) => {
12918
+ if (block.type === "paragraph") {
12919
+ const layout = projectParagraphLayout(
12920
+ block,
12921
+ pageIndex,
12922
+ totalPages,
12923
+ styles,
12924
+ innerWidth,
12925
+ measurer,
12926
+ defaultTabStop
12927
+ );
12928
+ return sum + getProjectedParagraphBlockHeight(block, layout, styles);
12929
+ }
12930
+ if (block.type === "table") {
12931
+ return sum + estimateTableBlockHeight(
12932
+ block,
12933
+ styles,
12934
+ innerWidth,
12935
+ measurer,
12936
+ defaultTabStop
12937
+ );
12938
+ }
12939
+ return sum;
12940
+ }, 0);
12941
+ return Math.max(
12942
+ 1,
12943
+ Math.ceil(
12944
+ contentHeight + padding.top + padding.bottom + TEXT_BOX_AUTOFIT_SAFETY_PX$1
12945
+ )
12946
+ );
12947
+ }
12948
+ function paginateParagraphBlock(track, params, sourceBlock, nextBlock, index) {
12949
+ var _a;
12950
+ const {
12951
+ pageSettings,
12952
+ contentWidth,
12953
+ measurer,
12954
+ styles,
12955
+ totalPages,
12956
+ defaultTabStop,
12957
+ measuredHeights,
12958
+ measuredParagraphLayouts
12959
+ } = params;
12960
+ const pageIndex = track.pageIndex;
12961
+ const projectedParagraphLayout = projectParagraphLayoutWithExclusions(
12962
+ sourceBlock,
12963
+ pageSettings,
12964
+ contentWidth,
12965
+ measurer,
12966
+ pageIndex,
12967
+ totalPages,
12968
+ styles,
12969
+ defaultTabStop,
12970
+ (textBox) => estimateTextBoxAutoFitHeight(
12971
+ textBox,
12972
+ styles,
12973
+ measurer,
12974
+ pageIndex,
12975
+ totalPages,
12976
+ defaultTabStop
12977
+ )
12978
+ );
12979
+ const measuredParagraphLayout = measuredParagraphLayouts == null ? void 0 : measuredParagraphLayouts[sourceBlock.id];
12980
+ const paragraphLayout = measuredParagraphLayout && isMeasuredLayoutCurrent(projectedParagraphLayout, measuredParagraphLayout) ? applyMeasuredLineGeometry(
12981
+ projectedParagraphLayout,
12982
+ measuredParagraphLayout
12983
+ ) : projectedParagraphLayout;
12984
+ let collapseWithPrevious = false;
12985
+ let contextualAdjustedPreviousBlock;
12986
+ let contextualAdjustedAmount = 0;
12987
+ let paragraphTotalHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? getProjectedParagraphBlockHeight(sourceBlock, paragraphLayout, styles);
12988
+ const paragraphStyle = getEffectiveParagraphStyle(sourceBlock, styles);
12989
+ const nextBlockHeight = (nextBlock == null ? void 0 : nextBlock.type) === "paragraph" ? (measuredHeights == null ? void 0 : measuredHeights[nextBlock.id]) ?? estimateParagraphBlockHeight(
12990
+ nextBlock,
12991
+ styles,
12992
+ contentWidth,
12993
+ measurer,
12994
+ {
12995
+ allowSpacingBefore: !shouldCollapseContextualSpacing(
12996
+ sourceBlock,
12997
+ nextBlock,
12998
+ styles
12999
+ )
13000
+ },
13001
+ defaultTabStop
13002
+ ) : nextBlock ? (measuredHeights == null ? void 0 : measuredHeights[nextBlock.id]) ?? estimateTableBlockHeight(
13003
+ nextBlock,
13004
+ styles,
13005
+ contentWidth,
13006
+ measurer,
13007
+ defaultTabStop
13008
+ ) : 0;
13009
+ if (paragraphStyle.keepWithNext && track.blocks.length > 0 && track.height + paragraphTotalHeight + nextBlockHeight > track.currentMaxHeight && paragraphTotalHeight + nextBlockHeight <= track.currentMaxHeight) {
13010
+ track.flush();
13011
+ }
13012
+ const previousBlock = track.blocks.at(-1);
13013
+ const previousParagraph = (previousBlock == null ? void 0 : previousBlock.blockType) === "paragraph" && ((_a = previousBlock.sourceBlock) == null ? void 0 : _a.type) === "paragraph" ? previousBlock.sourceBlock : void 0;
13014
+ collapseWithPrevious = track.blocks.length > 0 && shouldCollapseContextualSpacing(previousParagraph, sourceBlock, styles);
13015
+ if (collapseWithPrevious && previousBlock && previousParagraph) {
13016
+ const previousStyle = getEffectiveParagraphStyle(previousParagraph, styles);
13017
+ const collapsedSpacingAfter = previousStyle.spacingAfter ?? 0;
13018
+ if (collapsedSpacingAfter > 0) {
13019
+ previousBlock.estimatedHeight = Math.max(
13020
+ 0,
13021
+ previousBlock.estimatedHeight - collapsedSpacingAfter
13022
+ );
13023
+ track.height = Math.max(0, track.height - collapsedSpacingAfter);
13024
+ contextualAdjustedPreviousBlock = previousBlock;
13025
+ contextualAdjustedAmount = collapsedSpacingAfter;
13026
+ }
13027
+ paragraphTotalHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? getProjectedParagraphBlockHeight(
13028
+ sourceBlock,
13029
+ paragraphLayout,
13030
+ styles,
13031
+ false
13032
+ );
13033
+ }
13034
+ if (paragraphStyle.keepLinesTogether && paragraphTotalHeight <= track.currentMaxHeight) {
13035
+ if (track.blocks.length > 0 && track.height + paragraphTotalHeight > track.currentMaxHeight) {
13036
+ track.flush();
13037
+ }
13038
+ const segmentId = `${sourceBlock.id}:segment:0`;
13039
+ const rawMeasuredHeight = getParagraphMeasuredHeight(
13040
+ measuredHeights,
13041
+ sourceBlock.id,
13042
+ segmentId,
13043
+ true,
13044
+ paragraphTotalHeight
13045
+ );
13046
+ const hasMeasuredHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) !== void 0 || (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) !== void 0;
13047
+ const measuredHeight = collapseWithPrevious && hasMeasuredHeight ? Math.max(0, rawMeasuredHeight - (paragraphStyle.spacingBefore ?? 0)) : rawMeasuredHeight;
13048
+ track.blocks.push({
13049
+ blockId: segmentId,
13050
+ sourceBlockId: sourceBlock.id,
13051
+ blockType: sourceBlock.type,
13052
+ paragraphId: sourceBlock.id,
13053
+ globalIndex: index,
13054
+ estimatedHeight: measuredHeight,
13055
+ layout: paragraphLayout,
13056
+ sourceBlock
13057
+ });
13058
+ track.height += measuredHeight;
13059
+ return;
13060
+ }
13061
+ let startLineIndex = 0;
13062
+ let segmentIndex = 0;
13063
+ while (startLineIndex < paragraphLayout.lines.length) {
13064
+ const remainingHeight = track.currentMaxHeight - track.height;
13065
+ let lineEndIndex = startLineIndex;
13066
+ let segmentHeight = 0;
13067
+ while (lineEndIndex < paragraphLayout.lines.length) {
13068
+ const candidateLines = paragraphLayout.lines.slice(
13069
+ startLineIndex,
13070
+ lineEndIndex + 1
13071
+ );
13072
+ const candidateHeight = getParagraphSegmentHeight(
13073
+ sourceBlock,
13074
+ candidateLines,
13075
+ startLineIndex === 0,
13076
+ lineEndIndex === paragraphLayout.lines.length - 1,
13077
+ styles,
13078
+ !collapseWithPrevious
13079
+ );
13080
+ const candidateFitHeight = getParagraphSegmentFitHeight(
13081
+ sourceBlock,
13082
+ candidateHeight,
13083
+ lineEndIndex === paragraphLayout.lines.length - 1,
13084
+ styles
13085
+ );
13086
+ const tolerance = 1.5;
13087
+ if (candidateFitHeight > remainingHeight + tolerance && lineEndIndex === startLineIndex && track.blocks.length > 0) {
13088
+ break;
13089
+ }
13090
+ if (candidateFitHeight > remainingHeight + tolerance && lineEndIndex > startLineIndex) {
13091
+ break;
13092
+ }
13093
+ segmentHeight = candidateHeight;
13094
+ lineEndIndex += 1;
13095
+ }
13096
+ if (lineEndIndex === startLineIndex && track.blocks.length > 0) {
13097
+ if (contextualAdjustedPreviousBlock && contextualAdjustedAmount > 0) {
13098
+ contextualAdjustedPreviousBlock.estimatedHeight += contextualAdjustedAmount;
13099
+ track.height += contextualAdjustedAmount;
13100
+ contextualAdjustedPreviousBlock = void 0;
13101
+ contextualAdjustedAmount = 0;
13102
+ }
13103
+ collapseWithPrevious = false;
13104
+ track.flush();
13105
+ continue;
13106
+ }
13107
+ if (lineEndIndex === startLineIndex) {
13108
+ lineEndIndex = Math.min(paragraphLayout.lines.length, startLineIndex + 1);
13109
+ segmentHeight = getParagraphSegmentHeight(
13110
+ sourceBlock,
13111
+ paragraphLayout.lines.slice(startLineIndex, lineEndIndex),
13112
+ startLineIndex === 0,
13113
+ lineEndIndex === paragraphLayout.lines.length,
13114
+ styles,
13115
+ !collapseWithPrevious
13116
+ );
13117
+ }
13118
+ if (lineEndIndex < paragraphLayout.lines.length) {
13119
+ const widowOrphanAdjusted = applyWidowOrphanControl(
13120
+ sourceBlock,
13121
+ paragraphLayout.lines,
13122
+ startLineIndex,
13123
+ lineEndIndex,
13124
+ styles,
13125
+ !collapseWithPrevious,
13126
+ true,
13127
+ track.blocks.length > 0
13128
+ );
13129
+ lineEndIndex = widowOrphanAdjusted.endLineIndexExclusive;
13130
+ segmentHeight = widowOrphanAdjusted.height;
13131
+ if (lineEndIndex === startLineIndex) {
13132
+ if (contextualAdjustedPreviousBlock && contextualAdjustedAmount > 0) {
13133
+ contextualAdjustedPreviousBlock.estimatedHeight += contextualAdjustedAmount;
13134
+ track.height += contextualAdjustedAmount;
13135
+ contextualAdjustedPreviousBlock = void 0;
13136
+ contextualAdjustedAmount = 0;
13137
+ }
13138
+ collapseWithPrevious = false;
13139
+ track.flush();
13140
+ continue;
13141
+ }
13142
+ }
13143
+ const segmentLayout = createParagraphSegmentLayout(
13144
+ paragraphLayout,
13145
+ startLineIndex,
13146
+ lineEndIndex
13147
+ );
13148
+ const segmentId = `${sourceBlock.id}:segment:${segmentIndex}`;
13149
+ const isWholeParagraphSegment = startLineIndex === 0 && lineEndIndex === paragraphLayout.lines.length;
13150
+ const rawMeasuredHeight = getParagraphMeasuredHeight(
13151
+ measuredHeights,
13152
+ sourceBlock.id,
13153
+ segmentId,
13154
+ isWholeParagraphSegment,
13155
+ segmentHeight
13156
+ );
13157
+ const hasMeasuredHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) !== void 0 || isWholeParagraphSegment && (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) !== void 0;
13158
+ const measuredHeight = collapseWithPrevious && startLineIndex === 0 && hasMeasuredHeight ? Math.max(0, rawMeasuredHeight - (paragraphStyle.spacingBefore ?? 0)) : rawMeasuredHeight;
13159
+ track.blocks.push({
13160
+ blockId: segmentId,
13161
+ sourceBlockId: sourceBlock.id,
13162
+ blockType: sourceBlock.type,
13163
+ paragraphId: sourceBlock.id,
13164
+ globalIndex: index,
13165
+ estimatedHeight: measuredHeight,
13166
+ layout: segmentLayout,
13167
+ sourceBlock
13168
+ });
13169
+ track.height += measuredHeight;
13170
+ startLineIndex = lineEndIndex;
13171
+ segmentIndex += 1;
13172
+ if (startLineIndex < paragraphLayout.lines.length) {
13173
+ track.flush();
13174
+ }
13175
+ }
13176
+ }
12761
13177
  function normalizeCellStartPositions(row, starts, legacyStarts) {
12762
13178
  return row.cells.map((_, cellIdx) => {
12763
13179
  var _a, _b;
@@ -12943,125 +13359,283 @@ function positionsFinishedRow(row, ends) {
12943
13359
  }
12944
13360
  );
12945
13361
  }
12946
- const MAX_COLUMN_BALANCE_ITERATIONS = 100;
12947
- function projectColumnedBlocksLayout(context2, count, runTrackLayout) {
12948
- var _a, _b;
12949
- const { pageSettings, maxPageHeight, pageOffset = 0, existingPages = [] } = context2;
12950
- const colWidth = ((_a = getPageColumnRects(pageSettings)[0]) == null ? void 0 : _a.width) ?? getPageContentWidth(pageSettings);
12951
- const runTracks = (blocks, trackHeight) => runTrackLayout({
12952
- ...context2,
12953
- blocks,
12954
- maxPageHeight: trackHeight,
12955
- contentWidthOverride: colWidth,
12956
- pageOffset: 0,
12957
- existingPages: [],
12958
- reservedHeightByPageIndex: void 0
12959
- });
12960
- let tracks = runTracks(context2.blocks, maxPageHeight);
12961
- if (tracks.length > 1 || tracks.length === 1 && count > 1) {
12962
- const trailingStart = Math.floor((tracks.length - 1) / count) * count;
12963
- const trailingTracks = tracks.slice(trailingStart);
12964
- const firstTrailingBlock = (_b = trailingTracks[0]) == null ? void 0 : _b.blocks[0];
12965
- const prevTrack = trailingStart > 0 ? tracks[trailingStart - 1] : void 0;
12966
- const prevLastBlock = prevTrack == null ? void 0 : prevTrack.blocks[prevTrack.blocks.length - 1];
12967
- const cleanBoundary = firstTrailingBlock != null && (prevLastBlock == null || prevLastBlock.globalIndex !== firstTrailingBlock.globalIndex);
12968
- if (cleanBoundary) {
12969
- const startIndex = firstTrailingBlock.globalIndex;
12970
- const sourceSubset = context2.blocks.slice(startIndex);
12971
- const sumHeight = trailingTracks.reduce(
12972
- (sum, track) => sum + track.height,
12973
- 0
12974
- );
12975
- let target = Math.max(24, Math.ceil(sumHeight / count));
12976
- let balanced = runTracks(sourceSubset, target);
12977
- for (let iteration = 0; balanced.length > count && target < maxPageHeight && iteration < MAX_COLUMN_BALANCE_ITERATIONS; iteration += 1) {
12978
- target = Math.min(maxPageHeight, Math.ceil(target * 1.05) + 4);
12979
- balanced = runTracks(sourceSubset, target);
12980
- }
12981
- if (balanced.length <= count) {
12982
- tracks = [...tracks.slice(0, trailingStart), ...balanced];
13362
+ function paginateTableBlock(track, params, sourceBlock, index) {
13363
+ const { contentWidth, measurer, styles, defaultTabStop, measuredHeights } = params;
13364
+ const tableHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? estimateTableBlockHeight(
13365
+ sourceBlock,
13366
+ styles,
13367
+ contentWidth,
13368
+ measurer,
13369
+ defaultTabStop
13370
+ );
13371
+ const maxHeightForCurrentPage = track.currentMaxHeight;
13372
+ const firstRow = sourceBlock.rows[0];
13373
+ const canSplitSingleRow = canSplitTableRow(firstRow);
13374
+ if (!canSplitSingleRow && sourceBlock.rows.length <= 1 || track.height + tableHeight <= maxHeightForCurrentPage) {
13375
+ if (track.blocks.length > 0 && track.height + tableHeight > maxHeightForCurrentPage) {
13376
+ track.flush();
13377
+ }
13378
+ track.blocks.push({
13379
+ blockId: sourceBlock.id,
13380
+ sourceBlockId: sourceBlock.id,
13381
+ blockType: sourceBlock.type,
13382
+ globalIndex: index,
13383
+ estimatedHeight: tableHeight,
13384
+ sourceBlock
13385
+ });
13386
+ track.height += tableHeight;
13387
+ return;
13388
+ }
13389
+ const rowGroups = getTableRowGroups(sourceBlock);
13390
+ const headerRowCount = getRepeatableHeaderRowCount(
13391
+ sourceBlock,
13392
+ getTableHeaderRowCount(sourceBlock),
13393
+ rowGroups
13394
+ );
13395
+ let groupStartIndex = 0;
13396
+ let segmentIndex = 0;
13397
+ let currentCellBlockPositions;
13398
+ while (groupStartIndex < rowGroups.length) {
13399
+ const startRowIndex = rowGroups[groupStartIndex].startRowIndex;
13400
+ const repeatedHeaderRowCount = startRowIndex > 0 ? headerRowCount : 0;
13401
+ const remainingHeight = track.currentMaxHeight - track.height;
13402
+ let groupEndIndex = groupStartIndex;
13403
+ let segmentHeight = 0;
13404
+ let splitEnds;
13405
+ let splitEndPositions;
13406
+ let isLastRowSplit = false;
13407
+ while (groupEndIndex < rowGroups.length) {
13408
+ const candidateEndRowIndex = rowGroups[groupEndIndex].endRowIndexExclusive;
13409
+ let candidateHeight = 0;
13410
+ if (groupEndIndex === groupStartIndex && currentCellBlockPositions) {
13411
+ const firstRow2 = sourceBlock.rows[startRowIndex];
13412
+ const starts = normalizeCellStartPositions(
13413
+ firstRow2,
13414
+ currentCellBlockPositions,
13415
+ void 0
13416
+ );
13417
+ const ends = firstRow2.cells.map((cell) => ({
13418
+ blockIndex: cell.blocks.length
13419
+ }));
13420
+ const slicedFirstRow = buildRowSliceFromPositions(
13421
+ firstRow2,
13422
+ starts,
13423
+ ends
13424
+ );
13425
+ candidateHeight = getTableSegmentHeight(
13426
+ {
13427
+ ...sourceBlock,
13428
+ rows: [slicedFirstRow]
13429
+ },
13430
+ 0,
13431
+ 1,
13432
+ repeatedHeaderRowCount,
13433
+ styles,
13434
+ contentWidth,
13435
+ measurer,
13436
+ defaultTabStop
13437
+ );
13438
+ } else {
13439
+ candidateHeight = getTableSegmentHeight(
13440
+ sourceBlock,
13441
+ startRowIndex,
13442
+ candidateEndRowIndex,
13443
+ repeatedHeaderRowCount,
13444
+ styles,
13445
+ contentWidth,
13446
+ measurer,
13447
+ defaultTabStop
13448
+ );
13449
+ }
13450
+ if (candidateHeight <= remainingHeight) {
13451
+ segmentHeight = candidateHeight;
13452
+ groupEndIndex += 1;
13453
+ continue;
13454
+ }
13455
+ const isSingleRowGroup = candidateEndRowIndex === rowGroups[groupEndIndex].startRowIndex + 1;
13456
+ const targetRow = sourceBlock.rows[rowGroups[groupEndIndex].startRowIndex];
13457
+ const isSplitCandidate = isSingleRowGroup && canSplitTableRow(targetRow);
13458
+ if (isSplitCandidate) {
13459
+ const precedingHeight = groupEndIndex > groupStartIndex ? getTableSegmentHeight(
13460
+ sourceBlock,
13461
+ startRowIndex,
13462
+ rowGroups[groupEndIndex].startRowIndex,
13463
+ repeatedHeaderRowCount,
13464
+ styles,
13465
+ contentWidth,
13466
+ measurer,
13467
+ defaultTabStop
13468
+ ) : 0;
13469
+ const availableForSplitRow = remainingHeight - precedingHeight;
13470
+ if (availableForSplitRow > 0) {
13471
+ const starts = normalizeCellStartPositions(
13472
+ targetRow,
13473
+ groupEndIndex === groupStartIndex ? currentCellBlockPositions : void 0,
13474
+ void 0
13475
+ );
13476
+ const ends = targetRow.cells.map(
13477
+ (_, cellIdx) => findCellSplitEndPosition(
13478
+ targetRow,
13479
+ cellIdx,
13480
+ starts[cellIdx] ?? { blockIndex: 0 },
13481
+ availableForSplitRow,
13482
+ styles,
13483
+ measurer,
13484
+ defaultTabStop,
13485
+ contentWidth,
13486
+ sourceBlock,
13487
+ rowGroups[groupEndIndex].startRowIndex
13488
+ )
13489
+ );
13490
+ const canProgress = positionsProgressed(starts, ends);
13491
+ if (canProgress) {
13492
+ splitEnds = positionsToBlockIndexes(ends);
13493
+ isLastRowSplit = true;
13494
+ const slicedLastRow = buildRowSliceFromPositions(
13495
+ targetRow,
13496
+ starts,
13497
+ ends
13498
+ );
13499
+ const segmentRows = [
13500
+ ...sourceBlock.rows.slice(
13501
+ startRowIndex,
13502
+ rowGroups[groupEndIndex].startRowIndex
13503
+ ),
13504
+ slicedLastRow
13505
+ ];
13506
+ segmentHeight = getTableSegmentHeight(
13507
+ { ...sourceBlock, rows: segmentRows },
13508
+ 0,
13509
+ segmentRows.length,
13510
+ repeatedHeaderRowCount,
13511
+ styles,
13512
+ contentWidth,
13513
+ measurer,
13514
+ defaultTabStop
13515
+ );
13516
+ splitEndPositions = ends;
13517
+ groupEndIndex += 1;
13518
+ break;
13519
+ }
13520
+ }
12983
13521
  }
13522
+ break;
12984
13523
  }
12985
- }
12986
- const pages = [...existingPages];
12987
- const startPageIndex = existingPages.length > 0 ? existingPages[existingPages.length - 1].index + 1 : pageOffset;
12988
- const physicalPageCount = Math.ceil(tracks.length / count);
12989
- for (let p = 0; p < physicalPageCount; p += 1) {
12990
- const pageIndex = startPageIndex + p;
12991
- const pageTracks = tracks.slice(p * count, p * count + count);
12992
- const blocks = [];
12993
- let height = 0;
12994
- pageTracks.forEach((track, columnIndex) => {
12995
- for (const block of track.blocks) {
12996
- block.columnIndex = columnIndex;
12997
- blocks.push(block);
13524
+ if (groupEndIndex === groupStartIndex && track.blocks.length > 0) {
13525
+ track.flush();
13526
+ continue;
13527
+ }
13528
+ if (groupEndIndex === groupStartIndex) {
13529
+ const targetRow = sourceBlock.rows[startRowIndex];
13530
+ const isSingleRowGroup = rowGroups[groupStartIndex].endRowIndexExclusive === startRowIndex + 1;
13531
+ const isSplitCandidate = isSingleRowGroup && canSplitTableRow(targetRow);
13532
+ if (isSplitCandidate) {
13533
+ const starts = normalizeCellStartPositions(
13534
+ targetRow,
13535
+ currentCellBlockPositions,
13536
+ void 0
13537
+ );
13538
+ let ends = starts.map(
13539
+ (start, cellIdx) => findCellSplitEndPosition(
13540
+ targetRow,
13541
+ cellIdx,
13542
+ start,
13543
+ track.currentMaxHeight,
13544
+ styles,
13545
+ measurer,
13546
+ defaultTabStop,
13547
+ contentWidth,
13548
+ sourceBlock,
13549
+ startRowIndex
13550
+ )
13551
+ );
13552
+ if (!positionsProgressed(starts, ends)) {
13553
+ ends = starts.map((start, cellIdx) => ({
13554
+ blockIndex: Math.min(
13555
+ targetRow.cells[cellIdx].blocks.length,
13556
+ start.blockIndex + 1
13557
+ )
13558
+ }));
13559
+ }
13560
+ splitEnds = positionsToBlockIndexes(ends);
13561
+ splitEndPositions = ends;
13562
+ isLastRowSplit = true;
13563
+ const slicedLastRow = buildRowSliceFromPositions(
13564
+ targetRow,
13565
+ starts,
13566
+ ends
13567
+ );
13568
+ segmentHeight = getTableSegmentHeight(
13569
+ { ...sourceBlock, rows: [slicedLastRow] },
13570
+ 0,
13571
+ 1,
13572
+ repeatedHeaderRowCount,
13573
+ styles,
13574
+ contentWidth,
13575
+ measurer,
13576
+ defaultTabStop
13577
+ );
13578
+ groupEndIndex += 1;
13579
+ } else {
13580
+ groupEndIndex = rowGroups[groupStartIndex].endRowIndexExclusive;
13581
+ segmentHeight = getTableSegmentHeight(
13582
+ sourceBlock,
13583
+ startRowIndex,
13584
+ groupEndIndex,
13585
+ repeatedHeaderRowCount,
13586
+ styles,
13587
+ contentWidth,
13588
+ measurer,
13589
+ defaultTabStop
13590
+ );
12998
13591
  }
12999
- height = Math.max(height, track.height);
13000
- });
13001
- pages.push({
13002
- id: `page:${pageIndex + 1}`,
13003
- index: pageIndex,
13004
- height,
13005
- maxHeight: maxPageHeight,
13006
- blocks,
13007
- pageSettings
13008
- });
13009
- }
13010
- if (pages.length === 0) {
13011
- pages.push({
13012
- id: `page:${startPageIndex + 1}`,
13013
- index: startPageIndex,
13014
- height: 0,
13015
- maxHeight: maxPageHeight,
13016
- blocks: [],
13017
- pageSettings
13592
+ }
13593
+ const segmentId = `${sourceBlock.id}:segment:${segmentIndex}`;
13594
+ const measuredSegmentHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) ?? segmentHeight;
13595
+ const endRowIndex = rowGroups[groupEndIndex - 1].endRowIndexExclusive;
13596
+ track.blocks.push({
13597
+ blockId: segmentId,
13598
+ sourceBlockId: sourceBlock.id,
13599
+ blockType: sourceBlock.type,
13600
+ globalIndex: index,
13601
+ estimatedHeight: measuredSegmentHeight,
13602
+ tableSegment: {
13603
+ startRowIndex,
13604
+ endRowIndex,
13605
+ repeatedHeaderRowCount,
13606
+ startRowCellBlockStarts: positionsToBlockIndexes(
13607
+ currentCellBlockPositions
13608
+ ),
13609
+ endRowCellBlockEnds: splitEnds,
13610
+ startRowCellBlockPositions: hasPartialPositions(
13611
+ currentCellBlockPositions
13612
+ ) ? currentCellBlockPositions : void 0,
13613
+ endRowCellBlockPositions: hasPartialPositions(splitEndPositions) ? splitEndPositions : void 0
13614
+ },
13615
+ sourceBlock
13018
13616
  });
13019
- }
13020
- return pages;
13021
- }
13022
- const TEXT_BOX_AUTOFIT_SAFETY_PX$1 = 2;
13023
- function estimateTextBoxAutoFitHeight(textBox, styles, measurer, pageIndex, totalPages, defaultTabStop) {
13024
- var _a, _b, _c, _d, _e;
13025
- if (!((_a = textBox.body) == null ? void 0 : _a.autoFit)) {
13026
- return textBox.height;
13027
- }
13028
- const padding = {
13029
- left: ((_b = textBox.body) == null ? void 0 : _b.paddingLeft) ?? 0,
13030
- top: ((_c = textBox.body) == null ? void 0 : _c.paddingTop) ?? 0,
13031
- right: ((_d = textBox.body) == null ? void 0 : _d.paddingRight) ?? 0,
13032
- bottom: ((_e = textBox.body) == null ? void 0 : _e.paddingBottom) ?? 0
13033
- };
13034
- const innerWidth = Math.max(1, textBox.width - padding.left - padding.right);
13035
- const contentHeight = textBox.blocks.reduce((sum, block) => {
13036
- if (block.type === "paragraph") {
13037
- const layout = projectParagraphLayout(
13038
- block,
13039
- pageIndex,
13040
- totalPages,
13041
- styles,
13042
- innerWidth,
13043
- measurer,
13044
- defaultTabStop
13045
- );
13046
- return sum + getProjectedParagraphBlockHeight(block, layout, styles);
13617
+ track.height += measuredSegmentHeight;
13618
+ segmentIndex += 1;
13619
+ if (isLastRowSplit) {
13620
+ const lastRowIndex = rowGroups[groupEndIndex - 1].startRowIndex;
13621
+ const lastRow = sourceBlock.rows[lastRowIndex];
13622
+ const ends = splitEndPositions ?? (splitEnds == null ? void 0 : splitEnds.map((blockIndex) => ({ blockIndex }))) ?? [];
13623
+ const isFinished = positionsFinishedRow(lastRow, ends);
13624
+ if (isFinished) {
13625
+ currentCellBlockPositions = void 0;
13626
+ groupStartIndex = groupEndIndex;
13627
+ } else {
13628
+ currentCellBlockPositions = ends;
13629
+ groupStartIndex = groupEndIndex - 1;
13630
+ }
13631
+ } else {
13632
+ currentCellBlockPositions = void 0;
13633
+ groupStartIndex = groupEndIndex;
13047
13634
  }
13048
- if (block.type === "table") {
13049
- return sum + estimateTableBlockHeight(
13050
- block,
13051
- styles,
13052
- innerWidth,
13053
- measurer,
13054
- defaultTabStop
13055
- );
13635
+ if (groupStartIndex < rowGroups.length) {
13636
+ track.flush();
13056
13637
  }
13057
- return sum;
13058
- }, 0);
13059
- return Math.max(
13060
- 1,
13061
- Math.ceil(
13062
- contentHeight + padding.top + padding.bottom + TEXT_BOX_AUTOFIT_SAFETY_PX$1
13063
- )
13064
- );
13638
+ }
13065
13639
  }
13066
13640
  function projectBlocksLayout(context2) {
13067
13641
  const columns = context2.pageSettings.columns;
@@ -13075,7 +13649,7 @@ function projectBlocksLayout(context2) {
13075
13649
  return projectColumnTrackLayout(context2);
13076
13650
  }
13077
13651
  function projectColumnTrackLayout(context2) {
13078
- var _a, _b;
13652
+ var _a;
13079
13653
  const {
13080
13654
  blocks,
13081
13655
  pageSettings,
@@ -13092,565 +13666,36 @@ function projectColumnTrackLayout(context2) {
13092
13666
  contentWidthOverride
13093
13667
  } = context2;
13094
13668
  const contentWidth = contentWidthOverride ?? getPageContentWidth(pageSettings);
13095
- const pages = [...existingPages];
13096
- const currentPage = pages[pages.length - 1];
13097
- let currentBlocks = currentPage ? [...currentPage.blocks] : [];
13098
- let currentHeight = currentPage ? currentPage.height : 0;
13099
- const getCurrentPageIndex = () => pageOffset + pages.length;
13100
- const getMaxHeightForPage = (pageIndex) => Math.max(
13101
- 24,
13102
- maxPageHeight - ((reservedHeightByPageIndex == null ? void 0 : reservedHeightByPageIndex.get(pageIndex)) ?? 0)
13669
+ const track = new PaginationTrack(
13670
+ pageOffset,
13671
+ maxPageHeight,
13672
+ reservedHeightByPageIndex,
13673
+ pageSettings,
13674
+ existingPages
13103
13675
  );
13104
- if (currentPage) {
13105
- pages.pop();
13106
- }
13107
- const flushPage = () => {
13108
- if (currentBlocks.length === 0 && pages.length > 0) {
13109
- return;
13110
- }
13111
- const pageIndex = getCurrentPageIndex();
13112
- const currentMaxHeight = getMaxHeightForPage(pageIndex);
13113
- pages.push({
13114
- id: `page:${pageIndex + 1}`,
13115
- index: pageIndex,
13116
- height: currentHeight,
13117
- maxHeight: currentMaxHeight,
13118
- blocks: currentBlocks,
13119
- pageSettings
13120
- });
13121
- currentBlocks = [];
13122
- currentHeight = 0;
13676
+ const params = {
13677
+ pageSettings,
13678
+ contentWidth,
13679
+ measurer,
13680
+ styles,
13681
+ totalPages,
13682
+ defaultTabStop,
13683
+ measuredHeights,
13684
+ measuredParagraphLayouts
13123
13685
  };
13124
13686
  for (let index = 0; index < blocks.length; index += 1) {
13125
13687
  const sourceBlock = blocks[index];
13126
13688
  const nextBlock = blocks[index + 1];
13127
- if (currentBlocks.length > 0 && (sourceBlock.type === "paragraph" ? getEffectiveParagraphStyle(sourceBlock, styles).pageBreakBefore : (_a = sourceBlock.style) == null ? void 0 : _a.pageBreakBefore)) {
13128
- flushPage();
13689
+ if (track.blocks.length > 0 && (sourceBlock.type === "paragraph" ? getEffectiveParagraphStyle(sourceBlock, styles).pageBreakBefore : (_a = sourceBlock.style) == null ? void 0 : _a.pageBreakBefore)) {
13690
+ track.flush();
13129
13691
  }
13130
13692
  if (sourceBlock.type === "paragraph") {
13131
- const pageIndex = pageOffset + pages.length;
13132
- const projectedParagraphLayout = projectParagraphLayoutWithExclusions(
13133
- sourceBlock,
13134
- pageSettings,
13135
- contentWidth,
13136
- measurer,
13137
- pageIndex,
13138
- totalPages,
13139
- styles,
13140
- defaultTabStop,
13141
- (textBox) => estimateTextBoxAutoFitHeight(
13142
- textBox,
13143
- styles,
13144
- measurer,
13145
- pageIndex,
13146
- totalPages,
13147
- defaultTabStop
13148
- )
13149
- );
13150
- const measuredParagraphLayout = measuredParagraphLayouts == null ? void 0 : measuredParagraphLayouts[sourceBlock.id];
13151
- const paragraphLayout = measuredParagraphLayout && isMeasuredLayoutCurrent(
13152
- projectedParagraphLayout,
13153
- measuredParagraphLayout
13154
- ) ? applyMeasuredLineGeometry(
13155
- projectedParagraphLayout,
13156
- measuredParagraphLayout
13157
- ) : projectedParagraphLayout;
13158
- let collapseWithPrevious = false;
13159
- let contextualAdjustedPreviousBlock;
13160
- let contextualAdjustedAmount = 0;
13161
- let paragraphTotalHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? getProjectedParagraphBlockHeight(sourceBlock, paragraphLayout, styles);
13162
- const paragraphStyle = getEffectiveParagraphStyle(sourceBlock, styles);
13163
- const nextBlockHeight = (nextBlock == null ? void 0 : nextBlock.type) === "paragraph" ? (measuredHeights == null ? void 0 : measuredHeights[nextBlock.id]) ?? estimateParagraphBlockHeight(
13164
- nextBlock,
13165
- styles,
13166
- contentWidth,
13167
- measurer,
13168
- {
13169
- allowSpacingBefore: !shouldCollapseContextualSpacing(
13170
- sourceBlock,
13171
- nextBlock,
13172
- styles
13173
- )
13174
- },
13175
- defaultTabStop
13176
- ) : nextBlock ? (measuredHeights == null ? void 0 : measuredHeights[nextBlock.id]) ?? estimateTableBlockHeight(
13177
- nextBlock,
13178
- styles,
13179
- contentWidth,
13180
- measurer,
13181
- defaultTabStop
13182
- ) : 0;
13183
- if (paragraphStyle.keepWithNext && currentBlocks.length > 0 && currentHeight + paragraphTotalHeight + nextBlockHeight > getMaxHeightForPage(getCurrentPageIndex()) && paragraphTotalHeight + nextBlockHeight <= getMaxHeightForPage(getCurrentPageIndex())) {
13184
- flushPage();
13185
- }
13186
- const previousBlock = currentBlocks.at(-1);
13187
- const previousParagraph = (previousBlock == null ? void 0 : previousBlock.blockType) === "paragraph" && ((_b = previousBlock.sourceBlock) == null ? void 0 : _b.type) === "paragraph" ? previousBlock.sourceBlock : void 0;
13188
- collapseWithPrevious = currentBlocks.length > 0 && shouldCollapseContextualSpacing(previousParagraph, sourceBlock, styles);
13189
- if (collapseWithPrevious && previousBlock && previousParagraph) {
13190
- const previousStyle = getEffectiveParagraphStyle(
13191
- previousParagraph,
13192
- styles
13193
- );
13194
- const collapsedSpacingAfter = previousStyle.spacingAfter ?? 0;
13195
- if (collapsedSpacingAfter > 0) {
13196
- previousBlock.estimatedHeight = Math.max(
13197
- 0,
13198
- previousBlock.estimatedHeight - collapsedSpacingAfter
13199
- );
13200
- currentHeight = Math.max(0, currentHeight - collapsedSpacingAfter);
13201
- contextualAdjustedPreviousBlock = previousBlock;
13202
- contextualAdjustedAmount = collapsedSpacingAfter;
13203
- }
13204
- paragraphTotalHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? getProjectedParagraphBlockHeight(
13205
- sourceBlock,
13206
- paragraphLayout,
13207
- styles,
13208
- false
13209
- );
13210
- }
13211
- if (paragraphStyle.keepLinesTogether && paragraphTotalHeight <= getMaxHeightForPage(getCurrentPageIndex())) {
13212
- if (currentBlocks.length > 0 && currentHeight + paragraphTotalHeight > getMaxHeightForPage(getCurrentPageIndex())) {
13213
- flushPage();
13214
- }
13215
- const segmentId = `${sourceBlock.id}:segment:0`;
13216
- const rawMeasuredHeight = getParagraphMeasuredHeight(
13217
- measuredHeights,
13218
- sourceBlock.id,
13219
- segmentId,
13220
- true,
13221
- paragraphTotalHeight
13222
- );
13223
- const hasMeasuredHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) !== void 0 || (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) !== void 0;
13224
- const measuredHeight = collapseWithPrevious && hasMeasuredHeight ? Math.max(
13225
- 0,
13226
- rawMeasuredHeight - (paragraphStyle.spacingBefore ?? 0)
13227
- ) : rawMeasuredHeight;
13228
- currentBlocks.push({
13229
- blockId: segmentId,
13230
- sourceBlockId: sourceBlock.id,
13231
- blockType: sourceBlock.type,
13232
- paragraphId: sourceBlock.id,
13233
- globalIndex: index,
13234
- estimatedHeight: measuredHeight,
13235
- layout: paragraphLayout,
13236
- sourceBlock
13237
- });
13238
- currentHeight += measuredHeight;
13239
- continue;
13240
- }
13241
- let startLineIndex = 0;
13242
- let segmentIndex2 = 0;
13243
- while (startLineIndex < paragraphLayout.lines.length) {
13244
- const remainingHeight = getMaxHeightForPage(getCurrentPageIndex()) - currentHeight;
13245
- let lineEndIndex = startLineIndex;
13246
- let segmentHeight = 0;
13247
- while (lineEndIndex < paragraphLayout.lines.length) {
13248
- const candidateLines = paragraphLayout.lines.slice(
13249
- startLineIndex,
13250
- lineEndIndex + 1
13251
- );
13252
- const candidateHeight = getParagraphSegmentHeight(
13253
- sourceBlock,
13254
- candidateLines,
13255
- startLineIndex === 0,
13256
- lineEndIndex === paragraphLayout.lines.length - 1,
13257
- styles,
13258
- !collapseWithPrevious
13259
- );
13260
- const candidateFitHeight = getParagraphSegmentFitHeight(
13261
- sourceBlock,
13262
- candidateHeight,
13263
- lineEndIndex === paragraphLayout.lines.length - 1,
13264
- styles
13265
- );
13266
- const tolerance = 1.5;
13267
- if (candidateFitHeight > remainingHeight + tolerance && lineEndIndex === startLineIndex && currentBlocks.length > 0) {
13268
- break;
13269
- }
13270
- if (candidateFitHeight > remainingHeight + tolerance && lineEndIndex > startLineIndex) {
13271
- break;
13272
- }
13273
- segmentHeight = candidateHeight;
13274
- lineEndIndex += 1;
13275
- }
13276
- if (lineEndIndex === startLineIndex && currentBlocks.length > 0) {
13277
- if (contextualAdjustedPreviousBlock && contextualAdjustedAmount > 0) {
13278
- contextualAdjustedPreviousBlock.estimatedHeight += contextualAdjustedAmount;
13279
- currentHeight += contextualAdjustedAmount;
13280
- contextualAdjustedPreviousBlock = void 0;
13281
- contextualAdjustedAmount = 0;
13282
- }
13283
- collapseWithPrevious = false;
13284
- flushPage();
13285
- continue;
13286
- }
13287
- if (lineEndIndex === startLineIndex) {
13288
- lineEndIndex = Math.min(
13289
- paragraphLayout.lines.length,
13290
- startLineIndex + 1
13291
- );
13292
- segmentHeight = getParagraphSegmentHeight(
13293
- sourceBlock,
13294
- paragraphLayout.lines.slice(startLineIndex, lineEndIndex),
13295
- startLineIndex === 0,
13296
- lineEndIndex === paragraphLayout.lines.length,
13297
- styles,
13298
- !collapseWithPrevious
13299
- );
13300
- }
13301
- if (lineEndIndex < paragraphLayout.lines.length) {
13302
- const widowOrphanAdjusted = applyWidowOrphanControl(
13303
- sourceBlock,
13304
- paragraphLayout.lines,
13305
- startLineIndex,
13306
- lineEndIndex,
13307
- styles,
13308
- !collapseWithPrevious,
13309
- true,
13310
- currentBlocks.length > 0
13311
- );
13312
- lineEndIndex = widowOrphanAdjusted.endLineIndexExclusive;
13313
- segmentHeight = widowOrphanAdjusted.height;
13314
- if (lineEndIndex === startLineIndex) {
13315
- if (contextualAdjustedPreviousBlock && contextualAdjustedAmount > 0) {
13316
- contextualAdjustedPreviousBlock.estimatedHeight += contextualAdjustedAmount;
13317
- currentHeight += contextualAdjustedAmount;
13318
- contextualAdjustedPreviousBlock = void 0;
13319
- contextualAdjustedAmount = 0;
13320
- }
13321
- collapseWithPrevious = false;
13322
- flushPage();
13323
- continue;
13324
- }
13325
- }
13326
- const segmentLayout = createParagraphSegmentLayout(
13327
- paragraphLayout,
13328
- startLineIndex,
13329
- lineEndIndex
13330
- );
13331
- const segmentId = `${sourceBlock.id}:segment:${segmentIndex2}`;
13332
- const isWholeParagraphSegment = startLineIndex === 0 && lineEndIndex === paragraphLayout.lines.length;
13333
- const rawMeasuredHeight = getParagraphMeasuredHeight(
13334
- measuredHeights,
13335
- sourceBlock.id,
13336
- segmentId,
13337
- isWholeParagraphSegment,
13338
- segmentHeight
13339
- );
13340
- const hasMeasuredHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) !== void 0 || isWholeParagraphSegment && (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) !== void 0;
13341
- const measuredHeight = collapseWithPrevious && startLineIndex === 0 && hasMeasuredHeight ? Math.max(
13342
- 0,
13343
- rawMeasuredHeight - (paragraphStyle.spacingBefore ?? 0)
13344
- ) : rawMeasuredHeight;
13345
- currentBlocks.push({
13346
- blockId: segmentId,
13347
- sourceBlockId: sourceBlock.id,
13348
- blockType: sourceBlock.type,
13349
- paragraphId: sourceBlock.id,
13350
- globalIndex: index,
13351
- estimatedHeight: measuredHeight,
13352
- layout: segmentLayout,
13353
- sourceBlock
13354
- });
13355
- currentHeight += measuredHeight;
13356
- startLineIndex = lineEndIndex;
13357
- segmentIndex2 += 1;
13358
- if (startLineIndex < paragraphLayout.lines.length) {
13359
- flushPage();
13360
- }
13361
- }
13362
- continue;
13363
- }
13364
- const tableHeight = (measuredHeights == null ? void 0 : measuredHeights[sourceBlock.id]) ?? estimateTableBlockHeight(
13365
- sourceBlock,
13366
- styles,
13367
- contentWidth,
13368
- measurer,
13369
- defaultTabStop
13370
- );
13371
- const maxHeightForCurrentPage = getMaxHeightForPage(getCurrentPageIndex());
13372
- const firstRow = sourceBlock.rows[0];
13373
- const canSplitSingleRow = canSplitTableRow(firstRow);
13374
- if (!canSplitSingleRow && sourceBlock.rows.length <= 1 || currentHeight + tableHeight <= maxHeightForCurrentPage) {
13375
- if (currentBlocks.length > 0 && currentHeight + tableHeight > maxHeightForCurrentPage) {
13376
- flushPage();
13377
- }
13378
- currentBlocks.push({
13379
- blockId: sourceBlock.id,
13380
- sourceBlockId: sourceBlock.id,
13381
- blockType: sourceBlock.type,
13382
- globalIndex: index,
13383
- estimatedHeight: tableHeight,
13384
- sourceBlock
13385
- });
13386
- currentHeight += tableHeight;
13693
+ paginateParagraphBlock(track, params, sourceBlock, nextBlock, index);
13387
13694
  continue;
13388
13695
  }
13389
- const rowGroups = getTableRowGroups(sourceBlock);
13390
- const headerRowCount = getRepeatableHeaderRowCount(
13391
- sourceBlock,
13392
- getTableHeaderRowCount(sourceBlock),
13393
- rowGroups
13394
- );
13395
- let groupStartIndex = 0;
13396
- let segmentIndex = 0;
13397
- let currentCellBlockPositions;
13398
- while (groupStartIndex < rowGroups.length) {
13399
- const startRowIndex = rowGroups[groupStartIndex].startRowIndex;
13400
- const repeatedHeaderRowCount = startRowIndex > 0 ? headerRowCount : 0;
13401
- const remainingHeight = getMaxHeightForPage(getCurrentPageIndex()) - currentHeight;
13402
- let groupEndIndex = groupStartIndex;
13403
- let segmentHeight = 0;
13404
- let splitEnds;
13405
- let splitEndPositions;
13406
- let isLastRowSplit = false;
13407
- while (groupEndIndex < rowGroups.length) {
13408
- const candidateEndRowIndex = rowGroups[groupEndIndex].endRowIndexExclusive;
13409
- let candidateHeight = 0;
13410
- if (groupEndIndex === groupStartIndex && currentCellBlockPositions) {
13411
- const firstRow2 = sourceBlock.rows[startRowIndex];
13412
- const starts = normalizeCellStartPositions(
13413
- firstRow2,
13414
- currentCellBlockPositions,
13415
- void 0
13416
- );
13417
- const ends = firstRow2.cells.map((cell) => ({
13418
- blockIndex: cell.blocks.length
13419
- }));
13420
- const slicedFirstRow = buildRowSliceFromPositions(
13421
- firstRow2,
13422
- starts,
13423
- ends
13424
- );
13425
- candidateHeight = getTableSegmentHeight(
13426
- {
13427
- ...sourceBlock,
13428
- rows: [slicedFirstRow]
13429
- },
13430
- 0,
13431
- 1,
13432
- repeatedHeaderRowCount,
13433
- styles,
13434
- contentWidth,
13435
- measurer,
13436
- defaultTabStop
13437
- );
13438
- } else {
13439
- candidateHeight = getTableSegmentHeight(
13440
- sourceBlock,
13441
- startRowIndex,
13442
- candidateEndRowIndex,
13443
- repeatedHeaderRowCount,
13444
- styles,
13445
- contentWidth,
13446
- measurer,
13447
- defaultTabStop
13448
- );
13449
- }
13450
- if (candidateHeight <= remainingHeight) {
13451
- segmentHeight = candidateHeight;
13452
- groupEndIndex += 1;
13453
- continue;
13454
- }
13455
- const isSingleRowGroup = candidateEndRowIndex === rowGroups[groupEndIndex].startRowIndex + 1;
13456
- const targetRow = sourceBlock.rows[rowGroups[groupEndIndex].startRowIndex];
13457
- const isSplitCandidate = isSingleRowGroup && canSplitTableRow(targetRow);
13458
- if (isSplitCandidate) {
13459
- const precedingHeight = groupEndIndex > groupStartIndex ? getTableSegmentHeight(
13460
- sourceBlock,
13461
- startRowIndex,
13462
- rowGroups[groupEndIndex].startRowIndex,
13463
- repeatedHeaderRowCount,
13464
- styles,
13465
- contentWidth,
13466
- measurer,
13467
- defaultTabStop
13468
- ) : 0;
13469
- const availableForSplitRow = remainingHeight - precedingHeight;
13470
- if (availableForSplitRow > 0) {
13471
- const starts = normalizeCellStartPositions(
13472
- targetRow,
13473
- groupEndIndex === groupStartIndex ? currentCellBlockPositions : void 0,
13474
- void 0
13475
- );
13476
- const ends = targetRow.cells.map(
13477
- (_, cellIdx) => findCellSplitEndPosition(
13478
- targetRow,
13479
- cellIdx,
13480
- starts[cellIdx] ?? { blockIndex: 0 },
13481
- availableForSplitRow,
13482
- styles,
13483
- measurer,
13484
- defaultTabStop,
13485
- contentWidth,
13486
- sourceBlock,
13487
- rowGroups[groupEndIndex].startRowIndex
13488
- )
13489
- );
13490
- const canProgress = positionsProgressed(starts, ends);
13491
- if (canProgress) {
13492
- splitEnds = positionsToBlockIndexes(ends);
13493
- isLastRowSplit = true;
13494
- const slicedLastRow = buildRowSliceFromPositions(
13495
- targetRow,
13496
- starts,
13497
- ends
13498
- );
13499
- const segmentRows = [
13500
- ...sourceBlock.rows.slice(
13501
- startRowIndex,
13502
- rowGroups[groupEndIndex].startRowIndex
13503
- ),
13504
- slicedLastRow
13505
- ];
13506
- segmentHeight = getTableSegmentHeight(
13507
- { ...sourceBlock, rows: segmentRows },
13508
- 0,
13509
- segmentRows.length,
13510
- repeatedHeaderRowCount,
13511
- styles,
13512
- contentWidth,
13513
- measurer,
13514
- defaultTabStop
13515
- );
13516
- splitEndPositions = ends;
13517
- groupEndIndex += 1;
13518
- break;
13519
- }
13520
- }
13521
- }
13522
- break;
13523
- }
13524
- if (groupEndIndex === groupStartIndex && currentBlocks.length > 0) {
13525
- flushPage();
13526
- continue;
13527
- }
13528
- if (groupEndIndex === groupStartIndex) {
13529
- const targetRow = sourceBlock.rows[startRowIndex];
13530
- const isSingleRowGroup = rowGroups[groupStartIndex].endRowIndexExclusive === startRowIndex + 1;
13531
- const isSplitCandidate = isSingleRowGroup && canSplitTableRow(targetRow);
13532
- if (isSplitCandidate) {
13533
- const starts = normalizeCellStartPositions(
13534
- targetRow,
13535
- currentCellBlockPositions,
13536
- void 0
13537
- );
13538
- let ends = starts.map(
13539
- (start, cellIdx) => findCellSplitEndPosition(
13540
- targetRow,
13541
- cellIdx,
13542
- start,
13543
- getMaxHeightForPage(getCurrentPageIndex()),
13544
- styles,
13545
- measurer,
13546
- defaultTabStop,
13547
- contentWidth,
13548
- sourceBlock,
13549
- startRowIndex
13550
- )
13551
- );
13552
- if (!positionsProgressed(starts, ends)) {
13553
- ends = starts.map((start, cellIdx) => ({
13554
- blockIndex: Math.min(
13555
- targetRow.cells[cellIdx].blocks.length,
13556
- start.blockIndex + 1
13557
- )
13558
- }));
13559
- }
13560
- splitEnds = positionsToBlockIndexes(ends);
13561
- splitEndPositions = ends;
13562
- isLastRowSplit = true;
13563
- const slicedLastRow = buildRowSliceFromPositions(
13564
- targetRow,
13565
- starts,
13566
- ends
13567
- );
13568
- segmentHeight = getTableSegmentHeight(
13569
- { ...sourceBlock, rows: [slicedLastRow] },
13570
- 0,
13571
- 1,
13572
- repeatedHeaderRowCount,
13573
- styles,
13574
- contentWidth,
13575
- measurer,
13576
- defaultTabStop
13577
- );
13578
- groupEndIndex += 1;
13579
- } else {
13580
- groupEndIndex = rowGroups[groupStartIndex].endRowIndexExclusive;
13581
- segmentHeight = getTableSegmentHeight(
13582
- sourceBlock,
13583
- startRowIndex,
13584
- groupEndIndex,
13585
- repeatedHeaderRowCount,
13586
- styles,
13587
- contentWidth,
13588
- measurer,
13589
- defaultTabStop
13590
- );
13591
- }
13592
- }
13593
- const segmentId = `${sourceBlock.id}:segment:${segmentIndex}`;
13594
- const measuredSegmentHeight = (measuredHeights == null ? void 0 : measuredHeights[segmentId]) ?? segmentHeight;
13595
- const endRowIndex = rowGroups[groupEndIndex - 1].endRowIndexExclusive;
13596
- currentBlocks.push({
13597
- blockId: segmentId,
13598
- sourceBlockId: sourceBlock.id,
13599
- blockType: sourceBlock.type,
13600
- globalIndex: index,
13601
- estimatedHeight: measuredSegmentHeight,
13602
- tableSegment: {
13603
- startRowIndex,
13604
- endRowIndex,
13605
- repeatedHeaderRowCount,
13606
- startRowCellBlockStarts: positionsToBlockIndexes(
13607
- currentCellBlockPositions
13608
- ),
13609
- endRowCellBlockEnds: splitEnds,
13610
- startRowCellBlockPositions: hasPartialPositions(
13611
- currentCellBlockPositions
13612
- ) ? currentCellBlockPositions : void 0,
13613
- endRowCellBlockPositions: hasPartialPositions(splitEndPositions) ? splitEndPositions : void 0
13614
- },
13615
- sourceBlock
13616
- });
13617
- currentHeight += measuredSegmentHeight;
13618
- segmentIndex += 1;
13619
- if (isLastRowSplit) {
13620
- const lastRowIndex = rowGroups[groupEndIndex - 1].startRowIndex;
13621
- const lastRow = sourceBlock.rows[lastRowIndex];
13622
- const ends = splitEndPositions ?? (splitEnds == null ? void 0 : splitEnds.map((blockIndex) => ({ blockIndex }))) ?? [];
13623
- const isFinished = positionsFinishedRow(lastRow, ends);
13624
- if (isFinished) {
13625
- currentCellBlockPositions = void 0;
13626
- groupStartIndex = groupEndIndex;
13627
- } else {
13628
- currentCellBlockPositions = ends;
13629
- groupStartIndex = groupEndIndex - 1;
13630
- }
13631
- } else {
13632
- currentCellBlockPositions = void 0;
13633
- groupStartIndex = groupEndIndex;
13634
- }
13635
- if (groupStartIndex < rowGroups.length) {
13636
- flushPage();
13637
- }
13638
- }
13639
- }
13640
- flushPage();
13641
- if (pages.length === 0) {
13642
- const pageIndex = pageOffset;
13643
- const currentMaxHeight = getMaxHeightForPage(pageIndex);
13644
- pages.push({
13645
- id: `page:${pageIndex + 1}`,
13646
- index: pageIndex,
13647
- height: 0,
13648
- maxHeight: currentMaxHeight,
13649
- blocks: [],
13650
- pageSettings
13651
- });
13696
+ paginateTableBlock(track, params, sourceBlock, index);
13652
13697
  }
13653
- return pages;
13698
+ return track.finalize();
13654
13699
  }
13655
13700
  function getProjectedBlocksHeight(blocks) {
13656
13701
  if (!blocks || blocks.length === 0) {