@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
@@ -9,6 +9,7 @@ import { expectTextBoxAnchorAttrs } from "../../prosemirror/textBoxAnchorAttrs.j
9
9
  import { assertValidProseMirrorDocument } from "../../prosemirror/validation.js";
10
10
  import { createStyleEngine } from "../../style-engine/styleEngine.js";
11
11
  import { getColumns } from "../sectionColumns.js";
12
+ import { convertAltChunkPlaceholder } from "./altChunkPlaceholder.js";
12
13
  import { mergeRunInParagraphs, reserveLeadingEmptyOutlineHeight, suppressFinalEmptyParagraphAfterTable, suppressFinalParagraphInRepeatedEmptySuffix } from "./flowBlockPostprocessing.js";
13
14
  import { convertBorderSpecToLayout } from "./flowBorders.js";
14
15
  import { nextBlockId, resetBlockIdCounter, twipsToPixels } from "./flowConversionShared.js";
@@ -384,6 +385,9 @@ function toFlowBlocks(doc, options = {}) {
384
385
  case "textBox":
385
386
  pushTextBox(node, pos);
386
387
  break;
388
+ case "preservedBlock":
389
+ for (const block of convertAltChunkPlaceholder(node, pos, opts)) trackedPush(block);
390
+ break;
387
391
  case "horizontalRule":
388
392
  case "pageBreak": {
389
393
  if (consumedPageBreakPositions.has(pos)) break;
@@ -0,0 +1,7 @@
1
+ import { BlockId, FlowBlock } from "../../layout-engine/types.js";
2
+ /**
3
+ * Each block's index by id, the first block's where ids repeat. A pass that
4
+ * looks up the block of every fragment builds it once instead of searching
5
+ * the blocks for each fragment.
6
+ */
7
+ export declare const indexBlocksById: (blocks: readonly FlowBlock[]) => ReadonlyMap<BlockId, number>;
@@ -0,0 +1,12 @@
1
+ // src/layout-bridge/engine/blockIndex.ts
2
+ /**
3
+ * Each block's index by id, the first block's where ids repeat. A pass that
4
+ * looks up the block of every fragment builds it once instead of searching
5
+ * the blocks for each fragment.
6
+ */
7
+ const indexBlocksById = (blocks) => {
8
+ const indices = /* @__PURE__ */ new Map();
9
+ for (const [index, block] of blocks.entries()) if (!indices.has(block.id)) indices.set(block.id, index);
10
+ return indices;
11
+ };
12
+ export { indexBlocksById };
@@ -224,6 +224,7 @@ function clickToPositionInParagraph(fragmentHit) {
224
224
  function clickToPositionInTableCell(tableCellHit) {
225
225
  const { cellBlock, cellMeasure, cellLocalX, cellLocalY, cellContentWidth } = tableCellHit;
226
226
  if (!cellBlock || !cellMeasure) return null;
227
+ if (cellBlock.fixedPosition !== void 0) return cellBlock.fixedPosition;
227
228
  return clickToPositionInParagraph({
228
229
  fragment: {
229
230
  kind: "paragraph",
@@ -255,7 +256,10 @@ function clickToPosition(fragmentHit, tableCellHit) {
255
256
  if (tableCellHit) return clickToPositionInTableCell(tableCellHit);
256
257
  if (!fragmentHit) return null;
257
258
  const { fragment } = fragmentHit;
258
- if (fragment.kind === "paragraph") return clickToPositionInParagraph(fragmentHit)?.pmPosition ?? null;
259
+ if (fragment.kind === "paragraph") {
260
+ if (fragmentHit.block.kind === "paragraph" && fragmentHit.block.fixedPosition !== void 0) return fragmentHit.block.fixedPosition;
261
+ return clickToPositionInParagraph(fragmentHit)?.pmPosition ?? null;
262
+ }
259
263
  if (fragment.kind === "image") return fragment.pmStart ?? null;
260
264
  return null;
261
265
  }
@@ -3,6 +3,7 @@ import { getTableCellContentWidth } from "../../layout-engine/measure/tableCellF
3
3
  import { buildTableCellGrid, buildTableCellPlacements, getTableCellSpacingInsetsY } from "../../layout-engine/measure/tableCellGrid.js";
4
4
  import { getHeaderRowsHeight } from "../../layout-engine/tableLayout.js";
5
5
  import { resolveTableCellPadding } from "../../layout-engine/types.js";
6
+ import { indexBlocksById } from "./blockIndex.js";
6
7
  // src/layout-bridge/engine/hitTest.ts
7
8
  /**
8
9
  * Hit Testing Utilities
@@ -78,12 +79,6 @@ function getPageIndexAtY(layout, y) {
78
79
  })?.pageIndex ?? null;
79
80
  }
80
81
  /**
81
- * Find a block by its ID in the blocks array.
82
- */
83
- function findBlockIndexById(blocks, blockId) {
84
- return blocks.findIndex((block) => block.id === blockId);
85
- }
86
- /**
87
82
  * Calculate the actual height of a paragraph fragment from its lines.
88
83
  */
89
84
  function calculateParagraphFragmentHeight(fragment, measure) {
@@ -107,8 +102,9 @@ function hitTestFragment(pageHit, blocks, measures, pagePoint) {
107
102
  if (Math.abs(dy) > .5) return dy;
108
103
  return a.x - b.x;
109
104
  });
105
+ const blockIndices = indexBlocksById(blocks);
110
106
  for (const fragment of sortedFragments) {
111
- const blockIndex = findBlockIndexById(blocks, fragment.blockId);
107
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
112
108
  if (blockIndex === -1) continue;
113
109
  const block = blocks[blockIndex];
114
110
  const measure = measures[blockIndex];
@@ -137,9 +133,10 @@ function hitTestFragment(pageHit, blocks, measures, pagePoint) {
137
133
  * Hit-test to find image fragments (they may overlap other content).
138
134
  */
139
135
  function hitTestImageFragment(pageHit, blocks, measures, pagePoint) {
136
+ const blockIndices = indexBlocksById(blocks);
140
137
  for (const fragment of pageHit.page.fragments) {
141
138
  if (fragment.kind !== "image") continue;
142
- const blockIndex = findBlockIndexById(blocks, fragment.blockId);
139
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
143
140
  if (blockIndex === -1) continue;
144
141
  const block = blocks[blockIndex];
145
142
  const measure = measures[blockIndex];
@@ -167,13 +164,14 @@ function hitTestImageFragment(pageHit, blocks, measures, pagePoint) {
167
164
  * @returns TableCellHit if a table cell was found, null otherwise.
168
165
  */
169
166
  function hitTestTableCell(pageHit, blocks, measures, pagePoint) {
167
+ const blockIndices = indexBlocksById(blocks);
170
168
  for (const fragment of pageHit.page.fragments) {
171
169
  if (fragment.kind !== "table") continue;
172
170
  const tableFragment = fragment;
173
171
  const withinX = pagePoint.x >= tableFragment.x && pagePoint.x <= tableFragment.x + tableFragment.width;
174
172
  const withinY = pagePoint.y >= tableFragment.y && pagePoint.y <= tableFragment.y + tableFragment.height;
175
173
  if (!withinX || !withinY) continue;
176
- const blockIndex = findBlockIndexById(blocks, tableFragment.blockId);
174
+ const blockIndex = blockIndices.get(tableFragment.blockId) ?? -1;
177
175
  if (blockIndex === -1) continue;
178
176
  const block = blocks[blockIndex];
179
177
  const measure = measures[blockIndex];
@@ -363,8 +361,9 @@ function isPointInContentArea(_layout, pageHit, pagePoint) {
363
361
  function findNearestFragment(pageHit, blocks, measures, pagePoint) {
364
362
  let nearestHit = null;
365
363
  let nearestDistance = Infinity;
364
+ const blockIndices = indexBlocksById(blocks);
366
365
  for (const fragment of pageHit.page.fragments) {
367
- const blockIndex = findBlockIndexById(blocks, fragment.blockId);
366
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
368
367
  if (blockIndex === -1) continue;
369
368
  const block = blocks[blockIndex];
370
369
  const measure = measures[blockIndex];
@@ -10,6 +10,7 @@ import { resolveTableCellPadding } from "../../layout-engine/types.js";
10
10
  import { normalizeHorizontalScalePercent } from "../../utils/horizontalScale.js";
11
11
  import { resolveParagraphLineGeometryForBlock, resolvePhysicalParagraphInlineLayout } from "../../utils/paragraphInlineLayout.js";
12
12
  import { inlineImageBoundingBox } from "../../utils/rotationBoundingBox.js";
13
+ import { indexBlocksById } from "./blockIndex.js";
13
14
  import { getPageTop } from "./hitTest.js";
14
15
  import { computeLinePmRange } from "./linePmRange.js";
15
16
  // src/layout-bridge/engine/selectionRects.ts
@@ -49,9 +50,6 @@ function mathRunToFontStyle(run) {
49
50
  /**
50
51
  * Find a block by its ID.
51
52
  */
52
- function findBlockById(blocks, blockId) {
53
- return blocks.findIndex((block) => block.id === blockId);
54
- }
55
53
  function getCellContentOffsetY(cell, cellMeasure, rowHeight) {
56
54
  const { top: padTop } = resolveTableCellPadding(cell);
57
55
  const spareHeight = Math.max(0, rowHeight - cellMeasure.height);
@@ -211,12 +209,13 @@ function selectionToRects(layout, blocks, measures, from, to) {
211
209
  const selTo = Math.max(from, to);
212
210
  const rects = [];
213
211
  const tableCellPlacements = /* @__PURE__ */ new WeakMap();
212
+ const blockIndices = indexBlocksById(blocks);
214
213
  for (let pageIndex = 0; pageIndex < layout.pages.length; pageIndex++) {
215
214
  const page = layout.pages[pageIndex];
216
215
  const pageTopY = getPageTop(layout, pageIndex);
217
216
  for (const fragment of page.fragments) {
218
217
  if (fragment.kind === "paragraph") {
219
- const blockIndex = findBlockById(blocks, fragment.blockId);
218
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
220
219
  if (blockIndex === -1) continue;
221
220
  const block = blocks[blockIndex];
222
221
  const measure = measures[blockIndex];
@@ -261,7 +260,7 @@ function selectionToRects(layout, blocks, measures, from, to) {
261
260
  }
262
261
  }
263
262
  if (fragment.kind === "table") {
264
- const blockIndex = findBlockById(blocks, fragment.blockId);
263
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
265
264
  if (blockIndex === -1) continue;
266
265
  const block = blocks[blockIndex];
267
266
  const measure = measures[blockIndex];
@@ -385,12 +384,13 @@ function selectionToRects(layout, blocks, measures, from, to) {
385
384
  * @returns Caret position, or null if not found.
386
385
  */
387
386
  function getCaretPosition(layout, blocks, measures, pmPosition) {
387
+ const blockIndices = indexBlocksById(blocks);
388
388
  for (let pageIndex = 0; pageIndex < layout.pages.length; pageIndex++) {
389
389
  const page = layout.pages[pageIndex];
390
390
  const pageTopY = getPageTop(layout, pageIndex);
391
391
  for (const fragment of page.fragments) {
392
392
  if (fragment.kind === "paragraph") {
393
- const blockIndex = findBlockById(blocks, fragment.blockId);
393
+ const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
394
394
  if (blockIndex === -1) continue;
395
395
  const block = blocks[blockIndex];
396
396
  const measure = measures[blockIndex];
@@ -0,0 +1,36 @@
1
+ import { FootnoteContent, FootnoteWindow, Page } from "./types.js";
2
+ /** What each note's reference reserves on a page of this content height. */
3
+ export declare const footnoteReservationHeights: (heights: ReadonlyMap<number, number>, contentHeight: number) => Map<number, number>;
4
+ /** Every height a window of the note may end at, ascending, the note's end last. */
5
+ export declare const footnoteBreakOffsets: (content: Pick<FootnoteContent, "measures" | "height">) => number[];
6
+ type NoteContent = Pick<FootnoteContent, "measures" | "height">;
7
+ type PlanOptions = {
8
+ pages: readonly Page[];
9
+ contentById: ReadonlyMap<number, NoteContent>;
10
+ /** Pages already added past the last body page for a note's rest. */
11
+ trailingPages?: number;
12
+ };
13
+ export type FootnoteContinuationPlan = {
14
+ /** A page number's notes and their height, for each page the plan changes. */
15
+ pages: Map<number, {
16
+ ids: number[];
17
+ windows: FootnoteWindow[];
18
+ height: number;
19
+ }>;
20
+ /** The height a carried note reserves on a page before the body is placed. */
21
+ reservedHeights: Map<number, number>;
22
+ /** Pages the rest of a note still needs beyond the ones laid out. */
23
+ extraPages: number;
24
+ /** How many pages past the last body page the layout should add. */
25
+ trailingPages: number;
26
+ };
27
+ /** Where each note's windows fall, given how the body laid out. */
28
+ export declare const planFootnoteContinuation: ({ pages, contentById, trailingPages }: PlanOptions) => FootnoteContinuationPlan;
29
+ /** Whether a layout was made with what this plan asks for. */
30
+ export declare const footnoteContinuationSettled: (used: {
31
+ reservedHeights: ReadonlyMap<number, number> | undefined;
32
+ trailingPages: number;
33
+ }, plan: FootnoteContinuationPlan) => boolean;
34
+ /** The pages with a plan's note windows. */
35
+ export declare const applyFootnoteContinuation: (pages: readonly Page[], plan: FootnoteContinuationPlan) => Page[];
36
+ export {};
@@ -0,0 +1,210 @@
1
+ import { measuredLineAdvance } from "./lineFlow.js";
2
+ import "./types.js";
3
+ // src/layout-engine/footnoteContinuation.ts
4
+ /**
5
+ * A footnote taller than the room its page leaves continues on the next page.
6
+ *
7
+ * The note's reference line keeps its page and the note fills what is left of
8
+ * it. What remains opens the next page's note area, ahead of that page's own
9
+ * notes, and the body there moves up to make room. A note never breaks through
10
+ * a line: each page shows a window of the note between two line bottoms.
11
+ */
12
+ /** The most of a page a note may claim, keeping body beside its reference. */
13
+ const NOTE_SHARE_OF_PAGE = .75;
14
+ const EPSILON = .01;
15
+ const contentHeightOf = (page) => page.size.h - page.margins.top - page.margins.bottom;
16
+ const noteShareOf = (contentHeight) => Math.max(0, contentHeight) * NOTE_SHARE_OF_PAGE;
17
+ /** What each note's reference reserves on a page of this content height. */
18
+ const footnoteReservationHeights = (heights, contentHeight) => {
19
+ const share = noteShareOf(contentHeight);
20
+ const reserved = /* @__PURE__ */ new Map();
21
+ for (const [id, height] of heights) reserved.set(id, Math.min(height, share));
22
+ return reserved;
23
+ };
24
+ const blockHeight = (measure) => {
25
+ if (measure.kind === "paragraph" || measure.kind === "table") return measure.totalHeight;
26
+ return measure.kind === "image" || measure.kind === "textBox" ? measure.height : 0;
27
+ };
28
+ /** Where a block can be cut inside itself: below a line or below a row. */
29
+ const inBlockBreakOffsets = (measure, top) => {
30
+ const offsets = [];
31
+ let bottom = top;
32
+ if (measure.kind === "paragraph") for (const line of measure.lines.slice(0, -1)) {
33
+ bottom += measuredLineAdvance(line);
34
+ offsets.push(bottom);
35
+ }
36
+ else if (measure.kind === "table") for (const row of measure.rows.slice(0, -1)) {
37
+ bottom += row.height;
38
+ offsets.push(bottom);
39
+ }
40
+ return offsets;
41
+ };
42
+ /** Every height a window of the note may end at, ascending, the note's end last. */
43
+ const footnoteBreakOffsets = (content) => {
44
+ const offsets = [];
45
+ let top = 0;
46
+ for (const measure of content.measures) {
47
+ offsets.push(...inBlockBreakOffsets(measure, top));
48
+ top += blockHeight(measure);
49
+ offsets.push(top);
50
+ }
51
+ offsets.push(content.height);
52
+ return [...new Set(offsets)].toSorted((a, b) => a - b);
53
+ };
54
+ const bodyBottomOf = (page) => {
55
+ let bottom = 0;
56
+ for (const fragment of page.fragments) bottom = Math.max(bottom, fragment.y + ("height" in fragment ? fragment.height : 0));
57
+ return Math.max(0, bottom - page.margins.top);
58
+ };
59
+ /** What of these notes fits a page's room, and what goes on to the next page. */
60
+ const placeEntries = ({ entries, room, fullRoom, contentById }) => {
61
+ const ids = [];
62
+ const windows = [];
63
+ const rest = [];
64
+ let left = room;
65
+ let cut = false;
66
+ let height = 12;
67
+ for (const { noteId, from } of entries) {
68
+ const content = contentById.get(noteId);
69
+ if (!content) continue;
70
+ if (cut) {
71
+ rest.push({
72
+ noteId,
73
+ from
74
+ });
75
+ continue;
76
+ }
77
+ const remaining = content.height - from;
78
+ if (remaining + 0 <= left + EPSILON) {
79
+ ids.push(noteId);
80
+ if (from > 0) windows.push({
81
+ noteId,
82
+ from,
83
+ to: content.height
84
+ });
85
+ left -= remaining + 0;
86
+ height += remaining + 0;
87
+ continue;
88
+ }
89
+ const start = from + EPSILON;
90
+ const offsets = footnoteBreakOffsets(content).filter((offset) => offset > start);
91
+ let fitting;
92
+ for (const offset of offsets) if (offset - from <= left + EPSILON) fitting = offset;
93
+ const next = offsets.at(0);
94
+ const oversized = ids.length === 0 && next !== void 0 && next - from > fullRoom + EPSILON;
95
+ const to = fitting ?? (oversized ? next : void 0);
96
+ cut = true;
97
+ if (to === void 0) {
98
+ rest.push({
99
+ noteId,
100
+ from
101
+ });
102
+ continue;
103
+ }
104
+ ids.push(noteId);
105
+ windows.push({
106
+ noteId,
107
+ from,
108
+ to
109
+ });
110
+ height += to - from + 0;
111
+ if (to < content.height - EPSILON) rest.push({
112
+ noteId,
113
+ from: to
114
+ });
115
+ }
116
+ return {
117
+ ids,
118
+ windows,
119
+ rest,
120
+ height: ids.length === 0 ? 0 : height
121
+ };
122
+ };
123
+ /** Where each note's windows fall, given how the body laid out. */
124
+ const planFootnoteContinuation = ({ pages, contentById, trailingPages = 0 }) => {
125
+ const plan = {
126
+ pages: /* @__PURE__ */ new Map(),
127
+ reservedHeights: /* @__PURE__ */ new Map(),
128
+ extraPages: 0,
129
+ trailingPages
130
+ };
131
+ const last = pages.at(-1);
132
+ if (!last) return plan;
133
+ const reserveFor = (entries, fromPage) => {
134
+ let needed = 12;
135
+ for (const { noteId, from } of entries) {
136
+ const height = contentById.get(noteId)?.height ?? from;
137
+ needed += height - from + 0;
138
+ }
139
+ for (let next = fromPage; needed > EPSILON; next += 1) {
140
+ const share = noteShareOf(contentHeightOf(pages[next - 1] ?? last));
141
+ if (share <= EPSILON) {
142
+ if (next > pages.length) break;
143
+ continue;
144
+ }
145
+ plan.reservedHeights.set(next, Math.min(needed, share));
146
+ needed -= share;
147
+ }
148
+ };
149
+ let carried = [];
150
+ for (const page of pages) {
151
+ const own = (page.footnoteIds ?? []).map((noteId) => ({
152
+ noteId,
153
+ from: 0
154
+ }));
155
+ const fullRoom = contentHeightOf(page) - 12;
156
+ const placed = placeEntries({
157
+ entries: [...carried, ...own],
158
+ room: fullRoom - bodyBottomOf(page),
159
+ fullRoom,
160
+ contentById
161
+ });
162
+ if (carried.length > 0 || placed.rest.length > 0) plan.pages.set(page.number, {
163
+ ids: placed.ids,
164
+ windows: placed.windows,
165
+ height: placed.height
166
+ });
167
+ carried = placed.rest;
168
+ if (carried.length > 0) reserveFor(carried, page.number + 1);
169
+ }
170
+ const fullRoom = contentHeightOf(last) - 12;
171
+ while (carried.length > 0) {
172
+ plan.extraPages += 1;
173
+ carried = placeEntries({
174
+ entries: carried,
175
+ room: fullRoom,
176
+ fullRoom,
177
+ contentById
178
+ }).rest;
179
+ }
180
+ let surplus = 0;
181
+ if (plan.extraPages === 0) {
182
+ const noteOn = (page) => plan.pages.get(page.number)?.ids.length ?? page.footnoteIds?.length ?? 0;
183
+ for (const page of pages.slice(pages.length - trailingPages).toReversed()) {
184
+ if (page.fragments.length > 0 || noteOn(page) > 0) break;
185
+ surplus += 1;
186
+ }
187
+ }
188
+ plan.trailingPages = trailingPages + plan.extraPages - surplus;
189
+ return plan;
190
+ };
191
+ /** Whether a layout was made with what this plan asks for. */
192
+ const footnoteContinuationSettled = (used, plan) => {
193
+ if (used.trailingPages !== plan.trailingPages) return false;
194
+ if ((used.reservedHeights?.size ?? 0) !== plan.reservedHeights.size) return false;
195
+ for (const [page, height] of plan.reservedHeights) if (Math.abs((used.reservedHeights?.get(page) ?? -1) - height) > EPSILON) return false;
196
+ return true;
197
+ };
198
+ /** The pages with a plan's note windows. */
199
+ const applyFootnoteContinuation = (pages, plan) => pages.map((page) => {
200
+ const placed = plan.pages.get(page.number);
201
+ if (!placed) return page;
202
+ const next = {
203
+ ...page,
204
+ footnoteIds: placed.ids,
205
+ footnoteReservedHeight: placed.height
206
+ };
207
+ if (placed.windows.length > 0) next.footnoteWindows = placed.windows;
208
+ return next;
209
+ });
210
+ export { applyFootnoteContinuation, footnoteBreakOffsets, footnoteContinuationSettled, footnoteReservationHeights, planFootnoteContinuation };
@@ -1,4 +1,4 @@
1
- import { 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 } from "./types.js";
1
+ import { 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 } from "./types.js";
2
2
  import { PageState, Paginator, PaginatorOptions, createPaginator } from "./paginator.js";
3
3
  import { KeepNextChain, calculateChainHeight, computeKeepNextChains, getMidChainIndices, hasKeepLines, hasPageBreakBefore } from "./keep-together.js";
4
4
  import { resolveSectionHeaderFooterRefs } from "./headerFooterRefs.js";
@@ -25,4 +25,4 @@ export declare function applyContextualSpacing(blocks: FlowBlock[]): void;
25
25
  * reservations as page floors so every column participates in the same footnote geometry.
26
26
  */
27
27
  export declare function layoutDocument(blocks: FlowBlock[], measures: Measure[], options: LayoutOptions): Layout;
28
- export { BlockId, BorderStyle, type BreakDecision, 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, type KeepNextChain, Layout, LayoutOptions, LineBreakRun, ListMarkerFormatting, MathRun, Measure, MeasuredLine, NOTE_SEPARATOR_RULE_THICKNESS, NOTE_SEPARATOR_WIDTH_FRACTION, NoteAreaLayout, NoteSeparatorKind, NoteSeparatorRule, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, type SectionLayoutConfig, SectionPageNumbering, type SectionState, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxGradientFill, TextBoxMeasure, TextRun, applyPendingToActive, assertExhaustiveFlowBlock, calculateChainHeight, collectSectionConfigs, computeKeepNextChains, createInitialSectionState, createPaginator, findPageIndexContainingPmPos, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getEffectiveColumns, getEffectiveMargins, getEffectivePageSize, getHeaderRowsHeight, getMidChainIndices, getTableRowLeadingWidth, hasKeepLines, hasPageBreakBefore, isFloatingImageRun, isFloatingTextBoxBlock, isListNumPr, isTextWrappingFloatingImageRun, resolveSectionHeaderFooterRefs, resolveTableCellPadding, resolveTableWidthPx, scheduleSectionBreak, stripFlowBlockPmAnchors, tableColumnsArePinned };
28
+ export { BlockId, BorderStyle, type BreakDecision, 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, type KeepNextChain, Layout, LayoutOptions, LineBreakRun, ListMarkerFormatting, MathRun, Measure, MeasuredLine, NOTE_SEPARATOR_RULE_THICKNESS, NOTE_SEPARATOR_WIDTH_FRACTION, NoteAreaLayout, NoteSeparatorKind, NoteSeparatorRule, Page, PageBreakBlock, PageBreakMeasure, PageHeaderFooterRefs, PageMargins, type PageState, type Paginator, type PaginatorOptions, ParagraphAttrs, ParagraphBlock, ParagraphBorders, ParagraphFragment, ParagraphIndent, ParagraphMeasure, ParagraphSpacing, RenderedPageBreakRun, Run, RunFormatting, SdtGroup, SectionBreakBlock, SectionBreakMeasure, type SectionLayoutConfig, SectionPageNumbering, type SectionState, TabAlignment, TabRun, TabStop, TableBlock, TableCell, TableCellMeasure, TableFragment, TableMeasure, TableRow, TableRowMeasure, TextBoxBlock, TextBoxFlowAttrs, TextBoxFragment, TextBoxGradientFill, TextBoxMeasure, TextRun, applyPendingToActive, assertExhaustiveFlowBlock, calculateChainHeight, collectSectionConfigs, computeKeepNextChains, createInitialSectionState, createPaginator, findPageIndexContainingPmPos, floatingTextBoxReservesBand, floatingTextBoxWrapsText, getEffectiveColumns, getEffectiveMargins, getEffectivePageSize, getHeaderRowsHeight, getMidChainIndices, getTableRowLeadingWidth, hasKeepLines, hasPageBreakBefore, isFloatingImageRun, isFloatingTextBoxBlock, isListNumPr, isTextWrappingFloatingImageRun, resolveSectionHeaderFooterRefs, resolveTableCellPadding, resolveTableWidthPx, scheduleSectionBreak, stripFlowBlockPmAnchors, tableColumnsArePinned };
@@ -1,4 +1,5 @@
1
1
  import { reflowFootnoteColumns } from "./footnoteColumnReflow.js";
2
+ import { footnoteReservationHeights } from "./footnoteContinuation.js";
2
3
  import { resolveSectionHeaderFooterRefs } from "./headerFooterRefs.js";
3
4
  import { layoutImage } from "./imageLayout.js";
4
5
  import { calculateChainHeight, computeKeepNextChains, getMidChainIndices, hasKeepLines, hasPageBreakBefore } from "./keep-together.js";
@@ -125,6 +126,8 @@ function layoutDocumentPass(blocks, measures, options) {
125
126
  let activeSectionMarginTop = initialConfig.margins.top;
126
127
  let activeSectionPageHeight = initialConfig.pageSize.h;
127
128
  let activeSectionMarginBottom = initialConfig.margins.bottom;
129
+ const noteHeightsForActiveSection = () => options.footnoteHeightById && options.footnoteContinuation ? footnoteReservationHeights(options.footnoteHeightById, activeSectionPageHeight - activeSectionMarginTop - activeSectionMarginBottom) : options.footnoteHeightById;
130
+ let footnoteHeightById = noteHeightsForActiveSection();
128
131
  let renderedBreakState = INITIAL_RENDERED_BREAK_STATE;
129
132
  const noteAreaContinuation = createNoteAreaContinuation(options.noteAreas, paginator);
130
133
  for (let i = 0; i < blocks.length; i++) {
@@ -166,13 +169,13 @@ function layoutDocumentPass(blocks, measures, options) {
166
169
  measure,
167
170
  paginator,
168
171
  contentWidth: paginator.columnWidth,
169
- footnoteHeightById: options.footnoteHeightById,
172
+ footnoteHeightById,
170
173
  suppressSpaceBefore: breakDecision.suppressSpaceBefore || suppressDocumentStartAutomaticSpaceBefore
171
174
  });
172
175
  break;
173
176
  case "table":
174
177
  if (block.floating) layoutFloatingTable(block, measure, paginator, paginator.getContentWidth());
175
- else layoutTable(block, measure, paginator, options.footnoteHeightById);
178
+ else layoutTable(block, measure, paginator, footnoteHeightById);
176
179
  break;
177
180
  case "image":
178
181
  layoutImage(block, measure, paginator);
@@ -216,6 +219,7 @@ function layoutDocumentPass(blocks, measures, options) {
216
219
  activeSectionMarginTop = nextSectionConfig.margins.top;
217
220
  activeSectionPageHeight = nextSectionConfig.pageSize.h;
218
221
  activeSectionMarginBottom = nextSectionConfig.margins.bottom;
222
+ footnoteHeightById = noteHeightsForActiveSection();
219
223
  sectionIdx++;
220
224
  break;
221
225
  }
@@ -230,6 +234,7 @@ function layoutDocumentPass(blocks, measures, options) {
230
234
  }
231
235
  paginator.setPageTopContinuation(void 0);
232
236
  if (paginator.states.length === 0) paginator.getCurrentState();
237
+ for (let added = 0; added < (options.footnoteContinuation?.trailingPages ?? 0); added += 1) paginator.forcePageBreak();
233
238
  return {
234
239
  pageSize,
235
240
  pages: paginator.pages,
@@ -192,6 +192,8 @@ const imageMeasureCacheInput = (run) => ({
192
192
  exactLineHeight: run.exactLineHeight,
193
193
  positioned: run.position !== void 0
194
194
  });
195
+ /** A cache input naming no position: one that names a position does not compile. */
196
+ const positionFree = (input) => input;
195
197
  const runMeasureCacheInput = (run, fontContextRef, documentFontContextRef) => {
196
198
  switch (run.kind) {
197
199
  case "text":
@@ -199,15 +201,18 @@ const runMeasureCacheInput = (run, fontContextRef, documentFontContextRef) => {
199
201
  case "renderedPageBreak":
200
202
  case "field":
201
203
  case "math": {
202
- const { embeddedFontFamilyMap, documentFontFacts, ...formatting } = run;
203
- return {
204
+ const { embeddedFontFamilyMap, documentFontFacts, pmStart: _pmStart, pmEnd: _pmEnd, ...formatting } = run;
205
+ return positionFree({
204
206
  ...formatting,
205
207
  embeddedFontFamilies: fontContextRef(embeddedFontFamilyMap),
206
208
  documentFontFacts: documentFontContextRef(documentFontFacts)
207
- };
209
+ });
208
210
  }
209
- case "lineBreak": return run;
210
- case "image": return imageMeasureCacheInput(run);
211
+ case "lineBreak": {
212
+ const { pmStart: _pmStart, pmEnd: _pmEnd, ...lineBreak } = run;
213
+ return positionFree(lineBreak);
214
+ }
215
+ case "image": return positionFree(imageMeasureCacheInput(run));
211
216
  default: return run;
212
217
  }
213
218
  };
@@ -589,7 +589,7 @@ function measureParagraph(block, maxWidth, options) {
589
589
  while (chunkStart < measuredWord.length) {
590
590
  const spaceLeft = currentLine.availableWidth - currentLine.width - chunkLeadingLetterSpacing + WIDTH_TOLERANCE;
591
591
  const remaining = measuredWord.slice(chunkStart);
592
- let bestEnd = findMaxFittingLength(remaining, style, spaceLeft, currentLine.width === 0, breakPolicy);
592
+ const bestEnd = findMaxFittingLength(remaining, style, spaceLeft, currentLine.width === 0, breakPolicy);
593
593
  if (bestEnd === 0) {
594
594
  startNewLine(runIndex, charIndex + chunkStart);
595
595
  chunkLeadingLetterSpacing = 0;
@@ -1,7 +1,9 @@
1
+ import { document_d_exports } from "../../types/document.js";
1
2
  import { ImageRun, TableCell, TableCellMeasure } from "../types.js";
2
3
  import { FloatingImageZone } from "./floatingZones.js";
3
4
  export type TableCellFloatingImage = {
4
5
  src: string;
6
+ preview?: document_d_exports.PreviewDescriptor;
5
7
  width: number;
6
8
  height: number;
7
9
  alt?: string;
@@ -64,6 +64,7 @@ function getTableCellFloatingImages(cell, cellMeasure, contentWidth, resolvePosi
64
64
  else if (run.cssFloat === "right") wrapText = "left";
65
65
  result.push({
66
66
  src: run.src,
67
+ ...run.preview ? { preview: run.preview } : {},
67
68
  width: run.width,
68
69
  height: run.height,
69
70
  ...run.alt !== void 0 ? { alt: run.alt } : {},
@@ -0,0 +1,16 @@
1
+ import { TableBlock, TableRow } from "../types.js";
2
+ /** A vertical span in the coordinates of whatever is being painted. */
3
+ export type VisibleBand = {
4
+ readonly top: number;
5
+ readonly bottom: number;
6
+ };
7
+ /** The same band in the coordinates of a child that starts at `origin`. */
8
+ export declare const bandFromOrigin: (band: VisibleBand, origin: number) => VisibleBand;
9
+ export declare const isOutsideBand: (band: VisibleBand | undefined, top: number, bottom: number) => boolean;
10
+ /**
11
+ * Where a row's paint ends: a merged cell belongs to the row that opens it and
12
+ * reaches through every row it spans. `rowTops` has `rows.length + 1` entries.
13
+ */
14
+ export declare const tableRowPaintBottom: (row: TableRow, rowIndex: number, rowTops: readonly number[]) => number;
15
+ /** Floating cell content can paint outside the row it is anchored in. */
16
+ export declare function tableHasFloatingCellContent(block: TableBlock): boolean;
@@ -0,0 +1,28 @@
1
+ import { isFloatingImageRun, isFloatingTextBoxBlock } from "../types.js";
2
+ // src/layout-engine/measure/tableVisibleBand.ts
3
+ /** The same band in the coordinates of a child that starts at `origin`. */
4
+ const bandFromOrigin = (band, origin) => ({
5
+ top: band.top - origin,
6
+ bottom: band.bottom - origin
7
+ });
8
+ const isOutsideBand = (band, top, bottom) => band !== void 0 && (bottom <= band.top || top >= band.bottom);
9
+ /**
10
+ * Where a row's paint ends: a merged cell belongs to the row that opens it and
11
+ * reaches through every row it spans. `rowTops` has `rows.length + 1` entries.
12
+ */
13
+ const tableRowPaintBottom = (row, rowIndex, rowTops) => {
14
+ let widestSpan = 1;
15
+ for (const cell of row.cells) widestSpan = Math.max(widestSpan, cell.rowSpan ?? 1);
16
+ const lastTop = rowTops.length - 1;
17
+ return rowTops[Math.min(lastTop, rowIndex + widestSpan)] ?? 0;
18
+ };
19
+ /** Floating cell content can paint outside the row it is anchored in. */
20
+ function tableHasFloatingCellContent(block) {
21
+ for (const row of block.rows) for (const cell of row.cells) for (const cellBlock of cell.blocks) {
22
+ if (cellBlock.kind === "textBox" && isFloatingTextBoxBlock(cellBlock)) return true;
23
+ if (cellBlock.kind === "paragraph" && cellBlock.runs.some((run) => run.kind === "image" && isFloatingImageRun(run))) return true;
24
+ if (cellBlock.kind === "table" && tableHasFloatingCellContent(cellBlock)) return true;
25
+ }
26
+ return false;
27
+ }
28
+ export { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom };