@stll/folio-core 0.66.2 → 0.67.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 (119) hide show
  1. package/dist/ai-edits/apply.js +45 -10
  2. package/dist/ai-edits/batch-claims.js +5 -3
  3. package/dist/ai-edits/clean-text.js +4 -1
  4. package/dist/ai-edits/read.js +6 -4
  5. package/dist/ai-edits/snapshot.js +24 -14
  6. package/dist/ai-edits/table-cell-mutations.js +3 -2
  7. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  8. package/dist/controller/canonicalComposition.d.ts +1 -1
  9. package/dist/controller/canonicalComposition.js +76 -18
  10. package/dist/controller/canonicalInput.d.ts +0 -1
  11. package/dist/controller/canonicalInput.js +19 -1
  12. package/dist/controller/canonicalSession.js +1 -2
  13. package/dist/controller/hiddenEditorManager.d.ts +6 -0
  14. package/dist/controller/hiddenEditorManager.js +3 -1
  15. package/dist/controller/layoutPipeline.d.ts +2 -0
  16. package/dist/controller/layoutPipeline.js +7 -3
  17. package/dist/controller/layoutSession.d.ts +1 -0
  18. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  19. package/dist/display-list/build/tablePrimitives.js +29 -13
  20. package/dist/docx/chartPreview.d.ts +4 -1
  21. package/dist/docx/chartPreview.js +26 -15
  22. package/dist/docx/mainDocumentPart.d.ts +6 -0
  23. package/dist/docx/mainDocumentPart.js +65 -0
  24. package/dist/docx/packageParts.d.ts +1 -1
  25. package/dist/docx/packageParts.js +10 -4
  26. package/dist/docx/previewBudget.d.ts +6 -0
  27. package/dist/docx/previewBudget.js +7 -1
  28. package/dist/docx/rezip.js +4 -4
  29. package/dist/docx/shapeAlternateContent.js +19 -0
  30. package/dist/docx/unzip.js +2 -0
  31. package/dist/i18n/messages/ar.gen.js +1 -0
  32. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  33. package/dist/i18n/messages/catalogs.gen.js +17 -0
  34. package/dist/i18n/messages/cs.gen.js +1 -0
  35. package/dist/i18n/messages/de.gen.js +1 -0
  36. package/dist/i18n/messages/en.gen.js +1 -0
  37. package/dist/i18n/messages/es.gen.js +1 -0
  38. package/dist/i18n/messages/et.gen.js +1 -0
  39. package/dist/i18n/messages/fr.gen.js +1 -0
  40. package/dist/i18n/messages/he.gen.js +1 -0
  41. package/dist/i18n/messages/hi.gen.js +1 -0
  42. package/dist/i18n/messages/hu.gen.js +1 -0
  43. package/dist/i18n/messages/lt.gen.js +1 -0
  44. package/dist/i18n/messages/lv.gen.js +1 -0
  45. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  46. package/dist/i18n/messages/pl.gen.js +1 -0
  47. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  48. package/dist/i18n/messages/sk.gen.js +1 -0
  49. package/dist/i18n/messages/tr.gen.js +1 -0
  50. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  51. package/dist/internal/wholeStoryRevisionResolution.js +57 -12
  52. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  53. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  54. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  55. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  56. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  57. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  58. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  59. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  60. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  61. package/dist/layout-bridge/convert/tableConversion.js +6 -2
  62. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  63. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  64. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  65. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  66. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  67. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  68. package/dist/layout-engine/tableLayout.js +7 -4
  69. package/dist/layout-engine/tableRowBreak.d.ts +10 -0
  70. package/dist/layout-engine/tableRowBreak.js +151 -36
  71. package/dist/layout-engine/types.d.ts +7 -2
  72. package/dist/layout-painter/previewSvg.d.ts +8 -0
  73. package/dist/layout-painter/previewSvg.js +47 -0
  74. package/dist/layout-painter/renderImage.js +2 -1
  75. package/dist/layout-painter/renderPage.d.ts +1 -0
  76. package/dist/layout-painter/renderPage.js +6 -3
  77. package/dist/layout-painter/renderParagraph.js +3 -2
  78. package/dist/layout-painter/renderTable.d.ts +5 -2
  79. package/dist/layout-painter/renderTable.js +33 -19
  80. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  81. package/dist/prosemirror/commands/comments.js +20 -7
  82. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  83. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  84. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  85. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  86. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  87. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  88. package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
  89. package/dist/prosemirror/conversion/fromProseDoc.js +39 -4
  90. package/dist/prosemirror/conversion/toProseDoc.js +6 -4
  91. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  92. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  93. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  94. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  95. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  96. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  97. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  98. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  99. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  100. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  101. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  102. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  103. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  104. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  105. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  106. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  107. package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
  108. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  109. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  110. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  111. package/dist/prosemirror/plugins/suggestionMode.js +175 -21
  112. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  113. package/dist/prosemirror/rowGridOmissions.js +21 -0
  114. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  115. package/dist/prosemirror/tableGridMutation.js +118 -15
  116. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  117. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  118. package/dist/prosemirror/validation.js +1 -1
  119. package/package.json +2 -2
