@officedk/pptxdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,739 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { assertValidLang } from "../../../core/dist/theme.js";
|
|
3
|
+
import { parseLinkTarget } from "../../../core/dist/author-schemas.js";
|
|
4
|
+
import { parseCapabilityLayoutContract } from "../../../core/dist/layout.js";
|
|
5
|
+
import "../../../core/dist/capability.js";
|
|
6
|
+
import { assertXml10Characters, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
7
|
+
import "../../../emit/dist/index.js";
|
|
8
|
+
import "../../../import/dist/index.js";
|
|
9
|
+
import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
|
|
10
|
+
import { fontPresentationContributions } from "../font/font-embedding.js";
|
|
11
|
+
import { motionAnnotations, pickMotionProps } from "../motion/motion-api.js";
|
|
12
|
+
import { nativeLinkXml, parseMorphKey, parseOptionalName } from "../shared/identity.js";
|
|
13
|
+
import { resolvePlaceholderGeometry } from "../shared/style-inheritance.js";
|
|
14
|
+
import { emitTextBody, parseTextParagraphs, renderTextOutlinesSvg, resolveTextBody } from "../shared/text-service.js";
|
|
15
|
+
import { gradientDefSvg, paintImageFillSvg, resolveBackgroundValue } from "../shared/visual.js";
|
|
16
|
+
import { tableCodegen } from "./table-codegen.js";
|
|
17
|
+
import { tableImportHandler, tablePlaceholderImportHandler } from "./table-import.js";
|
|
18
|
+
import { assertAllowedTableKeys, assertTableEmuExtent, assertTableTextAlignment, cellAllowedParameters, cellStyleKeys, parseOptionalTableId, parseTableCellPadding, parseTableColumns, parseTableCoordinate, parseTableMergeSpan, parseTablePositiveSize, parseTableVerticalAlign, resolveTableCellBorders, resolveTableLayerBorders, rowAllowedParameters, rowStyleKeys, tableAllowedParameters, tableStyleKeys, tableTextStyleKeys } from "./table-schemas.js";
|
|
19
|
+
import { emptyTableCellXml, tableCellPropertiesXml, tableFrameXml } from "./table-xml.js";
|
|
20
|
+
import "./table-declaration.js";
|
|
21
|
+
// ../capabilities/dist/table/table.js
|
|
22
|
+
const maximumExtentEmu = 2147483647;
|
|
23
|
+
function fail(code, message, path, details) {
|
|
24
|
+
throw new CapabilityError(code, message, path, details);
|
|
25
|
+
}
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function record(value, label, path) {
|
|
30
|
+
if (!isRecord(value)) fail("invalid-parameter", `${label} must be an object`, path);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function pathLabel(value, fallback) {
|
|
34
|
+
return typeof value === "string" && value.trim() !== "" ? value : fallback;
|
|
35
|
+
}
|
|
36
|
+
function textStyle(styleValue, label, path, additional = []) {
|
|
37
|
+
const style = record(styleValue ?? {}, `${label}.style`, path);
|
|
38
|
+
assertAllowedTableKeys(style, [...tableTextStyleKeys, ...additional], `${label}.style`, path);
|
|
39
|
+
if (style["lang"] !== void 0) try {
|
|
40
|
+
assertValidLang(style["lang"]);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof CapabilityError) fail(error.code, error.message, path);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
assertTableTextAlignment(style["align"], path);
|
|
46
|
+
const textStyle = {};
|
|
47
|
+
for (const key of tableTextStyleKeys) {
|
|
48
|
+
const value = style[key];
|
|
49
|
+
if (value !== void 0) textStyle[key] = value;
|
|
50
|
+
}
|
|
51
|
+
parseTableVerticalAlign(style["verticalAlign"], path);
|
|
52
|
+
return {
|
|
53
|
+
textStyle,
|
|
54
|
+
style
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function mergeTextStyle(parent, child) {
|
|
58
|
+
return {
|
|
59
|
+
...parent,
|
|
60
|
+
...child
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function parseLayerBackground(style, label, theme, path) {
|
|
64
|
+
if (!Object.hasOwn(style, "background") || style["background"] === void 0) return { declared: false };
|
|
65
|
+
const raw = style["background"];
|
|
66
|
+
try {
|
|
67
|
+
resolveBackgroundValue(theme, raw, void 0);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof CapabilityError) fail(error.code, `${label}.style.background: ${error.message}`, path);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
declared: true,
|
|
74
|
+
value: raw
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function trackStyle(input, type, path) {
|
|
78
|
+
const additional = type === "table" ? tableStyleKeys : type === "row" ? rowStyleKeys : cellStyleKeys;
|
|
79
|
+
return textStyle(input.props["style"], type === "table" ? "Table" : type === "row" ? "Row" : "Cell", path, additional);
|
|
80
|
+
}
|
|
81
|
+
function resolveCellBody(cell, theme, width, height, contentSized = false) {
|
|
82
|
+
try {
|
|
83
|
+
return resolveTextBody(cell.paragraphs, cell.textStyle, theme, cell.verticalAlign, {
|
|
84
|
+
width,
|
|
85
|
+
...height === void 0 ? {} : { height },
|
|
86
|
+
...contentSized ? { contentSized: true } : {}
|
|
87
|
+
}, "table-cell");
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof CapabilityError) fail(error.code, error.message, cell.path, error.details);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function identityPath(type, props, index) {
|
|
94
|
+
return `${type}[${pathLabel(props["id"], String(index + 1))}]`;
|
|
95
|
+
}
|
|
96
|
+
function prepareRows(input, columns, tableTextStyle, tableVerticalAlign, tableBackgroundRaw, tableBorders, theme, slideNumber) {
|
|
97
|
+
const rows = [];
|
|
98
|
+
const cells = [];
|
|
99
|
+
const owners = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const child of input.children) {
|
|
101
|
+
if (!("props" in child)) {
|
|
102
|
+
if (child.text.trim() !== "") fail("invalid-table-structure", "Text in Table must be placed inside Cell");
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (child.type !== "row") fail("invalid-table-structure", "Table can only contain Row directly");
|
|
106
|
+
const rowIndex = rows.length;
|
|
107
|
+
const rowPath = identityPath("row", child.props, rowIndex);
|
|
108
|
+
assertAllowedTableKeys(child.props, rowAllowedParameters, "Row", rowPath);
|
|
109
|
+
const rowAuthorId = parseOptionalTableId(child.props["id"], rowPath);
|
|
110
|
+
const rowStyle = trackStyle(child, "row", rowPath);
|
|
111
|
+
const heightValue = rowStyle.style["height"];
|
|
112
|
+
const height = heightValue === void 0 ? void 0 : parseTablePositiveSize(heightValue, "Row.style.height", rowPath);
|
|
113
|
+
const rowBgParsed = parseLayerBackground(rowStyle.style, "Row", theme, rowPath);
|
|
114
|
+
const rowBackgroundRaw = rowBgParsed.declared ? rowBgParsed.value : tableBackgroundRaw;
|
|
115
|
+
const rowBorders = resolveTableLayerBorders(rowStyle.style, tableBorders, "Row", theme, rowPath);
|
|
116
|
+
const rowVerticalAlign = parseTableVerticalAlign(rowStyle.style["verticalAlign"], rowPath) ?? tableVerticalAlign;
|
|
117
|
+
const row = {
|
|
118
|
+
path: rowPath,
|
|
119
|
+
...rowAuthorId === void 0 ? {} : { authorId: rowAuthorId },
|
|
120
|
+
...height === void 0 ? {} : { height },
|
|
121
|
+
textStyle: mergeTextStyle(tableTextStyle, rowStyle.textStyle),
|
|
122
|
+
verticalAlign: rowVerticalAlign,
|
|
123
|
+
...rowBackgroundRaw === void 0 ? {} : { backgroundRaw: rowBackgroundRaw },
|
|
124
|
+
borders: rowBorders
|
|
125
|
+
};
|
|
126
|
+
rows.push(row);
|
|
127
|
+
let column = 0;
|
|
128
|
+
let cellIndex = 0;
|
|
129
|
+
for (const cellChild of child.children) {
|
|
130
|
+
if (!("props" in cellChild)) {
|
|
131
|
+
if (cellChild.text.trim() !== "") fail("invalid-table-structure", "Text in Row must be placed inside Cell", rowPath);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (cellChild.type !== "cell") fail("invalid-table-structure", "Row can only contain Cell directly", rowPath);
|
|
135
|
+
const cellPath = `${rowPath}/${identityPath("cell", cellChild.props, cellIndex)}`;
|
|
136
|
+
cellIndex += 1;
|
|
137
|
+
assertAllowedTableKeys(cellChild.props, cellAllowedParameters, "Cell", cellPath);
|
|
138
|
+
const cellAuthorId = parseOptionalTableId(cellChild.props["id"], cellPath);
|
|
139
|
+
while (owners.has(`${rowIndex}:${column}`)) column += 1;
|
|
140
|
+
const colSpan = parseTableMergeSpan(cellChild.props["colSpan"], "colSpan", cellPath);
|
|
141
|
+
const rowSpan = parseTableMergeSpan(cellChild.props["rowSpan"], "rowSpan", cellPath);
|
|
142
|
+
if (column + colSpan > columns.length) fail("invalid-table-merge", `Cells in row ${rowIndex + 1} exceed ${columns.length} column count`, cellPath);
|
|
143
|
+
if (rowIndex + rowSpan > input.children.filter((item) => "props" in item && item.type === "row").length) fail("invalid-table-merge", `rowSpan ${rowSpan} extends past the last row of the table`, cellPath);
|
|
144
|
+
for (let row = rowIndex; row < rowIndex + rowSpan; row += 1) for (let col = column; col < column + colSpan; col += 1) if (owners.has(`${row}:${col}`)) fail("conflicting-table-merge", "Cell merge region overlaps with an existing cell", cellPath);
|
|
145
|
+
const cellStyle = trackStyle(cellChild, "cell", cellPath);
|
|
146
|
+
const cellBgParsed = parseLayerBackground(cellStyle.style, "Cell", theme, cellPath);
|
|
147
|
+
const cellBackgroundRaw = cellBgParsed.declared ? cellBgParsed.value : row.backgroundRaw;
|
|
148
|
+
const cellVerticalAlign = parseTableVerticalAlign(cellStyle.style["verticalAlign"], cellPath) ?? rowVerticalAlign;
|
|
149
|
+
const borders = resolveTableCellBorders(cellStyle.style, row.borders, theme, cellPath);
|
|
150
|
+
const cellTextStyle = {
|
|
151
|
+
...mergeTextStyle(row.textStyle, cellStyle.textStyle),
|
|
152
|
+
textWrap: "normal"
|
|
153
|
+
};
|
|
154
|
+
let parsedParagraphs;
|
|
155
|
+
let parsedTextStyle;
|
|
156
|
+
try {
|
|
157
|
+
const textResult = parseTextParagraphs(cellChild.children, cellTextStyle, theme, { slideNumber }, cellPath);
|
|
158
|
+
parsedParagraphs = textResult.paragraphs;
|
|
159
|
+
parsedTextStyle = textResult.style;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error instanceof CapabilityError) fail(error.code, error.message, cellPath, error.details);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
const cell = {
|
|
165
|
+
row: rowIndex,
|
|
166
|
+
column,
|
|
167
|
+
rowSpan,
|
|
168
|
+
colSpan,
|
|
169
|
+
path: cellPath,
|
|
170
|
+
...cellAuthorId === void 0 ? {} : { authorId: cellAuthorId },
|
|
171
|
+
paragraphs: parsedParagraphs,
|
|
172
|
+
textStyle: parsedTextStyle,
|
|
173
|
+
verticalAlign: cellVerticalAlign,
|
|
174
|
+
padding: parseTableCellPadding(cellStyle.style, cellPath),
|
|
175
|
+
...cellBackgroundRaw === void 0 ? {} : { backgroundRaw: cellBackgroundRaw },
|
|
176
|
+
borders
|
|
177
|
+
};
|
|
178
|
+
cells.push(cell);
|
|
179
|
+
for (let row = rowIndex; row < rowIndex + rowSpan; row += 1) for (let col = column; col < column + colSpan; col += 1) owners.set(`${row}:${col}`, cell);
|
|
180
|
+
column += colSpan;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (rows.length === 0) fail("invalid-table-structure", "Table requires at least one row");
|
|
184
|
+
for (let row = 0; row < rows.length; row += 1) {
|
|
185
|
+
const missing = columns.findIndex((_, column) => !owners.has(`${row}:${column}`));
|
|
186
|
+
if (missing >= 0) fail("invalid-table-structure", `Row ${row + 1}, column ${missing + 1} is not covered by a Cell or merged cell`, rows[row]?.path);
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
rows,
|
|
190
|
+
cells
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function roundSvgNumber(value) {
|
|
194
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
195
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
196
|
+
}
|
|
197
|
+
function tableBorderAttributes(border) {
|
|
198
|
+
const w = Math.max(1, border.width);
|
|
199
|
+
let dashAttr = "";
|
|
200
|
+
switch (border.dash) {
|
|
201
|
+
case "solid":
|
|
202
|
+
dashAttr = "";
|
|
203
|
+
break;
|
|
204
|
+
case "dash":
|
|
205
|
+
dashAttr = ` stroke-dasharray="${roundSvgNumber(w * 4)} ${roundSvgNumber(w * 3)}"`;
|
|
206
|
+
break;
|
|
207
|
+
case "dot":
|
|
208
|
+
dashAttr = ` stroke-dasharray="${roundSvgNumber(w)} ${roundSvgNumber(w * 2)}"`;
|
|
209
|
+
break;
|
|
210
|
+
default: return border.dash;
|
|
211
|
+
}
|
|
212
|
+
return `fill="none" stroke="#${border.color.hex}" stroke-opacity="${roundSvgNumber(border.color.alpha ?? 1)}" stroke-width="${roundSvgNumber(border.width)}"${dashAttr}`;
|
|
213
|
+
}
|
|
214
|
+
function emitTableModel(model, emitContext) {
|
|
215
|
+
const { x, y, widths, heights, rows, columns, resolvedAnchors, owners, name, fontUses } = model;
|
|
216
|
+
const embedFonts = emitContext.options.embedFonts;
|
|
217
|
+
const rowsXml = rows.map((_, rowIndex) => {
|
|
218
|
+
const rowCells = [];
|
|
219
|
+
for (let column = 0; column < columns.length; column += 1) {
|
|
220
|
+
const entry = resolvedAnchors.get(`${rowIndex}:${column}`);
|
|
221
|
+
if (entry === void 0) {
|
|
222
|
+
const owner = owners.get(`${rowIndex}:${column}`);
|
|
223
|
+
const hMerge = column > owner.column ? " hMerge=\"1\"" : "";
|
|
224
|
+
const vMerge = rowIndex > owner.row ? " vMerge=\"1\"" : "";
|
|
225
|
+
const spanAttributes = [...rowIndex === owner.row && owner.rowSpan > 1 ? [`rowSpan="${owner.rowSpan}"`] : [], ...column === owner.column && owner.colSpan > 1 ? [`gridSpan="${owner.colSpan}"`] : []];
|
|
226
|
+
rowCells.push(`<a:tc${hMerge}${vMerge}${spanAttributes.length === 0 ? "" : ` ${spanAttributes.join(" ")}`}>${emptyTableCellXml(owner.textStyle["lang"])}</a:tc>`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const { cell, body, fill } = entry;
|
|
230
|
+
if ((embedFonts === "full" || embedFonts === "subset") && body.missingGlyphErrors.length > 0) {
|
|
231
|
+
const issue = body.missingGlyphErrors[0];
|
|
232
|
+
fail("font-missing-glyph", issue.message, cell.path, {
|
|
233
|
+
font: issue.font,
|
|
234
|
+
characters: issue.characters
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
let emittedXml;
|
|
238
|
+
try {
|
|
239
|
+
emittedXml = emitTextBody(body, emitContext.theme, { createFieldId: emitContext.createTextFieldId }).xml;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (error instanceof CapabilityError) fail(error.code, error.message, error.path ?? cell.path, error.details);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
const spanAttributes = [...cell.colSpan > 1 ? [`gridSpan="${cell.colSpan}"`] : [], ...cell.rowSpan > 1 ? [`rowSpan="${cell.rowSpan}"`] : []];
|
|
245
|
+
const attributes = spanAttributes.length === 0 ? "" : ` ${spanAttributes.join(" ")}`;
|
|
246
|
+
const properties = tableCellPropertiesXml(cell.padding, cell.verticalAlign, cell.borders, fill, (resource) => emitContext.registerResource(resource), entry.box);
|
|
247
|
+
rowCells.push(`<a:tc${attributes}>${emittedXml}${properties}</a:tc>`);
|
|
248
|
+
}
|
|
249
|
+
return rowCells.join("");
|
|
250
|
+
});
|
|
251
|
+
const presentationContributions = fontPresentationContributions(fontUses, embedFonts);
|
|
252
|
+
return {
|
|
253
|
+
xml: tableFrameXml(emitContext.id, xmlEscape(name), x, y, widths, heights, rowsXml, nativeLinkXml(emitContext.nativeLink), model.placeholder),
|
|
254
|
+
...presentationContributions.length === 0 ? {} : { presentationContributions }
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function paintTableModel(model, paintContext) {
|
|
258
|
+
const defs = [];
|
|
259
|
+
const fills = [];
|
|
260
|
+
const texts = [];
|
|
261
|
+
const borders = [];
|
|
262
|
+
const placeholders = [];
|
|
263
|
+
for (const entry of model.resolvedCells) {
|
|
264
|
+
const { cell, box: cellBox, fill, body, hasText, hasOverflow } = entry;
|
|
265
|
+
if (!Number.isFinite(cellBox.x) || !Number.isFinite(cellBox.y) || !Number.isFinite(cellBox.width) || !Number.isFinite(cellBox.height) || cellBox.width <= 1e-6 || cellBox.height <= 1e-6) continue;
|
|
266
|
+
const idPrefix = `tbl-s${paintContext.slideNumber}-o${paintContext.objectId}-r${cell.row}-c${cell.column}`;
|
|
267
|
+
if (fill.kind === "solid") fills.push(`<rect x="${roundSvgNumber(cellBox.x)}" y="${roundSvgNumber(cellBox.y)}" width="${roundSvgNumber(cellBox.width)}" height="${roundSvgNumber(cellBox.height)}" fill="#${fill.color.hex}" fill-opacity="${roundSvgNumber(fill.color.alpha ?? 1)}" stroke="none"/>`);
|
|
268
|
+
else if (fill.kind === "linear-gradient" || fill.kind === "radial-gradient") {
|
|
269
|
+
const fillDefId = `${idPrefix}-fill`;
|
|
270
|
+
defs.push(gradientDefSvg(fillDefId, fill));
|
|
271
|
+
fills.push(`<rect x="${roundSvgNumber(cellBox.x)}" y="${roundSvgNumber(cellBox.y)}" width="${roundSvgNumber(cellBox.width)}" height="${roundSvgNumber(cellBox.height)}" fill="url(#${fillDefId})" stroke="none"/>`);
|
|
272
|
+
} else if (fill.kind === "image") {
|
|
273
|
+
const fillDefId = `${idPrefix}-fill`;
|
|
274
|
+
const patternSvg = paintImageFillSvg(fill, fillDefId, cellBox, paintContext.registerRasterResource);
|
|
275
|
+
if (fill.source.kind === "external") placeholders.push({
|
|
276
|
+
...cell.authorId === void 0 ? {} : { id: cell.authorId },
|
|
277
|
+
path: `${paintContext.path}/${cell.path}`,
|
|
278
|
+
url: fill.source.externalUrl
|
|
279
|
+
});
|
|
280
|
+
if (patternSvg !== "") {
|
|
281
|
+
defs.push(patternSvg);
|
|
282
|
+
fills.push(`<rect x="${roundSvgNumber(cellBox.x)}" y="${roundSvgNumber(cellBox.y)}" width="${roundSvgNumber(cellBox.width)}" height="${roundSvgNumber(cellBox.height)}" fill="url(#${fillDefId})" stroke="none"/>`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (hasText) try {
|
|
286
|
+
const glyphs = renderTextOutlinesSvg({
|
|
287
|
+
paragraphs: body.paragraphs,
|
|
288
|
+
box: cellBox,
|
|
289
|
+
insets: cell.padding,
|
|
290
|
+
verticalAlign: cell.verticalAlign,
|
|
291
|
+
theme: paintContext.theme,
|
|
292
|
+
measuredLayout: body.measuredLayout,
|
|
293
|
+
idPrefix
|
|
294
|
+
});
|
|
295
|
+
if (glyphs !== "") {
|
|
296
|
+
if (hasOverflow) {
|
|
297
|
+
const clipId = `${idPrefix}-clip`;
|
|
298
|
+
defs.push(`<clipPath id="${clipId}" clipPathUnits="userSpaceOnUse"><rect x="${roundSvgNumber(cellBox.x)}" y="${roundSvgNumber(cellBox.y)}" width="${roundSvgNumber(cellBox.width)}" height="${roundSvgNumber(cellBox.height)}"/></clipPath>`);
|
|
299
|
+
texts.push(`<g clip-path="url(#${clipId})">${glyphs}</g>`);
|
|
300
|
+
} else texts.push(glyphs);
|
|
301
|
+
}
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (error instanceof CapabilityError) throw new CapabilityError(error.code, error.message, error.path ?? cell.path, error.details);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
const { top, right, bottom, left } = cell.borders;
|
|
307
|
+
const sameSide = (a, b) => a === b || a !== void 0 && b !== void 0 && a.width === b.width && a.dash === b.dash && a.color.hex === b.color.hex && a.color.alpha === b.color.alpha;
|
|
308
|
+
if (sameSide(top, right) && sameSide(top, bottom) && sameSide(top, left)) {
|
|
309
|
+
if (top !== void 0) borders.push(`<rect x="${roundSvgNumber(cellBox.x)}" y="${roundSvgNumber(cellBox.y)}" width="${roundSvgNumber(cellBox.width)}" height="${roundSvgNumber(cellBox.height)}" ${tableBorderAttributes(top)}/>`);
|
|
310
|
+
} else {
|
|
311
|
+
const x1 = roundSvgNumber(cellBox.x);
|
|
312
|
+
const y1 = roundSvgNumber(cellBox.y);
|
|
313
|
+
const x2 = roundSvgNumber(cellBox.x + cellBox.width);
|
|
314
|
+
const y2 = roundSvgNumber(cellBox.y + cellBox.height);
|
|
315
|
+
if (top !== void 0) borders.push(`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y1}" ${tableBorderAttributes(top)}/>`);
|
|
316
|
+
if (right !== void 0) borders.push(`<line x1="${x2}" y1="${y1}" x2="${x2}" y2="${y2}" ${tableBorderAttributes(right)}/>`);
|
|
317
|
+
if (bottom !== void 0) borders.push(`<line x1="${x1}" y1="${y2}" x2="${x2}" y2="${y2}" ${tableBorderAttributes(bottom)}/>`);
|
|
318
|
+
if (left !== void 0) borders.push(`<line x1="${x1}" y1="${y1}" x2="${x1}" y2="${y2}" ${tableBorderAttributes(left)}/>`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
svg: `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}<g>${fills.join("")}${texts.join("")}${borders.join("")}</g>`,
|
|
323
|
+
...placeholders.length === 0 ? {} : { placeholders }
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function failTableMeasurementUnavailable(result, defaultMessage, cellPath) {
|
|
327
|
+
if (result.measurementError !== void 0 && result.measurementError.code !== "font-measurement-unavailable") fail(result.measurementError.code, result.measurementError.message, cellPath, result.measurementError.details);
|
|
328
|
+
const errorFont = typeof result.measurementError?.details?.["font"] === "object" && result.measurementError.details["font"] !== null ? result.measurementError.details["font"] : void 0;
|
|
329
|
+
const fallbackFont = result.unmeasuredIssues.missingResourceFonts[0] ?? result.unmeasuredIssues.referencedFonts[0];
|
|
330
|
+
const font = errorFont ?? fallbackFont;
|
|
331
|
+
fail("font-measurement-unavailable", defaultMessage, cellPath, {
|
|
332
|
+
...font === void 0 ? {} : { font },
|
|
333
|
+
reason: "missing-resource"
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/** Shared calculation of table tracks and text dimensions used by layout measurement and table resolution. */
|
|
337
|
+
function tableLayoutModel(parsed, requestedWidth, theme) {
|
|
338
|
+
const { columns, tableStyle, rows, cells } = parsed;
|
|
339
|
+
const claims = [];
|
|
340
|
+
const addTextResult = (result) => {
|
|
341
|
+
claims.push(...result.resourceClaims);
|
|
342
|
+
};
|
|
343
|
+
const naturalWidths = /* @__PURE__ */ new Map();
|
|
344
|
+
if (columns.some((track) => track.kind === "auto" || track.kind === "fr" && requestedWidth === void 0)) for (const cell of cells) {
|
|
345
|
+
if (cell.colSpan !== 1) continue;
|
|
346
|
+
const track = columns[cell.column];
|
|
347
|
+
if (!(track?.kind === "auto" || track?.kind === "fr" && requestedWidth === void 0)) continue;
|
|
348
|
+
const measured = resolveCellBody(cell, theme, "max-content", void 0, false);
|
|
349
|
+
addTextResult(measured);
|
|
350
|
+
if (measured.textMetrics?.status === "unmeasured" && measured.textMetrics.reason === "missing-glyphs") {
|
|
351
|
+
const issue = measured.missingGlyphErrors[0];
|
|
352
|
+
const glyphFont = measured.unmeasuredIssues.missingGlyphFonts[0];
|
|
353
|
+
fail("font-missing-glyph", issue?.message ?? "auto columns require glyphs for all visible characters", cell.path, issue !== void 0 ? {
|
|
354
|
+
font: issue.font,
|
|
355
|
+
characters: issue.characters
|
|
356
|
+
} : glyphFont !== void 0 ? {
|
|
357
|
+
font: {
|
|
358
|
+
family: glyphFont.family,
|
|
359
|
+
weight: glyphFont.weight,
|
|
360
|
+
style: glyphFont.style
|
|
361
|
+
},
|
|
362
|
+
characters: glyphFont.missingGlyphs ?? []
|
|
363
|
+
} : void 0);
|
|
364
|
+
}
|
|
365
|
+
if (measured.measurement === void 0 && measured.text.trim() !== "") failTableMeasurementUnavailable(measured, "auto columns require available font metrics; provide measurement fonts or use explicit column widths", cell.path);
|
|
366
|
+
naturalWidths.set(cell, measured.measurement?.width ?? 0);
|
|
367
|
+
}
|
|
368
|
+
const widths = columns.map((track, index) => {
|
|
369
|
+
if (track.kind === "px") return track.value;
|
|
370
|
+
const intrinsic = Math.max(0, ...cells.filter((cell) => cell.column === index && cell.colSpan === 1).map((cell) => (naturalWidths.get(cell) ?? 0) + cell.padding.left + cell.padding.right));
|
|
371
|
+
return Math.max(1, intrinsic);
|
|
372
|
+
});
|
|
373
|
+
if (requestedWidth !== void 0) {
|
|
374
|
+
const fractionTotal = columns.reduce((sum, track) => sum + (track.kind === "fr" ? track.value : 0), 0);
|
|
375
|
+
const fixedWidth = widths.reduce((sum, value, index) => sum + (columns[index]?.kind === "fr" ? 0 : value), 0);
|
|
376
|
+
if (fractionTotal > 0) {
|
|
377
|
+
const free = requestedWidth - fixedWidth;
|
|
378
|
+
if (free >= columns.filter((track) => track.kind === "fr").length) columns.forEach((track, index) => {
|
|
379
|
+
if (track.kind === "fr") widths[index] = free * track.value / fractionTotal;
|
|
380
|
+
});
|
|
381
|
+
else columns.forEach((track, index) => {
|
|
382
|
+
if (track.kind === "fr") widths[index] = 1;
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
385
|
+
const baseWidth = widths.reduce((sum, value) => sum + value, 0);
|
|
386
|
+
if (requestedWidth > baseWidth && baseWidth > 0) widths.forEach((value, index) => {
|
|
387
|
+
widths[index] = value * requestedWidth / baseWidth;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (widths.map((width, index) => assertTableEmuExtent(width, `column ${index + 1} width`)).reduce((sum, value) => sum + value, 0) > maximumExtentEmu) fail("invalid-table-geometry", "Total table column width exceeds writable range");
|
|
392
|
+
const heights = rows.map((row) => row.height ?? 0);
|
|
393
|
+
const widthOf = (cell) => widths.slice(cell.column, cell.column + cell.colSpan).reduce((sum, width) => sum + width, 0);
|
|
394
|
+
const requiredHeight = (cell) => {
|
|
395
|
+
const result = resolveCellBody(cell, theme, Math.max(0, widthOf(cell) - cell.padding.left - cell.padding.right), void 0, false);
|
|
396
|
+
addTextResult(result);
|
|
397
|
+
if (result.textMetrics?.status === "unmeasured" && result.textMetrics.reason === "missing-glyphs") {
|
|
398
|
+
const issue = result.missingGlyphErrors[0];
|
|
399
|
+
const glyphFont = result.unmeasuredIssues.missingGlyphFonts[0];
|
|
400
|
+
fail("font-missing-glyph", issue?.message ?? "Automatic row height requires glyphs for all visible characters", cell.path, issue !== void 0 ? {
|
|
401
|
+
font: issue.font,
|
|
402
|
+
characters: issue.characters
|
|
403
|
+
} : glyphFont !== void 0 ? {
|
|
404
|
+
font: {
|
|
405
|
+
family: glyphFont.family,
|
|
406
|
+
weight: glyphFont.weight,
|
|
407
|
+
style: glyphFont.style
|
|
408
|
+
},
|
|
409
|
+
characters: glyphFont.missingGlyphs ?? []
|
|
410
|
+
} : void 0);
|
|
411
|
+
}
|
|
412
|
+
if (result.measurement === void 0 && result.text.trim() !== "") failTableMeasurementUnavailable(result, "Automatic row height requires available font metrics; provide measurement fonts or specify height on Row", cell.path);
|
|
413
|
+
return (result.measurement?.height ?? 0) + cell.padding.top + cell.padding.bottom;
|
|
414
|
+
};
|
|
415
|
+
for (const cell of cells) {
|
|
416
|
+
if (cell.rowSpan !== 1 || rows[cell.row]?.height !== void 0) continue;
|
|
417
|
+
heights[cell.row] = Math.max(heights[cell.row] ?? 0, requiredHeight(cell));
|
|
418
|
+
}
|
|
419
|
+
for (const cell of cells) {
|
|
420
|
+
if (cell.rowSpan === 1) continue;
|
|
421
|
+
const covered = Array.from({ length: cell.rowSpan }, (_, index) => cell.row + index);
|
|
422
|
+
const growable = covered.filter((row) => rows[row]?.height === void 0);
|
|
423
|
+
if (growable.length === 0) continue;
|
|
424
|
+
const currentHeight = covered.reduce((sum, row) => sum + (heights[row] ?? 0), 0);
|
|
425
|
+
const missing = requiredHeight(cell) - currentHeight;
|
|
426
|
+
if (missing <= 0) continue;
|
|
427
|
+
const targetRow = growable.at(-1);
|
|
428
|
+
if (targetRow !== void 0) heights[targetRow] = (heights[targetRow] ?? 0) + missing;
|
|
429
|
+
}
|
|
430
|
+
heights.forEach((height, index) => {
|
|
431
|
+
if (height <= 0) heights[index] = 1;
|
|
432
|
+
});
|
|
433
|
+
if (heights.map((height, index) => assertTableEmuExtent(height, `row ${index + 1} height`, rows[index]?.path)).reduce((sum, value) => sum + value, 0) > maximumExtentEmu) fail("invalid-table-geometry", "Total table row height exceeds writable range");
|
|
434
|
+
return {
|
|
435
|
+
columns,
|
|
436
|
+
tableStyle,
|
|
437
|
+
rows,
|
|
438
|
+
cells,
|
|
439
|
+
widths,
|
|
440
|
+
heights,
|
|
441
|
+
claims
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const tableCompatiblePlaceholderRoles = /* @__PURE__ */ new Set(["tbl", "obj"]);
|
|
445
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `table`. */
|
|
446
|
+
const tableMechanism = defineCanvasMechanism({
|
|
447
|
+
key: "table",
|
|
448
|
+
role: "canvas",
|
|
449
|
+
emit: emitTableModel,
|
|
450
|
+
paint: paintTableModel,
|
|
451
|
+
import: tableImportHandler
|
|
452
|
+
});
|
|
453
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `table-placeholder`. */
|
|
454
|
+
const tablePlaceholderMechanism = defineCanvasMechanism({
|
|
455
|
+
key: "table-placeholder",
|
|
456
|
+
role: "canvas",
|
|
457
|
+
emit: emitTableModel,
|
|
458
|
+
paint: paintTableModel,
|
|
459
|
+
import: tablePlaceholderImportHandler
|
|
460
|
+
});
|
|
461
|
+
/** Table module independently validates row and column structure, resolving layout/cells once for emit and paint. */
|
|
462
|
+
const tableCapability = {
|
|
463
|
+
declaration: "table",
|
|
464
|
+
mechanisms: [tableMechanism, tablePlaceholderMechanism],
|
|
465
|
+
codegen: tableCodegen,
|
|
466
|
+
bind(input, context) {
|
|
467
|
+
const placeholder = context.placeholder;
|
|
468
|
+
if (placeholder !== void 0) {
|
|
469
|
+
const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
|
|
470
|
+
if (!tableCompatiblePlaceholderRoles.has(role)) fail("incompatible-placeholder-content", `Table cannot be bound to ${role} placeholder`);
|
|
471
|
+
}
|
|
472
|
+
assertAllowedTableKeys(input.props, tableAllowedParameters, "Table");
|
|
473
|
+
const requestedName = parseOptionalName(input.props["name"]);
|
|
474
|
+
const morphKey = parseMorphKey(input.props["morphKey"]);
|
|
475
|
+
const link = parseLinkTarget(input.props["link"]);
|
|
476
|
+
const allowedStyleKeys = new Set(tableStyleKeys);
|
|
477
|
+
const contract = {
|
|
478
|
+
...parseCapabilityLayoutContract({
|
|
479
|
+
nativeKind: "graphicFrame",
|
|
480
|
+
props: input.props,
|
|
481
|
+
allowedStyleKeys,
|
|
482
|
+
allowPadding: false,
|
|
483
|
+
path: context.path
|
|
484
|
+
}),
|
|
485
|
+
contentMinimumsEnforced: true
|
|
486
|
+
};
|
|
487
|
+
const columns = parseTableColumns(input.props["columns"]);
|
|
488
|
+
const tableStyle = trackStyle(input, "table");
|
|
489
|
+
const tableBgParsed = parseLayerBackground(tableStyle.style, "Table", context.theme, context.path);
|
|
490
|
+
const tableBorders = resolveTableLayerBorders(tableStyle.style, {}, "Table", context.theme, context.path);
|
|
491
|
+
const tableVerticalAlign = parseTableVerticalAlign(tableStyle.style["verticalAlign"]) ?? "middle";
|
|
492
|
+
const { rows, cells } = prepareRows(input, columns, tableStyle.textStyle, tableVerticalAlign, tableBgParsed.value, tableBorders, context.theme, context.slideNumber);
|
|
493
|
+
const placeholderGeometry = placeholder === void 0 ? void 0 : resolvePlaceholderGeometry(placeholder, input.props);
|
|
494
|
+
const parsed = {
|
|
495
|
+
columns,
|
|
496
|
+
tableStyle,
|
|
497
|
+
tableVerticalAlign,
|
|
498
|
+
rows,
|
|
499
|
+
cells,
|
|
500
|
+
contract,
|
|
501
|
+
declaredX: placeholderGeometry?.x,
|
|
502
|
+
declaredY: placeholderGeometry?.y,
|
|
503
|
+
declaredWidth: placeholderGeometry?.width ?? contract.explicitPixelSize?.width,
|
|
504
|
+
declaredHeight: placeholderGeometry?.height ?? contract.explicitPixelSize?.height
|
|
505
|
+
};
|
|
506
|
+
const authorId = typeof input.props["id"] === "string" ? input.props["id"] : void 0;
|
|
507
|
+
const motionProps = pickMotionProps(input.props);
|
|
508
|
+
const native = {
|
|
509
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
510
|
+
...requestedName === void 0 ? {} : { hasExplicitName: true },
|
|
511
|
+
...link === void 0 ? {} : { link }
|
|
512
|
+
};
|
|
513
|
+
return {
|
|
514
|
+
contract,
|
|
515
|
+
...morphKey !== void 0 || requestedName !== void 0 || link !== void 0 ? { native } : {},
|
|
516
|
+
measureLayout(request) {
|
|
517
|
+
const declaredSize = typeof parsed.declaredWidth === "number" ? parseTablePositiveSize(parsed.declaredWidth, "Table.width") : void 0;
|
|
518
|
+
const declaredHeight = typeof parsed.declaredHeight === "number" ? parseTablePositiveSize(parsed.declaredHeight, "Table.height") : void 0;
|
|
519
|
+
const availableWidth = request.availableWidth !== void 0 && request.availableWidth > 0 ? request.availableWidth : void 0;
|
|
520
|
+
const natural = (declaredSize !== void 0 || request.widthMode === "exactly") && !columns.some((track) => track.kind === "auto") ? void 0 : tableLayoutModel(parsed, void 0, request.theme);
|
|
521
|
+
const naturalWidth = natural?.widths.reduce((sum, width) => sum + width, 0) ?? 0;
|
|
522
|
+
const requestedWidth = declaredSize ?? (availableWidth !== void 0 && (request.widthMode === "exactly" || request.widthMode === void 0 || naturalWidth > availableWidth) ? availableWidth : void 0);
|
|
523
|
+
const model = requestedWidth === void 0 ? natural ?? tableLayoutModel(parsed, void 0, request.theme) : tableLayoutModel(parsed, requestedWidth, request.theme);
|
|
524
|
+
const width = model.widths.reduce((sum, value) => sum + value, 0);
|
|
525
|
+
const baseHeight = model.heights.reduce((sum, value) => sum + value, 0);
|
|
526
|
+
const targetHeight = declaredHeight ?? (request.heightMode === "exactly" ? request.availableHeight : void 0);
|
|
527
|
+
const hasAutoRow = rows.some((row) => row.height === void 0);
|
|
528
|
+
return {
|
|
529
|
+
width,
|
|
530
|
+
height: targetHeight !== void 0 && targetHeight > baseHeight + .01 && hasAutoRow ? targetHeight : baseHeight,
|
|
531
|
+
minContentWidth: natural === void 0 ? width : naturalWidth,
|
|
532
|
+
minContentHeight: baseHeight
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
resolve(resolveContext) {
|
|
536
|
+
const requestedWidth = (typeof parsed.declaredWidth === "number" ? parseTablePositiveSize(parsed.declaredWidth, "Table.width") : void 0) ?? resolveContext.layoutBox?.width;
|
|
537
|
+
const model = tableLayoutModel(parsed, requestedWidth, resolveContext.theme);
|
|
538
|
+
const { widths } = model;
|
|
539
|
+
const heights = [...model.heights];
|
|
540
|
+
const claims = [...model.claims];
|
|
541
|
+
const fontUses = [];
|
|
542
|
+
const addTextResult = (result, path) => {
|
|
543
|
+
claims.push(...result.resourceClaims);
|
|
544
|
+
fontUses.push(...result.fontUses.map((use) => ({
|
|
545
|
+
...use,
|
|
546
|
+
path
|
|
547
|
+
})));
|
|
548
|
+
};
|
|
549
|
+
const targetHeight = (typeof parsed.declaredHeight === "number" ? parseTablePositiveSize(parsed.declaredHeight, "Table.height") : void 0) ?? resolveContext.layoutBox?.height;
|
|
550
|
+
if (targetHeight !== void 0) {
|
|
551
|
+
const naturalHeight = heights.reduce((sum, value) => sum + value, 0);
|
|
552
|
+
if (targetHeight > naturalHeight + .01) {
|
|
553
|
+
const growable = rows.flatMap((row, index) => row.height === void 0 ? [index] : []);
|
|
554
|
+
if (growable.length > 0) {
|
|
555
|
+
const extra = (targetHeight - naturalHeight) / growable.length;
|
|
556
|
+
for (const row of growable) heights[row] = (heights[row] ?? 0) + extra;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const x = parseTableCoordinate(resolveContext.layoutBox?.x ?? parsed.declaredX, "x");
|
|
561
|
+
const y = parseTableCoordinate(resolveContext.layoutBox?.y ?? parsed.declaredY, "y");
|
|
562
|
+
const width = parseTablePositiveSize(widths.reduce((sum, value) => sum + value, 0), "Table.width");
|
|
563
|
+
const box = {
|
|
564
|
+
x,
|
|
565
|
+
y,
|
|
566
|
+
width,
|
|
567
|
+
height: parseTablePositiveSize(heights.reduce((sum, value) => sum + value, 0), "Table.height")
|
|
568
|
+
};
|
|
569
|
+
const columnOffsets = [];
|
|
570
|
+
let offsetX = x;
|
|
571
|
+
for (const w of widths) {
|
|
572
|
+
columnOffsets.push(offsetX);
|
|
573
|
+
offsetX += w;
|
|
574
|
+
}
|
|
575
|
+
const rowOffsets = [];
|
|
576
|
+
let offsetY = y;
|
|
577
|
+
for (const h of heights) {
|
|
578
|
+
rowOffsets.push(offsetY);
|
|
579
|
+
offsetY += h;
|
|
580
|
+
}
|
|
581
|
+
const cellBoxes = /* @__PURE__ */ new Map();
|
|
582
|
+
for (const cell of cells) cellBoxes.set(cell, {
|
|
583
|
+
x: columnOffsets[cell.column] ?? x,
|
|
584
|
+
y: rowOffsets[cell.row] ?? y,
|
|
585
|
+
width: widths.slice(cell.column, cell.column + cell.colSpan).reduce((sum, value) => sum + value, 0),
|
|
586
|
+
height: heights.slice(cell.row, cell.row + cell.rowSpan).reduce((sum, value) => sum + value, 0)
|
|
587
|
+
});
|
|
588
|
+
const widthOf = (cell) => widths.slice(cell.column, cell.column + cell.colSpan).reduce((sum, width) => sum + width, 0);
|
|
589
|
+
const innerWidthOf = (cell) => Math.max(0, widthOf(cell) - cell.padding.left - cell.padding.right);
|
|
590
|
+
const anchors = new Map(cells.map((cell) => [`${cell.row}:${cell.column}`, cell]));
|
|
591
|
+
const owners = /* @__PURE__ */ new Map();
|
|
592
|
+
for (const cell of cells) for (let row = cell.row; row < cell.row + cell.rowSpan; row += 1) for (let column = cell.column; column < cell.column + cell.colSpan; column += 1) owners.set(`${row}:${column}`, cell);
|
|
593
|
+
const matrix = rows.map(() => Array.from({ length: columns.length }, () => ""));
|
|
594
|
+
const resolvedCells = [];
|
|
595
|
+
const resolvedAnchors = /* @__PURE__ */ new Map();
|
|
596
|
+
const fontUsages = [];
|
|
597
|
+
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) for (let column = 0; column < columns.length; column += 1) {
|
|
598
|
+
const cell = anchors.get(`${rowIndex}:${column}`);
|
|
599
|
+
if (cell === void 0) {
|
|
600
|
+
if (owners.get(`${rowIndex}:${column}`) === void 0) fail("invalid-table-structure", "Table row contains undeclared cells");
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const innerHeight = Math.max(0, heights.slice(cell.row, cell.row + cell.rowSpan).reduce((sum, value) => sum + value, 0) - cell.padding.top - cell.padding.bottom);
|
|
604
|
+
const contentSized = rows.slice(cell.row, cell.row + cell.rowSpan).some((row) => row.height === void 0);
|
|
605
|
+
const body = resolveCellBody(cell, resolveContext.theme, innerWidthOf(cell), innerHeight, contentSized);
|
|
606
|
+
addTextResult(body, cell.path);
|
|
607
|
+
for (const usage of body.fontUsages) fontUsages.push({
|
|
608
|
+
...usage,
|
|
609
|
+
path: cell.path
|
|
610
|
+
});
|
|
611
|
+
matrix[rowIndex][column] = body.text;
|
|
612
|
+
const fill = resolveBackgroundValue(resolveContext.theme, cell.backgroundRaw, void 0);
|
|
613
|
+
const entry = {
|
|
614
|
+
cell,
|
|
615
|
+
box: cellBoxes.get(cell),
|
|
616
|
+
fill,
|
|
617
|
+
body,
|
|
618
|
+
hasText: cell.paragraphs.some((paragraph) => paragraph.style.list !== void 0 || paragraph.runs.some((run) => run.text.length > 0)),
|
|
619
|
+
hasOverflow: body.textMetrics?.status === "measured" && !body.textMetrics.fits
|
|
620
|
+
};
|
|
621
|
+
resolvedCells.push(entry);
|
|
622
|
+
resolvedAnchors.set(`${rowIndex}:${column}`, entry);
|
|
623
|
+
}
|
|
624
|
+
const name = resolveContext.morphName ?? requestedName ?? placeholder?.layoutPlaceholder?.name ?? `Table ${resolveContext.id - 1}`;
|
|
625
|
+
try {
|
|
626
|
+
assertXml10Characters(name);
|
|
627
|
+
} catch {
|
|
628
|
+
fail("invalid-xml-character", "Table.name contains characters not allowed in XML 1.0");
|
|
629
|
+
}
|
|
630
|
+
const resolvedRowObservations = rows.map((row, rowIndex) => {
|
|
631
|
+
const rowY = rowOffsets[rowIndex] ?? y;
|
|
632
|
+
const rowHeight = heights[rowIndex] ?? 0;
|
|
633
|
+
const rowPath = `${resolveContext.path}/row[${row.authorId ?? rowIndex}]`;
|
|
634
|
+
return {
|
|
635
|
+
index: rowIndex,
|
|
636
|
+
...row.authorId === void 0 ? {} : { id: row.authorId },
|
|
637
|
+
path: rowPath,
|
|
638
|
+
y: rowY,
|
|
639
|
+
height: rowHeight,
|
|
640
|
+
box: {
|
|
641
|
+
x,
|
|
642
|
+
y: rowY,
|
|
643
|
+
width,
|
|
644
|
+
height: rowHeight
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
});
|
|
648
|
+
const resolvedCellObservations = cells.map((cell) => {
|
|
649
|
+
const textMetrics = resolvedAnchors.get(`${cell.row}:${cell.column}`)?.body.textMetrics;
|
|
650
|
+
if (textMetrics === void 0) throw new Error(`Missing textMetrics for table cell (${cell.row}, ${cell.column})`);
|
|
651
|
+
const cellPath = `${resolvedRowObservations[cell.row]?.path ?? `${resolveContext.path}/row[${cell.row}]`}/cell[${cell.authorId ?? cell.column}]`;
|
|
652
|
+
return {
|
|
653
|
+
row: cell.row,
|
|
654
|
+
column: cell.column,
|
|
655
|
+
rowSpan: cell.rowSpan,
|
|
656
|
+
colSpan: cell.colSpan,
|
|
657
|
+
...cell.authorId === void 0 ? {} : { id: cell.authorId },
|
|
658
|
+
path: cellPath,
|
|
659
|
+
box: cellBoxes.get(cell),
|
|
660
|
+
text: matrix[cell.row]?.[cell.column] ?? "",
|
|
661
|
+
textMetrics
|
|
662
|
+
};
|
|
663
|
+
});
|
|
664
|
+
const subParts = resolvedRowObservations.map((rowObs) => ({
|
|
665
|
+
kind: "row",
|
|
666
|
+
...rowObs.id === void 0 ? {} : { authorId: rowObs.id },
|
|
667
|
+
path: rowObs.path,
|
|
668
|
+
box: rowObs.box,
|
|
669
|
+
text: matrix[rowObs.index]?.join(" ") ?? "",
|
|
670
|
+
parts: resolvedCellObservations.filter((cellObs) => cellObs.row === rowObs.index).map((cellObs) => ({
|
|
671
|
+
kind: "cell",
|
|
672
|
+
...cellObs.id === void 0 ? {} : { authorId: cellObs.id },
|
|
673
|
+
path: cellObs.path,
|
|
674
|
+
box: cellObs.box,
|
|
675
|
+
text: cellObs.text,
|
|
676
|
+
textMetrics: cellObs.textMetrics
|
|
677
|
+
}))
|
|
678
|
+
}));
|
|
679
|
+
const observation = {
|
|
680
|
+
columns: [...widths],
|
|
681
|
+
rows: resolvedRowObservations,
|
|
682
|
+
cells: resolvedCellObservations,
|
|
683
|
+
merges: cells.filter((cell) => cell.colSpan > 1 || cell.rowSpan > 1).map(({ row, column, rowSpan, colSpan }) => ({
|
|
684
|
+
row,
|
|
685
|
+
column,
|
|
686
|
+
rowSpan,
|
|
687
|
+
colSpan
|
|
688
|
+
}))
|
|
689
|
+
};
|
|
690
|
+
const annotations = motionAnnotations(motionProps, {
|
|
691
|
+
kind: "table",
|
|
692
|
+
name,
|
|
693
|
+
...authorId === void 0 ? {} : { authorId },
|
|
694
|
+
textBody: true,
|
|
695
|
+
filled: resolvedCells.some((entry) => entry.fill.kind !== "none"),
|
|
696
|
+
box,
|
|
697
|
+
rotationDegrees: 0,
|
|
698
|
+
hasBackground: resolvedCells.some((entry) => entry.fill.kind !== "none")
|
|
699
|
+
});
|
|
700
|
+
const resolvedModel = {
|
|
701
|
+
x,
|
|
702
|
+
y,
|
|
703
|
+
widths,
|
|
704
|
+
heights,
|
|
705
|
+
rows,
|
|
706
|
+
columns,
|
|
707
|
+
resolvedCells,
|
|
708
|
+
resolvedAnchors,
|
|
709
|
+
owners,
|
|
710
|
+
name,
|
|
711
|
+
fontUses,
|
|
712
|
+
...placeholder === void 0 ? {} : { placeholder: placeholder.nativeRef }
|
|
713
|
+
};
|
|
714
|
+
const mechanism = placeholder === void 0 ? tableMechanism : tablePlaceholderMechanism;
|
|
715
|
+
return {
|
|
716
|
+
observation: {
|
|
717
|
+
id: resolveContext.id,
|
|
718
|
+
kind: "table",
|
|
719
|
+
name,
|
|
720
|
+
box,
|
|
721
|
+
table: observation
|
|
722
|
+
},
|
|
723
|
+
parts: subParts,
|
|
724
|
+
extensions: [],
|
|
725
|
+
...annotations.length === 0 ? {} : { annotations },
|
|
726
|
+
resourceClaims: claims,
|
|
727
|
+
...fontUsages.length === 0 ? {} : { fontUsages },
|
|
728
|
+
emit(emitContext) {
|
|
729
|
+
return mechanism.emit(resolvedModel, emitContext);
|
|
730
|
+
},
|
|
731
|
+
paint(paintContext) {
|
|
732
|
+
return mechanism.paint(resolvedModel, paintContext);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
export { tableCapability, tableMechanism, tablePlaceholderMechanism };
|