@stll/folio-core 0.67.0 → 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 (251) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +104 -34
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/note-references.d.ts +6 -0
  7. package/dist/ai-edits/note-references.js +7 -1
  8. package/dist/ai-edits/read.d.ts +19 -0
  9. package/dist/ai-edits/snapshot.d.ts +6 -0
  10. package/dist/ai-edits/snapshot.js +8 -3
  11. package/dist/ai-edits/types.d.ts +9 -1
  12. package/dist/ai-suggestions/apply.js +13 -4
  13. package/dist/compare/compare.js +2 -1
  14. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  15. package/dist/compare/inserted-resource-snapshot.js +7 -3
  16. package/dist/controller/canonicalClipboard.js +29 -12
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  19. package/dist/controller/canonicalInlineProjection.js +192 -28
  20. package/dist/controller/canonicalInput.d.ts +2 -1
  21. package/dist/controller/canonicalInput.js +28 -1
  22. package/dist/controller/canonicalListRendering.d.ts +2 -1
  23. package/dist/controller/canonicalListRendering.js +1 -1
  24. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  25. package/dist/controller/canonicalLockGuard.js +88 -0
  26. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  27. package/dist/controller/canonicalPublicOperations.js +274 -20
  28. package/dist/controller/canonicalSession.d.ts +87 -7
  29. package/dist/controller/canonicalSession.js +327 -73
  30. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  31. package/dist/controller/canonicalStoryEditor.js +4 -3
  32. package/dist/controller/canonicalStructure.d.ts +2 -1
  33. package/dist/controller/canonicalStructure.js +129 -7
  34. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  35. package/dist/controller/contentControlWidgetController.js +13 -1
  36. package/dist/controller/folioEditor.js +1 -0
  37. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  38. package/dist/controller/headerFooterEditorManager.js +5 -5
  39. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  40. package/dist/controller/hiddenEditorApi.js +1 -0
  41. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  42. package/dist/controller/hiddenEditorManager.js +91 -37
  43. package/dist/controller/layoutPipeline.js +48 -15
  44. package/dist/controller/noteEditorManager.d.ts +2 -2
  45. package/dist/controller/noteEditorManager.js +5 -5
  46. package/dist/display-list/build/pageFurniture.js +41 -19
  47. package/dist/display-list/build/tablePrimitives.js +23 -4
  48. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  49. package/dist/document-operations.d.ts +8 -0
  50. package/dist/document-operations.js +4 -3
  51. package/dist/docx/blockContentParser.d.ts +7 -3
  52. package/dist/docx/blockContentParser.js +2 -3
  53. package/dist/docx/blockPlainText.js +2 -0
  54. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  55. package/dist/docx/bookmarkRangeJoin.js +43 -0
  56. package/dist/docx/canonicalSave.js +5 -1
  57. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  58. package/dist/docx/canonicalSessionInput.js +7 -2
  59. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  60. package/dist/docx/commentAnchorIndex.js +39 -11
  61. package/dist/docx/commentRangeIntegrity.js +30 -24
  62. package/dist/docx/commentRangeJoin.d.ts +4 -0
  63. package/dist/docx/commentRangeJoin.js +26 -12
  64. package/dist/docx/commentReferenceCompletion.js +5 -4
  65. package/dist/docx/commentReferenceNormalization.js +40 -18
  66. package/dist/docx/compatibility.js +9 -2
  67. package/dist/docx/containerChildren.js +22 -1
  68. package/dist/docx/encryption/compoundFile.js +9 -1
  69. package/dist/docx/encryption/encryptionInfo.js +16 -2
  70. package/dist/docx/ensureParaIds.js +46 -7
  71. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  72. package/dist/docx/ensureUniqueControlIds.js +110 -0
  73. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  74. package/dist/docx/headerFooterVerbatim.js +13 -2
  75. package/dist/docx/hostCommentThreads.d.ts +17 -0
  76. package/dist/docx/hostCommentThreads.js +49 -0
  77. package/dist/docx/hyperlinkParser.js +9 -2
  78. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  79. package/dist/docx/inlineWrapperContent.js +9 -2
  80. package/dist/docx/listMarkerComputation.d.ts +35 -1
  81. package/dist/docx/listMarkerComputation.js +39 -1
  82. package/dist/docx/listModelNormalization.d.ts +44 -1
  83. package/dist/docx/listModelNormalization.js +227 -96
  84. package/dist/docx/markupRangeMarker.d.ts +14 -0
  85. package/dist/docx/markupRangeMarker.js +15 -1
  86. package/dist/docx/metadataPrivacy.js +43 -22
  87. package/dist/docx/normalizeBaseDirection.js +3 -1
  88. package/dist/docx/paragraphParser.js +159 -48
  89. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  90. package/dist/docx/paragraphPropertySource.js +22 -1
  91. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  92. package/dist/docx/paragraphTraversal.js +2 -0
  93. package/dist/docx/parseWarningMessage.js +2 -1
  94. package/dist/docx/parser.js +6 -0
  95. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  96. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  97. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  98. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  99. package/dist/docx/reviewResolutionProvenance.js +110 -25
  100. package/dist/docx/rezip.d.ts +6 -0
  101. package/dist/docx/rezip.js +38 -21
  102. package/dist/docx/selectiveSave.js +6 -10
  103. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  104. package/dist/docx/selectiveXmlPatch.js +11 -7
  105. package/dist/docx/serializer/documentSerializer.js +3 -1
  106. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  107. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  108. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  109. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  110. package/dist/docx/serializer/noteSerializer.js +23 -16
  111. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  112. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  113. package/dist/docx/serializer/runSerializer.js +2 -2
  114. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  115. package/dist/docx/serializer/tableSerializer.js +4 -2
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  117. package/dist/docx/server/createBilingualDocument.js +27 -5
  118. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  119. package/dist/docx/sessionListPruning.d.ts +2 -0
  120. package/dist/docx/sessionListPruning.js +50 -0
  121. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  122. package/dist/docx/splitRevisionPieces.js +14 -0
  123. package/dist/docx/storyBlockReplay.js +4 -0
  124. package/dist/docx/structuralXmlPatch.js +19 -7
  125. package/dist/docx/tableParser.d.ts +6 -2
  126. package/dist/docx/tableParser.js +2 -3
  127. package/dist/docx/textBoxContentParser.d.ts +11 -0
  128. package/dist/docx/textBoxContentParser.js +51 -0
  129. package/dist/docx/textBoxParser.d.ts +0 -5
  130. package/dist/docx/textBoxParser.js +1 -23
  131. package/dist/docx/verticalMergeProjection.js +1 -1
  132. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  133. package/dist/fonts/fontsourceFaces.js +1 -7
  134. package/dist/i18n/messages/ar.gen.js +2 -0
  135. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  136. package/dist/i18n/messages/catalogs.gen.js +34 -0
  137. package/dist/i18n/messages/cs.gen.js +2 -0
  138. package/dist/i18n/messages/de.gen.js +2 -0
  139. package/dist/i18n/messages/en.gen.js +2 -0
  140. package/dist/i18n/messages/es.gen.js +2 -0
  141. package/dist/i18n/messages/et.gen.js +2 -0
  142. package/dist/i18n/messages/fr.gen.js +2 -0
  143. package/dist/i18n/messages/he.gen.js +2 -0
  144. package/dist/i18n/messages/hi.gen.js +2 -0
  145. package/dist/i18n/messages/hu.gen.js +2 -0
  146. package/dist/i18n/messages/lt.gen.js +2 -0
  147. package/dist/i18n/messages/lv.gen.js +2 -0
  148. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  149. package/dist/i18n/messages/pl.gen.js +2 -0
  150. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  151. package/dist/i18n/messages/sk.gen.js +2 -0
  152. package/dist/i18n/messages/tr.gen.js +2 -0
  153. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  154. package/dist/internal/acceptedBlockProjection.js +2 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  156. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  157. package/dist/internal/revisionResolutionInline.js +1 -2
  158. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  159. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  160. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  161. package/dist/layout-bridge/engine/hitTest.js +9 -10
  162. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  163. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  164. package/dist/layout-engine/footnoteContinuation.js +210 -0
  165. package/dist/layout-engine/index.d.ts +2 -2
  166. package/dist/layout-engine/index.js +7 -2
  167. package/dist/layout-engine/measure/cache.js +10 -5
  168. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  169. package/dist/layout-engine/tableLayout.js +29 -5
  170. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  171. package/dist/layout-engine/tableRowBreak.js +43 -1
  172. package/dist/layout-engine/types.d.ts +36 -1
  173. package/dist/layout-painter/renderPage.d.ts +4 -4
  174. package/dist/layout-painter/renderPage.js +46 -17
  175. package/dist/layout-painter/renderTable.js +7 -4
  176. package/dist/managers/AutoSaveManager.d.ts +5 -1
  177. package/dist/managers/FindReplaceManager.js +3 -10
  178. package/dist/markdown/escape.d.ts +20 -1
  179. package/dist/markdown/escape.js +43 -1
  180. package/dist/markdown/renderBlock.js +4 -1
  181. package/dist/markdown/renderParagraph.js +13 -27
  182. package/dist/markdown/renderTable.js +6 -2
  183. package/dist/markdown/trailers.js +1 -0
  184. package/dist/pdf/images.d.ts +17 -1
  185. package/dist/pdf/images.js +22 -4
  186. package/dist/pdf/writePdf.js +4 -2
  187. package/dist/prosemirror/attrs/index.js +1 -0
  188. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  189. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  190. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  191. package/dist/prosemirror/commands/comments.d.ts +25 -0
  192. package/dist/prosemirror/commands/comments.js +102 -11
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +1 -1
  195. package/dist/prosemirror/commentIdAllocator.js +2 -2
  196. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  197. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  198. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  199. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  200. package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
  201. package/dist/prosemirror/conversion/index.d.ts +1 -1
  202. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  203. package/dist/prosemirror/conversion/toProseDoc.js +319 -51
  204. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  205. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  206. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  207. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  208. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  209. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  210. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  211. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  212. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  213. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  214. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  215. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  216. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  217. package/dist/prosemirror/index.d.ts +2 -2
  218. package/dist/prosemirror/listLabels.js +3 -2
  219. package/dist/prosemirror/listNumbering.d.ts +6 -0
  220. package/dist/prosemirror/listNumbering.js +12 -9
  221. package/dist/prosemirror/lockedControls.d.ts +13 -0
  222. package/dist/prosemirror/lockedControls.js +106 -0
  223. package/dist/prosemirror/markupViewProjection.js +1 -1
  224. package/dist/prosemirror/noteReferenceReview.js +2 -2
  225. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  226. package/dist/prosemirror/plugins/suggestionMode.js +20 -9
  227. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  228. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  229. package/dist/prosemirror/replacedAnnotations.js +1 -0
  230. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  231. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  232. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  233. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  234. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  235. package/dist/prosemirror/runStyleFormatting.js +16 -13
  236. package/dist/prosemirror/schema/marks.d.ts +6 -0
  237. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  238. package/dist/prosemirror/validation.js +1 -0
  239. package/dist/redline.js +23 -9
  240. package/dist/server.d.ts +2 -2
  241. package/dist/style-sets/extract.js +2 -2
  242. package/dist/types/canonicalCapabilities.d.ts +29 -8
  243. package/dist/types/canonicalCapabilities.js +13 -9
  244. package/dist/utils/cssString.d.ts +7 -0
  245. package/dist/utils/cssString.js +9 -0
  246. package/dist/utils/fontResolver.js +4 -1
  247. package/dist/utils/replaceText.d.ts +11 -0
  248. package/dist/utils/replaceText.js +39 -7
  249. package/dist/version-comparison.d.ts +9 -1
  250. package/dist/version-comparison.js +11 -5
  251. package/package.json +2 -2
