@stll/folio-core 0.69.0 → 0.70.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 (1081) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +4 -4
  2. package/dist/ai-edits/apply.d.ts +39 -16
  3. package/dist/ai-edits/apply.js +1014 -723
  4. package/dist/ai-edits/block-identity.d.ts +6 -0
  5. package/dist/ai-edits/block-identity.js +11 -1
  6. package/dist/ai-edits/blockRange.d.ts +9 -0
  7. package/dist/ai-edits/clean-text.d.ts +2 -0
  8. package/dist/ai-edits/clean-text.js +2 -1
  9. package/dist/ai-edits/comment-lifecycle.d.ts +24 -0
  10. package/dist/ai-edits/comment-lifecycle.js +17 -8
  11. package/dist/ai-edits/directJoin.d.ts +30 -0
  12. package/dist/ai-edits/directJoin.js +30 -0
  13. package/dist/ai-edits/existingRevisions.d.ts +9 -0
  14. package/dist/ai-edits/existingRevisions.js +30 -0
  15. package/dist/ai-edits/finalSectionReview.d.ts +11 -0
  16. package/dist/ai-edits/finalSectionReview.js +26 -0
  17. package/dist/ai-edits/headless.d.ts +275 -14
  18. package/dist/ai-edits/headless.js +1595 -193
  19. package/dist/ai-edits/index.d.ts +11 -10
  20. package/dist/ai-edits/index.js +2 -2
  21. package/dist/ai-edits/markdownInsertion.d.ts +25 -0
  22. package/dist/ai-edits/markdownInsertion.js +67 -0
  23. package/dist/ai-edits/minimal-replacement.d.ts +120 -1
  24. package/dist/ai-edits/minimal-replacement.js +81 -1
  25. package/dist/ai-edits/newListNumbering.d.ts +20 -9
  26. package/dist/ai-edits/newListNumbering.js +25 -10
  27. package/dist/ai-edits/note-references.d.ts +19 -1
  28. package/dist/ai-edits/note-references.js +3 -1
  29. package/dist/ai-edits/pending-suggestions.d.ts +44 -2
  30. package/dist/ai-edits/pending-suggestions.js +481 -20
  31. package/dist/ai-edits/pendingJoin.d.ts +170 -0
  32. package/dist/ai-edits/pendingJoin.js +272 -0
  33. package/dist/ai-edits/read.d.ts +57 -4
  34. package/dist/ai-edits/read.js +317 -40
  35. package/dist/ai-edits/removed-blocks.d.ts +1 -1
  36. package/dist/ai-edits/result-validation.d.ts +36 -1
  37. package/dist/ai-edits/result-validation.js +1 -1
  38. package/dist/ai-edits/retired-comment-receipts.d.ts +20 -0
  39. package/dist/ai-edits/retired-comment-receipts.js +165 -0
  40. package/dist/ai-edits/revisionStretches.d.ts +17 -0
  41. package/dist/ai-edits/snapshot.d.ts +12 -3
  42. package/dist/ai-edits/snapshot.js +9 -7
  43. package/dist/ai-edits/snapshotBatchFacts.d.ts +52 -0
  44. package/dist/ai-edits/snapshotBatchFacts.js +184 -0
  45. package/dist/ai-edits/table-geometry.d.ts +45 -11
  46. package/dist/ai-edits/table-geometry.js +141 -26
  47. package/dist/ai-edits/table-mutation-plan.d.ts +12 -0
  48. package/dist/ai-edits/table-mutation-plan.js +1 -1
  49. package/dist/ai-edits/table-row-column-mutations.d.ts +26 -3
  50. package/dist/ai-edits/table-row-column-mutations.js +90 -11
  51. package/dist/ai-edits/table-template.d.ts +21 -0
  52. package/dist/ai-edits/tableInsertionModes.d.ts +10 -0
  53. package/dist/ai-edits/tableInsertionModes.js +8 -0
  54. package/dist/ai-edits/tracked-batch-fidelity.d.ts +23 -0
  55. package/dist/ai-edits/tracked-batch-fidelity.js +357 -0
  56. package/dist/ai-edits/types.d.ts +81 -15
  57. package/dist/ai-edits/undefinedReferences.d.ts +49 -0
  58. package/dist/ai-edits/undefinedReferences.js +234 -0
  59. package/dist/ai-suggestions/apply.d.ts +12 -0
  60. package/dist/ai-suggestions/conflict.d.ts +9 -0
  61. package/dist/ai-suggestions/text-positions.d.ts +13 -0
  62. package/dist/canonical/batchCommentReferences.d.ts +20 -0
  63. package/dist/canonical/batchCommentReferences.js +93 -0
  64. package/dist/canonical/canonicalBatchReview.d.ts +25 -0
  65. package/dist/canonical/canonicalBatchReview.js +132 -0
  66. package/dist/{controller → canonical}/canonicalComments.d.ts +7 -4
  67. package/dist/{controller → canonical}/canonicalComments.js +36 -9
  68. package/dist/canonical/canonicalCompilerRefusal.d.ts +13 -0
  69. package/dist/canonical/canonicalCompilerRefusal.js +75 -0
  70. package/dist/canonical/canonicalIdLease.d.ts +40 -0
  71. package/dist/canonical/canonicalIdLease.js +96 -0
  72. package/dist/{controller → canonical}/canonicalInlineProjection.d.ts +1 -1
  73. package/dist/{controller → canonical}/canonicalInlineProjection.js +40 -20
  74. package/dist/canonical/canonicalInsertedCommentRange.d.ts +15 -0
  75. package/dist/canonical/canonicalInsertedCommentRange.js +43 -0
  76. package/dist/canonical/canonicalInsertionReplayIds.d.ts +40 -0
  77. package/dist/canonical/canonicalInsertionReplayIds.js +73 -0
  78. package/dist/canonical/canonicalJoinedReceipts.d.ts +11 -0
  79. package/dist/canonical/canonicalJoinedReceipts.js +22 -0
  80. package/dist/{controller → canonical}/canonicalListRendering.js +1 -1
  81. package/dist/{controller → canonical}/canonicalLockGuard.d.ts +12 -1
  82. package/dist/{controller → canonical}/canonicalLockGuard.js +96 -21
  83. package/dist/{controller → canonical}/canonicalOperations.js +1 -1
  84. package/dist/{controller → canonical}/canonicalProjectionBlocks.d.ts +11 -1
  85. package/dist/{controller → canonical}/canonicalProjectionBlocks.js +8 -4
  86. package/dist/{controller → canonical}/canonicalPublicOperations.d.ts +24 -9
  87. package/dist/canonical/canonicalPublicOperations.js +4791 -0
  88. package/dist/canonical/canonicalRemoteHistory.d.ts +48 -0
  89. package/dist/canonical/canonicalRemoteHistory.js +176 -0
  90. package/dist/canonical/canonicalRevisionLocks.d.ts +18 -0
  91. package/dist/canonical/canonicalRevisionLocks.js +30 -0
  92. package/dist/canonical/canonicalRevisionReceipts.d.ts +15 -0
  93. package/dist/canonical/canonicalRevisionReceipts.js +25 -0
  94. package/dist/canonical/canonicalRoomBase.d.ts +23 -0
  95. package/dist/canonical/canonicalRoomBase.js +38 -0
  96. package/dist/canonical/canonicalSeedContent.d.ts +36 -0
  97. package/dist/{controller → canonical}/canonicalSeedContent.js +53 -5
  98. package/dist/{controller → canonical}/canonicalSelection.js +1 -1
  99. package/dist/{controller → canonical}/canonicalSession.d.ts +239 -12
  100. package/dist/{controller → canonical}/canonicalSession.js +1069 -173
  101. package/dist/canonical/canonicalSourceNormalization.d.ts +42 -0
  102. package/dist/{controller → canonical}/canonicalSourceNormalization.js +41 -23
  103. package/dist/{controller → canonical}/canonicalTocSelection.js +1 -1
  104. package/dist/canonical/canonicalTrackedBatchFidelity.d.ts +9 -0
  105. package/dist/canonical/canonicalTrackedBatchFidelity.js +125 -0
  106. package/dist/canonical/canonicalWholeTextFidelity.d.ts +21 -0
  107. package/dist/canonical/canonicalWholeTextFidelity.js +88 -0
  108. package/dist/canonical/commentAnchorParagraph.d.ts +10 -0
  109. package/dist/canonical/commentAnchorParagraph.js +11 -0
  110. package/dist/canonical/controlEdges.d.ts +12 -0
  111. package/dist/canonical/controlEdges.js +17 -0
  112. package/dist/canonical/paragraphPatchAsRead.d.ts +19 -0
  113. package/dist/canonical/paragraphPatchAsRead.js +32 -0
  114. package/dist/canonical/propertySourcePreservation.d.ts +38 -0
  115. package/dist/canonical/propertySourcePreservation.js +129 -0
  116. package/dist/canonical/replacementRunSources.d.ts +29 -0
  117. package/dist/canonical/replacementRunSources.js +78 -0
  118. package/dist/compare/compare.d.ts +8 -6
  119. package/dist/compare/compare.js +37 -8
  120. package/dist/compare/content-alignment.d.ts +10 -1
  121. package/dist/compare/content-alignment.js +188 -27
  122. package/dist/compare/content.d.ts +9 -1
  123. package/dist/compare/content.js +2 -2
  124. package/dist/compare/formatting.d.ts +1 -0
  125. package/dist/compare/import-style-closure.d.ts +1 -1
  126. package/dist/compare/inline-atom-alignment.d.ts +83 -0
  127. package/dist/compare/inline-atom-alignment.js +173 -0
  128. package/dist/compare/inline-atoms-model.d.ts +65 -0
  129. package/dist/compare/inline-atoms-model.js +1131 -0
  130. package/dist/compare/inline-atoms.d.ts +4 -4
  131. package/dist/compare/inline-atoms.js +28 -139
  132. package/dist/compare/inline-provenance-model.d.ts +37 -0
  133. package/dist/compare/inline-provenance-model.js +138 -0
  134. package/dist/compare/inline-provenance.d.ts +52 -4
  135. package/dist/compare/inline-provenance.js +40 -7
  136. package/dist/compare/plan.d.ts +38 -4
  137. package/dist/compare/plan.js +22 -8
  138. package/dist/compare/scenario.d.ts +22 -1
  139. package/dist/compare/section-boundary-properties.d.ts +38 -5
  140. package/dist/compare/section-boundary-properties.js +164 -48
  141. package/dist/compare/style-resources.d.ts +3 -2
  142. package/dist/compare/style-resources.js +5 -4
  143. package/dist/compare/types.d.ts +5 -2
  144. package/dist/compare/verification.d.ts +24 -3
  145. package/dist/compare/verification.js +25 -18
  146. package/dist/compat/eigenpal.d.ts +32 -31
  147. package/dist/compat/eigenpal.js +3 -5
  148. package/dist/content-controls/findContentControls.d.ts +9 -0
  149. package/dist/content-controls/index.d.ts +8 -0
  150. package/dist/content-controls/mutateContentControls.d.ts +9 -0
  151. package/dist/controller/activeEditorStory.d.ts +1 -0
  152. package/dist/controller/anonymizationHighlights.d.ts +56 -0
  153. package/dist/controller/anonymizationHighlights.js +148 -0
  154. package/dist/controller/autocompleteSuggestion.d.ts +85 -0
  155. package/dist/controller/autocompleteSuggestion.js +213 -0
  156. package/dist/controller/canonicalClipboard.d.ts +2 -2
  157. package/dist/controller/canonicalClipboard.js +34 -14
  158. package/dist/controller/canonicalClipboardResources.js +9 -4
  159. package/dist/controller/canonicalCollaboration.d.ts +147 -0
  160. package/dist/controller/canonicalCollaboration.js +360 -0
  161. package/dist/controller/canonicalComposition.d.ts +7 -1
  162. package/dist/controller/canonicalComposition.js +14 -8
  163. package/dist/controller/canonicalContentControlValue.d.ts +17 -0
  164. package/dist/controller/canonicalContentControlValue.js +72 -0
  165. package/dist/controller/canonicalIndexedDbJournal.d.ts +6 -0
  166. package/dist/controller/canonicalIndexedDbJournal.js +80 -0
  167. package/dist/controller/canonicalInput.d.ts +13 -2
  168. package/dist/controller/canonicalInput.js +96 -11
  169. package/dist/controller/canonicalPresence.d.ts +63 -0
  170. package/dist/controller/canonicalPresence.js +125 -0
  171. package/dist/controller/canonicalReview.d.ts +1 -1
  172. package/dist/controller/canonicalReview.js +1 -1
  173. package/dist/controller/canonicalRoomAuthority.d.ts +66 -0
  174. package/dist/controller/canonicalRoomAuthority.js +119 -0
  175. package/dist/controller/canonicalRoomEditor.d.ts +87 -0
  176. package/dist/controller/canonicalRoomEditor.js +98 -0
  177. package/dist/controller/canonicalRoomTransport.d.ts +79 -0
  178. package/dist/controller/canonicalRoomTransport.js +104 -0
  179. package/dist/controller/canonicalRoomWire.d.ts +80 -0
  180. package/dist/controller/canonicalRoomWire.js +155 -0
  181. package/dist/controller/canonicalStoryEditor.d.ts +12 -0
  182. package/dist/controller/canonicalStoryEditor.js +39 -7
  183. package/dist/controller/canonicalStructure.d.ts +15 -5
  184. package/dist/controller/canonicalStructure.js +95 -34
  185. package/dist/controller/canonicalTabRoom.d.ts +91 -0
  186. package/dist/controller/canonicalTabRoom.js +553 -0
  187. package/dist/controller/canonicalYjsRoom.d.ts +102 -0
  188. package/dist/controller/canonicalYjsRoom.js +454 -0
  189. package/dist/controller/contentControlWidgetController.d.ts +16 -0
  190. package/dist/controller/contentControlWidgetController.js +7 -1
  191. package/dist/controller/documentChangeNotification.d.ts +5 -0
  192. package/dist/controller/documentChangeNotification.js +7 -0
  193. package/dist/controller/folioEditor.d.ts +12 -4
  194. package/dist/controller/folioEditor.js +18 -1
  195. package/dist/controller/folioEditorEvents.d.ts +1 -1
  196. package/dist/controller/fontReadiness.d.ts +14 -1
  197. package/dist/controller/fontReadiness.js +4 -4
  198. package/dist/controller/headerFooterEditorManager.d.ts +13 -7
  199. package/dist/controller/headerFooterEditorManager.js +24 -25
  200. package/dist/controller/hiddenEditorApi.d.ts +87 -13
  201. package/dist/controller/hiddenEditorApi.js +41 -3
  202. package/dist/controller/hiddenEditorManager.d.ts +62 -17
  203. package/dist/controller/hiddenEditorManager.js +378 -78
  204. package/dist/controller/hyphenationReadiness.d.ts +10 -0
  205. package/dist/controller/layoutPipeline.d.ts +14 -12
  206. package/dist/controller/layoutPipeline.js +64 -53
  207. package/dist/controller/layoutSession.d.ts +7 -6
  208. package/dist/controller/legacyTextAddress.d.ts +9 -0
  209. package/dist/controller/legacyTextAddress.js +52 -0
  210. package/dist/controller/noteEditorManager.d.ts +14 -7
  211. package/dist/controller/noteEditorManager.js +33 -32
  212. package/dist/controller/textPositionLookup.d.ts +24 -0
  213. package/dist/controller/textPositionLookup.js +78 -0
  214. package/dist/display-list/build/buildContext.d.ts +11 -0
  215. package/dist/display-list/build/buildDisplayList.d.ts +14 -1
  216. package/dist/display-list/build/colors.d.ts +8 -0
  217. package/dist/display-list/build/floatingImages.d.ts +10 -0
  218. package/dist/display-list/build/fontTable.d.ts +8 -0
  219. package/dist/display-list/build/furniture.d.ts +14 -2
  220. package/dist/display-list/build/glyphs.d.ts +7 -0
  221. package/dist/display-list/build/headerFooterPrimitives.d.ts +13 -0
  222. package/dist/display-list/build/imagePrimitives.d.ts +10 -0
  223. package/dist/display-list/build/pageBorderPrimitives.d.ts +16 -2
  224. package/dist/display-list/build/pageFurniture.d.ts +13 -0
  225. package/dist/display-list/build/paragraphPrimitives.d.ts +18 -0
  226. package/dist/display-list/build/paragraphPrimitives.js +17 -5
  227. package/dist/display-list/build/previewPrimitives.d.ts +14 -0
  228. package/dist/display-list/build/regions.d.ts +14 -0
  229. package/dist/display-list/build/storyPrimitives.d.ts +16 -0
  230. package/dist/display-list/build/strokes.d.ts +21 -3
  231. package/dist/display-list/build/strokes.js +2 -3
  232. package/dist/display-list/build/tablePrimitives.d.ts +15 -1
  233. package/dist/display-list/build/tablePrimitives.js +92 -55
  234. package/dist/display-list/build/textBoxPrimitives.d.ts +6 -0
  235. package/dist/display-list/build/unsupported.d.ts +10 -0
  236. package/dist/display-list/build/watermarkPrimitives.d.ts +15 -1
  237. package/dist/display-list/dom/renderDisplayListToDom.d.ts +33 -0
  238. package/dist/display-list/dom/renderDisplayListToDom.js +12 -4
  239. package/dist/display-list/editor/displayListPagePainter.d.ts +29 -1
  240. package/dist/display-list/editor/pageRenderer.d.ts +7 -0
  241. package/dist/display-list/html/renderDisplayListToHtml.d.ts +10 -0
  242. package/dist/display-list/primitives.d.ts +12 -1
  243. package/dist/display-list/selectDisplayPages.d.ts +8 -0
  244. package/dist/display-list/types.d.ts +11 -0
  245. package/dist/document-operations.d.ts +35 -5
  246. package/dist/document-operations.js +178 -40
  247. package/dist/docx/attributeRemainder.d.ts +35 -1
  248. package/dist/docx/automaticNoteMarkImport.d.ts +12 -0
  249. package/dist/docx/automaticNoteMarkImport.js +41 -0
  250. package/dist/docx/blockContentParser.d.ts +14 -5
  251. package/dist/docx/blockContentParser.js +19 -0
  252. package/dist/docx/blockPlainText.d.ts +14 -0
  253. package/dist/docx/blockPlainText.js +55 -4
  254. package/dist/docx/bookmarkParser.d.ts +17 -0
  255. package/dist/docx/bookmarkRangeJoin.d.ts +14 -0
  256. package/dist/docx/borderParser.d.ts +11 -0
  257. package/dist/docx/builtInStyles.d.ts +44 -1
  258. package/dist/docx/canonicalSave.d.ts +14 -4
  259. package/dist/docx/canonicalSave.js +128 -30
  260. package/dist/docx/canonicalSessionInput.d.ts +59 -4
  261. package/dist/docx/canonicalSessionInput.js +147 -6
  262. package/dist/docx/canonicalStoryRepack.d.ts +1 -0
  263. package/dist/docx/canonicalStoryRepack.js +2 -2
  264. package/dist/docx/chartPreview.js +10 -9
  265. package/dist/docx/commentAnchorIndex.d.ts +33 -7
  266. package/dist/docx/commentAnchorIndex.js +162 -36
  267. package/dist/docx/commentIdNormalization.d.ts +14 -0
  268. package/dist/docx/commentParagraphIds.d.ts +17 -0
  269. package/dist/docx/commentParagraphIds.js +79 -0
  270. package/dist/docx/commentParser.d.ts +20 -1
  271. package/dist/docx/commentParser.js +5 -0
  272. package/dist/docx/commentRangeIntegrity.js +27 -11
  273. package/dist/docx/commentRangeJoin.d.ts +21 -1
  274. package/dist/docx/commentRangeJoin.js +5 -1
  275. package/dist/docx/commentReferenceCompletion.d.ts +29 -2
  276. package/dist/docx/commentReferenceCompletion.js +4 -3
  277. package/dist/docx/commentReferenceNormalization.d.ts +17 -0
  278. package/dist/docx/commentReferenceNormalization.js +484 -49
  279. package/dist/docx/commentReplyMarkers.d.ts +22 -0
  280. package/dist/docx/compatibility.d.ts +10 -0
  281. package/dist/docx/containerChildren.d.ts +26 -1
  282. package/dist/docx/containerChildren.js +29 -3
  283. package/dist/docx/contentTypeRegistry.d.ts +16 -0
  284. package/dist/docx/contentTypeRegistry.js +48 -20
  285. package/dist/docx/danglingRelationshipReferences.d.ts +13 -0
  286. package/dist/docx/defaultParagraphStyle.d.ts +14 -1
  287. package/dist/docx/documentClone.d.ts +3 -2
  288. package/dist/docx/documentClone.js +1 -1
  289. package/dist/docx/documentParser.d.ts +28 -3
  290. package/dist/docx/documentParser.js +71 -4
  291. package/dist/docx/drawingAnchor.d.ts +17 -0
  292. package/dist/docx/drawingGroupChildren.d.ts +12 -0
  293. package/dist/docx/drawingIdNormalization.d.ts +8 -0
  294. package/dist/docx/drawingIdNormalization.js +46 -1
  295. package/dist/docx/drawingUtils.d.ts +6 -0
  296. package/dist/docx/drawingUtils.js +2 -2
  297. package/dist/docx/encryption/agileDecryption.d.ts +7 -0
  298. package/dist/docx/ensureParaIds.d.ts +73 -0
  299. package/dist/docx/ensureParaIds.js +299 -59
  300. package/dist/docx/ensureUniqueControlIds.js +10 -3
  301. package/dist/docx/ensureUniqueRevisionIds.d.ts +28 -0
  302. package/dist/docx/ensureUniqueRevisionIds.js +140 -0
  303. package/dist/docx/fieldParser.d.ts +27 -2
  304. package/dist/docx/fieldState.d.ts +15 -0
  305. package/dist/docx/fieldWrapperCaptures.d.ts +18 -0
  306. package/dist/docx/fieldWrapperCaptures.js +117 -0
  307. package/dist/docx/foldedListNumberFields.d.ts +14 -0
  308. package/dist/docx/fontTableParser.d.ts +11 -0
  309. package/dist/docx/footnoteParser.d.ts +24 -3
  310. package/dist/docx/footnoteParser.js +29 -6
  311. package/dist/docx/graphicFrameLocks.d.ts +9 -1
  312. package/dist/docx/groupDrawingParser.d.ts +2 -2
  313. package/dist/docx/headerFooterParser.d.ts +37 -5
  314. package/dist/docx/headerFooterParser.js +18 -4
  315. package/dist/docx/headerFooterRefParser.d.ts +7 -0
  316. package/dist/docx/hostCommentThreads.d.ts +10 -1
  317. package/dist/docx/hyperlinkParser.d.ts +20 -3
  318. package/dist/docx/hyperlinkParser.js +19 -24
  319. package/dist/docx/imageParser.d.ts +27 -0
  320. package/dist/docx/index.d.ts +3 -3
  321. package/dist/docx/inlineContentRemovals.d.ts +8 -0
  322. package/dist/docx/inlineWrapperContent.d.ts +33 -1
  323. package/dist/docx/inlineWrapperContent.js +145 -1
  324. package/dist/docx/inlineWrapperParser.d.ts +14 -0
  325. package/dist/docx/listMarkerComputation.d.ts +37 -6
  326. package/dist/docx/listMarkerComputation.js +77 -28
  327. package/dist/docx/listModelNormalization.d.ts +24 -8
  328. package/dist/docx/listModelNormalization.js +426 -142
  329. package/dist/docx/listNumberingInstances.d.ts +38 -8
  330. package/dist/docx/listNumberingInstances.js +89 -42
  331. package/dist/docx/mainDocumentPart.d.ts +22 -1
  332. package/dist/docx/mainDocumentPart.js +51 -12
  333. package/dist/docx/markupRangeMarker.d.ts +16 -0
  334. package/dist/docx/markupRangeMarker.js +11 -2
  335. package/dist/docx/mathToMathml.d.ts +28 -0
  336. package/dist/docx/mergePropertyChangeLinks.d.ts +11 -0
  337. package/dist/docx/mergePropertyChangeLinks.js +30 -0
  338. package/dist/docx/nonVisualDrawingProps.d.ts +6 -0
  339. package/dist/docx/normalizeBaseDirection.d.ts +17 -0
  340. package/dist/docx/normalizedSourceParts.d.ts +21 -0
  341. package/dist/docx/normalizedSourceParts.js +81 -0
  342. package/dist/docx/notePropertiesParser.d.ts +7 -0
  343. package/dist/docx/noteReferenceMark.d.ts +9 -0
  344. package/dist/docx/noteReferenceStyles.d.ts +13 -0
  345. package/dist/docx/numberingParser.d.ts +12 -0
  346. package/dist/docx/numberingReference.d.ts +10 -0
  347. package/dist/docx/numberingReferenceNormalization.d.ts +15 -0
  348. package/dist/docx/packageRelationshipsRoot.d.ts +24 -0
  349. package/dist/docx/packageRelationshipsRoot.js +28 -0
  350. package/dist/docx/packageUnnamedParagraphIds.d.ts +18 -0
  351. package/dist/docx/packageUnnamedParagraphIds.js +78 -0
  352. package/dist/docx/paraIdAttribute.d.ts +15 -0
  353. package/dist/docx/paragraphParser.d.ts +15 -3
  354. package/dist/docx/paragraphParser.js +126 -140
  355. package/dist/docx/paragraphProperties.d.ts +15 -1
  356. package/dist/docx/paragraphProperties.js +3 -5
  357. package/dist/docx/paragraphPropertySource.d.ts +55 -21
  358. package/dist/docx/paragraphPropertySource.js +183 -40
  359. package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
  360. package/dist/docx/paragraphTraversal.d.ts +39 -4
  361. package/dist/docx/paragraphTraversal.js +158 -42
  362. package/dist/docx/parseContext.d.ts +15 -0
  363. package/dist/docx/parseWarningMessage.d.ts +9 -0
  364. package/dist/docx/parseWarningMessage.js +7 -0
  365. package/dist/docx/parser.d.ts +1 -1
  366. package/dist/docx/parser.js +103 -29
  367. package/dist/docx/parserEnums.d.ts +21 -0
  368. package/dist/docx/partRelationships.d.ts +15 -0
  369. package/dist/docx/partRelationships.js +58 -0
  370. package/dist/docx/preservedRunContent.d.ts +2 -1
  371. package/dist/docx/preservedRunContent.js +40 -1
  372. package/dist/docx/previewBudget.d.ts +31 -0
  373. package/dist/docx/relsParser.d.ts +23 -0
  374. package/dist/docx/removeHeaderFooterParts.d.ts +1 -1
  375. package/dist/docx/replyToComment.d.ts +22 -1
  376. package/dist/docx/replyToComment.js +25 -21
  377. package/dist/docx/reviewResolutionProvenance.d.ts +32 -5
  378. package/dist/docx/reviewResolutionProvenance.js +229 -38
  379. package/dist/docx/rezip.d.ts +58 -11
  380. package/dist/docx/rezip.js +367 -101
  381. package/dist/docx/runConsolidator.d.ts +13 -0
  382. package/dist/docx/runParser.d.ts +4 -3
  383. package/dist/docx/runParser.js +27 -6
  384. package/dist/docx/runPayload.d.ts +29 -0
  385. package/dist/docx/saveDiagnostics.d.ts +3 -5
  386. package/dist/docx/sdtProperties.d.ts +17 -0
  387. package/dist/docx/sdtPropertiesPatch.d.ts +14 -0
  388. package/dist/docx/sectionParser.d.ts +21 -0
  389. package/dist/docx/sectionParser.js +1 -6
  390. package/dist/docx/selectiveSave.js +271 -80
  391. package/dist/docx/selectiveXmlPatch.d.ts +36 -1
  392. package/dist/docx/selectiveXmlPatch.js +342 -78
  393. package/dist/docx/serializer/blockSdtSerializer.d.ts +10 -0
  394. package/dist/docx/serializer/borderSerializer.d.ts +8 -0
  395. package/dist/docx/serializer/commentSerializer.d.ts +12 -1
  396. package/dist/docx/serializer/commentSerializer.js +1 -1
  397. package/dist/docx/serializer/documentSerializer.d.ts +21 -3
  398. package/dist/docx/serializer/documentSerializer.js +44 -6
  399. package/dist/docx/serializer/groupTextBoxWriteBack.d.ts +14 -0
  400. package/dist/docx/serializer/headerFooterSerializer.d.ts +11 -0
  401. package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
  402. package/dist/docx/serializer/markupRangeAttributes.js +3 -1
  403. package/dist/docx/serializer/noteSerializer.d.ts +21 -0
  404. package/dist/docx/serializer/numberingSerializer.d.ts +14 -0
  405. package/dist/docx/serializer/paragraphSerializer.d.ts +11 -0
  406. package/dist/docx/serializer/paragraphSerializer.js +21 -9
  407. package/dist/docx/serializer/partNamespaces.d.ts +2 -0
  408. package/dist/docx/serializer/partNamespaces.js +3 -1
  409. package/dist/docx/serializer/runSerializer.js +12 -3
  410. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +15 -0
  411. package/dist/docx/serializer/stylesSerializer.d.ts +26 -1
  412. package/dist/docx/serializer/stylesSerializer.js +111 -23
  413. package/dist/docx/serializer/tableSerializer.js +9 -7
  414. package/dist/docx/serializer/themeSerializer.d.ts +2 -1
  415. package/dist/docx/server/applyDocxXmlPatchProposal.js +1 -1
  416. package/dist/docx/server/build.d.ts +2 -2
  417. package/dist/docx/server/changeListFormat.d.ts +20 -0
  418. package/dist/docx/server/changeListFormat.js +102 -0
  419. package/dist/docx/server/createBilingualDocument.d.ts +21 -0
  420. package/dist/docx/server/materializeYjsDocx.js +2 -2
  421. package/dist/docx/server/migrateYjsAttrSchema.js +5 -5
  422. package/dist/docx/sessionListPruning.d.ts +11 -0
  423. package/dist/docx/settingsParser.d.ts +10 -0
  424. package/dist/docx/shadingParser.d.ts +10 -0
  425. package/dist/docx/shapeAlternateContent.js +9 -2
  426. package/dist/docx/shapeParser.d.ts +27 -0
  427. package/dist/docx/splitRevisionPieces.d.ts +1 -1
  428. package/dist/docx/storyBlockReplay.d.ts +37 -3
  429. package/dist/docx/storyBlockReplay.js +277 -68
  430. package/dist/docx/strictNames.d.ts +12 -1
  431. package/dist/docx/strictValueEncodings.gen.d.ts +9 -0
  432. package/dist/docx/structuralXmlPatch.d.ts +19 -3
  433. package/dist/docx/structuralXmlPatch.js +136 -53
  434. package/dist/docx/styleParser.d.ts +20 -3
  435. package/dist/docx/styleParser.js +3 -2
  436. package/dist/docx/tableLook.d.ts +15 -1
  437. package/dist/docx/tableParser.d.ts +17 -6
  438. package/dist/docx/tableParser.js +10 -5
  439. package/dist/docx/textBoxContentParser.d.ts +3 -2
  440. package/dist/docx/textBoxParser.d.ts +30 -3
  441. package/dist/docx/themeColorAttribute.d.ts +11 -0
  442. package/dist/docx/themeParser.d.ts +17 -5
  443. package/dist/docx/trackedMoveRangeNormalization.d.ts +9 -0
  444. package/dist/docx/trackedMoveRangeNormalization.js +40 -16
  445. package/dist/docx/transitionalSpelling.d.ts +9 -0
  446. package/dist/docx/unnamedParagraphIds.d.ts +33 -0
  447. package/dist/docx/unnamedParagraphIds.js +43 -0
  448. package/dist/docx/unreferencedHeaderFooters.d.ts +27 -0
  449. package/dist/docx/unreferencedHeaderFooters.js +130 -0
  450. package/dist/docx/unzip.d.ts +25 -0
  451. package/dist/docx/verbatimCapture.d.ts +18 -0
  452. package/dist/docx/verbatimCapture.js +76 -9
  453. package/dist/docx/vmlImageParser.d.ts +32 -1
  454. package/dist/docx/watermarkParser.d.ts +21 -0
  455. package/dist/docx/wrapPolygon.d.ts +11 -0
  456. package/dist/docx/wrapTypes.d.ts +6 -0
  457. package/dist/docx/xmlParser.d.ts +22 -18
  458. package/dist/docx/xmlParser.js +1 -18
  459. package/dist/docx/xmlRootInsertion.d.ts +8 -0
  460. package/dist/docx/xmlRootInsertion.js +28 -0
  461. package/dist/docx/xmlSafety.d.ts +1 -0
  462. package/dist/docx/xmlSafety.js +7 -11
  463. package/dist/export-pdf.d.ts +24 -1
  464. package/dist/fields/resolveFieldValues.js +2 -1
  465. package/dist/fonts/fontsourceFaces.d.ts +2 -2
  466. package/dist/fonts/headlessMeasure.d.ts +16 -0
  467. package/dist/generated/text_shaper.js +71 -59
  468. package/dist/generated/text_shaper_bg.wasm +0 -0
  469. package/dist/headless-layout.d.ts +36 -5
  470. package/dist/headless-layout.js +19 -4
  471. package/dist/i18n/messages/ar.gen.js +1 -0
  472. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  473. package/dist/i18n/messages/catalogs.gen.js +17 -0
  474. package/dist/i18n/messages/cs.gen.js +1 -0
  475. package/dist/i18n/messages/de.gen.js +1 -0
  476. package/dist/i18n/messages/en.gen.js +1 -0
  477. package/dist/i18n/messages/es.gen.js +1 -0
  478. package/dist/i18n/messages/et.gen.js +1 -0
  479. package/dist/i18n/messages/fr.gen.js +1 -0
  480. package/dist/i18n/messages/he.gen.js +1 -0
  481. package/dist/i18n/messages/hi.gen.js +1 -0
  482. package/dist/i18n/messages/hu.gen.js +1 -0
  483. package/dist/i18n/messages/lt.gen.js +1 -0
  484. package/dist/i18n/messages/lv.gen.js +1 -0
  485. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  486. package/dist/i18n/messages/pl.gen.js +1 -0
  487. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  488. package/dist/i18n/messages/sk.gen.js +1 -0
  489. package/dist/i18n/messages/tr.gen.js +1 -0
  490. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  491. package/dist/index.d.ts +33 -31
  492. package/dist/index.js +3 -4
  493. package/dist/internal/canonicalOperationStaging.d.ts +2 -0
  494. package/dist/internal/canonicalOperationStaging.js +4 -0
  495. package/dist/internal/canonicalTyping.d.ts +9 -0
  496. package/dist/internal/canonicalTyping.js +7 -0
  497. package/dist/internal/compare/inline-presentation.d.ts +8 -0
  498. package/dist/internal/indexedPositionMap.js +2 -1
  499. package/dist/internal/revisionResolutionInline.js +13 -13
  500. package/dist/internal/revisionResolutionStep.js +1 -0
  501. package/dist/internal/revisionResolutionTracking.js +2 -1
  502. package/dist/internal/wholeStoryRevisionResolution.d.ts +1 -1
  503. package/dist/internal/wholeStoryRevisionResolution.js +57 -66
  504. package/dist/layout-bridge/cellSelectionHighlight.d.ts +8 -0
  505. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +7 -0
  506. package/dist/layout-bridge/convert/editingFont.d.ts +26 -0
  507. package/dist/layout-bridge/convert/editingFont.js +42 -0
  508. package/dist/layout-bridge/convert/endnoteLayout.d.ts +19 -1
  509. package/dist/layout-bridge/convert/flowBlockPostprocessing.d.ts +5 -0
  510. package/dist/layout-bridge/convert/flowBorders.d.ts +10 -4
  511. package/dist/layout-bridge/convert/flowBorders.js +13 -1
  512. package/dist/layout-bridge/convert/flowConversionShared.d.ts +27 -12
  513. package/dist/layout-bridge/convert/flowConversionShared.js +36 -11
  514. package/dist/layout-bridge/convert/footnoteLayout.d.ts +12 -4
  515. package/dist/layout-bridge/convert/footnoteLayout.js +3 -1
  516. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +25 -5
  517. package/dist/layout-bridge/convert/imageConversion.d.ts +5 -1
  518. package/dist/layout-bridge/convert/listMarkers.d.ts +12 -7
  519. package/dist/layout-bridge/convert/markupViewFlow.d.ts +21 -0
  520. package/dist/layout-bridge/convert/markupViewFlow.js +4 -1
  521. package/dist/layout-bridge/convert/noteReferences.d.ts +4 -0
  522. package/dist/layout-bridge/convert/pageBreakSplitting.d.ts +4 -0
  523. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +13 -8
  524. package/dist/layout-bridge/convert/paragraphAttrs.js +1 -1
  525. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +10 -0
  526. package/dist/layout-bridge/convert/paragraphBlockCache.js +3 -10
  527. package/dist/layout-bridge/convert/paragraphConversion.d.ts +8 -4
  528. package/dist/layout-bridge/convert/paragraphFrames.d.ts +2 -4
  529. package/dist/layout-bridge/convert/paragraphFrames.js +4 -4
  530. package/dist/layout-bridge/convert/paragraphMarkFormatting.d.ts +13 -4
  531. package/dist/layout-bridge/convert/paragraphRuns.d.ts +5 -0
  532. package/dist/layout-bridge/convert/paragraphRuns.js +18 -4
  533. package/dist/layout-bridge/convert/runFormattingMerge.d.ts +10 -4
  534. package/dist/layout-bridge/convert/runMarkFormatting.d.ts +8 -3
  535. package/dist/layout-bridge/convert/runMarkFormatting.js +3 -5
  536. package/dist/layout-bridge/convert/sectionBoundaries.d.ts +4 -0
  537. package/dist/layout-bridge/convert/tableConversion.d.ts +15 -5
  538. package/dist/layout-bridge/convert/tableConversion.js +40 -19
  539. package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +38 -1
  540. package/dist/layout-bridge/convert/textBoxFill.d.ts +7 -2
  541. package/dist/layout-bridge/convert/textFormattingConversion.d.ts +18 -12
  542. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +8 -2
  543. package/dist/layout-bridge/convert/toFlowBlocks.js +67 -14
  544. package/dist/layout-bridge/convert/topLevelConversion.d.ts +26 -4
  545. package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +10 -0
  546. package/dist/layout-bridge/dom/clickToPositionDom.js +4 -4
  547. package/dist/layout-bridge/dom/noteStoryDom.d.ts +1 -0
  548. package/dist/layout-bridge/engine/blockIndex.d.ts +3 -0
  549. package/dist/layout-bridge/engine/clickToPosition.d.ts +9 -0
  550. package/dist/layout-bridge/engine/hitTest.d.ts +6 -0
  551. package/dist/layout-bridge/engine/hitTest.js +3 -3
  552. package/dist/layout-bridge/engine/measuring/index.d.ts +20 -8
  553. package/dist/layout-bridge/engine/selectionRects.d.ts +9 -0
  554. package/dist/layout-bridge/headerFooterLayout.d.ts +12 -0
  555. package/dist/layout-bridge/headerFooterLayout.js +3 -3
  556. package/dist/layout-bridge/sectionColumns.d.ts +10 -1
  557. package/dist/layout-engine/footnoteContinuation.d.ts +8 -0
  558. package/dist/layout-engine/imageLayout.d.ts +4 -1
  559. package/dist/layout-engine/index.d.ts +10 -5
  560. package/dist/layout-engine/index.js +9 -3
  561. package/dist/layout-engine/keep-together.d.ts +6 -0
  562. package/dist/layout-engine/layoutFlowShared.d.ts +4 -0
  563. package/dist/layout-engine/layoutInstrumentation.d.ts +40 -1
  564. package/dist/layout-engine/layoutInstrumentation.js +26 -4
  565. package/dist/layout-engine/lineFlow.d.ts +1 -0
  566. package/dist/layout-engine/lineFlow.js +4 -1
  567. package/dist/layout-engine/measure/advanceComposition.d.ts +14 -1
  568. package/dist/layout-engine/measure/automaticTextSpacing.d.ts +1 -1
  569. package/dist/layout-engine/measure/cache.d.ts +6 -0
  570. package/dist/layout-engine/measure/cache.js +3 -0
  571. package/dist/layout-engine/measure/crossRunWords.d.ts +1 -1
  572. package/dist/layout-engine/measure/floatingLineClearance.d.ts +4 -0
  573. package/dist/layout-engine/measure/floatingTablePosition.d.ts +32 -1
  574. package/dist/layout-engine/measure/floatingTablePosition.js +49 -1
  575. package/dist/layout-engine/measure/font-metrics.worker.d.ts +16 -0
  576. package/dist/layout-engine/measure/hyphenationDictionaries.d.ts +18 -0
  577. package/dist/layout-engine/measure/hyphenationPreload.d.ts +4 -0
  578. package/dist/layout-engine/measure/index.d.ts +18 -8
  579. package/dist/layout-engine/measure/index.js +2 -1
  580. package/dist/layout-engine/measure/inlineObjectMetrics.d.ts +4 -0
  581. package/dist/layout-engine/measure/justification.d.ts +5 -1
  582. package/dist/layout-engine/measure/lineFitting.d.ts +6 -1
  583. package/dist/layout-engine/measure/lineTypography.d.ts +6 -1
  584. package/dist/layout-engine/measure/listMarkerWidth.d.ts +16 -1
  585. package/dist/layout-engine/measure/measureBlocks.d.ts +4 -1
  586. package/dist/layout-engine/measure/measureBlocks.js +127 -102
  587. package/dist/layout-engine/measure/measureContainer.d.ts +17 -0
  588. package/dist/layout-engine/measure/measureHelpers.d.ts +10 -1
  589. package/dist/layout-engine/measure/measureParagraph.d.ts +7 -1
  590. package/dist/layout-engine/measure/measureParagraph.js +51 -21
  591. package/dist/layout-engine/measure/measureProvider.d.ts +10 -0
  592. package/dist/layout-engine/measure/measureTypes.d.ts +8 -0
  593. package/dist/layout-engine/measure/measureWorker.d.ts +30 -0
  594. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +14 -0
  595. package/dist/layout-engine/measure/measuresHoldNoPositions.d.ts +40 -0
  596. package/dist/layout-engine/measure/measuresHoldNoPositions.js +14 -0
  597. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +12 -0
  598. package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +21 -2
  599. package/dist/layout-engine/measure/paragraphMeasureShared.js +20 -1
  600. package/dist/layout-engine/measure/paragraphTabs.d.ts +4 -0
  601. package/dist/layout-engine/measure/raisedTableWrap.d.ts +16 -0
  602. package/dist/layout-engine/measure/raisedTableWrap.js +105 -0
  603. package/dist/layout-engine/measure/tableBorderBands.d.ts +35 -0
  604. package/dist/layout-engine/measure/tableBorderBands.js +251 -0
  605. package/dist/layout-engine/measure/tableCellFloating.js +1 -1
  606. package/dist/layout-engine/measure/tableCellFlow.d.ts +4 -4
  607. package/dist/layout-engine/measure/tableCellFlow.js +7 -10
  608. package/dist/layout-engine/measure/tableCellGrid.d.ts +4 -1
  609. package/dist/layout-engine/measure/tableCellGrid.js +30 -3
  610. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  611. package/dist/layout-engine/measure/tableMeasureMemo.d.ts +23 -0
  612. package/dist/layout-engine/measure/tableMeasureMemo.js +40 -0
  613. package/dist/layout-engine/measure/tableNoWrapWidths.d.ts +12 -0
  614. package/dist/layout-engine/measure/tableNoWrapWidths.js +73 -0
  615. package/dist/layout-engine/measure/tableVisibleBand.d.ts +6 -0
  616. package/dist/layout-engine/measure/textMeasurementPolicy.d.ts +7 -1
  617. package/dist/layout-engine/noteAreaFlow.d.ts +10 -1
  618. package/dist/layout-engine/paginator.d.ts +6 -0
  619. package/dist/layout-engine/paginator.js +6 -5
  620. package/dist/layout-engine/paragraphLayout.d.ts +5 -1
  621. package/dist/layout-engine/paragraphSpacing.d.ts +17 -2
  622. package/dist/layout-engine/paragraphSpacing.js +103 -15
  623. package/dist/layout-engine/pmPageIndex.d.ts +14 -1
  624. package/dist/layout-engine/pmPageIndex.js +10 -1
  625. package/dist/layout-engine/section-breaks.d.ts +6 -0
  626. package/dist/layout-engine/sectionLayout.d.ts +6 -1
  627. package/dist/layout-engine/sectionVerticalAlignment.js +2 -1
  628. package/dist/layout-engine/tableHeaderCompatibility.d.ts +3 -0
  629. package/dist/layout-engine/tableHeaderCompatibility.js +5 -0
  630. package/dist/layout-engine/tableLayout.d.ts +17 -6
  631. package/dist/layout-engine/tableLayout.js +36 -25
  632. package/dist/layout-engine/tableRowBreak.d.ts +16 -0
  633. package/dist/layout-engine/tableRowBreak.js +2 -1
  634. package/dist/layout-engine/textBoxFlow.d.ts +9 -0
  635. package/dist/layout-engine/textBoxLayout.d.ts +5 -1
  636. package/dist/layout-engine/types.d.ts +35 -2
  637. package/dist/layout-engine/types.js +77 -27
  638. package/dist/layout-painter/borderStroke.d.ts +1 -1
  639. package/dist/layout-painter/characterFillBand.d.ts +14 -0
  640. package/dist/layout-painter/characterFillBand.js +79 -0
  641. package/dist/layout-painter/imageLayout.d.ts +11 -2
  642. package/dist/layout-painter/index.d.ts +12 -6
  643. package/dist/layout-painter/pageShellStyles.d.ts +9 -0
  644. package/dist/layout-painter/previewSvg.d.ts +7 -0
  645. package/dist/layout-painter/reconcileRenderedContent.js +3 -1
  646. package/dist/layout-painter/registry/modules/image.d.ts +7 -0
  647. package/dist/layout-painter/registry/modules/paragraph.d.ts +8 -0
  648. package/dist/layout-painter/registry/modules/table.d.ts +6 -0
  649. package/dist/layout-painter/registry/modules/textBox.d.ts +3 -0
  650. package/dist/layout-painter/registry/modules.d.ts +10 -0
  651. package/dist/layout-painter/registry/registry.d.ts +8 -0
  652. package/dist/layout-painter/registry/types.d.ts +11 -0
  653. package/dist/layout-painter/renderFragment.d.ts +6 -0
  654. package/dist/layout-painter/renderImage.d.ts +8 -0
  655. package/dist/layout-painter/renderPage.d.ts +10 -3
  656. package/dist/layout-painter/renderPage.js +23 -4
  657. package/dist/layout-painter/renderParagraph.d.ts +6 -0
  658. package/dist/layout-painter/renderParagraph.js +33 -16
  659. package/dist/layout-painter/renderTable.d.ts +10 -1
  660. package/dist/layout-painter/renderTable.js +112 -24
  661. package/dist/layout-painter/renderTextBox.d.ts +9 -0
  662. package/dist/layout-painter/renderUtils.d.ts +5 -1
  663. package/dist/layout-painter/renderWatermark.d.ts +11 -1
  664. package/dist/layout-painter/sdtBoundary.d.ts +10 -0
  665. package/dist/managers/ClipboardManager.d.ts +13 -0
  666. package/dist/managers/ContextMenuManager.d.ts +16 -4
  667. package/dist/managers/ContextMenuManager.js +3 -3
  668. package/dist/managers/DocumentLoaderManager.d.ts +19 -5
  669. package/dist/managers/DocumentLoaderManager.js +48 -13
  670. package/dist/managers/EditorModeManager.d.ts +11 -0
  671. package/dist/managers/ErrorManager.d.ts +11 -0
  672. package/dist/managers/FindReplaceManager.d.ts +14 -27
  673. package/dist/managers/FindReplaceManager.js +0 -49
  674. package/dist/managers/HistoryManager.d.ts +18 -0
  675. package/dist/managers/TableSelectionManager.d.ts +18 -4
  676. package/dist/managers/TableSelectionManager.js +22 -5
  677. package/dist/managers/editorShortcuts.d.ts +14 -2
  678. package/dist/managers/editorShortcuts.js +5 -3
  679. package/dist/managers/types.d.ts +15 -1
  680. package/dist/markdown/annotations.d.ts +9 -0
  681. package/dist/markdown/countParagraphList.d.ts +8 -0
  682. package/dist/markdown/escape.d.ts +6 -4
  683. package/dist/markdown/escape.js +17 -8
  684. package/dist/markdown/images.d.ts +11 -0
  685. package/dist/markdown/index.d.ts +24 -1
  686. package/dist/markdown/index.js +18 -1
  687. package/dist/markdown/internals.d.ts +7 -0
  688. package/dist/markdown/renderBlock.d.ts +5 -0
  689. package/dist/markdown/renderBlock.js +2 -7
  690. package/dist/markdown/renderParagraph.d.ts +22 -2
  691. package/dist/markdown/renderParagraph.js +11 -9
  692. package/dist/markdown/renderRuns.d.ts +10 -0
  693. package/dist/markdown/renderRuns.js +36 -3
  694. package/dist/markdown/renderTable.d.ts +7 -0
  695. package/dist/markdown/renderTable.js +2 -2
  696. package/dist/markdown/trailers.d.ts +7 -0
  697. package/dist/markdown/types.d.ts +9 -2
  698. package/dist/model.d.ts +25 -3
  699. package/dist/paged-layout/pageText.d.ts +1 -1
  700. package/dist/paged-layout/paragraphFlash.d.ts +3 -0
  701. package/dist/paged-layout/rangeProjection.d.ts +20 -1
  702. package/dist/paged-layout/rangeProjection.js +22 -4
  703. package/dist/paged-layout/scrollToPmPosition.d.ts +15 -0
  704. package/dist/paged-layout/sectionBlockWidths.d.ts +2 -2
  705. package/dist/paged-layout/sectionGeometry.d.ts +4 -3
  706. package/dist/paged-layout/selectionViewportRect.d.ts +13 -0
  707. package/dist/panel-layout.d.ts +18 -1
  708. package/dist/panel-layout.js +36 -2
  709. package/dist/pdf/contentStream.d.ts +12 -0
  710. package/dist/pdf/fonts.d.ts +19 -0
  711. package/dist/pdf/paint.d.ts +9 -1
  712. package/dist/pdf/paint.js +51 -0
  713. package/dist/prosemirror/acceptedBlockNeighbours.d.ts +50 -0
  714. package/dist/prosemirror/acceptedBlockNeighbours.js +63 -0
  715. package/dist/prosemirror/alternateContentAttrs.d.ts +1 -1
  716. package/dist/prosemirror/anchoredTextBoxes.d.ts +20 -0
  717. package/dist/prosemirror/attrs/index.d.ts +2 -2
  718. package/dist/prosemirror/attrs/index.js +1 -1
  719. package/dist/prosemirror/authoredTransformAttrs.d.ts +14 -0
  720. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -2
  721. package/dist/prosemirror/canonicalCommands.d.ts +26 -1
  722. package/dist/prosemirror/canonicalCommands.js +12 -1
  723. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  724. package/dist/prosemirror/canonicalTableCommands.d.ts +14 -0
  725. package/dist/prosemirror/canonicalTableCommands.js +18 -6
  726. package/dist/prosemirror/cellDragSelection.d.ts +9 -0
  727. package/dist/prosemirror/commands/comments.d.ts +22 -0
  728. package/dist/prosemirror/commands/comments.js +374 -154
  729. package/dist/prosemirror/commands/contentControls.d.ts +20 -3
  730. package/dist/prosemirror/commands/contentControls.js +18 -1
  731. package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +11 -1
  732. package/dist/prosemirror/commands/formatPainter.d.ts +10 -0
  733. package/dist/prosemirror/commands/formatPainter.js +0 -1
  734. package/dist/prosemirror/commands/formatting.d.ts +9 -2
  735. package/dist/prosemirror/commands/hyperlink.d.ts +12 -0
  736. package/dist/prosemirror/commands/image.d.ts +12 -0
  737. package/dist/prosemirror/commands/index.d.ts +10 -5
  738. package/dist/prosemirror/commands/pageBreak.d.ts +3 -0
  739. package/dist/prosemirror/commands/paragraph.d.ts +8 -1
  740. package/dist/prosemirror/commands/pastePlainText.d.ts +8 -0
  741. package/dist/prosemirror/commands/pastePlainText.js +1 -1
  742. package/dist/prosemirror/commands/propertyChangeScope.d.ts +28 -15
  743. package/dist/prosemirror/commands/propertyChangeScope.js +5 -12
  744. package/dist/prosemirror/commands/replaceRangeText.d.ts +22 -0
  745. package/dist/prosemirror/commands/replaceRangeText.js +44 -0
  746. package/dist/prosemirror/commands/resolveAllTableChanges.js +3 -2
  747. package/dist/prosemirror/commands/resolveParagraphProperties.js +4 -8
  748. package/dist/prosemirror/commands/rulerParagraph.d.ts +25 -0
  749. package/dist/prosemirror/commands/rulerParagraph.js +18 -0
  750. package/dist/prosemirror/commands/sectionBreak.d.ts +5 -0
  751. package/dist/prosemirror/commands/table.d.ts +7 -0
  752. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  753. package/dist/prosemirror/commentIdAllocator.d.ts +12 -6
  754. package/dist/prosemirror/commentIdAllocator.js +38 -29
  755. package/dist/prosemirror/commentOps.d.ts +7 -0
  756. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +1 -1
  757. package/dist/prosemirror/commentRangeInlineAtoms.d.ts +4 -3
  758. package/dist/prosemirror/commentRangeInlineAtoms.js +1 -1
  759. package/dist/prosemirror/commentRecords.d.ts +17 -0
  760. package/dist/prosemirror/commentRecords.js +132 -5
  761. package/dist/prosemirror/commentReferenceAttrs.d.ts +1 -1
  762. package/dist/prosemirror/commentReferenceIntegrity.js +93 -14
  763. package/dist/prosemirror/containerFinalParagraph.d.ts +2 -0
  764. package/dist/prosemirror/containerFinalParagraph.js +3 -1
  765. package/dist/prosemirror/contentControlRevisions.d.ts +14 -0
  766. package/dist/prosemirror/conversion/effectiveTableCellFormatting.d.ts +5 -4
  767. package/dist/prosemirror/conversion/fromProseDoc.d.ts +1 -1
  768. package/dist/prosemirror/conversion/fromProseDoc.js +72 -58
  769. package/dist/prosemirror/conversion/index.d.ts +6 -1
  770. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +21 -0
  771. package/dist/prosemirror/conversion/runShadingMark.d.ts +13 -1
  772. package/dist/prosemirror/conversion/storyConversionOptions.d.ts +16 -0
  773. package/dist/prosemirror/conversion/storyConversionOptions.js +13 -0
  774. package/dist/prosemirror/conversion/toProseDoc.d.ts +35 -10
  775. package/dist/prosemirror/conversion/toProseDoc.js +197 -136
  776. package/dist/prosemirror/copyOriginResolution.js +23 -10
  777. package/dist/prosemirror/documentSchema.d.ts +12 -0
  778. package/dist/prosemirror/emptyRangeAnchor.d.ts +39 -8
  779. package/dist/prosemirror/emptyRangeAnchor.js +63 -10
  780. package/dist/prosemirror/extensions/ExtensionManager.d.ts +7 -0
  781. package/dist/prosemirror/extensions/ExtensionManager.js +2 -0
  782. package/dist/prosemirror/extensions/StarterKit.d.ts +11 -2
  783. package/dist/prosemirror/extensions/core/DocExtension.d.ts +3 -0
  784. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +3 -0
  785. package/dist/prosemirror/extensions/core/HistoryExtension.js +3 -2
  786. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +13 -4
  787. package/dist/prosemirror/extensions/core/ParagraphExtension.js +5 -3
  788. package/dist/prosemirror/extensions/core/TextExtension.d.ts +3 -0
  789. package/dist/prosemirror/extensions/create.d.ts +6 -0
  790. package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +5 -0
  791. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -3
  792. package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +10 -0
  793. package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +10 -0
  794. package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +6 -0
  795. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +20 -0
  796. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +20 -23
  797. package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +13 -0
  798. package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +9 -0
  799. package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +6 -0
  800. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +14 -0
  801. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +38 -21
  802. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +8 -3
  803. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +5 -14
  804. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +17 -0
  805. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +7 -3
  806. package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +14 -0
  807. package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +4 -1
  808. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +32 -3
  809. package/dist/prosemirror/extensions/features/pasteCleanup.js +23 -3
  810. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +22 -0
  811. package/dist/prosemirror/extensions/features/pastedCellSections.js +78 -0
  812. package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +22 -0
  813. package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +1 -0
  814. package/dist/prosemirror/extensions/markRegistry.d.ts +14 -1
  815. package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +3 -0
  816. package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +3 -0
  817. package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +8 -0
  818. package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +14 -0
  819. package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +6 -0
  820. package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +3 -0
  821. package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +4 -6
  822. package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +3 -0
  823. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +5 -0
  824. package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +17 -0
  825. package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +3 -0
  826. package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +3 -0
  827. package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +19 -0
  828. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +12 -0
  829. package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +3 -0
  830. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -2
  831. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +2 -1
  832. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -0
  833. package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +3 -0
  834. package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +3 -0
  835. package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +3 -0
  836. package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +3 -0
  837. package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +3 -0
  838. package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +6 -0
  839. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +7 -0
  840. package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +3 -0
  841. package/dist/prosemirror/extensions/marks/markUtils.d.ts +10 -3
  842. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +22 -0
  843. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +11 -0
  844. package/dist/prosemirror/extensions/nodes/BlockMoveRangeBoundaryExtension.d.ts +14 -0
  845. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +17 -0
  846. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.d.ts +1 -0
  847. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +38 -4
  848. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +2 -1
  849. package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +8 -0
  850. package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +3 -0
  851. package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +3 -0
  852. package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +3 -0
  853. package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +7 -0
  854. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +1 -0
  855. package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +3 -0
  856. package/dist/prosemirror/extensions/nodes/PageBreakRunExtension.d.ts +1 -0
  857. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +25 -0
  858. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +9 -0
  859. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +1 -0
  860. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +7 -19
  861. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.d.ts +1 -0
  862. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +6 -0
  863. package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +6 -0
  864. package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +3 -0
  865. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +8 -1
  866. package/dist/prosemirror/extensions/nodes/TableExtension.js +6 -6
  867. package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.d.ts +7 -0
  868. package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +7 -0
  869. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +9 -0
  870. package/dist/prosemirror/extensions/types.d.ts +10 -1
  871. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  872. package/dist/prosemirror/hyperlinkRemoval.d.ts +13 -1
  873. package/dist/prosemirror/imageCommit.d.ts +10 -0
  874. package/dist/prosemirror/index.d.ts +30 -20
  875. package/dist/prosemirror/indexedNodeLookup.d.ts +11 -0
  876. package/dist/prosemirror/inlineWrapperStack.d.ts +12 -0
  877. package/dist/prosemirror/insertOperations.d.ts +10 -1
  878. package/dist/prosemirror/insertOperations.js +2 -2
  879. package/dist/prosemirror/insertionGaps.d.ts +21 -0
  880. package/dist/prosemirror/insertionGaps.js +86 -0
  881. package/dist/prosemirror/keptRangeBoundaries.d.ts +16 -12
  882. package/dist/prosemirror/keptRangeBoundaries.js +28 -34
  883. package/dist/prosemirror/listAutoformatMarkers.d.ts +11 -0
  884. package/dist/prosemirror/listInstanceReferences.d.ts +5 -0
  885. package/dist/prosemirror/listLabels.d.ts +16 -3
  886. package/dist/prosemirror/listLabels.js +0 -6
  887. package/dist/prosemirror/listMarker.d.ts +2 -2
  888. package/dist/prosemirror/listNumbering.d.ts +1 -1
  889. package/dist/prosemirror/listRendering.d.ts +2 -2
  890. package/dist/prosemirror/listRenderingAttrs.d.ts +10 -1
  891. package/dist/prosemirror/lockedControls.d.ts +6 -0
  892. package/dist/prosemirror/markupViewNotes.d.ts +11 -1
  893. package/dist/prosemirror/markupViewProjection.d.ts +21 -4
  894. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +1 -1
  895. package/dist/prosemirror/nativeSelection.d.ts +21 -3
  896. package/dist/prosemirror/nativeSelection.js +69 -19
  897. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  898. package/dist/prosemirror/noteReferenceReview.d.ts +17 -3
  899. package/dist/prosemirror/noteReferenceReview.js +26 -5
  900. package/dist/prosemirror/pageBreakRunProjection.d.ts +2 -1
  901. package/dist/prosemirror/paraText.d.ts +14 -0
  902. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +13 -1
  903. package/dist/prosemirror/paragraphIndentation.d.ts +6 -3
  904. package/dist/prosemirror/paragraphIndentation.js +2 -3
  905. package/dist/prosemirror/paragraphList.d.ts +1 -1
  906. package/dist/prosemirror/paragraphMarkJoin.d.ts +29 -1
  907. package/dist/prosemirror/paragraphMarkJoin.js +25 -6
  908. package/dist/prosemirror/paragraphPropertyCarry.d.ts +15 -1
  909. package/dist/prosemirror/paragraphPropertyCarry.js +5 -3
  910. package/dist/prosemirror/paragraphSpacing.d.ts +1 -1
  911. package/dist/prosemirror/pastePlacement.d.ts +17 -0
  912. package/dist/prosemirror/pastePlacement.js +22 -0
  913. package/dist/prosemirror/pastedCommentCopies.d.ts +87 -0
  914. package/dist/prosemirror/pastedCommentCopies.js +379 -0
  915. package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +12 -0
  916. package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +14 -0
  917. package/dist/prosemirror/plugins/contentControlWidgets.d.ts +15 -9
  918. package/dist/prosemirror/plugins/contentControlWidgets.js +22 -28
  919. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +17 -0
  920. package/dist/prosemirror/plugins/documentNumbering.d.ts +2 -1
  921. package/dist/prosemirror/plugins/documentStyleState.d.ts +3 -4
  922. package/dist/prosemirror/plugins/documentStyles.d.ts +20 -3
  923. package/dist/prosemirror/plugins/index.d.ts +7 -1
  924. package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +18 -1
  925. package/dist/prosemirror/plugins/paragraphStyleResolution.js +12 -2
  926. package/dist/prosemirror/plugins/pmTextScan.d.ts +18 -0
  927. package/dist/prosemirror/plugins/pmTextScan.js +42 -33
  928. package/dist/prosemirror/plugins/revisionIds.d.ts +14 -1
  929. package/dist/prosemirror/plugins/revisionIds.js +5 -1
  930. package/dist/prosemirror/plugins/selectionTracker.d.ts +12 -2
  931. package/dist/prosemirror/plugins/suggestionMode.d.ts +14 -11
  932. package/dist/prosemirror/plugins/suggestionMode.js +212 -34
  933. package/dist/prosemirror/plugins/templateDirectives.d.ts +17 -0
  934. package/dist/prosemirror/plugins/templatePreviewValues.d.ts +23 -0
  935. package/dist/prosemirror/plugins/templateSlashMenu.d.ts +19 -0
  936. package/dist/prosemirror/plugins/transactionInvariants.d.ts +19 -0
  937. package/dist/prosemirror/positionSweep.d.ts +21 -0
  938. package/dist/prosemirror/queries.d.ts +9 -0
  939. package/dist/prosemirror/queries.js +2 -2
  940. package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -2
  941. package/dist/prosemirror/rangeAnchorAttrs.js +55 -33
  942. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  943. package/dist/prosemirror/rejoinRunCarriers.d.ts +17 -0
  944. package/dist/prosemirror/replaceFindMatches.d.ts +20 -0
  945. package/dist/prosemirror/replaceFindMatches.js +33 -0
  946. package/dist/prosemirror/replacedAnnotations.d.ts +143 -0
  947. package/dist/prosemirror/replacedAnnotations.js +223 -26
  948. package/dist/prosemirror/revisionCarriers.js +9 -0
  949. package/dist/prosemirror/runFormattingFromMarks.d.ts +3 -3
  950. package/dist/prosemirror/runFormattingFromMarks.js +10 -51
  951. package/dist/prosemirror/runFormattingProvenance.d.ts +2 -1
  952. package/dist/prosemirror/runFormattingProvenance.js +2 -1
  953. package/dist/prosemirror/runFormattingReconciliation.js +3 -12
  954. package/dist/prosemirror/runIdentity.d.ts +14 -0
  955. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +7 -0
  956. package/dist/prosemirror/runPropertyChangeResolution.d.ts +5 -13
  957. package/dist/prosemirror/runPropertyChangeResolution.js +13 -30
  958. package/dist/prosemirror/runStyleFormatting.d.ts +42 -113
  959. package/dist/prosemirror/runStyleFormatting.js +17 -74
  960. package/dist/prosemirror/schema/index.d.ts +8 -1
  961. package/dist/prosemirror/schema/marks.d.ts +16 -2
  962. package/dist/prosemirror/schema/nodes.d.ts +15 -14
  963. package/dist/prosemirror/sectionCarrier.d.ts +21 -0
  964. package/dist/prosemirror/sectionMarkEdits.d.ts +18 -0
  965. package/dist/prosemirror/selectionState.d.ts +10 -4
  966. package/dist/prosemirror/storyListNumbering.d.ts +10 -0
  967. package/dist/prosemirror/styles/index.d.ts +3 -0
  968. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +20 -18
  969. package/dist/prosemirror/styles/paragraphStyleCascade.js +10 -19
  970. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +4 -3
  971. package/dist/prosemirror/styles/styleResolver.d.ts +40 -15
  972. package/dist/prosemirror/styles/styleResolver.js +6 -6
  973. package/dist/prosemirror/styles/styleToggleCascade.d.ts +18 -11
  974. package/dist/prosemirror/styles/styleToggleCascade.js +2 -11
  975. package/dist/prosemirror/styles/tableStyleRegions.d.ts +20 -7
  976. package/dist/prosemirror/styles/tableStyleRegions.js +14 -13
  977. package/dist/prosemirror/tableCellPaste.d.ts +21 -0
  978. package/dist/prosemirror/tableCellPaste.js +32 -2
  979. package/dist/prosemirror/tableGridMutation.d.ts +9 -0
  980. package/dist/prosemirror/tableGridMutation.js +34 -2
  981. package/dist/prosemirror/tablePositionedBookmarks.d.ts +6 -0
  982. package/dist/prosemirror/tableResize.d.ts +10 -0
  983. package/dist/prosemirror/tableRunIn.d.ts +26 -1
  984. package/dist/prosemirror/tableRunIn.js +39 -11
  985. package/dist/prosemirror/textBoxAnchorAttrs.d.ts +1 -1
  986. package/dist/prosemirror/textBoxHostCollapse.d.ts +11 -0
  987. package/dist/prosemirror/utils/findParagraphByParaId.d.ts +5 -0
  988. package/dist/prosemirror/utils/tabCalculator.d.ts +6 -0
  989. package/dist/prosemirror/utils/visualLineNavigation.js +1 -1
  990. package/dist/prosemirror/validation.js +6 -11
  991. package/dist/prosemirror/yjsDocumentMetadata.d.ts +9 -3
  992. package/dist/prosemirror/yjsDocumentMetadata.js +49 -10
  993. package/dist/prosemirror/zeroWidthAnchors.d.ts +18 -0
  994. package/dist/redline.d.ts +4 -1
  995. package/dist/redline.js +21 -13
  996. package/dist/render-dom/BodySelectionOverlay.d.ts +5 -0
  997. package/dist/render-dom/RemoteSelectionOverlay.js +3 -3
  998. package/dist/server.d.ts +30 -18
  999. package/dist/server.js +4 -3
  1000. package/dist/shaping/placeRun.d.ts +8 -0
  1001. package/dist/shaping/shaper.d.ts +19 -0
  1002. package/dist/style-engine/index.d.ts +5 -0
  1003. package/dist/style-engine/styleEngine.d.ts +32 -13
  1004. package/dist/style-sets/extract.d.ts +1 -1
  1005. package/dist/style-sets/styleSetNormalization.d.ts +20 -1
  1006. package/dist/text-shaping.d.ts +9 -1
  1007. package/dist/types/anonymization.d.ts +17 -0
  1008. package/dist/types/anonymization.js +0 -0
  1009. package/dist/types/autocomplete.d.ts +46 -0
  1010. package/dist/types/autocomplete.js +0 -0
  1011. package/dist/types/canonicalCapabilities.d.ts +40 -42
  1012. package/dist/types/canonicalCapabilities.js +43 -44
  1013. package/dist/types/canonicalSave.d.ts +36 -0
  1014. package/dist/types/documentModel.d.ts +37 -0
  1015. package/dist/types/documentModel.js +24 -0
  1016. package/dist/types/docxSerialization.d.ts +10 -0
  1017. package/dist/types/index.d.ts +5 -0
  1018. package/dist/types/remote-selection.d.ts +2 -1
  1019. package/dist/types/selectiveSaveDecline.d.ts +44 -0
  1020. package/dist/types/selectiveSaveDecline.js +0 -0
  1021. package/dist/types/tableWidthKind.d.ts +2 -0
  1022. package/dist/types/tableWidthKind.js +9 -0
  1023. package/dist/utils/base64.d.ts +20 -0
  1024. package/dist/utils/borderCss.d.ts +18 -1
  1025. package/dist/utils/colorResolver.d.ts +12 -11
  1026. package/dist/utils/createDocument.d.ts +8 -1
  1027. package/dist/utils/createDocument.js +20 -2
  1028. package/dist/utils/diagonalHatch.d.ts +2 -0
  1029. package/dist/utils/diagonalHatch.js +16 -0
  1030. package/dist/utils/extremes.d.ts +4 -0
  1031. package/dist/utils/extremes.js +14 -0
  1032. package/dist/utils/findMatchView.d.ts +2 -2
  1033. package/dist/utils/findReplace.d.ts +2 -2
  1034. package/dist/utils/findReplace.js +3 -2
  1035. package/dist/utils/fontFamilyMerge.d.ts +2 -1
  1036. package/dist/utils/fontResolver.d.ts +11 -2
  1037. package/dist/utils/formatToStyle.d.ts +22 -8
  1038. package/dist/utils/headerFooter.d.ts +16 -2
  1039. package/dist/utils/headerFooter.js +2 -6
  1040. package/dist/utils/imageResize.js +1 -1
  1041. package/dist/utils/listItems.d.ts +7 -0
  1042. package/dist/utils/listItems.js +9 -0
  1043. package/dist/utils/mergeDocumentContent.d.ts +7 -0
  1044. package/dist/utils/outlineHeadings.d.ts +1 -1
  1045. package/dist/utils/paragraphFormattingMerge.d.ts +11 -3
  1046. package/dist/utils/paragraphFormattingMerge.js +0 -8
  1047. package/dist/utils/paragraphInlineLayout.js +2 -1
  1048. package/dist/utils/repeatingStrokeGradient.d.ts +8 -0
  1049. package/dist/utils/repeatingStrokeGradient.js +13 -0
  1050. package/dist/utils/rotationBoundingBox.d.ts +8 -0
  1051. package/dist/utils/rulerControl.d.ts +71 -0
  1052. package/dist/utils/rulerControl.js +94 -0
  1053. package/dist/utils/tableOperations.d.ts +20 -4
  1054. package/dist/utils/tableOperations.js +1 -0
  1055. package/dist/utils/textDirectionFlow.d.ts +10 -0
  1056. package/dist/utils/textFormattingMerge.d.ts +18 -2
  1057. package/dist/utils/textFormattingMerge.js +0 -20
  1058. package/dist/utils/units.d.ts +2 -0
  1059. package/dist/utils/units.js +3 -1
  1060. package/dist/version-comparison.d.ts +63 -1
  1061. package/dist/version-comparison.js +2 -1
  1062. package/dist/watermark/index.d.ts +11 -0
  1063. package/dist/watermark/index.js +0 -5
  1064. package/package.json +7 -7
  1065. package/dist/controller/canonicalPublicOperations.js +0 -1276
  1066. package/dist/controller/canonicalSeedContent.d.ts +0 -12
  1067. package/dist/controller/canonicalSourceNormalization.d.ts +0 -21
  1068. package/dist/docx/canonicalResourceSave.d.ts +0 -15
  1069. package/dist/docx/canonicalResourceSave.js +0 -27
  1070. package/dist/internal/acceptedBlockProjection.d.ts +0 -9
  1071. package/dist/internal/acceptedBlockProjection.js +0 -50
  1072. package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +0 -60
  1073. package/dist/prosemirror/plugins/anonymizationDecorations.js +0 -111
  1074. package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +0 -127
  1075. package/dist/prosemirror/plugins/autocompleteSuggestion.js +0 -282
  1076. package/dist/utils/replaceText.d.ts +0 -25
  1077. package/dist/utils/replaceText.js +0 -242
  1078. /package/dist/{controller → canonical}/canonicalListRendering.d.ts +0 -0
  1079. /package/dist/{controller → canonical}/canonicalOperations.d.ts +0 -0
  1080. /package/dist/{controller → canonical}/canonicalSelection.d.ts +0 -0
  1081. /package/dist/{controller → canonical}/canonicalTocSelection.d.ts +0 -0
