@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
@@ -0,0 +1,111 @@
1
+ import { modelledAttributeNames } from "./propertyElementAttributes.js";
2
+ import { OOXML_NAMESPACES } from "./serializer/partNamespaces.js";
3
+ import { getLocalName, resolveAttributeNamespaceUri } from "./xmlParser.js";
4
+ import { TaggedError } from "better-result";
5
+ import { escapeXmlAttribute } from "@stll/docx-core";
6
+ //#region src/docx/attributeRemainder.ts
7
+ /** Namespace URI to the prefix a rebuilt part binds for it. */
8
+ const CANONICAL_PREFIX = new Map(Object.entries(OOXML_NAMESPACES).map(([prefix, { uri }]) => [uri, prefix]));
9
+ const XML_LOCAL_NAME = /^[\p{L}_][\p{L}\p{M}\p{N}._\-\u{00B7}\u{203F}-\u{2040}]*$/u;
10
+ var InvalidPreservedAttributeError = class extends TaggedError("InvalidPreservedAttributeError") {};
11
+ /** Whether an attribute remainder can be emitted under a bound canonical name. */
12
+ const isSerializablePreservedAttribute = ({ namespace, name }) => name !== "xmlns" && XML_LOCAL_NAME.test(name) && (namespace === void 0 || CANONICAL_PREFIX.has(namespace));
13
+ /**
14
+ * The modelled set of an element whose serializer writes no attribute at all.
15
+ *
16
+ * `w:r`, `w:tr` and `w:sectPr` are rebuilt as bare start tags, so everything
17
+ * their source wrote is the remainder. Named rather than spelled `new Set()`
18
+ * at each call site, so the claim is visible and one place has to change when
19
+ * one of them gains a modelled attribute.
20
+ */
21
+ const NO_MODELLED_ATTRIBUTES = /* @__PURE__ */ new Set();
22
+ /**
23
+ * What a part's root element states rather than carries, so the remainder skips it.
24
+ *
25
+ * `mc:Ignorable` is a projection of the root's own `xmlns:*` bindings — it
26
+ * lists which of them a consumer may skip — and `serializePartElement` derives
27
+ * both from the prefixes the rebuilt body actually uses. Replaying the
28
+ * source's would name prefixes the rebuilt root does not bind, which no
29
+ * consumer accepts, and the writer appends its own, so the part would carry
30
+ * the attribute twice. This is the same rule namespace declarations already
31
+ * follow, one attribute further on.
32
+ */
33
+ const DERIVED_PART_ROOT_ATTRIBUTES = /* @__PURE__ */ new Set(["Ignorable"]);
34
+ /**
35
+ * Every attribute on the element the model has no field for.
36
+ *
37
+ * @returns the remainder, or `undefined` when the parser read them all — an
38
+ * empty list is never written, so a fully modelled element stays identical
39
+ * in the model.
40
+ */
41
+ const attributeRemainder = ({ element, modelled }) => {
42
+ const attributes = element.attributes;
43
+ if (!attributes) return;
44
+ const remainder = [];
45
+ for (const [spelling, value] of Object.entries(attributes)) {
46
+ if (value === void 0 || spelling === "xmlns" || spelling.startsWith("xmlns:")) continue;
47
+ const name = getLocalName(spelling);
48
+ if (modelled.has(name)) continue;
49
+ const namespace = resolveAttributeNamespaceUri(element, spelling);
50
+ if (namespace !== void 0 && !CANONICAL_PREFIX.has(namespace)) continue;
51
+ remainder.push({
52
+ ...namespace === void 0 ? {} : { namespace },
53
+ name,
54
+ value: String(value)
55
+ });
56
+ }
57
+ return remainder.length === 0 ? void 0 : remainder;
58
+ };
59
+ const NAMES_BY_TABLE = /* @__PURE__ */ new WeakMap();
60
+ /**
61
+ * The remainder of an attribute bag, with the modelled set derived from the
62
+ * record's own fields.
63
+ *
64
+ * `w:ind`, `w:spacing`, `w:framePr`, `w:tab`, a border side and `w:shd` are
65
+ * bags rather than containers: the child dispatcher decides each of them
66
+ * whole, so an attribute the record has no field for is kept only while the
67
+ * reader takes nothing from the element at all. Passing the record's table
68
+ * from `propertyElementAttributes.ts` rather than a set spelled at the call
69
+ * site is what keeps the predicate derived from the model: a field added
70
+ * without an attribute to name does not compile.
71
+ */
72
+ const readAttributeBag = (element, modelled) => {
73
+ let names = NAMES_BY_TABLE.get(modelled);
74
+ if (names === void 0) {
75
+ names = new Set(modelledAttributeNames(modelled));
76
+ NAMES_BY_TABLE.set(modelled, names);
77
+ }
78
+ return attributeRemainder({
79
+ element,
80
+ modelled: names
81
+ });
82
+ };
83
+ /** The name a fragment such as `w14:paraId="1F2E"` writes. */
84
+ const spelledName = (fragment) => fragment.slice(0, fragment.indexOf("="));
85
+ /**
86
+ * The element's attributes, modelled first and the remainder after them.
87
+ *
88
+ * @param modelled the fragments the serializer is about to emit, already
89
+ * spelled — they win a collision, because the model is the editable copy
90
+ * @returns the fragments to write, so an element with neither writes nothing
91
+ */
92
+ const serializePreservedAttributes = (modelled, preserved) => {
93
+ if (preserved === void 0 || preserved.length === 0) return [...modelled];
94
+ const written = new Set(modelled.map(spelledName));
95
+ const fragments = [...modelled];
96
+ for (const attribute of preserved) {
97
+ const { namespace, name, value } = attribute;
98
+ if (!isSerializablePreservedAttribute(attribute)) throw new InvalidPreservedAttributeError({
99
+ message: "A preserved attribute must have an XML local name and a bound namespace",
100
+ name
101
+ });
102
+ const prefix = namespace === void 0 ? void 0 : CANONICAL_PREFIX.get(namespace);
103
+ const spelling = prefix === void 0 ? name : `${prefix}:${name}`;
104
+ if (written.has(spelling)) continue;
105
+ written.add(spelling);
106
+ fragments.push(`${spelling}="${escapeXmlAttribute(value)}"`);
107
+ }
108
+ return fragments;
109
+ };
110
+ //#endregion
111
+ export { DERIVED_PART_ROOT_ATTRIBUTES, InvalidPreservedAttributeError, NO_MODELLED_ATTRIBUTES, attributeRemainder, isSerializablePreservedAttribute, readAttributeBag, serializePreservedAttributes };
@@ -1,11 +1,13 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { NumberingMap } from "./numberingParser.js";
3
- import { StyleMap } from "./styleParser.js";
3
+ import { ParseContext } from "./parseContext.js";
4
4
  import { XmlElement } from "./xmlParser.js";
