@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,50 @@
1
+ import { visitInlineContentSlots } from "./paragraphTraversal.js";
2
+ //#region src/docx/commentAnchorIndex.ts
3
+ const visitCommentMarkers = (blocks, visit) => {
4
+ const visitParagraph = (paragraph) => {
5
+ visitInlineContentSlots(paragraph, ({ content, index, item }) => {
6
+ if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") visit({
7
+ content,
8
+ index,
9
+ item
10
+ });
11
+ });
12
+ };
13
+ const visitBlock = (block) => {
14
+ if (block.type === "paragraph") {
15
+ visitParagraph(block);
16
+ return;
17
+ }
18
+ if (block.type === "table") {
19
+ for (const row of block.rows) for (const cell of row.cells) visitBlocks(cell.content);
20
+ return;
21
+ }
22
+ if (block.type !== "blockSdt") return;
23
+ visitBlocks(block.content);
24
+ };
25
+ const visitBlocks = (nested) => {
26
+ for (const block of nested) visitBlock(block);
27
+ };
28
+ visitBlocks(blocks);
29
+ };
30
+ /**
31
+ * Comments that open a range anywhere in these blocks.
32
+ *
33
+ * A `commentReference` whose id is absent has no highlight of its own — the
34
+ * point-comment shape the model's `CommentReference` documents — and only that
35
+ * one needs its mark anchored onto neighbouring text. Anchoring one whose range
36
+ * exists stretches that range to wherever the reference sits, which is how a
37
+ * comment on one word came back covering the rest of the sentence. The range
38
+ * and the reference need not share a paragraph, so the question is asked of the
39
+ * whole story: a reference that trails the end of a range three paragraphs back
40
+ * is still not a point comment.
41
+ */
42
+ const rangedCommentIds = (blocks) => {
43
+ const ids = /* @__PURE__ */ new Set();
44
+ visitCommentMarkers(blocks, ({ item }) => {
45
+ if (item.type === "commentRangeStart") ids.add(item.id);
46
+ });
47
+ return ids;
48
+ };
49
+ //#endregion
50
+ export { rangedCommentIds, visitCommentMarkers };
@@ -1,6 +1,6 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { StyleMap } from "./styleParser.js";
3
2
  import { ParseContext } from "./parseContext.js";
3
+ import { StyleMap } from "./styleParser.js";
4
4
  //#region src/docx/commentParser.d.ts
