@stll/folio-core 0.52.0 → 0.54.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 (389) hide show
  1. package/README.md +23 -0
  2. package/dist/ai-edits/apply.d.ts +26 -1
  3. package/dist/ai-edits/apply.js +1779 -141
  4. package/dist/ai-edits/batch-claims.d.ts +145 -0
  5. package/dist/ai-edits/batch-claims.js +275 -0
  6. package/dist/ai-edits/blockRange.js +9 -3
  7. package/dist/ai-edits/character-boundaries.d.ts +43 -0
  8. package/dist/ai-edits/character-boundaries.js +95 -0
  9. package/dist/ai-edits/clean-text.d.ts +33 -3
  10. package/dist/ai-edits/clean-text.js +52 -6
  11. package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
  12. package/dist/ai-edits/comment-lifecycle.js +52 -0
  13. package/dist/ai-edits/headless.d.ts +91 -7
  14. package/dist/ai-edits/headless.js +520 -51
  15. package/dist/ai-edits/index.d.ts +2 -1
  16. package/dist/ai-edits/index.js +2 -1
  17. package/dist/ai-edits/minimal-replacement.d.ts +21 -6
  18. package/dist/ai-edits/minimal-replacement.js +134 -15
  19. package/dist/ai-edits/newListNumbering.d.ts +23 -0
  20. package/dist/ai-edits/newListNumbering.js +94 -0
  21. package/dist/ai-edits/note-references.d.ts +96 -0
  22. package/dist/ai-edits/note-references.js +139 -0
  23. package/dist/ai-edits/pending-suggestions.d.ts +79 -0
  24. package/dist/ai-edits/pending-suggestions.js +306 -0
  25. package/dist/ai-edits/read.d.ts +6 -4
  26. package/dist/ai-edits/read.js +113 -50
  27. package/dist/ai-edits/result-validation.d.ts +29 -0
  28. package/dist/ai-edits/result-validation.js +164 -0
  29. package/dist/ai-edits/revisionStretches.d.ts +17 -0
  30. package/dist/ai-edits/revisionStretches.js +80 -0
  31. package/dist/ai-edits/snapshot.d.ts +36 -3
  32. package/dist/ai-edits/snapshot.js +180 -25
  33. package/dist/ai-edits/table-cell-mutations.d.ts +4 -2
  34. package/dist/ai-edits/table-cell-mutations.js +6 -2
  35. package/dist/ai-edits/table-geometry.d.ts +1 -1
  36. package/dist/ai-edits/table-row-column-mutations.d.ts +44 -17
  37. package/dist/ai-edits/table-row-column-mutations.js +86 -34
  38. package/dist/ai-edits/types.d.ts +155 -16
  39. package/dist/compare/compare.d.ts +1 -1
  40. package/dist/compare/compare.js +65 -16
  41. package/dist/compare/content-alignment.d.ts +5 -1
  42. package/dist/compare/content-alignment.js +52 -34
  43. package/dist/compare/content-types.d.ts +7 -0
  44. package/dist/compare/content.d.ts +4 -1
  45. package/dist/compare/content.js +6 -1
  46. package/dist/compare/formatting.js +2 -1
  47. package/dist/compare/inline-atoms.d.ts +21 -4
  48. package/dist/compare/inline-atoms.js +138 -16
  49. package/dist/compare/inline-provenance.js +1 -1
  50. package/dist/compare/plan.js +10 -5
  51. package/dist/compare/scenario.js +14 -3
  52. package/dist/compare/section-boundary-properties.js +1 -1
  53. package/dist/compare/types.d.ts +4 -2
  54. package/dist/compare/types.js +2 -1
  55. package/dist/compare/verification.d.ts +1 -1
  56. package/dist/compare/verification.js +15 -3
  57. package/dist/controller/committedLayoutDiff.d.ts +25 -0
  58. package/dist/controller/committedLayoutDiff.js +71 -0
  59. package/dist/controller/contentControlWidgetController.d.ts +1 -1
  60. package/dist/controller/folioEditor.d.ts +1 -1
  61. package/dist/controller/fontReadiness.d.ts +70 -3
  62. package/dist/controller/fontReadiness.js +100 -10
  63. package/dist/controller/headerFooterEditorManager.js +6 -1
  64. package/dist/controller/layoutPipeline.d.ts +12 -10
  65. package/dist/controller/layoutPipeline.js +65 -11
  66. package/dist/controller/layoutRunOptions.d.ts +24 -0
  67. package/dist/controller/layoutRunOptions.js +17 -0
  68. package/dist/controller/layoutScheduler.d.ts +19 -14
  69. package/dist/controller/layoutScheduler.js +15 -12
  70. package/dist/controller/layoutSession.d.ts +26 -2
  71. package/dist/controller/layoutSession.js +1 -1
  72. package/dist/controller/noteEditorManager.js +8 -3
  73. package/dist/document-operations.d.ts +11 -2
  74. package/dist/document-operations.js +230 -21
  75. package/dist/docx/altChunk.d.ts +8 -0
  76. package/dist/docx/altChunk.js +17 -0
  77. package/dist/docx/archiveInflation.d.ts +127 -0
  78. package/dist/docx/archiveInflation.js +181 -0
  79. package/dist/docx/attributeRemainder.d.ts +1 -1
  80. package/dist/docx/blockContentParser.d.ts +64 -1
  81. package/dist/docx/blockContentParser.js +17 -4
  82. package/dist/docx/blockCustomXmlShell.d.ts +7 -0
  83. package/dist/docx/blockCustomXmlShell.js +14 -0
  84. package/dist/docx/blockPlainText.js +7 -0
  85. package/dist/docx/commentAnchorIndex.js +1 -1
  86. package/dist/docx/commentRangeIntegrity.js +8 -3
  87. package/dist/docx/commentReferenceNormalization.js +1 -1
  88. package/dist/docx/commentReplyMarkers.js +20 -1
  89. package/dist/docx/compatibility.d.ts +1 -1
  90. package/dist/docx/compatibility.js +34 -13
  91. package/dist/docx/containerChildren.gen.d.ts +1 -1
  92. package/dist/docx/containerChildren.gen.js +1 -0
  93. package/dist/docx/documentParser.js +12 -12
  94. package/dist/docx/drawingIdNormalization.d.ts +3 -1
  95. package/dist/docx/drawingIdNormalization.js +6 -1
  96. package/dist/docx/ensureParaIds.js +119 -97
  97. package/dist/docx/footnoteParser.js +8 -4
  98. package/dist/docx/headerFooterParser.js +3 -3
  99. package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
  100. package/dist/docx/headerFooterReferenceNormalization.js +52 -27
  101. package/dist/docx/hyperlinkParser.d.ts +1 -1
  102. package/dist/docx/index.d.ts +1 -1
  103. package/dist/docx/listNumberingInstances.d.ts +59 -0
  104. package/dist/docx/listNumberingInstances.js +249 -0
  105. package/dist/docx/metadataPrivacy.js +24 -1
  106. package/dist/docx/normalizeBaseDirection.js +2 -1
  107. package/dist/docx/noteReferenceMark.d.ts +15 -0
  108. package/dist/docx/noteReferenceMark.js +48 -0
  109. package/dist/docx/opaqueCarrier.d.ts +7 -0
  110. package/dist/docx/opaqueCarrier.js +38 -0
  111. package/dist/docx/packageParts.js +4 -1
  112. package/dist/docx/paragraphParser.js +96 -27
  113. package/dist/docx/paragraphPropertySource.d.ts +4 -2
  114. package/dist/docx/paragraphPropertySource.js +10 -2
  115. package/dist/docx/paragraphTraversal.js +1 -0
  116. package/dist/docx/parseWarningMessage.js +4 -1
  117. package/dist/docx/parser.js +175 -22
  118. package/dist/docx/rezip.js +31 -7
  119. package/dist/docx/sdtProperties.js +1 -1
  120. package/dist/docx/sdtPropertiesPatch.js +3 -0
  121. package/dist/docx/selectiveSave.js +16 -9
  122. package/dist/docx/selectiveXmlPatch.d.ts +3 -1
  123. package/dist/docx/selectiveXmlPatch.js +186 -39
  124. package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
  125. package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
  126. package/dist/docx/serializer/documentSerializer.js +2 -0
  127. package/dist/docx/serializer/headerFooterSerializer.js +2 -0
  128. package/dist/docx/serializer/noteSerializer.js +3 -1
  129. package/dist/docx/serializer/paragraphSerializer.js +33 -9
  130. package/dist/docx/serializer/tableSerializer.js +25 -38
  131. package/dist/docx/server/boundedArchive.d.ts +8 -13
  132. package/dist/docx/server/boundedArchive.js +70 -59
  133. package/dist/docx/server/createBilingualDocument.js +3 -3
  134. package/dist/docx/server/extractDocxText.d.ts +8 -2
  135. package/dist/docx/server/extractDocxText.js +2 -2
  136. package/dist/docx/server/validateDocxConformance.d.ts +1 -1
  137. package/dist/docx/server/validateDocxConformance.js +1 -0
  138. package/dist/docx/tableParser.d.ts +157 -1
  139. package/dist/docx/tableParser.js +89 -10
  140. package/dist/docx/textBoxParser.js +1 -1
  141. package/dist/docx/unzip.d.ts +20 -2
  142. package/dist/docx/unzip.js +136 -25
  143. package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
  144. package/dist/docx/wordprocessingPrefixes.js +286 -0
  145. package/dist/fonts/embeddedFonts.js +1 -1
  146. package/dist/i18n/messages/catalogs.gen.d.ts +170 -34
  147. package/dist/i18n/messages/catalogs.gen.js +187 -51
  148. package/dist/i18n/messages/messages.gen.d.ts +10 -2
  149. package/dist/internal/compare/inline-presentation.d.ts +2 -1
  150. package/dist/internal/compare/inline-presentation.js +11 -10
  151. package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
  152. package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
  153. package/dist/internal/indexedPositionMap.d.ts +11 -0
  154. package/dist/internal/indexedPositionMap.js +42 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
  156. package/dist/internal/revisionResolutionEdits.d.ts +13 -0
  157. package/dist/internal/revisionResolutionEdits.js +19 -0
  158. package/dist/internal/revisionResolutionInline.d.ts +24 -0
  159. package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
  160. package/dist/internal/revisionResolutionStep.d.ts +34 -0
  161. package/dist/internal/revisionResolutionStep.js +282 -0
  162. package/dist/internal/revisionResolutionTracking.d.ts +11 -0
  163. package/dist/internal/revisionResolutionTracking.js +124 -0
  164. package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
  165. package/dist/internal/wholeStoryRevisionResolution.js +600 -0
  166. package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
  167. package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
  168. package/dist/layout-bridge/convert/tableConversion.js +1 -1
  169. package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
  170. package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
  171. package/dist/layout-engine/layoutInstrumentation.js +4 -1
  172. package/dist/layout-engine/measure/cache.d.ts +18 -1
  173. package/dist/layout-engine/measure/cache.js +31 -1
  174. package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
  175. package/dist/layout-engine/measure/measureContainer.js +7 -47
  176. package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
  177. package/dist/layout-engine/measure/measureHelpers.js +22 -2
  178. package/dist/layout-engine/measure/measureParagraph.js +2 -2
  179. package/dist/layout-engine/measure/measureWorker.js +2 -3
  180. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
  181. package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
  182. package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
  183. package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
  184. package/dist/layout-engine/types.d.ts +6 -0
  185. package/dist/layout-painter/renderPage.js +1 -0
  186. package/dist/layout-painter/renderParagraph.js +1 -1
  187. package/dist/managers/ContextMenuManager.js +5 -2
  188. package/dist/managers/types.d.ts +3 -0
  189. package/dist/markdown/escape.d.ts +2 -2
  190. package/dist/markdown/escape.js +4 -5
  191. package/dist/markdown/fromMarkdown.js +2 -1
  192. package/dist/markdown/internals.d.ts +11 -1
  193. package/dist/markdown/internals.js +24 -3
  194. package/dist/markdown/renderBlock.js +121 -25
  195. package/dist/markdown/renderParagraph.d.ts +13 -1
  196. package/dist/markdown/renderParagraph.js +85 -38
  197. package/dist/markdown/renderRuns.d.ts +10 -1
  198. package/dist/markdown/renderRuns.js +323 -69
  199. package/dist/markdown/renderTable.js +24 -12
  200. package/dist/markdown/trailers.js +2 -2
  201. package/dist/markdown/types.d.ts +29 -7
  202. package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
  203. package/dist/paged-layout/incrementalMeasure.js +1 -9
  204. package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
  205. package/dist/paged-layout/transactionDirtyRange.js +29 -41
  206. package/dist/panel-layout.d.ts +83 -0
  207. package/dist/panel-layout.js +96 -0
  208. package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
  209. package/dist/prosemirror/anchoredTextBoxes.js +156 -0
  210. package/dist/prosemirror/attrs/index.d.ts +6 -2
  211. package/dist/prosemirror/attrs/index.js +172 -1
  212. package/dist/prosemirror/clearRunColor.d.ts +6 -0
  213. package/dist/prosemirror/clearRunColor.js +46 -0
  214. package/dist/prosemirror/commands/comments.d.ts +7 -8
  215. package/dist/prosemirror/commands/comments.js +281 -212
  216. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  217. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  218. package/dist/prosemirror/commands/formatPainter.js +1 -1
  219. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  220. package/dist/prosemirror/commands/hyperlink.js +2 -1
  221. package/dist/prosemirror/commands/index.d.ts +2 -2
  222. package/dist/prosemirror/commands/index.js +2 -2
  223. package/dist/prosemirror/commands/paragraph.d.ts +7 -1
  224. package/dist/prosemirror/commands/paragraph.js +9 -1
  225. package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
  226. package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
  227. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  228. package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
  229. package/dist/prosemirror/commands/propertyChangeScope.js +24 -3
  230. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
  231. package/dist/prosemirror/commands/resolveAllTableChanges.js +620 -0
  232. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
  233. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
  234. package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
  235. package/dist/prosemirror/commands/resolveParagraphProperties.js +73 -0
  236. package/dist/prosemirror/commands/sectionBreak.js +2 -1
  237. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +15 -2
  238. package/dist/prosemirror/commands/tableCellMergeResolution.js +23 -7
  239. package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
  240. package/dist/prosemirror/containerFinalParagraph.js +7 -6
  241. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  242. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
  243. package/dist/prosemirror/conversion/fromProseDoc.js +177 -605
  244. package/dist/prosemirror/conversion/toProseDoc.d.ts +4 -11
  245. package/dist/prosemirror/conversion/toProseDoc.js +70 -154
  246. package/dist/prosemirror/documentSchema.d.ts +8 -0
  247. package/dist/prosemirror/documentSchema.js +18 -0
  248. package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
  249. package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
  250. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  251. package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
  252. package/dist/prosemirror/extensions/StarterKit.js +5 -1
  253. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  254. package/dist/prosemirror/extensions/core/ParagraphExtension.js +116 -63
  255. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +4 -1
  256. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
  257. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
  258. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
  259. package/dist/prosemirror/extensions/features/ListExtension.js +167 -128
  260. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
  261. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
  262. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
  263. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
  264. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
  265. package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
  266. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  267. package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
  268. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +124 -0
  269. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +33 -11
  270. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
  271. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
  272. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
  273. package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
  274. package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
  275. package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
  276. package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
  277. package/dist/prosemirror/extensions/marks/markUtils.d.ts +15 -8
  278. package/dist/prosemirror/extensions/marks/markUtils.js +25 -10
  279. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +12 -0
  280. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +46 -0
  281. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
  282. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
  283. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
  284. package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
  285. package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
  286. package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
  287. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
  288. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  289. package/dist/prosemirror/extensions/nodes/TableExtension.js +121 -226
  290. package/dist/prosemirror/extensions/types.d.ts +11 -1
  291. package/dist/prosemirror/findReplaceSelection.js +1 -1
  292. package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
  293. package/dist/prosemirror/hyperlinkRemoval.js +129 -0
  294. package/dist/prosemirror/index.d.ts +5 -3
  295. package/dist/prosemirror/index.js +5 -3
  296. package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
  297. package/dist/prosemirror/indexedNodeLookup.js +103 -0
  298. package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
  299. package/dist/prosemirror/listAutoformatMarkers.js +98 -0
  300. package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
  301. package/dist/prosemirror/listInstanceReferences.js +72 -0
  302. package/dist/prosemirror/listLabels.d.ts +24 -0
  303. package/dist/prosemirror/listLabels.js +111 -0
  304. package/dist/prosemirror/listNumbering.d.ts +92 -0
  305. package/dist/prosemirror/listNumbering.js +330 -0
  306. package/dist/prosemirror/listRendering.d.ts +27 -0
  307. package/dist/prosemirror/listRendering.js +27 -0
  308. package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
  309. package/dist/prosemirror/listRenderingAttrs.js +8 -1
  310. package/dist/prosemirror/markupViewNotes.d.ts +8 -0
  311. package/dist/prosemirror/markupViewNotes.js +49 -0
  312. package/dist/prosemirror/markupViewProjection.d.ts +97 -0
  313. package/dist/prosemirror/markupViewProjection.js +88 -0
  314. package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
  315. package/dist/prosemirror/noteReferenceReview.js +332 -0
  316. package/dist/prosemirror/numberingAttr.d.ts +9 -1
  317. package/dist/prosemirror/numberingAttr.js +9 -1
  318. package/dist/prosemirror/outlineLevelAttr.js +1 -1
  319. package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
  320. package/dist/prosemirror/paragraphIndentation.js +32 -7
  321. package/dist/prosemirror/paragraphMarkJoin.d.ts +21 -0
  322. package/dist/prosemirror/paragraphMarkJoin.js +26 -0
  323. package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
  324. package/dist/prosemirror/paragraphPropertyCarry.js +158 -0
  325. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  326. package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
  327. package/dist/prosemirror/plugins/documentNumbering.js +97 -11
  328. package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
  329. package/dist/prosemirror/plugins/documentStyleState.js +32 -0
  330. package/dist/prosemirror/plugins/documentStyles.d.ts +3 -13
  331. package/dist/prosemirror/plugins/documentStyles.js +67 -17
  332. package/dist/prosemirror/plugins/index.d.ts +2 -1
  333. package/dist/prosemirror/plugins/index.js +2 -1
  334. package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
  335. package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
  336. package/dist/prosemirror/plugins/suggestionMode.d.ts +27 -3
  337. package/dist/prosemirror/plugins/suggestionMode.js +490 -63
  338. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  339. package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
  340. package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
  341. package/dist/prosemirror/positionSweep.d.ts +24 -0
  342. package/dist/prosemirror/positionSweep.js +222 -0
  343. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +23 -3
  344. package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
  345. package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
  346. package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
  347. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  348. package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
  349. package/dist/prosemirror/replacedAnnotations.js +170 -1
  350. package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
  351. package/dist/prosemirror/runFormattingFromMarks.js +567 -0
  352. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  353. package/dist/prosemirror/runFormattingReconciliation.js +10 -9
  354. package/dist/prosemirror/schema/index.d.ts +2 -2
  355. package/dist/prosemirror/schema/index.js +3 -0
  356. package/dist/prosemirror/schema/nodes.d.ts +44 -11
  357. package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
  358. package/dist/prosemirror/sectionMarkEdits.js +59 -0
  359. package/dist/prosemirror/storyListNumbering.d.ts +17 -0
  360. package/dist/prosemirror/storyListNumbering.js +102 -0
  361. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
  362. package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
  363. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
  364. package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
  365. package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
  366. package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
  367. package/dist/prosemirror/tableCellPaste.d.ts +74 -0
  368. package/dist/prosemirror/tableCellPaste.js +525 -0
  369. package/dist/prosemirror/tableGridMutation.d.ts +87 -2
  370. package/dist/prosemirror/tableGridMutation.js +255 -2
  371. package/dist/prosemirror/tableRunIn.d.ts +51 -0
  372. package/dist/prosemirror/tableRunIn.js +165 -0
  373. package/dist/prosemirror/textInput.js +11 -2
  374. package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
  375. package/dist/prosemirror/trackedRevisionPath.js +32 -0
  376. package/dist/prosemirror/validation.js +5 -1
  377. package/dist/redline.js +93 -9
  378. package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
  379. package/dist/render-dom/BodySelectionOverlay.js +3 -2
  380. package/dist/server.d.ts +2 -2
  381. package/dist/utils/findReplace.js +2 -2
  382. package/dist/utils/mergeDocumentContent.js +1 -1
  383. package/dist/utils/noteReferenceLabels.d.ts +36 -0
  384. package/dist/utils/noteReferenceLabels.js +32 -0
  385. package/dist/utils/replaceText.js +1 -1
  386. package/dist/version-comparison.d.ts +1 -0
  387. package/dist/version-comparison.js +1 -0
  388. package/package.json +6 -5
  389. package/dist/internal/headlessRevisionResolution.d.ts +0 -23