5
+ import { StyleMap } from "./styleParser.js";
5
6
  //#region src/docx/blockContentParser.d.ts
6
7
  type ParseBlockContentOptions = {
7
8
  inHeaderFooter?: boolean;
8
9
  rootXmlns?: Record<string, string>;
10
+ context?: ParseContext | undefined;
9
11
  };
10
12
  declare const parseBlockContent: (parent: XmlElement, styles: StyleMap | null, theme: document_d_exports.Theme | null, numbering: NumberingMap | null, rels: document_d_exports.RelationshipMap | null, media: Map<string, document_d_exports.MediaFile> | null, options?: ParseBlockContentOptions) => document_d_exports.BlockContent[];
11
13
  //#endregion
@@ -1,15 +1,13 @@
1
- import { attachPendingRangeMarkers, attachTrailingRangeMarkers, isBlockRangeMarker } from "./blockRangeMarkers.js";
2
1
  import { parseBookmarkEnd, parseBookmarkStart } from "./bookmarkParser.js";
3
- import { appendBookmarkMarkerToLastParagraphInBlocks, prependBookmarkMarkersToFirstParagraphInBlocks } from "./bookmarkPlacement.js";
4
2
  import { convertBulletToUnicode } from "./bulletMarkers.js";
3
+ import { CAPTURE, dispatchChildren, ownedElsewhere, withPreservedChildren } from "./containerChildren.js";
5
4
  import { isNumberingReference } from "./numberingReference.js";
6
5
  import { formatOoxmlCounter } from "./ooxmlCounterFormatter.js";
7
6
  import { parseParagraph } from "./paragraphParser.js";
8
7
  import { enrichParagraphTextBoxes } from "./paragraphTextBoxEnrichment.js";
9
- import { parseSdtProperties } from "./sdtProperties.js";
8
+ import { captureSdtSiblingMarkers, parseSdtProperties } from "./sdtProperties.js";
10
9
  import { parseTable } from "./tableParser.js";
11
- import { captureVerbatimXml } from "./verbatimCapture.js";
12
- import { findChild, getChildElements, getLocalName, mergeXmlnsDeclarations, selectAlternateContentBranch } from "./xmlParser.js";
10
+ import { findWordprocessingChild, mergeXmlnsDeclarations, selectAlternateContentBranch } from "./xmlParser.js";
13
11
  //#region src/docx/blockContentParser.ts
14
12
  const computeListMarker = (paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }) => {
15
13
  const listRendering = paragraph.listRendering;
@@ -89,6 +87,29 @@ const withContainerXmlns = (state, element) => ({
89
87
  rootXmlns: mergeXmlnsDeclarations(state.options?.rootXmlns ?? {}, element)
90
88
  }
91
89
  });
