superdoc 2.0.0-next.2 → 2.0.0-next.3

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 (27) hide show
  1. package/dist/chunks/{PdfViewer-C4xgIIbF.es.js → PdfViewer-4xn9rggA.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-CWO98Qls.cjs → PdfViewer-C6tuSJXA.cjs} +1 -1
  3. package/dist/chunks/{index-s9GUR_Gc.es.js → index-CSZ7bAL7.es.js} +3 -3
  4. package/dist/chunks/{index-BY-3Vl72.cjs → index-k0xTe_8v.cjs} +3 -3
  5. package/dist/chunks/{index-BqPa6D4q-Dulj8zfc.cjs → index-lLnrqNSJ-CMJxa5vJ.cjs} +1 -1
  6. package/dist/chunks/{index-BqPa6D4q-8U4x8RP6.es.js → index-lLnrqNSJ-DoACeFqL.es.js} +1 -1
  7. package/dist/chunks/{super-editor.es-CT28vUbx.es.js → super-editor.es-B1DZfUz0.es.js} +537 -130
  8. package/dist/chunks/{super-editor.es-BM-ulSRj.cjs → super-editor.es-BY4paJvP.cjs} +537 -130
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-CDlAWcRu.js → converter-Bd6dIe0l.js} +1 -1
  11. package/dist/super-editor/chunks/{docx-zipper-B2VXuf8h.js → docx-zipper-Dzdi5pfi.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-B4Q_tNET.js → editor-C3sjGwAb.js} +538 -131
  13. package/dist/super-editor/chunks/{index-BqPa6D4q.js → index-lLnrqNSJ.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-BD-lDCLr.js → toolbar-Bn20lflQ.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +2 -2
  24. package/dist/superdoc.es.js +2 -2
  25. package/dist/superdoc.umd.js +539 -132
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -42428,7 +42428,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42428
42428
  static getStoredSuperdocVersion(docx) {
42429
42429
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42430
42430
  }
42431
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.2") {
42431
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.3") {
42432
42432
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42433
42433
  }
42434
42434
  /**
@@ -68384,7 +68384,7 @@ ${err.toString()}`);
68384
68384
  const shouldSkipNodeView = (editor) => {
68385
68385
  return isHeadless(editor);
68386
68386
  };
68387
- const summaryVersion = "2.0.0-next.2";
68387
+ const summaryVersion = "2.0.0-next.3";
68388
68388
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
68389
68389
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
68390
68390
  function mapAttributes(attrs) {
@@ -69173,7 +69173,7 @@ ${err.toString()}`);
69173
69173
  { default: remarkStringify2 },
69174
69174
  { default: remarkGfm2 }
69175
69175
  ] = await Promise.all([
69176
- Promise.resolve().then(() => indexBqPa6D4q),
69176
+ Promise.resolve().then(() => indexLLnrqNSJ),
69177
69177
  Promise.resolve().then(() => indexDRCvimau),
69178
69178
  Promise.resolve().then(() => indexC_x_N6Uh),
69179
69179
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -69378,7 +69378,7 @@ ${err.toString()}`);
69378
69378
  * Process collaboration migrations
69379
69379
  */
69380
69380
  processCollaborationMigrations() {
69381
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.2");
69381
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.3");
69382
69382
  if (!this.options.ydoc) return;
69383
69383
  const metaMap = this.options.ydoc.getMap("meta");
69384
69384
  let docVersion = metaMap.get("version");
@@ -76630,7 +76630,7 @@ ${l}
76630
76630
  return true;
76631
76631
  }
76632
76632
  const LIST_MARKER_GAP$2 = 8;
76633
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
76633
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
76634
76634
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
76635
76635
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
76636
76636
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -77557,6 +77557,7 @@ ${l}
77557
77557
  const block = lookup2.block;
77558
77558
  const measure = lookup2.measure;
77559
77559
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
77560
+ const alignment2 = block.attrs?.alignment;
77560
77561
  const fragmentEl = this.doc.createElement("div");
77561
77562
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
77562
77563
  const isTocEntry = block.attrs?.isTocEntry;
@@ -77635,7 +77636,7 @@ ${l}
77635
77636
  const textStart = paraIndentLeft + firstLine;
77636
77637
  tabWidth = textStart - currentPos;
77637
77638
  if (tabWidth <= 0) {
77638
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77639
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77639
77640
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77640
77641
  tabWidth = LIST_MARKER_GAP$2;
77641
77642
  }
@@ -77662,6 +77663,21 @@ ${l}
77662
77663
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
77663
77664
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
77664
77665
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
77666
+ if (alignment2 === "justify" || alignment2 === "both") {
77667
+ console.log(
77668
+ "[justify-debug][painter-firstline-available]",
77669
+ JSON.stringify({
77670
+ blockId: block.id,
77671
+ fragmentWidth: fragment.width,
77672
+ markerTabWidth: listFirstLineMarkerTabWidth,
77673
+ paraIndentRight,
77674
+ availableWidthOverride,
77675
+ lineMaxWidth: line.maxWidth ?? null,
77676
+ lineWidth: line.width,
77677
+ lineNaturalWidth: line.naturalWidth ?? null
77678
+ })
77679
+ );
77680
+ }
77665
77681
  }
77666
77682
  const isLastLineOfFragment = index2 === lines.length - 1;
77667
77683
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -77787,7 +77803,7 @@ ${l}
77787
77803
  const textStart = paraIndentLeft + firstLine;
77788
77804
  tabWidth = textStart - currentPos;
77789
77805
  if (tabWidth <= 0) {
77790
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77806
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77791
77807
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77792
77808
  tabWidth = LIST_MARKER_GAP$2;
77793
77809
  }
@@ -79321,6 +79337,23 @@ ${l}
79321
79337
  if (spacingPerSpace !== 0) {
79322
79338
  el.style.wordSpacing = `${spacingPerSpace}px`;
79323
79339
  }
