@stll/folio-core 0.66.2 → 0.68.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 (323) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +138 -17
  3. package/dist/ai-edits/batch-claims.js +5 -3
  4. package/dist/ai-edits/clean-text.js +4 -1
  5. package/dist/ai-edits/headless.d.ts +36 -21
  6. package/dist/ai-edits/headless.js +104 -34
  7. package/dist/ai-edits/index.d.ts +2 -2
  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/read.d.ts +19 -0
  11. package/dist/ai-edits/read.js +6 -4
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +32 -17
  14. package/dist/ai-edits/table-cell-mutations.js +3 -2
  15. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  16. package/dist/ai-edits/types.d.ts +9 -1
  17. package/dist/ai-suggestions/apply.js +13 -4
  18. package/dist/compare/compare.js +2 -1
  19. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  20. package/dist/compare/inserted-resource-snapshot.js +7 -3
  21. package/dist/controller/canonicalClipboard.js +29 -12
  22. package/dist/controller/canonicalComposition.d.ts +1 -1
  23. package/dist/controller/canonicalComposition.js +77 -19
  24. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  25. package/dist/controller/canonicalInlineProjection.js +192 -28
  26. package/dist/controller/canonicalInput.d.ts +2 -2
  27. package/dist/controller/canonicalInput.js +47 -2
  28. package/dist/controller/canonicalListRendering.d.ts +2 -1
  29. package/dist/controller/canonicalListRendering.js +1 -1
  30. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  31. package/dist/controller/canonicalLockGuard.js +88 -0
  32. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  33. package/dist/controller/canonicalPublicOperations.js +274 -20
  34. package/dist/controller/canonicalSession.d.ts +87 -7
  35. package/dist/controller/canonicalSession.js +328 -75
  36. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  37. package/dist/controller/canonicalStoryEditor.js +4 -3
  38. package/dist/controller/canonicalStructure.d.ts +2 -1
  39. package/dist/controller/canonicalStructure.js +129 -7
  40. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  41. package/dist/controller/contentControlWidgetController.js +13 -1
  42. package/dist/controller/folioEditor.js +1 -0
  43. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  44. package/dist/controller/headerFooterEditorManager.js +5 -5
  45. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  46. package/dist/controller/hiddenEditorApi.js +1 -0
  47. package/dist/controller/hiddenEditorManager.d.ts +10 -3
  48. package/dist/controller/hiddenEditorManager.js +94 -38
  49. package/dist/controller/layoutPipeline.d.ts +2 -0
  50. package/dist/controller/layoutPipeline.js +55 -18
  51. package/dist/controller/layoutSession.d.ts +1 -0
  52. package/dist/controller/noteEditorManager.d.ts +2 -2
  53. package/dist/controller/noteEditorManager.js +5 -5
  54. package/dist/display-list/build/pageFurniture.js +41 -19
  55. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  56. package/dist/display-list/build/tablePrimitives.js +49 -14
  57. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  58. package/dist/document-operations.d.ts +8 -0
  59. package/dist/document-operations.js +4 -3
  60. package/dist/docx/blockContentParser.d.ts +7 -3
  61. package/dist/docx/blockContentParser.js +2 -3
  62. package/dist/docx/blockPlainText.js +2 -0
  63. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  64. package/dist/docx/bookmarkRangeJoin.js +43 -0
  65. package/dist/docx/canonicalSave.js +5 -1
  66. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  67. package/dist/docx/canonicalSessionInput.js +7 -2
  68. package/dist/docx/chartPreview.d.ts +4 -1
  69. package/dist/docx/chartPreview.js +26 -15
  70. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  71. package/dist/docx/commentAnchorIndex.js +39 -11
  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/encryption/compoundFile.js +9 -1
  80. package/dist/docx/encryption/encryptionInfo.js +16 -2
  81. package/dist/docx/ensureParaIds.js +46 -7
  82. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  83. package/dist/docx/ensureUniqueControlIds.js +110 -0
  84. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  85. package/dist/docx/headerFooterVerbatim.js +13 -2
  86. package/dist/docx/hostCommentThreads.d.ts +17 -0
  87. package/dist/docx/hostCommentThreads.js +49 -0
  88. package/dist/docx/hyperlinkParser.js +9 -2
  89. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  90. package/dist/docx/inlineWrapperContent.js +9 -2
  91. package/dist/docx/listMarkerComputation.d.ts +35 -1
  92. package/dist/docx/listMarkerComputation.js +39 -1
  93. package/dist/docx/listModelNormalization.d.ts +44 -1
  94. package/dist/docx/listModelNormalization.js +227 -96
  95. package/dist/docx/mainDocumentPart.d.ts +6 -0
  96. package/dist/docx/mainDocumentPart.js +65 -0
  97. package/dist/docx/markupRangeMarker.d.ts +14 -0
  98. package/dist/docx/markupRangeMarker.js +15 -1
  99. package/dist/docx/metadataPrivacy.js +43 -22
  100. package/dist/docx/normalizeBaseDirection.js +3 -1
  101. package/dist/docx/packageParts.d.ts +1 -1
  102. package/dist/docx/packageParts.js +10 -4
  103. package/dist/docx/paragraphParser.js +159 -48
  104. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  105. package/dist/docx/paragraphPropertySource.js +22 -1
  106. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  107. package/dist/docx/paragraphTraversal.js +2 -0
  108. package/dist/docx/parseWarningMessage.js +2 -1
  109. package/dist/docx/parser.js +6 -0
  110. package/dist/docx/previewBudget.d.ts +6 -0
  111. package/dist/docx/previewBudget.js +7 -1
  112. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  113. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  114. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  115. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  116. package/dist/docx/reviewResolutionProvenance.js +110 -25
  117. package/dist/docx/rezip.d.ts +6 -0
  118. package/dist/docx/rezip.js +42 -25
  119. package/dist/docx/selectiveSave.js +6 -10
  120. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  121. package/dist/docx/selectiveXmlPatch.js +11 -7
  122. package/dist/docx/serializer/documentSerializer.js +3 -1
  123. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  124. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  125. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  126. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  127. package/dist/docx/serializer/noteSerializer.js +23 -16
  128. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  129. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  130. package/dist/docx/serializer/runSerializer.js +2 -2
  131. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  132. package/dist/docx/serializer/tableSerializer.js +4 -2
  133. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  134. package/dist/docx/server/createBilingualDocument.js +27 -5
  135. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  136. package/dist/docx/sessionListPruning.d.ts +2 -0
  137. package/dist/docx/sessionListPruning.js +50 -0
  138. package/dist/docx/shapeAlternateContent.js +19 -0
  139. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  140. package/dist/docx/splitRevisionPieces.js +14 -0
  141. package/dist/docx/storyBlockReplay.js +4 -0
  142. package/dist/docx/structuralXmlPatch.js +19 -7
  143. package/dist/docx/tableParser.d.ts +6 -2
  144. package/dist/docx/tableParser.js +2 -3
  145. package/dist/docx/textBoxContentParser.d.ts +11 -0
  146. package/dist/docx/textBoxContentParser.js +51 -0
  147. package/dist/docx/textBoxParser.d.ts +0 -5
  148. package/dist/docx/textBoxParser.js +1 -23
  149. package/dist/docx/unzip.js +2 -0
  150. package/dist/docx/verticalMergeProjection.js +1 -1
  151. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  152. package/dist/fonts/fontsourceFaces.js +1 -7
  153. package/dist/i18n/messages/ar.gen.js +3 -0
  154. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  155. package/dist/i18n/messages/catalogs.gen.js +51 -0
  156. package/dist/i18n/messages/cs.gen.js +3 -0
  157. package/dist/i18n/messages/de.gen.js +3 -0
  158. package/dist/i18n/messages/en.gen.js +3 -0
  159. package/dist/i18n/messages/es.gen.js +3 -0
  160. package/dist/i18n/messages/et.gen.js +3 -0
  161. package/dist/i18n/messages/fr.gen.js +3 -0
  162. package/dist/i18n/messages/he.gen.js +3 -0
  163. package/dist/i18n/messages/hi.gen.js +3 -0
  164. package/dist/i18n/messages/hu.gen.js +3 -0
  165. package/dist/i18n/messages/lt.gen.js +3 -0
  166. package/dist/i18n/messages/lv.gen.js +3 -0
  167. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  168. package/dist/i18n/messages/pl.gen.js +3 -0
  169. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  170. package/dist/i18n/messages/sk.gen.js +3 -0
  171. package/dist/i18n/messages/tr.gen.js +3 -0
  172. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  173. package/dist/internal/acceptedBlockProjection.js +2 -0
  174. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  175. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  176. package/dist/internal/revisionResolutionInline.js +1 -2
  177. package/dist/internal/wholeStoryRevisionResolution.js +57 -12
  178. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  179. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  180. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  181. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  182. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  183. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  184. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  185. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  186. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  187. package/dist/layout-bridge/convert/tableConversion.js +25 -10
  188. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  189. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  190. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  191. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  192. package/dist/layout-bridge/engine/hitTest.js +9 -10
  193. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  194. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  195. package/dist/layout-engine/footnoteContinuation.js +210 -0
  196. package/dist/layout-engine/index.d.ts +2 -2
  197. package/dist/layout-engine/index.js +7 -2
  198. package/dist/layout-engine/measure/cache.js +10 -5
  199. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  200. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  201. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  202. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  203. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  204. package/dist/layout-engine/tableLayout.js +34 -7
  205. package/dist/layout-engine/tableRowBreak.d.ts +46 -0
  206. package/dist/layout-engine/tableRowBreak.js +193 -36
  207. package/dist/layout-engine/types.d.ts +43 -3
  208. package/dist/layout-painter/previewSvg.d.ts +8 -0
  209. package/dist/layout-painter/previewSvg.js +47 -0
  210. package/dist/layout-painter/renderImage.js +2 -1
  211. package/dist/layout-painter/renderPage.d.ts +5 -4
  212. package/dist/layout-painter/renderPage.js +52 -20
  213. package/dist/layout-painter/renderParagraph.js +3 -2
  214. package/dist/layout-painter/renderTable.d.ts +5 -2
  215. package/dist/layout-painter/renderTable.js +39 -22
  216. package/dist/managers/AutoSaveManager.d.ts +5 -1
  217. package/dist/managers/FindReplaceManager.js +3 -10
  218. package/dist/markdown/escape.d.ts +20 -1
  219. package/dist/markdown/escape.js +43 -1
  220. package/dist/markdown/renderBlock.js +4 -1
  221. package/dist/markdown/renderParagraph.js +13 -27
  222. package/dist/markdown/renderTable.js +6 -2
  223. package/dist/markdown/trailers.js +1 -0
  224. package/dist/pdf/images.d.ts +17 -1
  225. package/dist/pdf/images.js +22 -4
  226. package/dist/pdf/writePdf.js +4 -2
  227. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  228. package/dist/prosemirror/attrs/index.js +1 -0
  229. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  230. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  231. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  232. package/dist/prosemirror/commands/comments.d.ts +25 -0
  233. package/dist/prosemirror/commands/comments.js +122 -18
  234. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  235. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  236. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  237. package/dist/prosemirror/commands/index.d.ts +1 -1
  238. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  239. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  240. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  241. package/dist/prosemirror/commentIdAllocator.js +2 -2
  242. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  243. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  244. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  245. package/dist/prosemirror/commentReferenceIntegrity.js +22 -8
  246. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  247. package/dist/prosemirror/conversion/fromProseDoc.js +115 -35
  248. package/dist/prosemirror/conversion/index.d.ts +1 -1
  249. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  250. package/dist/prosemirror/conversion/toProseDoc.js +325 -55
  251. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  252. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  253. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  254. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  255. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  256. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  257. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  258. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  259. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  260. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  261. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  262. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  263. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  264. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  265. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  266. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  267. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  268. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  269. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  270. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  271. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  272. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  273. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  274. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  275. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  276. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  277. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  278. package/dist/prosemirror/extensions/nodes/TableExtension.js +119 -38
  279. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  280. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  281. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  282. package/dist/prosemirror/index.d.ts +2 -2
  283. package/dist/prosemirror/listLabels.js +3 -2
  284. package/dist/prosemirror/listNumbering.d.ts +6 -0
  285. package/dist/prosemirror/listNumbering.js +12 -9
  286. package/dist/prosemirror/lockedControls.d.ts +13 -0
  287. package/dist/prosemirror/lockedControls.js +106 -0
  288. package/dist/prosemirror/markupViewProjection.js +1 -1
  289. package/dist/prosemirror/noteReferenceReview.js +2 -2
  290. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  291. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  292. package/dist/prosemirror/plugins/suggestionMode.js +195 -30
  293. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  294. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  295. package/dist/prosemirror/replacedAnnotations.js +1 -0
  296. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  297. package/dist/prosemirror/rowGridOmissions.js +21 -0
  298. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  299. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  300. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  301. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  302. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  303. package/dist/prosemirror/runStyleFormatting.js +16 -13
  304. package/dist/prosemirror/schema/marks.d.ts +6 -0
  305. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  306. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  307. package/dist/prosemirror/tableGridMutation.js +118 -15
  308. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  309. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  310. package/dist/prosemirror/validation.js +2 -1
  311. package/dist/redline.js +23 -9
  312. package/dist/server.d.ts +2 -2
  313. package/dist/style-sets/extract.js +2 -2
  314. package/dist/types/canonicalCapabilities.d.ts +29 -8
  315. package/dist/types/canonicalCapabilities.js +13 -9
  316. package/dist/utils/cssString.d.ts +7 -0
  317. package/dist/utils/cssString.js +9 -0
  318. package/dist/utils/fontResolver.js +4 -1
  319. package/dist/utils/replaceText.d.ts +11 -0
  320. package/dist/utils/replaceText.js +39 -7
  321. package/dist/version-comparison.d.ts +9 -1
  322. package/dist/version-comparison.js +11 -5
  323. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { DocumentFontFacts } from "../fonts/documentFontFacts.js";
