@stll/folio-core 0.45.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (451) hide show
  1. package/dist/ai-edits/apply.js +85 -43
  2. package/dist/ai-edits/headless.js +2 -2
  3. package/dist/ai-edits/read.d.ts +1 -0
  4. package/dist/ai-edits/read.js +1 -0
  5. package/dist/ai-edits/snapshot.js +32 -27
  6. package/dist/ai-edits/table-cell-mutations.js +15 -7
  7. package/dist/ai-edits/table-geometry.js +21 -18
  8. package/dist/ai-edits/table-template.js +2 -2
  9. package/dist/compare/compare.js +2 -5
  10. package/dist/compare/content-alignment.js +108 -12
  11. package/dist/compare/content-types.d.ts +8 -2
  12. package/dist/compare/content.js +2 -11
  13. package/dist/compare/plan.js +7 -4
  14. package/dist/compare/scenario.js +2 -5
  15. package/dist/compare/section-boundary-properties.js +1 -2
  16. package/dist/compare/types.d.ts +9 -1
  17. package/dist/compare/types.js +12 -1
  18. package/dist/compat/eigenpal.d.ts +2 -1
  19. package/dist/compat/eigenpal.js +2 -1
  20. package/dist/content-controls/checkboxDisplay.d.ts +17 -0
  21. package/dist/content-controls/checkboxDisplay.js +46 -0
  22. package/dist/content-controls/findContentControls.js +3 -1
  23. package/dist/content-controls/mutateContentControls.js +57 -43
  24. package/dist/controller/contentControlWidgetController.d.ts +1 -0
  25. package/dist/controller/contentControlWidgetController.js +3 -0
  26. package/dist/controller/hiddenEditorApi.js +3 -1
  27. package/dist/controller/hiddenEditorManager.d.ts +1 -1
  28. package/dist/controller/hiddenEditorManager.js +6 -3
  29. package/dist/controller/layoutPipeline.js +8 -3
  30. package/dist/display-list/build/buildDisplayList.js +20 -1
  31. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  32. package/dist/display-list/build/imagePrimitives.js +38 -18
  33. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  34. package/dist/display-list/build/paragraphPrimitives.js +113 -14
  35. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  36. package/dist/display-list/build/previewPrimitives.js +89 -0
  37. package/dist/display-list/build/strokes.d.ts +177 -8
  38. package/dist/display-list/build/strokes.js +167 -47
  39. package/dist/display-list/build/tablePrimitives.js +4 -2
  40. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  41. package/dist/display-list/build/textDecorations.d.ts +15 -1
  42. package/dist/display-list/build/textDecorations.js +15 -1
  43. package/dist/display-list/dom/renderDisplayListToDom.js +11 -21
  44. package/dist/display-list/primitives.d.ts +13 -2
  45. package/dist/display-list/primitives.js +36 -1
  46. package/dist/display-list/types.d.ts +17 -0
  47. package/dist/document-operations.js +2 -1
  48. package/dist/docx/attributeRemainder.d.ts +76 -0
  49. package/dist/docx/attributeRemainder.js +111 -0
  50. package/dist/docx/blockContentParser.d.ts +3 -1
  51. package/dist/docx/blockContentParser.js +102 -106
  52. package/dist/docx/blockPlainText.d.ts +3 -4
  53. package/dist/docx/blockPlainText.js +3 -0
  54. package/dist/docx/borderParser.js +26 -11
  55. package/dist/docx/builtInStyles.d.ts +8 -16
  56. package/dist/docx/builtInStyles.js +54 -17
  57. package/dist/docx/commentAnchorIndex.d.ts +30 -0
  58. package/dist/docx/commentAnchorIndex.js +50 -0
  59. package/dist/docx/commentParser.d.ts +1 -1
  60. package/dist/docx/commentParser.js +56 -39
  61. package/dist/docx/commentRangeIntegrity.d.ts +16 -1
  62. package/dist/docx/commentRangeIntegrity.js +42 -1
  63. package/dist/docx/commentRangeJoin.d.ts +9 -0
  64. package/dist/docx/commentRangeJoin.js +33 -0
  65. package/dist/docx/commentReferenceCompletion.d.ts +9 -0
  66. package/dist/docx/commentReferenceCompletion.js +47 -0
  67. package/dist/docx/commentReferenceNormalization.js +3 -1
  68. package/dist/docx/commentReplyMarkers.js +11 -19
  69. package/dist/docx/compatibility.js +56 -41
  70. package/dist/docx/containerChildren.d.ts +208 -0
  71. package/dist/docx/containerChildren.gen.d.ts +43 -0
  72. package/dist/docx/containerChildren.gen.js +263 -0
  73. package/dist/docx/containerChildren.js +153 -0
  74. package/dist/docx/diagramPreview.d.ts +14 -2
  75. package/dist/docx/diagramPreview.js +81 -169
  76. package/dist/docx/documentParser.d.ts +1 -1
  77. package/dist/docx/documentParser.js +7 -4
  78. package/dist/docx/drawingAnchor.d.ts +87 -0
  79. package/dist/docx/drawingAnchor.js +201 -0
  80. package/dist/docx/drawingUtils.d.ts +43 -38
  81. package/dist/docx/drawingUtils.js +205 -118
  82. package/dist/docx/ensureParaIds.js +17 -7
  83. package/dist/docx/fieldParser.d.ts +1 -1
  84. package/dist/docx/fieldParser.js +4 -4
  85. package/dist/docx/fieldState.d.ts +26 -0
  86. package/dist/docx/fieldState.js +53 -0
  87. package/dist/docx/fontTableParser.js +102 -41
  88. package/dist/docx/footnoteParser.d.ts +1 -1
  89. package/dist/docx/footnoteParser.js +10 -6
  90. package/dist/docx/graphicFrameLocks.d.ts +16 -4
  91. package/dist/docx/graphicFrameLocks.js +19 -6
  92. package/dist/docx/groupDrawingParser.js +4 -3
  93. package/dist/docx/headerFooterParser.js +1 -1
  94. package/dist/docx/headerFooterReferenceNormalization.js +1 -0
  95. package/dist/docx/hyperlinkParser.d.ts +66 -9
  96. package/dist/docx/hyperlinkParser.js +153 -26
  97. package/dist/docx/imageParser.js +160 -115
  98. package/dist/docx/index.d.ts +2 -1
  99. package/dist/docx/index.js +2 -1
  100. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  101. package/dist/docx/inlineContentRemovals.js +46 -0
  102. package/dist/docx/inlineWrapperContent.d.ts +166 -0
  103. package/dist/docx/inlineWrapperContent.js +165 -0
  104. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  105. package/dist/docx/inlineWrapperParser.js +60 -0
  106. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  107. package/dist/docx/normalizeBaseDirection.js +12 -1
  108. package/dist/docx/numberingParser.d.ts +25 -2
  109. package/dist/docx/numberingParser.js +264 -361
  110. package/dist/docx/numberingReference.d.ts +9 -16
  111. package/dist/docx/numberingReference.js +17 -16
  112. package/dist/docx/numberingReferenceNormalization.js +7 -7
  113. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  114. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  115. package/dist/docx/paraIdAttribute.d.ts +111 -0
  116. package/dist/docx/paraIdAttribute.js +142 -0
  117. package/dist/docx/paragraphParser.d.ts +10 -25
  118. package/dist/docx/paragraphParser.js +421 -496
  119. package/dist/docx/paragraphProperties.d.ts +23 -0
  120. package/dist/docx/paragraphProperties.js +279 -0
  121. package/dist/docx/paragraphPropertySource.js +7 -1
  122. package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
  123. package/dist/docx/paragraphTextBoxEnrichment.js +20 -59
  124. package/dist/docx/paragraphTraversal.d.ts +14 -10
  125. package/dist/docx/paragraphTraversal.js +53 -52
  126. package/dist/docx/parseWarningMessage.js +5 -1
  127. package/dist/docx/parserEnums.d.ts +6 -8
  128. package/dist/docx/parserEnums.js +4 -6
  129. package/dist/docx/preservedRunContent.d.ts +32 -0
  130. package/dist/docx/preservedRunContent.js +96 -0
  131. package/dist/docx/previewBudget.d.ts +44 -23
  132. package/dist/docx/previewBudget.js +61 -30
  133. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  134. package/dist/docx/propertyElementAttributes.js +114 -0
  135. package/dist/docx/renderedPageBreakNormalization.js +4 -6
  136. package/dist/docx/rezip.d.ts +28 -2
  137. package/dist/docx/rezip.js +152 -27
  138. package/dist/docx/runConsolidator.d.ts +42 -2
  139. package/dist/docx/runConsolidator.js +60 -6
  140. package/dist/docx/runParser.d.ts +55 -19
  141. package/dist/docx/runParser.js +394 -306
  142. package/dist/docx/runPayload.d.ts +5 -0
  143. package/dist/docx/runPayload.js +4 -0
  144. package/dist/docx/sdtProperties.d.ts +39 -5
  145. package/dist/docx/sdtProperties.js +205 -84
  146. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  147. package/dist/docx/sdtPropertiesPatch.js +68 -112
  148. package/dist/docx/sectionParser.d.ts +1 -2
  149. package/dist/docx/sectionParser.js +241 -238
  150. package/dist/docx/selectiveSave.js +3 -2
  151. package/dist/docx/selectiveXmlPatch.d.ts +66 -3
  152. package/dist/docx/selectiveXmlPatch.js +276 -133
  153. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  154. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  155. package/dist/docx/serializer/borderSerializer.js +12 -10
  156. package/dist/docx/serializer/commentSerializer.js +5 -7
  157. package/dist/docx/serializer/documentSerializer.js +11 -11
  158. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  159. package/dist/docx/serializer/headerFooterSerializer.js +10 -9
  160. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  161. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  162. package/dist/docx/serializer/noteSerializer.js +11 -8
  163. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  164. package/dist/docx/serializer/numberingSerializer.js +81 -79
  165. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  166. package/dist/docx/serializer/paragraphSerializer.js +156 -236
  167. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  168. package/dist/docx/serializer/runSerializer.js +134 -75
  169. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  170. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  171. package/dist/docx/serializer/sectionPropertiesSerializer.js +42 -49
  172. package/dist/docx/serializer/settingsSerializer.js +6 -4
  173. package/dist/docx/serializer/stylesSerializer.js +8 -11
  174. package/dist/docx/serializer/tableSerializer.js +283 -105
  175. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  176. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  177. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  178. package/dist/docx/serializer/xmlUtils.js +1 -1
  179. package/dist/docx/server/createBilingualDocument.js +20 -16
  180. package/dist/docx/server/materializeYjsDocx.d.ts +1 -1
  181. package/dist/docx/server/materializeYjsDocx.js +9 -1
  182. package/dist/docx/server/migrateYjsAttrSchema.d.ts +55 -0
  183. package/dist/docx/server/migrateYjsAttrSchema.js +95 -0
  184. package/dist/docx/settingsParser.js +7 -4
  185. package/dist/docx/shadingParser.d.ts +2 -1
  186. package/dist/docx/shadingParser.js +43 -7
  187. package/dist/docx/shapeParser.js +13 -8
  188. package/dist/docx/strictNames.d.ts +11 -0
  189. package/dist/docx/strictNames.gen.d.ts +45 -0
  190. package/dist/docx/strictNames.gen.js +50 -0
  191. package/dist/docx/strictNames.js +43 -0
  192. package/dist/docx/strictValueEncodings.gen.js +133 -131
  193. package/dist/docx/styleParser.js +17 -349
  194. package/dist/docx/tableParser.d.ts +11 -2
  195. package/dist/docx/tableParser.js +665 -220
  196. package/dist/docx/textBoxParser.d.ts +28 -3
  197. package/dist/docx/textBoxParser.js +69 -9
  198. package/dist/docx/themeColorAttribute.d.ts +13 -0
  199. package/dist/docx/themeColorAttribute.js +24 -0
  200. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  201. package/dist/docx/unzip.js +5 -4
  202. package/dist/docx/vmlImageParser.d.ts +30 -5
  203. package/dist/docx/vmlImageParser.js +91 -32
  204. package/dist/docx/vmlPreview.js +2 -2
  205. package/dist/docx/wrapPolygon.d.ts +30 -0
  206. package/dist/docx/wrapPolygon.js +70 -0
  207. package/dist/docx/xmlEncoding.d.ts +5 -0
  208. package/dist/docx/xmlEncoding.js +12 -0
  209. package/dist/docx/xmlParser.d.ts +23 -1
  210. package/dist/docx/xmlParser.js +31 -2
  211. package/dist/fonts/embeddedFonts.js +3 -3
  212. package/dist/headless-layout.js +12 -1
  213. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  214. package/dist/i18n/messages/catalogs.gen.js +102 -34
  215. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  216. package/dist/index.d.ts +2 -1
  217. package/dist/index.js +2 -1
  218. package/dist/internal/headlessRevisionResolution.js +9 -0
  219. package/dist/internal/pageBreakRunSourceDescendantIndex.js +7 -2
  220. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  221. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  222. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  223. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  224. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  225. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  226. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  227. package/dist/layout-bridge/convert/toFlowBlocks.js +267 -101
  228. package/dist/layout-engine/index.d.ts +2 -2
  229. package/dist/layout-engine/index.js +53 -17
  230. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  231. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  232. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  233. package/dist/layout-engine/measure/tableCellFloating.js +2 -0
  234. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  235. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  236. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  237. package/dist/layout-engine/paragraphSequence.js +3 -2
  238. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  239. package/dist/layout-engine/section-breaks.d.ts +49 -2
  240. package/dist/layout-engine/section-breaks.js +55 -4
  241. package/dist/layout-engine/types.d.ts +69 -17
  242. package/dist/layout-engine/types.js +16 -1
  243. package/dist/layout-painter/borderStroke.d.ts +18 -4
  244. package/dist/layout-painter/renderImage.d.ts +5 -1
  245. package/dist/layout-painter/renderImage.js +10 -3
  246. package/dist/layout-painter/renderPage.d.ts +2 -0
  247. package/dist/layout-painter/renderPage.js +10 -4
  248. package/dist/layout-painter/renderParagraph.d.ts +14 -1
  249. package/dist/layout-painter/renderParagraph.js +34 -28
  250. package/dist/layout-painter/renderTable.d.ts +4 -1
  251. package/dist/layout-painter/renderTable.js +22 -22
  252. package/dist/layout-painter/renderTextBox.js +5 -3
  253. package/dist/managers/autoSaveCodec.d.ts +9 -1
  254. package/dist/managers/autoSaveCodec.js +12 -4
  255. package/dist/markdown/renderBlock.js +3 -0
  256. package/dist/markdown/renderRuns.d.ts +1 -1
  257. package/dist/markdown/renderRuns.js +34 -6
  258. package/dist/markdown/renderTable.js +24 -6
  259. package/dist/markdown/trailers.js +4 -1
  260. package/dist/model.d.ts +3 -3
  261. package/dist/model.js +2 -2
  262. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  263. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  264. package/dist/pdf/images.js +142 -6
  265. package/dist/prosemirror/attrs/index.d.ts +34 -5
  266. package/dist/prosemirror/attrs/index.js +639 -48
  267. package/dist/prosemirror/authoredTransformAttrs.d.ts +28 -0
  268. package/dist/prosemirror/authoredTransformAttrs.js +64 -0
  269. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  270. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  271. package/dist/prosemirror/commands/comments.js +68 -53
  272. package/dist/prosemirror/commands/contentControls.js +33 -20
  273. package/dist/prosemirror/commands/image.d.ts +10 -3
  274. package/dist/prosemirror/commands/image.js +46 -29
  275. package/dist/prosemirror/commands/pageBreak.js +1 -1
  276. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  277. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  278. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  279. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  280. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  281. package/dist/prosemirror/commentReferenceAttrs.d.ts +8 -0
  282. package/dist/prosemirror/commentReferenceAttrs.js +33 -0
  283. package/dist/prosemirror/commentReferenceIntegrity.d.ts +47 -0
  284. package/dist/prosemirror/commentReferenceIntegrity.js +43 -0
  285. package/dist/prosemirror/conversion/fromProseDoc.d.ts +17 -12
  286. package/dist/prosemirror/conversion/fromProseDoc.js +553 -207
  287. package/dist/prosemirror/conversion/index.d.ts +2 -2
  288. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  289. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  290. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  291. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  292. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  293. package/dist/prosemirror/conversion/toProseDoc.d.ts +7 -9
  294. package/dist/prosemirror/conversion/toProseDoc.js +801 -411
  295. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  296. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  297. package/dist/prosemirror/extensions/StarterKit.js +14 -58
  298. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  299. package/dist/prosemirror/extensions/core/ParagraphExtension.js +21 -16
  300. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +48 -29
  301. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -1
  302. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +5 -3
  303. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  304. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +1 -0
  305. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  306. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  307. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  308. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  309. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  310. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  311. package/dist/prosemirror/extensions/markRegistry.d.ts +65 -0
  312. package/dist/prosemirror/extensions/markRegistry.js +138 -0
  313. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +18 -0
  314. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +77 -0
  315. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  316. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  317. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  318. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  319. package/dist/prosemirror/extensions/marks/markUtils.d.ts +2 -1
  320. package/dist/prosemirror/extensions/marks/markUtils.js +49 -5
  321. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  322. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  323. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  324. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  325. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  326. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +11 -0
  327. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +97 -0
  328. package/dist/prosemirror/extensions/nodes/FieldExtension.js +9 -7
  329. package/dist/prosemirror/extensions/nodes/ImageExtension.js +24 -1
  330. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  331. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  332. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +32 -0
  333. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +67 -0
  334. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +16 -0
  335. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +60 -0
  336. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  337. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  338. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  339. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  340. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +7 -0
  341. package/dist/prosemirror/extensions/nodes/TableExtension.js +142 -123
  342. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +9 -1
  343. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  344. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  345. package/dist/prosemirror/extensions/types.d.ts +12 -3
  346. package/dist/prosemirror/index.d.ts +4 -2
  347. package/dist/prosemirror/index.js +2 -1
  348. package/dist/prosemirror/inlineWrapperStack.d.ts +39 -0
  349. package/dist/prosemirror/inlineWrapperStack.js +92 -0
  350. package/dist/prosemirror/listMarker.d.ts +2 -2
  351. package/dist/prosemirror/listMarker.js +7 -8
  352. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  353. package/dist/prosemirror/listState.d.ts +62 -0
  354. package/dist/prosemirror/listState.js +49 -0
  355. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  356. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  357. package/dist/prosemirror/numberedRefFields.js +4 -4
  358. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  359. package/dist/prosemirror/numberingAttr.js +74 -0
  360. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  361. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  362. package/dist/prosemirror/pageBreakRunProjection.d.ts +17 -7
  363. package/dist/prosemirror/pageBreakRunProjection.js +19 -9
  364. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  365. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  366. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  367. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  368. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  369. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  370. package/dist/prosemirror/replacedAnnotations.d.ts +59 -0
  371. package/dist/prosemirror/replacedAnnotations.js +183 -0
  372. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  373. package/dist/prosemirror/revisionCarriers.js +86 -60
  374. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +5 -1
  375. package/dist/prosemirror/runFormattingInlineCarriers.js +7 -1
  376. package/dist/prosemirror/runIdentity.d.ts +28 -0
  377. package/dist/prosemirror/runIdentity.js +36 -0
  378. package/dist/prosemirror/runStyleFormatting.js +1 -1
  379. package/dist/prosemirror/schema/index.d.ts +3 -3
  380. package/dist/prosemirror/schema/marks.d.ts +47 -4
  381. package/dist/prosemirror/schema/nodes.d.ts +309 -26
  382. package/dist/prosemirror/schema/nodes.js +16 -1
  383. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  384. package/dist/prosemirror/sectionCarrier.js +40 -0
  385. package/dist/prosemirror/selectionState.d.ts +3 -0
  386. package/dist/prosemirror/selectionState.js +4 -1
  387. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  388. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  389. package/dist/prosemirror/tableResize.js +5 -6
  390. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +4 -0
  391. package/dist/prosemirror/trackedRunInlineAtoms.js +4 -0
  392. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  393. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  394. package/dist/prosemirror/validation.js +31 -6
  395. package/dist/prosemirror/yjsDocumentMetadata.d.ts +73 -0
  396. package/dist/prosemirror/yjsDocumentMetadata.js +592 -0
  397. package/dist/prosemirror/zeroWidthAnchors.js +6 -0
  398. package/dist/render-dom/commentAnchorAttributes.d.ts +37 -0
  399. package/dist/render-dom/commentAnchorAttributes.js +54 -0
  400. package/dist/server.d.ts +3 -1
  401. package/dist/server.js +3 -1
  402. package/dist/style-sets/extract.js +4 -4
  403. package/dist/style-sets/stellaStyle.js +36 -23
  404. package/dist/types/colors.d.ts +2 -2
  405. package/dist/types/content.d.ts +2 -2
  406. package/dist/types/documentEnumValues.d.ts +53 -26
  407. package/dist/types/documentEnumValues.js +72 -174
  408. package/dist/types/formatting.d.ts +2 -2
  409. package/dist/types/index.d.ts +9 -2
  410. package/dist/utils/borderCss.d.ts +246 -0
  411. package/dist/utils/borderCss.js +325 -0
  412. package/dist/utils/clipboard.d.ts +9 -1
  413. package/dist/utils/clipboard.js +27 -1
  414. package/dist/utils/colorResolver.d.ts +4 -3
  415. package/dist/utils/colorResolver.js +45 -76
  416. package/dist/utils/createDocument.js +24 -6
  417. package/dist/utils/findReplace.js +52 -10
  418. package/dist/utils/formatToStyle.d.ts +84 -2
  419. package/dist/utils/formatToStyle.js +133 -52
  420. package/dist/utils/headingCollector.js +3 -2
  421. package/dist/utils/imageLuminance.d.ts +15 -0
  422. package/dist/utils/imageLuminance.js +32 -0
  423. package/dist/utils/mergeDocumentContent.js +12 -20
  424. package/dist/utils/paragraphFormattingMerge.js +27 -6
  425. package/dist/utils/replaceText.js +1 -0
  426. package/dist/utils/tableOperations.d.ts +5 -3
  427. package/dist/utils/tableOperations.js +14 -1
  428. package/dist/utils/tablePlacement.d.ts +7 -0
  429. package/dist/utils/tablePlacement.js +14 -0
  430. package/dist/utils/textDirectionFlow.d.ts +15 -0
  431. package/dist/utils/textDirectionFlow.js +38 -0
  432. package/dist/utils/textFormattingMerge.js +16 -4
  433. package/package.json +10 -10
  434. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  435. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  436. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  437. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  438. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  439. package/dist/compare/__fixtures__/nested-table.js +0 -50
  440. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  441. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  442. package/dist/docx/blockRangeMarkers.d.ts +0 -36
  443. package/dist/docx/blockRangeMarkers.js +0 -59
  444. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  445. package/dist/docx/bookmarkPlacement.js +0 -50
  446. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  447. package/dist/fonts/embeddedFontTable.js +0 -80
  448. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  449. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
  450. package/dist/prosemirror/yjsParagraphSourceContract.d.ts +0 -9
  451. package/dist/prosemirror/yjsParagraphSourceContract.js +0 -26