79340
+ if (justifyShouldApply && spacingPerSpace < 0) {
79341
+ console.log(
79342
+ "[justify-debug][painter-wordspacing-negative]",
79343
+ JSON.stringify({
79344
+ blockId: block.id,
79345
+ lineIndex: lineIndex ?? null,
79346
+ alignment: alignment2 ?? null,
79347
+ availableWidth,
79348
+ lineWidth,
79349
+ lineMaxWidth: line.maxWidth ?? null,
79350
+ lineNaturalWidth: line.naturalWidth ?? null,
79351
+ spaceCount,
79352
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
79353
+ skipJustify: Boolean(skipJustify)
79354
+ })
79355
+ );
79356
+ }
79324
79357
  if (hasExplicitPositioning && line.segments) {
79325
79358
  const paraIndent = block.attrs?.indent;
79326
79359
  const indentLeft = paraIndent?.left ?? 0;
@@ -81514,6 +81547,28 @@ ${l}
81514
81547
  const TAB_CHAR_LENGTH = 1;
81515
81548
  const SPACE_CHARS = SPACE_CHARS$1;
81516
81549
  const isTabRun$1 = (run2) => run2?.kind === "tab";
81550
+ const isWordChar$3 = (char) => {
81551
+ if (!char) return false;
81552
+ const code2 = char.charCodeAt(0);
81553
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
81554
+ };
81555
+ const capitalizeText$2 = (text2) => {
81556
+ if (!text2) return text2;
81557
+ let result = "";
81558
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
81559
+ const prevChar = i2 > 0 ? text2[i2 - 1] : "";
81560
+ const ch = text2[i2];
81561
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
81562
+ }
81563
+ return result;
81564
+ };
81565
+ const applyTextTransform$2 = (text2, transform) => {
81566
+ if (!text2 || !transform || transform === "none") return text2;
81567
+ if (transform === "uppercase") return text2.toUpperCase();
81568
+ if (transform === "lowercase") return text2.toLowerCase();
81569
+ if (transform === "capitalize") return capitalizeText$2(text2);
81570
+ return text2;
81571
+ };
81517
81572
  function getMeasurementContext() {
81518
81573
  if (measurementCtx) return measurementCtx;
81519
81574
  if (typeof document === "undefined") {
@@ -81689,17 +81744,18 @@ ${l}
81689
81744
  }
81690
81745
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81691
81746
  const runLength = text2.length;
81747
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81692
81748
  if (currentCharOffset + runLength >= charOffset) {
81693
81749
  const offsetInRun = charOffset - currentCharOffset;
81694
81750
  ctx2.font = getRunFontString(run2);
81695
- const textUpToTarget = text2.slice(0, offsetInRun);
81751
+ const textUpToTarget = displayText.slice(0, offsetInRun);
81696
81752
  const measured2 = ctx2.measureText(textUpToTarget);
81697
81753
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
81698
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
81754
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text2.slice(0, offsetInRun)) : 0;
81699
81755
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
81700
81756
  }
81701
81757
  ctx2.font = getRunFontString(run2);
81702
- const measured = ctx2.measureText(text2);
81758
+ const measured = ctx2.measureText(displayText);
81703
81759
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81704
81760
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text2) : 0;
81705
81761
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -81738,8 +81794,9 @@ ${l}
81738
81794
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
81739
81795
  }
81740
81796
  const text2 = run2.text ?? "";
81741
- const segmentText = text2.slice(segment.fromChar, segment.toChar);
81742
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
81797
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81798
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
81799
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
81743
81800
  ctx2.font = getRunFontString(run2);
81744
81801
  const measured = ctx2.measureText(textUpToTarget);
81745
81802
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -81835,12 +81892,13 @@ ${l}
81835
81892
  }
81836
81893
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81837
81894
  const runLength = text2.length;
81895
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81838
81896
  if (runLength === 0) continue;
81839
81897
  ctx2.font = getRunFontString(run2);
81840
81898
  for (let i2 = 0; i2 <= runLength; i2++) {
81841
- const textUpToChar = text2.slice(0, i2);
81899
+ const textUpToChar = displayText.slice(0, i2);
81842
81900
  const measured2 = ctx2.measureText(textUpToChar);
81843
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
81901
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text2.slice(0, i2)) : 0;
81844
81902
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i2, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
81845
81903
  if (charX >= safeX) {
81846
81904
  if (i2 === 0) {
@@ -81850,7 +81908,7 @@ ${l}
81850
81908
  pmPosition: pmPosition3
81851
81909
  };
81852
81910
  }
81853
- const prevText = text2.slice(0, i2 - 1);
81911
+ const prevText = displayText.slice(0, i2 - 1);
81854
81912
  const prevMeasured = ctx2.measureText(prevText);
81855
81913
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i2 - 1, runLength);
81856
81914
  const distToPrev = Math.abs(safeX - prevX);
@@ -81863,7 +81921,7 @@ ${l}
81863
81921
  };
81864
81922
  }
81865
81923
  }
81866
- const measured = ctx2.measureText(text2);
81924
+ const measured = ctx2.measureText(displayText);
81867
81925
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81868
81926
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text2) : 0;
81869
81927
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -82294,6 +82352,83 @@ ${l}
82294
82352
  }
82295
82353
  return index2;
82296
82354
  }
82355
+ const LIST_MARKER_GAP$1 = 8;
82356
+ const MIN_MARKER_GUTTER = 24;
82357
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
82358
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
82359
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
82360
+ const SPACE_SUFFIX_GAP_PX = 4;
82361
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
82362
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
82363
+ const marker = wordLayout?.marker;
82364
+ if (!marker) {
82365
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
82366
+ return textStartPx;
82367
+ }
82368
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
82369
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
82370
+ if (markerTextWidth == null && marker.markerText) {
82371
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
82372
+ }
82373
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth < 0) {
82374
+ markerTextWidth = markerBoxWidth;
82375
+ }
82376
+ markerTextWidth = Math.max(0, markerTextWidth);
82377
+ let markerStartPos;
82378
+ if (wordLayout?.firstLineIndentMode === true && Number.isFinite(marker.markerX)) {
82379
+ markerStartPos = marker.markerX;
82380
+ } else {
82381
+ markerStartPos = indentLeft - hanging + firstLine;
82382
+ }
82383
+ if (!Number.isFinite(markerStartPos)) {
82384
+ markerStartPos = 0;
82385
+ }
82386
+ const currentPos = markerStartPos + markerTextWidth;
82387
+ const suffix2 = marker.suffix ?? "tab";
82388
+ if (suffix2 === "space") {
82389
+ return markerStartPos + markerTextWidth + SPACE_SUFFIX_GAP_PX;
82390
+ }
82391
+ if (suffix2 === "nothing") {
82392
+ return markerStartPos + markerTextWidth;
82393
+ }
82394
+ const markerJustification = marker.justification ?? "left";
82395
+ if (markerJustification !== "left") {
82396
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
82397
+ return markerStartPos + markerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
82398
+ }
82399
+ if (wordLayout?.firstLineIndentMode === true) {
82400
+ let targetTabStop;
82401
+ if (Array.isArray(wordLayout.tabsPx)) {
82402
+ for (const tab of wordLayout.tabsPx) {
82403
+ if (typeof tab === "number" && tab > currentPos) {
82404
+ targetTabStop = tab;
82405
+ break;
82406
+ }
82407
+ }
82408
+ }
82409
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
82410
+ let tabWidth2;
82411
+ if (targetTabStop !== void 0) {
82412
+ tabWidth2 = targetTabStop - currentPos;
82413
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
82414
+ tabWidth2 = textStartTarget - currentPos;
82415
+ } else {
82416
+ tabWidth2 = LIST_MARKER_GAP$1;
82417
+ }
82418
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
82419
+ tabWidth2 = LIST_MARKER_GAP$1;
82420
+ }
82421
+ return markerStartPos + markerTextWidth + tabWidth2;
82422
+ }
82423
+ const textStart = indentLeft + firstLine;
82424
+ let tabWidth = textStart - currentPos;
82425
+ if (tabWidth <= 0) {
82426
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
82427
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
82428
+ tabWidth = LIST_MARKER_GAP$1;
82429
+ }
82430
+ return markerStartPos + markerTextWidth + tabWidth;
82431
+ }
82297
82432
  function getWordLayoutConfig(block) {
82298
82433
  if (!block || block.kind !== "paragraph") {
82299
82434
  return void 0;
@@ -82326,9 +82461,16 @@ ${l}
82326
82461
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
82327
82462
  let indentAdjust = paraIndentLeft;
82328
82463
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
82464
+ const resolvedTextStart = resolveListTextStartPx(
82465
+ wordLayout,
82466
+ paraIndentLeft,
82467
+ Math.max(firstLineIndent, 0),
82468
+ Math.max(hangingIndent, 0),
82469
+ () => markerWidth
82470
+ // Use provided markerWidth since we don't have canvas access here
82471
+ );
82329
82472
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
82330
- const markerTextStartX = wordLayout?.marker?.textStartX;
82331
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
82473
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
82332
82474
  } else if (isFirstLine && !isListItem2) {
82333
82475
  indentAdjust += firstLineOffset;
82334
82476
  }
@@ -82484,7 +82626,10 @@ ${l}
82484
82626
  }
82485
82627
  function createFloatingObjectManager(columns, margins, pageWidth) {
82486
82628
  const zones = [];
82487
- const marginLeft = Math.max(0, margins?.left ?? 0);
82629
+ let currentColumns = columns;
82630
+ let currentMargins = margins;
82631
+ let currentPageWidth = pageWidth;
82632
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
82488
82633
  return {
82489
82634
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
82490
82635
  if (!drawingBlock.anchor?.isAnchored) {
@@ -82497,7 +82642,7 @@ ${l}
82497
82642
  }
82498
82643
  const objectWidth = measure.width ?? 0;
82499
82644
  const objectHeight = measure.height ?? 0;
82500
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
82645
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
82501
82646
  const y2 = anchorY + (anchor.offsetV ?? 0);
82502
82647
  const zone = {
82503
82648
  imageBlockId: drawingBlock.id,
@@ -82531,7 +82676,7 @@ ${l}
82531
82676
  }
82532
82677
  const tableWidth = measure.totalWidth ?? 0;
82533
82678
  const tableHeight = measure.totalHeight ?? 0;
82534
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
82679
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
82535
82680
  const y2 = anchorY + (anchor.offsetV ?? 0);
82536
82681
  const zone = {
82537
82682
  imageBlockId: tableBlock.id,
@@ -82579,7 +82724,7 @@ ${l}
82579
82724
  }
82580
82725
  const leftFloats = [];
82581
82726
  const rightFloats = [];
82582
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
82727
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
82583
82728
  const columnCenter = columnOrigin + baseWidth / 2;
82584
82729
  for (const zone of wrappingZones) {
82585
82730
  if (zone.wrapMode === "left") {
@@ -82618,6 +82763,22 @@ ${l}
82618
82763
  },
82619
82764
  clear() {
82620
82765
  zones.length = 0;
82766
+ },
82767
+ /**
82768
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
82769
+ * This method should be called when the layout configuration changes (e.g., section breaks,
82770
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
82771
+ * correctly relative to the new layout boundaries.
82772
+ *
82773
+ * @param nextColumns - Column layout configuration (width, gap, count)
82774
+ * @param nextMargins - Optional page margins (left, right) in pixels
82775
+ * @param nextPageWidth - Optional total page width in pixels
82776
+ */
82777
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
82778
+ currentColumns = nextColumns;
82779
+ currentMargins = nextMargins;
82780
+ currentPageWidth = nextPageWidth;
82781
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
82621
82782
  }
82622
82783
  };
82623
82784
  }
@@ -82717,7 +82878,14 @@ ${l}
82717
82878
  const props = {};
82718
82879
  if (source.kind !== "sectionBreak") return props;
82719
82880
  if (source.margins) {
82720
- props.margins = { header: source.margins.header, footer: source.margins.footer };
82881
+ props.margins = {
82882
+ header: source.margins.header,
82883
+ footer: source.margins.footer,
82884
+ top: source.margins.top,
82885
+ right: source.margins.right,
82886
+ bottom: source.margins.bottom,
82887
+ left: source.margins.left
82888
+ };
82721
82889
  }
82722
82890
  if (source.pageSize) {
82723
82891
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -82765,20 +82933,36 @@ ${l}
82765
82933
  next2.activeOrientation = block.orientation;
82766
82934
  next2.pendingOrientation = null;
82767
82935
  }
82936
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
82937
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
82938
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
82939
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
82768
82940
  if (block.margins?.header !== void 0) {
82769
- const headerDistance = Math.max(0, block.margins.header);
82770
82941
  next2.activeHeaderDistance = headerDistance;
82771
82942
  next2.pendingHeaderDistance = headerDistance;
82772
- next2.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
82773
- next2.pendingTopMargin = next2.activeTopMargin;
82774
82943
  }
82775
82944
  if (block.margins?.footer !== void 0) {
82776
- const footerDistance = Math.max(0, block.margins.footer);
82777
82945
  next2.activeFooterDistance = footerDistance;
82778
82946
  next2.pendingFooterDistance = footerDistance;
82779
- next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
82947
+ }
82948
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
82949
+ next2.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
82950
+ next2.pendingTopMargin = next2.activeTopMargin;
82951
+ }
82952
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
82953
+ next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
82780
82954
  next2.pendingBottomMargin = next2.activeBottomMargin;
82781
82955
  }
82956
+ if (block.margins?.left !== void 0) {
82957
+ const leftMargin = Math.max(0, block.margins.left);
82958
+ next2.activeLeftMargin = leftMargin;
82959
+ next2.pendingLeftMargin = leftMargin;
82960
+ }
82961
+ if (block.margins?.right !== void 0) {
82962
+ const rightMargin = Math.max(0, block.margins.right);
82963
+ next2.activeRightMargin = rightMargin;
82964
+ next2.pendingRightMargin = rightMargin;
82965
+ }
82782
82966
  if (block.columns) {
82783
82967
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
82784
82968
  next2.pendingColumns = null;
@@ -82787,26 +82971,42 @@ ${l}
82787
82971
  }
82788
82972
  const headerPx = block.margins?.header;
82789
82973
  const footerPx = block.margins?.footer;
82974
+ const topPx = block.margins?.top;
82975
+ const bottomPx = block.margins?.bottom;
82790
82976
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
82791
82977
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
82978
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
82979
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
82792
82980
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
82793
82981
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
82794
- if (typeof headerPx === "number") {
82795
- const newHeaderDist = Math.max(0, headerPx);
82982
+ if (typeof headerPx === "number" || typeof topPx === "number") {
82983
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
82984
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
82796
82985
  next2.pendingHeaderDistance = newHeaderDist;
82797
- next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
82986
+ next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
82798
82987
  } else {
82799
82988
  next2.pendingTopMargin = nextTop;
82800
82989
  next2.pendingHeaderDistance = nextHeader;
82801
82990
  }
82802
- if (typeof footerPx === "number") {
82803
- const newFooterDist = Math.max(0, footerPx);
82991
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
82992
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
82993
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
82804
82994
  next2.pendingFooterDistance = newFooterDist;
82805
- next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
82995
+ next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
82806
82996
  } else {
82807
82997
  next2.pendingBottomMargin = nextBottom;
82808
82998
  next2.pendingFooterDistance = nextFooter;
82809
82999
  }
83000
+ if (typeof block.margins?.left === "number") {
83001
+ next2.pendingLeftMargin = Math.max(0, block.margins.left);
83002
+ } else {
83003
+ next2.pendingLeftMargin = nextLeft;
83004
+ }
83005
+ if (typeof block.margins?.right === "number") {
83006
+ next2.pendingRightMargin = Math.max(0, block.margins.right);
83007
+ } else {
83008
+ next2.pendingRightMargin = nextRight;
83009
+ }
82810
83010
  if (block.pageSize) {
82811
83011
  next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
82812
83012
  }
@@ -82866,6 +83066,12 @@ ${l}
82866
83066
  if (next2.pendingBottomMargin != null) {
82867
83067
  next2.activeBottomMargin = next2.pendingBottomMargin;
82868
83068
  }
83069
+ if (next2.pendingLeftMargin != null) {
83070
+ next2.activeLeftMargin = next2.pendingLeftMargin;
83071
+ }
83072
+ if (next2.pendingRightMargin != null) {
83073
+ next2.activeRightMargin = next2.pendingRightMargin;
83074
+ }
82869
83075
  if (next2.pendingHeaderDistance != null) {
82870
83076
  next2.activeHeaderDistance = next2.pendingHeaderDistance;
82871
83077
  }
@@ -82883,6 +83089,8 @@ ${l}
82883
83089
  }