@@ -1,8 +1,17 @@
1
+ import { canonicalCommentBody, compileCanonicalComments } from "../canonical/canonicalComments.js";
2
+ import { createCanonicalSectionPropertiesOperation } from "../canonical/canonicalOperations.js";
3
+ import { CanonicalPublicOperations } from "../canonical/canonicalPublicOperations.js";
4
+ import { canonicalRevisionLocks } from "../canonical/canonicalRevisionLocks.js";
5
+ import { openCanonicalDocxSession, openCanonicalRoomBase } from "../canonical/canonicalRoomBase.js";
6
+ import { CanonicalSessionError, createCanonicalSession, publishCanonicalProjection } from "../canonical/canonicalSession.js";
7
+ import { matchInlineAtomsOnModel } from "../compare/inline-atoms-model.js";
1
8
  import { matchInlineAtoms } from "../compare/inline-atoms.js";
2
- import { matchInlineProvenance } from "../compare/inline-provenance.js";
3
- import { stageSectionBoundaryProperties } from "../compare/section-boundary-properties.js";
9
+ import { inlineProvenanceOperations } from "../compare/inline-provenance-model.js";
10
+ import { matchInlineProvenance, planInlineProvenance } from "../compare/inline-provenance.js";
11
+ import { stageSectionBoundaryOperations, stageSectionBoundaryProperties } from "../compare/section-boundary-properties.js";
4
12
  import { importReferencedStyleDefinitions, styleClosureNumberingReferences } from "../compare/style-resources.js";
