@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
@@ -29,6 +29,7 @@ const UNNUMBERED_PARAGRAPH_WARNING = PARSE_WARNING_CODES.unnumberedParagraph;
29
29
  const UNNUMBERED_STYLE_WARNING = PARSE_WARNING_CODES.unnumberedStyle;
30
30
  const normalizeNumberingReferences = ({ documentBody, numbering, headers, footers, footnotes, endnotes }) => {
31
31
  let unnumberedDanglingReferences = 0;
32
+ const danglingNumIds = /* @__PURE__ */ new Set();
32
33
  visitDocxParagraphs({
33
34
  documentBody,
34
35
  headers,
@@ -39,22 +40,31 @@ const normalizeNumberingReferences = ({ documentBody, numbering, headers, footer
39
40
  const formatting = paragraph.formatting;
40
41
  const numId = paragraphNumberingReferenceId(formatting?.numPr);
41
42
  if (!formatting || numId === void 0 || resolvesNumbering(numId, numbering)) return;
43
+ danglingNumIds.add(numId);
42
44
  formatting.numPr = NO_PARAGRAPH_NUMBERING$1;
43
45
  delete formatting.numPrFromStyle;
44
46
  delete paragraph.listRendering;
45
47
  unnumberedDanglingReferences += 1;
46
48
  });
47
- return { unnumberedDanglingReferences };
49
+ return {
50
+ unnumberedDanglingReferences,
51
+ danglingNumIds
52
+ };
48
53
  };
49
54
  const normalizeStyleNumberingReferences = ({ styles, numbering }) => {
50
55
  const unnumberedStyleIds = [];
56
+ const danglingNumIds = /* @__PURE__ */ new Set();
51
57
  for (const style of styles) {
52
58
  const pPr = style.pPr;
53
59
  const numId = paragraphNumberingReferenceId(pPr?.numPr);
54
60
  if (!pPr || numId === void 0 || resolvesNumbering(numId, numbering)) continue;
61
+ danglingNumIds.add(numId);
55
62
  pPr.numPr = NO_PARAGRAPH_NUMBERING$1;
56
63
  unnumberedStyleIds.push(style.styleId);
57
64
  }
58
- return { unnumberedStyleIds };
65
+ return {
66
+ unnumberedStyleIds,
67
+ danglingNumIds
68
+ };
59
69
  };
60
70
  export { UNNUMBERED_PARAGRAPH_WARNING, UNNUMBERED_STYLE_WARNING, normalizeNumberingReferences, normalizeStyleNumberingReferences };
@@ -21,12 +21,13 @@ import { assignParagraphPropertySource } from "./paragraphPropertySource.js";
21
21
  import { preserveInlineChild, preserveRunChild, preservedInlineCapture } from "./preservedRunContent.js";
22
22
  import { standalonePreviewLedger } from "./previewBudget.js";
23
23
  import { FOLIO_REVIEW_HISTORY_NAMESPACE } from "./reviewHistoryNamespace.js";
24
- import { ReviewResolutionProvenanceError, parseParagraphMarkResolutionJoin, parseResolutionJoins } from "./reviewResolutionProvenance.js";
24
+ import { parseParagraphMarkResolutionJoin, parseResolutionJoins, parseSplitResolutionPiece } from "./reviewResolutionProvenance.js";
25
25
  import { consolidateParagraphContent } from "./runConsolidator.js";
26
26
  import { parseRun } from "./runParser.js";
27
27
  import { runHoldsPayload } from "./runPayload.js";
28
28
  import { captureSdtSiblingMarkers, parseSdtProperties } from "./sdtProperties.js";
29
29
  import { parseSectionProperties } from "./sectionParser.js";
30
+ import { splitPieces, tagSplitPiece } from "./splitRevisionPieces.js";
30
31
  import { hasAttributeAnySpelling } from "./strictNames.js";
31
32
  import { scanRunForTextBoxDrawings } from "./textBoxParser.js";
32
33
  import { parsePropertyChangeInfo, parseTrackedChangeInfo } from "./trackedChangeInfo.js";
@@ -232,7 +233,13 @@ function parseParagraphMarkChange(pPr) {
232
233
  };
233
234
  }
234
235
  }