82884
83090
  next2.pendingTopMargin = null;
82885
83091
  next2.pendingBottomMargin = null;
83092
+ next2.pendingLeftMargin = null;
83093
+ next2.pendingRightMargin = null;
82886
83094
  next2.pendingHeaderDistance = null;
82887
83095
  next2.pendingFooterDistance = null;
82888
83096
  next2.pendingPageSize = null;
@@ -83111,7 +83319,8 @@ ${l}
83111
83319
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
83112
83320
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83113
83321
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
83114
- lines = normalizeLines(newMeasure);
83322
+ const newLines = normalizeLines(newMeasure);
83323
+ lines = newLines;
83115
83324
  didRemeasureForColumnWidth = true;
83116
83325
  }
83117
83326
  let fromLine = 0;
@@ -83193,7 +83402,8 @@ ${l}
83193
83402
  if (narrowestRemeasureWidth < remeasureWidth) {
83194
83403
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83195
83404
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
83196
- lines = normalizeLines(newMeasure);
83405
+ const newLines = normalizeLines(newMeasure);
83406
+ lines = newLines;
83197
83407
  didRemeasureForFloats = true;
83198
83408
  }
83199
83409
  }
@@ -84350,8 +84560,8 @@ ${l}
84350
84560
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
84351
84561
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
84352
84562
  };
84353
- const contentWidth = pageSize.w - (margins.left + margins.right);
84354
- if (contentWidth <= 0) {
84563
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
84564
+ if (baseContentWidth <= 0) {
84355
84565
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
84356
84566
  }
84357
84567
  const validateContentHeight = (height) => {
@@ -84381,8 +84591,12 @@ ${l}
84381
84591
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
84382
84592
  let activeTopMargin = effectiveTopMargin;
84383
84593
  let activeBottomMargin = effectiveBottomMargin;
84594
+ let activeLeftMargin = margins.left;
84595
+ let activeRightMargin = margins.right;
84384
84596
  let pendingTopMargin = null;
84385
84597
  let pendingBottomMargin = null;
84598
+ let pendingLeftMargin = null;
84599
+ let pendingRightMargin = null;
84386
84600
  let activeHeaderDistance = margins.header ?? margins.top;
84387
84601
  let pendingHeaderDistance = null;
84388
84602
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -84395,10 +84609,11 @@ ${l}
84395
84609
  let pendingOrientation = null;
84396
84610
  let activeVAlign = null;
84397
84611
  let pendingVAlign = null;
84612
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
84398
84613
  const floatManager = createFloatingObjectManager(
84399
- normalizeColumns(activeColumns, contentWidth),
84400
- { left: margins.left, right: margins.right },
84401
- pageSize.w
84614
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84615
+ { left: activeLeftMargin, right: activeRightMargin },
84616
+ activePageSize.w
84402
84617
  );
84403
84618
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks2);
84404
84619
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -84415,22 +84630,38 @@ ${l}
84415
84630
  next2.activeOrientation = block.orientation;
84416
84631
  next2.pendingOrientation = null;
84417
84632
  }
84633
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
84634
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
84635
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
84636
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
84418
84637
  if (block.margins?.header !== void 0) {
84419
- const headerDist = Math.max(0, block.margins.header);
84420
- next2.activeHeaderDistance = headerDist;
84421
- next2.pendingHeaderDistance = headerDist;
84422
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
84423
- next2.activeTopMargin = Math.max(baseMargins.top, requiredTop);
84424
- next2.pendingTopMargin = next2.activeTopMargin;
84638
+ next2.activeHeaderDistance = headerDistance2;
84639
+ next2.pendingHeaderDistance = headerDistance2;
84425
84640
  }
84426
84641
  if (block.margins?.footer !== void 0) {
84427
- const footerDistance2 = Math.max(0, block.margins.footer);
84428
84642
  next2.activeFooterDistance = footerDistance2;
84429
84643
  next2.pendingFooterDistance = footerDistance2;
84644
+ }
84645
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
84646
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
84647
+ next2.activeTopMargin = Math.max(sectionTop, requiredTop);
84648
+ next2.pendingTopMargin = next2.activeTopMargin;
84649
+ }
84650
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
84430
84651
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
84431
- next2.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84652
+ next2.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
84432
84653
  next2.pendingBottomMargin = next2.activeBottomMargin;
84433
84654
  }
