@stll/folio-core 0.67.0 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +106 -36
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  7. package/dist/ai-edits/newListNumbering.js +24 -1
  8. package/dist/ai-edits/note-references.d.ts +6 -0
  9. package/dist/ai-edits/note-references.js +7 -1
  10. package/dist/ai-edits/pending-suggestions.js +2 -2
  11. package/dist/ai-edits/read.d.ts +19 -0
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +8 -3
  14. package/dist/ai-edits/types.d.ts +9 -1
  15. package/dist/ai-suggestions/apply.js +13 -4
  16. package/dist/compare/compare.js +2 -1
  17. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  18. package/dist/compare/inserted-resource-snapshot.js +7 -3
  19. package/dist/controller/canonicalClipboard.js +31 -14
  20. package/dist/controller/canonicalComposition.js +35 -6
  21. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  22. package/dist/controller/canonicalInlineProjection.js +192 -28
  23. package/dist/controller/canonicalInput.d.ts +2 -1
  24. package/dist/controller/canonicalInput.js +32 -7
  25. package/dist/controller/canonicalListRendering.d.ts +2 -1
  26. package/dist/controller/canonicalListRendering.js +1 -1
  27. package/dist/controller/canonicalLockGuard.d.ts +23 -0
  28. package/dist/controller/canonicalLockGuard.js +133 -0
  29. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  30. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  31. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  32. package/dist/controller/canonicalPublicOperations.js +676 -46
  33. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  34. package/dist/controller/canonicalSeedContent.js +131 -0
  35. package/dist/controller/canonicalSession.d.ts +133 -21
  36. package/dist/controller/canonicalSession.js +738 -205
  37. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  38. package/dist/controller/canonicalSourceNormalization.js +148 -0
  39. package/dist/controller/canonicalStoryEditor.d.ts +4 -3
  40. package/dist/controller/canonicalStoryEditor.js +20 -15
  41. package/dist/controller/canonicalStructure.d.ts +2 -1
  42. package/dist/controller/canonicalStructure.js +129 -7
  43. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  44. package/dist/controller/contentControlWidgetController.js +13 -1
  45. package/dist/controller/folioEditor.js +4 -0
  46. package/dist/controller/headerFooterEditorManager.d.ts +7 -2
  47. package/dist/controller/headerFooterEditorManager.js +11 -6
  48. package/dist/controller/hiddenEditorApi.d.ts +17 -2
  49. package/dist/controller/hiddenEditorApi.js +4 -0
  50. package/dist/controller/hiddenEditorManager.d.ts +11 -3
  51. package/dist/controller/hiddenEditorManager.js +157 -48
  52. package/dist/controller/layoutPipeline.js +50 -16
  53. package/dist/controller/layoutSession.d.ts +3 -0
  54. package/dist/controller/layoutSession.js +3 -1
  55. package/dist/controller/noteEditorManager.d.ts +7 -2
  56. package/dist/controller/noteEditorManager.js +11 -6
  57. package/dist/display-list/build/pageFurniture.js +41 -19
  58. package/dist/display-list/build/tablePrimitives.js +23 -4
  59. package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
  60. package/dist/document-operations.d.ts +9 -1
  61. package/dist/document-operations.js +4 -3
  62. package/dist/docx/blockContentParser.d.ts +7 -3
  63. package/dist/docx/blockContentParser.js +2 -3
  64. package/dist/docx/blockPlainText.js +2 -0
  65. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  66. package/dist/docx/bookmarkRangeJoin.js +43 -0
  67. package/dist/docx/canonicalSave.js +11 -2
  68. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  69. package/dist/docx/canonicalSessionInput.js +7 -2
  70. package/dist/docx/commentAnchorIndex.d.ts +40 -5
  71. package/dist/docx/commentAnchorIndex.js +94 -12
  72. package/dist/docx/commentRangeIntegrity.js +30 -24
  73. package/dist/docx/commentRangeJoin.d.ts +4 -0
  74. package/dist/docx/commentRangeJoin.js +26 -12
  75. package/dist/docx/commentReferenceCompletion.js +5 -4
  76. package/dist/docx/commentReferenceNormalization.js +40 -18
  77. package/dist/docx/compatibility.js +9 -2
  78. package/dist/docx/containerChildren.js +22 -1
  79. package/dist/docx/contentTypeRegistry.js +1 -1
  80. package/dist/docx/encryption/compoundFile.js +9 -1
  81. package/dist/docx/encryption/encryptionInfo.js +16 -2
  82. package/dist/docx/ensureParaIds.js +46 -7
  83. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  84. package/dist/docx/ensureUniqueControlIds.js +110 -0
  85. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  86. package/dist/docx/headerFooterVerbatim.js +13 -2
  87. package/dist/docx/hostCommentThreads.d.ts +27 -0
  88. package/dist/docx/hostCommentThreads.js +72 -0
  89. package/dist/docx/hyperlinkParser.js +9 -2
  90. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  91. package/dist/docx/inlineWrapperContent.js +9 -2
  92. package/dist/docx/listMarkerComputation.d.ts +35 -1
  93. package/dist/docx/listMarkerComputation.js +39 -1
  94. package/dist/docx/listModelNormalization.d.ts +44 -1
  95. package/dist/docx/listModelNormalization.js +226 -96
  96. package/dist/docx/listNumberingInstances.d.ts +1 -1
  97. package/dist/docx/listNumberingInstances.js +2 -2
  98. package/dist/docx/markupRangeMarker.d.ts +14 -0
  99. package/dist/docx/markupRangeMarker.js +15 -1
  100. package/dist/docx/metadataPrivacy.js +43 -22
  101. package/dist/docx/normalizeBaseDirection.js +3 -1
  102. package/dist/docx/numberingIds.d.ts +6 -0
  103. package/dist/docx/numberingIds.js +6 -1
  104. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  105. package/dist/docx/numberingReferenceNormalization.js +12 -2
  106. package/dist/docx/paragraphParser.js +159 -48
  107. package/dist/docx/paragraphPropertySource.d.ts +29 -0
  108. package/dist/docx/paragraphPropertySource.js +106 -16
  109. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  110. package/dist/docx/paragraphTraversal.js +2 -0
  111. package/dist/docx/parseWarningMessage.js +2 -1
  112. package/dist/docx/parser.js +8 -0
  113. package/dist/docx/removeHeaderFooterParts.js +1 -1
  114. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  115. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  116. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  117. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  118. package/dist/docx/reviewResolutionProvenance.js +171 -33
  119. package/dist/docx/rezip.d.ts +6 -0
  120. package/dist/docx/rezip.js +38 -21
  121. package/dist/docx/selectiveSave.js +6 -10
  122. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  123. package/dist/docx/selectiveXmlPatch.js +11 -7
  124. package/dist/docx/serializer/documentSerializer.js +5 -2
  125. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  126. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  127. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  128. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  129. package/dist/docx/serializer/noteSerializer.js +23 -16
  130. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  131. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  132. package/dist/docx/serializer/partNamespaces.js +1 -1
  133. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  134. package/dist/docx/serializer/runSerializer.js +2 -2
  135. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  136. package/dist/docx/serializer/tableSerializer.js +4 -2
  137. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  138. package/dist/docx/server/build.d.ts +1 -1
  139. package/dist/docx/server/createBilingualDocument.js +27 -5
  140. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  141. package/dist/docx/sessionListPruning.d.ts +2 -0
  142. package/dist/docx/sessionListPruning.js +50 -0
  143. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  144. package/dist/docx/splitRevisionPieces.js +14 -0
  145. package/dist/docx/storyBlockReplay.js +19 -2
  146. package/dist/docx/structuralXmlPatch.js +44 -11
  147. package/dist/docx/tableParser.d.ts +6 -2
  148. package/dist/docx/tableParser.js +2 -3
  149. package/dist/docx/textBoxContentParser.d.ts +11 -0
  150. package/dist/docx/textBoxContentParser.js +51 -0
  151. package/dist/docx/textBoxParser.d.ts +0 -5
  152. package/dist/docx/textBoxParser.js +1 -23
  153. package/dist/docx/verticalMergeProjection.js +1 -1
  154. package/dist/docx/xmlParser.d.ts +1 -1
  155. package/dist/docx/xmlParser.js +2 -3
  156. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  157. package/dist/fonts/fontsourceFaces.js +1 -7
  158. package/dist/i18n/messages/ar.gen.js +3 -0
  159. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  160. package/dist/i18n/messages/catalogs.gen.js +51 -0
  161. package/dist/i18n/messages/cs.gen.js +3 -0
  162. package/dist/i18n/messages/de.gen.js +3 -0
  163. package/dist/i18n/messages/en.gen.js +3 -0
  164. package/dist/i18n/messages/es.gen.js +3 -0
  165. package/dist/i18n/messages/et.gen.js +3 -0
  166. package/dist/i18n/messages/fr.gen.js +3 -0
  167. package/dist/i18n/messages/he.gen.js +3 -0
  168. package/dist/i18n/messages/hi.gen.js +3 -0
  169. package/dist/i18n/messages/hu.gen.js +3 -0
  170. package/dist/i18n/messages/lt.gen.js +3 -0
  171. package/dist/i18n/messages/lv.gen.js +3 -0
  172. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  173. package/dist/i18n/messages/pl.gen.js +3 -0
  174. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  175. package/dist/i18n/messages/sk.gen.js +3 -0
  176. package/dist/i18n/messages/tr.gen.js +3 -0
  177. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  178. package/dist/internal/acceptedBlockProjection.js +2 -0
  179. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  180. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  181. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  182. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  183. package/dist/internal/revisionResolutionInline.js +1 -2
  184. package/dist/internal/subtreeHolds.d.ts +12 -0
  185. package/dist/internal/subtreeHolds.js +25 -0
  186. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  187. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  188. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  189. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  190. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  191. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  192. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  193. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  194. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  195. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  196. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  197. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  198. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  199. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  200. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  201. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  202. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  203. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  204. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  205. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  206. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  207. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  208. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  209. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  210. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  211. package/dist/layout-bridge/engine/hitTest.js +9 -10
  212. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  213. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  214. package/dist/layout-bridge/tableInsertHover.js +2 -1
  215. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  216. package/dist/layout-engine/footnoteContinuation.js +210 -0
  217. package/dist/layout-engine/index.d.ts +2 -2
  218. package/dist/layout-engine/index.js +7 -2
  219. package/dist/layout-engine/measure/cache.d.ts +2 -0
  220. package/dist/layout-engine/measure/cache.js +16 -6
  221. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  222. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  223. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  224. package/dist/layout-engine/tableLayout.js +29 -5
  225. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  226. package/dist/layout-engine/tableRowBreak.js +43 -1
  227. package/dist/layout-engine/types.d.ts +42 -1
  228. package/dist/layout-painter/imageLayout.js +2 -1
  229. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  230. package/dist/layout-painter/pageShellStyles.js +32 -0
  231. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  232. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  233. package/dist/layout-painter/renderFragment.js +4 -6
  234. package/dist/layout-painter/renderImage.js +2 -2
  235. package/dist/layout-painter/renderPage.d.ts +4 -4
  236. package/dist/layout-painter/renderPage.js +54 -46
  237. package/dist/layout-painter/renderParagraph.js +3 -3
  238. package/dist/layout-painter/renderTable.js +16 -16
  239. package/dist/layout-painter/renderTextBox.js +2 -2
  240. package/dist/layout-painter/sdtBoundary.js +3 -2
  241. package/dist/managers/AutoSaveManager.d.ts +5 -1
  242. package/dist/managers/FindReplaceManager.js +3 -10
  243. package/dist/markdown/escape.d.ts +20 -1
  244. package/dist/markdown/escape.js +43 -1
  245. package/dist/markdown/renderBlock.js +4 -1
  246. package/dist/markdown/renderParagraph.js +13 -27
  247. package/dist/markdown/renderTable.js +6 -2
  248. package/dist/markdown/trailers.js +1 -0
  249. package/dist/paged-layout/blockGeometry.js +3 -2
  250. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  251. package/dist/paged-layout/editorScrollRoot.js +10 -1
  252. package/dist/paged-layout/rangeProjection.js +5 -4
  253. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  254. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  255. package/dist/paged-layout/selectionViewportRect.js +8 -2
  256. package/dist/pdf/images.d.ts +17 -1
  257. package/dist/pdf/images.js +22 -4
  258. package/dist/pdf/writePdf.js +4 -2
  259. package/dist/prosemirror/attrs/index.js +2 -0
  260. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  261. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  262. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  263. package/dist/prosemirror/commands/comments.d.ts +30 -2
  264. package/dist/prosemirror/commands/comments.js +189 -18
  265. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  266. package/dist/prosemirror/commands/index.d.ts +1 -1
  267. package/dist/prosemirror/commentIdAllocator.js +2 -2
  268. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  269. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  270. package/dist/prosemirror/commentRecords.d.ts +137 -0
  271. package/dist/prosemirror/commentRecords.js +400 -0
  272. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  273. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  274. package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
  275. package/dist/prosemirror/conversion/index.d.ts +2 -2
  276. package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
  277. package/dist/prosemirror/conversion/toProseDoc.js +432 -76
  278. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  279. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  280. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  281. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  282. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  283. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
  284. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  285. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  286. package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
  287. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  288. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  289. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  290. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  291. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  292. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  293. package/dist/prosemirror/index.d.ts +3 -3
  294. package/dist/prosemirror/listLabels.js +3 -2
  295. package/dist/prosemirror/listNumbering.d.ts +6 -0
  296. package/dist/prosemirror/listNumbering.js +12 -9
  297. package/dist/prosemirror/lockedControls.d.ts +13 -0
  298. package/dist/prosemirror/lockedControls.js +106 -0
  299. package/dist/prosemirror/markupViewProjection.js +1 -1
  300. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  301. package/dist/prosemirror/nativeSelection.js +74 -0
  302. package/dist/prosemirror/noteReferenceReview.js +2 -2
  303. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  304. package/dist/prosemirror/numberedRefFields.js +16 -5
  305. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  306. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  307. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  308. package/dist/prosemirror/plugins/documentNumbering.js +37 -15
  309. package/dist/prosemirror/plugins/suggestionMode.js +33 -10
  310. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  311. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  312. package/dist/prosemirror/replacedAnnotations.js +1 -0
  313. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  314. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  315. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  316. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  317. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  318. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  319. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  320. package/dist/prosemirror/runStyleFormatting.js +16 -13
  321. package/dist/prosemirror/schema/marks.d.ts +13 -1
  322. package/dist/prosemirror/storyListNumbering.js +7 -2
  323. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  324. package/dist/prosemirror/tableResize.d.ts +10 -9
  325. package/dist/prosemirror/tableResize.js +60 -49
  326. package/dist/prosemirror/textInput.d.ts +30 -1
  327. package/dist/prosemirror/textInput.js +144 -17
  328. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  329. package/dist/prosemirror/validation.d.ts +19 -0
  330. package/dist/prosemirror/validation.js +79 -5
  331. package/dist/redline.js +23 -9
  332. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  333. package/dist/render-dom/RenderedDomContext.js +7 -6
  334. package/dist/server.d.ts +2 -2
  335. package/dist/style-sets/extract.js +2 -2
  336. package/dist/types/canonicalCapabilities.d.ts +38 -16
  337. package/dist/types/canonicalCapabilities.js +21 -18
  338. package/dist/utils/cssString.d.ts +7 -0
  339. package/dist/utils/cssString.js +9 -0
  340. package/dist/utils/findMatchView.js +4 -3
  341. package/dist/utils/fontResolver.js +4 -1
  342. package/dist/utils/formatToStyle.d.ts +1 -1
  343. package/dist/utils/mergeDocumentContent.js +2 -2
  344. package/dist/utils/paintedPositions.d.ts +60 -0
  345. package/dist/utils/paintedPositions.js +101 -0
  346. package/dist/utils/replaceText.d.ts +11 -0
  347. package/dist/utils/replaceText.js +39 -7
  348. package/dist/version-comparison.d.ts +9 -1
  349. package/dist/version-comparison.js +11 -5
  350. package/package.json +2 -3
