@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,236 @@
|
|
|
1
|
+
import { readInternalDeclarationProps } from "../../../core/dist/document-internals.js";
|
|
2
|
+
import "../../../codegen/dist/index.js";
|
|
3
|
+
import "../../../core/dist/capability.js";
|
|
4
|
+
import { CommonNode } from "../../../core/dist/document.js";
|
|
5
|
+
import { defineObjectCodegen, expr } from "../../../codegen/dist/types.js";
|
|
6
|
+
import { serializeImageDescriptorValue } from "../image/image-codegen.js";
|
|
7
|
+
import { motionPropKeySet } from "../motion/motion-schemas.js";
|
|
8
|
+
import { shapeAllowedPropKeyList, shapeStyleSchema } from "./shape-declaration.js";
|
|
9
|
+
// ../capabilities/dist/shape/shape-codegen.js
|
|
10
|
+
const objectMotionPropKeys = motionPropKeySet;
|
|
11
|
+
const shapeAllowedPropKeys = new Set(shapeAllowedPropKeyList);
|
|
12
|
+
const shapeAllowedChildKinds = /* @__PURE__ */ new Set([
|
|
13
|
+
"paragraph",
|
|
14
|
+
"span",
|
|
15
|
+
"sup",
|
|
16
|
+
"sub",
|
|
17
|
+
"slide-number",
|
|
18
|
+
"br",
|
|
19
|
+
"motion-step"
|
|
20
|
+
]);
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function isPlainRecord(value) {
|
|
25
|
+
if (!isRecord(value)) return false;
|
|
26
|
+
const proto = Object.getPrototypeOf(value);
|
|
27
|
+
return proto === Object.prototype || proto === null;
|
|
28
|
+
}
|
|
29
|
+
function singleTextLeaf(node) {
|
|
30
|
+
if (node.children.length !== 1) return void 0;
|
|
31
|
+
const only = node.children[0];
|
|
32
|
+
if (only === void 0 || only instanceof CommonNode) return void 0;
|
|
33
|
+
const leaf = only;
|
|
34
|
+
return leaf.type === "#text" ? leaf.text : void 0;
|
|
35
|
+
}
|
|
36
|
+
function assertAllowedShapeChildren(node, ctx) {
|
|
37
|
+
let childIndex = 0;
|
|
38
|
+
for (const child of node.children) {
|
|
39
|
+
if (!(child instanceof CommonNode)) continue;
|
|
40
|
+
const label = child.id === void 0 ? `${child.type}[${childIndex + 1}]` : `${child.type}[${child.id}]`;
|
|
41
|
+
if (!shapeAllowedChildKinds.has(child.type)) ctx.fail("invalid-document", `shape declaration cannot contain ${JSON.stringify(child.type)} child`, `${ctx.path}/${label}`);
|
|
42
|
+
childIndex += 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function formatSvgNumber(value, ctx, propPath) {
|
|
46
|
+
if (typeof value !== "number" || !Number.isFinite(value)) ctx.fail("unexpressible-value", `Non-finite geometry coordinate ${String(value)} cannot be expressed in source`, propPath);
|
|
47
|
+
return Object.is(value, -0) ? "0" : String(value);
|
|
48
|
+
}
|
|
49
|
+
function commandsToSvgPath(commands, ctx, basePath) {
|
|
50
|
+
if (commands.length === 0) return void 0;
|
|
51
|
+
const segments = [];
|
|
52
|
+
for (let index = 0; index < commands.length; index += 1) {
|
|
53
|
+
const command = commands[index];
|
|
54
|
+
if (!isRecord(command) || typeof command["op"] !== "string") return;
|
|
55
|
+
const cmdPath = `${basePath}.commands[${index}]`;
|
|
56
|
+
switch (command["op"]) {
|
|
57
|
+
case "M":
|
|
58
|
+
case "L": {
|
|
59
|
+
if (index === 0 && command["op"] !== "M") return void 0;
|
|
60
|
+
const x = formatSvgNumber(command["x"], ctx, `${cmdPath}.x`);
|
|
61
|
+
const y = formatSvgNumber(command["y"], ctx, `${cmdPath}.y`);
|
|
62
|
+
segments.push(`${command["op"]} ${x} ${y}`);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "C": {
|
|
66
|
+
if (index === 0) return void 0;
|
|
67
|
+
const x1 = formatSvgNumber(command["x1"], ctx, `${cmdPath}.x1`);
|
|
68
|
+
const y1 = formatSvgNumber(command["y1"], ctx, `${cmdPath}.y1`);
|
|
69
|
+
const x2 = formatSvgNumber(command["x2"], ctx, `${cmdPath}.x2`);
|
|
70
|
+
const y2 = formatSvgNumber(command["y2"], ctx, `${cmdPath}.y2`);
|
|
71
|
+
const x = formatSvgNumber(command["x"], ctx, `${cmdPath}.x`);
|
|
72
|
+
const y = formatSvgNumber(command["y"], ctx, `${cmdPath}.y`);
|
|
73
|
+
segments.push(`C ${x1} ${y1} ${x2} ${y2} ${x} ${y}`);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "Q": {
|
|
77
|
+
if (index === 0) return void 0;
|
|
78
|
+
const x1 = formatSvgNumber(command["x1"], ctx, `${cmdPath}.x1`);
|
|
79
|
+
const y1 = formatSvgNumber(command["y1"], ctx, `${cmdPath}.y1`);
|
|
80
|
+
const x = formatSvgNumber(command["x"], ctx, `${cmdPath}.x`);
|
|
81
|
+
const y = formatSvgNumber(command["y"], ctx, `${cmdPath}.y`);
|
|
82
|
+
segments.push(`Q ${x1} ${y1} ${x} ${y}`);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "Z":
|
|
86
|
+
if (index === 0) return void 0;
|
|
87
|
+
segments.push("Z");
|
|
88
|
+
break;
|
|
89
|
+
default: return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return segments.join(" ");
|
|
93
|
+
}
|
|
94
|
+
function trySerializeCustomAsPath(value, ctx) {
|
|
95
|
+
if (value["connectionSites"] !== void 0) return;
|
|
96
|
+
const width = value["width"];
|
|
97
|
+
const height = value["height"];
|
|
98
|
+
const paths = value["paths"];
|
|
99
|
+
if (typeof width !== "number" || !Number.isFinite(width) || width <= 0 || typeof height !== "number" || !Number.isFinite(height) || height <= 0 || !Array.isArray(paths) || paths.length === 0) return;
|
|
100
|
+
const firstPath = paths[0];
|
|
101
|
+
if (!isRecord(firstPath)) return void 0;
|
|
102
|
+
const uniformFill = firstPath["fill"];
|
|
103
|
+
const uniformStroke = firstPath["stroke"];
|
|
104
|
+
const svgStrings = [];
|
|
105
|
+
for (let index = 0; index < paths.length; index += 1) {
|
|
106
|
+
const entry = paths[index];
|
|
107
|
+
if (!isRecord(entry) || !Array.isArray(entry["commands"])) return;
|
|
108
|
+
if (entry["fill"] !== uniformFill || entry["stroke"] !== uniformStroke) return;
|
|
109
|
+
const svg = commandsToSvgPath(entry["commands"], ctx, `@geometry.paths[${index}]`);
|
|
110
|
+
if (svg === void 0) return void 0;
|
|
111
|
+
svgStrings.push(svg);
|
|
112
|
+
}
|
|
113
|
+
const pathFn = ctx.useImport("path");
|
|
114
|
+
const dataExpr = svgStrings.length === 1 ? JSON.stringify(svgStrings[0]) : ctx.emitValueExpr(svgStrings, "@geometry.paths");
|
|
115
|
+
const optionsObj = {
|
|
116
|
+
viewBox: [width, height],
|
|
117
|
+
...uniformFill === void 0 ? {} : { fill: uniformFill },
|
|
118
|
+
...uniformStroke === void 0 ? {} : { stroke: uniformStroke }
|
|
119
|
+
};
|
|
120
|
+
return expr(`${pathFn}(${dataExpr}, ${ctx.emitValueExpr(optionsObj, "@geometry")})`);
|
|
121
|
+
}
|
|
122
|
+
function serializeGeometryProp(value, ctx) {
|
|
123
|
+
if (typeof value === "string") return value;
|
|
124
|
+
if (!isRecord(value)) return expr(ctx.emitValueExpr(value, "@geometry"));
|
|
125
|
+
if (value["type"] === "preset" && typeof value["name"] === "string") {
|
|
126
|
+
const presetFn = ctx.useImport("preset");
|
|
127
|
+
const adjust = value["adjust"];
|
|
128
|
+
if (adjust !== void 0) {
|
|
129
|
+
if (!isRecord(adjust)) ctx.fail("unexpressible-value", "Preset geometry adjust must be a plain record", "@geometry.adjust");
|
|
130
|
+
if (Object.entries(adjust).filter(([, entryValue]) => entryValue !== void 0).length > 0) return expr(`${presetFn}(${JSON.stringify(value["name"])}, ${ctx.emitValueExpr(adjust, "@geometry.adjust")})`);
|
|
131
|
+
}
|
|
132
|
+
return expr(`${presetFn}(${JSON.stringify(value["name"])})`);
|
|
133
|
+
}
|
|
134
|
+
if (value["type"] === "custom") {
|
|
135
|
+
const asPath = trySerializeCustomAsPath(value, ctx);
|
|
136
|
+
if (asPath !== void 0) return asPath;
|
|
137
|
+
}
|
|
138
|
+
return expr(ctx.emitValueExpr(value, "@geometry"));
|
|
139
|
+
}
|
|
140
|
+
function serializeGradientValue(value, ctx) {
|
|
141
|
+
if (!isRecord(value)) return void 0;
|
|
142
|
+
const type = value["type"];
|
|
143
|
+
if (type === "linear-gradient") {
|
|
144
|
+
const angle = value["angle"];
|
|
145
|
+
const stops = value["stops"];
|
|
146
|
+
if (typeof angle !== "number" || !Array.isArray(stops)) return void 0;
|
|
147
|
+
const fn = ctx.useImport("linearGradient");
|
|
148
|
+
const args = [ctx.emitValueExpr(angle, "@angle"), ...stops.map((stop, idx) => ctx.emitValueExpr(stop, `@stops[${idx}]`))];
|
|
149
|
+
return expr(`${fn}(${args.join(", ")})`);
|
|
150
|
+
}
|
|
151
|
+
if (type === "radial-gradient") {
|
|
152
|
+
const stops = value["stops"];
|
|
153
|
+
if (!Array.isArray(stops)) return void 0;
|
|
154
|
+
const fn = ctx.useImport("radialGradient");
|
|
155
|
+
const args = stops.map((stop, idx) => ctx.emitValueExpr(stop, `@stops[${idx}]`));
|
|
156
|
+
return expr(`${fn}(${args.join(", ")})`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function serializeShapeStyleProp(style, ctx) {
|
|
160
|
+
if (!isPlainRecord(style)) ctx.fail("unexpressible-value", "Shape.style must be a plain object", "@style");
|
|
161
|
+
const parsed = shapeStyleSchema.safeParse(style);
|
|
162
|
+
if (!parsed.success) {
|
|
163
|
+
const issue = parsed.error.issues[0];
|
|
164
|
+
const issuePath = issue !== void 0 && issue.path.length > 0 ? `@style.${issue.path.join(".")}` : "@style";
|
|
165
|
+
ctx.fail("unexpressible-value", issue?.message ?? "Shape.style cannot be expressed", issuePath);
|
|
166
|
+
}
|
|
167
|
+
const entries = [];
|
|
168
|
+
for (const [key, entryValue] of Object.entries(style)) {
|
|
169
|
+
if (entryValue === void 0) continue;
|
|
170
|
+
if (key === "background") {
|
|
171
|
+
const serializedImage = serializeImageDescriptorValue(entryValue, ctx);
|
|
172
|
+
entries.push([key, serializedImage ?? entryValue]);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
entries.push([key, entryValue]);
|
|
176
|
+
}
|
|
177
|
+
return expr(ctx.formatProps(entries));
|
|
178
|
+
}
|
|
179
|
+
function collectShapeProps(node, ctx) {
|
|
180
|
+
const props = readInternalDeclarationProps(node);
|
|
181
|
+
const extra = ctx.emitObjectExtraProps(props);
|
|
182
|
+
const entries = [];
|
|
183
|
+
for (const [key, value] of Object.entries(props)) {
|
|
184
|
+
if (value === void 0) continue;
|
|
185
|
+
if (!shapeAllowedPropKeys.has(key)) ctx.fail("invalid-document", `shape declaration does not support property ${JSON.stringify(key)}`, `@${key}`);
|
|
186
|
+
if (objectMotionPropKeys.has(key)) {
|
|
187
|
+
if (Object.hasOwn(extra, key)) entries.push([key, extra[key]]);
|
|
188
|
+
else ctx.fail("unexpressible-value", `Object property ${JSON.stringify(key)} requires motion codegen support`, `@${key}`);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (key === "geometry") {
|
|
192
|
+
entries.push([key, serializeGeometryProp(value, ctx)]);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (key === "style") {
|
|
196
|
+
entries.push([key, serializeShapeStyleProp(value, ctx)]);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
entries.push([key, value]);
|
|
200
|
+
}
|
|
201
|
+
return entries;
|
|
202
|
+
}
|
|
203
|
+
function emitShapeVanilla(node, ctx) {
|
|
204
|
+
assertAllowedShapeChildren(node, ctx);
|
|
205
|
+
const callee = ctx.useImport("shape");
|
|
206
|
+
const propsEntries = collectShapeProps(node, ctx);
|
|
207
|
+
const leafText = singleTextLeaf(node);
|
|
208
|
+
if (leafText !== void 0) {
|
|
209
|
+
const args = propsEntries.length === 0 ? [JSON.stringify(leafText)] : [JSON.stringify(leafText), ctx.formatProps(propsEntries)];
|
|
210
|
+
return ctx.formatVanillaCall(callee, args);
|
|
211
|
+
}
|
|
212
|
+
if (node.children.length === 0) {
|
|
213
|
+
const args = propsEntries.length === 0 ? [] : [ctx.formatProps(propsEntries)];
|
|
214
|
+
return ctx.formatVanillaCall(callee, args);
|
|
215
|
+
}
|
|
216
|
+
const children = ctx.emitRichTextChildren(node.children);
|
|
217
|
+
const contentArg = ctx.emitValueExpr(children.map((code) => expr(code)));
|
|
218
|
+
const args = propsEntries.length === 0 ? [contentArg] : [contentArg, ctx.formatProps(propsEntries)];
|
|
219
|
+
return ctx.formatVanillaCall(callee, args);
|
|
220
|
+
}
|
|
221
|
+
function emitShapeReact(node, ctx) {
|
|
222
|
+
assertAllowedShapeChildren(node, ctx);
|
|
223
|
+
const tag = ctx.useImport("Shape");
|
|
224
|
+
const propsEntries = collectShapeProps(node, ctx);
|
|
225
|
+
const children = node.children.length === 0 ? [] : ctx.emitRichTextChildren(node.children);
|
|
226
|
+
return ctx.formatJsxElement(tag, propsEntries, children);
|
|
227
|
+
}
|
|
228
|
+
/** Source codegen contribution for `shape` declarations and DrawingML gradient values. */
|
|
229
|
+
const shapeCodegen = defineObjectCodegen({
|
|
230
|
+
declarations: { shape: {
|
|
231
|
+
emitVanilla: emitShapeVanilla,
|
|
232
|
+
emitReact: emitShapeReact
|
|
233
|
+
} },
|
|
234
|
+
valueSerializers: [serializeGradientValue]
|
|
235
|
+
});
|
|
236
|
+
export { serializeGeometryProp, shapeCodegen };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { authorIdSchema } from "../../../core/dist/author-ids.js";
|
|
2
|
+
import { layoutStyleShape } from "../../../core/dist/layout-schemas.js";
|
|
3
|
+
import { geometrySchema } from "../../../core/dist/geometry-schemas.js";
|
|
4
|
+
import { textStyleShape, visualStyleShape } from "../../../core/dist/theme.js";
|
|
5
|
+
import { linkTargetSchema } from "../../../core/dist/author-schemas.js";
|
|
6
|
+
import "../../../core/dist/capability.js";
|
|
7
|
+
import { pxToEmu } from "../../../emit/dist/ooxml.js";
|
|
8
|
+
import { RichTextContainer } from "../../../core/dist/document.js";
|
|
9
|
+
import "../../../emit/dist/index.js";
|
|
10
|
+
import { motionPropsShape } from "../motion/motion-schemas.js";
|
|
11
|
+
import "../shared/geometry.js";
|
|
12
|
+
import { optionalNameSchema } from "../shared/identity.js";
|
|
13
|
+
import { morphKeySchema } from "../shared/morph-api.js";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
// ../capabilities/dist/shape/shape-declaration.js
|
|
16
|
+
const shapeCoordinateSchema = z.number().finite().min(-1e6).max(1e6);
|
|
17
|
+
const shapeSizeSchema = z.number().finite().positive().refine((value) => {
|
|
18
|
+
const extentEmu = pxToEmu(value);
|
|
19
|
+
return extentEmu >= 1 && extentEmu <= 2147483647;
|
|
20
|
+
});
|
|
21
|
+
const shapeStyleObjectSchema = z.strictObject({
|
|
22
|
+
...layoutStyleShape,
|
|
23
|
+
...visualStyleShape,
|
|
24
|
+
...textStyleShape
|
|
25
|
+
});
|
|
26
|
+
const shapeStyleKeyList = Object.keys(shapeStyleObjectSchema.shape);
|
|
27
|
+
const rawShapeStyleSchema = shapeStyleObjectSchema.readonly();
|
|
28
|
+
const shapeStyleSchema = rawShapeStyleSchema;
|
|
29
|
+
const shapeDeclarationPropsObjectSchema = z.strictObject({
|
|
30
|
+
id: authorIdSchema.optional(),
|
|
31
|
+
name: optionalNameSchema.optional(),
|
|
32
|
+
morphKey: morphKeySchema.optional(),
|
|
33
|
+
link: linkTargetSchema.optional(),
|
|
34
|
+
geometry: geometrySchema.optional(),
|
|
35
|
+
style: rawShapeStyleSchema.optional(),
|
|
36
|
+
...motionPropsShape
|
|
37
|
+
});
|
|
38
|
+
const shapeAllowedPropKeyList = Object.keys(shapeDeclarationPropsObjectSchema.shape);
|
|
39
|
+
const shapeDeclarationPropsKeys = [...shapeAllowedPropKeyList, "children"];
|
|
40
|
+
shapeDeclarationPropsObjectSchema.readonly();
|
|
41
|
+
/** Creates the editable native shape shared by the command factory and the Shape JSX element. */
|
|
42
|
+
function createShapeNode(props) {
|
|
43
|
+
return new RichTextContainer("shape", "shape", props);
|
|
44
|
+
}
|
|
45
|
+
export { createShapeNode, shapeAllowedPropKeyList, shapeCoordinateSchema, shapeDeclarationPropsKeys, shapeSizeSchema, shapeStyleKeyList, shapeStyleSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { hostNodeCreator } from "../../../core/dist/host.js";
|
|
2
|
+
import { motionElement } from "../motion/motion-elements.js";
|
|
3
|
+
import { createShapeNode } from "./shape-declaration.js";
|
|
4
|
+
// ../capabilities/dist/shape/shape-elements.js
|
|
5
|
+
/** Declares a native object handled by the shape module within the React tree. */
|
|
6
|
+
function Shape(props) {
|
|
7
|
+
return motionElement("shape", {
|
|
8
|
+
...props,
|
|
9
|
+
[hostNodeCreator]: createShapeNode
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export { Shape };
|