84655
+ if (block.margins?.left !== void 0) {
84656
+ const leftMargin = Math.max(0, block.margins.left);
84657
+ next2.activeLeftMargin = leftMargin;
84658
+ next2.pendingLeftMargin = leftMargin;
84659
+ }
84660
+ if (block.margins?.right !== void 0) {
84661
+ const rightMargin = Math.max(0, block.margins.right);
84662
+ next2.activeRightMargin = rightMargin;
84663
+ next2.pendingRightMargin = rightMargin;
84664
+ }
84434
84665
  if (block.columns) {
84435
84666
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
84436
84667
  next2.pendingColumns = null;
@@ -84459,27 +84690,35 @@ ${l}
84459
84690
  const headerPx = block.margins?.header;
84460
84691
  const footerPx = block.margins?.footer;
84461
84692
  const topPx = block.margins?.top;
84693
+ const bottomPx = block.margins?.bottom;
84694
+ const leftPx = block.margins?.left;
84695
+ const rightPx = block.margins?.right;
84462
84696
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
84463
84697
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
84698
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
84699
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
84464
84700
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
84465
84701
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
84466
84702
  next2.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
84467
84703
  next2.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
84468
84704
  if (typeof headerPx === "number" || typeof topPx === "number") {
84469
- const sectionTop = topPx ?? baseMargins.top;
84705
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
84470
84706
  const sectionHeader = next2.pendingHeaderDistance;
84471
84707
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
84472
84708
  next2.pendingTopMargin = Math.max(sectionTop, requiredTop);
84473
84709
  } else {
84474
84710
  next2.pendingTopMargin = nextTop;
84475
84711
  }
84476
- if (typeof footerPx === "number") {
84712
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
84477
84713
  const sectionFooter = next2.pendingFooterDistance;
84714
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
84478
84715
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
84479
- next2.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84716
+ next2.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
84480
84717
  } else {
84481
84718
  next2.pendingBottomMargin = nextBottom;
84482
84719
  }
84720
+ next2.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
84721
+ next2.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
84483
84722
  if (block.pageSize) next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
84484
84723
  if (block.orientation) next2.pendingOrientation = block.orientation;
84485
84724
  const sectionType = block.type ?? "continuous";
@@ -84564,7 +84803,7 @@ ${l}
84564
84803
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
84565
84804
  let pendingSectionIndex = null;
84566
84805
  const paginator = createPaginator({
84567
- margins: { left: margins.left, right: margins.right },
84806
+ margins: paginatorMargins,
84568
84807
  getActiveTopMargin: () => activeTopMargin,
84569
84808
  getActiveBottomMargin: () => activeBottomMargin,
84570
84809
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -84579,8 +84818,12 @@ ${l}
84579
84818
  const applied = applyPendingToActive({
84580
84819
  activeTopMargin,
84581
84820
  activeBottomMargin,
84821
+ activeLeftMargin,
84822
+ activeRightMargin,
84582
84823
  pendingTopMargin,
84583
84824
  pendingBottomMargin,
84825
+ pendingLeftMargin,
84826
+ pendingRightMargin,
84584
84827
  activeHeaderDistance,
84585
84828
  activeFooterDistance,
84586
84829
  pendingHeaderDistance,
@@ -84595,8 +84838,12 @@ ${l}
84595
84838
  });
84596
84839
  activeTopMargin = applied.activeTopMargin;
84597
84840
  activeBottomMargin = applied.activeBottomMargin;
84841
+ activeLeftMargin = applied.activeLeftMargin;
84842
+ activeRightMargin = applied.activeRightMargin;
84598
84843
  pendingTopMargin = applied.pendingTopMargin;
84599
84844
  pendingBottomMargin = applied.pendingBottomMargin;
84845
+ pendingLeftMargin = applied.pendingLeftMargin;
84846
+ pendingRightMargin = applied.pendingRightMargin;
84600
84847
  activeHeaderDistance = applied.activeHeaderDistance;
84601
84848
  activeFooterDistance = applied.activeFooterDistance;
84602
84849
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -84608,6 +84855,14 @@ ${l}
84608
84855
  activeOrientation = applied.activeOrientation;
84609
84856
  pendingOrientation = applied.pendingOrientation;
84610
84857
  cachedColumnsState.state = null;
84858
+ paginatorMargins.left = activeLeftMargin;
84859
+ paginatorMargins.right = activeRightMargin;
84860
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84861
+ floatManager.setLayoutContext(
84862
+ normalizeColumns(activeColumns, contentWidth),
84863
+ { left: activeLeftMargin, right: activeRightMargin },
84864
+ activePageSize.w
84865
+ );
84611
84866
  if (pendingNumbering) {
84612
84867
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
84613
84868
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -84652,7 +84907,7 @@ ${l}
84652
84907
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
84653
84908
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
84654
84909
  const getCurrentColumns = () => {
84655
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
84910
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84656
84911
  const state2 = states[states.length - 1] ?? null;
84657
84912
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
84658
84913
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -84685,6 +84940,12 @@ ${l}
84685
84940
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
84686
84941
  activeColumns = newColumns;
84687
84942
  cachedColumnsState.state = null;
84943
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84944
+ floatManager.setLayoutContext(
84945
+ normalizeColumns(activeColumns, contentWidth),
84946
+ { left: activeLeftMargin, right: activeRightMargin },
84947
+ activePageSize.w
84948
+ );
84688
84949
  };
84689
84950
  const anchoredByParagraph = collectAnchoredDrawings(blocks2, measures);
84690
84951
  const anchoredTablesByParagraph = collectAnchoredTables(blocks2, measures);
@@ -84716,10 +84977,10 @@ ${l}
84716
84977
  if (alignV === "top") {
84717
84978
  anchorY = offsetV;
84718
84979
  } else if (alignV === "bottom") {
84719
- const pageHeight = contentBottom + margins.bottom;
84980
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84720
84981
  anchorY = pageHeight - imageHeight + offsetV;
84721
84982
  } else if (alignV === "center") {
84722
- const pageHeight = contentBottom + margins.bottom;
84983
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84723
84984
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
84724
84985
  } else {
84725
84986
  anchorY = offsetV;
@@ -84730,11 +84991,11 @@ ${l}
84730
84991
  const anchorX = entry.block.anchor ? computeAnchorX(
84731
84992
  entry.block.anchor,
84732
84993
  state2.columnIndex,
84733
- normalizeColumns(activeColumns, contentWidth),
84994
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84734
84995
  entry.measure.width,
84735
- { left: margins.left, right: margins.right },
84996
+ { left: activeLeftMargin, right: activeRightMargin },
84736
84997
  activePageSize.w
84737
- ) : margins.left;
84998
+ ) : activeLeftMargin;
84738
84999
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
84739
85000
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
84740
85001
  }
@@ -84772,8 +85033,12 @@ ${l}
84772
85033
  const sectionState = {
84773
85034
  activeTopMargin,
84774
85035
  activeBottomMargin,
85036
+ activeLeftMargin,
85037
+ activeRightMargin,
84775
85038
  pendingTopMargin,
84776
85039
  pendingBottomMargin,
85040
+ pendingLeftMargin,
85041
+ pendingRightMargin,
84777
85042
  activeHeaderDistance,
84778
85043
  activeFooterDistance,
84779
85044
  pendingHeaderDistance,
@@ -84807,8 +85072,12 @@ ${l}
84807
85072
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
84808
85073
  activeTopMargin = updatedState.activeTopMargin;
84809
85074
  activeBottomMargin = updatedState.activeBottomMargin;
85075
+ activeLeftMargin = updatedState.activeLeftMargin;
85076
+ activeRightMargin = updatedState.activeRightMargin;
84810
85077
  pendingTopMargin = updatedState.pendingTopMargin;
84811
85078
  pendingBottomMargin = updatedState.pendingBottomMargin;
85079
+ pendingLeftMargin = updatedState.pendingLeftMargin;
85080
+ pendingRightMargin = updatedState.pendingRightMargin;
84812
85081
  activeHeaderDistance = updatedState.activeHeaderDistance;
84813
85082
  activeFooterDistance = updatedState.activeFooterDistance;
84814
85083
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -84946,8 +85215,8 @@ ${l}
84946
85215
  pageMargins: {
84947
85216
  top: activeTopMargin,
84948
85217
  bottom: activeBottomMargin,
84949
- left: margins.left,
84950
- right: margins.right
85218
+ left: activeLeftMargin,
85219
+ right: activeRightMargin
84951
85220
  },
84952
85221
  columns: getCurrentColumns(),
84953
85222
  placedAnchoredIds
@@ -84969,9 +85238,9 @@ ${l}
84969
85238
  const cols = getCurrentColumns();
84970
85239
  let maxWidth;
84971
85240
  if (relativeFrom === "page") {
84972
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
85241
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
84973
85242
  } else if (relativeFrom === "margin") {
84974
- maxWidth = activePageSize.w - margins.left - margins.right;
85243
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84975
85244
  } else {
84976
85245
  maxWidth = cols.width;
84977
85246
  }
@@ -86158,11 +86427,11 @@ ${l}
86158
86427
  if (text2.length === 0) return null;
86159
86428
  const clampedPos = Math.max(0, Math.min(localPos, text2.length));
86160
86429
  let wordStart = clampedPos;
86161
- while (wordStart > 0 && isWordChar(text2[wordStart - 1])) {
86430
+ while (wordStart > 0 && isWordChar$2(text2[wordStart - 1])) {
86162
86431
  wordStart--;
86163
86432
  }
86164
86433
  let wordEnd = clampedPos;
86165
- while (wordEnd < text2.length && isWordChar(text2[wordEnd])) {
86434
+ while (wordEnd < text2.length && isWordChar$2(text2[wordEnd])) {
86166
86435
  wordEnd++;
86167
86436
  }
86168
86437
  if (wordStart === wordEnd) {
@@ -86225,7 +86494,7 @@ ${l}
86225
86494
  }
86226
86495
  return null;
86227
86496
  }
86228
- function isWordChar(char) {
86497
+ function isWordChar$2(char) {
86229
86498
  return /[\p{L}\p{N}_]/u.test(char);
86230
86499
  }
86231
86500
  function isWhitespace$1(char) {
@@ -86260,6 +86529,29 @@ ${l}
86260
86529
  function runText(run2) {
86261
86530
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
86262
86531
  }
86532
+ const isWordChar$1 = (char) => {
86533
+ if (!char) return false;
86534
+ const code2 = char.charCodeAt(0);
86535
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
86536
+ };
86537
+ const capitalizeText$1 = (text2, fullText, startOffset) => {
86538
+ if (!text2) return text2;
86539
+ const hasFullText = typeof startOffset === "number" && fullText != null;
86540
+ let result = "";
86541
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
86542
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
86543
+ const ch = text2[i2];
86544
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
86545
+ }
86546
+ return result;
86547
+ };
86548
+ const applyTextTransform$1 = (text2, transform, fullText, startOffset) => {
86549
+ if (!text2 || !transform || transform === "none") return text2;
86550
+ if (transform === "uppercase") return text2.toUpperCase();
86551
+ if (transform === "lowercase") return text2.toLowerCase();
86552
+ if (transform === "capitalize") return capitalizeText$1(text2, fullText, startOffset);
86553
+ return text2;
86554
+ };
86263
86555
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
86264
86556
  const TWIPS_PER_INCH$4 = 1440;
86265
86557
  const PX_PER_INCH$3 = 96;
@@ -86268,6 +86560,13 @@ ${l}
86268
86560
  const WIDTH_FUDGE_PX = 0.5;
86269
86561
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
86270
86562
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
86563
+ const markerFontString = (run2) => {
86564
+ const size2 = run2?.fontSize ?? 16;
86565
+ const family = run2?.fontFamily ?? "Arial";
86566
+ const italic = run2?.italic ? "italic " : "";
86567
+ const bold = run2?.bold ? "bold " : "";
86568
+ return `${italic}${bold}${size2}px ${family}`.trim();
86569
+ };
86271
86570
  const buildTabStopsPx$1 = (indent2, tabs, tabIntervalTwips) => {
86272
86571
  const paragraphIndentTwips = {
86273
86572
  left: pxToTwips$1(Math.max(0, indent2?.left ?? 0)),
@@ -86298,7 +86597,8 @@ ${l}
86298
86597
  };
86299
86598
  function measureRunSliceWidth(run2, fromChar, toChar) {
86300
86599
  const context = getCtx();
86301
- const text2 = runText(run2).slice(fromChar, toChar);
86600
+ const fullText = runText(run2);
86601
+ const text2 = applyTextTransform$1(fullText.slice(fromChar, toChar), run2.textTransform, fullText, fromChar);
86302
86602
  if (!context) {
86303
86603
  const textRun = isTextRun$2(run2) ? run2 : null;
86304
86604
  const size2 = textRun?.fontSize ?? 16;
@@ -86344,8 +86644,21 @@ ${l}
86344
86644
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
86345
86645
  const markerTextStartX = wordLayout?.marker?.textStartX;
86346
86646
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
86347
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
86348
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86647
+ const resolvedTextStartPx = resolveListTextStartPx(
86648
+ wordLayout,
86649
+ indentLeft,
86650
+ indentFirstLine,
86651
+ indentHanging,
86652
+ (markerText, marker) => {
86653
+ const context = getCtx();
86654
+ if (!context) return 0;
86655
+ context.font = markerFontString(marker.run);
86656
+ return context.measureText(markerText).width;
86657
+ }
86658
+ );
86659
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
86660
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
86661
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86349
86662
  const tabStops = buildTabStopsPx$1(indent2, attrs?.tabs, attrs?.tabIntervalTwips);
86350
86663
  let currentRun = 0;
86351
86664
  let currentChar = 0;
@@ -86885,7 +87198,7 @@ ${l}
86885
87198
  if (dirty.deletedBlockIds.length > 0) {
86886
87199
  measureCache.invalidate(dirty.deletedBlockIds);
86887
87200
  }
86888
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
87201
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
86889
87202
  if (measurementWidth <= 0 || measurementHeight <= 0) {
86890
87203
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
86891
87204
  }
@@ -87154,7 +87467,7 @@ ${l}
87154
87467
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
87155
87468
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
87156
87469
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
87157
- function resolveMeasurementConstraints(options) {
87470
+ function resolveMeasurementConstraints(options, blocks2) {
87158
87471
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
87159
87472
  const margins = {
87160
87473
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -87162,23 +87475,41 @@ ${l}
87162
87475
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
87163
87476
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
87164
87477
  };
87165
- const contentWidth = pageSize.w - (margins.left + margins.right);
87166
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
87167
- const columns = options.columns;
87168
- if (columns && columns.count > 1) {
87478
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
87479
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
87480
+ const computeColumnWidth = (contentWidth, columns) => {
87481
+ if (!columns || columns.count <= 1) return contentWidth;
87169
87482
  const gap = Math.max(0, columns.gap ?? 0);
87170
87483
  const totalGap = gap * (columns.count - 1);
87171
- const columnWidth = (contentWidth - totalGap) / columns.count;
87172
- if (columnWidth > 0) {
87173
- return {
87174
- measurementWidth: columnWidth,
87175
- measurementHeight: contentHeight
87484
+ return (contentWidth - totalGap) / columns.count;
87485
+ };
87486
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
87487
+ let measurementHeight = baseContentHeight;
87488
+ if (blocks2 && blocks2.length > 0) {
87489
+ for (const block of blocks2) {
87490
+ if (block.kind !== "sectionBreak") continue;
87491
+ const sectionPageSize = block.pageSize ?? pageSize;
87492
+ const sectionMargins = {
87493
+ top: normalizeMargin(block.margins?.top, margins.top),
87494
+ right: normalizeMargin(block.margins?.right, margins.right),
87495
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
87496
+ left: normalizeMargin(block.margins?.left, margins.left)
87176
87497
  };
87498
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
87499
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
87500
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
87501
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
87502
+ if (columnWidth > measurementWidth) {
87503
+ measurementWidth = columnWidth;
87504
+ }
87505
+ if (contentHeight > measurementHeight) {
87506
+ measurementHeight = contentHeight;
87507
+ }
87177
87508
  }
87178
87509
  }
87179
87510
  return {
87180
- measurementWidth: contentWidth,
87181
- measurementHeight: contentHeight
87511
+ measurementWidth,
87512
+ measurementHeight
87182
87513
  };
87183
87514
  }
87184
87515
  const serializeHeaderFooterResults = (kind, batch2) => {
@@ -93156,8 +93487,8 @@ ${l}
93156
93487
  }
93157
93488
  return void 0;
93158
93489
  }
93159
- const DEFAULT_LIST_HANGING_PX$1 = 18;
93160
- const LIST_MARKER_GAP$1 = 8;
93490
+ const DEFAULT_LIST_HANGING_PX = 18;
93491
+ const LIST_MARKER_GAP = 8;
93161
93492
  const DEFAULT_BULLET_GLYPH = "•";
93162
93493
  const DEFAULT_DECIMAL_PATTERN = "%1.";
93163
93494
  const ASCII_UPPERCASE_A = 65;
@@ -93568,7 +93899,7 @@ ${l}
93568
93899
  let markerBoxWidthPx;
93569
93900
  let markerX;
93570
93901
  if (hasFirstLineIndent) {
93571
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
93902
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
93572
93903
  markerX = indentLeftPx + (firstLinePx ?? 0);
93573
93904
  layout.textStartPx = markerX + markerBoxWidthPx;
93574
93905
  layout.hangingPx = 0;
@@ -93668,12 +93999,12 @@ ${l}
93668
93999
  let markerBox = Math.max(hangingPxRaw || 0, 0);
93669
94000
  if (markerBox <= 0) {
93670
94001
  if (glyphWidthPx != null && glyphWidthPx > 0) {
93671
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94002
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93672
94003
  } else {
93673
- markerBox = DEFAULT_LIST_HANGING_PX$1;
94004
+ markerBox = DEFAULT_LIST_HANGING_PX;
93674
94005
  }
93675
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
93676
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94006
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
94007
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93677
94008
  }
93678
94009
  return markerBox;
93679
94010
  };
@@ -93693,7 +94024,7 @@ ${l}
93693
94024
  textStartX: textStartPx,
93694
94025
  baselineOffsetPx: markerRun.baselineShift ?? 0,
93695
94026
  // Gutter is the small gap between marker and text, not the full marker box width
93696
- gutterWidthPx: LIST_MARKER_GAP$1,
94027
+ gutterWidthPx: LIST_MARKER_GAP,
93697
94028
  justification: numbering.lvlJc ?? "left",
93698
94029
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
93699
94030
  run: markerRun,
@@ -94385,6 +94716,31 @@ ${l}
94385
94716
  return null;
94386
94717
  }
94387
94718
  };
94719
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
94720
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
94721
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
94722
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
94723
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
94724
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
94725
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
94726
+ wordLayout.firstLineIndentMode = false;
94727
+ }
94728
+ if (wordLayout.firstLineIndentMode === true) {
94729
+ if (isFiniteNumber(wordLayout.textStartPx)) {
94730
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
94731
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
94732
+ }
94733
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
94734
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
94735
+ }
94736
+ } else {
94737
+ wordLayout.textStartPx = indentLeft;
94738
+ if (wordLayout.marker) {
94739
+ wordLayout.marker.textStartX = indentLeft;
94740
+ }
94741
+ }
94742
+ return wordLayout;
94743
+ };
94388
94744
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
94389
94745
  const attrs = para.attrs ?? {};
94390
94746
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -94707,8 +95063,11 @@ ${l}
94707
95063
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
94708
95064
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
94709
95065
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94710
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94711
- if (firstLinePx > 0) {
95066
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95067
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95068
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95069
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95070
+ if (firstLinePx > 0 && !hangingPx) {
94712
95071
  wordLayout = {
94713
95072
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
94714
95073
  firstLineIndentMode: true,
@@ -94716,10 +95075,13 @@ ${l}
94716
95075
  };
94717
95076
  }
94718
95077
  }
94719
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
95078
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
94720
95079
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94721
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94722
- if (firstLinePx > 0) {
95080
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95081
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95082
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95083
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95084
+ if (firstLinePx > 0 && !hangingPx) {
94723
95085
  wordLayout = {
94724
95086
  ...wordLayout,
94725
95087
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -94739,6 +95101,7 @@ ${l}
94739
95101
  wordLayout.marker.suffix = listRendering.suffix;
94740
95102
  }
94741
95103
  }
95104
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
94742
95105
  paragraphAttrs.wordLayout = wordLayout;
94743
95106
  }
94744
95107
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -98855,11 +99218,6 @@ ${l}
98855
99218
  cleanups
98856
99219
  };
98857
99220
  }
98858
- const LIST_MARKER_GAP = 8;
98859
- const MIN_MARKER_GUTTER = 24;
98860
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
98861
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
98862
- const DEFAULT_LIST_HANGING_PX = 18;
98863
99221
  function calculateRotatedBounds(input2) {
98864
99222
  const width = Math.max(0, input2.width);
98865
99223
  const height = Math.max(0, input2.height);
@@ -99123,8 +99481,25 @@ ${l}
99123
99481
  const rawTextStartPx = wordLayout?.textStartPx;
99124
99482
  const markerTextStartX = wordLayout?.marker?.textStartX;
99125
99483
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
99126
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
99127
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
99484
+ const resolvedTextStartPx = resolveListTextStartPx(
99485
+ wordLayout,
99486
+ indentLeft,
99487
+ firstLine,
99488
+ hanging,
99489
+ (markerText, marker) => {
99490
+ const markerRun = {
99491
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
99492
+ fontSize: marker.run?.fontSize ?? 16,
99493
+ bold: marker.run?.bold ?? false,
99494
+ italic: marker.run?.italic ?? false
99495
+ };
99496
+ const { font: markerFont } = buildFontString(markerRun);
99497
+ return measureText(markerText, markerFont, ctx2);
99498
+ }
99499
+ );
99500
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
99501
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
99502
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
99128
99503
  } else {
99129
99504
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
99130
99505
  }
@@ -99211,7 +99586,7 @@ ${l}
99211
99586
  pendingTabAlignment = null;
99212
99587
  return startX;
99213
99588
  };
99214
- const alignSegmentAtTab = (segmentText, font, runContext) => {
99589
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
99215
99590
  if (!pendingTabAlignment || !currentLine) return void 0;
99216
99591
  const { val } = pendingTabAlignment;
99217
99592
  let segmentWidth = 0;
@@ -99220,11 +99595,11 @@ ${l}
99220
99595
  const idx = segmentText.indexOf(decimalSeparator);
99221
99596
  if (idx >= 0) {
99222
99597
  const beforeText = segmentText.slice(0, idx);
99223
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
99598
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
99224
99599
  }
99225
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99600
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99226
99601
  } else if (val === "end" || val === "center") {
99227
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99602
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99228
99603
  }
99229
99604
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
99230
99605
  };
@@ -99276,8 +99651,8 @@ ${l}
99276
99651
  const { font } = buildFontString(
99277
99652
  lastRun
99278
99653
  );
99279
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
99280
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
99654
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
99655
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
99281
99656
  const delta = Math.max(0, fullWidth - keptWidth);
99282
99657
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
99283
99658
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -99488,7 +99863,8 @@ ${l}
99488
99863
  continue;
99489
99864
  }
99490
99865
  if (isFieldAnnotationRun(run2)) {
99491
- const displayText = run2.displayLabel || "";
99866
+ const rawDisplayText = run2.displayLabel || "";
99867
+ const displayText = applyTextTransform(rawDisplayText, run2);
99492
99868
  const annotationFontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
99493
99869
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
99494
99870
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -99591,7 +99967,7 @@ ${l}
99591
99967
  const spacesLength = segment.length;
99592
99968
  const spacesStartChar = charPosInRun;
99593
99969
  const spacesEndChar = charPosInRun + spacesLength;
99594
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
99970
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
99595
99971
  if (!currentLine) {
99596
99972
  currentLine = {
99597
99973
  fromRun: runIndex,
@@ -99655,7 +100031,7 @@ ${l}
99655
100031
  }
99656
100032
  let segmentStartX;
99657
100033
  if (currentLine && pendingTabAlignment) {
99658
- segmentStartX = alignSegmentAtTab(segment, font, run2);
100034
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
99659
100035
  if (segmentStartX == null) {
99660
100036
  segmentStartX = currentLine.width;
99661
100037
  }
@@ -99665,7 +100041,7 @@ ${l}
99665
100041
  if (word2 === "") {
99666
100042
  const spaceStartChar = charPosInRun;
99667
100043
  const spaceEndChar = charPosInRun + 1;
99668
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
100044
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
99669
100045
  if (!currentLine) {
99670
100046
  currentLine = {
99671
100047
  fromRun: runIndex,
@@ -99716,12 +100092,12 @@ ${l}
99716
100092
  charPosInRun = spaceEndChar;
99717
100093
  continue;
99718
100094
  }
99719
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
99720
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99721
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
99722
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
99723
100095
  const wordStartChar = charPosInRun;
100096
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
100097
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99724
100098
  const wordEndNoSpace = charPosInRun + word2.length;
100099
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
100100
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
99725
100101
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
99726
100102
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
99727
100103
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -99740,7 +100116,7 @@ ${l}
99740
100116
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
99741
100117
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
99742
100118
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
99743
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
100119
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
99744
100120
  let chunkCharOffset = wordStartChar;
99745
100121
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
99746
100122
  const chunk = chunks[chunkIndex];
@@ -99864,7 +100240,7 @@ ${l}
99864
100240
  if (candidateSpaces > 0) {
99865
100241
  const overflow = totalWidthWithWord - availableWidth;
99866
100242
  if (overflow > 0) {
99867
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
100243
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
99868
100244
  const perSpaceCompression = overflow / candidateSpaces;
99869
100245
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
99870
100246
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -100039,8 +100415,8 @@ ${l}
100039
100415
  const { font: markerFont } = buildFontString(markerRun);
100040
100416
  const markerText = wordLayout.marker.markerText ?? "";
100041
100417
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100042
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
100043
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
100418
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
100419
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
100044
100420
  markerInfo = {
100045
100421
  markerWidth: markerBoxWidth,
100046
100422
  markerTextWidth: glyphWidth,
@@ -100384,7 +100760,7 @@ ${l}
100384
100760
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100385
100761
  indentLeft = resolveIndentLeft(item);
100386
100762
  const indentHanging = resolveIndentHanging(item);
100387
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
100763
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
100388
100764
  }
100389
100765
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
100390
100766
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -100410,16 +100786,46 @@ ${l}
100410
100786
  fontSize: 16
100411
100787
  };
100412
100788
  };
100413
- const measureRunWidth = (text2, font, ctx2, run2) => {
100789
+ const isWordChar = (char) => {
100790
+ if (!char) return false;
100791
+ const code2 = char.charCodeAt(0);
100792
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
100793
+ };
100794
+ const capitalizeText = (text2, fullText, startOffset) => {
100795
+ if (!text2) return text2;
100796
+ const hasFullText = typeof startOffset === "number" && fullText != null;
100797
+ let result = "";
100798
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
100799
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
100800
+ const ch = text2[i2];
100801
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
100802
+ }
100803
+ return result;
100804
+ };
100805
+ const applyTextTransform = (text2, run2, startOffset) => {
100806
+ const transform = run2.textTransform;
100807
+ if (!text2 || !transform || transform === "none") return text2;
100808
+ if (transform === "uppercase") return text2.toUpperCase();
100809
+ if (transform === "lowercase") return text2.toLowerCase();
100810
+ if (transform === "capitalize") {
100811
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text2;
100812
+ return capitalizeText(text2, fullText, startOffset);
100813
+ }
100814
+ return text2;
100815
+ };
100816
+ const measureRunWidth = (text2, font, ctx2, run2, startOffset) => {
100414
100817
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
100415
- const width = getMeasuredTextWidth(text2, font, letterSpacing, ctx2);
100818
+ const displayText = applyTextTransform(text2, run2, startOffset);
100819
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
100416
100820
  return roundValue(width);
100417
100821
  };
100418
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
100822
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
100419
100823
  const chunks = [];
100824
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
100420
100825
  if (maxWidth <= 0) {
100421
- for (const char of word2) {
100422
- const charWidth = measureRunWidth(char, font, ctx2, run2);
100826
+ for (let i2 = 0; i2 < word2.length; i2++) {
100827
+ const char = word2[i2];
100828
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100423
100829
  chunks.push({ text: char, width: charWidth });
100424
100830
  }
100425
100831
  return chunks;
@@ -100429,11 +100835,11 @@ ${l}
100429
100835
  for (let i2 = 0; i2 < word2.length; i2++) {
100430
100836
  const char = word2[i2];
100431
100837
  const testChunk = currentChunk + char;
100432
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
100838
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
100433
100839
  if (testWidth > maxWidth && currentChunk.length > 0) {
100434
100840
  chunks.push({ text: currentChunk, width: currentWidth });
100435
100841
  currentChunk = char;
100436
- currentWidth = measureRunWidth(char, font, ctx2, run2);
100842
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100437
100843
  } else {
100438
100844
  currentChunk = testChunk;
100439
100845
  currentWidth = testWidth;
@@ -100487,7 +100893,8 @@ ${l}
100487
100893
  italic: run2.italic
100488
100894
  });
100489
100895
  ctx2.font = font;
100490
- const metrics = ctx2.measureText(run2.text);
100896
+ const displayText = applyTextTransform(run2.text, run2);
100897
+ const metrics = ctx2.measureText(displayText);
100491
100898
  const advanceWidth = metrics.width;
100492
100899
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
100493
100900
  const textWidth = Math.max(advanceWidth, paintedWidth);
@@ -100513,7 +100920,7 @@ ${l}
100513
100920
  if (indentHanging > 0) {
100514
100921
  return indentHanging;
100515
100922
  }
100516
- return DEFAULT_LIST_HANGING_PX;
100923
+ return DEFAULT_LIST_HANGING_PX$1;
100517
100924
  };
100518
100925
  const buildTabStopsPx = (indent2, tabs, tabIntervalTwips) => {
100519
100926
  const paragraphIndentTwips = {
@@ -157258,7 +157665,7 @@ ${style2}
157258
157665
  this.config.colors = shuffleArray(this.config.colors);
157259
157666
  this.userColorMap = /* @__PURE__ */ new Map();
157260
157667
  this.colorIndex = 0;
157261
- this.version = "2.0.0-next.2";
157668
+ this.version = "2.0.0-next.3";
157262
157669
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
157263
157670
  this.superdocId = config2.superdocId || v4();
157264
157671
  this.colors = this.config.colors;
@@ -159731,7 +160138,7 @@ ${style2}
159731
160138
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
159732
160139
  );
159733
160140
  }
159734
- const indexBqPa6D4q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
160141
+ const indexLLnrqNSJ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
159735
160142
  __proto__: null,
159736
160143
  unified
159737
160144
  }, Symbol.toStringTag, { value: "Module" }));