@@ -13,11 +13,14 @@ import { cssBorderStyle } from "../utils/borderCss.js";
13
13
  import { resolveFontFamily } from "../utils/fontResolver.js";
14
14
  import { borderToStyle } from "../utils/formatToStyle.js";
15
15
  import { normalizeHorizontalScalePercent } from "../utils/horizontalScale.js";
16
+ import { shiftPaintedPositions, writePaintedRange } from "../utils/paintedPositions.js";
16
17
  import { pageHorizontalColumns, paragraphInlinePictureViewport } from "../utils/paragraphInlineLayout.js";
17
18
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
18
19
  import { eighthsToPixels, pointsToPixels } from "../utils/units.js";
19
20
  import { resolveAnchoredImagePosition as resolveAnchoredImagePosition$1 } from "./anchoredImagePosition.js";
21
+ import { applyPageShellStyles } from "./pageShellStyles.js";
20
22
  import { paintedImageSource } from "./previewSvg.js";
23
+ import { reconcileRenderedContent } from "./reconcileRenderedContent.js";
21
24
  import { renderFragment } from "./renderFragment.js";
22
25
  import { applyImageVisualAttrs, hasImageVisualAttrs, renderImageFragment } from "./renderImage.js";
23
26
  import { renderParagraphFragment } from "./renderParagraph.js";
@@ -52,22 +55,13 @@ const PAGE_CLASS_NAMES = {
52
55
  const HEADER_FOOTER_RULE_CLIP_MARGIN = pointsToPixels(1.5);
53
56
  const DEFAULT_MARGIN_GUIDE_COLOR = "#c0c0c0";
54
57
  const getDefaultPageFontFamily = () => resolveFontFamily(DEFAULT_FONT_FAMILY).cssFallback;
58
+ /** The part of a note a page shows, when the note continues across pages. */
59
+ const windowOfNote = (windows, noteId) => windows?.find((candidate) => candidate.noteId === noteId);
55
60
  /**
56
61
  * Apply page styles to an element
57
62
  */
58
63
  function applyPageStyles(element, width, height, options) {
59
- element.style.position = "relative";
60
- element.style.width = `${width}px`;
61
- element.style.height = `${height}px`;
62
- element.style.backgroundColor = options.backgroundColor ?? "var(--doc-canvas, #ffffff)";
63
- element.style.color = "var(--doc-canvas-text, #1f2937)";
64
- element.style.overflow = "hidden";
65
- element.style.border = "none";
66
- element.style.boxShadow = "none";
67
- element.style.outline = "none";
68
- element.style.fontFamily = resolveFontFamily(DEFAULT_FONT_FAMILY, options).cssFallback;
69
- element.style.fontSize = `${1056 / 72}px`;
70
- element.style.color = "var(--doc-canvas-text, #000)";
64
+ applyPageShellStyles(element, width, height, options);
71
65
  }
72
66
  function pageBorderShouldRender(pageNumber, display) {
73
67
  switch (display ?? "allPages") {
@@ -438,8 +432,7 @@ function renderFloatingImagesLayer(floatingImages, doc, layerMode = "front") {
438
432
  container.style.pointerEvents = "auto";
439
433
  container.style.top = `${floatImg.y}px`;
440
434
  container.style.left = `${floatImg.x}px`;
441
- if (floatImg.pmStart !== void 0) container.dataset["pmStart"] = String(floatImg.pmStart);
442
- if (floatImg.pmEnd !== void 0) container.dataset["pmEnd"] = String(floatImg.pmEnd);
435
+ writePaintedRange(container, floatImg.pmStart, floatImg.pmEnd);
443
436
  const img = doc.createElement("img");
444
437
  applySanitizedImageSrc(img, paintedImageSource(floatImg));
445
438
  img.style.width = `${floatImg.width}px`;
@@ -592,8 +585,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
592
585
  img.height = floatImg.height;
593
586
  if (floatImg.alt) img.alt = floatImg.alt;
594
587
  img.classList.add("layout-run", "layout-run-image");
595
- if (floatImg.pmStart !== void 0) img.dataset["pmStart"] = String(floatImg.pmStart);
596
- if (floatImg.pmEnd !== void 0) img.dataset["pmEnd"] = String(floatImg.pmEnd);
588
+ writePaintedRange(img, floatImg.pmStart, floatImg.pmEnd);
597
589
  img.style.position = "absolute";
598
590
  img.style.display = "block";
599
591
  img.style.width = `${floatImg.width}px`;
@@ -621,10 +613,11 @@ function isPositionedHeaderFooterTextBoxBlock(block) {
621
613
  * from eigenpal/docx-editor#485, extended for folio's fallback rendering
622
614
  * and any wrapper margin so the helper matches the painted stack.
623
615
  */
624
- function calculateFootnoteAreaRenderHeight(footnotes) {
616
+ function calculateFootnoteAreaRenderHeight(footnotes, windows) {
625
617
  let height = 12;
626
618
  for (const fn of footnotes) {
627
- const entryHeight = fn.content ? fn.content.height : 13;
619
+ const noteWindow = windowOfNote(windows, fn.noteId);
620
+ const entryHeight = noteWindow ? noteWindow.to - noteWindow.from : fn.content?.height ?? 13;
628
621
  height += entryHeight + 0;
629
622
  }
630
623
  return height;
@@ -652,7 +645,7 @@ function renderFlowedNoteSeparators(page, contentEl, doc) {
652
645
  * Render the footnote area at the bottom of a page.
653
646
  * Includes a separator line (33% width) and footnote entries.
654
647
  */
655
- function renderFootnoteArea(footnotes, contentWidth, doc, context) {
648
+ function renderFootnoteArea(footnotes, contentWidth, doc, context, windows) {
656
649
  const container = doc.createElement("div");
657
650
  container.className = "layout-footnote-area";
658
651
  container.style.width = `${contentWidth}px`;
@@ -671,7 +664,7 @@ function renderFootnoteArea(footnotes, contentWidth, doc, context) {
671
664
  fnEl.style.marginBottom = `0px`;
672
665
  fnEl.style.color = "var(--doc-canvas-text, #000)";
673
666
  if (fn.content) {
674
- const contentEl = renderFootnoteContent(fn, contentWidth, doc, context);
667
+ const contentEl = renderFootnoteContent(fn, contentWidth, doc, context, windowOfNote(windows, fn.noteId));
675
668
  fnEl.append(contentEl);
676
669
  } else {
677
670
  fnEl.style.fontSize = "10px";
@@ -688,7 +681,7 @@ function renderFootnoteArea(footnotes, contentWidth, doc, context) {
688
681
  }
689
682
  return container;
690
683
  }
691
- function renderFootnoteContent(footnote, contentWidth, doc, context) {
684
+ function renderFootnoteContent(footnote, contentWidth, doc, context, noteWindow) {
692
685
  const content = footnote.content;
693
686
  if (!content) panic("Missing structured footnote content");
694
687
  const wrapper = doc.createElement("div");
@@ -696,6 +689,16 @@ function renderFootnoteContent(footnote, contentWidth, doc, context) {
696
689
  wrapper.style.position = "relative";
697
690
  wrapper.style.width = `${contentWidth}px`;
698
691
  wrapper.style.height = `${content.height}px`;
692
+ const shown = noteWindow ? doc.createElement("div") : wrapper;
693
+ if (noteWindow) {
694
+ shown.className = "layout-footnote-window";
695
+ shown.style.position = "relative";
696
+ shown.style.overflow = "hidden";
697
+ shown.style.width = `${contentWidth}px`;
698
+ shown.style.height = `${noteWindow.to - noteWindow.from}px`;
699
+ wrapper.style.top = `${-noteWindow.from}px`;
700
+ shown.append(wrapper);
701
+ }
699
702
  const renderContext = {
700
703
  pageNumber: context?.pageNumber ?? 0,
701
704
  ...context?.pageNumberFormat === void 0 ? {} : { pageNumberFormat: context.pageNumberFormat },
@@ -719,7 +722,7 @@ function renderFootnoteContent(footnote, contentWidth, doc, context) {
719
722
  wrapper.append(blockEl);
720
723
  y += getFootnoteMeasureHeight(measure);
721
724
  }
722
- return wrapper;
725
+ return shown;
723
726
  }
724
727
  function renderFootnoteBlock(block, measure, contentWidth, y, context, doc) {
725
728
  const renderBlock = stripFlowBlockPmAnchors(block);
@@ -1071,9 +1074,9 @@ function renderPage(page, context, options = {}) {
1071
1074
  }
1072
1075
  renderFlowedNoteSeparators(page, contentEl, doc);
1073
1076
  if (options.footnoteArea && options.footnoteArea.length > 0) {
1074
- const fnAreaEl = renderFootnoteArea(options.footnoteArea, contentWidth, doc, context);
1077
+ const fnAreaEl = renderFootnoteArea(options.footnoteArea, contentWidth, doc, context, page.footnoteWindows);
1075
1078
  fnAreaEl.style.position = "absolute";
1076
- const reservedHeight = Math.max(page.footnoteReservedHeight ?? 0, calculateFootnoteAreaRenderHeight(options.footnoteArea));
1079
+ const reservedHeight = Math.max(page.footnoteReservedHeight ?? 0, calculateFootnoteAreaRenderHeight(options.footnoteArea, page.footnoteWindows));
1077
1080
  const contentAreaBottom = page.size.h - page.margins.bottom - page.margins.top;
1078
1081
  fnAreaEl.style.top = `${Math.max(-page.margins.top, contentAreaBottom - reservedHeight)}px`;
1079
1082
  fnAreaEl.style.left = "0";
@@ -1306,11 +1309,17 @@ function buildPageRenderArgs(page, totalPages, options) {
1306
1309
  * Compute a fingerprint string for a page that changes when its content changes.
1307
1310
  * Used to detect which pages need re-rendering on incremental updates.
1308
1311
  */
1309
- function computePageFingerprint(page, blockLookup) {
1310
- return computePageFingerprintInternal(page, blockLookup, { includePmPositions: true });
1312
+ function computePageFingerprint(page, blockLookup, footnotes) {
1313
+ return computePageFingerprintInternal(page, blockLookup, {
1314
+ includePmPositions: true,
1315
+ footnotes
1316
+ });
1311
1317
  }
1312
- function computePageRenderFingerprint(page, blockLookup) {
1313
- return computePageFingerprintInternal(page, blockLookup, { includePmPositions: false });
1318
+ function computePageRenderFingerprint(page, blockLookup, footnotes) {
1319
+ return computePageFingerprintInternal(page, blockLookup, {
1320
+ includePmPositions: false,
1321
+ footnotes
1322
+ });
1314
1323
  }
1315
1324
  const pageMarginsFingerprint = (margins) => [
1316
1325
  margins.top,
@@ -1330,7 +1339,14 @@ function computePageFingerprintInternal(page, blockLookup, options) {
1330
1339
  if (page.sectionIndex !== void 0) parts.push(`si:${page.sectionIndex}`);
1331
1340
  if (page.sectionPageNumber !== void 0) parts.push(`sp:${page.sectionPageNumber}`);
1332
1341
  if (page.headerFooterRefs) parts.push(`hf:${JSON.stringify(page.headerFooterRefs)}`);
1333
- if (page.footnoteReservedHeight) parts.push(`fn:${page.footnoteReservedHeight}`);
1342
+ if (page.footnoteReservedHeight) {
1343
+ parts.push(`fn:${page.footnoteReservedHeight}`);
1344
+ if (page.footnoteWindows) parts.push(`fnw:${JSON.stringify(page.footnoteWindows)}`);
1345
+ }
1346
+ for (const note of options.footnotes ?? []) {
1347
+ parts.push(`fnc:${note.noteId ?? ""},${note.displayNumber},${note.text ?? ""}`);
1348
+ for (const block of note.content?.blocks ?? []) parts.push(computeContentFingerprint(block), computeAnnotationFingerprint(block, false));
1349
+ }
1334
1350
  for (const frag of page.fragments) {
1335
1351
  let fp = `${frag.kind}:${frag.blockId},${frag.x},${frag.y},${frag.width},${frag.height}`;
1336
1352
  if (options.includePmPositions && frag.pmStart !== void 0) fp += `,ps:${frag.pmStart}`;
@@ -1341,6 +1357,7 @@ function computePageFingerprintInternal(page, blockLookup, options) {
1341
1357
  if (frag.headerRowCount !== void 0) fp += `,hr:${frag.headerRowCount}`;
1342
1358
  if (frag.topClip !== void 0) fp += `,tc:${frag.topClip}`;
1343
1359
  if (frag.bottomClip !== void 0) fp += `,bc:${frag.bottomClip}`;
1360
+ if (frag.cellLineBand !== void 0) fp += `,clb:${frag.cellLineBand.shownThrough}:${frag.cellLineBand.cut}:${JSON.stringify(frag.cellLineBand.cells)}`;
1344
1361
  if (frag.continuesFromPrev) fp += ",cfp";
1345
1362
  if (frag.continuesOnNext) fp += ",con";
1346
1363
  }
@@ -1583,7 +1600,8 @@ function renderPages(pages, container, options = {}) {
1583
1600
  prev.element.dataset["pageNumber"] = String(page.number);
1584
1601
  continue;
1585
1602
  }
1586
- const newFp = computePageFingerprint(page, options.blockLookup);
1603
+ const pageFootnotes = options.footnotesByPage?.get(page.number);
1604
+ const newFp = computePageFingerprint(page, options.blockLookup, pageFootnotes);
1587
1605
  if (prev.fingerprint === newFp && !totalPagesChanged && !fieldContextChanged) continue;
1588
1606
  const shell = prev.element;
1589
1607
  if (totalPagesChanged || fieldContextChanged) {
@@ -1596,7 +1614,7 @@ function renderPages(pages, container, options = {}) {
1596
1614
  shell.dataset["pageNumber"] = String(page.number);
1597
1615
  continue;
1598
1616
  }
1599
- const newRenderFp = computePageRenderFingerprint(page, options.blockLookup);
1617
+ const newRenderFp = computePageRenderFingerprint(page, options.blockLookup, pageFootnotes);
1600
1618
  if (!(!(prev.renderFingerprint !== newRenderFp) && syncRenderedPmPositionData(shell, oldPage, data.page))) repopulatePageContent(shell, prevDataMap, totalPages, options);
1601
1619
  prev.fingerprint = newFp;
1602
1620
  prev.renderFingerprint = newRenderFp;
@@ -1872,7 +1890,7 @@ function repopulatePageContent(shell, pageDataMap, totalPages, options) {
1872
1890
  if (newFontStyle && oldFontStyle) replaceRenderedPageElement(oldFontStyle, newFontStyle);
1873
1891
  else if (newFontStyle) shell.prepend(newFontStyle);
1874
1892
  else if (oldFontStyle) removeRenderedPage(oldFontStyle);
1875
- replaceRenderedPageElement(oldContentEl, newContentEl);
1893
+ if (!reconcileRenderedContent(oldContentEl, newContentEl)) replaceRenderedPageElement(oldContentEl, newContentEl);
1876
1894
  syncPageWatermarkOverlay(shell, data.page, pageOptions, options.document ?? document);
1877
1895
  releaseDisplayPageResources(fullPageEl);
1878
1896
  return;
@@ -1886,11 +1904,7 @@ function syncRenderedPmPositionData(shell, oldPage, newPage) {
1886
1904
  const delta = getUniformPagePositionDelta(oldPage, newPage);
1887
1905
  if (delta === null) return false;
1888
1906
  if (delta === 0) return true;
1889
- for (const element of shell.querySelectorAll("[data-pm-start], [data-pm-end], [data-table-pm-start]")) {
1890
- shiftNumericDatasetValue(element, "pmStart", delta);
1891
- shiftNumericDatasetValue(element, "pmEnd", delta);
1892
- shiftNumericDatasetValue(element, "tablePmStart", delta);
1893
- }
1907
+ shiftPaintedPositions(shell, delta);
1894
1908
  return true;
1895
1909
  }
1896
1910
  function getUniformPagePositionDelta(oldPage, newPage) {
@@ -1919,18 +1933,12 @@ function readPositionDelta(previous, next) {
1919
1933
  if (previous === void 0 || next === void 0) return null;
1920
1934
  return next - previous;
1921
1935
  }
1922
- function shiftNumericDatasetValue(element, key, delta) {
1923
- const value = element.dataset[key];
1924
- if (value === void 0) return;
1925
- const numeric = Number(value);
1926
- if (!Number.isFinite(numeric)) return;
1927
- element.dataset[key] = String(numeric + delta);
1928
- }
1929
1936
  function syncPageShellFingerprints(shell, data, options) {
1930
1937
  const pageState = shell.parentElement?.__pageRenderState?.pageStates[data.index];
1931
1938
  if (!pageState || pageState.element !== shell) return;
1932
- pageState.fingerprint = computePageFingerprint(data.page, options.blockLookup);
1933
- pageState.renderFingerprint = computePageRenderFingerprint(data.page, options.blockLookup);
1939
+ const pageFootnotes = options.footnotesByPage?.get(data.page.number);
1940
+ pageState.fingerprint = computePageFingerprint(data.page, options.blockLookup, pageFootnotes);
1941
+ pageState.renderFingerprint = computePageRenderFingerprint(data.page, options.blockLookup, pageFootnotes);
1934
1942
  }
1935
1943
  /**
1936
1944
  * Find the page shell whose layout fragments cover (or are nearest
@@ -16,6 +16,7 @@ import { resolveFontFamily } from "../utils/fontResolver.js";
16
16
  import "../utils/fontWeights.js";
17
17
  import { underlineDecorationCss } from "../utils/formatToStyle.js";
18
18
  import { getHorizontalScaleFactor } from "../utils/horizontalScale.js";
19
+ import { writePaintedRange } from "../utils/paintedPositions.js";
19
20
  import { getParagraphFrame } from "../utils/paragraphFrame.js";
20
21
  import { inlinePictureClipInsets, resolveParagraphLineGeometryForBlock, resolvePhysicalParagraphInlineLayout } from "../utils/paragraphInlineLayout.js";
21
22
  import { inlineImageBoundingBox, parseRotationDegrees, rotatedBoundingBox } from "../utils/rotationBoundingBox.js";
@@ -345,8 +346,7 @@ function reserveScaledAdvance({ element, unscaledWidth, horizontalScale, visualS
345
346
  * Apply PM position data attributes
346
347
  */
347
348
  function applyPmPositions(element, pmStart, pmEnd) {
348
- if (pmStart !== void 0) element.dataset["pmStart"] = String(pmStart);
349
- if (pmEnd !== void 0) element.dataset["pmEnd"] = String(pmEnd);
349
+ writePaintedRange(element, pmStart, pmEnd);
350
350
  }
351
351
  const NON_COMPRESSIBLE_WHITESPACE_PATTERN = /([^\S ]+)/gu;
352
352
  const HAS_NON_COMPRESSIBLE_WHITESPACE_PATTERN = /[^\S ]/u;
@@ -1613,7 +1613,7 @@ function bordersFormGroup(a, b) {
1613
1613
  if (!a || !b) return false;
1614
1614
  return bordersEqual(a.top, b.top) && bordersEqual(a.bottom, b.bottom) && bordersEqual(a.left, b.left) && bordersEqual(a.right, b.right) && bordersEqual(a.between, b.between);
1615
1615
  }
1616
- const paragraphHasTrackedChanges = (block) => block.reviewIndicator === "change-bar" || block.attrs?.listMarkerRevision !== void 0 || block.runs.some((run) => run.kind !== "lineBreak" && (run.isInsertion === true || run.isDeletion === true));
1616
+ const paragraphHasTrackedChanges = (block) => block.reviewIndicator === "change-bar" || block.attrs?.listMarkerRevision !== void 0 || block.attrs?.formattingRevision === true || block.runs.some((run) => run.kind !== "lineBreak" && (run.isInsertion === true || run.isDeletion === true));
1617
1617
  /**
1618
1618
  * Render a paragraph fragment
1619
1619
  *
@@ -7,6 +7,7 @@ import { resolveTableInlineOffset, resolveTableInlinePlacement } from "../layout
7
7
  import { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../layout-engine/measure/tableVisibleBand.js";
8
8
  import { isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
9
9
  import { paintsCssBorder } from "../utils/borderCss.js";
10
+ import { writePaintedRange, writePaintedTableStart } from "../utils/paintedPositions.js";
10
11
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
11
12
  import { emuToPixels } from "../utils/units.js";
12
13
  import { resolveAnchoredImagePosition } from "./anchoredImagePosition.js";
@@ -100,8 +101,7 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
100
101
  imgContainer.style.left = `${img.x}px`;
101
102
  imgContainer.style.top = `${img.y}px`;
102
103
  imgContainer.style.pointerEvents = "auto";
103
- if (img.pmStart !== void 0) imgContainer.dataset["pmStart"] = String(img.pmStart);
104
- if (img.pmEnd !== void 0) imgContainer.dataset["pmEnd"] = String(img.pmEnd);
104
+ writePaintedRange(imgContainer, img.pmStart, img.pmEnd);
105
105
  const imgEl = doc.createElement("img");
106
106
  applySanitizedImageSrc(imgEl, paintedImageSource(img));
107
107
  imgEl.style.width = `${img.width}px`;
@@ -298,8 +298,7 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
298
298
  tableEl.style.marginRight = `${placement.offset}px`;
299
299
  } else tableEl.style.marginLeft = `${placement.offset}px`;
300
300
  tableEl.dataset["blockId"] = String(block.id);
301
- if (block.pmStart !== void 0) tableEl.dataset["pmStart"] = String(block.pmStart);
302
- if (block.pmEnd !== void 0) tableEl.dataset["pmEnd"] = String(block.pmEnd);
301
+ writePaintedRange(tableEl, block.pmStart, block.pmEnd);
303
302
  const rowYPositions = [];
304
303
  let yPos = 0;
305
304
  for (const i_item of measure.rows) {
@@ -498,8 +497,7 @@ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, border
498
497
  const firstBlock = cell.blocks.at(0);
499
498
  const lastBlock = cell.blocks.at(-1);
500
499
  const pmStart = firstBlock !== void 0 && "pmStart" in firstBlock ? firstBlock.pmStart : void 0;
501
- if (pmStart !== void 0) cellEl.dataset["pmStart"] = String(pmStart);
502
- if (lastBlock && "pmEnd" in lastBlock) cellEl.dataset["pmEnd"] = String(lastBlock.pmEnd);
500
+ writePaintedRange(cellEl, pmStart, lastBlock && "pmEnd" in lastBlock ? lastBlock.pmEnd : void 0);
503
501
  }
504
502
  return cellEl;
505
503
  }
@@ -523,7 +521,7 @@ const continuationRowBottomBorderOffsets = (fragment, block, measure, cellGrid)
523
521
  snapAfterRow
524
522
  });
525
523
  };
526
- function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, visibleBand, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
524
+ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, cellBands, visibleBand, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
527
525
  const bordersSeparated = (cellSpacing ?? 0) > 0;
528
526
  const rowEl = doc.createElement("div");
529
527
  rowEl.className = TABLE_CLASS_NAMES.row;
@@ -560,9 +558,10 @@ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows,
560
558
  const drawLeft = bordersSeparated || isFirstCol || !hasVisibleBorder(leftCell?.borders?.right);
561
559
  const spacing = getTableCellSpacingInsetsY(cellSpacing, rowIndex, rowSpan, totalRows);
562
560
  const boxHeight = Math.max(0, cellHeight - spacing.top - spacing.bottom);
563
- const boxClip = contentClip ? {
564
- top: contentClip.top - spacing.top,
565
- bottom: contentClip.bottom - spacing.top
561
+ const cellClip = cellBands?.[cellIndex] ?? contentClip;
562
+ const boxClip = cellClip ? {
563
+ top: cellClip.top - spacing.top,
564
+ bottom: cellClip.bottom - spacing.top
566
565
  } : void 0;
567
566
  const paintBottomBorderSeparately = bottomBorderOffset > 0 && hasVisibleBorder(cell.borders?.bottom);
568
567
  const cellEl = renderTableCell({
@@ -638,8 +637,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
638
637
  tableEl.dataset["blockId"] = String(fragment.blockId);
639
638
  tableEl.dataset["fromRow"] = String(fragment.fromRow);
640
639
  tableEl.dataset["toRow"] = String(fragment.toRow);
641
- if (fragment.pmStart !== void 0) tableEl.dataset["pmStart"] = String(fragment.pmStart);
642
- if (fragment.pmEnd !== void 0) tableEl.dataset["pmEnd"] = String(fragment.pmEnd);
640
+ writePaintedRange(tableEl, fragment.pmStart, fragment.pmEnd);
643
641
  const tableColumnsWidth = block.bidi ? measure.columnWidths.reduce((sum, columnWidth) => sum + columnWidth, 0) : 0;
644
642
  let handleX = 0;
645
643
  for (let col = 0; col < measure.columnWidths.length - 1; col++) {
@@ -657,7 +655,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
657
655
  handle.dataset["columnIndex"] = String(col);
658
656
  handle.dataset["tableBlockId"] = String(fragment.blockId);
659
657
  if (block.bidi) handle.dataset["bidi"] = "true";
660
- if (fragment.pmStart !== void 0) handle.dataset["tablePmStart"] = String(fragment.pmStart);
658
+ if (fragment.pmStart !== void 0) writePaintedTableStart(handle, fragment.pmStart);
661
659
  tableEl.append(handle);
662
660
  }
663
661
  const rowYPositions = [];
@@ -740,7 +738,9 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
740
738
  top: rowTopClip ?? 0,
741
739
  bottom: rowBottomClip ?? rowMeasure.height
742
740
  } : void 0;
741
+ const cellBands = rowIndex === fragment.fromRow ? fragment.cellLineBand?.cells : void 0;
743
742
  const rowEl = renderTableRow({
743
+ ...cellBands ? { cellBands } : {},
744
744
  row,
745
745
  rowMeasure,
746
746
  rowIndex,
@@ -802,7 +802,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
802
802
  rowHandle.style.zIndex = "10";
803
803
  rowHandle.dataset["rowIndex"] = String(rowIdx);
804
804
  rowHandle.dataset["tableBlockId"] = String(fragment.blockId);
805
- if (fragment.pmStart !== void 0) rowHandle.dataset["tablePmStart"] = String(fragment.pmStart);
805
+ if (fragment.pmStart !== void 0) writePaintedTableStart(rowHandle, fragment.pmStart);
806
806
  tableEl.append(rowHandle);
807
807
  }
808
808
  }
@@ -819,7 +819,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
819
819
  bottomHandle.dataset["rowIndex"] = String(block.rows.length - 1);
820
820
  bottomHandle.dataset["tableBlockId"] = String(fragment.blockId);
821
821
  bottomHandle.dataset["isEdge"] = "bottom";
822
- if (fragment.pmStart !== void 0) bottomHandle.dataset["tablePmStart"] = String(fragment.pmStart);
822
+ if (fragment.pmStart !== void 0) writePaintedTableStart(bottomHandle, fragment.pmStart);
823
823
  tableEl.append(bottomHandle);
824
824
  }
825
825
  if (fragment.toRow === block.rows.length) {
@@ -836,7 +836,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
836
836
  rightHandle.dataset["columnIndex"] = String(block.bidi ? 0 : measure.columnWidths.length - 1);
837
837
  rightHandle.dataset["tableBlockId"] = String(fragment.blockId);
838
838
  rightHandle.dataset["isEdge"] = "right";
839
- if (fragment.pmStart !== void 0) rightHandle.dataset["tablePmStart"] = String(fragment.pmStart);
839
+ if (fragment.pmStart !== void 0) writePaintedTableStart(rightHandle, fragment.pmStart);
840
840
  tableEl.append(rightHandle);
841
841
  }
842
842
  return tableEl;
@@ -2,6 +2,7 @@ import { layoutTextBoxContent } from "../layout-engine/measure/textBoxParagraphL
2
2
  import { DEFAULT_TEXTBOX_MARGINS } from "../layout-engine/types.js";
3
3
  import { presetDashForOutlineAttr } from "../types/documentEnumValues.js";
4
4
  import { cssBorderStyleForDash } from "../utils/borderCss.js";
5
+ import { writePaintedRange } from "../utils/paintedPositions.js";
5
6
  import { setAuthoredBackgroundColor } from "./documentColors.js";
6
7
  import { renderParagraphFragment } from "./renderParagraph.js";
7
8
  import { panic } from "better-result";
@@ -69,8 +70,7 @@ function renderTextBoxFragment(fragment, block, measure, context, options = {})
69
70
  containerEl.style.justifyContent = block.verticalAlign === "middle" ? "center" : "flex-end";
70
71
  }
71
72
  containerEl.dataset["blockId"] = String(fragment.blockId);
72
- if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
73
- if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
73
+ writePaintedRange(containerEl, fragment.pmStart, fragment.pmEnd);
74
74
  const innerWidth = fragment.width - margins.left - margins.right;
75
75
  const contentLayout = layoutTextBoxContent(block.content, measure.innerMeasures);
76
76
  for (let i = 0; i < block.content.length; i++) {
@@ -1,3 +1,4 @@
1
+ import { readPaintedContentControlKey, writePaintedContentControlKey } from "../utils/paintedPositions.js";
1
2
  // src/layout-painter/sdtBoundary.ts
2
3
  function applySdtDataAttrs(el, sdtGroups) {
3
4
  if (!sdtGroups || sdtGroups.length === 0) return;
@@ -5,7 +6,7 @@ function applySdtDataAttrs(el, sdtGroups) {
5
6
  const innermost = sdtGroups.at(-1);
6
7
  if (innermost) {
7
8
  el.dataset["sdtId"] = innermost.id;
8
- el.dataset["sdtPmPos"] = String(innermost.pmPos);
9
+ writePaintedContentControlKey(el, innermost.pmPos);
9
10
  el.dataset["sdtType"] = innermost.sdtType;
10
11
  if (innermost.position) el.dataset["sdtPosition"] = innermost.position;
11
12
  if (innermost.alias) el.dataset["sdtAlias"] = innermost.alias;
@@ -58,7 +59,7 @@ function enclosingSdtGroupIds(doc, from, to) {
58
59
  function applySdtFocus(container, focusedIds) {
59
60
  const boxes = container.querySelectorAll("[data-sdt-boundary]");
60
61
  for (const box of boxes) {
61
- const id = box.dataset["sdtPmPos"];
62
+ const id = readPaintedContentControlKey(box);
62
63
  const on = id != null && focusedIds.has(id);
63
64
  if (on !== box.classList.contains("is-focused")) box.classList.toggle("is-focused", on);
64
65
  }
@@ -4,7 +4,11 @@ import { Subscribable } from "./Subscribable.js";
4
4
  export type AutoSaveStatus = "idle" | "saving" | "saved" | "error";
5
5
  /** Configuration for {@link AutoSaveManager}. */
6
6
  export type AutoSaveManagerOptions = {
7
- /** Storage key for localStorage (default: 'docx-editor-autosave'). */
7
+ /**
8
+ * Storage key for localStorage (default: 'docx-editor-autosave'). Recovery
9
+ * offers whatever this key holds, so a host whose origin serves several
10
+ * users or documents should derive the key from both.
11
+ */
8
12
  storageKey?: string;
9
13
  /** Save interval in milliseconds (default: 30000 - 30 seconds). */
10
14
  interval?: number;
@@ -1,5 +1,5 @@
1
1
  import { replaceEligibility } from "../utils/findReplace.js";
2
- import { replaceTextInDocument } from "../utils/replaceText.js";
2
+ import { replaceTextInDocument, replaceTextRangesInDocument } from "../utils/replaceText.js";
3
3
  // src/managers/FindReplaceManager.ts
4
4
  /**
5
5
  * The cursor index after stepping `direction` over `totalCount` matches,
@@ -103,19 +103,12 @@ var FindReplaceManager = class {
103
103
  replaceAll(document, matches, replaceText) {
104
104
  if (matches.length === 0) return null;
105
105
  const eligibleMatches = matches.filter((match) => replaceEligibility(match).status === "allowed");
106
- let skippedCount = matches.length - eligibleMatches.length;
107
- let replacedCount = 0;
108
106
  const sortedMatches = [...eligibleMatches].toSorted((a, b) => {
109
107
  if (a.paragraphIndex !== b.paragraphIndex) return b.paragraphIndex - a.paragraphIndex;
110
108
  return b.startOffset - a.startOffset;
111
109
  });
112
- let nextDocument = document;
113
- for (const match of sortedMatches) try {
114
- nextDocument = replaceTextInDocument(nextDocument, toReplaceRange(match), replaceText);
115
- replacedCount++;
116
- } catch {
117
- skippedCount++;
118
- }
110
+ const { document: nextDocument, replacedCount, failedCount } = replaceTextRangesInDocument(document, sortedMatches.map((match) => toReplaceRange(match)), replaceText);
111
+ const skippedCount = matches.length - eligibleMatches.length + failedCount;
119
112
  if (replacedCount > 0) this.result = null;
120
113
  return {
121
114
  document: nextDocument,
@@ -24,6 +24,13 @@ export declare function escapeInline(text: string): string;
24
24
  * line.
25
25
  */
26
26
  export declare function escapeTableCell(text: string): string;
27
+ /**
28
+ * CommonMark strips the blanks at the start of a line and takes the blanks
29
+ * before a line ending as the hard break's own syntax, so text blanks next to
30
+ * an inline break would be lost on reading. They are written as character
31
+ * references instead, which read back as the blanks they are.
32
+ */
33
+ export declare const protectBreakBlanks: (text: string) => string;
27
34
  /** Single-line Markdown blocks express inline breaks without their two-space syntax. */
28
35
  export declare const inlineBreaksToHtml: (text: string) => string;
29
36
  export declare function escapeLinkUrl(url: string): string;
@@ -32,4 +39,16 @@ export declare function escapeLinkUrl(url: string): string;
32
39
  * first, then the brackets that would confuse the link parser, and collapse
33
40
  * newlines so the alt stays single-line.
34
41
  */
35
- export declare function escapeAltText(text: string): string;
42
+ export declare function escapeAltText(text: string): string;
43
+ /**
44
+ * A plain paragraph whose visible text begins with markdown block syntax (e.g.
45
+ * `# Not a heading`, `- value`, `1. value`, `> quote`) would be reclassified as
46
+ * a heading/list/blockquote on re-parse, even though Word carries no matching
47
+ * style/list metadata. Escape the leading marker so literal text round-trips.
48
+ */
49
+ export declare function escapeLeadingBlockMarker(text: string): string;
50
+ /**
51
+ * Text that is not Markdown (a `text/plain` alternative-format chunk) as a
52
+ * Markdown block that reads back as the same literal text.
53
+ */
54
+ export declare const escapePlainTextBlock: (text: string) => string;
@@ -32,9 +32,37 @@ function escapeInline(text) {
32
32
  function escapeTableCell(text) {
33
33
  return inlineBreaksToHtml(text.replace(/\|/gu, "&#124;"));
34
34
  }
35
+ const TWO_SPACE_BREAK = " \n";
36
+ const BACKSLASH_BREAK = "\\\n";
37
+ /** A blank as a character reference, which no line-edge rule strips. */
38
+ const BLANK_REFERENCES = {
39
+ " ": "&#32;",
40
+ " ": "&#9;"
41
+ };
42
+ const blankReferences = (blanks) => blanks.replace(/[ \t]/gu, (blank) => BLANK_REFERENCES[blank] ?? blank);
43
+ /**
44
+ * CommonMark strips the blanks at the start of a line and takes the blanks
45
+ * before a line ending as the hard break's own syntax, so text blanks next to
46
+ * an inline break would be lost on reading. They are written as character
47
+ * references instead, which read back as the blanks they are.
48
+ */
49
+ const protectBreakBlanks = (text) => {
50
+ const lines = text.split(TWO_SPACE_BREAK);
51
+ let out = "";
52
+ lines.forEach((line, index) => {
53
+ const last = index === lines.length - 1;
54
+ const start = index === 0 ? 0 : /^[ \t]*/u.exec(line)?.[0].length ?? 0;
55
+ const end = last ? line.length : line.length - (/[ \t]*$/u.exec(line)?.[0].length ?? 0);
56
+ out += end <= start ? blankReferences(line) : blankReferences(line.slice(0, start)) + line.slice(start, end) + blankReferences(line.slice(end));
57
+ if (last) return;
58
+ out += line.length === 0 ? BACKSLASH_BREAK : TWO_SPACE_BREAK;
59
+ });
60
+ return out;
61
+ };
35
62
  /** Single-line Markdown blocks express inline breaks without their two-space syntax. */
36
63
  const inlineBreaksToHtml = (text) => text.split(/\r?\n/u).map((line, index, lines) => {
37
64
  if (index === lines.length - 1) return line;
65
+ if (line === "\\") return "";
38
66
  let end = line.length;
39
67
  while (end > 0 && line.at(end - 1) === " ") end--;
40
68
  return line.slice(0, end);
@@ -61,4 +89,18 @@ function escapeLinkUrl(url) {
61
89
  function escapeAltText(text) {
62
90
  return text.replace(/(?<ch>[\\[\]])/gu, "\\$<ch>").replace(/\r?\n/gu, " ");
63
91
  }
64
- export { escapeAltText, escapeInline, escapeLinkUrl, escapeTableCell, inlineBreaksToHtml };
92
+ /**
93
+ * A plain paragraph whose visible text begins with markdown block syntax (e.g.
94
+ * `# Not a heading`, `- value`, `1. value`, `> quote`) would be reclassified as
95
+ * a heading/list/blockquote on re-parse, even though Word carries no matching
96
+ * style/list metadata. Escape the leading marker so literal text round-trips.
97
+ */
98
+ function escapeLeadingBlockMarker(text) {
99
+ return text.replace(/^(?<ws>[ \t]*)(?<marker>[#>=])/gmu, "$<ws>\\$<marker>").replace(/^(?<ws>[ \t]*)(?<marker>[-+*])(?=[ \t]|$)/gmu, "$<ws>\\$<marker>").replace(/^(?<ws>[ \t]*)-(?=[- \t]*$)/gmu, "$<ws>\\-").replace(/^(?<ws>[ \t]*)(?<num>\d{1,9})(?<marker>[.)])(?<after>[ \t])/gmu, "$<ws>$<num>\\$<marker>$<after>");
100
+ }
101
+ /**
102
+ * Text that is not Markdown (a `text/plain` alternative-format chunk) as a
103
+ * Markdown block that reads back as the same literal text.
104
+ */
105
+ const escapePlainTextBlock = (text) => escapeLeadingBlockMarker(escapeInline(text));
106
+ export { escapeAltText, escapeInline, escapeLeadingBlockMarker, escapeLinkUrl, escapePlainTextBlock, escapeTableCell, inlineBreaksToHtml, protectBreakBlanks };
@@ -1,6 +1,7 @@
1
1
  import { ALT_CHUNK_READER_DIAGNOSTIC, isAltChunkMarkup } from "../docx/altChunk.js";
2
2
  import { OPAQUE_REVISION_CARRIER_READER_DIAGNOSTIC, isOpaqueNestedRowMarkup, opaqueRevisionCarrierName } from "../docx/opaqueCarrier.js";
3
3
  import { projectAcceptedBlocks } from "../internal/acceptedBlockProjection.js";
4
+ import { escapePlainTextBlock } from "./escape.js";
4
5
  import { pushWarning } from "./internals.js";
5
6
  import { renderParagraphBlock } from "./renderParagraph.js";
6
7
  import { renderTable } from "./renderTable.js";
@@ -43,7 +44,7 @@ function renderBlocks(ctx, pkg, blocks) {
43
44
  }
44
45
  case "preservedBlock": {
45
46
  let markdown;
46
- if (isAltChunkMarkup(block.xml)) markdown = block.readerText === void 0 ? ALT_CHUNK_READER_DIAGNOSTIC : `${ALT_CHUNK_READER_DIAGNOSTIC}\n\n${block.readerText}`;
47
+ if (isAltChunkMarkup(block.xml)) markdown = block.readerText === void 0 ? ALT_CHUNK_READER_DIAGNOSTIC : `${ALT_CHUNK_READER_DIAGNOSTIC}\n\n${escapePlainTextBlock(block.readerText)}`;
47
48
  else if (opaqueRevisionCarrierName(block.xml) !== void 0) markdown = OPAQUE_REVISION_CARRIER_READER_DIAGNOSTIC;
48
49
  else if (isOpaqueNestedRowMarkup(block.xml)) markdown = "[Unsupported nested w:tr content]";
49
50
  else return { type: "delimiter" };
@@ -55,6 +56,8 @@ function renderBlocks(ctx, pkg, blocks) {
55
56
  }
56
57
  case "bookmarkStart":
57
58
  case "bookmarkEnd":
59
+ case "commentRangeStart":
60
+ case "commentRangeEnd":
58
61
  case "moveFromRangeStart":
59
62
  case "moveFromRangeEnd":
60
63
  case "moveToRangeStart":