@@ -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;
@@ -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, snapOversizedRowBreak, 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.oversizedBreakOffsets[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;
@@ -149,18 +152,30 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
149
152
  if (slice <= 0) {
150
153
  const from = consumed;
151
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
+ }
152
167
  }
153
168
  }
154
169
  discardPassedRenderedBreakHints();
155
170
  const renderedBreakHint = renderedBreakHints[renderedBreakHintIndex];
156
- 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) {
157
172
  slice = renderedBreakHint.offset - consumed;
158
173
  renderedBreakHintIndex += 1;
159
174
  forceRenderedPageBreak = true;
160
175
  }
161
176
  const sliceBottom = consumed + slice;
162
177
  const continuationSkip = sliceBottom < splittableRow.height ? getRowContinuationSkip(breakInfo, currentRowIndex, sliceBottom) : 0;
163
- const nextConsumed = Math.min(splittableRow.height, sliceBottom + continuationSkip);
178
+ const nextConsumed = perCellCut ? perCellCut.nextTop : Math.min(splittableRow.height, sliceBottom + continuationSkip);
164
179
  const moreAfter = !(nextConsumed >= splittableRow.height) || currentRowIndex + 1 < rows.length;
165
180
  const fragmentHeight = headerOverhead + slice;
166
181
  const sliceFragment = {
@@ -177,11 +192,19 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
177
192
  toRow: currentRowIndex + 1,
178
193
  ...block.pmStart !== void 0 ? { pmStart: block.pmStart } : {},
179
194
  ...block.pmEnd !== void 0 ? { pmEnd: block.pmEnd } : {},
180
- ...consumed > 0 || currentRowIndex > 0 ? { continuesFromPrev: true } : {},
195
+ ...consumed > 0 || shownThrough > 0 || currentRowIndex > 0 ? { continuesFromPrev: true } : {},
181
196
  ...moreAfter ? { continuesOnNext: true } : {},
182
197
  ...repeatHeaderRows ? { headerRowCount } : {},
183
198
  ...consumed > 0 ? { topClip: consumed } : {},
184
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
+ } } : {},
185
208
  ...block.sdtGroups ? { sdtGroups: block.sdtGroups } : {}
