superdoc 1.0.2 → 1.0.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 (30) hide show
  1. package/dist/chunks/{PdfViewer-Dk7wI3bm.cjs → PdfViewer-2wYU1nQs.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-C51KNTCu.es.js → PdfViewer-Brf64q-p.es.js} +1 -1
  3. package/dist/chunks/{index-DDZ1ZT8N-DzepXBTN.cjs → index-BFesQTtm-DF8MwT73.cjs} +1 -1
  4. package/dist/chunks/{index-DDZ1ZT8N-MJzqg0qg.es.js → index-BFesQTtm-DNeH374x.es.js} +1 -1
  5. package/dist/chunks/{index-Cf7hdzkm.cjs → index-DeETxTrW.cjs} +3 -3
  6. package/dist/chunks/{index-rtbawgUA.es.js → index-KBIvw6xZ.es.js} +3 -3
  7. package/dist/chunks/{super-editor.es-BijxiFs9.cjs → super-editor.es-C_LoTWvJ.cjs} +687 -136
  8. package/dist/chunks/{super-editor.es-DFXddrgb.es.js → super-editor.es-DWpzsMUa.es.js} +687 -136
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  10. package/dist/style.css +6 -6
  11. package/dist/super-editor/ai-writer.es.js +2 -2
  12. package/dist/super-editor/chunks/{converter-VYPiNbpo.js → converter-BhELnOP5.js} +1 -1
  13. package/dist/super-editor/chunks/{docx-zipper-D8Tzq3RX.js → docx-zipper-Bwi8bTEB.js} +1 -1
  14. package/dist/super-editor/chunks/{editor-mgoEnsBi.js → editor-Dyj08tpz.js} +684 -150
  15. package/dist/super-editor/chunks/{index-DDZ1ZT8N.js → index-BFesQTtm.js} +1 -1
  16. package/dist/super-editor/chunks/{toolbar-DULgxvjl.js → toolbar-DRFf1nRv.js} +2 -2
  17. package/dist/super-editor/converter.es.js +1 -1
  18. package/dist/super-editor/docx-zipper.es.js +2 -2
  19. package/dist/super-editor/editor.es.js +3 -3
  20. package/dist/super-editor/file-zipper.es.js +1 -1
  21. package/dist/super-editor/style.css +6 -6
  22. package/dist/super-editor/super-editor.es.js +41 -17
  23. package/dist/super-editor/toolbar.es.js +2 -2
  24. package/dist/super-editor.cjs +1 -1
  25. package/dist/super-editor.es.js +1 -1
  26. package/dist/superdoc.cjs +2 -2
  27. package/dist/superdoc.es.js +2 -2
  28. package/dist/superdoc.umd.js +689 -138
  29. package/dist/superdoc.umd.js.map +1 -1
  30. package/package.json +1 -1
@@ -42428,7 +42428,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42428
42428
  static getStoredSuperdocVersion(docx) {
42429
42429
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42430
42430
  }
42431
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.2") {
42431
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.3") {
42432
42432
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42433
42433
  }
42434
42434
  /**
@@ -68384,7 +68384,7 @@ ${err.toString()}`);
68384
68384
  const shouldSkipNodeView = (editor) => {
68385
68385
  return isHeadless(editor);
68386
68386
  };
68387
- const summaryVersion = "1.0.2";
68387
+ const summaryVersion = "1.0.3";
68388
68388
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
68389
68389
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
68390
68390
  function mapAttributes(attrs) {
@@ -69173,7 +69173,7 @@ ${err.toString()}`);
69173
69173
  { default: remarkStringify2 },
69174
69174
  { default: remarkGfm2 }
69175
69175
  ] = await Promise.all([
69176
- Promise.resolve().then(() => indexDDZ1ZT8N),
69176
+ Promise.resolve().then(() => indexBFesQTtm),
69177
69177
  Promise.resolve().then(() => indexDRCvimau),
69178
69178
  Promise.resolve().then(() => indexC_x_N6Uh),
69179
69179
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -69378,7 +69378,7 @@ ${err.toString()}`);
69378
69378
  * Process collaboration migrations
69379
69379
  */
69380
69380
  processCollaborationMigrations() {
69381
- console.debug("[checkVersionMigrations] Current editor version", "1.0.2");
69381
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.3");
69382
69382
  if (!this.options.ydoc) return;
69383
69383
  const metaMap = this.options.ydoc.getMap("meta");
69384
69384
  let docVersion = metaMap.get("version");
@@ -76630,7 +76630,7 @@ ${l}
76630
76630
  return true;
76631
76631
  }
76632
76632
  const LIST_MARKER_GAP$2 = 8;
76633
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
76633
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
76634
76634
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
76635
76635
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
76636
76636
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -77557,6 +77557,7 @@ ${l}
77557
77557
  const block = lookup2.block;
77558
77558
  const measure = lookup2.measure;
77559
77559
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
77560
+ const alignment2 = block.attrs?.alignment;
77560
77561
  const fragmentEl = this.doc.createElement("div");
77561
77562
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
77562
77563
  const isTocEntry = block.attrs?.isTocEntry;
@@ -77635,7 +77636,7 @@ ${l}
77635
77636
  const textStart = paraIndentLeft + firstLine;
77636
77637
  tabWidth = textStart - currentPos;
77637
77638
  if (tabWidth <= 0) {
77638
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77639
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77639
77640
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77640
77641
  tabWidth = LIST_MARKER_GAP$2;
77641
77642
  }
@@ -77662,6 +77663,21 @@ ${l}
77662
77663
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
77663
77664
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
77664
77665
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
77666
+ if (alignment2 === "justify" || alignment2 === "both") {
77667
+ console.log(
77668
+ "[justify-debug][painter-firstline-available]",
77669
+ JSON.stringify({
77670
+ blockId: block.id,
77671
+ fragmentWidth: fragment.width,
77672
+ markerTabWidth: listFirstLineMarkerTabWidth,
77673
+ paraIndentRight,
77674
+ availableWidthOverride,
77675
+ lineMaxWidth: line.maxWidth ?? null,
77676
+ lineWidth: line.width,
77677
+ lineNaturalWidth: line.naturalWidth ?? null
77678
+ })
77679
+ );
77680
+ }
77665
77681
  }
77666
77682
  const isLastLineOfFragment = index2 === lines.length - 1;
77667
77683
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -77787,7 +77803,7 @@ ${l}
77787
77803
  const textStart = paraIndentLeft + firstLine;
77788
77804
  tabWidth = textStart - currentPos;
77789
77805
  if (tabWidth <= 0) {
77790
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77806
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77791
77807
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77792
77808
  tabWidth = LIST_MARKER_GAP$2;
77793
77809
  }
@@ -79321,6 +79337,23 @@ ${l}
79321
79337
  if (spacingPerSpace !== 0) {
79322
79338
  el.style.wordSpacing = `${spacingPerSpace}px`;
79323
79339
  }
79340
+ if (justifyShouldApply && spacingPerSpace < 0) {
79341
+ console.log(
79342
+ "[justify-debug][painter-wordspacing-negative]",
79343
+ JSON.stringify({
79344
+ blockId: block.id,
79345
+ lineIndex: lineIndex ?? null,
79346
+ alignment: alignment2 ?? null,
79347
+ availableWidth,
79348
+ lineWidth,
79349
+ lineMaxWidth: line.maxWidth ?? null,
79350
+ lineNaturalWidth: line.naturalWidth ?? null,
79351
+ spaceCount,
79352
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
79353
+ skipJustify: Boolean(skipJustify)
79354
+ })
79355
+ );
79356
+ }
79324
79357
  if (hasExplicitPositioning && line.segments) {
79325
79358
  const paraIndent = block.attrs?.indent;
79326
79359
  const indentLeft = paraIndent?.left ?? 0;
@@ -81514,6 +81547,28 @@ ${l}
81514
81547
  const TAB_CHAR_LENGTH = 1;
81515
81548
  const SPACE_CHARS = SPACE_CHARS$1;
81516
81549
  const isTabRun$1 = (run2) => run2?.kind === "tab";
81550
+ const isWordChar$3 = (char) => {
81551
+ if (!char) return false;
81552
+ const code2 = char.charCodeAt(0);
81553
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
81554
+ };
81555
+ const capitalizeText$2 = (text2) => {
81556
+ if (!text2) return text2;
81557
+ let result = "";
81558
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
81559
+ const prevChar = i2 > 0 ? text2[i2 - 1] : "";
81560
+ const ch = text2[i2];
81561
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
81562
+ }
81563
+ return result;
81564
+ };
81565
+ const applyTextTransform$2 = (text2, transform) => {
81566
+ if (!text2 || !transform || transform === "none") return text2;
81567
+ if (transform === "uppercase") return text2.toUpperCase();
81568
+ if (transform === "lowercase") return text2.toLowerCase();
81569
+ if (transform === "capitalize") return capitalizeText$2(text2);
81570
+ return text2;
81571
+ };
81517
81572
  function getMeasurementContext() {
81518
81573
  if (measurementCtx) return measurementCtx;
81519
81574
  if (typeof document === "undefined") {
@@ -81689,17 +81744,18 @@ ${l}
81689
81744
  }
81690
81745
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81691
81746
  const runLength = text2.length;
81747
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81692
81748
  if (currentCharOffset + runLength >= charOffset) {
81693
81749
  const offsetInRun = charOffset - currentCharOffset;
81694
81750
  ctx2.font = getRunFontString(run2);
81695
- const textUpToTarget = text2.slice(0, offsetInRun);
81751
+ const textUpToTarget = displayText.slice(0, offsetInRun);
81696
81752
  const measured2 = ctx2.measureText(textUpToTarget);
81697
81753
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
81698
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
81754
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text2.slice(0, offsetInRun)) : 0;
81699
81755
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
81700
81756
  }
