@superdoc-dev/cli 0.8.0-next.72 → 0.8.0-next.73

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 +692 -149
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -65823,7 +65823,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
65823
65823
  emptyOptions2 = {};
65824
65824
  });
65825
65825
 
65826
- // ../../packages/superdoc/dist/chunks/SuperConverter-DFi0X147.es.js
65826
+ // ../../packages/superdoc/dist/chunks/SuperConverter-ing-1fvK.es.js
65827
65827
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
65828
65828
  const fieldValue = extension$1.config[field];
65829
65829
  if (typeof fieldValue === "function")
@@ -96179,6 +96179,9 @@ function extractSectionType(elements) {
96179
96179
  return val;
96180
96180
  return "nextPage";
96181
96181
  }
96182
+ function extractSectionTypeIsExplicit(elements) {
96183
+ return elements.some((el) => el?.name === "w:type");
96184
+ }
96182
96185
  function extractPageSizeAndOrientation(elements) {
96183
96186
  const pgSz = elements.find((el) => el?.name === "w:pgSz");
96184
96187
  if (!pgSz?.attributes)
@@ -96289,6 +96292,7 @@ function extractSectionData(para) {
96289
96292
  footerPx
96290
96293
  };
96291
96294
  const type = extractSectionType(sectPrElements);
96295
+ const typeIsExplicit = extractSectionTypeIsExplicit(sectPrElements);
96292
96296
  const { pageSizePx, orientation } = extractPageSizeAndOrientation(sectPrElements);
96293
96297
  const titlePg = sectPrElements.some((el) => el?.name === "w:titlePg");
96294
96298
  const fallbackMargins = extractFallbackMargins(sectPrElements, headerPx, footerPx);
@@ -96308,6 +96312,7 @@ function extractSectionData(para) {
96308
96312
  bottomPx,
96309
96313
  leftPx,
96310
96314
  type,
96315
+ typeIsExplicit,
96311
96316
  pageSizePx,
96312
96317
  orientation,
96313
96318
  columnsPx,
@@ -96351,6 +96356,7 @@ function createSectionBreakBlock(section, blockIdGen, extraAttrs) {
96351
96356
  attrs: {
96352
96357
  source: "sectPr",
96353
96358
  sectionIndex: section.sectionIndex,
96359
+ ...section.typeIsExplicit ? { typeIsExplicit: true } : {},
96354
96360
  ...extraAttrs
96355
96361
  },
96356
96362
  ...section.pageSize && { pageSize: section.pageSize },
@@ -96376,6 +96382,21 @@ function shouldRequirePageBoundary(current, next) {
96376
96382
  function hasIntrinsicBoundarySignals(_) {
96377
96383
  return false;
96378
96384
  }
96385
+ function maybeEmitNextSectionBreakForNode(args2) {
96386
+ const { sectionState, nextBlockId, pushBlock } = args2;
96387
+ if (sectionState.ranges.length === 0)
96388
+ return;
96389
+ if (sectionState.currentSectionIndex >= sectionState.ranges.length - 1)
96390
+ return;
96391
+ const nextSection = sectionState.ranges[sectionState.currentSectionIndex + 1];
96392
+ if (!nextSection)
96393
+ return;
96394
+ if (sectionState.currentNodeIndex !== nextSection.startNodeIndex)
96395
+ return;
96396
+ const currentSection = sectionState.ranges[sectionState.currentSectionIndex];
96397
+ pushBlock(createSectionBreakBlock(nextSection, nextBlockId, shouldRequirePageBoundary(currentSection, nextSection) || hasIntrinsicBoundarySignals(nextSection) ? { requirePageBoundary: true } : undefined));
96398
+ sectionState.currentSectionIndex++;
96399
+ }
96379
96400
  function emitPendingSectionBreakForParagraph(args2) {
96380
96401
  const { sectionState, nextBlockId, blocks, recordBlockKind } = args2;
96381
96402
  if (!sectionState || sectionState.ranges.length === 0)
@@ -96409,6 +96430,7 @@ function shouldIgnoreSectionBreak(paragraph2, index2, total, hasBodySectPr) {
96409
96430
  function findParagraphsWithSectPr(doc$2) {
96410
96431
  const paragraphs = [];
96411
96432
  let paragraphIndex = 0;
96433
+ let nodeIndex = 0;
96412
96434
  const getNodeChildren = (node3) => {
96413
96435
  if (Array.isArray(node3.content))
96414
96436
  return node3.content;
@@ -96422,30 +96444,35 @@ function findParagraphsWithSectPr(doc$2) {
96422
96444
  }
96423
96445
  return [];
96424
96446
  };
96425
- const visitNode = (node3) => {
96447
+ const visitNode = (node3, outerNodeIndex) => {
96426
96448
  if (node3.type === "paragraph") {
96427
96449
  if (hasSectPr(node3))
96428
96450
  paragraphs.push({
96429
96451
  index: paragraphIndex,
96452
+ nodeIndex: outerNodeIndex,
96430
96453
  node: node3
96431
96454
  });
96432
96455
  paragraphIndex++;
96433
96456
  return;
96434
96457
  }
96435
96458
  if (node3.type === "index" || node3.type === "bibliography" || node3.type === "tableOfAuthorities" || node3.type === "documentPartObject" || node3.type === "tableOfContents")
96436
- getNodeChildren(node3).forEach(visitNode);
96459
+ getNodeChildren(node3).forEach((child) => visitNode(child, outerNodeIndex));
96437
96460
  };
96438
96461
  if (doc$2.content)
96439
- for (const node3 of doc$2.content)
96440
- visitNode(node3);
96462
+ for (const node3 of doc$2.content) {
96463
+ visitNode(node3, nodeIndex);
96464
+ nodeIndex++;
96465
+ }
96441
96466
  return {
96442
96467
  paragraphs,
96443
- totalCount: paragraphIndex
96468
+ totalCount: paragraphIndex,
96469
+ totalNodeCount: nodeIndex
96444
96470
  };
96445
96471
  }
96446
96472
  function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
96447
96473
  const ranges = [];
96448
96474
  let currentStart = 0;
96475
+ let currentStartNode = 0;
96449
96476
  paragraphs.forEach((item, idx) => {
96450
96477
  if (shouldIgnoreSectionBreak(item.node, idx, paragraphs.length, hasBodySectPr))
96451
96478
  return;
@@ -96456,6 +96483,8 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
96456
96483
  const hasAnyMargin = sectionData.headerPx != null || sectionData.footerPx != null || sectionData.topPx != null || sectionData.rightPx != null || sectionData.bottomPx != null || sectionData.leftPx != null;
96457
96484
  const range = {
96458
96485
  sectionIndex: idx,
96486
+ startNodeIndex: currentStartNode,
96487
+ endNodeIndex: item.nodeIndex,
96459
96488
  startParagraphIndex: currentStart,
96460
96489
  endParagraphIndex: item.index,
96461
96490
  sectPr,
@@ -96471,6 +96500,7 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
96471
96500
  orientation: sectionData.orientation ?? null,
96472
96501
  columns: sectionData.columnsPx ?? null,
96473
96502
  type: sectionData.type ?? DEFAULT_PARAGRAPH_SECTION_TYPE,
96503
+ typeIsExplicit: sectionData.typeIsExplicit ?? false,
96474
96504
  titlePg: sectionData.titlePg ?? false,
96475
96505
  headerRefs: sectionData.headerRefs,
96476
96506
  footerRefs: sectionData.footerRefs,
@@ -96479,6 +96509,7 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
96479
96509
  };
96480
96510
  ranges.push(range);
96481
96511
  currentStart = item.index + 1;
96512
+ currentStartNode = item.nodeIndex + 1;
96482
96513
  });
96483
96514
  return ranges;
96484
96515
  }
@@ -96499,7 +96530,7 @@ function publishSectionMetadata(sectionRanges, options) {
96499
96530
  });
96500
96531
  });
96501
96532
  }
96502
- function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagraphs, sectionIndex) {
96533
+ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagraphs, sectionIndex, nodeBounds) {
96503
96534
  const clampedStart = Math.max(0, Math.min(currentStart, Math.max(totalParagraphs - 1, 0)));
96504
96535
  const bodySectionData = extractSectionData({
96505
96536
  type: "paragraph",
@@ -96508,8 +96539,12 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
96508
96539
  if (!bodySectionData)
96509
96540
  return null;
96510
96541
  const hasAnyMargin = bodySectionData.headerPx != null || bodySectionData.footerPx != null || bodySectionData.topPx != null || bodySectionData.rightPx != null || bodySectionData.bottomPx != null || bodySectionData.leftPx != null;
96542
+ const totalNodes = nodeBounds?.totalNodeCount ?? totalParagraphs;
96543
+ const startNodeIndex = nodeBounds ? Math.max(0, Math.min(nodeBounds.startNodeIndex, Math.max(totalNodes - 1, 0))) : clampedStart;
96511
96544
  return {
96512
96545
  sectionIndex,
96546
+ startNodeIndex,
96547
+ endNodeIndex: Math.max(startNodeIndex, totalNodes - 1),
96513
96548
  startParagraphIndex: clampedStart,
96514
96549
  endParagraphIndex: totalParagraphs - 1,
96515
96550
  sectPr: bodySectPr,
@@ -96525,6 +96560,7 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
96525
96560
  orientation: bodySectionData.orientation ?? null,
96526
96561
  columns: bodySectionData.columnsPx ?? null,
96527
96562
  type: bodySectionData.type ?? DEFAULT_BODY_SECTION_TYPE,
96563
+ typeIsExplicit: bodySectionData.typeIsExplicit ?? false,
96528
96564
  titlePg: bodySectionData.titlePg ?? false,
96529
96565
  headerRefs: bodySectionData.headerRefs,
96530
96566
  footerRefs: bodySectionData.footerRefs,
@@ -96532,9 +96568,13 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
96532
96568
  vAlign: bodySectionData.vAlign
96533
96569
  };
96534
96570
  }
96535
- function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex) {
96571
+ function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex, nodeBounds) {
96572
+ const totalNodes = nodeBounds?.totalNodeCount ?? totalParagraphs;
96573
+ const startNodeIndex = nodeBounds?.startNodeIndex ?? currentStart;
96536
96574
  return {
96537
96575
  sectionIndex,
96576
+ startNodeIndex,
96577
+ endNodeIndex: Math.max(startNodeIndex, totalNodes - 1),
96538
96578
  startParagraphIndex: currentStart,
96539
96579
  endParagraphIndex: totalParagraphs - 1,
96540
96580
  sectPr: null,
@@ -96543,21 +96583,30 @@ function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex)
96543
96583
  orientation: null,
96544
96584
  columns: null,
96545
96585
  type: DEFAULT_BODY_SECTION_TYPE,
96586
+ typeIsExplicit: false,
96546
96587
  titlePg: false,
96547
96588
  headerRefs: undefined,
96548
96589
  footerRefs: undefined
96549
96590
  };
96550
96591
  }
96551
96592
  function analyzeSectionRanges(doc$2, bodySectPr) {
96552
- const { paragraphs, totalCount } = findParagraphsWithSectPr(doc$2);
96593
+ const { paragraphs, totalCount, totalNodeCount } = findParagraphsWithSectPr(doc$2);
96553
96594
  const ranges = buildSectionRangesFromParagraphs(paragraphs, Boolean(bodySectPr));
96554
- const currentStart = ranges.length > 0 ? ranges[ranges.length - 1].endParagraphIndex + 1 : 0;
96595
+ const last2 = ranges[ranges.length - 1];
96596
+ const currentStart = last2 ? last2.endParagraphIndex + 1 : 0;
96597
+ const currentStartNode = last2 ? last2.endNodeIndex + 1 : 0;
96555
96598
  if (isSectPrElement$1(bodySectPr)) {
96556
- const finalSection = createFinalSectionFromBodySectPr(bodySectPr, Math.min(currentStart, totalCount), totalCount, ranges.length);
96599
+ const finalSection = createFinalSectionFromBodySectPr(bodySectPr, Math.min(currentStart, totalCount), totalCount, ranges.length, {
96600
+ startNodeIndex: Math.min(currentStartNode, totalNodeCount),
96601
+ totalNodeCount
96602
+ });
96557
96603
  if (finalSection)
96558
96604
  ranges.push(finalSection);
96559
96605
  } else if (ranges.length > 0) {
96560
- const fallbackFinal = createDefaultFinalSection(Math.min(currentStart, totalCount), totalCount, ranges.length);
96606
+ const fallbackFinal = createDefaultFinalSection(Math.min(currentStart, totalCount), totalCount, ranges.length, {
96607
+ startNodeIndex: Math.min(currentStartNode, totalNodeCount),
96608
+ totalNodeCount
96609
+ });
96561
96610
  if (fallbackFinal) {
96562
96611
  fallbackFinal.type = DEFAULT_PARAGRAPH_SECTION_TYPE;
96563
96612
  ranges.push(fallbackFinal);
@@ -98135,16 +98184,20 @@ function readOddEvenHeadersFlag(editor) {
98135
98184
  return settingsRoot.elements.some((entry) => entry.name === "w:evenAndOddHeaders");
98136
98185
  }
98137
98186
  function createSyntheticRange(bodySectPr, paragraphCount) {
98187
+ const lastIndex = Math.max(paragraphCount - 1, 0);
98138
98188
  return {
98139
98189
  sectionIndex: 0,
98190
+ startNodeIndex: 0,
98191
+ endNodeIndex: lastIndex,
98140
98192
  startParagraphIndex: 0,
98141
- endParagraphIndex: Math.max(paragraphCount - 1, 0),
98193
+ endParagraphIndex: lastIndex,
98142
98194
  sectPr: bodySectPr ?? null,
98143
98195
  margins: null,
98144
98196
  pageSize: null,
98145
98197
  orientation: null,
98146
98198
  columns: null,
98147
98199
  type: SectionType.CONTINUOUS,
98200
+ typeIsExplicit: false,
98148
98201
  titlePg: false,
98149
98202
  headerRefs: undefined,
98150
98203
  footerRefs: undefined,
@@ -118340,7 +118393,7 @@ var isRegExp = (value) => {
118340
118393
  state.kern = kernNode.attributes["w:val"];
118341
118394
  }
118342
118395
  }, SuperConverter;
118343
- var init_SuperConverter_DFi0X147_es = __esm(() => {
118396
+ var init_SuperConverter_ing_1fvK_es = __esm(() => {
118344
118397
  init_rolldown_runtime_Bg48TavK_es();
118345
118398
  init_jszip_C49i9kUs_es();
118346
118399
  init_xml_js_CqGKpaft_es();
@@ -155941,7 +155994,7 @@ var init_SuperConverter_DFi0X147_es = __esm(() => {
155941
155994
  };
155942
155995
  });
155943
155996
 
155944
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-C9nvGdZQ.es.js
155997
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-B_1fvPL0.es.js
155945
155998
  function parseSizeUnit(val = "0") {
155946
155999
  const length3 = val.toString() || "0";
155947
156000
  const value = Number.parseFloat(length3);
@@ -158577,8 +158630,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
158577
158630
  }
158578
158631
  };
158579
158632
  };
158580
- var init_create_headless_toolbar_C9nvGdZQ_es = __esm(() => {
158581
- init_SuperConverter_DFi0X147_es();
158633
+ var init_create_headless_toolbar_B_1fvPL0_es = __esm(() => {
158634
+ init_SuperConverter_ing_1fvK_es();
158582
158635
  init_constants_DrU4EASo_es();
158583
158636
  init_dist_B8HfvhaK_es();
158584
158637
  CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
@@ -207264,7 +207317,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
207264
207317
  init_remark_gfm_BhnWr3yf_es();
207265
207318
  });
207266
207319
 
207267
- // ../../packages/superdoc/dist/chunks/src-JQdl170N.es.js
207320
+ // ../../packages/superdoc/dist/chunks/src-4bO9QmBD.es.js
207268
207321
  function deleteProps(obj, propOrProps) {
207269
207322
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
207270
207323
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -253702,7 +253755,8 @@ function toFlowBlocks(pmDoc, options) {
253702
253755
  sectionState: {
253703
253756
  ranges: sectionRanges,
253704
253757
  currentSectionIndex: 0,
253705
- currentParagraphIndex: 0
253758
+ currentParagraphIndex: 0,
253759
+ currentNodeIndex: 0
253706
253760
  },
253707
253761
  converters,
253708
253762
  themeColors,
@@ -253711,9 +253765,18 @@ function toFlowBlocks(pmDoc, options) {
253711
253765
  trackedListLastOrdinals: /* @__PURE__ */ new Map
253712
253766
  };
253713
253767
  doc$12.content.forEach((node3) => {
253768
+ maybeEmitNextSectionBreakForNode({
253769
+ sectionState: handlerContext.sectionState,
253770
+ nextBlockId,
253771
+ pushBlock: (block) => {
253772
+ blocks2.push(block);
253773
+ recordBlockKind(block.kind);
253774
+ }
253775
+ });
253714
253776
  const handler2 = nodeHandlers2[node3.type];
253715
253777
  if (handler2)
253716
253778
  handler2(node3, handlerContext);
253779
+ handlerContext.sectionState.currentNodeIndex++;
253717
253780
  });
253718
253781
  if (sectionRanges.length > 0) {
253719
253782
  const lastSectionIndex = sectionRanges.length - 1;
@@ -256201,6 +256264,167 @@ function computeDisplayPageNumber(pages, sections) {
256201
256264
  }
256202
256265
  return result;
256203
256266
  }
256267
+ function calculateBalancedColumnHeight(ctx$1, config2 = DEFAULT_BALANCING_CONFIG) {
256268
+ if (ctx$1.columnCount <= 1)
256269
+ return createSingleColumnResult(ctx$1);
256270
+ if (ctx$1.contentBlocks.length === 0)
256271
+ return {
256272
+ targetColumnHeight: 0,
256273
+ columnAssignments: /* @__PURE__ */ new Map,
256274
+ success: true,
256275
+ iterations: 0
256276
+ };
256277
+ const totalHeight = ctx$1.contentBlocks.reduce((sum, b$1) => sum + b$1.measuredHeight, 0);
256278
+ const maxBlockHeight = ctx$1.contentBlocks.reduce((m$1, b$1) => Math.max(m$1, b$1.measuredHeight), 0);
256279
+ if (totalHeight < config2.minColumnHeight * ctx$1.columnCount)
256280
+ return createSingleColumnResult(ctx$1);
256281
+ let lo = Math.max(maxBlockHeight, config2.minColumnHeight);
256282
+ let hi = Math.min(totalHeight, ctx$1.availableHeight);
256283
+ if (lo > hi)
256284
+ lo = hi;
256285
+ let bestResult = null;
256286
+ let bestH = hi;
256287
+ let iterations = 0;
256288
+ while (lo <= hi) {
256289
+ iterations++;
256290
+ const mid = Math.floor((lo + hi) / 2);
256291
+ const sim = simulateBalancedLayout(ctx$1, mid, config2);
256292
+ const maxCol = Math.max(...sim.columnHeights);
256293
+ if (sim.assignments.size === ctx$1.contentBlocks.length && maxCol <= mid) {
256294
+ bestResult = sim;
256295
+ bestH = mid;
256296
+ hi = mid - 1;
256297
+ } else
256298
+ lo = mid + 1;
256299
+ if (iterations >= config2.maxIterations)
256300
+ break;
256301
+ }
256302
+ if (bestResult)
256303
+ return {
256304
+ targetColumnHeight: bestH,
256305
+ columnAssignments: bestResult.assignments,
256306
+ success: true,
256307
+ iterations,
256308
+ blockBreakPoints: bestResult.breakPoints.size > 0 ? bestResult.breakPoints : undefined
256309
+ };
256310
+ return createSequentialResult(ctx$1);
256311
+ }
256312
+ function simulateBalancedLayout(ctx$1, targetHeight, config2) {
256313
+ const assignments = /* @__PURE__ */ new Map;
256314
+ const breakPoints = /* @__PURE__ */ new Map;
256315
+ const columnHeights = new Array(ctx$1.columnCount).fill(0);
256316
+ let currentColumn = 0;
256317
+ for (let i4 = 0;i4 < ctx$1.contentBlocks.length; i4++) {
256318
+ const block = ctx$1.contentBlocks[i4];
256319
+ const nextBlock = ctx$1.contentBlocks[i4 + 1];
256320
+ if (columnHeights[currentColumn] + block.measuredHeight > targetHeight && currentColumn < ctx$1.columnCount - 1) {
256321
+ if (block.keepWithNext && nextBlock) {
256322
+ const combinedHeight = block.measuredHeight + nextBlock.measuredHeight;
256323
+ if (columnHeights[currentColumn] + combinedHeight <= targetHeight) {
256324
+ assignments.set(block.blockId, currentColumn);
256325
+ columnHeights[currentColumn] += block.measuredHeight;
256326
+ continue;
256327
+ }
256328
+ }
256329
+ if (block.canBreak && block.lineHeights && block.lineHeights.length > 1) {
256330
+ const breakPoint = calculateParagraphBreakPoint(block, targetHeight - columnHeights[currentColumn], block.orphanLines ?? 1, block.widowLines ?? 1);
256331
+ if (breakPoint.canBreak && breakPoint.breakAfterLine >= 0) {
256332
+ const heightBefore = block.lineHeights.slice(0, breakPoint.breakAfterLine + 1).reduce((sum, h$2) => sum + h$2, 0);
256333
+ const heightAfter = block.measuredHeight - heightBefore;
256334
+ breakPoints.set(block.blockId, {
256335
+ blockId: block.blockId,
256336
+ breakAfterLine: breakPoint.breakAfterLine,
256337
+ heightBeforeBreak: heightBefore,
256338
+ heightAfterBreak: heightAfter
256339
+ });
256340
+ assignments.set(block.blockId, currentColumn);
256341
+ columnHeights[currentColumn] += heightBefore;
256342
+ currentColumn++;
256343
+ columnHeights[currentColumn] += heightAfter;
256344
+ continue;
256345
+ }
256346
+ }
256347
+ currentColumn++;
256348
+ }
256349
+ assignments.set(block.blockId, currentColumn);
256350
+ columnHeights[currentColumn] += block.measuredHeight;
256351
+ }
256352
+ return {
256353
+ assignments,
256354
+ columnHeights,
256355
+ hasOverflow: columnHeights.some((h$2) => h$2 > ctx$1.availableHeight),
256356
+ breakPoints
256357
+ };
256358
+ }
256359
+ function calculateParagraphBreakPoint(block, availableHeight, orphanLines, widowLines) {
256360
+ if (!block.lineHeights || block.lineHeights.length === 0)
256361
+ return {
256362
+ breakAfterLine: -1,
256363
+ canBreak: false
256364
+ };
256365
+ const lines = block.lineHeights;
256366
+ let heightSoFar = 0;
256367
+ for (let i4 = 0;i4 < lines.length; i4++) {
256368
+ heightSoFar += lines[i4];
256369
+ if (heightSoFar > availableHeight) {
256370
+ const linesBeforeBreak = i4;
256371
+ const linesAfterBreak = lines.length - i4;
256372
+ if (linesAfterBreak < widowLines) {
256373
+ const adjustedBreak = Math.max(0, i4 - (widowLines - linesAfterBreak));
256374
+ if (adjustedBreak < orphanLines)
256375
+ return {
256376
+ breakAfterLine: -1,
256377
+ canBreak: false
256378
+ };
256379
+ return {
256380
+ breakAfterLine: adjustedBreak - 1,
256381
+ canBreak: true
256382
+ };
256383
+ }
256384
+ if (linesBeforeBreak < orphanLines)
256385
+ return {
256386
+ breakAfterLine: -1,
256387
+ canBreak: false
256388
+ };
256389
+ return {
256390
+ breakAfterLine: i4 - 1,
256391
+ canBreak: true
256392
+ };
256393
+ }
256394
+ }
256395
+ return {
256396
+ breakAfterLine: lines.length - 1,
256397
+ canBreak: true
256398
+ };
256399
+ }
256400
+ function createSingleColumnResult(ctx$1) {
256401
+ const assignments = /* @__PURE__ */ new Map;
256402
+ for (const block of ctx$1.contentBlocks)
256403
+ assignments.set(block.blockId, 0);
256404
+ return {
256405
+ targetColumnHeight: ctx$1.availableHeight,
256406
+ columnAssignments: assignments,
256407
+ success: true,
256408
+ iterations: 0
256409
+ };
256410
+ }
256411
+ function createSequentialResult(ctx$1) {
256412
+ const assignments = /* @__PURE__ */ new Map;
256413
+ const columnHeights = new Array(ctx$1.columnCount).fill(0);
256414
+ let currentColumn = 0;
256415
+ for (const block of ctx$1.contentBlocks) {
256416
+ if (columnHeights[currentColumn] + block.measuredHeight > ctx$1.availableHeight && currentColumn < ctx$1.columnCount - 1)
256417
+ currentColumn++;
256418
+ assignments.set(block.blockId, currentColumn);
256419
+ columnHeights[currentColumn] += block.measuredHeight;
256420
+ }
256421
+ return {
256422
+ targetColumnHeight: Math.max(...columnHeights),
256423
+ columnAssignments: assignments,
256424
+ success: false,
256425
+ iterations: 0
256426
+ };
256427
+ }
256204
256428
  function shouldSkipBalancing(ctx$1, config2 = DEFAULT_BALANCING_CONFIG) {
256205
256429
  if (!config2.enabled)
256206
256430
  return true;
@@ -256232,76 +256456,211 @@ function getFragmentHeight(fragment2, measureMap) {
256232
256456
  return sum;
256233
256457
  }
256234
256458
  if (fragment2.kind === "image" || fragment2.kind === "drawing" || fragment2.kind === "table") {
256235
- if (typeof fragment2.height === "number")
256459
+ if (typeof fragment2.height === "number" && fragment2.height > 0)
256236
256460
  return fragment2.height;
256237
256461
  const measure = measureMap.get(fragment2.blockId);
256238
- if (measure && typeof measure.height === "number")
256239
- return measure.height;
256462
+ if (measure) {
256463
+ if (typeof measure.height === "number" && measure.height > 0)
256464
+ return measure.height;
256465
+ if (fragment2.kind === "table" && typeof measure.totalHeight === "number")
256466
+ return measure.totalHeight;
256467
+ }
256468
+ if (typeof fragment2.height === "number")
256469
+ return fragment2.height;
256240
256470
  }
256241
256471
  return 0;
256242
256472
  }
256243
- function balancePageColumns(fragments, columns, margins, topMargin, availableHeight, measureMap) {
256244
- if (columns.count <= 1 || fragments.length === 0)
256245
- return;
256246
- const columnX = (columnIndex) => {
256247
- return margins.left + columnIndex * (columns.width + columns.gap);
256248
- };
256249
- const rowMap = /* @__PURE__ */ new Map;
256250
- fragments.forEach((fragment2, idx) => {
256251
- const y$1 = Math.round(fragment2.y);
256252
- if (!rowMap.has(y$1))
256253
- rowMap.set(y$1, []);
256254
- const height = getFragmentHeight(fragment2, measureMap);
256255
- rowMap.get(y$1).push({
256256
- fragment: fragment2,
256257
- height,
256258
- originalIndex: idx
256259
- });
256260
- });
256261
- const sortedRows = [...rowMap.entries()].sort((a2, b$1) => a2[0] - b$1[0]);
256262
- let totalHeight = 0;
256263
- const contentBlocks = [];
256264
- for (const [, rowFragments] of sortedRows) {
256265
- const maxHeight = Math.max(...rowFragments.map((f2) => f2.height));
256266
- totalHeight += maxHeight;
256267
- contentBlocks.push({
256268
- blockId: rowFragments[0]?.fragment.blockId ?? `row-${contentBlocks.length}`,
256269
- measuredHeight: maxHeight,
256270
- canBreak: false,
256271
- keepWithNext: false,
256272
- keepTogether: true
256273
- });
256473
+ function getBalancingHeight(fragment2, measureMap, sectPrMarkerBlockIds) {
256474
+ if (fragment2.kind === "para" && sectPrMarkerBlockIds && sectPrMarkerBlockIds.has(fragment2.blockId))
256475
+ return 0;
256476
+ return getFragmentHeight(fragment2, measureMap);
256477
+ }
256478
+ function balanceSectionOnPage(args$1) {
256479
+ const { sectionColumns, sectionHasExplicitColumnBreak, sectionIndex, blockSectionMap, fragments } = args$1;
256480
+ if (sectionColumns.count <= 1)
256481
+ return null;
256482
+ if (sectionHasExplicitColumnBreak)
256483
+ return null;
256484
+ if (sectionColumns.equalWidth === false && Array.isArray(sectionColumns.widths) && sectionColumns.widths.length > 0)
256485
+ return null;
256486
+ const sectionFragments = fragments.filter((f2) => blockSectionMap.get(f2.blockId) === sectionIndex);
256487
+ if (sectionFragments.length === 0)
256488
+ return null;
256489
+ const columnCount = sectionColumns.count;
256490
+ const columnGap = sectionColumns.gap;
256491
+ const columnWidth = sectionColumns.width ?? 0;
256492
+ if (columnWidth <= 0)
256493
+ return null;
256494
+ let sectionTopY = Number.POSITIVE_INFINITY;
256495
+ for (const f2 of sectionFragments)
256496
+ if (f2.y < sectionTopY)
256497
+ sectionTopY = f2.y;
256498
+ if (!Number.isFinite(sectionTopY))
256499
+ sectionTopY = args$1.topMargin;
256500
+ const remainingHeight = args$1.availableHeight - (sectionTopY - args$1.topMargin);
256501
+ if (remainingHeight <= 0)
256502
+ return null;
256503
+ let precedingHeightBeforeTable = 0;
256504
+ for (const f2 of sectionFragments) {
256505
+ if (f2.kind === "table")
256506
+ break;
256507
+ precedingHeightBeforeTable += getBalancingHeight(f2, args$1.measureMap, args$1.sectPrMarkerBlockIds);
256274
256508
  }
256509
+ const splitResult = splitDominantTableAtRowBoundary({
256510
+ sectionFragments,
256511
+ fragments,
256512
+ columnCount,
256513
+ measureMap: args$1.measureMap,
256514
+ sectPrMarkerBlockIds: args$1.sectPrMarkerBlockIds,
256515
+ precedingHeight: precedingHeightBeforeTable
256516
+ });
256517
+ const ordered = [...sectionFragments].sort((a2, b$1) => {
256518
+ if (a2.x !== b$1.x)
256519
+ return a2.x - b$1.x;
256520
+ return a2.y - b$1.y;
256521
+ });
256522
+ const contentBlocks = ordered.map((f2, i4) => ({
256523
+ blockId: `${f2.blockId}#${i4}`,
256524
+ measuredHeight: getBalancingHeight(f2, args$1.measureMap, args$1.sectPrMarkerBlockIds),
256525
+ canBreak: false,
256526
+ keepWithNext: false,
256527
+ keepTogether: true
256528
+ }));
256275
256529
  if (shouldSkipBalancing({
256276
- columnCount: columns.count,
256277
- columnWidth: columns.width,
256278
- columnGap: columns.gap,
256279
- availableHeight,
256530
+ columnCount,
256531
+ columnWidth,
256532
+ columnGap,
256533
+ availableHeight: remainingHeight,
256280
256534
  contentBlocks
256281
- }))
256282
- return;
256283
- const targetHeight = totalHeight / columns.count;
256284
- if (targetHeight < DEFAULT_BALANCING_CONFIG.minColumnHeight)
256285
- return;
256286
- let currentColumn = 0;
256287
- let currentColumnHeight = 0;
256288
- let currentY = topMargin;
256289
- for (const [, rowFragments] of sortedRows) {
256290
- const rowHeight = Math.max(...rowFragments.map((f2) => f2.height));
256291
- if (currentColumnHeight > 0 && currentColumnHeight + rowHeight >= targetHeight && currentColumn < columns.count - 1) {
256292
- currentColumn++;
256293
- currentColumnHeight = 0;
256294
- currentY = topMargin;
256295
- }
256296
- const colX = columnX(currentColumn);
256297
- for (const info of rowFragments) {
256298
- info.fragment.x = colX;
256299
- info.fragment.y = currentY;
256300
- info.fragment.width = columns.width;
256535
+ })) {
256536
+ splitResult?.rollback();
256537
+ return null;
256538
+ }
256539
+ const result = calculateBalancedColumnHeight({
256540
+ columnCount,
256541
+ columnWidth,
256542
+ columnGap,
256543
+ availableHeight: remainingHeight,
256544
+ contentBlocks
256545
+ }, DEFAULT_BALANCING_CONFIG);
256546
+ const columnX = (columnIndex) => args$1.margins.left + columnIndex * (columnWidth + columnGap);
256547
+ const colCursors = new Array(columnCount).fill(sectionTopY);
256548
+ let maxY = sectionTopY;
256549
+ for (let i4 = 0;i4 < ordered.length; i4++) {
256550
+ const f2 = ordered[i4];
256551
+ const block = contentBlocks[i4];
256552
+ const col = result.columnAssignments.get(block.blockId) ?? 0;
256553
+ f2.x = columnX(col);
256554
+ f2.y = colCursors[col];
256555
+ f2.width = columnWidth;
256556
+ colCursors[col] += block.measuredHeight;
256557
+ if (colCursors[col] > maxY)
256558
+ maxY = colCursors[col];
256559
+ }
256560
+ return { maxY };
256561
+ }
256562
+ function splitDominantTableAtRowBoundary(args$1) {
256563
+ const { sectionFragments, fragments, columnCount, measureMap, sectPrMarkerBlockIds } = args$1;
256564
+ const precedingHeight = Math.max(0, args$1.precedingHeight ?? 0);
256565
+ if (columnCount <= 1)
256566
+ return null;
256567
+ const tables = sectionFragments.filter((f2) => f2.kind === "table");
256568
+ if (tables.length !== 1)
256569
+ return null;
256570
+ const table2 = tables[0];
256571
+ const fromRow = table2.fromRow ?? 0;
256572
+ const toRow = table2.toRow ?? fromRow;
256573
+ if (toRow - fromRow < 2)
256574
+ return null;
256575
+ const measure = measureMap.get(table2.blockId);
256576
+ if (!measure || measure.kind !== "table" || !Array.isArray(measure.rows))
256577
+ return null;
256578
+ const totalSectionHeight = sectionFragments.reduce((sum, f2) => sum + getBalancingHeight(f2, measureMap, sectPrMarkerBlockIds), 0);
256579
+ if (totalSectionHeight <= 0)
256580
+ return null;
256581
+ const target = Math.max(1, totalSectionHeight / columnCount - precedingHeight);
256582
+ if (getBalancingHeight(table2, measureMap, sectPrMarkerBlockIds) <= target + 1)
256583
+ return null;
256584
+ let running = 0;
256585
+ let splitRow = fromRow + 1;
256586
+ for (let r$1 = fromRow;r$1 < toRow - 1; r$1++) {
256587
+ const h$2 = measure.rows[r$1]?.height ?? 0;
256588
+ if (running + h$2 >= target) {
256589
+ splitRow = r$1 + 1;
256590
+ break;
256301
256591
  }
256302
- currentColumnHeight += rowHeight;
256303
- currentY += rowHeight;
256592
+ running += h$2;
256593
+ splitRow = r$1 + 2;
256304
256594
  }
256595
+ if (splitRow <= fromRow || splitRow >= toRow)
256596
+ return null;
256597
+ const firstHalfRows = measure.rows.slice(fromRow, splitRow);
256598
+ const secondHalfRows = measure.rows.slice(splitRow, toRow);
256599
+ const firstHalfHeight = firstHalfRows.reduce((s2, r$1) => s2 + (r$1.height ?? 0), 0);
256600
+ const secondHalfHeight = secondHalfRows.reduce((s2, r$1) => s2 + (r$1.height ?? 0), 0);
256601
+ const makeRowBoundaries = (rows, startIndex) => {
256602
+ const out = [];
256603
+ let y$1 = 0.5;
256604
+ for (let i4 = 0;i4 < rows.length; i4++) {
256605
+ const h$2 = rows[i4].height ?? 0;
256606
+ out.push({
256607
+ index: startIndex + i4,
256608
+ y: y$1,
256609
+ height: h$2,
256610
+ minHeight: h$2,
256611
+ resizable: true
256612
+ });
256613
+ y$1 += h$2;
256614
+ }
256615
+ return out;
256616
+ };
256617
+ const originalMetadata = table2.metadata;
256618
+ const firstMetadata = originalMetadata ? {
256619
+ ...originalMetadata,
256620
+ rowBoundaries: makeRowBoundaries(firstHalfRows, 0)
256621
+ } : undefined;
256622
+ const secondMetadata = originalMetadata ? {
256623
+ ...originalMetadata,
256624
+ rowBoundaries: makeRowBoundaries(secondHalfRows, 0)
256625
+ } : undefined;
256626
+ const originalToRow = table2.toRow;
256627
+ const originalHeight = table2.height;
256628
+ const originalContinuesOnNext = table2.continuesOnNext ?? false;
256629
+ table2.toRow = splitRow;
256630
+ table2.height = firstHalfHeight;
256631
+ table2.continuesOnNext = true;
256632
+ if (firstMetadata)
256633
+ table2.metadata = firstMetadata;
256634
+ const secondHalf = {
256635
+ ...table2,
256636
+ fromRow: splitRow,
256637
+ toRow,
256638
+ height: secondHalfHeight,
256639
+ continuesFromPrev: true,
256640
+ continuesOnNext: originalContinuesOnNext,
256641
+ metadata: secondMetadata ?? table2.metadata
256642
+ };
256643
+ const fragIdx = fragments.indexOf(table2);
256644
+ if (fragIdx >= 0)
256645
+ fragments.splice(fragIdx + 1, 0, secondHalf);
256646
+ const sectIdx = sectionFragments.indexOf(table2);
256647
+ if (sectIdx >= 0)
256648
+ sectionFragments.splice(sectIdx + 1, 0, secondHalf);
256649
+ return {
256650
+ applied: true,
256651
+ rollback: () => {
256652
+ table2.toRow = originalToRow;
256653
+ table2.height = originalHeight;
256654
+ table2.continuesOnNext = originalContinuesOnNext;
256655
+ table2.metadata = originalMetadata;
256656
+ const fIdx = fragments.indexOf(secondHalf);
256657
+ if (fIdx >= 0)
256658
+ fragments.splice(fIdx, 1);
256659
+ const sIdx = sectionFragments.indexOf(secondHalf);
256660
+ if (sIdx >= 0)
256661
+ sectionFragments.splice(sIdx, 1);
256662
+ }
256663
+ };
256305
256664
  }
256306
256665
  function resolvePageNumberTokens(layout, blocks2, measures, numberingCtx) {
256307
256666
  const affectedBlockIds = /* @__PURE__ */ new Set;
@@ -257130,6 +257489,48 @@ function layoutDocument(blocks2, measures, options = {}) {
257130
257489
  right: activeRightMargin
257131
257490
  }, activePageSize.w);
257132
257491
  };
257492
+ const balancingMeasureMap = /* @__PURE__ */ new Map;
257493
+ const blockSectionMap = /* @__PURE__ */ new Map;
257494
+ const sectionColumnsMap = /* @__PURE__ */ new Map;
257495
+ const sectionHasExplicitColumnBreak = /* @__PURE__ */ new Set;
257496
+ const sectionEndBreakType = /* @__PURE__ */ new Map;
257497
+ const sectionTypeIsExplicit = /* @__PURE__ */ new Map;
257498
+ let lastSectionIdx = null;
257499
+ const sectPrMarkerBlockIds = /* @__PURE__ */ new Set;
257500
+ let documentHasExplicitColumnBreak = false;
257501
+ let documentHasAnySectionBreak = false;
257502
+ const alreadyBalancedSections = /* @__PURE__ */ new Set;
257503
+ let currentSectionIdx = null;
257504
+ blocks2.forEach((block, idx) => {
257505
+ const measure = measures[idx];
257506
+ if (measure)
257507
+ balancingMeasureMap.set(block.id, measure);
257508
+ const blockWithAttrs = block;
257509
+ const attrSectionIdx = blockWithAttrs.attrs?.sectionIndex;
257510
+ if (block.kind === "sectionBreak") {
257511
+ documentHasAnySectionBreak = true;
257512
+ if (typeof attrSectionIdx === "number") {
257513
+ currentSectionIdx = attrSectionIdx;
257514
+ lastSectionIdx = attrSectionIdx;
257515
+ if (block.columns)
257516
+ sectionColumnsMap.set(attrSectionIdx, cloneColumnLayout(block.columns));
257517
+ if (typeof block.type === "string")
257518
+ sectionEndBreakType.set(attrSectionIdx, block.type);
257519
+ if (typeof blockWithAttrs.attrs?.typeIsExplicit === "boolean")
257520
+ sectionTypeIsExplicit.set(attrSectionIdx, blockWithAttrs.attrs.typeIsExplicit);
257521
+ }
257522
+ }
257523
+ if (currentSectionIdx !== null) {
257524
+ blockSectionMap.set(block.id, currentSectionIdx);
257525
+ if (block.kind === "columnBreak") {
257526
+ sectionHasExplicitColumnBreak.add(currentSectionIdx);
257527
+ documentHasExplicitColumnBreak = true;
257528
+ }
257529
+ } else if (block.kind === "columnBreak")
257530
+ documentHasExplicitColumnBreak = true;
257531
+ if (block.kind === "paragraph" && blockWithAttrs.attrs?.sectPrMarker === true)
257532
+ sectPrMarkerBlockIds.add(block.id);
257533
+ });
257133
257534
  const anchoredByParagraph = collectAnchoredDrawings(blocks2, measures);
257134
257535
  const anchoredTables = collectAnchoredTables(blocks2, measures);
257135
257536
  const anchoredTablesByParagraph = anchoredTables.byParagraph;
@@ -257352,7 +257753,47 @@ function layoutDocument(blocks2, measures, options = {}) {
257352
257753
  let state = paginator.ensurePage();
257353
257754
  const columnIndexBefore = state.columnIndex;
257354
257755
  const newColumns = updatedState.pendingColumns;
257355
- if (columnIndexBefore >= newColumns.count)
257756
+ let endingSectionIndex = null;
257757
+ for (let i4 = state.page.fragments.length - 1;i4 >= 0; i4--) {
257758
+ const mapped = blockSectionMap.get(state.page.fragments[i4].blockId);
257759
+ if (typeof mapped === "number" && mapped !== metadataIndex) {
257760
+ endingSectionIndex = mapped;
257761
+ break;
257762
+ }
257763
+ }
257764
+ const endingSectionColumns = endingSectionIndex !== null ? sectionColumnsMap.get(endingSectionIndex) : undefined;
257765
+ const willBalance = endingSectionIndex !== null && !!endingSectionColumns && endingSectionColumns.count > 1 && !sectionHasExplicitColumnBreak.has(endingSectionIndex);
257766
+ let balanceResult = null;
257767
+ if (willBalance) {
257768
+ const activeRegionTop = state.constraintBoundaries[state.constraintBoundaries.length - 1]?.y ?? activeTopMargin;
257769
+ const availableHeight = activePageSize.h - activeBottomMargin - activeRegionTop;
257770
+ const normalized = normalizeColumns(endingSectionColumns, activePageSize.w - (activeLeftMargin + activeRightMargin));
257771
+ balanceResult = balanceSectionOnPage({
257772
+ fragments: state.page.fragments,
257773
+ sectionIndex: endingSectionIndex,
257774
+ sectionColumns: {
257775
+ count: normalized.count,
257776
+ gap: normalized.gap,
257777
+ width: normalized.width,
257778
+ widths: endingSectionColumns.widths,
257779
+ equalWidth: endingSectionColumns.equalWidth
257780
+ },
257781
+ sectionHasExplicitColumnBreak: false,
257782
+ blockSectionMap,
257783
+ margins: { left: activeLeftMargin },
257784
+ topMargin: activeRegionTop,
257785
+ columnWidth: normalized.width,
257786
+ availableHeight,
257787
+ measureMap: balancingMeasureMap,
257788
+ sectPrMarkerBlockIds
257789
+ });
257790
+ if (balanceResult) {
257791
+ state.cursorY = balanceResult.maxY;
257792
+ state.maxCursorY = balanceResult.maxY;
257793
+ alreadyBalancedSections.add(endingSectionIndex);
257794
+ }
257795
+ }
257796
+ if (balanceResult === null && columnIndexBefore >= newColumns.count)
257356
257797
  state = paginator.startNewPage();
257357
257798
  startMidPageRegion(state, newColumns);
257358
257799
  }
@@ -257716,46 +258157,74 @@ function layoutDocument(blocks2, measures, options = {}) {
257716
258157
  for (const fragment2 of page.fragments)
257717
258158
  fragment2.y += yOffset;
257718
258159
  }
257719
- if (activeColumns.count > 1) {
257720
- const contentWidth = pageSize.w - (activeLeftMargin + activeRightMargin);
257721
- const normalizedCols = normalizeColumns(activeColumns, contentWidth);
257722
- const measureMap = /* @__PURE__ */ new Map;
257723
- const blockSectionMap = /* @__PURE__ */ new Map;
257724
- const sectionColumnsMap = /* @__PURE__ */ new Map;
257725
- blocks2.forEach((block, idx) => {
257726
- const measure = measures[idx];
257727
- if (measure)
257728
- measureMap.set(block.id, measure);
257729
- const sectionIdx = block.attrs?.sectionIndex;
257730
- if (typeof sectionIdx === "number") {
257731
- blockSectionMap.set(block.id, sectionIdx);
257732
- if (block.kind === "sectionBreak" && block.columns)
257733
- sectionColumnsMap.set(sectionIdx, cloneColumnLayout(block.columns));
257734
- }
257735
- });
257736
- for (const page of pages)
257737
- if (page === pages[pages.length - 1] && page.fragments.length > 0) {
257738
- const finalSectionColumns = sectionColumnsMap.get(activeSectionIndex) ?? activeColumns;
257739
- if (finalSectionColumns?.equalWidth === false && Array.isArray(finalSectionColumns.widths) && finalSectionColumns.widths.length > 0)
257740
- continue;
257741
- if (new Set(page.fragments.map((f2) => Math.round(f2.x))).size > 1)
257742
- continue;
257743
- if (new Set(page.fragments.map((f2) => Math.round(f2.width))).size > 1)
257744
- continue;
257745
- const fragmentSections = /* @__PURE__ */ new Set;
257746
- for (const f2 of page.fragments) {
257747
- const section = blockSectionMap.get(f2.blockId);
257748
- if (section !== undefined)
257749
- fragmentSections.add(section);
257750
- }
257751
- const fragmentsToBalance = fragmentSections.size > 1 ? page.fragments.filter((f2) => {
257752
- return blockSectionMap.get(f2.blockId) === activeSectionIndex;
257753
- }) : page.fragments;
257754
- if (fragmentsToBalance.length > 0) {
257755
- const availableHeight = pageSize.h - activeBottomMargin - activeTopMargin;
257756
- balancePageColumns(fragmentsToBalance, normalizedCols, { left: activeLeftMargin }, activeTopMargin, availableHeight, measureMap);
258160
+ const FALLBACK_SECTION_IDX = -1;
258161
+ if (sectionColumnsMap.size === 0 && !documentHasAnySectionBreak && activeColumns.count > 1 && !documentHasExplicitColumnBreak) {
258162
+ sectionColumnsMap.set(FALLBACK_SECTION_IDX, cloneColumnLayout(activeColumns));
258163
+ for (const block of blocks2)
258164
+ blockSectionMap.set(block.id, FALLBACK_SECTION_IDX);
258165
+ }
258166
+ for (const [sectionIdx, sectionCols] of sectionColumnsMap) {
258167
+ if (sectionCols.count <= 1)
258168
+ continue;
258169
+ if (sectionHasExplicitColumnBreak.has(sectionIdx))
258170
+ continue;
258171
+ if (alreadyBalancedSections.has(sectionIdx))
258172
+ continue;
258173
+ if (sectionIdx !== FALLBACK_SECTION_IDX) {
258174
+ const endBreakType = sectionEndBreakType.get(sectionIdx);
258175
+ const typeIsExplicit = sectionTypeIsExplicit.get(sectionIdx) === true;
258176
+ const isLast = lastSectionIdx !== null && sectionIdx === lastSectionIdx;
258177
+ const bodyExplicitContinuousIdx = lastSectionIdx !== null && sectionTypeIsExplicit.get(lastSectionIdx) === true && sectionEndBreakType.get(lastSectionIdx) === "continuous" ? lastSectionIdx : null;
258178
+ const isExplicitNonContinuous = typeIsExplicit && (endBreakType === "nextPage" || endBreakType === "evenPage" || endBreakType === "oddPage");
258179
+ let sectionPagesCount = 0;
258180
+ for (const p$12 of pages)
258181
+ if (p$12.fragments.some((f2) => blockSectionMap.get(f2.blockId) === sectionIdx)) {
258182
+ sectionPagesCount += 1;
258183
+ if (sectionPagesCount > 1)
258184
+ break;
257757
258185
  }
257758
- }
258186
+ const isMultiPage = sectionPagesCount > 1;
258187
+ if (isMultiPage && !isLast)
258188
+ continue;
258189
+ const allowedByMidDocContinuous = endBreakType === "continuous" && !isLast;
258190
+ const allowedByBodyExplicitContinuous = bodyExplicitContinuousIdx !== null && sectionIdx === bodyExplicitContinuousIdx - 1 && !isExplicitNonContinuous;
258191
+ if (!allowedByMidDocContinuous && !allowedByBodyExplicitContinuous && !isMultiPage)
258192
+ continue;
258193
+ }
258194
+ let lastPageForSection = null;
258195
+ for (const p$12 of pages)
258196
+ if (p$12.fragments.some((f2) => blockSectionMap.get(f2.blockId) === sectionIdx))
258197
+ lastPageForSection = p$12;
258198
+ if (!lastPageForSection)
258199
+ continue;
258200
+ const sectionPageSize = lastPageForSection.size ?? pageSize;
258201
+ const sectionPageMargins = lastPageForSection.margins;
258202
+ const sectionLeftMargin = sectionPageMargins?.left ?? activeLeftMargin;
258203
+ const sectionRightMargin = sectionPageMargins?.right ?? activeRightMargin;
258204
+ const sectionTopMarginPx = sectionPageMargins?.top ?? activeTopMargin;
258205
+ const sectionBottomMargin = sectionPageMargins?.bottom ?? activeBottomMargin;
258206
+ const sectionContentWidth = sectionPageSize.w - (sectionLeftMargin + sectionRightMargin);
258207
+ const sectionAvailableHeight = sectionPageSize.h - sectionBottomMargin - sectionTopMarginPx;
258208
+ const normalized = normalizeColumns(sectionCols, sectionContentWidth);
258209
+ balanceSectionOnPage({
258210
+ fragments: lastPageForSection.fragments,
258211
+ sectionIndex: sectionIdx,
258212
+ sectionColumns: {
258213
+ count: normalized.count,
258214
+ gap: normalized.gap,
258215
+ width: normalized.width,
258216
+ widths: sectionCols.widths,
258217
+ equalWidth: sectionCols.equalWidth
258218
+ },
258219
+ sectionHasExplicitColumnBreak: false,
258220
+ blockSectionMap,
258221
+ margins: { left: sectionLeftMargin },
258222
+ topMargin: sectionTopMarginPx,
258223
+ columnWidth: normalized.width,
258224
+ availableHeight: sectionAvailableHeight,
258225
+ measureMap: balancingMeasureMap,
258226
+ sectPrMarkerBlockIds
258227
+ });
257759
258228
  }
257760
258229
  for (const state of states) {
257761
258230
  const boundaries = state.constraintBoundaries;
@@ -267357,12 +267826,43 @@ async function measureParagraphBlock(block, maxWidth) {
267357
267826
  if (lineToTrim.naturalWidth != null && typeof lineToTrim.naturalWidth === "number")
267358
267827
  lineToTrim.naturalWidth = roundValue(Math.max(0, lineToTrim.naturalWidth - delta));
267359
267828
  };
267360
- const getAlignmentStopForOrdinal = (ordinal) => {
267829
+ const tabSegmentInfo = /* @__PURE__ */ new Map;
267830
+ {
267831
+ let segmentTabRunIndices = [];
267832
+ const closeSegment = () => {
267833
+ const total = segmentTabRunIndices.length;
267834
+ segmentTabRunIndices.forEach((runIdx, ord) => {
267835
+ tabSegmentInfo.set(runIdx, {
267836
+ localOrdinal: ord,
267837
+ segmentTotal: total
267838
+ });
267839
+ });
267840
+ segmentTabRunIndices = [];
267841
+ };
267842
+ for (let i4 = 0;i4 < runsToProcess.length; i4++) {
267843
+ const r$1 = runsToProcess[i4];
267844
+ if (isLineBreakRun(r$1) || r$1.kind === "break" && r$1.breakType === "line")
267845
+ closeSegment();
267846
+ else if (isTabRun(r$1))
267847
+ segmentTabRunIndices.push(i4);
267848
+ }
267849
+ closeSegment();
267850
+ }
267851
+ const getAlignmentStopForOrdinal = (ordinal, runIdx) => {
267361
267852
  if (alignmentTabStopsPx.length === 0 || totalTabRuns === 0 || !Number.isFinite(ordinal))
267362
267853
  return null;
267363
- if (ordinal < 0 || ordinal >= totalTabRuns)
267854
+ let scopeOrdinal = ordinal;
267855
+ let scopeTotal = totalTabRuns;
267856
+ if (runIdx !== undefined) {
267857
+ const info = tabSegmentInfo.get(runIdx);
267858
+ if (info) {
267859
+ scopeOrdinal = info.localOrdinal;
267860
+ scopeTotal = info.segmentTotal;
267861
+ }
267862
+ }
267863
+ if (scopeOrdinal < 0 || scopeOrdinal >= scopeTotal)
267364
267864
  return null;
267365
- const remainingTabs = totalTabRuns - ordinal - 1;
267865
+ const remainingTabs = scopeTotal - scopeOrdinal - 1;
267366
267866
  const targetIndex = alignmentTabStopsPx.length - 1 - remainingTabs;
267367
267867
  if (targetIndex < 0 || targetIndex >= alignmentTabStopsPx.length)
267368
267868
  return null;
@@ -267476,16 +267976,16 @@ async function measureParagraphBlock(block, maxWidth) {
267476
267976
  let target;
267477
267977
  const resolvedTabIndex = typeof run2.tabIndex === "number" && Number.isFinite(run2.tabIndex) ? run2.tabIndex : sequentialTabIndex;
267478
267978
  sequentialTabIndex = Math.max(sequentialTabIndex, resolvedTabIndex + 1);
267479
- const forcedAlignment = getAlignmentStopForOrdinal(resolvedTabIndex);
267979
+ const greedy = getNextTabStopPx(absCurrentX, tabStops, tabStopCursor);
267980
+ const forcedAlignment = greedy.stop?.source === "default" ? getAlignmentStopForOrdinal(resolvedTabIndex, runIndex) : null;
267480
267981
  if (forcedAlignment && forcedAlignment.stop.pos > absCurrentX + TAB_EPSILON) {
267481
267982
  stop = forcedAlignment.stop;
267482
267983
  target = forcedAlignment.stop.pos;
267483
267984
  tabStopCursor = forcedAlignment.index + 1;
267484
267985
  } else {
267485
- const nextStop = getNextTabStopPx(absCurrentX, tabStops, tabStopCursor);
267486
- target = nextStop.target;
267487
- tabStopCursor = nextStop.nextIndex;
267488
- stop = nextStop.stop;
267986
+ target = greedy.target;
267987
+ tabStopCursor = greedy.nextIndex;
267988
+ stop = greedy.stop;
267489
267989
  }
267490
267990
  const maxAbsWidth = currentLine.maxWidth + effectiveIndent;
267491
267991
  const clampedTarget = Math.min(target, maxAbsWidth);
@@ -287413,7 +287913,16 @@ menclose::after {
287413
287913
  misses: this.#misses
287414
287914
  };
287415
287915
  }
287416
- }, MIN_BORDER_SIZE_PX2 = 0.5, MAX_BORDER_SIZE_PX2 = 100, borderSizeToPx = (size$1) => eighthPointsToPixels(size$1, { clamp: true }), clampPixelBorderWidth = (width) => Math.min(MAX_BORDER_SIZE_PX2, Math.max(MIN_BORDER_SIZE_PX2, width)), resolveBorderWidth = (size$1, unit) => {
287916
+ }, MIN_BORDER_SIZE_PX2 = 0.5, MAX_BORDER_SIZE_PX2 = 100, borderSizeToPx = (size$1) => {
287917
+ if (!isFiniteNumber(size$1))
287918
+ return;
287919
+ if (size$1 <= 0)
287920
+ return 0;
287921
+ const width = eighthPointsToPixels(size$1);
287922
+ if (width == null)
287923
+ return;
287924
+ return clampPixelBorderWidth(width);
287925
+ }, clampPixelBorderWidth = (width) => Math.min(MAX_BORDER_SIZE_PX2, Math.max(MIN_BORDER_SIZE_PX2, width)), resolveBorderWidth = (size$1, unit) => {
287417
287926
  if (unit === "eighthPoints")
287418
287927
  return borderSizeToPx(size$1);
287419
287928
  return clampPixelBorderWidth(size$1);
@@ -290699,12 +291208,43 @@ menclose::after {
290699
291208
  stop,
290700
291209
  index: index2
290701
291210
  })).filter(({ stop }) => stop.val === "end" || stop.val === "center" || stop.val === "decimal");
290702
- const getAlignmentStopForOrdinal = (ordinal) => {
291211
+ const tabSegmentInfo = /* @__PURE__ */ new Map;
291212
+ {
291213
+ let segmentTabRunIndices = [];
291214
+ const closeSegment = () => {
291215
+ const total = segmentTabRunIndices.length;
291216
+ segmentTabRunIndices.forEach((runIdx, ord) => {
291217
+ tabSegmentInfo.set(runIdx, {
291218
+ localOrdinal: ord,
291219
+ segmentTotal: total
291220
+ });
291221
+ });
291222
+ segmentTabRunIndices = [];
291223
+ };
291224
+ for (let i4 = 0;i4 < runs2.length; i4++) {
291225
+ const r$1 = runs2[i4];
291226
+ if (r$1.kind === "lineBreak" || r$1.kind === "break" && r$1.breakType === "line")
291227
+ closeSegment();
291228
+ else if (r$1.kind === "tab")
291229
+ segmentTabRunIndices.push(i4);
291230
+ }
291231
+ closeSegment();
291232
+ }
291233
+ const getAlignmentStopForOrdinal = (ordinal, runIdx) => {
290703
291234
  if (alignmentTabStopsPx.length === 0 || totalTabRuns === 0 || !Number.isFinite(ordinal))
290704
291235
  return null;
290705
- if (ordinal < 0 || ordinal >= totalTabRuns)
291236
+ let scopeOrdinal = ordinal;
291237
+ let scopeTotal = totalTabRuns;
291238
+ if (runIdx !== undefined) {
291239
+ const info = tabSegmentInfo.get(runIdx);
291240
+ if (info) {
291241
+ scopeOrdinal = info.localOrdinal;
291242
+ scopeTotal = info.segmentTotal;
291243
+ }
291244
+ }
291245
+ if (scopeOrdinal < 0 || scopeOrdinal >= scopeTotal)
290706
291246
  return null;
290707
- const remainingTabs = totalTabRuns - ordinal - 1;
291247
+ const remainingTabs = scopeTotal - scopeOrdinal - 1;
290708
291248
  const targetIndex = alignmentTabStopsPx.length - 1 - remainingTabs;
290709
291249
  if (targetIndex < 0 || targetIndex >= alignmentTabStopsPx.length)
290710
291250
  return null;
@@ -290729,21 +291269,21 @@ menclose::after {
290729
291269
  const leaders = [];
290730
291270
  const effectiveIndent = lineIndex === 0 ? indentLeft + rawFirstLineOffset : indentLeft;
290731
291271
  const maxAbsWidth = typeof line.maxWidth === "number" && Number.isFinite(line.maxWidth) ? line.maxWidth + effectiveIndent : Number.POSITIVE_INFINITY;
290732
- const applyTab = (startRunIndex, startChar, run2, tabOrdinal) => {
291272
+ const applyTab = (startRunIndex, startChar, run2, tabOrdinal, tabRunIdx) => {
290733
291273
  const originX = cursorX;
290734
291274
  const absCurrentX = cursorX + effectiveIndent;
290735
291275
  let stop;
290736
291276
  let target;
290737
- const forcedAlignment = typeof tabOrdinal === "number" && Number.isFinite(tabOrdinal) ? getAlignmentStopForOrdinal(tabOrdinal) : null;
291277
+ const greedy = getNextTabStopPx$1(absCurrentX, tabStops, tabStopCursor);
291278
+ const forcedAlignment = greedy.stop?.source === "default" && typeof tabOrdinal === "number" && Number.isFinite(tabOrdinal) ? getAlignmentStopForOrdinal(tabOrdinal, tabRunIdx) : null;
290738
291279
  if (forcedAlignment && forcedAlignment.stop.pos > absCurrentX + TAB_EPSILON$1) {
290739
291280
  stop = forcedAlignment.stop;
290740
291281
  target = forcedAlignment.stop.pos;
290741
291282
  tabStopCursor = forcedAlignment.index + 1;
290742
291283
  } else {
290743
- const next2 = getNextTabStopPx$1(absCurrentX, tabStops, tabStopCursor);
290744
- stop = next2.stop;
290745
- target = next2.target;
290746
- tabStopCursor = next2.nextIndex;
291284
+ stop = greedy.stop;
291285
+ target = greedy.target;
291286
+ tabStopCursor = greedy.nextIndex;
290747
291287
  }
290748
291288
  const clampedTarget = Number.isFinite(maxAbsWidth) ? Math.min(target, maxAbsWidth) : target;
290749
291289
  const relativeTarget = clampedTarget - effectiveIndent;
@@ -290788,7 +291328,7 @@ menclose::after {
290788
291328
  continue;
290789
291329
  if (run2.kind === "tab") {
290790
291330
  const ordinal = consumeTabOrdinal(run2.tabIndex);
290791
- applyTab(runIndex + 1, 0, run2, ordinal);
291331
+ applyTab(runIndex + 1, 0, run2, ordinal, runIndex);
290792
291332
  continue;
290793
291333
  }
290794
291334
  const text5 = runText(run2);
@@ -298527,12 +299067,12 @@ menclose::after {
298527
299067
  return;
298528
299068
  console.log(...args$1);
298529
299069
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
298530
- var init_src_JQdl170N_es = __esm(() => {
299070
+ var init_src_4bO9QmBD_es = __esm(() => {
298531
299071
  init_rolldown_runtime_Bg48TavK_es();
298532
- init_SuperConverter_DFi0X147_es();
299072
+ init_SuperConverter_ing_1fvK_es();
298533
299073
  init_jszip_C49i9kUs_es();
298534
299074
  init_uuid_qzgm05fK_es();
298535
- init_create_headless_toolbar_C9nvGdZQ_es();
299075
+ init_create_headless_toolbar_B_1fvPL0_es();
298536
299076
  init_constants_DrU4EASo_es();
298537
299077
  init_dist_B8HfvhaK_es();
298538
299078
  init_unified_Dsuw2be5_es();
@@ -326089,7 +326629,10 @@ function print() { __p += __j.call(arguments, '') }
326089
326629
  const separatorPositions = this.getColumnSeparatorPositions(columns, leftMargin, contentWidth);
326090
326630
  if (separatorPositions.length === 0)
326091
326631
  continue;
326632
+ const fragmentsInRegion = page.fragments.filter((f2) => f2.y >= yStart - 0.5 && f2.y < yEnd + 0.5);
326092
326633
  for (const separatorX of separatorPositions) {
326634
+ if (!fragmentsInRegion.some((f2) => f2.x >= separatorX))
326635
+ continue;
326093
326636
  const separatorEl = this.doc.createElement("div");
326094
326637
  separatorEl.dataset.superdocColumnSeparator = "true";
326095
326638
  separatorEl.style.position = "absolute";
@@ -335938,11 +336481,11 @@ function print() { __p += __j.call(arguments, '') }
335938
336481
  ];
335939
336482
  });
335940
336483
 
335941
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-_B0b9R4K.es.js
336484
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CPZeYqzS.es.js
335942
336485
  var MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
335943
- var init_create_super_doc_ui__B0b9R4K_es = __esm(() => {
335944
- init_SuperConverter_DFi0X147_es();
335945
- init_create_headless_toolbar_C9nvGdZQ_es();
336486
+ var init_create_super_doc_ui_CPZeYqzS_es = __esm(() => {
336487
+ init_SuperConverter_ing_1fvK_es();
336488
+ init_create_headless_toolbar_B_1fvPL0_es();
335946
336489
  MOD_ALIASES = new Set([
335947
336490
  "Mod",
335948
336491
  "Meta",
@@ -335984,16 +336527,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
335984
336527
 
335985
336528
  // ../../packages/superdoc/dist/super-editor.es.js
335986
336529
  var init_super_editor_es = __esm(() => {
335987
- init_src_JQdl170N_es();
335988
- init_SuperConverter_DFi0X147_es();
336530
+ init_src_4bO9QmBD_es();
336531
+ init_SuperConverter_ing_1fvK_es();
335989
336532
  init_jszip_C49i9kUs_es();
335990
336533
  init_xml_js_CqGKpaft_es();
335991
- init_create_headless_toolbar_C9nvGdZQ_es();
336534
+ init_create_headless_toolbar_B_1fvPL0_es();
335992
336535
  init_constants_DrU4EASo_es();
335993
336536
  init_dist_B8HfvhaK_es();
335994
336537
  init_unified_Dsuw2be5_es();
335995
336538
  init_DocxZipper_CUX64E5K_es();
335996
- init_create_super_doc_ui__B0b9R4K_es();
336539
+ init_create_super_doc_ui_CPZeYqzS_es();
335997
336540
  init_ui_CGB3qmy3_es();
335998
336541
  init_eventemitter3_UwU_CLPU_es();
335999
336542
  init_errors_C_DoKMoN_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.8.0-next.72",
3
+ "version": "0.8.0-next.73",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -25,20 +25,20 @@
25
25
  "@types/ws": "^8.5.13",
26
26
  "typescript": "^5.9.2",
27
27
  "@superdoc/document-api": "0.0.1",
28
- "@superdoc/pm-adapter": "0.0.0",
28
+ "@superdoc/super-editor": "0.0.1",
29
29
  "superdoc": "1.31.0",
30
- "@superdoc/super-editor": "0.0.1"
30
+ "@superdoc/pm-adapter": "0.0.0"
31
31
  },
32
32
  "module": "src/index.ts",
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@superdoc-dev/cli-darwin-arm64": "0.8.0-next.72",
38
- "@superdoc-dev/cli-darwin-x64": "0.8.0-next.72",
39
- "@superdoc-dev/cli-linux-x64": "0.8.0-next.72",
40
- "@superdoc-dev/cli-linux-arm64": "0.8.0-next.72",
41
- "@superdoc-dev/cli-windows-x64": "0.8.0-next.72"
37
+ "@superdoc-dev/cli-darwin-arm64": "0.8.0-next.73",
38
+ "@superdoc-dev/cli-darwin-x64": "0.8.0-next.73",
39
+ "@superdoc-dev/cli-linux-x64": "0.8.0-next.73",
40
+ "@superdoc-dev/cli-windows-x64": "0.8.0-next.73",
41
+ "@superdoc-dev/cli-linux-arm64": "0.8.0-next.73"
42
42
  },
43
43
  "scripts": {
44
44
  "predev": "node scripts/ensure-superdoc-build.js",