@@ -1,16 +1,19 @@
1
1
  import { FolioDocxReviewer, getFolioDocxComparisonAccess } from "../ai-edits/headless.js";
2
- import { detachFolioAIEditSnapshotExternalHyperlinks, numberingReferenceKeysOf, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf } from "../ai-edits/snapshot.js";
2
+ import { withComparisonNoteReferenceEdits } from "../ai-edits/note-references.js";
3
+ import { alignedNoteReferenceLabels, detachFolioAIEditSnapshotExternalHyperlinks, numberingReferenceKeysOf, relabelFolioAIEditSnapshotNoteReferences, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf } from "../ai-edits/snapshot.js";
3
4
  import { projectTableGeometry } from "../ai-edits/table-geometry.js";
4
5
  import { tableTemplateCanCrossPackageLosslessly } from "../ai-edits/table-template.js";
5
6
  import { createScopedWordDiffOptions } from "../ai-edits/word-diff.js";
6
7
  import "../document-operations.js";
7
8
  import { pairFolioDocumentStories } from "../document-stories.js";
9
+ import { isAltChunkMarkup } from "../docx/altChunk.js";
10
+ import { isOpaqueNestedRowMarkup, opaqueRevisionCarrierName } from "../docx/opaqueCarrier.js";
8
11
  import { sectionReferenceHistory } from "../docx/sectionReferenceHistory.js";