81701
81757
  ctx2.font = getRunFontString(run2);
81702
- const measured = ctx2.measureText(text2);
81758
+ const measured = ctx2.measureText(displayText);
81703
81759
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81704
81760
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text2) : 0;
81705
81761
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -81738,8 +81794,9 @@ ${l}
81738
81794
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
81739
81795
  }
81740
81796
  const text2 = run2.text ?? "";
81741
- const segmentText = text2.slice(segment.fromChar, segment.toChar);
81742
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
81797
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81798
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
81799
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
81743
81800
  ctx2.font = getRunFontString(run2);
81744
81801
  const measured = ctx2.measureText(textUpToTarget);
81745
81802
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -81835,12 +81892,13 @@ ${l}
81835
81892
  }
81836
81893
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81837
81894
  const runLength = text2.length;
81895
+ const displayText = applyTextTransform$2(text2, run2.textTransform);
81838
81896
  if (runLength === 0) continue;
81839
81897
  ctx2.font = getRunFontString(run2);
81840
81898
  for (let i2 = 0; i2 <= runLength; i2++) {
81841
- const textUpToChar = text2.slice(0, i2);
81899
+ const textUpToChar = displayText.slice(0, i2);
81842
81900
  const measured2 = ctx2.measureText(textUpToChar);
81843
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
81901
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text2.slice(0, i2)) : 0;
81844
81902
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i2, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
81845
81903
  if (charX >= safeX) {
81846
81904
  if (i2 === 0) {
@@ -81850,7 +81908,7 @@ ${l}
81850
81908
  pmPosition: pmPosition3
81851
81909
  };
81852
81910
  }
81853
- const prevText = text2.slice(0, i2 - 1);
81911
+ const prevText = displayText.slice(0, i2 - 1);
81854
81912
  const prevMeasured = ctx2.measureText(prevText);
81855
81913
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i2 - 1, runLength);
81856
81914
  const distToPrev = Math.abs(safeX - prevX);
@@ -81863,7 +81921,7 @@ ${l}
81863
81921
  };
81864
81922
  }
81865
81923
  }
81866
- const measured = ctx2.measureText(text2);
81924
+ const measured = ctx2.measureText(displayText);
81867
81925
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81868
81926
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text2) : 0;
81869
81927
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -82294,6 +82352,83 @@ ${l}
82294
82352
  }
82295
82353
  return index2;
82296
82354
  }
82355
+ const LIST_MARKER_GAP$1 = 8;
82356
+ const MIN_MARKER_GUTTER = 24;
82357
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
82358
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
82359
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
82360
+ const SPACE_SUFFIX_GAP_PX = 4;
82361
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
82362
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
82363
+ const marker = wordLayout?.marker;
82364
+ if (!marker) {
82365
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
82366
+ return textStartPx;
82367
+ }
82368
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
82369
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
82370
+ if (markerTextWidth == null && marker.markerText) {
82371
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
82372
+ }
82373
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth < 0) {
82374
+ markerTextWidth = markerBoxWidth;
82375
+ }
82376
+ markerTextWidth = Math.max(0, markerTextWidth);
82377
+ let markerStartPos;
82378
+ if (wordLayout?.firstLineIndentMode === true && Number.isFinite(marker.markerX)) {
82379
+ markerStartPos = marker.markerX;
82380
+ } else {
82381
+ markerStartPos = indentLeft - hanging + firstLine;
82382
+ }
82383
+ if (!Number.isFinite(markerStartPos)) {
82384
+ markerStartPos = 0;
82385
+ }
82386
+ const currentPos = markerStartPos + markerTextWidth;
82387
+ const suffix2 = marker.suffix ?? "tab";
82388
+ if (suffix2 === "space") {
82389
+ return markerStartPos + markerTextWidth + SPACE_SUFFIX_GAP_PX;
82390
+ }
82391
+ if (suffix2 === "nothing") {
82392
+ return markerStartPos + markerTextWidth;
82393
+ }
82394
+ const markerJustification = marker.justification ?? "left";
82395
+ if (markerJustification !== "left") {
82396
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
82397
+ return markerStartPos + markerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
82398
+ }
82399
+ if (wordLayout?.firstLineIndentMode === true) {
82400
+ let targetTabStop;
82401
+ if (Array.isArray(wordLayout.tabsPx)) {
82402
+ for (const tab of wordLayout.tabsPx) {
82403
+ if (typeof tab === "number" && tab > currentPos) {
82404
+ targetTabStop = tab;
82405
+ break;
82406
+ }
82407
+ }
82408
+ }
82409
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
82410
+ let tabWidth2;
82411
+ if (targetTabStop !== void 0) {
82412
+ tabWidth2 = targetTabStop - currentPos;
82413
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
82414
+ tabWidth2 = textStartTarget - currentPos;
82415
+ } else {
82416
+ tabWidth2 = LIST_MARKER_GAP$1;
82417
+ }
82418
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
82419
+ tabWidth2 = LIST_MARKER_GAP$1;
82420
+ }
82421
+ return markerStartPos + markerTextWidth + tabWidth2;
82422
+ }
82423
+ const textStart = indentLeft + firstLine;
82424
+ let tabWidth = textStart - currentPos;
82425
+ if (tabWidth <= 0) {
82426
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
82427
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
82428
+ tabWidth = LIST_MARKER_GAP$1;
82429
+ }
82430
+ return markerStartPos + markerTextWidth + tabWidth;
82431
+ }
82297
82432
  function getWordLayoutConfig(block) {
82298
82433
  if (!block || block.kind !== "paragraph") {
82299
82434
  return void 0;
@@ -82326,9 +82461,16 @@ ${l}
82326
82461
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
82327
82462
  let indentAdjust = paraIndentLeft;
82328
82463
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
82464
+ const resolvedTextStart = resolveListTextStartPx(
82465
+ wordLayout,
82466
+ paraIndentLeft,
82467
+ Math.max(firstLineIndent, 0),
82468
+ Math.max(hangingIndent, 0),
82469
+ () => markerWidth
82470
+ // Use provided markerWidth since we don't have canvas access here
82471
+ );
82329
82472
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
82330
- const markerTextStartX = wordLayout?.marker?.textStartX;
82331
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
82473
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
82332
82474
  } else if (isFirstLine && !isListItem2) {
82333
82475
  indentAdjust += firstLineOffset;
82334
82476
  }
@@ -82484,7 +82626,10 @@ ${l}
82484
82626
  }
82485
82627
  function createFloatingObjectManager(columns, margins, pageWidth) {
82486
82628
  const zones = [];
82487
- const marginLeft = Math.max(0, margins?.left ?? 0);
82629
+ let currentColumns = columns;
82630
+ let currentMargins = margins;
82631
+ let currentPageWidth = pageWidth;
82632
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
82488
82633
  return {
82489
82634
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
82490
82635
  if (!drawingBlock.anchor?.isAnchored) {
@@ -82497,7 +82642,7 @@ ${l}
82497
82642
  }
82498
82643
  const objectWidth = measure.width ?? 0;
82499
82644
  const objectHeight = measure.height ?? 0;
82500
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
82645
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
82501
82646
  const y2 = anchorY + (anchor.offsetV ?? 0);
82502
82647
  const zone = {
82503
82648
  imageBlockId: drawingBlock.id,
@@ -82531,7 +82676,7 @@ ${l}
82531
82676
  }
82532
82677
  const tableWidth = measure.totalWidth ?? 0;
82533
82678
  const tableHeight = measure.totalHeight ?? 0;
82534
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
82679
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
82535
82680
  const y2 = anchorY + (anchor.offsetV ?? 0);
82536
82681
  const zone = {
82537
82682
  imageBlockId: tableBlock.id,
@@ -82579,7 +82724,7 @@ ${l}
82579
82724
  }
82580
82725
  const leftFloats = [];
82581
82726
  const rightFloats = [];
82582
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
82727
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
82583
82728
  const columnCenter = columnOrigin + baseWidth / 2;
82584
82729
  for (const zone of wrappingZones) {
82585
82730
  if (zone.wrapMode === "left") {
@@ -82618,6 +82763,22 @@ ${l}
82618
82763
  },
82619
82764
  clear() {
82620
82765
  zones.length = 0;
82766
+ },
82767
+ /**
82768
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
82769
+ * This method should be called when the layout configuration changes (e.g., section breaks,
82770
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
82771
+ * correctly relative to the new layout boundaries.
82772
+ *
82773
+ * @param nextColumns - Column layout configuration (width, gap, count)
82774
+ * @param nextMargins - Optional page margins (left, right) in pixels
82775
+ * @param nextPageWidth - Optional total page width in pixels
82776
+ */
82777
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
82778
+ currentColumns = nextColumns;
82779
+ currentMargins = nextMargins;
82780
+ currentPageWidth = nextPageWidth;
82781
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
82621
82782
  }
82622
82783
  };
82623
82784
  }