@@ -1,17 +1,22 @@
1
1
  import { parseHorizontalScalePercent } from "../utils/horizontalScale.js";
2
+ import { NO_MODELLED_ATTRIBUTES, attributeRemainder } from "./attributeRemainder.js";
3
+ import { CAPTURE, dispatchChildren, keptUnless, ownedElsewhere, sequencePositions } from "./containerChildren.js";
2
4
  import { parseDiagramPreview } from "./diagramPreview.js";
5
+ import { parseFieldState } from "./fieldState.js";
3
6
  import { isGroupDrawing, parseGroupDrawing } from "./groupDrawingParser.js";
4
7
  import { parseImage } from "./imageParser.js";
5
8
  import { imageRawXmlFingerprint } from "./imageRawXml.js";
6
- 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";
10
+ import { preserveRunChild } from "./preservedRunContent.js";
7
11
  import { parseShading } from "./shadingParser.js";
8
12
  import { parseShapeFromDrawing, shouldPreserveRawShapeDrawing } from "./shapeParser.js";
9
13
  import { isTextBoxDrawing } from "./textBoxParser.js";
14
+ import { parseThemeColorAttribute } from "./themeColorAttribute.js";
10
15
  import { resolveThemeFontRef } from "./themeParser.js";
11
16
  import { parsePropertyChangeInfo } from "./trackedChangeInfo.js";
