@stll/folio-core 0.7.0 → 0.9.0

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 (193) hide show
  1. package/README.md +39 -0
  2. package/dist/ai-edits/apply.js +18 -4
  3. package/dist/ai-edits/blockRange.d.ts +13 -2
  4. package/dist/ai-edits/blockRange.js +23 -2
  5. package/dist/ai-edits/headless.d.ts +31 -4
  6. package/dist/ai-edits/headless.js +148 -35
  7. package/dist/ai-edits/index.d.ts +6 -4
  8. package/dist/ai-edits/index.js +4 -1
  9. package/dist/ai-edits/scoped-reading.d.ts +9 -0
  10. package/dist/ai-edits/scoped-reading.js +60 -0
  11. package/dist/ai-edits/snapshot.js +53 -7
  12. package/dist/ai-edits/types.d.ts +46 -3
  13. package/dist/compat/eigenpal.d.ts +8 -3
  14. package/dist/compat/eigenpal.js +7 -2
  15. package/dist/controller/fontReadiness.d.ts +29 -0
  16. package/dist/controller/fontReadiness.js +139 -0
  17. package/dist/controller/latestRequestGate.d.ts +13 -0
  18. package/dist/controller/latestRequestGate.js +16 -0
  19. package/dist/controller/layoutPipeline.js +88 -10
  20. package/dist/document-operations.d.ts +10 -3
  21. package/dist/document-operations.js +29 -14
  22. package/dist/docx/blockContentParser.js +53 -10
  23. package/dist/docx/commentParser.js +1 -1
  24. package/dist/docx/compatibility.d.ts +30 -2
  25. package/dist/docx/compatibility.js +118 -39
  26. package/dist/docx/conformance.d.ts +6 -0
  27. package/dist/docx/conformance.js +18 -0
  28. package/dist/docx/encryption/agileDecryption.js +1 -1
  29. package/dist/docx/encryption/encryptionInfo.js +1 -1
  30. package/dist/docx/encryption/openEncryptedDocx.js +1 -1
  31. package/dist/docx/ensureParaIds.d.ts +29 -0
  32. package/dist/docx/ensureParaIds.js +423 -0
  33. package/dist/docx/fontTableParser.d.ts +6 -0
  34. package/dist/docx/fontTableParser.js +72 -0
  35. package/dist/docx/groupDrawingParser.js +7 -2
  36. package/dist/docx/headerFooterParser.js +1 -1
  37. package/dist/docx/normalizeBaseDirection.js +1 -1
  38. package/dist/docx/numberingParser.js +2 -0
  39. package/dist/docx/paragraphParser.js +21 -1
  40. package/dist/docx/paragraphTextBoxEnrichment.js +141 -2
  41. package/dist/docx/parser.d.ts +1 -1
  42. package/dist/docx/parser.js +14 -9
  43. package/dist/docx/rezip.js +70 -5
  44. package/dist/docx/runConsolidator.js +4 -0
  45. package/dist/docx/runParser.js +19 -1
  46. package/dist/docx/selectiveSave.js +3 -3
  47. package/dist/docx/selectiveXmlPatch.d.ts +10 -1
  48. package/dist/docx/selectiveXmlPatch.js +1 -1
  49. package/dist/docx/serializer/fontTableSerializer.d.ts +6 -0
  50. package/dist/docx/serializer/fontTableSerializer.js +26 -0
  51. package/dist/docx/serializer/headerFooterSerializer.js +1 -1
  52. package/dist/docx/serializer/paragraphSerializer.js +8 -0
  53. package/dist/docx/serializer/runSerializer.js +14 -2
  54. package/dist/docx/serializer/settingsSerializer.d.ts +6 -0
  55. package/dist/docx/serializer/settingsSerializer.js +16 -0
  56. package/dist/docx/serializer/stylesSerializer.d.ts +6 -0
  57. package/dist/docx/serializer/stylesSerializer.js +56 -0
  58. package/dist/docx/serializer/tableSerializer.js +29 -26
  59. package/dist/docx/serializer/themeSerializer.d.ts +6 -0
  60. package/dist/docx/serializer/themeSerializer.js +36 -0
  61. package/dist/docx/settingsParser.js +46 -0
  62. package/dist/docx/styleParser.js +26 -1
  63. package/dist/docx/tableParser.js +19 -1
  64. package/dist/docx/textBoxParser.js +6 -1
  65. package/dist/docx/vmlImageParser.js +146 -1
  66. package/dist/i18n/messages/catalogs.gen.d.ts +5916 -5916
  67. package/dist/i18n/messages/catalogs.gen.js +5910 -5910
  68. package/dist/index.d.ts +8 -3
  69. package/dist/index.js +7 -2
  70. package/dist/layout-bridge/convert/footnoteLayout.d.ts +3 -0
  71. package/dist/layout-bridge/convert/footnoteLayout.js +3 -1
  72. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +3 -0
  73. package/dist/layout-bridge/convert/headerFooterLayout.js +22 -3
  74. package/dist/layout-bridge/convert/paragraphFrames.d.ts +7 -0
  75. package/dist/layout-bridge/convert/paragraphFrames.js +136 -0
  76. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +14 -2
  77. package/dist/layout-bridge/convert/toFlowBlocks.js +93 -17
  78. package/dist/layout-bridge/engine/hitTest.js +2 -1
  79. package/dist/layout-bridge/engine/measuring/index.d.ts +2 -1
  80. package/dist/layout-bridge/engine/measuring/index.js +2 -1
  81. package/dist/layout-bridge/engine/selectionRects.js +2 -1
  82. package/dist/layout-engine/headerFooterRefs.d.ts +7 -0
  83. package/dist/layout-engine/headerFooterRefs.js +40 -0
  84. package/dist/layout-engine/index.d.ts +3 -2
  85. package/dist/layout-engine/index.js +68 -106
  86. package/dist/layout-engine/measure/cache.js +11 -3
  87. package/dist/layout-engine/measure/font-metrics.worker.js +1 -0
  88. package/dist/layout-engine/measure/index.d.ts +2 -1
  89. package/dist/layout-engine/measure/index.js +2 -1
  90. package/dist/layout-engine/measure/lineBreakProvider.d.ts +33 -0
  91. package/dist/layout-engine/measure/lineBreakProvider.js +252 -0
  92. package/dist/layout-engine/measure/lineBreaks.d.ts +7 -2
  93. package/dist/layout-engine/measure/lineBreaks.js +11 -18
  94. package/dist/layout-engine/measure/listMarkerWidth.d.ts +4 -1
  95. package/dist/layout-engine/measure/listMarkerWidth.js +33 -8
  96. package/dist/layout-engine/measure/measureBlocks.d.ts +4 -2
  97. package/dist/layout-engine/measure/measureBlocks.js +138 -86
  98. package/dist/layout-engine/measure/measureContainer.js +32 -9
  99. package/dist/layout-engine/measure/measureHelpers.js +5 -2
  100. package/dist/layout-engine/measure/measureParagraph.js +346 -74
  101. package/dist/layout-engine/measure/measureTypes.d.ts +2 -1
  102. package/dist/layout-engine/measure/measureWorker.d.ts +2 -2
  103. package/dist/layout-engine/measure/measureWorker.js +8 -19
  104. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +3 -14
  105. package/dist/layout-engine/measure/tableCellFloating.d.ts +10 -3
  106. package/dist/layout-engine/measure/tableCellFloating.js +37 -29
  107. package/dist/layout-engine/measure/tableCellFlow.d.ts +27 -0
  108. package/dist/layout-engine/measure/tableCellFlow.js +73 -0
  109. package/dist/layout-engine/measure/tableCellGrid.d.ts +15 -0
  110. package/dist/layout-engine/measure/tableCellGrid.js +62 -0
  111. package/dist/layout-engine/measure/textBoxParagraphLayout.d.ts +18 -0
  112. package/dist/layout-engine/measure/textBoxParagraphLayout.js +32 -0
  113. package/dist/layout-engine/measure/textMeasurementPolicy.d.ts +18 -0
  114. package/dist/layout-engine/measure/textMeasurementPolicy.js +24 -0
  115. package/dist/layout-engine/paginator.d.ts +2 -1
  116. package/dist/layout-engine/paginator.js +7 -6
  117. package/dist/layout-engine/paragraphFrame.d.ts +22 -0
  118. package/dist/layout-engine/paragraphFrame.js +17 -0
  119. package/dist/layout-engine/paragraphSequence.d.ts +7 -0
  120. package/dist/layout-engine/paragraphSequence.js +25 -0
  121. package/dist/layout-engine/paragraphSpacing.d.ts +17 -0
  122. package/dist/layout-engine/paragraphSpacing.js +30 -0
  123. package/dist/layout-engine/renderedBreakReconciliation.d.ts +63 -0
  124. package/dist/layout-engine/renderedBreakReconciliation.js +86 -0
  125. package/dist/layout-engine/tableRowBreak.d.ts +5 -2
  126. package/dist/layout-engine/tableRowBreak.js +62 -29
  127. package/dist/layout-engine/types.d.ts +54 -12
  128. package/dist/layout-engine/types.js +15 -2
  129. package/dist/layout-painter/anchoredImagePosition.d.ts +23 -0
  130. package/dist/layout-painter/anchoredImagePosition.js +95 -0
  131. package/dist/layout-painter/borderStroke.d.ts +23 -0
  132. package/dist/layout-painter/borderStroke.js +39 -0
  133. package/dist/layout-painter/renderImage.d.ts +5 -4
  134. package/dist/layout-painter/renderImage.js +18 -4
  135. package/dist/layout-painter/renderPage.d.ts +2 -27
  136. package/dist/layout-painter/renderPage.js +15 -101
  137. package/dist/layout-painter/renderParagraph.js +45 -26
  138. package/dist/layout-painter/renderTable.d.ts +2 -0
  139. package/dist/layout-painter/renderTable.js +257 -47
  140. package/dist/layout-painter/renderTextBox.js +17 -7
  141. package/dist/managers/DocumentLoaderManager.d.ts +1 -1
  142. package/dist/managers/DocumentLoaderManager.js +2 -2
  143. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  144. package/dist/paged-layout/sectionBlockWidths.js +9 -0
  145. package/dist/paged-layout/sectionGeometry.js +1 -1
  146. package/dist/prosemirror/attrs/index.d.ts +4 -2
  147. package/dist/prosemirror/attrs/index.js +32 -2
  148. package/dist/prosemirror/commands/propertyChangeScope.js +1 -1
  149. package/dist/prosemirror/conversion/fromProseDoc.js +35 -18
  150. package/dist/prosemirror/conversion/toProseDoc.js +73 -37
  151. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  152. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -2
  153. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  154. package/dist/prosemirror/extensions/features/ListExtension.js +2 -0
  155. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +68 -16
  156. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +1 -0
  157. package/dist/prosemirror/extensions/marks/HighlightExtension.js +1 -1
  158. package/dist/prosemirror/extensions/marks/LanguageExtension.d.ts +7 -0
  159. package/dist/prosemirror/extensions/marks/LanguageExtension.js +30 -0
  160. package/dist/prosemirror/extensions/marks/RunShadingExtension.js +1 -1
  161. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  162. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +1 -1
  163. package/dist/prosemirror/extensions/marks/markUtils.js +12 -0
  164. package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
  165. package/dist/prosemirror/extensions/nodes/TableExtension.js +4 -2
  166. package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +2 -1
  167. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +7 -0
  168. package/dist/prosemirror/schema/index.d.ts +2 -2
  169. package/dist/prosemirror/schema/marks.d.ts +6 -1
  170. package/dist/prosemirror/schema/nodes.d.ts +16 -12
  171. package/dist/prosemirror/styles/resolvedStyleAttrs.js +2 -0
  172. package/dist/prosemirror/utils/tabCalculator.d.ts +3 -1
  173. package/dist/prosemirror/utils/tabCalculator.js +12 -10
  174. package/dist/prosemirror/validation.js +4 -1
  175. package/dist/redline.js +13 -3
  176. package/dist/server.d.ts +9 -4
  177. package/dist/server.js +7 -2
  178. package/dist/style-sets/extract.d.ts +35 -0
  179. package/dist/style-sets/extract.js +123 -0
  180. package/dist/style-sets/stellaStyle.d.ts +13 -0
  181. package/dist/style-sets/stellaStyle.js +516 -0
  182. package/dist/style-sets/types.d.ts +31 -0
  183. package/dist/style-sets/types.js +5 -0
  184. package/dist/types/index.d.ts +2 -1
  185. package/dist/utils/createDocument.d.ts +12 -2
  186. package/dist/utils/createDocument.js +55 -36
  187. package/dist/utils/fontResolver.js +6 -6
  188. package/dist/utils/formatToStyle.js +1 -1
  189. package/dist/utils/hexId.d.ts +8 -1
  190. package/dist/utils/hexId.js +11 -3
  191. package/dist/utils/paragraphFormattingMerge.d.ts +14 -3
  192. package/dist/utils/paragraphFormattingMerge.js +14 -4
  193. package/package.json +5 -1
@@ -1,17 +1,19 @@
1
1
  import { NUMBER_FORMAT_VALUES } from "../../types/documentEnumValues.js";
2
2
  import { AUTO_PARAGRAPH_SPACING_PX, halfPointsToPixels, halfPointsToPoints, pointsToPixels } from "../../utils/units.js";
3
+ import { convertBulletToUnicode } from "../../docx/bulletMarkers.js";
3
4
  import { padDecimal } from "../../docx/numberingParser.js";
4
- import { DEFAULT_TEXTBOX_MARGINS } from "../../layout-engine/types.js";
5
+ import { autospacingMatchesBase } from "../../prosemirror/autospacingBase.js";
6
+ import { directionIsRtl } from "../../prosemirror/paragraphDirection.js";
7
+ import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../../prosemirror/attrs/index.js";
8
+ import { assertValidProseMirrorDocument } from "../../prosemirror/validation.js";
9
+ import { runShadingAttrsToShading } from "../../prosemirror/conversion/runShadingMark.js";
5
10
  import { resolveColor, resolveHighlightToCss } from "../../utils/colorResolver.js";
6
11
  import { resolveShadingFill } from "../../utils/formatToStyle.js";
7
- import { convertBulletToUnicode } from "../../docx/bulletMarkers.js";
12
+ import { DEFAULT_TEXTBOX_MARGINS } from "../../layout-engine/types.js";
8
13
  import { setTextBoxGroupId } from "../../layout-engine/textBoxGroup.js";
