@stll/folio-core 0.67.0 → 0.69.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 (350) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +106 -36
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  7. package/dist/ai-edits/newListNumbering.js +24 -1
  8. package/dist/ai-edits/note-references.d.ts +6 -0
  9. package/dist/ai-edits/note-references.js +7 -1
  10. package/dist/ai-edits/pending-suggestions.js +2 -2
  11. package/dist/ai-edits/read.d.ts +19 -0
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +8 -3
  14. package/dist/ai-edits/types.d.ts +9 -1
  15. package/dist/ai-suggestions/apply.js +13 -4
  16. package/dist/compare/compare.js +2 -1
  17. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  18. package/dist/compare/inserted-resource-snapshot.js +7 -3
  19. package/dist/controller/canonicalClipboard.js +31 -14
  20. package/dist/controller/canonicalComposition.js +35 -6
  21. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  22. package/dist/controller/canonicalInlineProjection.js +192 -28
  23. package/dist/controller/canonicalInput.d.ts +2 -1
  24. package/dist/controller/canonicalInput.js +32 -7
  25. package/dist/controller/canonicalListRendering.d.ts +2 -1
  26. package/dist/controller/canonicalListRendering.js +1 -1
  27. package/dist/controller/canonicalLockGuard.d.ts +23 -0
  28. package/dist/controller/canonicalLockGuard.js +133 -0
  29. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  30. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  31. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  32. package/dist/controller/canonicalPublicOperations.js +676 -46
  33. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  34. package/dist/controller/canonicalSeedContent.js +131 -0
  35. package/dist/controller/canonicalSession.d.ts +133 -21
  36. package/dist/controller/canonicalSession.js +738 -205
  37. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  38. package/dist/controller/canonicalSourceNormalization.js +148 -0
  39. package/dist/controller/canonicalStoryEditor.d.ts +4 -3
  40. package/dist/controller/canonicalStoryEditor.js +20 -15
  41. package/dist/controller/canonicalStructure.d.ts +2 -1
  42. package/dist/controller/canonicalStructure.js +129 -7
  43. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  44. package/dist/controller/contentControlWidgetController.js +13 -1
  45. package/dist/controller/folioEditor.js +4 -0
  46. package/dist/controller/headerFooterEditorManager.d.ts +7 -2
  47. package/dist/controller/headerFooterEditorManager.js +11 -6
  48. package/dist/controller/hiddenEditorApi.d.ts +17 -2
  49. package/dist/controller/hiddenEditorApi.js +4 -0
  50. package/dist/controller/hiddenEditorManager.d.ts +11 -3
  51. package/dist/controller/hiddenEditorManager.js +157 -48
  52. package/dist/controller/layoutPipeline.js +50 -16
  53. package/dist/controller/layoutSession.d.ts +3 -0
  54. package/dist/controller/layoutSession.js +3 -1
  55. package/dist/controller/noteEditorManager.d.ts +7 -2
  56. package/dist/controller/noteEditorManager.js +11 -6
  57. package/dist/display-list/build/pageFurniture.js +41 -19
  58. package/dist/display-list/build/tablePrimitives.js +23 -4
  59. package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
  60. package/dist/document-operations.d.ts +9 -1
  61. package/dist/document-operations.js +4 -3
  62. package/dist/docx/blockContentParser.d.ts +7 -3
  63. package/dist/docx/blockContentParser.js +2 -3
  64. package/dist/docx/blockPlainText.js +2 -0
  65. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  66. package/dist/docx/bookmarkRangeJoin.js +43 -0
  67. package/dist/docx/canonicalSave.js +11 -2
  68. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  69. package/dist/docx/canonicalSessionInput.js +7 -2
  70. package/dist/docx/commentAnchorIndex.d.ts +40 -5
  71. package/dist/docx/commentAnchorIndex.js +94 -12
  72. package/dist/docx/commentRangeIntegrity.js +30 -24
  73. package/dist/docx/commentRangeJoin.d.ts +4 -0
  74. package/dist/docx/commentRangeJoin.js +26 -12
  75. package/dist/docx/commentReferenceCompletion.js +5 -4
  76. package/dist/docx/commentReferenceNormalization.js +40 -18
  77. package/dist/docx/compatibility.js +9 -2
  78. package/dist/docx/containerChildren.js +22 -1
  79. package/dist/docx/contentTypeRegistry.js +1 -1
  80. package/dist/docx/encryption/compoundFile.js +9 -1
  81. package/dist/docx/encryption/encryptionInfo.js +16 -2
  82. package/dist/docx/ensureParaIds.js +46 -7
  83. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  84. package/dist/docx/ensureUniqueControlIds.js +110 -0
  85. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  86. package/dist/docx/headerFooterVerbatim.js +13 -2
  87. package/dist/docx/hostCommentThreads.d.ts +27 -0
  88. package/dist/docx/hostCommentThreads.js +72 -0
  89. package/dist/docx/hyperlinkParser.js +9 -2
  90. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  91. package/dist/docx/inlineWrapperContent.js +9 -2
  92. package/dist/docx/listMarkerComputation.d.ts +35 -1
  93. package/dist/docx/listMarkerComputation.js +39 -1
  94. package/dist/docx/listModelNormalization.d.ts +44 -1
  95. package/dist/docx/listModelNormalization.js +226 -96
  96. package/dist/docx/listNumberingInstances.d.ts +1 -1
  97. package/dist/docx/listNumberingInstances.js +2 -2
  98. package/dist/docx/markupRangeMarker.d.ts +14 -0
  99. package/dist/docx/markupRangeMarker.js +15 -1
  100. package/dist/docx/metadataPrivacy.js +43 -22
  101. package/dist/docx/normalizeBaseDirection.js +3 -1
  102. package/dist/docx/numberingIds.d.ts +6 -0
  103. package/dist/docx/numberingIds.js +6 -1
  104. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  105. package/dist/docx/numberingReferenceNormalization.js +12 -2
  106. package/dist/docx/paragraphParser.js +159 -48
  107. package/dist/docx/paragraphPropertySource.d.ts +29 -0
  108. package/dist/docx/paragraphPropertySource.js +106 -16
  109. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  110. package/dist/docx/paragraphTraversal.js +2 -0
  111. package/dist/docx/parseWarningMessage.js +2 -1
  112. package/dist/docx/parser.js +8 -0
  113. package/dist/docx/removeHeaderFooterParts.js +1 -1
  114. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  115. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  116. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  117. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  118. package/dist/docx/reviewResolutionProvenance.js +171 -33
  119. package/dist/docx/rezip.d.ts +6 -0
  120. package/dist/docx/rezip.js +38 -21
  121. package/dist/docx/selectiveSave.js +6 -10
  122. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  123. package/dist/docx/selectiveXmlPatch.js +11 -7
  124. package/dist/docx/serializer/documentSerializer.js +5 -2
  125. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  126. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  127. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  128. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  129. package/dist/docx/serializer/noteSerializer.js +23 -16
  130. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  131. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  132. package/dist/docx/serializer/partNamespaces.js +1 -1
  133. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  134. package/dist/docx/serializer/runSerializer.js +2 -2
  135. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  136. package/dist/docx/serializer/tableSerializer.js +4 -2
  137. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  138. package/dist/docx/server/build.d.ts +1 -1
  139. package/dist/docx/server/createBilingualDocument.js +27 -5
  140. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  141. package/dist/docx/sessionListPruning.d.ts +2 -0
  142. package/dist/docx/sessionListPruning.js +50 -0
  143. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  144. package/dist/docx/splitRevisionPieces.js +14 -0
  145. package/dist/docx/storyBlockReplay.js +19 -2
  146. package/dist/docx/structuralXmlPatch.js +44 -11
  147. package/dist/docx/tableParser.d.ts +6 -2
  148. package/dist/docx/tableParser.js +2 -3
  149. package/dist/docx/textBoxContentParser.d.ts +11 -0
  150. package/dist/docx/textBoxContentParser.js +51 -0
  151. package/dist/docx/textBoxParser.d.ts +0 -5
  152. package/dist/docx/textBoxParser.js +1 -23
  153. package/dist/docx/verticalMergeProjection.js +1 -1
  154. package/dist/docx/xmlParser.d.ts +1 -1
  155. package/dist/docx/xmlParser.js +2 -3
  156. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  157. package/dist/fonts/fontsourceFaces.js +1 -7
  158. package/dist/i18n/messages/ar.gen.js +3 -0
  159. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  160. package/dist/i18n/messages/catalogs.gen.js +51 -0
  161. package/dist/i18n/messages/cs.gen.js +3 -0
  162. package/dist/i18n/messages/de.gen.js +3 -0
  163. package/dist/i18n/messages/en.gen.js +3 -0
  164. package/dist/i18n/messages/es.gen.js +3 -0
  165. package/dist/i18n/messages/et.gen.js +3 -0
  166. package/dist/i18n/messages/fr.gen.js +3 -0
  167. package/dist/i18n/messages/he.gen.js +3 -0
  168. package/dist/i18n/messages/hi.gen.js +3 -0
  169. package/dist/i18n/messages/hu.gen.js +3 -0
  170. package/dist/i18n/messages/lt.gen.js +3 -0
  171. package/dist/i18n/messages/lv.gen.js +3 -0
  172. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  173. package/dist/i18n/messages/pl.gen.js +3 -0
  174. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  175. package/dist/i18n/messages/sk.gen.js +3 -0
  176. package/dist/i18n/messages/tr.gen.js +3 -0
  177. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  178. package/dist/internal/acceptedBlockProjection.js +2 -0
  179. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  180. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  181. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  182. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  183. package/dist/internal/revisionResolutionInline.js +1 -2
  184. package/dist/internal/subtreeHolds.d.ts +12 -0
  185. package/dist/internal/subtreeHolds.js +25 -0
  186. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  187. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  188. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  189. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  190. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  191. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  192. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  193. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  194. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  195. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  196. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  197. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  198. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  199. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  200. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  201. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  202. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  203. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  204. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  205. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  206. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  207. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  208. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  209. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  210. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  211. package/dist/layout-bridge/engine/hitTest.js +9 -10
  212. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  213. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  214. package/dist/layout-bridge/tableInsertHover.js +2 -1
  215. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  216. package/dist/layout-engine/footnoteContinuation.js +210 -0
  217. package/dist/layout-engine/index.d.ts +2 -2
  218. package/dist/layout-engine/index.js +7 -2
  219. package/dist/layout-engine/measure/cache.d.ts +2 -0
  220. package/dist/layout-engine/measure/cache.js +16 -6
  221. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  222. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  223. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  224. package/dist/layout-engine/tableLayout.js +29 -5
  225. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  226. package/dist/layout-engine/tableRowBreak.js +43 -1
  227. package/dist/layout-engine/types.d.ts +42 -1
  228. package/dist/layout-painter/imageLayout.js +2 -1
  229. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  230. package/dist/layout-painter/pageShellStyles.js +32 -0
  231. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  232. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  233. package/dist/layout-painter/renderFragment.js +4 -6
  234. package/dist/layout-painter/renderImage.js +2 -2
  235. package/dist/layout-painter/renderPage.d.ts +4 -4
  236. package/dist/layout-painter/renderPage.js +54 -46
  237. package/dist/layout-painter/renderParagraph.js +3 -3
  238. package/dist/layout-painter/renderTable.js +16 -16
  239. package/dist/layout-painter/renderTextBox.js +2 -2
  240. package/dist/layout-painter/sdtBoundary.js +3 -2
  241. package/dist/managers/AutoSaveManager.d.ts +5 -1
  242. package/dist/managers/FindReplaceManager.js +3 -10
  243. package/dist/markdown/escape.d.ts +20 -1
  244. package/dist/markdown/escape.js +43 -1
  245. package/dist/markdown/renderBlock.js +4 -1
  246. package/dist/markdown/renderParagraph.js +13 -27
  247. package/dist/markdown/renderTable.js +6 -2
  248. package/dist/markdown/trailers.js +1 -0
  249. package/dist/paged-layout/blockGeometry.js +3 -2
  250. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  251. package/dist/paged-layout/editorScrollRoot.js +10 -1
  252. package/dist/paged-layout/rangeProjection.js +5 -4
  253. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  254. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  255. package/dist/paged-layout/selectionViewportRect.js +8 -2
  256. package/dist/pdf/images.d.ts +17 -1
  257. package/dist/pdf/images.js +22 -4
  258. package/dist/pdf/writePdf.js +4 -2
  259. package/dist/prosemirror/attrs/index.js +2 -0
  260. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  261. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  262. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  263. package/dist/prosemirror/commands/comments.d.ts +30 -2
  264. package/dist/prosemirror/commands/comments.js +189 -18
  265. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  266. package/dist/prosemirror/commands/index.d.ts +1 -1
  267. package/dist/prosemirror/commentIdAllocator.js +2 -2
  268. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  269. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  270. package/dist/prosemirror/commentRecords.d.ts +137 -0
  271. package/dist/prosemirror/commentRecords.js +400 -0
  272. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  273. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  274. package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
  275. package/dist/prosemirror/conversion/index.d.ts +2 -2
  276. package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
  277. package/dist/prosemirror/conversion/toProseDoc.js +432 -76
  278. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  279. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  280. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  281. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  282. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  283. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
  284. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  285. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  286. package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
  287. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  288. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  289. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  290. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  291. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  292. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  293. package/dist/prosemirror/index.d.ts +3 -3
  294. package/dist/prosemirror/listLabels.js +3 -2
  295. package/dist/prosemirror/listNumbering.d.ts +6 -0
  296. package/dist/prosemirror/listNumbering.js +12 -9
  297. package/dist/prosemirror/lockedControls.d.ts +13 -0
  298. package/dist/prosemirror/lockedControls.js +106 -0
  299. package/dist/prosemirror/markupViewProjection.js +1 -1
  300. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  301. package/dist/prosemirror/nativeSelection.js +74 -0
  302. package/dist/prosemirror/noteReferenceReview.js +2 -2
  303. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  304. package/dist/prosemirror/numberedRefFields.js +16 -5
  305. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  306. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  307. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  308. package/dist/prosemirror/plugins/documentNumbering.js +37 -15
  309. package/dist/prosemirror/plugins/suggestionMode.js +33 -10
  310. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  311. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  312. package/dist/prosemirror/replacedAnnotations.js +1 -0
  313. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  314. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  315. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  316. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  317. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  318. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  319. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  320. package/dist/prosemirror/runStyleFormatting.js +16 -13
  321. package/dist/prosemirror/schema/marks.d.ts +13 -1
  322. package/dist/prosemirror/storyListNumbering.js +7 -2
  323. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  324. package/dist/prosemirror/tableResize.d.ts +10 -9
  325. package/dist/prosemirror/tableResize.js +60 -49
  326. package/dist/prosemirror/textInput.d.ts +30 -1
  327. package/dist/prosemirror/textInput.js +144 -17
  328. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  329. package/dist/prosemirror/validation.d.ts +19 -0
  330. package/dist/prosemirror/validation.js +79 -5
  331. package/dist/redline.js +23 -9
  332. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  333. package/dist/render-dom/RenderedDomContext.js +7 -6
  334. package/dist/server.d.ts +2 -2
  335. package/dist/style-sets/extract.js +2 -2
  336. package/dist/types/canonicalCapabilities.d.ts +38 -16
  337. package/dist/types/canonicalCapabilities.js +21 -18
  338. package/dist/utils/cssString.d.ts +7 -0
  339. package/dist/utils/cssString.js +9 -0
  340. package/dist/utils/findMatchView.js +4 -3
  341. package/dist/utils/fontResolver.js +4 -1
  342. package/dist/utils/formatToStyle.d.ts +1 -1
  343. package/dist/utils/mergeDocumentContent.js +2 -2
  344. package/dist/utils/paintedPositions.d.ts +60 -0
  345. package/dist/utils/paintedPositions.js +101 -0
  346. package/dist/utils/replaceText.d.ts +11 -0
  347. package/dist/utils/replaceText.js +39 -7
  348. package/dist/version-comparison.d.ts +9 -1
  349. package/dist/version-comparison.js +11 -5
  350. package/package.json +2 -3