9
12
  import { sameCanonicalInlinePresentation } from "../internal/compare/inline-presentation.js";
10
13
  import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
11
14
  import { canonicalJson } from "../utils/canonicalJson.js";
12
15
  import { createContentComparisonWorkSession } from "./content.js";
13
- import { sameInlineAtoms } from "./inline-atoms.js";
16
+ import { MISSING_NOTE_DETAIL, sameInlineAtoms } from "./inline-atoms.js";
14
17
  import { sameAuthoredInlineProvenance } from "./inline-provenance.js";
15
18
  import { planStoryCompare } from "./plan.js";
16
19
  import { withFixedPackageDates } from "./reproducible-package.js";
@@ -67,6 +70,26 @@ const parseSide = async (buffer, side, author) => await Result.tryPromise({
67
70
  cause
68
71
  })
69
72
  });
73
+ const snapshotContainsUnsupportedCarrier = (snapshot) => {
74
+ let found = false;
75
+ sourceDocumentOf(snapshot).descendants((node) => {
76
+ if (node.type.name === "preservedBlock") {
77
+ const xml = node.attrs["xml"];
78
+ if (typeof xml === "string" && (isAltChunkMarkup(xml) || opaqueRevisionCarrierName(xml) !== void 0 || isOpaqueNestedRowMarkup(xml))) found = true;
79
+ }
80
+ const preserved = node.attrs["_preserved"];
81
+ if (preserved !== null && typeof preserved === "object" && "children" in preserved) {
82
+ const children = preserved.children;
83
+ if (!Array.isArray(children)) return;
84
+ for (const child of children) {
85
+ if (child === null || typeof child !== "object" || !("xml" in child)) continue;
86
+ const xml = child.xml;
87
+ if (typeof xml === "string" && (opaqueRevisionCarrierName(xml) !== void 0 || isOpaqueNestedRowMarkup(xml))) found = true;
88
+ }
89
+ }
90
+ });
91
+ return found;
92
+ };
70
93
  /** Verify formatting only where the plan claims a text-equal formatting change. */