90
+ /**
91
+ * The two block children this walk skips, and who reads them instead.
92
+ *
93
+ * Both are read off the container element rather than met here: the body's own
94
+ * `w:sectPr` by the document parser, a cell's `w:tcPr` by the table parser.
95
+ * They are in this map because it is total over the union every block
96
+ * container shares, not because this walk reads them.
97
+ *
98
+ * Declared at module scope so the claim is registered when the module loads,
99
+ * rather than the first time a document is parsed.
100
+ */
101
+ const BLOCK_CHILD_OWNERS = {
102
+ sectPr: ownedElsewhere({
103
+ container: "block-content",
104
+ child: "sectPr",
105
+ reader: "documentParser#parseDocumentBody"
106
+ }),
107
+ tcPr: ownedElsewhere({
108
+ container: "block-content",
109
+ child: "tcPr",
110
+ reader: "tableParser#parseTableCell"
111
+ })
112
+ };
92
113
  const parseBlockContent = (parent, styles, theme, numbering, rels, media, options) => parseBlockContentWithState(parent, styles, theme, numbering, rels, media, {
93
114
  listCounters: /* @__PURE__ */ new Map(),
94
115
  abstractCounters: /* @__PURE__ */ new Map(),
@@ -104,112 +125,87 @@ const parseBlockContent = (parent, styles, theme, numbering, rels, media, option
104
125
  }
105
126
  });