@@ -82717,7 +82878,14 @@ ${l}
82717
82878
  const props = {};
82718
82879
  if (source.kind !== "sectionBreak") return props;
82719
82880
  if (source.margins) {
82720
- props.margins = { header: source.margins.header, footer: source.margins.footer };
82881
+ props.margins = {
82882
+ header: source.margins.header,
82883
+ footer: source.margins.footer,
82884
+ top: source.margins.top,
82885
+ right: source.margins.right,
82886
+ bottom: source.margins.bottom,
82887
+ left: source.margins.left
82888
+ };
82721
82889
  }
82722
82890
  if (source.pageSize) {
82723
82891
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -82765,20 +82933,36 @@ ${l}
82765
82933
  next2.activeOrientation = block.orientation;
82766
82934
  next2.pendingOrientation = null;
82767
82935
  }
82936
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
82937
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
82938
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
82939
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
82768
82940
  if (block.margins?.header !== void 0) {
82769
- const headerDistance = Math.max(0, block.margins.header);
82770
82941
  next2.activeHeaderDistance = headerDistance;
82771
82942
  next2.pendingHeaderDistance = headerDistance;
82772
- next2.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
82773
- next2.pendingTopMargin = next2.activeTopMargin;
82774
82943
  }
82775
82944
  if (block.margins?.footer !== void 0) {
82776
- const footerDistance = Math.max(0, block.margins.footer);
82777
82945
  next2.activeFooterDistance = footerDistance;
82778
82946
  next2.pendingFooterDistance = footerDistance;
82779
- next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
82947
+ }
82948
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
82949
+ next2.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
82950
+ next2.pendingTopMargin = next2.activeTopMargin;
82951
+ }
82952
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
82953
+ next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
82780
82954
  next2.pendingBottomMargin = next2.activeBottomMargin;
82781
82955
  }
82956
+ if (block.margins?.left !== void 0) {
82957
+ const leftMargin = Math.max(0, block.margins.left);
82958
+ next2.activeLeftMargin = leftMargin;
82959
+ next2.pendingLeftMargin = leftMargin;
82960
+ }
82961
+ if (block.margins?.right !== void 0) {
82962
+ const rightMargin = Math.max(0, block.margins.right);
82963
+ next2.activeRightMargin = rightMargin;
82964
+ next2.pendingRightMargin = rightMargin;
82965
+ }
82782
82966
  if (block.columns) {
82783
82967
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
82784
82968
  next2.pendingColumns = null;
@@ -82787,26 +82971,42 @@ ${l}
82787
82971
  }
82788
82972
  const headerPx = block.margins?.header;
82789
82973
  const footerPx = block.margins?.footer;
82974
+ const topPx = block.margins?.top;
82975
+ const bottomPx = block.margins?.bottom;
82790
82976
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
82791
82977
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
82978
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
82979
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
82792
82980
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
82793
82981
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
82794
- if (typeof headerPx === "number") {
82795
- const newHeaderDist = Math.max(0, headerPx);
82982
+ if (typeof headerPx === "number" || typeof topPx === "number") {
82983
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
82984
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
82796
82985
  next2.pendingHeaderDistance = newHeaderDist;
82797
- next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
82986
+ next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
82798
82987
  } else {
82799
82988
  next2.pendingTopMargin = nextTop;
82800
82989
  next2.pendingHeaderDistance = nextHeader;
82801
82990
  }
82802
- if (typeof footerPx === "number") {
82803
- const newFooterDist = Math.max(0, footerPx);
82991
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
82992
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
82993
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
82804
82994
  next2.pendingFooterDistance = newFooterDist;
82805
- next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
82995
+ next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
82806
82996
  } else {
82807
82997
  next2.pendingBottomMargin = nextBottom;
82808
82998
  next2.pendingFooterDistance = nextFooter;
82809
82999
  }
83000
+ if (typeof block.margins?.left === "number") {
83001
+ next2.pendingLeftMargin = Math.max(0, block.margins.left);
83002
+ } else {
83003
+ next2.pendingLeftMargin = nextLeft;
83004
+ }
83005
+ if (typeof block.margins?.right === "number") {
83006
+ next2.pendingRightMargin = Math.max(0, block.margins.right);
83007
+ } else {
83008
+ next2.pendingRightMargin = nextRight;
83009
+ }
82810
83010
  if (block.pageSize) {
82811
83011
  next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
82812
83012
  }
@@ -82866,6 +83066,12 @@ ${l}
82866
83066
  if (next2.pendingBottomMargin != null) {
82867
83067
  next2.activeBottomMargin = next2.pendingBottomMargin;
82868
83068
  }
83069
+ if (next2.pendingLeftMargin != null) {
83070
+ next2.activeLeftMargin = next2.pendingLeftMargin;
83071
+ }
83072
+ if (next2.pendingRightMargin != null) {
83073
+ next2.activeRightMargin = next2.pendingRightMargin;
83074
+ }
82869
83075
  if (next2.pendingHeaderDistance != null) {
82870
83076
  next2.activeHeaderDistance = next2.pendingHeaderDistance;
82871
83077
  }
@@ -82883,6 +83089,8 @@ ${l}
82883
83089
  }
82884
83090
  next2.pendingTopMargin = null;
82885
83091
  next2.pendingBottomMargin = null;
83092
+ next2.pendingLeftMargin = null;
83093
+ next2.pendingRightMargin = null;
82886
83094
  next2.pendingHeaderDistance = null;
82887
83095
  next2.pendingFooterDistance = null;
82888
83096
  next2.pendingPageSize = null;
@@ -83111,7 +83319,8 @@ ${l}
83111
83319
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
83112
83320
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83113
83321
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
83114
- lines = normalizeLines(newMeasure);
83322
+ const newLines = normalizeLines(newMeasure);
83323
+ lines = newLines;
83115
83324
  didRemeasureForColumnWidth = true;
83116
83325
  }
83117
83326
  let fromLine = 0;
@@ -83193,7 +83402,8 @@ ${l}
83193
83402
  if (narrowestRemeasureWidth < remeasureWidth) {
83194
83403
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83195
83404
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
83196
- lines = normalizeLines(newMeasure);
83405
+ const newLines = normalizeLines(newMeasure);
83406
+ lines = newLines;
83197
83407
  didRemeasureForFloats = true;
83198
83408
  }
83199
83409
  }
@@ -83537,6 +83747,94 @@ ${l}
83537
83747
  function getCellTotalLines(cell2) {
83538
83748
  return getCellLines(cell2).length;
83539
83749
  }
83750
+ function mergePmRange(target, range2) {
83751
+ if (typeof range2.pmStart === "number") {
83752
+ target.pmStart = target.pmStart == null ? range2.pmStart : Math.min(target.pmStart, range2.pmStart);
83753
+ }
83754
+ if (typeof range2.pmEnd === "number") {
83755
+ target.pmEnd = target.pmEnd == null ? range2.pmEnd : Math.max(target.pmEnd, range2.pmEnd);
83756
+ }
83757
+ }
83758
+ function computeCellPmRange(cell2, cellMeasure, fromLine, toLine) {
83759
+ const range2 = {};
83760
+ if (!cell2 || !cellMeasure) return range2;
83761
+ const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
83762
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
83763
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
83764
+ let cumulativeLineCount = 0;
83765
+ for (let i2 = 0; i2 < maxBlocks; i2++) {
83766
+ const block = cellBlocks[i2];
83767
+ const blockMeasure = blockMeasures[i2];
83768
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
83769
+ const paraMeasure = blockMeasure;
83770
+ const lines = paraMeasure.lines;
83771
+ const blockLineCount = lines?.length ?? 0;
83772
+ const blockStartGlobal = cumulativeLineCount;
83773
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
83774
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
83775
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
83776
+ if (lines && lines.length > 0 && localFrom < localTo) {
83777
+ mergePmRange(range2, computeFragmentPmRange(block, lines, localFrom, localTo));
83778
+ } else {
83779
+ mergePmRange(range2, extractBlockPmRange(block));
83780
+ }
83781
+ cumulativeLineCount += blockLineCount;
83782
+ continue;
83783
+ }
83784
+ mergePmRange(range2, extractBlockPmRange(block));
83785
+ }
83786
+ return range2;
83787
+ }
83788
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
83789
+ const range2 = {};
83790
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
83791
+ const row2 = block.rows[rowIndex];
83792
+ const rowMeasure = measure.rows[rowIndex];
83793
+ if (!row2 || !rowMeasure) continue;
83794
+ const isPartial = partialRow?.rowIndex === rowIndex;
83795
+ const cellCount = Math.min(row2.cells.length, rowMeasure.cells.length);
83796
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
83797
+ const cell2 = row2.cells[cellIndex];
83798
+ const cellMeasure = rowMeasure.cells[cellIndex];
83799
+ if (!cell2 || !cellMeasure) continue;
83800
+ const totalLines = getCellTotalLines(cellMeasure);
83801
+ let fromLine = 0;
83802
+ let toLine = totalLines;
83803
+ if (isPartial) {
83804
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
83805
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
83806
+ if (hasValidFromLineByCell) {
83807
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
83808
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
83809
+ fromLine = rawFrom;
83810
+ }
83811
+ }
83812
+ if (hasValidToLineByCell) {
83813
+ const rawTo = partialRow.toLineByCell[cellIndex];
83814
+ if (typeof rawTo === "number") {
83815
+ toLine = rawTo === -1 ? totalLines : rawTo;
83816
+ }
83817
+ }
83818
+ }
83819
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
83820
+ toLine = Math.max(0, Math.min(toLine, totalLines));
83821
+ if (toLine < fromLine) {
83822
+ toLine = fromLine;
83823
+ }
83824
+ mergePmRange(range2, computeCellPmRange(cell2, cellMeasure, fromLine, toLine));
83825
+ }
83826
+ }
83827
+ return range2;
83828
+ }
83829
+ function applyTableFragmentPmRange(fragment, block, measure) {
83830
+ const range2 = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
83831
+ if (range2.pmStart != null) {
83832
+ fragment.pmStart = range2.pmStart;
83833
+ }
83834
+ if (range2.pmEnd != null) {
83835
+ fragment.pmEnd = range2.pmEnd;
83836
+ }
83837
+ }
83540
83838
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
83541
83839
  const row2 = measure.rows[rowIndex];
