@stll/folio-core 0.46.0 → 0.47.1

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 (370) hide show
  1. package/dist/ai-edits/apply.d.ts +17 -1
  2. package/dist/ai-edits/apply.js +31 -27
  3. package/dist/ai-edits/headless.d.ts +9 -2
  4. package/dist/ai-edits/headless.js +5 -3
  5. package/dist/ai-edits/read.d.ts +1 -0
  6. package/dist/ai-edits/read.js +1 -0
  7. package/dist/ai-edits/snapshot.js +32 -27
  8. package/dist/ai-edits/table-cell-mutations.js +15 -7
  9. package/dist/ai-edits/table-geometry.js +21 -18
  10. package/dist/ai-edits/table-template.js +2 -2
  11. package/dist/compare/compare.js +2 -1
  12. package/dist/compare/content-alignment.js +192 -46
  13. package/dist/compare/content-types.d.ts +8 -2
  14. package/dist/compare/content.js +2 -11
  15. package/dist/compare/plan.js +7 -4
  16. package/dist/compare/section-boundary-properties.js +1 -2
  17. package/dist/content-controls/checkboxDisplay.d.ts +8 -2
  18. package/dist/content-controls/checkboxDisplay.js +11 -5
  19. package/dist/content-controls/mutateContentControls.js +41 -42
  20. package/dist/controller/layoutPipeline.js +8 -3
  21. package/dist/display-list/build/buildDisplayList.js +7 -7
  22. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  23. package/dist/display-list/build/imagePrimitives.js +38 -20
  24. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  25. package/dist/display-list/build/paragraphPrimitives.js +93 -13
  26. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  27. package/dist/display-list/build/previewPrimitives.js +89 -0
  28. package/dist/display-list/build/strokes.d.ts +177 -8
  29. package/dist/display-list/build/strokes.js +167 -47
  30. package/dist/display-list/build/tablePrimitives.js +4 -2
  31. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  32. package/dist/display-list/build/textDecorations.d.ts +15 -1
  33. package/dist/display-list/build/textDecorations.js +15 -1
  34. package/dist/display-list/dom/renderDisplayListToDom.js +1 -19
  35. package/dist/display-list/primitives.d.ts +13 -2
  36. package/dist/display-list/primitives.js +36 -1
  37. package/dist/document-operations.d.ts +9 -2
  38. package/dist/document-operations.js +5 -3
  39. package/dist/docx/attributeRemainder.d.ts +34 -1
  40. package/dist/docx/attributeRemainder.js +49 -3
  41. package/dist/docx/blockContentParser.d.ts +2 -0
  42. package/dist/docx/blockContentParser.js +39 -67
  43. package/dist/docx/blockPlainText.js +3 -1
  44. package/dist/docx/borderParser.js +26 -11
  45. package/dist/docx/builtInStyles.d.ts +8 -16
  46. package/dist/docx/builtInStyles.js +54 -17
  47. package/dist/docx/commentAnchorIndex.js +1 -1
  48. package/dist/docx/commentParser.js +3 -3
  49. package/dist/docx/commentRangeIntegrity.js +1 -1
  50. package/dist/docx/commentRangeJoin.js +1 -1
  51. package/dist/docx/commentReferenceNormalization.js +3 -2
  52. package/dist/docx/commentReplyMarkers.js +1 -1
  53. package/dist/docx/compatibility.js +56 -42
  54. package/dist/docx/containerChildren.d.ts +110 -13
  55. package/dist/docx/containerChildren.gen.d.ts +16 -1
  56. package/dist/docx/containerChildren.gen.js +18 -1
  57. package/dist/docx/containerChildren.js +63 -13
  58. package/dist/docx/diagramPreview.d.ts +14 -2
  59. package/dist/docx/diagramPreview.js +81 -169
  60. package/dist/docx/documentParser.js +4 -1
  61. package/dist/docx/drawingAnchor.d.ts +87 -0
  62. package/dist/docx/drawingAnchor.js +201 -0
  63. package/dist/docx/drawingUtils.d.ts +43 -38
  64. package/dist/docx/drawingUtils.js +205 -118
  65. package/dist/docx/fontTableParser.js +102 -41
  66. package/dist/docx/footnoteParser.js +10 -6
  67. package/dist/docx/groupDrawingParser.js +4 -3
  68. package/dist/docx/headerFooterReferenceNormalization.js +1 -1
  69. package/dist/docx/hyperlinkParser.d.ts +45 -7
  70. package/dist/docx/hyperlinkParser.js +126 -57
  71. package/dist/docx/imageParser.js +127 -107
  72. package/dist/docx/index.d.ts +2 -1
  73. package/dist/docx/index.js +2 -1
  74. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  75. package/dist/docx/inlineContentRemovals.js +46 -0
  76. package/dist/docx/inlineWrapperContent.d.ts +84 -3
  77. package/dist/docx/inlineWrapperContent.js +85 -4
  78. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  79. package/dist/docx/inlineWrapperParser.js +60 -0
  80. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  81. package/dist/docx/normalizeBaseDirection.js +4 -2
  82. package/dist/docx/numberingParser.d.ts +25 -2
  83. package/dist/docx/numberingParser.js +264 -361
  84. package/dist/docx/numberingReference.d.ts +9 -16
  85. package/dist/docx/numberingReference.js +17 -16
  86. package/dist/docx/numberingReferenceNormalization.js +7 -7
  87. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  88. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  89. package/dist/docx/paraIdAttribute.d.ts +91 -1
  90. package/dist/docx/paraIdAttribute.js +79 -1
  91. package/dist/docx/paragraphParser.d.ts +9 -24
  92. package/dist/docx/paragraphParser.js +212 -396
  93. package/dist/docx/paragraphProperties.d.ts +23 -0
  94. package/dist/docx/paragraphProperties.js +279 -0
  95. package/dist/docx/paragraphPropertySource.js +2 -0
  96. package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
  97. package/dist/docx/paragraphTextBoxEnrichment.js +14 -7
  98. package/dist/docx/paragraphTraversal.d.ts +14 -10
  99. package/dist/docx/paragraphTraversal.js +47 -49
  100. package/dist/docx/parseWarningMessage.js +3 -0
  101. package/dist/docx/parserEnums.d.ts +6 -8
  102. package/dist/docx/parserEnums.js +4 -6
  103. package/dist/docx/preservedRunContent.js +16 -6
  104. package/dist/docx/previewBudget.d.ts +44 -23
  105. package/dist/docx/previewBudget.js +61 -30
  106. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  107. package/dist/docx/propertyElementAttributes.js +114 -0
  108. package/dist/docx/renderedPageBreakNormalization.js +2 -2
  109. package/dist/docx/rezip.d.ts +28 -2
  110. package/dist/docx/rezip.js +78 -9
  111. package/dist/docx/runConsolidator.d.ts +42 -2
  112. package/dist/docx/runConsolidator.js +60 -6
  113. package/dist/docx/runParser.d.ts +54 -18
  114. package/dist/docx/runParser.js +379 -295
  115. package/dist/docx/runPayload.d.ts +5 -0
  116. package/dist/docx/runPayload.js +4 -0
  117. package/dist/docx/sdtProperties.d.ts +39 -5
  118. package/dist/docx/sdtProperties.js +205 -84
  119. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  120. package/dist/docx/sdtPropertiesPatch.js +68 -112
  121. package/dist/docx/sectionParser.d.ts +1 -2
  122. package/dist/docx/sectionParser.js +236 -240
  123. package/dist/docx/selectiveSave.js +3 -2
  124. package/dist/docx/selectiveXmlPatch.d.ts +21 -2
  125. package/dist/docx/selectiveXmlPatch.js +195 -99
  126. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  127. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  128. package/dist/docx/serializer/borderSerializer.js +10 -8
  129. package/dist/docx/serializer/documentSerializer.js +3 -0
  130. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  131. package/dist/docx/serializer/headerFooterSerializer.js +3 -0
  132. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  133. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  134. package/dist/docx/serializer/noteSerializer.js +3 -0
  135. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  136. package/dist/docx/serializer/numberingSerializer.js +81 -79
  137. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  138. package/dist/docx/serializer/paragraphSerializer.js +88 -188
  139. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  140. package/dist/docx/serializer/runSerializer.js +109 -59
  141. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  142. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  143. package/dist/docx/serializer/sectionPropertiesSerializer.js +34 -45
  144. package/dist/docx/serializer/settingsSerializer.js +6 -4
  145. package/dist/docx/serializer/stylesSerializer.js +8 -11
  146. package/dist/docx/serializer/tableSerializer.js +268 -100
  147. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  148. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  149. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  150. package/dist/docx/serializer/xmlUtils.js +1 -1
  151. package/dist/docx/server/createBilingualDocument.js +18 -16
  152. package/dist/docx/server/migrateYjsAttrSchema.js +3 -3
  153. package/dist/docx/settingsParser.js +7 -4
  154. package/dist/docx/shadingParser.d.ts +2 -1
  155. package/dist/docx/shadingParser.js +43 -7
  156. package/dist/docx/shapeParser.js +8 -3
  157. package/dist/docx/strictNames.d.ts +11 -0
  158. package/dist/docx/strictNames.gen.d.ts +45 -0
  159. package/dist/docx/strictNames.gen.js +50 -0
  160. package/dist/docx/strictNames.js +43 -0
  161. package/dist/docx/strictValueEncodings.gen.js +133 -131
  162. package/dist/docx/styleParser.js +17 -349
  163. package/dist/docx/tableParser.d.ts +10 -1
  164. package/dist/docx/tableParser.js +505 -181
  165. package/dist/docx/textBoxParser.d.ts +3 -1
  166. package/dist/docx/textBoxParser.js +18 -8
  167. package/dist/docx/themeColorAttribute.d.ts +13 -0
  168. package/dist/docx/themeColorAttribute.js +24 -0
  169. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  170. package/dist/docx/vmlImageParser.d.ts +13 -4
  171. package/dist/docx/vmlImageParser.js +74 -31
  172. package/dist/docx/vmlPreview.js +2 -2
  173. package/dist/docx/wrapPolygon.d.ts +30 -0
  174. package/dist/docx/wrapPolygon.js +70 -0
  175. package/dist/docx/xmlParser.d.ts +14 -1
  176. package/dist/docx/xmlParser.js +18 -2
  177. package/dist/fonts/embeddedFonts.js +3 -3
  178. package/dist/headless-layout.js +2 -0
  179. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  180. package/dist/i18n/messages/catalogs.gen.js +102 -34
  181. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  182. package/dist/internal/headlessRevisionResolution.js +9 -0
  183. package/dist/internal/pageBreakRunSourceDescendantIndex.js +3 -1
  184. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  185. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  186. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  187. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  188. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  189. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  190. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  191. package/dist/layout-bridge/convert/toFlowBlocks.js +177 -101
  192. package/dist/layout-engine/index.d.ts +2 -2
  193. package/dist/layout-engine/index.js +53 -17
  194. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  195. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  196. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  197. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  198. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  199. package/dist/layout-engine/paragraphSequence.js +3 -2
  200. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  201. package/dist/layout-engine/section-breaks.d.ts +49 -2
  202. package/dist/layout-engine/section-breaks.js +55 -4
  203. package/dist/layout-engine/types.d.ts +47 -17
  204. package/dist/layout-engine/types.js +16 -1
  205. package/dist/layout-painter/borderStroke.d.ts +18 -4
  206. package/dist/layout-painter/renderPage.js +6 -4
  207. package/dist/layout-painter/renderParagraph.d.ts +2 -1
  208. package/dist/layout-painter/renderParagraph.js +13 -26
  209. package/dist/layout-painter/renderTable.d.ts +4 -1
  210. package/dist/layout-painter/renderTable.js +22 -22
  211. package/dist/layout-painter/renderTextBox.js +5 -3
  212. package/dist/markdown/renderBlock.js +3 -1
  213. package/dist/markdown/renderRuns.js +7 -2
  214. package/dist/markdown/renderTable.js +2 -1
  215. package/dist/model.d.ts +3 -3
  216. package/dist/model.js +2 -2
  217. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  218. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  219. package/dist/prosemirror/attrs/index.d.ts +22 -4
  220. package/dist/prosemirror/attrs/index.js +498 -60
  221. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  222. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  223. package/dist/prosemirror/commands/comments.js +68 -53
  224. package/dist/prosemirror/commands/contentControls.js +24 -19
  225. package/dist/prosemirror/commands/image.d.ts +1 -1
  226. package/dist/prosemirror/commands/image.js +4 -1
  227. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  228. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  229. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  230. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  231. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  232. package/dist/prosemirror/conversion/fromProseDoc.d.ts +18 -2
  233. package/dist/prosemirror/conversion/fromProseDoc.js +330 -183
  234. package/dist/prosemirror/conversion/index.d.ts +2 -2
  235. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  236. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  237. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  238. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  239. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  240. package/dist/prosemirror/conversion/toProseDoc.js +371 -141
  241. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  242. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  243. package/dist/prosemirror/extensions/StarterKit.js +8 -2
  244. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  245. package/dist/prosemirror/extensions/core/ParagraphExtension.js +19 -15
  246. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  247. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  248. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  249. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  250. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  251. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  252. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  253. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  254. package/dist/prosemirror/extensions/markRegistry.d.ts +26 -2
  255. package/dist/prosemirror/extensions/markRegistry.js +73 -10
  256. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +17 -3
  257. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  258. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  259. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  260. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  261. package/dist/prosemirror/extensions/marks/markUtils.js +2 -1
  262. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  263. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  264. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  265. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  266. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  267. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +10 -0
  268. package/dist/prosemirror/extensions/nodes/ImageExtension.js +8 -1
  269. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  270. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  271. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  272. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  273. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  274. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  275. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +4 -0
  276. package/dist/prosemirror/extensions/nodes/TableExtension.js +141 -123
  277. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +4 -0
  278. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  279. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  280. package/dist/prosemirror/extensions/types.d.ts +12 -3
  281. package/dist/prosemirror/index.d.ts +4 -2
  282. package/dist/prosemirror/index.js +2 -1
  283. package/dist/prosemirror/inlineWrapperStack.js +20 -3
  284. package/dist/prosemirror/listMarker.d.ts +2 -2
  285. package/dist/prosemirror/listMarker.js +7 -8
  286. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  287. package/dist/prosemirror/listState.d.ts +62 -0
  288. package/dist/prosemirror/listState.js +49 -0
  289. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  290. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  291. package/dist/prosemirror/numberedRefFields.js +4 -4
  292. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  293. package/dist/prosemirror/numberingAttr.js +74 -0
  294. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  295. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  296. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  297. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  298. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  299. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  300. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  301. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  302. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  303. package/dist/prosemirror/replacedAnnotations.js +24 -6
  304. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  305. package/dist/prosemirror/revisionCarriers.js +86 -60
  306. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -0
  307. package/dist/prosemirror/runFormattingInlineCarriers.js +2 -0
  308. package/dist/prosemirror/runIdentity.d.ts +28 -0
  309. package/dist/prosemirror/runIdentity.js +36 -0
  310. package/dist/prosemirror/runStyleFormatting.js +1 -1
  311. package/dist/prosemirror/schema/index.d.ts +2 -2
  312. package/dist/prosemirror/schema/marks.d.ts +23 -4
  313. package/dist/prosemirror/schema/nodes.d.ts +220 -24
  314. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  315. package/dist/prosemirror/sectionCarrier.js +40 -0
  316. package/dist/prosemirror/selectionState.d.ts +3 -0
  317. package/dist/prosemirror/selectionState.js +4 -1
  318. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  319. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  320. package/dist/prosemirror/tableResize.js +5 -6
  321. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +2 -0
  322. package/dist/prosemirror/trackedRunInlineAtoms.js +2 -0
  323. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  324. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  325. package/dist/prosemirror/validation.js +17 -6
  326. package/dist/prosemirror/yjsDocumentMetadata.d.ts +2 -2
  327. package/dist/prosemirror/yjsDocumentMetadata.js +428 -7
  328. package/dist/prosemirror/zeroWidthAnchors.js +4 -0
  329. package/dist/style-sets/extract.js +4 -4
  330. package/dist/style-sets/stellaStyle.js +36 -23
  331. package/dist/types/colors.d.ts +2 -2
  332. package/dist/types/content.d.ts +2 -2
  333. package/dist/types/documentEnumValues.d.ts +53 -26
  334. package/dist/types/documentEnumValues.js +72 -174
  335. package/dist/types/formatting.d.ts +2 -2
  336. package/dist/types/index.d.ts +9 -2
  337. package/dist/utils/borderCss.d.ts +246 -0
  338. package/dist/utils/borderCss.js +325 -0
  339. package/dist/utils/colorResolver.d.ts +4 -3
  340. package/dist/utils/colorResolver.js +45 -76
  341. package/dist/utils/createDocument.js +24 -6
  342. package/dist/utils/findReplace.js +52 -10
  343. package/dist/utils/formatToStyle.d.ts +84 -2
  344. package/dist/utils/formatToStyle.js +133 -52
  345. package/dist/utils/headingCollector.js +3 -2
  346. package/dist/utils/mergeDocumentContent.js +5 -3
  347. package/dist/utils/paragraphFormattingMerge.js +27 -6
  348. package/dist/utils/replaceText.js +1 -1
  349. package/dist/utils/tableOperations.d.ts +5 -3
  350. package/dist/utils/tableOperations.js +14 -1
  351. package/dist/utils/tablePlacement.d.ts +7 -0
  352. package/dist/utils/tablePlacement.js +14 -0
  353. package/dist/utils/textDirectionFlow.d.ts +15 -0
  354. package/dist/utils/textDirectionFlow.js +38 -0
  355. package/dist/utils/textFormattingMerge.js +16 -4
  356. package/package.json +10 -10
  357. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  358. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  359. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  360. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  361. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  362. package/dist/compare/__fixtures__/nested-table.js +0 -50
  363. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  364. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  365. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  366. package/dist/docx/bookmarkPlacement.js +0 -52
  367. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  368. package/dist/fonts/embeddedFontTable.js +0 -80
  369. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  370. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
