@stll/folio-core 0.66.1 → 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.
- package/dist/ai-edits/apply.d.ts +13 -1
- package/dist/ai-edits/apply.js +572 -140
- package/dist/ai-edits/batch-claims.d.ts +26 -0
- package/dist/ai-edits/batch-claims.js +32 -5
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/headless.d.ts +6 -0
- package/dist/ai-edits/headless.js +25 -3
- package/dist/ai-edits/newListNumbering.d.ts +4 -1
- package/dist/ai-edits/newListNumbering.js +4 -2
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.js +24 -14
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- package/dist/ai-edits/types.d.ts +1 -1
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +76 -18
- package/dist/controller/canonicalInput.d.ts +0 -1
- package/dist/controller/canonicalInput.js +19 -1
- package/dist/controller/canonicalSession.js +1 -2
- package/dist/controller/hiddenEditorManager.d.ts +6 -0
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +7 -3
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +29 -13
- package/dist/document-operations.d.ts +13 -1
- package/dist/document-operations.js +11 -4
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/listNumberingInstances.d.ts +6 -4
- package/dist/docx/listNumberingInstances.js +12 -11
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- package/dist/docx/numberingIds.d.ts +10 -0
- package/dist/docx/numberingIds.js +5 -1
- package/dist/docx/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/paragraphParser.js +16 -3
- package/dist/docx/paragraphProperties.js +2 -1
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -1
- package/dist/docx/rezip.js +4 -4
- package/dist/docx/serializer/paragraphSerializer.js +86 -66
- package/dist/docx/shapeAlternateContent.js +19 -0
- package/dist/docx/unzip.js +2 -0
- package/dist/i18n/messages/ar.gen.js +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
- package/dist/i18n/messages/catalogs.gen.js +34 -0
- package/dist/i18n/messages/cs.gen.js +2 -0
- package/dist/i18n/messages/de.gen.js +2 -0
- package/dist/i18n/messages/en.gen.js +2 -0
- package/dist/i18n/messages/es.gen.js +2 -0
- package/dist/i18n/messages/et.gen.js +2 -0
- package/dist/i18n/messages/fr.gen.js +2 -0
- package/dist/i18n/messages/he.gen.js +2 -0
- package/dist/i18n/messages/hi.gen.js +2 -0
- package/dist/i18n/messages/hu.gen.js +2 -0
- package/dist/i18n/messages/lt.gen.js +2 -0
- package/dist/i18n/messages/lv.gen.js +2 -0
- package/dist/i18n/messages/messages.gen.d.ts +2 -0
- package/dist/i18n/messages/pl.gen.js +2 -0
- package/dist/i18n/messages/pt-BR.gen.js +2 -0
- package/dist/i18n/messages/sk.gen.js +2 -0
- package/dist/i18n/messages/tr.gen.js +2 -0
- package/dist/i18n/messages/zh-CN.gen.js +2 -0
- package/dist/internal/wholeStoryRevisionResolution.d.ts +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +81 -21
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/runMarkFormatting.js +1 -0
- package/dist/layout-bridge/convert/tableConversion.js +6 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +7 -4
- package/dist/layout-engine/tableRowBreak.d.ts +10 -0
- package/dist/layout-engine/tableRowBreak.js +151 -36
- package/dist/layout-engine/types.d.ts +7 -2
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +1 -0
- package/dist/layout-painter/renderPage.js +6 -3
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +33 -19
- package/dist/markdown/renderRuns.js +68 -12
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/commands/comments.js +22 -7
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- package/dist/prosemirror/commands/resolveParagraphProperties.js +15 -2
- package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
- package/dist/prosemirror/conversion/fromProseDoc.js +94 -22
- package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +23 -1
- package/dist/prosemirror/conversion/hyphenTextCarriers.js +46 -1
- package/dist/prosemirror/conversion/toProseDoc.js +21 -13
- package/dist/prosemirror/extensions/StarterKit.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/features/pasteCleanup.js +6 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -1
- package/dist/prosemirror/extensions/markRegistry.d.ts +3 -1
- package/dist/prosemirror/extensions/markRegistry.js +3 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/HyphenElementExtension.js +54 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/fieldRepresentation.js +2 -1
- package/dist/prosemirror/hyphenElementAttrs.d.ts +10 -0
- package/dist/prosemirror/hyphenElementAttrs.js +32 -0
- package/dist/prosemirror/keptRangeBoundaries.d.ts +2 -0
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.js +3 -2
- package/dist/prosemirror/paragraphIndentation.js +2 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -14
- package/dist/prosemirror/paragraphPropertyCarry.js +4 -28
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +194 -27
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -0
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -0
- package/dist/prosemirror/sectionCarrier.d.ts +8 -0
- package/dist/prosemirror/sectionCarrier.js +29 -1
- package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +10 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +12 -2
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/tableRunIn.d.ts +24 -9
- package/dist/prosemirror/tableRunIn.js +107 -21
- package/dist/prosemirror/textInput.js +3 -1
- package/dist/prosemirror/validation.js +7 -1
- package/dist/utils/createDocument.js +11 -8
- package/dist/utils/formatToStyle.js +2 -2
- package/dist/utils/units.d.ts +5 -0
- package/dist/utils/units.js +6 -1
- package/package.json +3 -3
|
@@ -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.
|
|
21
|
-
*
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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 (
|
|
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 = (
|
|
145
|
-
const skips =
|
|
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
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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 };
|
|
@@ -585,6 +585,11 @@ export type ParagraphAttrs = {
|
|
|
585
585
|
export type ParagraphBlock = {
|
|
586
586
|
kind: "paragraph";
|
|
587
587
|
id: BlockId;
|
|
588
|
+
/**
|
|
589
|
+
* Set on a block that exists only in layout: its text is in no ProseMirror
|
|
590
|
+
* node, so a click anywhere in it resolves to this position.
|
|
591
|
+
*/
|
|
592
|
+
fixedPosition?: number;
|
|
588
593
|
/** Stable Word `w14:paraId` / PM `paraId`, when available. */
|
|
589
594
|
paraId?: string;
|
|
590
595
|
runs: Run[];
|
|
@@ -749,8 +754,8 @@ export type ImageBlock = {
|
|
|
749
754
|
src: string;
|
|
750
755
|
/**
|
|
751
756
|
* Set instead of `src` for a drawing with no image data: the display list
|
|
752
|
-
*
|
|
753
|
-
* neither paints nothing
|
|
757
|
+
* draws it as primitives and the legacy painter as an SVG source. `src` is
|
|
758
|
+
* then empty, and a block with neither paints nothing.
|
|
754
759
|
*/
|
|
755
760
|
preview?: PreviewDescriptor;
|
|
756
761
|
width: number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
/** `preview` as an `<img>` source that fills whatever box the image has. */
|
|
3
|
+
export declare const previewToSvgDataUrl: (preview: document_d_exports.PreviewDescriptor) => string;
|
|
4
|
+
/** The source an image paints from: its bytes, or its drawn preview. */
|
|
5
|
+
export declare const paintedImageSource: (image: {
|
|
6
|
+
readonly src: string;
|
|
7
|
+
readonly preview?: document_d_exports.PreviewDescriptor;
|
|
8
|
+
}) => string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { paintPreview } from "../display-list/build/previewPrimitives.js";
|
|
2
|
+
import { svgPreviewDataUrl } from "../docx/previewBudget.js";
|
|
3
|
+
import { panic } from "better-result";
|
|
4
|
+
// src/layout-painter/previewSvg.ts
|
|
5
|
+
/**
|
|
6
|
+
* What the DOM painter shows for a drawing with no image data.
|
|
7
|
+
*
|
|
8
|
+
* Its marks come from the display list's own `paintPreview`, so the two painters
|
|
9
|
+
* cannot draw a preview differently. An SVG in an `<img>` runs no script and
|
|
10
|
+
* fetches nothing, and every value written here is a number.
|
|
11
|
+
*/
|
|
12
|
+
const cssColor = ({ r, g, b, a }) => `rgba(${String(r)},${String(g)},${String(b)},${String(a)})`;
|
|
13
|
+
const svgPoints = (points) => points.map(({ xPx, yPx }) => `${String(xPx)},${String(yPx)}`).join(" ");
|
|
14
|
+
const svgMark = (primitive) => {
|
|
15
|
+
switch (primitive.kind) {
|
|
16
|
+
case "rect": {
|
|
17
|
+
const { xPx, yPx, widthPx, heightPx } = primitive.rect;
|
|
18
|
+
const fill = primitive.fill ? cssColor(primitive.fill) : "none";
|
|
19
|
+
return `<rect x="${String(xPx)}" y="${String(yPx)}" width="${String(widthPx)}" height="${String(heightPx)}" fill="${fill}"/>`;
|
|
20
|
+
}
|
|
21
|
+
case "polygon": return `<polygon points="${svgPoints(primitive.points)}" fill="${cssColor(primitive.fill)}"/>`;
|
|
22
|
+
case "polyline": return `<polyline points="${svgPoints(primitive.points)}" fill="none" stroke="${cssColor(primitive.stroke.color)}" stroke-width="${String(primitive.stroke.thicknessPx)}"/>`;
|
|
23
|
+
default: return panic(`a preview does not draw ${primitive.kind}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const dataUrls = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
/** `preview` as an `<img>` source that fills whatever box the image has. */
|
|
28
|
+
const previewToSvgDataUrl = (preview) => {
|
|
29
|
+
const known = dataUrls.get(preview);
|
|
30
|
+
if (known !== void 0) return known;
|
|
31
|
+
const hasArea = preview.extent.width > 0 && preview.extent.height > 0;
|
|
32
|
+
const widthPx = hasArea ? preview.extent.width : 1;
|
|
33
|
+
const heightPx = hasArea ? preview.extent.height : 1;
|
|
34
|
+
const marks = paintPreview(preview, {
|
|
35
|
+
xPx: 0,
|
|
36
|
+
yPx: 0,
|
|
37
|
+
widthPx,
|
|
38
|
+
heightPx
|
|
39
|
+
});
|
|
40
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${String(widthPx)} ${String(heightPx)}" width="${String(widthPx)}" height="${String(heightPx)}" preserveAspectRatio="none">${marks.map(svgMark).join("")}</svg>`;
|
|
41
|
+
const url = svgPreviewDataUrl(svg);
|
|
42
|
+
dataUrls.set(preview, url);
|
|
43
|
+
return url;
|
|
44
|
+
};
|
|
45
|
+
/** The source an image paints from: its bytes, or its drawn preview. */
|
|
46
|
+
const paintedImageSource = (image) => image.preview ? previewToSvgDataUrl(image.preview) : image.src;
|
|
47
|
+
export { paintedImageSource, previewToSvgDataUrl };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { imageLuminanceFilter } from "../utils/imageLuminance.js";
|
|
2
2
|
import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
|
|
3
3
|
import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js";
|
|
4
|
+
import { paintedImageSource } from "./previewSvg.js";
|
|
4
5
|
// src/layout-painter/renderImage.ts
|
|
5
6
|
/**
|
|
6
7
|
* CSS class names for image elements
|
|
@@ -139,7 +140,7 @@ function renderImageFragment(fragment, block, _measure, _context, options = {})
|
|
|
139
140
|
if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
|
|
140
141
|
if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
|
|
141
142
|
const imgEl = doc.createElement("img");
|
|
142
|
-
applySanitizedImageSrc(imgEl, block
|
|
143
|
+
applySanitizedImageSrc(imgEl, paintedImageSource(block));
|
|
143
144
|
imgEl.alt = block.alt ?? "";
|
|
144
145
|
imgEl.style.width = "100%";
|
|
145
146
|
imgEl.style.height = "100%";
|
|
@@ -17,6 +17,7 @@ import { pageHorizontalColumns, paragraphInlinePictureViewport } from "../utils/
|
|
|
17
17
|
import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
|
|
18
18
|
import { eighthsToPixels, pointsToPixels } from "../utils/units.js";
|
|
19
19
|
import { resolveAnchoredImagePosition as resolveAnchoredImagePosition$1 } from "./anchoredImagePosition.js";
|
|
20
|
+
import { paintedImageSource } from "./previewSvg.js";
|
|
20
21
|
import { renderFragment } from "./renderFragment.js";
|
|
21
22
|
import { applyImageVisualAttrs, hasImageVisualAttrs, renderImageFragment } from "./renderImage.js";
|
|
22
23
|
import { renderParagraphFragment } from "./renderParagraph.js";
|
|
@@ -388,6 +389,7 @@ function extractFloatingImagesFromParagraph(block, fragmentY, geometry) {
|
|
|
388
389
|
else if (imgRun.cssFloat === "right") wrapText = "left";
|
|
389
390
|
floatingImages.push({
|
|
390
391
|
src: imgRun.src,
|
|
392
|
+
...imgRun.preview ? { preview: imgRun.preview } : {},
|
|
391
393
|
width: imgRun.width,
|
|
392
394
|
height: imgRun.height,
|
|
393
395
|
...imgRun.alt !== void 0 ? { alt: imgRun.alt } : {},
|
|
@@ -439,7 +441,7 @@ function renderFloatingImagesLayer(floatingImages, doc, layerMode = "front") {
|
|
|
439
441
|
if (floatImg.pmStart !== void 0) container.dataset["pmStart"] = String(floatImg.pmStart);
|
|
440
442
|
if (floatImg.pmEnd !== void 0) container.dataset["pmEnd"] = String(floatImg.pmEnd);
|
|
441
443
|
const img = doc.createElement("img");
|
|
442
|
-
applySanitizedImageSrc(img, floatImg
|
|
444
|
+
applySanitizedImageSrc(img, paintedImageSource(floatImg));
|
|
443
445
|
img.style.width = `${floatImg.width}px`;
|
|
444
446
|
img.style.height = `${floatImg.height}px`;
|
|
445
447
|
img.style.display = "block";
|
|
@@ -480,6 +482,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
|
|
|
480
482
|
const inlineRuns = [];
|
|
481
483
|
for (const run of paragraphBlock.runs) if (run.kind === "image" && (isFloatingImageRun(run) || run.position)) floatingImages.push({
|
|
482
484
|
src: run.src,
|
|
485
|
+
...run.preview ? { preview: run.preview } : {},
|
|
483
486
|
width: run.width,
|
|
484
487
|
height: run.height,
|
|
485
488
|
...run.alt !== void 0 ? { alt: run.alt } : {},
|
|
@@ -584,7 +587,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
|
|
|
584
587
|
}
|
|
585
588
|
for (const floatImg of floatingImages) {
|
|
586
589
|
const img = doc.createElement("img");
|
|
587
|
-
applySanitizedImageSrc(img, floatImg
|
|
590
|
+
applySanitizedImageSrc(img, paintedImageSource(floatImg));
|
|
588
591
|
img.width = floatImg.width;
|
|
589
592
|
img.height = floatImg.height;
|
|
590
593
|
if (floatImg.alt) img.alt = floatImg.alt;
|
|
@@ -1411,7 +1414,7 @@ function collectContentFingerprint(block, parts) {
|
|
|
1411
1414
|
function runContentKey(run) {
|
|
1412
1415
|
if (run.kind === "lineBreak") return "lb";
|
|
1413
1416
|
if (run.kind === "renderedPageBreak") return "rpb";
|
|
1414
|
-
if (run.kind === "image") return `img:${run
|
|
1417
|
+
if (run.kind === "image") return `img:${paintedImageSource(run)}|${run.width}x${run.height}${run.transform ? `|tr:${run.transform}` : ""}`;
|
|
1415
1418
|
const parts = [run.kind];
|
|
1416
1419
|
if (run.kind === "text") {
|
|
1417
1420
|
parts.push(`t:${run.text}`);
|
|
@@ -27,6 +27,7 @@ import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js"
|
|
|
27
27
|
import { borderStrokeToCss, resolveParagraphBorderHorizontalOutsets } from "./borderStroke.js";
|
|
28
28
|
import { planCursiveJoiners, withCursiveJoiners } from "./cursiveJoiners.js";
|
|
29
29
|
import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
|
|
30
|
+
import { paintedImageSource } from "./previewSvg.js";
|
|
30
31
|
import { applyImageBorder, applyImageColorAttrs, applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs, wrapImageWithCrop } from "./renderImage.js";
|
|
31
32
|
import { applySdtDataAttrs } from "./sdtBoundary.js";
|
|
32
33
|
import { panic } from "better-result";
|
|
@@ -560,7 +561,7 @@ function getLeaderChar(leader) {
|
|
|
560
561
|
function renderInlineImageRun({ run, doc, sizing }) {
|
|
561
562
|
const img = doc.createElement("img");
|
|
562
563
|
img.className = `${PARAGRAPH_CLASS_NAMES.run} ${PARAGRAPH_CLASS_NAMES.image}`;
|
|
563
|
-
applyImageRunSource(img, run
|
|
564
|
+
applyImageRunSource(img, paintedImageSource(run));
|
|
564
565
|
img.width = run.width;
|
|
565
566
|
img.height = run.height;
|
|
566
567
|
img.style.width = `${run.width}px`;
|
|
@@ -629,7 +630,7 @@ function renderBlockImage(run, doc) {
|
|
|
629
630
|
container.style.marginTop = `${run.distTop ?? 6}px`;
|
|
630
631
|
container.style.marginBottom = `${run.distBottom ?? 6}px`;
|
|
631
632
|
const img = doc.createElement("img");
|
|
632
|
-
applyImageRunSource(img, run
|
|
633
|
+
applyImageRunSource(img, paintedImageSource(run));
|
|
633
634
|
img.width = run.width;
|
|
634
635
|
img.height = run.height;
|
|
635
636
|
if (run.alt) img.alt = run.alt;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TableBlock, TableFragment, TableMeasure } from "../layout-engine/types.js";
|
|
2
2
|
import { PageGeometry } from "./anchoredImagePosition.js";
|
|
3
3
|
import { RenderContext } from "./renderUtils.js";
|
|
4
|
+
import { VisibleBand } from "../layout-engine/measure/tableVisibleBand.js";
|
|
4
5
|
import { TextDirection } from "@stll/docx-core/model";
|
|
5
6
|
/**
|
|
6
7
|
* CSS class names for table elements
|
|
@@ -25,9 +26,11 @@ export type RenderTableFragmentOptions = {
|
|
|
25
26
|
pageGeometry?: PageGeometry;
|
|
26
27
|
};
|
|
27
28
|
/**
|
|
28
|
-
* Render a nested table (within a cell)
|
|
29
|
+
* Render a nested table (within a cell). A `visibleBand` builds only the rows
|
|
30
|
+
* that band shows; the table keeps its full height, so the rest of the cell
|
|
31
|
+
* flows the same.
|
|
29
32
|
*/
|
|
30
|
-
export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number): HTMLElement;
|
|
33
|
+
export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number, visibleBand?: VisibleBand): HTMLElement;
|
|
31
34
|
/**
|
|
32
35
|
* Render a table fragment to DOM
|
|
33
36
|
*
|
|
@@ -4,13 +4,15 @@ import { createTableCellFlowState, finishTableCellFlow, placeTableCellBlock } fr
|
|
|
4
4
|
import { buildTableCellGrid, buildTableCellPlacements, getSourceCellAt, getTableCellSpacingInsetsY } from "../layout-engine/measure/tableCellGrid.js";
|
|
5
5
|
import { tableFragmentBottomBorders } from "../layout-engine/measure/tableFragmentBorderGeometry.js";
|
|
6
6
|
import { resolveTableInlineOffset, resolveTableInlinePlacement } from "../layout-engine/measure/tableInlinePlacement.js";
|
|
7
|
-
import {
|
|
7
|
+
import { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../layout-engine/measure/tableVisibleBand.js";
|
|
8
|
+
import { isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
|
|
8
9
|
import { paintsCssBorder } from "../utils/borderCss.js";
|
|
9
10
|
import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
|
|
10
11
|
import { emuToPixels } from "../utils/units.js";
|
|
11
12
|
import { resolveAnchoredImagePosition } from "./anchoredImagePosition.js";
|
|
12
13
|
import { borderStrokeToCss, resolveCssBorderStroke } from "./borderStroke.js";
|
|
13
14
|
import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
|
|
15
|
+
import { paintedImageSource } from "./previewSvg.js";
|
|
14
16
|
import { applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs } from "./renderImage.js";
|
|
15
17
|
import { renderParagraphFragment } from "./renderParagraph.js";
|
|
16
18
|
import { renderTextBoxFragment } from "./renderTextBox.js";
|
|
@@ -63,7 +65,7 @@ const CELL_TEXT_ROTATION_DEGREES = {
|
|
|
63
65
|
};
|
|
64
66
|
/** The quarter turn a cell's `w:textDirection` puts on its content. */
|
|
65
67
|
const cellTextRotationDegrees = (direction) => direction === void 0 ? 0 : CELL_TEXT_ROTATION_DEGREES[TEXT_DIRECTION_FLOW_BY_TOKEN[direction]];
|
|
66
|
-
function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition }) {
|
|
68
|
+
function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition, visibleBand }) {
|
|
67
69
|
const contentEl = doc.createElement("div");
|
|
68
70
|
contentEl.className = TABLE_CLASS_NAMES.cellContent;
|
|
69
71
|
contentEl.style.position = "relative";
|
|
@@ -101,7 +103,7 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
|
|
|
101
103
|
if (img.pmStart !== void 0) imgContainer.dataset["pmStart"] = String(img.pmStart);
|
|
102
104
|
if (img.pmEnd !== void 0) imgContainer.dataset["pmEnd"] = String(img.pmEnd);
|
|
103
105
|
const imgEl = doc.createElement("img");
|
|
104
|
-
applySanitizedImageSrc(imgEl, img
|
|
106
|
+
applySanitizedImageSrc(imgEl, paintedImageSource(img));
|
|
105
107
|
imgEl.style.width = `${img.width}px`;
|
|
106
108
|
imgEl.style.height = `${img.height}px`;
|
|
107
109
|
imgEl.style.display = "block";
|
|
@@ -184,9 +186,16 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
|
|
|
184
186
|
} else if (block?.kind === "table" && measure?.kind === "table") {
|
|
185
187
|
const tableBlock = block;
|
|
186
188
|
const tableMeasure = measure;
|
|
187
|
-
const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth);
|
|
188
|
-
nestedTableEl.style.position = "relative";
|
|
189
189
|
const placement = placeTableCellBlock(flowState, tableBlock, tableMeasure);
|
|
190
|
+
if (isOutsideBand(visibleBand, placement.top, placement.contentTop + placement.contentHeight)) {
|
|
191
|
+
const unbuilt = doc.createElement("div");
|
|
192
|
+
unbuilt.style.height = `${placement.leadingSpacing + placement.contentHeight}px`;
|
|
193
|
+
contentEl.append(unbuilt);
|
|
194
|
+
anchorParagraphY = flowState.height;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth, visibleBand && bandFromOrigin(visibleBand, placement.contentTop));
|
|
198
|
+
nestedTableEl.style.position = "relative";
|
|
190
199
|
if (placement.leadingSpacing > 0) {
|
|
191
200
|
const spacer = doc.createElement("div");
|
|
192
201
|
spacer.style.height = `${placement.leadingSpacing}px`;
|
|
@@ -264,18 +273,12 @@ function resolveCellTextBoxY(block) {
|
|
|
264
273
|
if (vertical?.posOffset !== void 0) return emuToPixels(vertical.posOffset);
|
|
265
274
|
return 0;
|
|
266
275
|
}
|
|
267
|
-
function tableHasFloatingCellContent(block) {
|
|
268
|
-
for (const row of block.rows) for (const cell of row.cells) for (const cellBlock of cell.blocks) {
|
|
269
|
-
if (cellBlock.kind === "textBox" && isFloatingTextBoxBlock(cellBlock)) return true;
|
|
270
|
-
if (cellBlock.kind === "paragraph" && cellBlock.runs.some((run) => run.kind === "image" && isFloatingImageRun(run))) return true;
|
|
271
|
-
if (cellBlock.kind === "table" && tableHasFloatingCellContent(cellBlock)) return true;
|
|
272
|
-
}
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
276
|
/**
|
|
276
|
-
* Render a nested table (within a cell)
|
|
277
|
+
* Render a nested table (within a cell). A `visibleBand` builds only the rows
|
|
278
|
+
* that band shows; the table keeps its full height, so the rest of the cell
|
|
279
|
+
* flows the same.
|
|
277
280
|
*/
|
|
278
|
-
function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth) {
|
|
281
|
+
function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth, visibleBand) {
|
|
279
282
|
const tableEl = doc.createElement("div");
|
|
280
283
|
tableEl.className = `${TABLE_CLASS_NAMES.table} layout-nested-table`;
|
|
281
284
|
tableEl.style.position = "relative";
|
|
@@ -313,11 +316,12 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
|
|
|
313
316
|
cellSpacing: block.cellSpacing
|
|
314
317
|
});
|
|
315
318
|
let y = 0;
|
|
319
|
+
let paintedRow = false;
|
|
316
320
|
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
|
|
317
321
|
const row = block.rows[rowIndex];
|
|
318
322
|
const rowMeasure = measure.rows[rowIndex];
|
|
319
323
|
if (!row || !rowMeasure) continue;
|
|
320
|
-
if (row.hidden) {
|
|
324
|
+
if (row.hidden || isOutsideBand(visibleBand, y, tableRowPaintBottom(row, rowIndex, rowYPositions))) {
|
|
321
325
|
y += rowMeasure.height;
|
|
322
326
|
continue;
|
|
323
327
|
}
|
|
@@ -331,11 +335,13 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
|
|
|
331
335
|
context,
|
|
332
336
|
doc,
|
|
333
337
|
rowYPositions,
|
|
338
|
+
isFirstRowInFragment: visibleBand !== void 0 && !paintedRow && y >= visibleBand.top,
|
|
334
339
|
bidi: block.bidi === true,
|
|
335
340
|
columnsPinned,
|
|
336
341
|
cellGrid,
|
|
337
342
|
cellPlacements,
|
|
338
343
|
cellSpacing: block.cellSpacing,
|
|
344
|
+
...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, y) } : {},
|
|
339
345
|
inlineOffset: resolveTableInlineOffset({
|
|
340
346
|
table: block,
|
|
341
347
|
rowJustification: row.justification,
|
|
@@ -344,6 +350,7 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
|
|
|
344
350
|
}) - tableInlineOffset
|
|
345
351
|
});
|
|
346
352
|
tableEl.append(rowEl);
|
|
353
|
+
paintedRow = true;
|
|
347
354
|
y += rowMeasure.height;
|
|
348
355
|
}
|
|
349
356
|
tableEl.style.height = `${y}px`;
|
|
@@ -391,7 +398,7 @@ function renderCellDiagonalBorder({ border, direction, cellWidth, cellHeight, do
|
|
|
391
398
|
}
|
|
392
399
|
return line;
|
|
393
400
|
}
|
|
394
|
-
function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, pageContentPosition }) {
|
|
401
|
+
function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, visibleBand, pageContentPosition }) {
|
|
395
402
|
const cellEl = doc.createElement("div");
|
|
396
403
|
cellEl.className = TABLE_CLASS_NAMES.cell;
|
|
397
404
|
cellEl.style.position = "absolute";
|
|
@@ -430,11 +437,15 @@ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, border
|
|
|
430
437
|
}
|
|
431
438
|
const cellTextRotation = cellTextRotationDegrees(cell.textDirection);
|
|
432
439
|
const contentWidthOverride = cellTextRotation === 0 ? void 0 : Math.max(1, rowHeight - padTop - padBottom);
|
|
440
|
+
const contentMovesInCell = contentClip === void 0 && (cell.verticalAlign === "center" || cell.verticalAlign === "bottom");
|
|
441
|
+
const topBorderHeight = borderFlags.drawTop && hasVisibleBorder(cell.borders?.top) ? cell.borders?.top?.width ?? 0 : 0;
|
|
442
|
+
const contentBand = visibleBand && cellTextRotation === 0 && !contentMovesInCell ? bandFromOrigin(visibleBand, padTop + topBorderHeight) : void 0;
|
|
433
443
|
const renderedContent = renderCellContent({
|
|
434
444
|
cell,
|
|
435
445
|
cellMeasure,
|
|
436
446
|
context,
|
|
437
447
|
doc,
|
|
448
|
+
...contentBand ? { visibleBand: contentBand } : {},
|
|
438
449
|
...contentWidthOverride !== void 0 ? { contentWidthOverride } : {},
|
|
439
450
|
...pageContentPosition ? { pageContentPosition: {
|
|
440
451
|
geometry: pageContentPosition.geometry,
|
|
@@ -512,7 +523,7 @@ const continuationRowBottomBorderOffsets = (fragment, block, measure, cellGrid)
|
|
|
512
523
|
snapAfterRow
|
|
513
524
|
});
|
|
514
525
|
};
|
|
515
|
-
function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
|
|
526
|
+
function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, visibleBand, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
|
|
516
527
|
const bordersSeparated = (cellSpacing ?? 0) > 0;
|
|
517
528
|
const rowEl = doc.createElement("div");
|
|
518
529
|
rowEl.className = TABLE_CLASS_NAMES.row;
|
|
@@ -572,6 +583,7 @@ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows,
|
|
|
572
583
|
context,
|
|
573
584
|
doc,
|
|
574
585
|
...boxClip ? { contentClip: boxClip } : {},
|
|
586
|
+
...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, spacing.top) } : {},
|
|
575
587
|
...pageContentPosition ? { pageContentPosition: {
|
|
576
588
|
geometry: pageContentPosition.geometry,
|
|
577
589
|
x: pageContentPosition.x + inlineOffset + cellLeft,
|
|
@@ -621,7 +633,8 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
|
|
|
621
633
|
tableEl.style.position = "absolute";
|
|
622
634
|
tableEl.style.width = `${fragment.width}px`;
|
|
623
635
|
tableEl.style.height = `${fragment.height}px`;
|
|
624
|
-
|
|
636
|
+
const hasFloatingCellContent = tableHasFloatingCellContent(block);
|
|
637
|
+
tableEl.style.overflow = hasFloatingCellContent ? "visible" : "hidden";
|
|
625
638
|
tableEl.dataset["blockId"] = String(fragment.blockId);
|
|
626
639
|
tableEl.dataset["fromRow"] = String(fragment.fromRow);
|
|
627
640
|
tableEl.dataset["toRow"] = String(fragment.toRow);
|
|
@@ -745,6 +758,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
|
|
|
745
758
|
cellSpacing: block.cellSpacing,
|
|
746
759
|
bottomBorderOffset: contentRowBottomBorderOffsets[rowIndex - fragment.fromRow] ?? 0,
|
|
747
760
|
...contentClip ? { contentClip } : {},
|
|
761
|
+
...contentClip && !hasFloatingCellContent ? { visibleBand: contentClip } : {},
|
|
748
762
|
...tablePageContentPosition ? { pageContentPosition: {
|
|
749
763
|
...tablePageContentPosition,
|
|
750
764
|
y: tablePageContentPosition.y + y
|