@harbour-enterprises/superdoc 2.0.0-next.1 → 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 (28) hide show
  1. package/dist/chunks/{PdfViewer-BDQHgDVD.es.js → PdfViewer-4xn9rggA.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-Cun5Zr8u.cjs → PdfViewer-C6tuSJXA.cjs} +1 -1
  3. package/dist/chunks/{index-CGAmeAEK.es.js → index-CSZ7bAL7.es.js} +3 -3
  4. package/dist/chunks/{index-if-EH8uU.cjs → index-k0xTe_8v.cjs} +3 -3
  5. package/dist/chunks/{index-Dq6vXk74-Vm-euNb7.cjs → index-lLnrqNSJ-CMJxa5vJ.cjs} +1 -1
  6. package/dist/chunks/{index-Dq6vXk74-CQD7nLbH.es.js → index-lLnrqNSJ-DoACeFqL.es.js} +1 -1
  7. package/dist/chunks/{super-editor.es-DyaHVXrq.es.js → super-editor.es-B1DZfUz0.es.js} +558 -132
  8. package/dist/chunks/{super-editor.es-CwNpXZzP.cjs → super-editor.es-BY4paJvP.cjs} +558 -132
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-BtoNJWI9.js → converter-Bd6dIe0l.js} +1 -1
  12. package/dist/super-editor/chunks/{docx-zipper-CLkDdGOr.js → docx-zipper-Dzdi5pfi.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-COH8793Z.js → editor-C3sjGwAb.js} +568 -149
  14. package/dist/super-editor/chunks/{index-Dq6vXk74.js → index-lLnrqNSJ.js} +1 -1
  15. package/dist/super-editor/chunks/{toolbar-Ca-BPuJ2.js → toolbar-Bn20lflQ.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/super-editor.es.js +28 -14
  21. package/dist/super-editor/toolbar.es.js +2 -2
  22. package/dist/super-editor.cjs +1 -1
  23. package/dist/super-editor.es.js +1 -1
  24. package/dist/superdoc.cjs +2 -2
  25. package/dist/superdoc.es.js +2 -2
  26. package/dist/superdoc.umd.js +560 -134
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +1 -1
@@ -42427,7 +42427,7 @@ const _SuperConverter = class _SuperConverter2 {
42427
42427
  static getStoredSuperdocVersion(docx) {
42428
42428
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42429
42429
  }
42430
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.1") {
42430
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.3") {
42431
42431
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42432
42432
  }
42433
42433
  /**
@@ -60508,7 +60508,7 @@ const isHeadless = (editor) => {
60508
60508
  const shouldSkipNodeView = (editor) => {
60509
60509
  return isHeadless(editor);
60510
60510
  };
60511
- const summaryVersion = "2.0.0-next.1";
60511
+ const summaryVersion = "2.0.0-next.3";
60512
60512
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
60513
60513
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
60514
60514
  function mapAttributes(attrs) {
@@ -61297,7 +61297,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61297
61297
  { default: remarkStringify },
61298
61298
  { default: remarkGfm }
61299
61299
  ] = await Promise.all([
61300
- Promise.resolve().then(() => require("./index-Dq6vXk74-Vm-euNb7.cjs")),
61300
+ Promise.resolve().then(() => require("./index-lLnrqNSJ-CMJxa5vJ.cjs")),
61301
61301
  Promise.resolve().then(() => require("./index-DRCvimau-H4Ck3S9a.cjs")),
61302
61302
  Promise.resolve().then(() => require("./index-C_x_N6Uh-Db3CUJMX.cjs")),
61303
61303
  Promise.resolve().then(() => require("./index-D_sWOSiG-BtDZzJ6I.cjs")),
@@ -61502,7 +61502,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61502
61502
  * Process collaboration migrations
61503
61503
  */
61504
61504
  processCollaborationMigrations() {
61505
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.1");
61505
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.3");
61506
61506
  if (!this.options.ydoc) return;
61507
61507
  const metaMap = this.options.ydoc.getMap("meta");
61508
61508
  let docVersion = metaMap.get("version");
@@ -68754,7 +68754,7 @@ function isMinimalWordLayout(value) {
68754
68754
  return true;
68755
68755
  }
68756
68756
  const LIST_MARKER_GAP$2 = 8;
68757
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
68757
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
68758
68758
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
68759
68759
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
68760
68760
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -69681,6 +69681,7 @@ const _DomPainter = class _DomPainter2 {
69681
69681
  const block = lookup2.block;
69682
69682
  const measure = lookup2.measure;
69683
69683
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
69684
+ const alignment2 = block.attrs?.alignment;
69684
69685
  const fragmentEl = this.doc.createElement("div");
69685
69686
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
69686
69687
  const isTocEntry = block.attrs?.isTocEntry;
@@ -69759,7 +69760,7 @@ const _DomPainter = class _DomPainter2 {
69759
69760
  const textStart = paraIndentLeft + firstLine;
69760
69761
  tabWidth = textStart - currentPos;
69761
69762
  if (tabWidth <= 0) {
69762
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
69763
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69763
69764
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69764
69765
  tabWidth = LIST_MARKER_GAP$2;
69765
69766
  }
@@ -69786,6 +69787,21 @@ const _DomPainter = class _DomPainter2 {
69786
69787
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
69787
69788
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
69788
69789
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
69790
+ if (alignment2 === "justify" || alignment2 === "both") {
69791
+ console.log(
69792
+ "[justify-debug][painter-firstline-available]",
69793
+ JSON.stringify({
69794
+ blockId: block.id,
69795
+ fragmentWidth: fragment.width,
69796
+ markerTabWidth: listFirstLineMarkerTabWidth,
69797
+ paraIndentRight,
69798
+ availableWidthOverride,
69799
+ lineMaxWidth: line.maxWidth ?? null,
69800
+ lineWidth: line.width,
69801
+ lineNaturalWidth: line.naturalWidth ?? null
69802
+ })
69803
+ );
69804
+ }
69789
69805
  }
69790
69806
  const isLastLineOfFragment = index2 === lines.length - 1;
69791
69807
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -69911,7 +69927,7 @@ const _DomPainter = class _DomPainter2 {
69911
69927
  const textStart = paraIndentLeft + firstLine;
69912
69928
  tabWidth = textStart - currentPos;
69913
69929
  if (tabWidth <= 0) {
69914
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
69930
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69915
69931
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69916
69932
  tabWidth = LIST_MARKER_GAP$2;
69917
69933
  }
@@ -71445,6 +71461,23 @@ const _DomPainter = class _DomPainter2 {
71445
71461
  if (spacingPerSpace !== 0) {
71446
71462
  el.style.wordSpacing = `${spacingPerSpace}px`;
71447
71463
  }
71464
+ if (justifyShouldApply && spacingPerSpace < 0) {
71465
+ console.log(
71466
+ "[justify-debug][painter-wordspacing-negative]",
71467
+ JSON.stringify({
71468
+ blockId: block.id,
71469
+ lineIndex: lineIndex ?? null,
71470
+ alignment: alignment2 ?? null,
71471
+ availableWidth,
71472
+ lineWidth,
71473
+ lineMaxWidth: line.maxWidth ?? null,
71474
+ lineNaturalWidth: line.naturalWidth ?? null,
71475
+ spaceCount,
71476
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
71477
+ skipJustify: Boolean(skipJustify)
71478
+ })
71479
+ );
71480
+ }
71448
71481
  if (hasExplicitPositioning && line.segments) {
71449
71482
  const paraIndent = block.attrs?.indent;
71450
71483
  const indentLeft = paraIndent?.left ?? 0;
@@ -73638,6 +73671,28 @@ let measurementCtx = null;
73638
73671
  const TAB_CHAR_LENGTH = 1;
73639
73672
  const SPACE_CHARS = SPACE_CHARS$1;
73640
73673
  const isTabRun$1 = (run2) => run2?.kind === "tab";
73674
+ const isWordChar$3 = (char) => {
73675
+ if (!char) return false;
73676
+ const code = char.charCodeAt(0);
73677
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
73678
+ };
73679
+ const capitalizeText$2 = (text) => {
73680
+ if (!text) return text;
73681
+ let result = "";
73682
+ for (let i = 0; i < text.length; i += 1) {
73683
+ const prevChar = i > 0 ? text[i - 1] : "";
73684
+ const ch = text[i];
73685
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
73686
+ }
73687
+ return result;
73688
+ };
73689
+ const applyTextTransform$2 = (text, transform) => {
73690
+ if (!text || !transform || transform === "none") return text;
73691
+ if (transform === "uppercase") return text.toUpperCase();
73692
+ if (transform === "lowercase") return text.toLowerCase();
73693
+ if (transform === "capitalize") return capitalizeText$2(text);
73694
+ return text;
73695
+ };
73641
73696
  function getMeasurementContext() {
73642
73697
  if (measurementCtx) return measurementCtx;
73643
73698
  if (typeof document === "undefined") {
@@ -73813,17 +73868,18 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
73813
73868
  }
73814
73869
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73815
73870
  const runLength = text.length;
73871
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73816
73872
  if (currentCharOffset + runLength >= charOffset) {
73817
73873
  const offsetInRun = charOffset - currentCharOffset;
73818
73874
  ctx2.font = getRunFontString(run2);
73819
- const textUpToTarget = text.slice(0, offsetInRun);
73875
+ const textUpToTarget = displayText.slice(0, offsetInRun);
73820
73876
  const measured2 = ctx2.measureText(textUpToTarget);
73821
73877
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
73822
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
73878
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text.slice(0, offsetInRun)) : 0;
73823
73879
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
73824
73880
  }
73825
73881
  ctx2.font = getRunFontString(run2);
73826
- const measured = ctx2.measureText(text);
73882
+ const measured = ctx2.measureText(displayText);
73827
73883
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73828
73884
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text) : 0;
73829
73885
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -73862,8 +73918,9 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
73862
73918
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
73863
73919
  }
73864
73920
  const text = run2.text ?? "";
73865
- const segmentText = text.slice(segment.fromChar, segment.toChar);
73866
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
73921
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73922
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
73923
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
73867
73924
  ctx2.font = getRunFontString(run2);
73868
73925
  const measured = ctx2.measureText(textUpToTarget);
73869
73926
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -73959,12 +74016,13 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73959
74016
  }
73960
74017
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73961
74018
  const runLength = text.length;
74019
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73962
74020
  if (runLength === 0) continue;
73963
74021
  ctx2.font = getRunFontString(run2);
73964
74022
  for (let i = 0; i <= runLength; i++) {
73965
- const textUpToChar = text.slice(0, i);
74023
+ const textUpToChar = displayText.slice(0, i);
73966
74024
  const measured2 = ctx2.measureText(textUpToChar);
73967
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
74025
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text.slice(0, i)) : 0;
73968
74026
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
73969
74027
  if (charX >= safeX) {
73970
74028
  if (i === 0) {
@@ -73974,7 +74032,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73974
74032
  pmPosition: pmPosition3
73975
74033
  };
73976
74034
  }
73977
- const prevText = text.slice(0, i - 1);
74035
+ const prevText = displayText.slice(0, i - 1);
73978
74036
  const prevMeasured = ctx2.measureText(prevText);
73979
74037
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i - 1, runLength);
73980
74038
  const distToPrev = Math.abs(safeX - prevX);
@@ -73987,7 +74045,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73987
74045
  };
73988
74046
  }
73989
74047
  }
73990
- const measured = ctx2.measureText(text);
74048
+ const measured = ctx2.measureText(displayText);
73991
74049
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73992
74050
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
73993
74051
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -74418,6 +74476,83 @@ function findCharIndexAtX(textNode, container, targetX) {
74418
74476
  }
74419
74477
  return index2;
74420
74478
  }
74479
+ const LIST_MARKER_GAP$1 = 8;
74480
+ const MIN_MARKER_GUTTER = 24;
74481
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
74482
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
74483
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
74484
+ const SPACE_SUFFIX_GAP_PX = 4;
74485
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
74486
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
74487
+ const marker = wordLayout?.marker;
74488
+ if (!marker) {
74489
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
74490
+ return textStartPx;
74491
+ }
74492
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
74493
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
74494
+ if (markerTextWidth == null && marker.markerText) {
74495
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
74496
+ }
74497
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth < 0) {
74498
+ markerTextWidth = markerBoxWidth;
74499
+ }
74500
+ markerTextWidth = Math.max(0, markerTextWidth);
74501
+ let markerStartPos;
74502
+ if (wordLayout?.firstLineIndentMode === true && Number.isFinite(marker.markerX)) {
74503
+ markerStartPos = marker.markerX;
74504
+ } else {
74505
+ markerStartPos = indentLeft - hanging + firstLine;
74506
+ }
74507
+ if (!Number.isFinite(markerStartPos)) {
74508
+ markerStartPos = 0;
74509
+ }
74510
+ const currentPos = markerStartPos + markerTextWidth;
74511
+ const suffix2 = marker.suffix ?? "tab";
74512
+ if (suffix2 === "space") {
74513
+ return markerStartPos + markerTextWidth + SPACE_SUFFIX_GAP_PX;
74514
+ }
74515
+ if (suffix2 === "nothing") {
74516
+ return markerStartPos + markerTextWidth;
74517
+ }
74518
+ const markerJustification = marker.justification ?? "left";
74519
+ if (markerJustification !== "left") {
74520
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
74521
+ return markerStartPos + markerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
74522
+ }
74523
+ if (wordLayout?.firstLineIndentMode === true) {
74524
+ let targetTabStop;
74525
+ if (Array.isArray(wordLayout.tabsPx)) {
74526
+ for (const tab of wordLayout.tabsPx) {
74527
+ if (typeof tab === "number" && tab > currentPos) {
74528
+ targetTabStop = tab;
74529
+ break;
74530
+ }
74531
+ }
74532
+ }
74533
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
74534
+ let tabWidth2;
74535
+ if (targetTabStop !== void 0) {
74536
+ tabWidth2 = targetTabStop - currentPos;
74537
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
74538
+ tabWidth2 = textStartTarget - currentPos;
74539
+ } else {
74540
+ tabWidth2 = LIST_MARKER_GAP$1;
74541
+ }
74542
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
74543
+ tabWidth2 = LIST_MARKER_GAP$1;
74544
+ }
74545
+ return markerStartPos + markerTextWidth + tabWidth2;
74546
+ }
74547
+ const textStart = indentLeft + firstLine;
74548
+ let tabWidth = textStart - currentPos;
74549
+ if (tabWidth <= 0) {
74550
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
74551
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
74552
+ tabWidth = LIST_MARKER_GAP$1;
74553
+ }
74554
+ return markerStartPos + markerTextWidth + tabWidth;
74555
+ }
74421
74556
  function getWordLayoutConfig(block) {
74422
74557
  if (!block || block.kind !== "paragraph") {
74423
74558
  return void 0;
@@ -74450,9 +74585,16 @@ function calculateTextStartIndent(params2) {
74450
74585
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
74451
74586
  let indentAdjust = paraIndentLeft;
74452
74587
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
74588
+ const resolvedTextStart = resolveListTextStartPx(
74589
+ wordLayout,
74590
+ paraIndentLeft,
74591
+ Math.max(firstLineIndent, 0),
74592
+ Math.max(hangingIndent, 0),
74593
+ () => markerWidth
74594
+ // Use provided markerWidth since we don't have canvas access here
74595
+ );
74453
74596
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
74454
- const markerTextStartX = wordLayout?.marker?.textStartX;
74455
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
74597
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
74456
74598
  } else if (isFirstLine && !isListItem2) {
74457
74599
  indentAdjust += firstLineOffset;
74458
74600
  }
@@ -74608,7 +74750,10 @@ function getHeaderFooterTypeForSection(pageNumber, sectionIndex, identifier, opt
74608
74750
  }
74609
74751
  function createFloatingObjectManager(columns, margins, pageWidth) {
74610
74752
  const zones = [];
74611
- const marginLeft = Math.max(0, margins?.left ?? 0);
74753
+ let currentColumns = columns;
74754
+ let currentMargins = margins;
74755
+ let currentPageWidth = pageWidth;
74756
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
74612
74757
  return {
74613
74758
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
74614
74759
  if (!drawingBlock.anchor?.isAnchored) {
@@ -74621,7 +74766,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74621
74766
  }
74622
74767
  const objectWidth = measure.width ?? 0;
74623
74768
  const objectHeight = measure.height ?? 0;
74624
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
74769
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
74625
74770
  const y2 = anchorY + (anchor.offsetV ?? 0);
74626
74771
  const zone = {
74627
74772
  imageBlockId: drawingBlock.id,
@@ -74655,7 +74800,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74655
74800
  }
74656
74801
  const tableWidth = measure.totalWidth ?? 0;
74657
74802
  const tableHeight = measure.totalHeight ?? 0;
74658
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
74803
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
74659
74804
  const y2 = anchorY + (anchor.offsetV ?? 0);
74660
74805
  const zone = {
74661
74806
  imageBlockId: tableBlock.id,
@@ -74703,7 +74848,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74703
74848
  }
74704
74849
  const leftFloats = [];
74705
74850
  const rightFloats = [];
74706
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
74851
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
74707
74852
  const columnCenter = columnOrigin + baseWidth / 2;
74708
74853
  for (const zone of wrappingZones) {
74709
74854
  if (zone.wrapMode === "left") {
@@ -74742,6 +74887,22 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74742
74887
  },
74743
74888
  clear() {
74744
74889
  zones.length = 0;
74890
+ },
74891
+ /**
74892
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
74893
+ * This method should be called when the layout configuration changes (e.g., section breaks,
74894
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
74895
+ * correctly relative to the new layout boundaries.
74896
+ *
74897
+ * @param nextColumns - Column layout configuration (width, gap, count)
74898
+ * @param nextMargins - Optional page margins (left, right) in pixels
74899
+ * @param nextPageWidth - Optional total page width in pixels
74900
+ */
74901
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
74902
+ currentColumns = nextColumns;
74903
+ currentMargins = nextMargins;
74904
+ currentPageWidth = nextPageWidth;
74905
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
74745
74906
  }
74746
74907
  };
74747
74908
  }
@@ -74841,7 +75002,14 @@ function computeNextSectionPropsAtBreak(blocks) {
74841
75002
  const props = {};
74842
75003
  if (source.kind !== "sectionBreak") return props;
74843
75004
  if (source.margins) {
74844
- props.margins = { header: source.margins.header, footer: source.margins.footer };
75005
+ props.margins = {
75006
+ header: source.margins.header,
75007
+ footer: source.margins.footer,
75008
+ top: source.margins.top,
75009
+ right: source.margins.right,
75010
+ bottom: source.margins.bottom,
75011
+ left: source.margins.left
75012
+ };
74845
75013
  }
74846
75014
  if (source.pageSize) {
74847
75015
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -74889,20 +75057,36 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74889
75057
  next.activeOrientation = block.orientation;
74890
75058
  next.pendingOrientation = null;
74891
75059
  }
75060
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
75061
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
75062
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
75063
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
74892
75064
  if (block.margins?.header !== void 0) {
74893
- const headerDistance = Math.max(0, block.margins.header);
74894
75065
  next.activeHeaderDistance = headerDistance;
74895
75066
  next.pendingHeaderDistance = headerDistance;
74896
- next.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
74897
- next.pendingTopMargin = next.activeTopMargin;
74898
75067
  }
74899
75068
  if (block.margins?.footer !== void 0) {
74900
- const footerDistance = Math.max(0, block.margins.footer);
74901
75069
  next.activeFooterDistance = footerDistance;
74902
75070
  next.pendingFooterDistance = footerDistance;
74903
- next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
75071
+ }
75072
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
75073
+ next.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
75074
+ next.pendingTopMargin = next.activeTopMargin;
75075
+ }
75076
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
75077
+ next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
74904
75078
  next.pendingBottomMargin = next.activeBottomMargin;
74905
75079
  }
75080
+ if (block.margins?.left !== void 0) {
75081
+ const leftMargin = Math.max(0, block.margins.left);
75082
+ next.activeLeftMargin = leftMargin;
75083
+ next.pendingLeftMargin = leftMargin;
75084
+ }
75085
+ if (block.margins?.right !== void 0) {
75086
+ const rightMargin = Math.max(0, block.margins.right);
75087
+ next.activeRightMargin = rightMargin;
75088
+ next.pendingRightMargin = rightMargin;
75089
+ }
74906
75090
  if (block.columns) {
74907
75091
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
74908
75092
  next.pendingColumns = null;
@@ -74911,26 +75095,42 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74911
75095
  }
74912
75096
  const headerPx = block.margins?.header;
74913
75097
  const footerPx = block.margins?.footer;
75098
+ const topPx = block.margins?.top;
75099
+ const bottomPx = block.margins?.bottom;
74914
75100
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
74915
75101
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
75102
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
75103
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
74916
75104
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
74917
75105
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
74918
- if (typeof headerPx === "number") {
74919
- const newHeaderDist = Math.max(0, headerPx);
75106
+ if (typeof headerPx === "number" || typeof topPx === "number") {
75107
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
75108
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
74920
75109
  next.pendingHeaderDistance = newHeaderDist;
74921
- next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
75110
+ next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
74922
75111
  } else {
74923
75112
  next.pendingTopMargin = nextTop;
74924
75113
  next.pendingHeaderDistance = nextHeader;
74925
75114
  }
74926
- if (typeof footerPx === "number") {
74927
- const newFooterDist = Math.max(0, footerPx);
75115
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
75116
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
75117
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
74928
75118
  next.pendingFooterDistance = newFooterDist;
74929
- next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
75119
+ next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
74930
75120
  } else {
74931
75121
  next.pendingBottomMargin = nextBottom;
74932
75122
  next.pendingFooterDistance = nextFooter;
74933
75123
  }
75124
+ if (typeof block.margins?.left === "number") {
75125
+ next.pendingLeftMargin = Math.max(0, block.margins.left);
75126
+ } else {
75127
+ next.pendingLeftMargin = nextLeft;
75128
+ }
75129
+ if (typeof block.margins?.right === "number") {
75130
+ next.pendingRightMargin = Math.max(0, block.margins.right);
75131
+ } else {
75132
+ next.pendingRightMargin = nextRight;
75133
+ }
74934
75134
  if (block.pageSize) {
74935
75135
  next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
74936
75136
  }
@@ -74990,6 +75190,12 @@ function applyPendingToActive(state2) {
74990
75190
  if (next.pendingBottomMargin != null) {
74991
75191
  next.activeBottomMargin = next.pendingBottomMargin;
74992
75192
  }
75193
+ if (next.pendingLeftMargin != null) {
75194
+ next.activeLeftMargin = next.pendingLeftMargin;
75195
+ }
75196
+ if (next.pendingRightMargin != null) {
75197
+ next.activeRightMargin = next.pendingRightMargin;
75198
+ }
74993
75199
  if (next.pendingHeaderDistance != null) {
74994
75200
  next.activeHeaderDistance = next.pendingHeaderDistance;
74995
75201
  }
@@ -75007,6 +75213,8 @@ function applyPendingToActive(state2) {
75007
75213
  }
75008
75214
  next.pendingTopMargin = null;
75009
75215
  next.pendingBottomMargin = null;
75216
+ next.pendingLeftMargin = null;
75217
+ next.pendingRightMargin = null;
75010
75218
  next.pendingHeaderDistance = null;
75011
75219
  next.pendingFooterDistance = null;
75012
75220
  next.pendingPageSize = null;
@@ -75235,7 +75443,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75235
75443
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
75236
75444
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75237
75445
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
75238
- lines = normalizeLines(newMeasure);
75446
+ const newLines = normalizeLines(newMeasure);
75447
+ lines = newLines;
75239
75448
  didRemeasureForColumnWidth = true;
75240
75449
  }
75241
75450
  let fromLine = 0;
@@ -75317,7 +75526,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75317
75526
  if (narrowestRemeasureWidth < remeasureWidth) {
75318
75527
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75319
75528
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
75320
- lines = normalizeLines(newMeasure);
75529
+ const newLines = normalizeLines(newMeasure);
75530
+ lines = newLines;
75321
75531
  didRemeasureForFloats = true;
75322
75532
  }
75323
75533
  }
@@ -76474,8 +76684,8 @@ function layoutDocument(blocks, measures, options = {}) {
76474
76684
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
76475
76685
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
76476
76686
  };
76477
- const contentWidth = pageSize.w - (margins.left + margins.right);
76478
- if (contentWidth <= 0) {
76687
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
76688
+ if (baseContentWidth <= 0) {
76479
76689
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
76480
76690
  }
76481
76691
  const validateContentHeight = (height) => {
@@ -76505,8 +76715,12 @@ function layoutDocument(blocks, measures, options = {}) {
76505
76715
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
76506
76716
  let activeTopMargin = effectiveTopMargin;
76507
76717
  let activeBottomMargin = effectiveBottomMargin;
76718
+ let activeLeftMargin = margins.left;
76719
+ let activeRightMargin = margins.right;
76508
76720
  let pendingTopMargin = null;
76509
76721
  let pendingBottomMargin = null;
76722
+ let pendingLeftMargin = null;
76723
+ let pendingRightMargin = null;
76510
76724
  let activeHeaderDistance = margins.header ?? margins.top;
76511
76725
  let pendingHeaderDistance = null;
76512
76726
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -76519,10 +76733,11 @@ function layoutDocument(blocks, measures, options = {}) {
76519
76733
  let pendingOrientation = null;
76520
76734
  let activeVAlign = null;
76521
76735
  let pendingVAlign = null;
76736
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
76522
76737
  const floatManager = createFloatingObjectManager(
76523
- normalizeColumns(activeColumns, contentWidth),
76524
- { left: margins.left, right: margins.right },
76525
- pageSize.w
76738
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76739
+ { left: activeLeftMargin, right: activeRightMargin },
76740
+ activePageSize.w
76526
76741
  );
76527
76742
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
76528
76743
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -76539,22 +76754,38 @@ function layoutDocument(blocks, measures, options = {}) {
76539
76754
  next.activeOrientation = block.orientation;
76540
76755
  next.pendingOrientation = null;
76541
76756
  }
76757
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
76758
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
76759
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
76760
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
76542
76761
  if (block.margins?.header !== void 0) {
76543
- const headerDist = Math.max(0, block.margins.header);
76544
- next.activeHeaderDistance = headerDist;
76545
- next.pendingHeaderDistance = headerDist;
76546
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
76547
- next.activeTopMargin = Math.max(baseMargins.top, requiredTop);
76548
- next.pendingTopMargin = next.activeTopMargin;
76762
+ next.activeHeaderDistance = headerDistance2;
76763
+ next.pendingHeaderDistance = headerDistance2;
76549
76764
  }
76550
76765
  if (block.margins?.footer !== void 0) {
76551
- const footerDistance2 = Math.max(0, block.margins.footer);
76552
76766
  next.activeFooterDistance = footerDistance2;
76553
76767
  next.pendingFooterDistance = footerDistance2;
76768
+ }
76769
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
76770
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
76771
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
76772
+ next.pendingTopMargin = next.activeTopMargin;
76773
+ }
76774
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
76554
76775
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
76555
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
76776
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
76556
76777
  next.pendingBottomMargin = next.activeBottomMargin;
76557
76778
  }
76779
+ if (block.margins?.left !== void 0) {
76780
+ const leftMargin = Math.max(0, block.margins.left);
76781
+ next.activeLeftMargin = leftMargin;
76782
+ next.pendingLeftMargin = leftMargin;
76783
+ }
76784
+ if (block.margins?.right !== void 0) {
76785
+ const rightMargin = Math.max(0, block.margins.right);
76786
+ next.activeRightMargin = rightMargin;
76787
+ next.pendingRightMargin = rightMargin;
76788
+ }
76558
76789
  if (block.columns) {
76559
76790
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
76560
76791
  next.pendingColumns = null;
@@ -76583,27 +76814,35 @@ function layoutDocument(blocks, measures, options = {}) {
76583
76814
  const headerPx = block.margins?.header;
76584
76815
  const footerPx = block.margins?.footer;
76585
76816
  const topPx = block.margins?.top;
76817
+ const bottomPx = block.margins?.bottom;
76818
+ const leftPx = block.margins?.left;
76819
+ const rightPx = block.margins?.right;
76586
76820
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
76587
76821
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
76822
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
76823
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
76588
76824
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
76589
76825
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
76590
76826
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
76591
76827
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
76592
76828
  if (typeof headerPx === "number" || typeof topPx === "number") {
76593
- const sectionTop = topPx ?? baseMargins.top;
76829
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
76594
76830
  const sectionHeader = next.pendingHeaderDistance;
76595
76831
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
76596
76832
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
76597
76833
  } else {
76598
76834
  next.pendingTopMargin = nextTop;
76599
76835
  }
76600
- if (typeof footerPx === "number") {
76836
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
76601
76837
  const sectionFooter = next.pendingFooterDistance;
76838
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
76602
76839
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
76603
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
76840
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
76604
76841
  } else {
76605
76842
  next.pendingBottomMargin = nextBottom;
76606
76843
  }
76844
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
76845
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
76607
76846
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
76608
76847
  if (block.orientation) next.pendingOrientation = block.orientation;
76609
76848
  const sectionType = block.type ?? "continuous";
@@ -76688,7 +76927,7 @@ function layoutDocument(blocks, measures, options = {}) {
76688
76927
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
76689
76928
  let pendingSectionIndex = null;
76690
76929
  const paginator = createPaginator({
76691
- margins: { left: margins.left, right: margins.right },
76930
+ margins: paginatorMargins,
76692
76931
  getActiveTopMargin: () => activeTopMargin,
76693
76932
  getActiveBottomMargin: () => activeBottomMargin,
76694
76933
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -76703,8 +76942,12 @@ function layoutDocument(blocks, measures, options = {}) {
76703
76942
  const applied = applyPendingToActive({
76704
76943
  activeTopMargin,
76705
76944
  activeBottomMargin,
76945
+ activeLeftMargin,
76946
+ activeRightMargin,
76706
76947
  pendingTopMargin,
76707
76948
  pendingBottomMargin,
76949
+ pendingLeftMargin,
76950
+ pendingRightMargin,
76708
76951
  activeHeaderDistance,
76709
76952
  activeFooterDistance,
76710
76953
  pendingHeaderDistance,
@@ -76719,8 +76962,12 @@ function layoutDocument(blocks, measures, options = {}) {
76719
76962
  });
76720
76963
  activeTopMargin = applied.activeTopMargin;
76721
76964
  activeBottomMargin = applied.activeBottomMargin;
76965
+ activeLeftMargin = applied.activeLeftMargin;
76966
+ activeRightMargin = applied.activeRightMargin;
76722
76967
  pendingTopMargin = applied.pendingTopMargin;
76723
76968
  pendingBottomMargin = applied.pendingBottomMargin;
76969
+ pendingLeftMargin = applied.pendingLeftMargin;
76970
+ pendingRightMargin = applied.pendingRightMargin;
76724
76971
  activeHeaderDistance = applied.activeHeaderDistance;
76725
76972
  activeFooterDistance = applied.activeFooterDistance;
76726
76973
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -76732,6 +76979,14 @@ function layoutDocument(blocks, measures, options = {}) {
76732
76979
  activeOrientation = applied.activeOrientation;
76733
76980
  pendingOrientation = applied.pendingOrientation;
76734
76981
  cachedColumnsState.state = null;
76982
+ paginatorMargins.left = activeLeftMargin;
76983
+ paginatorMargins.right = activeRightMargin;
76984
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
76985
+ floatManager.setLayoutContext(
76986
+ normalizeColumns(activeColumns, contentWidth),
76987
+ { left: activeLeftMargin, right: activeRightMargin },
76988
+ activePageSize.w
76989
+ );
76735
76990
  if (pendingNumbering) {
76736
76991
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
76737
76992
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -76776,7 +77031,7 @@ function layoutDocument(blocks, measures, options = {}) {
76776
77031
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
76777
77032
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
76778
77033
  const getCurrentColumns = () => {
76779
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
77034
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
76780
77035
  const state2 = states[states.length - 1] ?? null;
76781
77036
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
76782
77037
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -76809,6 +77064,12 @@ function layoutDocument(blocks, measures, options = {}) {
76809
77064
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
76810
77065
  activeColumns = newColumns;
76811
77066
  cachedColumnsState.state = null;
77067
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77068
+ floatManager.setLayoutContext(
77069
+ normalizeColumns(activeColumns, contentWidth),
77070
+ { left: activeLeftMargin, right: activeRightMargin },
77071
+ activePageSize.w
77072
+ );
76812
77073
  };
76813
77074
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
76814
77075
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -76840,10 +77101,10 @@ function layoutDocument(blocks, measures, options = {}) {
76840
77101
  if (alignV === "top") {
76841
77102
  anchorY = offsetV;
76842
77103
  } else if (alignV === "bottom") {
76843
- const pageHeight = contentBottom + margins.bottom;
77104
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76844
77105
  anchorY = pageHeight - imageHeight + offsetV;
76845
77106
  } else if (alignV === "center") {
76846
- const pageHeight = contentBottom + margins.bottom;
77107
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76847
77108
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
76848
77109
  } else {
76849
77110
  anchorY = offsetV;
@@ -76854,11 +77115,11 @@ function layoutDocument(blocks, measures, options = {}) {
76854
77115
  const anchorX = entry.block.anchor ? computeAnchorX(
76855
77116
  entry.block.anchor,
76856
77117
  state2.columnIndex,
76857
- normalizeColumns(activeColumns, contentWidth),
77118
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76858
77119
  entry.measure.width,
76859
- { left: margins.left, right: margins.right },
77120
+ { left: activeLeftMargin, right: activeRightMargin },
76860
77121
  activePageSize.w
76861
- ) : margins.left;
77122
+ ) : activeLeftMargin;
76862
77123
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
76863
77124
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
76864
77125
  }
@@ -76896,8 +77157,12 @@ function layoutDocument(blocks, measures, options = {}) {
76896
77157
  const sectionState = {
76897
77158
  activeTopMargin,
76898
77159
  activeBottomMargin,
77160
+ activeLeftMargin,
77161
+ activeRightMargin,
76899
77162
  pendingTopMargin,
76900
77163
  pendingBottomMargin,
77164
+ pendingLeftMargin,
77165
+ pendingRightMargin,
76901
77166
  activeHeaderDistance,
76902
77167
  activeFooterDistance,
76903
77168
  pendingHeaderDistance,
@@ -76931,8 +77196,12 @@ function layoutDocument(blocks, measures, options = {}) {
76931
77196
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
76932
77197
  activeTopMargin = updatedState.activeTopMargin;
76933
77198
  activeBottomMargin = updatedState.activeBottomMargin;
77199
+ activeLeftMargin = updatedState.activeLeftMargin;
77200
+ activeRightMargin = updatedState.activeRightMargin;
76934
77201
  pendingTopMargin = updatedState.pendingTopMargin;
76935
77202
  pendingBottomMargin = updatedState.pendingBottomMargin;
77203
+ pendingLeftMargin = updatedState.pendingLeftMargin;
77204
+ pendingRightMargin = updatedState.pendingRightMargin;
76936
77205
  activeHeaderDistance = updatedState.activeHeaderDistance;
76937
77206
  activeFooterDistance = updatedState.activeFooterDistance;
76938
77207
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -77070,8 +77339,8 @@ function layoutDocument(blocks, measures, options = {}) {
77070
77339
  pageMargins: {
77071
77340
  top: activeTopMargin,
77072
77341
  bottom: activeBottomMargin,
77073
- left: margins.left,
77074
- right: margins.right
77342
+ left: activeLeftMargin,
77343
+ right: activeRightMargin
77075
77344
  },
77076
77345
  columns: getCurrentColumns(),
77077
77346
  placedAnchoredIds
@@ -77093,9 +77362,9 @@ function layoutDocument(blocks, measures, options = {}) {
77093
77362
  const cols = getCurrentColumns();
77094
77363
  let maxWidth;
77095
77364
  if (relativeFrom === "page") {
77096
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
77365
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
77097
77366
  } else if (relativeFrom === "margin") {
77098
- maxWidth = activePageSize.w - margins.left - margins.right;
77367
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77099
77368
  } else {
77100
77369
  maxWidth = cols.width;
77101
77370
  }
@@ -78282,11 +78551,11 @@ function findWordBoundaries(blocks, pos) {
78282
78551
  if (text.length === 0) return null;
78283
78552
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
78284
78553
  let wordStart = clampedPos;
78285
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
78554
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
78286
78555
  wordStart--;
78287
78556
  }
78288
78557
  let wordEnd = clampedPos;
78289
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
78558
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
78290
78559
  wordEnd++;
78291
78560
  }
78292
78561
  if (wordStart === wordEnd) {
@@ -78349,7 +78618,7 @@ function findBlockAtPosition(blocks, pos) {
78349
78618
  }
78350
78619
  return null;
78351
78620
  }
78352
- function isWordChar(char) {
78621
+ function isWordChar$2(char) {
78353
78622
  return /[\p{L}\p{N}_]/u.test(char);
78354
78623
  }
78355
78624
  function isWhitespace(char) {
@@ -78384,6 +78653,29 @@ function fontString(run2) {
78384
78653
  function runText(run2) {
78385
78654
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
78386
78655
  }
78656
+ const isWordChar$1 = (char) => {
78657
+ if (!char) return false;
78658
+ const code = char.charCodeAt(0);
78659
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
78660
+ };
78661
+ const capitalizeText$1 = (text, fullText, startOffset) => {
78662
+ if (!text) return text;
78663
+ const hasFullText = typeof startOffset === "number" && fullText != null;
78664
+ let result = "";
78665
+ for (let i = 0; i < text.length; i += 1) {
78666
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
78667
+ const ch = text[i];
78668
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
78669
+ }
78670
+ return result;
78671
+ };
78672
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
78673
+ if (!text || !transform || transform === "none") return text;
78674
+ if (transform === "uppercase") return text.toUpperCase();
78675
+ if (transform === "lowercase") return text.toLowerCase();
78676
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
78677
+ return text;
78678
+ };
78387
78679
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
78388
78680
  const TWIPS_PER_INCH$4 = 1440;
78389
78681
  const PX_PER_INCH$3 = 96;
@@ -78392,6 +78684,13 @@ const TAB_EPSILON$1 = 0.1;
78392
78684
  const WIDTH_FUDGE_PX = 0.5;
78393
78685
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
78394
78686
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
78687
+ const markerFontString = (run2) => {
78688
+ const size2 = run2?.fontSize ?? 16;
78689
+ const family = run2?.fontFamily ?? "Arial";
78690
+ const italic = run2?.italic ? "italic " : "";
78691
+ const bold = run2?.bold ? "bold " : "";
78692
+ return `${italic}${bold}${size2}px ${family}`.trim();
78693
+ };
78395
78694
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
78396
78695
  const paragraphIndentTwips = {
78397
78696
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -78422,7 +78721,8 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
78422
78721
  };
78423
78722
  function measureRunSliceWidth(run2, fromChar, toChar) {
78424
78723
  const context = getCtx();
78425
- const text = runText(run2).slice(fromChar, toChar);
78724
+ const fullText = runText(run2);
78725
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), run2.textTransform, fullText, fromChar);
78426
78726
  if (!context) {
78427
78727
  const textRun = isTextRun$2(run2) ? run2 : null;
78428
78728
  const size2 = textRun?.fontSize ?? 16;
@@ -78468,8 +78768,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
78468
78768
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
78469
78769
  const markerTextStartX = wordLayout?.marker?.textStartX;
78470
78770
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
78471
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
78472
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
78771
+ const resolvedTextStartPx = resolveListTextStartPx(
78772
+ wordLayout,
78773
+ indentLeft,
78774
+ indentFirstLine,
78775
+ indentHanging,
78776
+ (markerText, marker) => {
78777
+ const context = getCtx();
78778
+ if (!context) return 0;
78779
+ context.font = markerFontString(marker.run);
78780
+ return context.measureText(markerText).width;
78781
+ }
78782
+ );
78783
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
78784
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
78785
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
78473
78786
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
78474
78787
  let currentRun = 0;
78475
78788
  let currentChar = 0;
@@ -79009,7 +79322,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79009
79322
  if (dirty.deletedBlockIds.length > 0) {
79010
79323
  measureCache.invalidate(dirty.deletedBlockIds);
79011
79324
  }
79012
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
79325
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
79013
79326
  if (measurementWidth <= 0 || measurementHeight <= 0) {
79014
79327
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
79015
79328
  }
@@ -79278,7 +79591,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79278
79591
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
79279
79592
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
79280
79593
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
79281
- function resolveMeasurementConstraints(options) {
79594
+ function resolveMeasurementConstraints(options, blocks) {
79282
79595
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
79283
79596
  const margins = {
79284
79597
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -79286,23 +79599,41 @@ function resolveMeasurementConstraints(options) {
79286
79599
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
79287
79600
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
79288
79601
  };
79289
- const contentWidth = pageSize.w - (margins.left + margins.right);
79290
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
79291
- const columns = options.columns;
79292
- if (columns && columns.count > 1) {
79602
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
79603
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
79604
+ const computeColumnWidth = (contentWidth, columns) => {
79605
+ if (!columns || columns.count <= 1) return contentWidth;
79293
79606
  const gap = Math.max(0, columns.gap ?? 0);
79294
79607
  const totalGap = gap * (columns.count - 1);
79295
- const columnWidth = (contentWidth - totalGap) / columns.count;
79296
- if (columnWidth > 0) {
79297
- return {
79298
- measurementWidth: columnWidth,
79299
- measurementHeight: contentHeight
79608
+ return (contentWidth - totalGap) / columns.count;
79609
+ };
79610
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
79611
+ let measurementHeight = baseContentHeight;
79612
+ if (blocks && blocks.length > 0) {
79613
+ for (const block of blocks) {
79614
+ if (block.kind !== "sectionBreak") continue;
79615
+ const sectionPageSize = block.pageSize ?? pageSize;
79616
+ const sectionMargins = {
79617
+ top: normalizeMargin(block.margins?.top, margins.top),
79618
+ right: normalizeMargin(block.margins?.right, margins.right),
79619
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
79620
+ left: normalizeMargin(block.margins?.left, margins.left)
79300
79621
  };
79622
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
79623
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
79624
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
79625
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
79626
+ if (columnWidth > measurementWidth) {
79627
+ measurementWidth = columnWidth;
79628
+ }
79629
+ if (contentHeight > measurementHeight) {
79630
+ measurementHeight = contentHeight;
79631
+ }
79301
79632
  }
79302
79633
  }
79303
79634
  return {
79304
- measurementWidth: contentWidth,
79305
- measurementHeight: contentHeight
79635
+ measurementWidth,
79636
+ measurementHeight
79306
79637
  };
79307
79638
  }
79308
79639
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -81369,6 +81700,7 @@ function isInRegisteredSurface(event) {
81369
81700
  }
81370
81701
  return false;
81371
81702
  }
81703
+ const SLASH_MENU_HANDLED_FLAG = "__sdHandledBySlashMenu";
81372
81704
  class PresentationInputBridge {
81373
81705
  /**
81374
81706
  * Creates a new PresentationInputBridge that forwards user input events from the visible layout
@@ -81582,6 +81914,10 @@ forwardCompositionEvent_fn = function(event) {
81582
81914
  __privateMethod$1(this, _PresentationInputBridge_instances, dispatchToTarget_fn).call(this, event, synthetic);
81583
81915
  };
81584
81916
  forwardContextMenu_fn = function(event) {
81917
+ const handledBySlashMenu = Boolean(event[SLASH_MENU_HANDLED_FLAG]);
81918
+ if (handledBySlashMenu) {
81919
+ return;
81920
+ }
81585
81921
  if (!__privateGet$1(this, _isEditable).call(this)) {
81586
81922
  return;
81587
81923
  }
@@ -85275,8 +85611,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
85275
85611
  }
85276
85612
  return void 0;
85277
85613
  }
85278
- const DEFAULT_LIST_HANGING_PX$1 = 18;
85279
- const LIST_MARKER_GAP$1 = 8;
85614
+ const DEFAULT_LIST_HANGING_PX = 18;
85615
+ const LIST_MARKER_GAP = 8;
85280
85616
  const DEFAULT_BULLET_GLYPH = "•";
85281
85617
  const DEFAULT_DECIMAL_PATTERN = "%1.";
85282
85618
  const ASCII_UPPERCASE_A = 65;
@@ -85687,7 +86023,7 @@ function computeWordParagraphLayout(input) {
85687
86023
  let markerBoxWidthPx;
85688
86024
  let markerX;
85689
86025
  if (hasFirstLineIndent) {
85690
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
86026
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
85691
86027
  markerX = indentLeftPx + (firstLinePx ?? 0);
85692
86028
  layout.textStartPx = markerX + markerBoxWidthPx;
85693
86029
  layout.hangingPx = 0;
@@ -85787,12 +86123,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
85787
86123
  let markerBox = Math.max(hangingPxRaw || 0, 0);
85788
86124
  if (markerBox <= 0) {
85789
86125
  if (glyphWidthPx != null && glyphWidthPx > 0) {
85790
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86126
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85791
86127
  } else {
85792
- markerBox = DEFAULT_LIST_HANGING_PX$1;
86128
+ markerBox = DEFAULT_LIST_HANGING_PX;
85793
86129
  }
85794
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
85795
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86130
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
86131
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85796
86132
  }
85797
86133
  return markerBox;
85798
86134
  };
@@ -85812,7 +86148,7 @@ const buildMarkerLayout = ({
85812
86148
  textStartX: textStartPx,
85813
86149
  baselineOffsetPx: markerRun.baselineShift ?? 0,
85814
86150
  // Gutter is the small gap between marker and text, not the full marker box width
85815
- gutterWidthPx: LIST_MARKER_GAP$1,
86151
+ gutterWidthPx: LIST_MARKER_GAP,
85816
86152
  justification: numbering.lvlJc ?? "left",
85817
86153
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
85818
86154
  run: markerRun,
@@ -86504,6 +86840,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
86504
86840
  return null;
86505
86841
  }
86506
86842
  };
86843
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
86844
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
86845
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
86846
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
86847
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
86848
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
86849
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
86850
+ wordLayout.firstLineIndentMode = false;
86851
+ }
86852
+ if (wordLayout.firstLineIndentMode === true) {
86853
+ if (isFiniteNumber(wordLayout.textStartPx)) {
86854
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
86855
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
86856
+ }
86857
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
86858
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
86859
+ }
86860
+ } else {
86861
+ wordLayout.textStartPx = indentLeft;
86862
+ if (wordLayout.marker) {
86863
+ wordLayout.marker.textStartX = indentLeft;
86864
+ }
86865
+ }
86866
+ return wordLayout;
86867
+ };
86507
86868
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
86508
86869
  const attrs = para.attrs ?? {};
86509
86870
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -86826,8 +87187,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86826
87187
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
86827
87188
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
86828
87189
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86829
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86830
- if (firstLinePx > 0) {
87190
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87191
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87192
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87193
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87194
+ if (firstLinePx > 0 && !hangingPx) {
86831
87195
  wordLayout = {
86832
87196
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
86833
87197
  firstLineIndentMode: true,
@@ -86835,10 +87199,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86835
87199
  };
86836
87200
  }
86837
87201
  }
86838
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
87202
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
86839
87203
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86840
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86841
- if (firstLinePx > 0) {
87204
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87205
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87206
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87207
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87208
+ if (firstLinePx > 0 && !hangingPx) {
86842
87209
  wordLayout = {
86843
87210
  ...wordLayout,
86844
87211
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -86858,6 +87225,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86858
87225
  wordLayout.marker.suffix = listRendering.suffix;
86859
87226
  }
86860
87227
  }
87228
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
86861
87229
  paragraphAttrs.wordLayout = wordLayout;
86862
87230
  }
86863
87231
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -90974,11 +91342,6 @@ function initHeaderFooterRegistry({
90974
91342
  cleanups
90975
91343
  };
90976
91344
  }
90977
- const LIST_MARKER_GAP = 8;
90978
- const MIN_MARKER_GUTTER = 24;
90979
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
90980
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
90981
- const DEFAULT_LIST_HANGING_PX = 18;
90982
91345
  function calculateRotatedBounds(input) {
90983
91346
  const width = Math.max(0, input.width);
90984
91347
  const height = Math.max(0, input.height);
@@ -91242,8 +91605,25 @@ async function measureParagraphBlock(block, maxWidth) {
91242
91605
  const rawTextStartPx = wordLayout?.textStartPx;
91243
91606
  const markerTextStartX = wordLayout?.marker?.textStartX;
91244
91607
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
91245
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
91246
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
91608
+ const resolvedTextStartPx = resolveListTextStartPx(
91609
+ wordLayout,
91610
+ indentLeft,
91611
+ firstLine,
91612
+ hanging,
91613
+ (markerText, marker) => {
91614
+ const markerRun = {
91615
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
91616
+ fontSize: marker.run?.fontSize ?? 16,
91617
+ bold: marker.run?.bold ?? false,
91618
+ italic: marker.run?.italic ?? false
91619
+ };
91620
+ const { font: markerFont } = buildFontString(markerRun);
91621
+ return measureText(markerText, markerFont, ctx2);
91622
+ }
91623
+ );
91624
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
91625
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
91626
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
91247
91627
  } else {
91248
91628
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
91249
91629
  }
@@ -91330,7 +91710,7 @@ async function measureParagraphBlock(block, maxWidth) {
91330
91710
  pendingTabAlignment = null;
91331
91711
  return startX;
91332
91712
  };
91333
- const alignSegmentAtTab = (segmentText, font, runContext) => {
91713
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
91334
91714
  if (!pendingTabAlignment || !currentLine) return void 0;
91335
91715
  const { val } = pendingTabAlignment;
91336
91716
  let segmentWidth = 0;
@@ -91339,11 +91719,11 @@ async function measureParagraphBlock(block, maxWidth) {
91339
91719
  const idx = segmentText.indexOf(decimalSeparator);
91340
91720
  if (idx >= 0) {
91341
91721
  const beforeText = segmentText.slice(0, idx);
91342
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
91722
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
91343
91723
  }
91344
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
91724
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91345
91725
  } else if (val === "end" || val === "center") {
91346
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
91726
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91347
91727
  }
91348
91728
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
91349
91729
  };
@@ -91395,8 +91775,8 @@ async function measureParagraphBlock(block, maxWidth) {
91395
91775
  const { font } = buildFontString(
91396
91776
  lastRun
91397
91777
  );
91398
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
91399
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
91778
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
91779
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
91400
91780
  const delta = Math.max(0, fullWidth - keptWidth);
91401
91781
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
91402
91782
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -91607,7 +91987,8 @@ async function measureParagraphBlock(block, maxWidth) {
91607
91987
  continue;
91608
91988
  }
91609
91989
  if (isFieldAnnotationRun(run2)) {
91610
- const displayText = run2.displayLabel || "";
91990
+ const rawDisplayText = run2.displayLabel || "";
91991
+ const displayText = applyTextTransform(rawDisplayText, run2);
91611
91992
  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;
91612
91993
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
91613
91994
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -91710,7 +92091,7 @@ async function measureParagraphBlock(block, maxWidth) {
91710
92091
  const spacesLength = segment.length;
91711
92092
  const spacesStartChar = charPosInRun;
91712
92093
  const spacesEndChar = charPosInRun + spacesLength;
91713
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
92094
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
91714
92095
  if (!currentLine) {
91715
92096
  currentLine = {
91716
92097
  fromRun: runIndex,
@@ -91774,7 +92155,7 @@ async function measureParagraphBlock(block, maxWidth) {
91774
92155
  }
91775
92156
  let segmentStartX;
91776
92157
  if (currentLine && pendingTabAlignment) {
91777
- segmentStartX = alignSegmentAtTab(segment, font, run2);
92158
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
91778
92159
  if (segmentStartX == null) {
91779
92160
  segmentStartX = currentLine.width;
91780
92161
  }
@@ -91784,7 +92165,7 @@ async function measureParagraphBlock(block, maxWidth) {
91784
92165
  if (word2 === "") {
91785
92166
  const spaceStartChar = charPosInRun;
91786
92167
  const spaceEndChar = charPosInRun + 1;
91787
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
92168
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
91788
92169
  if (!currentLine) {
91789
92170
  currentLine = {
91790
92171
  fromRun: runIndex,
@@ -91835,12 +92216,12 @@ async function measureParagraphBlock(block, maxWidth) {
91835
92216
  charPosInRun = spaceEndChar;
91836
92217
  continue;
91837
92218
  }
91838
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
91839
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91840
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
91841
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
91842
92219
  const wordStartChar = charPosInRun;
92220
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
92221
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91843
92222
  const wordEndNoSpace = charPosInRun + word2.length;
92223
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
92224
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
91844
92225
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
91845
92226
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
91846
92227
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -91859,7 +92240,7 @@ async function measureParagraphBlock(block, maxWidth) {
91859
92240
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
91860
92241
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
91861
92242
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
91862
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
92243
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
91863
92244
  let chunkCharOffset = wordStartChar;
91864
92245
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
91865
92246
  const chunk = chunks[chunkIndex];
@@ -91983,7 +92364,7 @@ async function measureParagraphBlock(block, maxWidth) {
91983
92364
  if (candidateSpaces > 0) {
91984
92365
  const overflow = totalWidthWithWord - availableWidth;
91985
92366
  if (overflow > 0) {
91986
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
92367
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
91987
92368
  const perSpaceCompression = overflow / candidateSpaces;
91988
92369
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
91989
92370
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -92158,8 +92539,8 @@ async function measureParagraphBlock(block, maxWidth) {
92158
92539
  const { font: markerFont } = buildFontString(markerRun);
92159
92540
  const markerText = wordLayout.marker.markerText ?? "";
92160
92541
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92161
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
92162
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
92542
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
92543
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
92163
92544
  markerInfo = {
92164
92545
  markerWidth: markerBoxWidth,
92165
92546
  markerTextWidth: glyphWidth,
@@ -92503,7 +92884,7 @@ async function measureListBlock(block, constraints) {
92503
92884
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92504
92885
  indentLeft = resolveIndentLeft(item);
92505
92886
  const indentHanging = resolveIndentHanging(item);
92506
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
92887
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
92507
92888
  }
92508
92889
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
92509
92890
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -92529,16 +92910,46 @@ const getPrimaryRun = (paragraph) => {
92529
92910
  fontSize: 16
92530
92911
  };
92531
92912
  };
92532
- const measureRunWidth = (text, font, ctx2, run2) => {
92913
+ const isWordChar = (char) => {
92914
+ if (!char) return false;
92915
+ const code = char.charCodeAt(0);
92916
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
92917
+ };
92918
+ const capitalizeText = (text, fullText, startOffset) => {
92919
+ if (!text) return text;
92920
+ const hasFullText = typeof startOffset === "number" && fullText != null;
92921
+ let result = "";
92922
+ for (let i = 0; i < text.length; i += 1) {
92923
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
92924
+ const ch = text[i];
92925
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
92926
+ }
92927
+ return result;
92928
+ };
92929
+ const applyTextTransform = (text, run2, startOffset) => {
92930
+ const transform = run2.textTransform;
92931
+ if (!text || !transform || transform === "none") return text;
92932
+ if (transform === "uppercase") return text.toUpperCase();
92933
+ if (transform === "lowercase") return text.toLowerCase();
92934
+ if (transform === "capitalize") {
92935
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text;
92936
+ return capitalizeText(text, fullText, startOffset);
92937
+ }
92938
+ return text;
92939
+ };
92940
+ const measureRunWidth = (text, font, ctx2, run2, startOffset) => {
92533
92941
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
92534
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
92942
+ const displayText = applyTextTransform(text, run2, startOffset);
92943
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
92535
92944
  return roundValue(width);
92536
92945
  };
92537
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
92946
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
92538
92947
  const chunks = [];
92948
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
92539
92949
  if (maxWidth <= 0) {
92540
- for (const char of word2) {
92541
- const charWidth = measureRunWidth(char, font, ctx2, run2);
92950
+ for (let i = 0; i < word2.length; i++) {
92951
+ const char = word2[i];
92952
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92542
92953
  chunks.push({ text: char, width: charWidth });
92543
92954
  }
92544
92955
  return chunks;
@@ -92548,11 +92959,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
92548
92959
  for (let i = 0; i < word2.length; i++) {
92549
92960
  const char = word2[i];
92550
92961
  const testChunk = currentChunk + char;
92551
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
92962
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
92552
92963
  if (testWidth > maxWidth && currentChunk.length > 0) {
92553
92964
  chunks.push({ text: currentChunk, width: currentWidth });
92554
92965
  currentChunk = char;
92555
- currentWidth = measureRunWidth(char, font, ctx2, run2);
92966
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92556
92967
  } else {
92557
92968
  currentChunk = testChunk;
92558
92969
  currentWidth = testWidth;
@@ -92606,7 +93017,8 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
92606
93017
  italic: run2.italic
92607
93018
  });
92608
93019
  ctx2.font = font;
92609
- const metrics = ctx2.measureText(run2.text);
93020
+ const displayText = applyTextTransform(run2.text, run2);
93021
+ const metrics = ctx2.measureText(displayText);
92610
93022
  const advanceWidth = metrics.width;
92611
93023
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
92612
93024
  const textWidth = Math.max(advanceWidth, paintedWidth);
@@ -92632,7 +93044,7 @@ const resolveIndentHanging = (item) => {
92632
93044
  if (indentHanging > 0) {
92633
93045
  return indentHanging;
92634
93046
  }
92635
- return DEFAULT_LIST_HANGING_PX;
93047
+ return DEFAULT_LIST_HANGING_PX$1;
92636
93048
  };
92637
93049
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
92638
93050
  const paragraphIndentTwips = {
@@ -129694,11 +130106,23 @@ const _sfc_main$8 = {
129694
130106
  closeMenu({ restoreCursor: false });
129695
130107
  }
129696
130108
  };
129697
- const handleRightClick = async (event) => {
130109
+ const shouldHandleContextMenu = (event) => {
129698
130110
  const readOnly = !props.editor?.isEditable;
129699
130111
  const contextMenuDisabled = props.editor?.options?.disableContextMenu;
129700
130112
  const bypass = shouldBypassContextMenu(event);
129701
- if (readOnly || contextMenuDisabled || bypass) {
130113
+ return !readOnly && !contextMenuDisabled && !bypass;
130114
+ };
130115
+ const handleRightClickCapture = (event) => {
130116
+ try {
130117
+ if (shouldHandleContextMenu(event)) {
130118
+ event[SLASH_MENU_HANDLED_FLAG] = true;
130119
+ }
130120
+ } catch (error) {
130121
+ console.warn("[SlashMenu] Error in capture phase context menu handler:", error);
130122
+ }
130123
+ };
130124
+ const handleRightClick = async (event) => {
130125
+ if (!shouldHandleContextMenu(event)) {
129702
130126
  return;
129703
130127
  }
129704
130128
  event.preventDefault();
@@ -129809,6 +130233,7 @@ const _sfc_main$8 = {
129809
130233
  props.editor.on("slashMenu:open", slashMenuOpenHandler);
129810
130234
  contextMenuTarget = getEditorSurfaceElement(props.editor);
129811
130235
  if (contextMenuTarget) {
130236
+ contextMenuTarget.addEventListener("contextmenu", handleRightClickCapture, true);
129812
130237
  contextMenuTarget.addEventListener("contextmenu", handleRightClick);
129813
130238
  }
129814
130239
  slashMenuCloseHandler = () => {
@@ -129832,6 +130257,7 @@ const _sfc_main$8 = {
129832
130257
  props.editor.off("slashMenu:close", slashMenuCloseHandler);
129833
130258
  }
129834
130259
  props.editor.off("update", handleEditorUpdate);
130260
+ contextMenuTarget?.removeEventListener("contextmenu", handleRightClickCapture, true);
129835
130261
  contextMenuTarget?.removeEventListener("contextmenu", handleRightClick);
129836
130262
  } catch (error) {
129837
130263
  console.warn("[SlashMenu] Error during cleanup:", error);