@stll/folio-core 0.46.0 → 0.47.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 (366) hide show
  1. package/dist/ai-edits/apply.js +26 -24
  2. package/dist/ai-edits/headless.js +1 -1
  3. package/dist/ai-edits/read.d.ts +1 -0
  4. package/dist/ai-edits/read.js +1 -0
  5. package/dist/ai-edits/snapshot.js +32 -27
  6. package/dist/ai-edits/table-cell-mutations.js +15 -7
  7. package/dist/ai-edits/table-geometry.js +21 -18
  8. package/dist/ai-edits/table-template.js +2 -2
  9. package/dist/compare/content-alignment.js +108 -12
  10. package/dist/compare/content-types.d.ts +8 -2
  11. package/dist/compare/content.js +2 -11
  12. package/dist/compare/plan.js +7 -4
  13. package/dist/compare/section-boundary-properties.js +1 -2
  14. package/dist/content-controls/checkboxDisplay.d.ts +8 -2
  15. package/dist/content-controls/checkboxDisplay.js +11 -5
  16. package/dist/content-controls/mutateContentControls.js +41 -42
  17. package/dist/controller/layoutPipeline.js +8 -3
  18. package/dist/display-list/build/buildDisplayList.js +7 -7
  19. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  20. package/dist/display-list/build/imagePrimitives.js +38 -20
  21. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  22. package/dist/display-list/build/paragraphPrimitives.js +93 -13
  23. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  24. package/dist/display-list/build/previewPrimitives.js +89 -0
  25. package/dist/display-list/build/strokes.d.ts +177 -8
  26. package/dist/display-list/build/strokes.js +167 -47
  27. package/dist/display-list/build/tablePrimitives.js +4 -2
  28. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  29. package/dist/display-list/build/textDecorations.d.ts +15 -1
  30. package/dist/display-list/build/textDecorations.js +15 -1
  31. package/dist/display-list/dom/renderDisplayListToDom.js +1 -19
  32. package/dist/display-list/primitives.d.ts +13 -2
  33. package/dist/display-list/primitives.js +36 -1
  34. package/dist/document-operations.js +2 -1
  35. package/dist/docx/attributeRemainder.d.ts +34 -1
  36. package/dist/docx/attributeRemainder.js +49 -3
  37. package/dist/docx/blockContentParser.d.ts +2 -0
  38. package/dist/docx/blockContentParser.js +39 -67
  39. package/dist/docx/blockPlainText.js +3 -1
  40. package/dist/docx/borderParser.js +26 -11
  41. package/dist/docx/builtInStyles.d.ts +8 -16
  42. package/dist/docx/builtInStyles.js +54 -17
  43. package/dist/docx/commentAnchorIndex.js +1 -1
  44. package/dist/docx/commentParser.js +3 -3
  45. package/dist/docx/commentRangeIntegrity.js +1 -1
  46. package/dist/docx/commentRangeJoin.js +1 -1
  47. package/dist/docx/commentReferenceNormalization.js +3 -2
  48. package/dist/docx/commentReplyMarkers.js +1 -1
  49. package/dist/docx/compatibility.js +56 -42
  50. package/dist/docx/containerChildren.d.ts +110 -13
  51. package/dist/docx/containerChildren.gen.d.ts +16 -1
  52. package/dist/docx/containerChildren.gen.js +18 -1
  53. package/dist/docx/containerChildren.js +63 -13
  54. package/dist/docx/diagramPreview.d.ts +14 -2
  55. package/dist/docx/diagramPreview.js +81 -169
  56. package/dist/docx/documentParser.js +4 -1
  57. package/dist/docx/drawingAnchor.d.ts +87 -0
  58. package/dist/docx/drawingAnchor.js +201 -0
  59. package/dist/docx/drawingUtils.d.ts +43 -38
  60. package/dist/docx/drawingUtils.js +205 -118
  61. package/dist/docx/fontTableParser.js +102 -41
  62. package/dist/docx/footnoteParser.js +10 -6
  63. package/dist/docx/groupDrawingParser.js +4 -3
  64. package/dist/docx/headerFooterReferenceNormalization.js +1 -1
  65. package/dist/docx/hyperlinkParser.d.ts +45 -7
  66. package/dist/docx/hyperlinkParser.js +126 -57
  67. package/dist/docx/imageParser.js +127 -107
  68. package/dist/docx/index.d.ts +2 -1
  69. package/dist/docx/index.js +2 -1
  70. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  71. package/dist/docx/inlineContentRemovals.js +46 -0
  72. package/dist/docx/inlineWrapperContent.d.ts +84 -3
  73. package/dist/docx/inlineWrapperContent.js +85 -4
  74. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  75. package/dist/docx/inlineWrapperParser.js +60 -0
  76. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  77. package/dist/docx/normalizeBaseDirection.js +4 -2
  78. package/dist/docx/numberingParser.d.ts +25 -2
  79. package/dist/docx/numberingParser.js +264 -361
  80. package/dist/docx/numberingReference.d.ts +9 -16
  81. package/dist/docx/numberingReference.js +17 -16
  82. package/dist/docx/numberingReferenceNormalization.js +7 -7
  83. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  84. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  85. package/dist/docx/paraIdAttribute.d.ts +91 -1
  86. package/dist/docx/paraIdAttribute.js +79 -1
  87. package/dist/docx/paragraphParser.d.ts +9 -24
  88. package/dist/docx/paragraphParser.js +212 -396
  89. package/dist/docx/paragraphProperties.d.ts +23 -0
  90. package/dist/docx/paragraphProperties.js +279 -0
  91. package/dist/docx/paragraphPropertySource.js +2 -0
  92. package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
  93. package/dist/docx/paragraphTextBoxEnrichment.js +14 -7
  94. package/dist/docx/paragraphTraversal.d.ts +14 -10
  95. package/dist/docx/paragraphTraversal.js +47 -49
  96. package/dist/docx/parseWarningMessage.js +3 -0
  97. package/dist/docx/parserEnums.d.ts +6 -8
  98. package/dist/docx/parserEnums.js +4 -6
  99. package/dist/docx/preservedRunContent.js +16 -6
  100. package/dist/docx/previewBudget.d.ts +44 -23
  101. package/dist/docx/previewBudget.js +61 -30
  102. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  103. package/dist/docx/propertyElementAttributes.js +114 -0
  104. package/dist/docx/renderedPageBreakNormalization.js +2 -2
  105. package/dist/docx/rezip.d.ts +28 -2
  106. package/dist/docx/rezip.js +78 -9
  107. package/dist/docx/runConsolidator.d.ts +42 -2
  108. package/dist/docx/runConsolidator.js +60 -6
  109. package/dist/docx/runParser.d.ts +54 -18
  110. package/dist/docx/runParser.js +379 -295
  111. package/dist/docx/runPayload.d.ts +5 -0
  112. package/dist/docx/runPayload.js +4 -0
  113. package/dist/docx/sdtProperties.d.ts +39 -5
  114. package/dist/docx/sdtProperties.js +205 -84
  115. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  116. package/dist/docx/sdtPropertiesPatch.js +68 -112
  117. package/dist/docx/sectionParser.d.ts +1 -2
  118. package/dist/docx/sectionParser.js +236 -240
  119. package/dist/docx/selectiveSave.js +3 -2
  120. package/dist/docx/selectiveXmlPatch.d.ts +21 -2
  121. package/dist/docx/selectiveXmlPatch.js +195 -99
  122. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  123. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  124. package/dist/docx/serializer/borderSerializer.js +10 -8
  125. package/dist/docx/serializer/documentSerializer.js +3 -0
  126. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  127. package/dist/docx/serializer/headerFooterSerializer.js +3 -0
  128. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  129. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  130. package/dist/docx/serializer/noteSerializer.js +3 -0
  131. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  132. package/dist/docx/serializer/numberingSerializer.js +81 -79
  133. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  134. package/dist/docx/serializer/paragraphSerializer.js +88 -188
  135. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  136. package/dist/docx/serializer/runSerializer.js +109 -59
  137. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  138. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  139. package/dist/docx/serializer/sectionPropertiesSerializer.js +34 -45
  140. package/dist/docx/serializer/settingsSerializer.js +6 -4
  141. package/dist/docx/serializer/stylesSerializer.js +8 -11
  142. package/dist/docx/serializer/tableSerializer.js +268 -100
  143. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  144. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  145. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  146. package/dist/docx/serializer/xmlUtils.js +1 -1
  147. package/dist/docx/server/createBilingualDocument.js +18 -16
  148. package/dist/docx/server/migrateYjsAttrSchema.js +3 -3
  149. package/dist/docx/settingsParser.js +7 -4
  150. package/dist/docx/shadingParser.d.ts +2 -1
  151. package/dist/docx/shadingParser.js +43 -7
  152. package/dist/docx/shapeParser.js +8 -3
  153. package/dist/docx/strictNames.d.ts +11 -0
  154. package/dist/docx/strictNames.gen.d.ts +45 -0
  155. package/dist/docx/strictNames.gen.js +50 -0
  156. package/dist/docx/strictNames.js +43 -0
  157. package/dist/docx/strictValueEncodings.gen.js +133 -131
  158. package/dist/docx/styleParser.js +17 -349
  159. package/dist/docx/tableParser.d.ts +10 -1
  160. package/dist/docx/tableParser.js +505 -181
  161. package/dist/docx/textBoxParser.d.ts +3 -1
  162. package/dist/docx/textBoxParser.js +18 -8
  163. package/dist/docx/themeColorAttribute.d.ts +13 -0
  164. package/dist/docx/themeColorAttribute.js +24 -0
  165. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  166. package/dist/docx/vmlImageParser.d.ts +13 -4
  167. package/dist/docx/vmlImageParser.js +74 -31
  168. package/dist/docx/vmlPreview.js +2 -2
  169. package/dist/docx/wrapPolygon.d.ts +30 -0
  170. package/dist/docx/wrapPolygon.js +70 -0
  171. package/dist/docx/xmlParser.d.ts +14 -1
  172. package/dist/docx/xmlParser.js +18 -2
  173. package/dist/fonts/embeddedFonts.js +3 -3
  174. package/dist/headless-layout.js +2 -0
  175. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  176. package/dist/i18n/messages/catalogs.gen.js +102 -34
  177. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  178. package/dist/internal/headlessRevisionResolution.js +9 -0
  179. package/dist/internal/pageBreakRunSourceDescendantIndex.js +3 -1
  180. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  181. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  182. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  183. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  184. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  185. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  186. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  187. package/dist/layout-bridge/convert/toFlowBlocks.js +177 -101
  188. package/dist/layout-engine/index.d.ts +2 -2
  189. package/dist/layout-engine/index.js +53 -17
  190. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  191. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  192. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  193. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  194. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  195. package/dist/layout-engine/paragraphSequence.js +3 -2
  196. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  197. package/dist/layout-engine/section-breaks.d.ts +49 -2
  198. package/dist/layout-engine/section-breaks.js +55 -4
  199. package/dist/layout-engine/types.d.ts +47 -17
  200. package/dist/layout-engine/types.js +16 -1
  201. package/dist/layout-painter/borderStroke.d.ts +18 -4
  202. package/dist/layout-painter/renderPage.js +6 -4
  203. package/dist/layout-painter/renderParagraph.d.ts +2 -1
  204. package/dist/layout-painter/renderParagraph.js +13 -26
  205. package/dist/layout-painter/renderTable.d.ts +4 -1
  206. package/dist/layout-painter/renderTable.js +22 -22
  207. package/dist/layout-painter/renderTextBox.js +5 -3
  208. package/dist/markdown/renderBlock.js +3 -1
  209. package/dist/markdown/renderRuns.js +7 -2
  210. package/dist/markdown/renderTable.js +2 -1
  211. package/dist/model.d.ts +3 -3
  212. package/dist/model.js +2 -2
  213. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  214. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  215. package/dist/prosemirror/attrs/index.d.ts +22 -4
  216. package/dist/prosemirror/attrs/index.js +498 -60
  217. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  218. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  219. package/dist/prosemirror/commands/comments.js +68 -53
  220. package/dist/prosemirror/commands/contentControls.js +24 -19
  221. package/dist/prosemirror/commands/image.d.ts +1 -1
  222. package/dist/prosemirror/commands/image.js +4 -1
  223. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  224. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  225. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  226. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  227. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  228. package/dist/prosemirror/conversion/fromProseDoc.d.ts +18 -2
  229. package/dist/prosemirror/conversion/fromProseDoc.js +330 -183
  230. package/dist/prosemirror/conversion/index.d.ts +2 -2
  231. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  232. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  233. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  234. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  235. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  236. package/dist/prosemirror/conversion/toProseDoc.js +371 -141
  237. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  238. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  239. package/dist/prosemirror/extensions/StarterKit.js +8 -2
  240. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  241. package/dist/prosemirror/extensions/core/ParagraphExtension.js +19 -15
  242. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  243. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  244. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  245. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  246. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  247. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  248. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  249. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  250. package/dist/prosemirror/extensions/markRegistry.d.ts +26 -2
  251. package/dist/prosemirror/extensions/markRegistry.js +73 -10
  252. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +17 -3
  253. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  254. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  255. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  256. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  257. package/dist/prosemirror/extensions/marks/markUtils.js +2 -1
  258. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  259. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  260. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  261. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  262. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  263. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +10 -0
  264. package/dist/prosemirror/extensions/nodes/ImageExtension.js +8 -1
  265. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  266. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  267. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  268. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  269. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  270. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  271. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +4 -0
  272. package/dist/prosemirror/extensions/nodes/TableExtension.js +141 -123
  273. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +4 -0
  274. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  275. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  276. package/dist/prosemirror/extensions/types.d.ts +12 -3
  277. package/dist/prosemirror/index.d.ts +4 -2
  278. package/dist/prosemirror/index.js +2 -1
  279. package/dist/prosemirror/inlineWrapperStack.js +20 -3
  280. package/dist/prosemirror/listMarker.d.ts +2 -2
  281. package/dist/prosemirror/listMarker.js +7 -8
  282. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  283. package/dist/prosemirror/listState.d.ts +62 -0
  284. package/dist/prosemirror/listState.js +49 -0
  285. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  286. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  287. package/dist/prosemirror/numberedRefFields.js +4 -4
  288. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  289. package/dist/prosemirror/numberingAttr.js +74 -0
  290. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  291. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  292. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  293. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  294. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  295. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  296. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  297. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  298. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  299. package/dist/prosemirror/replacedAnnotations.js +24 -6
  300. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  301. package/dist/prosemirror/revisionCarriers.js +86 -60
  302. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -0
  303. package/dist/prosemirror/runFormattingInlineCarriers.js +2 -0
  304. package/dist/prosemirror/runIdentity.d.ts +28 -0
  305. package/dist/prosemirror/runIdentity.js +36 -0
  306. package/dist/prosemirror/runStyleFormatting.js +1 -1
  307. package/dist/prosemirror/schema/index.d.ts +2 -2
  308. package/dist/prosemirror/schema/marks.d.ts +23 -4
  309. package/dist/prosemirror/schema/nodes.d.ts +220 -24
  310. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  311. package/dist/prosemirror/sectionCarrier.js +40 -0
  312. package/dist/prosemirror/selectionState.d.ts +3 -0
  313. package/dist/prosemirror/selectionState.js +4 -1
  314. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  315. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  316. package/dist/prosemirror/tableResize.js +5 -6
  317. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +2 -0
  318. package/dist/prosemirror/trackedRunInlineAtoms.js +2 -0
  319. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  320. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  321. package/dist/prosemirror/validation.js +17 -6
  322. package/dist/prosemirror/yjsDocumentMetadata.d.ts +2 -2
  323. package/dist/prosemirror/yjsDocumentMetadata.js +428 -7
  324. package/dist/prosemirror/zeroWidthAnchors.js +4 -0
  325. package/dist/style-sets/extract.js +4 -4
  326. package/dist/style-sets/stellaStyle.js +36 -23
  327. package/dist/types/colors.d.ts +2 -2
  328. package/dist/types/content.d.ts +2 -2
  329. package/dist/types/documentEnumValues.d.ts +53 -26
  330. package/dist/types/documentEnumValues.js +72 -174
  331. package/dist/types/formatting.d.ts +2 -2
  332. package/dist/types/index.d.ts +9 -2
  333. package/dist/utils/borderCss.d.ts +246 -0
  334. package/dist/utils/borderCss.js +325 -0
  335. package/dist/utils/colorResolver.d.ts +4 -3
  336. package/dist/utils/colorResolver.js +45 -76
  337. package/dist/utils/createDocument.js +24 -6
  338. package/dist/utils/findReplace.js +52 -10
  339. package/dist/utils/formatToStyle.d.ts +84 -2
  340. package/dist/utils/formatToStyle.js +133 -52
  341. package/dist/utils/headingCollector.js +3 -2
  342. package/dist/utils/mergeDocumentContent.js +5 -3
  343. package/dist/utils/paragraphFormattingMerge.js +27 -6
  344. package/dist/utils/replaceText.js +1 -1
  345. package/dist/utils/tableOperations.d.ts +5 -3
  346. package/dist/utils/tableOperations.js +14 -1
  347. package/dist/utils/tablePlacement.d.ts +7 -0
  348. package/dist/utils/tablePlacement.js +14 -0
  349. package/dist/utils/textDirectionFlow.d.ts +15 -0
  350. package/dist/utils/textDirectionFlow.js +38 -0
  351. package/dist/utils/textFormattingMerge.js +16 -4
  352. package/package.json +10 -10
  353. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  354. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  355. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  356. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  357. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  358. package/dist/compare/__fixtures__/nested-table.js +0 -50
  359. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  360. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  361. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  362. package/dist/docx/bookmarkPlacement.js +0 -52
  363. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  364. package/dist/fonts/embeddedFontTable.js +0 -80
  365. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  366. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
