@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
@@ -2,7 +2,7 @@ import { projectedFootnoteReserveGrowth } from "./layoutFlowShared.js";
2
2
  import { resolveFloatingTablePageX } from "./measure/floatingTablePosition.js";
3
3
  import { resolveTableInlineOffset } from "./measure/tableInlinePlacement.js";
4
4
  import { isEmptyParagraph } from "./paragraphSpacing.js";
5
- import { buildTableRowBreakInfo, getRowContinuationSkip, snapRowBreak } from "./tableRowBreak.js";
5
+ import { buildTableRowBreakInfo, cellBandFromLines, getRowContinuationSkip, perCellRowCut, rowCellLineBands, snapOversizedRowBreak, snapRowBreak } from "./tableRowBreak.js";
6
6
  import "./types.js";
7
7
  // src/layout-engine/tableLayout.ts
8
8
  /**
@@ -97,7 +97,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
97
97
  const row = rows[rowIndex];
98
98
  const sourceRow = block.rows[rowIndex];
99
99
  if (!row || !sourceRow || sourceRow.heightRule === "exact" || sourceRow.isHeader || verticallyMergedRows.has(rowIndex)) return false;
100
- if ((breakInfo.breakOffsets[rowIndex]?.length ?? 0) <= 1) return false;
100
+ if ((breakInfo.oversizedBreakOffsets[rowIndex]?.length ?? 0) <= 1 && !rowCellLineBands(block, measure, rowIndex).some((lines) => lines.length > 1)) return false;
101
101
  const freshHeaderOverhead = headerRowCount > 0 && rowIndex >= headerRowCount ? headerRowsHeight : 0;
102
102
  const oversized = row.height + freshHeaderOverhead > getCurrentRowCapacity(state);
103
103
  if (sourceRow.cantSplit) return oversized && rowOpensFlowRegion(rowIndex, state);
@@ -106,6 +106,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
106
106
  const currentAvailableHeight = paginator.getAvailableHeight() - currentHeaderOverhead - state.trailingSpacing;
107
107
  return oversized || row.height > currentAvailableHeight;
108
108
  };
109
+ const rowCellBands = (rowIndex, band) => rowCellLineBands(block, measure, rowIndex).map((lines) => cellBandFromLines(lines, band));
109
110
  while (currentRowIndex < rows.length) {
110
111
  const rowState = paginator.getCurrentState();
111
112
  const rowHeaderOverhead = shouldRepeatHeaderRows(currentRowIndex, 0, rowState) ? headerRowsHeight : 0;
@@ -122,6 +123,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
122
123
  const splittableRow = rows[currentRowIndex];
123
124
  if (canSplitRow(currentRowIndex)) {
124
125
  let consumed = 0;
126
+ let shownThrough = 0;
125
127
  const renderedBreakHints = tableRowHasTrackedChanges(block, currentRowIndex) ? [] : breakInfo.renderedBreakHints[currentRowIndex] ?? [];
126
128
  let renderedBreakHintIndex = 0;
127
129
  const discardPassedRenderedBreakHints = () => {
@@ -138,6 +140,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
138
140
  const sliceAvail = paginator.getAvailableHeight() - headerOverhead - (consumed === 0 ? sliceState.trailingSpacing : 0);
139
141
  let slice = snapRowBreak(breakInfo, currentRowIndex, consumed, sliceAvail);
140
142
  let forceRenderedPageBreak = false;
143
+ let perCellCut = null;
141
144
  if (slice <= 0) {
142
145
  if (!(sliceState.cursorY === sliceState.topMargin && sliceState.page.fragments.length === 0)) {
143
146
  const previousPageNumber = sliceState.page.number;
@@ -145,19 +148,34 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
145
148
  advanceAfterNaturalFlowBreak(previousPageNumber);
146
149
  continue;
147
150
  }
148
- const from = consumed;
149
- slice = (breakInfo.breakOffsets[currentRowIndex]?.find((o) => o > from) ?? splittableRow.height) - consumed;
151
+ slice = snapOversizedRowBreak(breakInfo, currentRowIndex, consumed, sliceAvail);
152
+ if (slice <= 0) {
153
+ const from = consumed;
154
+ slice = (breakInfo.oversizedBreakOffsets[currentRowIndex]?.find((o) => o > from) ?? splittableRow.height) - consumed;
155
+ if (slice > sliceAvail) {
156
+ const cutPlan = perCellRowCut({
157
+ cellLines: rowCellLineBands(block, measure, currentRowIndex),
158
+ bandTop: consumed,
159
+ shownThrough: Math.max(shownThrough, consumed),
160
+ maxSlice: sliceAvail
161
+ });
162
+ if (cutPlan) {
163
+ slice = sliceAvail;
164
+ perCellCut = cutPlan;
165
+ }
166
+ }
167
+ }
150
168
  }
151
169
  discardPassedRenderedBreakHints();
152
170
  const renderedBreakHint = renderedBreakHints[renderedBreakHintIndex];
153
- if (renderedBreakHint && renderedBreakHint.offset <= consumed + slice && sliceAvail - (renderedBreakHint.offset - consumed) <= renderedBreakHint.lineAdvance * 3) {
171
+ if (!perCellCut && renderedBreakHint && renderedBreakHint.offset <= consumed + slice && sliceAvail - (renderedBreakHint.offset - consumed) <= renderedBreakHint.lineAdvance * 3) {
154
172
  slice = renderedBreakHint.offset - consumed;
155
173
  renderedBreakHintIndex += 1;
156
174
  forceRenderedPageBreak = true;
157
175
  }
158
176
  const sliceBottom = consumed + slice;
159
177
  const continuationSkip = sliceBottom < splittableRow.height ? getRowContinuationSkip(breakInfo, currentRowIndex, sliceBottom) : 0;
160
- const nextConsumed = Math.min(splittableRow.height, sliceBottom + continuationSkip);
178
+ const nextConsumed = perCellCut ? perCellCut.nextTop : Math.min(splittableRow.height, sliceBottom + continuationSkip);
161
179
  const moreAfter = !(nextConsumed >= splittableRow.height) || currentRowIndex + 1 < rows.length;
162
180
  const fragmentHeight = headerOverhead + slice;
163
181
  const sliceFragment = {
@@ -174,11 +192,19 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
174
192
  toRow: currentRowIndex + 1,
175
193
  ...block.pmStart !== void 0 ? { pmStart: block.pmStart } : {},
176
194
  ...block.pmEnd !== void 0 ? { pmEnd: block.pmEnd } : {},
177
- ...consumed > 0 || currentRowIndex > 0 ? { continuesFromPrev: true } : {},
195
+ ...consumed > 0 || shownThrough > 0 || currentRowIndex > 0 ? { continuesFromPrev: true } : {},
178
196
  ...moreAfter ? { continuesOnNext: true } : {},
179
197
  ...repeatHeaderRows ? { headerRowCount } : {},
180
198
  ...consumed > 0 ? { topClip: consumed } : {},
181
199
  ...sliceBottom >= splittableRow.height ? {} : { bottomClip: sliceBottom },
200
+ ...perCellCut || shownThrough > consumed ? { cellLineBand: {
201
+ shownThrough,
202
+ cut: sliceBottom,
203
+ cells: rowCellBands(currentRowIndex, {
204
+ shownThrough,
205
+ cut: sliceBottom
206
+ })
207
+ } } : {},
182
208
  ...block.sdtGroups ? { sdtGroups: block.sdtGroups } : {}
183
209
  };
184
210
  const sliceResult = paginator.addFragment(sliceFragment, fragmentHeight, 0, 0);
@@ -188,6 +214,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
188
214
  rowIndex: currentRowIndex
189
215
  });
190
216
  consumed = nextConsumed;
217
+ shownThrough = perCellCut ? perCellCut.cut : consumed;
191
218
  if (consumed < splittableRow.height) {
192
219
  if (forceRenderedPageBreak) paginator.forcePageBreak();
193
220
  else {
@@ -13,6 +13,11 @@ export type TableRowBreakInfo = {
13
13
  * final boundary.
14
14
  */
15
15
  breakOffsets: number[][];
16
+ /**
17
+ * `breakOffsets` plus the line bottoms inside nested rows that stay whole
18
+ * while a flow region can hold them: where to break once none can.
19
+ */
20
+ oversizedBreakOffsets: number[][];
16
21
  /** Safe cached page boundaries within each row, relative to the row top. */
17
22
  renderedBreakHints: RenderedRowBreakHint[][];
18
23
  /** Suppressible leading paragraph whitespace after each matching break offset. */
@@ -27,6 +32,42 @@ export type TableRowBreakInfo = {
27
32
  export declare function tableKeepNextOpeningHeight(block: TableBlock, measure: TableMeasure): number;
28
33
  /** Build break geometry for a table from its block + measure. */
29
34
  export declare function buildTableRowBreakInfo(block: TableBlock, measure: TableMeasure): TableRowBreakInfo;
35
+ /** Each cell's whole lines and atomic blocks, relative to the row top. */
36
+ export declare function rowCellLineBands(block: TableBlock, measure: TableMeasure, rowIndex: number): {
37
+ top: number;
38
+ bottom: number;
39
+ }[][];
40
+ type PerCellRowCutOptions = {
41
+ cellLines: readonly (readonly {
42
+ top: number;
43
+ bottom: number;
44
+ }[])[];
45
+ bandTop: number;
46
+ shownThrough: number;
47
+ maxSlice: number;
48
+ };
49
+ /**
50
+ * Cut a row that no shared line boundary lets a page hold. The cut itself runs
51
+ * through some cell's line, which then waits for the next band, so that band
52
+ * starts at the highest such line. Null when no line would finish on this page,
53
+ * or the next band would not start lower than this one, which is a line taller
54
+ * than the page: only clipping can place that.
55
+ */
56
+ export declare function perCellRowCut({ cellLines, bandTop, shownThrough, maxSlice }: PerCellRowCutOptions): {
57
+ cut: number;
58
+ nextTop: number;
59
+ } | null;
60
+ /** The part of one cell a `cellLineBand` shows, in the row's own coordinates. */
61
+ export declare function cellBandFromLines(lines: readonly {
62
+ top: number;
63
+ bottom: number;
64
+ }[], { shownThrough, cut }: {
65
+ shownThrough: number;
66
+ cut: number;
67
+ }): {
68
+ top: number;
69
+ bottom: number;
70
+ };
30
71
  /** Leading empty-paragraph whitespace to consume when a row resumes after `offset`. */
31
72
  export declare function getRowContinuationSkip(info: TableRowBreakInfo, rowIndex: number, offset: number): number;
32
73
  /**
@@ -35,4 +76,9 @@ export declare function getRowContinuationSkip(info: TableRowBreakInfo, rowIndex
35
76
  * `maxSlice`. Returns 0 when not even the first line fits.
36
77
  */
37
78
  export declare function snapRowBreak(info: TableRowBreakInfo, rowIndex: number, fromOffset: number, maxSlice: number): number;
79
+ /**
80
+ * `snapRowBreak` for a region that starts empty and still cannot hold the next
81
+ * unit: nested rows that stay whole give way so their content stays reachable.
82
+ */
83
+ export declare function snapOversizedRowBreak(info: TableRowBreakInfo, rowIndex: number, fromOffset: number, maxSlice: number): number;
38
84
  export {};
@@ -17,19 +17,60 @@ import { resolveTableCellPadding } from "./types.js";
17
17
  *
18
18
  * This computes, per row, the safe break offsets (the y of every line bottom in
19
19
  * the row's cells) so the paginator can snap a break to the deepest whole line
20
- * that still fits. Vertically-merged cells that span into a row are not modeled
21
- * here yet (a separate follow-up); each row uses its own cells' content.
20
+ * that still fits. A nested table contributes the lines and row bottoms of its
21
+ * own rows, so it continues across regions like the table that holds it.
22
+ * Vertically-merged cells that span into a row of the top-level table are not
23
+ * modeled here yet (a separate follow-up); each row uses its own cells' content.
22
24
  */
23
25
  const BREAK_OFFSET_EPSILON = .01;
24
- function isInsideRange(offset, range) {
25
- return offset > range.top && offset < range.bottom;
26
- }
26
+ /**
27
+ * Sorted, disjoint form of `ranges`. Ranges that only touch stay separate:
28
+ * their shared edge is a clean break.
29
+ */
30
+ const mergeBreakRanges = (ranges) => {
31
+ const merged = [];
32
+ for (const range of ranges.toSorted((a, b) => a.top - b.top)) {
33
+ const previous = merged.at(-1);
34
+ if (previous && range.top < previous.bottom) {
35
+ previous.bottom = Math.max(previous.bottom, range.bottom);
36
+ continue;
37
+ }
38
+ merged.push({ ...range });
39
+ }
40
+ return merged;
41
+ };
42
+ /**
43
+ * Binary search over the output of `mergeBreakRanges`. An offset within rounding
44
+ * of an edge is on that edge: nested positions are sums of more line heights
45
+ * than the sibling line they have to meet.
46
+ */
47
+ const isInsideMergedRanges = (offset, ranges) => {
48
+ let low = 0;
49
+ let high = ranges.length - 1;
50
+ while (low <= high) {
51
+ const middle = low + high >> 1;
52
+ const range = ranges[middle];
53
+ if (!range) return false;
54
+ if (offset <= range.top + BREAK_OFFSET_EPSILON) high = middle - 1;
55
+ else if (offset >= range.bottom - BREAK_OFFSET_EPSILON) low = middle + 1;
56
+ else return true;
57
+ }
58
+ return false;
59
+ };
27
60
  function getVerticalAlignmentOffset(cell, measure, rowHeight) {
28
61
  const spareHeight = Math.max(0, rowHeight - measure.height);
29
62
  if (cell?.verticalAlign === "bottom") return spareHeight;
30
63
  if (cell?.verticalAlign === "center") return spareHeight / 2;
31
64
  return 0;
32
65
  }
66
+ /** A nested table can outgrow the argument count `push(...items)` allows. */
67
+ const appendAll = (target, items) => {
68
+ for (const item of items) target.push(item);
69
+ };
70
+ const shiftRange = (range, offset) => ({
71
+ top: range.top + offset,
72
+ bottom: range.bottom + offset
73
+ });
33
74
  function shiftCellGeometry(geometry, offset) {
34
75
  if (offset <= 0) return geometry;
35
76
  return {
@@ -38,21 +79,75 @@ function shiftCellGeometry(geometry, offset) {
38
79
  offset: hint.offset + offset,
39
80
  lineAdvance: hint.lineAdvance
40
81
  })),
41
- unsafeRanges: geometry.unsafeRanges.map((range) => ({
42
- top: range.top + offset,
43
- bottom: range.bottom + offset
44
- })),
45
- suppressibleLeadingRanges: geometry.suppressibleLeadingRanges.map((range) => ({
46
- top: range.top + offset,
47
- bottom: range.bottom + offset
48
- }))
82
+ unsafeRanges: geometry.unsafeRanges.map((range) => shiftRange(range, offset)),
83
+ keepTogetherRanges: geometry.keepTogetherRanges.map((range) => shiftRange(range, offset)),
84
+ suppressibleLeadingRanges: geometry.suppressibleLeadingRanges.map((range) => shiftRange(range, offset))
85
+ };
86
+ }
87
+ /** Each measured cell's geometry in one table row, relative to the row top. */
88
+ function rowCellGeometries(block, measure, rowIndex) {
89
+ const rowHeight = measure.rows[rowIndex]?.height ?? 0;
90
+ const sourceCells = block.rows[rowIndex]?.cells ?? [];
91
+ const measuredCells = measure.rows[rowIndex]?.cells ?? [];
92
+ const geometries = [];
93
+ for (let c = 0; c < measuredCells.length; c++) {
94
+ const measuredCell = measuredCells[c];
95
+ if (!measuredCell) continue;
96
+ const sourceCell = sourceCells[c];
97
+ const spacing = getTableCellSpacingInsetsY(block.cellSpacing, rowIndex, sourceCell?.rowSpan ?? 1, block.rows.length);
98
+ geometries.push(shiftCellGeometry(cellBreakGeometry(sourceCell, measuredCell), spacing.top + getVerticalAlignmentOffset(sourceCell, measuredCell, Math.max(0, rowHeight - spacing.top - spacing.bottom))));
99
+ }
100
+ return geometries;
101
+ }
102
+ /** `w:cantSplit` (§17.4.6) and header rows stay whole while a region can hold them. */
103
+ const nestedRowKeepsTogether = (row) => row?.cantSplit === true || row?.isHeader === true;
104
+ /**
105
+ * Break geometry of a table nested in a cell, relative to its top. The cells of
106
+ * all its rows join one flat geometry: a break must clear every line of every
107
+ * cell, including a merged cell that spans several rows. Whitespace that a
108
+ * continuation may consume is left out, because it would have to be shared with
109
+ * the sibling cells flattening no longer tells apart.
110
+ */
111
+ function nestedTableBreakGeometry(block, measure) {
112
+ const nested = {
113
+ bottoms: [],
114
+ renderedBreakHints: [],
115
+ unsafeRanges: [],
116
+ keepTogetherRanges: [],
117
+ suppressibleLeadingRanges: []
49
118
  };
119
+ let rowTop = 0;
120
+ for (let r = 0; r < measure.rows.length; r++) {
121
+ const rowHeight = measure.rows[r]?.height ?? 0;
122
+ const sourceRow = block.rows[r];
123
+ if (sourceRow?.hidden !== true && rowHeight > 0) {
124
+ const rowBand = {
125
+ top: rowTop,
126
+ bottom: rowTop + rowHeight
127
+ };
128
+ nested.bottoms.push(rowBand.bottom);
129
+ if (nestedRowKeepsTogether(sourceRow)) nested.keepTogetherRanges.push(rowBand);
130
+ const fixedBox = sourceRow?.heightRule === "exact";
131
+ if (fixedBox) nested.unsafeRanges.push(rowBand);
132
+ const cells = fixedBox ? [] : rowCellGeometries(block, measure, r);
133
+ for (const cell of cells) {
134
+ const geometry = shiftCellGeometry(cell, rowTop);
135
+ appendAll(nested.bottoms, geometry.bottoms);
136
+ appendAll(nested.renderedBreakHints, geometry.renderedBreakHints);
137
+ appendAll(nested.unsafeRanges, geometry.unsafeRanges);
138
+ appendAll(nested.keepTogetherRanges, geometry.keepTogetherRanges);
139
+ }
140
+ }
141
+ rowTop += rowHeight;
142
+ }
143
+ return nested;
50
144
  }
