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
@@ -42410,7 +42410,7 @@ const _SuperConverter = class _SuperConverter2 {
42410
42410
  static getStoredSuperdocVersion(docx) {
42411
42411
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42412
42412
  }
42413
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.1") {
42413
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.3") {
42414
42414
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42415
42415
  }
42416
42416
  /**
@@ -60491,7 +60491,7 @@ const isHeadless = (editor) => {
60491
60491
  const shouldSkipNodeView = (editor) => {
60492
60492
  return isHeadless(editor);
60493
60493
  };
60494
- const summaryVersion = "2.0.0-next.1";
60494
+ const summaryVersion = "2.0.0-next.3";
60495
60495
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
60496
60496
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
60497
60497
  function mapAttributes(attrs) {
@@ -61280,7 +61280,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61280
61280
  { default: remarkStringify },
61281
61281
  { default: remarkGfm }
61282
61282
  ] = await Promise.all([
61283
- import("./index-Dq6vXk74-CQD7nLbH.es.js"),
61283
+ import("./index-lLnrqNSJ-DoACeFqL.es.js"),
61284
61284
  import("./index-DRCvimau-Cw339678.es.js"),
61285
61285
  import("./index-C_x_N6Uh-DJn8hIEt.es.js"),
61286
61286
  import("./index-D_sWOSiG-DE96TaT5.es.js"),
@@ -61485,7 +61485,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61485
61485
  * Process collaboration migrations
61486
61486
  */
61487
61487
  processCollaborationMigrations() {
61488
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.1");
61488
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.3");
61489
61489
  if (!this.options.ydoc) return;
61490
61490
  const metaMap = this.options.ydoc.getMap("meta");
61491
61491
  let docVersion = metaMap.get("version");
@@ -68737,7 +68737,7 @@ function isMinimalWordLayout(value) {
68737
68737
  return true;
68738
68738
  }
68739
68739
  const LIST_MARKER_GAP$2 = 8;
68740
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
68740
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
68741
68741
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
68742
68742
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
68743
68743
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -69664,6 +69664,7 @@ const _DomPainter = class _DomPainter2 {
69664
69664
  const block = lookup2.block;
69665
69665
  const measure = lookup2.measure;
69666
69666
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
69667
+ const alignment2 = block.attrs?.alignment;
69667
69668
  const fragmentEl = this.doc.createElement("div");
69668
69669
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
69669
69670
  const isTocEntry = block.attrs?.isTocEntry;
@@ -69742,7 +69743,7 @@ const _DomPainter = class _DomPainter2 {
69742
69743
  const textStart = paraIndentLeft + firstLine;
69743
69744
  tabWidth = textStart - currentPos;
69744
69745
  if (tabWidth <= 0) {
69745
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
69746
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69746
69747
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69747
69748
  tabWidth = LIST_MARKER_GAP$2;
69748
69749
  }
@@ -69769,6 +69770,21 @@ const _DomPainter = class _DomPainter2 {
69769
69770
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
69770
69771
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
69771
69772
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
69773
+ if (alignment2 === "justify" || alignment2 === "both") {
69774
+ console.log(
69775
+ "[justify-debug][painter-firstline-available]",
69776
+ JSON.stringify({
69777
+ blockId: block.id,
69778
+ fragmentWidth: fragment.width,
69779
+ markerTabWidth: listFirstLineMarkerTabWidth,
69780
+ paraIndentRight,
69781
+ availableWidthOverride,
69782
+ lineMaxWidth: line.maxWidth ?? null,
69783
+ lineWidth: line.width,
69784
+ lineNaturalWidth: line.naturalWidth ?? null
69785
+ })
69786
+ );
69787
+ }
69772
69788
  }
69773
69789
  const isLastLineOfFragment = index2 === lines.length - 1;
69774
69790
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -69894,7 +69910,7 @@ const _DomPainter = class _DomPainter2 {
69894
69910
  const textStart = paraIndentLeft + firstLine;
69895
69911
  tabWidth = textStart - currentPos;
69896
69912
  if (tabWidth <= 0) {
69897
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
69913
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69898
69914
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69899
69915
  tabWidth = LIST_MARKER_GAP$2;
69900
69916
  }
@@ -71428,6 +71444,23 @@ const _DomPainter = class _DomPainter2 {
71428
71444
  if (spacingPerSpace !== 0) {
71429
71445
  el.style.wordSpacing = `${spacingPerSpace}px`;
71430
71446
  }
71447
+ if (justifyShouldApply && spacingPerSpace < 0) {
71448
+ console.log(
71449
+ "[justify-debug][painter-wordspacing-negative]",
71450
+ JSON.stringify({
71451
+ blockId: block.id,
71452
+ lineIndex: lineIndex ?? null,
71453
+ alignment: alignment2 ?? null,
71454
+ availableWidth,
71455
+ lineWidth,
71456
+ lineMaxWidth: line.maxWidth ?? null,
71457
+ lineNaturalWidth: line.naturalWidth ?? null,
71458
+ spaceCount,
71459
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
71460
+ skipJustify: Boolean(skipJustify)
71461
+ })
71462
+ );
71463
+ }
71431
71464
  if (hasExplicitPositioning && line.segments) {
71432
71465
  const paraIndent = block.attrs?.indent;
71433
71466
  const indentLeft = paraIndent?.left ?? 0;
@@ -73621,6 +73654,28 @@ let measurementCtx = null;
73621
73654
  const TAB_CHAR_LENGTH = 1;
73622
73655
  const SPACE_CHARS = SPACE_CHARS$1;
73623
73656
  const isTabRun$1 = (run2) => run2?.kind === "tab";
73657
+ const isWordChar$3 = (char) => {
73658
+ if (!char) return false;
73659
+ const code = char.charCodeAt(0);
73660
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
73661
+ };
73662
+ const capitalizeText$2 = (text) => {
73663
+ if (!text) return text;
73664
+ let result = "";
73665
+ for (let i = 0; i < text.length; i += 1) {
73666
+ const prevChar = i > 0 ? text[i - 1] : "";
73667
+ const ch = text[i];
73668
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
73669
+ }
73670
+ return result;
73671
+ };
73672
+ const applyTextTransform$2 = (text, transform) => {
73673
+ if (!text || !transform || transform === "none") return text;
73674
+ if (transform === "uppercase") return text.toUpperCase();
73675
+ if (transform === "lowercase") return text.toLowerCase();
73676
+ if (transform === "capitalize") return capitalizeText$2(text);
73677
+ return text;
73678
+ };
73624
73679
  function getMeasurementContext() {
73625
73680
  if (measurementCtx) return measurementCtx;
73626
73681
  if (typeof document === "undefined") {
@@ -73796,17 +73851,18 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
73796
73851
  }
73797
73852
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73798
73853
  const runLength = text.length;
73854
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73799
73855
  if (currentCharOffset + runLength >= charOffset) {
73800
73856
  const offsetInRun = charOffset - currentCharOffset;
73801
73857
  ctx2.font = getRunFontString(run2);
73802
- const textUpToTarget = text.slice(0, offsetInRun);
73858
+ const textUpToTarget = displayText.slice(0, offsetInRun);
73803
73859
  const measured2 = ctx2.measureText(textUpToTarget);
73804
73860
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
73805
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
73861
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text.slice(0, offsetInRun)) : 0;
73806
73862
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
73807
73863
  }
73808
73864
  ctx2.font = getRunFontString(run2);
73809
- const measured = ctx2.measureText(text);
73865
+ const measured = ctx2.measureText(displayText);
73810
73866
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73811
73867
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text) : 0;
73812
73868
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -73845,8 +73901,9 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
73845
73901
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
73846
73902
  }
73847
73903
  const text = run2.text ?? "";
73848
- const segmentText = text.slice(segment.fromChar, segment.toChar);
73849
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
73904
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73905
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
73906
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
73850
73907
  ctx2.font = getRunFontString(run2);
73851
73908
  const measured = ctx2.measureText(textUpToTarget);
73852
73909
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -73942,12 +73999,13 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73942
73999
  }
73943
74000
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73944
74001
  const runLength = text.length;
74002
+ const displayText = applyTextTransform$2(text, run2.textTransform);
73945
74003
  if (runLength === 0) continue;
73946
74004
  ctx2.font = getRunFontString(run2);
73947
74005
  for (let i = 0; i <= runLength; i++) {
73948
- const textUpToChar = text.slice(0, i);
74006
+ const textUpToChar = displayText.slice(0, i);
73949
74007
  const measured2 = ctx2.measureText(textUpToChar);
73950
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
74008
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text.slice(0, i)) : 0;
73951
74009
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
73952
74010
  if (charX >= safeX) {
73953
74011
  if (i === 0) {
@@ -73957,7 +74015,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73957
74015
  pmPosition: pmPosition3
73958
74016
  };
73959
74017
  }
73960
- const prevText = text.slice(0, i - 1);
74018
+ const prevText = displayText.slice(0, i - 1);
73961
74019
  const prevMeasured = ctx2.measureText(prevText);
73962
74020
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i - 1, runLength);
73963
74021
  const distToPrev = Math.abs(safeX - prevX);
@@ -73970,7 +74028,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73970
74028
  };
73971
74029
  }