12
17
  import { captureVerbatimXml } from "./verbatimCapture.js";
13
18
  import { parseVmlImageContent, shouldPreserveRawVmlPict } from "./vmlImageParser.js";
14
- import { cloneWithXmlnsDeclarations, findAllDeep, findChild, findChildren, getAttribute, getChildElements, getLocalName, getTextContent, mergeXmlnsDeclarations, parseBooleanElement, parseNumericAttribute, parseOnOffAttribute, 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";
15
20
  import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
16
21
  //#region src/docx/runParser.ts
17
22
  /**
@@ -22,124 +27,113 @@ import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
22
27
  */
23
28
  const MAX_LANGUAGE_TAG_LENGTH = 35;
24
29
  const truncateLanguageTag = (value) => value === void 0 ? void 0 : value.slice(0, MAX_LANGUAGE_TAG_LENGTH);
25
- /**
26
- * Parse color value from attributes
27
- */
28
- function parseColorValue(rgb, themeColor, themeTint, themeShade) {
30
+ function parseColorValue({ rgb, themeColor, themeTint, themeShade, element }) {
29
31
  const color = {};
30
32
  if (rgb && rgb !== "auto") color.rgb = rgb;
31
33
  else if (rgb === "auto") color.auto = true;
32
- const validatedThemeColor = narrowEnum(themeColor, ThemeColorSlotSchema);
33
- if (validatedThemeColor) color.themeColor = validatedThemeColor;
34
+ const parsedThemeColor = parseThemeColorAttribute({
35
+ raw: themeColor,
36
+ element
37
+ });
38
+ if (parsedThemeColor !== void 0) color.themeColor = parsedThemeColor;
34
39
  if (themeTint) color.themeTint = themeTint;
35
40
  if (themeShade) color.themeShade = themeShade;
36
41
  return color;
37
42
  }
38
- function collectFirstRunPropertyChildren(rPr) {
39
- const children = {};
40
- for (const child of rPr.elements ?? []) {
41
- if (child.type !== "element") continue;
42
- switch (getLocalName(child.name)) {
43
- case "b":
44
- children.b ??= child;
45
- break;
46
- case "bCs":
47
- children.bCs ??= child;
48
- break;
49
- case "caps":
50
- children.caps ??= child;
51
- break;
52
- case "color":
53
- children.color ??= child;
54
- break;
55
- case "noProof":
56
- children.noProof ??= child;
57
- break;
58
- case "cs":
59
- children.cs ??= child;
60
- break;
61
- case "dstrike":
62
- children.dstrike ??= child;
63
- break;
64
- case "effect":
65
- children.effect ??= child;
66
- break;
67
- case "em":
68
- children.em ??= child;
69
- break;
70
- case "emboss":
71
- children.emboss ??= child;
72
- break;
73
- case "highlight":
74
- children.highlight ??= child;
75
- break;
76
- case "i":
77
- children.i ??= child;
78
- break;
79
- case "iCs":
80
- children.iCs ??= child;
81
- break;
82
- case "imprint":
83
- children.imprint ??= child;
84
- break;
85
- case "kern":
86
- children.kern ??= child;
87
- break;
88
- case "lang":
89
- children.lang ??= child;
90
- break;
91
- case "outline":
92
- children.outline ??= child;
93
- break;
94
- case "position":
95
- children.position ??= child;
96
- break;
97
- case "rFonts":
98
- children.rFonts ??= child;
99
- break;
100
- case "rtl":
101
- children.rtl ??= child;
102
- break;
103
- case "rStyle":
104
- children.rStyle ??= child;
105
- break;
106
- case "shadow":
107
- children.shadow ??= child;
108
- break;
109
- case "shd":
110
- children.shd ??= child;
111
- break;
112
- case "smallCaps":
113
- children.smallCaps ??= child;
114
- break;
115
- case "spacing":
116
- children.spacing ??= child;
117
- break;
118
- case "strike":
119
- children.strike ??= child;
120
- break;
121
- case "sz":
122
- children.sz ??= child;
123
- break;
124
- case "szCs":
125
- children.szCs ??= child;
126
- break;
127
- case "u":
128
- children.u ??= child;
129
- break;
130
- case "vanish":
131
- children.vanish ??= child;
132
- break;
133
- case "vertAlign":
134
- children.vertAlign ??= child;
135
- break;
136
- case "w":
137
- children.w ??= child;
138
- break;
139
- }
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);
140
134
  }
141
- return children;
142
- }
135
+ return (read) => (child) => winner.get(getLocalName(child.name)) === child ? read(child) : void 0;
136
+ };
143
137
  /**
144
138
  * `w:vertAlign` `baseline` is the reserved value that means "no vertical
145
139
  * offset", not a third offset beside `superscript` and `subscript`. It is
@@ -148,191 +142,283 @@ function collectFirstRunPropertyChildren(rPr) {
148
142
  */