14
+ import { setParagraphFrame } from "../../layout-engine/paragraphFrame.js";
9
15
  import { getColumns } from "../sectionColumns.js";
10
- import { directionIsRtl } from "../../prosemirror/paragraphDirection.js";
11
- import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../../prosemirror/attrs/index.js";
12
- import { autospacingMatchesBase } from "../../prosemirror/autospacingBase.js";
13
- import { runShadingAttrsToShading } from "../../prosemirror/conversion/runShadingMark.js";
14
- import { assertValidProseMirrorDocument } from "../../prosemirror/validation.js";
16
+ import { groupParagraphFrames } from "./paragraphFrames.js";
15
17
  //#region src/layout-bridge/convert/toFlowBlocks.ts
16
18
  const DEFAULT_FONT = "Calibri";
17
19
  const DEFAULT_TABLE_CELL_MARGIN_TWIPS = {
@@ -242,6 +244,15 @@ function extractRunFormatting(marks, theme) {
242
244
  if (attrs.eastAsia) formatting.eastAsiaFontFamily = attrs.eastAsia;
243
245
  break;
244
246
  }
247
+ case "language": {
248
+ const attrs = expectLanguageMarkAttrs(mark);
249
+ formatting.language = {
250
+ ...attrs.val ? { val: attrs.val } : {},
251
+ ...attrs.eastAsia ? { eastAsia: attrs.eastAsia } : {},
252
+ ...attrs.bidi ? { bidi: attrs.bidi } : {}
253
+ };
254
+ break;
255
+ }
245
256
  case "characterSpacing": {
246
257
  const attrs = expectCharacterSpacingMarkAttrs(mark);
247
258
  if (attrs.spacing !== void 0) formatting.letterSpacing = twipsToPixels(attrs.spacing);
@@ -373,6 +384,7 @@ function paragraphRunDefaults(pmAttrs, theme) {
373
384
  const fontFamily = defaultTextFormatting.fontFamily?.ascii ?? defaultTextFormatting.fontFamily?.hAnsi;
374
385
  if (fontFamily) result.fontFamily = fontFamily;
375
386
  if (defaultTextFormatting.fontFamily?.eastAsia) result.eastAsiaFontFamily = defaultTextFormatting.fontFamily.eastAsia;
387
+ if (defaultTextFormatting.language) result.language = { ...defaultTextFormatting.language };
376
388
  if (defaultTextFormatting.fontSize !== void 0) result.fontSize = defaultTextFormatting.fontSize / 2;
377
389
  if (defaultTextFormatting.bold !== void 0) result.bold = defaultTextFormatting.bold;
378
390
  if (defaultTextFormatting.italic !== void 0) result.italic = defaultTextFormatting.italic;
@@ -427,6 +439,7 @@ function buildImageRun(attrs, constrained, pmStart, pmEnd, trackedChange) {
427
439
  if (attrs.distBottom !== void 0) run.distBottom = attrs.distBottom;
428
440
  if (attrs.distLeft !== void 0) run.distLeft = attrs.distLeft;
429
441
  if (attrs.distRight !== void 0) run.distRight = attrs.distRight;
442
+ if (attrs._docxObjectPreview === true) run.exactLineHeight = true;
430
443
  if (attrs.cropTop != null) run.cropTop = attrs.cropTop;
431
444
  if (attrs.cropRight != null) run.cropRight = attrs.cropRight;
432
445
  if (attrs.cropBottom != null) run.cropBottom = attrs.cropBottom;
@@ -613,6 +626,9 @@ function readNumberFormats(value) {
613
626
  function readListMarkerSuffix(value) {
614
627
  if (value === "tab" || value === "space" || value === "nothing") return value;
615
628
  }
629
+ function readListMarkerAlignment(value) {
630
+ if (value === "left" || value === "center" || value === "right") return value;
631
+ }
616
632
  function toPreviousListAttrs(previousFormatting) {
617
633
  const attrs = {};
618
634
  const numPr = previousFormatting["numPr"];
@@ -639,6 +655,10 @@ function toPreviousListAttrs(previousFormatting) {
639
655
  if (typeof listMarkerFontFamily === "string") attrs.listMarkerFontFamily = listMarkerFontFamily;
640
656
  const listMarkerFontSize = previousFormatting["listMarkerFontSize"];
641
657
  if (typeof listMarkerFontSize === "number") attrs.listMarkerFontSize = listMarkerFontSize;
658
+ const listMarkerBold = previousFormatting["listMarkerBold"];
659
+ if (typeof listMarkerBold === "boolean") attrs.listMarkerBold = listMarkerBold;
660
+ const listMarkerAlignment = readListMarkerAlignment(previousFormatting["listMarkerAlignment"]);
661
+ if (listMarkerAlignment) attrs.listMarkerAlignment = listMarkerAlignment;
642
662
  const listMarkerSuffix = readListMarkerSuffix(previousFormatting["listMarkerSuffix"]);
643
663
  if (listMarkerSuffix) attrs.listMarkerSuffix = listMarkerSuffix;
644
664
  return attrs;
@@ -662,6 +682,8 @@ function applyDeletedListMarkerAttrs(attrs, change, listCounters, listAbstractCo
662
682
  if (previousListAttrs.listMarkerHidden !== void 0) attrs.listMarkerHidden = previousListAttrs.listMarkerHidden;
663
683
  if (previousListAttrs.listMarkerFontFamily) attrs.listMarkerFontFamily = previousListAttrs.listMarkerFontFamily;
664
684
  if (previousListAttrs.listMarkerFontSize) attrs.listMarkerFontSize = previousListAttrs.listMarkerFontSize;
685
+ if (previousListAttrs.listMarkerBold !== void 0) attrs.listMarkerBold = previousListAttrs.listMarkerBold;
686
+ if (previousListAttrs.listMarkerAlignment) attrs.listMarkerAlignment = previousListAttrs.listMarkerAlignment;
665
687
  if (previousListAttrs.listMarkerSuffix) attrs.listMarkerSuffix = previousListAttrs.listMarkerSuffix;
666
688
  }
667
689
  function convertParagraphAttrs(pmAttrs, theme, listCounters, listAbstractCounters, listSeenNumIds, defaultTabStopTwips, originalListCounters, originalListAbstractCounters, originalListSeenNumIds) {
@@ -752,6 +774,9 @@ function convertParagraphAttrs(pmAttrs, theme, listCounters, listAbstractCounter
752
774
  return tabStop;
753
775
  });
754
776
  if (pmAttrs.pageBreakBefore) attrs.pageBreakBefore = true;
777
+ if (pmAttrs.kinsoku !== void 0 && pmAttrs.kinsoku !== null) attrs.kinsoku = pmAttrs.kinsoku;
778
+ if (pmAttrs.overflowPunctuation !== void 0 && pmAttrs.overflowPunctuation !== null) attrs.overflowPunctuation = pmAttrs.overflowPunctuation;
779
+ if (pmAttrs.suppressAutoHyphens !== void 0 && pmAttrs.suppressAutoHyphens !== null) attrs.suppressAutoHyphens = pmAttrs.suppressAutoHyphens;
755
780
  if (pmAttrs.renderedPageBreakBefore) attrs.renderedPageBreakBefore = true;
756
781
  if (pmAttrs.keepNext) attrs.keepNext = true;
757
782
  if (pmAttrs.keepLines) attrs.keepLines = true;
@@ -793,6 +818,8 @@ function convertParagraphAttrs(pmAttrs, theme, listCounters, listAbstractCounter
793
818
  if (pmAttrs.listMarkerHidden) attrs.listMarkerHidden = true;
794
819
  if (pmAttrs.listMarkerFontFamily) attrs.listMarkerFontFamily = pmAttrs.listMarkerFontFamily;
795
820
  if (pmAttrs.listMarkerFontSize) attrs.listMarkerFontSize = pmAttrs.listMarkerFontSize;
821
+ if (pmAttrs.listMarkerBold !== null && pmAttrs.listMarkerBold !== void 0) attrs.listMarkerBold = pmAttrs.listMarkerBold;
822
+ if (pmAttrs.listMarkerAlignment) attrs.listMarkerAlignment = pmAttrs.listMarkerAlignment;
796
823
  if (pmAttrs.listMarkerSuffix) attrs.listMarkerSuffix = pmAttrs.listMarkerSuffix;
797
824
  if (pmAttrs.listMarkerSecondSlotOffsetTwips !== void 0) attrs.listMarkerSecondSlotOffsetTwips = pmAttrs.listMarkerSecondSlotOffsetTwips;
798
825
  if (!pmAttrs.numPr) {
@@ -832,10 +859,13 @@ function convertParagraph(node, startPos, options) {
832
859
  const pmAttrs = expectParagraphAttrs(node);
833
860
  const runs = paragraphToRuns(node, startPos, options);
834
861
  const attrs = convertParagraphAttrs(pmAttrs, options.theme, options.listCounters, options.listAbstractCounters, options.listSeenNumIds, options.defaultTabStopTwips, options.originalListCounters, options.originalListAbstractCounters, options.originalListSeenNumIds);
862
+ if (options.lineBreakRules) attrs.lineBreakRules = options.lineBreakRules;
863
+ if (options.automaticHyphenation) attrs.automaticHyphenation = options.automaticHyphenation;
835
864
  const defaultTextFormatting = pmAttrs.defaultTextFormatting;
836
865
  if (runs.length === 0) {
837
866
  if (pmAttrs._originalFormatting && Object.entries(pmAttrs._originalFormatting).some(([key, value]) => key !== "runProperties" && value !== void 0 && value !== null)) attrs.hasDirectParagraphFormatting = true;
838
867
  const paragraphMarkFormatting = pmAttrs._originalFormatting?.runProperties;
868
+ if (paragraphMarkFormatting && Object.values(paragraphMarkFormatting).some((value) => value !== void 0 && value !== null)) attrs.hasDirectParagraphMarkFormatting = true;
839
869
  if (paragraphMarkFormatting?.fontSize !== void 0) attrs.defaultFontSize = paragraphMarkFormatting.fontSize / 2;
840
870
  const paragraphMarkFontFamily = paragraphMarkFormatting?.fontFamily?.ascii ?? paragraphMarkFormatting?.fontFamily?.hAnsi;
841
871
  if (paragraphMarkFontFamily) attrs.defaultFontFamily = paragraphMarkFontFamily;
@@ -844,8 +874,10 @@ function convertParagraph(node, startPos, options) {
844
874
  attrs.suppressEmptyParagraphHeight = true;
845
875
  if (attrs.listMarker !== void 0) attrs.listMarkerHidden = true;
846
876
  }
877
+ const hasVisibleParagraphPayload = attrs.listMarker !== void 0 && !attrs.listMarkerHidden || attrs.borders?.top !== void 0 || attrs.borders?.bottom !== void 0 || attrs.borders?.left !== void 0 || attrs.borders?.right !== void 0 || attrs.borders?.between !== void 0 || attrs.borders?.bar !== void 0 || attrs.shading !== void 0;
878
+ if (runs.length === 0 && pmAttrs._pageBreakCarrier === true && !hasVisibleParagraphPayload) attrs.suppressEmptyParagraphHeight = true;
847
879
  const bookmarkNames = pmAttrs.bookmarks?.map((b) => b.name);
848
- return {
880
+ const block = {
849
881
  kind: "paragraph",
850
882
  id: nextBlockId(),
851
883
  runs,
@@ -855,6 +887,21 @@ function convertParagraph(node, startPos, options) {
855
887
  pmStart: startPos,
856
888
  pmEnd: startPos + node.nodeSize
857
889
  };
890
+ const frame = pmAttrs._originalFormatting?.frame;
891
+ if (frame !== void 0 && frame.dropCap !== "drop" && frame.dropCap !== "margin") setParagraphFrame(block, {
892
+ ...frame.width !== void 0 ? { width: twipsToPixels(frame.width) } : {},
893
+ ...frame.height !== void 0 ? { height: twipsToPixels(frame.height) } : {},
894
+ ...frame.hSpace !== void 0 ? { hSpace: twipsToPixels(frame.hSpace) } : {},
895
+ ...frame.vSpace !== void 0 ? { vSpace: twipsToPixels(frame.vSpace) } : {},
896
+ ...frame.hAnchor !== void 0 ? { hAnchor: frame.hAnchor } : {},
897
+ ...frame.vAnchor !== void 0 ? { vAnchor: frame.vAnchor } : {},
898
+ ...frame.x !== void 0 ? { x: twipsToPixels(frame.x) } : {},
899
+ ...frame.y !== void 0 ? { y: twipsToPixels(frame.y) } : {},
900
+ ...frame.xAlign !== void 0 ? { xAlign: frame.xAlign } : {},
901
+ ...frame.yAlign !== void 0 ? { yAlign: frame.yAlign } : {},
902
+ ...frame.wrap !== void 0 ? { wrap: frame.wrap } : {}
903
+ });
904
+ return block;
858
905
  }
859
906
  /**
860
907
  * Word keeps terminal empty body paragraphs after a final table as editable
@@ -879,6 +926,16 @@ function suppressTerminalEmptyParagraphsAfterTable(blocks) {
879
926
  };
880
927
  }
881
928
  }
929
+ function suppressFinalParagraphInRepeatedEmptySuffix(blocks) {
930
+ let suffixStart = blocks.length;
931
+ while (suffixStart > 0 && isPaintlessTerminalParagraph(blocks[suffixStart - 1])) suffixStart -= 1;
932
+ if (suffixStart === 0 || blocks.length - suffixStart < 2 || blocks[suffixStart - 1]?.kind === "table") return;
933
+ const finalBlock = blocks.at(-1);
934
+ if (isPaintlessTerminalParagraph(finalBlock)) finalBlock.attrs = {
935
+ ...finalBlock.attrs,
936
+ suppressEmptyParagraphHeight: true
937
+ };
938
+ }
882
939
  function reserveLeadingEmptyOutlineHeight(blocks) {
883
940
  const firstBlock = blocks.at(0);
884
941
  if (firstBlock?.kind !== "paragraph" || firstBlock.runs.length !== 0 || firstBlock.attrs?.outlineLevel !== 0) return;
@@ -892,7 +949,7 @@ function reserveLeadingEmptyOutlineHeight(blocks) {
892
949
  * OOXML stores border widths in eighths of a point.
893
950
  */
894
951
  function borderWidthToPixels(eighthsOfPoint) {
895
- return Math.max(1, Math.round(eighthsOfPoint / 8 * 1.333));
952
+ return pointsToPixels(eighthsOfPoint / 8);
896
953
  }
897
954
  const OOXML_TO_CSS_BORDER = {
898
955
  single: "solid",
@@ -919,7 +976,7 @@ function convertBorderSpecToLayout(border, theme) {
919
976
  if (!border.style || border.style === "none" || border.style === "nil") return;
920
977
  const result = {
921
978
  style: OOXML_TO_CSS_BORDER[border.style] || "solid",
922
- width: borderWidthToPixels(border.size ?? 0),
979
+ width: border.size === void 0 ? 1 : borderWidthToPixels(border.size),
923
980
  color: border.color ? resolveColor(border.color, theme) : "#000000"
924
981
  };
925
982
  if (border.space !== void 0) result.space = pointsToPixels(border.space);
@@ -939,10 +996,23 @@ function extractCellBorders(borders, theme) {
939
996
  "right"
940
997
  ]) {
941
998
  const border = borders[side];
942
- result[side] = (border ? convertBorderSpecToLayout(border, theme) : void 0) ?? {
943
- width: 0,
944
- style: "none"
945
- };
999
+ const converted = border ? convertBorderSpecToLayout(border, theme) : void 0;
1000
+ if (!converted) {
1001
+ result[side] = {
1002
+ width: 0,
1003
+ style: "none"
1004
+ };
1005
+ continue;
1006
+ }
1007
+ result[side] = border?.size === 0 ? {
1008
+ ...converted,
1009
+ width: 0
1010
+ } : converted;
1011
+ }
1012
+ for (const side of ["topLeftToBottomRight", "topRightToBottomLeft"]) {
1013
+ const border = borders[side];
1014
+ const converted = border ? convertBorderSpecToLayout(border, theme) : void 0;
1015
+ if (converted) result[side] = converted;
946
1016
  }
947
1017
  return Object.keys(result).length > 0 ? result : void 0;
948
1018
  }
@@ -961,7 +1031,7 @@ function convertTableCell(node, startPos, options, tableCellMargins) {
961
1031
  offset += child.nodeSize;
962
1032
  });
963
1033
  const trailingBlock = blocks.at(-1);
964
- if (blocks.length > 1 && trailingBlock?.kind === "paragraph" && trailingBlock.runs.every((run) => run.kind === "text" && run.text.length === 0)) trailingBlock.attrs = {
1034
+ if (blocks.at(-2)?.kind === "table" && trailingBlock?.kind === "paragraph" && trailingBlock.runs.every((run) => run.kind === "text" && run.text.length === 0)) trailingBlock.attrs = {
965
1035
  ...trailingBlock.attrs,
966
1036
  suppressEmptyParagraphHeight: true
967
1037
  };
@@ -983,13 +1053,14 @@ function convertTableCell(node, startPos, options, tableCellMargins) {
983
1053
  };
984
1054
  const cell = {
985
1055
  id: nextBlockId(),
986
- blocks,
1056
+ blocks: groupParagraphFrames(blocks, nextBlockId),
987
1057
  colSpan: attrs.colspan,
988
1058
  rowSpan: attrs.rowspan,
989
1059
  padding
990
1060
  };
991
1061
  if (attrs.width) cell.width = twipsToPixels(attrs.width);
992
1062
  if (attrs.verticalAlign) cell.verticalAlign = attrs.verticalAlign;
1063
+ if (attrs.textDirection) cell.textDirection = attrs.textDirection;
993
1064
  if (attrs.backgroundColor) cell.background = `#${attrs.backgroundColor}`;
994
1065
  const cellBorders = extractCellBorders(attrs.borders, options.theme);
995
1066
  if (cellBorders) cell.borders = cellBorders;
@@ -1011,9 +1082,12 @@ function convertTableRow(node, startPos, options, tableCellMargins) {
1011
1082
  id: nextBlockId(),
1012
1083
  cells
1013
1084
  };
1085
+ if (attrs._originalFormatting?.gridBefore) row.gridBefore = attrs._originalFormatting.gridBefore;
1086
+ if (attrs._originalFormatting?.gridAfter) row.gridAfter = attrs._originalFormatting.gridAfter;
1014
1087
  if (attrs.height) row.height = twipsToPixels(attrs.height);
1015
1088
  if (attrs.heightRule) row.heightRule = attrs.heightRule;
1016
1089
  if (attrs.isHeader) row.isHeader = attrs.isHeader;
1090
+ if (attrs._originalFormatting?.cantSplit) row.cantSplit = true;
1017
1091
  if (attrs.hidden) row.hidden = attrs.hidden;
1018
1092
  return row;
1019
1093
  }
@@ -1136,6 +1210,7 @@ function convertTextBoxNode(node, startPos, opts) {
1136
1210
  pmEnd: startPos + node.nodeSize
1137
1211
  };
1138
1212
  if (attrs.height !== void 0) textBox.height = attrs.height;
1213
+ if (attrs.autoFit !== void 0) textBox.autoFit = attrs.autoFit;
1139
1214
  if (attrs.fillColor !== void 0) textBox.fillColor = attrs.fillColor;
1140
1215
  if (attrs.outlineWidth !== void 0) textBox.outlineWidth = attrs.outlineWidth;
1141
1216
  if (attrs.outlineColor !== void 0) textBox.outlineColor = attrs.outlineColor;
@@ -1342,7 +1417,8 @@ function toFlowBlocks(doc, options = {}) {
1342
1417
  });
1343
1418
  reserveLeadingEmptyOutlineHeight(blocks);
1344
1419
  suppressTerminalEmptyParagraphsAfterTable(blocks);
1345
- return mergeRunInParagraphs(blocks);
1420
+ suppressFinalParagraphInRepeatedEmptySuffix(blocks);
1421
+ return groupParagraphFrames(mergeRunInParagraphs(blocks), nextBlockId);
1346
1422
  }
1347
1423
  /**
1348
1424
  * Merge consecutive paragraph blocks where the first carries
@@ -1,4 +1,5 @@
1
1
  import { measuredLineRangeHeight } from "../../layout-engine/lineFlow.js";
2
+ import { getTableRowLeadingWidth } from "../../layout-engine/types.js";
2
3
  import { getHeaderRowsHeight } from "../../layout-engine/index.js";
3
4
  //#region src/layout-bridge/engine/hitTest.ts
4
5
  /**
@@ -213,7 +214,7 @@ function hitTestTableCell(pageHit, blocks, measures, pagePoint) {
213
214
  const rowMeasure = tableMeasure.rows[rowIndex];
214
215
  const row = tableBlock.rows[rowIndex];
215
216
  if (!rowMeasure || !row) continue;
216
- let colX = 0;
217
+ let colX = getTableRowLeadingWidth(row, tableMeasure.columnWidths);
217
218
  let colIndex = -1;
218
219
  if (rowMeasure.cells.length === 0 || row.cells.length === 0) continue;
219
220
  for (let c = 0; c < rowMeasure.cells.length; c++) {
@@ -2,9 +2,10 @@ import { FontMetrics, FontStyle, RunMeasurement, TextMeasurement } from "../../.
2
2
  import { getFontMetrics, measureRun, measureText, measureTextWidth } from "../../../layout-engine/measure/measureProvider.js";
3
3
  import { getCanvasContext, resetCanvasContext } from "../../../layout-engine/measure/measureContainer.js";
4
4
  import { buildFontString, findCharacterAtX, getXForCharacter, halfPtToPx, ptToPx, pxToHalfPt, pxToPt, pxToTwips, twipsToPx } from "../../../layout-engine/measure/measureHelpers.js";
5
+ import { LineBreakPolicy, LineBreakProvider, defaultLineBreakProvider, getLineBreakProvider, getLineBreakProviderGeneration, resetLineBreakProvider, setLineBreakProvider } from "../../../layout-engine/measure/lineBreakProvider.js";
5
6
  import { FloatingExclusionRect, FloatingImageZone, FloatingLineMargins, FloatingLineSegmentZone, WrapTextDirection, getFloatingAvailableWidth, getFloatingMargins, rectsToFloatingZones } from "../../../layout-engine/measure/floatingZones.js";
6
7
  import { clampFloatingWrapMargins } from "../../../layout-engine/measure/clampFloatingWrapMargins.js";
7
8
  import { MIN_WRAP_SEGMENT_WIDTH, MeasureParagraphOptions, findClearLineY, getRunCharWidths, measureParagraph, measureParagraphs } from "../../../layout-engine/measure/measureParagraph.js";
8
9
  import { clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getFontCacheSize, getParagraphCacheSize, getTextCacheSize, getTotalCacheSize, hashParagraphBlock, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFontCacheSize, setParagraphCacheSize, setTextCacheSize } from "../../../layout-engine/measure/cache.js";
9
10
  import { FolioMeasurementFeatureFlags, isWorkerFontMetricsEnabled, setFolioMeasurementFlags } from "../../../layout-engine/measure/featureFlags.js";
10
- export { type FloatingExclusionRect, type FloatingImageZone, type FloatingLineMargins, type FloatingLineSegmentZone, type FolioMeasurementFeatureFlags, type FontMetrics, type FontStyle, MIN_WRAP_SEGMENT_WIDTH, type MeasureParagraphOptions, type RunMeasurement, type TextMeasurement, type WrapTextDirection, buildFontString, clampFloatingWrapMargins, clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, findCharacterAtX, findClearLineY, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getCanvasContext, getFloatingAvailableWidth, getFloatingMargins, getFontCacheSize, getFontMetrics, getParagraphCacheSize, getRunCharWidths, getTextCacheSize, getTotalCacheSize, getXForCharacter, halfPtToPx, hashParagraphBlock, isWorkerFontMetricsEnabled, measureParagraph, measureParagraphs, measureRun, measureText, measureTextWidth, ptToPx, pxToHalfPt, pxToPt, pxToTwips, rectsToFloatingZones, resetCanvasContext, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFolioMeasurementFlags, setFontCacheSize, setParagraphCacheSize, setTextCacheSize, twipsToPx };
11
+ export { type FloatingExclusionRect, type FloatingImageZone, type FloatingLineMargins, type FloatingLineSegmentZone, type FolioMeasurementFeatureFlags, type FontMetrics, type FontStyle, type LineBreakPolicy, type LineBreakProvider, MIN_WRAP_SEGMENT_WIDTH, type MeasureParagraphOptions, type RunMeasurement, type TextMeasurement, type WrapTextDirection, buildFontString, clampFloatingWrapMargins, clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, defaultLineBreakProvider, findCharacterAtX, findClearLineY, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getCanvasContext, getFloatingAvailableWidth, getFloatingMargins, getFontCacheSize, getFontMetrics, getLineBreakProvider, getLineBreakProviderGeneration, getParagraphCacheSize, getRunCharWidths, getTextCacheSize, getTotalCacheSize, getXForCharacter, halfPtToPx, hashParagraphBlock, isWorkerFontMetricsEnabled, measureParagraph, measureParagraphs, measureRun, measureText, measureTextWidth, ptToPx, pxToHalfPt, pxToPt, pxToTwips, rectsToFloatingZones, resetCanvasContext, resetLineBreakProvider, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFolioMeasurementFlags, setFontCacheSize, setLineBreakProvider, setParagraphCacheSize, setTextCacheSize, twipsToPx };
@@ -1,9 +1,10 @@
1
1
  import { getFontMetrics, measureRun, measureText, measureTextWidth } from "../../../layout-engine/measure/measureProvider.js";
2
2
  import { buildFontString, findCharacterAtX, getXForCharacter, halfPtToPx, ptToPx, pxToHalfPt, pxToPt, pxToTwips, twipsToPx } from "../../../layout-engine/measure/measureHelpers.js";
3
+ import { defaultLineBreakProvider, getLineBreakProvider, getLineBreakProviderGeneration, resetLineBreakProvider, setLineBreakProvider } from "../../../layout-engine/measure/lineBreakProvider.js";
3
4
  import { clampFloatingWrapMargins } from "../../../layout-engine/measure/clampFloatingWrapMargins.js";
4
5
  import { getFloatingAvailableWidth, getFloatingMargins, rectsToFloatingZones } from "../../../layout-engine/measure/floatingZones.js";
5
6
  import { MIN_WRAP_SEGMENT_WIDTH, findClearLineY, getRunCharWidths, measureParagraph, measureParagraphs } from "../../../layout-engine/measure/measureParagraph.js";
6
7
  import { clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getFontCacheSize, getParagraphCacheSize, getTextCacheSize, getTotalCacheSize, hashParagraphBlock, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFontCacheSize, setParagraphCacheSize, setTextCacheSize } from "../../../layout-engine/measure/cache.js";
7
8
  import { isWorkerFontMetricsEnabled, setFolioMeasurementFlags } from "../../../layout-engine/measure/featureFlags.js";
8
9
  import { getCanvasContext, resetCanvasContext } from "../../../layout-engine/measure/measureContainer.js";
9
- export { MIN_WRAP_SEGMENT_WIDTH, buildFontString, clampFloatingWrapMargins, clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, findCharacterAtX, findClearLineY, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getCanvasContext, getFloatingAvailableWidth, getFloatingMargins, getFontCacheSize, getFontMetrics, getParagraphCacheSize, getRunCharWidths, getTextCacheSize, getTotalCacheSize, getXForCharacter, halfPtToPx, hashParagraphBlock, isWorkerFontMetricsEnabled, measureParagraph, measureParagraphs, measureRun, measureText, measureTextWidth, ptToPx, pxToHalfPt, pxToPt, pxToTwips, rectsToFloatingZones, resetCanvasContext, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFolioMeasurementFlags, setFontCacheSize, setParagraphCacheSize, setTextCacheSize, twipsToPx };
10
+ export { MIN_WRAP_SEGMENT_WIDTH, buildFontString, clampFloatingWrapMargins, clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, defaultLineBreakProvider, findCharacterAtX, findClearLineY, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getCanvasContext, getFloatingAvailableWidth, getFloatingMargins, getFontCacheSize, getFontMetrics, getLineBreakProvider, getLineBreakProviderGeneration, getParagraphCacheSize, getRunCharWidths, getTextCacheSize, getTotalCacheSize, getXForCharacter, halfPtToPx, hashParagraphBlock, isWorkerFontMetricsEnabled, measureParagraph, measureParagraphs, measureRun, measureText, measureTextWidth, ptToPx, pxToHalfPt, pxToPt, pxToTwips, rectsToFloatingZones, resetCanvasContext, resetLineBreakProvider, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFolioMeasurementFlags, setFontCacheSize, setLineBreakProvider, setParagraphCacheSize, setTextCacheSize, twipsToPx };
@@ -2,6 +2,7 @@ import { measureRun } from "../../layout-engine/measure/measureProvider.js";
2
2
  import { buildRunFontStyle } from "../../layout-engine/measure/measureHelpers.js";
3
3
  import { inlineImageBoundingBox } from "../../utils/rotationBoundingBox.js";
4
4
  import { measuredLineContentOffset } from "../../layout-engine/lineFlow.js";
5
+ import { getTableRowLeadingWidth } from "../../layout-engine/types.js";
5
6
  import { measureParagraph } from "../../layout-engine/measure/measureParagraph.js";
6
7
  import { buildTableCellFloatingZones, getTableCellContentWidth, getTableCellFloatingImages } from "../../layout-engine/measure/tableCellFloating.js";
7
8
  import { getHeaderRowsHeight } from "../../layout-engine/index.js";
@@ -314,7 +315,7 @@ function selectionToRects(layout, blocks, measures, from, to) {
314
315
  if (!row || !rowMeasure) continue;
315
316
  const clipTop = tableFragment.topClip ?? 0;
316
317
  const clipBottom = tableFragment.bottomClip ?? rowMeasure.height;
317
- let cellX = 0;
318
+ let cellX = getTableRowLeadingWidth(row, tableMeasure.columnWidths);
318
319
  for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
319
320
  const cell = row.cells[cellIndex];
320
321
  const cellMeasure = rowMeasure.cells[cellIndex];
@@ -0,0 +1,7 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { PageHeaderFooterRefs } from "./types.js";
3
+
4
+ //#region src/layout-engine/headerFooterRefs.d.ts
5
+ declare const resolveSectionHeaderFooterRefs: (documentModel: document_d_exports.Document | null | undefined) => PageHeaderFooterRefs[] | undefined;
6
+ //#endregion
7
+ export { resolveSectionHeaderFooterRefs };
@@ -0,0 +1,40 @@
1
+ //#region src/layout-engine/headerFooterRefs.ts
2
+ const resolveSectionRefs = (props, inherited, documentEvenAndOddHeaders) => {
3
+ const refs = {
4
+ ...inherited,
5
+ evenAndOddHeaders: props.evenAndOddHeaders ?? documentEvenAndOddHeaders
6
+ };
7
+ if (props.titlePg !== void 0) refs.titlePg = props.titlePg;
8
+ for (const ref of props.headerReferences ?? []) if (ref.type === "default") refs.headerDefault = ref.rId;
9
+ else if (ref.type === "first") refs.headerFirst = ref.rId;
10
+ else refs.headerEven = ref.rId;
11
+ for (const ref of props.footerReferences ?? []) if (ref.type === "default") refs.footerDefault = ref.rId;
12
+ else if (ref.type === "first") refs.footerFirst = ref.rId;
13
+ else refs.footerEven = ref.rId;
14
+ return refs;
15
+ };
16
+ const inheritedRefsFrom = (refs) => ({
17
+ ...refs.headerDefault === void 0 ? {} : { headerDefault: refs.headerDefault },
18
+ ...refs.headerFirst === void 0 ? {} : { headerFirst: refs.headerFirst },
19
+ ...refs.headerEven === void 0 ? {} : { headerEven: refs.headerEven },
20
+ ...refs.footerDefault === void 0 ? {} : { footerDefault: refs.footerDefault },
21
+ ...refs.footerFirst === void 0 ? {} : { footerFirst: refs.footerFirst },
22
+ ...refs.footerEven === void 0 ? {} : { footerEven: refs.footerEven }
23
+ });
24
+ const resolveSectionHeaderFooterRefs = (documentModel) => {
25
+ const body = documentModel?.package.document;
26
+ if (!body) return;
27
+ const sections = [];
28
+ if (body.sections && body.sections.length > 0) sections.push(...body.sections.map(({ properties }) => properties));
29
+ else if (body.finalSectionProperties) sections.push(body.finalSectionProperties);
30
+ if (sections.length === 0) return;
31
+ const documentEvenAndOddHeaders = documentModel.package.settings?.evenAndOddHeaders === true;
32
+ let inherited = {};
33
+ return sections.map((props) => {
34
+ const refs = resolveSectionRefs(props, inherited, documentEvenAndOddHeaders);
35
+ inherited = inheritedRefsFrom(refs);
36
+ return refs;
37
+ });
38
+ };
39
+ //#endregion
40
+ export { resolveSectionHeaderFooterRefs };
@@ -1,6 +1,7 @@
1
- import { BlockId, BorderStyle, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, Layout, LayoutOptions, LineBreakRun, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImageRun, tableColumnsArePinned } from "./types.js";
1
+ import { BlockId, BorderStyle, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, Layout, LayoutOptions, LineBreakRun, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getTableRowLeadingWidth, isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImageRun, tableColumnsArePinned } from "./types.js";
2
2
  import { PageState, Paginator, PaginatorOptions, createPaginator } from "./paginator.js";
3
3
  import { KeepNextChain, calculateChainHeight, computeKeepNextChains, getMidChainIndices, hasKeepLines, hasPageBreakBefore } from "./keep-together.js";
4
+ import { resolveSectionHeaderFooterRefs } from "./headerFooterRefs.js";
4
5
  import { BreakDecision, SectionState, applyPendingToActive, createInitialSectionState, getEffectiveColumns, getEffectiveMargins, getEffectivePageSize, scheduleSectionBreak } from "./section-breaks.js";
5
6
  import { assertExhaustiveFlowBlock, findPageIndexContainingPmPos } from "./pmPageIndex.js";
6
7
 
@@ -43,4 +44,4 @@ declare function layoutDocument(blocks: FlowBlock[], measures: Measure[], option
43
44
  */
44
45
  declare function getHeaderRowsHeight(measure: TableMeasure, headerRowCount: number): number;
45
46
  //#endregion
46
- export { BlockId, BorderStyle, type BreakDecision, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, type KeepNextChain, Layout, LayoutOptions, LineBreakRun, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionLayoutConfig, type SectionState, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, applyContextualSpacing, applyPendingToActive, assertExhaustiveFlowBlock, calculateChainHeight, collectSectionConfigs, computeKeepNextChains, createInitialSectionState, createPaginator, findPageIndexContainingPmPos, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getEffectiveColumns, getEffectiveMargins, getEffectivePageSize, getHeaderRowsHeight, getMidChainIndices, hasKeepLines, hasPageBreakBefore, isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImageRun, layoutDocument, scheduleSectionBreak, tableColumnsArePinned };
47
+ export { BlockId, BorderStyle, type BreakDecision, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, type KeepNextChain, Layout, LayoutOptions, LineBreakRun, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionLayoutConfig, type SectionState, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, applyContextualSpacing, applyPendingToActive, assertExhaustiveFlowBlock, calculateChainHeight, collectSectionConfigs, computeKeepNextChains, createInitialSectionState, createPaginator, findPageIndexContainingPmPos, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getEffectiveColumns, getEffectiveMargins, getEffectivePageSize, getHeaderRowsHeight, getMidChainIndices, getTableRowLeadingWidth, hasKeepLines, hasPageBreakBefore, isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImageRun, layoutDocument, resolveSectionHeaderFooterRefs, scheduleSectionBreak, tableColumnsArePinned };