@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,10 +1,14 @@
1
1
  import { buildCleanBlockText } from "../ai-edits/clean-text.js";
2
- import { sourceDocumentOf } from "../ai-edits/snapshot.js";
2
+ import { noteReferenceOf } from "../ai-edits/note-references.js";
3
+ import { collectNoteReferenceLabels, sourceDocumentOf } from "../ai-edits/snapshot.js";
4
+ import { drawingXmlWithoutIdentity } from "../docx/drawingIdNormalization.js";
3
5
  import { resolveAllChangesInHeadlessStateWithMapping } from "../prosemirror/commands/comments.js";
4
6
  import { runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
5
7
  import { canonicalJson } from "../utils/canonicalJson.js";
6
8
  import { prepareTargetInlineAtom } from "./inline-atom-resources.js";
7
9
  //#region src/compare/inline-atoms.ts
10
+ /** A revised reference names a note the redline's package does not have. */
11
+ const MISSING_NOTE_DETAIL = "a note reference names a footnote or endnote the base document does not have";
8
12
  const actionRangeCount = (action) => action.kind === "replace-text" && action.textDisposition === "retained" || action.kind === "replace-atom" && action.atomDisposition === "retained" ? 2 : 1;
9
13
  const MAX_INLINE_ATOM_LCS_CELLS = 16384;
10
14
  const isSupportedAtom = (node) => node.isInline && node.isAtom && (node.type.name === "field" || node.type.name === "image" || node.type.name === "pageBreakRun");
@@ -65,6 +69,11 @@ const offsetAt = ({ offsets, position }) => {
65
69
  */
66
70
  const CONVERSION_LOCAL_ATTRS = { textBoxAnchor: ["anchorId"] };
67
71
  const documentFactAttrs = (node) => {
72
+ if (node.type.name === "field" || node.type.name === "structuredField") {
73
+ const equivalentFieldForms = node.type.name === "field" && (node.attrs["fieldKind"] === "simple" || node.attrs["fieldKind"] === "complex") && node.attrs["fieldResultIsFallback"] == null;
74
+ return Object.fromEntries(Object.entries(node.attrs).filter(([name]) => name !== "_docxFieldCode" && (!equivalentFieldForms || name !== "fieldKind")));
75
+ }
76
+ if (node.type.name === "image") return Object.fromEntries(Object.entries(node.attrs).filter(([name]) => name !== "docPrId").map(([name, value]) => [name, name === "_docxRawXml" && typeof value === "string" ? drawingXmlWithoutIdentity(value) : value]));
68
77
  const local = CONVERSION_LOCAL_ATTRS[node.type.name];
69
78
  if (!local) return node.attrs;
70
79
  return Object.fromEntries(Object.entries(node.attrs).filter(([name]) => !local.includes(name)));
@@ -74,8 +83,22 @@ const atomKey = (node) => canonicalJson({
74
83
  attrs: documentFactAttrs(node),
75
84
  content: node.content.toJSON()
76
85
  });
77
- const atomBlockOf = ({ node, from }, fieldResults) => {
78
- const clean = buildCleanBlockText(node, from, { fieldResults });
86
+ const atomBlockOf = ({ node, from }, fieldResults, noteReferences) => {
87
+ const clean = buildCleanBlockText(node, from, {
88
+ fieldResults,
89
+ noteReferences
90
+ });
91
+ const references = [];
92
+ for (const boundary of clean.structuralBoundaries) {
93
+ if (boundary.type !== "noteReference") continue;
94
+ references.push({
95
+ noteType: boundary.noteType,
96
+ noteId: boundary.noteId,
97
+ offset: boundary.offset,
98
+ length: boundary.length,
99
+ from: boundary.from
100
+ });
101
+ }
79
102
  const supported = [];
80
103
  const unsupportedTopology = [];
81
104
  node.descendants((child, relativePosition) => {
@@ -116,7 +139,8 @@ const atomBlockOf = ({ node, from }, fieldResults) => {
116
139
  cleanText: clean.text,
117
140
  offsets: clean.offsets,
118
141
  supported,
119
- unsupportedTopology
142
+ unsupportedTopology,
143
+ noteReferences: references
120
144
  };
121
145
  };
122
146
  const targetBlockIdLookup = (snapshot) => {
@@ -138,7 +162,44 @@ const targetBlockIdLookup = (snapshot) => {
138
162
  return owner?.id;
139
163
  };
140
164
  };
141
- const atomBlocksOf = (doc, fieldResults) => textBlocksOf(doc).map((block) => atomBlockOf(block, fieldResults));
165
+ const atomBlocksOf = (doc, fieldResults, noteReferences = "sourceText") => textBlocksOf(doc).map((block) => atomBlockOf(block, fieldResults, noteReferences));
166
+ const noteReferenceKey = ({ noteType, noteId }) => `${noteType}:${noteId}`;
167
+ /** Every note a story references, tracked-deleted references included. */
168
+ const referencedNotesOf = (doc) => {
169
+ const notes = /* @__PURE__ */ new Set();
170
+ doc.descendants((node) => {
171
+ const reference = noteReferenceOf(node);
172
+ if (reference) notes.add(noteReferenceKey(reference));
173
+ return !node.isText;
174
+ });
175
+ return notes;
176
+ };
177
+ const hasNoteReference = (doc) => {
178
+ let found = false;
179
+ doc.descendants((node) => {
180
+ if (found) return false;
181
+ if (noteReferenceOf(node)) found = true;
182
+ return !node.isText;
183
+ });
184
+ return found;
185
+ };
186
+ /**
187
+ * Whether this comparison inserted text that may stand for a note reference.
188
+ * Operations carry clean text, where a reference reads as its marker, so an
189
+ * operation that brings a reference writes the marker as text.
190
+ */
191
+ const wroteNoteReferenceMarker = (doc, originalRevisionIdSeed) => {
192
+ let found = false;
193
+ doc.descendants((node) => {
194
+ if (found) return false;
195
+ if (!node.isText) return true;
196
+ if (!node.text?.includes("[^") || noteReferenceOf(node)) return false;
197
+ const revisionId = node.marks.find(({ type }) => type.name === "insertion")?.attrs["revisionId"];
198
+ if (typeof revisionId === "number" && revisionId >= originalRevisionIdSeed) found = true;
199
+ return false;
200
+ });
201
+ return found;
202
+ };
142
203
  const sameBlockTopology = (left, right) => {
143
204
  if (left.node.type !== right.node.type || left.cleanText !== right.cleanText) return false;
144
205
  const supportedOffsets = /* @__PURE__ */ new Set([...left.supported.map(({ offset }) => offset), ...right.supported.map(({ offset }) => offset)]);
@@ -279,12 +340,15 @@ const sourceTextBlockIds = (source) => {
279
340
  }
280
341
  return blocks;
281
342
  };
282
- const sameParagraphSourcePosition = ({ sourceBlocks, reviewed, offset, fieldResults }) => {
343
+ const sameParagraphSourcePosition = ({ sourceBlocks, reviewed, offset, fieldResults, noteReferences }) => {
283
344
  const paraId = reviewed.node.attrs["paraId"];
284
345
  if (typeof paraId !== "string" || paraId.length === 0) return null;
285
346
  const source = sourceBlocks.get(paraId);
286
347
  if (!source || source.node.type !== reviewed.node.type) return null;
287
- const clean = buildCleanBlockText(source.node, source.from, { fieldResults });
348
+ const clean = buildCleanBlockText(source.node, source.from, {
349
+ fieldResults,
350
+ noteReferences
351
+ });
288
352
  return clean.text === reviewed.cleanText ? clean.offsets[offset] ?? null : null;
289
353
  };
290
354
  const textRangeDisposition = ({ doc, from, to, expectedText, originalRevisionIdSeed }) => {
@@ -332,14 +396,17 @@ const atomDisposition = ({ atom, originalRevisionIdSeed }) => {
332
396
  return typeof revisionId === "number" && revisionId >= originalRevisionIdSeed ? "inserted" : null;
333
397
  };
334
398
  /**
335
- * Restore field, image, and page-break atoms omitted by text-only comparison operations.
399
+ * Restore field, image, and page-break atoms omitted by text-only comparison
400
+ * operations, and the note references whose markers they wrote as text.
336
401
  * Positions come from the legacy review resolver's mapping, never a guessed
337
402
  * paragraph correspondence: paragraph-mark deletions can merge paragraphs.
338
403
  */
339
- const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisionIdSeed, author, maxRanges }) => {
404
+ const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisionIdSeed, author, maxRanges, noteReferenceLabels, baseNotes }) => {
340
405
  if (!Number.isSafeInteger(maxRanges) || maxRanges < 0) return { status: "budget-exceeded" };
341
406
  const targetDocument = sourceDocumentOf(targetSnapshot);
342
- if (!hasSupportedAtom(state.doc) && !hasSupportedAtom(targetDocument)) return {
407
+ const restoresNoteReferences = wroteNoteReferenceMarker(state.doc, originalRevisionIdSeed) && hasNoteReference(targetDocument);
408
+ const noteReferences = restoresNoteReferences ? noteReferenceLabels ?? collectNoteReferenceLabels(targetDocument) : "sourceText";
409
+ if (!restoresNoteReferences && !hasSupportedAtom(state.doc) && !hasSupportedAtom(targetDocument)) return {
343
410
  status: "matched",
344
411
  transaction: state.tr,
345
412
  nextRevisionId: revisionStamp.idSeed,
@@ -349,8 +416,8 @@ const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisi
349
416
  const reviewed = resolveAllChangesInHeadlessStateWithMapping(state, "accept");
350
417
  const targetBlockIdAt = targetBlockIdLookup(targetSnapshot);
351
418
  let sourceBlocks;
352
- const liveBlocks = atomBlocksOf(reviewed.state.doc, "text");
353
- const targetBlocks = atomBlocksOf(targetDocument, "text");
419
+ const liveBlocks = atomBlocksOf(reviewed.state.doc, "text", noteReferences);
420
+ const targetBlocks = atomBlocksOf(targetDocument, "text", noteReferences);
354
421
  if (liveBlocks.length !== targetBlocks.length) return { status: "unalignable" };
355
422
  const actions = [];
356
423
  let rangeCount = 0;
@@ -361,19 +428,63 @@ const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisi
361
428
  actions.push(action);
362
429
  return true;
363
430
  };
431
+ let referencedNotes;
364
432
  let omittedLiveBlocks;
365
433
  let omittedTargetBlocks;
366
434
  for (const [index, fullLive] of liveBlocks.entries()) {
367
435
  const fullTarget = targetBlocks[index];
368
436
  if (!fullTarget) return { status: "unalignable" };
437
+ if ((fullLive.noteReferences.length > 0 || fullTarget.noteReferences.length > 0) && fullLive.cleanText === fullTarget.cleanText) {
438
+ const kept = new Map(fullLive.noteReferences.map((reference) => [reference.offset, reference]));
439
+ for (const reference of fullTarget.noteReferences) {
440
+ const live = kept.get(reference.offset);
441
+ if (live) {
442
+ kept.delete(reference.offset);
443
+ if (noteReferenceKey(live) !== noteReferenceKey(reference) || live.length !== reference.length) return { status: "unalignable" };
444
+ continue;
445
+ }
446
+ referencedNotes ??= baseNotes ?? referencedNotesOf(state.doc);
447
+ if (!referencedNotes.has(noteReferenceKey(reference))) return {
448
+ status: "unalignable",
449
+ detail: MISSING_NOTE_DETAIL
450
+ };
451
+ const node = targetDocument.nodeAt(reference.from);
452
+ const reviewedFrom = fullLive.offsets[reference.offset];
453
+ const reviewedLast = fullLive.offsets[reference.offset + reference.length - 1];
454
+ if (!node || !noteReferenceOf(node) || reviewedFrom === void 0 || reviewedLast === void 0) return { status: "unalignable" };
455
+ const from = mappedSourcePosition({
456
+ mapping: reviewed.mapping,
457
+ position: reviewedFrom
458
+ });
459
+ const to = mappedSourcePosition({
460
+ mapping: reviewed.mapping,
461
+ position: reviewedLast + 1
462
+ });
463
+ if (from === null || to === null || textRangeDisposition({
464
+ doc: state.doc,
465
+ from,
466
+ to,
467
+ expectedText: fullTarget.cleanText.slice(reference.offset, reference.offset + reference.length),
468
+ originalRevisionIdSeed
469
+ }) !== "inserted") return { status: "unalignable" };
470
+ if (!planAction({
471
+ kind: "note-reference",
472
+ from,
473
+ to,
474
+ node,
475
+ targetBlockId: targetBlockIdAt(fullTarget.from)
476
+ })) return { status: "budget-exceeded" };
477
+ }
478
+ if (kept.size > 0) return { status: "unalignable" };
479
+ }
369
480
  if (fullLive.supported.length === 0 && fullTarget.supported.length === 0) continue;
370
481
  if (sameSupportedAtoms(fullLive, fullTarget)) continue;
371
482
  let live = fullLive;
372
483
  let target = fullTarget;
373
484
  let fieldResults = "text";
374
485
  if (!sameBlockTopology(live, target)) {
375
- omittedLiveBlocks ??= atomBlocksOf(reviewed.state.doc, "omitted");
376
- omittedTargetBlocks ??= atomBlocksOf(targetDocument, "omitted");
486
+ omittedLiveBlocks ??= atomBlocksOf(reviewed.state.doc, "omitted", noteReferences);
487
+ omittedTargetBlocks ??= atomBlocksOf(targetDocument, "omitted", noteReferences);
377
488
  const omittedLive = omittedLiveBlocks[index];
378
489
  const omittedTarget = omittedTargetBlocks[index];
379
490
  if (!omittedLive || !omittedTarget || !sameBlockTopology(omittedLive, omittedTarget)) return { status: "unalignable" };
@@ -441,7 +552,8 @@ const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisi
441
552
  sourceBlocks: sourceBlocks ??= sourceTextBlockIds(state.doc),
442
553
  reviewed: live,
443
554
  offset: atom.offset,
444
- fieldResults
555
+ fieldResults,
556
+ noteReferences
445
557
  });
446
558
  if (from === null) return { status: "unalignable" };
447
559
  const resultText = runFormattingInlineAtomResultText(atom.node);
@@ -520,6 +632,16 @@ const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisi
520
632
  if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
521
633
  continue;
522
634
  }
635
+ if (action.kind === "note-reference") {
636
+ const from = transaction.mapping.map(action.from, 1);
637
+ const to = transaction.mapping.map(action.to, -1);
638
+ const written = transaction.doc.nodeAt(from);
639
+ const noteMark = action.node.marks.find(({ type }) => type.name === "footnoteRef");
640
+ if (from >= to || !written?.isText || !noteMark) return { status: "unalignable" };
641
+ transaction.replaceWith(from, to, state.schema.text(action.node.text ?? "", noteMark.addToSet(written.marks)));
642
+ if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
643
+ continue;
644
+ }
523
645
  if (action.kind === "replace-atom") {
524
646
  const from = transaction.mapping.map(action.from, 1);
525
647
  const to = transaction.mapping.map(action.to, -1);
@@ -581,4 +703,4 @@ const sameInlineAtoms = (leftDocument, rightDocument) => {
581
703
  });
582
704
  };
583
705
  //#endregion
584
- export { matchInlineAtoms, sameInlineAtoms };
706
+ export { MISSING_NOTE_DETAIL, matchInlineAtoms, sameInlineAtoms };
@@ -1,6 +1,6 @@
1
1
  import { sourceDocumentOf, styleResolverOf } from "../ai-edits/snapshot.js";
2
2
  import { expectHyperlinkMarkAttrs, expectRunPropertyChangeMarkAttrs, expectTableCellAttrs } from "../prosemirror/attrs/index.js";
3
- import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyles.js";
3
+ import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
4
4
  import { applyMarksToRunFormattingRepresentation, expandRunFormattingCarrier, runFormattingCarrierReviewText } from "../prosemirror/runFormattingInlineCarriers.js";
5
5
  import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "../prosemirror/runFormattingReconciliation.js";
6
6
  import { nearestParagraphRunStyleContext } from "../prosemirror/runStyleFormatting.js";
@@ -223,6 +223,7 @@ const shareAContainer = (left, right) => {
223
223
  /** Narrow the neutral patch to the operation contract without explicit undefined fields. */
224
224
  const toFolioAIBlockParagraphProperties = (properties) => ({
225
225
  ...properties.styleId !== void 0 && { styleId: properties.styleId },
226
+ ...properties.outlineLevel !== void 0 && { outlineLevel: properties.outlineLevel },
226
227
  ...properties.listLevel !== void 0 && { listLevel: properties.listLevel },
227
228
  ...properties.listReference !== void 0 && { numbering: properties.listReference },
228
229
  ...properties.alignment !== void 0 && { alignment: properties.alignment },
@@ -594,18 +595,22 @@ const planStoryCompare = ({ story, baseSnapshot, targetSnapshot, maxOperations,
594
595
  const moveSourceId = moveSourceByTargetBlockId.get(block.id);
595
596
  const structuralBoundary = block.structuralBoundaries?.at(0);
596
597
  const hardPageBreak = block.text.length === 0 && block.structuralBoundaries?.length === 1 && structuralBoundary?.type === "pageBreak" && structuralBoundary.offset === 0 ? { ...structuralBoundary.clear !== void 0 && { clear: structuralBoundary.clear } } : void 0;
597
- const shared = {
598
- text: block.text,
599
- ...(block.text.includes(" ") || block.text.includes("\n")) && { lineBreakMode: "inline" },
600
- ...moveSourceId !== void 0 && { moveId: moveIdOf(moveSourceId) },
601
- ...hardPageBreak !== void 0 && { hardPageBreak },
598
+ const paragraphProperties = {
602
599
  styleId: block.styleId ?? null,
600
+ outlineLevel: block.directOutlineLevel ?? null,
603
601
  listLevel: block.listLevel ?? null,
604
602
  numbering: block.listReference ?? null,
605
603
  alignment: block.directAlignment ?? null,
606
604
  spacing: block.directSpacing ?? null,
607
605
  indentation: block.directIndentation ?? null
608
606
  };
607
+ const shared = {
608
+ text: block.text,
609
+ ...(block.text.includes(" ") || block.text.includes("\n")) && { lineBreakMode: "inline" },
610
+ ...moveSourceId !== void 0 && { moveId: moveIdOf(moveSourceId) },
611
+ ...hardPageBreak !== void 0 && { hardPageBreak },
612
+ ...paragraphProperties
613
+ };
609
614
  if (anchorId !== null) {
610
615
  operations.push({
611
616
  id: nextOperationId(),
@@ -1,5 +1,6 @@
1
1
  import { FolioDocxReviewer } from "../ai-edits/headless.js";
2
2
  import { createFolioAITextRangeHandle } from "../ai-edits/snapshot.js";
3
+ import "../document-operations.js";
3
4
  import { CompareDocxParseError, compareDocxSerializeError } from "./types.js";
4
5
  import { Result, panic } from "better-result";
5
6
  //#region src/compare/scenario.ts
@@ -234,14 +235,24 @@ const applyEditScript = async (base, script) => {
234
235
  operations: plan.operations
235
236
  });
236
237
  }
237
- const { skipped } = reviewer.applyOperations(planned.flatMap(({ operations }) => [...operations]), {
238
- mode: "direct",
239
- snapshot
238
+ const { skipped } = reviewer.applyDocumentOperationsToStory({
239
+ story: { type: "main" },
240
+ batch: {
241
+ version: 1,
242
+ mode: "direct",
243
+ operations: planned.flatMap(({ operations }) => [...operations])
244
+ },
245
+ snapshot,
246
+ undefinedStyles: "keep"
240
247
  });
241
248
  const skippedIds = new Set(skipped.map(({ id }) => id));
242
249
  const applied = [];
243
250
  for (const { step, operations } of planned) {
244
251
  if (operations.some(({ id }) => skippedIds.has(id))) {
252
+ if (!operations.every(({ id }) => skippedIds.has(id))) panic("An edit script step was applied in part", {
253
+ step,
254
+ skipped
255
+ });
245
256
  unresolved.push({
246
257
  step,
247
258
  reason: "refused"
@@ -12,7 +12,7 @@ const boundaryChildrenOf = (document) => {
12
12
  let hasChangeHistory = false;
13
13
  document.forEach((node, position) => {
14
14
  if (node.type.name !== "paragraph") {
15
- if (node.type.name === "preservedBlock") return;
15
+ if (node.type.name === "preservedBlock" || node.type.name === "blockBookmarkBoundary") return;
16
16
  children.push({
17
17
  type: "other",
18
18
  nodeType: node.type.name
@@ -25,7 +25,9 @@ type CompareDocxOptions = {
25
25
  * redline that reads plausibly and is wrong is worse than no redline.
26
26
  * `"emit"` returns the redline anyway, with `verification` naming every
27
27
  * invariant that did not hold, for a caller that would rather show its best
28
- * attempt and say what is missing.
28
+ * attempt and say what is missing. A reference to a note the base document
29
+ * does not have is refused either way: the redline would carry its marker
30
+ * as text that reads like a reference.
29
31
  */
30
32
  onUnverified?: "refuse" | "emit";
31
33
  /**
@@ -222,7 +224,7 @@ type CompareChange = {
222
224
  baseBlockIds: readonly string[];
223
225
  };
224
226
  /** Why a part of the package is absent from `changes`. */
225
- declare const COMPARE_UNSUPPORTED_REASONS: readonly ["story-missing-in-base", "story-missing-in-target", "story-not-editable"];
227
+ declare const COMPARE_UNSUPPORTED_REASONS: readonly ["story-missing-in-base", "story-missing-in-target", "story-not-editable", "unsupported-content"];
226
228
  type CompareUnsupportedReason = (typeof COMPARE_UNSUPPORTED_REASONS)[number];
227
229
  /**
228
230
  * A package part the comparison did not cover. Reported rather than dropped so
@@ -10,7 +10,8 @@ const COMPARE_REVISION_FORMATS = ["word", "folio-exact"];
10
10
  const COMPARE_UNSUPPORTED_REASONS = Object.freeze([
11
11
  "story-missing-in-base",
12
12
  "story-missing-in-target",
13
- "story-not-editable"
13
+ "story-not-editable",
14
+ "unsupported-content"
14
15
  ]);
15
16
  var InvalidCompareDocxOptionsError = class extends TaggedError("InvalidCompareDocxOptionsError") {};
16
17
  var CompareDocxParseError = class extends TaggedError("CompareDocxParseError") {};
@@ -33,7 +33,7 @@ type CompareVerification = {
33
33
  status: "unverified";
34
34
  failures: readonly CompareVerificationFailure[];
35
35
  };
36
- type ProjectedBlock = Pick<FolioAIBlock, "text" | "table" | "styleId" | "listLevel" | "listReference" | "directAlignment" | "directSpacing" | "directIndentation" | "structuralBoundaries">;
36
+ type ProjectedBlock = Pick<FolioAIBlock, "kind" | "headingLevel" | "text" | "table" | "styleId" | "directOutlineLevel" | "listLevel" | "listReference" | "directAlignment" | "directSpacing" | "directIndentation" | "structuralBoundaries">;
37
37
  type ClassifyOptions<T> = {
38
38
  invariant: CompareVerificationInvariant;
39
39
  story: FolioDocumentStoryHandle;
@@ -1,5 +1,6 @@
1
1
  import { paragraphIndentationEqual } from "../prosemirror/paragraphIndentation.js";
2
2
  import { paragraphSpacingEqual } from "../prosemirror/paragraphSpacing.js";
3
+ import { sameFolioContentOutlineLevel } from "./content.js";
3
4
  import { PARAGRAPH_MARK_CHANGE_KINDS } from "@stll/docx-core/model";
4
5
  //#region src/compare/verification.ts
5
6
  /**
@@ -8,10 +9,15 @@ import { PARAGRAPH_MARK_CHANGE_KINDS } from "@stll/docx-core/model";
8
9
  * The check compares two block projections: what accepting the generated
9
10
  * revisions leaves against the target, and what rejecting them leaves against
10
11
  * the base. A projection carries each block's container, style, list level,
11
- * direct alignment, spacing, indentation and text, so WHICH field diverged names
12
+ * direct outline level, alignment, spacing, indentation and text, so WHICH field diverged names
12
13
  * which part of the pipeline lost the difference — and that is worth reporting
13
14
  * as a typed cause rather than as one opaque "did not reproduce".
14
15
  *
16
+ * It also carries what a reader sees those properties add up to: the block's
17
+ * kind and heading level. The stated properties are what an operation writes,
18
+ * so a projection of them alone checks the applier against its own vocabulary;
19
+ * the resolved classification is checked independently of how it was reached.
20
+ *
15
21
  * Every `detail` string here is structural: counts, offsets, container kinds.
16
22
  * Never a phrase of either document, because a caller may log it, put it in a
17
23
  * report, or quote it in a review.
@@ -51,11 +57,15 @@ const sameStructuralBoundaries = (left, right) => {
51
57
  for (let index = 0; index < leftLength; index++) {
52
58
  const boundary = left[index];
53
59
  const other = right[index];
54
- if (boundary === void 0 || other === void 0 || boundary.type !== other.type || boundary.offset !== other.offset || boundary.clear !== other.clear) return false;
60
+ if (boundary === void 0 || other === void 0 || boundary.offset !== other.offset) return false;
61
+ if (boundary.type === "pageBreak") {
62
+ if (other.type !== "pageBreak" || boundary.clear !== other.clear) return false;
63
+ } else if (other.type !== "noteReference" || boundary.noteType !== other.noteType || boundary.length !== other.length) return false;
55
64
  }
56
65
  return true;
57
66
  };
58
- const sameProjectedBlock = (left, right) => sameContainer(left.table, right.table) && sameStructuralBoundaries(left.structuralBoundaries, right.structuralBoundaries) && left.styleId === right.styleId && left.listLevel === right.listLevel && left.listReference?.numId === right.listReference?.numId && left.listReference?.level === right.listReference?.level && left.directAlignment === right.directAlignment && paragraphSpacingEqual(left.directSpacing, right.directSpacing) && paragraphIndentationEqual(left.directIndentation, right.directIndentation) && left.text === right.text;
67
+ const sameClassification = (left, right) => left.kind === right.kind && left.headingLevel === right.headingLevel;
68
+ const sameProjectedBlock = (left, right) => sameContainer(left.table, right.table) && sameClassification(left, right) && sameStructuralBoundaries(left.structuralBoundaries, right.structuralBoundaries) && left.styleId === right.styleId && sameFolioContentOutlineLevel(left.directOutlineLevel, right.directOutlineLevel) && left.listLevel === right.listLevel && left.listReference?.numId === right.listReference?.numId && left.listReference?.level === right.listReference?.level && left.directAlignment === right.directAlignment && paragraphSpacingEqual(left.directSpacing, right.directSpacing) && paragraphIndentationEqual(left.directIndentation, right.directIndentation) && left.text === right.text;
59
69
  const containerKind = (container) => container ? "cell" : "body";
60
70
  const collapseWhitespace = (text) => text.replace(/\s+/gu, " ").trim();
61
71
  const sameBlockProjection = (left, right) => left.length === right.length && left.every((entry, index) => {
@@ -172,8 +182,10 @@ const classifyProjectionMismatch = ({ invariant, story, actual, expected }) => {
172
182
  if (!sameContainer(left.table, right.table)) return failure("container", `a block sits in a ${containerKind(left.table)} where it is expected in a ${containerKind(right.table)}, ${at} (${counts})`);
173
183
  if (!sameStructuralBoundaries(left.structuralBoundaries, right.structuralBoundaries)) return failure("inline-structure", `a block's zero-width inline structure does not match ${at} (${counts})`);
174
184
  if (left.text === right.text && left.styleId !== right.styleId) return failure("style", `the paragraph style did not move ${at} (${counts})`);
185
+ if (left.text === right.text && !sameFolioContentOutlineLevel(left.directOutlineLevel, right.directOutlineLevel)) return failure("style", `the direct outline level did not move ${at} (${counts})`);
175
186
  if (left.text === right.text && left.listLevel !== right.listLevel) return failure("list-level", `the list level did not move ${at} (${counts})`);
176
187
  if (left.text === right.text && (left.listReference?.numId !== right.listReference?.numId || left.listReference?.level !== right.listReference?.level)) return failure("list-level", `the numbering reference did not move ${at} (${counts})`);
188
+ if (left.text === right.text && !sameClassification(left, right)) return left.kind === "heading" || right.kind === "heading" ? failure("style", `the heading classification did not move ${at} (${counts})`) : failure("list-level", `the list membership did not move ${at} (${counts})`);
177
189
  if (left.text === right.text && left.directAlignment !== right.directAlignment) return failure("alignment", `the direct paragraph alignment did not move ${at} (${counts})`);
178
190
  if (left.text === right.text && !paragraphSpacingEqual(left.directSpacing, right.directSpacing)) return failure("spacing", `the direct paragraph spacing did not move ${at} (${counts})`);
179
191
  if (left.text === right.text && !paragraphIndentationEqual(left.directIndentation, right.directIndentation)) return failure("indentation", `the direct paragraph indentation did not move ${at} (${counts})`);
@@ -0,0 +1,25 @@
1
+ import { DirtyRange } from "../paged-layout/incrementalMeasure.js";
2
+ import { LayoutTemplatePreview } from "./layoutSession.js";
3
+ import { Node } from "prosemirror-model";
4
+ //#region src/controller/committedLayoutDiff.d.ts
5
+ type LayoutFlowSource = {
6
+ doc: Node;
7
+ preview: LayoutTemplatePreview;
8
+ };
9
+ type CommittedLayoutDiff = {
10
+ type: "full";
11
+ } | {
12
+ type: "range";
13
+ /** In the next document's positions. */
14
+ range: DirtyRange;
15
+ };
16
+ /**
17
+ * The span of `next` whose flow blocks may differ from the ones the committed
18
+ * layout measured for `committed`, or `full` when no span bounds it.
19
+ *
20
+ * `full` also covers "nothing in the body flow changed": such a pass was
21
+ * requested for an input outside it (a header, footer or note story).
22
+ */
23
+ declare const diffAgainstCommittedLayout: (committed: LayoutFlowSource, next: LayoutFlowSource) => CommittedLayoutDiff;
24
+ //#endregion
25
+ export { CommittedLayoutDiff, LayoutFlowSource, diffAgainstCommittedLayout };
@@ -0,0 +1,71 @@
1
+ import { templatePreviewDirtyRange } from "../layout-bridge/convert/templatePreviewFlow.js";
2
+ //#region src/controller/committedLayoutDiff.ts
3
+ const FULL = { type: "full" };
4
+ const diffDocuments = (before, after) => {
5
+ const start = before.content.findDiffStart(after.content);
6
+ if (start === null) return null;
7
+ const end = before.content.findDiffEnd(after.content);
8
+ if (end === null) return null;
9
+ const overlap = start - Math.min(end.a, end.b);
10
+ return overlap > 0 ? {
11
+ start,
12
+ endBefore: end.a + overlap,
13
+ endAfter: end.b + overlap
14
+ } : {
15
+ start,
16
+ endBefore: end.a,
17
+ endAfter: end.b
18
+ };
19
+ };
20
+ /** Map a range of the previous document into the next one's positions. */
21
+ const mapRangeThroughDiff = (range, diff) => {
22
+ const shift = diff.endAfter - diff.endBefore;
23
+ const mapPosition = (pos, insideChange) => {
24
+ if (pos < diff.start) return pos;
25
+ if (pos >= diff.endBefore) return pos + shift;
26
+ return insideChange;
27
+ };
28
+ return {
29
+ ...range,
30
+ from: mapPosition(range.from, diff.start),
31
+ to: mapPosition(range.to, diff.endAfter)
32
+ };
33
+ };
34
+ const mapPreviewThroughDiff = (preview, diff) => ({
35
+ entries: preview.entries.map((entry) => mapRangeThroughDiff(entry, diff)),
36
+ hidden: preview.hidden.map((range) => mapRangeThroughDiff(range, diff))
37
+ });
38
+ const unionRanges = (first, second) => {
39
+ if (!first) return second;
40
+ if (!second) return first;
41
+ return {
42
+ from: Math.min(first.from, second.from),
43
+ to: Math.max(first.to, second.to)
44
+ };
45
+ };
46
+ /**
47
+ * The span of `next` whose flow blocks may differ from the ones the committed
48
+ * layout measured for `committed`, or `full` when no span bounds it.
49
+ *
50
+ * `full` also covers "nothing in the body flow changed": such a pass was
51
+ * requested for an input outside it (a header, footer or note story).
52
+ */
53
+ const diffAgainstCommittedLayout = (committed, next) => {
54
+ if (committed.preview.mode !== next.preview.mode) return FULL;
55
+ if (!committed.doc.sameMarkup(next.doc)) return FULL;
56
+ const docDiff = diffDocuments(committed.doc, next.doc);
57
+ let range = docDiff ? {
58
+ from: docDiff.start,
59
+ to: docDiff.endAfter
60
+ } : null;
61
+ if (committed.preview.entries !== next.preview.entries || committed.preview.hidden !== next.preview.hidden) {
62
+ const previousPreview = docDiff ? mapPreviewThroughDiff(committed.preview, docDiff) : committed.preview;
63
+ range = unionRanges(range, templatePreviewDirtyRange(previousPreview, next.preview));
64
+ }
65
+ return range ? {
66
+ type: "range",
67
+ range
68
+ } : FULL;
69
+ };
70
+ //#endregion
71
+ export { diffAgainstCommittedLayout };
@@ -1,5 +1,5 @@
1
- import { ContentControlWidgetEvent } from "../prosemirror/plugins/contentControlWidgets.js";
2
1
  import { Subscribable } from "../managers/Subscribable.js";
2
+ import { ContentControlWidgetEvent } from "../prosemirror/plugins/contentControlWidgets.js";
3
3
  import { EditorView } from "prosemirror-view";
4
4
  //#region src/controller/contentControlWidgetController.d.ts
5
5
  type ContentControlListItem = {
@@ -3,7 +3,7 @@ import { DocxInput } from "../utils/docxInput.js";
3
3
  import { Layout } from "../layout-engine/types.js";
4
4
  import { HiddenEditorApi } from "./hiddenEditorApi.js";
5
5
  import { FolioEditorEmitter } from "./folioEditorEvents.js";
6
- import { LayoutRunOptions } from "./layoutScheduler.js";
6
+ import { LayoutRunOptions } from "./layoutRunOptions.js";
7
7
  import { EditorState } from "prosemirror-state";
8
8
  //#region src/controller/folioEditor.d.ts
9
9
  type FolioEditorDeps = {
@@ -1,8 +1,58 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { EditorState } from "prosemirror-state";
3
3
  //#region src/controller/fontReadiness.d.ts
4
+ /** The parts of a `FontFace` layout readiness reads. */
5
+ type LayoutFontSetFace = Pick<FontFace, "family" | "status">;
6
+ type LayoutFontSetListener = (event: {
7
+ fontfaces: readonly LayoutFontSetFace[];
8
+ }) => void;
9
+ /**
10
+ * The parts of a `FontFaceSet` layout readiness uses; `document.fonts` in a
11
+ * browser, a scripted stand-in in tests.
12
+ */
13
+ type LayoutFontSet = Iterable<LayoutFontSetFace> & {
14
+ load: (font: string, text?: string) => Promise<unknown>;
15
+ readonly ready: Promise<unknown>;
16
+ addEventListener: (type: "loadingdone", listener: LayoutFontSetListener) => void;
17
+ removeEventListener: (type: "loadingdone", listener: LayoutFontSetListener) => void;
18
+ };
4
19
  declare function getDocumentFontSet(): FontFaceSet | null;
5
- declare function documentFontsAreLoaded(): boolean;
20
+ /**
21
+ * Names the faces available to measurement: which faces of the families
22
+ * measured stacks name have loaded. Equal signatures mean every measured glyph
23
+ * resolves to the same face, so a measurement taken under one is valid under
24
+ * the other; a host UI face loading leaves it unchanged.
25
+ *
26
+ * Counted over loaded faces only (a face never unloads, and a failed one adds
27
+ * no glyphs) with a per-face identity sum, so a removal replaced by an addition
28
+ * still changes it: a new face's id exceeds every earlier one. The family set
29
+ * only grows, and a family joins it when first measured, so read it after
30
+ * measuring to name what a layout measured in. Without a font set (a server or
31
+ * headless host) there is nothing to load and the signature is constant.
32
+ */
33
+ declare function readFontSetSignature(fontSet?: LayoutFontSet | null): string;
34
+ type WatchLayoutFontLoadsOptions = {
35
+ /**
36
+ * The font-set signature the committed layout was measured in, or `null`
37
+ * before one is committed (the first layout measures whatever has loaded).
38
+ */
39
+ measuredFontSet: () => string | null;
40
+ relayout: () => void;
41
+ fontSet?: LayoutFontSet | null;
42
+ };
43
+ /**
44
+ * Re-run layout whenever a face that can change a measured width finishes
45
+ * loading after the committed layout measured without it.
46
+ *
47
+ * Tied to what loaded, never to a time window: fontsource splits each face
48
+ * into `unicode-range` subsets the browser fetches when painted text first
49
+ * needs them, so a subset can land at any moment after the first layout. A
50
+ * load the committed layout already saw (its event can arrive after the layout
51
+ * ran) leaves the signature unchanged and relays nothing, as does a face of a
52
+ * family no measured stack names (a host UI font). Returns the unsubscribe
53
+ * function.
54
+ */
55
+ declare function watchLayoutFontLoads({ measuredFontSet, relayout, fontSet }: WatchLayoutFontLoadsOptions): () => void;
6
56
  declare const LAYOUT_FONT_DESCRIPTORS: readonly [{
7
57
  readonly style: "normal";
8
58
  readonly weight: 400;
@@ -21,8 +71,25 @@ type LayoutFontFace = {
21
71
  style: (typeof LAYOUT_FONT_DESCRIPTORS)[number]["style"];
22
72
  weight: (typeof LAYOUT_FONT_DESCRIPTORS)[number]["weight"];
23
73
  };
24
- declare function waitForInitialLayoutFonts(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): Promise<boolean>;
74
+ /**
75
+ * Resolve once every face the first layout will measure has loaded (`true`),
76
+ * or after a timeout (`false`), so the first layout does not measure fallbacks.
77
+ *
78
+ * Each face is loaded for the document's own characters. A bundled face is a
79
+ * set of `unicode-range` subsets, and `FontFaceSet.load` fetches only the
80
+ * subsets covering the text it is given; without text it takes a single space
81
+ * and loads only the Latin subset, so Czech, Polish, Greek and Cyrillic were
82
+ * measured in a fallback.
83
+ */
84
+ declare function waitForInitialLayoutFonts(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"], fontSet?: LayoutFontSet | null): Promise<boolean>;
85
+ /**
86
+ * Every distinct character the layout will measure, as one string: the body
87
+ * text (tracked deletions included, since All Markup paints them), list
88
+ * markers, headers, footers and notes. Always carries a space, which every
89
+ * line measures.
90
+ */
91
+ declare function collectLayoutText(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): string;
25
92
  declare function collectInitialLayoutFontFamilies(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): Set<string>;
26
93
  declare function collectInitialLayoutFontFaces(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): LayoutFontFace[];
27
94
  //#endregion
28
- export { LayoutFontFace, collectInitialLayoutFontFaces, collectInitialLayoutFontFamilies, documentFontsAreLoaded, getDocumentFontSet, waitForInitialLayoutFonts };
95
+ export { LayoutFontFace, LayoutFontSet, LayoutFontSetFace, WatchLayoutFontLoadsOptions, collectInitialLayoutFontFaces, collectInitialLayoutFontFamilies, collectLayoutText, getDocumentFontSet, readFontSetSignature, waitForInitialLayoutFonts, watchLayoutFontLoads };