@@ -6,19 +6,21 @@ import { partitionRunsAtPageBreaks } from "../../internal/pageBreakRunPartition.
6
6
  import { setHyperlinkInstanceIndex } from "../../layout-engine/measure/hyperlinkInstance.js";
7
7
  import { setParagraphFrame } from "../../layout-engine/paragraphFrame.js";
8
8
  import { setTextBoxGroupId } from "../../layout-engine/textBoxGroup.js";
9
- import { DEFAULT_TEXTBOX_MARGINS } from "../../layout-engine/types.js";
9
+ import { DEFAULT_TEXTBOX_MARGINS, isListNumPr } from "../../layout-engine/types.js";
10
10
  import { getPageNumbering } from "../../paged-layout/sectionGeometry.js";
11
11
  import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectInlineWrapperMarkAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectParagraphAttrs, expectPreservedXmlAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectSymbolAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../../prosemirror/attrs/index.js";
12
12
  import { autospacingMatchesBase } from "../../prosemirror/autospacingBase.js";
13
13
  import { runShadingAttrsToShading } from "../../prosemirror/conversion/runShadingMark.js";
14
14
  import { advanceListMarker, advanceVisibleListMarker, cloneListCounterState, formatCounter, resolveListTemplate } from "../../prosemirror/listMarker.js";