149
143
  const isBaselineVertAlign = (vertAlign) => vertAlign === "baseline";
150
144
  /**
151
- * 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.
152
147
  *
153
- * Handles ALL rPr properties:
154
- * - w:b (bold), w:i (italic), w:u (underline with style)
155
- * - w:strike (strikethrough), w:dstrike (double strike)
156
- * - w:vertAlign (superscript/subscript)
157
- * - w:smallCaps, w:caps (capitalization)
158
- * - w:highlight (text highlight color)
159
- * - w:shd (character shading)
160
- * - w:color (text color with theme resolution)
161
- * - w:sz (font size in half-points)
162
- * - w:rFonts (font family with theme resolution)
163
- * - w:spacing (character spacing)
164
- * - w:effect (text effects)
165
- * - And more...
148
+ * @returns whether the element stated any font at all.
166
149
  */
167
- function parseRunProperties(rPr, theme, _styles) {
168
- if (!rPr) return;
169
- const formatting = {};
170
- const propertyChildren = collectFirstRunPropertyChildren(rPr);
171
- const b = propertyChildren.b;
172
- if (b) formatting.bold = parseBooleanElement(b);
173
- const bCs = propertyChildren.bCs;
174
- if (bCs) formatting.boldCs = parseBooleanElement(bCs);
175
- const i = propertyChildren.i;
176
- if (i) formatting.italic = parseBooleanElement(i);
177
- const iCs = propertyChildren.iCs;
178
- if (iCs) formatting.italicCs = parseBooleanElement(iCs);
179
- const u = propertyChildren.u;
180
- if (u) {
181
- const style = narrowEnum(getAttribute(u, "w", "val"), UnderlineStyleSchema);
182
- if (style) {
183
- formatting.underline = { style };
184
- const colorVal = getAttribute(u, "w", "color");
185
- const themeColor = getAttribute(u, "w", "themeColor");
186
- 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;
187
168
  }
188
169
  }
189
- const strike = propertyChildren.strike;
190
- if (strike) formatting.strike = parseBooleanElement(strike);
191
- const dstrike = propertyChildren.dstrike;
192
- if (dstrike) formatting.doubleStrike = parseBooleanElement(dstrike);
193
- const vertAlign = propertyChildren.vertAlign;
194
- if (vertAlign) {
195
- const val = getAttribute(vertAlign, "w", "val");
196
- if (val === "superscript" || val === "subscript" || val === "baseline") formatting.vertAlign = val;
197
- }
198
- const smallCaps = propertyChildren.smallCaps;
199
- if (smallCaps) formatting.smallCaps = parseBooleanElement(smallCaps);
200
- const caps = propertyChildren.caps;
201
- if (caps) formatting.allCaps = parseBooleanElement(caps);
202
- const vanish = propertyChildren.vanish;
203
- if (vanish) formatting.hidden = parseBooleanElement(vanish);
204
- const noProof = propertyChildren.noProof;
205
- if (noProof) formatting.noProof = parseBooleanElement(noProof);
206
- const color = propertyChildren.color;
207
- if (color) formatting.color = parseColorValue(getAttribute(color, "w", "val"), getAttribute(color, "w", "themeColor"), getAttribute(color, "w", "themeTint"), getAttribute(color, "w", "themeShade"));
208
- const highlight = propertyChildren.highlight;
209
- if (highlight) {
210
- const val = narrowEnum(getAttribute(highlight, "w", "val"), HighlightColorSchema);
211
- if (val) formatting.highlight = val;
212
- }
213
- const shd = propertyChildren.shd;
214
- if (shd) {
215
- const shadingResult = parseShading(shd);
216
- if (shadingResult) formatting.shading = shadingResult;
217
- }
218
- const sz = propertyChildren.sz;
219
- if (sz) {
220
- const val = parseNumericAttribute(sz, "w", "val");
221
- if (val !== void 0) formatting.fontSize = val;
222
- }
223
- const szCs = propertyChildren.szCs;
224
- if (szCs) {
225
- const val = parseNumericAttribute(szCs, "w", "val");
226
- if (val !== void 0) formatting.fontSizeCs = val;
227
- }
228
- const rFonts = propertyChildren.rFonts;
229
- if (rFonts) {
230
- const fontFamily = {};
231
- const ascii = getAttribute(rFonts, "w", "ascii");
232
- if (ascii) fontFamily.ascii = ascii;
233
- const hAnsi = getAttribute(rFonts, "w", "hAnsi");
234
- if (hAnsi) fontFamily.hAnsi = hAnsi;
235
- const eastAsia = getAttribute(rFonts, "w", "eastAsia");
236
- if (eastAsia) fontFamily.eastAsia = eastAsia;
237
- const csFont = getAttribute(rFonts, "w", "cs");
238
- if (csFont) fontFamily.cs = csFont;
239
- const hint = narrowEnum(getAttribute(rFonts, "w", "hint"), FontHintSchema);
240
- if (hint) fontFamily.hint = hint;
241
- const asciiTheme = narrowEnum(getAttribute(rFonts, "w", "asciiTheme"), FontThemeSchema);
242
- if (asciiTheme) {
243
- fontFamily.asciiTheme = asciiTheme;
244
- if (theme && !fontFamily.ascii) {
245
- const resolved = resolveThemeFontRef(theme, asciiTheme);
246
- if (resolved) fontFamily.ascii = resolved;
247
- }
248
- }
249
- const hAnsiTheme = narrowEnum(getAttribute(rFonts, "w", "hAnsiTheme"), FontThemeSchema);
250
- if (hAnsiTheme) {
251
- fontFamily.hAnsiTheme = hAnsiTheme;
252
- if (theme && !fontFamily.hAnsi) {
253
- const resolved = resolveThemeFontRef(theme, hAnsiTheme);
254
- if (resolved) fontFamily.hAnsi = resolved;
255
- }
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;
256
176
  }
257
- const eastAsiaTheme = narrowEnum(getAttribute(rFonts, "w", "eastAsiaTheme"), FontThemeSchema);
258
- if (eastAsiaTheme) {
259
- fontFamily.eastAsiaTheme = eastAsiaTheme;
260
- if (theme && !fontFamily.eastAsia) {
261
- const resolved = resolveThemeFontRef(theme, eastAsiaTheme);
262
- if (resolved) fontFamily.eastAsia = resolved;
263
- }
264
- }
265
- const csTheme = narrowEnum(getAttribute(rFonts, "w", "cstheme"), FontThemeSchema);
266
- if (csTheme) {
267
- fontFamily.csTheme = csTheme;
268
- if (theme && !fontFamily.cs) {
269
- const resolved = resolveThemeFontRef(theme, csTheme);
270
- if (resolved) fontFamily.cs = resolved;
271
- }
272
- }
273
- formatting.fontFamily = fontFamily;
274
177
  }
275
- const lang = propertyChildren.lang;
276
- if (lang) {
277
- const val = truncateLanguageTag(getAttribute(lang, "w", "val") || void 0);
278
- const eastAsia = truncateLanguageTag(getAttribute(lang, "w", "eastAsia") || void 0);
279
- const bidi = truncateLanguageTag(getAttribute(lang, "w", "bidi") || void 0);
280
- if (val || eastAsia || bidi) formatting.language = {
281
- ...val ? { val } : {},
282
- ...eastAsia ? { eastAsia } : {},
283
- ...bidi ? { bidi } : {}
284
- };
285
- }
286
- const spacing = propertyChildren.spacing;
287
- if (spacing) {
288
- const val = parseNumericAttribute(spacing, "w", "val");
289
- if (val !== void 0) formatting.spacing = val;
290
- }
291
- const position = propertyChildren.position;
292
- if (position) {
293
- const val = parseNumericAttribute(position, "w", "val");
294
- if (val !== void 0) formatting.position = val;
295
- }
296
- const w = propertyChildren.w;
297
- if (w) {
298
- const val = parseHorizontalScalePercent(getAttribute(w, "w", "val"));
299
- if (val !== void 0) formatting.scale = val;
300
- }
301
- const kern = propertyChildren.kern;
302
- if (kern) {
303
- const val = parseNumericAttribute(kern, "w", "val");
304
- if (val !== void 0) formatting.kerning = val;
305
- }
306
- const effect = propertyChildren.effect;
307
- if (effect) {
308
- const val = narrowEnum(getAttribute(effect, "w", "val"), TextEffectSchema);
309
- if (val) formatting.effect = val;
310
- }
311
- const em = propertyChildren.em;
312
- if (em) {
313
- const val = narrowEnum(getAttribute(em, "w", "val"), EmphasisMarkSchema);
314
- 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
+ }
315
185
  }