71
94
  const formattingRoundTripFailure = ({ invariant, story, changes, actualBlocks, expectedBlocks, expectedBlockId }) => {
72
95
  const expectedIndexById = new Map(expectedBlocks.map(({ id }, index) => [id, index]));
@@ -286,6 +309,14 @@ const parseComparison = async (base, target, options) => {
286
309
  });
287
310
  continue;
288
311
  }
312
+ if (snapshotContainsUnsupportedCarrier(baseSnapshot) || snapshotContainsUnsupportedCarrier(targetSnapshot)) {
313
+ unsupported.push({
314
+ reason: "unsupported-content",
315
+ baseStory,
316
+ targetStory
317
+ });
318
+ continue;
319
+ }
289
320
  const rawBaseSnapshot = baseSnapshot;
290
321
  if (revisionFormat === "folio-exact" && baseStory.type === "main" && getFolioDocxComparisonAccess(reviewer).stageTerminalTableReviewCarrier(sourceDocumentOf(targetSnapshot))) {
291
322
  const staged = reviewer.snapshotStory(baseStory);
@@ -368,6 +399,8 @@ const parseComparison = async (base, target, options) => {
368
399
  unsupported
369
400
  });
370
401
  };
402
+ /** The note-reference markers a story's plan is written in: the base's, then the target's new notes. */
403
+ const noteReferenceLabelsOf = (pair) => alignedNoteReferenceLabels(sourceDocumentOf(pair.baseSnapshot), sourceDocumentOf(pair.targetSnapshot));
371
404
  const planCopiesNonPortableWholeTable = (pair, plan) => {
372
405
  const targetTables = new Map(storyTablesOf(pair.targetSnapshot).map(({ index, node }) => [index, node]));
373
406
  return plan.tableTemplates.some(({ targetRowIndex, targetTableIndex }) => {
@@ -389,10 +422,11 @@ const planComparison = ({ pairs }) => {
389
422
  const remainingStructuralTokenLookups = workSession.alignment.remainingStructuralTokenLookups;
390
423
  const remainingMoveComparisons = workSession.remainingMoveComparisons;
391
424
  const remainingMoveTokenLookups = workSession.remainingMoveTokenLookups;
425
+ const planningTarget = relabelFolioAIEditSnapshotNoteReferences(pair.targetSnapshot, noteReferenceLabelsOf(pair));
392
426
  let plan = planStoryCompare({
393
427
  story: pair.baseStory,
394
428
  baseSnapshot: pair.baseSnapshot,
395
- targetSnapshot: pair.targetSnapshot,
429
+ targetSnapshot: planningTarget,
396
430
  maxOperations: remainingOperations,
397
431
  wholeTableReplacement: "allow",
398
432
  workSession
@@ -405,7 +439,7 @@ const planComparison = ({ pairs }) => {
405
439
  plan = planStoryCompare({
406
440
  story: pair.baseStory,
407
441
  baseSnapshot: pair.baseSnapshot,
408
- targetSnapshot: pair.targetSnapshot,
442
+ targetSnapshot: planningTarget,
409
443
  maxOperations: remainingOperations,
410
444
  wholeTableReplacement: "avoid",
411
445
  workSession
@@ -454,7 +488,15 @@ const COMPARE_SKIP_DISPOSITION = {
454
488
  pendingRunPropertyChange: "unwritable",
455
489
  noopOperation: "unwritable",
456
490
  documentVersionMismatch: "fatal",
457
- documentNotEditable: "fatal"
491
+ documentNotEditable: "fatal",
492
+ payloadDoesNotFit: "unwritable",
493
+ overlappingOperation: "fatal",
494
+ splitsCharacter: "unwritable",
495
+ protectedReference: "unwritable",
496
+ missingStyle: "fatal",
497
+ missingNumbering: "fatal",
498
+ invalidResult: "fatal",
499
+ pendingDeletion: "unwritable"
458
500
  };
459
501
  const getCompareSkipDisposition = (reason) => COMPARE_SKIP_DISPOSITION[reason];
460
502
  /**
@@ -494,8 +536,10 @@ const resolveTableTemplates = (targetTables, requests) => {
494
536
  * what you could not represent" and "give me nothing unless you can prove it"
495
537
  * are both legitimate asks and only the caller knows which one it is making.
496
538
  */
497
- const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat, terminalTableCarrierStaged, numberingChanges, targetNumbering, targetNumberingReferences, targetNumberingReferenceMap, finalSectionComparison, styleImportFailure, pairs }, planned) => {
539
+ const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat, terminalTableCarrierStaged, numberingChanges, targetNumbering, targetNumberingReferences, targetNumberingReferenceMap, finalSectionComparison, styleImportFailure, pairs, unsupported }, planned) => {
498
540
  const relationshipIds = sectionRelationshipMap(pairs);
541
+ const baseNotes = /* @__PURE__ */ new Set();
542
+ for (const { baseStory } of [...pairs, ...unsupported]) if (baseStory?.type === "footnote" || baseStory?.type === "endnote") baseNotes.add(`${baseStory.type}:${String(baseStory.noteId)}`);
499
543
  const plannedOperationCount = planned.reduce((count, { plan }) => count + plan.operations.length, 0);
500
544
  const finalSectionOperationCount = finalSectionComparison.status === "stage" ? 1 : 0;
501
545
  if (plannedOperationCount + finalSectionOperationCount > 1e4) return Result.err(new CompareDocxOperationLimitError({
@@ -560,13 +604,14 @@ const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat,
560
604
  documentChanged ||= geometryChanged;
561
605
  idSeed = afterGeometry;
562
606
  if (plan.operations.length > 0) {
563
- const { skipped, nextRevisionId } = reviewer.applyDocumentOperationsToStory({
607
+ const operationRevisionStamp = {
608
+ date: revisionStamp.date,
609
+ idSeed
610
+ };
611
+ const { skipped, nextRevisionId } = withComparisonNoteReferenceEdits(() => reviewer.applyDocumentOperationsToStory({
564
612
  story: pair.baseStory,
565
613
  snapshot: pair.baseSnapshot,
566
- revisionStamp: {
567
- date: revisionStamp.date,
568
- idSeed
569
- },
614
+ revisionStamp: operationRevisionStamp,
570
615
  wordDiff,
571
616
  batch: {
572
617
  version: 1,
@@ -574,8 +619,9 @@ const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat,
574
619
  operations: plan.operations
575
620
  },
576
621
  tableTemplates: resolveTableTemplates(targetTables, plan.tableTemplates),
577
- replacementBackground: "keep"
578
- });
622
+ replacementBackground: "keep",
623
+ undefinedStyles: "keep"
624
+ }));
579
625
  if (nextRevisionId === void 0) panic("The applier did not report where it left the revision-id counter", { story: pair.baseStory });
580
626
  idSeed = nextRevisionId;
581
627
  documentChanged = true;
@@ -614,6 +660,8 @@ const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat,
614
660
  const atoms = comparisonAccess.matchInlineAtoms({
615
661
  story: pair.baseStory,
616
662
  targetSnapshot: pair.targetSnapshot,
663
+ noteReferenceLabels: noteReferenceLabelsOf(pair),
664
+ baseNotes,
617
665
  revisionStamp: {
618
666
  date: revisionStamp.date,
619
667
  idSeed
@@ -646,7 +694,7 @@ const applyComparison = ({ reviewer, revisionStamp, granularity, revisionFormat,
646
694
  invariant: "accept-reproduces-target",
647
695
  cause: "inline-structure",
648
696
  story: pair.baseStory,
649
- detail: "supported inline atoms could not be aligned to the revised content"
697
+ detail: atoms.detail ?? "supported inline atoms could not be aligned to the revised content"
650
698
  });
651
699
  break;
652
700
  case "budget-exceeded": return Result.err(new CompareDocxOperationLimitError({
@@ -927,8 +975,9 @@ const compareDocx = async (base, target, options) => {
927
975
  const applied = applyComparison(parsed.value, planned.value);
928
976
  if (applied.isErr()) return Result.err(applied.error);
929
977
  const { changes, verification } = applied.value;
930
- if (verification.status === "unverified" && (options.onUnverified ?? "refuse") === "refuse") {
931
- const [firstFailure] = verification.failures;
978
+ const missingNote = verification.status === "unverified" ? verification.failures.find(({ detail }) => detail === MISSING_NOTE_DETAIL) : void 0;
979
+ if (verification.status === "unverified" && (missingNote !== void 0 || (options.onUnverified ?? "refuse") === "refuse")) {
980
+ const firstFailure = missingNote ?? verification.failures[0];
932
981
  if (firstFailure === void 0) panic("An unverified comparison reported no failing invariant");
933
982
  return Result.err(new CompareDocxRoundTripError({
934
983
  message: `The generated tracked changes do not satisfy ${firstFailure.invariant}: ${firstFailure.detail}`,
@@ -17,6 +17,10 @@ type FolioContentBlockPair = {
17
17
  baseIndex: number;
18
18
  revisedIndex: number;
19
19
  };
20
+ type IncreasingPairOptions = {
21
+ priority?: (pair: FolioContentBlockPair) => number;
22
+ tieBreak?: "earliest" | "minimum-tail";
23
+ };
20
24
  /**
21
25
  * Longest strictly increasing subsequence by revised index.
22
26
  *
@@ -24,7 +28,7 @@ type FolioContentBlockPair = {
24
28
  * preserving the historical deterministic tie break while reducing the
25
29
  * stable-anchor pass from quadratic to O(n log n).
26
30
  */
27
- declare const longestIncreasingFolioContentPairs: (pairs: readonly FolioContentBlockPair[]) => FolioContentBlockPair[];
31
+ declare const longestIncreasingFolioContentPairs: (pairs: readonly FolioContentBlockPair[], options?: IncreasingPairOptions) => FolioContentBlockPair[];
28
32
  type FolioContentAlignedBlockEvent<Block extends FolioContentBlock = FolioContentBlock> = {
29
33
  type: "pair";
30
34
  baseBlock: Block;
@@ -45,15 +45,29 @@ const folioContentIdStability = (block) => block.idStability ?? "stable";
45
45
  * preserving the historical deterministic tie break while reducing the
46
46
  * stable-anchor pass from quadratic to O(n log n).
47
47
  */
48
- const longestIncreasingFolioContentPairs = (pairs) => {
48
+ const longestIncreasingFolioContentPairs = (pairs, options = {}) => {
49
49
  if (pairs.length === 0) return [];
50
50
  const coordinates = [...new Set(pairs.map(({ revisedIndex }) => revisedIndex))].toSorted((left, right) => left - right);
51
51
  const rankByCoordinate = new Map(coordinates.map((coordinate, index) => [coordinate, index + 1]));
52
- const treeLengths = new Int32Array(coordinates.length + 1);
53
52
  const treeIndexes = new Int32Array(coordinates.length + 1).fill(-1);
54
53
  const lengths = new Int32Array(pairs.length).fill(1);
55
54
  const predecessors = new Int32Array(pairs.length).fill(-1);
56
- const earlier = (leftLength, leftIndex, rightLength, rightIndex) => leftLength > rightLength || leftLength === rightLength && leftLength > 0 && leftIndex < rightIndex;
55
+ const priorities = new Int32Array(pairs.length);
56
+ const earlier = ({ leftIndex, rightIndex }) => {
57
+ const leftLength = lengths[leftIndex] ?? 0;
58
+ const rightLength = lengths[rightIndex] ?? 0;
59
+ if (leftLength !== rightLength) return leftLength > rightLength;
60
+ if (leftLength === 0) return false;
61
+ const leftPriority = priorities[leftIndex] ?? 0;
62
+ const rightPriority = priorities[rightIndex] ?? 0;
63
+ if (leftPriority !== rightPriority) return leftPriority > rightPriority;
64
+ if (options.tieBreak === "minimum-tail") {
65
+ const leftTail = pairs[leftIndex]?.revisedIndex ?? Number.POSITIVE_INFINITY;
66
+ const rightTail = pairs[rightIndex]?.revisedIndex ?? Number.POSITIVE_INFINITY;
67
+ if (leftTail !== rightTail) return leftTail < rightTail;
68
+ }
69
+ return leftIndex < rightIndex;
70
+ };
57
71
  let bestEnd = 0;
58
72
  let groupStart = 0;
59
73
  while (groupStart < pairs.length) {
@@ -63,32 +77,38 @@ const longestIncreasingFolioContentPairs = (pairs) => {
63
77
  for (let pairIndex = groupStart; pairIndex < groupEnd; pairIndex++) {
64
78
  const pair = pairs[pairIndex];
65
79
  const rank = pair === void 0 ? void 0 : rankByCoordinate.get(pair.revisedIndex);
66
- if (rank === void 0) continue;
80
+ if (rank === void 0 || pair === void 0) continue;
67
81
  let predecessorLength = 0;
68
82
  let predecessorIndex = -1;
69
83
  for (let cursor = rank - 1; cursor > 0; cursor -= cursor & -cursor) {
70
- const candidateLength = treeLengths[cursor] ?? 0;
71
84
  const candidateIndex = treeIndexes[cursor] ?? -1;
72
- if (earlier(candidateLength, candidateIndex, predecessorLength, predecessorIndex)) {
85
+ const candidateLength = lengths[candidateIndex] ?? 0;
86
+ if (earlier({
87
+ leftIndex: candidateIndex,
88
+ rightIndex: predecessorIndex
89
+ })) {
73
90
  predecessorLength = candidateLength;
74
91
  predecessorIndex = candidateIndex;
75
92
  }
76
93
  }
77
94
  lengths[pairIndex] = predecessorLength + 1;
78
95
  predecessors[pairIndex] = predecessorIndex;
79
- if ((lengths[pairIndex] ?? 0) > (lengths[bestEnd] ?? 0)) bestEnd = pairIndex;
96
+ priorities[pairIndex] = (priorities[predecessorIndex] ?? 0) + (options.priority?.(pair) ?? 0);
97
+ if (earlier({
98
+ leftIndex: pairIndex,
99
+ rightIndex: bestEnd
100
+ })) bestEnd = pairIndex;
80
101
  }
81
102
  for (let pairIndex = groupStart; pairIndex < groupEnd; pairIndex++) {
82
103
  const pair = pairs[pairIndex];
83
104
  const rank = pair === void 0 ? void 0 : rankByCoordinate.get(pair.revisedIndex);
84
105
  if (rank === void 0) continue;
85
- for (let cursor = rank; cursor < treeLengths.length; cursor += cursor & -cursor) {
86
- const currentLength = treeLengths[cursor] ?? 0;
106
+ for (let cursor = rank; cursor < treeIndexes.length; cursor += cursor & -cursor) {
87
107
  const currentIndex = treeIndexes[cursor] ?? -1;
88
- if (earlier(lengths[pairIndex] ?? 0, pairIndex, currentLength, currentIndex)) {
89
- treeLengths[cursor] = lengths[pairIndex] ?? 0;
90
- treeIndexes[cursor] = pairIndex;
91
- }
108
+ if (earlier({
109
+ leftIndex: pairIndex,
110
+ rightIndex: currentIndex
111
+ })) treeIndexes[cursor] = pairIndex;
92
112
  }
93
113
  }
94
114
  groupStart = groupEnd;
@@ -238,27 +258,14 @@ const pairByUniqueExactText = ({ base, revised, baseFrom, baseTo, revisedFrom, r
238
258
  }
239
259
  const orderedCandidates = candidates.toSorted((left, right) => left.baseIndex - right.baseIndex || left.revisedIndex - right.revisedIndex);
240
260
  if (orderedCandidates.length === 0) return [];
241
- const tailRevisedIndexes = [];
242
- const tailCandidateIndexes = [];
243
- const predecessors = new Int32Array(orderedCandidates.length).fill(-1);
244
- orderedCandidates.forEach((candidate, candidateIndex) => {
245
- let lower = 0;
246
- let upper = tailRevisedIndexes.length;
247
- while (lower < upper) {
248
- const middle = lower + Math.floor((upper - lower) / 2);
249
- if ((tailRevisedIndexes[middle] ?? Number.POSITIVE_INFINITY) < candidate.revisedIndex) lower = middle + 1;
250
- else upper = middle;
261
+ return longestIncreasingFolioContentPairs(orderedCandidates, {
262
+ tieBreak: "minimum-tail",
263
+ priority: ({ baseIndex, revisedIndex }) => {
264
+ const baseBlock = base[baseIndex];
265
+ const revisedBlock = revised[revisedIndex];
266
+ return baseBlock && revisedBlock && baseBlock.pairingFacts.id === revisedBlock.pairingFacts.id && baseBlock.pairingFacts.idStability !== revisedBlock.pairingFacts.idStability ? 1 : 0;
251
267
  }
252
- predecessors[candidateIndex] = lower === 0 ? -1 : tailCandidateIndexes[lower - 1] ?? -1;
253
- tailRevisedIndexes[lower] = candidate.revisedIndex;
254
- tailCandidateIndexes[lower] = candidateIndex;
255
268
  });
256
- const pairs = [];
257
- for (let candidateIndex = tailCandidateIndexes.at(-1) ?? -1; candidateIndex !== -1; candidateIndex = predecessors[candidateIndex] ?? -1) {
258
- const candidate = orderedCandidates[candidateIndex];
259
- if (candidate) pairs.push(candidate);
260
- }
261
- return pairs.toReversed();
262
269
  };
263
270
  /**
264
271
  * Unique exact text anchors, then again inside every sub-gap they leave:
@@ -1331,7 +1338,7 @@ const pairTableRows = ({ baseRows, revisedRows, workSession, idStability }) => {
1331
1338
  item: row,
1332
1339
  profile: rowStructureProfile(row, idStability)
1333
1340
  });
1334
- return alignProfiledContentSequence({
1341
+ const aligned = alignProfiledContentSequence({
1335
1342
  base: baseRows.map(profile),
1336
1343
  revised: revisedRows.map(profile),
1337
1344
  workSession,
@@ -1339,7 +1346,18 @@ const pairTableRows = ({ baseRows, revisedRows, workSession, idStability }) => {
1339
1346
  soleShiftedPairResiduePolicy: "row-count-evidence",
1340
1347
  primaryEvidence: "exact",
1341
1348
  similarityFactor: (base, revised) => base.profile.physicalCellCount === revised.profile.physicalCellCount ? 1 : .5
1342
- }).map((alignment) => {
1349
+ });
1350
+ const baseRow = baseRows.at(0);
1351
+ const revisedRow = revisedRows.at(0);
1352
+ if (baseRows.length === 1 && baseRow !== void 0 && revisedRow !== void 0 && !aligned.some(({ type }) => type === "pair")) return [{
1353
+ type: "pair",
1354
+ baseRow,
1355
+ revisedRow
1356
+ }, ...revisedRows.slice(1).map((row) => ({
1357
+ type: "revisedOnly",
1358
+ row
1359
+ }))];
1360
+ return aligned.map((alignment) => {
1343
1361
  switch (alignment.type) {
1344
1362
  case "pair": return {
1345
1363
  type: "pair",
@@ -116,8 +116,15 @@ type FolioContentBlock<Kind extends string = string> = {
116
116
  idStability?: FolioContentIdStability;
117
117
  /** One-based heading depth when the block has outline semantics. */
118
118
  headingLevel?: number;
119
+ /**
120
+ * The number or bullet the block shows beside its text (`2.1.`, `a)`, `•`),
121
+ * a numbered heading's included; an unnumbered heading's style id. Absent
122
+ * when the block shows neither, a marker its level hides included.
123
+ */
119
124
  displayLabel?: string;
120
125
  styleId?: string;
126
+ /** Authored `w:outlineLvl`; absent when heading depth comes only from a style. */
127
+ directOutlineLevel?: document_d_exports.OutlineLevel;
121
128
  /** Direct paragraph alignment; absent when alignment comes only from a style. */
122
129
  directAlignment?: FolioContentParagraphAlignment;
123
130
  /** Direct paragraph spacing; absent when every spacing value is inherited. */
@@ -55,12 +55,15 @@ type FolioContentTextSegment = {
55
55
  /** Target-side paragraph properties that differ from the base block. */
56
56
  type FolioContentParagraphFormattingPatch = {
57
57
  styleId?: string | null;
58
+ outlineLevel?: FolioContentBlock["directOutlineLevel"] | null;
58
59
  listLevel?: number | null;
59
60
  listReference?: FolioContentListReference | null;
60
61
  alignment?: FolioContentBlock["directAlignment"] | null;
61
62
  spacing?: FolioContentParagraphSpacing | null;
62
63
  indentation?: FolioContentParagraphIndentation | null;
63
64
  };
65
+ /** Authored outline identity, including the distinction between heading and body text. */
66
+ declare const sameFolioContentOutlineLevel: (left: FolioContentBlock["directOutlineLevel"], right: FolioContentBlock["directOutlineLevel"]) => boolean;
64
67
  /** Presentation differences for one text-aligned block pair. */
65
68
  type FolioContentFormattingChange = {
66
69
  paragraph?: FolioContentParagraphFormattingPatch;
@@ -210,4 +213,4 @@ declare const compareAlignedFolioContent: <Block extends FolioContentBlock>({ ba
210
213
  /** Compare two representation-neutral ordered content snapshots. */
211
214
  declare const compareContent: <Block extends FolioContentBlock = FolioContentBlock>(options: CompareContentOptions<Block>) => Result<FolioContentComparison<Block>, FolioContentComparisonError>;
212
215
  //#endregion
213
- export { CompareContentOptions, FOLIO_CONTENT_COMPARISON_LIMITS, FolioContentBlockProperty, FolioContentComparison, FolioContentComparisonError, FolioContentComparisonEvent, FolioContentComparisonLimit, FolioContentComparisonLimitError, FolioContentComparisonWorkSession, type FolioContentFormatRange, FolioContentFormattingChange, FolioContentInlinePresentationProjectionError, FolioContentParagraphFormattingPatch, FolioContentStructuralChange, FolioContentTextSegment, InvalidFolioContentComparisonError, changedFolioContentParagraphFormatting, compareAlignedFolioContent, compareContent, createContentComparisonWorkSession, detectFolioContentMoves, detectFolioContentParagraphMarkPlans };
216
+ export { CompareContentOptions, FOLIO_CONTENT_COMPARISON_LIMITS, FolioContentBlockProperty, FolioContentComparison, FolioContentComparisonError, FolioContentComparisonEvent, FolioContentComparisonLimit, FolioContentComparisonLimitError, FolioContentComparisonWorkSession, type FolioContentFormatRange, FolioContentFormattingChange, FolioContentInlinePresentationProjectionError, FolioContentParagraphFormattingPatch, FolioContentStructuralChange, FolioContentTextSegment, InvalidFolioContentComparisonError, changedFolioContentParagraphFormatting, compareAlignedFolioContent, compareContent, createContentComparisonWorkSession, detectFolioContentMoves, detectFolioContentParagraphMarkPlans, sameFolioContentOutlineLevel };
@@ -1,4 +1,5 @@
1
1
  import { WORD_DIFF_GRANULARITIES, createWordDiffSession } from "../ai-edits/word-diff.js";
2
+ import { outlineLevelFromAttrValue } from "../prosemirror/outlineLevelAttr.js";
2
3
  import { paragraphIndentationEqual } from "../prosemirror/paragraphIndentation.js";
3
4
  import { PARAGRAPH_ALIGNMENT_VALUES } from "../types/documentEnumValues.js";
4
5
  import { alignFolioContentStructure, contentBlocksShareContainer, createFolioContentAlignmentWorkSession } from "./content-alignment.js";
@@ -43,6 +44,8 @@ const MAX_MOVE_PROFILE_CODE_UNITS = 1048576;
43
44
  var InvalidFolioContentComparisonError = class extends TaggedError("InvalidFolioContentComparisonError") {};
44
45
  var FolioContentComparisonLimitError = class extends TaggedError("FolioContentComparisonLimitError") {};
45
46
  var FolioContentInlinePresentationProjectionError = class extends TaggedError("FolioContentInlinePresentationProjectionError") {};
47
+ /** Authored outline identity, including the distinction between heading and body text. */
48
+ const sameFolioContentOutlineLevel = (left, right) => left?.kind === right?.kind && (left?.kind !== "heading" || right?.kind === "heading" && left.level === right.level);
46
49
  const createContentComparisonWorkSession = (granularity) => ({
47
50
  alignment: createFolioContentAlignmentWorkSession(),
48
51
  remainingMoveComparisons: MAX_MOVE_SIMILARITY_COMPARISONS,
@@ -99,6 +102,7 @@ const validateParagraphFormatting = (block, side, blockIndex) => {
99
102
  if (block.headingLevel !== void 0 && (!isFiniteInteger(block.headingLevel) || block.headingLevel < 1)) return invalidInput(side, `blocks[${String(blockIndex)}].headingLevel`, "Heading levels must be positive integers.", blockIndex);
100
103
  if (block.listLevel !== void 0 && (!isFiniteInteger(block.listLevel) || block.listLevel < 0)) return invalidInput(side, `blocks[${String(blockIndex)}].listLevel`, "List levels must be non-negative integers.", blockIndex);
101
104
  if (block.directAlignment !== void 0 && !PARAGRAPH_ALIGNMENTS.has(block.directAlignment)) return invalidInput(side, `blocks[${String(blockIndex)}].directAlignment`, "Paragraph alignment is not recognized.", blockIndex);
105
+ if (block.directOutlineLevel !== void 0 && outlineLevelFromAttrValue(block.directOutlineLevel) === null) return invalidInput(side, `blocks[${String(blockIndex)}].directOutlineLevel`, "Direct outline level is not recognized.", blockIndex);
102
106
  const spacing = block.directSpacing;
103
107
  if (spacing === void 0) return null;
104
108
  if (!isRecord(spacing)) return invalidInput(side, `blocks[${String(blockIndex)}].directSpacing`, "Direct paragraph spacing must be an object.", blockIndex);
@@ -409,6 +413,7 @@ const paragraphSpacingEqual = (base, revised) => base?.spaceBefore === revised?.
409
413
  const changedFolioContentParagraphFormatting = (base, revised) => {
410
414
  const patch = {};
411
415
  if ((base.styleId ?? null) !== (revised.styleId ?? null)) patch.styleId = revised.styleId ?? null;
416
+ if (!sameFolioContentOutlineLevel(base.directOutlineLevel, revised.directOutlineLevel)) patch.outlineLevel = revised.directOutlineLevel ?? null;
412
417
  const listReferenceChanged = base.listReference?.numId !== revised.listReference?.numId;
413
418
  const targetOmitsLevelOnChangedReference = listReferenceChanged && revised.listReference !== void 0 && revised.listLevel === void 0;
414
419
  if (base.listLevel !== revised.listLevel || targetOmitsLevelOnChangedReference) patch.listLevel = revised.listLevel ?? null;
@@ -950,4 +955,4 @@ const compareContent = (options) => {
950
955
  });
951
956
  };
952
957
  //#endregion
953
- export { FOLIO_CONTENT_COMPARISON_LIMITS, FolioContentComparisonLimitError, FolioContentInlinePresentationProjectionError, InvalidFolioContentComparisonError, changedFolioContentParagraphFormatting, compareAlignedFolioContent, compareContent, createContentComparisonWorkSession, detectFolioContentMoves, detectFolioContentParagraphMarkPlans };
958
+ export { FOLIO_CONTENT_COMPARISON_LIMITS, FolioContentComparisonLimitError, FolioContentInlinePresentationProjectionError, InvalidFolioContentComparisonError, changedFolioContentParagraphFormatting, compareAlignedFolioContent, compareContent, createContentComparisonWorkSession, detectFolioContentMoves, detectFolioContentParagraphMarkPlans, sameFolioContentOutlineLevel };
@@ -5,7 +5,8 @@ import { canonicalInlinePresentationSegments } from "../internal/compare/inline-
5
5
  const inlineFormattingSegments = ({ baseBlock, targetBlock, maxSegments }) => canonicalInlinePresentationSegments({
6
6
  baseBlock,
7
7
  revisedBlock: targetBlock,
8
- maxSegments
8
+ maxSegments,
9
+ presentationBasis: baseBlock.styleId === targetBlock.styleId ? "full" : "authored"
9
10
  });
10
11
  //#endregion
11
12
  export { inlineFormattingSegments };
@@ -1,7 +1,8 @@
1
1
  import { FolioAIEditSnapshot } from "../ai-edits/types.js";
2
2
  import { FolioRevisionStamp } from "../ai-edits/apply.js";
3
- import { EditorState, Transaction } from "prosemirror-state";
3
+ import { NoteReferenceLabels } from "../ai-edits/note-references.js";
4
4
  import { Node } from "prosemirror-model";
5
+ import { EditorState, Transaction } from "prosemirror-state";
5
6
  //#region src/compare/inline-atoms.d.ts
6
7
  type MatchInlineAtomsOptions = {
7
8
  state: EditorState;
@@ -11,6 +12,17 @@ type MatchInlineAtomsOptions = {
11
12
  originalRevisionIdSeed: number;
12
13
  author: string;
13
14
  maxRanges: number;
15
+ /**
16
+ * The markers the comparison's operations wrote note references as.
17
+ * Defaults to the target story's own numbering.
18
+ */
19
+ noteReferenceLabels?: NoteReferenceLabels;
20
+ /**
21
+ * The notes the base package defines, as `footnote:<id>` / `endnote:<id>`.
22
+ * A reference the comparison writes may only name one of them. Defaults to
23
+ * the notes the story already references.
24
+ */
25
+ baseNotes?: ReadonlySet<string>;
14
26
  };
15
27
  type MatchInlineAtomsResult = {
16
28
  status: "matched";
@@ -20,16 +32,21 @@ type MatchInlineAtomsResult = {
20
32
  rangeCount: number;
21
33
  } | {
22
34
  status: "unalignable";
35
+ /** Why, when the cause is more specific than an alignment failure. */
36
+ detail?: string;
23
37
  } | {
24
38
  status: "budget-exceeded";
25
39
  };
40
+ /** A revised reference names a note the redline's package does not have. */
41
+ declare const MISSING_NOTE_DETAIL = "a note reference names a footnote or endnote the base document does not have";
26
42
  /**
27
- * Restore field, image, and page-break atoms omitted by text-only comparison operations.
43
+ * Restore field, image, and page-break atoms omitted by text-only comparison
44
+ * operations, and the note references whose markers they wrote as text.
28
45
  * Positions come from the legacy review resolver's mapping, never a guessed
29
46
  * paragraph correspondence: paragraph-mark deletions can merge paragraphs.
30
47
  */
31
- declare const matchInlineAtoms: ({ state, targetSnapshot, revisionStamp, originalRevisionIdSeed, author, maxRanges }: MatchInlineAtomsOptions) => MatchInlineAtomsResult;
48
+ declare const matchInlineAtoms: ({ state, targetSnapshot, revisionStamp, originalRevisionIdSeed, author, maxRanges, noteReferenceLabels, baseNotes }: MatchInlineAtomsOptions) => MatchInlineAtomsResult;
32
49
  /** Compare supported inline atom identity after accept or reject projection. */
33
50
  declare const sameInlineAtoms: (leftDocument: Node, rightDocument: Node) => boolean;
34
51
  //#endregion
35
- export { MatchInlineAtomsOptions, MatchInlineAtomsResult, matchInlineAtoms, sameInlineAtoms };
52
+ export { MISSING_NOTE_DETAIL, MatchInlineAtomsOptions, MatchInlineAtomsResult, matchInlineAtoms, sameInlineAtoms };