@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
@@ -1,20 +1,22 @@
1
1
  import { parseHorizontalScalePercent } from "../utils/horizontalScale.js";
2
2
  import { NO_MODELLED_ATTRIBUTES, attributeRemainder } from "./attributeRemainder.js";
3
+ import { CAPTURE, dispatchChildren, keptUnless, ownedElsewhere, sequencePositions } from "./containerChildren.js";
3
4
  import { parseDiagramPreview } from "./diagramPreview.js";
4
5
  import { parseFieldState } from "./fieldState.js";
5
6
  import { isGroupDrawing, parseGroupDrawing } from "./groupDrawingParser.js";
6
7
  import { parseImage } from "./imageParser.js";
7
8
  import { imageRawXmlFingerprint } from "./imageRawXml.js";
8
- import { EmphasisMarkSchema, FontHintSchema, FontThemeSchema, HighlightColorSchema, PositionalTabAlignmentSchema, PositionalTabLeaderSchema, PositionalTabRelativeToSchema, TextEffectSchema, ThemeColorSlotSchema, UnderlineStyleSchema, narrowEnum } from "./parserEnums.js";
9
+ import { EmphasisMarkSchema, FontHintSchema, FontThemeSchema, HighlightColorSchema, PositionalTabAlignmentSchema, PositionalTabLeaderSchema, PositionalTabRelativeToSchema, TextEffectSchema, UnderlineStyleSchema, narrowEnum } from "./parserEnums.js";
9
10
  import { preserveRunChild } from "./preservedRunContent.js";
10
11
  import { parseShading } from "./shadingParser.js";
11
12
  import { parseShapeFromDrawing, shouldPreserveRawShapeDrawing } from "./shapeParser.js";
12
13
  import { isTextBoxDrawing } from "./textBoxParser.js";
14
+ import { parseThemeColorAttribute } from "./themeColorAttribute.js";
13
15
  import { resolveThemeFontRef } from "./themeParser.js";
14
16
  import { parsePropertyChangeInfo } from "./trackedChangeInfo.js";
15
17
  import { captureVerbatimXml } from "./verbatimCapture.js";
16
18
  import { parseVmlImageContent, shouldPreserveRawVmlPict } from "./vmlImageParser.js";
17
- import { cloneWithXmlnsDeclarations, findAllDeep, findChild, findChildren, getAttribute, getChildElements, getLocalName, getTextContent, mergeXmlnsDeclarations, parseBooleanElement, parseNumericAttribute, selectAlternateContentBranch } from "./xmlParser.js";
19
+ import { WORDPROCESSINGML_NAMESPACE_URIS, cloneWithXmlnsDeclarations, findAllDeep, findChild, findChildren, getAttribute, getChildElements, getLocalName, getNamespaceUri, getTextContent, mergeXmlnsDeclarations, parseBooleanElement, parseNumericAttribute, selectAlternateContentBranch } from "./xmlParser.js";
18
20
  import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
19
21
  //#region src/docx/runParser.ts
20
22
  /**
@@ -25,124 +27,113 @@ import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
25
27
  */
26
28
  const MAX_LANGUAGE_TAG_LENGTH = 35;
27
29
  const truncateLanguageTag = (value) => value === void 0 ? void 0 : value.slice(0, MAX_LANGUAGE_TAG_LENGTH);