15
15
  import { resolveNumberedRefFields } from "../../prosemirror/numberedRefFields.js";
16
- import { directionToBidi } from "../../prosemirror/paragraphDirection.js";
16
+ import { directionIsRtl, directionToBidi } from "../../prosemirror/paragraphDirection.js";
17
17
  import { resolveEffectiveRunStyleFormatting } from "../../prosemirror/runStyleFormatting.js";
18
+ import { parseSectionBreakType } from "../../prosemirror/sectionCarrier.js";
18
19
  import { expectTextBoxAnchorAttrs } from "../../prosemirror/textBoxAnchorAttrs.js";
19
20
  import { assertValidProseMirrorDocument } from "../../prosemirror/validation.js";
20
21
  import { createStyleEngine } from "../../style-engine/styleEngine.js";
21
22
  import { normalizeShapeTextAnchor } from "../../types/documentEnumValues.js";
23
+ import { cssBorderStyle, cssBorderStyleOf } from "../../utils/borderCss.js";
22
24
  import { resolveColor, resolveHighlightToCss } from "../../utils/colorResolver.js";
23
25
  import { resolveThemeFont } from "../../utils/fontResolver.js";
24
26
  import { resolveShadingFill } from "../../utils/formatToStyle.js";
@@ -31,6 +33,7 @@ import { AUTO_PARAGRAPH_SPACING_PX, halfPointsToPixels, halfPointsToPoints, poin
31
33
  import { getColumns } from "../sectionColumns.js";
32
34
  import { groupParagraphFrames } from "./paragraphFrames.js";
33
35
  import { panic } from "better-result";
36
+ import { headingLevelOf, paragraphNumberingLevel, paragraphNumberingReferenceId, sameStatedParagraphNumbering, statesNoBorder } from "@stll/docx-core/model";
34
37
  //#region src/layout-bridge/convert/toFlowBlocks.ts
35
38
  const DETACHED_WATERMARK_HOST_ATTR = "_detachedWatermarkHost";
36
39
  const expectDetachedWatermarkHostAttr = (attrs) => {
@@ -39,7 +42,14 @@ const expectDetachedWatermarkHostAttr = (attrs) => {
39
42
  if (typeof value !== "boolean") panic("Invalid ProseMirror detached watermark host attrs:\nparagraph.attrs._detachedWatermarkHost: Expected a boolean.");
40
43
  return value;
41
44
  };
42
- const DEFAULT_FONT = "Calibri";
45
+ /**
46
+ * Word's layout fallback when an imported OOXML style hierarchy never supplies
47
+ * `w:sz`. ECMA-376 deliberately leaves that terminal fallback to the consumer;
48
+ * this value matches Word and is therefore applied by the DOCX composition
49
+ * roots, while standalone ProseMirror documents keep the layout engine's 11pt
50
+ * default.
51
+ */
52
+ const WORD_UNSPECIFIED_FONT_SIZE = 10;
43
53
  const TEXT_BOX_ANCHOR_BLOCK_ID = Symbol.for("stll.textBoxAnchorBlockId");
44
54
  const DEFAULT_TABLE_CELL_MARGIN_TWIPS = {
45
55
  top: 0,
@@ -72,7 +82,6 @@ function constrainImageToPage(width, height, pageContentHeight) {
72
82
  height: pageContentHeight
73
83
  };
74
84
  }
75
- const DEFAULT_SIZE = 11;
76
85
  /**
77
86
  * Convert twips to pixels (1 twip = 1/1440 inch, 1 inch = 96 CSS px).
78
87
  * No rounding — precision prevents cumulative layout drift across paragraphs.
@@ -141,31 +150,43 @@ const MARK_PAINT_DISPOSITIONS = {
141
150
  deletion: "runFormatting",
142
151
  inlineWrapper: "runFormatting",
143
152
  characterStyle: "resolvedElsewhere",
144
- pageBreakRunOwner: "notPainted",
153
+ runIdentity: "notPainted",
145
154
  runPropertyChange: "notPainted"
146
155
  };
147
156
  const markPaintDisposition = (name) => {
148
157
  return MARK_PAINT_DISPOSITIONS[name];
149
158
  };
150
159
  /**
151
- * The direction one bidirectional wrapper lays its content out in, as the
152
- * innermost layer of a stack states it.
160
+ * Whether a layer states how its content is laid out.
153
161
  *
154
- * Only the innermost is read: a wrapper inside another is the one whose
155
- * direction the text is laid out in, and the outer layers are what the save
156
- * leg rebuilds the nesting from.
162
+ * A smart tag and a custom-XML wrapper name an element in another vocabulary
163
+ * and say nothing about layout, so the painter draws the text exactly as it
164
+ * would without them. The `switch` is here rather than inline so a kind added
165
+ * to the model has to answer the question.
157
166
  */
158
- const innermostBidiWrapper = (stack) => {
159
- const layer = stack.at(-1);
160
- if (layer === void 0) return;
167
+ const paintedDirection = (layer) => {
161
168
  switch (layer.kind) {
162
169
  case "bidi": return layer.direction === void 0 ? { control: layer.control } : {
163
170
  control: layer.control,
164
171
  direction: layer.direction
165
172
  };
166
- default:
167
- layer.kind;
168
- return;
173
+ case "smartTag":
174
+ case "customXml": return;
175
+ default: return;
176
+ }
177
+ };
178
+ /**
179
+ * The direction the innermost bidirectional layer of a stack lays its content out in.
180
+ *
181
+ * Innermost wins: a bidirectional wrapper inside another is the one the text is
182
+ * laid out in, and the outer layers are what the save leg rebuilds the nesting
183
+ * from. The layers that state no direction are skipped rather than ending the
184
+ * search, so a smart tag inside a `w:dir` still reads right to left.
185
+ */
186
+ const innermostBidiWrapper = (stack) => {
187
+ for (const layer of stack.toReversed()) {
188
+ const direction = paintedDirection(layer);
189
+ if (direction !== void 0) return direction;
169
190
  }
170
191
  };
171
192
  /**
@@ -340,6 +361,7 @@ function extractRunFormatting(marks, theme, fontAlternates) {
340
361
  case "deletion": {
341
362
  const attrs = expectTrackedChangeMarkAttrs(mark);
342
363
  formatting.isDeletion = true;
364
+ if (attrs._historicalFormatting) formatting.usesHistoricalFormatting = true;
343
365
  formatting.changeAuthor = attrs.author;
344
366
  if (attrs.date !== void 0) formatting.changeDate = attrs.date;
345
367
  formatting.changeRevisionId = attrs.revisionId;
@@ -384,6 +406,7 @@ function markDefaultBlackTextColorSource(formatting, paraDefaults) {
384
406
  };
385
407
  }
386
408
  function mergeRunFormatting(paraDefaults, formatting) {
409
+ if (formatting.isDeletion && formatting.usesHistoricalFormatting) return formatting;
387
410
  const merged = {
388
411
  ...paraDefaults,
389
412
  ...markDefaultBlackTextColorSource(formatting, paraDefaults)
@@ -596,6 +619,7 @@ function buildImageRun(attrs, constrained, pmStart, pmEnd, trackedChange) {
596
619
  const run = {
597
620
  kind: "image",
598
621
  src: attrs.src,
622
+ ...attrs.preview ? { preview: attrs.preview } : {},
599
623
  width: constrained.width,
600
624
  height: constrained.height,
601
625
  pmStart,
@@ -620,9 +644,10 @@ function buildImageRun(attrs, constrained, pmStart, pmEnd, trackedChange) {
620
644
  if (attrs.cropLeft != null) run.cropLeft = attrs.cropLeft;
621
645
  if (attrs.borderWidth != null) run.borderWidth = attrs.borderWidth;
622
646
  if (attrs.borderColor) run.borderColor = attrs.borderColor;
623
- if (attrs.borderStyle) run.borderStyle = attrs.borderStyle;
647
+ const runBorderStyle = cssBorderStyleOf(attrs.borderStyle);
648
+ if (runBorderStyle) run.borderStyle = runBorderStyle;
624
649
  if (attrs.position !== void 0) run.position = attrs.position;
625
- if (attrs.layoutInCell !== void 0) run.layoutInCell = attrs.layoutInCell;
650
+ if (attrs.anchor?.layoutInCell !== void 0) run.layoutInCell = attrs.anchor.layoutInCell;
626
651
  if (trackedChange?.isInsertion) run.isInsertion = true;
627
652
  if (trackedChange?.isDeletion) run.isDeletion = true;
628
653
  if (trackedChange?.changeAuthor !== void 0) run.changeAuthor = trackedChange.changeAuthor;
@@ -632,7 +657,11 @@ function buildImageRun(attrs, constrained, pmStart, pmEnd, trackedChange) {
632
657
  }
633
658
  /** A package image whose bytes cannot paint still owns its authored line box. */
634
659
  const hasRelationshipBackedImageBox = (attrs) => typeof attrs.rId === "string" && attrs.rId.trim().length > 0 && typeof attrs.width === "number" && Number.isFinite(attrs.width) && attrs.width >= 0 && typeof attrs.height === "number" && Number.isFinite(attrs.height) && attrs.height >= 0;
635
- const hasPaintableImageSource = (src) => sanitizeImageSrc(src) !== void 0;
660
+ /**
661
+ * A preview counts as a source: the bytes are not in the attrs, but the
662
+ * display list can produce them without I/O when it interns the descriptor.
663
+ */
664
+ const hasPaintableImageSource = (attrs) => attrs.preview !== void 0 || sanitizeImageSrc(attrs.src) !== void 0;
636
665
  /**
637
666
  * In TOC paragraphs, strip the resolved Hyperlink character-style colour and
638
667
  * underline so the painter's link fallback doesn't fire. The PM doc keeps the
@@ -806,7 +835,7 @@ function paragraphToRuns(node, startPos, _options, pageBreaks) {
806
835
  }
807
836
  if (child.type.name === "image") {
808
837
  const attrs = expectImageAttrs(child);
809
- if (!hasPaintableImageSource(attrs.src) && !hasRelationshipBackedImageBox(attrs)) return;
838
+ if (!hasPaintableImageSource(attrs) && !hasRelationshipBackedImageBox(attrs)) return;
810
839
  const constrained = constrainImageToPage(attrs.width ?? 100, attrs.height ?? 100, _options.pageContentHeight);
811
840
  const trackedFmt = extractRunFormatting(effectiveMarks, theme, fontAlternates);
812
841
  const run = buildImageRun(attrs, constrained, childPos, childPos + child.nodeSize, trackedFmt);
@@ -885,6 +914,20 @@ function paragraphToRuns(node, startPos, _options, pageBreaks) {
885
914
  node.forEach((child, childOffset) => {
886
915
  pushRunsForChild(child, offset + childOffset);
887
916
  });
917
+ const { defaultFont, defaultSize } = _options;
918
+ if (defaultFont !== void 0 || defaultSize !== void 0) for (const run of runs) switch (run.kind) {
919
+ case "text":
920
+ case "tab":
921
+ case "renderedPageBreak":
922
+ case "field":
923
+ case "math":
924
+ if (defaultFont !== void 0) run.fontFamily ??= defaultFont;
925
+ if (defaultSize !== void 0) run.fontSize ??= defaultSize;
926
+ break;
927
+ case "image":
928
+ case "lineBreak": break;
929
+ default:
930
+ }
888
931
  return runs;
889
932
  }
890
933
  function toListMarkerRevision(kind, info) {
@@ -904,13 +947,7 @@ function isRemovedNumberingChange(change) {
904
947
  }
905
948
  function isChangedNumberingChange(currentNumPr, change) {
906
949
  const previousFormatting = change.previousFormatting;
907
- return previousFormatting != null && Object.hasOwn(previousFormatting, "numPr") && isListNumPr(previousFormatting.numPr) && !areListNumPrEqual(previousFormatting.numPr, currentNumPr);
908
- }
909
- function areListNumPrEqual(left, right) {
910
- return left.numId === right.numId && left.ilvl === right.ilvl;
911
- }
912
- function isListNumPr(value) {
913
- return value !== void 0 && value !== null;
950
+ return previousFormatting != null && Object.hasOwn(previousFormatting, "numPr") && isListNumPr(previousFormatting.numPr) && !sameStatedParagraphNumbering(previousFormatting.numPr, currentNumPr);
914
951
  }
915
952
  function toPreviousListAttrs(previousFormatting) {
916
953
  const attrs = {};
@@ -971,7 +1008,20 @@ function applyDeletedListMarkerAttrs(attrs, change, listCounterState, theme, fon
971
1008
  if (previousListAttrs.listMarkerAlignment) attrs.listMarkerAlignment = previousListAttrs.listMarkerAlignment;
972
1009
  if (previousListAttrs.listMarkerSuffix) attrs.listMarkerSuffix = previousListAttrs.listMarkerSuffix;
973
1010
  }
1011
+ /**
1012
+ * Every `ST_Jc` member, and the flow alignment that paints it.
1013
+ *
1014
+ * `start` and `end` stay unresolved here: they name an edge of the writing
1015
+ * direction, not a side of the page, so which of `left` and `right` paints
1016
+ * them depends on the paragraph's direction. `numTab` has no flow alignment at
1017
+ * all — it aligns the paragraph to the list number's tab stop, which the flow
1018
+ * engine does not model — so it falls back to the start edge, which is where a
1019
+ * numbered paragraph without one sits.
1020
+ */
974
1021
  const FLOW_ALIGNMENT_BY_PARAGRAPH_ALIGNMENT = {
1022
+ start: "start",
1023
+ end: "end",
1024
+ numTab: "start",
975
1025
  left: "left",
976
1026
  center: "center",
977
1027
  right: "right",
@@ -982,10 +1032,19 @@ const FLOW_ALIGNMENT_BY_PARAGRAPH_ALIGNMENT = {
982
1032
  lowKashida: "justify",
983
1033
  thaiDistribute: "justify"
984
1034
  };
1035
+ /** Resolve a logical alignment against the direction the paragraph runs in. */
1036
+ const resolveFlowAlignment = (alignment, rightToLeft) => {
1037
+ const flow = FLOW_ALIGNMENT_BY_PARAGRAPH_ALIGNMENT[alignment];
1038
+ switch (flow) {
1039
+ case "start": return rightToLeft ? "right" : "left";
1040
+ case "end": return rightToLeft ? "left" : "right";
1041
+ default: return flow;
1042
+ }
1043
+ };
985
1044
  function convertParagraphAttrs(pmAttrs, { theme, fontAlternates, listCounterStreams, defaultTabStopTwips }) {
986
1045
  const attrs = {};
987
- if (pmAttrs.alignment) attrs.alignment = FLOW_ALIGNMENT_BY_PARAGRAPH_ALIGNMENT[pmAttrs.alignment];
988
- if (typeof pmAttrs.outlineLevel === "number") attrs.outlineLevel = pmAttrs.outlineLevel;
1046
+ if (pmAttrs.alignment) attrs.alignment = resolveFlowAlignment(pmAttrs.alignment, directionIsRtl(pmAttrs.direction));
1047
+ if (pmAttrs.outlineLevel !== void 0) attrs.outlineLevel = pmAttrs.outlineLevel;
989
1048
  const spaceBefore = pmAttrs.spaceBefore;
990
1049
  const spaceAfter = pmAttrs.spaceAfter;
991
1050
  const lineSpacing = pmAttrs.lineSpacing;
@@ -1022,8 +1081,8 @@ function convertParagraphAttrs(pmAttrs, { theme, fontAlternates, listCounterStre
1022
1081
  let indentLeft = typeof pmAttrs.indentLeft === "number" ? pmAttrs.indentLeft : void 0;
1023
1082
  let indentFirstLine = typeof pmAttrs.indentFirstLine === "number" ? pmAttrs.indentFirstLine : void 0;
1024
1083
  let hangingIndent = pmAttrs.hangingIndent;
1025
- if (pmAttrs.numPr?.numId && indentLeft === void 0 && indentFirstLine === void 0) {
1026
- indentLeft = ((pmAttrs.numPr.ilvl ?? 0) + 1) * 720;
1084
+ if (paragraphNumberingReferenceId(pmAttrs.numPr) !== void 0 && indentLeft === void 0 && indentFirstLine === void 0) {
1085
+ indentLeft = ((paragraphNumberingLevel(pmAttrs.numPr) ?? 0) + 1) * 720;
1027
1086
  if (indentFirstLine === void 0) {
1028
1087
  indentFirstLine = -360;
1029
1088
  hangingIndent = true;
@@ -1057,14 +1116,17 @@ function convertParagraphAttrs(pmAttrs, { theme, fontAlternates, listCounterStre
1057
1116
  }
1058
1117
  const shadingRgb = pmAttrs.shading?.fill?.rgb?.toUpperCase();
1059
1118
  if (shadingRgb && shadingRgb !== "FFFFFF" && shadingRgb !== "FFFFFE") attrs.shading = `#${pmAttrs.shading?.fill?.rgb}`;
1060
- if (pmAttrs.tabs && pmAttrs.tabs.length > 0) attrs.tabs = pmAttrs.tabs.map((tab) => {
1061
- const tabStop = {
1062
- val: mapTabAlignment(tab.alignment),
1063
- pos: tab.position
1064
- };
1065
- if (tab.leader) tabStop.leader = tab.leader;
1066
- return tabStop;
1067
- });
1119
+ if (pmAttrs.tabs && pmAttrs.tabs.length > 0) {
1120
+ const rightToLeft = directionIsRtl(pmAttrs.direction);
1121
+ attrs.tabs = pmAttrs.tabs.map((tab) => {
1122
+ const tabStop = {
1123
+ val: resolveTabAlignment(tab.alignment, rightToLeft),
1124
+ pos: tab.position
1125
+ };
1126
+ if (tab.leader) tabStop.leader = tab.leader;
1127
+ return tabStop;
1128
+ });
1129
+ }
1068
1130
  if (pmAttrs.pageBreakBefore) attrs.pageBreakBefore = true;
1069
1131
  if (pmAttrs.kinsoku !== void 0 && pmAttrs.kinsoku !== null) attrs.kinsoku = pmAttrs.kinsoku;
1070
1132
  if (pmAttrs.overflowPunctuation !== void 0 && pmAttrs.overflowPunctuation !== null) attrs.overflowPunctuation = pmAttrs.overflowPunctuation;
@@ -1081,10 +1143,7 @@ function convertParagraphAttrs(pmAttrs, { theme, fontAlternates, listCounterStre
1081
1143
  const propertyChanges = pmAttrs._propertyChanges ?? [];
1082
1144
  let changedNumberingChange;
1083
1145
  if (pmAttrs.numPr) {
1084
- const numPr = {};
1085
- if (pmAttrs.numPr.numId !== void 0) numPr.numId = pmAttrs.numPr.numId;
1086
- if (pmAttrs.numPr.ilvl !== void 0) numPr.ilvl = pmAttrs.numPr.ilvl;
1087
- attrs.numPr = numPr;
1146
+ attrs.numPr = pmAttrs.numPr;
1088
1147
  if (pmAttrs.pPrMark?.kind === "del") attrs.listMarkerRevision = toListMarkerRevision("del", pmAttrs.pPrMark.info);
1089
1148
  else if (pmAttrs.pPrMark?.kind === "ins") attrs.listMarkerRevision = toListMarkerRevision("ins", pmAttrs.pPrMark.info);
1090
1149
  else {
@@ -1131,20 +1190,35 @@ function convertParagraphAttrs(pmAttrs, { theme, fontAlternates, listCounterStre
1131
1190
  return attrs;
1132
1191
  }
1133
1192
  /**
1134
- * Map document TabStopAlignment to layout engine TabAlignment
1193
+ * Every `ST_TabJc` member, and the layout engine's name for it.
1194
+ *
1195
+ * The engine's `start` and `end` are its names for the left and right edges of
1196
+ * the line, not direction-aware ones, so `w:tab w:val="left"` maps to `start`
1197
+ * unconditionally. `ST_TabJc`'s own `start` and `end` *are* direction-aware
1198
+ * and stay unresolved here, under names the engine has no member for.
1199
+ * `num`, the tab a numbered paragraph's text hangs from, has no engine
1200
+ * alignment of its own and falls back to the line's start edge.
1135
1201
  */
1136
- function mapTabAlignment(align) {
1137
- switch (align) {
1138
- case "left": return "start";
1139
- case "right": return "end";
1140
- case "center": return "center";
1141
- case "decimal": return "decimal";
1142
- case "bar": return "bar";
1143
- case "clear": return "clear";
1144
- case "num": return "start";
1145
- default: return "start";
1202
+ const TAB_ALIGNMENT_BY_TAB_STOP_ALIGNMENT = {
1203
+ start: "logicalStart",
1204
+ end: "logicalEnd",
1205
+ num: "logicalStart",
1206
+ left: "start",
1207
+ right: "end",
1208
+ center: "center",
1209
+ decimal: "decimal",
1210
+ bar: "bar",
1211
+ clear: "clear"
1212
+ };
1213
+ /** Resolve a logical tab alignment against the direction the paragraph runs in. */
1214
+ const resolveTabAlignment = (alignment, rightToLeft) => {
1215
+ const mapped = TAB_ALIGNMENT_BY_TAB_STOP_ALIGNMENT[alignment];
1216
+ switch (mapped) {
1217
+ case "logicalStart": return rightToLeft ? "end" : "start";
1218
+ case "logicalEnd": return rightToLeft ? "start" : "end";
1219
+ default: return mapped;
1146
1220
  }
1147
- }
1221
+ };
1148
1222
  /**
1149
1223
  * Convert a paragraph node to a ParagraphBlock.
1150
1224
  */
@@ -1166,6 +1240,8 @@ function convertParagraph(node, startPos, options, pageBreaks) {
1166
1240
  listCounterStreams: options.listCounterStreams,
1167
1241
  defaultTabStopTwips: options.defaultTabStopTwips
1168
1242
  });
1243
+ if (options.defaultFont !== void 0) attrs.defaultFontFamily ??= options.defaultFont;
1244
+ if (options.defaultSize !== void 0) attrs.defaultFontSize ??= options.defaultSize;
1169
1245
  if (options.lineBreakRules) attrs.lineBreakRules = options.lineBreakRules;
1170
1246
  if (options.justificationCompatibility) attrs.justificationCompatibility = options.justificationCompatibility;
1171
1247
  if (options.automaticHyphenation) attrs.automaticHyphenation = options.automaticHyphenation;
@@ -1370,7 +1446,7 @@ function suppressFinalParagraphInRepeatedEmptySuffix(blocks) {
1370
1446
  }
1371
1447
  function reserveLeadingEmptyOutlineHeight(blocks) {
1372
1448
  const firstBlock = blocks.at(0);
1373
- if (firstBlock?.kind !== "paragraph" || firstBlock.runs.length !== 0 || firstBlock.attrs?.outlineLevel !== 0) return;
1449
+ if (firstBlock?.kind !== "paragraph" || firstBlock.runs.length !== 0 || headingLevelOf(firstBlock.attrs?.outlineLevel) !== 0) return;
1374
1450
  firstBlock.attrs = {
1375
1451
  ...firstBlock.attrs,
1376
1452
  reserveEmptyOutlineHeight: true
@@ -1383,31 +1459,14 @@ function reserveLeadingEmptyOutlineHeight(blocks) {
1383
1459
  function borderWidthToPixels(eighthsOfPoint) {
1384
1460
  return pointsToPixels(eighthsOfPoint / 8);
1385
1461
  }
1386
- const OOXML_TO_CSS_BORDER = {
1387
- single: "solid",
1388
- double: "double",
1389
- dotted: "dotted",
1390
- dashed: "dashed",
1391
- thick: "solid",
1392
- dashSmallGap: "dashed",
1393
- dotDash: "dashed",
1394
- dotDotDash: "dotted",
1395
- triple: "double",
1396
- wave: "solid",
1397
- doubleWave: "double",
1398
- threeDEmboss: "ridge",
1399
- threeDEngrave: "groove",
1400
- outset: "outset",
1401
- inset: "inset"
1402
- };
1403
1462
  /**
1404
1463
  * Convert an OOXML BorderSpec to a layout-engine BorderStyle.
1405
1464
  * Shared by paragraph borders, cell borders, and header/footer borders.
1406
1465
  */
1407
1466
  function convertBorderSpecToLayout(border, theme) {
1408
- if (!border.style || border.style === "none" || border.style === "nil") return;
1467
+ if (border.style === void 0 || statesNoBorder(border.style)) return;
1409
1468
  const result = {
1410
- style: OOXML_TO_CSS_BORDER[border.style] || "solid",
1469
+ style: cssBorderStyle(border.style),
1411
1470
  width: border.size === void 0 ? 1 : borderWidthToPixels(border.size),
1412
1471
  color: border.color ? resolveColor(border.color, theme) : "#000000"
1413
1472
  };
@@ -1507,17 +1566,34 @@ function convertTableCell(node, startPos, options, tableCellMargins) {
1507
1566
  };
1508
1567
  }
1509
1568
  /**
1510
- * Convert a table row node.
1569
+ * Resolve an `ST_JcTable` placement to the flow engine's logical alignment.
1570
+ *
1571
+ * `start` and `end` name an edge of the writing direction, not a side of the
1572
+ * page, the same distinction `ST_Jc` draws for a paragraph. The flow engine
1573
+ * applies `w:bidiVisual` when it resolves that logical alignment to a physical
1574
+ * side, so the bridge must not mirror it first.
1511
1575
  */
1512
- function convertTableRow(node, startPos, options, tableCellMargins) {
1576
+ const resolveTablePlacement = (placement) => {
1577
+ switch (placement) {
1578
+ case "start": return "left";
1579
+ case "end": return "right";
1580
+ case "left":
1581
+ case "center":
1582
+ case "right": return placement;
1583
+ default: return placement;
1584
+ }
1585
+ };
1586
+ function convertTableRow(node, startPos, options, { cellMargins }) {
1513
1587
  const cells = [];
1514
1588
  let offset = startPos + 1;
1515
1589
  let breakBefore;
1516
1590
  node.forEach((child) => {
1517
1591
  if (child.type.name === "tableCell" || child.type.name === "tableHeader") {
1518
- const converted = convertTableCell(child, offset, options, tableCellMargins);
1519
- if (converted.breakBefore !== void 0) breakBefore = converted.breakBefore;
1520
- cells.push(converted.cell);
1592
+ if (!expectTableCellAttrs(child)._omittedGridSlot) {
1593
+ const converted = convertTableCell(child, offset, options, cellMargins);
1594
+ if (converted.breakBefore !== void 0) breakBefore = converted.breakBefore;
1595
+ cells.push(converted.cell);
1596
+ }
1521
1597
  }
1522
1598
  offset += child.nodeSize;
1523
1599
  });
@@ -1535,7 +1611,7 @@ function convertTableRow(node, startPos, options, tableCellMargins) {
1535
1611
  if (breakBefore !== void 0) row.breakBefore = breakBefore;
1536
1612
  if (attrs.hidden) row.hidden = attrs.hidden;
1537
1613
  const effectiveJustification = attrs._originalFormatting?.justification ?? attrs._resolvedJustification;
1538
- if (effectiveJustification) row.justification = effectiveJustification;
1614
+ if (effectiveJustification) row.justification = resolveTablePlacement(effectiveJustification);
1539
1615
  return row;
1540
1616
  }
1541
1617
  /**
@@ -1545,9 +1621,10 @@ function convertTable(node, startPos, options) {
1545
1621
  const rows = [];
1546
1622
  let offset = startPos + 1;
1547
1623
  const attrs = expectTableAttrs(node);
1548
- const tableCellMargins = attrs.cellMargins;
1624
+ const rightToLeft = (attrs._resolvedBidi ?? attrs._originalFormatting?.bidi) === true;
1625
+ const rowContext = { ...attrs.cellMargins === void 0 ? {} : { cellMargins: attrs.cellMargins } };
1549
1626
  node.forEach((child) => {
1550
- if (child.type.name === "tableRow") rows.push(convertTableRow(child, offset, options, tableCellMargins));
1627
+ if (child.type.name === "tableRow") rows.push(convertTableRow(child, offset, options, rowContext));
1551
1628
  offset += child.nodeSize;
1552
1629
  });
1553
1630
  let columnWidths = attrs.columnWidths?.map(twipsToPixels);
@@ -1557,7 +1634,8 @@ function convertTable(node, startPos, options) {
1557
1634
  const cellWidths = rows[0].cells.map((cell) => cell.width);
1558
1635
  if (cellWidths.every((w) => w !== void 0 && w > 0)) columnWidths = cellWidths;
1559
1636
  }
1560
- const justification = attrs.justification ?? attrs._resolvedJustification;
1637
+ const authoredJustification = attrs.justification ?? attrs._resolvedJustification;
1638
+ const justification = authoredJustification === void 0 ? void 0 : resolveTablePlacement(authoredJustification);
1561
1639
  const originalFormatting = attrs._originalFormatting;
1562
1640
  const effectiveIndent = attrs._resolvedIndent ?? originalFormatting?.indent;
1563
1641
  const indentPx = effectiveIndent?.value !== void 0 && effectiveIndent?.type === "dxa" ? twipsToPixels(effectiveIndent.value) : void 0;
@@ -1593,7 +1671,7 @@ function convertTable(node, startPos, options) {
1593
1671
  if (indentPx !== void 0) tableBlock.indent = indentPx;
1594
1672
  if (options.tableIndentCompatibility && !dropsAuthoredIndent) tableBlock.indentCompatibility = options.tableIndentCompatibility;
1595
1673
  if (floatingPx) tableBlock.floating = floatingPx;
1596
- if (attrs._resolvedBidi ?? originalFormatting?.bidi) tableBlock.bidi = true;
1674
+ if (rightToLeft) tableBlock.bidi = true;
1597
1675
  return tableBlock;
1598
1676
  }
1599
1677
  /**
@@ -1601,7 +1679,7 @@ function convertTable(node, startPos, options) {
1601
1679
  */
1602
1680
  function convertImage(node, startPos, pageContentHeight) {
1603
1681
  const attrs = expectImageAttrs(node);
1604
- if (!hasPaintableImageSource(attrs.src) && !hasRelationshipBackedImageBox(attrs)) return;
1682
+ if (!hasPaintableImageSource(attrs) && !hasRelationshipBackedImageBox(attrs)) return;
1605
1683
  const wrapType = attrs.wrapType;
1606
1684
  const shouldAnchor = wrapType === "behind" || wrapType === "inFront";
1607
1685
  const constrained = constrainImageToPage(attrs.width ?? 100, attrs.height ?? 100, pageContentHeight);
@@ -1609,6 +1687,7 @@ function convertImage(node, startPos, pageContentHeight) {
1609
1687
  kind: "image",
1610
1688
  id: nextBlockId(),
1611
1689
  src: attrs.src,
1690
+ ...attrs.preview ? { preview: attrs.preview } : {},
1612
1691
  width: constrained.width,
1613
1692
  height: constrained.height,
1614
1693
  pmStart: startPos,
@@ -1635,7 +1714,8 @@ function convertImage(node, startPos, pageContentHeight) {
1635
1714
  if (attrs.cropLeft != null) imgBlock.cropLeft = attrs.cropLeft;
1636
1715
  if (attrs.borderWidth != null) imgBlock.borderWidth = attrs.borderWidth;
1637
1716
  if (attrs.borderColor) imgBlock.borderColor = attrs.borderColor;
1638
- if (attrs.borderStyle) imgBlock.borderStyle = attrs.borderStyle;
1717
+ const imageBorderStyle = cssBorderStyleOf(attrs.borderStyle);
1718
+ if (imageBorderStyle) imgBlock.borderStyle = imageBorderStyle;
1639
1719
  return imgBlock;
1640
1720
  }
1641
1721
  /** Convert a textBox PM node to a TextBoxBlock. */
@@ -1744,15 +1824,13 @@ function coalesceTrailingPageBreakBeforeContinuousSection(blocks, splitPageBreak
1744
1824
  }
1745
1825
  return result;
1746
1826
  }
1827
+ /**
1828
+ * The last section's start mode, off a document attribute the schema types as
1829
+ * `any`. `parseSectionBreakType` owns the enumeration, so a member added to
1830
+ * `ST_SectionMark` reaches the paginator instead of being dropped here.
1831
+ */
1747
1832
  function readFinalSectionStart(doc) {
1748
- const sectionStart = doc.attrs["_finalSectionStart"];
1749
- switch (sectionStart) {
1750
- case "continuous":
1751
- case "nextPage":
1752
- case "oddPage":
1753
- case "evenPage": return sectionStart;
1754
- default: return;
1755
- }
1833
+ return parseSectionBreakType(doc.attrs["_finalSectionStart"]) ?? void 0;
1756
1834
  }
1757
1835
  /**
1758
1836
  * Convert a ProseMirror document to FlowBlock array.
@@ -1794,8 +1872,6 @@ function toFlowBlocks(doc, options = {}) {
1794
1872
  const { firstPageBreakRunPosition } = buildPageBreakRunDescendantIndex(doc);
1795
1873
  const opts = {
1796
1874
  ...options,
1797
- defaultFont: options.defaultFont ?? DEFAULT_FONT,
1798
- defaultSize: options.defaultSize ?? DEFAULT_SIZE,
1799
1875
  listCounters: listCounterState.counters,
1800
1876
  listAbstractCounters: listCounterState.abstractCounters,
1801
1877
  listSeenNumIds: listCounterState.seenLevels,
@@ -1855,7 +1931,7 @@ function toFlowBlocks(doc, options = {}) {
1855
1931
  const child = parent.child(index);
1856
1932
  const next = index + 1 < parent.childCount ? parent.child(index + 1) : void 0;
1857
1933
  const paragraphAttrs = child.type.name === "paragraph" ? expectParagraphAttrs(child) : void 0;
1858
- if (paragraphAttrs && next?.type.name === "pageBreak" && paragraphAttrs._trailingPageBreak === true && (paragraphAttrs._sectionProperties || paragraphAttrs.sectionBreakType)) {
1934
+ if (paragraphAttrs && next?.type.name === "pageBreak" && paragraphAttrs._trailingPageBreak === true && paragraphAttrs._sectionProperties !== void 0) {
1859
1935
  trailingPageBreakSectionPositions.add(childStart);
1860
1936
  consumedPageBreakPositions.add(childStart + child.nodeSize);
1861
1937
  }
@@ -1924,7 +2000,7 @@ function toFlowBlocks(doc, options = {}) {
1924
2000
  case "paragraph": {
1925
2001
  const pmAttrs = expectParagraphAttrs(node);
1926
2002
  const secProps = pmAttrs._sectionProperties;
1927
- const hasSectionBreak = secProps !== void 0 || pmAttrs.sectionBreakType !== null && pmAttrs.sectionBreakType !== void 0;
2003
+ const hasSectionBreak = secProps !== void 0;
1928
2004
  const hasListFormatting = pmAttrs.numPr !== null && pmAttrs.numPr !== void 0 || pmAttrs.listMarker !== null && pmAttrs.listMarker !== void 0;
1929
2005
  const firstChild = node.firstChild;
1930
2006
  const startsWithColumnBreak = firstChild?.type.name === "hardBreak" && expectHardBreakAttrs(firstChild).breakType === "column";
@@ -1987,7 +2063,7 @@ function toFlowBlocks(doc, options = {}) {
1987
2063
  kind: "sectionBreak",
1988
2064
  id: nextBlockId()
1989
2065
  };
1990
- const breakType = secProps?.sectionStart ?? pmAttrs.sectionBreakType;
2066
+ const breakType = secProps?.sectionStart;
1991
2067
  if (breakType) sectionBreak.type = breakType;
1992
2068
  if (secProps) {
1993
2069
  sectionBreak.pageNumbering = getPageNumbering(secProps);
@@ -2158,4 +2234,4 @@ function mergeRunInParagraphs(blocks) {
2158
2234
  return out;
2159
2235
  }
2160
2236
  //#endregion
2161
- export { convertBorderSpecToLayout, formatCounter, resetBlockIdCounter, resolveListTemplate, toFlowBlocks };
2237
+ export { WORD_UNSPECIFIED_FONT_SIZE, convertBorderSpecToLayout, formatCounter, resetBlockIdCounter, resolveListTemplate, toFlowBlocks };
@@ -1,4 +1,4 @@
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, ListMarkerFormatting, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionPageNumbering, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getTableRowLeadingWidth, isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImageRun, resolveTableCellPadding, resolveTableWidthPx, 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, ListMarkerFormatting, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionPageNumbering, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getTableRowLeadingWidth, isFloatingImageRun, isFloatingTextBoxBlock, isListNumPr, isTextWrappingFloatingImageRun, resolveTableCellPadding, resolveTableWidthPx, 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
4
  import { resolveSectionHeaderFooterRefs } from "./headerFooterRefs.js";
@@ -42,4 +42,4 @@ declare function layoutDocument(blocks: FlowBlock[], measures: Measure[], option
42
42
  */
43
43
  declare function getHeaderRowsHeight(measure: TableMeasure, headerRowCount: number): number;
44
44
  //#endregion
45
- 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, ListMarkerFormatting, ListNumPr, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionLayoutConfig, SectionPageNumbering, 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, resolveTableCellPadding, resolveTableWidthPx, scheduleSectionBreak, tableColumnsArePinned };
45
+ 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, ListMarkerFormatting, MathRun, Measure, MeasuredLine, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionLayoutConfig, SectionPageNumbering, 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, isListNumPr, isTextWrappingFloatingImageRun, layoutDocument, resolveSectionHeaderFooterRefs, resolveTableCellPadding, resolveTableWidthPx, scheduleSectionBreak, tableColumnsArePinned };