316
- const emboss = propertyChildren.emboss;
317
- if (emboss) formatting.emboss = parseBooleanElement(emboss);
318
- const imprint = propertyChildren.imprint;
319
- if (imprint) formatting.imprint = parseBooleanElement(imprint);
320
- const outline = propertyChildren.outline;
321
- if (outline) formatting.outline = parseBooleanElement(outline);
322
- const shadow = propertyChildren.shadow;
323
- if (shadow) formatting.shadow = parseBooleanElement(shadow);
324
- const rtl = propertyChildren.rtl;
325
- if (rtl) formatting.rtl = parseBooleanElement(rtl);
326
- const cs = propertyChildren.cs;
327
- if (cs) formatting.cs = parseBooleanElement(cs);
328
- const rStyle = propertyChildren.rStyle;
329
- if (rStyle) {
330
- const val = getAttribute(rStyle, "w", "val");
331
- 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
+ }
332
193
  }
333
- 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;
334
420
  }
335
- function parseRunPropertyChanges(rPr, theme, styles, currentFormatting) {
421
+ function parseRunPropertyChanges(rPr, theme, currentFormatting) {
336
422
  if (!rPr) return;
337
423
  const changes = findChildren(rPr, "w", "rPrChange").map((changeElement) => {
338
424
  const previousRPr = findChild(changeElement, "w", "rPr");
@@ -340,11 +426,11 @@ function parseRunPropertyChanges(rPr, theme, styles, currentFormatting) {
340
426
  type: "runPropertyChange",
341
427
  info: parsePropertyChangeInfo(changeElement)
342
428
  };
343
- const previousFormatting = parseRunProperties(previousRPr, theme, styles ?? void 0);
429
+ const previousFormatting = parseRunProperties(previousRPr, theme, RUN_PROPERTY_OWNERS.standalone);
344
430
  if (previousFormatting) change.previousFormatting = previousFormatting;
345
431
  if (currentFormatting) change.currentFormatting = currentFormatting;
346
432
  return change;
347
- }).filter((change) => change.previousFormatting || change.currentFormatting);
433
+ });
348
434
  return changes.length > 0 ? changes : void 0;
