@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,32 +1,46 @@
1
1
  import { splitsGraphemeCluster, splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
2
- import { CommentMarkerCache, paragraphCommentMarkers, visitCommentMarkerItems } from "../docx/commentAnchorIndex.js";
2
+ import { getTrackedChangeGroupsForIds } from "../ai-edits/read.js";
3
+ import { CommentMarkerCache, paragraphCommentMarkers, positionedCommentGaps, visitCommentMarkerItems } from "../docx/commentAnchorIndex.js";
4
+ import { copyHeaderFooterBaselineHandles, getDocumentSourceBaseline } from "../docx/headerFooterVerbatim.js";
3
5
  import { ListNormalizationCache } from "../docx/listModelNormalization.js";
4
- import { cloneDocumentWithParagraphPropertySources, copyDocumentParagraphPropertySourceContract, copyParagraphPropertySource, restoreParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
6
+ import { cloneDocumentWithParagraphPropertySources, getProseParagraphPropertySourceToken, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
5
7
  import { visitInlineContentSlots } from "../docx/paragraphTraversal.js";
6
8
  import { isCellMergeContinuation } from "../docx/tableParser.js";
9
+ import { referencedHeaderFooters, retiredHeaderFooters } from "../docx/unreferencedHeaderFooters.js";
7
10
  import { calculateRowSpans } from "../docx/verticalMergeProjection.js";
11
+ import { canonicalOperationStagingAccess } from "../internal/canonicalOperationStaging.js";
12
+ import { recordCanonicalTyping } from "../internal/canonicalTyping.js";
8
13
  import { canonicalCellSelectionRanges, canonicalContentPosition, canonicalSelectionRange } from "../prosemirror/canonicalSelectionRange.js";
9
14
  import { expectCommentRangeBoundaryAttrs } from "../prosemirror/commentRangeBoundaryAttrs.js";
15
+ import { storyConversionOptions } from "../prosemirror/conversion/storyConversionOptions.js";
10
16
  import { ProjectionBlockCache, collectPairedBookmarkIds, footnoteToProseDoc, headerFooterToProseDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
11
- import { markPackageChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
17
+ import { heldUnreferencedNotes } from "../prosemirror/noteReferenceReview.js";
18
+ import { preservesReplacementCommentAlignment } from "../prosemirror/replacedAnnotations.js";
12
19
  import { runFormattingPatchFromMarks } from "../prosemirror/runFormattingFromMarks.js";
13
20
  import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
21
+ import { canonicalJson } from "../utils/canonicalJson.js";
22
+ import { itemBefore } from "../utils/listItems.js";
23
+ import { CanonicalIdLease } from "./canonicalIdLease.js";
14
24
  import { InlineProjectionCache, canonicalNativeCells, projectCanonicalInline } from "./canonicalInlineProjection.js";
15
25
  import { normalizeCanonicalListRendering } from "./canonicalListRendering.js";
16
26
  import { lockViolationBetween } from "./canonicalLockGuard.js";
17
27
  import { ParagraphIdIndex, sameIdOrder, storyFactContributions } from "./canonicalProjectionBlocks.js";
18
- import { unsupportedSeedReason } from "./canonicalSeedContent.js";
28
+ import { rebaseHistorySteps, remoteSelection } from "./canonicalRemoteHistory.js";
29
+ import { canonicalRevisionLocks } from "./canonicalRevisionLocks.js";
30
+ import { changedWindow, unsupportedEditReason, unsupportedSeedReason } from "./canonicalSeedContent.js";
19
31
  import { restoreCanonicalSelection } from "./canonicalSelection.js";
20
32
  import { canonicalSourceRestores, normalizeCanonicalSource, withUneditedSourceRestored } from "./canonicalSourceNormalization.js";
21
33
  import { mapTocSelection } from "./canonicalTocSelection.js";
34
+ import { controlEdgesAt } from "./controlEdges.js";
35
+ import { ownedSourceCopies, preservePropertySources, preservePropertySourcesWholeStories } from "./propertySourcePreservation.js";
22
36
  import { Result, TaggedError, panic } from "better-result";
23
37
  import { hasIllegalXmlCharacters } from "@stll/docx-core";
24
38
  import { lockedControlMessage } from "@stll/docx-core/model";
25
39
  import { Fragment } from "prosemirror-model";
26
40
  import { CellSelection } from "prosemirror-tables";
27
- import { DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_TYPES, OP_STORIES, applyDocumentOp, applyDocumentOps, combineEdits, compileEditorIntent, createEditorIntentIdAllocator, documentStories, editorParagraphGroups, findStoryBody, normalizeForOps, packageParagraphIds, paragraphIdsIn, sameStory, suggestedCommentIds, suggestionRevisionInfos, survivingComments, validateOpsDocument } from "@stll/docx-core/ops";
41
+ import { DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_TYPES, ID_LEASE_KINDS, OP_STORIES, applyDocumentOp, applyDocumentOps, combineEdits, combineRecordedRevisions, compileEditorIntent, createEditorIntentIdAllocator, documentStories, editorParagraphGroups, findStoryBody, formatParaId, freshLeasedIds, inverseMeetingDocument, isBlockBoundary, normalizeForOps, packageParagraphIds, paragraphIdsIn, paragraphsThroughTextBoxes, planWholeParagraphReplacement, sameStory, suggestedCommentIds, suggestionRevisionInfos, survivingComments, validateOpsDocument, withParagraphCopies } from "@stll/docx-core/ops";
28
42
  import { AllSelection, NodeSelection, Selection, TextSelection } from "prosemirror-state";
29
- // src/controller/canonicalSession.ts
43
+ // src/canonical/canonicalSession.ts
30
44
  const CanonicalSessionErrorBase = TaggedError("CanonicalSessionError");
31
45
  var CanonicalSessionError = class extends CanonicalSessionErrorBase {};
32
46
  const refuse = (message) => Result.err(new CanonicalSessionError({
@@ -34,6 +48,12 @@ const refuse = (message) => Result.err(new CanonicalSessionError({
34
48
  message,
35
49
  reason: "refused"
36
50
  }));
51
+ /** A refusal under the gap or rule it belongs to. */
52
+ const refuseUnder = (ground, message) => Result.err(new CanonicalSessionError({
53
+ ground,
54
+ message,
55
+ reason: "refused"
56
+ }));
37
57
  /** A change a content control's lock forbids: the document's rule, not a gap. */
38
58
  const lockRefusal = (violation) => Result.err(new CanonicalSessionError({
39
59
  ground: { rule: CANONICAL_RULE.contentControlLock },
@@ -45,6 +65,36 @@ const noChange = (message) => Result.err(new CanonicalSessionError({
45
65
  message,
46
66
  reason: "noChange"
47
67
  }));
68
+ /**
69
+ * What the session says for an intent the compiler or the engine refused. A
70
+ * change the engine cannot record belongs to the capability that would record
71
+ * it: the tracked table records for a
72
+ * suggested row, column or table change. Every other refusal is unclassified.
73
+ */
74
+ const intentRefusal = (intent, mode, { reason, message }) => {
75
+ if (reason === DOCUMENT_OP_REFUSAL_REASONS.NO_CHANGE) return noChange(message);
76
+ if (reason === DOCUMENT_OP_REFUSAL_REASONS.UNRECORDABLE_LINK_SUGGESTION) return Result.err(new CanonicalSessionError({
77
+ ground: { rule: CANONICAL_RULE.linkSuggestionShape },
78
+ message,
79
+ reason: "refused"
80
+ }));
81
+ if (reason !== DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE) return refuse(message);
82
+ let gap;
83
+ switch (intent.type) {
84
+ case "table":
85
+ case "tableRow":
86
+ case "tableBlock":
87
+ if (mode.type !== "suggesting") return refuse(message);
88
+ gap = CANONICAL_GAP.trackedTableStructure;
89
+ break;
90
+ default: return refuse(message);
91
+ }
92
+ return Result.err(new CanonicalSessionError({
93
+ ground: { gap },
94
+ message,
95
+ reason: "refused"
96
+ }));
97
+ };
48
98
  const COMMENT_OPERATION_TYPES = /* @__PURE__ */ new Set([
49
99
  DOCUMENT_OP_TYPES.CREATE_COMMENT,
50
100
  DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT,
@@ -52,7 +102,8 @@ const COMMENT_OPERATION_TYPES = /* @__PURE__ */ new Set([
52
102
  DOCUMENT_OP_TYPES.DELETE_COMMENT,
53
103
  DOCUMENT_OP_TYPES.RESTORE_COMMENT_STATE
54
104
  ]);
55
- const operationChangesPackage = (op) => {
105
+ /** The story an operation edits, or null for one that edits the package. */
106
+ const operationStory = (op) => {
56
107
  switch (op.type) {
57
108
  case DOCUMENT_OP_TYPES.CREATE_COMMENT:
58
109
  case DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT:
@@ -68,14 +119,27 @@ const operationChangesPackage = (op) => {
68
119
  case DOCUMENT_OP_TYPES.SET_PACKAGE_RESOURCES:
69
120
  case DOCUMENT_OP_TYPES.CREATE_NUMBERING_INSTANCE:
70
121
  case DOCUMENT_OP_TYPES.DELETE_NUMBERING_INSTANCE:
71
- case DOCUMENT_OP_TYPES.SET_SECTION_ENDPOINT: return true;
122
+ case DOCUMENT_OP_TYPES.SET_SECTION_ENDPOINT: return null;
72
123
  default:
73
- if ("story" in op) return !sameStory(op.story, OP_STORIES.MAIN);
74
- if ("at" in op) return !sameStory(op.at.story, OP_STORIES.MAIN);
75
- if ("from" in op) return !sameStory(op.from.story, OP_STORIES.MAIN);
124
+ if ("story" in op) return op.story;
125
+ if ("at" in op) return op.at.story;
126
+ if ("from" in op) return op.from.story;
76
127
  return op;
77
128
  }
78
129
  };
130
+ /**
131
+ * An edit inside a header or footer: the selective save writes every header
132
+ * and footer part whole, and declines one that needs a resource of its own,
133
+ * so the edit leaves the body's paragraph splice standing.
134
+ */
135
+ const editsHeaderFooter = (op) => {
136
+ const story = operationStory(op);
137
+ return story !== null && story !== OP_STORIES.MAIN && (story.kind === "header" || story.kind === "footer");
138
+ };
139
+ const operationChangesPackage = (op) => {
140
+ const story = operationStory(op);
141
+ return story === null || !sameStory(story, OP_STORIES.MAIN) && !editsHeaderFooter(op);
142
+ };
79
143
  const operationChangesStructure = (op) => {
80
144
  switch (op.type) {
81
145
  case DOCUMENT_OP_TYPES.DELETE_BLOCKS:
@@ -99,7 +163,8 @@ const operationChangesStructure = (op) => {
99
163
  case DOCUMENT_OP_TYPES.SET_CELL_PROPS:
100
164
  case DOCUMENT_OP_TYPES.SET_ROW_PROPS:
101
165
  case DOCUMENT_OP_TYPES.SET_TABLE_PROPS:
102
- case DOCUMENT_OP_TYPES.SET_REVISION_INFO: return true;
166
+ case DOCUMENT_OP_TYPES.SET_REVISION_INFO:
167
+ case DOCUMENT_OP_TYPES.SET_CONTENT_CONTROL: return true;
103
168
  case DOCUMENT_OP_TYPES.CREATE_HEADER_FOOTER:
104
169
  case DOCUMENT_OP_TYPES.REMOVE_HEADER_FOOTER:
105
170
  case DOCUMENT_OP_TYPES.ADD_NOTE:
@@ -223,6 +288,12 @@ var CanonicalProjection = class CanonicalProjection {
223
288
  return address;
224
289
  }
225
290
  /** The paragraph whose content holds `position`, its ends included. */
291
+ /** Whether `position` lies in a text box's content. */
292
+ insideTextBox(position) {
293
+ const resolved = this.doc.resolve(Math.max(0, Math.min(position, this.doc.content.size)));
294
+ for (let depth = resolved.depth; depth > 0; depth -= 1) if (resolved.node(depth).type.name === "textBox") return true;
295
+ return false;
296
+ }
226
297
  paragraphAround(position) {
227
298
  let low = 0;
228
299
  let high = this.starts.length - 1;
@@ -255,7 +326,7 @@ var CanonicalProjection = class CanonicalProjection {
255
326
  if (!Number.isInteger(position)) return refuse("The input position is not an integer.");
256
327
  position = canonicalContentPosition(this.doc, position);
257
328
  const paragraph = this.paragraphAround(position);
258
- if (paragraph === void 0) return refuse("The input is outside a plain paragraph.");
329
+ if (paragraph === void 0) return this.insideTextBox(position) ? refuseUnder({ gap: CANONICAL_GAP.publicUnsupportedInline }, "The canonical session holds no address in this paragraph, such as one in a text box.") : refuse("The input is outside a plain paragraph.");
259
330
  const relative = position - paragraph.start;
260
331
  const offset = paragraph.boundaries.findIndex((gaps) => gaps.some((gap) => gap.position === relative));
261
332
  if (offset < 0) return refuse("The input splits an indivisible inline element.");
@@ -368,6 +439,15 @@ var CanonicalProjection = class CanonicalProjection {
368
439
  const slot = this.index.get(blockId);
369
440
  if (slot === void 0 || slot.paragraph < 0) return void 0;
370
441
  const paragraph = this.addressOf(slot.block, slot.paragraph);
442
+ const index = paragraph.container.indexOf(paragraph.source);
443
+ if (index >= 0) {
444
+ let at = index + 1;
445
+ while (paragraph.source.sectionProperties === void 0 && paragraph.container[at] !== void 0 && isBlockBoundary(paragraph.container[at] ?? panic("A block is listed."))) at += 1;
446
+ const following = paragraph.container[at];
447
+ if (following?.type !== "paragraph" || following.paraId === void 0) return void 0;
448
+ const address = this.paragraph(following.paraId);
449
+ return address?.container === paragraph.container ? address : void 0;
450
+ }
371
451
  let block = slot.block;
372
452
  let next = slot.paragraph + 1;
373
453
  while (block < this.blocks.length && next >= (this.blocks[block]?.paragraphs.length ?? 0)) {
@@ -407,39 +487,6 @@ const changedStories = ({ document, previous }) => {
407
487
  }
408
488
  return stories;
409
489
  };
410
- const preservePropertySources = ({ target, source, stories = documentStories(source), indentation = "derive" }) => {
411
- const collectParagraphs = (blocks) => {
412
- const paragraphs = [];
413
- for (const block of blocks) {
414
- if (block.type === "paragraph") {
415
- paragraphs.push(block);
416
- continue;
417
- }
418
- if (block.type !== "table") continue;
419
- for (const row of block.rows) for (const cell of row.cells) paragraphs.push(...collectParagraphs(cell.content));
420
- }
421
- return paragraphs;
422
- };
423
- for (const story of stories) {
424
- const originals = findStoryBody(source, story)?.content ?? [];
425
- const derived = findStoryBody(target, story)?.content ?? [];
426
- if (originals === derived) continue;
427
- const originalParagraphs = collectParagraphs(originals);
428
- const derivedParagraphs = collectParagraphs(derived);
429
- const paragraphs = new Map(derivedParagraphs.flatMap((paragraph) => paragraph.paraId === void 0 ? [] : [[paragraph.paraId, paragraph]]));
430
- for (const [index, original] of originalParagraphs.entries()) {
431
- const next = original.paraId === void 0 ? derivedParagraphs.at(index) : paragraphs.get(original.paraId);
432
- if (next !== void 0 && next !== original) {
433
- copyParagraphPropertySource(next, original);
434
- if (indentation === "restore") restoreParagraphIndentationProjection({
435
- target: next,
436
- source: original
437
- });
438
- }
439
- }
440
- }
441
- copyDocumentParagraphPropertySourceContract(target, source);
442
- };
443
490
  const newStoryProjectionCaches = () => ({
444
491
  blocks: new ProjectionBlockCache(),
445
492
  inline: new InlineProjectionCache(),
@@ -454,6 +501,43 @@ const holdsTextBox = (paragraph) => {
454
501
  });
455
502
  return found;
456
503
  };
504
+ /**
505
+ * The selection a publish shows, read back as addresses, with the
506
+ * transaction's text selection moved to exactly where those addresses place
507
+ * it. Undo and redo restore a selection by its addresses, so a publish must
508
+ * show the position its address gives back: one of several editor positions
509
+ * an address names (either side of a link's edge) becomes the one restoring
510
+ * gives, and a position no address names (inside a character, or where an
511
+ * unplaceable selection fell back) moves to the nearest one that has one.
512
+ */
513
+ const placeShownSelection = (transaction, projection) => {
514
+ const current = transaction.selection;
515
+ if (current instanceof TextSelection) {
516
+ const size = transaction.doc.content.size;
517
+ const nearestAddressable = (position) => {
518
+ for (let distance = 0; distance <= size; distance += 1) for (const candidate of [position - distance, position + distance]) if (candidate >= 0 && candidate <= size && projection.addressAt(candidate).isOk()) return candidate;
519
+ };
520
+ const anchor = nearestAddressable(current.anchor);
521
+ const head = nearestAddressable(current.head);
522
+ if (anchor === void 0 || head === void 0) return void 0;
523
+ const addressed = {
524
+ anchor: projection.addressAt(anchor).unwrap(),
525
+ head: projection.addressAt(head).unwrap()
526
+ };
527
+ const placed = {
528
+ anchor: projection.positionAt(addressed.anchor),
529
+ head: projection.positionAt(addressed.head)
530
+ };
531
+ if (placed.anchor.isErr() || placed.head.isErr()) return void 0;
532
+ if (placed.anchor.value !== current.anchor || placed.head.value !== current.head) transaction.setSelection(TextSelection.create(transaction.doc, placed.anchor.value, placed.head.value));
533
+ return {
534
+ type: "text",
535
+ ...addressed
536
+ };
537
+ }
538
+ const read = projection.selectionAt(transaction);
539
+ return read.isOk() ? read.value : void 0;
540
+ };
457
541
  const structureRefusal = () => new CanonicalSessionError({
458
542
  ground: { gap: CANONICAL_GAP.storyContentProjection },
459
543
  reason: "refused",
@@ -471,7 +555,7 @@ const visitBlockSources = (block, container, visit, insideSkippedContinuation) =
471
555
  visit(block, container, insideSkippedContinuation);
472
556
  return;
473
557
  }
474
- if (block.type === "blockSdt") {
558
+ if (block.type === "blockSdt" || block.type === "blockCustomXml") {
475
559
  visitSourceParagraphs(block.content, visit, insideSkippedContinuation);
476
560
  return;
477
561
  }
@@ -486,9 +570,20 @@ const visitBlockSources = (block, container, visit, insideSkippedContinuation) =
486
570
  }
487
571
  }
488
572
  };
573
+ /** The paragraphs of the text boxes a paragraph draws, those inside them included. */
574
+ const visitTextBoxSources = (paragraph, visit) => {
575
+ visitInlineContentSlots(paragraph, ({ item }) => {
576
+ if (item.type !== "run") return;
577
+ for (const content of item.content) if (content.type === "shape" && content.shape.textBody !== void 0) visitSourceParagraphs(content.shape.textBody.content, (source, container) => {
578
+ visit(source, container);
579
+ visitTextBoxSources(source, visit);
580
+ });
581
+ });
582
+ };
489
583
  const collectSources = (content, start, end, takenElsewhere) => {
490
584
  const found = {
491
585
  located: /* @__PURE__ */ new Map(),
586
+ boxed: /* @__PURE__ */ new Map(),
492
587
  idsByBlock: [],
493
588
  all: [],
494
589
  continuation: /* @__PURE__ */ new Set(),
@@ -500,6 +595,13 @@ const collectSources = (content, start, end, takenElsewhere) => {
500
595
  };
501
596
  const visit = (source, container, continuation) => {
502
597
  found.all.push(source);
598
+ visitTextBoxSources(source, (boxed, boxContent) => {
599
+ if (boxed.paraId !== void 0 && !found.boxed.has(boxed.paraId)) found.boxed.set(boxed.paraId, {
600
+ source: boxed,
601
+ container: boxContent,
602
+ top: at.top
603
+ });
604
+ });
503
605
  if (continuation) found.continuation.add(source);
504
606
  if (source.paraId === void 0) return;
505
607
  if (found.located.has(source.paraId) || takenElsewhere(source.paraId)) found.repeated = true;
@@ -540,6 +642,43 @@ var OpenComments = class {
540
642
  }
541
643
  };
542
644
  /**
645
+ * The paragraphs of a text box's editor node, addressed as its story's
646
+ * paragraphs. A paragraph the session cannot place in the box's source (one
647
+ * the conversion drew without it) gets no address, so input there refuses
648
+ * and the box keeps its source as it was.
649
+ */
650
+ const projectTextBoxParagraphs = ({ box, offset, walk, paragraphs }) => {
651
+ const open = new OpenComments([]);
652
+ const commentContext = {
653
+ rangedIds: walk.facts.rangedIds,
654
+ pointIds: walk.facts.pointIds,
655
+ openIds: open.ids
656
+ };
657
+ box.descendants((node, childOffset) => {
658
+ if (node.type.name !== "paragraph") return true;
659
+ const paraId = node.attrs["paraId"];
660
+ const located = typeof paraId === "string" ? walk.locateBoxed(paraId) : void 0;
661
+ if (typeof paraId !== "string" || located === void 0 || !walk.takeBoxed(located.source)) return false;
662
+ const inlineArgs = {
663
+ source: located.source,
664
+ paragraph: node,
665
+ pairedBookmarkIds: walk.facts.pairedBookmarkIds,
666
+ commentContext
667
+ };
668
+ const inline = walk.inline === void 0 ? projectCanonicalInline(inlineArgs) : walk.inline.project(inlineArgs);
669
+ if (inline.isOk()) paragraphs.push({
670
+ blockId: paraId,
671
+ container: located.container,
672
+ offset: offset + 1 + childOffset + 1,
673
+ inline: inline.value,
674
+ node,
675
+ source: located.source
676
+ });
677
+ passCommentMarkers(walk.markersOf(located.source), open);
678
+ return false;
679
+ });
680
+ };
681
+ /**
543
682
  * The paragraphs of the top-level node at `index`, each start from the
544
683
  * node's own, and whether each came from the story block at that index.
545
684
  */
@@ -556,6 +695,12 @@ const projectBlock = (top, index, walk) => {
556
695
  if (failure !== void 0) return false;
557
696
  if (node.type.name === "textBox") {
558
697
  if (node.attrs["_docxPlacement"] === "standalone" && node.attrs["_docxHostParagraph"] != null && !walk.claimTextBoxHost()) failure = structureRefusal();
698
+ else projectTextBoxParagraphs({
699
+ box: node,
700
+ offset,
701
+ walk,
702
+ paragraphs
703
+ });
559
704
  return false;
560
705
  }
561
706
  if (node.type.name === "blockCommentRangeBoundary") {
@@ -566,6 +711,7 @@ const projectBlock = (top, index, walk) => {
566
711
  }
567
712
  if (node.type.name !== "paragraph") return true;
568
713
  if (parent?.attrs["_omittedGridSlot"] != null) return false;
714
+ if ((parent?.type.name === "blockSdt" || parent?.type.name === "blockCustomXml") && parent.attrs["_originallyEmpty"] === true) return false;
569
715
  const paraId = node.attrs["paraId"];
570
716
  const located = typeof paraId === "string" ? walk.locate(paraId) : void 0;
571
717
  if (typeof paraId !== "string" || located === void 0) {
@@ -578,6 +724,7 @@ const projectBlock = (top, index, walk) => {
578
724
  return false;
579
725
  }
580
726
  if (located.top !== index) local = false;
727
+ passCommentMarkers(walk.positionedComments.before.get(source), walk.open);
581
728
  const inlineArgs = {
582
729
  source,
583
730
  paragraph: node,
@@ -602,6 +749,7 @@ const projectBlock = (top, index, walk) => {
602
749
  source
603
750
  });
604
751
  walk.passComments(source);
752
+ passCommentMarkers(walk.positionedComments.after.get(source), walk.open);
605
753
  return false;
606
754
  };
607
755
  if (visit(top, 0, null) && top.content.size > 0) top.descendants((node, offset, parent) => visit(node, offset + 1, parent));
@@ -611,22 +759,28 @@ const projectBlock = (top, index, walk) => {
611
759
  local
612
760
  });
613
761
  };
614
- /** Opens and closes the ranges a paragraph's markers start and end. */
615
- const commentPasser = (markersOf, open) => (paragraph) => {
616
- for (const item of markersOf(paragraph)) {
762
+ const passCommentMarkers = (markers, open) => {
763
+ for (const item of markers ?? []) {
617
764
  if (item.type === "commentRangeStart") open.ids.add(item.id);
618
765
  if (item.type === "commentRangeEnd") open.ids.delete(item.id);
619
766
  }
620
767
  };
768
+ /** Opens and closes the ranges a paragraph's markers start and end. */
769
+ const commentPasser = (markersOf, open) => (paragraph) => passCommentMarkers(markersOf(paragraph), open);
621
770
  /** Every paragraph's address, walking every top-level node. */
622
771
  const projectEveryBlock = ({ doc, content, story, markersOf, inline }) => {
623
772
  const pairedBookmarkIds = collectPairedBookmarkIds(content);
624
773
  const rangedIds = /* @__PURE__ */ new Set();
625
774
  const referencedIds = /* @__PURE__ */ new Set();
626
- visitCommentMarkerItems(content, markersOf, (item) => {
627
- if (item.type === "commentRangeStart") rangedIds.add(item.id);
628
- if (item.type === "commentReference") referencedIds.add(item.id);
629
- });
775
+ const commentWalk = {
776
+ markersOf,
777
+ visit(item) {
778
+ if (item.type === "commentRangeStart") rangedIds.add(item.id);
779
+ if (item.type === "commentReference") referencedIds.add(item.id);
780
+ }
781
+ };
782
+ visitCommentMarkerItems(content, commentWalk);
783
+ visitSourceParagraphs(content, (source) => visitTextBoxSources(source, (boxed) => visitCommentMarkerItems([boxed], commentWalk)));
630
784
  const facts = {
631
785
  pairedBookmarkIds,
632
786
  rangedIds,
@@ -642,15 +796,24 @@ const projectEveryBlock = ({ doc, content, story, markersOf, inline }) => {
642
796
  const continuationSources = found.continuation;
643
797
  const idsByBlock = found.idsByBlock;
644
798
  const projectedSources = /* @__PURE__ */ new Set();
799
+ const projectedBoxed = /* @__PURE__ */ new Set();
645
800
  const orderedSources = [...allSources];
646
801
  const sourceOrder = new Map(orderedSources.map((source, index) => [source, index]));
647
802
  const textBoxHosts = /* @__PURE__ */ new Set();
803
+ const positionedComments = positionedCommentGaps(content, continuationSources);
648
804
  let nextSource = 0;
649
805
  const walk = {
650
806
  facts,
651
807
  open,
652
808
  content,
653
809
  locate: (paraId) => sources.get(paraId),
810
+ locateBoxed: (paraId) => found.boxed.get(paraId),
811
+ takeBoxed: (source) => {
812
+ if (projectedBoxed.has(source)) return false;
813
+ projectedBoxed.add(source);
814
+ return true;
815
+ },
816
+ markersOf,
654
817
  claimTextBoxHost: () => {
655
818
  reusable = false;
656
819
  let index = nextSource;
@@ -659,7 +822,9 @@ const projectEveryBlock = ({ doc, content, story, markersOf, inline }) => {
659
822
  if (host === void 0 || !holdsTextBox(host)) return false;
660
823
  textBoxHosts.add(host);
661
824
  nextSource = index + 1;
825
+ passCommentMarkers(positionedComments.before.get(host), open);
662
826
  passComments(host);
827
+ passCommentMarkers(positionedComments.after.get(host), open);
663
828
  return true;
664
829
  },
665
830
  take: (source) => {
@@ -669,6 +834,7 @@ const projectEveryBlock = ({ doc, content, story, markersOf, inline }) => {
669
834
  return true;
670
835
  },
671
836
  passComments,
837
+ positionedComments,
672
838
  inline
673
839
  };
674
840
  const blocks = [];
@@ -727,11 +893,19 @@ const projectChangedBlocks = (previous, { doc, content, story, markersOf, inline
727
893
  const continuationSources = found.continuation;
728
894
  const open = new OpenComments(before[start - 1]?.openAfter ?? []);
729
895
  const projectedSources = /* @__PURE__ */ new Set();
896
+ const projectedBoxed = /* @__PURE__ */ new Set();
730
897
  const walk = {
731
898
  facts: previous.facts,
732
899
  open,
733
900
  content,
734
901
  locate: (paraId) => sources.get(paraId),
902
+ locateBoxed: (paraId) => found.boxed.get(paraId),
903
+ takeBoxed: (source) => {
904
+ if (projectedBoxed.has(source)) return false;
905
+ projectedBoxed.add(source);
906
+ return true;
907
+ },
908
+ markersOf,
735
909
  claimTextBoxHost: () => false,
736
910
  take: (source) => {
737
911
  if (projectedSources.has(source)) return false;
@@ -739,6 +913,7 @@ const projectChangedBlocks = (previous, { doc, content, story, markersOf, inline
739
913
  return true;
740
914
  },
741
915
  passComments: commentPasser(markersOf, open),
916
+ positionedComments: positionedCommentGaps(content.slice(start, newEnd), continuationSources),
742
917
  inline
743
918
  };
744
919
  const window = [];
@@ -784,10 +959,11 @@ const project = ({ document, styles, story = OP_STORIES.MAIN, caches, previous }
784
959
  const body = findStoryBody(document, story);
785
960
  if (!body) return refuse("The canonical story no longer exists.");
786
961
  const currentStyles = Object.hasOwn(document.package, "styles") ? document.package.styles : styles;
787
- const options = {
788
- ...currentStyles == null ? {} : { styles: currentStyles },
789
- ...document.package.theme === void 0 ? {} : { theme: document.package.theme }
790
- };
962
+ const options = storyConversionOptions({
963
+ styles: currentStyles,
964
+ theme: document.package.theme,
965
+ numbering: document.package.numbering
966
+ });
791
967
  const converted = Result.try({
792
968
  try: () => {
793
969
  if (story === OP_STORIES.MAIN) return toProseDoc(document, caches === void 0 ? options : {
@@ -840,6 +1016,8 @@ const intentStory = (intent) => {
840
1016
  const UNDO_GROUP_WINDOW_MS = 500;
841
1017
  const samePosition = (left, right) => sameStory(left.story, right.story) && left.blockId === right.blockId && left.offset === right.offset && (left.zeroWidthBefore ?? 0) === (right.zeroWidthBefore ?? 0);
842
1018
  const sameSelection = (left, right) => left.type === right.type && samePosition(left.anchor, right.anchor) && samePosition(left.head, right.head);
1019
+ /** The ops that undo `group`, applied to the document it left. */
1020
+ const undoOpsOf = (group) => group.undo.type === "replayed" ? group.undo.inverse : group.entries.toReversed().flatMap((entry) => entry.inverse);
843
1021
  const continuesGroup = (previous, next) => {
844
1022
  switch (next.semantic) {
845
1023
  case "typing":
@@ -861,6 +1039,27 @@ const isCanonicalProjectionTransaction = (transaction, session) => {
861
1039
  const authorization = authorizedProjections.get(transaction);
862
1040
  return authorization?.session === session && authorization.version === session.version && transaction.doc.eq(authorization.doc);
863
1041
  };
1042
+ /** A node's shape without its text, for a refusal that names a change. */
1043
+ const nodeShapeOf = (node) => JSON.stringify({
1044
+ type: node.type.name,
1045
+ attrs: node.attrs,
1046
+ children: node.content.content.map((child) => ({
1047
+ type: child.type.name,
1048
+ marks: child.marks.map((mark) => mark.toJSON())
1049
+ }))
1050
+ });
1051
+ /**
1052
+ * Where an appended transaction moved the published document off the
1053
+ * projection: the innermost node holding the first difference, by its type,
1054
+ * attributes and children's marks, so the refusal carries no document text.
1055
+ */
1056
+ const projectionChangeOf = (projected, published) => {
1057
+ const at = projected.content.findDiffStart(published.content);
1058
+ if (at === null) return "a plugin appended a document change";
1059
+ const expected = projected.resolve(Math.min(at, projected.content.size));
1060
+ const actual = published.resolve(Math.min(at, published.content.size));
1061
+ return `a plugin changed the ${expected.parent.type.name} in body block ${expected.index(0)} from ${nodeShapeOf(expected.parent)} to ${nodeShapeOf(actual.parent)}`;
1062
+ };
864
1063
  /** The model publishes only after PM and every plugin accept its exact projection. */
865
1064
  const publishCanonicalProjection = ({ state, commit, session }) => {
866
1065
  if (!isCanonicalProjectionTransaction(commit.transaction, session)) return refuse("The staged canonical projection is unauthorized.");
@@ -874,11 +1073,22 @@ const publishCanonicalProjection = ({ state, commit, session }) => {
874
1073
  });
875
1074
  if (applied.isErr()) return applied;
876
1075
  const staged = applied.value;
877
- if (!staged.transactions.includes(commit.transaction) || !staged.state.doc.eq(commit.projection.doc) || staged.transactions.some((transaction) => transaction.docChanged && !isCanonicalProjectionTransaction(transaction, session))) return refuse("A plugin refused or changed the canonical projection.");
1076
+ if (!staged.transactions.includes(commit.transaction)) return refuse("A plugin refused or changed the canonical projection: a plugin filtered the projection transaction.");
1077
+ if (!staged.state.doc.eq(commit.projection.doc) || staged.transactions.some((transaction) => transaction.docChanged && !isCanonicalProjectionTransaction(transaction, session))) return refuse(`A plugin refused or changed the canonical projection: ${projectionChangeOf(commit.projection.doc, staged.state.doc)}.`);
878
1078
  const published = commit.publish();
879
1079
  if (published.isErr()) return published;
880
1080
  return Result.ok(staged);
881
1081
  };
1082
+ /**
1083
+ * How a change is admitted against content-control locks. An edit is judged
1084
+ * on its result. A restage rebuilds a pending suggestion recorded before the
1085
+ * save: no new edit, so a lock that arrived since does not refuse it, while
1086
+ * resolving the suggestion stays under the lock.
1087
+ */
1088
+ const CANONICAL_ADMISSION = {
1089
+ edit: "edit",
1090
+ restage: "restage"
1091
+ };
882
1092
  const storyProjectionKey = (story) => {
883
1093
  switch (story.kind) {
884
1094
  case "header":
@@ -888,6 +1098,55 @@ const storyProjectionKey = (story) => {
888
1098
  default: return panic(`Unknown canonical story ${story}`);
889
1099
  }
890
1100
  };
1101
+ const sameStoryParts = (left, right) => ["headers", "footers"].every((kind) => canonicalJson([...left.package[kind]?.keys() ?? []].toSorted()) === canonicalJson([...right.package[kind]?.keys() ?? []].toSorted()));
1102
+ /**
1103
+ * What a save baseline keeps of the parsed saved package: its buffer, the
1104
+ * capture of its body, and its headers and footers with their verbatim
1105
+ * sources. The body content itself is not kept.
1106
+ */
1107
+ const saveBaselineOf = (saved, buffer) => {
1108
+ const baseline = {
1109
+ originalBuffer: buffer,
1110
+ package: {
1111
+ document: {
1112
+ ...saved.package.document,
1113
+ content: []
1114
+ },
1115
+ ...saved.package.headers === void 0 ? {} : { headers: saved.package.headers },
1116
+ ...saved.package.footers === void 0 ? {} : { footers: saved.package.footers }
1117
+ }
1118
+ };
1119
+ copyHeaderFooterBaselineHandles(baseline, saved);
1120
+ return baseline;
1121
+ };
1122
+ /** Every note paragraph of `document`, in its text boxes too, by its id's key. */
1123
+ const noteParagraphsOf = (document) => {
1124
+ const paragraphs = /* @__PURE__ */ new Map();
1125
+ const notes = [...(document.package.footnotes ?? []).map(({ id, content }) => ({
1126
+ story: {
1127
+ kind: "footnote",
1128
+ id
1129
+ },
1130
+ content
1131
+ })), ...(document.package.endnotes ?? []).map(({ id, content }) => ({
1132
+ story: {
1133
+ kind: "endnote",
1134
+ id
1135
+ },
1136
+ content
1137
+ }))];
1138
+ for (const { story, content } of notes) for (const { paragraph } of paragraphsThroughTextBoxes(document, story)) if (paragraph.paraId !== void 0) paragraphs.set(paragraph.paraId.toUpperCase(), {
1139
+ paragraph,
1140
+ note: content
1141
+ });
1142
+ return paragraphs;
1143
+ };
1144
+ /** Every paragraph of `document`, in every story and text box, by its id's key. */
1145
+ const storyParagraphsOf = (document) => {
1146
+ const paragraphs = /* @__PURE__ */ new Map();
1147
+ for (const story of documentStories(document)) for (const { paragraph } of paragraphsThroughTextBoxes(document, story)) if (paragraph.paraId !== void 0) paragraphs.set(paragraph.paraId.toUpperCase(), paragraph);
1148
+ return paragraphs;
1149
+ };
891
1150
  /** Immutable model authority with a journal staged independently of the PM view. */
892
1151
  var CanonicalSession = class {
893
1152
  currentDocument;
@@ -895,32 +1154,75 @@ var CanonicalSession = class {
895
1154
  sourceBlockIds;
896
1155
  currentVersion = 0;
897
1156
  saveTouched = /* @__PURE__ */ new Set();
1157
+ /** Every paragraph an edit touched since the session opened, undo and redo included. */
1158
+ touchedSinceOpen = /* @__PURE__ */ new Set();
1159
+ /** The document as the session opened it, which note parts are written against. */
1160
+ openedDocument;
898
1161
  saveStructure = "stable";
1162
+ /**
1163
+ * The package a save wrote, parsed, once it is the baseline later saves
1164
+ * patch against: `saveTouched` and `saveStructure` then count from its
1165
+ * version. Holding only the latest releases every earlier one.
1166
+ */
1167
+ saveBaseline = null;
1168
+ /** A save whose package is being read to become the baseline. */
1169
+ pendingSaveBaseline = null;
899
1170
  allocateIntentIds = createEditorIntentIdAllocator();
900
1171
  mode = { type: "editing" };
901
1172
  allocatedBlockIds = /* @__PURE__ */ new Set();
902
1173
  nextBlockId = 1;
1174
+ leased;
903
1175
  sourceOwners = /* @__PURE__ */ new Map();
904
1176
  storyProjections = /* @__PURE__ */ new Map();
905
1177
  currentSelection = null;
1178
+ /**
1179
+ * The selection the editor of each header, footer or note last showed,
1180
+ * keyed by story. Its editor records it whenever it changes, an edit in the
1181
+ * story commits it, and every peer's edit moves it with the text, as the
1182
+ * body's selection moves.
1183
+ */
1184
+ storySelections = /* @__PURE__ */ new Map();
906
1185
  applied = [];
907
1186
  groupingBoundary = 0;
908
1187
  lifecycle = { type: "committed" };
909
1188
  undone = [];
1189
+ historyDropListeners = /* @__PURE__ */ new Set();
1190
+ committedListeners = /* @__PURE__ */ new Set();
1191
+ newOpId;
910
1192
  styles;
911
1193
  sourceRestores;
1194
+ /**
1195
+ * The ids of the paragraphs the session added to the stories it read in its
1196
+ * own form (a story's closing paragraph), which no package names: a reader
1197
+ * reports them as positional.
1198
+ */
1199
+ get sourceMintedParaIds() {
1200
+ return new Set(this.sourceRestores.flatMap(({ minted }) => minted));
1201
+ }
1202
+ /** Notes the opened package held without a reference: content, kept on save. */
1203
+ heldUnreferencedNotes;
1204
+ /** Headers and footers a section of the opened package referenced. */
1205
+ referencedHeaderFootersAtOpen;
1206
+ /** {@link retiredHeaderFooters} of the document it was read from. */
1207
+ retiredHeaderFootersCache;
912
1208
  /** What earlier projections converted, reused by every later one. */
913
1209
  caches;
914
- constructor({ document, projection, styles, sourceRestores = [], caches }) {
1210
+ constructor({ document, projection, styles, sourceRestores = [], caches, idLease, newOpId = () => crypto.randomUUID() }) {
1211
+ this.newOpId = newOpId;
1212
+ this.leased = idLease === void 0 ? void 0 : new CanonicalIdLease(idLease, document);
915
1213
  this.sourceRestores = sourceRestores;
916
1214
  this.caches = caches;
1215
+ this.heldUnreferencedNotes = heldUnreferencedNotes(document);
1216
+ this.referencedHeaderFootersAtOpen = referencedHeaderFooters(document);
1217
+ this.openedDocument = document;
917
1218
  this.currentDocument = document;
918
1219
  this.currentProjection = projection;
919
- this.sourceBlockIds = new Set(packageParagraphIds(document.package));
920
- for (const blockId of packageParagraphIds(document.package)) this.allocatedBlockIds.add(blockId.toUpperCase());
1220
+ const blockIds = packageParagraphIds(document.package);
1221
+ this.sourceBlockIds = new Set(blockIds);
1222
+ for (const blockId of blockIds) this.allocatedBlockIds.add(blockId.toUpperCase());
921
1223
  this.advanceBlockId();
922
1224
  this.styles = styles == null ? styles : structuredClone(styles);
923
- this.rememberSources(document);
1225
+ this.rememberSources(document.package.document.content);
924
1226
  }
925
1227
  /** Render only the committed comment projection while provisional IME blocks document snapshots. */
926
1228
  getCommittedComments() {
@@ -936,10 +1238,30 @@ var CanonicalSession = class {
936
1238
  hasStyle(styleId) {
937
1239
  return (this.styles ?? this.currentDocument.package.styles)?.styles.some((style) => style.styleId === styleId) ?? false;
938
1240
  }
1241
+ /** How a replacement in the current mode removes the words it changes. */
1242
+ replacementRemoval() {
1243
+ switch (this.mode.type) {
1244
+ case "editing": return {
1245
+ type: "direct",
1246
+ comments: this.currentDocument.package.document.comments ?? []
1247
+ };
1248
+ case "suggesting": return { type: "tracked" };
1249
+ default: {
1250
+ const unhandled = this.mode;
1251
+ return panic(`Unknown canonical session mode ${String(unhandled)}`);
1252
+ }
1253
+ }
1254
+ }
939
1255
  advanceBlockId() {
940
1256
  while (this.allocatedBlockIds.has(this.nextBlockId.toString(16).padStart(8, "0").toUpperCase())) this.nextBlockId += 1;
941
1257
  }
942
1258
  freshBlockId() {
1259
+ if (this.leased !== void 0) {
1260
+ const fresh = this.freshBlockIds([1]);
1261
+ if (fresh.isErr()) return fresh;
1262
+ const id = fresh.value[0]?.[0];
1263
+ return id === void 0 ? refuse("The paragraph identity lease is exhausted.") : Result.ok(id);
1264
+ }
943
1265
  if (this.nextBlockId > 2147483647) return refuse("The paragraph identity space is exhausted.");
944
1266
  return Result.ok(this.nextBlockId.toString(16).padStart(8, "0").toUpperCase());
945
1267
  }
@@ -951,6 +1273,16 @@ var CanonicalSession = class {
951
1273
  freshBlockIds(counts) {
952
1274
  const total = counts.reduce((sum, count) => sum + count, 0);
953
1275
  const ids = [];
1276
+ if (this.leased !== void 0) {
1277
+ const leased = freshLeasedIds({
1278
+ lease: this.leased.lease,
1279
+ kind: ID_LEASE_KINDS.PARAGRAPH,
1280
+ count: total,
1281
+ taken: (id) => this.allocatedBlockIds.has(formatParaId(id))
1282
+ });
1283
+ if (leased.length < total) return refuse("The paragraph identity lease is exhausted.");
1284
+ ids.push(...leased.map(formatParaId));
1285
+ }
954
1286
  for (let candidate = this.nextBlockId; ids.length < total; candidate += 1) {
955
1287
  if (candidate > 2147483647) return refuse("The paragraph identity space is exhausted.");
956
1288
  const id = candidate.toString(16).padStart(8, "0").toUpperCase();
@@ -965,18 +1297,22 @@ var CanonicalSession = class {
965
1297
  return Result.ok(groups);
966
1298
  }
967
1299
  intentMode(document, intent) {
1300
+ const leased = this.leased === void 0 ? {} : { idLease: this.leased.lease };
968
1301
  if (this.mode.type === "editing" && !this.intentNeedsIdentityIds(document, intent)) return {
969
1302
  type: "editing",
970
- reservedBlockIds: this.allocatedBlockIds
1303
+ reservedBlockIds: this.allocatedBlockIds,
1304
+ ...leased
971
1305
  };
972
- const ids = this.allocateIntentIds(document, intent);
1306
+ const ids = this.allocateIntentIds(document, intent, this.leased?.lease);
973
1307
  return this.mode.type === "editing" ? {
974
1308
  type: "editing",
975
1309
  newIds: ids.newIds,
976
- reservedBlockIds: this.allocatedBlockIds
1310
+ reservedBlockIds: this.allocatedBlockIds,
1311
+ ...leased
977
1312
  } : {
978
1313
  type: "suggesting",
979
1314
  reservedBlockIds: this.allocatedBlockIds,
1315
+ ...leased,
980
1316
  revision: {
981
1317
  id: ids.revisionId,
982
1318
  author: this.mode.author,
@@ -1028,8 +1364,9 @@ var CanonicalSession = class {
1028
1364
  return paragraph !== void 0 && hasIdentity(paragraph);
1029
1365
  });
1030
1366
  }
1031
- rememberSources(document) {
1032
- for (const block of document.package.document.content) if (block.type === "paragraph" && block.paraId !== void 0) this.sourceOwners.set(block.paraId, block);
1367
+ /** Record each paragraph among `blocks` as the owner of its id. */
1368
+ rememberSources(blocks) {
1369
+ for (const block of blocks) if (block.type === "paragraph" && block.paraId !== void 0) this.sourceOwners.set(block.paraId, block);
1033
1370
  }
1034
1371
  get document() {
1035
1372
  if (this.isComposing) throw new CanonicalSessionError({
@@ -1039,20 +1376,147 @@ var CanonicalSession = class {
1039
1376
  });
1040
1377
  return this.currentDocument;
1041
1378
  }
1379
+ /**
1380
+ * The `header:<rId>` and `footer:<rId>` parts a resolution retired: the
1381
+ * opened package referenced them and no section names them now. A save
1382
+ * drops them; a reader lists them no more.
1383
+ */
1384
+ retiredHeaderFooters() {
1385
+ const document = this.currentDocument;
1386
+ if (this.retiredHeaderFootersCache?.document !== document) this.retiredHeaderFootersCache = {
1387
+ document,
1388
+ retired: retiredHeaderFooters(document, this.referencedHeaderFootersAtOpen)
1389
+ };
1390
+ return this.retiredHeaderFootersCache.retired;
1391
+ }
1042
1392
  captureSaveSnapshot() {
1043
1393
  if (this.isComposing) throw new CanonicalSessionError({
1044
1394
  ground: { gap: CANONICAL_GAP.save },
1045
1395
  reason: "refused",
1046
1396
  message: "Composition must finish before saving the canonical document."
1047
1397
  });
1048
- const retainedBlockIdKeys = new Set([...this.sourceBlockIds, ...packageParagraphIds(this.currentDocument.package)].map((blockId) => blockId.toUpperCase()));
1398
+ const retainedBlockIdKeys = new Set([
1399
+ ...this.sourceBlockIds,
1400
+ ...this.saveBaseline?.blockIds ?? [],
1401
+ ...packageParagraphIds(this.currentDocument.package)
1402
+ ].map((blockId) => blockId.toUpperCase()));
1403
+ const document = withUneditedSourceRestored(cloneDocumentWithParagraphPropertySources(this.currentDocument), this.sourceRestores);
1404
+ const noteParagraphs = this.noteParagraphChanges();
1049
1405
  return {
1050
- document: withUneditedSourceRestored(cloneDocumentWithParagraphPropertySources(this.currentDocument), this.sourceRestores),
1406
+ document,
1407
+ ...this.saveBaseline === null ? {} : { saveBaseline: {
1408
+ buffer: this.saveBaseline.buffer,
1409
+ document: this.saveBaseline.document
1410
+ } },
1051
1411
  version: this.currentVersion,
1052
1412
  changedBlockIds: [...this.saveTouched].filter((blockId) => retainedBlockIdKeys.has(blockId.toUpperCase())),
1053
- structure: this.saveStructure
1413
+ structure: this.saveStructure,
1414
+ heldUnreferencedNotes: this.heldUnreferencedNotes,
1415
+ referencedHeaderFootersAtOpen: this.referencedHeaderFootersAtOpen,
1416
+ noteParagraphs,
1417
+ restoredSinceSource: this.paragraphsRestoredSinceSource(new Set(noteParagraphs.changedSinceSource.map((id) => id.toUpperCase())))
1054
1418
  };
1055
1419
  }
1420
+ /**
1421
+ * The paragraphs an edit touched since the session opened whose content is
1422
+ * again what the opened document held, between the same neighbours: an
1423
+ * edit and its undo, or a change and its rejection, left them as they were.
1424
+ * A paragraph added or removed beside one is placed by it, so it stays a
1425
+ * change, and so does a note paragraph in `changedNotes`, whose note
1426
+ * changed around it.
1427
+ */
1428
+ paragraphsRestoredSinceSource(changedNotes) {
1429
+ if (this.touchedSinceOpen.size === 0) return [];
1430
+ const current = storyParagraphsOf(this.currentDocument);
1431
+ const opened = storyParagraphsOf(this.openedDocument);
1432
+ const neighbours = (paragraphs) => {
1433
+ const ids = [...paragraphs.keys()];
1434
+ return new Map(ids.map((id, index) => [id, `${ids[index - 1] ?? ""}|${ids[index + 1] ?? ""}`]));
1435
+ };
1436
+ const currentNeighbours = neighbours(current);
1437
+ const openedNeighbours = neighbours(opened);
1438
+ return [...this.touchedSinceOpen].filter((id) => {
1439
+ const key = id.toUpperCase();
1440
+ const now = current.get(key);
1441
+ const then = opened.get(key);
1442
+ return now !== void 0 && then !== void 0 && !changedNotes.has(key) && currentNeighbours.get(key) === openedNeighbours.get(key) && (now === then || canonicalJson(now) === canonicalJson(then));
1443
+ });
1444
+ }
1445
+ /**
1446
+ * The note paragraphs touched since the save baseline, and those that
1447
+ * differ from the opened document among the ones touched since it opened:
1448
+ * a note an edit and its undo left as it was is no change. A paragraph the
1449
+ * edit left as it was still counts when its note changed around it (cells
1450
+ * merged, a row's or cell's revision), which no paragraph records.
1451
+ */
1452
+ noteParagraphChanges() {
1453
+ if (this.touchedSinceOpen.size === 0) return {
1454
+ touched: [],
1455
+ changedSinceSource: []
1456
+ };
1457
+ const current = noteParagraphsOf(this.currentDocument);
1458
+ const opened = noteParagraphsOf(this.openedDocument);
1459
+ const isNote = (id) => current.has(id.toUpperCase()) || opened.has(id.toUpperCase());
1460
+ const noteJson = /* @__PURE__ */ new Map();
1461
+ const jsonOf = (note) => {
1462
+ const known = noteJson.get(note);
1463
+ if (known !== void 0) return known;
1464
+ const json = canonicalJson(note);
1465
+ noteJson.set(note, json);
1466
+ return json;
1467
+ };
1468
+ return {
1469
+ touched: [...this.saveTouched].filter(isNote),
1470
+ changedSinceSource: [...this.touchedSinceOpen].filter((id) => {
1471
+ const now = current.get(id.toUpperCase());
1472
+ const then = opened.get(id.toUpperCase());
1473
+ if (now === void 0 || then === void 0) return now !== then;
1474
+ if (now.paragraph !== then.paragraph && canonicalJson(now.paragraph) !== canonicalJson(then.paragraph)) return true;
1475
+ return now.note !== then.note && jsonOf(now.note) !== jsonOf(then.note);
1476
+ })
1477
+ };
1478
+ }
1479
+ /**
1480
+ * Start making the package saved at `version` the baseline later saves
1481
+ * patch against. Edits from now on are counted from that version too, so
1482
+ * {@link completeSaveBaseline} can swap the counts without losing one.
1483
+ * Refused unless `version` is the current one.
1484
+ */
1485
+ beginSaveBaseline(version) {
1486
+ if (this.isComposing || version !== this.currentVersion) return false;
1487
+ this.pendingSaveBaseline = {
1488
+ version,
1489
+ blockIds: packageParagraphIds(this.currentDocument.package),
1490
+ touched: /* @__PURE__ */ new Set(),
1491
+ structure: "stable"
1492
+ };
1493
+ return true;
1494
+ }
1495
+ /**
1496
+ * Make `saved`, the package written at `version` as parsed, the baseline:
1497
+ * later saves patch it and count changes from that version, and an undo
1498
+ * past it counts as a change like any other edit. Declined, keeping the
1499
+ * previous baseline and its counts, when a later save started, or when
1500
+ * `saved` does not hold the body paragraphs the session held at `version`
1501
+ * in the same order, or the same headers and footers.
1502
+ */
1503
+ completeSaveBaseline(version, saved) {
1504
+ const pending = this.pendingSaveBaseline;
1505
+ if (pending?.version !== version) return false;
1506
+ this.pendingSaveBaseline = null;
1507
+ const blockIds = packageParagraphIds(saved.package);
1508
+ const buffer = saved.originalBuffer;
1509
+ if (buffer === void 0 || getDocumentSourceBaseline(saved).type !== "captured" || blockIds.length !== pending.blockIds.length || blockIds.some((blockId, index) => blockId.toUpperCase() !== pending.blockIds[index]?.toUpperCase()) || !sameStoryParts(saved, this.currentDocument)) return false;
1510
+ this.saveBaseline = {
1511
+ version,
1512
+ blockIds,
1513
+ buffer,
1514
+ document: saveBaselineOf(saved, buffer)
1515
+ };
1516
+ this.saveTouched = pending.touched;
1517
+ this.saveStructure = pending.structure;
1518
+ return true;
1519
+ }
1056
1520
  get projection() {
1057
1521
  return this.currentProjection;
1058
1522
  }
@@ -1066,10 +1530,56 @@ var CanonicalSession = class {
1066
1530
  get selection() {
1067
1531
  return this.currentSelection;
1068
1532
  }
1533
+ /**
1534
+ * Record the selection the editor of a header, footer or note shows, so a
1535
+ * peer's edit to the story moves it with the text (`storySelection`). The
1536
+ * state must show the story's current projection.
1537
+ */
1538
+ recordStorySelection(state, story) {
1539
+ const projected = this.projectStory(story);
1540
+ if (projected.isErr()) return projected;
1541
+ const projection = projected.value;
1542
+ if (state.doc !== projection.doc && !state.doc.eq(projection.doc)) return refuse("The story editor shows a stale canonical projection.");
1543
+ const selection = projection.selectionAt(state);
1544
+ if (selection.isErr()) {
1545
+ this.storySelections.delete(storyProjectionKey(story));
1546
+ return selection;
1547
+ }
1548
+ this.storySelections.set(storyProjectionKey(story), selection.value);
1549
+ return Result.ok(void 0);
1550
+ }
1551
+ /**
1552
+ * The selection the editor of `story` last recorded or committed, moved
1553
+ * over every peer's edit since; null before its editor recorded one.
1554
+ */
1555
+ storySelection(story) {
1556
+ return this.storySelections.get(storyProjectionKey(story)) ?? null;
1557
+ }
1069
1558
  /** Every paragraph identity this session has read or minted, live or retired. */
1070
1559
  get reservedBlockIds() {
1071
1560
  return this.allocatedBlockIds;
1072
1561
  }
1562
+ /** The ids this session may still mint, when it holds a lease. */
1563
+ get idLease() {
1564
+ return this.leased?.lease;
1565
+ }
1566
+ /**
1567
+ * Take the lease a room granted a session opened before it joined: from
1568
+ * then on every id it mints comes from the lease. Only an unedited session
1569
+ * without a lease takes one.
1570
+ */
1571
+ adoptIdLease(lease) {
1572
+ if (this.leased !== void 0) return refuse("The session already holds an id lease.");
1573
+ if (this.currentVersion !== 0) return refuse("The session was edited before it took an id lease.");
1574
+ this.leased = new CanonicalIdLease(lease, this.currentDocument);
1575
+ return Result.ok(void 0);
1576
+ }
1577
+ /** Add blocks the authority granted; ids this session already minted stay spent. */
1578
+ extendIdLease(lease) {
1579
+ if (this.leased === void 0) return refuse("The session was created without an id lease.");
1580
+ this.leased.extend(lease);
1581
+ return Result.ok(void 0);
1582
+ }
1073
1583
  get version() {
1074
1584
  return this.currentVersion;
1075
1585
  }
@@ -1107,14 +1617,19 @@ var CanonicalSession = class {
1107
1617
  const checked = this.checkState(state, projection);
1108
1618
  if (checked.isErr()) return checked;
1109
1619
  if (!Number.isFinite(time)) return refuse("The input time is invalid.");
1110
- if (from > to || hasIllegalXmlCharacters(text) || /[\t\r\n]/u.test(text)) return refuse("Canonical input accepts a well-formed text replacement.");
1620
+ if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to > projection.doc.content.size || from > to || hasIllegalXmlCharacters(text) || /[\t\r\n]/u.test(text)) return refuse("Canonical input accepts a well-formed text replacement.");
1111
1621
  if (from === to && text.length === 0) return noChange("The input makes no text change.");
1112
1622
  const replacesStructuralSelection = state.selection instanceof AllSelection && from === state.selection.from && to === state.selection.to;
1113
1623
  if (state.selection instanceof CellSelection) {
1114
1624
  if (from !== state.selection.from || to !== state.selection.to) return refuse("A replacement range cannot partially address a cell selection.");
1625
+ const ranges = canonicalCellSelectionRanges(state.selection);
1626
+ const firstRange = ranges.at(0);
1627
+ const lastRange = ranges.at(-1);
1628
+ if (firstRange === void 0 || lastRange === void 0) return refuse("The selected cells contain no editable text.");
1115
1629
  const intents = [];
1630
+ const commentChanges = [];
1116
1631
  let first = true;
1117
- for (const range of canonicalCellSelectionRanges(state.selection)) {
1632
+ for (const range of ranges) {
1118
1633
  const edges = projection.rangeEdgesAt(range.from, range.to);
1119
1634
  const cellFrom = projection.inputAddressAt(range.from, edges.start);
1120
1635
  if (cellFrom.isErr()) return cellFrom;
@@ -1126,8 +1641,23 @@ var CanonicalSession = class {
1126
1641
  to: cellTo.value,
1127
1642
  text: first ? text : ""
1128
1643
  });
1644
+ commentChanges.push({
1645
+ from: range.from,
1646
+ to: range.to,
1647
+ text: first ? text : "",
1648
+ markers: edges.start === "beforeMarkers" || edges.end === "afterMarkers" ? "selected" : "retained"
1649
+ });
1129
1650
  first = false;
1130
1651
  }
1652
+ if (text !== "" && !preservesReplacementCommentAlignment({
1653
+ doc: state.doc,
1654
+ source: {
1655
+ from: firstRange.from,
1656
+ to: lastRange.to
1657
+ },
1658
+ changes: commentChanges,
1659
+ removal: this.replacementRemoval()
1660
+ })) return refuseUnder({ gap: CANONICAL_GAP.commentReplacementAlignment }, "Canonical replacement cannot preserve the aligned comment ranges.");
1131
1661
  return this.prepareIntents(state, {
1132
1662
  intents,
1133
1663
  semantic
@@ -1145,17 +1675,33 @@ var CanonicalSession = class {
1145
1675
  if (start.isErr()) return start;
1146
1676
  const end = inputFrom === inputTo && editCaret !== void 0 ? Result.ok(editCaret) : projection.inputAddressAt(inputTo, edges.end);
1147
1677
  if (end.isErr()) return end;
1678
+ if (inputFrom < inputTo && text !== "") {
1679
+ const retirement = planWholeParagraphReplacement({
1680
+ document: this.currentDocument,
1681
+ from: start.value,
1682
+ to: end.value,
1683
+ suggesting: this.mode.type === "suggesting" ? { author: this.mode.author } : void 0
1684
+ });
1685
+ if (retirement.isErr()) return refuse(retirement.error.message);
1686
+ if (!preservesReplacementCommentAlignment({
1687
+ doc: state.doc,
1688
+ retiredCommentIds: retirement.value?.commentIds,
1689
+ removal: this.replacementRemoval(),
1690
+ source: {
1691
+ from: inputFrom,
1692
+ to: inputTo
1693
+ },
1694
+ changes: [{
1695
+ from: inputFrom,
1696
+ to: inputTo,
1697
+ text,
1698
+ markers: edges.start === "beforeMarkers" || edges.end === "afterMarkers" ? "selected" : "retained"
1699
+ }]
1700
+ })) return refuseUnder({ gap: CANONICAL_GAP.commentReplacementAlignment }, "Canonical replacement cannot preserve the aligned comment ranges.");
1701
+ }
1148
1702
  const preSelection = projection.selectionAt(state);
1149
1703
  if (preSelection.isErr()) return preSelection;
1150
- const innerEdge = (position, side) => {
1151
- const resolved = state.doc.resolve(position);
1152
- return resolved.parent.type.name === "sdt" && resolved.parentOffset === (side === "start" ? 0 : resolved.parent.content.size);
1153
- };
1154
- const inside = {
1155
- ...innerEdge(inputFrom, "start") ? { start: true } : {},
1156
- ...innerEdge(inputTo, "end") ? { end: true } : {}
1157
- };
1158
- if (this.mode.type === "suggesting" && text.length > 0 && inside.start === true && inside.end === true && state.doc.resolve(inputFrom).parent === state.doc.resolve(inputTo).parent) return refuse("A suggestion over a content control's whole text is unavailable in this session.");
1704
+ const inside = controlEdgesAt(state.doc, inputFrom, inputTo);
1159
1705
  const intent = {
1160
1706
  type: "replaceText",
1161
1707
  from: start.value,
@@ -1179,39 +1725,49 @@ var CanonicalSession = class {
1179
1725
  const isCaret = state.selection.empty;
1180
1726
  const deletion = isCaret && text.length === 0 && (semantic === "deleteBackward" || semantic === "deleteForward") ? deletionRange(state, semantic === "deleteBackward" ? "backward" : "forward") : null;
1181
1727
  const grouping = isCaret && (semantic === "typing" && from === to && from === state.selection.head || deletion?.isOk() && deletion.value.from === from && deletion.value.to === to) ? "run" : "isolated";
1728
+ const groupingKey = {
1729
+ preSelection: preSelection.value,
1730
+ postSelection,
1731
+ semantic,
1732
+ grouping: compositionPhase === "correction" ? "compositionCorrection" : grouping,
1733
+ time,
1734
+ boundary: this.groupingBoundary
1735
+ };
1736
+ const group = this.applied.at(-1);
1737
+ const previous = group?.entries.at(-1);
1738
+ const joins = group !== void 0 && previous !== void 0 && continuesGroup(previous, groupingKey);
1182
1739
  return this.stage({
1183
1740
  state,
1184
1741
  story,
1185
1742
  ops,
1186
1743
  selection: postSelection,
1187
1744
  origin: "input",
1745
+ history: joins ? "joined" : "opened",
1746
+ ...semantic === "typing" && inputFrom === inputTo && text.length > 0 ? { typing: {
1747
+ at: start.value,
1748
+ after: caret,
1749
+ text
1750
+ } } : {},
1188
1751
  ...compiled.value.applied === void 0 ? {} : { stagedApplied: compiled.value.applied },
1189
- onPublish: (inverse, version) => {
1752
+ onPublish: (inverse, version, shown) => {
1190
1753
  const entry = {
1191
1754
  type: "applied",
1192
1755
  ops,
1193
1756
  inverse,
1194
- preSelection: preSelection.value,
1195
- postSelection,
1757
+ ...groupingKey,
1196
1758
  preDocument,
1197
1759
  postDocument: this.currentDocument,
1198
1760
  version,
1199
- origin: "input",
1200
- semantic,
1201
- grouping: compositionPhase === "correction" ? "compositionCorrection" : grouping,
1202
- time,
1203
- boundary: this.groupingBoundary
1761
+ origin: "input"
1204
1762
  };
1205
- const group = this.applied.at(-1);
1206
- const previous = group?.entries.at(-1);
1207
- if (group !== void 0 && previous !== void 0 && continuesGroup(previous, entry)) {
1763
+ if (group !== void 0 && joins) {
1208
1764
  group.entries.push(entry);
1209
- group.postSelection = postSelection;
1765
+ group.postSelection = shown;
1210
1766
  } else this.applied.push({
1211
1767
  entries: [entry],
1212
1768
  undo: { type: "entries" },
1213
1769
  preSelection: preSelection.value,
1214
- postSelection
1770
+ postSelection: shown
1215
1771
  });
1216
1772
  this.undone.length = 0;
1217
1773
  }
@@ -1280,31 +1836,28 @@ var CanonicalSession = class {
1280
1836
  edits.push(imported.value);
1281
1837
  }
1282
1838
  for (const intent of intents) {
1283
- if (this.mode.type === "suggesting" && (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink" || intent.type === "generateTOC")) return Result.err(new CanonicalSessionError({
1284
- ground: { gap: CANONICAL_GAP.trackedHyperlinkResolution },
1285
- reason: "refused",
1286
- message: "Hyperlink and TOC suggestions require serializable wrapper review provenance."
1287
- }));
1288
1839
  const compiled = compileEditorIntent(document, {
1289
1840
  intent,
1290
1841
  mode: this.intentMode(document, intent),
1291
1842
  firstBlockId: this.nextBlockId
1292
1843
  });
1293
- if (compiled.isErr()) {
1294
- if (compiled.error.reason === DOCUMENT_OP_REFUSAL_REASONS.NO_CHANGE) return noChange(compiled.error.message);
1295
- if (compiled.error.reason === DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE && (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink")) return Result.err(new CanonicalSessionError({
1296
- ground: { gap: CANONICAL_GAP.trackedHyperlinkResolution },
1297
- reason: "refused",
1298
- message: compiled.error.message
1299
- }));
1300
- return refuse(compiled.error.message);
1301
- }
1844
+ if (compiled.isErr()) return intentRefusal(intent, this.mode, compiled.error);
1302
1845
  const applied = compiled.value.applied === void 0 ? applyDocumentOps(document, compiled.value.ops) : Result.ok(compiled.value.applied);
1303
- if (applied.isErr()) return applied.error.reason === DOCUMENT_OP_REFUSAL_REASONS.NO_CHANGE ? noChange(applied.error.message) : refuse(applied.error.message);
1846
+ if (applied.isErr()) return intentRefusal(intent, this.mode, applied.error);
1304
1847
  document = applied.value.document;
1305
1848
  edits.push(applied.value);
1306
1849
  ops.push(...compiled.value.ops);
1307
- if (intent.type === "generateTOC") {
1850
+ if (this.mode.type === "suggesting" && (intent.type === "setHyperlink" || intent.type === "removeHyperlink")) postSelection = {
1851
+ type: "text",
1852
+ anchor: intent.from,
1853
+ head: compiled.value.selection
1854
+ };
1855
+ else if (this.mode.type === "suggesting" && intent.type === "generateTOC") postSelection = {
1856
+ type: "text",
1857
+ anchor: compiled.value.selection,
1858
+ head: compiled.value.selection
1859
+ };
1860
+ else if (intent.type === "generateTOC") {
1308
1861
  const mapping = {
1309
1862
  at: intent.at,
1310
1863
  after: compiled.value.selection,
@@ -1322,7 +1875,7 @@ var CanonicalSession = class {
1322
1875
  }
1323
1876
  const stagedApplied = {
1324
1877
  ...combineEdits(this.currentDocument, edits),
1325
- revisions: edits.flatMap(({ revisions }) => revisions)
1878
+ ...combineRecordedRevisions(edits)
1326
1879
  };
1327
1880
  return this.prepareJournalledOps({
1328
1881
  state,
@@ -1339,7 +1892,80 @@ var CanonicalSession = class {
1339
1892
  postSelection
1340
1893
  });
1341
1894
  }
1342
- prepareJournalledOps({ state, ops, postSelection, stagedApplied, semantic = "structure" }) {
1895
+ /** Verify compiled insertions and stage only the chain this session applied. */
1896
+ beginVerifiedOperationStaging(access, admission) {
1897
+ if (access !== canonicalOperationStagingAccess) panic("Only the public-operation compiler may stage verified operations.");
1898
+ const base = this.currentDocument;
1899
+ const version = this.currentVersion;
1900
+ const verified = /* @__PURE__ */ new WeakMap();
1901
+ let document = base;
1902
+ const ops = [];
1903
+ const effects = [];
1904
+ const recorded = [];
1905
+ return {
1906
+ apply: (before, input) => {
1907
+ const op = structuredClone(input);
1908
+ return applyDocumentOps(before, [op]).map((applied) => {
1909
+ const { document: next, inverse, touched, revisions, folded } = applied;
1910
+ const view = Object.freeze({
1911
+ document: next,
1912
+ revisions: Object.freeze([...revisions]),
1913
+ folded: Object.freeze([...folded])
1914
+ });
1915
+ verified.set(view, {
1916
+ before,
1917
+ document: next,
1918
+ op,
1919
+ effect: {
1920
+ inverse,
1921
+ touched
1922
+ },
1923
+ recorded: {
1924
+ revisions,
1925
+ folded
1926
+ }
1927
+ });
1928
+ return view;
1929
+ });
1930
+ },
1931
+ append: (view) => {
1932
+ const step = verified.get(view);
1933
+ if (step === void 0 || step.before !== document) return false;
1934
+ verified.delete(view);
1935
+ document = step.document;
1936
+ ops.push(step.op);
1937
+ effects.push(step.effect);
1938
+ recorded.push(step.recorded);
1939
+ return true;
1940
+ },
1941
+ prepare: (state, postSelection) => {
1942
+ if (version !== this.currentVersion || base !== this.currentDocument) return refuse("The compiled operations use a stale canonical document.");
1943
+ const combined = combineEdits(document, effects.map(({ inverse, touched }) => ({
1944
+ document,
1945
+ inverse,
1946
+ touched
1947
+ })));
1948
+ return this.prepareJournalledOps({
1949
+ state,
1950
+ ops: [...ops],
1951
+ postSelection,
1952
+ stagedApplied: {
1953
+ ...combined,
1954
+ ...combineRecordedRevisions(recorded)
1955
+ },
1956
+ admission
1957
+ });
1958
+ },
1959
+ /** Stage operations the compiler applied itself, under this admission. */
1960
+ prepareOps: (state, compiled, postSelection) => this.prepareJournalledOps({
1961
+ state,
1962
+ ops: compiled,
1963
+ postSelection,
1964
+ admission
1965
+ })
1966
+ };
1967
+ }
1968
+ prepareJournalledOps({ state, ops, postSelection, stagedApplied, semantic = "structure", admission }) {
1343
1969
  const story = postSelection.anchor.story;
1344
1970
  const projected = this.projectStory(story);
1345
1971
  if (projected.isErr()) return projected;
@@ -1353,14 +1979,16 @@ var CanonicalSession = class {
1353
1979
  ops,
1354
1980
  selection: postSelection,
1355
1981
  origin: "input",
1982
+ history: "opened",
1356
1983
  ...stagedApplied === void 0 ? {} : { stagedApplied },
1357
- onPublish: (inverse, version) => {
1984
+ ...admission === void 0 ? {} : { admission },
1985
+ onPublish: (inverse, version, shown) => {
1358
1986
  const entry = {
1359
1987
  type: "applied",
1360
1988
  ops,
1361
1989
  inverse,
1362
1990
  preSelection: preSelection.value,
1363
- postSelection,
1991
+ postSelection: shown,
1364
1992
  preDocument,
1365
1993
  postDocument: this.currentDocument,
1366
1994
  version,
@@ -1374,7 +2002,7 @@ var CanonicalSession = class {
1374
2002
  entries: [entry],
1375
2003
  undo: { type: "entries" },
1376
2004
  preSelection: preSelection.value,
1377
- postSelection
2005
+ postSelection: shown
1378
2006
  });
1379
2007
  this.undone.length = 0;
1380
2008
  }
@@ -1386,7 +2014,7 @@ var CanonicalSession = class {
1386
2014
  const to = this.projection.inputAddressAt(state.selection.to);
1387
2015
  if (to.isErr()) return to;
1388
2016
  const source = this.projection.paragraph(from.value.blockId);
1389
- const nextStyle = (this.styles ?? this.currentDocument.package.styles)?.styles.find(({ styleId }) => styleId === source?.source.formatting?.styleId)?.next;
2017
+ const nextStyle = (Object.hasOwn(this.currentDocument.package, "styles") ? this.currentDocument.package.styles : this.styles)?.styles.find(({ styleId }) => styleId === source?.source.formatting?.styleId)?.next;
1390
2018
  const fresh = this.freshBlockId();
1391
2019
  if (fresh.isErr()) return fresh;
1392
2020
  const intents = [{
@@ -1439,16 +2067,17 @@ var CanonicalSession = class {
1439
2067
  revisionIds: ids,
1440
2068
  decision: resolution
1441
2069
  }];
1442
- let firstHeld = null;
1443
- const lockHeld = revisionIds.filter((id) => {
1444
- const alone = applyDocumentOps(this.currentDocument, resolve([id]));
1445
- if (alone.isErr()) return false;
1446
- const violation = lockViolationBetween(this.currentDocument, alone.value.document);
1447
- firstHeld ??= violation;
1448
- return violation !== null;
2070
+ const changes = getTrackedChangeGroupsForIds(state.doc, revisionIds);
2071
+ const locks = canonicalRevisionLocks({
2072
+ document: this.currentDocument,
2073
+ story: OP_STORIES.MAIN,
2074
+ groups: changes,
2075
+ decision: resolution
1449
2076
  });
1450
- if (firstHeld !== null && lockHeld.length === revisionIds.length) return lockRefusal(firstHeld);
1451
- const resolved = revisionIds.filter((id) => !lockHeld.includes(id));
2077
+ const firstHeld = locks.held.at(0);
2078
+ if (firstHeld !== void 0 && locks.held.length === changes.length) return lockRefusal(firstHeld.violation);
2079
+ const lockHeld = locks.held.flatMap(({ ids }) => ids);
2080
+ const resolved = locks.unlocked.flat();
1452
2081
  const ops = [...before, ...resolved.length === 0 ? [] : resolve(resolved)];
1453
2082
  const applied = applyDocumentOps(this.currentDocument, ops);
1454
2083
  if (applied.isErr()) return refuse(applied.error.message);
@@ -1492,17 +2121,25 @@ var CanonicalSession = class {
1492
2121
  * comments stay as ordinary comments.
1493
2122
  */
1494
2123
  prepareSuggestion(state, { suggestionId, resolution, author, date }) {
1495
- const infos = suggestionRevisionInfos(this.currentDocument, OP_STORIES.MAIN, suggestionId);
2124
+ const revisions = documentStories(this.currentDocument).map((story) => ({
2125
+ story,
2126
+ infos: suggestionRevisionInfos(this.currentDocument, story, suggestionId)
2127
+ })).filter(({ infos }) => infos.length > 0);
1496
2128
  const commentIds = suggestedCommentIds(this.currentDocument, suggestionId);
1497
- if (infos.length === 0 && commentIds.length === 0) return noChange(`No pending suggestion ${suggestionId}.`);
2129
+ if (revisions.length === 0 && commentIds.length === 0) return noChange(`No pending suggestion ${suggestionId}.`);
1498
2130
  if (resolution === "reject") return this.prepareResolve(state, {
1499
- revisionIds: infos.map(({ id }) => id),
2131
+ revisionIds: [],
1500
2132
  resolution: "reject",
1501
- before: commentIds.map((id) => ({
2133
+ before: [...commentIds.map((id) => ({
1502
2134
  type: DOCUMENT_OP_TYPES.DELETE_COMMENT,
1503
2135
  id,
1504
2136
  scope: "thread"
1505
- }))
2137
+ })), ...revisions.toSorted(({ story: left }, { story: right }) => Number(left === OP_STORIES.MAIN) - Number(right === OP_STORIES.MAIN)).map(({ story, infos }) => ({
2138
+ type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
2139
+ story,
2140
+ revisionIds: infos.map(({ id }) => id),
2141
+ decision: "reject"
2142
+ }))]
1506
2143
  });
1507
2144
  const checked = this.checkState(state);
1508
2145
  if (checked.isErr()) return checked;
@@ -1510,9 +2147,9 @@ var CanonicalSession = class {
1510
2147
  if (selection.isErr()) return selection;
1511
2148
  const comments = this.currentDocument.package.document.comments ?? [];
1512
2149
  const ops = [];
1513
- if (infos.length > 0) ops.push({
2150
+ for (const { story, infos } of revisions) ops.push({
1514
2151
  type: DOCUMENT_OP_TYPES.SET_REVISION_INFO,
1515
- story: OP_STORIES.MAIN,
2152
+ story,
1516
2153
  infos: infos.map(({ id }) => ({
1517
2154
  id,
1518
2155
  author,
@@ -1540,8 +2177,8 @@ var CanonicalSession = class {
1540
2177
  return refuse("The canonical story no longer exists.");
1541
2178
  }
1542
2179
  const cached = this.storyProjections.get(key);
1543
- const theme = this.currentDocument.package.theme;
1544
- if (cached?.content === body.content && cached.theme === theme) return Result.ok(cached.projection);
2180
+ const { styles, theme } = this.currentDocument.package;
2181
+ if (cached?.content === body.content && cached.styles === styles && cached.theme === theme) return Result.ok(cached.projection);
1545
2182
  const projected = project({
1546
2183
  document: this.currentDocument,
1547
2184
  styles: this.styles,
@@ -1551,6 +2188,7 @@ var CanonicalSession = class {
1551
2188
  });
1552
2189
  if (projected.isOk()) this.storyProjections.set(key, {
1553
2190
  content: body.content,
2191
+ styles,
1554
2192
  theme,
1555
2193
  projection: projected.value
1556
2194
  });
@@ -1588,7 +2226,7 @@ var CanonicalSession = class {
1588
2226
  }],
1589
2227
  openStart: 0,
1590
2228
  openEnd: 0
1591
- });
2229
+ }, this.leased?.lease);
1592
2230
  const next = {
1593
2231
  ...op,
1594
2232
  ...this.mode.type === "suggesting" ? { revision: {
@@ -1624,14 +2262,15 @@ var CanonicalSession = class {
1624
2262
  ops: preparedOps,
1625
2263
  selection: postSelection,
1626
2264
  origin: "input",
1627
- onPublish: (inverse, version) => {
2265
+ history: "opened",
2266
+ onPublish: (inverse, version, shown) => {
1628
2267
  this.applied.push({
1629
2268
  entries: [{
1630
2269
  type: "applied",
1631
2270
  ops: preparedOps,
1632
2271
  inverse,
1633
2272
  preSelection: selected.value,
1634
- postSelection,
2273
+ postSelection: shown,
1635
2274
  preDocument,
1636
2275
  postDocument: this.currentDocument,
1637
2276
  version,
@@ -1643,23 +2282,193 @@ var CanonicalSession = class {
1643
2282
  }],
1644
2283
  undo: { type: "entries" },
1645
2284
  preSelection: selected.value,
1646
- postSelection
2285
+ postSelection: shown
1647
2286
  });
1648
2287
  this.undone.length = 0;
1649
2288
  }
1650
2289
  });
1651
2290
  }
2291
+ /**
2292
+ * A step rebased over a remote edit keeps its inverse's preconditions, so
2293
+ * it may no longer apply. Such a step is dropped with every step beneath
2294
+ * it, which were recorded on top of what it would have restored.
2295
+ */
2296
+ rebasedStepApplies(group, ops, stack) {
2297
+ if (group.rebased !== true) return Result.ok(void 0);
2298
+ const applied = applyDocumentOps(this.currentDocument, ops);
2299
+ if (applied.isOk()) return Result.ok(applied.value);
2300
+ const dropped = stack === "undo" ? {
2301
+ undo: this.applied.length,
2302
+ redo: 0
2303
+ } : {
2304
+ undo: 0,
2305
+ redo: this.undone.length
2306
+ };
2307
+ if (stack === "undo") this.applied.length = 0;
2308
+ else this.undone.length = 0;
2309
+ this.reportHistoryDrop(dropped);
2310
+ return refuse(`The ${stack} step no longer applies after a remote edit: ${applied.error.message}`);
2311
+ }
2312
+ /** Called with every history drop a remote edit causes; returns the unsubscribe. */
2313
+ onHistoryDrop(listener) {
2314
+ this.historyDropListeners.add(listener);
2315
+ return () => {
2316
+ this.historyDropListeners.delete(listener);
2317
+ };
2318
+ }
2319
+ /**
2320
+ * Called with every commit once it is published, after the editor and its
2321
+ * plugins accepted the projection and the session's history recorded it;
2322
+ * returns the unsubscribe. A collaboration binding sends exactly these.
2323
+ */
2324
+ onCommitted(listener) {
2325
+ this.committedListeners.add(listener);
2326
+ return () => {
2327
+ this.committedListeners.delete(listener);
2328
+ };
2329
+ }
2330
+ reportHistoryDrop(drop) {
2331
+ if (drop.undo === 0 && drop.redo === 0) return;
2332
+ for (const listener of this.historyDropListeners) listener(drop);
2333
+ }
2334
+ /**
2335
+ * Stage another actor's sequenced edit through the same path as a local
2336
+ * one. `change` is what the optimistic client reported: its ops apply to
2337
+ * this session's document, already rebased over the pending local batches.
2338
+ * It journals no undo step and opens no undo group. The local undo and redo
2339
+ * steps are rebased over it; a step that no longer rebases is dropped with
2340
+ * every step beneath it and reported to `onHistoryDrop`, and a `replaced`
2341
+ * change drops them all. The selection moves by paragraph id and offset,
2342
+ * over a `replaced` change's `moves` when it has them. It waits while a composition is pending; any other refusal means this
2343
+ * session no longer follows the shared document.
2344
+ */
2345
+ prepareRemote(state, change, story = OP_STORIES.MAIN) {
2346
+ const projected = this.projectStory(story);
2347
+ if (projected.isErr()) return projected;
2348
+ const checked = this.checkState(state, projected.value);
2349
+ if (checked.isErr()) return checked;
2350
+ const applied = applyDocumentOps(this.currentDocument, change.batch.ops);
2351
+ if (applied.isErr()) return refuse(applied.error.message);
2352
+ const shown = projected.value.selectionAt(state);
2353
+ const before = shown.isOk() ? shown.value : this.currentSelection;
2354
+ const selection = remoteSelection({
2355
+ selection: before,
2356
+ over: change.type === "replaced" ? change.moves ?? change.batch : change.batch,
2357
+ previous: this.currentDocument,
2358
+ document: applied.value.document,
2359
+ story
2360
+ });
2361
+ const history = this.rebasedHistory(change, selection);
2362
+ const storySelections = [...this.storySelections].flatMap(([key, held]) => findStoryBody(applied.value.document, held.head.story) === void 0 ? [] : [[key, remoteSelection({
2363
+ selection: held,
2364
+ over: change.batch,
2365
+ previous: this.currentDocument,
2366
+ document: applied.value.document,
2367
+ story: held.head.story
2368
+ })]]);
2369
+ return this.stage({
2370
+ state,
2371
+ story,
2372
+ ops: change.batch.ops,
2373
+ selection,
2374
+ origin: "remote",
2375
+ history: "remote",
2376
+ stagedApplied: applied.value,
2377
+ previousProjection: projected.value,
2378
+ opId: change.batch.opId,
2379
+ onPublish: () => {
2380
+ this.storySelections.clear();
2381
+ for (const [key, moved] of storySelections) this.storySelections.set(key, moved);
2382
+ const shownStory = selection.head.story;
2383
+ if (shownStory !== OP_STORIES.MAIN && findStoryBody(applied.value.document, shownStory) !== void 0) this.storySelections.set(storyProjectionKey(shownStory), selection);
2384
+ this.applied.splice(0, this.applied.length, ...history.applied);
2385
+ this.undone.splice(0, this.undone.length, ...history.undone);
2386
+ this.breakUndoGroup();
2387
+ this.reportHistoryDrop(history.dropped);
2388
+ }
2389
+ });
2390
+ }
2391
+ /** Both history stacks as they stand after `change`, top steps first rebased. */
2392
+ rebasedHistory(change, fallback) {
2393
+ if (change.type === "replaced") return {
2394
+ applied: [],
2395
+ undone: [],
2396
+ dropped: {
2397
+ undo: this.applied.length,
2398
+ redo: this.undone.length
2399
+ }
2400
+ };
2401
+ const groups = this.applied.toReversed();
2402
+ const applied = rebaseHistorySteps({
2403
+ document: this.currentDocument,
2404
+ over: change.batch,
2405
+ fallback,
2406
+ steps: groups.map((group) => ({
2407
+ ops: undoOpsOf(group),
2408
+ before: group.postSelection,
2409
+ after: group.preSelection
2410
+ }))
2411
+ }).flatMap((step, index) => {
2412
+ const group = groups.at(index);
2413
+ return group === void 0 ? [] : [{
2414
+ entries: group.entries,
2415
+ undo: {
2416
+ type: "replayed",
2417
+ inverse: step.ops
2418
+ },
2419
+ preSelection: step.after,
2420
+ postSelection: step.before,
2421
+ rebased: true
2422
+ }];
2423
+ });
2424
+ const undoneSteps = this.undone.toReversed();
2425
+ const undone = rebaseHistorySteps({
2426
+ document: this.currentDocument,
2427
+ over: change.batch,
2428
+ fallback,
2429
+ steps: undoneSteps.map(({ group, redoOps }) => ({
2430
+ ops: redoOps,
2431
+ before: group.preSelection,
2432
+ after: group.postSelection
2433
+ }))
2434
+ }).flatMap((step, index) => {
2435
+ const entry = undoneSteps.at(index);
2436
+ return entry === void 0 ? [] : [{
2437
+ type: "undone",
2438
+ group: {
2439
+ ...entry.group,
2440
+ preSelection: step.before,
2441
+ postSelection: step.after,
2442
+ rebased: true
2443
+ },
2444
+ redoOps: step.ops
2445
+ }];
2446
+ });
2447
+ return {
2448
+ applied: applied.toReversed(),
2449
+ undone: undone.toReversed(),
2450
+ dropped: {
2451
+ undo: groups.length - applied.length,
2452
+ redo: undoneSteps.length - undone.length
2453
+ }
2454
+ };
2455
+ }
1652
2456
  prepareUndo(state, story = OP_STORIES.MAIN) {
1653
2457
  const group = this.applied.at(-1);
1654
2458
  if (group === void 0) return refuse("There is no canonical edit to undo.");
1655
- const propertySourceDocument = group.entries.at(0)?.preDocument;
2459
+ const ops = undoOpsOf(group);
2460
+ const rebased = this.rebasedStepApplies(group, ops, "undo");
2461
+ if (rebased.isErr()) return rebased;
2462
+ const propertySourceDocument = group.rebased === true ? void 0 : group.entries.at(0)?.preDocument;
1656
2463
  return this.stage({
1657
2464
  state,
1658
2465
  story,
1659
- ops: group.undo.type === "replayed" ? group.undo.inverse : group.entries.toReversed().flatMap((entry) => entry.inverse),
2466
+ ops,
1660
2467
  selection: group.preSelection,
1661
2468
  origin: "undo",
2469
+ history: "undo",
1662
2470
  ...propertySourceDocument === void 0 ? {} : { propertySourceDocument },
2471
+ ...rebased.value === void 0 ? {} : { stagedApplied: rebased.value },
1663
2472
  onPublish: (redoOps) => {
1664
2473
  this.applied.pop();
1665
2474
  this.undone.push({
@@ -1674,14 +2483,18 @@ var CanonicalSession = class {
1674
2483
  prepareRedo(state, story = OP_STORIES.MAIN) {
1675
2484
  const undone = this.undone.at(-1);
1676
2485
  if (undone === void 0) return refuse("There is no canonical edit to redo.");
1677
- const propertySourceDocument = undone.group.entries.at(-1)?.postDocument;
2486
+ const rebased = this.rebasedStepApplies(undone.group, undone.redoOps, "redo");
2487
+ if (rebased.isErr()) return rebased;
2488
+ const propertySourceDocument = undone.group.rebased === true ? void 0 : undone.group.entries.at(-1)?.postDocument;
1678
2489
  return this.stage({
1679
2490
  state,
1680
2491
  story,
1681
2492
  ops: undone.redoOps,
1682
2493
  selection: undone.group.postSelection,
1683
2494
  origin: "redo",
2495
+ history: "redo",
1684
2496
  ...propertySourceDocument === void 0 ? {} : { propertySourceDocument },
2497
+ ...rebased.value === void 0 ? {} : { stagedApplied: rebased.value },
1685
2498
  onPublish: (inverse) => {
1686
2499
  this.undone.pop();
1687
2500
  this.applied.push({
@@ -1691,13 +2504,14 @@ var CanonicalSession = class {
1691
2504
  inverse
1692
2505
  },
1693
2506
  preSelection: undone.group.preSelection,
1694
- postSelection: undone.group.postSelection
2507
+ postSelection: undone.group.postSelection,
2508
+ ...undone.group.rebased === true ? { rebased: true } : {}
1695
2509
  });
1696
2510
  this.breakUndoGroup();
1697
2511
  }
1698
2512
  });
1699
2513
  }
1700
- stage({ state, ops, selection, origin, onPublish, propertySourceDocument, stagedApplied, story = OP_STORIES.MAIN, previousProjection }) {
2514
+ stage({ state, ops, selection, origin, history, onPublish, propertySourceDocument, stagedApplied, story = OP_STORIES.MAIN, previousProjection, opId, typing, admission = CANONICAL_ADMISSION.edit }) {
1701
2515
  const previous = previousProjection === void 0 ? this.projectStory(story) : Result.ok(previousProjection);
1702
2516
  if (previous.isErr()) return previous;
1703
2517
  const checked = this.checkState(state, previous.value);
@@ -1705,40 +2519,46 @@ var CanonicalSession = class {
1705
2519
  const applied = stagedApplied === void 0 ? applyDocumentOps(this.currentDocument, ops) : Result.ok(stagedApplied);
1706
2520
  if (applied.isErr()) return refuse(applied.error.message);
1707
2521
  if (applied.value.inverse.length === 0) return noChange("The intent makes no document change.");
1708
- const locked = lockViolationBetween(this.currentDocument, applied.value.document);
2522
+ const locked = admission === CANONICAL_ADMISSION.restage ? null : lockViolationBetween(this.currentDocument, applied.value.document);
1709
2523
  if (locked !== null) return lockRefusal(locked);
1710
- if (propertySourceDocument !== void 0) preservePropertySources({
2524
+ if (propertySourceDocument !== void 0) applied.value.document = preservePropertySources({
1711
2525
  target: applied.value.document,
1712
2526
  source: propertySourceDocument,
1713
2527
  indentation: "restore"
1714
2528
  });
1715
2529
  const normalized = normalizeCanonicalListRendering(applied.value.document, this.caches.lists);
1716
2530
  applied.value.document = normalized.document;
1717
- applied.value.inverse = normalized.inverse.concat(applied.value.inverse);
2531
+ applied.value.inverse = inverseMeetingDocument(normalized.document, normalized.inverse.concat(applied.value.inverse));
2532
+ const leaseJudgement = origin === "remote" ? this.leased?.admit(applied.value.document) : this.leased?.judge(applied.value.document);
2533
+ if (leaseJudgement?.type === "outside") return refuse(`The ${leaseJudgement.id.kind} id ${leaseJudgement.id.id} is outside this author's id lease.`);
1718
2534
  const changed = changedStories({
1719
2535
  document: applied.value.document,
1720
2536
  previous: this.currentDocument
1721
2537
  });
1722
- if (unsupportedSeedReason(applied.value.document, changed) !== null) return Result.err(new CanonicalSessionError({
2538
+ if (unsupportedEditReason({
2539
+ previous: this.currentDocument,
2540
+ document: applied.value.document,
2541
+ stories: changed
2542
+ }) !== null) return Result.err(new CanonicalSessionError({
1723
2543
  ground: { gap: CANONICAL_GAP.storyContentProjection },
1724
2544
  reason: "refused",
1725
2545
  message: "The operations produce unsupported canonical story content."
1726
2546
  }));
1727
- preservePropertySources({
2547
+ applied.value.document = preservePropertySources({
1728
2548
  target: applied.value.document,
1729
2549
  source: this.currentDocument,
1730
2550
  stories: changed
1731
2551
  });
1732
- if (propertySourceDocument !== void 0) preservePropertySources({
2552
+ if (propertySourceDocument !== void 0) applied.value.document = preservePropertySources({
1733
2553
  target: applied.value.document,
1734
2554
  source: propertySourceDocument
1735
2555
  });
1736
- const stagedSources = new Map(this.sourceOwners);
1737
- for (const block of applied.value.document.package.document.content) {
1738
- if (block.type !== "paragraph" || block.paraId === void 0) continue;
1739
- const source = stagedSources.get(block.paraId);
1740
- if (source && block !== source) copyParagraphPropertySource(block, source);
1741
- }
2556
+ applied.value.document = withParagraphCopies({
2557
+ document: applied.value.document,
2558
+ story: OP_STORIES.MAIN,
2559
+ copies: ownedSourceCopies(this.sourceOwners, changedWindow(this.currentDocument.package.document.content, applied.value.document.package.document.content).added)
2560
+ });
2561
+ const remembered = changedWindow(this.currentDocument.package.document.content, applied.value.document.package.document.content).added;
1742
2562
  const projectedStory = findStoryBody(applied.value.document, story) ? story : OP_STORIES.MAIN;
1743
2563
  const projected = project({
1744
2564
  document: applied.value.document,
@@ -1762,6 +2582,18 @@ var CanonicalSession = class {
1762
2582
  const transaction = state.tr;
1763
2583
  const before = state.doc;
1764
2584
  const after = projected.value.doc;
2585
+ const retainedTokens = /* @__PURE__ */ new Set();
2586
+ const retainPropertyOwner = (node) => {
2587
+ if (node.type.name !== "paragraph") return true;
2588
+ const id = node.attrs["paraId"];
2589
+ const token = getProseParagraphPropertySourceToken(node);
2590
+ const owner = typeof id === "string" ? previous.value.paragraph(id) : void 0;
2591
+ if (typeof token === "string" && owner !== void 0 && getProseParagraphPropertySourceToken(owner.node) === token) retainedTokens.add(token);
2592
+ return false;
2593
+ };
2594
+ const retainPropertyOwnersIn = (node) => {
2595
+ if (retainPropertyOwner(node)) node.descendants(retainPropertyOwner);
2596
+ };
1765
2597
  let prefix = 0;
1766
2598
  let from = 0;
1767
2599
  while (prefix < before.childCount && prefix < after.childCount && before.child(prefix).eq(after.child(prefix))) {
@@ -1780,8 +2612,16 @@ var CanonicalSession = class {
1780
2612
  const replacement = [];
1781
2613
  for (let index = prefix; index < newEnd; index += 1) replacement.push(after.child(index));
1782
2614
  transaction.replaceWith(from, to, Fragment.fromArray(replacement));
2615
+ replacement.forEach(retainPropertyOwnersIn);
2616
+ }
2617
+ if (!transaction.doc.eq(projected.value.doc)) {
2618
+ transaction.replaceWith(0, transaction.doc.content.size, projected.value.doc.content);
2619
+ after.forEach(retainPropertyOwnersIn);
1783
2620
  }
1784
- if (!transaction.doc.eq(projected.value.doc)) transaction.replaceWith(0, transaction.doc.content.size, projected.value.doc.content);
2621
+ markParagraphPropertySourceTransfers(transaction, [...retainedTokens].map((selectedToken) => ({
2622
+ displacedToken: null,
2623
+ selectedToken
2624
+ })));
1785
2625
  for (const [name, value] of Object.entries(projected.value.doc.attrs)) if (transaction.doc.attrs[name] !== value) transaction.setDocAttribute(name, value);
1786
2626
  if (sameStory(selection.anchor.story, projectedStory) && sameStory(selection.head.story, projectedStory)) {
1787
2627
  if (!restoreCanonicalSelection({
@@ -1794,6 +2634,7 @@ var CanonicalSession = class {
1794
2634
  }
1795
2635
  })) return refuse("Canonical history cannot restore the selected inline atom.");
1796
2636
  }
2637
+ const shown = (sameStory(selection.anchor.story, projectedStory) && sameStory(selection.head.story, projectedStory) ? placeShownSelection(transaction, projected.value) : void 0) ?? selection;
1797
2638
  const held = projected.value.heldAs(transaction.doc);
1798
2639
  const heldBody = bodyProjection.value === projected.value ? held : bodyProjection.value;
1799
2640
  transaction.setMeta(CANONICAL_PROJECTION_META, {
@@ -1801,7 +2642,6 @@ var CanonicalSession = class {
1801
2642
  origin,
1802
2643
  version: this.version + 1
1803
2644
  });
1804
- if (ops.some(operationChangesPackage)) markPackageChange(transaction);
1805
2645
  transaction.setMeta("addToHistory", false);
1806
2646
  const baseVersion = this.version;
1807
2647
  const baseBoundary = this.groupingBoundary;
@@ -1812,6 +2652,7 @@ var CanonicalSession = class {
1812
2652
  });
1813
2653
  return Result.ok({
1814
2654
  transaction,
2655
+ ops,
1815
2656
  document: applied.value.document,
1816
2657
  projection: held,
1817
2658
  bodyProjection: heldBody,
@@ -1819,6 +2660,7 @@ var CanonicalSession = class {
1819
2660
  touched: applied.value.touched,
1820
2661
  version: baseVersion + 1,
1821
2662
  origin,
2663
+ history,
1822
2664
  publish: () => {
1823
2665
  if (this.isComposing || this.groupingBoundary !== baseBoundary) return refuse("The staged canonical commit crossed a composition or selection boundary.");
1824
2666
  if (this.version !== baseVersion) return refuse("The staged canonical commit is stale.");
@@ -1829,49 +2671,69 @@ var CanonicalSession = class {
1829
2671
  if (op.type === DOCUMENT_OP_TYPES.ADD_NOTE) for (const blockId of paragraphIdsIn(op.note.content)) this.allocatedBlockIds.add(blockId.toUpperCase());
1830
2672
  }
1831
2673
  this.advanceBlockId();
1832
- this.rememberSources(applied.value.document);
2674
+ this.rememberSources(remembered);
1833
2675
  if (projectedStory !== OP_STORIES.MAIN) {
1834
2676
  const body = findStoryBody(applied.value.document, projectedStory);
1835
2677
  if (body === void 0) panic("A staged story projection lost its source.");
1836
2678
  this.storyProjections.set(storyProjectionKey(projectedStory), {
1837
2679
  content: body.content,
2680
+ styles: applied.value.document.package.styles,
1838
2681
  theme: applied.value.document.package.theme,
1839
2682
  projection: held
1840
2683
  });
1841
2684
  }
1842
2685
  this.currentSelection = selection;
2686
+ const selectedStory = selection.head.story;
2687
+ if (selectedStory !== OP_STORIES.MAIN) this.storySelections.set(storyProjectionKey(selectedStory), selection);
2688
+ for (const [key, kept] of this.storySelections) if (findStoryBody(applied.value.document, kept.head.story) === void 0) this.storySelections.delete(key);
1843
2689
  this.currentDocument = applied.value.document;
1844
2690
  this.currentProjection = heldBody;
2691
+ if (leaseJudgement?.type === "allowed") this.leased?.commit(leaseJudgement.census, leaseJudgement.ids);
2692
+ const pending = this.pendingSaveBaseline;
1845
2693
  for (const ids of [
1846
2694
  applied.value.touched.modified,
1847
2695
  applied.value.touched.inserted,
1848
2696
  applied.value.touched.removed
1849
- ]) for (const id of ids) this.saveTouched.add(id);
1850
- const bodyOps = ops.filter((op) => !COMMENT_OPERATION_TYPES.has(op.type));
1851
- if (bodyOps.some(operationChangesStructure) || bodyOps.some(operationChangesPackage) || bodyOps.length > 0 && (applied.value.touched.inserted.length > 0 || applied.value.touched.removed.length > 0)) this.saveStructure = "changed";
2697
+ ]) for (const id of ids) {
2698
+ this.saveTouched.add(id);
2699
+ this.touchedSinceOpen.add(id);
2700
+ pending?.touched.add(id);
2701
+ }
2702
+ const bodyOps = ops.filter((op) => !COMMENT_OPERATION_TYPES.has(op.type) && !editsHeaderFooter(op));
2703
+ if (bodyOps.some(operationChangesStructure) || bodyOps.some(operationChangesPackage) || bodyOps.length > 0 && (applied.value.touched.inserted.length > 0 || applied.value.touched.removed.length > 0)) {
2704
+ this.saveStructure = "changed";
2705
+ if (pending) pending.structure = "changed";
2706
+ }
1852
2707
  this.currentVersion = baseVersion + 1;
1853
- onPublish(applied.value.inverse, this.currentVersion);
2708
+ onPublish(applied.value.inverse, this.currentVersion, shown);
2709
+ const committed = {
2710
+ opId: opId ?? this.newOpId(),
2711
+ ops,
2712
+ inverse: applied.value.inverse,
2713
+ version: this.currentVersion,
2714
+ origin
2715
+ };
2716
+ if (typing !== void 0) recordCanonicalTyping(committed, typing);
2717
+ for (const listener of this.committedListeners) listener(committed);
1854
2718
  return Result.ok(void 0);
1855
2719
  }
1856
2720
  });
1857
2721
  }
1858
2722
  };
1859
- const createCanonicalSession = (document, styles) => {
2723
+ const createCanonicalSession = (document, styles, { idLease, newOpId } = {}) => {
1860
2724
  const owned = cloneDocumentWithParagraphPropertySources(document);
1861
2725
  const source = normalizeCanonicalSource(owned);
1862
2726
  const unsupported = unsupportedSeedReason(source.document);
1863
2727
  if (unsupported !== null) return refuse(unsupported);
1864
- const identified = normalizeForOps(source.document);
1865
- preservePropertySources({
1866
- target: identified,
2728
+ const identified = preservePropertySourcesWholeStories({
2729
+ target: normalizeForOps(source.document),
1867
2730
  source: owned
1868
2731
  });
1869
2732
  const validated = validateOpsDocument(identified);
1870
2733
  if (validated.isErr()) return refuse(validated.error.message);
1871
2734
  const caches = newStoryProjectionCaches();
1872
- const normalized = normalizeCanonicalListRendering(identified, caches.lists).document;
1873
- preservePropertySources({
1874
- target: normalized,
2735
+ const normalized = preservePropertySourcesWholeStories({
2736
+ target: normalizeCanonicalListRendering(identified, caches.lists).document,
1875
2737
  source: owned
1876
2738
  });
1877
2739
  const projected = project({
@@ -1885,7 +2747,9 @@ const createCanonicalSession = (document, styles) => {
1885
2747
  projection: projected.value,
1886
2748
  styles,
1887
2749
  sourceRestores: canonicalSourceRestores(normalized, source.normalized),
1888
- caches
2750
+ caches,
2751
+ idLease,
2752
+ newOpId
1889
2753
  }));
1890
2754
  };
1891
2755
  const hasDeletedParagraphMark = (node) => {
@@ -1986,11 +2850,43 @@ const deletionRange = (state, direction) => {
1986
2850
  let boundary = visibleOffset + (direction === "backward" ? -1 : 1);
1987
2851
  while (splitsGraphemeCluster(text, boundary)) boundary += direction === "backward" ? -1 : 1;
1988
2852
  const from = physicalStarts.at(direction === "backward" ? boundary : visibleOffset);
1989
- const to = physicalEnds.at((direction === "backward" ? visibleOffset : boundary) - 1);
2853
+ const to = itemBefore(physicalEnds, direction === "backward" ? visibleOffset : boundary);
1990
2854
  if (from === void 0 || to === void 0) panic("Canonical deletion lost a grapheme boundary.");
1991
2855
  return Result.ok({
1992
2856
  from,
1993
2857
  to
1994
2858
  });
1995
2859
  };
1996
- export { CANONICAL_PROJECTION_META, CanonicalSessionError, createCanonicalSession, deletionRange, isCanonicalJoinBoundary, isCanonicalProjectionTransaction, newStoryProjectionCaches, project as projectCanonicalStory, publishCanonicalProjection };
2860
+ /**
2861
+ * The deletion a browser measured (by word or by line) as the visible
2862
+ * characters its range covers whole, in the caret's paragraph: from the first
2863
+ * such character's start to the last one's end. Zero-width anchors at the
2864
+ * range's edges stay, as they do beside a plain character deletion; an inline
2865
+ * atom only partly covered stays; `null` when the range covers no visible
2866
+ * character.
2867
+ */
2868
+ const measuredDeletionRange = (state, measured) => {
2869
+ const context = visibleDeletionContext(state);
2870
+ if (context.isErr()) return context;
2871
+ const { physicalStarts, physicalEnds } = context.value;
2872
+ let from;
2873
+ let to;
2874
+ for (const [unit, start] of physicalStarts.entries()) {
2875
+ const end = physicalEnds.at(unit);
2876
+ if (end === void 0) panic("Canonical deletion lost a visible character's end.");
2877
+ if (start < measured.from || end > measured.to) continue;
2878
+ from ??= start;
2879
+ to = end;
2880
+ }
2881
+ if (from === void 0 || to === void 0) return Result.ok(null);
2882
+ let noteMarkers = 0;
2883
+ state.doc.nodesBetween(from, to, (node) => {
2884
+ if (node.type.name === "noteMarker") noteMarkers += 1;
2885
+ });
2886
+ if (noteMarkers > 0) return refuse("Automatic note marks cannot be deleted as characters.");
2887
+ return Result.ok({
2888
+ from,
2889
+ to
2890
+ });
2891
+ };
2892
+ export { CANONICAL_ADMISSION, CANONICAL_PROJECTION_META, CanonicalSessionError, createCanonicalSession, deletionRange, isCanonicalJoinBoundary, isCanonicalProjectionTransaction, measuredDeletionRange, newStoryProjectionCaches, project as projectCanonicalStory, publishCanonicalProjection };