235
- function pushTrackedChangeWrapper({ contents, type, info, resolutionJoins, content, preserveEmpty = false }) {
236
+ function pushTrackedChangeWrapper(params) {
237
+ const before = params.contents.length;
238
+ pushTrackedChangeWrapperRecord(params);
239
+ const pushed = params.contents.at(-1);
240
+ if (params.split !== void 0 && params.contents.length > before && pushed !== void 0) splitPieces.set(pushed, params.split);
241
+ }
242
+ function pushTrackedChangeWrapperRecord({ contents, type, info, resolutionJoins, content, preserveEmpty = false }) {
236
243
  if (content.length === 0 && !preserveEmpty) return;
237
244
  const provenance = resolutionJoins === void 0 ? {} : { resolutionJoins };
238
245
  if (type === "insertion") {
@@ -269,46 +276,20 @@ function pushTrackedChangeWrapper({ contents, type, info, resolutionJoins, conte
269
276
  ...provenance
270
277
  });
271
278
  }
272
- function pushTrackedChangeSegments({ contents, type, info, resolutionJoins, parsedContent }) {
273
- if (resolutionJoins !== void 0 && parsedContent.some((item) => !isTrackedChangeWrapperChild(item))) throw new ReviewResolutionProvenanceError({
274
- attribute: "resolutionJoins",
275
- reason: "invalid",
276
- message: "Tracked-resolution provenance cannot bind a fragmented imported wrapper."
277
- });
278
- if (!parsedContent.some(isTrackedChangeWrapperChild)) {
279
- pushTrackedChangeWrapper({
280
- contents,
281
- type,
282
- info,
283
- resolutionJoins,
284
- content: [],
285
- preserveEmpty: true
286
- });
287
- contents.push(...parsedContent);
288
- return;
289
- }
290
- const segment = [];
291
- for (const content of parsedContent) {
292
- if (isTrackedChangeWrapperChild(content)) {
293
- segment.push(content);
294
- continue;
295
- }
296
- pushTrackedChangeWrapper({
297
- contents,
298
- type,
299
- info,
300
- resolutionJoins,
301
- content: segment
302
- });
303
- segment.length = 0;
304
- contents.push(content);
279
+ function pushTrackedChangeSegments({ contents, type, info, resolutionJoins, parsedContent, split }) {
280
+ const content = [];
281
+ for (const item of parsedContent) {
282
+ if (!isTrackedChangeWrapperChild(item)) panic(`A ${item.type} is not a tracked change child; the invariant that every paragraph content kind is one broke.`);
283
+ content.push(item);
305
284
  }
306
285
  pushTrackedChangeWrapper({
307
286
  contents,
308
287
  type,
309
288
  info,
310
289
  resolutionJoins,
311
- content: segment
290
+ content,
291
+ preserveEmpty: true,
292
+ ...split === void 0 ? {} : { split }
312
293
  });
313
294
  }
314
295
  function pushInlineSdtSegments({ contents, properties, parsedContent }) {
@@ -404,12 +385,16 @@ const linkedRevisionContent = (wrapped, linkOver) => {
404
385
  case "insertion":
405
386
  case "deletion":
406
387
  case "moveFrom":
407
- case "moveTo":
408
- content.push({
388
+ case "moveTo": {
389
+ const relinked = {
409
390
  ...item,
410
391
  content: linkedRevisionContent(item.content, linkOver)
411
- });
392
+ };
393
+ const split = splitPieces.get(item);
394
+ if (split !== void 0) splitPieces.set(relinked, split);
395
+ content.push(relinked);
412
396
  break;
397
+ }
413
398
  case "inlineSdt": return panic("An SDT under a hyperlink must retain its opaque source span");
414
399
  default: if (isTrackedChangeWrapperChild(item)) content.push(item);
415
400
  }
@@ -420,11 +405,15 @@ const linkedRevisionContent = (wrapped, linkOver) => {
420
405
  const hoistRevision = (wrapper) => (child, { styles, theme, rels, media, previews, inScopeXmlns, items, linkOver }) => {
421
406
  const wrapped = parseParagraphContents(child, styles, theme, null, rels, media, previews, TRACKED_CHANGE_PARSE_CONTEXT[wrapper], inScopeXmlns, "hyperlink");
422
407
  const content = linkedRevisionContent(wrapped, linkOver);
408
+ const split = parseSplitResolutionPiece(child);
409
+ const resolutionJoins = parseResolutionJoins(child);
423
410
  items.push({
424
411
  type: "hoistedRevision",
425
412
  wrapper,
426
413
  info: parseTrackedChangeInfo(child),
427
- content
414
+ content,
415
+ ...split === void 0 ? {} : { split },
416
+ ...resolutionJoins === void 0 ? {} : { resolutionJoins }
428
417
  });
429
418
  };
430
419
  const HYPERLINK_REVISION_HOISTING_HANDLERS = {
@@ -435,6 +424,30 @@ const HYPERLINK_REVISION_HOISTING_HANDLERS = {
435
424
  moveTo: hoistRevision("moveTo")
436
425
  };
437
426
  /**
427
+ * A link holding a complex field, read with the paragraph's field scan so a
428
+ * field whose `begin` and `end` are both inside the link is one child.
429
+ *
430
+ * A table of contents entry is one link over the heading text,
431
+ * a tab and the `PAGEREF` page number. The link reads its runs one at a time,
432
+ * which would leave the page number's field characters as loose runs. A field
433
+ * the link does not close stays as the loose runs it was read as, and so does
434
+ * the whole link when the scan returns anything a link cannot hold.
435
+ */
436
+ const linkWithFields = (node, children, rels, styles, theme, media, rootXmlns, previews) => {
437
+ if (!children.some((child) => getLocalName(child.name) === "r" && findWordprocessingChild(child, "fldChar") !== void 0)) return void 0;
438
+ const contents = parseParagraphContents(node, styles, theme, null, rels, media, previews, "default", rootXmlns, "hyperlink");
439
+ const linked = [];
440
+ for (const item of contents) if (isHyperlinkContent(item)) linked.push(item);
441
+ if (linked.length !== contents.length || !linked.some(({ type }) => type === "complexField")) {
442
+ previews.release(contents);
443
+ return;
444
+ }
445
+ return {
446
+ ...parseHyperlinkShell(node, rels),
447
+ children: linked
448
+ };
449
+ };
450
+ /**
438
451
  * A `w:hyperlink` as paragraph content, with any revision wrapper it holds
439
452
  * hoisted around it.
440
453
  *
@@ -444,7 +457,12 @@ const HYPERLINK_REVISION_HOISTING_HANDLERS = {
444
457
  * inverse of what the serializer writes, so a package survives the round trip.
445
458
  */
446
459
  function parseHyperlinkParagraphContents(node, rels, styles, theme, media, rootXmlns, previews) {
447
- if (!getChildElements(node).some((child) => HYPERLINK_REVISION_WRAPPERS.has(getLocalName(child.name)))) return [parseHyperlink(node, rels, styles, theme, media, rootXmlns, previews)];
460
+ const children = getChildElements(node);
461
+ if (!children.some((child) => HYPERLINK_REVISION_WRAPPERS.has(getLocalName(child.name)))) {
462
+ const linkedFields = linkWithFields(node, children, rels, styles, theme, media, rootXmlns, previews);
463
+ if (linkedFields !== void 0) return [linkedFields];
464
+ return [parseHyperlink(node, rels, styles, theme, media, rootXmlns, previews)];
465
+ }
448
466
  const inScopeXmlns = mergeXmlnsDeclarations(rootXmlns, node);
449
467
  const shell = parseHyperlinkShell(node, rels);
450
468
  const linkOver = (linkChildren) => ({
@@ -490,7 +508,9 @@ function parseHyperlinkParagraphContents(node, rels, styles, theme, media, rootX
490
508
  type: item.wrapper,
491
509
  info: item.info,
492
510
  content: item.content,
493
- preserveEmpty: true
511
+ preserveEmpty: true,
512
+ split: item.split,
513
+ resolutionJoins: item.resolutionJoins
494
514
  });
495
515
  }
496
516
  flushPlain();
@@ -901,7 +921,9 @@ const assembledFieldBeginsOf = (container) => {
901
921
  * adds.
902
922
  */
903
923
  const paragraphInlineWrapper = (element) => (child, { styles, theme, rels, media, previews, trackedContext, inScopeXmlns, inlineScope, contents }) => {
904
- contents.push(inlineWrapperOf(element, child, parseParagraphContents(child, styles, theme, null, rels, media, previews, trackedContext, mergeXmlnsDeclarations(inScopeXmlns, child), inlineScope)));
924
+ const wrapper = inlineWrapperOf(element, child, parseParagraphContents(child, styles, theme, null, rels, media, previews, trackedContext, mergeXmlnsDeclarations(inScopeXmlns, child), inlineScope));
925
+ tagSplitPiece(child, wrapper);
926
+ contents.push(wrapper);
905
927
  };
906
928
  const PARAGRAPH_CONTENT_UNDECLARED = { AlternateContent: (child, { contents, styles, theme, rels, media, previews, trackedContext, inScopeXmlns, inlineScope }) => {
907
929
  const selectedBranch = selectAlternateContentBranch(child);
@@ -914,13 +936,15 @@ const PARAGRAPH_CONTENT_UNDECLARED_NAMESPACES = { [OMML_NAMESPACE]: (child, { co
914
936
  /** All revision wrappers retain typed review ownership while parsing their children. */
915
937
  const trackedParagraphRevision = (type) => (child, { contents, styles, theme, rels, media, previews, inScopeXmlns, inlineScope }) => {
916
938
  const resolutionJoins = parseResolutionJoins(child);
939
+ const split = parseSplitResolutionPiece(child);
917
940
  const parsedContent = parseParagraphContents(child, styles, theme, null, rels, media, previews, TRACKED_CHANGE_PARSE_CONTEXT[type], inScopeXmlns, inlineScope);
918
941
  pushTrackedChangeSegments({
919
942
  contents,
920
943
  type,
921
944
  info: parseTrackedChangeInfo(child),
922
945
  resolutionJoins,
923
- parsedContent
946
+ parsedContent,
947
+ split
924
948
  });
925
949
  };
926
950
  const PARAGRAPH_CONTENT_HANDLERS = {
@@ -976,7 +1000,7 @@ const PARAGRAPH_CONTENT_HANDLERS = {
976
1000
  scan.complexFieldOpenRuns.push(withOrphanFieldCharsPreserved(run, runElement));
977
1001
  if (commentReferenceId !== null || trackedContext === "deletion") scan.complexFieldSourceRuns = null;
978
1002
  else scan.complexFieldSourceRuns?.push(runElement);
979
- if (instrText) scan.complexFieldInstr += instrText;
1003
+ if (instrText && !(isNestedField && scan.afterSeparator)) scan.complexFieldInstr += instrText;
980
1004
  if ((!scan.complexFieldFormatting || Object.keys(scan.complexFieldFormatting).length === 0) && run.formatting && Object.keys(run.formatting).length > 0) scan.complexFieldFormatting = run.formatting;
981
1005
  let inFieldCodeRegion = !hasFieldBegin && !scan.afterSeparator;
982
1006
  const fieldCodeContent = [];
@@ -996,8 +1020,12 @@ const PARAGRAPH_CONTENT_HANDLERS = {
996
1020
  content: fieldCodeContent
997
1021
  });
998
1022
  if (hasFieldSeparate && !isNestedField) scan.afterSeparator = true;
999
- if (scan.afterSeparator && !hasFieldEnd) {
1000
- if (!hasFieldSeparate) scan.complexFieldResultRuns.push(isHiddenByOpenFieldCode(scan) ? hiddenRunCaptureOf(runElement, run.formatting) : run);
1023
+ const ownStructure = !isNestedField && (hasFieldSeparate || hasFieldEnd);
1024
+ if (scan.afterSeparator && !ownStructure) {
1025
+ let resultRun = run;
1026
+ if (isHiddenByOpenFieldCode(scan)) resultRun = hiddenRunCaptureOf(runElement, run.formatting);
1027
+ else if (isNestedField) resultRun = withOrphanFieldCharsPreserved(run, runElement);
1028
+ scan.complexFieldResultRuns.push(resultRun);
1001
1029
  }
1002
1030
  if (hasFieldEnd && !isNestedField) {
1003
1031
  let resultRuns = scan.complexFieldResultRuns;
@@ -1211,8 +1239,90 @@ function parseParagraphContents(paraElement, styles, theme, _numbering, rels, me
1211
1239
  }
1212
1240
  });
1213
1241
  if (scan.inComplexField) contents.push(...scan.complexFieldOpenRuns);
1214
- return withPreservedChildren(contents, preserved, preservedInlineCapture);
1242
+ return joinSplitRevisionPieces(withPreservedChildren(contents, preserved, preservedInlineCapture));
1215
1243
  }
1244
+ /**
1245
+ * Put back together each change the serializer wrote as several elements
1246
+ * around a hyperlink: its pieces, read as neighbouring wrappers of one kind
1247
+ * and author, become the one change again, under the first piece's id and
1248
+ * with the joins it carried. Pieces that do not line up stay as they were
1249
+ * read, without the joins, which no one piece could own.
1250
+ */
1251
+ const joinSplitRevisionPieces = (source) => {
1252
+ const contents = source.map(sinkLiftedLink);
1253
+ if (!contents.some((item) => splitPieces.has(item))) return source;
1254
+ const out = [];
1255
+ for (let index = 0; index < contents.length; index += 1) {
1256
+ const first = contents[index];
1257
+ if (first === void 0) continue;
1258
+ const split = splitPieces.get(first);
1259
+ if (split?.piece !== 0 || !isSplittable(first)) {
1260
+ out.push(first);
1261
+ continue;
1262
+ }
1263
+ const pieces = contents.slice(index, index + split.pieces);
1264
+ if (!(pieces.length === split.pieces && pieces.every((piece, ordinal) => {
1265
+ const own = splitPieces.get(piece);
1266
+ return own?.piece === ordinal && own.pieces === split.pieces && isSplittable(piece) && samePieceOwner(first, piece);
1267
+ }))) {
1268
+ out.push(first);
1269
+ continue;
1270
+ }
1271
+ const joined = [];
1272
+ for (const piece of pieces) if (isSplittable(piece)) joined.push(...piece.content);
1273
+ if (first.type === "inlineWrapper") {
1274
+ out.push({
1275
+ ...first,
1276
+ content: joinSplitRevisionPieces(joined)
1277
+ });
1278
+ index += split.pieces - 1;
1279
+ continue;
1280
+ }
1281
+ const content = joinSplitRevisionPieces(joined).filter(isTrackedChangeWrapperChild);
1282
+ const { resolutionJoins: _pieceJoins, ...rest } = first;
1283
+ out.push({
1284
+ ...rest,
1285
+ content,
1286
+ ...split.joins === void 0 ? {} : { resolutionJoins: split.joins }
1287
+ });
1288
+ index += split.pieces - 1;
1289
+ }
1290
+ return out;
1291
+ };
1292
+ /**
1293
+ * A lifted link the parser read around the pieces it holds, put back below
1294
+ * them: the serializer writes the link outermost and every split piece inside
1295
+ * it, so the piece a wrapper or change was split into sits under the link
1296
+ * the change originally held.
1297
+ */
1298
+ const sinkLiftedLink = (item) => {
1299
+ if (item.type !== "hyperlink") return item;
1300
+ const [only, ...rest] = item.children;
1301
+ if (only === void 0 || rest.length > 0 || !splitPieces.has(only)) return item;
1302
+ if (!isSplittable(only)) return item;
1303
+ const sunk = {
1304
+ ...only,
1305
+ content: [sinkLiftedLink({
1306
+ ...item,
1307
+ children: [...only.content]
1308
+ })]
1309
+ };
1310
+ splitPieces.set(sunk, splitPieces.get(only));
1311
+ return sunk;
1312
+ };
1313
+ /** What the serializer splits around a lifted link: changes and transparent wrappers. */
1314
+ const isSplittable = (item) => isTrackedRunChange(item) || item.type === "inlineWrapper";
1315
+ /** Whether two pieces came from one element: the same record, its content aside. */
1316
+ const samePieceOwner = (first, piece) => {
1317
+ if (first.type !== piece.type) return false;
1318
+ if (first.type === "inlineWrapper" || piece.type === "inlineWrapper") {
1319
+ const { content: _first, ...firstOwner } = first;
1320
+ const { content: _piece, ...pieceOwner } = piece;
1321
+ return JSON.stringify(firstOwner) === JSON.stringify(pieceOwner);
1322
+ }
1323
+ return first.info.author === piece.info.author && first.info.date === piece.info.date;
1324
+ };
1325
+ const isTrackedRunChange = (item) => item.type === "insertion" || item.type === "deletion" || item.type === "moveFrom" || item.type === "moveTo";
1216
1326
  function getCommentReferenceId(runElement) {
1217
1327
  const commentReference = findChild(runElement, "w", "commentReference");
1218
1328
  if (!commentReference) return null;
@@ -1426,6 +1536,7 @@ const getHyperlinkText = (hyperlink) => hyperlink.children.map((child) => {
1426
1536
  case "moveToRangeEnd": return "";
1427
1537
  case "preservedInline": return child.text;
1428
1538
  case "inlineWrapper": return child.content.map(getParagraphContentText).join("");
1539
+ case "complexField": return getParagraphContentText(child);
1429
1540
  default: return panic(`Unsupported hyperlink child in plain-text extraction: ${JSON.stringify(child)}`);
1430
1541
  }
1431
1542
  }).join("");
@@ -34,6 +34,11 @@ type AssignParagraphIndentationProjectionOptions = {
34
34
  /** Keep the model's effective indentation without making inherited values authored. */
35
35
  export declare const assignParagraphIndentationProjection: ({ paragraph, authored, inherited }: AssignParagraphIndentationProjectionOptions) => void;
36
36
  export declare const PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR = "_docxParagraphSourceToken";
37
+ /**
38
+ * Where a paragraph-mark join takes the source attributes from: the next
39
+ * paragraph, whose mark stays. The joins then record the source transfer.
40
+ */
41
+ export declare const PARAGRAPH_SOURCE_JOIN_RULES: Readonly<Record<typeof PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, "next">>;
37
42
  export declare const PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR = "_docxParagraphSourceContract";
38
43
  /** Durable identity nested inside opaque collapsed-cell ProseMirror attrs; stripped on restore. */
39
44
  export declare const TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR = "_docxParagraphSourceBinding";
@@ -71,6 +76,30 @@ export declare const paragraphPropertySourceBelongsToDocument: (paragraph: docum
71
76
  export declare const getProseDocumentParagraphPropertySourceContract: (document: Node) => string | null;
72
77
  export declare const getProseParagraphPropertySourceToken: (paragraph: Node) => unknown;
73
78
  export declare const copyDocumentParagraphPropertySourceContract: (target: document_d_exports.Document, source: document_d_exports.Document) => void;
79
+ /**
80
+ * Every fact this module keeps for a paragraph outside its fields, by
81
+ * identity. A conversion of the paragraph may read any of them, so a
82
+ * converted paragraph is reused only while they are the ones it was
83
+ * converted with.
84
+ */
85
+ export declare const paragraphPropertySourceState: (paragraph: document_d_exports.Paragraph) => readonly unknown[];
86
+ /**
87
+ * Where the facts `paragraphPropertySourceState` reads for a paragraph stood:
88
+ * they are keyed by the paragraph, by its formatting object, and by handles
89
+ * that are written once, when they are made. Reading it allocates; matching
90
+ * it against the paragraph does not.
91
+ */
92
+ export type ParagraphPropertySourceStamp = Readonly<{
93
+ paragraph: number | undefined;
94
+ formatting: object | undefined;
95
+ formattingStamp: number | undefined;
96
+ }>;
97
+ export declare const paragraphPropertySourceStamp: (paragraph: document_d_exports.Paragraph) => ParagraphPropertySourceStamp;
98
+ /**
99
+ * Whether no fact kept for the paragraph changed since `stamp` was read: its
100
+ * `paragraphPropertySourceState` is then the one it was.
101
+ */
102
+ export declare const paragraphPropertySourceStampMatches: (paragraph: document_d_exports.Paragraph, stamp: ParagraphPropertySourceStamp) => boolean;
74
103
  export declare const getParagraphPropertySourceToken: (paragraph: document_d_exports.Paragraph) => string | undefined;
75
104
  type ParagraphSourceIdentity = {
76
105
  type: "durable";
@@ -6,6 +6,60 @@ import { visitDocxParagraphs } from "./paragraphTraversal.js";
6
6
  import { parseXmlDocument } from "./xmlParser.js";
7
7
  import { TaggedError, panic } from "better-result";
8
8
  // src/docx/paragraphPropertySource.ts
9
+ /**
10
+ * A stamp per object, renewed whenever a fact this module keeps for it
11
+ * changes. Every table read by `paragraphPropertySourceState` writes through
12
+ * `KeptFacts` or `KeptFlags`, and every handle a paragraph carries is set
13
+ * through `keepHandle`, so an unchanged stamp means unchanged facts.
14
+ */
15
+ const factStamps = /* @__PURE__ */ new WeakMap();
16
+ let lastFactStamp = 0;
17
+ const renewFacts = (key) => {
18
+ lastFactStamp += 1;
19
+ factStamps.set(key, lastFactStamp);
20
+ };
21
+ /** A weak table whose writes renew the stamp of the key they change. */
22
+ var KeptFacts = class {
23
+ table = /* @__PURE__ */ new WeakMap();
24
+ get(key) {
25
+ return this.table.get(key);
26
+ }
27
+ has(key) {
28
+ return this.table.has(key);
29
+ }
30
+ set(key, value) {
31
+ if (this.table.has(key) && this.table.get(key) === value) return;
32
+ this.table.set(key, value);
33
+ renewFacts(key);
34
+ }
35
+ };
36
+ /** A weak set whose writes renew the stamp of the key they change. */
37
+ var KeptFlags = class {
38
+ flags = /* @__PURE__ */ new WeakSet();
39
+ has(key) {
40
+ return this.flags.has(key);
41
+ }
42
+ add(key) {
43
+ if (this.flags.has(key)) return;
44
+ this.flags.add(key);
45
+ renewFacts(key);
46
+ }
47
+ delete(key) {
48
+ if (this.flags.delete(key)) renewFacts(key);
49
+ }
50
+ };
51
+ /** Set or remove (`undefined`) the handle a paragraph carries under `key`. */
52
+ const keepHandle = (paragraph, key, descriptor) => {
53
+ const current = Object.getOwnPropertyDescriptor(paragraph, key);
54
+ if (descriptor === void 0) {
55
+ if (current === void 0) return;
56
+ Reflect.deleteProperty(paragraph, key);
57
+ } else {
58
+ if (current !== void 0 && current.value === descriptor.value) return;
59
+ Object.defineProperty(paragraph, key, descriptor);
60
+ }
61
+ renewFacts(paragraph);
62
+ };
9
63
  const paragraphPropertySourceEmissionFingerprint = Symbol("paragraphPropertySourceEmissionFingerprint");
10
64
  const paragraphPropertySourceIndentationBaseline = Symbol("paragraphPropertySourceIndentationBaseline");
11
65
  const INDENTATION_FIELDS = [
@@ -16,8 +70,8 @@ const INDENTATION_FIELDS = [
16
70
  ];
17
71
  const paragraphPropertyCapture = Symbol("paragraphPropertyCapture");
18
72
  const paragraphIndentationProjection = Symbol("paragraphIndentationProjection");
19
- const indentationProjections = /* @__PURE__ */ new WeakMap();
20
- const assignedIndentationProjections = /* @__PURE__ */ new WeakSet();
73
+ const indentationProjections = new KeptFacts();
74
+ const assignedIndentationProjections = new KeptFlags();
21
75
  const indentationProjectionFor = (paragraph) => {
22
76
  const handle = Object.getOwnPropertyDescriptor(paragraph, paragraphIndentationProjection)?.value;
23
77
  return typeof handle === "object" && handle !== null ? indentationProjections.get(handle) : void 0;
@@ -33,12 +87,12 @@ const sameParagraphIndentationProjection = ({ left, right }) => {
33
87
  const copyParagraphIndentationProjection = ({ target, source }) => {
34
88
  if (assignedIndentationProjections.has(target) || Object.hasOwn(target, paragraphIndentationProjection)) return;
35
89
  const descriptor = Object.getOwnPropertyDescriptor(source, paragraphIndentationProjection);
36
- if (descriptor && indentationProjectionFor(source)) Object.defineProperty(target, paragraphIndentationProjection, descriptor);
90
+ if (descriptor && indentationProjectionFor(source)) keepHandle(target, paragraphIndentationProjection, descriptor);
37
91
  };
38
92
  /** History restores its captured authored/effective baseline before normalization. */
39
93
  const restoreParagraphIndentationProjection = ({ target, source }) => {
40
94
  assignedIndentationProjections.delete(target);
41
- Reflect.deleteProperty(target, paragraphIndentationProjection);
95
+ keepHandle(target, paragraphIndentationProjection, void 0);
42
96
  copyParagraphIndentationProjection({
43
97
  target,
44
98
  source
@@ -70,7 +124,7 @@ const assignParagraphIndentationProjection = ({ paragraph, authored, inherited }
70
124
  };
71
125
  if (Object.keys(paragraph.formatting).length === 0) delete paragraph.formatting;
72
126
  if (Object.values(effective).every((value) => value === void 0) || getParagraphPropertySource(paragraph) === void 0 && INDENTATION_FIELDS.every((key) => effective[key] === authored?.[key])) {
73
- Reflect.deleteProperty(paragraph, paragraphIndentationProjection);
127
+ keepHandle(paragraph, paragraphIndentationProjection, void 0);
74
128
  return;
75
129
  }
76
130
  const handle = Object.freeze({});
@@ -78,14 +132,14 @@ const assignParagraphIndentationProjection = ({ paragraph, authored, inherited }
78
132
  effective: Object.freeze(indentationFields(paragraph.formatting)),
79
133
  authored: Object.freeze(indentationFields(authored))
80
134
  }));
81
- Object.defineProperty(paragraph, paragraphIndentationProjection, {
135
+ keepHandle(paragraph, paragraphIndentationProjection, {
82
136
  value: handle,
83
137
  enumerable: true,
84
138
  configurable: true
85
139
  });
86
140
  };
87
- const paragraphPropertyCaptures = /* @__PURE__ */ new WeakMap();
88
- const paragraphSourceRecordKinds = /* @__PURE__ */ new WeakMap();
141
+ const paragraphPropertyCaptures = new KeptFacts();
142
+ const paragraphSourceRecordKinds = new KeptFacts();
89
143
  const captureForParagraph = (paragraph) => {
90
144
  const handle = Object.getOwnPropertyDescriptor(paragraph, paragraphPropertyCapture)?.value;
91
145
  if (!Object.hasOwn(paragraph, paragraphPropertyCapture)) return paragraphPropertyCaptures.get(paragraph);
@@ -94,7 +148,7 @@ const captureForParagraph = (paragraph) => {
94
148
  const attachParagraphCapture = (paragraph, capture) => {
95
149
  const handle = Object.freeze({});
96
150
  paragraphPropertyCaptures.set(handle, capture);
97
- Object.defineProperty(paragraph, paragraphPropertyCapture, {
151
+ keepHandle(paragraph, paragraphPropertyCapture, {
98
152
  value: handle,
99
153
  enumerable: true,
100
154
  configurable: true
@@ -114,12 +168,17 @@ const ownedParagraphPropertySource = (paragraph, xml) => {
114
168
  });
115
169
  };
116
170
  const proseParagraphSourceOwners = /* @__PURE__ */ new WeakMap();
117
- const paragraphPropertySourceCandidates = /* @__PURE__ */ new WeakMap();
118
- const paragraphPropertySourceTransferIds = /* @__PURE__ */ new WeakMap();
119
- const paragraphPropertySourceTokens = /* @__PURE__ */ new WeakMap();
171
+ const paragraphPropertySourceCandidates = new KeptFacts();
172
+ const paragraphPropertySourceTransferIds = new KeptFacts();
173
+ const paragraphPropertySourceTokens = new KeptFacts();
120
174
  const documentParagraphPropertySourceBindingBrand = Symbol("documentParagraphPropertySourceBinding");
121
175
  const documentParagraphPropertySourceBinding = Symbol("paragraphPropertySourceBinding");
122
176
  const PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR = "_docxParagraphSourceToken";
177
+ /**
178
+ * Where a paragraph-mark join takes the source attributes from: the next
179
+ * paragraph, whose mark stays. The joins then record the source transfer.
180
+ */
181
+ const PARAGRAPH_SOURCE_JOIN_RULES = { [PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR]: "next" };
123
182
  const PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR = "_docxParagraphSourceContract";
124
183
  /** Durable identity nested inside opaque collapsed-cell ProseMirror attrs; stripped on restore. */
125
184
  const TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR = "_docxParagraphSourceBinding";
@@ -307,6 +366,33 @@ const copyDocumentParagraphPropertySourceContract = (target, source) => {
307
366
  const binding = getDocumentParagraphPropertySourceBinding(source);
308
367
  if (binding) setDocumentParagraphPropertySourceBinding(target, binding);
309
368
  };
369
+ /**
370
+ * Every fact this module keeps for a paragraph outside its fields, by
371
+ * identity. A conversion of the paragraph may read any of them, so a
372
+ * converted paragraph is reused only while they are the ones it was
373
+ * converted with.
374
+ */
375
+ const paragraphPropertySourceState = (paragraph) => [
376
+ paragraphPropertySourceTokens.get(paragraph),
377
+ paragraphPropertySourceCandidates.get(paragraph),
378
+ paragraphPropertySourceTransferIds.get(paragraph),
379
+ paragraphSourceRecordKinds.get(paragraph),
380
+ captureForParagraph(paragraph),
381
+ indentationProjectionFor(paragraph),
382
+ assignedIndentationProjections.has(paragraph),
383
+ decodedTableCellParagraphSourcePayloads.get(paragraph),
384
+ ...paragraph.formatting === void 0 ? [] : [paragraphPropertyCaptures.get(paragraph.formatting), indentationProjections.get(paragraph.formatting)]
385
+ ];
386
+ const paragraphPropertySourceStamp = (paragraph) => ({
387
+ paragraph: factStamps.get(paragraph),
388
+ formatting: paragraph.formatting,
389
+ formattingStamp: paragraph.formatting === void 0 ? void 0 : factStamps.get(paragraph.formatting)
390
+ });
391
+ /**
392
+ * Whether no fact kept for the paragraph changed since `stamp` was read: its
393
+ * `paragraphPropertySourceState` is then the one it was.
394
+ */
395
+ const paragraphPropertySourceStampMatches = (paragraph, stamp) => factStamps.get(paragraph) === stamp.paragraph && paragraph.formatting === stamp.formatting && (paragraph.formatting === void 0 || factStamps.get(paragraph.formatting) === stamp.formattingStamp);
310
396
  const getParagraphPropertySourceToken = (paragraph) => paragraphPropertySourceTokens.get(paragraph);
311
397
  /** Byte captures can follow derivations; only explicit copies carry durable tokens. */
312
398
  const inspectParagraphSourceIdentity = (paragraph, document) => {
@@ -343,8 +429,8 @@ const cloneParagraphWithoutPropertySource = (paragraph, overrides) => {
343
429
  ...paragraph,
344
430
  ...overrides
345
431
  };
346
- Reflect.deleteProperty(cloned, paragraphPropertyCapture);
347
- Reflect.deleteProperty(cloned, paragraphIndentationProjection);
432
+ keepHandle(cloned, paragraphPropertyCapture, void 0);
433
+ keepHandle(cloned, paragraphIndentationProjection, void 0);
348
434
  return cloned;
349
435
  };
350
436
  const paragraphsIn = (document) => {
@@ -441,6 +527,8 @@ const tableCellBlockTraversalByType = {
441
527
  blockCustomXml: "blockSdt",
442
528
  bookmarkEnd: "leaf",
443
529
  bookmarkStart: "leaf",
530
+ commentRangeEnd: "leaf",
531
+ commentRangeStart: "leaf",
444
532
  moveFromRangeEnd: "leaf",
445
533
  moveFromRangeStart: "leaf",
446
534
  moveToRangeEnd: "leaf",
@@ -658,6 +746,8 @@ const TABLE_CELL_LEAF_BLOCK_FIELDS = {
658
746
  name: "string"
659
747
  },
660
748
  bookmarkEnd: { id: "number" },
749
+ commentRangeStart: { id: "number" },
750
+ commentRangeEnd: { id: "number" },
661
751
  moveFromRangeStart: {
662
752
  id: "number",
663
753
  name: "string",
@@ -679,7 +769,7 @@ function visitDecodedTableCellLeafBlock(block, blockType, path) {
679
769
  }
680
770
  const decodedTableCellParagraphSourcePayloadBrand = Symbol("decodedTableCellParagraphSourcePayload");
681
771
  const decodedTableCellParagraphSourcePayloadStates = /* @__PURE__ */ new WeakMap();
682
- const decodedTableCellParagraphSourcePayloads = /* @__PURE__ */ new WeakMap();
772
+ const decodedTableCellParagraphSourcePayloads = new KeptFacts();
683
773
  const decodedTableCellParagraphSourcePayloadState = (payload) => {
684
774
  const state = decodedTableCellParagraphSourcePayloadStates.get(payload);
685
775
  if (!state) panic("A collapsed-cell paragraph source payload bypassed its decoder.");
@@ -931,4 +1021,4 @@ const linkParagraphPropertySourceCandidate = (target, source) => {
931
1021
  };
932
1022
  const getParagraphPropertySourceCandidate = (paragraph) => paragraphPropertySourceCandidates.get(paragraph);
933
1023
  const getParagraphPropertySourceTransferId = (paragraph) => paragraphPropertySourceTransferIds.get(paragraph);
934
- export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
1024
+ export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PARAGRAPH_SOURCE_JOIN_RULES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceStamp, paragraphPropertySourceStampMatches, paragraphPropertySourceState, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
@@ -4,7 +4,8 @@ import { groupPreviewTextBoxes } from "./groupDrawingParser.js";
4
4
  import { parseParagraph } from "./paragraphParser.js";
5
5
  import { consolidateParagraphContent } from "./runConsolidator.js";
6
6
  import { captureShapeAlternateContent } from "./shapeAlternateContent.js";
7
- import { getTextBoxContentElement, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, scanRunForTextBoxDrawings } from "./textBoxParser.js";
7
+ import { parseTextBoxContent } from "./textBoxContentParser.js";
8
+ import { getTextBoxContentElement, parseTextBox, parseTextBoxFromShape, scanRunForTextBoxDrawings } from "./textBoxParser.js";
8
9
  import { isVmlPictParsedByRunParser } from "./vmlImageParser.js";
9
10
  import { WORDPROCESSINGML_NAMESPACE_URIS, findChildByLocalName, findChildByNamespaceUri, findDeep, findWordprocessingChild, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
10
11
  // src/docx/paragraphTextBoxEnrichment.ts
@@ -104,6 +104,8 @@ const visitBlockChildren = ({ block, visitRecord, visitBlocks }) => {
104
104
  case "preservedBlock":
105
105
  case "bookmarkStart":
106
106
  case "bookmarkEnd":
107
+ case "commentRangeStart":
108
+ case "commentRangeEnd":
107
109
  case "moveFromRangeStart":
108
110
  case "moveFromRangeEnd":
109
111
  case "moveToRangeStart":