106
127
  const parseBlockContentWithState = (parent, styles, theme, numbering, rels, media, state) => {
107
- const content = [];
108
- const children = getChildElements(parent);
109
- const pendingBookmarkMarkers = [];
110
- const pendingRangeMarkers = [];
111
- for (const child of children) {
112
- const localName = getLocalName(child.name ?? "");
113
- if (localName === "p") {
114
- const paragraph = parseParagraph(child, styles, theme, numbering, rels, media, state.options);
115
- prependPendingBookmarkMarkers(paragraph, pendingBookmarkMarkers);
116
- enrichParagraphTextBoxes(paragraph, child, styles, theme, numbering, rels, media, parseTable);
117
- computeListMarker(paragraph, {
118
- numbering,
119
- listCounters: state.listCounters,
120
- abstractCounters: state.abstractCounters,
121
- restartedNumIds: state.restartedNumIds,
122
- previousList: state.previousList
123
- });
124
- attachPendingRangeMarkers(paragraph, pendingRangeMarkers);
125
- content.push(paragraph);
126
- continue;
127
- }
128
- if (localName === "tbl") {
129
- const table = parseTable(child, styles, theme, numbering, rels, media, state.options);
130
- if (!table) continue;
131
- if (prependBookmarkMarkersToFirstParagraphInBlocks([table], pendingBookmarkMarkers)) pendingBookmarkMarkers.length = 0;
132
- attachPendingRangeMarkers(table, pendingRangeMarkers);
133
- content.push(table);
134
- continue;
135
- }
136
- if (localName === "sdt") {
137
- const sdtPr = findChild(child, "w", "sdtPr");
138
- const sdtEndPr = findChild(child, "w", "sdtEndPr");
139
- const sdtContent = findChild(child, "w", "sdtContent");
140
- const properties = parseSdtProperties(sdtPr, sdtEndPr);
141
- const captured = captureSdtSiblingMarkers(child);
142
- if (captured.before.length > 0) properties.rawSdtChildrenBeforeContent = captured.before;
143
- if (captured.after.length > 0) properties.rawSdtChildrenAfterContent = captured.after;
144
- const blockSdt = {
145
- type: "blockSdt",
146
- properties,
147
- content: sdtContent ? parseBlockContentWithState(sdtContent, styles, theme, numbering, rels, media, withContainerXmlns(withContainerXmlns(state, child), sdtContent)) : []
148
- };
149
- if (prependBookmarkMarkersToFirstParagraphInBlocks(blockSdt.content, pendingBookmarkMarkers)) pendingBookmarkMarkers.length = 0;
150
- attachPendingRangeMarkers(blockSdt, pendingRangeMarkers);
151
- content.push(blockSdt);
152
- continue;
153
- }
154
- if (localName === "AlternateContent") {
128
+ const modelled = [];
129
+ return withPreservedChildren(modelled, dispatchChildren({
130
+ element: parent,
131
+ container: "block-content",
132
+ capturePosition: () => modelled.length,
133
+ undeclared: { AlternateContent: (child) => {
155
134
  const selectedBranch = selectAlternateContentBranch(child);
156
- if (selectedBranch) content.push(...parseBlockContentWithState(selectedBranch, styles, theme, numbering, rels, media, withContainerXmlns(withContainerXmlns(state, child), selectedBranch)));
157
- continue;
158
- }
159
- if (localName === "bookmarkStart" || localName === "bookmarkEnd") {
160
- const marker = parseBookmarkMarker(child, localName);
161
- if (!appendBookmarkMarkerToLastParagraphInBlocks(content, marker)) pendingBookmarkMarkers.push(marker);
162
- continue;
135
+ if (!selectedBranch) return;
136
+ modelled.push(...parseBlockContentWithState(selectedBranch, styles, theme, numbering, rels, media, withContainerXmlns(withContainerXmlns(state, child), selectedBranch)));
137
+ } },
138
+ handlers: {
139
+ p: (child) => {
140
+ const paragraph = parseParagraph(child, styles, theme, numbering, rels, media, {
141
+ ...state.options,
142
+ runConsolidation: "deferred"
143
+ });
144
+ enrichParagraphTextBoxes(paragraph, child, styles, theme, numbering, rels, media, parseTable, state.options?.context);
145
+ computeListMarker(paragraph, {
146
+ numbering,
147
+ listCounters: state.listCounters,
148
+ abstractCounters: state.abstractCounters,
149
+ restartedNumIds: state.restartedNumIds,
150
+ previousList: state.previousList
151
+ });
152
+ modelled.push(paragraph);
153
+ },
154
+ tbl: (child) => {
155
+ const table = parseTable(child, styles, theme, numbering, rels, media, state.options);
156
+ if (!table) return;
157
+ modelled.push(table);
158
+ },
159
+ sdt: (child) => {
160
+ modelled.push(parseBlockSdt(child, styles, theme, numbering, rels, media, state));
161
+ },
162
+ bookmarkStart: (child) => {
163
+ modelled.push(parseBookmarkStart(child));
164
+ },
165
+ bookmarkEnd: (child) => {
166
+ modelled.push(parseBookmarkEnd(child));
167
+ },
168
+ ...BLOCK_CHILD_OWNERS,
169
+ altChunk: CAPTURE,
170
+ commentRangeEnd: CAPTURE,
171
+ commentRangeStart: CAPTURE,
172
+ customXml: CAPTURE,
173
+ customXmlDelRangeEnd: CAPTURE,
174
+ customXmlDelRangeStart: CAPTURE,
175
+ customXmlInsRangeEnd: CAPTURE,
176
+ customXmlInsRangeStart: CAPTURE,
177
+ customXmlMoveFromRangeEnd: CAPTURE,
178
+ customXmlMoveFromRangeStart: CAPTURE,
179
+ customXmlMoveToRangeEnd: CAPTURE,
180
+ customXmlMoveToRangeStart: CAPTURE,
181
+ del: CAPTURE,
182
+ ins: CAPTURE,
183
+ moveFrom: CAPTURE,
184
+ moveFromRangeEnd: CAPTURE,
185
+ moveFromRangeStart: CAPTURE,
186
+ moveTo: CAPTURE,
187
+ moveToRangeEnd: CAPTURE,
188
+ moveToRangeStart: CAPTURE,
189
+ permEnd: CAPTURE,
190
+ permStart: CAPTURE,
191
+ proofErr: CAPTURE
163
192
  }
164
- if (isBlockRangeMarker(localName)) pendingRangeMarkers.push(captureVerbatimXml(child));
165
- }
166
- if (pendingBookmarkMarkers.length > 0) content.push({
167
- type: "paragraph",
168
- content: [...pendingBookmarkMarkers]
169
- });
170
- attachTrailingRangeMarkers(content, pendingRangeMarkers);
171
- return content;
193
+ }), (xml) => ({
194
+ type: "preservedBlock",
195
+ xml
196
+ }));
172
197
  };
173
- /**
174
- * Walk a `<w:sdt>` element's direct children and return the verbatim XML
175
- * for every child that is NOT `<w:sdtPr>`, `<w:sdtEndPr>`, or
176
- * `<w:sdtContent>` — split by position relative to sdtContent.
177
- *
178
- * Per MS-OE376 §2.5.2.30, Word emits 16 range-marker elements (bookmark,
179
- * comment, custom XML, tracked-change ranges) as direct sdt siblings of
180
- * sdtContent. Without preserving them, a comment thread or tracked
181
- * change that crosses an SDT boundary loses a delimiter when folio
182
- * serializes the parsed model back out.
183
- */
184
- const captureSdtSiblingMarkers = (sdt) => {
185
- const beforeParts = [];
186
- const afterParts = [];
187
- let sawContent = false;
188
- for (const ch of sdt.elements ?? []) {
189
- if (ch.type !== "element" || !ch.name) continue;
190
- const local = getLocalName(ch.name);
191
- if (local === "sdtPr" || local === "sdtEndPr") continue;
192
- if (local === "sdtContent") {
193
- sawContent = true;
194
- continue;
195
- }
196
- const xml = captureVerbatimXml(ch);
197
- if (sawContent) afterParts.push(xml);
198
- else beforeParts.push(xml);
199
- }
198
+ const parseBlockSdt = (child, styles, theme, numbering, rels, media, state) => {
199
+ const sdtContent = findWordprocessingChild(child, "sdtContent");
200
+ const properties = parseSdtProperties(findWordprocessingChild(child, "sdtPr"), findWordprocessingChild(child, "sdtEndPr"));
201
+ const captured = captureSdtSiblingMarkers(child);
202
+ if (captured.before.length > 0) properties.rawSdtChildrenBeforeContent = captured.before;
203
+ if (captured.after.length > 0) properties.rawSdtChildrenAfterContent = captured.after;
200
204
  return {
201
- before: beforeParts.join(""),
202
- after: afterParts.join("")
205
+ type: "blockSdt",
206
+ properties,
207
+ content: sdtContent ? parseBlockContentWithState(sdtContent, styles, theme, numbering, rels, media, withContainerXmlns(withContainerXmlns(state, child), sdtContent)) : []
203
208
  };
204
209
  };
205
- const parseBookmarkMarker = (child, localName) => {
206
- if (localName === "bookmarkStart") return parseBookmarkStart(child);
207
- return parseBookmarkEnd(child);
208
- };
209
- const prependPendingBookmarkMarkers = (paragraph, pendingBookmarkMarkers) => {
210
- if (pendingBookmarkMarkers.length === 0) return;
211
- paragraph.content.unshift(...pendingBookmarkMarkers);
212
- pendingBookmarkMarkers.length = 0;
213
- };
214
210
  //#endregion
215
211
  export { parseBlockContent };
@@ -1,8 +1,7 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  //#region src/docx/blockPlainText.d.ts
3
- type PlainTextBlock = document_d_exports.Paragraph | document_d_exports.Table | document_d_exports.BlockSdt;
4
3
  /** One entry per block, so callers can join or count lines as they need. */
5
- declare const collectBlockTexts: (blocks: readonly PlainTextBlock[]) => string[];
6
- declare const blockPlainText: (blocks: readonly PlainTextBlock[]) => string;
4
+ declare const collectBlockTexts: (blocks: readonly document_d_exports.BlockContent[]) => string[];
5
+ declare const blockPlainText: (blocks: readonly document_d_exports.BlockContent[]) => string;
7
6
  //#endregion
8
- export { PlainTextBlock, blockPlainText, collectBlockTexts };
7
+ export { blockPlainText, collectBlockTexts };
@@ -31,6 +31,9 @@ const collectBlockTexts = (blocks) => {
31
31
  case "blockSdt":
32
32
  texts.push(...collectBlockTexts(block.content));
33
33
  break;
34
+ case "preservedBlock":
35
+ case "bookmarkStart":
36
+ case "bookmarkEnd": break;
34
37
  default: panic(`Unsupported block in plain-text extraction: ${JSON.stringify(block)}`);
35
38
  }
36
39
  return texts;
@@ -1,6 +1,8 @@
1
- import { BorderStyleSchema, ThemeColorSlotSchema, narrowEnum } from "./parserEnums.js";
1
+ import { readAttributeBag } from "./attributeRemainder.js";
2
+ import { BORDER_ATTRIBUTES } from "./propertyElementAttributes.js";
3
+ import { parseThemeColorAttribute } from "./themeColorAttribute.js";
2
4
  import { getAttribute, parseNumericAttribute, parseOnOffAttribute } from "./xmlParser.js";
3
- import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
5
+ import { PARSE_WARNING_CODES, borderStyleFrom, isBorderStyle } from "@stll/docx-core/model";
4
6
  //#region src/docx/borderParser.ts
5
7
  /**
6
8
  * The one reader for `CT_Border`, shared by the paragraph (`w:pBdr`), style,
@@ -9,21 +11,27 @@ import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
9
11
  * `w:val` is `ST_Border`, whose 193 members include two distinct "no border"
10
12
  * tokens: `nil` and `none`. They are not interchangeable downstream, and an
11
13
  * explicit one overrides a border inherited from the container, so the member
12
- * the author wrote is preserved exactly. Members outside the model's known
13
- * union survive verbatim rather than collapsing to a default, which is how the
14
- * repo already treats `w:numFmt`, `w:suff` and `w:tab`.
14
+ * the author wrote is preserved exactly. A token outside the enumeration is
15
+ * kept verbatim and reported, which is how the repo already treats `w:numFmt`,
16
+ * `w:suff` and `w:tab`.
15
17
  */
16
- const parseBorderColor = (border) => {
18
+ /** `ST_HexColor`'s reserved "let the consumer decide" token, as `shadingParser` spells it. */
19
+ const AUTOMATIC_COLOR = "auto";
20
+ const parseBorderColor = (border, context) => {
17
21
  const rgb = getAttribute(border, "w", "color");
18
22
  const themeColor = getAttribute(border, "w", "themeColor");
19
23
  const themeTint = getAttribute(border, "w", "themeTint");
20
24
  const themeShade = getAttribute(border, "w", "themeShade");
21
25
  if (rgb === null && themeColor === null && themeTint === null && themeShade === null) return;
22
26
  const color = {};
23
- if (rgb === "auto") color.auto = true;
27
+ if (rgb === AUTOMATIC_COLOR) color.auto = true;
24
28
  else if (rgb) color.rgb = rgb;
25
- const validatedThemeColor = narrowEnum(themeColor, ThemeColorSlotSchema);
26
- if (validatedThemeColor) color.themeColor = validatedThemeColor;
29
+ const parsedThemeColor = parseThemeColorAttribute({
30
+ raw: themeColor,
31
+ element: border.name ?? "border",
32
+ context
33
+ });
34
+ if (parsedThemeColor !== void 0) color.themeColor = parsedThemeColor;
27
35
  if (themeTint) color.themeTint = themeTint;
28
36
  if (themeShade) color.themeShade = themeShade;
29
37
  return color;
@@ -44,8 +52,13 @@ function parseBorderSpec(border, context) {
44
52
  });
45
53
  return;
46
54
  }
47
- const spec = { style: narrowEnum(rawStyle, BorderStyleSchema) ?? rawStyle };
48
- const color = parseBorderColor(border);
55
+ if (!isBorderStyle(rawStyle)) context?.warn({
56
+ code: PARSE_WARNING_CODES.borderStyleOutsideEnum,
57
+ element: border.name ?? "border",
58
+ value: rawStyle
59
+ });
60
+ const spec = { style: borderStyleFrom(rawStyle) };
61
+ const color = parseBorderColor(border, context);
49
62
  if (color) spec.color = color;
50
63
  const size = parseNumericAttribute(border, "w", "sz");
51
64
  if (size !== void 0) spec.size = size;
@@ -65,6 +78,8 @@ function parseBorderSpec(border, context) {
65
78
  if (bottomLeftArtRelationshipId) spec.bottomLeftArtRelationshipId = bottomLeftArtRelationshipId;
66
79
  const bottomRightArtRelationshipId = getAttribute(border, "r", "bottomRight")?.trim();
67
80
  if (bottomRightArtRelationshipId) spec.bottomRightArtRelationshipId = bottomRightArtRelationshipId;
81
+ const preservedAttributes = readAttributeBag(border, BORDER_ATTRIBUTES);
82
+ if (preservedAttributes) spec.preservedAttributes = preservedAttributes;
68
83
  return spec;
69
84
  }
70
85
  //#endregion
@@ -1,24 +1,16 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { OutlineLevel } from "@stll/docx-core/model";
2
3
  //#region src/docx/builtInStyles.d.ts
3
4
  /**
4
- * The tenth `w:outlineLvl` value. 17.3.1.20: "the val attribute … can be from
5
- * 0 to 9, where 9 specifically indicates that there is no outline level
6
- * specifically applied to this paragraph." It is a deliberate "not a heading",
7
- * not a tenth level. Every range test goes through
8
- * {@link isHeadingOutlineLevel} so the reserved value keeps one meaning across
9
- * the codebase.
10
- *
11
- * The same clause adds that an omitted element "is assumed to be 9". That
5
+ * 17.3.1.20 adds that an omitted `w:outlineLvl` "is assumed to be 9". That
12
6
  * default cannot be applied to a *style* definition, because 17.7.1 tells
13
7
  * producers not to write a property "already been set by a previous level of
14
8
  * the style hierarchy": a document that names a style `heading 1` and omits
15
9
  * the level is inheriting the consumer's built-in definition, which carries
16
10
  * level 0. An absent level therefore means "unspecified, ask the name", and
17
- * only a written 9 means body text.
11
+ * only {@link BODY_TEXT_OUTLINE_LEVEL} means body text — which is why the
12
+ * model keeps absence and the body-text arm apart.
18
13
  */
19
- declare const BODY_TEXT_OUTLINE_LEVEL = 9;
20
- /** True when an outline level names a heading rather than body text. */
21
- declare const isHeadingOutlineLevel: (level: number | null | undefined) => level is number;
22
14
  /**
23
15
  * Compare style names the way producers actually write them. The corpus shows
24
16
  * both `heading 1` (Annex L, 94.8%) and `Heading 1` (5.2%), and LibreOffice
@@ -84,8 +76,8 @@ declare const builtInTableOfContentsStyleName: (level: number) => string;
84
76
  * quadratic.
85
77
  */
86
78
  type BuiltInStyleIndex = {
87
- /** The style's effective `w:outlineLvl`, including 9, or undefined. */
88
- outlineLevelOf: (styleId: string | null | undefined) => number | undefined;
79
+ /** The style's effective `w:outlineLvl`, body text included, or undefined. */
80
+ outlineLevelOf: (styleId: string | null | undefined) => OutlineLevel | undefined;
89
81
  /** The zero-based level a built-in heading *name* implies, or undefined. */
90
82
  headingLevelFromNameOf: (styleId: string | null | undefined) => number | undefined;
91
83
  /** The built-in this style is, by name, or undefined for a custom style. */
@@ -113,7 +105,7 @@ declare const EMPTY_BUILT_IN_STYLE_INDEX: BuiltInStyleIndex;
113
105
  */
114
106
  type ParagraphOutlineSource = {
115
107
  styleId?: string | null | undefined;
116
- outlineLevel?: number | null | undefined;
108
+ outlineLevel?: OutlineLevel | null | undefined;
117
109
  };
118
110
  /**
119
111
  * The heading level a paragraph carries, zero-based (`heading 1` is 0), or
@@ -162,4 +154,4 @@ declare const resolveHeadingLevel: (paragraph: ParagraphOutlineSource, index: Bu
162
154
  /** True when the paragraph's style is Word's `Quote` or `Intense Quote`. */
163
155
  declare const isQuoteStyle: (styleId: string | null | undefined, index: BuiltInStyleIndex) => boolean;
164
156
  //#endregion
165
- export { BODY_TEXT_OUTLINE_LEVEL, BUILT_IN_STYLE_NAME, BuiltInStyleIndex, EMPTY_BUILT_IN_STYLE_INDEX, ParagraphOutlineSource, builtInHeadingStyleName, builtInTableOfContentsStyleName, createBuiltInStyleIndex, isHeadingOutlineLevel, isQuoteStyle, normalizeStyleName, resolveHeadingLevel };
157
+ export { BUILT_IN_STYLE_NAME, BuiltInStyleIndex, EMPTY_BUILT_IN_STYLE_INDEX, ParagraphOutlineSource, builtInHeadingStyleName, builtInTableOfContentsStyleName, createBuiltInStyleIndex, isQuoteStyle, normalizeStyleName, resolveHeadingLevel };
@@ -1,26 +1,57 @@
1
1
  import { BUILT_IN_DEFAULT_PARAGRAPH_STYLE_NAME, resolveDefaultParagraphStyle } from "./defaultParagraphStyle.js";
2
+ import { headingLevelOf } from "@stll/docx-core/model";
2
3
  //#region src/docx/builtInStyles.ts
3
4
  /**
4
- * The tenth `w:outlineLvl` value. 17.3.1.20: "the val attribute … can be from
5
- * 0 to 9, where 9 specifically indicates that there is no outline level
6
- * specifically applied to this paragraph." It is a deliberate "not a heading",
7
- * not a tenth level. Every range test goes through
8
- * {@link isHeadingOutlineLevel} so the reserved value keeps one meaning across
9
- * the codebase.
5
+ * Whether a paragraph is a heading, and of which level, without reading the
6
+ * style id.
10
7
  *
11
- * The same clause adds that an omitted element "is assumed to be 9". That
8
+ * A style id is opaque. ECMA-376 17.7.4.17 says a style id "can be assigned in
9
+ * any manner desired" and only requires it to be unique within the document,
10
+ * and Word fills it by stripping spaces and non-ASCII characters out of the
11
+ * *localized* UI name. The same built-in heading therefore arrives as
12
+ * `Heading1`, `berschrift1` (de), `Nadpis1` (cs), `Titre1` (fr), `Nagwek1`
13
+ * (pl), `Cmsor1` (hu), `Ttulo1` (es), `Overskrift1` (da) or a bare `1`.
14
+ * Matching the id finds English Word output and nothing else, the same trap
15
+ * `defaultParagraphStyle.ts` documents for `Normal`.
16
+ *
17
+ * Two signals survive localisation, in this order:
18
+ *
19
+ * 1. The effective `w:outlineLvl` — direct paragraph formatting, else the
20
+ * style chain (`styleParser` flattens `w:basedOn` into `style.pPr` per
21
+ * 17.7.1). 17.3.1.20 gives it the range 0..9 and says it "shall be used to
22
+ * calculate the TOC field", which is what a `TOC \u` field and the
23
+ * navigation pane read. So a custom style with an outline level *is* a
24
+ * heading, and a heading-named style reset to
25
+ * {@link BODY_TEXT_OUTLINE_LEVEL} is *not* (folio's own `TOCHeading`, based
26
+ * on `Heading1`, does exactly that).
27
+ * 2. The style's `w:name`. Part 1 has no normative list of built-in names, but
28
+ * it keys latent styles by name alone: a `w:lsdException` carries no style
29
+ * id, and 17.7.4.8 defines its `w:name` as "the primary name for the style
30
+ * which shall inherit this set of latent style property exceptions",
31
+ * ignored when "the current application does not know of an internal
32
+ * primary style with the current name". Annex L writes those names in
33
+ * English (`heading 1`…`heading 9`) with no locale qualification.
34
+ *
35
+ * The id is never a signal on its own.
36
+ *
37
+ * Measured over the 5,341-file public corpus: 207 files define a heading whose
38
+ * id is not `HeadingN` while the name is English, covering 123 distinct ids;
39
+ * only 4 documents localise the *name*, all ODF→OOXML exports (LibreOffice
40
+ * writing its ODF display names verbatim). Names are not case-stable (5.2% are
41
+ * `Heading 1` rather than the Annex L `heading 1`) and not space-stable
42
+ * (LibreOffice 25.8 writes `Heading1`, and `IntenseQuote` for `Intense
43
+ * Quote`), which is why {@link normalizeStyleName} ignores both.
44
+ */
45
+ /**
46
+ * 17.3.1.20 adds that an omitted `w:outlineLvl` "is assumed to be 9". That
12
47
  * default cannot be applied to a *style* definition, because 17.7.1 tells
13
48
  * producers not to write a property "already been set by a previous level of
14
49
  * the style hierarchy": a document that names a style `heading 1` and omits
15
50
  * the level is inheriting the consumer's built-in definition, which carries
16
51
  * level 0. An absent level therefore means "unspecified, ask the name", and
17
- * only a written 9 means body text.
52
+ * only {@link BODY_TEXT_OUTLINE_LEVEL} means body text — which is why the
53
+ * model keeps absence and the body-text arm apart.
18
54
  */
19
- const BODY_TEXT_OUTLINE_LEVEL = 9;
20
- /** The highest `w:outlineLvl` that still names a heading (outline level nine). */
21
- const MAX_HEADING_OUTLINE_LEVEL = 8;
22
- /** True when an outline level names a heading rather than body text. */
23
- const isHeadingOutlineLevel = (level) => typeof level === "number" && Number.isInteger(level) && level >= 0 && level <= MAX_HEADING_OUTLINE_LEVEL;
24
55
  /**
25
56
  * Compare style names the way producers actually write them. The corpus shows
26
57
  * both `heading 1` (Annex L, 94.8%) and `Heading 1` (5.2%), and LibreOffice
@@ -118,6 +149,11 @@ const inheritedOutlineLevel = (style, styleById) => {
118
149
  current = current.basedOn === void 0 ? void 0 : styleById.get(current.basedOn);
119
150
  }
120
151
  };
152
+ /** The level a heading style is indexed under, or undefined if it is not one. */
153
+ const headingLevelForIndex = (namedLevel, statedLevel) => {
154
+ if (namedLevel === void 0) return;
155
+ return statedLevel === void 0 ? namedLevel : headingLevelOf(statedLevel);
156
+ };
121
157
  const createBuiltInStyleIndex = (styles, docDefaults) => {
122
158
  const styleIdByHeadingLevel = /* @__PURE__ */ new Map();
123
159
  const styleIdByTableOfContentsLevel = /* @__PURE__ */ new Map();
@@ -136,8 +172,9 @@ const createBuiltInStyleIndex = (styles, docDefaults) => {
136
172
  for (const style of paragraphStyles) {
137
173
  if (style.name === void 0) continue;
138
174
  const namedLevel = headingOutlineLevelFromStyleName(style.name);
139
- const headingLevel = namedLevel === void 0 ? void 0 : inheritedOutlineLevel(style, styleById) ?? docDefaultOutlineLevel ?? namedLevel;
140
- if (headingLevel !== void 0 && isHeadingOutlineLevel(headingLevel) && !styleIdByHeadingLevel.has(headingLevel)) {
175
+ const statedLevel = inheritedOutlineLevel(style, styleById) ?? docDefaultOutlineLevel;
176
+ const headingLevel = headingLevelForIndex(namedLevel, statedLevel);
177
+ if (headingLevel !== void 0 && !styleIdByHeadingLevel.has(headingLevel)) {
141
178
  styleIdByHeadingLevel.set(headingLevel, style.styleId);
142
179
  continue;
143
180
  }
@@ -227,7 +264,7 @@ const EMPTY_BUILT_IN_STYLE_INDEX = createBuiltInStyleIndex([]);
227
264
  */
228
265
  const resolveHeadingLevel = (paragraph, index) => {
229
266
  const effective = paragraph.outlineLevel ?? index.outlineLevelOf(paragraph.styleId);
230
- if (effective !== null && effective !== void 0) return isHeadingOutlineLevel(effective) ? effective : void 0;
267
+ if (effective !== null && effective !== void 0) return headingLevelOf(effective);
231
268
  return index.headingLevelFromNameOf(paragraph.styleId) ?? index.undefinedBuiltInHeadingLevelOf(paragraph.styleId);
232
269
  };
233
270
  /** True when the paragraph's style is Word's `Quote` or `Intense Quote`. */
@@ -236,4 +273,4 @@ const isQuoteStyle = (styleId, index) => {
236
273
  return name === BUILT_IN_STYLE_NAME.quote || name === BUILT_IN_STYLE_NAME.intenseQuote;
237
274
  };
238
275
  //#endregion
239
- export { BODY_TEXT_OUTLINE_LEVEL, BUILT_IN_STYLE_NAME, EMPTY_BUILT_IN_STYLE_INDEX, builtInHeadingStyleName, builtInTableOfContentsStyleName, createBuiltInStyleIndex, isHeadingOutlineLevel, isQuoteStyle, normalizeStyleName, resolveHeadingLevel };
276
+ export { BUILT_IN_STYLE_NAME, EMPTY_BUILT_IN_STYLE_INDEX, builtInHeadingStyleName, builtInTableOfContentsStyleName, createBuiltInStyleIndex, isQuoteStyle, normalizeStyleName, resolveHeadingLevel };
@@ -0,0 +1,30 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/commentAnchorIndex.d.ts
3
+ type CommentMarkerSlot = {
4
+ /** The inline-content array the marker sits in, so a caller can splice it. */
5
+ content: document_d_exports.ParagraphContent[];
6
+ index: number;
7
+ item: Extract<document_d_exports.ParagraphContent, {
8
+ type: "commentRangeStart";
9
+ } | {
10
+ type: "commentRangeEnd";
11
+ } | {
12
+ type: "commentReference";
13
+ }>;
14
+ };
15
+ declare const visitCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], visit: (slot: CommentMarkerSlot) => void) => void;
16
+ /**
17
+ * Comments that open a range anywhere in these blocks.
18
+ *
19
+ * A `commentReference` whose id is absent has no highlight of its own — the
20
+ * point-comment shape the model's `CommentReference` documents — and only that
21
+ * one needs its mark anchored onto neighbouring text. Anchoring one whose range
22
+ * exists stretches that range to wherever the reference sits, which is how a
23
+ * comment on one word came back covering the rest of the sentence. The range
24
+ * and the reference need not share a paragraph, so the question is asked of the
25
+ * whole story: a reference that trails the end of a range three paragraphs back
26
+ * is still not a point comment.
27
+ */
28
+ declare const rangedCommentIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
29
+ //#endregion
30
+ export { CommentMarkerSlot, rangedCommentIds, visitCommentMarkers };