@@ -0,0 +1,70 @@
1
+ import { isAltChunkMarkup } from "../../docx/altChunk.js";
2
+ import { expectPreservedBlockAttrs } from "../../prosemirror/attrs/index.js";
3
+ import { detectBaseDirection } from "../../utils/baseDirection.js";
4
+ import { ALT_CHUNK_CONTENT } from "./flowConversionShared.js";
5
+ import { convertParagraph } from "./paragraphConversion.js";
6
+ // src/layout-bridge/convert/altChunkPlaceholder.ts
7
+ /** The marker where no editor supplies a localised one. */
8
+ const ALT_CHUNK_DEFAULT_MARKER_TEXT = "Content not displayed";
9
+ /** Tints the block, so it does not read as part of the editable text. */
10
+ const PLACEHOLDER_SHADING = "#F2F2F2";
11
+ const MARKER_COLOR = "#595959";
12
+ /** Past this, further lines of a chunk's text run together in the last block. */
13
+ const MAX_PLACEHOLDER_PARAGRAPHS = 2e3;
14
+ const altChunkNodes = /* @__PURE__ */ new WeakMap();
15
+ const isAltChunkNode = (node) => {
16
+ const known = altChunkNodes.get(node);
17
+ if (known !== void 0) return known;
18
+ const isAltChunk = isAltChunkMarkup(expectPreservedBlockAttrs(node).xml);
19
+ altChunkNodes.set(node, isAltChunk);
20
+ return isAltChunk;
21
+ };
22
+ const placeholderLines = (text) => {
23
+ const lines = text.split(/\r\n|\r|\n/u);
24
+ if (lines.length <= MAX_PLACEHOLDER_PARAGRAPHS) return lines;
25
+ const kept = lines.slice(0, 1999);
26
+ kept.push(lines.slice(1999).join(" "));
27
+ return kept;
28
+ };
29
+ /**
30
+ * The placeholder for a preserved block at `pos`, or nothing when the block is
31
+ * not an altChunk. Only the first paragraph addresses the node.
32
+ */
33
+ const convertAltChunkPlaceholder = (node, pos, options) => {
34
+ if (node.type.name !== "preservedBlock" || !isAltChunkNode(node)) return [];
35
+ const { readerText } = expectPreservedBlockAttrs(node);
36
+ const hasText = options.altChunkContent !== ALT_CHUNK_CONTENT.markerOnly && typeof readerText === "string" && readerText.trim() !== "";
37
+ const isMarker = !hasText;
38
+ const text = hasText ? readerText : options.altChunkMarkerText ?? "Content not displayed";
39
+ const { schema } = node.type;
40
+ const paragraphType = schema.nodes["paragraph"];
41
+ if (!paragraphType) return [];
42
+ const after = pos + node.nodeSize;
43
+ const blocks = [];
44
+ for (const [index, line] of placeholderLines(text).entries()) {
45
+ const block = convertParagraph(paragraphType.create(detectBaseDirection(line) === "rtl" ? { direction: { source: "auto" } } : null, line.length > 0 ? schema.text(line) : null), pos, options);
46
+ delete block.pmStart;
47
+ delete block.pmEnd;
48
+ if (index === 0) {
49
+ block.pmStart = pos;
50
+ block.pmEnd = after;
51
+ }
52
+ block.fixedPosition = after;
53
+ block.attrs = {
54
+ ...block.attrs,
55
+ shading: PLACEHOLDER_SHADING
56
+ };
57
+ for (const run of block.runs) {
58
+ if (run.kind !== "text") continue;
59
+ run.pmStart = after;
60
+ run.pmEnd = after;
61
+ if (isMarker) {
62
+ run.italic = true;
63
+ run.color = MARKER_COLOR;
64
+ }
65
+ }
66
+ blocks.push(block);
67
+ }
68
+ return blocks;
69
+ };
70
+ export { ALT_CHUNK_DEFAULT_MARKER_TEXT, convertAltChunkPlaceholder };
@@ -1,4 +1,5 @@
1
1
  import { expectTableCellAttrs, expectTableRowAttrs } from "../../prosemirror/attrs/index.js";
2
+ import { rowGridOmissions } from "../../prosemirror/rowGridOmissions.js";
2
3
  // src/layout-bridge/convert/fixedTableColumnWidths.ts
3
4
  /** Resolve absolute cell preferences for an unbounded fixed-layout grid (§17.4.53). */