@@ -85,6 +85,20 @@ const requireSpinCount = (attrs, element) => {
85
85
  });
86
86
  return spinCount;
87
87
  };
88
+ /**
89
+ * Agile decryption here is AES-CBC only, whose block is always 16 bytes.
90
+ * The block size also sizes the padded verifier and segment IVs, so any
91
+ * other declared value is refused while parsing.
92
+ */
93
+ const AES_BLOCK_BYTES = 16;
94
+ const requireAesBlockSize = (attrs, element) => {
95
+ const blockSize = requireInt(attrs, "blockSize", element);
96
+ if (blockSize !== AES_BLOCK_BYTES) throw new DocxEncryptionError({
97
+ code: DOCX_ENCRYPTION_ERROR_CODES.DECRYPTION_FAILED,
98
+ message: `EncryptionInfo <${element}> attribute "blockSize" must be ${AES_BLOCK_BYTES}: ${blockSize}`
99
+ });
100
+ return blockSize;
101
+ };
88
102
  const parseAgileXml = (xmlBytes) => {
89
103
  const xml = decodeText(xmlBytes, { encoding: "utf-8" });
90
104
  const keyDataTag = findElement(xml, "keyData");
@@ -102,14 +116,14 @@ const parseAgileXml = (xmlBytes) => {
102
116
  packageKeyBits: requireInt(keyData, "keyBits", "keyData"),
103
117
  packageHash: requireAttr(keyData, "hashAlgorithm", "keyData"),
104
118
  packageHashBytes: requireInt(keyData, "hashSize", "keyData"),
105
- cipherBlockBytes: requireInt(keyData, "blockSize", "keyData"),
119
+ cipherBlockBytes: requireAesBlockSize(keyData, "keyData"),
106
120
  cipherName: requireAttr(keyData, "cipherAlgorithm", "keyData"),
107
121
  cipherMode: requireAttr(keyData, "cipherChaining", "keyData"),
108
122
  passwordIterations: requireSpinCount(encryptedKey, "encryptedKey"),
109
123
  passwordSalt: requireBase64(encryptedKey, "saltValue", "encryptedKey"),
110
124
  passwordHash: requireAttr(encryptedKey, "hashAlgorithm", "encryptedKey"),
111
125
  passwordKeyBits: requireInt(encryptedKey, "keyBits", "encryptedKey"),
112
- passwordBlockBytes: requireInt(encryptedKey, "blockSize", "encryptedKey"),
126
+ passwordBlockBytes: requireAesBlockSize(encryptedKey, "encryptedKey"),
113
127
  encryptedVerifierInput: requireBase64(encryptedKey, "encryptedVerifierHashInput", "encryptedKey"),
114
128
  encryptedVerifierDigest: requireBase64(encryptedKey, "encryptedVerifierHashValue", "encryptedKey"),
115
129
  encryptedIntermediateKey: requireBase64(encryptedKey, "encryptedKeyValue", "encryptedKey"),
@@ -1,4 +1,4 @@
1
- import { deterministicHexId } from "../utils/hexId.js";
1
+ import { deterministicHexId, isValidHexId } from "../utils/hexId.js";
2
2
  import { resolvePackageRelationshipTarget } from "./packageParts.js";
3
3
  import { spliceXml } from "./selectiveXmlPatch.js";
4
4
  import { loadDocxArchive } from "./server/boundedArchive.js";
@@ -29,7 +29,9 @@ import { ZipArchive } from "@stll/docx-core/zip";
29
29
  * so documents carrying features folio's parser does not model come back
30
30
  * with those features byte-identical. Contract:
31
31
  *
32
- * - Parts covered: the officeDocument relationship target, `word/header*.xml`, `word/footer*.xml`,
32
+ * - Parts covered: the officeDocument relationship target, the header,
33
+ * footer, footnotes, and endnotes parts its relationships name (wherever
34
+ * they live), and `word/header*.xml`, `word/footer*.xml`,
33
35
  * `word/footnotes.xml`, `word/endnotes.xml`. Paragraphs nested in table
34
36
  * cells and in `mc:Choice` text boxes are plain `<w:p>` elements inside
35
37
  * those parts and are covered by the same scan. The comments part mints its
@@ -38,8 +40,9 @@ import { ZipArchive } from "@stll/docx-core/zip";
38
40
  * - Paragraphs inside `mc:Fallback` are never modified: Word regenerates the
39
41
  * fallback branch (duplicating the `mc:Choice` ids) on save, so stamping or
40
42
  * deduplicating there would churn on every Word round-trip.
41
- * - Existing ids are preserved. Only three cases get a fresh id: a missing
43
+ * - Existing ids are preserved. Only these cases get a fresh id: a missing
42
44
  * `paraId`, the reserved all-zero value (Word reads `00000000` as "no id"),
45
+ * a value that is not eight hex digits (the parser drops it as no id),
43
46
  * and a duplicate of an id already seen earlier in the scan (first
44
47
  * occurrence keeps it — the same rule `ParaIdAllocatorExtension` applies in
45
48
  * the editor). `w14:textId` is written alongside a newly minted `paraId`
@@ -78,6 +81,13 @@ const DIGITAL_SIGNATURE_PART_PREFIX = "_xmlsignatures/";
78
81
  /** Word reads an all-zero `w14:paraId` as "no id assigned". */
79
82
  const RESERVED_ZERO_ID_PATTERN = /^0*$/u;
80
83
  const PACKAGE_RELATIONSHIP_URI = "http://schemas.openxmlformats.org/package/2006/relationships";
84
+ /** Relationship types, under each office namespace, whose targets are editable stories. */
85
+ const STORY_RELATIONSHIP_TYPES = [
86
+ "header",
87
+ "footer",
88
+ "footnotes",
89
+ "endnotes"
90
+ ];
81
91
  const TARGET_PART_PATTERNS = [
82
92
  /^word\/header\d*\.xml$/u,
83
93
  /^word\/footer\d*\.xml$/u,
@@ -241,7 +251,7 @@ const scanPart = ({ partPath, spelling, context, seen }) => {
241
251
  continue;
242
252
  }
243
253
  const value = paraId.value.toUpperCase();
244
- const unassigned = RESERVED_ZERO_ID_PATTERN.test(value);
254
+ const unassigned = !isValidHexId(value) || RESERVED_ZERO_ID_PATTERN.test(value);
245
255
  if (!unassigned && !seen.has(value)) {
246
256
  seen.add(value);
247
257
  continue;
@@ -316,8 +326,33 @@ const mainDocumentPart = (rels, entries) => {
316
326
  if (name === void 0) throw createEnsureParaIdsError("officeDocument part not found");
317
327
  return name;
318
328
  };
329
+ /** The `.rels` part that holds `partName`'s relationships. */
330
+ const relationshipsPathFor = (partName) => {
331
+ const slash = partName.lastIndexOf("/");
332
+ return `${partName.slice(0, slash + 1)}_rels/${partName.slice(slash + 1)}.rels`;
333
+ };
334
+ /**
335
+ * The header, footer, and note parts the main part's relationships name.
336
+ * The parser follows these relationships, so a story at a custom path
337
+ * (`word/custom/defaultHeader.xml`) is as editable as `word/header1.xml`.
338
+ */
339
+ const relatedStoryParts = (rels, relsPath, entries) => {
340
+ const parts = /* @__PURE__ */ new Set();
341
+ const root = rels === null ? null : parseXmlDocument(rels);
342
+ if (root === null || getLocalName(root.name ?? "") !== "Relationships" || getNamespaceUri(root) !== PACKAGE_RELATIONSHIP_URI) return parts;
343
+ const storyTypes = /* @__PURE__ */ new Set();
344
+ for (const uri of OFFICE_RELATIONSHIP_NAMESPACE_URIS) for (const type of STORY_RELATIONSHIP_TYPES) storyTypes.add(`${uri}/${type}`);
345
+ for (const element of getChildElements(root)) {
346
+ if (getLocalName(element.name ?? "") !== "Relationship" || getNamespaceUri(element) !== PACKAGE_RELATIONSHIP_URI || !storyTypes.has(getAttribute(element, null, "Type") ?? "") || getAttribute(element, null, "TargetMode") === "External") continue;
347
+ const target = getAttribute(element, null, "Target");
348
+ const partPath = target === null ? void 0 : resolvePackageRelationshipTarget(target, relsPath);
349
+ const name = partPath === void 0 ? void 0 : entries.find((entry) => entry.toLowerCase() === partPath);
350
+ if (name !== void 0) parts.add(name);
351
+ }
352
+ return parts;
353
+ };
319
354
  /** OPC part names are case-insensitive; compare lowercased. */
320
- const isTargetPart = (path) => TARGET_PART_PATTERNS.some((pattern) => pattern.test(path.toLowerCase()));
355
+ const matchesTargetPattern = (path) => TARGET_PART_PATTERNS.some((pattern) => pattern.test(path.toLowerCase()));
321
356
  const toUint8Array = (docx) => docx instanceof Uint8Array ? docx : new Uint8Array(docx);
322
357
  const hasDigitalSignatureParts = (zip) => zip.entries().some(({ path }) => path.toLowerCase().startsWith(DIGITAL_SIGNATURE_PART_PREFIX));
323
358
  /**
@@ -331,7 +366,11 @@ const ensureParaIdsInternal = async (docx, options) => {
331
366
  const rels = relsPath === void 0 ? null : await archive.readEntryString(relsPath);
332
367
  if (rels === null) throw createEnsureParaIdsError("Package relationships not found");
333
368
  const documentPartName = mainDocumentPart(rels, archive.entries);
334
- const xmlPartNames = archive.entries.filter((name) => name.toLowerCase().endsWith(".xml") || name === documentPartName);
369
+ const documentRelsPath = relationshipsPathFor(documentPartName);
370
+ const documentRelsName = archive.entries.find((name) => name.toLowerCase() === documentRelsPath.toLowerCase());
371
+ const storyParts = relatedStoryParts(documentRelsName === void 0 ? null : await archive.readEntryString(documentRelsName), documentRelsPath, archive.entries);
372
+ const isTargetPart = (name) => name !== documentPartName && (storyParts.has(name) || matchesTargetPattern(name));
373
+ const xmlPartNames = archive.entries.filter((name) => name.toLowerCase().endsWith(".xml") || name === documentPartName || storyParts.has(name));
335
374
  const partTexts = /* @__PURE__ */ new Map();
336
375
  for (const name of xmlPartNames) {
337
376
  const text = await archive.readEntryString(name);
@@ -345,7 +384,7 @@ const ensureParaIdsInternal = async (docx, options) => {
345
384
  taken,
346
385
  docKey: deterministicHexId(documentXml)
347
386
  };
348
- const targetParts = [documentPartName, ...xmlPartNames.filter((name) => name !== documentPartName && isTargetPart(name)).sort((a, b) => a.localeCompare(b))];
387
+ const targetParts = [documentPartName, ...xmlPartNames.filter((name) => isTargetPart(name)).sort((a, b) => a.localeCompare(b))];
349
388
  const spellings = /* @__PURE__ */ new Map();
350
389
  const seen = /* @__PURE__ */ new Set();
351
390
  for (const [partPath, xml] of partTexts) if (partPath === documentPartName || isTargetPart(partPath)) {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Headless `w:sdtPr/w:id` normalization for a `.docx` buffer.
3
+ *
4
+ * A content control names itself by `w:id`, and the package model holds
5
+ * every control by that id. A package can repeat one: a producer that copied
6
+ * a control, or merged two documents, wrote the same id twice. The first
7
+ * control in document order keeps its id; each later control carrying it gets
8
+ * an id the package does not use. Every control is kept, and so is everything
9
+ * else in the part.
10
+ *
11
+ * Alternate content (`mc:Fallback`) restates the controls of its `mc:Choice`
12
+ * under the same ids for older readers, and the parser reads one of the two,
13
+ * so a fallback's ids are reserved but never counted as a repeat.
14
+ */
15
+ export type EnsureUniqueControlIdsResult = {
16
+ /** The normalized `.docx`; the input bytes when nothing repeated. */
17
+ docx: Uint8Array;
18
+ /** Controls given a new id. */
19
+ reminted: number;
20
+ };
21
+ /**
22
+ * Give each content control after the first carrying an id an id of its own.
23
+ * A signed package, or a part that does not scan, is left as it is.
24
+ */
25
+ export declare const ensureUniqueControlIds: (docx: Uint8Array) => Promise<EnsureUniqueControlIdsResult>;
@@ -0,0 +1,110 @@
1
+ import { spliceXml } from "./selectiveXmlPatch.js";
2
+ import { WORDPROCESSINGML_NAMESPACE_URIS, getLocalName, getNamespaceUri, resolveAttributeNamespaceUri } from "./xmlParser.js";
3
+ import { scanStreamingXmlElements } from "@stll/docx-core/xml";
4
+ import { ZipArchive } from "@stll/docx-core/zip";
5
+ // src/docx/ensureUniqueControlIds.ts
6
+ /**
7
+ * Headless `w:sdtPr/w:id` normalization for a `.docx` buffer.
8
+ *
9
+ * A content control names itself by `w:id`, and the package model holds
10
+ * every control by that id. A package can repeat one: a producer that copied
11
+ * a control, or merged two documents, wrote the same id twice. The first
12
+ * control in document order keeps its id; each later control carrying it gets
13
+ * an id the package does not use. Every control is kept, and so is everything
14
+ * else in the part.
15
+ *
16
+ * Alternate content (`mc:Fallback`) restates the controls of its `mc:Choice`
17
+ * under the same ids for older readers, and the parser reads one of the two,
18
+ * so a fallback's ids are reserved but never counted as a repeat.
19
+ */
20
+ const MC_NAMESPACE_URI = "http://schemas.openxmlformats.org/markup-compatibility/2006";
21
+ const DIGITAL_SIGNATURE_PART_PREFIX = "_xmlsignatures/";
22
+ /** The story parts: the body, headers, footers, notes and comments. */
23
+ const STORY_PART_PATTERN = /^word\/[^/]+\.xml$/iu;
24
+ const isWordprocessing = (element, localName) => getLocalName(element.name ?? "") === localName && WORDPROCESSINGML_NAMESPACE_URIS.has(getNamespaceUri(element) ?? "");
25
+ /** Every control id a part carries, in document order. */
26
+ const controlIdsIn = (xml) => {
27
+ const out = [];
28
+ const fallbacks = /* @__PURE__ */ new WeakSet();
29
+ return scanStreamingXmlElements(xml, ({ element, attributeValueSpans, parent }) => {
30
+ const inFallback = parent !== void 0 && fallbacks.has(parent) || getLocalName(element.name ?? "") === "Fallback" && getNamespaceUri(element) === MC_NAMESPACE_URI;
31
+ if (inFallback) fallbacks.add(element);
32
+ if (parent === void 0 || !isWordprocessing(element, "id") || !isWordprocessing(parent, "sdtPr")) return;
33
+ for (const [name, span] of attributeValueSpans) {
34
+ if (getLocalName(name) !== "val" || !WORDPROCESSINGML_NAMESPACE_URIS.has(resolveAttributeNamespaceUri(element, name) ?? "")) continue;
35
+ const value = Number(element.attributes?.[name]);
36
+ if (Number.isInteger(value)) out.push({
37
+ start: span.start,
38
+ end: span.end,
39
+ value,
40
+ inFallback
41
+ });
42
+ }
43
+ }).status === "scanned" ? out : void 0;
44
+ };
45
+ /**
46
+ * Give each content control after the first carrying an id an id of its own.
47
+ * A signed package, or a part that does not scan, is left as it is.
48
+ */
49
+ const ensureUniqueControlIds = async (docx) => {
50
+ const zip = await ZipArchive.read(docx);
51
+ const entries = zip.entries();
52
+ if (entries.some(({ path }) => path.toLowerCase().startsWith(DIGITAL_SIGNATURE_PART_PREFIX))) return {
53
+ docx,
54
+ reminted: 0
55
+ };
56
+ const parts = entries.map(({ path }) => path).filter((path) => STORY_PART_PATTERN.test(path)).sort((a, b) => {
57
+ const body = (path) => path.toLowerCase() === "word/document.xml" ? 0 : 1;
58
+ return body(a) - body(b) || a.localeCompare(b);
59
+ });
60
+ const texts = /* @__PURE__ */ new Map();
61
+ const ids = /* @__PURE__ */ new Map();
62
+ const taken = /* @__PURE__ */ new Set();
63
+ for (const path of parts) {
64
+ const xml = await zip.entry(path)?.text();
65
+ if (xml === void 0 || !xml.includes("sdtPr")) continue;
66
+ const found = controlIdsIn(xml);
67
+ if (found === void 0) continue;
68
+ texts.set(path, xml);
69
+ ids.set(path, found);
70
+ for (const { value } of found) taken.add(value);
71
+ }
72
+ let next = 1;
73
+ const fresh = () => {
74
+ while (taken.has(next)) next += 1;
75
+ taken.add(next);
76
+ return next;
77
+ };
78
+ const seen = /* @__PURE__ */ new Set();
79
+ let reminted = 0;
80
+ for (const [path, found] of ids) {
81
+ const edits = [];
82
+ for (const { start, end, value, inFallback } of found) {
83
+ if (inFallback) continue;
84
+ if (!seen.has(value)) {
85
+ seen.add(value);
86
+ continue;
87
+ }
88
+ edits.push({
89
+ start,
90
+ end,
91
+ newXml: String(fresh())
92
+ });
93
+ }
94
+ if (edits.length === 0) continue;
95
+ const patched = spliceXml(texts.get(path), edits);
96
+ if (patched === null) continue;
97
+ const source = zip.entry(path);
98
+ zip.set(path, patched, source ? { modified: source.modified } : {});
99
+ reminted += edits.length;
100
+ }
101
+ if (reminted === 0) return {
102
+ docx,
103
+ reminted
104
+ };
105
+ return {
106
+ docx: await zip.generate({ level: 6 }),
107
+ reminted
108
+ };
109
+ };
110
+ export { ensureUniqueControlIds };
@@ -26,6 +26,13 @@ export declare const refreshHeaderFooterVerbatimFingerprint: (hf: document_d_exp
26
26
  export declare const clearHeaderFooterVerbatimXml: (hf: document_d_exports.HeaderFooter) => void;
27
27
  /** Capture parsed resources on the same trusted handle, including an absent main part. */
28
28
  export declare const captureDocumentSourceBaseline: (document: document_d_exports.Document, xml: string | undefined) => void;
29
+ /** The numbering instance and abstract definition ids the source package had. */
30
+ export type SourceNumberingIds = {
31
+ readonly nums: ReadonlySet<number>;
32
+ readonly abstractNums: ReadonlySet<number>;
33
+ };
34
+ /** The numbering ids the parsed source had, or `undefined` without a capture. */
35
+ export declare const getDocumentSourceNumberingIds: (document: document_d_exports.Document) => SourceNumberingIds | undefined;
29
36
  /** Read the identity-stable, deeply frozen stylesheet without cloning or body comparison. */
30
37
  export declare const getDocumentSourceStyles: (document: document_d_exports.Document, liveStyles?: document_d_exports.Document["package"]["styles"]) => {
31
38
  readonly type: "missing";
@@ -160,11 +160,16 @@ const captureDocumentSourceBaseline = (document, xml) => {
160
160
  const resourceStyles = structuredClone(document.package.styles);
161
161
  freezeSourceStyles(resourceStyles);
162
162
  const styleIds = new Set(resourceStyles?.styles.map(({ styleId }) => styleId));
163
+ const numberingIds = {
164
+ nums: new Set(document.package.numbering?.nums.map(({ numId }) => numId)),
165
+ abstractNums: new Set(document.package.numbering?.abstractNums.map(({ abstractNumId }) => abstractNumId))
166
+ };
163
167
  if (xml === void 0) contentBaselines.set(handle, {
164
168
  type: "body",
165
169
  kind: "noMainPart",
166
170
  resourceStyles,
167
- styleIds
171
+ styleIds,
172
+ numberingIds
168
173
  });
169
174
  else contentBaselines.set(handle, {
170
175
  type: "body",
@@ -174,6 +179,7 @@ const captureDocumentSourceBaseline = (document, xml) => {
174
179
  body: structuredClone(document.package.document),
175
180
  resourceStyles,
176
181
  styleIds,
182
+ numberingIds,
177
183
  resourceRelationships: structuredClone(document.package.relationships),
178
184
  resourceMedia: new Map([...document.package.media ?? []].map(([path, media]) => [path, {
179
185
  data: media.data,
@@ -203,6 +209,11 @@ const readDocumentSourceCapture = (document) => {
203
209
  baseline
204
210
  };
205
211
  };
212
+ /** The numbering ids the parsed source had, or `undefined` without a capture. */
213
+ const getDocumentSourceNumberingIds = (document) => {
214
+ const source = readDocumentSourceCapture(document);
215
+ return source.type === "captured" ? source.baseline.numberingIds : void 0;
216
+ };
206
217
  /** Read the identity-stable, deeply frozen stylesheet without cloning or body comparison. */
207
218
  const getDocumentSourceStyles = (document, liveStyles) => {
208
219
  const source = readDocumentSourceCapture(document);
@@ -239,4 +250,4 @@ const getDocumentSourceBaseline = (document) => {
239
250
  resourceMedia: baseline.resourceMedia
240
251
  };
241
252
  };
242
- export { assignHeaderFooterVerbatimXml, canReplayHeaderFooterBlocks, canReplayHeaderFooterVerbatim, captureDocumentSourceBaseline, captureHeaderFooterPackageBaselines, clearHeaderFooterVerbatimXml, copyHeaderFooterBaselineHandles, copyHeaderFooterPackageBaselines, getDocumentSourceBaseline, getDocumentSourceStyles, getHeaderFooterSourceBaseline, getHeaderFooterVerbatimXml, refreshHeaderFooterVerbatimFingerprint };
253
+ export { assignHeaderFooterVerbatimXml, canReplayHeaderFooterBlocks, canReplayHeaderFooterVerbatim, captureDocumentSourceBaseline, captureHeaderFooterPackageBaselines, clearHeaderFooterVerbatimXml, copyHeaderFooterBaselineHandles, copyHeaderFooterPackageBaselines, getDocumentSourceBaseline, getDocumentSourceNumberingIds, getDocumentSourceStyles, getHeaderFooterSourceBaseline, getHeaderFooterVerbatimXml, refreshHeaderFooterVerbatimFingerprint };
@@ -0,0 +1,27 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { Comment } from "../types/content.js";
3
+ export declare function getCommentParentId(comment: Comment): number | null | undefined;
4
+ /**
5
+ * The comments whose reply chain reaches a top-level comment.
6
+ *
7
+ * Every top-level comment is kept, whether or not its anchor survives:
8
+ * documents without reply-thread metadata deliver replies as top-level
9
+ * comments, and dropping unanchored ones would drop those replies. Replies
10
+ * whose parent chain does not reach a kept top-level comment are dropped.
11
+ */
12
+ export declare function pruneOrphanedComments(comments: readonly Comment[], _referencedIds?: ReadonlySet<number>): Comment[];
13
+ export type HostCommentThreadsOptions = {
14
+ /**
15
+ * The comment ids the editor's own document anchors, or `null` when the
16
+ * host has no editor document. A thread anchored there that the document
17
+ * being saved leaves out (a comment a pending suggestion proposes, which
18
+ * the save holds back with the suggestion) is left out with its replies:
19
+ * a saved thread without its anchor is a stray card on reopening.
20
+ */
21
+ anchoredInEditor: ReadonlySet<number> | null;
22
+ };
23
+ /**
24
+ * `document` with its body's comment threads replaced by the host's. The body
25
+ * and package are copied, so the document passed in is left as it was.
26
+ */
27
+ export declare function withHostCommentThreads(document: document_d_exports.Document, comments: readonly Comment[], { anchoredInEditor }: HostCommentThreadsOptions): document_d_exports.Document;
@@ -0,0 +1,72 @@
1
+ import { setDocumentBodyComments } from "./canonicalModel.js";
2
+ import { visitCommentMarkers } from "./commentAnchorIndex.js";
3
+ // src/docx/hostCommentThreads.ts
4
+ function getCommentParentId(comment) {
5
+ return comment.parentId;
6
+ }
7
+ /**
8
+ * The comments whose reply chain reaches a top-level comment.
9
+ *
10
+ * Every top-level comment is kept, whether or not its anchor survives:
11
+ * documents without reply-thread metadata deliver replies as top-level
12
+ * comments, and dropping unanchored ones would drop those replies. Replies
13
+ * whose parent chain does not reach a kept top-level comment are dropped.
14
+ */
15
+ function pruneOrphanedComments(comments, _referencedIds) {
16
+ const keptIds = /* @__PURE__ */ new Set();
17
+ for (const comment of comments) {
18
+ const parentId = getCommentParentId(comment);
19
+ if (parentId === null || parentId === void 0) keptIds.add(comment.id);
20
+ }
21
+ let addedThisPass = true;
22
+ while (addedThisPass) {
23
+ addedThisPass = false;
24
+ for (const comment of comments) {
25
+ if (keptIds.has(comment.id)) continue;
26
+ const parentId = getCommentParentId(comment);
27
+ if (parentId !== null && parentId !== void 0 && keptIds.has(parentId)) {
28
+ keptIds.add(comment.id);
29
+ addedThisPass = true;
30
+ }
31
+ }
32
+ }
33
+ return comments.filter((comment) => keptIds.has(comment.id));
34
+ }
35
+ /** The comment ids the saved stories of `document` anchor. */
36
+ const commentIdsAnchoredIn = (document) => {
37
+ const ids = /* @__PURE__ */ new Set();
38
+ const visit = (blocks) => visitCommentMarkers(blocks, ({ item }) => {
39
+ ids.add(item.id);
40
+ });
41
+ const { package: pkg } = document;
42
+ visit(pkg.document.content);
43
+ for (const story of [
44
+ ...pkg.headers?.values() ?? [],
45
+ ...pkg.footers?.values() ?? [],
46
+ ...pkg.footnotes ?? [],
47
+ ...pkg.endnotes ?? []
48
+ ]) visit(story.content);
49
+ return ids;
50
+ };
51
+ /**
52
+ * `document` with its body's comment threads replaced by the host's. The body
53
+ * and package are copied, so the document passed in is left as it was.
54
+ */
55
+ function withHostCommentThreads(document, comments, { anchoredInEditor }) {
56
+ const body = { ...document.package.document };
57
+ const kept = (() => {
58
+ if (anchoredInEditor === null || anchoredInEditor.size === 0) return comments;
59
+ const saved = commentIdsAnchoredIn(document);
60
+ const heldBack = new Set(comments.filter(({ id }) => anchoredInEditor.has(id) && !saved.has(id)).map(({ id }) => id));
61
+ return heldBack.size === 0 ? comments : comments.filter(({ id }) => !heldBack.has(id));
62
+ })();
63
+ setDocumentBodyComments(body, pruneOrphanedComments(kept));
64
+ return {
65
+ ...document,
66
+ package: {
67
+ ...document.package,
68
+ document: body
69
+ }
70
+ };
71
+ }
72
+ export { getCommentParentId, pruneOrphanedComments, withHostCommentThreads };
@@ -8,6 +8,7 @@ import { standalonePreviewLedger } from "./previewBudget.js";
8
8
  import { RELATIONSHIP_TYPES, resolveRelationshipIdOfType } from "./relsParser.js";
9
9
  import { parseRun } from "./runParser.js";
10
10
  import { runHoldsPayload } from "./runPayload.js";
11
+ import { tagSplitPiece } from "./splitRevisionPieces.js";
11
12
  import { WORDPROCESSINGML_NAMESPACE_URIS, findChildren, getAttribute, getAttributeByNamespaceUri, mergeXmlnsDeclarations, parseNumericAttribute, parseOnOffAttribute } from "./xmlParser.js";
12
13
  import { isValidOoxmlNumericId } from "@stll/docx-core";
13
14
  // src/docx/hyperlinkParser.ts
@@ -278,7 +279,9 @@ const parseLinkedInlineWrapper = (element, node, context) => {
278
279
  }
279
280
  }
280
281
  });
281
- return inlineWrapperOf(element, node, withPreservedChildren(content, preserved, preservedInlineCapture));
282
+ const wrapper = inlineWrapperOf(element, node, withPreservedChildren(content, preserved, preservedInlineCapture));
283
+ tagSplitPiece(node, wrapper);
284
+ return wrapper;
282
285
  };
283
286
  /**
284
287
  * Get the display text of a hyperlink
@@ -353,7 +356,11 @@ function getHyperlinkRuns(hyperlink) {
353
356
  runs.push(item);
354
357
  continue;
355
358
  }
356
- if (item.type === "inlineWrapper") collect(item.content);
359
+ if (item.type === "inlineWrapper") {
360
+ collect(item.content);
361
+ continue;
362
+ }
363
+ if (item.type === "complexField") runs.push(...item.fieldResult);
357
364
  }
358
365
  };
359
366
  collect(hyperlink.children);
@@ -110,7 +110,7 @@ export declare const HYPERLINK_CONTENT: {
110
110
  readonly inlineWrapper: true;
111
111
  readonly preservedInline: true;
112
112
  readonly run: true;
113
- readonly complexField: false;
113
+ readonly complexField: true;
114
114
  readonly deletion: false;
115
115
  readonly hyperlink: false;
116
116
  readonly inlineSdt: false;
@@ -155,6 +155,13 @@ export declare const SIMPLE_FIELD_CONTENT: {
155
155
  readonly moveToRangeStart: false;
156
156
  readonly simpleField: false;
157
157
  };
158
+ /**
159
+ * Every paragraph content kind is a tracked change child. The reader keeps a
160
+ * tracked change whole on this: its resolution joins describe the one wrapper.
161
+ * A model kind outside `TrackedRunContent` turns this type to `never`, so the
162
+ * build fails until reading such a change is designed.
163
+ */
164
+ export declare const EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD: (typeof TRACKED_CHANGE_WRAPPER_CONTENT)[document_d_exports.ParagraphContent["type"]] extends true ? true : never;
158
165
  /**
159
166
  * Whether a revision wrapper keeps this content inside itself.
160
167
  *
@@ -110,7 +110,7 @@ const HYPERLINK_CONTENT = {
110
110
  inlineWrapper: true,
111
111
  preservedInline: true,
112
112
  run: true,
113
- complexField: false,
113
+ complexField: true,
114
114
  deletion: false,
115
115
  hyperlink: false,
116
116
  inlineSdt: false,
@@ -156,6 +156,13 @@ const SIMPLE_FIELD_CONTENT = {
156
156
  simpleField: false
157
157
  };
158
158
  /**
159
+ * Every paragraph content kind is a tracked change child. The reader keeps a
160
+ * tracked change whole on this: its resolution joins describe the one wrapper.
161
+ * A model kind outside `TrackedRunContent` turns this type to `never`, so the
162
+ * build fails until reading such a change is designed.
163
+ */
164
+ const EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD = true;
165
+ /**
159
166
  * Whether a revision wrapper keeps this content inside itself.
160
167
  *
161
168
  * Generic in the input so a caller that has already narrowed its content
@@ -169,4 +176,4 @@ const isInlineSdtContent = (content) => INLINE_SDT_CONTENT[content.type];
169
176
  const isHyperlinkContent = (content) => HYPERLINK_CONTENT[content.type];
170
177
  /** Whether a `w:fldSimple` keeps this content inside itself. */
171
178
  const isSimpleFieldContent = (content) => SIMPLE_FIELD_CONTENT[content.type];
172
- export { HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
179
+ export { EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD, HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
@@ -12,4 +12,38 @@ export type ComputeListMarkerOptions = {
12
12
  restartedNumIds: Set<number>;
13
13
  previousList: PreviousListState;
14
14
  };
15
- export declare const computeListMarker: (paragraph: document_d_exports.Paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }: ComputeListMarkerOptions) => void;
15
+ /**
16
+ * What each field of the marker counters depends on: the package alone, or
17
+ * the paragraphs of the story before the current one. Total over the fields:
18
+ * one added does not compile until it is placed, and the story half is what
19
+ * a snapshot copies.
20
+ */
21
+ declare const LIST_COUNTER_DEPENDENCY: {
22
+ readonly numbering: "package";
23
+ readonly listCounters: "story";
24
+ readonly abstractCounters: "story";
25
+ readonly restartedNumIds: "story";
26
+ readonly previousList: "story";
27
+ };
28
+ type CounterDependency = typeof LIST_COUNTER_DEPENDENCY;
29
+ type StoryCounterField = { [K in keyof CounterDependency]: CounterDependency[K] extends "story" ? K : never; }[keyof CounterDependency];
30
+ /**
31
+ * The story half of the marker counters at one paragraph, copied. Counter
32
+ * arrays are shared between a list instance and its abstract list, and a
33
+ * later paragraph advances the shared array, so the copy names each array by
34
+ * its index in `arrays` and keeps which entries share one.
35
+ */
36
+ export type ListCounterSnapshot = {
37
+ readonly arrays: readonly (readonly number[])[];
38
+ readonly listCounters: readonly (readonly [number, number])[];
39
+ readonly abstractCounters: readonly (readonly [number, number])[];
40
+ readonly restartedNumIds: readonly number[];
41
+ readonly previousList: Readonly<PreviousListState>;
42
+ } & Record<StoryCounterField, unknown>;
43
+ export declare const snapshotListCounters: (counters: ComputeListMarkerOptions) => ListCounterSnapshot;
44
+ /** Put the story half of `counters` back as the snapshot copied it. */
45
+ export declare const restoreListCounters: (counters: ComputeListMarkerOptions, snapshot: ListCounterSnapshot) => void;
46
+ /** Whether two snapshots hold the same counters, shared the same way, in the same order. */
47
+ export declare const sameListCounters: (left: ListCounterSnapshot, right: ListCounterSnapshot) => boolean;
48
+ export declare const computeListMarker: (paragraph: document_d_exports.Paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }: ComputeListMarkerOptions) => void;
49
+ export {};
@@ -1,7 +1,45 @@
1
1
  import { bulletMarkerFontName, convertBulletToUnicode } from "./bulletMarkers.js";
2
2
  import { resolveListTemplate } from "./listTemplate.js";
3
3
  import { isNumberingReference } from "./numberingReference.js";
4
+ import { panic } from "better-result";
4
5
  // src/docx/listMarkerComputation.ts
6
+ /** Marker counters shared by parsing and canonical model normalization. */
7
+ const snapshotListCounters = (counters) => {
8
+ const indices = /* @__PURE__ */ new Map();
9
+ const arrays = [];
10
+ const indexOf = (values) => {
11
+ const known = indices.get(values);
12
+ if (known !== void 0) return known;
13
+ indices.set(values, arrays.length);
14
+ arrays.push([...values]);
15
+ return arrays.length - 1;
16
+ };
17
+ return {
18
+ listCounters: [...counters.listCounters].map(([numId, values]) => [numId, indexOf(values)]),
19
+ abstractCounters: [...counters.abstractCounters].map(([abstractNumId, values]) => [abstractNumId, indexOf(values)]),
20
+ arrays,
21
+ restartedNumIds: [...counters.restartedNumIds],
22
+ previousList: { ...counters.previousList }
23
+ };
24
+ };
25
+ /** Put the story half of `counters` back as the snapshot copied it. */
26
+ const restoreListCounters = (counters, snapshot) => {
27
+ const arrays = snapshot.arrays.map((values) => [...values]);
28
+ const arrayAt = (index) => arrays[index] ?? panic("A list counter snapshot lost an array.");
29
+ const story = {
30
+ listCounters: new Map(snapshot.listCounters.map(([numId, index]) => [numId, arrayAt(index)])),
31
+ abstractCounters: new Map(snapshot.abstractCounters.map(([abstractNumId, index]) => [abstractNumId, arrayAt(index)])),
32
+ restartedNumIds: new Set(snapshot.restartedNumIds),
33
+ previousList: { ...snapshot.previousList }
34
+ };
35
+ Object.assign(counters, story);
36
+ };
37
+ const samePairs = (left, right) => left.length === right.length && left.every(([key, index], at) => right[at]?.[0] === key && right[at]?.[1] === index);
38
+ /** Whether two snapshots hold the same counters, shared the same way, in the same order. */
39
+ const sameListCounters = (left, right) => left.previousList.abstractNumId === right.previousList.abstractNumId && left.previousList.fromStyle === right.previousList.fromStyle && left.previousList.numId === right.previousList.numId && left.restartedNumIds.length === right.restartedNumIds.length && left.restartedNumIds.every((numId, at) => right.restartedNumIds[at] === numId) && samePairs(left.listCounters, right.listCounters) && samePairs(left.abstractCounters, right.abstractCounters) && left.arrays.length === right.arrays.length && left.arrays.every((values, at) => {
40
+ const other = right.arrays[at];
41
+ return other !== void 0 && values.length === other.length && values.every((value, index) => Object.is(value, other[index]));
42
+ });
5
43
  const computeListMarker = (paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }) => {
6
44
  const listRendering = paragraph.listRendering;
7
45
  if (!listRendering || !numbering) {
@@ -68,4 +106,4 @@ const computeListMarker = (paragraph, { numbering, listCounters, abstractCounter
68
106
  forceDecimal: currentLevelInfo?.isLgl === true || listRendering.isLegal === true
69
107
  });
70
108
  };
71
- export { computeListMarker };
109
+ export { computeListMarker, restoreListCounters, sameListCounters, snapshotListCounters };