@@ -36,6 +36,88 @@ declare function borderToStyle(border: document_d_exports.BorderSpec | undefined
36
36
  * @returns CSS color string or empty string
37
37
  */
38
38
  declare function resolveShadingFill(shading: document_d_exports.ShadingProperties | undefined | null, theme?: document_d_exports.Theme | null): string;
39
+ /** The CSS `text-decoration-style` keywords folio paints an underline with. */
40
+ type CssTextDecorationStyle = "solid" | "double" | "dotted" | "dashed" | "wavy";
41
+ /**
42
+ * What an authored underline paints as, in CSS.
43
+ *
44
+ * `decorationStyle` is absent for the member that paints no line at all; the
45
+ * caller decides whether that means "omit the decoration" or "inherit".
46
+ * `decorationThickness` is absent wherever the font's own underline weight is
47
+ * what Word draws.
48
+ */
49
+ type UnderlineDecorationCss = {
50
+ readonly decorationStyle?: CssTextDecorationStyle;
51
+ readonly decorationThickness?: string;
52
+ };
53
+ /**
54
+ * The underline every DOM backend draws when the author named no member.
55
+ *
56
+ * It is also what an underline CSS cannot spell parses back as; see
57
+ * `underlineStyleFromCssDecoration`.
58
+ */
59
+ declare const PLAIN_UNDERLINE = "single";
60
+ /**
61
+ * Every `ST_Underline` member's CSS line. The one table: the ProseMirror mark's
62
+ * `toDOM`, the DOM painter and `textToStyle` all render a run from this, so a
63
+ * member cannot paint one line in the editor and another on the page.
64
+ *
65
+ * `none` cancels an underline inherited from the style chain rather than
66
+ * naming a line style, and `text-decoration-style: none` is not a CSS keyword,
67
+ * so that member names no keyword and carries no declarations at all.
68
+ *
69
+ * Where CSS has no keyword for what Word draws, the member is approximated and
70
+ * the approximation is stated here rather than at a call site: `words`
71
+ * underlines the spaces between words too (`text-decoration-skip-ink` skips
72
+ * descender ink, not spaces, and `text-decoration-skip: spaces` never
73
+ * shipped); `wavyDouble` draws two straight lines rather than two wavy ones;
74
+ * `dashLong`, `dotDash` and `dotDotDash` draw the single dash pattern CSS has.
75
+ * The `*Heavy` members and `thick` differ from their plain counterparts in
76
+ * weight only, which the thickness carries, so the line they name is their
77
+ * plain counterpart's.
78
+ */
79
+ declare const UNDERLINE_DECORATION_STYLES: {
80
+ readonly none: undefined;
81
+ readonly single: "solid";
82
+ readonly words: "solid";
83
+ readonly double: "double";
84
+ readonly thick: "solid";
85
+ readonly dotted: "dotted";
86
+ readonly dottedHeavy: "dotted";
87
+ readonly dash: "dashed";
88
+ readonly dashedHeavy: "dashed";
89
+ readonly dashLong: "dashed";
90
+ readonly dashLongHeavy: "dashed";
91
+ readonly dotDash: "dashed";
92
+ readonly dashDotHeavy: "dashed";
93
+ readonly dotDotDash: "dashed";
94
+ readonly dashDotDotHeavy: "dashed";
95
+ readonly wave: "wavy";
96
+ readonly wavyHeavy: "wavy";
97
+ readonly wavyDouble: "double";
98
+ };
99
+ /**
100
+ * The CSS an authored underline paints with.
101
+ *
102
+ * CSS has no heavy keyword, so a weight is stated as a length: the plain ratio
103
+ * the display list strokes with, times the weight the member's own row carries
104
+ * (`display-list/build/strokes.ts`). Both backends therefore scale the same way
105
+ * with the font size, and which members are heavy is read off the row rather
106
+ * than listed again here, so the page and the editor cannot disagree about it.
107
+ */
108
+ declare const underlineDecorationCss: (style: document_d_exports.UnderlineStyle) => UnderlineDecorationCss;
109
+ /**
110
+ * The `ST_Underline` member an authored `text-decoration` or
111
+ * `text-decoration-style` value parses back as.
112
+ *
113
+ * The table is many-to-one, so the inverse cannot be: several members share
114
+ * every keyword. It resolves each keyword to that keyword's canonical author,
115
+ * the plain member whose own CSS is exactly the keyword, so a member folio
116
+ * cannot spell in CSS comes back as the sibling it is drawn as: `dottedHeavy`
117
+ * as `dotted`, `words` and `thick` as `single`, `wavyDouble` as `double`. A
118
+ * value naming no keyword folio writes parses as the plain underline.
119
+ */
120
+ declare const underlineStyleFromCssDecoration: (value: string) => document_d_exports.UnderlineStyle;
39
121
  /**
40
122
  * Merge multiple CSSProperties objects
41
123
  *
@@ -54,7 +136,7 @@ declare function mergeStyles(...styles: (CSSProperties | undefined | null)[]): C
54
136
  */
55
137
  declare function tableCellToStyle(formatting: {
56
138
  verticalAlign?: "top" | "center" | "bottom";
57
- textDirection?: string;
139
+ textDirection?: document_d_exports.TextDirection;
58
140
  shading?: document_d_exports.ShadingProperties;
59
141
  borders?: {
60
142
  top?: document_d_exports.BorderSpec;
@@ -99,4 +181,4 @@ declare function sectionToStyle(sectionProps: {
99
181
  };
100
182
  } | undefined | null, theme?: document_d_exports.Theme | null): CSSProperties;
101
183
  //#endregion
102
- export { borderToStyle, mergeStyles, paragraphToStyle, resolveShadingFill, sectionToStyle, tableCellToStyle, textToStyle };
184
+ export { CssTextDecorationStyle, PLAIN_UNDERLINE, UNDERLINE_DECORATION_STYLES, UnderlineDecorationCss, borderToStyle, mergeStyles, paragraphToStyle, resolveShadingFill, sectionToStyle, tableCellToStyle, textToStyle, underlineDecorationCss, underlineStyleFromCssDecoration };
@@ -1,7 +1,13 @@
1
+ import { UNDERLINE_STROKES } from "../display-list/build/strokes.js";
2
+ import { UNDERLINE_THICKNESS_RATIO } from "../display-list/build/textDecorations.js";
3
+ import { UNDERLINE_STYLE_VALUES } from "../types/documentEnumValues.js";
4
+ import { cssBorderStyle } from "./borderCss.js";
1
5
  import { resolveColor, resolveHighlightToCss, resolveShadingColor } from "./colorResolver.js";
2
6
  import { resolveFontFamily, resolveThemeFont } from "./fontResolver.js";
3
7
  import { getHorizontalScaleFactor, normalizeHorizontalScalePercent } from "./horizontalScale.js";
8
+ import { textFlowCss } from "./textDirectionFlow.js";
4
9
  import { AUTO_PARAGRAPH_SPACING_PX, eighthsToPixels, formatPx, halfPointsToPixels, halfPointsToPoints, twipsToPixels } from "./units.js";
10
+ import { statesNoBorder } from "@stll/docx-core/model";
5
11
  //#region src/utils/formatToStyle.ts
6
12
  /**
7
13
  * Convert TextFormatting to CSS properties for a run/span
@@ -31,10 +37,12 @@ function textToStyle(formatting, theme) {
31
37
  const decorations = [];
32
38
  const decorationStyles = [];
33
39
  const decorationColors = [];
40
+ let decorationThickness;
34
41
  if (formatting.underline && formatting.underline.style !== "none") {
35
42
  decorations.push("underline");
36
- const underlineStyle = mapUnderlineStyle(formatting.underline.style);
37
- if (underlineStyle !== "solid") decorationStyles.push(underlineStyle);
43
+ const underline = underlineDecorationCss(formatting.underline.style);
44
+ if (underline.decorationStyle !== void 0 && underline.decorationStyle !== "solid") decorationStyles.push(underline.decorationStyle);
45
+ decorationThickness = underline.decorationThickness;
38
46
  if (formatting.underline.color) decorationColors.push(resolveColor(formatting.underline.color, theme));
39
47
  }
40
48
  if (formatting.strike) decorations.push("line-through");
@@ -43,6 +51,7 @@ function textToStyle(formatting, theme) {
43
51
  style.textDecoration = decorations.join(" ");
44
52
  if (decorationStyles.length > 0) style.textDecorationStyle = decorationStyles[0];
45
53
  if (decorationColors.length > 0) style.textDecorationColor = decorationColors[0];
54
+ if (decorationThickness !== void 0) style.textDecorationThickness = decorationThickness;
46
55
  }
47
56
  if (formatting.vertAlign) switch (formatting.vertAlign) {
48
57
  case "superscript":
@@ -90,7 +99,7 @@ function textToStyle(formatting, theme) {
90
99
  function paragraphToStyle(formatting, theme) {
91
100
  if (!formatting) return {};
92
101
  const style = {};
93
- if (formatting.alignment) style.textAlign = mapAlignment(formatting.alignment);
102
+ if (formatting.alignment) style.textAlign = CSS_TEXT_ALIGN_BY_PARAGRAPH_ALIGNMENT[formatting.alignment];
94
103
  if (formatting.beforeAutospacing) style.marginTop = formatPx(AUTO_PARAGRAPH_SPACING_PX);
95
104
  else if (formatting.spaceBefore !== void 0) style.marginTop = formatPx(twipsToPixels(formatting.spaceBefore));
96
105
  if (formatting.afterAutospacing) style.marginBottom = formatPx(AUTO_PARAGRAPH_SPACING_PX);
@@ -136,11 +145,11 @@ function paragraphToStyle(formatting, theme) {
136
145
  * @returns Partial CSSProperties with border styles
137
146
  */
138
147
  function borderToStyle(border, side = "", theme) {
139
- if (!border || border.style === "none" || border.style === "nil") return {};
148
+ if (!border || statesNoBorder(border.style)) return {};
140
149
  const style = {};
141
150
  const widthPx = border.size !== void 0 && border.size !== 0 ? eighthsToPixels(border.size) : 1;
142
151
  const color = border.color ? resolveColor(border.color, theme) : "#000000";
143
- const cssStyle = mapBorderStyle(border.style);
152
+ const cssStyle = cssBorderStyle(border.style);
144
153
  const widthKey = `border${side}Width`;
145
154
  const styleKey = `border${side}Style`;
146
155
  const colorKey = `border${side}Color`;
@@ -211,58 +220,126 @@ function resolveShadingFill(shading, theme) {
211
220
  return "";
212
221
  }
213
222
  /**
214
- * Map OOXML underline style to CSS text-decoration-style
223
+ * The underline every DOM backend draws when the author named no member.
224
+ *
225
+ * It is also what an underline CSS cannot spell parses back as; see
226
+ * `underlineStyleFromCssDecoration`.
215
227
  */
216
- function mapUnderlineStyle(underlineStyle) {
217
- switch (underlineStyle) {
218
- case "double": return "double";
219
- case "dotted":
220
- case "dottedHeavy": return "dotted";
221
- case "dash":
222
- case "dashedHeavy":
223
- case "dashLong":
224
- case "dashLongHeavy":
225
- case "dotDash":
226
- case "dashDotHeavy":
227
- case "dotDotDash":
228
- case "dashDotDotHeavy": return "dashed";
229
- case "wave":
230
- case "wavyHeavy":
231
- case "wavyDouble": return "wavy";
232
- default: return "solid";
233
- }
234
- }
228
+ const PLAIN_UNDERLINE = "single";
235
229
  /**
236
- * Map OOXML paragraph alignment to CSS text-align
230
+ * Every `ST_Underline` member's CSS line. The one table: the ProseMirror mark's
231
+ * `toDOM`, the DOM painter and `textToStyle` all render a run from this, so a
232
+ * member cannot paint one line in the editor and another on the page.
233
+ *
234
+ * `none` cancels an underline inherited from the style chain rather than
235
+ * naming a line style, and `text-decoration-style: none` is not a CSS keyword,
236
+ * so that member names no keyword and carries no declarations at all.
237
+ *
238
+ * Where CSS has no keyword for what Word draws, the member is approximated and
239
+ * the approximation is stated here rather than at a call site: `words`
240
+ * underlines the spaces between words too (`text-decoration-skip-ink` skips
241
+ * descender ink, not spaces, and `text-decoration-skip: spaces` never
242
+ * shipped); `wavyDouble` draws two straight lines rather than two wavy ones;
243
+ * `dashLong`, `dotDash` and `dotDotDash` draw the single dash pattern CSS has.
244
+ * The `*Heavy` members and `thick` differ from their plain counterparts in
245
+ * weight only, which the thickness carries, so the line they name is their
246
+ * plain counterpart's.
237
247
  */
238
- function mapAlignment(alignment) {
239
- switch (alignment) {
240
- case "center": return "center";
241
- case "right": return "right";
242
- case "both":
243
- case "distribute": return "justify";
244
- default: return "left";
248
+ const UNDERLINE_DECORATION_STYLES = {
249
+ none: void 0,
250
+ single: "solid",
251
+ words: "solid",
252
+ double: "double",
253
+ thick: "solid",
254
+ dotted: "dotted",
255
+ dottedHeavy: "dotted",
256
+ dash: "dashed",
257
+ dashedHeavy: "dashed",
258
+ dashLong: "dashed",
259
+ dashLongHeavy: "dashed",
260
+ dotDash: "dashed",
261
+ dashDotHeavy: "dashed",
262
+ dotDotDash: "dashed",
263
+ dashDotDotHeavy: "dashed",
264
+ wave: "wavy",
265
+ wavyHeavy: "wavy",
266
+ wavyDouble: "double"
267
+ };
268
+ /**
269
+ * The CSS an authored underline paints with.
270
+ *
271
+ * CSS has no heavy keyword, so a weight is stated as a length: the plain ratio
272
+ * the display list strokes with, times the weight the member's own row carries
273
+ * (`display-list/build/strokes.ts`). Both backends therefore scale the same way
274
+ * with the font size, and which members are heavy is read off the row rather
275
+ * than listed again here, so the page and the editor cannot disagree about it.
276
+ */
277
+ const underlineDecorationCss = (style) => {
278
+ const decorationStyle = UNDERLINE_DECORATION_STYLES[style];
279
+ if (decorationStyle === void 0) return {};
280
+ const { weight } = UNDERLINE_STROKES[style];
281
+ if (weight === 1) return { decorationStyle };
282
+ return {
283
+ decorationStyle,
284
+ decorationThickness: `${(UNDERLINE_THICKNESS_RATIO * weight).toFixed(4)}em`
285
+ };
286
+ };
287
+ /**
288
+ * Each CSS keyword's canonical author, derived from the one table: the first
289
+ * member in enumeration order that paints exactly that keyword at the font's
290
+ * own weight.
291
+ */
292
+ const CANONICAL_UNDERLINE_STYLE_BY_CSS = (() => {
293
+ const canonical = /* @__PURE__ */ new Map();
294
+ for (const style of UNDERLINE_STYLE_VALUES) {
295
+ const { decorationStyle, decorationThickness } = underlineDecorationCss(style);
296
+ if (decorationStyle === void 0 || decorationThickness !== void 0) continue;
297
+ if (!canonical.has(decorationStyle)) canonical.set(decorationStyle, style);
245
298
  }
246
- }
299
+ return canonical;
300
+ })();
247
301
  /**
248
- * Map OOXML border style to CSS border-style
302
+ * The `ST_Underline` member an authored `text-decoration` or
303
+ * `text-decoration-style` value parses back as.
304
+ *
305
+ * The table is many-to-one, so the inverse cannot be: several members share
306
+ * every keyword. It resolves each keyword to that keyword's canonical author,
307
+ * the plain member whose own CSS is exactly the keyword, so a member folio
308
+ * cannot spell in CSS comes back as the sibling it is drawn as: `dottedHeavy`
309
+ * as `dotted`, `words` and `thick` as `single`, `wavyDouble` as `double`. A
310
+ * value naming no keyword folio writes parses as the plain underline.
249
311
  */
250
- function mapBorderStyle(borderStyle) {
251
- switch (borderStyle) {
252
- case "none":
253
- case "nil": return "none";
254
- case "double":
255
- case "triple": return "double";
256
- case "dotted": return "dotted";
257
- case "dashed":
258
- case "dashSmallGap": return "dashed";
259
- case "threeDEmboss": return "ridge";
260
- case "threeDEngrave": return "groove";
261
- case "outset": return "outset";
262
- case "inset": return "inset";
263
- default: return "solid";
312
+ const underlineStyleFromCssDecoration = (value) => {
313
+ for (const token of value.toLowerCase().split(/[\s,]+/u)) {
314
+ const style = CANONICAL_UNDERLINE_STYLE_BY_CSS.get(token);
315
+ if (style !== void 0) return style;
264
316
  }
265
- }
317
+ return PLAIN_UNDERLINE;
318
+ };
319
+ /**
320
+ * Every `ST_Jc` member, and the CSS `text-align` that renders it.
321
+ *
322
+ * `start` and `end` carry straight over: CSS spells the direction-aware edges
323
+ * the same way and resolves them against the element's direction, as Word
324
+ * does. The Kashida justifications and `distribute` all render as `justify`,
325
+ * which is as close as CSS gets. `numTab` aligns to the list number's tab
326
+ * stop, which CSS cannot express, so it renders at the start edge — where a
327
+ * numbered paragraph without one sits.
328
+ */
329
+ const CSS_TEXT_ALIGN_BY_PARAGRAPH_ALIGNMENT = {
330
+ start: "start",
331
+ end: "end",
332
+ numTab: "start",
333
+ left: "left",
334
+ center: "center",
335
+ right: "right",
336
+ both: "justify",
337
+ distribute: "justify",
338
+ mediumKashida: "justify",
339
+ highKashida: "justify",
340
+ lowKashida: "justify",
341
+ thaiDistribute: "justify"
342
+ };
266
343
  /**
267
344
  * Merge multiple CSSProperties objects
268
345
  *
@@ -287,7 +364,11 @@ function tableCellToStyle(formatting, theme) {
287
364
  if (!formatting) return {};
288
365
  const style = {};
289
366
  if (formatting.verticalAlign) style.verticalAlign = formatting.verticalAlign;
290
- if (formatting.textDirection && (formatting.textDirection.includes("rl") || formatting.textDirection.includes("Rl"))) style.direction = "rtl";
367
+ if (formatting.textDirection) {
368
+ const flow = textFlowCss(formatting.textDirection);
369
+ if (flow.writingMode !== "horizontal-tb") style.writingMode = flow.writingMode;
370
+ if (flow.rotateDegrees !== void 0) style.transform = `rotate(${String(flow.rotateDegrees)}deg)`;
371
+ }
291
372
  if (formatting.shading) {
292
373
  const bgColor = resolveShadingFill(formatting.shading, theme);
293
374
  if (bgColor) style.backgroundColor = bgColor;
@@ -328,4 +409,4 @@ function sectionToStyle(sectionProps, theme) {
328
409
  return style;
329
410
  }
330
411
  //#endregion
331
- export { borderToStyle, mergeStyles, paragraphToStyle, resolveShadingFill, sectionToStyle, tableCellToStyle, textToStyle };
412
+ export { PLAIN_UNDERLINE, UNDERLINE_DECORATION_STYLES, borderToStyle, mergeStyles, paragraphToStyle, resolveShadingFill, sectionToStyle, tableCellToStyle, textToStyle, underlineDecorationCss, underlineStyleFromCssDecoration };
@@ -1,4 +1,5 @@
1
1
  import { resolveHeadingLevel } from "../docx/builtInStyles.js";
2
+ import { readOutlineLevelAttr } from "../prosemirror/outlineLevelAttr.js";
2
3
  //#region src/utils/headingCollector.ts
3
4
  /**
4
5
  * Collect all headings from a ProseMirror document, in document order.
@@ -14,8 +15,8 @@ function collectHeadings(doc, styles) {
14
15
  doc.descendants((node, pos) => {
15
16
  if (node.type.name !== "paragraph") return;
16
17
  const level = resolveHeadingLevel({
17
- outlineLevel: node.attrs["outlineLevel"],
18
- styleId: node.attrs["styleId"]
18
+ outlineLevel: readOutlineLevelAttr(node.attrs["outlineLevel"]),
19
+ styleId: typeof node.attrs["styleId"] === "string" ? node.attrs["styleId"] : null
19
20
  }, styles);
20
21
  if (level === void 0) return;
21
22
  let text = "";
@@ -1,3 +1,4 @@
1
+ import { paragraphNumberingReferenceId } from "../docx/numberingReference.js";
1
2
  import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySource.js";
2
3
  //#region src/utils/mergeDocumentContent.ts
3
4
  /**
@@ -110,14 +111,15 @@ function remapTable(table, numIdRemap, abstractNumIdRemap) {
110
111
  };
111
112
  }
112
113
  function remapParagraph(paragraph, numIdRemap, abstractNumIdRemap) {
113
- const numId = paragraph.formatting?.numPr?.numId;
114
+ const numPr = paragraph.formatting?.numPr;
115
+ const numId = paragraphNumberingReferenceId(numPr);
114
116
  const remappedNumId = numId === void 0 ? void 0 : numIdRemap.get(numId);
115
- if (remappedNumId === void 0) return paragraph;
117
+ if (remappedNumId === void 0 || numPr?.kind !== "reference") return paragraph;
116
118
  return cloneParagraphWithoutPropertySource(paragraph, {
117
119
  formatting: {
118
120
  ...paragraph.formatting,
119
121
  numPr: {
120
- ...paragraph.formatting?.numPr,
122
+ ...numPr,
121
123
  numId: remappedNumId
122
124
  }
123
125
  },
@@ -1,4 +1,5 @@
1
1
  import { mergeTextFormatting } from "./textFormattingMerge.js";
2
+ import { mergeParagraphNumbering } from "@stll/docx-core/model";
2
3
  //#region src/utils/paragraphFormattingMerge.ts
3
4
  const PARAGRAPH_REPLACE_KEYS = [
4
5
  "alignment",
@@ -41,6 +42,28 @@ function mergeParagraphTabStops(inherited, direct) {
41
42
  return [...stopsByPosition.values()].toSorted((a, b) => a.position - b.position);
42
43
  }
43
44
  /**
45
+ * A resolved cascade carries no captured bytes.
46
+ *
47
+ * `preserved` holds the markup of the one element it was read from, and the
48
+ * two attribute remainders beside it hold the attributes of the `w:ind` and
49
+ * `w:spacing` that element carried. A style's `w:pPr` is not a paragraph's
50
+ * direct formatting, and a merge that let a spread carry either would write
51
+ * the same bytes at two tiers and make an inherited value outrank the tier it
52
+ * came from — the rule #873 states for every other inherited `w:pPr` value.
53
+ * Every caller of the merge below builds a resolved cascade rather than a
54
+ * saved element, so the drop is unconditional and belongs here, where a new
55
+ * field cannot slip past it in a spread.
56
+ *
57
+ * The remainders inside `borders`, `shading` and `tabs` are not dropped, and
58
+ * that is the same rule rather than an exception: those records replace
59
+ * wholesale, so an inherited one is written back only where the whole record
60
+ * is, and the attributes the author wrote on it belong with it.
61
+ */
62
+ const withoutPreservedMarkup = (formatting) => {
63
+ const { preserved: _preserved, indentPreservedAttributes: _indentPreservedAttributes, spacingPreservedAttributes: _spacingPreservedAttributes, ...resolved } = formatting;
64
+ return resolved;
65
+ };
66
+ /**
44
67
  * Merge paragraph properties for OOXML style cascade resolution.
45
68
  *
46
69
  * The source is the higher-priority layer. Most `w:pPr` properties replace an
@@ -51,11 +74,11 @@ function mergeParagraphTabStops(inherited, direct) {
51
74
  function mergeParagraphFormatting(target, source) {
52
75
  if (!source) return target;
53
76
  if (!target) {
54
- const result = { ...source };
77
+ const result = withoutPreservedMarkup(source);
55
78
  if (source.tabs !== void 0) result.tabs = [...source.tabs];
56
79
  return result;
57
80
  }
58
- const result = { ...target };
81
+ const result = withoutPreservedMarkup(target);
59
82
  for (const key of PARAGRAPH_REPLACE_KEYS) copyDefinedParagraphProperty(result, source, key);
60
83
  if (source.indentFirstLine !== void 0) result.hangingIndent = source.hangingIndent === true;
61
84
  const mergedRunProperties = mergeTextFormatting(result.runProperties, source.runProperties);
@@ -64,10 +87,8 @@ function mergeParagraphFormatting(target, source) {
64
87
  ...result.borders,
65
88
  ...source.borders
66
89
  };
67
- if (source.numPr !== void 0) result.numPr = {
68
- ...result.numPr,
69
- ...source.numPr
70
- };
90
+ const mergedNumbering = mergeParagraphNumbering(result.numPr, source.numPr);
91
+ if (mergedNumbering !== void 0) result.numPr = mergedNumbering;
71
92
  if (source.frame !== void 0) result.frame = {
72
93
  ...result.frame,
73
94
  ...source.frame
@@ -49,7 +49,7 @@ function getParagraphByIndex(body, paragraphIndex) {
49
49
  }
50
50
  continue;
51
51
  }
52
- if (block.type === "preservedBlock") continue;
52
+ if (block.type !== "blockSdt") continue;
53
53
  const found = walkBlocks(block.content);
54
54
  if (found !== null) return found;
55
55
  }
@@ -3,8 +3,10 @@ import { document_d_exports } from "../types/document.js";
3
3
  type TablePropertiesCommand = {
4
4
  width?: number | null;
5
5
  widthType?: document_d_exports.TableWidthType | null;
6
- justification?: "left" | "center" | "right" | null;
6
+ justification?: document_d_exports.TableAlignment | null;
7
7
  };
8
+ declare const TABLE_PROPERTY_JUSTIFICATIONS: readonly ("start" | "center" | "end" | "left" | "right")[];
9
+ declare const toTablePropertyJustification: (value: string | null | undefined) => NonNullable<TablePropertiesCommand["justification"]>;
8
10
  type TableAction = "addRowAbove" | "addRowBelow" | "addColumnLeft" | "addColumnRight" | "deleteRow" | "deleteColumn" | "mergeCells" | "splitCell" | "deleteTable" | "selectTable" | "selectRow" | "selectColumn" | "borderAll" | "borderOutside" | "borderInside" | "borderNone" | "borderTop" | "borderBottom" | "borderLeft" | "borderRight" | {
9
11
  type: "cellFillColor";
10
12
  color: string | null;
@@ -17,7 +19,7 @@ type TableAction = "addRowAbove" | "addRowBelow" | "addColumnLeft" | "addColumnR
17
19
  } | {
18
20
  type: "cellBorder";
19
21
  side: "top" | "bottom" | "left" | "right" | "all";
20
- style: string;
22
+ style: document_d_exports.BorderStyle;
21
23
  size: number;
22
24
  color: string;
23
25
  } | {
@@ -84,4 +86,4 @@ declare const deleteColumn: (table: document_d_exports.Table, columnIndex: numbe
84
86
  declare const mergeCells: (table: document_d_exports.Table, selection: TableSelection) => document_d_exports.Table;
85
87
  declare const splitCell: (table: document_d_exports.Table, rowIndex: number, columnIndex: number) => document_d_exports.Table;
86
88
  //#endregion
87
- export { TableAction, TableContext, TablePropertiesCommand, TableSelection, addColumn, addRow, createTableContext, deleteColumn, deleteRow, getCellAt, getColumnCount, mergeCells, splitCell };
89
+ export { TABLE_PROPERTY_JUSTIFICATIONS, TableAction, TableContext, TablePropertiesCommand, TableSelection, addColumn, addRow, createTableContext, deleteColumn, deleteRow, getCellAt, getColumnCount, mergeCells, splitCell, toTablePropertyJustification };
@@ -1,4 +1,17 @@
1
+ import { TABLE_JUSTIFICATION_VALUES } from "../types/documentEnumValues.js";
1
2
  //#region src/utils/tableOperations.ts
3
+ const TABLE_PROPERTY_JUSTIFICATION_ORDER = {
4
+ left: 0,
5
+ center: 1,
6
+ right: 2,
7
+ start: 3,
8
+ end: 4
9
+ };
10
+ const TABLE_PROPERTY_JUSTIFICATIONS = Object.freeze(TABLE_JUSTIFICATION_VALUES.toSorted((left, right) => TABLE_PROPERTY_JUSTIFICATION_ORDER[left] - TABLE_PROPERTY_JUSTIFICATION_ORDER[right]));
11
+ const toTablePropertyJustification = (value) => {
12
+ for (const justification of TABLE_PROPERTY_JUSTIFICATIONS) if (value === justification) return justification;
13
+ return "left";
14
+ };
2
15
  const getColumnCount = (table) => {
3
16
  let maxCols = 0;
4
17
  for (const row of table.rows) {
@@ -256,4 +269,4 @@ const splitCell = (table, rowIndex, columnIndex) => {
256
269
  };
257
270
  };
258
271
  //#endregion
259
- export { addColumn, addRow, createTableContext, deleteColumn, deleteRow, getCellAt, getColumnCount, mergeCells, splitCell };
272
+ export { TABLE_PROPERTY_JUSTIFICATIONS, addColumn, addRow, createTableContext, deleteColumn, deleteRow, getCellAt, getColumnCount, mergeCells, splitCell, toTablePropertyJustification };
@@ -0,0 +1,7 @@
1
+ import { TableAlignment } from "../types/formatting.js";
2
+ //#region src/utils/tablePlacement.d.ts
3
+ type PhysicalTableAlignment = "left" | "center" | "right";
4
+ /** Resolve an OOXML table placement to a physical inline alignment. */
5
+ declare const resolveTablePlacementAlignment: (placement: TableAlignment, rightToLeft: boolean) => PhysicalTableAlignment;
6
+ //#endregion
7
+ export { PhysicalTableAlignment, resolveTablePlacementAlignment };
@@ -0,0 +1,14 @@
1
+ //#region src/utils/tablePlacement.ts
2
+ /** Resolve an OOXML table placement to a physical inline alignment. */
3
+ const resolveTablePlacementAlignment = (placement, rightToLeft) => {
4
+ switch (placement) {
5
+ case "center": return "center";
6
+ case "left":
7
+ case "start": return rightToLeft ? "right" : "left";
8
+ case "right":
9
+ case "end": return rightToLeft ? "left" : "right";
10
+ default: return placement;
11
+ }
12
+ };
13
+ //#endregion
14
+ export { resolveTablePlacementAlignment };
@@ -0,0 +1,15 @@
1
+ import { TextDirection } from "@stll/docx-core/model";
2
+ //#region src/utils/textDirectionFlow.d.ts
3
+ type TextFlowCss = {
4
+ /** `horizontal-tb` needs no declaration; the others are written out. */
5
+ writingMode: "horizontal-tb" | "vertical-lr" | "vertical-rl";
6
+ /**
7
+ * CSS has no writing mode for a bottom-to-top flow, so the nearest one is
8
+ * turned upside down.
9
+ */
10
+ rotateDegrees?: 180;
11
+ };
12
+ /** The CSS a `w:textDirection` token renders as, through the flow it names. */
13
+ declare const textFlowCss: (direction: TextDirection) => TextFlowCss;
14
+ //#endregion
15
+ export { TextFlowCss, textFlowCss };
@@ -0,0 +1,38 @@
1
+ import { TEXT_DIRECTION_FLOW_BY_TOKEN } from "@stll/docx-core/model";
2
+ //#region src/utils/textDirectionFlow.ts
3
+ /**
4
+ * The CSS one `w:textDirection` flow renders as.
5
+ *
6
+ * `ST_TextDirection` spells each of its six flows twice — a Strict spelling
7
+ * and a Transitional one — so rendering is decided per flow and read through
8
+ * `TEXT_DIRECTION_FLOW_BY_TOKEN`. Both CSS projections, the editor's inline
9
+ * style and `tableCellToStyle`, read this one map: a cell written `tbRl` and
10
+ * its Strict twin written `rl` cannot render differently in one and the same
11
+ * in the other.
12
+ */
13
+ /**
14
+ * Each text flow, and the CSS that renders it.
15
+ *
16
+ * `tb` and `tbV` are the horizontal flows. `rl` and `rlV` run their lines
17
+ * right to left, `lrV` runs them left to right, and `lr` runs them left to
18
+ * right with its characters bottom-to-top, which CSS cannot express: it takes
19
+ * the nearest writing mode turned over.
20
+ *
21
+ * Total over the flows on purpose: a flow nobody mapped would otherwise render
22
+ * as horizontal text with nothing to say it had been dropped.
23
+ */
24
+ const TEXT_FLOW_CSS = {
25
+ tb: { writingMode: "horizontal-tb" },
26
+ tbV: { writingMode: "horizontal-tb" },
27
+ rl: { writingMode: "vertical-rl" },
28
+ rlV: { writingMode: "vertical-rl" },
29
+ lrV: { writingMode: "vertical-lr" },
30
+ lr: {
31
+ writingMode: "vertical-lr",
32
+ rotateDegrees: 180
33
+ }
34
+ };
35
+ /** The CSS a `w:textDirection` token renders as, through the flow it names. */
36
+ const textFlowCss = (direction) => TEXT_FLOW_CSS[TEXT_DIRECTION_FLOW_BY_TOKEN[direction]];
37
+ //#endregion
38
+ export { textFlowCss };
@@ -31,14 +31,26 @@ function mergeStyleTextFormatting(target, source) {
31
31
  }
32
32
  return result;
33
33
  }
34
+ /**
35
+ * A merge answers "what does this text look like once the style, the paragraph
36
+ * mark and the run have all had their say". `preserved` is not a value: it is
37
+ * the bytes one specific `w:rPr` held, and carrying it across a merge would
38
+ * write a style's or a paragraph mark's markup into every run that inherits
39
+ * from it. So no merged formatting has one, on any path out of the function.
40
+ */
41
+ const withoutPreserved = (formatting) => {
42
+ if (formatting.preserved === void 0) return formatting;
43
+ const { preserved: _preserved, ...values } = formatting;
44
+ return values;
45
+ };
34
46
  function mergeTextFormatting(target, source) {
35
47
  if (!source && !target) return;
36
- if (!source) return target;
37
- if (!target) return { ...source };
38
- const result = { ...target };
48
+ if (!source) return target && withoutPreserved(target);
49
+ if (!target) return withoutPreserved({ ...source });
50
+ const result = { ...withoutPreserved(target) };
39
51
  for (const key of Object.keys(source)) {
40
52
  const value = source[key];
41
- if (value === void 0) continue;
53
+ if (value === void 0 || key === "preserved") continue;
42
54
  if (key === "fontFamily" && typeof value === "object") {
43
55
  result["fontFamily"] = mergeFontFamily(target.fontFamily, value);
44
56
  continue;