83542
83840
  if (!row2) {
@@ -83681,6 +83979,7 @@ ${l}
83681
83979
  height,
83682
83980
  metadata
83683
83981
  };
83982
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
83684
83983
  state2.page.fragments.push(fragment);
83685
83984
  state2.cursorY += height;
83686
83985
  }
@@ -83759,6 +84058,7 @@ ${l}
83759
84058
  height,
83760
84059
  metadata
83761
84060
  };
84061
+ applyTableFragmentPmRange(fragment, block, measure);
83762
84062
  state2.page.fragments.push(fragment);
83763
84063
  state2.cursorY += height;
83764
84064
  return;
@@ -83822,6 +84122,7 @@ ${l}
83822
84122
  partialRow: continuationPartialRow,
83823
84123
  metadata: generateFragmentMetadata(measure)
83824
84124
  };
84125
+ applyTableFragmentPmRange(fragment2, block, measure);
83825
84126
  state2.page.fragments.push(fragment2);
83826
84127
  state2.cursorY += fragmentHeight2;
83827
84128
  }
@@ -83866,6 +84167,7 @@ ${l}
83866
84167
  partialRow: forcedPartialRow,
83867
84168
  metadata: generateFragmentMetadata(measure)
83868
84169
  };
84170
+ applyTableFragmentPmRange(fragment2, block, measure);
83869
84171
  state2.page.fragments.push(fragment2);
83870
84172
  state2.cursorY += fragmentHeight2;
83871
84173
  pendingPartialRow = forcedPartialRow;
@@ -83901,6 +84203,7 @@ ${l}
83901
84203
  partialRow: partialRow || void 0,
83902
84204
  metadata: generateFragmentMetadata(measure)
83903
84205
  };
84206
+ applyTableFragmentPmRange(fragment, block, measure);
83904
84207
  state2.page.fragments.push(fragment);
83905
84208
  state2.cursorY += fragmentHeight;
83906
84209
  if (partialRow && !partialRow.isLastPart) {
@@ -83918,7 +84221,7 @@ ${l}
83918
84221
  columnBoundaries: generateColumnBoundaries(measure),
83919
84222
  coordinateSystem: "fragment"
83920
84223
  };
83921
- return {
84224
+ const fragment = {
83922
84225
  kind: "table",
83923
84226
  blockId: block.id,
83924
84227
  fromRow: 0,
@@ -83929,6 +84232,8 @@ ${l}
83929
84232
  height: measure.totalHeight ?? 0,
83930
84233
  metadata
83931
84234
  };
84235
+ applyTableFragmentPmRange(fragment, block, measure);
84236
+ return fragment;
83932
84237
  }
83933
84238
  function isPageRelativeAnchor(block) {
83934
84239
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -84350,8 +84655,8 @@ ${l}
84350
84655
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
84351
84656
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
84352
84657
  };
84353
- const contentWidth = pageSize.w - (margins.left + margins.right);
84354
- if (contentWidth <= 0) {
84658
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
84659
+ if (baseContentWidth <= 0) {
84355
84660
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
84356
84661
  }
84357
84662
  const validateContentHeight = (height) => {
@@ -84381,8 +84686,12 @@ ${l}
84381
84686
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
84382
84687
  let activeTopMargin = effectiveTopMargin;
84383
84688
  let activeBottomMargin = effectiveBottomMargin;
84689
+ let activeLeftMargin = margins.left;
84690
+ let activeRightMargin = margins.right;
84384
84691
  let pendingTopMargin = null;
84385
84692
  let pendingBottomMargin = null;
84693
+ let pendingLeftMargin = null;
84694
+ let pendingRightMargin = null;
84386
84695
  let activeHeaderDistance = margins.header ?? margins.top;
84387
84696
  let pendingHeaderDistance = null;
84388
84697
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -84395,10 +84704,11 @@ ${l}
84395
84704
  let pendingOrientation = null;
84396
84705
  let activeVAlign = null;
84397
84706
  let pendingVAlign = null;
84707
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
84398
84708
  const floatManager = createFloatingObjectManager(
84399
- normalizeColumns(activeColumns, contentWidth),
84400
- { left: margins.left, right: margins.right },
84401
- pageSize.w
84709
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84710
+ { left: activeLeftMargin, right: activeRightMargin },
84711
+ activePageSize.w
84402
84712
  );
84403
84713
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks2);
84404
84714
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -84415,22 +84725,38 @@ ${l}
84415
84725
  next2.activeOrientation = block.orientation;
84416
84726
  next2.pendingOrientation = null;
84417
84727
  }
84728
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
84729
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
84730
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
84731
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
84418
84732
  if (block.margins?.header !== void 0) {
84419
- const headerDist = Math.max(0, block.margins.header);
84420
- next2.activeHeaderDistance = headerDist;
84421
- next2.pendingHeaderDistance = headerDist;
84422
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
84423
- next2.activeTopMargin = Math.max(baseMargins.top, requiredTop);
84424
- next2.pendingTopMargin = next2.activeTopMargin;
84733
+ next2.activeHeaderDistance = headerDistance2;
84734
+ next2.pendingHeaderDistance = headerDistance2;
84425
84735
  }
84426
84736
  if (block.margins?.footer !== void 0) {
84427
- const footerDistance2 = Math.max(0, block.margins.footer);
84428
84737
  next2.activeFooterDistance = footerDistance2;
84429
84738
  next2.pendingFooterDistance = footerDistance2;
84739
+ }
84740
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
84741
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
84742
+ next2.activeTopMargin = Math.max(sectionTop, requiredTop);
84743
+ next2.pendingTopMargin = next2.activeTopMargin;
84744
+ }
84745
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
84430
84746
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
84431
- next2.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84747
+ next2.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
84432
84748
  next2.pendingBottomMargin = next2.activeBottomMargin;
84433
84749
  }