349
435
  }
350
436
  /**
@@ -419,17 +505,14 @@ function parseEndnoteReference(element) {
419
505
  */
420
506
  function parseFieldChar(element) {
421
507
  const fldCharType = getAttribute(element, "w", "fldCharType");
422
- const fldLock = parseOnOffAttribute(element, "w", "fldLock") === true;
423
- const dirty = parseOnOffAttribute(element, "w", "dirty") === true;
424
508
  let charType = "begin";
425
509
  if (fldCharType === "separate") charType = "separate";
426
510
  else if (fldCharType === "end") charType = "end";
427
511
  const content = {
428
512
  type: "fieldChar",
429
- charType
513
+ charType,
514
+ ...parseFieldState(element)
430
515
  };
431
- if (fldLock) content.fldLock = true;
432
- if (dirty) content.dirty = true;
433
516
  const numberingChange = findChild(element, "w", "numberingChange");
434
517
  if (numberingChange) {
435
518
  const original = getAttribute(numberingChange, "w", "original");
@@ -576,10 +659,11 @@ function parseRunContents(runElement, rels, media, rootXmlns = {}) {
576
659
  }
577
660
  case "object": {
578
661
  const objectPreview = parseVmlImageContent(child, rels, media, rootXmlns);
579
- if (objectPreview) contents.push(objectPreview);
662
+ contents.push(objectPreview ?? preserveRunChild(child));
580
663
  break;
581
664
  }
582
665
  case "rPr": break;
666
+ case "commentReference": break;
583
667
  case "lastRenderedPageBreak":
584
668
  contents.push({ type: "renderedPageBreak" });
585
669
  break;
@@ -637,11 +721,9 @@ function parseRunContents(runElement, rels, media, rootXmlns = {}) {
637
721
  if (contents.length === contentsBeforeAlternate && !hasTextBoxBranch) contents.push(preserveOnlyDrawing(captureVerbatimXml(cloneWithXmlnsDeclarations(child, rootXmlns))));
638
722
  break;
639
723
  }
640
- case "footnoteRef":
641
- case "endnoteRef": break;
642
- case "separator":
643
- case "continuationSeparator": break;
644
- default: break;
724
+ default:
725
+ contents.push(preserveRunChild(child));
726
+ break;
645
727
  }
646
728
  return contents;
647
729
  }