4
5
  const fixedTableColumnWidths = (table, grid) => {
@@ -7,7 +8,7 @@ const fixedTableColumnWidths = (table, grid) => {
7
8
  const row = table.child(rowIndex);
8
9
  const rowAttrs = expectTableRowAttrs(row);
9
10
  if (rowAttrs.trIns || rowAttrs.trDel || rowAttrs.hidden) return grid;
10
- let column = Math.max(0, rowAttrs._originalFormatting?.gridBefore ?? 0);
11
+ let column = rowGridOmissions(row, 0).gridBefore;
11
12
  for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) {
12
13
  const attrs = expectTableCellAttrs(row.child(cellIndex));
13
14
  if (attrs._omittedGridSlot) continue;
@@ -8,7 +8,17 @@ import { Node } from "prosemirror-model";
8
8
  /**
9
9
  * Options for the conversion.
10
10
  */
11
+ /** How much of a `w:altChunk` a story has room to show. */
12
+ export declare const ALT_CHUNK_CONTENT: {
13
+ readonly text: "text";
14
+ readonly markerOnly: "markerOnly";
15
+ };
16
+ export type AltChunkContent = (typeof ALT_CHUNK_CONTENT)[keyof typeof ALT_CHUNK_CONTENT];
11
17
  export type ToFlowBlocksOptions = {
18
+ /** Localised text for a `w:altChunk` that has no text of its own to show. */
19
+ altChunkMarkerText?: string;
20
+ /** Defaults to the chunk's own text. */
21
+ altChunkContent?: AltChunkContent;
12
22
  /** Paint comment anchors and highlights; false leaves authored marks intact. */
13
23
  showCommentHighlights?: boolean;
14
24
  /** Embedded families owned by this editor, never ambient process state. */
@@ -1,5 +1,15 @@
1
1
  // src/layout-bridge/convert/flowConversionShared.ts
2
2
  /**
3
+ * Options for the conversion.
4
+ */
5
+ /** How much of a `w:altChunk` a story has room to show. */
6
+ const ALT_CHUNK_CONTENT = {
7
+ /** Its own text when it has any, otherwise the marker. */
8
+ text: "text",
9
+ /** Only the marker: the story's height cannot follow the chunk's length. */
10
+ markerOnly: "markerOnly"
11
+ };
12
+ /**
3
13
  * Convert twips to pixels (1 twip = 1/1440 inch, 1 inch = 96 CSS px).
4
14
  * No rounding — precision prevents cumulative layout drift across paragraphs.
5
15
  */
@@ -19,4 +29,4 @@ function nextBlockId() {
19
29
  function resetBlockIdCounter() {
20
30
  blockIdCounter = 0;
21
31
  }
22
- export { nextBlockId, resetBlockIdCounter, twipsToPixels };
32
+ export { ALT_CHUNK_CONTENT, nextBlockId, resetBlockIdCounter, twipsToPixels };
@@ -7,6 +7,7 @@ export type MeasureBlocksFn = (blocks: FlowBlock[], contentWidth: number) => Mea
7
7
  export type ConvertFootnoteOptions = Pick<ToFlowBlocksOptions, "embeddedFontFamilyMap" | "documentFontFacts"> & {
8
8
  /** Whether comment highlights are painted. Defaults to true. */
9
9
  showCommentHighlights?: boolean;
10
+ altChunkMarkerText?: string;
10
11
  markupView?: DisplayMode;
11
12
  styles?: document_d_exports.StyleDefinitions | null;
12
13
  numbering?: document_d_exports.NumberingDefinitions;
@@ -213,7 +213,10 @@ function convertNoteStoryToFlowBlocks(content, options, referenceMarkText) {
213
213
  if (options.theme !== void 0) proseOptions.theme = options.theme;
214
214
  if (options.numbering !== void 0) proseOptions.numbering = options.numbering;
215
215
  const pmDoc = footnoteToProseDoc(content, proseOptions);
216
- const flowOptions = { showCommentHighlights: options.showCommentHighlights !== false && options.markupView !== "no-markup" && options.markupView !== "original" };
216
+ const flowOptions = {
217
+ showCommentHighlights: options.showCommentHighlights !== false && options.markupView !== "no-markup" && options.markupView !== "original",
218
+ ...options.altChunkMarkerText === void 0 ? {} : { altChunkMarkerText: options.altChunkMarkerText }
219
+ };
217
220
  if (options.defaultSize !== void 0) flowOptions.defaultSize = options.defaultSize;
218
221
  if (options.styles) flowOptions.styles = options.styles;
219
222
  if (options.theme !== void 0) flowOptions.theme = options.theme;
@@ -44,6 +44,7 @@ export type ConvertHeaderFooterOptions = {
44
44
  markupView?: DisplayMode;
45
45
  /** Whether comment highlights are painted. Defaults to true. */
46
46
  showCommentHighlights?: boolean;
47
+ altChunkMarkerText?: string;
47
48
  styles?: document_d_exports.StyleDefinitions | null;
48
49
  numbering?: document_d_exports.NumberingDefinitions;
49
50
  theme?: document_d_exports.Theme | null;
@@ -3,6 +3,7 @@ import { isFloatingImageRun, isFloatingTextBoxBlock, isTextWrappingFloatingImage
3
3
  import { headerFooterToProseDoc } from "../../prosemirror/conversion/toProseDoc.js";
4
4
  import { projectStoryMarkupView } from "../../prosemirror/markupViewProjection.js";
5
5
  import { emuToPixels } from "../../utils/units.js";
6
+ import { ALT_CHUNK_CONTENT } from "./flowConversionShared.js";
6
7
  import { remapMarkupViewBlocks } from "./markupViewFlow.js";
7
8
  import { toFlowBlocks } from "./toFlowBlocks.js";
8
9
  // src/layout-bridge/convert/headerFooterLayout.ts
@@ -359,7 +360,11 @@ function convertHeaderFooterToContent(headerFooter, contentWidth, metrics, optio
359
360
  */
360
361
  function convertHeaderFooterPmDocToContent(pmDoc, contentWidth, metrics, options) {
361
362
  if (!pmDoc || pmDoc.content.size === 0) return;
362
- const flowOptions = { showCommentHighlights: options.showCommentHighlights !== false && options.markupView !== "no-markup" && options.markupView !== "original" };
363
+ const flowOptions = {
364
+ altChunkContent: ALT_CHUNK_CONTENT.markerOnly,
365
+ showCommentHighlights: options.showCommentHighlights !== false && options.markupView !== "no-markup" && options.markupView !== "original",
366
+ ...options.altChunkMarkerText === void 0 ? {} : { altChunkMarkerText: options.altChunkMarkerText }
367
+ };
363
368
  if (options.defaultSize !== void 0) flowOptions.defaultSize = options.defaultSize;
364
369
  if (options.styles) flowOptions.styles = options.styles;
365
370
  if (options.theme !== void 0) flowOptions.theme = options.theme;
@@ -1,8 +1,10 @@
1
1
  import { setTextBoxGroupId } from "../../layout-engine/textBoxGroup.js";
2
2
  import { DEFAULT_TEXTBOX_MARGINS } from "../../layout-engine/types.js";
3
3
  import { expectParagraphAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs } from "../../prosemirror/attrs/index.js";
4
+ import { rowGridOmissions } from "../../prosemirror/rowGridOmissions.js";
4
5
  import { textBoxHostParagraph } from "../../prosemirror/textBoxHostParagraph.js";
5
6
  import { normalizeShapeTextAnchor } from "../../types/documentEnumValues.js";
7
+ import { convertAltChunkPlaceholder } from "./altChunkPlaceholder.js";
6
8
  import { fixedTableColumnWidths } from "./fixedTableColumnWidths.js";
7
9
  import { convertBorderSpecToLayout } from "./flowBorders.js";
8
10
  import { nextBlockId, twipsToPixels } from "./flowConversionShared.js";
@@ -66,6 +68,7 @@ function convertTableCell(node, startPos, options, tableCellMargins) {
66
68
  blocks.push(block);
67
69
  } else if (child.type.name === "table") blocks.push(convertTable(child, childStart, options));
68
70
  else if (child.type.name === "textBox") blocks.push(convertTextBoxNode(child, childStart, options));
71
+ else if (child.type.name === "preservedBlock") blocks.push(...convertAltChunkPlaceholder(child, childStart, options));
69
72
  else if (child.type.name === "blockSdt" || child.type.name === "blockCustomXml") {
70
73
  let sdtChildStart = childStart + 1;
71
74
  child.forEach((sdtChild) => {
@@ -159,8 +162,9 @@ function convertTableRow(node, startPos, options, { cellMargins }) {
159
162
  id: nextBlockId(),
160
163
  cells
161
164
  };
162
- if (attrs._originalFormatting?.gridBefore) row.gridBefore = attrs._originalFormatting.gridBefore;
163
- if (attrs._originalFormatting?.gridAfter) row.gridAfter = attrs._originalFormatting.gridAfter;
165
+ const { gridBefore, gridAfter } = rowGridOmissions(node, attrs._originalFormatting?.gridAfter ?? 0);
166
+ if (gridBefore > 0) row.gridBefore = gridBefore;
167
+ if (gridAfter > 0) row.gridAfter = gridAfter;
164
168
  if (attrs.height) row.height = twipsToPixels(attrs.height);
165
169
  if (attrs.heightRule) row.heightRule = attrs.heightRule;
166
170
  if (attrs.isHeader) row.isHeader = attrs.isHeader;
@@ -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;
@@ -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
  }
@@ -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 };
@@ -2,7 +2,7 @@ import { projectedFootnoteReserveGrowth } from "./layoutFlowShared.js";
2
2
  import { resolveFloatingTablePageX } from "./measure/floatingTablePosition.js";
3
3
  import { resolveTableInlineOffset } from "./measure/tableInlinePlacement.js";
4
4
  import { isEmptyParagraph } from "./paragraphSpacing.js";
5
- import { buildTableRowBreakInfo, getRowContinuationSkip, snapRowBreak } from "./tableRowBreak.js";
5
+ import { buildTableRowBreakInfo, getRowContinuationSkip, snapOversizedRowBreak, snapRowBreak } from "./tableRowBreak.js";
6
6
  import "./types.js";
7
7
  // src/layout-engine/tableLayout.ts
8
8
  /**
@@ -97,7 +97,7 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
97
97
  const row = rows[rowIndex];
98
98
  const sourceRow = block.rows[rowIndex];
99
99
  if (!row || !sourceRow || sourceRow.heightRule === "exact" || sourceRow.isHeader || verticallyMergedRows.has(rowIndex)) return false;
100
- if ((breakInfo.breakOffsets[rowIndex]?.length ?? 0) <= 1) return false;
100
+ if ((breakInfo.oversizedBreakOffsets[rowIndex]?.length ?? 0) <= 1) 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);
@@ -145,8 +145,11 @@ function layoutTable(block, measure, paginator, footnoteHeightById) {
145
145
  advanceAfterNaturalFlowBreak(previousPageNumber);
146
146
  continue;
147
147
  }
148
- const from = consumed;
149
- slice = (breakInfo.breakOffsets[currentRowIndex]?.find((o) => o > from) ?? splittableRow.height) - consumed;
148
+ slice = snapOversizedRowBreak(breakInfo, currentRowIndex, consumed, sliceAvail);
149
+ if (slice <= 0) {
150
+ const from = consumed;
151
+ slice = (breakInfo.oversizedBreakOffsets[currentRowIndex]?.find((o) => o > from) ?? splittableRow.height) - consumed;
152
+ }
150
153
  }
151
154
  discardPassedRenderedBreakHints();
152
155
  const renderedBreakHint = renderedBreakHints[renderedBreakHintIndex];
@@ -13,6 +13,11 @@ export type TableRowBreakInfo = {
13
13
  * final boundary.
14
14
  */
15
15
  breakOffsets: number[][];
16
+ /**
17
+ * `breakOffsets` plus the line bottoms inside nested rows that stay whole
18
+ * while a flow region can hold them: where to break once none can.
19
+ */
20
+ oversizedBreakOffsets: number[][];
16
21
  /** Safe cached page boundaries within each row, relative to the row top. */
17
22
  renderedBreakHints: RenderedRowBreakHint[][];
18
23
  /** Suppressible leading paragraph whitespace after each matching break offset. */
@@ -35,4 +40,9 @@ export declare function getRowContinuationSkip(info: TableRowBreakInfo, rowIndex
35
40
  * `maxSlice`. Returns 0 when not even the first line fits.
36
41
  */
37
42
  export declare function snapRowBreak(info: TableRowBreakInfo, rowIndex: number, fromOffset: number, maxSlice: number): number;
43
+ /**
44
+ * `snapRowBreak` for a region that starts empty and still cannot hold the next
45
+ * unit: nested rows that stay whole give way so their content stays reachable.
46
+ */
47
+ export declare function snapOversizedRowBreak(info: TableRowBreakInfo, rowIndex: number, fromOffset: number, maxSlice: number): number;
38
48
  export {};
@@ -17,19 +17,60 @@ import { resolveTableCellPadding } from "./types.js";
17
17
  *
18
18
  * This computes, per row, the safe break offsets (the y of every line bottom in
19
19
  * the row's cells) so the paginator can snap a break to the deepest whole line
20
- * that still fits. Vertically-merged cells that span into a row are not modeled
21
- * here yet (a separate follow-up); each row uses its own cells' content.
20
+ * that still fits. A nested table contributes the lines and row bottoms of its
21
+ * own rows, so it continues across regions like the table that holds it.
22
+ * Vertically-merged cells that span into a row of the top-level table are not
23
+ * modeled here yet (a separate follow-up); each row uses its own cells' content.
22
24
  */
23
25
  const BREAK_OFFSET_EPSILON = .01;
24
- function isInsideRange(offset, range) {
25
- return offset > range.top && offset < range.bottom;
26
- }
26
+ /**
27
+ * Sorted, disjoint form of `ranges`. Ranges that only touch stay separate:
28
+ * their shared edge is a clean break.
29
+ */
30
+ const mergeBreakRanges = (ranges) => {
31
+ const merged = [];
32
+ for (const range of ranges.toSorted((a, b) => a.top - b.top)) {
33
+ const previous = merged.at(-1);
34
+ if (previous && range.top < previous.bottom) {
35
+ previous.bottom = Math.max(previous.bottom, range.bottom);
36
+ continue;
37
+ }
38
+ merged.push({ ...range });
39
+ }
40
+ return merged;
41
+ };
42
+ /**
43
+ * Binary search over the output of `mergeBreakRanges`. An offset within rounding
44
+ * of an edge is on that edge: nested positions are sums of more line heights
45
+ * than the sibling line they have to meet.
46
+ */
47
+ const isInsideMergedRanges = (offset, ranges) => {
48
+ let low = 0;
49
+ let high = ranges.length - 1;
50
+ while (low <= high) {
51
+ const middle = low + high >> 1;
52
+ const range = ranges[middle];
53
+ if (!range) return false;
54
+ if (offset <= range.top + BREAK_OFFSET_EPSILON) high = middle - 1;
55
+ else if (offset >= range.bottom - BREAK_OFFSET_EPSILON) low = middle + 1;
56
+ else return true;
57
+ }
58
+ return false;
59
+ };
27
60
  function getVerticalAlignmentOffset(cell, measure, rowHeight) {
28
61
  const spareHeight = Math.max(0, rowHeight - measure.height);
29
62
  if (cell?.verticalAlign === "bottom") return spareHeight;
30
63
  if (cell?.verticalAlign === "center") return spareHeight / 2;
31
64
  return 0;
32
65
  }
66
+ /** A nested table can outgrow the argument count `push(...items)` allows. */
67
+ const appendAll = (target, items) => {
68
+ for (const item of items) target.push(item);
69
+ };
70
+ const shiftRange = (range, offset) => ({
71
+ top: range.top + offset,
72
+ bottom: range.bottom + offset
73
+ });
33
74
  function shiftCellGeometry(geometry, offset) {
34
75
  if (offset <= 0) return geometry;
35
76
  return {
@@ -38,21 +79,75 @@ function shiftCellGeometry(geometry, offset) {
38
79
  offset: hint.offset + offset,
39
80
  lineAdvance: hint.lineAdvance
40
81
  })),
41
- unsafeRanges: geometry.unsafeRanges.map((range) => ({
42
- top: range.top + offset,
43
- bottom: range.bottom + offset
44
- })),
45
- suppressibleLeadingRanges: geometry.suppressibleLeadingRanges.map((range) => ({
46
- top: range.top + offset,
47
- bottom: range.bottom + offset
48
- }))
82
+ unsafeRanges: geometry.unsafeRanges.map((range) => shiftRange(range, offset)),
83
+ keepTogetherRanges: geometry.keepTogetherRanges.map((range) => shiftRange(range, offset)),
84
+ suppressibleLeadingRanges: geometry.suppressibleLeadingRanges.map((range) => shiftRange(range, offset))
49
85
  };
50
86
  }
87
+ /** Each measured cell's geometry in one table row, relative to the row top. */
88
+ function rowCellGeometries(block, measure, rowIndex) {
89
+ const rowHeight = measure.rows[rowIndex]?.height ?? 0;
90
+ const sourceCells = block.rows[rowIndex]?.cells ?? [];
91
+ const measuredCells = measure.rows[rowIndex]?.cells ?? [];
92
+ const geometries = [];
93
+ for (let c = 0; c < measuredCells.length; c++) {
94
+ const measuredCell = measuredCells[c];
95
+ if (!measuredCell) continue;
96
+ const sourceCell = sourceCells[c];
97
+ const spacing = getTableCellSpacingInsetsY(block.cellSpacing, rowIndex, sourceCell?.rowSpan ?? 1, block.rows.length);
98
+ geometries.push(shiftCellGeometry(cellBreakGeometry(sourceCell, measuredCell), spacing.top + getVerticalAlignmentOffset(sourceCell, measuredCell, Math.max(0, rowHeight - spacing.top - spacing.bottom))));
99
+ }
100
+ return geometries;
101
+ }
102
+ /** `w:cantSplit` (§17.4.6) and header rows stay whole while a region can hold them. */
103
+ const nestedRowKeepsTogether = (row) => row?.cantSplit === true || row?.isHeader === true;
104
+ /**
105
+ * Break geometry of a table nested in a cell, relative to its top. The cells of
106
+ * all its rows join one flat geometry: a break must clear every line of every
107
+ * cell, including a merged cell that spans several rows. Whitespace that a
108
+ * continuation may consume is left out, because it would have to be shared with
109
+ * the sibling cells flattening no longer tells apart.
110
+ */
111
+ function nestedTableBreakGeometry(block, measure) {
112
+ const nested = {
113
+ bottoms: [],
114
+ renderedBreakHints: [],
115
+ unsafeRanges: [],
116
+ keepTogetherRanges: [],
117
+ suppressibleLeadingRanges: []
118
+ };
119
+ let rowTop = 0;
120
+ for (let r = 0; r < measure.rows.length; r++) {
121
+ const rowHeight = measure.rows[r]?.height ?? 0;
122
+ const sourceRow = block.rows[r];
123
+ if (sourceRow?.hidden !== true && rowHeight > 0) {
124
+ const rowBand = {
125
+ top: rowTop,
126
+ bottom: rowTop + rowHeight
127
+ };
128
+ nested.bottoms.push(rowBand.bottom);
129
+ if (nestedRowKeepsTogether(sourceRow)) nested.keepTogetherRanges.push(rowBand);
130
+ const fixedBox = sourceRow?.heightRule === "exact";
131
+ if (fixedBox) nested.unsafeRanges.push(rowBand);
132
+ const cells = fixedBox ? [] : rowCellGeometries(block, measure, r);
133
+ for (const cell of cells) {
134
+ const geometry = shiftCellGeometry(cell, rowTop);
135
+ appendAll(nested.bottoms, geometry.bottoms);
136
+ appendAll(nested.renderedBreakHints, geometry.renderedBreakHints);
137
+ appendAll(nested.unsafeRanges, geometry.unsafeRanges);
138
+ appendAll(nested.keepTogetherRanges, geometry.keepTogetherRanges);
139
+ }
140
+ }
141
+ rowTop += rowHeight;
142
+ }
143
+ return nested;
144
+ }
51
145
  /** Cumulative break geometry within a single cell's content. */
52
146
  function cellBreakGeometry(cell, measure) {
53
147
  const bottoms = [];
54
148
  const renderedBreakHints = [];
55
149
  const unsafeRanges = [];
150
+ const keepTogetherRanges = [];
56
151
  const suppressibleLeadingRanges = [];
57
152
  const cellBlocks = cell?.blocks;
58
153
  const blockMeasures = measure.blocks;
@@ -103,11 +198,17 @@ function cellBreakGeometry(cell, measure) {
103
198
  if (blockHeight > 0) {
104
199
  const top = padTop + placement.contentTop;
105
200
  const y = top + blockHeight;
106
- unsafeRanges.push({
201
+ bottoms.push(y);
202
+ if (block.kind === "table" && blockMeasure.kind === "table") {
203
+ const nested = shiftCellGeometry(nestedTableBreakGeometry(block, blockMeasure), top);
204
+ appendAll(bottoms, nested.bottoms);
205
+ appendAll(renderedBreakHints, nested.renderedBreakHints);
206
+ appendAll(unsafeRanges, nested.unsafeRanges);
207
+ appendAll(keepTogetherRanges, nested.keepTogetherRanges);
208
+ } else unsafeRanges.push({
107
209
  top,
108
210
  bottom: y
109
211
  });
110
- bottoms.push(y);
111
212
  }
112
213
  }
113
214
  }
@@ -115,6 +216,7 @@ function cellBreakGeometry(cell, measure) {
115
216
  bottoms,
116
217
  renderedBreakHints,
117
218
  unsafeRanges,
219
+ keepTogetherRanges,
118
220
  suppressibleLeadingRanges
119
221
  };
120
222
  }
@@ -130,8 +232,8 @@ const mergeRenderedBreakHints = (hints) => {
130
232
  }
131
233
  return merged;
132
234
  };
133
- const continuationSkipForCell = (geometry, offset) => {
134
- if (!geometry.unsafeRanges.some(({ bottom }) => bottom > offset + BREAK_OFFSET_EPSILON)) return;
235
+ const continuationSkipForCell = ({ geometry, contentBottom }, offset) => {
236
+ if (contentBottom <= offset + BREAK_OFFSET_EPSILON) return;
135
237
  const leadingRange = geometry.suppressibleLeadingRanges.find(({ top, bottom }) => top <= offset + BREAK_OFFSET_EPSILON && bottom > offset + BREAK_OFFSET_EPSILON);
136
238
  return leadingRange ? leadingRange.bottom - offset : 0;
137
239
  };
@@ -141,8 +243,8 @@ const continuationSkipForCell = (geometry, offset) => {
141
243
  * every cell with remaining content is suppressible; non-empty paragraphs,
142
244
  * line boxes, cell padding, and explicit row height retain authored space.
143
245
  */
144
- const continuationSkipAfter = (geometries, offset) => {
145
- const skips = geometries.map((geometry) => continuationSkipForCell(geometry, offset)).filter((skip) => skip !== void 0);
246
+ const continuationSkipAfter = (cells, offset) => {
247
+ const skips = cells.map((cell) => continuationSkipForCell(cell, offset)).filter((skip) => skip !== void 0);
146
248
  if (skips.length === 0 || skips.some((skip) => skip <= BREAK_OFFSET_EPSILON)) return 0;
147
249
  return Math.min(...skips);
148
250
  };
@@ -178,32 +280,36 @@ function buildTableRowBreakInfo(block, measure) {
178
280
  }
179
281
  rowTops.push(acc);
180
282
  const breakOffsets = [];
283
+ const oversizedBreakOffsets = [];
181
284
  const renderedBreakHints = [];
182
285
  const continuationSkips = [];
183
286
  for (let r = 0; r < rowCount; r++) {
184
287
  const rowHeight = measure.rows[r]?.height ?? 0;
288
+ const cellGeometries = rowCellGeometries(block, measure, r);
185
289
  const offsets = /* @__PURE__ */ new Set();
186
290
  offsets.add(rowHeight);
187
- const sourceCells = block.rows[r]?.cells ?? [];
188
- const measuredCells = measure.rows[r]?.cells ?? [];
189
- const cellGeometries = [];
190
- for (let c = 0; c < measuredCells.length; c++) {
191
- const measuredCell = measuredCells[c];
192
- if (!measuredCell) continue;
193
- const sourceCell = sourceCells[c];
194
- const spacing = getTableCellSpacingInsetsY(block.cellSpacing, r, sourceCell?.rowSpan ?? 1, block.rows.length);
195
- const geometry = shiftCellGeometry(cellBreakGeometry(sourceCell, measuredCell), spacing.top + getVerticalAlignmentOffset(sourceCell, measuredCell, Math.max(0, rowHeight - spacing.top - spacing.bottom)));
196
- cellGeometries.push(geometry);
197
- for (const b of geometry.bottoms) if (b > 0 && b < rowHeight) offsets.add(b);
198
- }
199
- const sortedOffsets = [...offsets].filter((offset) => offset === rowHeight || cellGeometries.every((geometry) => geometry.unsafeRanges.every((range) => !isInsideRange(offset, range)))).sort((a, b) => a - b);
291
+ for (const geometry of cellGeometries) for (const b of geometry.bottoms) if (b > 0 && b < rowHeight) offsets.add(b);
292
+ const unsafeRanges = mergeBreakRanges(cellGeometries.flatMap((geometry) => geometry.unsafeRanges));
293
+ const keepTogetherRanges = mergeBreakRanges(cellGeometries.flatMap((geometry) => geometry.keepTogetherRanges));
294
+ const lineSafeOffsets = [...offsets].filter((offset) => offset === rowHeight || !isInsideMergedRanges(offset, unsafeRanges)).sort((a, b) => a - b);
295
+ const sortedOffsets = lineSafeOffsets.filter((offset) => offset === rowHeight || !isInsideMergedRanges(offset, keepTogetherRanges));
200
296
  breakOffsets.push(sortedOffsets);
201
- renderedBreakHints.push(mergeRenderedBreakHints(cellGeometries.flatMap((geometry) => geometry.renderedBreakHints).filter(({ offset }) => offset > BREAK_OFFSET_EPSILON && offset < rowHeight - BREAK_OFFSET_EPSILON && cellGeometries.every((geometry) => geometry.unsafeRanges.every((range) => !isInsideRange(offset, range))))));
202
- continuationSkips.push(sortedOffsets.map((offset) => continuationSkipAfter(cellGeometries, offset)));
297
+ oversizedBreakOffsets.push(lineSafeOffsets);
298
+ renderedBreakHints.push(mergeRenderedBreakHints(cellGeometries.flatMap((geometry) => geometry.renderedBreakHints).filter(({ offset }) => offset > BREAK_OFFSET_EPSILON && offset < rowHeight - BREAK_OFFSET_EPSILON && !isInsideMergedRanges(offset, unsafeRanges) && !isInsideMergedRanges(offset, keepTogetherRanges))));
299
+ const continuationCells = cellGeometries.map((geometry) => {
300
+ let contentBottom = Number.NEGATIVE_INFINITY;
301
+ for (const range of geometry.unsafeRanges) contentBottom = Math.max(contentBottom, range.bottom);
302
+ return {
303
+ geometry,
304
+ contentBottom
305
+ };
306
+ });
307
+ continuationSkips.push(sortedOffsets.map((offset) => continuationSkipAfter(continuationCells, offset)));
203
308
  }
204
309
  return {
205
310
  rowTops,
206
311
  breakOffsets,
312
+ oversizedBreakOffsets,
207
313
  renderedBreakHints,
208
314
  continuationSkips
209
315
  };
@@ -222,7 +328,16 @@ function getRowContinuationSkip(info, rowIndex, offset) {
222
328
  * `maxSlice`. Returns 0 when not even the first line fits.
223
329
  */
224
330
  function snapRowBreak(info, rowIndex, fromOffset, maxSlice) {
225
- const offsets = info.breakOffsets[rowIndex];
331
+ return snapToOffsets(info.breakOffsets[rowIndex], fromOffset, maxSlice);
332
+ }
333
+ /**
334
+ * `snapRowBreak` for a region that starts empty and still cannot hold the next
335
+ * unit: nested rows that stay whole give way so their content stays reachable.
336
+ */
337
+ function snapOversizedRowBreak(info, rowIndex, fromOffset, maxSlice) {
338
+ return snapToOffsets(info.oversizedBreakOffsets[rowIndex], fromOffset, maxSlice);
339
+ }
340
+ function snapToOffsets(offsets, fromOffset, maxSlice) {
226
341
  if (!offsets || offsets.length === 0) return 0;
227
342
  const limit = fromOffset + maxSlice;
228
343
  let best = 0;
@@ -233,4 +348,4 @@ function snapRowBreak(info, rowIndex, fromOffset, maxSlice) {
233
348
  }
234
349
  return best;
235
350
  }
236
- export { buildTableRowBreakInfo, getRowContinuationSkip, snapRowBreak, tableKeepNextOpeningHeight };
351
+ export { buildTableRowBreakInfo, getRowContinuationSkip, snapOversizedRowBreak, snapRowBreak, tableKeepNextOpeningHeight };