5
5
  type CommentExtendedInfo = {
6
6
  parentParaId?: string;
@@ -1,8 +1,10 @@
1
1
  import { commentThreadParaId } from "./commentThreadKey.js";
2
+ import { CAPTURE, dispatchChildren } from "./containerChildren.js";
3
+ import { PARA_ID_NAMESPACE_URIS, paraIdAttribute, paraIdParentAttribute } from "./paraIdAttribute.js";
2
4
  import { parseParagraph } from "./paragraphParser.js";
3
5
  import { cloneParagraphWithPropertySource } from "./paragraphPropertySource.js";
4
- import { parseRunProperties } from "./runParser.js";
5
- import { NAMESPACES, WORDPROCESSINGML_NAMESPACE_URIS, findChild, getAttribute, getAttributeByNamespaceUri, getChildElements, getLocalName, parseOnOffValue, parseXml } from "./xmlParser.js";
6
+ import { RUN_PROPERTY_OWNERS, parseRunProperties } from "./runParser.js";
7
+ import { findChild, getAttribute, getAttributeByNamespaceUri, getChildElements, getLocalName, parseOnOffValue, parseXml } from "./xmlParser.js";
6
8
  import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
7
9
  //#region src/docx/commentParser.ts
8
10
  /**
@@ -26,26 +28,6 @@ import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
26
28
  /** The whole lexical form of `ST_DecimalNumber`: an optional sign and digits. */
27
29
  const DECIMAL_NUMBER = /^[+-]?\d+$/u;
28
30
  const DEFAULT_ANNOTATION_REFERENCE_STYLE_ID = "CommentReference";
29
- /**
30
- * The namespaces a paraId may be written in: Word 2010 and Word 2012 wordml.
31
- *
32
- * Resolved by URI rather than by prefix, because the value is a thread key: an
33
- * unrelated `vendor:paraId` picked up by local name alone would key a comment
34
- * to the wrong thread and carry that thread's date, parent and resolved state.
35
- */
36
- const PARA_ID_NAMESPACE_URIS = /* @__PURE__ */ new Set([NAMESPACES.w14, NAMESPACES.w15]);
37
- /**
38
- * A paraId join key, wherever an exporter writes it: on `w:comment` or `w:p`.
39
- *
40
- * One reading for both, so the wrapper and the paragraphs cannot come to
41
- * disagree about what counts as a key. The literal reads are the fallback for
42
- * a part that writes a conventional prefix without binding it, which no URI
43
- * lookup can resolve.
44
- */
45
- const paraIdAttribute = (element) => {
46
- const raw = getAttributeByNamespaceUri(element, PARA_ID_NAMESPACE_URIS, "paraId") ?? element.attributes?.["w14:paraId"] ?? element.attributes?.["w15:paraId"] ?? getAttributeByNamespaceUri(element, WORDPROCESSINGML_NAMESPACE_URIS, "paraId") ?? element.attributes?.["w:paraId"];
47
- return raw === null || raw === void 0 ? void 0 : String(raw);
48
- };
49
31
  const normalizeAnnotationReferenceFormatting = (formatting) => {
50
32
  if (formatting?.styleId === DEFAULT_ANNOTATION_REFERENCE_STYLE_ID && Object.keys(formatting).length === 1) return;
51
33
  return formatting;
@@ -54,10 +36,10 @@ const normalizeFirstCommentParagraph = (paragraphElement, paragraph, theme) => {
54
36
  const firstContentElement = getChildElements(paragraphElement).find((element) => getLocalName(element.name) !== "pPr");
55
37
  if (!firstContentElement || getLocalName(firstContentElement.name) !== "r" || !findChild(firstContentElement, "w", "annotationRef")) return { paragraph };
56
38
  const runProperties = findChild(firstContentElement, "w", "rPr");
57
- const annotationReferenceFormatting = normalizeAnnotationReferenceFormatting(runProperties ? parseRunProperties(runProperties, theme) : void 0);
39
+ const annotationReferenceFormatting = normalizeAnnotationReferenceFormatting(runProperties ? parseRunProperties(runProperties, theme, RUN_PROPERTY_OWNERS.standalone) : void 0);
58
40
  const firstParsedContent = paragraph.content.at(0);
59
41
  return {
60
- paragraph: firstParsedContent?.type === "run" && firstParsedContent.content.length === 0 ? cloneParagraphWithPropertySource(paragraph, { content: paragraph.content.slice(1) }) : paragraph,
42
+ paragraph: firstParsedContent?.type === "run" && firstParsedContent.content.every((item) => item.type === "preservedXml" && item.text === "") ? cloneParagraphWithPropertySource(paragraph, { content: paragraph.content.slice(1) }) : paragraph,
61
43
  ...annotationReferenceFormatting !== void 0 ? { annotationReferenceFormatting } : {}
62
44
  };
63
45
  };
@@ -75,9 +57,9 @@ function parseCommentsExtensible(xml) {
75
57
  const container = findChild(root, "w16cex", "commentsExtensible") ?? root;
76
58
  for (const child of getChildElements(container)) {
77
59
  if ((child.name?.replace(/^.*:/u, "") ?? "") !== "comment") continue;
78
- const paraId = getAttribute(child, "w16cex", "paraId") ?? getAttribute(child, "w15", "paraId") ?? child.attributes?.["w16cex:paraId"] ?? child.attributes?.["w15:paraId"];
79
- const dateUtc = getAttribute(child, "w16cex", "dateUtc") ?? getAttribute(child, "w15", "dateUtc") ?? child.attributes?.["w16cex:dateUtc"] ?? child.attributes?.["w15:dateUtc"];
80
- const key = paraId === null || paraId === void 0 ? null : String(paraId).toUpperCase();
60
+ const paraId = paraIdAttribute(child);
61
+ const dateUtc = getAttributeByNamespaceUri(child, PARA_ID_NAMESPACE_URIS, "dateUtc") ?? child.attributes?.["w16cex:dateUtc"] ?? child.attributes?.["w15:dateUtc"];
62
+ const key = paraId === void 0 ? null : paraId.toUpperCase();
81
63
  if (key && dateUtc && !dateUtcByParaId.has(key)) dateUtcByParaId.set(key, String(dateUtc));
82
64
  }
83
65
  return dateUtcByParaId;
@@ -102,11 +84,11 @@ function parseCommentsExtended(xml) {
102
84
  const container = findChild(root, "w15", "commentsEx") ?? root;
103
85
  for (const child of getChildElements(container)) {
104
86
  if ((child.name?.replace(/^.*:/u, "") ?? "") !== "commentEx") continue;
105
- const paraId = getAttribute(child, "w15", "paraId") ?? child.attributes?.["w15:paraId"];
87
+ const paraId = paraIdAttribute(child);
106
88
  if (!paraId) continue;
107
- const key = String(paraId).toUpperCase();
89
+ const key = paraId.toUpperCase();
108
90
  if (infoByParaId.has(key)) continue;
109
- const parentParaId = getAttribute(child, "w15", "paraIdParent") ?? child.attributes?.["w15:paraIdParent"];
91
+ const parentParaId = paraIdParentAttribute(child);
110
92
  const doneAttr = getAttribute(child, "w15", "done") ?? child.attributes?.["w15:done"];
111
93
  const info = {};
112
94
  if (parentParaId) info.parentParaId = String(parentParaId).toUpperCase();
@@ -155,16 +137,50 @@ function parseComments(commentsXml, styles, theme, rels, media, commentsExtensib
155
137
  const done = (paraId ? extendedByParaId.get(paraId) : void 0)?.done;
156
138
  const paragraphs = [];
157
139
  let annotationReferenceFormatting;
158
- for (const contentChild of getChildElements(child)) if ((contentChild.name?.replace(/^.*:/u, "") ?? "") === "p") {
159
- const paragraph = parseParagraph(contentChild, styles, theme, null, rels, media);
160
- if (paragraphs.length > 0) {
161
- paragraphs.push(paragraph);
162
- continue;
140
+ const preserved = dispatchChildren({
141
+ element: child,
142
+ container: "w:comment",
143
+ capturePosition: () => paragraphs.length,
144
+ handlers: {
145
+ p: (contentChild) => {
146
+ const paragraph = parseParagraph(contentChild, styles, theme, null, rels, media);
147
+ if (paragraphs.length > 0) {
148
+ paragraphs.push(paragraph);
149
+ return;
150
+ }
151
+ const normalized = normalizeFirstCommentParagraph(contentChild, paragraph, theme);
152
+ annotationReferenceFormatting = normalized.annotationReferenceFormatting;
153
+ paragraphs.push(normalized.paragraph);
154
+ },
155
+ altChunk: CAPTURE,
156
+ bookmarkEnd: CAPTURE,
157
+ bookmarkStart: CAPTURE,
158
+ commentRangeEnd: CAPTURE,
159
+ commentRangeStart: CAPTURE,
160
+ customXml: CAPTURE,
161
+ customXmlDelRangeEnd: CAPTURE,
162
+ customXmlDelRangeStart: CAPTURE,
163
+ customXmlInsRangeEnd: CAPTURE,
164
+ customXmlInsRangeStart: CAPTURE,
165
+ customXmlMoveFromRangeEnd: CAPTURE,
166
+ customXmlMoveFromRangeStart: CAPTURE,
167
+ customXmlMoveToRangeEnd: CAPTURE,
168
+ customXmlMoveToRangeStart: CAPTURE,
169
+ del: CAPTURE,
170
+ ins: CAPTURE,
171
+ moveFrom: CAPTURE,
172
+ moveFromRangeEnd: CAPTURE,
173
+ moveFromRangeStart: CAPTURE,
174
+ moveTo: CAPTURE,
175
+ moveToRangeEnd: CAPTURE,
176
+ moveToRangeStart: CAPTURE,
177
+ permEnd: CAPTURE,
178
+ permStart: CAPTURE,
179
+ proofErr: CAPTURE,
180
+ sdt: CAPTURE,
181
+ tbl: CAPTURE
163
182
  }
164
- const normalized = normalizeFirstCommentParagraph(contentChild, paragraph, theme);
165
- annotationReferenceFormatting = normalized.annotationReferenceFormatting;
166
- paragraphs.push(normalized.paragraph);
167
- }
183
+ });
168
184
  if (paraId && !commentIdByParaId.has(paraId)) commentIdByParaId.set(paraId, id);
169
185
  parsed.push({
170
186
  comment: {
@@ -174,6 +190,7 @@ function parseComments(commentsXml, styles, theme, rels, media, commentsExtensib
174
190
  ...date !== void 0 ? { date } : {},
175
191
  ...done !== void 0 ? { done } : {},
176
192
  ...annotationReferenceFormatting !== void 0 ? { annotationReferenceFormatting } : {},
193
+ ...preserved !== void 0 ? { preserved } : {},
177
194
  content: paragraphs
178
195
  },
179
196
  threadParaId: paraId
@@ -1,5 +1,20 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  //#region src/docx/commentRangeIntegrity.d.ts
3
+ /**
4
+ * Comment ids whose range is not a start followed by an end in this story's
5
+ * XML. Either half alone is invalid OOXML and anchors nothing: Word shows no
6
+ * comment for a range that never opens.
7
+ */
8
+ declare const unbalancedCommentRangeIds: (xml: string) => Set<string>;
9
+ /**
10
+ * Whether rewriting `originalXml` into `patchedXml` left a comment range with
11
+ * only one half. A save patches the paragraphs an edit touched and keeps the
12
+ * rest of the part byte-for-byte, so an edit that moves a range's only start
13
+ * out of a patched paragraph and into an untouched one writes an end with no
14
+ * start. Ranges the source already had unbalanced are not this save's doing
15
+ * and stay tolerated.
16
+ */
17
+ declare const patchBreaksCommentRangeBalance: (originalXml: string, patchedXml: string) => boolean;
3
18
  declare const withoutOrphanCommentRanges: (doc: document_d_exports.Document) => document_d_exports.Document;
4
19
  //#endregion
5
- export { withoutOrphanCommentRanges };
20
+ export { patchBreaksCommentRangeBalance, unbalancedCommentRangeIds, withoutOrphanCommentRanges };
@@ -1,5 +1,45 @@
1
1
  import { cloneParagraphWithPropertySource } from "./paragraphPropertySource.js";
2
2
  //#region src/docx/commentRangeIntegrity.ts
3
+ const COMMENT_RANGE_MARKER_PATTERN = /<w:commentRange(Start|End)\s[^>]*w:id="(\d+)"/gu;
4
+ /**
5
+ * Comment ids whose range is not a start followed by an end in this story's
6
+ * XML. Either half alone is invalid OOXML and anchors nothing: Word shows no
7
+ * comment for a range that never opens.
8
+ */
9
+ const unbalancedCommentRangeIds = (xml) => {
10
+ const firstStart = /* @__PURE__ */ new Map();
11
+ const lastEnd = /* @__PURE__ */ new Map();
12
+ for (const match of xml.matchAll(COMMENT_RANGE_MARKER_PATTERN)) {
13
+ const [, half, id] = match;
14
+ if (id === void 0) continue;
15
+ if (half === "Start") {
16
+ if (!firstStart.has(id)) firstStart.set(id, match.index);
17
+ continue;
18
+ }
19
+ lastEnd.set(id, match.index);
20
+ }
21
+ const unbalanced = /* @__PURE__ */ new Set();
22
+ for (const id of /* @__PURE__ */ new Set([...firstStart.keys(), ...lastEnd.keys()])) {
23
+ const start = firstStart.get(id);
24
+ const end = lastEnd.get(id);
25
+ if (start === void 0 || end === void 0 || end < start) unbalanced.add(id);
26
+ }
27
+ return unbalanced;
28
+ };
29
+ /**
30
+ * Whether rewriting `originalXml` into `patchedXml` left a comment range with
31
+ * only one half. A save patches the paragraphs an edit touched and keeps the
32
+ * rest of the part byte-for-byte, so an edit that moves a range's only start
33
+ * out of a patched paragraph and into an untouched one writes an end with no
34
+ * start. Ranges the source already had unbalanced are not this save's doing
35
+ * and stay tolerated.
36
+ */
37
+ const patchBreaksCommentRangeBalance = (originalXml, patchedXml) => {
38
+ const introduced = unbalancedCommentRangeIds(patchedXml);
39
+ if (introduced.size === 0) return false;
40
+ const preexisting = unbalancedCommentRangeIds(originalXml);
41
+ return [...introduced].some((id) => !preexisting.has(id));
42
+ };
3
43
  const withoutOrphanCommentRanges = (doc) => {
4
44
  const validCommentIds = new Set((doc.package.document.comments ?? []).map((comment) => comment.id));
5
45
  const document = withoutOrphanDocumentBodyMarkers(doc.package.document, validCommentIds);
@@ -107,6 +147,7 @@ const withoutOrphanBlockMarkers = (blocks, validCommentIds) => {
107
147
  const withoutOrphanBlockMarker = (block, validCommentIds) => {
108
148
  if (block.type === "paragraph") return withoutOrphanParagraphMarkers(block, validCommentIds);
109
149
  if (block.type === "table") return withoutOrphanTableMarkers(block, validCommentIds);
150
+ if (block.type !== "blockSdt") return block;
110
151
  const content = withoutOrphanBlockMarkers(block.content, validCommentIds);
111
152
  if (!content) return block;
112
153
  return {
@@ -180,4 +221,4 @@ const withoutOrphanParagraphMarkers = (paragraph, validCommentIds) => {
180
221
  };
181
222
  const isCommentMarker = (content) => content.type === "commentRangeStart" || content.type === "commentRangeEnd" || content.type === "commentReference";
182
223
  //#endregion
183
- export { withoutOrphanCommentRanges };
224
+ export { patchBreaksCommentRangeBalance, unbalancedCommentRangeIds, withoutOrphanCommentRanges };
@@ -0,0 +1,9 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/commentRangeJoin.d.ts
3
+ /**
4
+ * Collapse each comment's range markers to its first start and its last end.
5
+ * Answers how many markers were dropped.
6
+ */
7
+ declare const joinCommentRangesAcrossParagraphs: (blocks: readonly document_d_exports.BlockContent[]) => number;
8
+ //#endregion
9
+ export { joinCommentRangesAcrossParagraphs };
@@ -0,0 +1,33 @@
1
+ import { visitCommentMarkers } from "./commentAnchorIndex.js";
2
+ import { InlineContentRemovals } from "./inlineContentRemovals.js";
3
+ //#region src/docx/commentRangeJoin.ts
4
+ /**
5
+ * Collapse each comment's range markers to its first start and its last end.
6
+ * Answers how many markers were dropped.
7
+ */
8
+ const joinCommentRangesAcrossParagraphs = (blocks) => {
9
+ const startsById = /* @__PURE__ */ new Map();
10
+ const endsById = /* @__PURE__ */ new Map();
11
+ visitCommentMarkers(blocks, ({ content, index, item }) => {
12
+ if (item.type === "commentReference") return;
13
+ const slotsById = item.type === "commentRangeStart" ? startsById : endsById;
14
+ const slots = slotsById.get(item.id);
15
+ if (slots) {
16
+ slots.push({
17
+ content,
18
+ index
19
+ });
20
+ return;
21
+ }
22
+ slotsById.set(item.id, [{
23
+ content,
24
+ index
25
+ }]);
26
+ });
27
+ const removals = new InlineContentRemovals();
28
+ for (const slots of startsById.values()) for (const slot of slots.slice(1)) removals.mark(slot);
29
+ for (const slots of endsById.values()) for (const slot of slots.slice(0, -1)) removals.mark(slot);
30
+ return removals.apply();
31
+ };
32
+ //#endregion
33
+ export { joinCommentRangesAcrossParagraphs };
@@ -0,0 +1,9 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/commentReferenceCompletion.d.ts
3
+ /**
4
+ * Give every comment that a `commentRangeEnd` closes but no `commentReference`
5
+ * names a reference after its last end. Answers how many were added.
6
+ */
7
+ declare const completeCommentReferences: (blocks: readonly document_d_exports.BlockContent[]) => number;
8
+ //#endregion
9
+ export { completeCommentReferences };
@@ -0,0 +1,47 @@
1
+ import { visitCommentMarkers } from "./commentAnchorIndex.js";
2
+ //#region src/docx/commentReferenceCompletion.ts
3
+ /**
4
+ * Give every comment that a `commentRangeEnd` closes but no `commentReference`
5
+ * names a reference after its last end. Answers how many were added.
6
+ */
7
+ const completeCommentReferences = (blocks) => {
8
+ const lastRangeEnds = /* @__PURE__ */ new Map();
9
+ const referencedIds = /* @__PURE__ */ new Set();
10
+ visitCommentMarkers(blocks, ({ content, index, item }) => {
11
+ if (item.type === "commentReference") {
12
+ referencedIds.add(item.id);
13
+ return;
14
+ }
15
+ if (item.type === "commentRangeEnd") lastRangeEnds.set(item.id, {
16
+ content,
17
+ index
18
+ });
19
+ });
20
+ const insertionsByContent = /* @__PURE__ */ new Map();
21
+ for (const [id, { content, index }] of lastRangeEnds) {
22
+ if (referencedIds.has(id)) continue;
23
+ const pending = insertionsByContent.get(content);
24
+ if (pending) {
25
+ pending.push({
26
+ index,
27
+ id
28
+ });
29
+ continue;
30
+ }
31
+ insertionsByContent.set(content, [{
32
+ index,
33
+ id
34
+ }]);
35
+ }
36
+ let added = 0;
37
+ for (const [content, pending] of insertionsByContent) for (const { index, id } of pending.toSorted((first, second) => second.index - first.index || second.id - first.id)) {
38
+ content.splice(index + 1, 0, {
39
+ type: "commentReference",
40
+ id
41
+ });
42
+ added += 1;
43
+ }
44
+ return added;
45
+ };
46
+ //#endregion
47
+ export { completeCommentReferences };
@@ -1,4 +1,5 @@
1
- import { InlineContentRemovals, visitInlineContentSlots } from "./paragraphTraversal.js";
1
+ import { InlineContentRemovals } from "./inlineContentRemovals.js";
2
+ import { visitInlineContentSlots } from "./paragraphTraversal.js";
2
3
  import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
3
4
  //#region src/docx/commentReferenceNormalization.ts
4
5
  /** The codes this normalisation is reported under, owned here, not at the caller. */
@@ -39,6 +40,7 @@ const normalizeCommentReferences = ({ documentBody, comments, headers, footers,
39
40
  normalizeTable(block);
40
41
  return;
41
42
  }
43
+ if (block.type !== "blockSdt") return;
42
44
  normalizeBlocks(block.content);
43
45
  };
44
46
  const normalizeBlocks = (blocks) => {
@@ -25,34 +25,26 @@ const eachParagraph = (blocks, visit) => {
25
25
  for (const row of block.rows ?? []) for (const cell of row.cells ?? []) eachParagraph(cell.content ?? [], visit);
26
26
  continue;
27
27
  }
28
+ if (block.type !== "blockSdt") continue;
28
29
  eachParagraph(block.content ?? [], visit);
29
30
  }
30
31
  };
31
- const scanAnchors = (surfaces) => {
32
- const rangeIds = /* @__PURE__ */ new Set();
32
+ /** Comment ids with any anchor (a range start OR a `commentReference` run). */
33
+ const scanAnchoredIds = (surfaces) => {
33
34
  const anchoredIds = /* @__PURE__ */ new Set();
34
35
  for (const group of surfaceBlockGroups(surfaces)) eachParagraph(group, (paragraph) => {
35
- for (const item of paragraph.content ?? []) if (item.type === "commentRangeStart") {
36
- rangeIds.add(item.id);
37
- anchoredIds.add(item.id);
38
- } else if (item.type === "commentReference") anchoredIds.add(item.id);
36
+ for (const item of paragraph.content ?? []) if (item.type === "commentRangeStart" || item.type === "commentReference") anchoredIds.add(item.id);
39
37
  });
40
- return {
41
- rangeIds,
42
- anchoredIds
43
- };
38
+ return anchoredIds;
44
39
  };
45
40
  /** Replies whose parent is another comment (the threaded-discussion shape). */
46
41
  const commentParentedReplies = (comments) => {
47
42
  const commentIds = new Set(comments.map((comment) => comment.id));
48
43
  return comments.filter((comment) => comment.parentId !== void 0 && commentIds.has(comment.parentId));
49
44
  };
50
- const injectIntoParagraph = (paragraph, replyIdsByParent, parentsWithRange) => {
45
+ const injectIntoParagraph = (paragraph, replyIdsByParent) => {
51
46
  const content = paragraph.content ?? [];
52
- if (!content.some((item) => {
53
- if (item.type === "commentRangeStart" || item.type === "commentRangeEnd") return replyIdsByParent.has(item.id);
54
- return item.type === "commentReference" && !parentsWithRange.has(item.id) ? replyIdsByParent.has(item.id) : false;
55
- })) return 0;
47
+ if (!content.some((item) => (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") && replyIdsByParent.has(item.id))) return 0;
56
48
  const next = [];
57
49
  let injected = 0;
58
50
  for (const item of content) {
@@ -68,7 +60,7 @@ const injectIntoParagraph = (paragraph, replyIdsByParent, parentsWithRange) => {
68
60
  type: "commentRangeEnd",
69
61
  id: replyId
70
62
  });
71
- else if (item.type === "commentReference" && !parentsWithRange.has(item.id)) for (const replyId of replyIdsByParent.get(item.id) ?? []) {
63
+ else if (item.type === "commentReference") for (const replyId of replyIdsByParent.get(item.id) ?? []) {
72
64
  next.push({
73
65
  type: "commentReference",
74
66
  id: replyId
@@ -82,7 +74,7 @@ const injectIntoParagraph = (paragraph, replyIdsByParent, parentsWithRange) => {
82
74
  const synthesizeReplyRangeMarkers = (surfaces) => {
83
75
  const replies = commentParentedReplies(surfaces.comments);
84
76
  if (replies.length === 0) return 0;
85
- const { rangeIds, anchoredIds } = scanAnchors(surfaces);
77
+ const anchoredIds = scanAnchoredIds(surfaces);
86
78
  const replyIdsByParent = /* @__PURE__ */ new Map();
87
79
  for (const reply of replies) {
88
80
  if (anchoredIds.has(reply.id) || reply.parentId === void 0) continue;
@@ -93,7 +85,7 @@ const synthesizeReplyRangeMarkers = (surfaces) => {
93
85
  if (replyIdsByParent.size === 0) return 0;
94
86
  let injected = 0;
95
87
  const visit = (paragraph) => {
96
- injected += injectIntoParagraph(paragraph, replyIdsByParent, rangeIds);
88
+ injected += injectIntoParagraph(paragraph, replyIdsByParent);
97
89
  };
98
90
  for (const group of surfaceBlockGroups(surfaces)) eachParagraph(group, visit);
99
91
  return injected;
@@ -116,7 +108,7 @@ const hasUnsynthesizedReplyRanges = (doc) => {
116
108
  const surfaces = surfacesFromDocument(doc);
117
109
  const replies = commentParentedReplies(surfaces.comments);
118
110
  if (replies.length === 0) return false;
119
- const { anchoredIds } = scanAnchors(surfaces);
111
+ const anchoredIds = scanAnchoredIds(surfaces);
120
112
  return replies.some((reply) => !anchoredIds.has(reply.id));
121
113
  };
122
114
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { DRAWING_SAFETY_CLASSES, classifyDrawingSafety } from "./imageRawXml.js";
2
+ import { panic } from "better-result";
2
3
  import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
3
4
  //#region src/docx/compatibility.ts
4
5
  /**
@@ -97,6 +98,7 @@ function inspectBlocks(blocks, context) {
97
98
  });
98
99
  continue;
99
100
  }
101
+ if (block.type !== "blockSdt") continue;
100
102
  inspectBlocks(block.content, {
101
103
  part: context.part,
102
104
  path: `${blockPath}.content`,
@@ -113,53 +115,66 @@ function inspectParagraphContent(content, context) {
113
115
  ...context,
114
116
  path: `${context.path}[${itemIndex}]`
115
117
  };
116
- if (item.type === "run") {
117
- inspectRun(item, itemContext);
118
- continue;
119
- }
120
- if (item.type === "hyperlink") {
121
- inspectHyperlink(item, itemContext);
122
- continue;
123
- }
124
- if (item.type === "inlineSdt") {
125
- inspectParagraphContent(item.content, {
126
- ...itemContext,
127
- path: `${itemContext.path}.content`
128
- });
129
- continue;
118
+ switch (item.type) {
119
+ case "run":
120
+ inspectRun(item, itemContext);
121
+ continue;
122
+ case "hyperlink":
123
+ inspectHyperlink(item, itemContext);
124
+ continue;
125
+ case "inlineSdt":
126
+ case "inlineWrapper":
127
+ case "insertion":
128
+ case "deletion":
129
+ case "moveFrom":
130
+ case "moveTo":
131
+ case "simpleField":
132
+ inspectParagraphContent(item.content, {
133
+ ...itemContext,
134
+ path: `${itemContext.path}.content`
135
+ });
136
+ continue;
137
+ case "complexField":
138
+ for (const [runIndex, run] of item.fieldCode.entries()) inspectRun(run, {
139
+ ...itemContext,
140
+ path: `${itemContext.path}.fieldCode[${runIndex}]`
141
+ });
142
+ for (const [runIndex, run] of item.fieldResult.entries()) inspectRun(run, {
143
+ ...itemContext,
144
+ path: `${itemContext.path}.fieldResult[${runIndex}]`
145
+ });
146
+ continue;
147
+ case "bookmarkStart":
148
+ case "bookmarkEnd":
149
+ case "commentRangeStart":
150
+ case "commentRangeEnd":
151
+ case "commentReference":
152
+ case "moveFromRangeStart":
153
+ case "moveFromRangeEnd":
154
+ case "moveToRangeStart":
155
+ case "moveToRangeEnd":
156
+ case "mathEquation":
157
+ case "preservedInline": continue;
158
+ default: panic(`Unsupported paragraph content: ${JSON.stringify(item)}`);
130
159
  }
131
- if (item.type === "insertion" || item.type === "deletion" || item.type === "moveFrom" || item.type === "moveTo") {
132
- inspectParagraphContent(item.content, {
133
- ...itemContext,
134
- path: `${itemContext.path}.content`
135
- });
136
- continue;
137
- }
138
- if (item.type === "simpleField") {
139
- inspectParagraphContent(item.content, {
140
- ...itemContext,
141
- path: `${itemContext.path}.content`
160
+ }
161
+ }
162
+ function inspectHyperlink(hyperlink, context) {
163
+ for (const [childIndex, child] of hyperlink.children.entries()) {
164
+ const path = `${context.path}.children[${childIndex}]`;
165
+ if (child.type === "run") {
166
+ inspectRun(child, {
167
+ ...context,
168
+ path
142
169
  });
143
170
  continue;
144
171
  }
145
- if (item.type === "complexField") {
146
- for (const [runIndex, run] of item.fieldCode.entries()) inspectRun(run, {
147
- ...itemContext,
148
- path: `${itemContext.path}.fieldCode[${runIndex}]`
149
- });
150
- for (const [runIndex, run] of item.fieldResult.entries()) inspectRun(run, {
151
- ...itemContext,
152
- path: `${itemContext.path}.fieldResult[${runIndex}]`
153
- });
154
- }
172
+ if (child.type === "inlineWrapper") inspectParagraphContent(child.content, {
173
+ ...context,
174
+ path: `${path}.content`
175
+ });
155
176
  }
156
177
  }
157
- function inspectHyperlink(hyperlink, context) {
158
- for (const [childIndex, child] of hyperlink.children.entries()) if (child.type === "run") inspectRun(child, {
159
- ...context,
160
- path: `${context.path}.children[${childIndex}]`
161
- });
162
- }
163
178
  function inspectRun(run, context) {
164
179
  for (const [contentIndex, content] of run.content.entries()) {
165
180
  if (content.type !== "drawing") continue;