5
- import { applyFolioDocumentOperationsInPackage } from "../document-operations.js";
13
+ import { applyFolioDocumentOperationsInPackage, parseFolioDocumentOperationBatch } from "../document-operations.js";
14
+ import { CanonicalSaveRepackRefusedError, serializeCanonicalSave } from "../docx/canonicalSave.js";
6
15
  import { removeCommentMarkers } from "../docx/commentAnchorIndex.js";
7
16
  import { applyReplyThreadMarkers } from "../docx/commentReplyMarkers.js";
8
17
  import { commentTextParagraph } from "../docx/commentTextParagraph.js";
@@ -12,52 +21,58 @@ import { isSeparatorEndnote, isSeparatorFootnote } from "../docx/footnoteParser.
12
21
  import { normalizeListModelRendering } from "../docx/listModelNormalization.js";
13
22
  import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
14
23
  import { getCachedNumberingMap } from "../docx/numberingParser.js";
24
+ import { cloneDocumentWithParagraphPropertySources } from "../docx/paragraphPropertySource.js";
15
25
  import { visitDocxParagraphs } from "../docx/paragraphTraversal.js";
16
26
  import { parseDocx } from "../docx/parser.js";
17
27
  import { createReply } from "../docx/replyToComment.js";
18
28
  import { repackDocx } from "../docx/rezip.js";