28
- /**
29
- * Parse color value from attributes
30
- */
31
- function parseColorValue(rgb, themeColor, themeTint, themeShade) {
30
+ function parseColorValue({ rgb, themeColor, themeTint, themeShade, element }) {
32
31
  const color = {};
33
32
  if (rgb && rgb !== "auto") color.rgb = rgb;
34
33
  else if (rgb === "auto") color.auto = true;
35
- const validatedThemeColor = narrowEnum(themeColor, ThemeColorSlotSchema);
36
- if (validatedThemeColor) color.themeColor = validatedThemeColor;
34
+ const parsedThemeColor = parseThemeColorAttribute({
35
+ raw: themeColor,
36
+ element
37
+ });
38
+ if (parsedThemeColor !== void 0) color.themeColor = parsedThemeColor;
37
39
  if (themeTint) color.themeTint = themeTint;
38
40
  if (themeShade) color.themeShade = themeShade;
39
41
  return color;
40
42
  }
41
- function collectFirstRunPropertyChildren(rPr) {
42
- const children = {};
43
- for (const child of rPr.elements ?? []) {
44
- if (child.type !== "element") continue;
45
- switch (getLocalName(child.name)) {
46
- case "b":
47
- children.b ??= child;
48
- break;
49
- case "bCs":
50
- children.bCs ??= child;
51
- break;
52
- case "caps":
53
- children.caps ??= child;
54
- break;
55
- case "color":
56
- children.color ??= child;
57
- break;
58
- case "noProof":
59
- children.noProof ??= child;
60
- break;
61
- case "cs":
62
- children.cs ??= child;
63
- break;
64
- case "dstrike":
65
- children.dstrike ??= child;
66
- break;
67
- case "effect":
68
- children.effect ??= child;
69
- break;
70
- case "em":
71
- children.em ??= child;
72
- break;
73
- case "emboss":
74
- children.emboss ??= child;
75
- break;
76
- case "highlight":
77
- children.highlight ??= child;
78
- break;
79
- case "i":
80
- children.i ??= child;
81
- break;
82
- case "iCs":
83
- children.iCs ??= child;
84
- break;
85
- case "imprint":
86
- children.imprint ??= child;
87
- break;
88
- case "kern":
89
- children.kern ??= child;
90
- break;
91
- case "lang":
92
- children.lang ??= child;
93
- break;
94
- case "outline":
95
- children.outline ??= child;
96
- break;
97
- case "position":
98
- children.position ??= child;
99
- break;
100
- case "rFonts":
101
- children.rFonts ??= child;
102
- break;
103
- case "rtl":
104
- children.rtl ??= child;
105
- break;
106
- case "rStyle":
107
- children.rStyle ??= child;
108
- break;
109
- case "shadow":
110
- children.shadow ??= child;
111
- break;
112
- case "shd":
113
- children.shd ??= child;
114
- break;
115
- case "smallCaps":
116
- children.smallCaps ??= child;
117
- break;
118
- case "spacing":
119
- children.spacing ??= child;
120
- break;
121
- case "strike":
122
- children.strike ??= child;
123
- break;
124
- case "sz":
125
- children.sz ??= child;
126
- break;
127
- case "szCs":
128
- children.szCs ??= child;
129
- break;
130
- case "u":
131
- children.u ??= child;
132
- break;
133
- case "vanish":
134
- children.vanish ??= child;
135
- break;
136
- case "vertAlign":
137
- children.vertAlign ??= child;
138
- break;
139
- case "w":
140
- children.w ??= child;
141
- break;
142
- }
43
+ /**
44
+ * Which record beside this `w:rPr` reads children out of it.
45
+ *
46
+ * The four owners of a run property set share one handler map, because they
47
+ * share one content model: `CT_RPr` is `EG_RPrBase` plus `w:rPrChange`, and
48
+ * `CT_ParaRPr` opens that with `EG_ParaRPrTrackChanges`. They differ only in
49
+ * which children a *sibling* record has already claimed, and a child claimed
50
+ * twice is written twice. Naming the owner states that once, at the call site
51
+ * that knows it, instead of leaving it to whichever reader ran first.
52
+ */
53
+ const RUN_PROPERTY_OWNERS = {
54
+ /** A `w:r`'s own properties: `Run.propertyChanges` reads the `w:rPrChange`. */
55
+ run: "run",
56
+ /**
57
+ * `w:pPr/w:rPr`. The paragraph's record reads the mark's revision
58
+ * (`ParagraphMarkChange`) and its `w:specVanish`
59
+ * (`ParagraphFormatting.runInWithNext`).
60
+ */
61
+ paragraphMark: "paragraphMark",
62
+ /**
63
+ * A style, a numbering level, a comment's reference mark, the snapshot
64
+ * inside a `w:rPrChange`: nothing beside it reads any of its children.
65
+ */
66
+ standalone: "standalone"
67
+ };
68
+ /**
69
+ * The children each owner's sibling record claims.
70
+ *
71
+ * Not the decision map: that one is total over the schema and lives in
72
+ * {@link parseRunProperties}. This names only the children a given owner reads
73
+ * somewhere else, so both cannot write the same element.
74
+ */
75
+ const OWNED_BY_A_SIBLING_RECORD = {
76
+ run: { rPrChange: ownedElsewhere({
77
+ container: "run-properties",
78
+ child: "rPrChange",
79
+ reader: "runParser#parseRun"
80
+ }) },
81
+ paragraphMark: {
82
+ ins: ownedElsewhere({
83
+ container: "run-properties",
84
+ child: "ins",
85
+ reader: "paragraphProperties#parseParagraphProperties"
86
+ }),
87
+ del: ownedElsewhere({
88
+ container: "run-properties",
89
+ child: "del",
90
+ reader: "paragraphProperties#parseParagraphProperties"
91
+ }),
92
+ moveFrom: ownedElsewhere({
93
+ container: "run-properties",
94
+ child: "moveFrom",
95
+ reader: "paragraphProperties#parseParagraphProperties"
96
+ }),
97
+ moveTo: ownedElsewhere({
98
+ container: "run-properties",
99
+ child: "moveTo",
100
+ reader: "paragraphProperties#parseParagraphProperties"
101
+ })
102
+ },
103
+ standalone: {}
104
+ };
105
+ /**
106
+ * A property stated twice in one `w:rPr` resolves to the last statement.
107
+ *
108
+ * `EG_RPrBase` is an `xsd:choice` referenced `maxOccurs="unbounded"`, so a
109
+ * repeat is valid markup rather than a malformed file with no defined answer,
110
+ * and producers write them: 44 of the 5299 packages in the public corpus hold
111
+ * one, almost all from LibreOffice, and `w:b`, `w:i` and `w:sz` are the names
112
+ * that repeat. 3131 of the 3132 repeats state the same value twice and settle
113
+ * nothing; the one that disagrees is `<w:sz w:val="24"/><w:sz w:val="26"/>` on
114
+ * an Arabic run whose `w:szCs` is 26, so the size that was meant is the later
115
+ * one. That is also the rule folio's style parser already applied, and the two
116
+ * readers now answer alike.
117
+ *
118
+ * The statements the last one beat are not kept. The writer puts a modelled
119
+ * child at its own place in the canonical order, so a kept earlier occurrence
120
+ * would come back *after* the value that beat it and invert what a consumer
121
+ * resolves. Dropping it also settles the ambiguity for everyone downstream:
122
+ * the saved element states the property once, and a reader that takes the
123
+ * first and a reader that takes the last then read the same value.
124
+ *
125
+ * The name comes off the child rather than from the map key, so the guard
126
+ * cannot name a property the handler does not read.
127
+ */
128
+ const readLastOccurrenceOnly = (rPr) => {
129
+ const winner = /* @__PURE__ */ new Map();
130
+ for (const child of getChildElements(rPr)) {
131
+ const namespace = getNamespaceUri(child);
132
+ if (namespace !== void 0 && !WORDPROCESSINGML_NAMESPACE_URIS.has(namespace)) continue;
133
+ winner.set(getLocalName(child.name), child);
143
134
  }
144
- return children;
145
- }
135
+ return (read) => (child) => winner.get(getLocalName(child.name)) === child ? read(child) : void 0;
136
+ };
146
137
  /**
147
138
  * `w:vertAlign` `baseline` is the reserved value that means "no vertical
148
139
  * offset", not a third offset beside `superscript` and `subscript`. It is
@@ -151,191 +142,283 @@ function collectFirstRunPropertyChildren(rPr) {
151
142
  */
152
143
  const isBaselineVertAlign = (vertAlign) => vertAlign === "baseline";
153
144
  /**
154
- * Parse run formatting properties (w:rPr)
145
+ * Read `w:rFonts` into `fontFamily`, resolving each theme slot to the font the
146
+ * theme names when the element did not spell one out.
155
147
  *
156
- * Handles ALL rPr properties:
157
- * - w:b (bold), w:i (italic), w:u (underline with style)
158
- * - w:strike (strikethrough), w:dstrike (double strike)
159
- * - w:vertAlign (superscript/subscript)
160
- * - w:smallCaps, w:caps (capitalization)
161
- * - w:highlight (text highlight color)
162
- * - w:shd (character shading)
163
- * - w:color (text color with theme resolution)
164
- * - w:sz (font size in half-points)
165
- * - w:rFonts (font family with theme resolution)
166
- * - w:spacing (character spacing)
167
- * - w:effect (text effects)
168
- * - And more...
148
+ * @returns whether the element stated any font at all.
169
149
  */
170
- function parseRunProperties(rPr, theme, _styles) {
171
- if (!rPr) return;
172
- const formatting = {};
173
- const propertyChildren = collectFirstRunPropertyChildren(rPr);
174
- const b = propertyChildren.b;
175
- if (b) formatting.bold = parseBooleanElement(b);
176
- const bCs = propertyChildren.bCs;
177
- if (bCs) formatting.boldCs = parseBooleanElement(bCs);
178
- const i = propertyChildren.i;
179
- if (i) formatting.italic = parseBooleanElement(i);
180
- const iCs = propertyChildren.iCs;
181
- if (iCs) formatting.italicCs = parseBooleanElement(iCs);
182
- const u = propertyChildren.u;
183
- if (u) {
184
- const style = narrowEnum(getAttribute(u, "w", "val"), UnderlineStyleSchema);
185
- if (style) {
186
- formatting.underline = { style };
187
- const colorVal = getAttribute(u, "w", "color");
188
- const themeColor = getAttribute(u, "w", "themeColor");
189
- if (colorVal || themeColor) formatting.underline.color = parseColorValue(colorVal, themeColor, getAttribute(u, "w", "themeTint"), getAttribute(u, "w", "themeShade"));
150
+ const readFontFamily = (rFonts, theme, formatting) => {
151
+ const fontFamily = {};
152
+ const ascii = getAttribute(rFonts, "w", "ascii");
153
+ if (ascii) fontFamily.ascii = ascii;
154
+ const hAnsi = getAttribute(rFonts, "w", "hAnsi");
155
+ if (hAnsi) fontFamily.hAnsi = hAnsi;
156
+ const eastAsia = getAttribute(rFonts, "w", "eastAsia");
157
+ if (eastAsia) fontFamily.eastAsia = eastAsia;
158
+ const csFont = getAttribute(rFonts, "w", "cs");
159
+ if (csFont) fontFamily.cs = csFont;
160
+ const hint = narrowEnum(getAttribute(rFonts, "w", "hint"), FontHintSchema);
161
+ if (hint) fontFamily.hint = hint;
162
+ const asciiTheme = narrowEnum(getAttribute(rFonts, "w", "asciiTheme"), FontThemeSchema);
163
+ if (asciiTheme) {
164
+ fontFamily.asciiTheme = asciiTheme;
165
+ if (theme && !fontFamily.ascii) {
166
+ const resolved = resolveThemeFontRef(theme, asciiTheme);
167
+ if (resolved) fontFamily.ascii = resolved;
190
168
  }
191
169
  }
192
- const strike = propertyChildren.strike;
193
- if (strike) formatting.strike = parseBooleanElement(strike);
194
- const dstrike = propertyChildren.dstrike;
195
- if (dstrike) formatting.doubleStrike = parseBooleanElement(dstrike);
196
- const vertAlign = propertyChildren.vertAlign;
197
- if (vertAlign) {
198
- const val = getAttribute(vertAlign, "w", "val");
199
- if (val === "superscript" || val === "subscript" || val === "baseline") formatting.vertAlign = val;
200
- }
201
- const smallCaps = propertyChildren.smallCaps;
202
- if (smallCaps) formatting.smallCaps = parseBooleanElement(smallCaps);
203
- const caps = propertyChildren.caps;
204
- if (caps) formatting.allCaps = parseBooleanElement(caps);
205
- const vanish = propertyChildren.vanish;
206
- if (vanish) formatting.hidden = parseBooleanElement(vanish);
207
- const noProof = propertyChildren.noProof;
208
- if (noProof) formatting.noProof = parseBooleanElement(noProof);
209
- const color = propertyChildren.color;
210
- if (color) formatting.color = parseColorValue(getAttribute(color, "w", "val"), getAttribute(color, "w", "themeColor"), getAttribute(color, "w", "themeTint"), getAttribute(color, "w", "themeShade"));
211
- const highlight = propertyChildren.highlight;
212
- if (highlight) {
213
- const val = narrowEnum(getAttribute(highlight, "w", "val"), HighlightColorSchema);
214
- if (val) formatting.highlight = val;
215
- }
216
- const shd = propertyChildren.shd;
217
- if (shd) {
218
- const shadingResult = parseShading(shd);
219
- if (shadingResult) formatting.shading = shadingResult;
220
- }
221
- const sz = propertyChildren.sz;
222
- if (sz) {
223
- const val = parseNumericAttribute(sz, "w", "val");
224
- if (val !== void 0) formatting.fontSize = val;
225
- }
226
- const szCs = propertyChildren.szCs;
227
- if (szCs) {
228
- const val = parseNumericAttribute(szCs, "w", "val");
229
- if (val !== void 0) formatting.fontSizeCs = val;
230
- }
231
- const rFonts = propertyChildren.rFonts;
232
- if (rFonts) {
233
- const fontFamily = {};
234
- const ascii = getAttribute(rFonts, "w", "ascii");
235
- if (ascii) fontFamily.ascii = ascii;
236
- const hAnsi = getAttribute(rFonts, "w", "hAnsi");
237
- if (hAnsi) fontFamily.hAnsi = hAnsi;
238
- const eastAsia = getAttribute(rFonts, "w", "eastAsia");
239
- if (eastAsia) fontFamily.eastAsia = eastAsia;
240
- const csFont = getAttribute(rFonts, "w", "cs");
241
- if (csFont) fontFamily.cs = csFont;
242
- const hint = narrowEnum(getAttribute(rFonts, "w", "hint"), FontHintSchema);
243
- if (hint) fontFamily.hint = hint;
244
- const asciiTheme = narrowEnum(getAttribute(rFonts, "w", "asciiTheme"), FontThemeSchema);
245
- if (asciiTheme) {
246
- fontFamily.asciiTheme = asciiTheme;
247
- if (theme && !fontFamily.ascii) {
248
- const resolved = resolveThemeFontRef(theme, asciiTheme);
249
- if (resolved) fontFamily.ascii = resolved;
250
- }
170
+ const hAnsiTheme = narrowEnum(getAttribute(rFonts, "w", "hAnsiTheme"), FontThemeSchema);
171
+ if (hAnsiTheme) {
172
+ fontFamily.hAnsiTheme = hAnsiTheme;
173
+ if (theme && !fontFamily.hAnsi) {
174
+ const resolved = resolveThemeFontRef(theme, hAnsiTheme);
175
+ if (resolved) fontFamily.hAnsi = resolved;
251
176
  }
252
- const hAnsiTheme = narrowEnum(getAttribute(rFonts, "w", "hAnsiTheme"), FontThemeSchema);
253
- if (hAnsiTheme) {
254
- fontFamily.hAnsiTheme = hAnsiTheme;
255
- if (theme && !fontFamily.hAnsi) {
256
- const resolved = resolveThemeFontRef(theme, hAnsiTheme);
257
- if (resolved) fontFamily.hAnsi = resolved;
258
- }
259
- }
260
- const eastAsiaTheme = narrowEnum(getAttribute(rFonts, "w", "eastAsiaTheme"), FontThemeSchema);
261
- if (eastAsiaTheme) {
262
- fontFamily.eastAsiaTheme = eastAsiaTheme;
263
- if (theme && !fontFamily.eastAsia) {
264
- const resolved = resolveThemeFontRef(theme, eastAsiaTheme);
265
- if (resolved) fontFamily.eastAsia = resolved;
266
- }
267
- }
268
- const csTheme = narrowEnum(getAttribute(rFonts, "w", "cstheme"), FontThemeSchema);
269
- if (csTheme) {
270
- fontFamily.csTheme = csTheme;
271
- if (theme && !fontFamily.cs) {
272
- const resolved = resolveThemeFontRef(theme, csTheme);
273
- if (resolved) fontFamily.cs = resolved;
274
- }
275
- }
276
- formatting.fontFamily = fontFamily;
277
- }
278
- const lang = propertyChildren.lang;
279
- if (lang) {
280
- const val = truncateLanguageTag(getAttribute(lang, "w", "val") || void 0);
281
- const eastAsia = truncateLanguageTag(getAttribute(lang, "w", "eastAsia") || void 0);
282
- const bidi = truncateLanguageTag(getAttribute(lang, "w", "bidi") || void 0);
283
- if (val || eastAsia || bidi) formatting.language = {
284
- ...val ? { val } : {},
285
- ...eastAsia ? { eastAsia } : {},
286
- ...bidi ? { bidi } : {}
287
- };
288
177
  }
289
- const spacing = propertyChildren.spacing;
290
- if (spacing) {
291
- const val = parseNumericAttribute(spacing, "w", "val");
292
- if (val !== void 0) formatting.spacing = val;
293
- }
294
- const position = propertyChildren.position;
295
- if (position) {
296
- const val = parseNumericAttribute(position, "w", "val");
297
- if (val !== void 0) formatting.position = val;
298
- }
299
- const w = propertyChildren.w;
300
- if (w) {
301
- const val = parseHorizontalScalePercent(getAttribute(w, "w", "val"));
302
- if (val !== void 0) formatting.scale = val;
303
- }
304
- const kern = propertyChildren.kern;
305
- if (kern) {
306
- const val = parseNumericAttribute(kern, "w", "val");
307
- if (val !== void 0) formatting.kerning = val;
308
- }
309
- const effect = propertyChildren.effect;
310
- if (effect) {
311
- const val = narrowEnum(getAttribute(effect, "w", "val"), TextEffectSchema);
312
- if (val) formatting.effect = val;
313
- }
314
- const em = propertyChildren.em;
315
- if (em) {
316
- const val = narrowEnum(getAttribute(em, "w", "val"), EmphasisMarkSchema);
317
- if (val) formatting.emphasisMark = val;
178
+ const eastAsiaTheme = narrowEnum(getAttribute(rFonts, "w", "eastAsiaTheme"), FontThemeSchema);
179
+ if (eastAsiaTheme) {
180
+ fontFamily.eastAsiaTheme = eastAsiaTheme;
181
+ if (theme && !fontFamily.eastAsia) {
182
+ const resolved = resolveThemeFontRef(theme, eastAsiaTheme);
183
+ if (resolved) fontFamily.eastAsia = resolved;
184
+ }
318
185
  }
319
- const emboss = propertyChildren.emboss;
320
- if (emboss) formatting.emboss = parseBooleanElement(emboss);
321
- const imprint = propertyChildren.imprint;
322
- if (imprint) formatting.imprint = parseBooleanElement(imprint);
323
- const outline = propertyChildren.outline;
324
- if (outline) formatting.outline = parseBooleanElement(outline);
325
- const shadow = propertyChildren.shadow;
326
- if (shadow) formatting.shadow = parseBooleanElement(shadow);
327
- const rtl = propertyChildren.rtl;
328
- if (rtl) formatting.rtl = parseBooleanElement(rtl);
329
- const cs = propertyChildren.cs;
330
- if (cs) formatting.cs = parseBooleanElement(cs);
331
- const rStyle = propertyChildren.rStyle;
332
- if (rStyle) {
333
- const val = getAttribute(rStyle, "w", "val");
334
- if (val) formatting.styleId = val;
186
+ const csTheme = narrowEnum(getAttribute(rFonts, "w", "cstheme"), FontThemeSchema);
187
+ if (csTheme) {
188
+ fontFamily.csTheme = csTheme;
189
+ if (theme && !fontFamily.cs) {
190
+ const resolved = resolveThemeFontRef(theme, csTheme);
191
+ if (resolved) fontFamily.cs = resolved;
192
+ }
335
193
  }
336
- return Object.keys(formatting).length > 0 ? formatting : void 0;
194
+ if (Object.keys(fontFamily).length === 0) return false;
195
+ formatting.fontFamily = fontFamily;
196
+ return true;
197
+ };
198
+ /** @returns whether `w:u` named an underline style the model admits. */
199
+ const readUnderline = (u, formatting) => {
200
+ const style = narrowEnum(getAttribute(u, "w", "val"), UnderlineStyleSchema);
201
+ if (!style) return false;
202
+ formatting.underline = { style };
203
+ const colorVal = getAttribute(u, "w", "color");
204
+ const themeColor = getAttribute(u, "w", "themeColor");
205
+ if (colorVal || themeColor) formatting.underline.color = parseColorValue({
206
+ rgb: colorVal,
207
+ themeColor,
208
+ themeTint: getAttribute(u, "w", "themeTint"),
209
+ themeShade: getAttribute(u, "w", "themeShade"),
210
+ element: u.name ?? "w:u"
211
+ });
212
+ return true;
213
+ };
214
+ /** @returns whether `w:lang` named a tag for any of the three scripts. */
215
+ const readLanguage = (lang, formatting) => {
216
+ const val = truncateLanguageTag(getAttribute(lang, "w", "val") || void 0);
217
+ const eastAsia = truncateLanguageTag(getAttribute(lang, "w", "eastAsia") || void 0);
218
+ const bidi = truncateLanguageTag(getAttribute(lang, "w", "bidi") || void 0);
219
+ if (!val && !eastAsia && !bidi) return false;
220
+ formatting.language = {
221
+ ...val ? { val } : {},
222
+ ...eastAsia ? { eastAsia } : {},
223
+ ...bidi ? { bidi } : {}
224
+ };
225
+ return true;
226
+ };
227
+ /**
228
+ * The one reader of a run property set (`w:rPr`).
229
+ *
230
+ * Every owner reads through here — a run, the paragraph mark, a style, a
231
+ * numbering level, a comment's reference mark and the snapshot inside either
232
+ * kind of `w:rPrChange` — so none of them can grow its own idea of which
233
+ * children exist, which values it admits, or which of two statements of one
234
+ * property wins. The style parser used to keep a copy of this function, and
235
+ * the copies had drifted on all three.
236
+ *
237
+ * Every child the content model declares carries a decision: a handler that
238
+ * reads it into {@link TextFormatting}, `ownedElsewhere` when the owner's
239
+ * sibling record reads it, or `CAPTURE` for markup folio models nothing for.
240
+ * A handler that looked and took nothing answers `CAPTURE` as well — `<w:sz/>`
241
+ * states no size and `<w:highlight w:val="chartreuse"/>` states a value the
242
+ * reader's enumeration does not admit, and neither can be decided by the
243
+ * child's name. What no reader took goes to `TextFormatting.preserved` at its
244
+ * schema ordinal, so a rebuild puts it back between the same two siblings.
245
+ *
246
+ * A property stated twice resolves to the last statement; see
247
+ * {@link readLastOccurrenceOnly} for the evidence and for why the statements
248
+ * it beat are not kept.
249
+ *
250
+ * An element that states nothing at all still yields a record: `undefined` here
251
+ * means the owner carried no `w:rPr`, never that the one it carried was empty.
252
+ */
253
+ function parseRunProperties(rPr, theme, owner) {
254
+ if (!rPr) return;
255
+ const formatting = {};
256
+ const wins = readLastOccurrenceOnly(rPr);
257
+ const preserved = dispatchChildren({
258
+ element: rPr,
259
+ container: "run-properties",
260
+ handlers: {
261
+ ins: CAPTURE,
262
+ del: CAPTURE,
263
+ moveFrom: CAPTURE,
264
+ moveTo: CAPTURE,
265
+ rStyle: wins((child) => {
266
+ const val = getAttribute(child, "w", "val");
267
+ if (val) formatting.styleId = val;
268
+ return keptUnless(Boolean(val));
269
+ }),
270
+ rFonts: wins((child) => keptUnless(readFontFamily(child, theme, formatting))),
271
+ b: wins((child) => {
272
+ formatting.bold = parseBooleanElement(child);
273
+ }),
274
+ bCs: wins((child) => {
275
+ formatting.boldCs = parseBooleanElement(child);
276
+ }),
277
+ i: wins((child) => {
278
+ formatting.italic = parseBooleanElement(child);
279
+ }),
280
+ iCs: wins((child) => {
281
+ formatting.italicCs = parseBooleanElement(child);
282
+ }),
283
+ caps: wins((child) => {
284
+ formatting.allCaps = parseBooleanElement(child);
285
+ }),
286
+ smallCaps: wins((child) => {
287
+ formatting.smallCaps = parseBooleanElement(child);
288
+ }),
289
+ strike: wins((child) => {
290
+ formatting.strike = parseBooleanElement(child);
291
+ }),
292
+ dstrike: wins((child) => {
293
+ formatting.doubleStrike = parseBooleanElement(child);
294
+ }),
295
+ outline: wins((child) => {
296
+ formatting.outline = parseBooleanElement(child);
297
+ }),
298
+ shadow: wins((child) => {
299
+ formatting.shadow = parseBooleanElement(child);
300
+ }),
301
+ emboss: wins((child) => {
302
+ formatting.emboss = parseBooleanElement(child);
303
+ }),
304
+ imprint: wins((child) => {
305
+ formatting.imprint = parseBooleanElement(child);
306
+ }),
307
+ noProof: wins((child) => {
308
+ formatting.noProof = parseBooleanElement(child);
309
+ }),
310
+ vanish: wins((child) => {
311
+ formatting.hidden = parseBooleanElement(child);
312
+ }),
313
+ rtl: wins((child) => {
314
+ formatting.rtl = parseBooleanElement(child);
315
+ }),
316
+ cs: wins((child) => {
317
+ formatting.cs = parseBooleanElement(child);
318
+ }),
319
+ /** Whether the run follows the section's document grid; no layout slot. */
320
+ snapToGrid: CAPTURE,
321
+ /** Web-view-only hiding, distinct from `w:vanish`; nothing reads it. */
322
+ webHidden: CAPTURE,
323
+ color: wins((child) => {
324
+ const color = parseColorValue({
325
+ rgb: getAttribute(child, "w", "val"),
326
+ themeColor: getAttribute(child, "w", "themeColor"),
327
+ themeTint: getAttribute(child, "w", "themeTint"),
328
+ themeShade: getAttribute(child, "w", "themeShade"),
329
+ element: child.name ?? "w:color"
330
+ });
331
+ if (Object.keys(color).length === 0) return CAPTURE;
332
+ formatting.color = color;
333
+ }),
334
+ spacing: wins((child) => {
335
+ const val = parseNumericAttribute(child, "w", "val");
336
+ if (val !== void 0) formatting.spacing = val;
337
+ return keptUnless(val !== void 0);
338
+ }),
339
+ w: wins((child) => {
340
+ const val = parseHorizontalScalePercent(getAttribute(child, "w", "val"));
341
+ if (val !== void 0) formatting.scale = val;
342
+ return keptUnless(val !== void 0);
343
+ }),
344
+ kern: wins((child) => {
345
+ const val = parseNumericAttribute(child, "w", "val");
346
+ if (val !== void 0) formatting.kerning = val;
347
+ return keptUnless(val !== void 0);
348
+ }),
349
+ position: wins((child) => {
350
+ const val = parseNumericAttribute(child, "w", "val");
351
+ if (val !== void 0) formatting.position = val;
352
+ return keptUnless(val !== void 0);
353
+ }),
354
+ sz: wins((child) => {
355
+ const val = parseNumericAttribute(child, "w", "val");
356
+ if (val !== void 0) formatting.fontSize = val;
357
+ return keptUnless(val !== void 0);
358
+ }),
359
+ szCs: wins((child) => {
360
+ const val = parseNumericAttribute(child, "w", "val");
361
+ if (val !== void 0) formatting.fontSizeCs = val;
362
+ return keptUnless(val !== void 0);
363
+ }),
364
+ highlight: wins((child) => {
365
+ const val = narrowEnum(getAttribute(child, "w", "val"), HighlightColorSchema);
366
+ if (val) formatting.highlight = val;
367
+ return keptUnless(Boolean(val));
368
+ }),
369
+ u: wins((child) => keptUnless(readUnderline(child, formatting))),
370
+ effect: wins((child) => {
371
+ const val = narrowEnum(getAttribute(child, "w", "val"), TextEffectSchema);
372
+ if (val) formatting.effect = val;
373
+ return keptUnless(Boolean(val));
374
+ }),
375
+ /** A text border around the run; `BorderSpec` is a paragraph/table slot. */
376
+ bdr: CAPTURE,
377
+ shd: wins((child) => {
378
+ const shading = parseShading(child);
379
+ if (shading) formatting.shading = shading;
380
+ return keptUnless(shading !== void 0);
381
+ }),
382
+ /** Compress the run's text into a fixed width; no layout slot holds it. */
383
+ fitText: CAPTURE,
384
+ vertAlign: wins((child) => {
385
+ const val = getAttribute(child, "w", "val");
386
+ if (val === "superscript" || val === "subscript" || val === "baseline") {
387
+ formatting.vertAlign = val;
388
+ return;
389
+ }
390
+ return CAPTURE;
391
+ }),
392
+ em: wins((child) => {
393
+ const val = narrowEnum(getAttribute(child, "w", "val"), EmphasisMarkSchema);
394
+ if (val) formatting.emphasisMark = val;
395
+ return keptUnless(Boolean(val));
396
+ }),
397
+ lang: wins((child) => keptUnless(readLanguage(child, formatting))),
398
+ /** East Asian two-lines-in-one and horizontal-in-vertical typesetting. */
399
+ eastAsianLayout: CAPTURE,
400
+ /**
401
+ * The run-in heading marker. On a paragraph mark the paragraph's record
402
+ * reads it (`runInWithNext`); under a run the schema declares it and folio
403
+ * models nothing for it.
404
+ */
405
+ specVanish: owner === RUN_PROPERTY_OWNERS.paragraphMark ? wins(() => void 0) : CAPTURE,
406
+ /** The run is part of an equation; folio has no run-level maths slot. */
407
+ oMath: CAPTURE,
408
+ /**
409
+ * The tracked property change. A run's record reads it into
410
+ * `Run.propertyChanges`; a paragraph mark has no such record, so its
411
+ * snapshot is kept whole rather than dropped with the revision.
412
+ */
413
+ rPrChange: CAPTURE,
414
+ ...OWNED_BY_A_SIBLING_RECORD[owner]
415
+ },
416
+ capturePosition: sequencePositions("run-properties", rPr)
417
+ });
418
+ if (preserved) formatting.preserved = preserved;
419
+ return formatting;
337
420
  }
338
- function parseRunPropertyChanges(rPr, theme, styles, currentFormatting) {
421
+ function parseRunPropertyChanges(rPr, theme, currentFormatting) {
339
422
  if (!rPr) return;
340
423
  const changes = findChildren(rPr, "w", "rPrChange").map((changeElement) => {
341
424
  const previousRPr = findChild(changeElement, "w", "rPr");
@@ -343,11 +426,11 @@ function parseRunPropertyChanges(rPr, theme, styles, currentFormatting) {
343
426
  type: "runPropertyChange",
344
427
  info: parsePropertyChangeInfo(changeElement)
345
428
  };
346
- const previousFormatting = parseRunProperties(previousRPr, theme, styles ?? void 0);
429
+ const previousFormatting = parseRunProperties(previousRPr, theme, RUN_PROPERTY_OWNERS.standalone);
347
430
  if (previousFormatting) change.previousFormatting = previousFormatting;
348
431
  if (currentFormatting) change.currentFormatting = currentFormatting;
349
432
  return change;
350
- }).filter((change) => change.previousFormatting || change.currentFormatting);
433
+ });
351
434
  return changes.length > 0 ? changes : void 0;
352
435
  }
353
436
  /**
@@ -648,22 +731,23 @@ function parseRunContents(runElement, rels, media, rootXmlns = {}) {
648
731
  * Parse a run element (w:r)
649
732
  *
650
733
  * @param node - The w:r XML element
651
- * @param styles - Style map for resolving style references
734
+ * @param _styles - Unread: a run's properties are parsed as the source wrote
735
+ * them, and style resolution happens above this parser
652
736
  * @param theme - Theme for resolving theme colors/fonts
653
737
  * @param rels - Relationship map for resolving image references
654
738
  * @param media - Media files map for image data
655
739
  * @returns Parsed Run object
656
740
  */
657
- function parseRun(node, styles, theme, rels = null, media = null, rootXmlns = {}) {
741
+ function parseRun(node, _styles, theme, rels = null, media = null, rootXmlns = {}) {
658
742
  const run = {
659
743
  type: "run",
660
744
  content: []
661
745
  };
662
746
  const rPr = findChild(node, "w", "rPr");
663
747
  if (rPr) {
664
- const formattingResult = parseRunProperties(rPr, theme, styles ?? void 0);
748
+ const formattingResult = parseRunProperties(rPr, theme, RUN_PROPERTY_OWNERS.run);
665
749
  if (formattingResult) run.formatting = formattingResult;
666
- const propertyChangesResult = parseRunPropertyChanges(rPr, theme, styles, run.formatting);
750
+ const propertyChangesResult = parseRunPropertyChanges(rPr, theme, run.formatting);
667
751
  if (propertyChangesResult) run.propertyChanges = propertyChangesResult;
668
752
  }
669
753
  run.content = parseRunContents(node, rels, media, mergeXmlnsDeclarations(rootXmlns, node));
@@ -736,4 +820,4 @@ function getFieldCharType(run) {
736
820
  return run.content.find((c) => c.type === "fieldChar")?.charType ?? null;
737
821
  }
738
822
  //#endregion
739
- export { getFieldCharType, getImages, getRunText, hasContent, hasFieldChar, hasImage, isBaselineVertAlign, parseRun, parseRunProperties };
823
+ export { RUN_PROPERTY_OWNERS, getFieldCharType, getImages, getRunText, hasContent, hasFieldChar, hasImage, isBaselineVertAlign, parseRun, parseRunProperties };