3
- import { FootnoteContent, HeaderFooterContent, ImageRun, Page, isFloatingImageRun } from "../layout-engine/types.js";
3
+ import { FootnoteContent, FootnoteWindow, HeaderFooterContent, ImageRun, Page, isFloatingImageRun } from "../layout-engine/types.js";
4
4
  import { AnchoredImagePosition, PageGeometry } from "./anchoredImagePosition.js";
5
5
  import { RenderContext, emuToPixels } from "./renderUtils.js";
6
6
  import { BlockLookup } from "./index.js";
@@ -10,6 +10,7 @@ import { BlockLookup } from "./index.js";
10
10
  */
11
11
  export type PageFloatingImage = {
12
12
  src: string;
13
+ preview?: document_d_exports.PreviewDescriptor;
13
14
  width: number;
14
15
  height: number;
15
16
  alt?: string;
@@ -248,12 +249,12 @@ export declare function renderFloatingImagesLayer(floatingImages: PageFloatingIm
248
249
  * from eigenpal/docx-editor#485, extended for folio's fallback rendering
249
250
  * and any wrapper margin so the helper matches the painted stack.
250
251
  */
251
- export declare function calculateFootnoteAreaRenderHeight(footnotes: FootnoteRenderItem[]): number;
252
+ export declare function calculateFootnoteAreaRenderHeight(footnotes: FootnoteRenderItem[], windows?: readonly FootnoteWindow[]): number;
252
253
  /**
253
254
  * Render the footnote area at the bottom of a page.
254
255
  * Includes a separator line (33% width) and footnote entries.
255
256
  */
256
- export declare function renderFootnoteArea(footnotes: FootnoteRenderItem[], contentWidth: number, doc: Document, context?: RenderContext): HTMLElement;
257
+ export declare function renderFootnoteArea(footnotes: FootnoteRenderItem[], contentWidth: number, doc: Document, context?: RenderContext, windows?: readonly FootnoteWindow[]): HTMLElement;
257
258
  /**
258
259
  * Render a single page to DOM
259
260
  *
@@ -279,7 +280,7 @@ export declare function applySectionHeaderFooterOptions(page: Page, pageOptions:
279
280
  * Compute a fingerprint string for a page that changes when its content changes.
280
281
  * Used to detect which pages need re-rendering on incremental updates.
281
282
  */
282
- export declare function computePageFingerprint(page: Page, blockLookup?: BlockLookup): string;
283
+ export declare function computePageFingerprint(page: Page, blockLookup?: BlockLookup, footnotes?: readonly FootnoteRenderItem[]): string;
283
284
  /**
284
285
  * Render multiple pages to a container with virtualization for large documents.
285
286
  *
@@ -17,6 +17,7 @@ import { pageHorizontalColumns, paragraphInlinePictureViewport } from "../utils/
17
17
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
18
18
  import { eighthsToPixels, pointsToPixels } from "../utils/units.js";
19
19
  import { resolveAnchoredImagePosition as resolveAnchoredImagePosition$1 } from "./anchoredImagePosition.js";
20
+ import { paintedImageSource } from "./previewSvg.js";
20
21
  import { renderFragment } from "./renderFragment.js";
21
22
  import { applyImageVisualAttrs, hasImageVisualAttrs, renderImageFragment } from "./renderImage.js";
22
23
  import { renderParagraphFragment } from "./renderParagraph.js";
@@ -51,6 +52,8 @@ const PAGE_CLASS_NAMES = {
51
52
  const HEADER_FOOTER_RULE_CLIP_MARGIN = pointsToPixels(1.5);
52
53
  const DEFAULT_MARGIN_GUIDE_COLOR = "#c0c0c0";
53
54
  const getDefaultPageFontFamily = () => resolveFontFamily(DEFAULT_FONT_FAMILY).cssFallback;
55
+ /** The part of a note a page shows, when the note continues across pages. */
56
+ const windowOfNote = (windows, noteId) => windows?.find((candidate) => candidate.noteId === noteId);
54
57
  /**
55
58
  * Apply page styles to an element
56
59
  */
@@ -388,6 +391,7 @@ function extractFloatingImagesFromParagraph(block, fragmentY, geometry) {
388
391
  else if (imgRun.cssFloat === "right") wrapText = "left";
389
392
  floatingImages.push({
390
393
  src: imgRun.src,
394
+ ...imgRun.preview ? { preview: imgRun.preview } : {},
391
395
  width: imgRun.width,
392
396
  height: imgRun.height,
393
397
  ...imgRun.alt !== void 0 ? { alt: imgRun.alt } : {},
@@ -439,7 +443,7 @@ function renderFloatingImagesLayer(floatingImages, doc, layerMode = "front") {
439
443
  if (floatImg.pmStart !== void 0) container.dataset["pmStart"] = String(floatImg.pmStart);
440
444
  if (floatImg.pmEnd !== void 0) container.dataset["pmEnd"] = String(floatImg.pmEnd);
441
445
  const img = doc.createElement("img");
442
- applySanitizedImageSrc(img, floatImg.src);
446
+ applySanitizedImageSrc(img, paintedImageSource(floatImg));
443
447
  img.style.width = `${floatImg.width}px`;
444
448
  img.style.height = `${floatImg.height}px`;
445
449
  img.style.display = "block";
@@ -480,6 +484,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
480
484
  const inlineRuns = [];
481
485
  for (const run of paragraphBlock.runs) if (run.kind === "image" && (isFloatingImageRun(run) || run.position)) floatingImages.push({
482
486
  src: run.src,
487
+ ...run.preview ? { preview: run.preview } : {},
483
488
  width: run.width,
484
489
  height: run.height,
485
490
  ...run.alt !== void 0 ? { alt: run.alt } : {},
@@ -584,7 +589,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
584
589
  }
585
590
  for (const floatImg of floatingImages) {
586
591
  const img = doc.createElement("img");
587
- applySanitizedImageSrc(img, floatImg.src);
592
+ applySanitizedImageSrc(img, paintedImageSource(floatImg));
588
593
  img.width = floatImg.width;
589
594
  img.height = floatImg.height;
590
595
  if (floatImg.alt) img.alt = floatImg.alt;
@@ -618,10 +623,11 @@ function isPositionedHeaderFooterTextBoxBlock(block) {
618
623
  * from eigenpal/docx-editor#485, extended for folio's fallback rendering
619
624
  * and any wrapper margin so the helper matches the painted stack.
620
625
  */
621
- function calculateFootnoteAreaRenderHeight(footnotes) {
626
+ function calculateFootnoteAreaRenderHeight(footnotes, windows) {
622
627
  let height = 12;
623
628
  for (const fn of footnotes) {
624
- const entryHeight = fn.content ? fn.content.height : 13;
629
+ const noteWindow = windowOfNote(windows, fn.noteId);
630
+ const entryHeight = noteWindow ? noteWindow.to - noteWindow.from : fn.content?.height ?? 13;
625
631
  height += entryHeight + 0;
626
632
  }
627
633
  return height;
@@ -649,7 +655,7 @@ function renderFlowedNoteSeparators(page, contentEl, doc) {
649
655
  * Render the footnote area at the bottom of a page.
650
656
  * Includes a separator line (33% width) and footnote entries.
651
657
  */
652
- function renderFootnoteArea(footnotes, contentWidth, doc, context) {
658
+ function renderFootnoteArea(footnotes, contentWidth, doc, context, windows) {
653
659
  const container = doc.createElement("div");
654
660
  container.className = "layout-footnote-area";
655
661
  container.style.width = `${contentWidth}px`;
@@ -668,7 +674,7 @@ function renderFootnoteArea(footnotes, contentWidth, doc, context) {
668
674
  fnEl.style.marginBottom = `0px`;
669
675
  fnEl.style.color = "var(--doc-canvas-text, #000)";
670
676
  if (fn.content) {
671
- const contentEl = renderFootnoteContent(fn, contentWidth, doc, context);
677
+ const contentEl = renderFootnoteContent(fn, contentWidth, doc, context, windowOfNote(windows, fn.noteId));
672
678
  fnEl.append(contentEl);
673
679
  } else {
674
680
  fnEl.style.fontSize = "10px";
@@ -685,7 +691,7 @@ function renderFootnoteArea(footnotes, contentWidth, doc, context) {
685
691
  }
686
692
  return container;
687
693
  }
688
- function renderFootnoteContent(footnote, contentWidth, doc, context) {
694
+ function renderFootnoteContent(footnote, contentWidth, doc, context, noteWindow) {
689
695
  const content = footnote.content;
690
696
  if (!content) panic("Missing structured footnote content");
691
697
  const wrapper = doc.createElement("div");
@@ -693,6 +699,16 @@ function renderFootnoteContent(footnote, contentWidth, doc, context) {
693
699
  wrapper.style.position = "relative";
694
700
  wrapper.style.width = `${contentWidth}px`;
695
701
  wrapper.style.height = `${content.height}px`;
702
+ const shown = noteWindow ? doc.createElement("div") : wrapper;
703
+ if (noteWindow) {
704
+ shown.className = "layout-footnote-window";
705
+ shown.style.position = "relative";
706
+ shown.style.overflow = "hidden";
707
+ shown.style.width = `${contentWidth}px`;
708
+ shown.style.height = `${noteWindow.to - noteWindow.from}px`;
709
+ wrapper.style.top = `${-noteWindow.from}px`;
710
+ shown.append(wrapper);
711
+ }
696
712
  const renderContext = {
697
713
  pageNumber: context?.pageNumber ?? 0,
698
714
  ...context?.pageNumberFormat === void 0 ? {} : { pageNumberFormat: context.pageNumberFormat },
@@ -716,7 +732,7 @@ function renderFootnoteContent(footnote, contentWidth, doc, context) {
716
732
  wrapper.append(blockEl);
717
733
  y += getFootnoteMeasureHeight(measure);
718
734
  }
719
- return wrapper;
735
+ return shown;
720
736
  }
721
737
  function renderFootnoteBlock(block, measure, contentWidth, y, context, doc) {
722
738
  const renderBlock = stripFlowBlockPmAnchors(block);
@@ -1068,9 +1084,9 @@ function renderPage(page, context, options = {}) {
1068
1084
  }
1069
1085
  renderFlowedNoteSeparators(page, contentEl, doc);
1070
1086
  if (options.footnoteArea && options.footnoteArea.length > 0) {
1071
- const fnAreaEl = renderFootnoteArea(options.footnoteArea, contentWidth, doc, context);
1087
+ const fnAreaEl = renderFootnoteArea(options.footnoteArea, contentWidth, doc, context, page.footnoteWindows);
1072
1088
  fnAreaEl.style.position = "absolute";
1073
- const reservedHeight = Math.max(page.footnoteReservedHeight ?? 0, calculateFootnoteAreaRenderHeight(options.footnoteArea));
1089
+ const reservedHeight = Math.max(page.footnoteReservedHeight ?? 0, calculateFootnoteAreaRenderHeight(options.footnoteArea, page.footnoteWindows));
1074
1090
  const contentAreaBottom = page.size.h - page.margins.bottom - page.margins.top;
1075
1091
  fnAreaEl.style.top = `${Math.max(-page.margins.top, contentAreaBottom - reservedHeight)}px`;
1076
1092
  fnAreaEl.style.left = "0";
@@ -1303,11 +1319,17 @@ function buildPageRenderArgs(page, totalPages, options) {
1303
1319
  * Compute a fingerprint string for a page that changes when its content changes.
1304
1320
  * Used to detect which pages need re-rendering on incremental updates.
1305
1321
  */
1306
- function computePageFingerprint(page, blockLookup) {
1307
- return computePageFingerprintInternal(page, blockLookup, { includePmPositions: true });
1322
+ function computePageFingerprint(page, blockLookup, footnotes) {
1323
+ return computePageFingerprintInternal(page, blockLookup, {
1324
+ includePmPositions: true,
1325
+ footnotes
1326
+ });
1308
1327
  }
1309
- function computePageRenderFingerprint(page, blockLookup) {
1310
- return computePageFingerprintInternal(page, blockLookup, { includePmPositions: false });
1328
+ function computePageRenderFingerprint(page, blockLookup, footnotes) {
1329
+ return computePageFingerprintInternal(page, blockLookup, {
1330
+ includePmPositions: false,
1331
+ footnotes
1332
+ });
1311
1333
  }
1312
1334
  const pageMarginsFingerprint = (margins) => [
1313
1335
  margins.top,
@@ -1327,7 +1349,14 @@ function computePageFingerprintInternal(page, blockLookup, options) {
1327
1349
  if (page.sectionIndex !== void 0) parts.push(`si:${page.sectionIndex}`);
1328
1350
  if (page.sectionPageNumber !== void 0) parts.push(`sp:${page.sectionPageNumber}`);
1329
1351
  if (page.headerFooterRefs) parts.push(`hf:${JSON.stringify(page.headerFooterRefs)}`);
1330
- if (page.footnoteReservedHeight) parts.push(`fn:${page.footnoteReservedHeight}`);
1352
+ if (page.footnoteReservedHeight) {
1353
+ parts.push(`fn:${page.footnoteReservedHeight}`);
1354
+ if (page.footnoteWindows) parts.push(`fnw:${JSON.stringify(page.footnoteWindows)}`);
1355
+ }
1356
+ for (const note of options.footnotes ?? []) {
1357
+ parts.push(`fnc:${note.noteId ?? ""},${note.displayNumber},${note.text ?? ""}`);
1358
+ for (const block of note.content?.blocks ?? []) parts.push(computeContentFingerprint(block), computeAnnotationFingerprint(block, false));
1359
+ }
1331
1360
  for (const frag of page.fragments) {
1332
1361
  let fp = `${frag.kind}:${frag.blockId},${frag.x},${frag.y},${frag.width},${frag.height}`;
1333
1362
  if (options.includePmPositions && frag.pmStart !== void 0) fp += `,ps:${frag.pmStart}`;
@@ -1338,6 +1367,7 @@ function computePageFingerprintInternal(page, blockLookup, options) {
1338
1367
  if (frag.headerRowCount !== void 0) fp += `,hr:${frag.headerRowCount}`;
1339
1368
  if (frag.topClip !== void 0) fp += `,tc:${frag.topClip}`;
1340
1369
  if (frag.bottomClip !== void 0) fp += `,bc:${frag.bottomClip}`;
1370
+ if (frag.cellLineBand !== void 0) fp += `,clb:${frag.cellLineBand.shownThrough}:${frag.cellLineBand.cut}:${JSON.stringify(frag.cellLineBand.cells)}`;
1341
1371
  if (frag.continuesFromPrev) fp += ",cfp";
1342
1372
  if (frag.continuesOnNext) fp += ",con";
1343
1373
  }
@@ -1411,7 +1441,7 @@ function collectContentFingerprint(block, parts) {
1411
1441
  function runContentKey(run) {
1412
1442
  if (run.kind === "lineBreak") return "lb";
1413
1443
  if (run.kind === "renderedPageBreak") return "rpb";
1414
- if (run.kind === "image") return `img:${run.src}|${run.width}x${run.height}${run.transform ? `|tr:${run.transform}` : ""}`;
1444
+ if (run.kind === "image") return `img:${paintedImageSource(run)}|${run.width}x${run.height}${run.transform ? `|tr:${run.transform}` : ""}`;
1415
1445
  const parts = [run.kind];
1416
1446
  if (run.kind === "text") {
1417
1447
  parts.push(`t:${run.text}`);
@@ -1580,7 +1610,8 @@ function renderPages(pages, container, options = {}) {
1580
1610
  prev.element.dataset["pageNumber"] = String(page.number);
1581
1611
  continue;
1582
1612
  }
1583
- const newFp = computePageFingerprint(page, options.blockLookup);
1613
+ const pageFootnotes = options.footnotesByPage?.get(page.number);
1614
+ const newFp = computePageFingerprint(page, options.blockLookup, pageFootnotes);
1584
1615
  if (prev.fingerprint === newFp && !totalPagesChanged && !fieldContextChanged) continue;
1585
1616
  const shell = prev.element;
1586
1617
  if (totalPagesChanged || fieldContextChanged) {
@@ -1593,7 +1624,7 @@ function renderPages(pages, container, options = {}) {
1593
1624
  shell.dataset["pageNumber"] = String(page.number);
1594
1625
  continue;
1595
1626
  }
1596
- const newRenderFp = computePageRenderFingerprint(page, options.blockLookup);
1627
+ const newRenderFp = computePageRenderFingerprint(page, options.blockLookup, pageFootnotes);
1597
1628
  if (!(!(prev.renderFingerprint !== newRenderFp) && syncRenderedPmPositionData(shell, oldPage, data.page))) repopulatePageContent(shell, prevDataMap, totalPages, options);
1598
1629
  prev.fingerprint = newFp;
1599
1630
  prev.renderFingerprint = newRenderFp;
@@ -1926,8 +1957,9 @@ function shiftNumericDatasetValue(element, key, delta) {
1926
1957
  function syncPageShellFingerprints(shell, data, options) {
1927
1958
  const pageState = shell.parentElement?.__pageRenderState?.pageStates[data.index];
1928
1959
  if (!pageState || pageState.element !== shell) return;
1929
- pageState.fingerprint = computePageFingerprint(data.page, options.blockLookup);
1930
- pageState.renderFingerprint = computePageRenderFingerprint(data.page, options.blockLookup);
1960
+ const pageFootnotes = options.footnotesByPage?.get(data.page.number);
1961
+ pageState.fingerprint = computePageFingerprint(data.page, options.blockLookup, pageFootnotes);
1962
+ pageState.renderFingerprint = computePageRenderFingerprint(data.page, options.blockLookup, pageFootnotes);
1931
1963
  }
1932
1964
  /**
1933
1965
  * Find the page shell whose layout fragments cover (or are nearest
@@ -27,6 +27,7 @@ import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js"
27
27
  import { borderStrokeToCss, resolveParagraphBorderHorizontalOutsets } from "./borderStroke.js";
28
28
  import { planCursiveJoiners, withCursiveJoiners } from "./cursiveJoiners.js";
29
29
  import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
30
+ import { paintedImageSource } from "./previewSvg.js";
30
31
  import { applyImageBorder, applyImageColorAttrs, applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs, wrapImageWithCrop } from "./renderImage.js";
31
32
  import { applySdtDataAttrs } from "./sdtBoundary.js";
32
33
  import { panic } from "better-result";
@@ -560,7 +561,7 @@ function getLeaderChar(leader) {
560
561
  function renderInlineImageRun({ run, doc, sizing }) {
561
562
  const img = doc.createElement("img");
562
563
  img.className = `${PARAGRAPH_CLASS_NAMES.run} ${PARAGRAPH_CLASS_NAMES.image}`;
563
- applyImageRunSource(img, run.src);
564
+ applyImageRunSource(img, paintedImageSource(run));
564
565
  img.width = run.width;
565
566
  img.height = run.height;
566
567
  img.style.width = `${run.width}px`;
@@ -629,7 +630,7 @@ function renderBlockImage(run, doc) {
629
630
  container.style.marginTop = `${run.distTop ?? 6}px`;
630
631
  container.style.marginBottom = `${run.distBottom ?? 6}px`;
631
632
  const img = doc.createElement("img");
632
- applyImageRunSource(img, run.src);
633
+ applyImageRunSource(img, paintedImageSource(run));
633
634
  img.width = run.width;
634
635
  img.height = run.height;
635
636
  if (run.alt) img.alt = run.alt;
@@ -1,6 +1,7 @@
1
1
  import { TableBlock, TableFragment, TableMeasure } from "../layout-engine/types.js";
2
2
  import { PageGeometry } from "./anchoredImagePosition.js";
3
3
  import { RenderContext } from "./renderUtils.js";
4
+ import { VisibleBand } from "../layout-engine/measure/tableVisibleBand.js";
4
5
  import { TextDirection } from "@stll/docx-core/model";
5
6
  /**
6
7
  * CSS class names for table elements
@@ -25,9 +26,11 @@ export type RenderTableFragmentOptions = {
25
26
  pageGeometry?: PageGeometry;
26
27
  };
27
28
  /**
28
- * Render a nested table (within a cell)
29
+ * Render a nested table (within a cell). A `visibleBand` builds only the rows
30
+ * that band shows; the table keeps its full height, so the rest of the cell
31
+ * flows the same.
29
32
  */
30
- export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number): HTMLElement;
33
+ export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number, visibleBand?: VisibleBand): HTMLElement;
31
34
  /**
32
35
  * Render a table fragment to DOM
33
36
  *
@@ -4,13 +4,15 @@ import { createTableCellFlowState, finishTableCellFlow, placeTableCellBlock } fr
4
4
  import { buildTableCellGrid, buildTableCellPlacements, getSourceCellAt, getTableCellSpacingInsetsY } from "../layout-engine/measure/tableCellGrid.js";
5
5
  import { tableFragmentBottomBorders } from "../layout-engine/measure/tableFragmentBorderGeometry.js";
6
6
  import { resolveTableInlineOffset, resolveTableInlinePlacement } from "../layout-engine/measure/tableInlinePlacement.js";
7
- import { isFloatingImageRun, isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
7
+ import { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../layout-engine/measure/tableVisibleBand.js";
8
+ import { isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
8
9
  import { paintsCssBorder } from "../utils/borderCss.js";
9
10
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
10
11
  import { emuToPixels } from "../utils/units.js";
11
12
  import { resolveAnchoredImagePosition } from "./anchoredImagePosition.js";
12
13
  import { borderStrokeToCss, resolveCssBorderStroke } from "./borderStroke.js";
13
14
  import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
15
+ import { paintedImageSource } from "./previewSvg.js";
14
16
  import { applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs } from "./renderImage.js";
15
17
  import { renderParagraphFragment } from "./renderParagraph.js";
16
18
  import { renderTextBoxFragment } from "./renderTextBox.js";
@@ -63,7 +65,7 @@ const CELL_TEXT_ROTATION_DEGREES = {
63
65
  };
64
66
  /** The quarter turn a cell's `w:textDirection` puts on its content. */
65
67
  const cellTextRotationDegrees = (direction) => direction === void 0 ? 0 : CELL_TEXT_ROTATION_DEGREES[TEXT_DIRECTION_FLOW_BY_TOKEN[direction]];
66
- function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition }) {
68
+ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition, visibleBand }) {
67
69
  const contentEl = doc.createElement("div");
68
70
  contentEl.className = TABLE_CLASS_NAMES.cellContent;
69
71
  contentEl.style.position = "relative";
@@ -101,7 +103,7 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
101
103
  if (img.pmStart !== void 0) imgContainer.dataset["pmStart"] = String(img.pmStart);
102
104
  if (img.pmEnd !== void 0) imgContainer.dataset["pmEnd"] = String(img.pmEnd);
103
105
  const imgEl = doc.createElement("img");
104
- applySanitizedImageSrc(imgEl, img.src);
106
+ applySanitizedImageSrc(imgEl, paintedImageSource(img));
105
107
  imgEl.style.width = `${img.width}px`;
106
108
  imgEl.style.height = `${img.height}px`;
107
109
  imgEl.style.display = "block";
@@ -184,9 +186,16 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
184
186
  } else if (block?.kind === "table" && measure?.kind === "table") {
185
187
  const tableBlock = block;
186
188
  const tableMeasure = measure;
187
- const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth);
188
- nestedTableEl.style.position = "relative";
189
189
  const placement = placeTableCellBlock(flowState, tableBlock, tableMeasure);
190
+ if (isOutsideBand(visibleBand, placement.top, placement.contentTop + placement.contentHeight)) {
191
+ const unbuilt = doc.createElement("div");
192
+ unbuilt.style.height = `${placement.leadingSpacing + placement.contentHeight}px`;
193
+ contentEl.append(unbuilt);
194
+ anchorParagraphY = flowState.height;
195
+ continue;
196
+ }
197
+ const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth, visibleBand && bandFromOrigin(visibleBand, placement.contentTop));
198
+ nestedTableEl.style.position = "relative";
190
199
  if (placement.leadingSpacing > 0) {
191
200
  const spacer = doc.createElement("div");
192
201
  spacer.style.height = `${placement.leadingSpacing}px`;
@@ -264,18 +273,12 @@ function resolveCellTextBoxY(block) {
264
273
  if (vertical?.posOffset !== void 0) return emuToPixels(vertical.posOffset);
265
274
  return 0;
266
275
  }
267
- function tableHasFloatingCellContent(block) {
268
- for (const row of block.rows) for (const cell of row.cells) for (const cellBlock of cell.blocks) {
269
- if (cellBlock.kind === "textBox" && isFloatingTextBoxBlock(cellBlock)) return true;
270
- if (cellBlock.kind === "paragraph" && cellBlock.runs.some((run) => run.kind === "image" && isFloatingImageRun(run))) return true;
271
- if (cellBlock.kind === "table" && tableHasFloatingCellContent(cellBlock)) return true;
272
- }
273
- return false;
274
- }
275
276
  /**
276
- * Render a nested table (within a cell)
277
+ * Render a nested table (within a cell). A `visibleBand` builds only the rows
278
+ * that band shows; the table keeps its full height, so the rest of the cell
279
+ * flows the same.
277
280
  */
278
- function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth) {
281
+ function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth, visibleBand) {
279
282
  const tableEl = doc.createElement("div");
280
283
  tableEl.className = `${TABLE_CLASS_NAMES.table} layout-nested-table`;
281
284
  tableEl.style.position = "relative";
@@ -313,11 +316,12 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
313
316
  cellSpacing: block.cellSpacing
314
317
  });
315
318
  let y = 0;
319
+ let paintedRow = false;
316
320
  for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
317
321
  const row = block.rows[rowIndex];
318
322
  const rowMeasure = measure.rows[rowIndex];
319
323
  if (!row || !rowMeasure) continue;
320
- if (row.hidden) {
324
+ if (row.hidden || isOutsideBand(visibleBand, y, tableRowPaintBottom(row, rowIndex, rowYPositions))) {
321
325
  y += rowMeasure.height;
322
326
  continue;
323
327
  }
@@ -331,11 +335,13 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
331
335
  context,
332
336
  doc,
333
337
  rowYPositions,
338
+ isFirstRowInFragment: visibleBand !== void 0 && !paintedRow && y >= visibleBand.top,
334
339
  bidi: block.bidi === true,
335
340
  columnsPinned,
336
341
  cellGrid,
337
342
  cellPlacements,
338
343
  cellSpacing: block.cellSpacing,
344
+ ...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, y) } : {},
339
345
  inlineOffset: resolveTableInlineOffset({
340
346
  table: block,
341
347
  rowJustification: row.justification,
@@ -344,6 +350,7 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
344
350
  }) - tableInlineOffset
345
351
  });
346
352
  tableEl.append(rowEl);
353
+ paintedRow = true;
347
354
  y += rowMeasure.height;
348
355
  }
349
356
  tableEl.style.height = `${y}px`;
@@ -391,7 +398,7 @@ function renderCellDiagonalBorder({ border, direction, cellWidth, cellHeight, do
391
398
  }
392
399
  return line;
393
400
  }
394
- function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, pageContentPosition }) {
401
+ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, visibleBand, pageContentPosition }) {
395
402
  const cellEl = doc.createElement("div");
396
403
  cellEl.className = TABLE_CLASS_NAMES.cell;
397
404
  cellEl.style.position = "absolute";
@@ -430,11 +437,15 @@ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, border
430
437
  }
431
438
  const cellTextRotation = cellTextRotationDegrees(cell.textDirection);
432
439
  const contentWidthOverride = cellTextRotation === 0 ? void 0 : Math.max(1, rowHeight - padTop - padBottom);
440
+ const contentMovesInCell = contentClip === void 0 && (cell.verticalAlign === "center" || cell.verticalAlign === "bottom");
441
+ const topBorderHeight = borderFlags.drawTop && hasVisibleBorder(cell.borders?.top) ? cell.borders?.top?.width ?? 0 : 0;
442
+ const contentBand = visibleBand && cellTextRotation === 0 && !contentMovesInCell ? bandFromOrigin(visibleBand, padTop + topBorderHeight) : void 0;
433
443
  const renderedContent = renderCellContent({
434
444
  cell,
435
445
  cellMeasure,
436
446
  context,
437
447
  doc,
448
+ ...contentBand ? { visibleBand: contentBand } : {},
438
449
  ...contentWidthOverride !== void 0 ? { contentWidthOverride } : {},
439
450
  ...pageContentPosition ? { pageContentPosition: {
440
451
  geometry: pageContentPosition.geometry,
@@ -512,7 +523,7 @@ const continuationRowBottomBorderOffsets = (fragment, block, measure, cellGrid)
512
523
  snapAfterRow
513
524
  });
514
525
  };
515
- function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
526
+ 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 }) {
516
527
  const bordersSeparated = (cellSpacing ?? 0) > 0;
517
528
  const rowEl = doc.createElement("div");
518
529
  rowEl.className = TABLE_CLASS_NAMES.row;
@@ -549,9 +560,10 @@ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows,
549
560
  const drawLeft = bordersSeparated || isFirstCol || !hasVisibleBorder(leftCell?.borders?.right);
550
561
  const spacing = getTableCellSpacingInsetsY(cellSpacing, rowIndex, rowSpan, totalRows);
551
562
  const boxHeight = Math.max(0, cellHeight - spacing.top - spacing.bottom);
552
- const boxClip = contentClip ? {
553
- top: contentClip.top - spacing.top,
554
- bottom: contentClip.bottom - spacing.top
563
+ const cellClip = cellBands?.[cellIndex] ?? contentClip;
564
+ const boxClip = cellClip ? {
565
+ top: cellClip.top - spacing.top,
566
+ bottom: cellClip.bottom - spacing.top
555
567
  } : void 0;
556
568
  const paintBottomBorderSeparately = bottomBorderOffset > 0 && hasVisibleBorder(cell.borders?.bottom);
557
569
  const cellEl = renderTableCell({
@@ -572,6 +584,7 @@ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows,
572
584
  context,
573
585
  doc,
574
586
  ...boxClip ? { contentClip: boxClip } : {},
587
+ ...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, spacing.top) } : {},
575
588
  ...pageContentPosition ? { pageContentPosition: {
576
589
  geometry: pageContentPosition.geometry,
577
590
  x: pageContentPosition.x + inlineOffset + cellLeft,
@@ -621,7 +634,8 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
621
634
  tableEl.style.position = "absolute";
622
635
  tableEl.style.width = `${fragment.width}px`;
623
636
  tableEl.style.height = `${fragment.height}px`;
624
- tableEl.style.overflow = tableHasFloatingCellContent(block) ? "visible" : "hidden";
637
+ const hasFloatingCellContent = tableHasFloatingCellContent(block);
638
+ tableEl.style.overflow = hasFloatingCellContent ? "visible" : "hidden";
625
639
  tableEl.dataset["blockId"] = String(fragment.blockId);
626
640
  tableEl.dataset["fromRow"] = String(fragment.fromRow);
627
641
  tableEl.dataset["toRow"] = String(fragment.toRow);
@@ -727,7 +741,9 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
727
741
  top: rowTopClip ?? 0,
728
742
  bottom: rowBottomClip ?? rowMeasure.height
729
743
  } : void 0;
744
+ const cellBands = rowIndex === fragment.fromRow ? fragment.cellLineBand?.cells : void 0;
730
745
  const rowEl = renderTableRow({
746
+ ...cellBands ? { cellBands } : {},
731
747
  row,
732
748
  rowMeasure,
733
749
  rowIndex,
@@ -745,6 +761,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
745
761
  cellSpacing: block.cellSpacing,
746
762
  bottomBorderOffset: contentRowBottomBorderOffsets[rowIndex - fragment.fromRow] ?? 0,
747
763
  ...contentClip ? { contentClip } : {},
764
+ ...contentClip && !hasFloatingCellContent ? { visibleBand: contentClip } : {},
748
765
  ...tablePageContentPosition ? { pageContentPosition: {
749
766
  ...tablePageContentPosition,
750
767
  y: tablePageContentPosition.y + y
@@ -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":