@@ -649,25 +731,31 @@ function parseRunContents(runElement, rels, media, rootXmlns = {}) {
649
731
  * Parse a run element (w:r)
650
732
  *
651
733
  * @param node - The w:r XML element
652
- * @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
653
736
  * @param theme - Theme for resolving theme colors/fonts
654
737
  * @param rels - Relationship map for resolving image references
655
738
  * @param media - Media files map for image data
656
739
  * @returns Parsed Run object
657
740
  */
658
- function parseRun(node, styles, theme, rels = null, media = null, rootXmlns = {}) {
741
+ function parseRun(node, _styles, theme, rels = null, media = null, rootXmlns = {}) {
659
742
  const run = {
660
743
  type: "run",
661
744
  content: []
662
745
  };
663
746
  const rPr = findChild(node, "w", "rPr");
664
747
  if (rPr) {
665
- const formattingResult = parseRunProperties(rPr, theme, styles ?? void 0);
748
+ const formattingResult = parseRunProperties(rPr, theme, RUN_PROPERTY_OWNERS.run);
666
749
  if (formattingResult) run.formatting = formattingResult;
667
- const propertyChangesResult = parseRunPropertyChanges(rPr, theme, styles, run.formatting);
750
+ const propertyChangesResult = parseRunPropertyChanges(rPr, theme, run.formatting);
668
751
  if (propertyChangesResult) run.propertyChanges = propertyChangesResult;
669
752
  }
670
753
  run.content = parseRunContents(node, rels, media, mergeXmlnsDeclarations(rootXmlns, node));
754
+ const remainder = attributeRemainder({
755
+ element: node,
756
+ modelled: NO_MODELLED_ATTRIBUTES
757
+ });
758
+ if (remainder) run.preservedAttributes = remainder;
671
759
  return run;
672
760
  }
673
761
  /**
@@ -732,4 +820,4 @@ function getFieldCharType(run) {
732
820
  return run.content.find((c) => c.type === "fieldChar")?.charType ?? null;
733
821
  }
734
822
  //#endregion
735
- export { getFieldCharType, getImages, getRunText, hasContent, hasFieldChar, hasImage, isBaselineVertAlign, parseRun, parseRunProperties };
823
+ export { RUN_PROPERTY_OWNERS, getFieldCharType, getImages, getRunText, hasContent, hasFieldChar, hasImage, isBaselineVertAlign, parseRun, parseRunProperties };