186
209
  };
187
210
  const sliceResult = paginator.addFragment(sliceFragment, fragmentHeight, 0, 0);
@@ -191,6 +214,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
191
214
  rowIndex: currentRowIndex
192
215
  });
193
216
  consumed = nextConsumed;
217
+ shownThrough = perCellCut ? perCellCut.cut : consumed;
194
218
  if (consumed < splittableRow.height) {
195
219
  if (forceRenderedPageBreak) paginator.forcePageBreak();
196
220
  else {
@@ -32,6 +32,42 @@ export type TableRowBreakInfo = {
32
32
  export declare function tableKeepNextOpeningHeight(block: TableBlock, measure: TableMeasure): number;
33
33
  /** Build break geometry for a table from its block + measure. */
34
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
+ };
35
71
  /** Leading empty-paragraph whitespace to consume when a row resumes after `offset`. */
36
72
  export declare function getRowContinuationSkip(info: TableRowBreakInfo, rowIndex: number, offset: number): number;
37
73
  /**
@@ -314,6 +314,48 @@ function buildTableRowBreakInfo(block, measure) {
314
314
  continuationSkips
315
315
  };
316
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
+ }
317
359
  /** Leading empty-paragraph whitespace to consume when a row resumes after `offset`. */
318
360
  function getRowContinuationSkip(info, rowIndex, offset) {
319
361
  const offsets = info.breakOffsets[rowIndex];
@@ -348,4 +390,4 @@ function snapToOffsets(offsets, fromOffset, maxSlice) {
348
390
  }
349
391
  return best;
350
392
  }
351
- export { buildTableRowBreakInfo, getRowContinuationSkip, snapOversizedRowBreak, 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.
@@ -1217,6 +1217,22 @@ export type TableFragment = FragmentBase & {
1217
1217
  */
1218
1218
  topClip?: number;
1219
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
+ };
1220
1236
  };
1221
1237
  /**
1222
1238
  * An image fragment positioned on a page.
@@ -1296,6 +1312,11 @@ export type Page = {
1296
1312
  endnoteIds?: number[];
1297
1313
  /** Height reserved for the footnote area at page bottom (pixels). */
1298
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[];
1299
1320
  /**
1300
1321
  * Rules drawn for the `w:separator` / `w:continuationSeparator` marks of a
1301
1322
  * note area that flows with the body (endnotes), in page coordinates.
@@ -1361,6 +1382,12 @@ export type HeaderFooterContentHeights = Partial<Record<"default" | "first" | "e
1361
1382
  /**
1362
1383
  * Pre-calculated footnote content for layout and rendering.
1363
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
+ };
1364
1391
  export type FootnoteContent = {
1365
1392
  /** Footnote ID. */
1366
1393
  id: number;
@@ -1445,6 +1472,14 @@ export type LayoutOptions = {
1445
1472
  * earlier-column placement.
1446
1473
  */
1447
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
+ };
1448
1483
  /** Header/footer references for each document section, by section index. */
1449
1484
  sectionHeaderFooterRefs?: PageHeaderFooterRefs[];
1450
1485
  /** Note areas (endnotes) whose blocks flow with the body blocks. */
@@ -1,6 +1,6 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { DocumentFontFacts } from "../fonts/documentFontFacts.js";
3
- import { FootnoteContent, HeaderFooterContent, ImageRun, Page, isFloatingImageRun } from "../layout-engine/types.js";
3
+ import { FootnoteContent, FootnoteWindow, HeaderFooterContent, ImageRun, Page, isFloatingImageRun } from "../layout-engine/types.js";
4
4
  import { AnchoredImagePosition, PageGeometry } from "./anchoredImagePosition.js";
5
5
  import { RenderContext, emuToPixels } from "./renderUtils.js";
6
6
  import { BlockLookup } from "./index.js";
@@ -249,12 +249,12 @@ export declare function renderFloatingImagesLayer(floatingImages: PageFloatingIm
249
249
  * from eigenpal/docx-editor#485, extended for folio's fallback rendering
250
250
  * and any wrapper margin so the helper matches the painted stack.
251
251
  */
252
- export declare function calculateFootnoteAreaRenderHeight(footnotes: FootnoteRenderItem[]): number;
252
+ export declare function calculateFootnoteAreaRenderHeight(footnotes: FootnoteRenderItem[], windows?: readonly FootnoteWindow[]): number;
253
253
  /**
254
254
  * Render the footnote area at the bottom of a page.
255
255
  * Includes a separator line (33% width) and footnote entries.
256
256
  */
257
- export declare function renderFootnoteArea(footnotes: FootnoteRenderItem[], contentWidth: number, doc: Document, context?: RenderContext): HTMLElement;
257
+ export declare function renderFootnoteArea(footnotes: FootnoteRenderItem[], contentWidth: number, doc: Document, context?: RenderContext, windows?: readonly FootnoteWindow[]): HTMLElement;
258
258
  /**
259
259
  * Render a single page to DOM
260
260
  *
@@ -280,7 +280,7 @@ export declare function applySectionHeaderFooterOptions(page: Page, pageOptions:
280
280
  * Compute a fingerprint string for a page that changes when its content changes.
281
281
  * Used to detect which pages need re-rendering on incremental updates.
282
282
  */
283
- export declare function computePageFingerprint(page: Page, blockLookup?: BlockLookup): string;
283
+ export declare function computePageFingerprint(page: Page, blockLookup?: BlockLookup, footnotes?: readonly FootnoteRenderItem[]): string;
284
284
  /**
285
285
  * Render multiple pages to a container with virtualization for large documents.
286
286
  *