51
145
  /** Cumulative break geometry within a single cell's content. */
52
146
  function cellBreakGeometry(cell, measure) {
53
147
  const bottoms = [];
54
148
  const renderedBreakHints = [];
55
149
  const unsafeRanges = [];
150
+ const keepTogetherRanges = [];
56
151
  const suppressibleLeadingRanges = [];
57
152
  const cellBlocks = cell?.blocks;
58
153
  const blockMeasures = measure.blocks;
@@ -103,11 +198,17 @@ function cellBreakGeometry(cell, measure) {
103
198
  if (blockHeight > 0) {
104
199
  const top = padTop + placement.contentTop;
105
200
  const y = top + blockHeight;
106
- unsafeRanges.push({
201
+ bottoms.push(y);
202
+ if (block.kind === "table" && blockMeasure.kind === "table") {
203
+ const nested = shiftCellGeometry(nestedTableBreakGeometry(block, blockMeasure), top);
204
+ appendAll(bottoms, nested.bottoms);
205
+ appendAll(renderedBreakHints, nested.renderedBreakHints);
206
+ appendAll(unsafeRanges, nested.unsafeRanges);
207
+ appendAll(keepTogetherRanges, nested.keepTogetherRanges);
208
+ } else unsafeRanges.push({
107
209
  top,
108
210
  bottom: y
109
211
  });
110
- bottoms.push(y);
111
212
  }
112
213
  }
113
214
  }
@@ -115,6 +216,7 @@ function cellBreakGeometry(cell, measure) {
115
216
  bottoms,
116
217
  renderedBreakHints,
117
218
  unsafeRanges,
219
+ keepTogetherRanges,
118
220
  suppressibleLeadingRanges
119
221
  };
120
222
  }
@@ -130,8 +232,8 @@ const mergeRenderedBreakHints = (hints) => {
130
232
  }
131
233
  return merged;
132
234
  };
133
- const continuationSkipForCell = (geometry, offset) => {
134
- if (!geometry.unsafeRanges.some(({ bottom }) => bottom > offset + BREAK_OFFSET_EPSILON)) return;
235
+ const continuationSkipForCell = ({ geometry, contentBottom }, offset) => {
236
+ if (contentBottom <= offset + BREAK_OFFSET_EPSILON) return;
135
237
  const leadingRange = geometry.suppressibleLeadingRanges.find(({ top, bottom }) => top <= offset + BREAK_OFFSET_EPSILON && bottom > offset + BREAK_OFFSET_EPSILON);
136
238
  return leadingRange ? leadingRange.bottom - offset : 0;
137
239
  };
@@ -141,8 +243,8 @@ const continuationSkipForCell = (geometry, offset) => {
141
243
  * every cell with remaining content is suppressible; non-empty paragraphs,
142
244
  * line boxes, cell padding, and explicit row height retain authored space.
143
245
  */
144
- const continuationSkipAfter = (geometries, offset) => {
145
- const skips = geometries.map((geometry) => continuationSkipForCell(geometry, offset)).filter((skip) => skip !== void 0);
246
+ const continuationSkipAfter = (cells, offset) => {
247
+ const skips = cells.map((cell) => continuationSkipForCell(cell, offset)).filter((skip) => skip !== void 0);
146
248
  if (skips.length === 0 || skips.some((skip) => skip <= BREAK_OFFSET_EPSILON)) return 0;
147
249
  return Math.min(...skips);
148
250
  };
@@ -178,36 +280,82 @@ function buildTableRowBreakInfo(block, measure) {
178
280
  }
179
281
  rowTops.push(acc);
180
282
  const breakOffsets = [];
283
+ const oversizedBreakOffsets = [];
181
284
  const renderedBreakHints = [];
182
285
  const continuationSkips = [];
183
286
  for (let r = 0; r < rowCount; r++) {
184
287
  const rowHeight = measure.rows[r]?.height ?? 0;
288
+ const cellGeometries = rowCellGeometries(block, measure, r);
185
289
  const offsets = /* @__PURE__ */ new Set();
186
290
  offsets.add(rowHeight);
187
- const sourceCells = block.rows[r]?.cells ?? [];
188
- const measuredCells = measure.rows[r]?.cells ?? [];
189
- const cellGeometries = [];
190
- for (let c = 0; c < measuredCells.length; c++) {
191
- const measuredCell = measuredCells[c];
192
- if (!measuredCell) continue;
193
- const sourceCell = sourceCells[c];
194
- const spacing = getTableCellSpacingInsetsY(block.cellSpacing, r, sourceCell?.rowSpan ?? 1, block.rows.length);
195
- const geometry = shiftCellGeometry(cellBreakGeometry(sourceCell, measuredCell), spacing.top + getVerticalAlignmentOffset(sourceCell, measuredCell, Math.max(0, rowHeight - spacing.top - spacing.bottom)));
196
- cellGeometries.push(geometry);
197
- for (const b of geometry.bottoms) if (b > 0 && b < rowHeight) offsets.add(b);
198
- }
199
- const sortedOffsets = [...offsets].filter((offset) => offset === rowHeight || cellGeometries.every((geometry) => geometry.unsafeRanges.every((range) => !isInsideRange(offset, range)))).sort((a, b) => a - b);
291
+ for (const geometry of cellGeometries) for (const b of geometry.bottoms) if (b > 0 && b < rowHeight) offsets.add(b);
292
+ const unsafeRanges = mergeBreakRanges(cellGeometries.flatMap((geometry) => geometry.unsafeRanges));
293
+ const keepTogetherRanges = mergeBreakRanges(cellGeometries.flatMap((geometry) => geometry.keepTogetherRanges));
294
+ const lineSafeOffsets = [...offsets].filter((offset) => offset === rowHeight || !isInsideMergedRanges(offset, unsafeRanges)).sort((a, b) => a - b);
295
+ const sortedOffsets = lineSafeOffsets.filter((offset) => offset === rowHeight || !isInsideMergedRanges(offset, keepTogetherRanges));
200
296
  breakOffsets.push(sortedOffsets);
201
- renderedBreakHints.push(mergeRenderedBreakHints(cellGeometries.flatMap((geometry) => geometry.renderedBreakHints).filter(({ offset }) => offset > BREAK_OFFSET_EPSILON && offset < rowHeight - BREAK_OFFSET_EPSILON && cellGeometries.every((geometry) => geometry.unsafeRanges.every((range) => !isInsideRange(offset, range))))));
202
- continuationSkips.push(sortedOffsets.map((offset) => continuationSkipAfter(cellGeometries, offset)));
297
+ oversizedBreakOffsets.push(lineSafeOffsets);
298
+ renderedBreakHints.push(mergeRenderedBreakHints(cellGeometries.flatMap((geometry) => geometry.renderedBreakHints).filter(({ offset }) => offset > BREAK_OFFSET_EPSILON && offset < rowHeight - BREAK_OFFSET_EPSILON && !isInsideMergedRanges(offset, unsafeRanges) && !isInsideMergedRanges(offset, keepTogetherRanges))));
299
+ const continuationCells = cellGeometries.map((geometry) => {
300
+ let contentBottom = Number.NEGATIVE_INFINITY;
301
+ for (const range of geometry.unsafeRanges) contentBottom = Math.max(contentBottom, range.bottom);
302
+ return {
303
+ geometry,
304
+ contentBottom
305
+ };
306
+ });
307
+ continuationSkips.push(sortedOffsets.map((offset) => continuationSkipAfter(continuationCells, offset)));
203
308
  }
204
309
  return {
205
310
  rowTops,
206
311
  breakOffsets,
312
+ oversizedBreakOffsets,
207
313
  renderedBreakHints,
208
314
  continuationSkips
209
315
  };
210
316
  }
317
+ /** Each cell's whole lines and atomic blocks, relative to the row top. */
318
+ function rowCellLineBands(block, measure, rowIndex) {
319
+ return rowCellGeometries(block, measure, rowIndex).map((geometry) => mergeBreakRanges(geometry.unsafeRanges));
320
+ }
321
+ /**
322
+ * Cut a row that no shared line boundary lets a page hold. The cut itself runs
323
+ * through some cell's line, which then waits for the next band, so that band
324
+ * starts at the highest such line. Null when no line would finish on this page,
325
+ * or the next band would not start lower than this one, which is a line taller
326
+ * than the page: only clipping can place that.
327
+ */
328
+ function perCellRowCut({ cellLines, bandTop, shownThrough, maxSlice }) {
329
+ const cut = bandTop + maxSlice;
330
+ let finishesLine = false;
331
+ let nextTop = cut;
332
+ for (const lines of cellLines) for (const line of lines) {
333
+ if (line.bottom <= shownThrough + BREAK_OFFSET_EPSILON) continue;
334
+ if (line.bottom <= cut + BREAK_OFFSET_EPSILON) {
335
+ finishesLine = true;
336
+ continue;
337
+ }
338
+ nextTop = Math.min(nextTop, line.top);
339
+ break;
340
+ }
341
+ return finishesLine && nextTop > bandTop + BREAK_OFFSET_EPSILON ? {
342
+ cut,
343
+ nextTop
344
+ } : null;
345
+ }
346
+ /** The part of one cell a `cellLineBand` shows, in the row's own coordinates. */
347
+ function cellBandFromLines(lines, { shownThrough, cut }) {
348
+ const shown = lines.filter(({ bottom }) => bottom > shownThrough + BREAK_OFFSET_EPSILON && bottom <= cut + BREAK_OFFSET_EPSILON);
349
+ const first = shown.at(0);
350
+ const last = shown.at(-1);
351
+ return first && last ? {
352
+ top: first.top,
353
+ bottom: last.bottom
354
+ } : {
355
+ top: cut,
356
+ bottom: cut
357
+ };
358
+ }
211
359
  /** Leading empty-paragraph whitespace to consume when a row resumes after `offset`. */
212
360
  function getRowContinuationSkip(info, rowIndex, offset) {
213
361
  const offsets = info.breakOffsets[rowIndex];
@@ -222,7 +370,16 @@ function getRowContinuationSkip(info, rowIndex, offset) {
222
370
  * `maxSlice`. Returns 0 when not even the first line fits.
223
371
  */
224
372
  function snapRowBreak(info, rowIndex, fromOffset, maxSlice) {
225
- const offsets = info.breakOffsets[rowIndex];
373
+ return snapToOffsets(info.breakOffsets[rowIndex], fromOffset, maxSlice);
374
+ }
375
+ /**
376
+ * `snapRowBreak` for a region that starts empty and still cannot hold the next
377
+ * unit: nested rows that stay whole give way so their content stays reachable.
378
+ */
379
+ function snapOversizedRowBreak(info, rowIndex, fromOffset, maxSlice) {
380
+ return snapToOffsets(info.oversizedBreakOffsets[rowIndex], fromOffset, maxSlice);
381
+ }
382
+ function snapToOffsets(offsets, fromOffset, maxSlice) {
226
383
  if (!offsets || offsets.length === 0) return 0;
227
384
  const limit = fromOffset + maxSlice;
228
385
  let best = 0;
@@ -233,4 +390,4 @@ function snapRowBreak(info, rowIndex, fromOffset, maxSlice) {
233
390
  }
234
391
  return best;
235
392
  }
236
- export { buildTableRowBreakInfo, getRowContinuationSkip, snapRowBreak, tableKeepNextOpeningHeight };
393
+ export { buildTableRowBreakInfo, cellBandFromLines, getRowContinuationSkip, perCellRowCut, rowCellLineBands, snapOversizedRowBreak, snapRowBreak, tableKeepNextOpeningHeight };
@@ -5,7 +5,7 @@ import { CssBorderStyle } from "../utils/borderCss.js";
5
5
  import { AutomaticTextSpacingPolicy } from "./measure/measureTypes.js";
6
6
  import { ImagePosition, ImageWrap, InlineWrapper, NumberFormat, OutlineLevel, ParagraphNumberingOverride, PreviewDescriptor, SdtProperties, SdtType, SectionStart, ShapeTextBody, TableCellFormatting, TableWidthType, UnderlineStyle, VerticalAlign } from "@stll/docx-core/model";
7
7
  declare namespace types_d_exports {
8
- export { BlockId, BorderStyle, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, Layout, LayoutOptions, LineBreakRun, ListMarkerFormatting, MathRun, Measure, MeasuredLine, NOTE_SEPARATOR_RULE_THICKNESS, NOTE_SEPARATOR_WIDTH_FRACTION, NoteAreaLayout, NoteSeparatorKind, NoteSeparatorRule, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionPageNumbering, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxGradientFill, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getTableRowLeadingWidth, isFloatingImageRun, isFloatingTextBoxBlock, isListNumPr, isTextWrappingFloatingImageRun, resolveTableCellPadding, resolveTableWidthPx, stripFlowBlockPmAnchors, tableColumnsArePinned };
8
+ export { BlockId, BorderStyle, CellBorderSpec, CellBorders, ColumnBreakBlock, ColumnBreakMeasure, ColumnLayout, DEFAULT_TEXTBOX_MARGINS, DEFAULT_TEXTBOX_WIDTH, DocumentPosition, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, FieldRun, FloatingTablePosition, FlowBlock, FootnoteContent, FootnoteWindow, Fragment, FragmentBase, HeaderFooterContent, HeaderFooterContentHeights, HeaderFooterLayout, HitTestResult, HyperlinkInfo, ImageBlock, ImageFragment, ImageMeasure, ImageRun, ImageRunPosition, Layout, LayoutOptions, LineBreakRun, ListMarkerFormatting, MathRun, Measure, MeasuredLine, NOTE_SEPARATOR_RULE_THICKNESS, NOTE_SEPARATOR_WIDTH_FRACTION, NoteAreaLayout, NoteSeparatorKind, NoteSeparatorRule, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, SectionPageNumbering, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxGradientFill, TextBoxMeasure, TextRun, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getTableRowLeadingWidth, isFloatingImageRun, isFloatingTextBoxBlock, isListNumPr, isTextWrappingFloatingImageRun, resolveTableCellPadding, resolveTableWidthPx, stripFlowBlockPmAnchors, tableColumnsArePinned };
9
9
  }
10
10
  /**
11
11
  * Unique identifier for a block in the document.
@@ -585,6 +585,11 @@ export type ParagraphAttrs = {
585
585
  export type ParagraphBlock = {
586
586
  kind: "paragraph";
587
587
  id: BlockId;
588
+ /**
589
+ * Set on a block that exists only in layout: its text is in no ProseMirror
590
+ * node, so a click anywhere in it resolves to this position.
591
+ */
592
+ fixedPosition?: number;
588
593
  /** Stable Word `w14:paraId` / PM `paraId`, when available. */
589
594
  paraId?: string;
590
595
  runs: Run[];
@@ -749,8 +754,8 @@ export type ImageBlock = {
749
754
  src: string;
750
755
  /**
751
756
  * Set instead of `src` for a drawing with no image data: the display list
752
- * rasterises it when it interns it. `src` is then empty, and a block with
753
- * neither paints nothing, as before.
757
+ * draws it as primitives and the legacy painter as an SVG source. `src` is
758
+ * then empty, and a block with neither paints nothing.
754
759
  */
755
760
  preview?: PreviewDescriptor;
756
761
  width: number;
@@ -1212,6 +1217,22 @@ export type TableFragment = FragmentBase & {
1212
1217
  */
1213
1218
  topClip?: number;
1214
1219
  bottomClip?: number;
1220
+ /**
1221
+ * Set when no line boundary is shared by every cell within a page: the band
1222
+ * above cuts through some cell's line, so each cell shows only the lines that
1223
+ * end in `(shownThrough, cut]`, in the row's own coordinates. The next band
1224
+ * starts at the highest line left over, so a cell can show nothing twice and
1225
+ * lose nothing, at the cost of a gap of up to one line beside a shorter cell.
1226
+ */
1227
+ cellLineBand?: {
1228
+ shownThrough: number;
1229
+ cut: number;
1230
+ /** Each cell's visible band, by cell index, in the row's own coordinates. */
1231
+ cells: readonly {
1232
+ top: number;
1233
+ bottom: number;
1234
+ }[];
1235
+ };
1215
1236
  };
1216
1237
  /**
1217
1238
  * An image fragment positioned on a page.
@@ -1291,6 +1312,11 @@ export type Page = {
1291
1312
  endnoteIds?: number[];
1292
1313
  /** Height reserved for the footnote area at page bottom (pixels). */
1293
1314
  footnoteReservedHeight?: number;
1315
+ /**
1316
+ * The part of a note this page shows, for a note too tall for its page. A
1317
+ * note listed in `footnoteIds` with no window shows whole.
1318
+ */
1319
+ footnoteWindows?: readonly FootnoteWindow[];
1294
1320
  /**
1295
1321
  * Rules drawn for the `w:separator` / `w:continuationSeparator` marks of a
1296
1322
  * note area that flows with the body (endnotes), in page coordinates.
@@ -1356,6 +1382,12 @@ export type HeaderFooterContentHeights = Partial<Record<"default" | "first" | "e
1356
1382
  /**
1357
1383
  * Pre-calculated footnote content for layout and rendering.
1358
1384
  */
1385
+ /** The part of a footnote's content one page shows, in the note's own heights. */
1386
+ export type FootnoteWindow = {
1387
+ noteId: number;
1388
+ from: number;
1389
+ to: number;
1390
+ };
1359
1391
  export type FootnoteContent = {
1360
1392
  /** Footnote ID. */
1361
1393
  id: number;
@@ -1440,6 +1472,14 @@ export type LayoutOptions = {
1440
1472
  * earlier-column placement.
1441
1473
  */
1442
1474
  footnoteHeightById?: Map<number, number>;
1475
+ /**
1476
+ * Set when a note taller than its page's room continues on the next pages.
1477
+ * A reference then reserves at most a share of its section's page, and the
1478
+ * layout ends with `trailingPages` pages for what passes the last body page.
1479
+ */
1480
+ footnoteContinuation?: {
1481
+ trailingPages: number;
1482
+ };
1443
1483
  /** Header/footer references for each document section, by section index. */
1444
1484
  sectionHeaderFooterRefs?: PageHeaderFooterRefs[];
1445
1485
  /** Note areas (endnotes) whose blocks flow with the body blocks. */
@@ -0,0 +1,8 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ /** `preview` as an `<img>` source that fills whatever box the image has. */
3
+ export declare const previewToSvgDataUrl: (preview: document_d_exports.PreviewDescriptor) => string;
4
+ /** The source an image paints from: its bytes, or its drawn preview. */
5
+ export declare const paintedImageSource: (image: {
6
+ readonly src: string;
7
+ readonly preview?: document_d_exports.PreviewDescriptor;
8
+ }) => string;
@@ -0,0 +1,47 @@
1
+ import { paintPreview } from "../display-list/build/previewPrimitives.js";
2
+ import { svgPreviewDataUrl } from "../docx/previewBudget.js";
3
+ import { panic } from "better-result";
4
+ // src/layout-painter/previewSvg.ts
5
+ /**
6
+ * What the DOM painter shows for a drawing with no image data.
7
+ *
8
+ * Its marks come from the display list's own `paintPreview`, so the two painters
9
+ * cannot draw a preview differently. An SVG in an `<img>` runs no script and
10
+ * fetches nothing, and every value written here is a number.
11
+ */
12
+ const cssColor = ({ r, g, b, a }) => `rgba(${String(r)},${String(g)},${String(b)},${String(a)})`;
13
+ const svgPoints = (points) => points.map(({ xPx, yPx }) => `${String(xPx)},${String(yPx)}`).join(" ");
14
+ const svgMark = (primitive) => {
15
+ switch (primitive.kind) {
16
+ case "rect": {
17
+ const { xPx, yPx, widthPx, heightPx } = primitive.rect;
18
+ const fill = primitive.fill ? cssColor(primitive.fill) : "none";
19
+ return `<rect x="${String(xPx)}" y="${String(yPx)}" width="${String(widthPx)}" height="${String(heightPx)}" fill="${fill}"/>`;
20
+ }
21
+ case "polygon": return `<polygon points="${svgPoints(primitive.points)}" fill="${cssColor(primitive.fill)}"/>`;
22
+ case "polyline": return `<polyline points="${svgPoints(primitive.points)}" fill="none" stroke="${cssColor(primitive.stroke.color)}" stroke-width="${String(primitive.stroke.thicknessPx)}"/>`;
23
+ default: return panic(`a preview does not draw ${primitive.kind}`);
24
+ }
25
+ };
26
+ const dataUrls = /* @__PURE__ */ new WeakMap();
27
+ /** `preview` as an `<img>` source that fills whatever box the image has. */
28
+ const previewToSvgDataUrl = (preview) => {
29
+ const known = dataUrls.get(preview);
30
+ if (known !== void 0) return known;
31
+ const hasArea = preview.extent.width > 0 && preview.extent.height > 0;
32
+ const widthPx = hasArea ? preview.extent.width : 1;
33
+ const heightPx = hasArea ? preview.extent.height : 1;
34
+ const marks = paintPreview(preview, {
35
+ xPx: 0,
36
+ yPx: 0,
37
+ widthPx,
38
+ heightPx
39
+ });
40
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${String(widthPx)} ${String(heightPx)}" width="${String(widthPx)}" height="${String(heightPx)}" preserveAspectRatio="none">${marks.map(svgMark).join("")}</svg>`;
41
+ const url = svgPreviewDataUrl(svg);
42
+ dataUrls.set(preview, url);
43
+ return url;
44
+ };
45
+ /** The source an image paints from: its bytes, or its drawn preview. */
46
+ const paintedImageSource = (image) => image.preview ? previewToSvgDataUrl(image.preview) : image.src;
47
+ export { paintedImageSource, previewToSvgDataUrl };
@@ -1,6 +1,7 @@
1
1
  import { imageLuminanceFilter } from "../utils/imageLuminance.js";
2
2
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
3
3
  import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js";
4
+ import { paintedImageSource } from "./previewSvg.js";
4
5
  // src/layout-painter/renderImage.ts
5
6
  /**
6
7
  * CSS class names for image elements
@@ -139,7 +140,7 @@ function renderImageFragment(fragment, block, _measure, _context, options = {})
139
140
  if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
140
141
  if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
141
142
  const imgEl = doc.createElement("img");
142
- applySanitizedImageSrc(imgEl, block.src);
143
+ applySanitizedImageSrc(imgEl, paintedImageSource(block));
143
144
  imgEl.alt = block.alt ?? "";
144
145
  imgEl.style.width = "100%";
145
146
  imgEl.style.height = "100%";