73972
74030
  }
73973
- const measured = ctx2.measureText(text);
74031
+ const measured = ctx2.measureText(displayText);
73974
74032
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73975
74033
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
73976
74034
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -74401,6 +74459,83 @@ function findCharIndexAtX(textNode, container, targetX) {
74401
74459
  }
74402
74460
  return index2;
74403
74461
  }
74462
+ const LIST_MARKER_GAP$1 = 8;
74463
+ const MIN_MARKER_GUTTER = 24;
74464
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
74465
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
74466
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
74467
+ const SPACE_SUFFIX_GAP_PX = 4;
74468
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
74469
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
74470
+ const marker = wordLayout?.marker;
74471
+ if (!marker) {
74472
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
74473
+ return textStartPx;
74474
+ }
74475
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
74476
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
74477
+ if (markerTextWidth == null && marker.markerText) {
74478
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
74479
+ }
74480
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth < 0) {
74481
+ markerTextWidth = markerBoxWidth;
74482
+ }
74483
+ markerTextWidth = Math.max(0, markerTextWidth);
74484
+ let markerStartPos;
74485
+ if (wordLayout?.firstLineIndentMode === true && Number.isFinite(marker.markerX)) {
74486
+ markerStartPos = marker.markerX;
74487
+ } else {
74488
+ markerStartPos = indentLeft - hanging + firstLine;
74489
+ }
74490
+ if (!Number.isFinite(markerStartPos)) {
74491
+ markerStartPos = 0;
74492
+ }
74493
+ const currentPos = markerStartPos + markerTextWidth;
74494
+ const suffix2 = marker.suffix ?? "tab";
74495
+ if (suffix2 === "space") {
74496
+ return markerStartPos + markerTextWidth + SPACE_SUFFIX_GAP_PX;
74497
+ }
74498
+ if (suffix2 === "nothing") {
74499
+ return markerStartPos + markerTextWidth;
74500
+ }
74501
+ const markerJustification = marker.justification ?? "left";
74502
+ if (markerJustification !== "left") {
74503
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
74504
+ return markerStartPos + markerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
74505
+ }
74506
+ if (wordLayout?.firstLineIndentMode === true) {
74507
+ let targetTabStop;
74508
+ if (Array.isArray(wordLayout.tabsPx)) {
74509
+ for (const tab of wordLayout.tabsPx) {
74510
+ if (typeof tab === "number" && tab > currentPos) {
74511
+ targetTabStop = tab;
74512
+ break;
74513
+ }
74514
+ }
74515
+ }
74516
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
74517
+ let tabWidth2;
74518
+ if (targetTabStop !== void 0) {
74519
+ tabWidth2 = targetTabStop - currentPos;
74520
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
74521
+ tabWidth2 = textStartTarget - currentPos;
74522
+ } else {
74523
+ tabWidth2 = LIST_MARKER_GAP$1;
74524
+ }
74525
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
74526
+ tabWidth2 = LIST_MARKER_GAP$1;
74527
+ }
74528
+ return markerStartPos + markerTextWidth + tabWidth2;
74529
+ }
74530
+ const textStart = indentLeft + firstLine;
74531
+ let tabWidth = textStart - currentPos;
74532
+ if (tabWidth <= 0) {
74533
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
74534
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
74535
+ tabWidth = LIST_MARKER_GAP$1;
74536
+ }
74537
+ return markerStartPos + markerTextWidth + tabWidth;
74538
+ }
74404
74539
  function getWordLayoutConfig(block) {
74405
74540
  if (!block || block.kind !== "paragraph") {
74406
74541
  return void 0;
@@ -74433,9 +74568,16 @@ function calculateTextStartIndent(params2) {
74433
74568
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
74434
74569
  let indentAdjust = paraIndentLeft;
74435
74570
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
74571
+ const resolvedTextStart = resolveListTextStartPx(
74572
+ wordLayout,
74573
+ paraIndentLeft,
74574
+ Math.max(firstLineIndent, 0),
74575
+ Math.max(hangingIndent, 0),
74576
+ () => markerWidth
74577
+ // Use provided markerWidth since we don't have canvas access here
74578
+ );
74436
74579
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
74437
- const markerTextStartX = wordLayout?.marker?.textStartX;
74438
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
74580
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
74439
74581
  } else if (isFirstLine && !isListItem2) {
74440
74582
  indentAdjust += firstLineOffset;
74441
74583
  }
@@ -74591,7 +74733,10 @@ function getHeaderFooterTypeForSection(pageNumber, sectionIndex, identifier, opt
74591
74733
  }
74592
74734
  function createFloatingObjectManager(columns, margins, pageWidth) {
74593
74735
  const zones = [];
74594
- const marginLeft = Math.max(0, margins?.left ?? 0);
74736
+ let currentColumns = columns;
74737
+ let currentMargins = margins;
74738
+ let currentPageWidth = pageWidth;
74739
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
74595
74740
  return {
74596
74741
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
74597
74742
  if (!drawingBlock.anchor?.isAnchored) {
@@ -74604,7 +74749,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74604
74749
  }
74605
74750
  const objectWidth = measure.width ?? 0;
74606
74751
  const objectHeight = measure.height ?? 0;
74607
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
74752
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
74608
74753
  const y2 = anchorY + (anchor.offsetV ?? 0);
74609
74754
  const zone = {
74610
74755
  imageBlockId: drawingBlock.id,
@@ -74638,7 +74783,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74638
74783
  }
74639
74784
  const tableWidth = measure.totalWidth ?? 0;
74640
74785
  const tableHeight = measure.totalHeight ?? 0;
74641
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
74786
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
74642
74787
  const y2 = anchorY + (anchor.offsetV ?? 0);
74643
74788
  const zone = {
74644
74789
  imageBlockId: tableBlock.id,
@@ -74686,7 +74831,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74686
74831
  }
74687
74832
  const leftFloats = [];
74688
74833
  const rightFloats = [];
74689
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
74834
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
74690
74835
  const columnCenter = columnOrigin + baseWidth / 2;
74691
74836
  for (const zone of wrappingZones) {
74692
74837
  if (zone.wrapMode === "left") {
@@ -74725,6 +74870,22 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74725
74870
  },
74726
74871
  clear() {
74727
74872
  zones.length = 0;
74873
+ },
74874
+ /**
74875
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
74876
+ * This method should be called when the layout configuration changes (e.g., section breaks,
74877
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
74878
+ * correctly relative to the new layout boundaries.
74879
+ *
74880
+ * @param nextColumns - Column layout configuration (width, gap, count)
74881
+ * @param nextMargins - Optional page margins (left, right) in pixels
74882
+ * @param nextPageWidth - Optional total page width in pixels
74883
+ */
74884
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
74885
+ currentColumns = nextColumns;
74886
+ currentMargins = nextMargins;
74887
+ currentPageWidth = nextPageWidth;
74888
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
74728
74889
  }
74729
74890
  };
74730
74891
  }
@@ -74824,7 +74985,14 @@ function computeNextSectionPropsAtBreak(blocks) {
74824
74985
  const props = {};
74825
74986
  if (source.kind !== "sectionBreak") return props;
74826
74987
  if (source.margins) {
74827
- props.margins = { header: source.margins.header, footer: source.margins.footer };
74988
+ props.margins = {
74989
+ header: source.margins.header,
74990
+ footer: source.margins.footer,
74991
+ top: source.margins.top,
74992
+ right: source.margins.right,
74993
+ bottom: source.margins.bottom,
74994
+ left: source.margins.left
74995
+ };
74828
74996
  }
74829
74997
  if (source.pageSize) {
74830
74998
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -74872,20 +75040,36 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74872
75040
  next.activeOrientation = block.orientation;
74873
75041
  next.pendingOrientation = null;
74874
75042
  }
75043
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
75044
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
75045
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
75046
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
74875
75047
  if (block.margins?.header !== void 0) {
74876
- const headerDistance = Math.max(0, block.margins.header);
74877
75048
  next.activeHeaderDistance = headerDistance;
74878
75049
  next.pendingHeaderDistance = headerDistance;
74879
- next.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
74880
- next.pendingTopMargin = next.activeTopMargin;
74881
75050
  }
74882
75051
  if (block.margins?.footer !== void 0) {
74883
- const footerDistance = Math.max(0, block.margins.footer);
74884
75052
  next.activeFooterDistance = footerDistance;
74885
75053
  next.pendingFooterDistance = footerDistance;
74886
- next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
75054
+ }
75055
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
75056
+ next.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
75057
+ next.pendingTopMargin = next.activeTopMargin;
75058
+ }
75059
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
75060
+ next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
74887
75061
  next.pendingBottomMargin = next.activeBottomMargin;
74888
75062
  }
75063
+ if (block.margins?.left !== void 0) {
75064
+ const leftMargin = Math.max(0, block.margins.left);
75065
+ next.activeLeftMargin = leftMargin;
75066
+ next.pendingLeftMargin = leftMargin;
75067
+ }
75068
+ if (block.margins?.right !== void 0) {
75069
+ const rightMargin = Math.max(0, block.margins.right);
75070
+ next.activeRightMargin = rightMargin;
75071
+ next.pendingRightMargin = rightMargin;
75072
+ }
74889
75073
  if (block.columns) {
74890
75074
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
74891
75075
  next.pendingColumns = null;
@@ -74894,26 +75078,42 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74894
75078
  }
74895
75079
  const headerPx = block.margins?.header;
74896
75080
  const footerPx = block.margins?.footer;
75081
+ const topPx = block.margins?.top;
75082
+ const bottomPx = block.margins?.bottom;
74897
75083
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
74898
75084
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
75085
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
75086
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
74899
75087
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
74900
75088
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
74901
- if (typeof headerPx === "number") {
74902
- const newHeaderDist = Math.max(0, headerPx);
75089
+ if (typeof headerPx === "number" || typeof topPx === "number") {
75090
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
75091
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
74903
75092
  next.pendingHeaderDistance = newHeaderDist;
74904
- next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
75093
+ next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
74905
75094
  } else {
74906
75095
  next.pendingTopMargin = nextTop;
74907
75096
  next.pendingHeaderDistance = nextHeader;
74908
75097
  }
74909
- if (typeof footerPx === "number") {
74910
- const newFooterDist = Math.max(0, footerPx);
75098
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
75099
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
75100
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
74911
75101
  next.pendingFooterDistance = newFooterDist;
74912
- next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
75102
+ next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
74913
75103
  } else {
74914
75104
  next.pendingBottomMargin = nextBottom;
74915
75105
  next.pendingFooterDistance = nextFooter;
74916
75106
  }
75107
+ if (typeof block.margins?.left === "number") {
75108
+ next.pendingLeftMargin = Math.max(0, block.margins.left);
75109
+ } else {
75110
+ next.pendingLeftMargin = nextLeft;
75111
+ }
75112
+ if (typeof block.margins?.right === "number") {
75113
+ next.pendingRightMargin = Math.max(0, block.margins.right);
75114
+ } else {
75115
+ next.pendingRightMargin = nextRight;
75116
+ }
74917
75117
  if (block.pageSize) {
74918
75118
  next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
74919
75119
  }
@@ -74973,6 +75173,12 @@ function applyPendingToActive(state2) {
74973
75173
  if (next.pendingBottomMargin != null) {
74974
75174
  next.activeBottomMargin = next.pendingBottomMargin;
74975
75175
  }
75176
+ if (next.pendingLeftMargin != null) {
75177
+ next.activeLeftMargin = next.pendingLeftMargin;
75178
+ }
75179
+ if (next.pendingRightMargin != null) {
75180
+ next.activeRightMargin = next.pendingRightMargin;
75181
+ }
74976
75182
  if (next.pendingHeaderDistance != null) {
74977
75183
  next.activeHeaderDistance = next.pendingHeaderDistance;
74978
75184
  }
@@ -74990,6 +75196,8 @@ function applyPendingToActive(state2) {
74990
75196
  }
74991
75197
  next.pendingTopMargin = null;
74992
75198
  next.pendingBottomMargin = null;
75199
+ next.pendingLeftMargin = null;
75200
+ next.pendingRightMargin = null;
74993
75201
  next.pendingHeaderDistance = null;
74994
75202
  next.pendingFooterDistance = null;
74995
75203
  next.pendingPageSize = null;
@@ -75218,7 +75426,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75218
75426
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
75219
75427
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75220
75428
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
75221
- lines = normalizeLines(newMeasure);
75429
+ const newLines = normalizeLines(newMeasure);
75430
+ lines = newLines;
75222
75431
  didRemeasureForColumnWidth = true;
75223
75432
  }
75224
75433
  let fromLine = 0;
@@ -75300,7 +75509,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75300
75509
  if (narrowestRemeasureWidth < remeasureWidth) {
75301
75510
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75302
75511
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
75303
- lines = normalizeLines(newMeasure);
75512
+ const newLines = normalizeLines(newMeasure);
75513
+ lines = newLines;
75304
75514
  didRemeasureForFloats = true;
75305
75515
  }
75306
75516
  }
@@ -76457,8 +76667,8 @@ function layoutDocument(blocks, measures, options = {}) {
76457
76667
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
76458
76668
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
76459
76669
  };
76460
- const contentWidth = pageSize.w - (margins.left + margins.right);
76461
- if (contentWidth <= 0) {
76670
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
76671
+ if (baseContentWidth <= 0) {
76462
76672
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
76463
76673
  }
76464
76674
  const validateContentHeight = (height) => {
@@ -76488,8 +76698,12 @@ function layoutDocument(blocks, measures, options = {}) {
76488
76698
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
76489
76699
  let activeTopMargin = effectiveTopMargin;
76490
76700
  let activeBottomMargin = effectiveBottomMargin;
76701
+ let activeLeftMargin = margins.left;
76702
+ let activeRightMargin = margins.right;
76491
76703
  let pendingTopMargin = null;
76492
76704
  let pendingBottomMargin = null;
76705
+ let pendingLeftMargin = null;
76706
+ let pendingRightMargin = null;
76493
76707
  let activeHeaderDistance = margins.header ?? margins.top;
76494
76708
  let pendingHeaderDistance = null;
76495
76709
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -76502,10 +76716,11 @@ function layoutDocument(blocks, measures, options = {}) {
76502
76716
  let pendingOrientation = null;
76503
76717
  let activeVAlign = null;
76504
76718
  let pendingVAlign = null;
76719
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
76505
76720
  const floatManager = createFloatingObjectManager(
76506
- normalizeColumns(activeColumns, contentWidth),
76507
- { left: margins.left, right: margins.right },
76508
- pageSize.w
76721
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76722
+ { left: activeLeftMargin, right: activeRightMargin },
76723
+ activePageSize.w
76509
76724
  );
76510
76725
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
76511
76726
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -76522,22 +76737,38 @@ function layoutDocument(blocks, measures, options = {}) {
76522
76737
  next.activeOrientation = block.orientation;
76523
76738
  next.pendingOrientation = null;
76524
76739
  }
76740
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
76741
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
76742
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
76743
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
76525
76744
  if (block.margins?.header !== void 0) {
76526
- const headerDist = Math.max(0, block.margins.header);
76527
- next.activeHeaderDistance = headerDist;
76528
- next.pendingHeaderDistance = headerDist;
76529
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
76530
- next.activeTopMargin = Math.max(baseMargins.top, requiredTop);
76531
- next.pendingTopMargin = next.activeTopMargin;
76745
+ next.activeHeaderDistance = headerDistance2;
76746
+ next.pendingHeaderDistance = headerDistance2;
76532
76747
  }
76533
76748
  if (block.margins?.footer !== void 0) {
76534
- const footerDistance2 = Math.max(0, block.margins.footer);
76535
76749
  next.activeFooterDistance = footerDistance2;
76536
76750
  next.pendingFooterDistance = footerDistance2;
76751
+ }
76752
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
76753
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
76754
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
76755
+ next.pendingTopMargin = next.activeTopMargin;
76756
+ }
76757
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
76537
76758
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
76538
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
76759
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
76539
76760
  next.pendingBottomMargin = next.activeBottomMargin;
76540
76761
  }
76762
+ if (block.margins?.left !== void 0) {
76763
+ const leftMargin = Math.max(0, block.margins.left);
76764
+ next.activeLeftMargin = leftMargin;
76765
+ next.pendingLeftMargin = leftMargin;
76766
+ }
76767
+ if (block.margins?.right !== void 0) {
76768
+ const rightMargin = Math.max(0, block.margins.right);
76769
+ next.activeRightMargin = rightMargin;
76770
+ next.pendingRightMargin = rightMargin;
76771
+ }
76541
76772
  if (block.columns) {
76542
76773
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
76543
76774
  next.pendingColumns = null;
@@ -76566,27 +76797,35 @@ function layoutDocument(blocks, measures, options = {}) {
76566
76797
  const headerPx = block.margins?.header;
76567
76798
  const footerPx = block.margins?.footer;
76568
76799
  const topPx = block.margins?.top;
76800
+ const bottomPx = block.margins?.bottom;
76801
+ const leftPx = block.margins?.left;
76802
+ const rightPx = block.margins?.right;
76569
76803
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
76570
76804
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
76805
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
76806
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
76571
76807
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
76572
76808
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
76573
76809
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
76574
76810
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
76575
76811
  if (typeof headerPx === "number" || typeof topPx === "number") {
76576
- const sectionTop = topPx ?? baseMargins.top;
76812
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
76577
76813
  const sectionHeader = next.pendingHeaderDistance;
76578
76814
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
76579
76815
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
76580
76816
  } else {
76581
76817
  next.pendingTopMargin = nextTop;
76582
76818
  }
76583
- if (typeof footerPx === "number") {
76819
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
76584
76820
  const sectionFooter = next.pendingFooterDistance;
76821
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
76585
76822
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
76586
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
76823
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
76587
76824
  } else {
76588
76825
  next.pendingBottomMargin = nextBottom;
76589
76826
  }
76827
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
76828
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
76590
76829
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
76591
76830
  if (block.orientation) next.pendingOrientation = block.orientation;
76592
76831
  const sectionType = block.type ?? "continuous";
@@ -76671,7 +76910,7 @@ function layoutDocument(blocks, measures, options = {}) {
76671
76910
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
76672
76911
  let pendingSectionIndex = null;
76673
76912
  const paginator = createPaginator({
76674
- margins: { left: margins.left, right: margins.right },
76913
+ margins: paginatorMargins,
76675
76914
  getActiveTopMargin: () => activeTopMargin,
76676
76915
  getActiveBottomMargin: () => activeBottomMargin,
76677
76916
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -76686,8 +76925,12 @@ function layoutDocument(blocks, measures, options = {}) {
76686
76925
  const applied = applyPendingToActive({
76687
76926
  activeTopMargin,
76688
76927
  activeBottomMargin,
76928
+ activeLeftMargin,
76929
+ activeRightMargin,
76689
76930
  pendingTopMargin,
76690
76931
  pendingBottomMargin,
76932
+ pendingLeftMargin,
76933
+ pendingRightMargin,
76691
76934
  activeHeaderDistance,
76692
76935
  activeFooterDistance,
76693
76936
  pendingHeaderDistance,
@@ -76702,8 +76945,12 @@ function layoutDocument(blocks, measures, options = {}) {
76702
76945
  });
76703
76946
  activeTopMargin = applied.activeTopMargin;
76704
76947
  activeBottomMargin = applied.activeBottomMargin;
76948
+ activeLeftMargin = applied.activeLeftMargin;
76949
+ activeRightMargin = applied.activeRightMargin;
76705
76950
  pendingTopMargin = applied.pendingTopMargin;
76706
76951
  pendingBottomMargin = applied.pendingBottomMargin;
76952
+ pendingLeftMargin = applied.pendingLeftMargin;
76953
+ pendingRightMargin = applied.pendingRightMargin;
76707
76954
  activeHeaderDistance = applied.activeHeaderDistance;
76708
76955
  activeFooterDistance = applied.activeFooterDistance;
76709
76956
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -76715,6 +76962,14 @@ function layoutDocument(blocks, measures, options = {}) {
76715
76962
  activeOrientation = applied.activeOrientation;
76716
76963
  pendingOrientation = applied.pendingOrientation;
76717
76964
  cachedColumnsState.state = null;
76965
+ paginatorMargins.left = activeLeftMargin;
76966
+ paginatorMargins.right = activeRightMargin;
76967
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
76968
+ floatManager.setLayoutContext(
76969
+ normalizeColumns(activeColumns, contentWidth),
76970
+ { left: activeLeftMargin, right: activeRightMargin },
76971
+ activePageSize.w
76972
+ );
76718
76973
  if (pendingNumbering) {
76719
76974
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
76720
76975
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -76759,7 +77014,7 @@ function layoutDocument(blocks, measures, options = {}) {
76759
77014
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
76760
77015
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
76761
77016
  const getCurrentColumns = () => {
76762
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
77017
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
76763
77018
  const state2 = states[states.length - 1] ?? null;
76764
77019
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
76765
77020
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -76792,6 +77047,12 @@ function layoutDocument(blocks, measures, options = {}) {
76792
77047
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
76793
77048
  activeColumns = newColumns;
76794
77049
  cachedColumnsState.state = null;
77050
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77051
+ floatManager.setLayoutContext(
77052
+ normalizeColumns(activeColumns, contentWidth),
77053
+ { left: activeLeftMargin, right: activeRightMargin },
77054
+ activePageSize.w
77055
+ );
76795
77056
  };
76796
77057
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
76797
77058
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -76823,10 +77084,10 @@ function layoutDocument(blocks, measures, options = {}) {
76823
77084
  if (alignV === "top") {
76824
77085
  anchorY = offsetV;
76825
77086
  } else if (alignV === "bottom") {
76826
- const pageHeight = contentBottom + margins.bottom;
77087
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76827
77088
  anchorY = pageHeight - imageHeight + offsetV;
76828
77089
  } else if (alignV === "center") {
76829
- const pageHeight = contentBottom + margins.bottom;
77090
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76830
77091
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
76831
77092
  } else {
76832
77093
  anchorY = offsetV;
@@ -76837,11 +77098,11 @@ function layoutDocument(blocks, measures, options = {}) {
76837
77098
  const anchorX = entry.block.anchor ? computeAnchorX(
76838
77099
  entry.block.anchor,
76839
77100
  state2.columnIndex,
76840
- normalizeColumns(activeColumns, contentWidth),
77101
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76841
77102
  entry.measure.width,
76842
- { left: margins.left, right: margins.right },
77103
+ { left: activeLeftMargin, right: activeRightMargin },
76843
77104
  activePageSize.w
76844
- ) : margins.left;
77105
+ ) : activeLeftMargin;
76845
77106
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
76846
77107
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
76847
77108
  }
@@ -76879,8 +77140,12 @@ function layoutDocument(blocks, measures, options = {}) {
76879
77140
  const sectionState = {
76880
77141
  activeTopMargin,
76881
77142
  activeBottomMargin,
77143
+ activeLeftMargin,
77144
+ activeRightMargin,
76882
77145
  pendingTopMargin,
76883
77146
  pendingBottomMargin,
77147
+ pendingLeftMargin,
77148
+ pendingRightMargin,
76884
77149
  activeHeaderDistance,
76885
77150
  activeFooterDistance,
76886
77151
  pendingHeaderDistance,
@@ -76914,8 +77179,12 @@ function layoutDocument(blocks, measures, options = {}) {
76914
77179
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
76915
77180
  activeTopMargin = updatedState.activeTopMargin;
76916
77181
  activeBottomMargin = updatedState.activeBottomMargin;
77182
+ activeLeftMargin = updatedState.activeLeftMargin;
77183
+ activeRightMargin = updatedState.activeRightMargin;
76917
77184
  pendingTopMargin = updatedState.pendingTopMargin;
76918
77185
  pendingBottomMargin = updatedState.pendingBottomMargin;
77186
+ pendingLeftMargin = updatedState.pendingLeftMargin;
77187
+ pendingRightMargin = updatedState.pendingRightMargin;
76919
77188
  activeHeaderDistance = updatedState.activeHeaderDistance;
76920
77189
  activeFooterDistance = updatedState.activeFooterDistance;
76921
77190
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -77053,8 +77322,8 @@ function layoutDocument(blocks, measures, options = {}) {
77053
77322
  pageMargins: {
77054
77323
  top: activeTopMargin,
77055
77324
  bottom: activeBottomMargin,
77056
- left: margins.left,
77057
- right: margins.right
77325
+ left: activeLeftMargin,
77326
+ right: activeRightMargin
77058
77327
  },
77059
77328
  columns: getCurrentColumns(),
77060
77329
  placedAnchoredIds
@@ -77076,9 +77345,9 @@ function layoutDocument(blocks, measures, options = {}) {
77076
77345
  const cols = getCurrentColumns();
77077
77346
  let maxWidth;
77078
77347
  if (relativeFrom === "page") {
77079
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
77348
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
77080
77349
  } else if (relativeFrom === "margin") {
77081
- maxWidth = activePageSize.w - margins.left - margins.right;
77350
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77082
77351
  } else {
77083
77352
  maxWidth = cols.width;
77084
77353
  }
@@ -78265,11 +78534,11 @@ function findWordBoundaries(blocks, pos) {
78265
78534
  if (text.length === 0) return null;
78266
78535
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
78267
78536
  let wordStart = clampedPos;
78268
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
78537
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
78269
78538
  wordStart--;
78270
78539
  }
78271
78540
  let wordEnd = clampedPos;
78272
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
78541
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
78273
78542
  wordEnd++;
78274
78543
  }
78275
78544
  if (wordStart === wordEnd) {
@@ -78332,7 +78601,7 @@ function findBlockAtPosition(blocks, pos) {
78332
78601
  }
78333
78602
  return null;
78334
78603
  }
78335
- function isWordChar(char) {
78604
+ function isWordChar$2(char) {
78336
78605
  return /[\p{L}\p{N}_]/u.test(char);
78337
78606
  }
78338
78607
  function isWhitespace(char) {
@@ -78367,6 +78636,29 @@ function fontString(run2) {
78367
78636
  function runText(run2) {
78368
78637
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
78369
78638
  }
78639
+ const isWordChar$1 = (char) => {
78640
+ if (!char) return false;
78641
+ const code = char.charCodeAt(0);
78642
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
78643
+ };
78644
+ const capitalizeText$1 = (text, fullText, startOffset) => {
78645
+ if (!text) return text;
78646
+ const hasFullText = typeof startOffset === "number" && fullText != null;
78647
+ let result = "";
78648
+ for (let i = 0; i < text.length; i += 1) {
78649
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
78650
+ const ch = text[i];
78651
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
78652
+ }
78653
+ return result;
78654
+ };
78655
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
78656
+ if (!text || !transform || transform === "none") return text;
78657
+ if (transform === "uppercase") return text.toUpperCase();
78658
+ if (transform === "lowercase") return text.toLowerCase();
78659
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
78660
+ return text;
78661
+ };
78370
78662
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
78371
78663
  const TWIPS_PER_INCH$4 = 1440;
78372
78664
  const PX_PER_INCH$3 = 96;
@@ -78375,6 +78667,13 @@ const TAB_EPSILON$1 = 0.1;
78375
78667
  const WIDTH_FUDGE_PX = 0.5;
78376
78668
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
78377
78669
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
78670
+ const markerFontString = (run2) => {
78671
+ const size2 = run2?.fontSize ?? 16;
78672
+ const family = run2?.fontFamily ?? "Arial";
78673
+ const italic = run2?.italic ? "italic " : "";
78674
+ const bold = run2?.bold ? "bold " : "";
78675
+ return `${italic}${bold}${size2}px ${family}`.trim();
78676
+ };
78378
78677
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
78379
78678
  const paragraphIndentTwips = {
78380
78679
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -78405,7 +78704,8 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
78405
78704
  };
78406
78705
  function measureRunSliceWidth(run2, fromChar, toChar) {
78407
78706
  const context = getCtx();
78408
- const text = runText(run2).slice(fromChar, toChar);
78707
+ const fullText = runText(run2);
78708
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), run2.textTransform, fullText, fromChar);
78409
78709
  if (!context) {
78410
78710
  const textRun = isTextRun$2(run2) ? run2 : null;
78411
78711
  const size2 = textRun?.fontSize ?? 16;
@@ -78451,8 +78751,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
78451
78751
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
78452
78752
  const markerTextStartX = wordLayout?.marker?.textStartX;
78453
78753
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
78454
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
78455
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
78754
+ const resolvedTextStartPx = resolveListTextStartPx(
78755
+ wordLayout,
78756
+ indentLeft,
78757
+ indentFirstLine,
78758
+ indentHanging,
78759
+ (markerText, marker) => {
78760
+ const context = getCtx();
78761
+ if (!context) return 0;
78762
+ context.font = markerFontString(marker.run);
78763
+ return context.measureText(markerText).width;
78764
+ }
78765
+ );
78766
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
78767
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
78768
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
78456
78769
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
78457
78770
  let currentRun = 0;
78458
78771
  let currentChar = 0;
@@ -78992,7 +79305,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
78992
79305
  if (dirty.deletedBlockIds.length > 0) {
78993
79306
  measureCache.invalidate(dirty.deletedBlockIds);
78994
79307
  }
78995
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
79308
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
78996
79309
  if (measurementWidth <= 0 || measurementHeight <= 0) {
78997
79310
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
78998
79311
  }
@@ -79261,7 +79574,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79261
79574
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
79262
79575
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
79263
79576
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
79264
- function resolveMeasurementConstraints(options) {
79577
+ function resolveMeasurementConstraints(options, blocks) {
79265
79578
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
79266
79579
  const margins = {
79267
79580
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -79269,23 +79582,41 @@ function resolveMeasurementConstraints(options) {
79269
79582
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
79270
79583
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
79271
79584
  };
79272
- const contentWidth = pageSize.w - (margins.left + margins.right);
79273
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
79274
- const columns = options.columns;
79275
- if (columns && columns.count > 1) {
79585
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
79586
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
79587
+ const computeColumnWidth = (contentWidth, columns) => {
79588
+ if (!columns || columns.count <= 1) return contentWidth;
79276
79589
  const gap = Math.max(0, columns.gap ?? 0);
79277
79590
  const totalGap = gap * (columns.count - 1);
79278
- const columnWidth = (contentWidth - totalGap) / columns.count;
79279
- if (columnWidth > 0) {
79280
- return {
79281
- measurementWidth: columnWidth,
79282
- measurementHeight: contentHeight
79591
+ return (contentWidth - totalGap) / columns.count;
79592
+ };
79593
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
79594
+ let measurementHeight = baseContentHeight;
79595
+ if (blocks && blocks.length > 0) {
79596
+ for (const block of blocks) {
79597
+ if (block.kind !== "sectionBreak") continue;
79598
+ const sectionPageSize = block.pageSize ?? pageSize;
79599
+ const sectionMargins = {
79600
+ top: normalizeMargin(block.margins?.top, margins.top),
79601
+ right: normalizeMargin(block.margins?.right, margins.right),
79602
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
79603
+ left: normalizeMargin(block.margins?.left, margins.left)
79283
79604
  };
79605
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
79606
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
79607
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
79608
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
79609
+ if (columnWidth > measurementWidth) {
79610
+ measurementWidth = columnWidth;
79611
+ }
79612
+ if (contentHeight > measurementHeight) {
79613
+ measurementHeight = contentHeight;
79614
+ }
79284
79615
  }
79285
79616
  }
79286
79617
  return {
79287
- measurementWidth: contentWidth,
79288
- measurementHeight: contentHeight
79618
+ measurementWidth,
79619
+ measurementHeight
79289
79620
  };
79290
79621
  }
79291
79622
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -81352,6 +81683,7 @@ function isInRegisteredSurface(event) {
81352
81683
  }
81353
81684
  return false;
81354
81685
  }
81686
+ const SLASH_MENU_HANDLED_FLAG = "__sdHandledBySlashMenu";
81355
81687
  class PresentationInputBridge {
81356
81688
  /**
81357
81689
  * Creates a new PresentationInputBridge that forwards user input events from the visible layout
@@ -81565,6 +81897,10 @@ forwardCompositionEvent_fn = function(event) {
81565
81897
  __privateMethod$1(this, _PresentationInputBridge_instances, dispatchToTarget_fn).call(this, event, synthetic);
81566
81898
  };
81567
81899
  forwardContextMenu_fn = function(event) {
81900
+ const handledBySlashMenu = Boolean(event[SLASH_MENU_HANDLED_FLAG]);
81901
+ if (handledBySlashMenu) {
81902
+ return;
81903
+ }
81568
81904
  if (!__privateGet$1(this, _isEditable).call(this)) {
81569
81905
  return;
81570
81906
  }
@@ -85258,8 +85594,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
85258
85594
  }
85259
85595
  return void 0;
85260
85596
  }
85261
- const DEFAULT_LIST_HANGING_PX$1 = 18;
85262
- const LIST_MARKER_GAP$1 = 8;
85597
+ const DEFAULT_LIST_HANGING_PX = 18;
85598
+ const LIST_MARKER_GAP = 8;
85263
85599
  const DEFAULT_BULLET_GLYPH = "•";
85264
85600
  const DEFAULT_DECIMAL_PATTERN = "%1.";
85265
85601
  const ASCII_UPPERCASE_A = 65;
@@ -85670,7 +86006,7 @@ function computeWordParagraphLayout(input) {
85670
86006
  let markerBoxWidthPx;
85671
86007
  let markerX;
85672
86008
  if (hasFirstLineIndent) {
85673
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
86009
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
85674
86010
  markerX = indentLeftPx + (firstLinePx ?? 0);
85675
86011
  layout.textStartPx = markerX + markerBoxWidthPx;
85676
86012
  layout.hangingPx = 0;
@@ -85770,12 +86106,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
85770
86106
  let markerBox = Math.max(hangingPxRaw || 0, 0);
85771
86107
  if (markerBox <= 0) {
85772
86108
  if (glyphWidthPx != null && glyphWidthPx > 0) {
85773
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86109
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85774
86110
  } else {
85775
- markerBox = DEFAULT_LIST_HANGING_PX$1;
86111
+ markerBox = DEFAULT_LIST_HANGING_PX;
85776
86112
  }
85777
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
85778
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86113
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
86114
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85779
86115
  }
85780
86116
  return markerBox;
85781
86117
  };
@@ -85795,7 +86131,7 @@ const buildMarkerLayout = ({
85795
86131
  textStartX: textStartPx,
85796
86132
  baselineOffsetPx: markerRun.baselineShift ?? 0,
85797
86133
  // Gutter is the small gap between marker and text, not the full marker box width
85798
- gutterWidthPx: LIST_MARKER_GAP$1,
86134
+ gutterWidthPx: LIST_MARKER_GAP,
85799
86135
  justification: numbering.lvlJc ?? "left",
85800
86136
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
85801
86137
  run: markerRun,
@@ -86487,6 +86823,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
86487
86823
  return null;
86488
86824
  }
86489
86825
  };
86826
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
86827
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
86828
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
86829
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
86830
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
86831
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
86832
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
86833
+ wordLayout.firstLineIndentMode = false;
86834
+ }
86835
+ if (wordLayout.firstLineIndentMode === true) {
86836
+ if (isFiniteNumber(wordLayout.textStartPx)) {
86837
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
86838
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
86839
+ }
86840
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
86841
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
86842
+ }
86843
+ } else {
86844
+ wordLayout.textStartPx = indentLeft;
86845
+ if (wordLayout.marker) {
86846
+ wordLayout.marker.textStartX = indentLeft;
86847
+ }
86848
+ }
86849
+ return wordLayout;
86850
+ };
86490
86851
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
86491
86852
  const attrs = para.attrs ?? {};
86492
86853
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -86809,8 +87170,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86809
87170
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
86810
87171
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
86811
87172
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86812
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86813
- if (firstLinePx > 0) {
87173
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87174
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87175
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87176
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87177
+ if (firstLinePx > 0 && !hangingPx) {
86814
87178
  wordLayout = {
86815
87179
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
86816
87180
  firstLineIndentMode: true,
@@ -86818,10 +87182,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86818
87182
  };
86819
87183
  }
86820
87184
  }
86821
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
87185
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
86822
87186
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86823
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86824
- if (firstLinePx > 0) {
87187
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87188
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87189
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87190
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87191
+ if (firstLinePx > 0 && !hangingPx) {
86825
87192
  wordLayout = {
86826
87193
  ...wordLayout,
86827
87194
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -86841,6 +87208,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86841
87208
  wordLayout.marker.suffix = listRendering.suffix;
86842
87209
  }
86843
87210
  }
87211
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
86844
87212
  paragraphAttrs.wordLayout = wordLayout;
86845
87213
  }
86846
87214
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -90957,11 +91325,6 @@ function initHeaderFooterRegistry({
90957
91325
  cleanups
90958
91326
  };
90959
91327
  }
90960
- const LIST_MARKER_GAP = 8;
90961
- const MIN_MARKER_GUTTER = 24;
90962
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
90963
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
90964
- const DEFAULT_LIST_HANGING_PX = 18;
90965
91328
  function calculateRotatedBounds(input) {
90966
91329
  const width = Math.max(0, input.width);
90967
91330
  const height = Math.max(0, input.height);
@@ -91225,8 +91588,25 @@ async function measureParagraphBlock(block, maxWidth) {
91225
91588
  const rawTextStartPx = wordLayout?.textStartPx;
91226
91589
  const markerTextStartX = wordLayout?.marker?.textStartX;
91227
91590
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
91228
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
91229
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
91591
+ const resolvedTextStartPx = resolveListTextStartPx(
91592
+ wordLayout,
91593
+ indentLeft,
91594
+ firstLine,
91595
+ hanging,
91596
+ (markerText, marker) => {
91597
+ const markerRun = {
91598
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
91599
+ fontSize: marker.run?.fontSize ?? 16,
91600
+ bold: marker.run?.bold ?? false,
91601
+ italic: marker.run?.italic ?? false
91602
+ };
91603
+ const { font: markerFont } = buildFontString(markerRun);
91604
+ return measureText(markerText, markerFont, ctx2);
91605
+ }
91606
+ );
91607
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
91608
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
91609
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
91230
91610
  } else {
91231
91611
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
91232
91612
  }
@@ -91313,7 +91693,7 @@ async function measureParagraphBlock(block, maxWidth) {
91313
91693
  pendingTabAlignment = null;
91314
91694
  return startX;
91315
91695
  };
91316
- const alignSegmentAtTab = (segmentText, font, runContext) => {
91696
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
91317
91697
  if (!pendingTabAlignment || !currentLine) return void 0;
91318
91698
  const { val } = pendingTabAlignment;
91319
91699
  let segmentWidth = 0;
@@ -91322,11 +91702,11 @@ async function measureParagraphBlock(block, maxWidth) {
91322
91702
  const idx = segmentText.indexOf(decimalSeparator);
91323
91703
  if (idx >= 0) {
91324
91704
  const beforeText = segmentText.slice(0, idx);
91325
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
91705
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
91326
91706
  }
91327
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
91707
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91328
91708
  } else if (val === "end" || val === "center") {
91329
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
91709
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91330
91710
  }
91331
91711
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
91332
91712
  };
@@ -91378,8 +91758,8 @@ async function measureParagraphBlock(block, maxWidth) {
91378
91758
  const { font } = buildFontString(
91379
91759
  lastRun
91380
91760
  );
91381
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
91382
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
91761
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
91762
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
91383
91763
  const delta = Math.max(0, fullWidth - keptWidth);
91384
91764
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
91385
91765
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -91590,7 +91970,8 @@ async function measureParagraphBlock(block, maxWidth) {
91590
91970
  continue;
91591
91971
  }
91592
91972
  if (isFieldAnnotationRun(run2)) {
91593
- const displayText = run2.displayLabel || "";
91973
+ const rawDisplayText = run2.displayLabel || "";
91974
+ const displayText = applyTextTransform(rawDisplayText, run2);
91594
91975
  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;
91595
91976
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
91596
91977
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -91693,7 +92074,7 @@ async function measureParagraphBlock(block, maxWidth) {
91693
92074
  const spacesLength = segment.length;
91694
92075
  const spacesStartChar = charPosInRun;
91695
92076
  const spacesEndChar = charPosInRun + spacesLength;
91696
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
92077
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
91697
92078
  if (!currentLine) {
91698
92079
  currentLine = {
91699
92080
  fromRun: runIndex,
@@ -91757,7 +92138,7 @@ async function measureParagraphBlock(block, maxWidth) {
91757
92138
  }
91758
92139
  let segmentStartX;
91759
92140
  if (currentLine && pendingTabAlignment) {
91760
- segmentStartX = alignSegmentAtTab(segment, font, run2);
92141
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
91761
92142
  if (segmentStartX == null) {
91762
92143
  segmentStartX = currentLine.width;
91763
92144
  }
@@ -91767,7 +92148,7 @@ async function measureParagraphBlock(block, maxWidth) {
91767
92148
  if (word2 === "") {
91768
92149
  const spaceStartChar = charPosInRun;
91769
92150
  const spaceEndChar = charPosInRun + 1;
91770
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
92151
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
91771
92152
  if (!currentLine) {
91772
92153
  currentLine = {
91773
92154
  fromRun: runIndex,
@@ -91818,12 +92199,12 @@ async function measureParagraphBlock(block, maxWidth) {
91818
92199
  charPosInRun = spaceEndChar;
91819
92200
  continue;
91820
92201
  }
91821
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
91822
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91823
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
91824
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
91825
92202
  const wordStartChar = charPosInRun;
92203
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
92204
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91826
92205
  const wordEndNoSpace = charPosInRun + word2.length;
92206
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
92207
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
91827
92208
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
91828
92209
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
91829
92210
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -91842,7 +92223,7 @@ async function measureParagraphBlock(block, maxWidth) {
91842
92223
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
91843
92224
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
91844
92225
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
91845
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
92226
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
91846
92227
  let chunkCharOffset = wordStartChar;
91847
92228
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
91848
92229
  const chunk = chunks[chunkIndex];
@@ -91966,7 +92347,7 @@ async function measureParagraphBlock(block, maxWidth) {
91966
92347
  if (candidateSpaces > 0) {
91967
92348
  const overflow = totalWidthWithWord - availableWidth;
91968
92349
  if (overflow > 0) {
91969
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
92350
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
91970
92351
  const perSpaceCompression = overflow / candidateSpaces;
91971
92352
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
91972
92353
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -92141,8 +92522,8 @@ async function measureParagraphBlock(block, maxWidth) {
92141
92522
  const { font: markerFont } = buildFontString(markerRun);
92142
92523
  const markerText = wordLayout.marker.markerText ?? "";
92143
92524
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92144
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
92145
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
92525
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
92526
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
92146
92527
  markerInfo = {
92147
92528
  markerWidth: markerBoxWidth,
92148
92529
  markerTextWidth: glyphWidth,
@@ -92486,7 +92867,7 @@ async function measureListBlock(block, constraints) {
92486
92867
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92487
92868
  indentLeft = resolveIndentLeft(item);
92488
92869
  const indentHanging = resolveIndentHanging(item);
92489
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
92870
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
92490
92871
  }
92491
92872
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
92492
92873
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -92512,16 +92893,46 @@ const getPrimaryRun = (paragraph) => {
92512
92893
  fontSize: 16
92513
92894
  };
92514
92895
  };
92515
- const measureRunWidth = (text, font, ctx2, run2) => {
92896
+ const isWordChar = (char) => {
92897
+ if (!char) return false;
92898
+ const code = char.charCodeAt(0);
92899
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
92900
+ };
92901
+ const capitalizeText = (text, fullText, startOffset) => {
92902
+ if (!text) return text;
92903
+ const hasFullText = typeof startOffset === "number" && fullText != null;
92904
+ let result = "";
92905
+ for (let i = 0; i < text.length; i += 1) {
92906
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
92907
+ const ch = text[i];
92908
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
92909
+ }
92910
+ return result;
92911
+ };
92912
+ const applyTextTransform = (text, run2, startOffset) => {
92913
+ const transform = run2.textTransform;
92914
+ if (!text || !transform || transform === "none") return text;
92915
+ if (transform === "uppercase") return text.toUpperCase();
92916
+ if (transform === "lowercase") return text.toLowerCase();
92917
+ if (transform === "capitalize") {
92918
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text;
92919
+ return capitalizeText(text, fullText, startOffset);
92920
+ }
92921
+ return text;
92922
+ };
92923
+ const measureRunWidth = (text, font, ctx2, run2, startOffset) => {
92516
92924
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
92517
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
92925
+ const displayText = applyTextTransform(text, run2, startOffset);
92926
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
92518
92927
  return roundValue(width);
92519
92928
  };
92520
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
92929
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
92521
92930
  const chunks = [];
92931
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
92522
92932
  if (maxWidth <= 0) {
92523
- for (const char of word2) {
92524
- const charWidth = measureRunWidth(char, font, ctx2, run2);
92933
+ for (let i = 0; i < word2.length; i++) {
92934
+ const char = word2[i];
92935
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92525
92936
  chunks.push({ text: char, width: charWidth });
92526
92937
  }
92527
92938
  return chunks;
@@ -92531,11 +92942,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
92531
92942
  for (let i = 0; i < word2.length; i++) {
92532
92943
  const char = word2[i];
92533
92944
  const testChunk = currentChunk + char;
92534
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
92945
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
92535
92946
  if (testWidth > maxWidth && currentChunk.length > 0) {
92536
92947
  chunks.push({ text: currentChunk, width: currentWidth });
92537
92948
  currentChunk = char;
92538
- currentWidth = measureRunWidth(char, font, ctx2, run2);
92949
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92539
92950
  } else {
92540
92951
  currentChunk = testChunk;
92541
92952
  currentWidth = testWidth;
@@ -92589,7 +93000,8 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
92589
93000
  italic: run2.italic
92590
93001
  });
92591
93002
  ctx2.font = font;
92592
- const metrics = ctx2.measureText(run2.text);
93003
+ const displayText = applyTextTransform(run2.text, run2);
93004
+ const metrics = ctx2.measureText(displayText);
92593
93005
  const advanceWidth = metrics.width;
92594
93006
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
92595
93007
  const textWidth = Math.max(advanceWidth, paintedWidth);
@@ -92615,7 +93027,7 @@ const resolveIndentHanging = (item) => {
92615
93027
  if (indentHanging > 0) {
92616
93028
  return indentHanging;
92617
93029
  }
92618
- return DEFAULT_LIST_HANGING_PX;
93030
+ return DEFAULT_LIST_HANGING_PX$1;
92619
93031
  };
92620
93032
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
92621
93033
  const paragraphIndentTwips = {
@@ -129677,11 +130089,23 @@ const _sfc_main$8 = {
129677
130089
  closeMenu({ restoreCursor: false });
129678
130090
  }
129679
130091
  };
129680
- const handleRightClick = async (event) => {
130092
+ const shouldHandleContextMenu = (event) => {
129681
130093
  const readOnly = !props.editor?.isEditable;
129682
130094
  const contextMenuDisabled = props.editor?.options?.disableContextMenu;
129683
130095
  const bypass = shouldBypassContextMenu(event);
129684
- if (readOnly || contextMenuDisabled || bypass) {
130096
+ return !readOnly && !contextMenuDisabled && !bypass;
130097
+ };
130098
+ const handleRightClickCapture = (event) => {
130099
+ try {
130100
+ if (shouldHandleContextMenu(event)) {
130101
+ event[SLASH_MENU_HANDLED_FLAG] = true;
130102
+ }
130103
+ } catch (error) {
130104
+ console.warn("[SlashMenu] Error in capture phase context menu handler:", error);
130105
+ }
130106
+ };
130107
+ const handleRightClick = async (event) => {
130108
+ if (!shouldHandleContextMenu(event)) {
129685
130109
  return;
129686
130110
  }
129687
130111
  event.preventDefault();
@@ -129792,6 +130216,7 @@ const _sfc_main$8 = {
129792
130216
  props.editor.on("slashMenu:open", slashMenuOpenHandler);
129793
130217
  contextMenuTarget = getEditorSurfaceElement(props.editor);
129794
130218
  if (contextMenuTarget) {
130219
+ contextMenuTarget.addEventListener("contextmenu", handleRightClickCapture, true);
129795
130220
  contextMenuTarget.addEventListener("contextmenu", handleRightClick);
129796
130221
  }
129797
130222
  slashMenuCloseHandler = () => {
@@ -129815,6 +130240,7 @@ const _sfc_main$8 = {
129815
130240
  props.editor.off("slashMenu:close", slashMenuCloseHandler);
129816
130241
  }
129817
130242
  props.editor.off("update", handleEditorUpdate);
130243
+ contextMenuTarget?.removeEventListener("contextmenu", handleRightClickCapture, true);
129818
130244
  contextMenuTarget?.removeEventListener("contextmenu", handleRightClick);
129819
130245
  } catch (error) {
129820
130246
  console.warn("[SlashMenu] Error during cleanup:", error);