84750
+ if (block.margins?.left !== void 0) {
84751
+ const leftMargin = Math.max(0, block.margins.left);
84752
+ next2.activeLeftMargin = leftMargin;
84753
+ next2.pendingLeftMargin = leftMargin;
84754
+ }
84755
+ if (block.margins?.right !== void 0) {
84756
+ const rightMargin = Math.max(0, block.margins.right);
84757
+ next2.activeRightMargin = rightMargin;
84758
+ next2.pendingRightMargin = rightMargin;
84759
+ }
84434
84760
  if (block.columns) {
84435
84761
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
84436
84762
  next2.pendingColumns = null;
@@ -84459,27 +84785,35 @@ ${l}
84459
84785
  const headerPx = block.margins?.header;
84460
84786
  const footerPx = block.margins?.footer;
84461
84787
  const topPx = block.margins?.top;
84788
+ const bottomPx = block.margins?.bottom;
84789
+ const leftPx = block.margins?.left;
84790
+ const rightPx = block.margins?.right;
84462
84791
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
84463
84792
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
84793
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
84794
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
84464
84795
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
84465
84796
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
84466
84797
  next2.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
84467
84798
  next2.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
84468
84799
  if (typeof headerPx === "number" || typeof topPx === "number") {
84469
- const sectionTop = topPx ?? baseMargins.top;
84800
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
84470
84801
  const sectionHeader = next2.pendingHeaderDistance;
84471
84802
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
84472
84803
  next2.pendingTopMargin = Math.max(sectionTop, requiredTop);
84473
84804
  } else {
84474
84805
  next2.pendingTopMargin = nextTop;
84475
84806
  }
84476
- if (typeof footerPx === "number") {
84807
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
84477
84808
  const sectionFooter = next2.pendingFooterDistance;
84809
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
84478
84810
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
84479
- next2.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84811
+ next2.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
84480
84812
  } else {
84481
84813
  next2.pendingBottomMargin = nextBottom;
84482
84814
  }
84815
+ next2.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
84816
+ next2.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
84483
84817
  if (block.pageSize) next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
84484
84818
  if (block.orientation) next2.pendingOrientation = block.orientation;
84485
84819
  const sectionType = block.type ?? "continuous";
@@ -84564,7 +84898,7 @@ ${l}
84564
84898
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
84565
84899
  let pendingSectionIndex = null;
84566
84900
  const paginator = createPaginator({
84567
- margins: { left: margins.left, right: margins.right },
84901
+ margins: paginatorMargins,
84568
84902
  getActiveTopMargin: () => activeTopMargin,
84569
84903
  getActiveBottomMargin: () => activeBottomMargin,
84570
84904
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -84579,8 +84913,12 @@ ${l}
84579
84913
  const applied = applyPendingToActive({
84580
84914
  activeTopMargin,
84581
84915
  activeBottomMargin,
84916
+ activeLeftMargin,
84917
+ activeRightMargin,
84582
84918
  pendingTopMargin,
84583
84919
  pendingBottomMargin,
84920
+ pendingLeftMargin,
84921
+ pendingRightMargin,
84584
84922
  activeHeaderDistance,
84585
84923
  activeFooterDistance,
84586
84924
  pendingHeaderDistance,
@@ -84595,8 +84933,12 @@ ${l}
84595
84933
  });
84596
84934
  activeTopMargin = applied.activeTopMargin;
84597
84935
  activeBottomMargin = applied.activeBottomMargin;
84936
+ activeLeftMargin = applied.activeLeftMargin;
84937
+ activeRightMargin = applied.activeRightMargin;
84598
84938
  pendingTopMargin = applied.pendingTopMargin;
84599
84939
  pendingBottomMargin = applied.pendingBottomMargin;
84940
+ pendingLeftMargin = applied.pendingLeftMargin;
84941
+ pendingRightMargin = applied.pendingRightMargin;
84600
84942
  activeHeaderDistance = applied.activeHeaderDistance;
84601
84943
  activeFooterDistance = applied.activeFooterDistance;
84602
84944
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -84608,6 +84950,14 @@ ${l}
84608
84950
  activeOrientation = applied.activeOrientation;
84609
84951
  pendingOrientation = applied.pendingOrientation;
84610
84952
  cachedColumnsState.state = null;
84953
+ paginatorMargins.left = activeLeftMargin;
84954
+ paginatorMargins.right = activeRightMargin;
84955
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84956
+ floatManager.setLayoutContext(
84957
+ normalizeColumns(activeColumns, contentWidth),
84958
+ { left: activeLeftMargin, right: activeRightMargin },
84959
+ activePageSize.w
84960
+ );
84611
84961
  if (pendingNumbering) {
84612
84962
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
84613
84963
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -84652,7 +85002,7 @@ ${l}
84652
85002
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
84653
85003
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
84654
85004
  const getCurrentColumns = () => {
84655
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
85005
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84656
85006
  const state2 = states[states.length - 1] ?? null;
84657
85007
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
84658
85008
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -84685,6 +85035,12 @@ ${l}
84685
85035
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
84686
85036
  activeColumns = newColumns;
84687
85037
  cachedColumnsState.state = null;
85038
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
85039
+ floatManager.setLayoutContext(
85040
+ normalizeColumns(activeColumns, contentWidth),
85041
+ { left: activeLeftMargin, right: activeRightMargin },
85042
+ activePageSize.w
85043
+ );
84688
85044
  };
84689
85045
  const anchoredByParagraph = collectAnchoredDrawings(blocks2, measures);
84690
85046
  const anchoredTablesByParagraph = collectAnchoredTables(blocks2, measures);
@@ -84716,10 +85072,10 @@ ${l}
84716
85072
  if (alignV === "top") {
84717
85073
  anchorY = offsetV;
84718
85074
  } else if (alignV === "bottom") {
84719
- const pageHeight = contentBottom + margins.bottom;
85075
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84720
85076
  anchorY = pageHeight - imageHeight + offsetV;
84721
85077
  } else if (alignV === "center") {
84722
- const pageHeight = contentBottom + margins.bottom;
85078
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84723
85079
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
84724
85080
  } else {
84725
85081
  anchorY = offsetV;
@@ -84730,11 +85086,11 @@ ${l}
84730
85086
  const anchorX = entry.block.anchor ? computeAnchorX(
84731
85087
  entry.block.anchor,
84732
85088
  state2.columnIndex,
84733
- normalizeColumns(activeColumns, contentWidth),
85089
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84734
85090
  entry.measure.width,
84735
- { left: margins.left, right: margins.right },
85091
+ { left: activeLeftMargin, right: activeRightMargin },
84736
85092
  activePageSize.w
84737
- ) : margins.left;
85093
+ ) : activeLeftMargin;
84738
85094
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
84739
85095
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
84740
85096
  }
@@ -84772,8 +85128,12 @@ ${l}
84772
85128
  const sectionState = {
84773
85129
  activeTopMargin,
84774
85130
  activeBottomMargin,
85131
+ activeLeftMargin,
85132
+ activeRightMargin,
84775
85133
  pendingTopMargin,
84776
85134
  pendingBottomMargin,
85135
+ pendingLeftMargin,
85136
+ pendingRightMargin,
84777
85137
  activeHeaderDistance,
84778
85138
  activeFooterDistance,
84779
85139
  pendingHeaderDistance,
@@ -84807,8 +85167,12 @@ ${l}
84807
85167
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
84808
85168
  activeTopMargin = updatedState.activeTopMargin;
84809
85169
  activeBottomMargin = updatedState.activeBottomMargin;
85170
+ activeLeftMargin = updatedState.activeLeftMargin;
85171
+ activeRightMargin = updatedState.activeRightMargin;
84810
85172
  pendingTopMargin = updatedState.pendingTopMargin;
84811
85173
  pendingBottomMargin = updatedState.pendingBottomMargin;
85174
+ pendingLeftMargin = updatedState.pendingLeftMargin;
85175
+ pendingRightMargin = updatedState.pendingRightMargin;
84812
85176
  activeHeaderDistance = updatedState.activeHeaderDistance;
84813
85177
  activeFooterDistance = updatedState.activeFooterDistance;
84814
85178
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -84946,8 +85310,8 @@ ${l}
84946
85310
  pageMargins: {
84947
85311
  top: activeTopMargin,
84948
85312
  bottom: activeBottomMargin,
84949
- left: margins.left,
84950
- right: margins.right
85313
+ left: activeLeftMargin,
85314
+ right: activeRightMargin
84951
85315
  },
84952
85316
  columns: getCurrentColumns(),
84953
85317
  placedAnchoredIds
@@ -84969,9 +85333,9 @@ ${l}
84969
85333
  const cols = getCurrentColumns();
84970
85334
  let maxWidth;
84971
85335
  if (relativeFrom === "page") {
84972
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
85336
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
84973
85337
  } else if (relativeFrom === "margin") {
84974
- maxWidth = activePageSize.w - margins.left - margins.right;
85338
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84975
85339
  } else {
84976
85340
  maxWidth = cols.width;
84977
85341
  }
@@ -85131,6 +85495,9 @@ ${l}
85131
85495
  if (!Number.isFinite(height) || height <= 0) {
85132
85496
  throw new Error("layoutHeaderFooter: height must be positive");
85133
85497
  }
85498
+ const maxBehindDocOverflow = Math.max(192, height * 4);
85499
+ const minBehindDocY = -maxBehindDocOverflow;
85500
+ const maxBehindDocY = height + maxBehindDocOverflow;
85134
85501
  const marginLeft = constraints.margins?.left ?? 0;
85135
85502
  const transformedBlocks = marginLeft > 0 ? blocks2.map((block) => {
85136
85503
  const hasPageRelativeAnchor = (block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null;
@@ -85161,6 +85528,18 @@ ${l}
85161
85528
  if (idx == null) continue;
85162
85529
  const block = blocks2[idx];
85163
85530
  const measure = measures[idx];
85531
+ const isAnchoredFragment = (fragment.kind === "image" || fragment.kind === "drawing") && fragment.isAnchored === true;
85532
+ if (isAnchoredFragment) {
85533
+ if (block.kind !== "image" && block.kind !== "drawing") {
85534
+ throw new Error(
85535
+ `Type mismatch: fragment kind is ${fragment.kind} but block kind is ${block.kind} for block ${block.id}`
85536
+ );
85537
+ }
85538
+ const anchoredBlock = block;
85539
+ if (anchoredBlock.anchor?.behindDoc && (fragment.y < minBehindDocY || fragment.y > maxBehindDocY)) {
85540
+ continue;
85541
+ }
85542
+ }
85164
85543
  if (fragment.y < minY) minY = fragment.y;
85165
85544
  let bottom2 = fragment.y;
85166
85545
  if (fragment.kind === "para" && measure?.kind === "paragraph") {
@@ -86158,11 +86537,11 @@ ${l}
86158
86537
  if (text2.length === 0) return null;
86159
86538
  const clampedPos = Math.max(0, Math.min(localPos, text2.length));
86160
86539
  let wordStart = clampedPos;
86161
- while (wordStart > 0 && isWordChar(text2[wordStart - 1])) {
86540
+ while (wordStart > 0 && isWordChar$2(text2[wordStart - 1])) {
86162
86541
  wordStart--;
86163
86542
  }
86164
86543
  let wordEnd = clampedPos;
86165
- while (wordEnd < text2.length && isWordChar(text2[wordEnd])) {
86544
+ while (wordEnd < text2.length && isWordChar$2(text2[wordEnd])) {
86166
86545
  wordEnd++;
86167
86546
  }
86168
86547
  if (wordStart === wordEnd) {
@@ -86225,7 +86604,7 @@ ${l}
86225
86604
  }
86226
86605
  return null;
86227
86606
  }
86228
- function isWordChar(char) {
86607
+ function isWordChar$2(char) {
86229
86608
  return /[\p{L}\p{N}_]/u.test(char);
86230
86609
  }
86231
86610
  function isWhitespace$1(char) {
@@ -86260,6 +86639,29 @@ ${l}
86260
86639
  function runText(run2) {
86261
86640
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
86262
86641
  }
86642
+ const isWordChar$1 = (char) => {
86643
+ if (!char) return false;
86644
+ const code2 = char.charCodeAt(0);
86645
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
86646
+ };
86647
+ const capitalizeText$1 = (text2, fullText, startOffset) => {
86648
+ if (!text2) return text2;
86649
+ const hasFullText = typeof startOffset === "number" && fullText != null;
86650
+ let result = "";
86651
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
86652
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
86653
+ const ch = text2[i2];
86654
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
86655
+ }
86656
+ return result;
86657
+ };
86658
+ const applyTextTransform$1 = (text2, transform, fullText, startOffset) => {
86659
+ if (!text2 || !transform || transform === "none") return text2;
86660
+ if (transform === "uppercase") return text2.toUpperCase();
86661
+ if (transform === "lowercase") return text2.toLowerCase();
86662
+ if (transform === "capitalize") return capitalizeText$1(text2, fullText, startOffset);
86663
+ return text2;
86664
+ };
86263
86665
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
86264
86666
  const TWIPS_PER_INCH$4 = 1440;
86265
86667
  const PX_PER_INCH$3 = 96;
@@ -86268,6 +86670,13 @@ ${l}
86268
86670
  const WIDTH_FUDGE_PX = 0.5;
86269
86671
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
86270
86672
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
86673
+ const markerFontString = (run2) => {
86674
+ const size2 = run2?.fontSize ?? 16;
86675
+ const family = run2?.fontFamily ?? "Arial";
86676
+ const italic = run2?.italic ? "italic " : "";
86677
+ const bold = run2?.bold ? "bold " : "";
86678
+ return `${italic}${bold}${size2}px ${family}`.trim();
86679
+ };
86271
86680
  const buildTabStopsPx$1 = (indent2, tabs, tabIntervalTwips) => {
86272
86681
  const paragraphIndentTwips = {
86273
86682
  left: pxToTwips$1(Math.max(0, indent2?.left ?? 0)),
@@ -86298,7 +86707,8 @@ ${l}
86298
86707
  };
86299
86708
  function measureRunSliceWidth(run2, fromChar, toChar) {
86300
86709
  const context = getCtx();
86301
- const text2 = runText(run2).slice(fromChar, toChar);
86710
+ const fullText = runText(run2);
86711
+ const text2 = applyTextTransform$1(fullText.slice(fromChar, toChar), run2.textTransform, fullText, fromChar);
86302
86712
  if (!context) {
86303
86713
  const textRun = isTextRun$2(run2) ? run2 : null;
86304
86714
  const size2 = textRun?.fontSize ?? 16;
@@ -86344,8 +86754,21 @@ ${l}
86344
86754
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
86345
86755
  const markerTextStartX = wordLayout?.marker?.textStartX;
86346
86756
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
86347
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
86348
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86757
+ const resolvedTextStartPx = resolveListTextStartPx(
86758
+ wordLayout,
86759
+ indentLeft,
86760
+ indentFirstLine,
86761
+ indentHanging,
86762
+ (markerText, marker) => {
86763
+ const context = getCtx();
86764
+ if (!context) return 0;
86765
+ context.font = markerFontString(marker.run);
86766
+ return context.measureText(markerText).width;
86767
+ }
86768
+ );
86769
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
86770
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
86771
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86349
86772
  const tabStops = buildTabStopsPx$1(indent2, attrs?.tabs, attrs?.tabIntervalTwips);
86350
86773
  let currentRun = 0;
86351
86774
  let currentChar = 0;
@@ -86885,7 +87308,7 @@ ${l}
86885
87308
  if (dirty.deletedBlockIds.length > 0) {
86886
87309
  measureCache.invalidate(dirty.deletedBlockIds);
86887
87310
  }
86888
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
87311
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
86889
87312
  if (measurementWidth <= 0 || measurementHeight <= 0) {
86890
87313
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
86891
87314
  }
@@ -87154,7 +87577,7 @@ ${l}
87154
87577
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
87155
87578
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
87156
87579
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
87157
- function resolveMeasurementConstraints(options) {
87580
+ function resolveMeasurementConstraints(options, blocks2) {
87158
87581
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
87159
87582
  const margins = {
87160
87583
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -87162,23 +87585,41 @@ ${l}
87162
87585
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
87163
87586
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
87164
87587
  };
87165
- const contentWidth = pageSize.w - (margins.left + margins.right);
87166
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
87167
- const columns = options.columns;
87168
- if (columns && columns.count > 1) {
87588
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
87589
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
87590
+ const computeColumnWidth = (contentWidth, columns) => {
87591
+ if (!columns || columns.count <= 1) return contentWidth;
87169
87592
  const gap = Math.max(0, columns.gap ?? 0);
87170
87593
  const totalGap = gap * (columns.count - 1);
87171
- const columnWidth = (contentWidth - totalGap) / columns.count;
87172
- if (columnWidth > 0) {
87173
- return {
87174
- measurementWidth: columnWidth,
87175
- measurementHeight: contentHeight
87594
+ return (contentWidth - totalGap) / columns.count;
87595
+ };
87596
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
87597
+ let measurementHeight = baseContentHeight;
87598
+ if (blocks2 && blocks2.length > 0) {
87599
+ for (const block of blocks2) {
87600
+ if (block.kind !== "sectionBreak") continue;
87601
+ const sectionPageSize = block.pageSize ?? pageSize;
87602
+ const sectionMargins = {
87603
+ top: normalizeMargin(block.margins?.top, margins.top),
87604
+ right: normalizeMargin(block.margins?.right, margins.right),
87605
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
87606
+ left: normalizeMargin(block.margins?.left, margins.left)
87176
87607
  };
87608
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
87609
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
87610
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
87611
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
87612
+ if (columnWidth > measurementWidth) {
87613
+ measurementWidth = columnWidth;
87614
+ }
87615
+ if (contentHeight > measurementHeight) {
87616
+ measurementHeight = contentHeight;
87617
+ }
87177
87618
  }
87178
87619
  }
87179
87620
  return {
87180
- measurementWidth: contentWidth,
87181
- measurementHeight: contentHeight
87621
+ measurementWidth,
87622
+ measurementHeight
87182
87623
  };
87183
87624
  }
87184
87625
  const serializeHeaderFooterResults = (kind, batch2) => {
@@ -89245,6 +89686,7 @@ ${l}
89245
89686
  }
89246
89687
  return false;
89247
89688
  }
89689
+ const SLASH_MENU_HANDLED_FLAG = "__sdHandledBySlashMenu";
89248
89690
  class PresentationInputBridge {
89249
89691
  /**
89250
89692
  * Creates a new PresentationInputBridge that forwards user input events from the visible layout
@@ -89458,6 +89900,10 @@ ${l}
89458
89900
  __privateMethod$1(this, _PresentationInputBridge_instances, dispatchToTarget_fn).call(this, event, synthetic);
89459
89901
  };
89460
89902
  forwardContextMenu_fn = function(event) {
89903
+ const handledBySlashMenu = Boolean(event[SLASH_MENU_HANDLED_FLAG]);
89904
+ if (handledBySlashMenu) {
89905
+ return;
89906
+ }
89461
89907
  if (!__privateGet$1(this, _isEditable).call(this)) {
89462
89908
  return;
89463
89909
  }
@@ -93151,8 +93597,8 @@ ${l}
93151
93597
  }
93152
93598
  return void 0;
93153
93599
  }
93154
- const DEFAULT_LIST_HANGING_PX$1 = 18;
93155
- const LIST_MARKER_GAP$1 = 8;
93600
+ const DEFAULT_LIST_HANGING_PX = 18;
93601
+ const LIST_MARKER_GAP = 8;
93156
93602
  const DEFAULT_BULLET_GLYPH = "•";
93157
93603
  const DEFAULT_DECIMAL_PATTERN = "%1.";
93158
93604
  const ASCII_UPPERCASE_A = 65;
@@ -93563,7 +94009,7 @@ ${l}
93563
94009
  let markerBoxWidthPx;
93564
94010
  let markerX;
93565
94011
  if (hasFirstLineIndent) {
93566
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
94012
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
93567
94013
  markerX = indentLeftPx + (firstLinePx ?? 0);
93568
94014
  layout.textStartPx = markerX + markerBoxWidthPx;
93569
94015
  layout.hangingPx = 0;
@@ -93663,12 +94109,12 @@ ${l}
93663
94109
  let markerBox = Math.max(hangingPxRaw || 0, 0);
93664
94110
  if (markerBox <= 0) {
93665
94111
  if (glyphWidthPx != null && glyphWidthPx > 0) {
93666
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94112
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93667
94113
  } else {
93668
- markerBox = DEFAULT_LIST_HANGING_PX$1;
94114
+ markerBox = DEFAULT_LIST_HANGING_PX;
93669
94115
  }
93670
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
93671
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94116
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
94117
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93672
94118
  }
93673
94119
  return markerBox;
93674
94120
  };
@@ -93688,7 +94134,7 @@ ${l}
93688
94134
  textStartX: textStartPx,
93689
94135
  baselineOffsetPx: markerRun.baselineShift ?? 0,
93690
94136
  // Gutter is the small gap between marker and text, not the full marker box width
93691
- gutterWidthPx: LIST_MARKER_GAP$1,
94137
+ gutterWidthPx: LIST_MARKER_GAP,
93692
94138
  justification: numbering.lvlJc ?? "left",
93693
94139
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
93694
94140
  run: markerRun,
@@ -94380,6 +94826,31 @@ ${l}
94380
94826
  return null;
94381
94827
  }
94382
94828
  };
94829
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
94830
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
94831
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
94832
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
94833
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
94834
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
94835
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
94836
+ wordLayout.firstLineIndentMode = false;
94837
+ }
94838
+ if (wordLayout.firstLineIndentMode === true) {
94839
+ if (isFiniteNumber(wordLayout.textStartPx)) {
94840
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
94841
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
94842
+ }
94843
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
94844
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
94845
+ }
94846
+ } else {
94847
+ wordLayout.textStartPx = indentLeft;
94848
+ if (wordLayout.marker) {
94849
+ wordLayout.marker.textStartX = indentLeft;
94850
+ }
94851
+ }
94852
+ return wordLayout;
94853
+ };
94383
94854
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
94384
94855
  const attrs = para.attrs ?? {};
94385
94856
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -94702,8 +95173,11 @@ ${l}
94702
95173
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
94703
95174
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
94704
95175
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94705
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94706
- if (firstLinePx > 0) {
95176
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95177
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95178
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95179
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95180
+ if (firstLinePx > 0 && !hangingPx) {
94707
95181
  wordLayout = {
94708
95182
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
94709
95183
  firstLineIndentMode: true,
@@ -94711,10 +95185,13 @@ ${l}
94711
95185
  };
94712
95186
  }
94713
95187
  }
94714
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
95188
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
94715
95189
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94716
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94717
- if (firstLinePx > 0) {
95190
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95191
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95192
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95193
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95194
+ if (firstLinePx > 0 && !hangingPx) {
94718
95195
  wordLayout = {
94719
95196
  ...wordLayout,
94720
95197
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -94734,6 +95211,7 @@ ${l}
94734
95211
  wordLayout.marker.suffix = listRendering.suffix;
94735
95212
  }
94736
95213
  }
95214
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
94737
95215
  paragraphAttrs.wordLayout = wordLayout;
94738
95216
  }
94739
95217
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -98850,11 +99328,6 @@ ${l}
98850
99328
  cleanups
98851
99329
  };
98852
99330
  }
98853
- const LIST_MARKER_GAP = 8;
98854
- const MIN_MARKER_GUTTER = 24;
98855
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
98856
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
98857
- const DEFAULT_LIST_HANGING_PX = 18;
98858
99331
  function calculateRotatedBounds(input2) {
98859
99332
  const width = Math.max(0, input2.width);
98860
99333
  const height = Math.max(0, input2.height);
@@ -99118,8 +99591,25 @@ ${l}
99118
99591
  const rawTextStartPx = wordLayout?.textStartPx;
99119
99592
  const markerTextStartX = wordLayout?.marker?.textStartX;
99120
99593
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
99121
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
99122
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
99594
+ const resolvedTextStartPx = resolveListTextStartPx(
99595
+ wordLayout,
99596
+ indentLeft,
99597
+ firstLine,
99598
+ hanging,
99599
+ (markerText, marker) => {
99600
+ const markerRun = {
99601
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
99602
+ fontSize: marker.run?.fontSize ?? 16,
99603
+ bold: marker.run?.bold ?? false,
99604
+ italic: marker.run?.italic ?? false
99605
+ };
99606
+ const { font: markerFont } = buildFontString(markerRun);
99607
+ return measureText(markerText, markerFont, ctx2);
99608
+ }
99609
+ );
99610
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
99611
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
99612
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
99123
99613
  } else {
99124
99614
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
99125
99615
  }
@@ -99206,7 +99696,7 @@ ${l}
99206
99696
  pendingTabAlignment = null;
99207
99697
  return startX;
99208
99698
  };
99209
- const alignSegmentAtTab = (segmentText, font, runContext) => {
99699
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
99210
99700
  if (!pendingTabAlignment || !currentLine) return void 0;
99211
99701
  const { val } = pendingTabAlignment;
99212
99702
  let segmentWidth = 0;
@@ -99215,11 +99705,11 @@ ${l}
99215
99705
  const idx = segmentText.indexOf(decimalSeparator);
99216
99706
  if (idx >= 0) {
99217
99707
  const beforeText = segmentText.slice(0, idx);
99218
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
99708
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
99219
99709
  }
99220
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99710
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99221
99711
  } else if (val === "end" || val === "center") {
99222
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99712
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99223
99713
  }
99224
99714
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
99225
99715
  };
@@ -99271,8 +99761,8 @@ ${l}
99271
99761
  const { font } = buildFontString(
99272
99762
  lastRun
99273
99763
  );
99274
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
99275
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
99764
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
99765
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
99276
99766
  const delta = Math.max(0, fullWidth - keptWidth);
99277
99767
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
99278
99768
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -99483,7 +99973,8 @@ ${l}
99483
99973
  continue;
99484
99974
  }
99485
99975
  if (isFieldAnnotationRun(run2)) {
99486
- const displayText = run2.displayLabel || "";
99976
+ const rawDisplayText = run2.displayLabel || "";
99977
+ const displayText = applyTextTransform(rawDisplayText, run2);
99487
99978
  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;
99488
99979
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
99489
99980
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -99586,7 +100077,7 @@ ${l}
99586
100077
  const spacesLength = segment.length;
99587
100078
  const spacesStartChar = charPosInRun;
99588
100079
  const spacesEndChar = charPosInRun + spacesLength;
99589
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
100080
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
99590
100081
  if (!currentLine) {
99591
100082
  currentLine = {
99592
100083
  fromRun: runIndex,
@@ -99650,7 +100141,7 @@ ${l}
99650
100141
  }
99651
100142
  let segmentStartX;
99652
100143
  if (currentLine && pendingTabAlignment) {
99653
- segmentStartX = alignSegmentAtTab(segment, font, run2);
100144
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
99654
100145
  if (segmentStartX == null) {
99655
100146
  segmentStartX = currentLine.width;
99656
100147
  }
@@ -99660,7 +100151,7 @@ ${l}
99660
100151
  if (word2 === "") {
99661
100152
  const spaceStartChar = charPosInRun;
99662
100153
  const spaceEndChar = charPosInRun + 1;
99663
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
100154
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
99664
100155
  if (!currentLine) {
99665
100156
  currentLine = {
99666
100157
  fromRun: runIndex,
@@ -99711,12 +100202,12 @@ ${l}
99711
100202
  charPosInRun = spaceEndChar;
99712
100203
  continue;
99713
100204
  }
99714
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
99715
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99716
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
99717
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
99718
100205
  const wordStartChar = charPosInRun;
100206
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
100207
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99719
100208
  const wordEndNoSpace = charPosInRun + word2.length;
100209
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
100210
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
99720
100211
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
99721
100212
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
99722
100213
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -99735,7 +100226,7 @@ ${l}
99735
100226
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
99736
100227
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
99737
100228
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
99738
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
100229
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
99739
100230
  let chunkCharOffset = wordStartChar;
99740
100231
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
99741
100232
  const chunk = chunks[chunkIndex];
@@ -99859,7 +100350,7 @@ ${l}
99859
100350
  if (candidateSpaces > 0) {
99860
100351
  const overflow = totalWidthWithWord - availableWidth;
99861
100352
  if (overflow > 0) {
99862
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
100353
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
99863
100354
  const perSpaceCompression = overflow / candidateSpaces;
99864
100355
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
99865
100356
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -100034,8 +100525,8 @@ ${l}
100034
100525
  const { font: markerFont } = buildFontString(markerRun);
100035
100526
  const markerText = wordLayout.marker.markerText ?? "";
100036
100527
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100037
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
100038
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
100528
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
100529
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
100039
100530
  markerInfo = {
100040
100531
  markerWidth: markerBoxWidth,
100041
100532
  markerTextWidth: glyphWidth,
@@ -100379,7 +100870,7 @@ ${l}
100379
100870
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100380
100871
  indentLeft = resolveIndentLeft(item);
100381
100872
  const indentHanging = resolveIndentHanging(item);
100382
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
100873
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
100383
100874
  }
100384
100875
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
100385
100876
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -100405,16 +100896,46 @@ ${l}
100405
100896
  fontSize: 16
100406
100897
  };
100407
100898
  };
100408
- const measureRunWidth = (text2, font, ctx2, run2) => {
100899
+ const isWordChar = (char) => {
100900
+ if (!char) return false;
100901
+ const code2 = char.charCodeAt(0);
100902
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
100903
+ };
100904
+ const capitalizeText = (text2, fullText, startOffset) => {
100905
+ if (!text2) return text2;
100906
+ const hasFullText = typeof startOffset === "number" && fullText != null;
100907
+ let result = "";
100908
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
100909
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
100910
+ const ch = text2[i2];
100911
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
100912
+ }
100913
+ return result;
100914
+ };
100915
+ const applyTextTransform = (text2, run2, startOffset) => {
100916
+ const transform = run2.textTransform;
100917
+ if (!text2 || !transform || transform === "none") return text2;
100918
+ if (transform === "uppercase") return text2.toUpperCase();
100919
+ if (transform === "lowercase") return text2.toLowerCase();
100920
+ if (transform === "capitalize") {
100921
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text2;
100922
+ return capitalizeText(text2, fullText, startOffset);
100923
+ }
100924
+ return text2;
100925
+ };
100926
+ const measureRunWidth = (text2, font, ctx2, run2, startOffset) => {
100409
100927
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
100410
- const width = getMeasuredTextWidth(text2, font, letterSpacing, ctx2);
100928
+ const displayText = applyTextTransform(text2, run2, startOffset);
100929
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
100411
100930
  return roundValue(width);
100412
100931
  };
100413
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
100932
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
100414
100933
  const chunks = [];
100934
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
100415
100935
  if (maxWidth <= 0) {
100416
- for (const char of word2) {
100417
- const charWidth = measureRunWidth(char, font, ctx2, run2);
100936
+ for (let i2 = 0; i2 < word2.length; i2++) {
100937
+ const char = word2[i2];
100938
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100418
100939
  chunks.push({ text: char, width: charWidth });
100419
100940
  }
100420
100941
  return chunks;
@@ -100424,11 +100945,11 @@ ${l}
100424
100945
  for (let i2 = 0; i2 < word2.length; i2++) {
100425
100946
  const char = word2[i2];
100426
100947
  const testChunk = currentChunk + char;
100427
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
100948
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
100428
100949
  if (testWidth > maxWidth && currentChunk.length > 0) {
100429
100950
  chunks.push({ text: currentChunk, width: currentWidth });
100430
100951
  currentChunk = char;
100431
- currentWidth = measureRunWidth(char, font, ctx2, run2);
100952
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100432
100953
  } else {
100433
100954
  currentChunk = testChunk;
100434
100955
  currentWidth = testWidth;
@@ -100482,7 +101003,8 @@ ${l}
100482
101003
  italic: run2.italic
100483
101004
  });
100484
101005
  ctx2.font = font;
100485
- const metrics = ctx2.measureText(run2.text);
101006
+ const displayText = applyTextTransform(run2.text, run2);
101007
+ const metrics = ctx2.measureText(displayText);
100486
101008
  const advanceWidth = metrics.width;
100487
101009
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
100488
101010
  const textWidth = Math.max(advanceWidth, paintedWidth);
@@ -100508,7 +101030,7 @@ ${l}
100508
101030
  if (indentHanging > 0) {
100509
101031
  return indentHanging;
100510
101032
  }
100511
- return DEFAULT_LIST_HANGING_PX;
101033
+ return DEFAULT_LIST_HANGING_PX$1;
100512
101034
  };
100513
101035
  const buildTabStopsPx = (indent2, tabs, tabIntervalTwips) => {
100514
101036
  const paragraphIndentTwips = {
@@ -100714,6 +101236,9 @@ ${l}
100714
101236
  if (event.button !== 0) {
100715
101237
  return;
100716
101238
  }
101239
+ if (event.ctrlKey && navigator.platform.includes("Mac")) {
101240
+ return;
101241
+ }
100717
101242
  __privateSet(this, _pendingMarginClick, null);
100718
101243
  const target = event.target;
100719
101244
  if (target?.closest?.(".superdoc-ruler-handle") != null) {
@@ -106123,6 +106648,8 @@ ${l}
106123
106648
  const cbRect = containingBlock.getBoundingClientRect();
106124
106649
  left2 -= cbRect.left;
106125
106650
  top2 -= cbRect.top;
106651
+ left2 += containingBlock.scrollLeft || 0;
106652
+ top2 += containingBlock.scrollTop || 0;
106126
106653
  } catch (error) {
106127
106654
  console.warn("SlashMenu: Failed to adjust for containing block", error);
106128
106655
  }
@@ -137461,7 +137988,7 @@ ${style2}
137461
137988
  if (open) {
137462
137989
  nextTick(() => {
137463
137990
  if (searchInput.value) {
137464
- searchInput.value.focus();
137991
+ searchInput.value.focus({ preventScroll: true });
137465
137992
  }
137466
137993
  });
137467
137994
  }
@@ -137566,15 +138093,31 @@ ${style2}
137566
138093
  };
137567
138094
  const handleGlobalOutsideClick = (event) => {
137568
138095
  if (isOpen.value && menuRef.value && !menuRef.value.contains(event.target)) {
137569
- moveCursorToMouseEvent(event, props.editor);
138096
+ const isCtrlClickOnMac = event.ctrlKey && isMacOS();
138097
+ const isLeftClick = event.button === 0 && !isCtrlClickOnMac;
138098
+ if (isLeftClick) {
138099
+ moveCursorToMouseEvent(event, props.editor);
138100
+ }
137570
138101
  closeMenu({ restoreCursor: false });
137571
138102
  }
137572
138103
  };
137573
- const handleRightClick = async (event) => {
138104
+ const shouldHandleContextMenu = (event) => {
137574
138105
  const readOnly = !props.editor?.isEditable;
137575
138106
  const contextMenuDisabled = props.editor?.options?.disableContextMenu;
137576
138107
  const bypass = shouldBypassContextMenu(event);
137577
- if (readOnly || contextMenuDisabled || bypass) {
138108
+ return !readOnly && !contextMenuDisabled && !bypass;
138109
+ };
138110
+ const handleRightClickCapture = (event) => {
138111
+ try {
138112
+ if (shouldHandleContextMenu(event)) {
138113
+ event[SLASH_MENU_HANDLED_FLAG] = true;
138114
+ }
138115
+ } catch (error) {
138116
+ console.warn("[SlashMenu] Error in capture phase context menu handler:", error);
138117
+ }
138118
+ };
138119
+ const handleRightClick = async (event) => {
138120
+ if (!shouldHandleContextMenu(event)) {
137578
138121
  return;
137579
138122
  }
137580
138123
  event.preventDefault();
@@ -137685,6 +138228,7 @@ ${style2}
137685
138228
  props.editor.on("slashMenu:open", slashMenuOpenHandler);
137686
138229
  contextMenuTarget = getEditorSurfaceElement(props.editor);
137687
138230
  if (contextMenuTarget) {
138231
+ contextMenuTarget.addEventListener("contextmenu", handleRightClickCapture, true);
137688
138232
  contextMenuTarget.addEventListener("contextmenu", handleRightClick);
137689
138233
  }
137690
138234
  slashMenuCloseHandler = () => {
@@ -137708,6 +138252,7 @@ ${style2}
137708
138252
  props.editor.off("slashMenu:close", slashMenuCloseHandler);
137709
138253
  }
137710
138254
  props.editor.off("update", handleEditorUpdate);
138255
+ contextMenuTarget?.removeEventListener("contextmenu", handleRightClickCapture, true);
137711
138256
  contextMenuTarget?.removeEventListener("contextmenu", handleRightClick);
137712
138257
  } catch (error) {
137713
138258
  console.warn("[SlashMenu] Error during cleanup:", error);
@@ -139647,6 +140192,12 @@ ${style2}
139647
140192
  if (props.options?.suppressSkeletonLoader || !props.options?.collaborationProvider) editorReady.value = true;
139648
140193
  });
139649
140194
  const handleMarginClick = (event) => {
140195
+ if (event.button !== 0) {
140196
+ return;
140197
+ }
140198
+ if (event.ctrlKey && isMacOS()) {
140199
+ return;
140200
+ }
139650
140201
  if (event.target.classList.contains("ProseMirror")) return;
139651
140202
  onMarginClickCursorChange(event, activeEditor.value);
139652
140203
  };
@@ -139785,7 +140336,7 @@ ${style2}
139785
140336
  };
139786
140337
  }
139787
140338
  });
139788
- const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-209a1e8b"]]);
140339
+ const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-c9a3c876"]]);
139789
140340
  const _hoisted_1$h = ["innerHTML"];
139790
140341
  const _sfc_main$i = {
139791
140342
  __name: "SuperInput",
@@ -157239,7 +157790,7 @@ ${style2}
157239
157790
  this.config.colors = shuffleArray(this.config.colors);
157240
157791
  this.userColorMap = /* @__PURE__ */ new Map();
157241
157792
  this.colorIndex = 0;
157242
- this.version = "1.0.2";
157793
+ this.version = "1.0.3";
157243
157794
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
157244
157795
  this.superdocId = config2.superdocId || v4();
157245
157796
  this.colors = this.config.colors;
@@ -159712,7 +160263,7 @@ ${style2}
159712
160263
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
159713
160264
  );
159714
160265
  }
159715
- const indexDDZ1ZT8N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
160266
+ const indexBFesQTtm = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
159716
160267
  __proto__: null,
159717
160268
  unified
159718
160269
  }, Symbol.toStringTag, { value: "Module" }));