19
- import { sectionReferenceHistory } from "../docx/sectionReferenceHistory.js";
20
29
  import { attemptSelectiveSave } from "../docx/selectiveSave.js";
21
30
  import { getEndnoteText, getFootnoteText, getHeaderFooterText } from "../docx/storyPlainText.js";
22
31
  import { pluginsForHeadlessRevisionResolution } from "../internal/headlessRevisionResolutionGuard.js";
23
32
  import { withTrackedSectionEndpointRemoval } from "../internal/sectionEndpointResolution.js";
24
33
  import { captureSectionReferenceInventory, resolvedSectionReferenceLosses, withSectionReferenceResolution } from "../internal/sectionReferenceResolution.js";
25
34
  import { expectCharacterStyleMarkAttrs, expectFootnoteRefMarkAttrs } from "../prosemirror/attrs/index.js";
26
- import { acceptAIEditRevision, acceptSuggestion, getSuggestions, rejectAIEditRevision, rejectAllSuggestions, rejectSuggestion, resolveAllChangesInHeadlessState, revisionResolutionLockViolation, suggestionIdOfRevision } from "../prosemirror/commands/comments.js";
27
- import { sectionRejectProperties } from "../prosemirror/commands/propertyChangeScope.js";
28
- import { allocateCommentId, createCommentIdAllocator, seedCommentAllocator } from "../prosemirror/commentIdAllocator.js";
35
+ import { acceptAIEditRevision, acceptSuggestion, getSuggestions, rejectAIEditRevision, rejectEverySuggestion, rejectSuggestion, resolveAllChangesInHeadlessState, revisionResolutionLockViolation, suggestionIdOfRevision, suggestionOwnersByRevision } from "../prosemirror/commands/comments.js";
36
+ import { createCommentIdAllocator, seedCommentAllocator } from "../prosemirror/commentIdAllocator.js";
37
+ import { commentThreadIds, removeCommentAnchors } from "../prosemirror/commentRecords.js";
29
38
  import { fromProseDoc, proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
30
39
  import { footnoteToProseDoc, headerFooterToProseDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
31
40
  import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
32
41
  import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
33
42
  import { getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
34
- import { completeNumberingForDoc } from "../prosemirror/listInstanceReferences.js";
43
+ import { completeNumberingForDoc, paragraphListReferences } from "../prosemirror/listInstanceReferences.js";
35
44
  import "../prosemirror/listMarker.js";
36
45
  import { lockedControlSpans } from "../prosemirror/lockedControls.js";
37
46
  import { deleteNoteWithReference, noteDeletionRevisions, noteKeysReferencedIn, noteReferenceStates, noteReferencesRestored, referenceDeletions, referencedNotes } from "../prosemirror/noteReferenceReview.js";
38
47
  import { createDocumentNumberingPlugin, getDocumentNumbering, withDocumentNumbering } from "../prosemirror/plugins/documentNumbering.js";
39
48
  import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
40
- import { createDocumentStylesPlugin, withDocumentStyles } from "../prosemirror/plugins/documentStyles.js";
49
+ import { createDocumentStyleContextPlugin, createDocumentStylesPlugin, withDocumentStyles } from "../prosemirror/plugins/documentStyles.js";
50
+ import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
41
51
  import { schema, singletonManager } from "../prosemirror/schema/index.js";
42
52
  import { sectionPropertiesOf } from "../prosemirror/sectionCarrier.js";
43
53
  import { storyListNumbering } from "../prosemirror/storyListNumbering.js";
44
54
  import { collapseEmptyTextBoxHosts } from "../prosemirror/textBoxHostCollapse.js";
55
+ import { CANONICAL_GAP, CANONICAL_RULE, headlessReviewerUsesCanonicalSession } from "../types/canonicalCapabilities.js";
56
+ import { readModel } from "../types/documentModel.js";
45
57
  import { canonicalJson } from "../utils/canonicalJson.js";
58
+ import { persistedBlock } from "./block-identity.js";
46
59
  import { buildAnnotatedBlockTextWithNoteReferences } from "./clean-text.js";
47
60
  import { anchoredCommentIdsInBlocks, anchoredCommentIdsInProseDoc, coveredCommentIdsInProseDoc, withoutLostCommentThreads } from "./comment-lifecycle.js";
61
+ import { stagedFinalSectionProperties } from "./finalSectionReview.js";
48
62
  import { noteReferenceEditsAllowed } from "./note-references.js";
49
63
  import { noteStoryInventory } from "./note-story-inventory.js";
50
64
  import { FolioPendingSuggestionRegistry, createPendingSuggestionSourceSnapshot, withoutPendingSuggestionCommentMarks } from "./pending-suggestions.js";
51
- import { getCommentAnchorsFromDoc, getTrackedChangeGroupIdsFromDoc, getTrackedChangeStatsFromDoc, getTrackedChangesFromDoc, getTrackedChangesFromSnapshot } from "./read.js";
65
+ import { getCommentAnchorsFromDoc, getTrackedChangeGroupIdsFromDoc, getTrackedChangeStatsFromDoc, getTrackedChangesFromDoc, getTrackedChangesFromSnapshot, listedRevisionGroups } from "./read.js";
52
66
  import { classifyResourceReference } from "./referenceClassification.js";
53
- import { collectNoteReferenceLabels, createFolioAIEditSnapshotWithStyleResolver, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, isFolioAIContentBlock, normalizeFolioAIBlockText, sourceDocumentOf } from "./snapshot.js";
54
- import { matchTableGeometry } from "./table-geometry.js";
67
+ import { collectNoteReferenceLabels, createReviewerSnapshot, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, isFolioAIContentBlock, normalizeFolioAIBlockText, sourceDocumentOf } from "./snapshot.js";
68
+ import { matchTableGeometry, matchTableGeometryOperations } from "./table-geometry.js";
55
69
  import { tableTemplateCanCrossPackageLosslessly } from "./table-template.js";
70
+ import { withOperationHeadingStyles } from "./undefinedReferences.js";
56
71
  import { TaggedError, panic } from "better-result";
57
72
  import { CONTENT_CONTROL_LOCK, REVIEW_CARRIERS, finalizeParagraphFormatting, lockedControlMessage, numberingLevelEntries, setDocumentBodyComments } from "@stll/docx-core/model";
58
- import { reconcileDocumentPartRelationships } from "@stll/docx-core/ops";
59
- import { EditorState } from "prosemirror-state";
73
+ import { DOCUMENT_OP_TYPES, OP_STORIES, captureStoryParts, freshCommentId, packageResourcesOpOf, pendingSuggestionIdsIn, reconcileDocumentPartRelationships, resolveSectionChange, resolveSectionChanges, resolvedDocumentView, sectionResolutionPatch, withoutPendingSuggestions } from "@stll/docx-core/ops";
60
74
  import { ZipArchive } from "@stll/docx-core/zip";
75
+ import { EditorState, Selection, TextSelection } from "prosemirror-state";
61
76
  // src/ai-edits/headless.ts
62
77
  /**
63
78
  * Headless `.docx` review path: buffer -> apply AI edits -> buffer, with
@@ -92,6 +107,64 @@ const createReviewerComment = ({ id, text, author, date }) => ({
92
107
  * entries are dropped, as an editor's undo history drops its oldest steps.
93
108
  */
94
109
  const FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT = 100;
110
+ /**
111
+ * The main story's state of a canonical reviewer: the session's projection
112
+ * with the package's numbering and styles, which the readers resolve
113
+ * against. It is rebuilt from the session after every commit, so it never
114
+ * holds anything the session does not.
115
+ */
116
+ const canonicalReviewerState = (session) => canonicalStoryState(session, session.projection.doc, session.projection);
117
+ /**
118
+ * The caret a story state starts at: the start of the story, or where the
119
+ * session first holds an address when it holds none there, as in the filler
120
+ * paragraph of a content control the source leaves empty.
121
+ */
122
+ const startingSelection = (doc, projection) => {
123
+ const start = Selection.atStart(doc);
124
+ if (projection === void 0 || projection.addressAt(start.from).isOk()) return void 0;
125
+ let found;
126
+ doc.descendants((node, position) => {
127
+ if (found !== void 0) return false;
128
+ if (!node.isTextblock) return true;
129
+ if (projection.addressAt(position + 1).isOk()) found = position + 1;
130
+ return false;
131
+ });
132
+ return found === void 0 ? void 0 : TextSelection.create(doc, found);
133
+ };
134
+ /** A story's state over `doc`, with the session document's numbering and styles. */
135
+ const canonicalStoryState = (session, doc, projection) => {
136
+ const document = readModel(session.document);
137
+ const selection = startingSelection(doc, projection);
138
+ return EditorState.create({
139
+ schema,
140
+ doc,
141
+ ...selection === void 0 ? {} : { selection },
142
+ plugins: [createDocumentNumberingPlugin(document.package.numbering), createDocumentStyleContextPlugin(document.package.styles)]
143
+ });
144
+ };
145
+ /** The session's name for a reviewer's story. */
146
+ const canonicalOpStory = (story) => {
147
+ switch (story.type) {
148
+ case "main": return OP_STORIES.MAIN;
149
+ case "header":
150
+ case "footer": return {
151
+ kind: story.type,
152
+ rId: story.relationshipId
153
+ };
154
+ case "footnote":
155
+ case "endnote": return {
156
+ kind: story.type,
157
+ id: story.noteId
158
+ };
159
+ default: return panic("Unknown reviewer story", { story });
160
+ }
161
+ };
162
+ /** The refusal of a canonical reviewer for what it cannot do on the session yet. */
163
+ const canonicalReviewerRefusal = (action) => new CanonicalSessionError({
164
+ ground: { gap: CANONICAL_GAP.publicHeadlessSession },
165
+ reason: "refused",
166
+ message: `A canonical headless reviewer cannot ${action} yet.`
167
+ });
95
168
  const FOLIO_REVIEWED_VIEWS = Object.freeze([
96
169
  "original",
97
170
  "current-markup",
@@ -100,8 +173,18 @@ const FOLIO_REVIEWED_VIEWS = Object.freeze([
100
173
  const FOLIO_RESOLVED_REVIEWED_VIEWS = Object.freeze(["original", "final"]);
101
174
  const UnsupportedFolioReviewedViewErrorBase = TaggedError("UnsupportedFolioReviewedViewError");
102
175
  var UnsupportedFolioReviewedViewError = class extends UnsupportedFolioReviewedViewErrorBase {};
176
+ const FolioRoomJournalErrorBase = TaggedError("FolioRoomJournalError");
177
+ /**
178
+ * Why a reviewer could not replay a room's journal. `legacyEngine`: only a
179
+ * canonical reviewer follows a room. `revisionGap`: a batch is not the one
180
+ * after the last the reviewer applied.
181
+ */
182
+ var FolioRoomJournalError = class extends FolioRoomJournalErrorBase {};
103
183
  const FolioDocumentStoryNotFoundErrorBase = TaggedError("FolioDocumentStoryNotFoundError");
104
184
  var FolioDocumentStoryNotFoundError = class extends FolioDocumentStoryNotFoundErrorBase {};
185
+ const FolioResolvedViewRefusedErrorBase = TaggedError("FolioResolvedViewRefusedError");
186
+ /** A resolved view whose revision resolution refused in some stories. */
187
+ var FolioResolvedViewRefusedError = class extends FolioResolvedViewRefusedErrorBase {};
105
188
  const FOLIO_RESOLVED_STORY_SERIALIZATION_MISMATCHES = Object.freeze({
106
189
  storyMissing: "story-missing",
107
190
  revisionMarkupRemains: "revision-markup-remains",
@@ -132,8 +215,7 @@ const mintedBlockOrdinals = (snapshot) => {
132
215
  * that moved still fails.
133
216
  */
134
217
  const resolvedStoryBlockProjection = (block, ordinal, minted) => {
135
- const persisted = { ...block };
136
- delete persisted.idStability;
218
+ const persisted = persistedBlock(block);
137
219
  return minted.has(ordinal) ? {
138
220
  ...persisted,
139
221
  id: `minted-${String(ordinal)}`
@@ -232,24 +314,18 @@ const resolveReviewedState = (state, view) => {
232
314
  if (view === "current-markup") return state;
233
315
  return resolveAllChangesInHeadlessState(state, view === "original" ? "reject" : "accept");
234
316
  };
235
- /**
236
- * Reject suggestions before resolving all ordinary revisions. A suggested
237
- * whole-paragraph or table insert is flagged on the node; its flag must stay
238
- * intact until that suggestion is explicitly accepted or rejected.
239
- */
240
- const rejectSuggestions = (state) => {
241
- let settled = state;
242
- rejectAllSuggestions()(state, (transaction) => {
243
- settled = state.apply(transaction);
244
- });
245
- return settled;
246
- };
247
317
  const createHeadlessPlugins = (styles, numbering) => [
248
318
  createDocumentNumberingPlugin(numbering),
249
319
  ...pluginsForHeadlessRevisionResolution(singletonManager.getPlugins()),
250
320
  createDocumentStylesPlugin(styles)
251
321
  ];
252
- const createStateSnapshot = (state) => createFolioAIEditSnapshotWithStyleResolver(state.doc, getDocumentStyleResolver(state), getDocumentNumbering(state));
322
+ /** A state's snapshot, of `doc` when it names the state's document otherwise spelled. */
323
+ const createStateSnapshot = (state, positionalParaIds, doc = state.doc) => createReviewerSnapshot({
324
+ doc,
325
+ styleResolver: getDocumentStyleResolver(state),
326
+ numbering: getDocumentNumbering(state),
327
+ positionalParaIds
328
+ });
253
329
  const formatStorySnapshotForLLM = (snapshot, annotated) => {
254
330
  const blocks = snapshot.blocks.filter(isFolioAIContentBlock);
255
331
  if (!annotated) return blocks.map(formatBlockForLLM).join("\n");
@@ -303,20 +379,197 @@ const paragraphPlainText = (paragraph) => {
303
379
  return parts.join("");
304
380
  };
305
381
  /**
306
- * Headless `.docx` reviewer. Parse a buffer, read blocks, apply
307
- * `FolioAIEditOperation`s against the document model, and write the reviewed
308
- * `.docx` back out — no editor instance, no DOM.
309
- *
310
- * @example
311
- * ```ts
312
- * const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { author: "AI" });
313
- * const { blocks } = reviewer.snapshot();
314
- * reviewer.applyOperations([
315
- * { id: "1", type: "replaceInBlock", blockId: blocks[0].id, find: "$50k", replace: "$500k" },
316
- * ], { undefinedReferences: "refuse" });
317
- * const reviewed = await reviewer.toBuffer();
318
- * ```
382
+ * Source-specific probes supply facts; a held proposal stays whole across all
383
+ * stories, and a change whose resolution would carry a held change away (its
384
+ * removed content or block holds it) is held with it. A change that only runs
385
+ * a held change's paragraph into the next is held with it when the held change
386
+ * belongs to a proposal, which is restaged on the paragraphs it was made on;
387
+ * an ordinary held change keeps its text and record wherever its paragraph
388
+ * goes.
319
389
  */
390
+ const classifyReviewLocks = ({ stories, grouping }) => {
391
+ switch (grouping) {
392
+ case "whole-proposal":
393
+ case "individual-change": break;
394
+ default: return panic("Unknown review lock grouping", { grouping });
395
+ }
396
+ const heldSuggestions = /* @__PURE__ */ new Map();
397
+ const held = stories.map(() => /* @__PURE__ */ new Map());
398
+ const heldIds = stories.map(() => /* @__PURE__ */ new Map());
399
+ const heldProposalIds = stories.map(() => /* @__PURE__ */ new Set());
400
+ const reasonFor = (change, storyIndex) => {
401
+ if (change.violation !== void 0) return {
402
+ violation: change.violation,
403
+ message: lockedControlMessage(change.violation)
404
+ };
405
+ const proposal = change.suggestionId === null ? void 0 : heldSuggestions.get(change.suggestionId);
406
+ if (proposal !== void 0) return {
407
+ violation: proposal,
408
+ message: `Another change in this proposal is held: ${lockedControlMessage(proposal)}`
409
+ };
410
+ for (const id of change.carries) {
411
+ const carried = heldIds[storyIndex]?.get(id);
412
+ if (carried !== void 0) return {
413
+ violation: carried,
414
+ message: `Resolving this change would take a held change with it: ${lockedControlMessage(carried)}`
415
+ };
416
+ }
417
+ for (const id of change.moves) {
418
+ if (!heldProposalIds[storyIndex]?.has(id)) continue;
419
+ const moved = heldIds[storyIndex]?.get(id);
420
+ if (moved !== void 0) return {
421
+ violation: moved,
422
+ message: `Resolving this change would run a held proposal's paragraph into the next: ${lockedControlMessage(moved)}`
423
+ };
424
+ }
425
+ };
426
+ for (let grew = true; grew;) {
427
+ grew = false;
428
+ for (const [storyIndex, { changes }] of stories.entries()) {
429
+ const storyHeld = held[storyIndex] ?? panic("Every story has its held changes");
430
+ for (const change of changes) {
431
+ if (storyHeld.has(change)) continue;
432
+ const reason = reasonFor(change, storyIndex);
433
+ if (reason === void 0) continue;
434
+ storyHeld.set(change, reason);
435
+ heldIds[storyIndex]?.set(change.id, reason.violation);
436
+ if (change.suggestionId !== null) heldProposalIds[storyIndex]?.add(change.id);
437
+ if (grouping === "whole-proposal" && change.suggestionId !== null && !heldSuggestions.has(change.suggestionId)) heldSuggestions.set(change.suggestionId, reason.violation);
438
+ grew = true;
439
+ }
440
+ }
441
+ }
442
+ return {
443
+ heldSuggestionIds: new Set(heldSuggestions.keys()),
444
+ stories: stories.map(({ source, changes }, storyIndex) => ({
445
+ source,
446
+ changes: changes.map((change) => {
447
+ const reason = held[storyIndex]?.get(change);
448
+ if (reason === void 0) return {
449
+ type: "free",
450
+ change
451
+ };
452
+ return {
453
+ type: "held",
454
+ change,
455
+ ...reason
456
+ };
457
+ })
458
+ }))
459
+ };
460
+ };
461
+ const PARAGRAPH_MARK_REMOVED_BY = {
462
+ accept: "paragraphMarkDeleted",
463
+ reject: "paragraphMarkInserted"
464
+ };
465
+ const RECORD_REMOVED_BY = {
466
+ accept: "deletion",
467
+ reject: "insertion"
468
+ };
469
+ const ROW_REMOVED_BY = {
470
+ accept: "trDel",
471
+ reject: "trIns"
472
+ };
473
+ const CELL_REMOVED_BY = {
474
+ accept: "del",
475
+ reject: "ins"
476
+ };
477
+ const numericRevisionId = (value) => typeof value === "object" && value !== null && "revisionId" in value && typeof value.revisionId === "number" ? value.revisionId : void 0;
478
+ /**
479
+ * The revision ids each change's resolution takes with it: every record inside
480
+ * content it removes (the text it inserted, when rejecting; deleted, when
481
+ * accepting) or inside a row or cell whose own carrier it removes. Removing a
482
+ * paragraph's mark removes the paragraph's own records and runs its content,
483
+ * with the records in it, into the next paragraph.
484
+ */
485
+ const revisionIdsCarriedByResolution = (doc, mode) => {
486
+ const removed = /* @__PURE__ */ new Map();
487
+ const moved = /* @__PURE__ */ new Map();
488
+ const add = (into, remover, ids) => {
489
+ const set = into.get(remover) ?? /* @__PURE__ */ new Set();
490
+ for (const id of ids) if (id !== remover) set.add(id);
491
+ into.set(remover, set);
492
+ };
493
+ const visit = (node, pos) => {
494
+ const ids = /* @__PURE__ */ new Set();
495
+ const removers = /* @__PURE__ */ new Set();
496
+ const markRemovers = /* @__PURE__ */ new Set();
497
+ for (const mark of node.marks) {
498
+ const id = numericRevisionId(mark.attrs);
499
+ if (id !== void 0) {
500
+ ids.add(id);
501
+ if (mark.type.name === RECORD_REMOVED_BY[mode]) removers.add(id);
502
+ }
503
+ const ancestors = mark.attrs["_docxRevisionAncestors"];
504
+ if (!Array.isArray(ancestors)) continue;
505
+ for (const ancestor of ancestors) {
506
+ const ancestorId = numericRevisionId(ancestor);
507
+ if (ancestorId === void 0) continue;
508
+ ids.add(ancestorId);
509
+ if (typeof ancestor === "object" && ancestor !== null && "type" in ancestor && ancestor.type === RECORD_REMOVED_BY[mode]) removers.add(ancestorId);
510
+ }
511
+ }
512
+ for (const carrier of getFolioNodeRevisionCarriers(node, pos)) {
513
+ ids.add(carrier.id);
514
+ if (carrier.type === PARAGRAPH_MARK_REMOVED_BY[mode]) markRemovers.add(carrier.id);
515
+ }
516
+ if (node.type.name === "tableRow") for (const attr of ["trIns", "trDel"]) {
517
+ const id = numericRevisionId(node.attrs[attr]);
518
+ if (id === void 0) continue;
519
+ ids.add(id);
520
+ if (attr === ROW_REMOVED_BY[mode]) removers.add(id);
521
+ }
522
+ const cellMarker = node.attrs["cellMarker"];
523
+ if (typeof cellMarker === "object" && cellMarker !== null && "info" in cellMarker && "kind" in cellMarker) {
524
+ const id = numericRevisionId(cellMarker.info);
525
+ if (id !== void 0) {
526
+ ids.add(id);
527
+ if (cellMarker.kind === CELL_REMOVED_BY[mode]) removers.add(id);
528
+ }
529
+ }
530
+ const own = new Set(ids);
531
+ const content = /* @__PURE__ */ new Set();
532
+ node.forEach((child, offset) => {
533
+ for (const id of visit(child, pos + 1 + offset)) {
534
+ ids.add(id);
535
+ content.add(id);
536
+ }
537
+ });
538
+ for (const remover of removers) add(removed, remover, ids);
539
+ for (const remover of markRemovers) {
540
+ add(removed, remover, own);
541
+ add(moved, remover, content);
542
+ }
543
+ return ids;
544
+ };
545
+ doc.forEach((child, offset) => {
546
+ visit(child, offset);
547
+ });
548
+ return {
549
+ removed,
550
+ moved
551
+ };
552
+ };
553
+ /**
554
+ * What a change's group takes along: its other members and what each removes
555
+ * (`carries`), and what each runs into the next paragraph (`moves`).
556
+ */
557
+ const carriedByGroup = (id, groupIds, { removed, moved }) => {
558
+ const carries = /* @__PURE__ */ new Set();
559
+ const moves = /* @__PURE__ */ new Set();
560
+ for (const member of [id, ...groupIds]) {
561
+ carries.add(member);
562
+ for (const inner of removed.get(member) ?? []) carries.add(inner);
563
+ for (const inner of moved.get(member) ?? []) moves.add(inner);
564
+ }
565
+ carries.delete(id);
566
+ for (const inner of carries) moves.delete(inner);
567
+ moves.delete(id);
568
+ return {
569
+ carries,
570
+ moves
571
+ };
572
+ };
320
573
  /**
321
574
  * The changes of a story, by revision id, that a content control's lock keeps
322
575
  * from being resolved in `mode`: every physical revision of one change is
@@ -333,10 +586,52 @@ const lockHeldChanges = (state, mode) => {
333
586
  }
334
587
  return held;
335
588
  };
589
+ /**
590
+ * One story's reading of the numbering: the lists the package was opened
591
+ * with, and those started since that `doc`'s paragraphs name. A list another
592
+ * story started is defined in that story's reading, not in this one.
593
+ */
594
+ const storyOwnNumbering = ({ current, loaded, doc }) => {
595
+ if (current === void 0) return void 0;
596
+ const kept = new Set((loaded?.nums ?? []).map(({ numId }) => numId));
597
+ doc.descendants((node) => {
598
+ for (const numId of paragraphListReferences(node)) kept.add(numId);
599
+ return !node.isTextblock;
600
+ });
601
+ return {
602
+ ...current,
603
+ nums: current.nums.filter(({ numId }) => kept.has(numId))
604
+ };
605
+ };
606
+ /**
607
+ * Headless `.docx` reviewer. Parse a buffer, read blocks, apply
608
+ * `FolioAIEditOperation`s against the document model, and write the reviewed
609
+ * `.docx` back out — no editor instance, no DOM.
610
+ *
611
+ * @example
612
+ * ```ts
613
+ * const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { author: "AI" });
614
+ * const { blocks } = reviewer.snapshot();
615
+ * reviewer.applyOperations([
616
+ * { id: "1", type: "replaceInBlock", blockId: blocks[0].id, find: "$50k", replace: "$500k" },
617
+ * ], { undefinedReferences: "refuse" });
618
+ * const reviewed = await reviewer.toBuffer();
619
+ * ```
620
+ */
336
621
  var FolioDocxReviewer = class FolioDocxReviewer {
622
+ /**
623
+ * A state's snapshot. On the canonical session a paragraph with no id (the
624
+ * filler of a content control its source leaves empty) is named by the
625
+ * positional id the legacy engine mints for it, so both engines name it
626
+ * alike; a legacy state already holds every id.
627
+ */
628
+ snapshotOf(state) {
629
+ return this.engine.type === "canonical" ? createStateSnapshot(state, this.positionalParaIds, ensureParaIdsInDoc(state.doc)) : createStateSnapshot(state, this.positionalParaIds);
630
+ }
337
631
  /** Default author for tracked changes and comments. */
338
632
  author;
339
- baseDocument;
633
+ /** The legacy reviewer's parsed model; a canonical one reads its session's. */
634
+ loadedDocument;
340
635
  finalSectionPropertiesOverride;
341
636
  originalBuffer;
342
637
  state;
@@ -351,8 +646,15 @@ var FolioDocxReviewer = class FolioDocxReviewer {
351
646
  importedFooters = /* @__PURE__ */ new Map();
352
647
  resolvedStoryExpectations = /* @__PURE__ */ new Map();
353
648
  createdComments = [];
649
+ deletedCommentIds = /* @__PURE__ */ new Set();
354
650
  /** Comments the body anchored when it was loaded, read as the editor projects it. */
355
651
  loadedMainCommentIds;
652
+ /**
653
+ * Paragraph ids the canonical session's input minted for paragraphs the
654
+ * package named none for: a snapshot reads them as positional, so nothing
655
+ * pairs two documents' paragraphs by them.
656
+ */
657
+ positionalParaIds;
356
658
  documentOperationUndoEntries = [];
357
659
  pendingSuggestions = new FolioPendingSuggestionRegistry();
358
660
  /**
@@ -364,13 +666,30 @@ var FolioDocxReviewer = class FolioDocxReviewer {
364
666
  * types its inputs `readonly Comment[]`).
365
667
  */
366
668
  resolvedOverrides = /* @__PURE__ */ new Map();
669
+ /** The last room revision {@link applyRoomJournal} applied. */
670
+ roomRevision = 0;
671
+ /** The resolved copies {@link resolvedSessionReader} last read, by view. */
672
+ resolvedSessionReaders = /* @__PURE__ */ new Map();
673
+ engine;
674
+ /** This document's comment ids: loaded, created, and never reissued. */
675
+ commentIds;
367
676
  constructor(args) {
368
- this.baseDocument = args.baseDocument;
677
+ this.loadedDocument = args.baseDocument;
678
+ this.positionalParaIds = args.positionalParaIds ?? /* @__PURE__ */ new Set();
369
679
  this.originalBuffer = args.originalBuffer;
370
680
  this.state = args.state;
371
681
  this.author = args.author;
372
- seedCommentAllocator(createCommentIdAllocator(), args.baseDocument.package.document.comments, { state: args.state });
373
- this.loadedMainCommentIds = anchoredCommentIdsInProseDoc(args.state.doc);
682
+ this.engine = args.engine.type === "legacy" ? args.engine : this.canonicalEngine(args.engine.session);
683
+ this.commentIds = args.commentIds?.clone() ?? createCommentIdAllocator();
684
+ seedCommentAllocator(this.commentIds, args.baseDocument.package.document.comments, { state: args.state });
685
+ this.loadedMainCommentIds = new Set(args.loadedMainCommentIds ?? anchoredCommentIdsInProseDoc(args.state.doc));
686
+ this.registerComparisonAccess();
687
+ }
688
+ registerComparisonAccess() {
689
+ if (this.engine.type === "canonical") {
690
+ comparisonAccessByReviewer.set(this, this.canonicalComparisonAccess());
691
+ return;
692
+ }
374
693
  comparisonAccessByReviewer.set(this, Object.freeze({
375
694
  stageTerminalTableReviewCarrier: (target) => this.stageTerminalTableReviewCarrier(target),
376
695
  stageTargetStyles: (options) => this.stageTargetStyles(options),
@@ -382,7 +701,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
382
701
  revision
383
702
  }),
384
703
  stageMappedSectionBoundaries: (options) => this.stageMappedSectionBoundaries(options),
385
- matchInlineAtoms: ({ story, ...options }) => {
704
+ matchInlineAtoms: ({ story, targetReviewer: _targetReviewer, targetStory: _targetStory, ...options }) => {
386
705
  const state = this.getEditableStoryState(story);
387
706
  if (!state) return panic("A compared story lost its editable state", { story });
388
707
  const result = matchInlineAtoms({
@@ -405,7 +724,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
405
724
  default: return panic("Unhandled inline atom result", { result });
406
725
  }
407
726
  },
408
- matchInlineProvenance: ({ story, ...options }) => {
727
+ matchInlineProvenance: ({ story, targetReviewer: _targetReviewer, targetStory: _targetStory, ...options }) => {
409
728
  const state = this.getEditableStoryState(story);
410
729
  if (!state) return panic("A compared story lost its editable state", { story });
411
730
  const result = matchInlineProvenance({
@@ -504,18 +823,25 @@ var FolioDocxReviewer = class FolioDocxReviewer {
504
823
  reservedStyleIds: [...reservedStyleIds],
505
824
  materializeDefaultParagraphStyle
506
825
  });
507
- if (result.status === "imported") {
508
- this.importedStyles = result.styles;
509
- this.state = withDocumentStyles(this.state, result.styles);
510
- for (const entry of this.secondaryStoryStates.values()) {
511
- const wasUntouched = entry.state === entry.initialState;
512
- const refreshed = withDocumentStyles(entry.state, result.styles);
513
- entry.state = refreshed;
514
- if (wasUntouched) entry.initialState = refreshed;
515
- }
826
+ if (result.status === "imported" && this.engine.type === "canonical") {
827
+ this.stagePackageResourcesOnSession({ styles: result.styles });
828
+ return result;
516
829
  }
830
+ if (result.status === "imported") this.installImportedStyles(result.styles);
517
831
  return result;
518
832
  }
833
+ installImportedStyles(styles, restoredStory) {
834
+ this.importedStyles = styles;
835
+ const definitions = styles ?? this.loadedDocument.package.styles;
836
+ if (restoredStory?.type !== "main") this.state = withDocumentStyles(this.state, definitions);
837
+ for (const entry of this.secondaryStoryStates.values()) {
838
+ if (restoredStory !== void 0 && editableStoryKey(entry.handle) === editableStoryKey(restoredStory)) continue;
839
+ const wasUntouched = entry.state === entry.initialState;
840
+ const refreshed = withDocumentStyles(entry.state, definitions);
841
+ entry.state = refreshed;
842
+ if (wasUntouched) entry.initialState = refreshed;
843
+ }
844
+ }
519
845
  /**
520
846
  * A raw final table has no paragraph mark after it for Word to merge into
521
847
  * when the target ends in a paragraph. Folio-exact comparison adds this
@@ -583,6 +909,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
583
909
  abstractNums: [...abstracts.values()],
584
910
  nums: [...nums.values()]
585
911
  };
912
+ if (this.engine.type === "canonical") {
913
+ this.stagePackageResourcesOnSession({ numbering });
914
+ return "staged";
915
+ }
586
916
  this.baseDocument.package.numbering = numbering;
587
917
  this.state = withDocumentNumbering(this.state, numbering);
588
918
  for (const entry of this.secondaryStoryStates.values()) entry.state = withDocumentNumbering(entry.state, numbering);
@@ -616,13 +946,34 @@ var FolioDocxReviewer = class FolioDocxReviewer {
616
946
  }
617
947
  return remapped;
618
948
  }
949
+ /**
950
+ * A canonical room's revision 0, which its authority is seeded with: the
951
+ * document an editor's canonical session reads from `buffer`, and the
952
+ * DOCX's snapshot identity.
953
+ */
954
+ static async openRoomBase(buffer) {
955
+ const base = await openCanonicalRoomBase(buffer);
956
+ if (base.isErr()) throw base.error;
957
+ return base.value;
958
+ }
619
959
  /** Parse a `.docx` buffer into a reviewer. */
620
960
  static async fromBuffer(buffer, options = {}) {
961
+ if (headlessReviewerUsesCanonicalSession(options.session)) return FolioDocxReviewer.fromCanonicalBuffer(buffer, options);
621
962
  const baseDocument = await parseDocx(buffer, {
622
963
  detectVariables: false,
623
964
  preloadFonts: false,
624
965
  password: options.password
625
966
  });
967
+ return FolioDocxReviewer.legacyOver(baseDocument, {
968
+ originalBuffer: baseDocument.originalBuffer ?? buffer,
969
+ author: options.author ?? "AI"
970
+ });
971
+ }
972
+ /**
973
+ * A legacy reviewer over a parsed or resolved document. A resolved one names
974
+ * the ids its source read as positional, which its model now spells as ids.
975
+ */
976
+ static legacyOver(baseDocument, { originalBuffer, author, positionalParaIds }) {
626
977
  const plugins = createHeadlessPlugins(baseDocument.package.styles, baseDocument.package.numbering);
627
978
  const state = ensureBaseDirectionInState(EditorState.create({
628
979
  schema,
@@ -631,17 +982,527 @@ var FolioDocxReviewer = class FolioDocxReviewer {
631
982
  }));
632
983
  return new FolioDocxReviewer({
633
984
  baseDocument,
634
- originalBuffer: baseDocument.originalBuffer ?? buffer,
985
+ originalBuffer,
635
986
  state,
636
- author: options.author ?? "AI"
987
+ author,
988
+ engine: { type: "legacy" },
989
+ ...positionalParaIds === void 0 ? {} : { positionalParaIds }
990
+ });
991
+ }
992
+ /**
993
+ * Load as a canonical editor does: the same input normalization (paragraph
994
+ * and content control ids minted in the package), then the session over the
995
+ * parsed document. A document the session cannot hold throws its refusal.
996
+ *
997
+ * The body is the session's projection. Headers, footers and notes are
998
+ * still read by the legacy story converters, from the session's document;
999
+ * they move to the session's own story projections with the secondary story
1000
+ * edits.
1001
+ */
1002
+ static async fromCanonicalBuffer(buffer, options) {
1003
+ const opened = await openCanonicalDocxSession(buffer, options.password);
1004
+ if (opened.isErr()) throw opened.error;
1005
+ const { document: parsed, mintedParaIds, session } = opened.value;
1006
+ return new FolioDocxReviewer({
1007
+ baseDocument: readModel(session.document),
1008
+ originalBuffer: parsed.originalBuffer ?? buffer,
1009
+ state: canonicalReviewerState(session),
1010
+ author: options.author ?? "AI",
1011
+ engine: {
1012
+ type: "canonical",
1013
+ session
1014
+ },
1015
+ positionalParaIds: /* @__PURE__ */ new Set([...mintedParaIds, ...session.sourceMintedParaIds])
1016
+ });
1017
+ }
1018
+ /**
1019
+ * The session and the editor's public operation compiler over it: the body
1020
+ * compiles against the reviewer's main state, another story against its
1021
+ * projection, and every commit publishes through {@link publishOnSession}.
1022
+ */
1023
+ canonicalEngine(session) {
1024
+ return {
1025
+ type: "canonical",
1026
+ session,
1027
+ operations: new CanonicalPublicOperations({
1028
+ session,
1029
+ undoLimit: 100,
1030
+ getState: (story) => {
1031
+ if (story === OP_STORIES.MAIN) return this.state;
1032
+ const projected = session.projectStory(story);
1033
+ return projected.isErr() ? null : canonicalStoryState(session, projected.value.doc, projected.value);
1034
+ },
1035
+ publish: (commit) => this.publishOnSession(commit)
1036
+ })
1037
+ };
1038
+ }
1039
+ /**
1040
+ * A live, independent copy of the reviewer: the same document, stories,
1041
+ * comments and pending suggestions, which a DOCX save would drop. Edits to
1042
+ * either leave the other as it is. The copy's undo history starts empty.
1043
+ */
1044
+ fork() {
1045
+ if (this.engine.type === "canonical") {
1046
+ const document = readModel(this.engine.session.document);
1047
+ const created = createCanonicalSession(document, document.package.styles);
1048
+ if (created.isErr()) throw created.error;
1049
+ const copy = new FolioDocxReviewer({
1050
+ baseDocument: document,
1051
+ originalBuffer: this.originalBuffer,
1052
+ state: canonicalReviewerState(created.value),
1053
+ author: this.author,
1054
+ engine: {
1055
+ type: "canonical",
1056
+ session: created.value
1057
+ },
1058
+ positionalParaIds: this.positionalParaIds
1059
+ });
1060
+ copy.pendingSuggestions = this.pendingSuggestions.clone();
1061
+ return copy;
1062
+ }
1063
+ return this.forkLegacy();
1064
+ }
1065
+ /** A constructor-backed copy over the legacy snapshot owner. */
1066
+ forkLegacy() {
1067
+ const snapshot = this.captureReviewerState();
1068
+ const copy = new FolioDocxReviewer({
1069
+ baseDocument: this.loadedDocument,
1070
+ originalBuffer: this.originalBuffer,
1071
+ state: snapshot.mainState.apply(snapshot.mainState.tr),
1072
+ author: this.author,
1073
+ engine: { type: "legacy" },
1074
+ loadedMainCommentIds: this.loadedMainCommentIds,
1075
+ commentIds: this.commentIds
1076
+ });
1077
+ copy.restoreReviewerState(snapshot);
1078
+ copy.pendingSuggestions = this.pendingSuggestions.clone();
1079
+ return copy;
1080
+ }
1081
+ canonicalComparisonAccess() {
1082
+ const refuse = (action) => {
1083
+ throw canonicalReviewerRefusal(action);
1084
+ };
1085
+ return Object.freeze({
1086
+ stageTerminalTableReviewCarrier: () => false,
1087
+ stageTargetStyles: (options) => this.stageTargetStyles(options),
1088
+ createComparisonHeaderFooter: (source, story) => this.createComparisonHeaderFooter(source, story),
1089
+ matchInlineAtoms: ({ story, targetReviewer, targetStory, targetSnapshot, noteReferenceLabels, ...options }) => {
1090
+ if (this.engine.type !== "canonical" || targetReviewer.engine.type !== "canonical") return refuse("match inline atoms against a legacy target");
1091
+ const result = matchInlineAtomsOnModel({
1092
+ ...options,
1093
+ document: this.engine.session.document,
1094
+ story: canonicalOpStory(story),
1095
+ target: {
1096
+ document: targetReviewer.engine.session.document,
1097
+ story: canonicalOpStory(targetStory),
1098
+ snapshot: targetSnapshot
1099
+ },
1100
+ noteReferenceLabels: noteReferenceLabels ?? refuse("match inline atoms without the comparison's note labels"),
1101
+ author: this.author
1102
+ });
1103
+ if (result.status !== "matched") return result;
1104
+ if (result.operations.length > 0) this.commitOpsOnSession(result.operations);
1105
+ return {
1106
+ status: "matched",
1107
+ nextRevisionId: result.nextRevisionId,
1108
+ changedTargetBlockIds: result.changedTargetBlockIds,
1109
+ rangeCount: result.rangeCount,
1110
+ documentChanged: result.operations.length > 0
1111
+ };
1112
+ },
1113
+ matchInlineProvenance: ({ story, targetReviewer: _targetReviewer, targetStory: _targetStory, revisionStamp, ...options }) => {
1114
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer matches on the session");
1115
+ const { session } = this.engine;
1116
+ const projected = session.projectStory(canonicalOpStory(story));
1117
+ if (projected.isErr()) throw projected.error;
1118
+ const projection = projected.value;
1119
+ const plan = planInlineProvenance({
1120
+ ...options,
1121
+ state: canonicalStoryState(session, projection.doc)
1122
+ });
1123
+ if (plan.status !== "planned") return plan;
1124
+ const written = inlineProvenanceOperations({
1125
+ document: session.document,
1126
+ changes: plan.changes,
1127
+ addressAt: (position) => {
1128
+ const address = projection.addressAt(position);
1129
+ return address.isOk() ? address.value : null;
1130
+ },
1131
+ revisionStamp,
1132
+ author: this.author
1133
+ });
1134
+ if (written.status !== "matched") return { status: "unalignable" };
1135
+ if (written.operations.length > 0) this.commitOpsOnSession(written.operations);
1136
+ return {
1137
+ status: "matched",
1138
+ nextRevisionId: written.nextRevisionId,
1139
+ changedTargetBlockIds: written.changedTargetBlockIds,
1140
+ rangeCount: plan.changes.length,
1141
+ documentChanged: written.operations.length > 0
1142
+ };
1143
+ },
1144
+ projectStories: (mode) => this.projectComparisonStoriesOnSession(mode),
1145
+ snapshotReviewedStory: (options) => this.snapshotReviewedStoryInternal(options),
1146
+ numberingDefinitions: () => this.baseDocument.package.numbering,
1147
+ styleDefinitions: () => this.baseDocument.package.styles,
1148
+ planTargetNumberingReferences: (target, references) => this.planTargetNumberingReferences(target, references),
1149
+ stageTargetNumbering: (target, references, remappedNumIds) => this.stageTargetNumbering(target, references, remappedNumIds),
1150
+ finalSectionProperties: () => this.currentFinalSectionProperties(),
1151
+ stageFinalSectionProperties: (options) => this.stageFinalSectionPropertiesOnSession(options),
1152
+ stageMappedSectionBoundaries: (options) => this.stageMappedSectionBoundariesOnSession(options)
1153
+ });
1154
+ }
1155
+ stageFinalSectionPropertiesOnSession(options) {
1156
+ const staged = stagedFinalSectionProperties({
1157
+ ...options,
1158
+ author: this.author
1159
+ });
1160
+ const op = staged && this.finalSectionOperation(() => staged);
1161
+ return op ? this.commitOpsOnSession([op]) : false;
1162
+ }
1163
+ /** Resolve on an independent fork, then publish only the complete semantic projection. */
1164
+ projectComparisonStoriesOnSession(mode) {
1165
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer projects comparison stories");
1166
+ const copy = this.fork();
1167
+ if (copy.engine.type !== "canonical") return panic("A canonical comparison fork must retain its engine");
1168
+ const handles = copy.listStoryHandlesInternal();
1169
+ const ids = /* @__PURE__ */ new Set();
1170
+ let present = false;
1171
+ if (mode === "with-revision-census") for (const change of copy.currentFinalSectionProperties()?.propertyChanges ?? []) {
1172
+ ids.add(change.info.id);
1173
+ present = true;
1174
+ }
1175
+ for (const handle of handles) {
1176
+ const state = copy.getEditableStoryState(handle);
1177
+ if (!state) continue;
1178
+ if (getSuggestions(state).length > 0) throw canonicalReviewerRefusal("project a story holding pending suggestions");
1179
+ if (mode === "with-revision-census") {
1180
+ const stats = getTrackedChangeStatsFromDoc(state.doc);
1181
+ for (const id of stats.ids) ids.add(id);
1182
+ present ||= stats.present;
1183
+ }
1184
+ }
1185
+ const operations = [];
1186
+ const session = copy.engine.session;
1187
+ const unsubscribe = session.onCommitted(({ ops }) => operations.push(...ops));
1188
+ let stories;
1189
+ try {
1190
+ stories = handles.map((handle) => {
1191
+ return {
1192
+ handle,
1193
+ snapshot: copy.resolveStoryOnSession(session, handle, "final") ? copy.snapshotStory(handle) : null
1194
+ };
1195
+ });
1196
+ } finally {
1197
+ unsubscribe();
1198
+ }
1199
+ if (operations.length > 0) this.commitOpsOnSession(operations);
1200
+ return {
1201
+ stories,
1202
+ revisions: {
1203
+ ids: [...ids],
1204
+ present
1205
+ }
1206
+ };
1207
+ }
1208
+ stagePackageResourcesOnSession(resources) {
1209
+ const before = this.baseDocument;
1210
+ this.commitOpsOnSession([packageResourcesOpOf({
1211
+ before,
1212
+ after: {
1213
+ ...before,
1214
+ package: {
1215
+ ...before.package,
1216
+ ...resources
1217
+ }
1218
+ }
1219
+ })]);
1220
+ }
1221
+ /**
1222
+ * Apply a canonical room's sequenced batches in revision order, as each
1223
+ * peer applies them. A reviewer opened on the room's base DOCX and given
1224
+ * its journal holds the room's document, which `toBuffer` saves.
1225
+ */
1226
+ applyRoomJournal(journal) {
1227
+ if (this.engine.type !== "canonical") throw new FolioRoomJournalError({
1228
+ message: "Only a canonical reviewer replays a room journal.",
1229
+ reason: "legacyEngine",
1230
+ expectedRevision: this.roomRevision + 1,
1231
+ receivedRevision: journal.at(0)?.revision
1232
+ });
1233
+ for (const batch of journal) {
1234
+ const expectedRevision = this.roomRevision + 1;
1235
+ if (batch.revision !== expectedRevision) throw new FolioRoomJournalError({
1236
+ message: `The room journal skips from revision ${this.roomRevision} to ${batch.revision}.`,
1237
+ reason: "revisionGap",
1238
+ expectedRevision,
1239
+ receivedRevision: batch.revision
1240
+ });
1241
+ this.commitOpsOnSession(batch.ops);
1242
+ this.roomRevision = batch.revision;
1243
+ }
1244
+ }
1245
+ commitOpsOnSession(ops) {
1246
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer commits session operations");
1247
+ const prepared = this.engine.session.prepareOperations(this.state, ops);
1248
+ if (prepared.isErr()) {
1249
+ if (prepared.error.reason === "noChange") return false;
1250
+ throw prepared.error;
1251
+ }
1252
+ return this.publishOnSession(prepared.value);
1253
+ }
1254
+ stageMappedSectionBoundariesOnSession(options) {
1255
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer stages on the session");
1256
+ const { session } = this.engine;
1257
+ const result = stageSectionBoundaryOperations({
1258
+ document: readModel(session.document),
1259
+ accepted: () => this.resolvedSessionCopy(session, "final").state.doc,
1260
+ target: options.target,
1261
+ originalRevisionIdSeed: options.originalRevisionIdSeed,
1262
+ revisionStamp: options.revision,
1263
+ author: this.author,
1264
+ maxRanges: options.maxRanges,
1265
+ mapTargetProperties: options.mapTargetProperties
1266
+ });
1267
+ if (result.status !== "matched") return result;
1268
+ return {
1269
+ status: "matched",
1270
+ rangeCount: result.operations.length,
1271
+ nextRevisionId: result.nextRevisionId,
1272
+ documentChanged: result.operations.length > 0 && this.commitOpsOnSession(result.operations)
1273
+ };
1274
+ }
1275
+ /** Restore the authoritative snapshot into an independent reviewer's collections. */
1276
+ restoreReviewerState(snapshot) {
1277
+ const { mainState, finalSectionPropertiesOverride, secondaryStoryStates, sectionReferenceRemovals, removedHeaderFooterStories, removedNoteStories, importedStyles, importedMedia, importedHeaders, importedFooters, createdComments, deletedCommentIds, resolvedOverrides, resolvedStoryExpectations, ...unhandled } = snapshot;
1278
+ this.state = mainState.apply(mainState.tr);
1279
+ this.finalSectionPropertiesOverride = finalSectionPropertiesOverride;
1280
+ for (const entry of secondaryStoryStates) this.secondaryStoryStates.set(secondaryStoryKey(entry.handle), {
1281
+ handle: entry.handle,
1282
+ state: entry.state.apply(entry.state.tr),
1283
+ initialState: entry.initialState.apply(entry.initialState.tr)
1284
+ });
1285
+ this.sectionReferenceRemovals.push(...sectionReferenceRemovals);
1286
+ for (const handle of removedHeaderFooterStories) this.removedHeaderFooterStories.set(headerFooterStoryKey(handle), handle);
1287
+ for (const handle of removedNoteStories) this.removedNoteStories.set(noteStoryKey(handle), handle);
1288
+ this.importedStyles = importedStyles;
1289
+ for (const [key, value] of importedMedia) this.importedMedia.set(key, value);
1290
+ for (const [key, value] of importedHeaders) this.importedHeaders.set(key, value);
1291
+ for (const [key, value] of importedFooters) this.importedFooters.set(key, value);
1292
+ this.createdComments.push(...createdComments);
1293
+ this.deletedCommentIds = deletedCommentIds;
1294
+ for (const [key, value] of resolvedOverrides) this.resolvedOverrides.set(key, value);
1295
+ for (const expectation of resolvedStoryExpectations) this.resolvedStoryExpectations.set(editableStoryKey(expectation.story), expectation);
1296
+ }
1297
+ /**
1298
+ * The model the readers read: the parsed package on the legacy engine, the
1299
+ * session's document, as it is after every commit, on the canonical one.
1300
+ */
1301
+ get baseDocument() {
1302
+ return this.engine.type === "canonical" ? readModel(this.engine.session.document) : this.loadedDocument;
1303
+ }
1304
+ /**
1305
+ * Publish a commit the session prepared on the reviewer's main state. The
1306
+ * state is then rebuilt from the session. A projection the state refuses
1307
+ * throws the session's refusal; nothing falls back to the legacy engine.
1308
+ */
1309
+ publishOnSession(commit) {
1310
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer publishes session commits");
1311
+ const { session } = this.engine;
1312
+ const published = publishCanonicalProjection({
1313
+ state: commit.selection.anchor.story === OP_STORIES.MAIN ? this.state : canonicalStoryState(session, commit.transaction.before),
1314
+ commit,
1315
+ session
1316
+ });
1317
+ if (published.isErr()) throw published.error;
1318
+ this.state = canonicalReviewerState(session);
1319
+ return true;
1320
+ }
1321
+ /**
1322
+ * Run a review resolution the session prepared. `false` when it changes
1323
+ * nothing or a content control's lock holds every change it names, as on
1324
+ * the legacy engine; any other refusal throws.
1325
+ */
1326
+ resolveOnSession(prepared) {
1327
+ if (prepared.isErr()) {
1328
+ const { error } = prepared;
1329
+ if (error.reason === "noChange") return {
1330
+ resolved: false,
1331
+ reason: "noChange"
1332
+ };
1333
+ if (error.ground.rule === CANONICAL_RULE.contentControlLock) return {
1334
+ resolved: false,
1335
+ reason: "lockHeld"
1336
+ };
1337
+ throw error;
1338
+ }
1339
+ const absorptions = prepared.value.touched.absorbed ?? [];
1340
+ const sourceSnapshotForStory = (story) => this.pendingSuggestionSource(story, /* @__PURE__ */ new Set());
1341
+ const absorption = absorptions.length === 0 ? null : this.pendingSuggestions.prepareAbsorption({
1342
+ survivors: new Map(absorptions.map(({ absorbed, survivor }) => [absorbed, survivor])),
1343
+ activeSuggestionIds: this.activeSuggestionIds(),
1344
+ sourceSnapshotForStory
1345
+ });
1346
+ this.publishOnSession(prepared.value);
1347
+ absorption?.({
1348
+ sourceSnapshotForStory,
1349
+ activeSuggestionIds: this.activeSuggestionIds()
1350
+ });
1351
+ this.pendingSuggestions.placeRemovedAnchors({
1352
+ activeSuggestionIds: this.activeSuggestionIds(),
1353
+ stateForStory: (story) => this.getEditableStoryState(story),
1354
+ savedSource: sourceSnapshotForStory
1355
+ });
1356
+ return {
1357
+ resolved: true,
1358
+ lockHeld: prepared.value.lockHeld ?? [],
1359
+ absorbedBlocks: absorptions.map(({ absorbed, survivor }) => ({
1360
+ blockId: absorbed,
1361
+ survivorBlockId: survivor
1362
+ }))
1363
+ };
1364
+ }
1365
+ /** A semantic operation for the final section, shared by staging and review resolution. */
1366
+ finalSectionOperation(resolve) {
1367
+ const current = this.currentFinalSectionProperties();
1368
+ const next = current && resolve(current);
1369
+ if (!current || !next) return null;
1370
+ return createCanonicalSectionPropertiesOperation(this.baseDocument, sectionResolutionPatch({
1371
+ current,
1372
+ next
1373
+ }));
1374
+ }
1375
+ /** Classify every story before a held fragment keeps its whole proposal pending. */
1376
+ storyResolutions(resolution) {
1377
+ const stories = this.listStoryHandlesInternal().toSorted((left, right) => Number(left.type === "main") - Number(right.type === "main")).flatMap((handle) => {
1378
+ const state = this.getEditableStoryState(handle);
1379
+ if (!state) return [];
1380
+ const story = canonicalOpStory(handle);
1381
+ const listed = listedRevisionGroups(state.doc);
1382
+ if (listed.length === 0) return [];
1383
+ const owners = suggestionOwnersByRevision(state);
1384
+ const changes = listed.flatMap(({ id, groupIds }) => {
1385
+ const suggestionId = owners.get(id) ?? null;
1386
+ return resolution === "accept" && suggestionId !== null ? [] : [{
1387
+ id,
1388
+ groupIds,
1389
+ suggestionId
1390
+ }];
1391
+ });
1392
+ const locks = canonicalRevisionLocks({
1393
+ document: this.baseDocument,
1394
+ story,
1395
+ groups: changes.map(({ groupIds }) => groupIds),
1396
+ decision: resolution
1397
+ });
1398
+ const held = new Map(locks.held.flatMap(({ ids, violation }) => ids.map((id) => [id, violation])));
1399
+ const carried = revisionIdsCarriedByResolution(state.doc, resolution);
1400
+ return [{
1401
+ source: { story },
1402
+ changes: changes.map(({ id, suggestionId, groupIds }) => {
1403
+ const { carries, moves } = carriedByGroup(id, groupIds, carried);
1404
+ return {
1405
+ id,
1406
+ suggestionId,
1407
+ groupIds,
1408
+ violation: held.get(id),
1409
+ carries,
1410
+ moves
1411
+ };
1412
+ })
1413
+ }];
637
1414
  });
1415
+ const classified = classifyReviewLocks({
1416
+ stories,
1417
+ grouping: "whole-proposal"
1418
+ });
1419
+ const ops = [];
1420
+ const skipped = [];
1421
+ const stagedIds = [];
1422
+ let count = 0;
1423
+ for (const { source: { story }, changes } of classified.stories) {
1424
+ const revisionIds = /* @__PURE__ */ new Set();
1425
+ for (const entry of changes) switch (entry.type) {
1426
+ case "held":
1427
+ skipped.push({
1428
+ id: entry.change.id,
1429
+ reason: CONTENT_CONTROL_LOCK,
1430
+ message: entry.message
1431
+ });
1432
+ break;
1433
+ case "free":
1434
+ count++;
1435
+ stagedIds.push(entry.change.id);
1436
+ for (const id of entry.change.groupIds) revisionIds.add(id);
1437
+ break;
1438
+ default: return panic("Unknown classified review lock", { entry });
1439
+ }
1440
+ if (revisionIds.size > 0) ops.push({
1441
+ type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
1442
+ story,
1443
+ revisionIds: [...revisionIds],
1444
+ decision: resolution
1445
+ });
1446
+ }
1447
+ return {
1448
+ ops,
1449
+ count,
1450
+ skipped,
1451
+ stagedIds,
1452
+ heldSuggestionIds: classified.heldSuggestionIds
1453
+ };
1454
+ }
1455
+ /** A story's snapshot as the compiler resolves operations against it. */
1456
+ snapshotOnSession(story) {
1457
+ if (story.type === "main") return this.snapshotOf(this.state);
1458
+ const snapshot = this.snapshotStory(story);
1459
+ if (!snapshot) throw new FolioDocumentStoryNotFoundError({
1460
+ message: `Document story ${JSON.stringify(story)} was not found.`,
1461
+ story
1462
+ });
1463
+ return snapshot;
1464
+ }
1465
+ /**
1466
+ * Apply a batch through the editor's canonical public operation compiler.
1467
+ * A suggested batch is recorded for {@link exportPendingSuggestions} as on
1468
+ * the legacy engine; the session holds its revisions and comments.
1469
+ */
1470
+ applyDocumentOperationsOnSession({ operations, story, batch, snapshot, author, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, restagesSuggestions }) {
1471
+ const sourceSnapshot = snapshot ?? this.snapshotOnSession(story);
1472
+ const operationAuthor = author ?? this.author;
1473
+ const activeBefore = this.activeSuggestionIds();
1474
+ const result = operations.apply({
1475
+ snapshot: sourceSnapshot,
1476
+ batch,
1477
+ story: story.type === "main" ? "main" : story,
1478
+ author: operationAuthor,
1479
+ ...revisionStamp !== void 0 && { revisionStamp },
1480
+ ...wordDiff !== void 0 && { wordDiff },
1481
+ ...tableTemplates !== void 0 && { tableTemplates },
1482
+ ...replacementBackground !== void 0 && { replacementBackground },
1483
+ undefinedReferences,
1484
+ ...restagesSuggestions === true ? { restagesSuggestions } : { pendingSuggestionIds: activeBefore }
1485
+ });
1486
+ if (batch.mode === "suggested") {
1487
+ const activeSuggestionIds = this.activeSuggestionIds();
1488
+ for (const id of activeBefore) activeSuggestionIds.add(id);
1489
+ this.pendingSuggestions.recordApplied({
1490
+ snapshot: sourceSnapshot,
1491
+ story,
1492
+ operations: batch.operations,
1493
+ applied: result.applied,
1494
+ author: operationAuthor,
1495
+ activeSuggestionIds
1496
+ });
1497
+ }
1498
+ return result;
638
1499
  }
639
1500
  /**
640
1501
  * Snapshot the current document into AI-facing blocks (id, kind, text) plus
641
1502
  * the anchor map the apply layer resolves operations against.
642
1503
  */
643
1504
  snapshot() {
644
- return createStateSnapshot(this.state);
1505
+ return this.snapshotOf(this.state);
645
1506
  }
646
1507
  /**
647
1508
  * The numbering ids every story but `story` defines: the package's and the
@@ -666,6 +1527,14 @@ var FolioDocxReviewer = class FolioDocxReviewer {
666
1527
  /** Every suggestion id the document's stories still carry. */
667
1528
  activeSuggestionIds() {
668
1529
  const active = new Set(getSuggestions(this.state).map(({ suggestionId }) => suggestionId));
1530
+ if (this.engine.type === "canonical") {
1531
+ for (const handle of this.listStoryHandlesInternal()) {
1532
+ if (handle.type === "main") continue;
1533
+ const state = this.getEditableStoryState(handle);
1534
+ for (const { suggestionId } of state ? getSuggestions(state) : []) active.add(suggestionId);
1535
+ }
1536
+ return active;
1537
+ }
669
1538
  for (const entry of this.secondaryStoryStates.values()) for (const { suggestionId } of getSuggestions(entry.state)) active.add(suggestionId);
670
1539
  return active;
671
1540
  }
@@ -674,23 +1543,46 @@ var FolioDocxReviewer = class FolioDocxReviewer {
674
1543
  const active = this.activeSuggestionIds();
675
1544
  return this.pendingSuggestions.exportPendingSuggestions({
676
1545
  activeSuggestionIds: active,
677
- snapshotForStory: (story, commentIds) => {
678
- const state = this.getEditableStoryState(story);
679
- return state ? createPendingSuggestionSourceSnapshot(state, commentIds) : null;
680
- }
1546
+ snapshotForStory: (story, commentIds) => this.pendingSuggestionSource(story, commentIds),
1547
+ stateForStory: (story) => this.engine.type === "canonical" ? this.getEditableStoryState(story) : null
681
1548
  });
682
1549
  }
1550
+ /**
1551
+ * A story as a save writes it, every pending suggestion rejected: what a
1552
+ * suggestion record's fingerprint describes. On the canonical engine it is
1553
+ * read from a session over the document the save writes, so a reviewer
1554
+ * reopened on the saved package reads the same story.
1555
+ */
1556
+ pendingSuggestionSource(story, commentIds) {
1557
+ if (this.engine.type === "canonical") {
1558
+ if (!this.getEditableStoryState(story)) return null;
1559
+ const document = this.toDocument();
1560
+ const created = createCanonicalSession(document, document.package.styles);
1561
+ if (created.isErr()) throw created.error;
1562
+ const saved = new FolioDocxReviewer({
1563
+ baseDocument: document,
1564
+ originalBuffer: this.originalBuffer,
1565
+ state: canonicalReviewerState(created.value),
1566
+ author: this.author,
1567
+ engine: {
1568
+ type: "canonical",
1569
+ session: created.value
1570
+ },
1571
+ positionalParaIds: this.positionalParaIds
1572
+ }).getEditableStoryState(story);
1573
+ return saved ? createPendingSuggestionSourceSnapshot(saved, /* @__PURE__ */ new Set()) : null;
1574
+ }
1575
+ const state = this.getEditableStoryState(story);
1576
+ return state ? createPendingSuggestionSourceSnapshot(state, commentIds) : null;
1577
+ }
683
1578
  /** Validate saved proposals against this document before restaging them. */
684
1579
  loadPendingSuggestions(records) {
685
1580
  return this.pendingSuggestions.loadPendingSuggestions({
686
1581
  records,
687
1582
  snapshotForStory: (story) => this.snapshotStory(story),
688
- sourceSnapshotForStory: (story, commentIds) => {
689
- const state = this.getEditableStoryState(story);
690
- return state ? createPendingSuggestionSourceSnapshot(state, commentIds) : null;
691
- },
1583
+ sourceSnapshotForStory: (story, commentIds) => this.pendingSuggestionSource(story, commentIds),
692
1584
  apply: (record, snapshot) => {
693
- const result = this.applyDocumentOperationsInternal({
1585
+ const restage = {
694
1586
  undefinedReferences: "refuse",
695
1587
  restagesSuggestions: true,
696
1588
  story: record.story,
@@ -700,7 +1592,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
700
1592
  mode: "suggested"
701
1593
  },
702
1594
  snapshot,
703
- author: record.author,
1595
+ author: record.author
1596
+ };
1597
+ const result = this.engine.type === "canonical" ? this.applyDocumentOperationsOnSession({
1598
+ ...restage,
1599
+ operations: this.engine.operations
1600
+ }) : this.applyDocumentOperationsInternal({
1601
+ ...restage,
704
1602
  createUndoEntry: false
705
1603
  });
706
1604
  return {
@@ -708,17 +1606,18 @@ var FolioDocxReviewer = class FolioDocxReviewer {
708
1606
  skipped: result.skipped
709
1607
  };
710
1608
  },
711
- activeSuggestionIds: () => {
712
- const active = new Set(getSuggestions(this.state).map(({ suggestionId }) => suggestionId));
713
- for (const entry of this.secondaryStoryStates.values()) for (const { suggestionId } of getSuggestions(entry.state)) active.add(suggestionId);
714
- return active;
715
- }
1609
+ activeSuggestionIds: () => this.activeSuggestionIds()
716
1610
  });
717
1611
  }
718
1612
  readNumberingDefinitions(story = MAIN_STORY) {
719
1613
  const doc = story.type === "main" ? this.state.doc : this.readSecondaryStoryDoc(story);
720
1614
  if (!doc) return null;
721
- return numberingLevelsOf(completeNumberingForDoc(this.baseDocument.package.numbering, doc)).toSorted((left, right) => left.numId - right.numId || left.level - right.level);
1615
+ const numbering = this.engine.type === "canonical" ? storyOwnNumbering({
1616
+ current: this.baseDocument.package.numbering,
1617
+ loaded: this.loadedDocument.package.numbering,
1618
+ doc
1619
+ }) : completeNumberingForDoc(this.baseDocument.package.numbering, doc);
1620
+ return numberingLevelsOf(numbering).toSorted((left, right) => left.numId - right.numId || left.level - right.level);
722
1621
  }
723
1622
  /** Return parsed package metadata without exposing the mutable document model. */
724
1623
  getDocumentProperties() {
@@ -733,7 +1632,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
733
1632
  /** Snapshot one editable story into stable, operation-ready blocks. */
734
1633
  snapshotStory(story) {
735
1634
  const state = this.getEditableStoryState(story);
736
- return state ? createStateSnapshot(state) : null;
1635
+ return state ? this.snapshotOf(state) : null;
737
1636
  }
738
1637
  snapshotReviewedStoryInternal(options = {}) {
739
1638
  const story = options.story ?? MAIN_STORY;
@@ -742,8 +1641,12 @@ var FolioDocxReviewer = class FolioDocxReviewer {
742
1641
  message: "Unsupported reviewed document view.",
743
1642
  receivedView: view
744
1643
  });
1644
+ if (view !== "current-markup") return this.resolvedReader(view).snapshotReviewedStoryInternal({
1645
+ story,
1646
+ view: "current-markup"
1647
+ });
745
1648
  const sourceState = this.getEditableStoryState(story);
746
- return sourceState ? createStateSnapshot(resolveReviewedState(sourceState, view)) : null;
1649
+ return sourceState ? this.snapshotOf(sourceState) : null;
747
1650
  }
748
1651
  projectComparisonStoriesInternal(mode) {
749
1652
  const handles = this.listStoryHandlesInternal();
@@ -793,8 +1696,12 @@ var FolioDocxReviewer = class FolioDocxReviewer {
793
1696
  message: "Unsupported reviewed document view.",
794
1697
  receivedView: view
795
1698
  });
1699
+ if (view !== "current-markup") return this.resolvedReader(view).storyTables({
1700
+ story,
1701
+ view: "current-markup"
1702
+ });
796
1703
  const sourceState = this.getEditableStoryState(story);
797
- return sourceState ? folioStoryTables(resolveReviewedState(sourceState, view).doc) : [];
1704
+ return sourceState ? folioStoryTables(sourceState.doc) : [];
798
1705
  }
799
1706
  /**
800
1707
  * Move the paired tables' own properties onto this story's tables, as
@@ -810,6 +1717,22 @@ var FolioDocxReviewer = class FolioDocxReviewer {
810
1717
  matchStoryTableGeometry({ story = MAIN_STORY, targetTables, pairings, revisionStamp }) {
811
1718
  const state = this.getEditableStoryState(story);
812
1719
  if (!state || pairings.length === 0) return revisionStamp.idSeed;
1720
+ if (this.engine.type === "canonical") {
1721
+ const matched = matchTableGeometryOperations({
1722
+ story: canonicalOpStory(story),
1723
+ baseTables: folioStoryTables(state.doc),
1724
+ targetTables,
1725
+ pairings,
1726
+ revision: {
1727
+ author: this.author,
1728
+ date: revisionStamp.date,
1729
+ idSeed: revisionStamp.idSeed
1730
+ }
1731
+ });
1732
+ if (matched.status === "unaddressable") throw canonicalReviewerRefusal("change the properties of a table cell without a paragraph id");
1733
+ if (matched.operations.length > 0) this.commitOpsOnSession(matched.operations);
1734
+ return matched.nextRevisionId;
1735
+ }
813
1736
  const transaction = state.tr;
814
1737
  const { nextRevisionId } = matchTableGeometry({
815
1738
  tr: transaction,
@@ -825,7 +1748,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
825
1748
  if (transaction.docChanged) this.setEditableStoryState(story, state.apply(transaction));
826
1749
  return nextRevisionId;
827
1750
  }
828
- /** Read one story through an immutable reviewed-view projection. */
1751
+ /**
1752
+ * Read one story through an immutable reviewed-view projection. A canonical
1753
+ * resolved view refuses when locks leave ordinary revisions pending.
1754
+ */
829
1755
  readReviewedStory(options = {}) {
830
1756
  const story = options.story ?? MAIN_STORY;
831
1757
  const view = options.view ?? "final";
@@ -842,8 +1768,14 @@ var FolioDocxReviewer = class FolioDocxReviewer {
842
1768
  changes: getTrackedChangesFromSnapshot(snapshot)
843
1769
  };
844
1770
  }
845
- /** Resolve one editable story to its original or final state. */
1771
+ /**
1772
+ * Resolve one editable story to its original or final state. A canonical
1773
+ * target story holding staged suggestions refuses; resolve those through
1774
+ * the suggestion methods first. A lock that prevents any target change
1775
+ * from resolving refuses before mutation.
1776
+ */
846
1777
  resolveReviewedStory({ story = MAIN_STORY, view }) {
1778
+ if (this.engine.type === "canonical") return this.resolveStoryOnSession(this.engine.session, story, view);
847
1779
  return this.resolveReviewedStorySnapshotInternal({
848
1780
  story,
849
1781
  view
@@ -858,7 +1790,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
858
1790
  if (!sourceState) return null;
859
1791
  const resolvedState = resolveReviewedState(sourceState, view);
860
1792
  this.setEditableStoryState(story, resolvedState);
861
- const snapshot = createStateSnapshot(resolvedState);
1793
+ const snapshot = this.snapshotOf(resolvedState);
862
1794
  const minted = mintedBlockOrdinals(snapshot);
863
1795
  this.resolvedStoryExpectations.set(editableStoryKey(story), {
864
1796
  story,
@@ -873,7 +1805,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
873
1805
  * (including any comments) is retained for {@link toBuffer}.
874
1806
  */
875
1807
  applyOperations(operations, options) {
876
- const { applied, skipped } = this.applyDocumentOperationsInternal({
1808
+ const internal = {
877
1809
  story: MAIN_STORY,
878
1810
  batch: {
879
1811
  version: 1,
@@ -883,7 +1815,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
883
1815
  ...options.snapshot !== void 0 && { snapshot: options.snapshot },
884
1816
  ...options.revisionStamp !== void 0 && { revisionStamp: options.revisionStamp },
885
1817
  ...options.wordDiff !== void 0 && { wordDiff: options.wordDiff },
886
- undefinedReferences: options.undefinedReferences,
1818
+ undefinedReferences: options.undefinedReferences
1819
+ };
1820
+ const { applied, skipped } = this.engine.type === "canonical" ? this.applyDocumentOperationsOnSession({
1821
+ ...internal,
1822
+ operations: this.engine.operations
1823
+ }) : this.applyDocumentOperationsInternal({
1824
+ ...internal,
887
1825
  createUndoEntry: false
888
1826
  });
889
1827
  return {
@@ -898,27 +1836,39 @@ var FolioDocxReviewer = class FolioDocxReviewer {
898
1836
  * edit semantics.
899
1837
  */
900
1838
  applyDocumentOperations(batch, options) {
901
- return this.applyDocumentOperationsInternal({
1839
+ const internal = {
902
1840
  story: MAIN_STORY,
903
- batch,
1841
+ batch: parseFolioDocumentOperationBatch(batch),
904
1842
  ...options.snapshot !== void 0 && { snapshot: options.snapshot },
905
1843
  ...options.revisionStamp !== void 0 && { revisionStamp: options.revisionStamp },
906
1844
  ...options.wordDiff !== void 0 && { wordDiff: options.wordDiff },
907
- undefinedReferences: options.undefinedReferences,
1845
+ undefinedReferences: options.undefinedReferences
1846
+ };
1847
+ return this.engine.type === "canonical" ? this.applyDocumentOperationsOnSession({
1848
+ ...internal,
1849
+ operations: this.engine.operations
1850
+ }) : this.applyDocumentOperationsInternal({
1851
+ ...internal,
908
1852
  createUndoEntry: true
909
1853
  });
910
1854
  }
911
1855
  /** Apply a versioned operation batch to one editable document story. */
912
1856
  applyDocumentOperationsToStory({ story, batch, snapshot, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences }) {
913
- return this.applyDocumentOperationsInternal({
1857
+ const internal = {
914
1858
  story,
915
- batch,
1859
+ batch: parseFolioDocumentOperationBatch(batch),
916
1860
  ...snapshot !== void 0 && { snapshot },
917
1861
  ...revisionStamp !== void 0 && { revisionStamp },
918
1862
  ...wordDiff !== void 0 && { wordDiff },
919
1863
  ...tableTemplates !== void 0 && { tableTemplates },
920
1864
  ...replacementBackground !== void 0 && { replacementBackground },
921
- undefinedReferences,
1865
+ undefinedReferences
1866
+ };
1867
+ return this.engine.type === "canonical" ? this.applyDocumentOperationsOnSession({
1868
+ ...internal,
1869
+ operations: this.engine.operations
1870
+ }) : this.applyDocumentOperationsInternal({
1871
+ ...internal,
922
1872
  createUndoEntry: true
923
1873
  });
924
1874
  }
@@ -928,12 +1878,17 @@ var FolioDocxReviewer = class FolioDocxReviewer {
928
1878
  return this.withNotesFollowingReferences(() => this.applyDocumentOperationsToStoryState(options));
929
1879
  }
930
1880
  applyDocumentOperationsToStoryState({ story, batch, author, snapshot, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, createUndoEntry, restagesSuggestions }) {
1881
+ const validatedBatch = parseFolioDocumentOperationBatch(batch);
931
1882
  const beforeState = this.requireEditableStoryState(story);
932
1883
  const operationAuthor = author ?? this.author;
933
- const sourceSnapshot = snapshot ?? createStateSnapshot(beforeState);
1884
+ const sourceSnapshot = snapshot ?? this.snapshotOf(beforeState);
934
1885
  const createdCommentsLengthBefore = this.createdComments.length;
1886
+ const beforeStyles = this.importedStyles;
1887
+ const definitions = beforeStyles ?? this.loadedDocument.package.styles;
1888
+ const candidateStyles = undefinedReferences === "keep" ? definitions : withOperationHeadingStyles(definitions, validatedBatch.operations);
1889
+ const candidateState = candidateStyles === definitions ? beforeState : withDocumentStyles(beforeState, candidateStyles);
935
1890
  const view = {
936
- state: beforeState,
1891
+ state: candidateState,
937
1892
  dispatch: (transaction) => {
938
1893
  view.state = view.state.apply(transaction);
939
1894
  }
@@ -941,7 +1896,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
941
1896
  const result = applyFolioDocumentOperationsInPackage({
942
1897
  view,
943
1898
  snapshot: sourceSnapshot,
944
- batch,
1899
+ batch: validatedBatch,
945
1900
  story: story.type === "main" ? "main" : story,
946
1901
  author: operationAuthor,
947
1902
  ...revisionStamp !== void 0 && { revisionStamp },
@@ -969,7 +1924,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
969
1924
  const appliedCommentIds = new Set(result.applied.flatMap(({ commentId }) => commentId === void 0 ? [] : [commentId]));
970
1925
  const createdByBatch = this.createdComments.splice(createdCommentsLengthBefore);
971
1926
  this.createdComments.push(...createdByBatch.filter((comment) => appliedCommentIds.has(comment.id)));
972
- this.setEditableStoryState(story, view.state);
1927
+ if (view.state !== candidateState) this.setEditableStoryState(story, view.state);
1928
+ if (candidateStyles !== definitions && view.state !== candidateState) {
1929
+ const appliedIds = new Set(result.applied.map(({ id }) => id));
1930
+ const committedStyles = withOperationHeadingStyles(definitions, validatedBatch.operations.filter(({ id }) => appliedIds.has(id)));
1931
+ if (committedStyles !== definitions) this.installImportedStyles(committedStyles);
1932
+ else this.setEditableStoryState(story, withDocumentStyles(view.state, definitions));
1933
+ }
973
1934
  if (batch.mode === "suggested") {
974
1935
  const activeSuggestionIds = new Set(getSuggestions(beforeState).map(({ suggestionId }) => suggestionId));
975
1936
  for (const { suggestionId } of getSuggestions(this.state)) activeSuggestionIds.add(suggestionId);
@@ -988,9 +1949,12 @@ var FolioDocxReviewer = class FolioDocxReviewer {
988
1949
  undoHandle: result.undoHandle,
989
1950
  story,
990
1951
  beforeState,
991
- afterState: view.state,
1952
+ afterState: this.requireEditableStoryState(story),
992
1953
  createdCommentsLengthBefore,
993
- createdCommentsLengthAfter: this.createdComments.length
1954
+ createdCommentsLengthAfter: this.createdComments.length,
1955
+ deletedCommentIds: this.deletedCommentIds,
1956
+ beforeStyles,
1957
+ afterStyles: this.importedStyles
994
1958
  });
995
1959
  const excess = this.documentOperationUndoEntries.length - 100;
996
1960
  if (excess > 0) this.documentOperationUndoEntries.splice(0, excess);
@@ -1003,6 +1967,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1003
1967
  * batches are kept; an older handle is `unknownHandle`.
1004
1968
  */
1005
1969
  undoDocumentOperations(undoHandle) {
1970
+ if (this.engine.type === "canonical") return this.engine.operations.undo(undoHandle);
1006
1971
  const entryIndex = this.documentOperationUndoEntries.findIndex((entry) => entry.undoHandle.type === undoHandle.type && entry.undoHandle.id === undoHandle.id);
1007
1972
  if (entryIndex === -1) return {
1008
1973
  status: "rejected",
@@ -1020,12 +1985,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1020
1985
  undoHandle,
1021
1986
  reason: "unknownHandle"
1022
1987
  };
1023
- if (this.requireEditableStoryState(entry.story) !== entry.afterState || this.createdComments.length !== entry.createdCommentsLengthAfter) return {
1988
+ if (this.requireEditableStoryState(entry.story) !== entry.afterState || this.createdComments.length !== entry.createdCommentsLengthAfter || this.deletedCommentIds !== entry.deletedCommentIds || this.importedStyles !== entry.afterStyles) return {
1024
1989
  status: "rejected",
1025
1990
  undoHandle,
1026
1991
  reason: "documentChanged"
1027
1992
  };
1028
1993
  this.withNotesFollowingReferences(() => this.setEditableStoryState(entry.story, entry.beforeState));
1994
+ if (entry.beforeStyles !== entry.afterStyles) this.installImportedStyles(entry.beforeStyles, entry.story);
1029
1995
  this.createdComments.length = entry.createdCommentsLengthBefore;
1030
1996
  this.documentOperationUndoEntries.pop();
1031
1997
  return {
@@ -1119,8 +2085,12 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1119
2085
  type: "endnote",
1120
2086
  noteId: endnote.id
1121
2087
  });
2088
+ const retired = this.engine.type === "canonical" ? this.engine.session.retiredHeaderFooters() : void 0;
1122
2089
  return handles.filter((handle) => {
1123
- if (handle.type === "header" || handle.type === "footer") return !this.removedHeaderFooterStories.has(headerFooterStoryKey(handle));
2090
+ if (handle.type === "header" || handle.type === "footer") {
2091
+ const key = headerFooterStoryKey(handle);
2092
+ return !this.removedHeaderFooterStories.has(key) && !retired?.has(key);
2093
+ }
1124
2094
  return true;
1125
2095
  });
1126
2096
  }
@@ -1170,7 +2140,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1170
2140
  if (!doc) continue;
1171
2141
  for (const id of coveredCommentIdsInProseDoc(doc)) covered.add(id);
1172
2142
  }
1173
- const definitions = this.withResolvedOverrides(this.keptCommentThreads([...this.baseDocument.package.document.comments ?? [], ...this.createdComments], this.state, this.secondaryStoryStates.values()).filter(({ id, parentId, anchorKind }) => anchorKind !== "range" || parentId !== void 0 || covered.has(id)));
2143
+ const definitions = this.withResolvedOverrides(this.keptCommentThreads(this.currentCommentDefinitions(), this.state, this.secondaryStoryStates.values()).filter(({ id, parentId, anchorKind }) => anchorKind !== "range" || parentId !== void 0 || covered.has(id)));
1174
2144
  if (definitions.length === 0) return [];
1175
2145
  const repliesByParent = /* @__PURE__ */ new Map();
1176
2146
  const topLevel = [];
@@ -1206,6 +2176,56 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1206
2176
  return threads.filter((thread) => (filter.author === void 0 || thread.author === filter.author) && (filter.done === void 0 || thread.done === filter.done));
1207
2177
  }
1208
2178
  /**
2179
+ * Delete comments by numeric id or exact author, with every dependent reply.
2180
+ * Returns the deleted ids in ascending order.
2181
+ */
2182
+ deleteComments(selector) {
2183
+ const comments = this.currentCommentDefinitions();
2184
+ const requested = selector.ids !== void 0 ? new Set(selector.ids) : new Set(comments.filter(({ author }) => author === selector.author).map(({ id }) => id));
2185
+ const removed = /* @__PURE__ */ new Set();
2186
+ const roots = /* @__PURE__ */ new Map();
2187
+ const knownIds = new Set(comments.map(({ id }) => id));
2188
+ for (const { id, parentId } of comments) {
2189
+ if (!requested.has(id) || removed.has(id)) continue;
2190
+ for (const descendant of commentThreadIds(comments, id)) {
2191
+ removed.add(descendant);
2192
+ roots.delete(descendant);
2193
+ }
2194
+ roots.set(id, parentId !== void 0 && knownIds.has(parentId) ? "reply" : "thread");
2195
+ }
2196
+ if (removed.size === 0) return { deleted: [] };
2197
+ if (this.engine.type === "canonical") {
2198
+ const prepared = this.engine.session.prepareOperations(this.state, [...roots].map(([id, scope]) => ({
2199
+ type: DOCUMENT_OP_TYPES.DELETE_COMMENT,
2200
+ id,
2201
+ scope
2202
+ })));
2203
+ if (prepared.isErr()) throw prepared.error;
2204
+ this.publishOnSession(prepared.value);
2205
+ } else this.deleteCommentAnchors(removed);
2206
+ return { deleted: [...removed].sort((left, right) => left - right) };
2207
+ }
2208
+ currentCommentDefinitions() {
2209
+ return [...this.baseDocument.package.document.comments ?? [], ...this.createdComments].filter(({ id }) => !this.deletedCommentIds.has(id));
2210
+ }
2211
+ deleteCommentAnchors(ids) {
2212
+ for (const story of this.listStoryHandlesInternal()) this.getEditableStoryState(story);
2213
+ const edits = [{
2214
+ handle: MAIN_STORY,
2215
+ state: this.state
2216
+ }, ...this.secondaryStoryStates.values()].flatMap(({ handle, state }) => {
2217
+ const transaction = state.tr;
2218
+ removeCommentAnchors(transaction, ids);
2219
+ return transaction.docChanged ? [{
2220
+ handle,
2221
+ state: state.apply(transaction)
2222
+ }] : [];
2223
+ });
2224
+ for (const { handle, state } of edits) this.setEditableStoryState(handle, state);
2225
+ this.deletedCommentIds = /* @__PURE__ */ new Set([...this.deletedCommentIds, ...ids]);
2226
+ for (const id of ids) this.resolvedOverrides.delete(id);
2227
+ }
2228
+ /**
1209
2229
  * Add a reply to a comment thread. Pass a {@link FolioReviewComment} from
1210
2230
  * {@link getComments} or its id; the reply threads under that comment's root
1211
2231
  * (Word threads are flat). On {@link toBuffer} the reply is written as a real
@@ -1216,12 +2236,18 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1216
2236
  */
1217
2237
  replyTo(target, input) {
1218
2238
  const parentId = typeof target === "number" ? target : target.id;
1219
- const existing = [...this.baseDocument.package.document.comments ?? [], ...this.createdComments];
1220
- const reply = createReply(existing, parentId, {
1221
- author: input.author ?? this.author,
1222
- text: input.text,
1223
- ...input.initials !== void 0 ? { initials: input.initials } : {},
1224
- ...input.date !== void 0 && { date: input.date }
2239
+ if (this.engine.type === "canonical") return this.replyOnSession(this.engine.session, parentId, input);
2240
+ const existing = this.currentCommentDefinitions();
2241
+ const reply = createReply({
2242
+ comments: existing,
2243
+ parentCommentId: parentId,
2244
+ input: {
2245
+ author: input.author ?? this.author,
2246
+ text: input.text,
2247
+ ...input.initials !== void 0 ? { initials: input.initials } : {},
2248
+ ...input.date !== void 0 && { date: input.date }
2249
+ },
2250
+ commentIds: this.commentIds
1225
2251
  });
1226
2252
  if (!reply) return null;
1227
2253
  this.createdComments.push(reply);
@@ -1275,11 +2301,70 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1275
2301
  */
1276
2302
  resolveComment(commentId, options = {}) {
1277
2303
  const resolved = options.resolved ?? true;
1278
- const target = [...this.baseDocument.package.document.comments ?? [], ...this.createdComments].find((comment) => String(comment.id) === commentId);
2304
+ if (this.engine.type === "canonical") return this.resolveCommentOnSession(this.engine.session, commentId, resolved);
2305
+ const target = this.currentCommentDefinitions().find((comment) => String(comment.id) === commentId);
1279
2306
  if (!target) return false;
1280
2307
  this.resolvedOverrides.set(target.id, resolved);
1281
2308
  return true;
1282
2309
  }
2310
+ /** Run a semantic comment command as one session commit, as the editor does. */
2311
+ commitCommentOnSession(session, command) {
2312
+ const compiled = compileCanonicalComments({
2313
+ document: readModel(session.document),
2314
+ command,
2315
+ idLease: session.idLease
2316
+ });
2317
+ if (compiled.isErr()) throw compiled.error;
2318
+ if (compiled.value.ops.length === 0) return;
2319
+ const prepared = session.prepareOperations(this.state, compiled.value.ops);
2320
+ if (prepared.isErr()) throw prepared.error;
2321
+ this.publishOnSession(prepared.value);
2322
+ }
2323
+ /**
2324
+ * A reply on the session: a comment anchored as a reply to `parentId`,
2325
+ * which the session threads under the parent's root and anchors on its
2326
+ * range, as the editor's reply does.
2327
+ */
2328
+ replyOnSession(session, parentId, input) {
2329
+ const document = readModel(session.document);
2330
+ if (!(document.package.document.comments ?? []).some(({ id }) => id === parentId)) return null;
2331
+ const id = freshCommentId(document, session.idLease);
2332
+ if (id.isErr()) throw canonicalReviewerRefusal("mint a comment id");
2333
+ const author = input.author ?? this.author;
2334
+ const date = input.date ?? (/* @__PURE__ */ new Date()).toISOString();
2335
+ this.commitCommentOnSession(session, {
2336
+ type: "create",
2337
+ anchor: {
2338
+ kind: "reply",
2339
+ parentId
2340
+ },
2341
+ comment: {
2342
+ id: id.value,
2343
+ author,
2344
+ done: false,
2345
+ date,
2346
+ ...input.initials !== void 0 && { initials: input.initials },
2347
+ content: canonicalCommentBody(document, input.text, session.idLease)
2348
+ }
2349
+ });
2350
+ return {
2351
+ id: id.value,
2352
+ author,
2353
+ date,
2354
+ text: input.text
2355
+ };
2356
+ }
2357
+ /** Resolve or reopen one comment through the session's comment record. */
2358
+ resolveCommentOnSession(session, commentId, resolved) {
2359
+ const target = (readModel(session.document).package.document.comments ?? []).find(({ id }) => String(id) === commentId);
2360
+ if (!target) return false;
2361
+ this.commitCommentOnSession(session, {
2362
+ type: "resolve",
2363
+ id: target.id,
2364
+ status: resolved ? "resolved" : "open"
2365
+ });
2366
+ return true;
2367
+ }
1283
2368
  /**
1284
2369
  * Where each header and footer part is shown, as the live section
1285
2370
  * references state it: its role (`w:type`) and the 1-based section, in
@@ -1316,26 +2401,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1316
2401
  currentFinalSectionProperties() {
1317
2402
  return this.finalSectionPropertiesOverride ?? this.baseDocument.package.document.finalSectionProperties;
1318
2403
  }
1319
- stageFinalSectionProperties({ target, previous, revision }) {
1320
- if (canonicalJson(target) === canonicalJson(previous)) return false;
1321
- const previousReferences = sectionReferenceHistory({
1322
- previous,
1323
- target
1324
- });
1325
- this.finalSectionPropertiesOverride = {
1326
- ...target,
1327
- propertyChanges: [{
1328
- type: "sectionPropertyChange",
1329
- info: {
1330
- id: revision.idSeed,
1331
- author: this.author,
1332
- date: revision.date
1333
- },
1334
- previousProperties: previous,
1335
- ...previousReferences !== void 0 && { previousReferences },
1336
- currentProperties: target
1337
- }]
1338
- };
2404
+ stageFinalSectionProperties(options) {
2405
+ const staged = stagedFinalSectionProperties({
2406
+ ...options,
2407
+ author: this.author
2408
+ });
2409
+ if (!staged) return false;
2410
+ this.finalSectionPropertiesOverride = staged;
1339
2411
  return true;
1340
2412
  }
1341
2413
  stageMappedSectionBoundaries({ target, originalRevisionIdSeed, maxRanges, revision, mapTargetProperties }) {
@@ -1360,37 +2432,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1360
2432
  }
1361
2433
  resolveFinalSectionProperties(mode, id) {
1362
2434
  const current = this.currentFinalSectionProperties();
1363
- const changes = current?.propertyChanges;
1364
- const targetIndex = changes?.findIndex(({ info }) => info.id === id);
1365
- if (!current || !changes || changes.length === 0 || targetIndex === void 0 || targetIndex < 0) return 0;
1366
- const { propertyChanges: _propertyChanges, ...liveProperties } = current;
1367
- const previousStates = changes.map((change) => sectionRejectProperties({
1368
- live: current,
1369
- previousProperties: change.previousProperties,
1370
- previousReferences: change.previousReferences
1371
- }));
1372
- let resolvedProperties = previousStates[0] ?? liveProperties;
1373
- const remaining = [];
1374
- for (const [index, change] of changes.entries()) {
1375
- const nextProperties = previousStates[index + 1] ?? liveProperties;
1376
- if (index === targetIndex) {
1377
- if (mode === "accept") resolvedProperties = nextProperties;
1378
- continue;
1379
- }
1380
- remaining.push({
1381
- ...change,
1382
- previousProperties: resolvedProperties,
1383
- ...change.previousReferences !== void 0 && { previousReferences: {
1384
- ...resolvedProperties.headerReferences !== void 0 && { headerReferences: resolvedProperties.headerReferences },
1385
- ...resolvedProperties.footerReferences !== void 0 && { footerReferences: resolvedProperties.footerReferences }
1386
- } }
1387
- });
1388
- resolvedProperties = nextProperties;
1389
- }
1390
- this.finalSectionPropertiesOverride = {
1391
- ...resolvedProperties,
1392
- ...remaining.length > 0 && { propertyChanges: remaining }
1393
- };
2435
+ const resolved = current && resolveSectionChange({
2436
+ current,
2437
+ decision: mode,
2438
+ id
2439
+ });
2440
+ if (!resolved) return 0;
2441
+ this.finalSectionPropertiesOverride = resolved;
1394
2442
  return 1;
1395
2443
  }
1396
2444
  /**
@@ -1404,6 +2452,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1404
2452
  * removal. A held change stays pending as it is.
1405
2453
  */
1406
2454
  acceptChange(target) {
2455
+ if (this.engine.type === "canonical") return this.resolveChangeOnSession(target, "accept");
1407
2456
  return this.resolveWithSectionReferenceHistory(() => this.withNotesFollowingReferences(() => this.acceptChangeInternal(target)));
1408
2457
  }
1409
2458
  acceptChangeInternal(target) {
@@ -1422,6 +2471,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1422
2471
  * deletion's text is restored. See {@link acceptChange} for targeting.
1423
2472
  */
1424
2473
  rejectChange(target) {
2474
+ if (this.engine.type === "canonical") return this.resolveChangeOnSession(target, "reject");
1425
2475
  return this.resolveWithSectionReferenceHistory(() => this.withNotesFollowingReferences(() => this.rejectChangeInternal(target)));
1426
2476
  }
1427
2477
  rejectChangeInternal(target) {
@@ -1437,6 +2487,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1437
2487
  }
1438
2488
  /** Convert one pending suggestion into an ordinary tracked change. */
1439
2489
  acceptSuggestion(suggestionId, options) {
2490
+ if (this.engine.type === "canonical") return this.resolveSuggestionOnSession(this.engine.session, suggestionId, "accept", options?.author ?? this.author);
1440
2491
  return this.resolveWithSectionReferenceHistory(() => {
1441
2492
  let accepted = false;
1442
2493
  for (const handle of this.listStoryHandlesInternal()) {
@@ -1449,6 +2500,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1449
2500
  }
1450
2501
  /** Remove one pending suggestion without applying it. */
1451
2502
  rejectSuggestion(suggestionId) {
2503
+ if (this.engine.type === "canonical") return this.resolveSuggestionOnSession(this.engine.session, suggestionId, "reject", this.author);
1452
2504
  return this.resolveWithSectionReferenceHistory(() => {
1453
2505
  let rejected = false;
1454
2506
  for (const handle of this.listStoryHandlesInternal()) {
@@ -1473,11 +2525,108 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1473
2525
  * ordinary changes resolved.
1474
2526
  */
1475
2527
  acceptAll() {
1476
- return this.resolveAll("accept");
2528
+ return this.engine.type === "canonical" ? this.resolveAllOnSession(this.engine.session, "accept") : this.resolveAll("accept");
1477
2529
  }
1478
2530
  /** Reject every tracked change in the package. See {@link acceptAll}. */
1479
2531
  rejectAll() {
1480
- return this.resolveAll("reject");
2532
+ return this.engine.type === "canonical" ? this.resolveAllOnSession(this.engine.session, "reject") : this.resolveAll("reject");
2533
+ }
2534
+ /**
2535
+ * One change of the body, resolved by the session's review intent: every
2536
+ * revision of the change (one a comment or a hyperlink splits carries
2537
+ * several ids) resolves together, as the editor resolves it.
2538
+ */
2539
+ resolveChangeOnSession(target, resolution) {
2540
+ if (this.engine.type !== "canonical") return panic("Only a canonical reviewer resolves on the session");
2541
+ const { session } = this.engine;
2542
+ const id = revisionIdOf(target);
2543
+ const suggestionId = suggestionIdOfRevision(this.state, id);
2544
+ if (suggestionId !== null) {
2545
+ const adopted = this.resolveSuggestionOnSession(session, suggestionId, resolution, this.author);
2546
+ if (!adopted || resolution === "reject") return adopted;
2547
+ }
2548
+ const section = this.finalSectionOperation((current) => resolveSectionChange({
2549
+ current,
2550
+ decision: resolution,
2551
+ id
2552
+ }));
2553
+ const prepared = session.prepareResolve(this.state, {
2554
+ revisionIds: [id],
2555
+ resolution,
2556
+ before: section ? [section] : []
2557
+ });
2558
+ if (prepared.isErr() && prepared.error.reason === "refused") return false;
2559
+ return this.resolveOnSession(prepared).resolved;
2560
+ }
2561
+ /**
2562
+ * One pending suggestion through the session's suggestion intent: rejected
2563
+ * with the comments it proposes, or adopted as ordinary tracked changes by
2564
+ * `author`. All stories belonging to the proposal publish together.
2565
+ */
2566
+ resolveSuggestionOnSession(session, suggestionId, resolution, author) {
2567
+ if (!this.activeSuggestionIds().has(suggestionId)) return false;
2568
+ const prepared = session.prepareSuggestion(this.state, {
2569
+ suggestionId,
2570
+ resolution,
2571
+ author,
2572
+ date: (/* @__PURE__ */ new Date()).toISOString()
2573
+ });
2574
+ if (prepared.isErr() && prepared.error.reason === "refused") return false;
2575
+ return this.resolveOnSession(prepared).resolved;
2576
+ }
2577
+ /**
2578
+ * Every reviewable change in the package in one session commit. A change a
2579
+ * content control's lock holds stays pending as it is and is listed in
2580
+ * `skipped`, as on the legacy engine.
2581
+ */
2582
+ resolveAllOnSession(session, resolution) {
2583
+ const recorded = this.pendingSuggestions.suggestionIds();
2584
+ for (const suggestionId of this.activeSuggestionIds()) if (!recorded.has(suggestionId)) return panic("A pending suggestion in the document has no record in the reviewer's registry", {
2585
+ suggestionId,
2586
+ resolution
2587
+ });
2588
+ const stories = this.storyResolutions(resolution);
2589
+ const skipped = [...stories.skipped];
2590
+ const sectionIds = (this.currentFinalSectionProperties()?.propertyChanges ?? []).map(({ info }) => info.id);
2591
+ const section = this.finalSectionOperation((current) => resolveSectionChanges(current, resolution));
2592
+ const proposedComments = resolution === "reject" ? (this.baseDocument.package.document.comments ?? []).filter(({ suggestionId }) => suggestionId !== void 0 && !stories.heldSuggestionIds.has(suggestionId)) : [];
2593
+ if (stories.count === 0 && proposedComments.length === 0 && section === null) return {
2594
+ resolved: 0,
2595
+ skipped
2596
+ };
2597
+ const outcome = this.resolveOnSession(session.prepareResolve(this.state, {
2598
+ revisionIds: [],
2599
+ resolution,
2600
+ before: [
2601
+ ...proposedComments.map(({ id }) => ({
2602
+ type: DOCUMENT_OP_TYPES.DELETE_COMMENT,
2603
+ id,
2604
+ scope: "thread"
2605
+ })),
2606
+ ...stories.ops,
2607
+ ...section ? [section] : []
2608
+ ]
2609
+ }));
2610
+ if (!outcome.resolved) {
2611
+ if (outcome.reason === "noChange") return {
2612
+ resolved: 0,
2613
+ skipped
2614
+ };
2615
+ skipped.push(...[...stories.stagedIds, ...sectionIds].map((id) => ({
2616
+ id,
2617
+ reason: CONTENT_CONTROL_LOCK,
2618
+ message: `Resolving change ${String(id)} changes a locked content control.`
2619
+ })));
2620
+ return {
2621
+ resolved: 0,
2622
+ skipped
2623
+ };
2624
+ }
2625
+ return {
2626
+ resolved: stories.count + sectionIds.length,
2627
+ skipped,
2628
+ ...outcome.absorbedBlocks.length === 0 ? {} : { absorbedBlocks: outcome.absorbedBlocks }
2629
+ };
1481
2630
  }
1482
2631
  resolveAll(mode) {
1483
2632
  return this.resolveWithSectionReferenceHistory(() => {
@@ -1512,15 +2661,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1512
2661
  }
1513
2662
  resolveEveryFinalSectionChange(mode) {
1514
2663
  const current = this.currentFinalSectionProperties();
1515
- const firstChange = current?.propertyChanges?.at(0);
1516
- if (!current || !firstChange) return 0;
1517
- const { propertyChanges, ...liveProperties } = current;
1518
- this.finalSectionPropertiesOverride = mode === "accept" ? liveProperties : sectionRejectProperties({
1519
- live: current,
1520
- previousProperties: firstChange.previousProperties,
1521
- previousReferences: firstChange.previousReferences
1522
- });
1523
- return propertyChanges?.length ?? 0;
2664
+ const resolved = current && resolveSectionChanges(current, mode);
2665
+ if (!resolved) return 0;
2666
+ this.finalSectionPropertiesOverride = resolved;
2667
+ return current?.propertyChanges?.length ?? 0;
1524
2668
  }
1525
2669
  resolveEveryStory(mode, skipped) {
1526
2670
  return this.withNotesFollowingReferences(() => this.resolveEveryStoryOnce(mode, skipped));
@@ -1579,7 +2723,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1579
2723
  * comment, another note), leaving out references inside the `skipped` notes.
1580
2724
  */
1581
2725
  noteKeysReferencedOutsideBody(skipped) {
1582
- const keys = new Set(noteKeysReferencedIn(this.baseDocument.package.document.comments ?? []));
2726
+ const keys = new Set(noteKeysReferencedIn(this.currentCommentDefinitions()));
1583
2727
  for (const handle of this.listStoryHandlesInternal()) {
1584
2728
  if (handle.type === "main") continue;
1585
2729
  let source;
@@ -1597,10 +2741,41 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1597
2741
  let count = 0;
1598
2742
  const resolvedStories = [];
1599
2743
  const refreshes = [];
1600
- for (const handle of this.listStoryHandlesInternal()) {
2744
+ const stories = this.listStoryHandlesInternal().flatMap((handle) => {
1601
2745
  const state = this.getEditableStoryState(handle);
1602
- if (!state) continue;
2746
+ if (!state) return [];
1603
2747
  const held = lockHeldChanges(state, mode);
2748
+ const carried = revisionIdsCarriedByResolution(state.doc, mode);
2749
+ return [{
2750
+ source: {
2751
+ handle,
2752
+ state
2753
+ },
2754
+ changes: getTrackedChangesFromDoc(state.doc).map(({ id }) => {
2755
+ const { carries, moves } = carriedByGroup(id, getTrackedChangeGroupIdsFromDoc(state.doc, id), carried);
2756
+ return {
2757
+ id,
2758
+ suggestionId: suggestionIdOfRevision(state, id),
2759
+ violation: held.get(id),
2760
+ carries,
2761
+ moves
2762
+ };
2763
+ })
2764
+ }];
2765
+ });
2766
+ const classified = classifyReviewLocks({
2767
+ stories,
2768
+ grouping: mode === "reject" ? "whole-proposal" : "individual-change"
2769
+ });
2770
+ for (const { source: { handle, state }, changes } of classified.stories) {
2771
+ const held = /* @__PURE__ */ new Map();
2772
+ for (const entry of changes) switch (entry.type) {
2773
+ case "held":
2774
+ held.set(entry.change.id, entry.violation);
2775
+ break;
2776
+ case "free": break;
2777
+ default: return panic("Unknown classified review lock", { entry });
2778
+ }
1604
2779
  if (held.size > 0) {
1605
2780
  count += this.resolveStoryAroundHeldChanges(handle, mode, held, skipped);
1606
2781
  continue;
@@ -1610,7 +2785,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1610
2785
  const withSuggestions = mode === "accept" && ordinaryCount > 0 && getSuggestions(state).length > 0 ? this.acceptOrdinaryChangesWithSuggestions(state, handle) : null;
1611
2786
  if (withSuggestions) refreshes.push(withSuggestions.refresh);
1612
2787
  let resolvedState = state;
1613
- if (mode === "reject") resolvedState = resolveAllChangesInHeadlessState(rejectSuggestions(state), mode);
2788
+ if (mode === "reject") resolvedState = resolveAllChangesInHeadlessState(rejectEverySuggestion(state), mode);
1614
2789
  else if (ordinaryCount > 0) resolvedState = withSuggestions?.state ?? resolveAllChangesInHeadlessState(state, mode);
1615
2790
  resolvedStories.push({
1616
2791
  handle,
@@ -1655,13 +2830,13 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1655
2830
  const records = this.exportPendingSuggestions().filter((record) => editableStoryKey(record.story) === editableStoryKey(story));
1656
2831
  const recordedIds = new Set(records.map(({ suggestionId }) => suggestionId));
1657
2832
  if (originalSuggestions.some(({ suggestionId }) => !recordedIds.has(suggestionId))) panic("A pending suggestion has no operation to restage after bulk acceptance");
1658
- let clean = rejectSuggestions(state);
2833
+ let clean = rejectEverySuggestion(state);
1659
2834
  const restagedCommentIds = new Set(records.flatMap(({ commentId }) => commentId === void 0 ? [] : [commentId]));
1660
2835
  clean = withoutPendingSuggestionCommentMarks(clean, restagedCommentIds);
1661
2836
  let resolved = resolveAllChangesInHeadlessState(clean, "accept");
1662
2837
  const restaged = [];
1663
2838
  for (const record of records) {
1664
- const snapshot = createStateSnapshot(resolved);
2839
+ const snapshot = this.snapshotOf(resolved);
1665
2840
  const view = {
1666
2841
  state: resolved,
1667
2842
  dispatch: (transaction) => {
@@ -1708,18 +2883,149 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1708
2883
  }
1709
2884
  /** Resolve ordinary revisions on a detached in-memory document. */
1710
2885
  toResolvedDocument(decision) {
2886
+ return this.resolvedCopy(decision === "accept" ? "final" : "original").toDocument();
2887
+ }
2888
+ /**
2889
+ * A detached reviewer holding the document with every change resolved to
2890
+ * `view`, which every resolved-view reader reads. Both engines resolve
2891
+ * through docx-core's revision resolution: a second session resolved that
2892
+ * way, or a legacy reviewer over the model that resolution returns.
2893
+ */
2894
+ resolvedCopy(view) {
2895
+ if (this.engine.type === "canonical") return this.resolvedSessionCopy(this.engine.session, view);
2896
+ const resolved = resolvedDocumentView(this.toDocument(), view === "final" ? "accept" : "reject");
2897
+ if (resolved.unresolved.length > 0) throw new FolioResolvedViewRefusedError({
2898
+ message: `The ${view} view cannot be read: the changes of ${resolved.unresolved.length} stories do not resolve.`,
2899
+ view,
2900
+ stories: resolved.unresolved
2901
+ });
2902
+ const rendered = normalizeListModelRendering(resolved.document, { inverse: "omit" }).document;
2903
+ return FolioDocxReviewer.legacyOver(rendered, {
2904
+ originalBuffer: this.originalBuffer,
2905
+ author: this.author,
2906
+ positionalParaIds: this.storyPositionalParaIds()
2907
+ });
2908
+ }
2909
+ /** The {@link resolvedCopy} a reader takes one story of. */
2910
+ resolvedReader(view) {
2911
+ return this.engine.type === "canonical" ? this.resolvedSessionReader(this.engine.session, view) : this.resolvedCopy(view);
2912
+ }
2913
+ /**
2914
+ * The {@link resolvedSessionCopy} a reader takes one story of: the stories
2915
+ * of one document share it until a commit replaces the document. Held
2916
+ * weakly, so a reviewer does not keep the copy's session alive.
2917
+ */
2918
+ resolvedSessionReader(session, view) {
2919
+ const { document } = session;
2920
+ const held = this.resolvedSessionReaders.get(view)?.deref();
2921
+ if (held?.document === document) return held.reviewer;
2922
+ const reviewer = this.resolvedSessionCopy(session, view);
2923
+ this.resolvedSessionReaders.set(view, new WeakRef({
2924
+ document,
2925
+ reviewer
2926
+ }));
2927
+ return reviewer;
2928
+ }
2929
+ /**
2930
+ * The paragraph ids this reviewer's stories read as positional: ids it
2931
+ * minted where the package named none, which `toDocument` writes as ids.
2932
+ */
2933
+ storyPositionalParaIds() {
2934
+ const ids = new Set(this.positionalParaIds);
2935
+ const states = [this.state, ...[...this.secondaryStoryStates.values()].map(({ state }) => state)];
2936
+ for (const { doc } of states) doc.descendants((node) => {
2937
+ const paraId = node.attrs["paraId"];
2938
+ if (node.attrs["idStability"] === "positional" && typeof paraId === "string") ids.add(paraId);
2939
+ });
2940
+ return ids;
2941
+ }
2942
+ /**
2943
+ * A reviewer on a second session over the current document, as a reviewer
2944
+ * reopened on it would hold it, with every change resolved to `view`. This
2945
+ * reviewer's session and journal are left as they are; what the session
2946
+ * cannot resolve yet refuses as `acceptAll` and `rejectAll` do.
2947
+ */
2948
+ resolvedSessionCopy(session, view) {
2949
+ const document = readModel(session.document);
2950
+ const created = createCanonicalSession(document, document.package.styles);
2951
+ if (created.isErr()) throw created.error;
1711
2952
  const copy = new FolioDocxReviewer({
1712
- baseDocument: this.toDocument(),
2953
+ baseDocument: document,
1713
2954
  originalBuffer: this.originalBuffer,
1714
- state: this.state,
1715
- author: this.author
2955
+ state: canonicalReviewerState(created.value),
2956
+ author: this.author,
2957
+ engine: {
2958
+ type: "canonical",
2959
+ session: created.value
2960
+ },
2961
+ positionalParaIds: this.positionalParaIds
2962
+ });
2963
+ copy.pendingSuggestions = this.pendingSuggestions.clone();
2964
+ if ((view === "final" ? copy.acceptAll() : copy.rejectAll()).skipped.length > 0) throw new CanonicalSessionError({
2965
+ reason: "refused",
2966
+ ground: { rule: CANONICAL_RULE.contentControlLock },
2967
+ message: `A locked content control prevents the ${view} view.`
2968
+ });
2969
+ if (pendingSuggestionIdsIn(copy.baseDocument).size > 0) throw canonicalReviewerRefusal(`read the ${view} view while suggestions remain pending`);
2970
+ return copy;
2971
+ }
2972
+ /**
2973
+ * Resolve one story's changes to `view` in one session commit: the body's
2974
+ * through the review intent, another story's as its resolution operation.
2975
+ */
2976
+ resolveStoryOnSession(session, story, view) {
2977
+ if (!isFolioResolvedReviewedView(view)) throw new UnsupportedFolioReviewedViewError({
2978
+ message: "Only original and final views can replace editable story state.",
2979
+ receivedView: view
2980
+ });
2981
+ const state = this.getEditableStoryState(story);
2982
+ if (!state) return false;
2983
+ if (getSuggestions(state).length > 0) throw canonicalReviewerRefusal("resolve a story holding pending suggestions");
2984
+ const resolution = view === "final" ? "accept" : "reject";
2985
+ const section = story.type === "main" ? this.finalSectionOperation((current) => resolveSectionChanges(current, resolution)) : null;
2986
+ const groups = listedRevisionGroups(state.doc).map(({ groupIds }) => groupIds);
2987
+ const ids = groups.flat();
2988
+ if (ids.length === 0 && section === null) return true;
2989
+ const firstHeld = canonicalRevisionLocks({
2990
+ document: this.baseDocument,
2991
+ story: canonicalOpStory(story),
2992
+ groups,
2993
+ decision: resolution
2994
+ }).held.at(0);
2995
+ if (firstHeld !== void 0) throw new CanonicalSessionError({
2996
+ reason: "refused",
2997
+ ground: { rule: CANONICAL_RULE.contentControlLock },
2998
+ message: lockedControlMessage(firstHeld.violation)
2999
+ });
3000
+ const outcome = this.resolveOnSession(story.type === "main" ? session.prepareResolve(this.state, {
3001
+ revisionIds: ids,
3002
+ resolution,
3003
+ before: section ? [section] : []
3004
+ }) : session.prepareResolve(this.state, {
3005
+ revisionIds: [],
3006
+ resolution,
3007
+ before: [{
3008
+ type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
3009
+ story: canonicalOpStory(story),
3010
+ revisionIds: ids,
3011
+ decision: resolution
3012
+ }]
3013
+ }));
3014
+ if (outcome.resolved && outcome.lockHeld.length > 0 || !outcome.resolved && outcome.reason === "lockHeld") throw new CanonicalSessionError({
3015
+ reason: "refused",
3016
+ ground: { rule: CANONICAL_RULE.contentControlLock },
3017
+ message: `A locked content control prevents the ${view} story view.`
1716
3018
  });
1717
- if (decision === "accept") copy.acceptAll();
1718
- else copy.rejectAll();
1719
- return copy.toDocument();
3019
+ const remaining = this.getEditableStoryState(story);
3020
+ return remaining === null || getTrackedChangesFromDoc(remaining.doc).length === 0;
1720
3021
  }
1721
3022
  /** The current document model with edits merged back in. */
1722
3023
  toDocument() {
3024
+ if (this.engine.type === "canonical") {
3025
+ const model = withoutPendingSuggestions(this.engine.session.captureSaveSnapshot().document);
3026
+ if (model.isErr()) throw model.error;
3027
+ return cloneDocumentWithParagraphPropertySources(reconcileDocumentPartRelationships(model.value));
3028
+ }
1723
3029
  const document = this.documentFromStateSnapshot(this.captureReviewerState());
1724
3030
  applyReplyThreadMarkers(document);
1725
3031
  visitDocxParagraphs({
@@ -1752,6 +3058,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1752
3058
  importedHeaders: new Map(this.importedHeaders),
1753
3059
  importedFooters: new Map(this.importedFooters),
1754
3060
  createdComments: [...this.createdComments],
3061
+ deletedCommentIds: this.deletedCommentIds,
1755
3062
  resolvedOverrides: new Map(this.resolvedOverrides),
1756
3063
  resolvedStoryExpectations: [...this.resolvedStoryExpectations.values()].filter(({ story }) => story.type === "main" || this.secondaryStorySource(story) !== void 0)
1757
3064
  };
@@ -1760,10 +3067,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1760
3067
  const pendingCommentIds = new Set(this.exportPendingSuggestions().flatMap(({ commentId }) => commentId === void 0 ? [] : [commentId]));
1761
3068
  const snapshot = {
1762
3069
  ...authored,
1763
- mainState: withoutPendingSuggestionCommentMarks(rejectSuggestions(authored.mainState), pendingCommentIds),
3070
+ mainState: withoutPendingSuggestionCommentMarks(rejectEverySuggestion(authored.mainState), pendingCommentIds),
1764
3071
  secondaryStoryStates: authored.secondaryStoryStates.map((entry) => ({
1765
3072
  ...entry,
1766
- state: withoutPendingSuggestionCommentMarks(rejectSuggestions(entry.state), pendingCommentIds)
3073
+ state: withoutPendingSuggestionCommentMarks(rejectEverySuggestion(entry.state), pendingCommentIds)
1767
3074
  })),
1768
3075
  createdComments: authored.createdComments.filter(({ id }) => !pendingCommentIds.has(id))
1769
3076
  };
@@ -1803,7 +3110,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1803
3110
  const definitions = [...document.package.document.comments ?? [], ...snapshot.createdComments];
1804
3111
  const knownDefinitions = [...this.baseDocument.package.document.comments ?? [], ...snapshot.createdComments];
1805
3112
  const keptThreadIds = new Set(this.keptCommentThreads(knownDefinitions, snapshot.mainState, snapshot.secondaryStoryStates).map(({ id }) => id));
1806
- const kept = definitions.filter(({ id }) => keptThreadIds.has(id));
3113
+ const kept = definitions.filter(({ id }) => keptThreadIds.has(id) && !snapshot.deletedCommentIds.has(id));
1807
3114
  const keptIds = new Set(kept.map(({ id }) => id));
1808
3115
  const retiredCommentIds = new Set(knownDefinitions.filter(({ id }) => !keptIds.has(id)).map(({ id }) => id));
1809
3116
  const modelStories = [
@@ -1910,6 +3217,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1910
3217
  * returns the reason instead of rewriting every part.
1911
3218
  */
1912
3219
  async save({ repack: repackPolicy = "allow" } = {}) {
3220
+ if (this.engine.type === "canonical") return this.saveOnSession(this.engine.session, repackPolicy);
1913
3221
  const save = this.captureSaveSnapshot();
1914
3222
  const selective = save.path.type === "selective-first" ? await this.trySelectiveSave(save.document, save.path.changedParaIds) : null;
1915
3223
  if (selective) {
@@ -1946,9 +3254,41 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1946
3254
  buffer
1947
3255
  };
1948
3256
  }
3257
+ /**
3258
+ * The editor's canonical save of the session's committed snapshot: the
3259
+ * selective patch of the loaded package when it applies, a repack
3260
+ * otherwise. Pending suggestions are written as rejected, as the editor
3261
+ * writes them.
3262
+ */
3263
+ async saveOnSession(session, repackPolicy) {
3264
+ const snapshot = session.captureSaveSnapshot();
3265
+ const reason = snapshot.structure === "changed" ? "structuralChange" : "selectiveDeclined";
3266
+ let saved;
3267
+ try {
3268
+ saved = await serializeCanonicalSave({
3269
+ snapshot,
3270
+ repack: repackPolicy
3271
+ });
3272
+ } catch (error) {
3273
+ if (CanonicalSaveRepackRefusedError.is(error)) return {
3274
+ type: "repackRefused",
3275
+ reason
3276
+ };
3277
+ throw error;
3278
+ }
3279
+ if (saved.path === "selective") return {
3280
+ type: "selective",
3281
+ buffer: saved.buffer
3282
+ };
3283
+ return {
3284
+ type: "full-repack",
3285
+ reason,
3286
+ buffer: saved.buffer
3287
+ };
3288
+ }
1949
3289
  async assertResolvedStoriesSerialized(buffer, expectations) {
1950
3290
  if (expectations.length === 0) return;
1951
- const reopened = await FolioDocxReviewer.fromBuffer(buffer);
3291
+ const reopened = await FolioDocxReviewer.fromBuffer(buffer, { session: "legacy" });
1952
3292
  for (const { story, text, blocks, minted } of expectations) {
1953
3293
  const serialized = reopened.readReviewedStory({
1954
3294
  story,
@@ -1995,19 +3335,27 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1995
3335
  getEditableStoryState(story) {
1996
3336
  if (story.type === "main") return this.state;
1997
3337
  if (!this.secondaryStorySource(story)) return null;
3338
+ if (this.engine.type === "canonical") {
3339
+ const projected = this.engine.session.projectStory(canonicalOpStory(story));
3340
+ if (projected.isErr()) throw projected.error;
3341
+ return canonicalStoryState(this.engine.session, projected.value.doc, projected.value);
3342
+ }
1998
3343
  const key = secondaryStoryKey(story);
1999
3344
  const existing = this.secondaryStoryStates.get(key);
2000
3345
  if (existing) return existing.state;
2001
3346
  const doc = this.secondaryStoryDoc(story);
2002
3347
  if (!doc) return null;
2003
- const state = ensureBaseDirectionInState(EditorState.create({
3348
+ const initialState = ensureBaseDirectionInState(EditorState.create({
2004
3349
  schema,
2005
3350
  doc,
2006
- plugins: createHeadlessPlugins(this.baseDocument.package.styles, this.baseDocument.package.numbering)
3351
+ plugins: createHeadlessPlugins(this.importedStyles ?? this.baseDocument.package.styles, this.baseDocument.package.numbering)
2007
3352
  }));
3353
+ const transaction = initialState.tr;
3354
+ if (this.deletedCommentIds.size > 0) removeCommentAnchors(transaction, this.deletedCommentIds);
3355
+ const state = transaction.docChanged ? initialState.apply(transaction) : initialState;
2008
3356
  this.secondaryStoryStates.set(key, {
2009
3357
  handle: story,
2010
- initialState: state,
3358
+ initialState,
2011
3359
  state
2012
3360
  });
2013
3361
  return state;
@@ -2025,12 +3373,25 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2025
3373
  secondaryStorySource(story) {
2026
3374
  return story.type === "header" || story.type === "footer" ? this.getHeaderFooterStory(story) : this.getNoteStory(story);
2027
3375
  }
3376
+ /**
3377
+ * On either engine a secondary story is converted from the reviewer's
3378
+ * model. A canonical reviewer's model is the session's document, so its
3379
+ * headers, footers and notes are read from the session but not through the
3380
+ * session's story projections yet.
3381
+ */
2028
3382
  secondaryStoryDoc(story) {
3383
+ if (this.engine.type === "canonical") {
3384
+ if (!this.secondaryStorySource(story)) return null;
3385
+ const projected = this.engine.session.projectStory(canonicalOpStory(story));
3386
+ if (projected.isErr()) throw projected.error;
3387
+ return projected.value.doc;
3388
+ }
2029
3389
  const source = this.secondaryStorySource(story);
2030
3390
  if (!source) return null;
3391
+ const styles = this.importedStyles ?? this.baseDocument.package.styles;
2031
3392
  const conversionOptions = {
2032
3393
  ...this.baseDocument.package.numbering !== void 0 && { numbering: this.baseDocument.package.numbering },
2033
- ...this.baseDocument.package.styles !== void 0 && { styles: this.baseDocument.package.styles },
3394
+ ...styles !== void 0 && { styles },
2034
3395
  ...this.baseDocument.package.theme !== void 0 && { theme: this.baseDocument.package.theme }
2035
3396
  };
2036
3397
  const storyDoc = story.type === "header" || story.type === "footer" ? headerFooterToProseDoc(source.content, conversionOptions) : footnoteToProseDoc(source.content, conversionOptions);
@@ -2124,6 +3485,40 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2124
3485
  content: []
2125
3486
  }]
2126
3487
  };
3488
+ if (this.engine.type === "canonical") {
3489
+ const document = this.baseDocument;
3490
+ const minted = this.engine.session.freshBlockIds([1]);
3491
+ if (minted.isErr()) throw minted.error;
3492
+ const paraId = minted.value.at(0)?.at(0);
3493
+ if (paraId === void 0) return panic("The session minted no paragraph id for a header part");
3494
+ const entries = [...(story.type === "header" ? document.package.headers : document.package.footers) ?? /* @__PURE__ */ new Map(), [relationshipId, {
3495
+ ...empty,
3496
+ content: [{
3497
+ type: "paragraph",
3498
+ paraId,
3499
+ content: []
3500
+ }]
3501
+ }]];
3502
+ const parts = story.type === "header" ? { headers: entries } : { footers: entries };
3503
+ const ops = [];
3504
+ if (importedMedia) ops.push(packageResourcesOpOf({
3505
+ before: document,
3506
+ after: {
3507
+ ...document,
3508
+ package: {
3509
+ ...document.package,
3510
+ media: new Map([...document.package.media ?? /* @__PURE__ */ new Map(), [importedMedia.path, importedMedia]])
3511
+ }
3512
+ }
3513
+ }));
3514
+ ops.push({
3515
+ type: DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS,
3516
+ expected: captureStoryParts(document, parts),
3517
+ parts
3518
+ });
3519
+ this.commitOpsOnSession(ops);
3520
+ return handle;
3521
+ }
2127
3522
  if (importedMedia) this.importedMedia.set(importedMedia.path, importedMedia);
2128
3523
  (story.type === "header" ? this.importedHeaders : this.importedFooters).set(relationshipId, empty);
2129
3524
  const state = ensureBaseDirectionInState(EditorState.create({
@@ -2162,7 +3557,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2162
3557
  * same states, so the text now describes exactly what a save would write.
2163
3558
  */
2164
3559
  storyBlocks(state, source) {
2165
- return state ? proseDocToBlocks(rejectSuggestions(state).doc, source.content, this.baseDocument.package.styles) : source.content;
3560
+ return state ? proseDocToBlocks(rejectEverySuggestion(state).doc, source.content, this.baseDocument.package.styles) : source.content;
2166
3561
  }
2167
3562
  getHeaderFooterStoryText(story, source) {
2168
3563
  const state = this.secondaryStoryStates.get(headerFooterStoryKey(story))?.state;
@@ -2335,7 +3730,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2335
3730
  }
2336
3731
  /** Allocate outside every parsed or newly-created comment and reply id. */
2337
3732
  nextCommentId() {
2338
- return allocateCommentId();
3733
+ return this.commentIds.next();
2339
3734
  }
2340
3735
  /**
2341
3736
  * Drive a ProseMirror command against the reviewer's headless state via the
@@ -2360,7 +3755,11 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2360
3755
  }
2361
3756
  };
2362
3757
  /** @internal Comparison-only access to atomic and fresh reviewer projections. */
2363
- const getFolioDocxComparisonAccess = (reviewer) => comparisonAccessByReviewer.get(reviewer) ?? panic("Comparison access was requested for an uninitialized DOCX reviewer");
3758
+ const getFolioDocxComparisonAccess = (reviewer) => {
3759
+ const access = comparisonAccessByReviewer.get(reviewer);
3760
+ if (access) return access;
3761
+ return panic("Comparison access was requested for an uninitialized DOCX reviewer");
3762
+ };
2364
3763
  /**
2365
3764
  * One-shot headless review: parse `buffer`, apply `operations`, and return the
2366
3765
  * reviewed `.docx` buffer alongside the applied / skipped breakdown. Convenience
@@ -2368,7 +3767,10 @@ const getFolioDocxComparisonAccess = (reviewer) => comparisonAccessByReviewer.ge
2368
3767
  * operations to run.
2369
3768
  */
2370
3769
  const applyFolioAIEditsToBuffer = async (buffer, operations, options = {}) => {
2371
- const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { ...options.author !== void 0 && { author: options.author } });
3770
+ const reviewer = await FolioDocxReviewer.fromBuffer(buffer, {
3771
+ ...options.author !== void 0 && { author: options.author },
3772
+ ...options.session !== void 0 && { session: options.session }
3773
+ });
2372
3774
  const { applied, skipped } = reviewer.applyOperations(operations, {
2373
3775
  undefinedReferences: "refuse",
2374
3776
  ...options.mode !== void 0 && { mode: options.mode },
@@ -2380,4 +3782,4 @@ const applyFolioAIEditsToBuffer = async (buffer, operations, options = {}) => {
2380
3782
  skipped
2381
3783
  };
2382
3784
  };
2383
- export { FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FolioDocumentStoryNotFoundError, FolioDocxReviewer, UnsupportedFolioReviewedViewError, applyFolioAIEditsToBuffer, getFolioDocxComparisonAccess, isFolioResolvedReviewedView, isFolioReviewedView };
3785
+ export { FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FolioDocumentStoryNotFoundError, FolioDocxReviewer, FolioRoomJournalError, UnsupportedFolioReviewedViewError, applyFolioAIEditsToBuffer, getFolioDocxComparisonAccess, isFolioResolvedReviewedView, isFolioReviewedView };