@officedk/pptxdk 0.0.0-stage → 0.1.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/README.md +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -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 +2272 -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 +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -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 +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -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 +48 -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 +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -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 +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -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 +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -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 +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -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-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -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 +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -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 +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { getMorphKeyLabel, isMorphKey } from "../../core/dist/morph.js";
|
|
2
|
+
import { defaultTheme, isFont, isTheme } from "../../core/dist/theme.js";
|
|
3
|
+
import { isSlideLayoutDefinition } from "../../core/dist/masters.js";
|
|
4
|
+
import "../../core/dist/index.js";
|
|
5
|
+
import "../../core/dist/capability.js";
|
|
6
|
+
import { CommonNode, SlideLayoutContainer, SlideMasterContainer } from "../../core/dist/document.js";
|
|
7
|
+
import { AssetRegistry } from "./assets.js";
|
|
8
|
+
import { IdentifierAllocator, toCamelCaseIdentifier, toPascalCaseIdentifier } from "./identifiers.js";
|
|
9
|
+
import { formatJsxElement, formatJsxTextChild, formatPropsObject, formatTsValue, formatVanillaCall, indentBlock } from "./printer.js";
|
|
10
|
+
import { CodegenError, codegenOptionsSchema, expr } from "./types.js";
|
|
11
|
+
// ../codegen/dist/codegen.js
|
|
12
|
+
const coreDeckPropKeys = /* @__PURE__ */ new Set([
|
|
13
|
+
"width",
|
|
14
|
+
"height",
|
|
15
|
+
"theme",
|
|
16
|
+
"style",
|
|
17
|
+
"title"
|
|
18
|
+
]);
|
|
19
|
+
const coreMasterPropKeys = /* @__PURE__ */ new Set([
|
|
20
|
+
"id",
|
|
21
|
+
"name",
|
|
22
|
+
"preserve",
|
|
23
|
+
"theme",
|
|
24
|
+
"colorMap",
|
|
25
|
+
"placeholders",
|
|
26
|
+
"textStyles",
|
|
27
|
+
"style"
|
|
28
|
+
]);
|
|
29
|
+
const coreLayoutPropKeys = /* @__PURE__ */ new Set([
|
|
30
|
+
"id",
|
|
31
|
+
"name",
|
|
32
|
+
"type",
|
|
33
|
+
"preserve",
|
|
34
|
+
"matchingName",
|
|
35
|
+
"userDrawn",
|
|
36
|
+
"showMasterShapes",
|
|
37
|
+
"showMasterPlaceholderAnimations",
|
|
38
|
+
"placeholders",
|
|
39
|
+
"colorMapOverride",
|
|
40
|
+
"themeOverride",
|
|
41
|
+
"style"
|
|
42
|
+
]);
|
|
43
|
+
const coreSlidePropKeys = /* @__PURE__ */ new Set([
|
|
44
|
+
"id",
|
|
45
|
+
"name",
|
|
46
|
+
"layout",
|
|
47
|
+
"placeholders",
|
|
48
|
+
"theme",
|
|
49
|
+
"colorMapOverride",
|
|
50
|
+
"themeOverride",
|
|
51
|
+
"style",
|
|
52
|
+
"hidden",
|
|
53
|
+
"showMasterPlaceholderAnimations",
|
|
54
|
+
"showMasterShapes"
|
|
55
|
+
]);
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
function isObjectCodegenContribution(value) {
|
|
60
|
+
return isRecord(value) && isRecord(value["declarations"]);
|
|
61
|
+
}
|
|
62
|
+
function isSlideCodegenContribution(value) {
|
|
63
|
+
return isRecord(value) && isRecord(value["slideProps"]);
|
|
64
|
+
}
|
|
65
|
+
function isDeclarationTextLeaf(child) {
|
|
66
|
+
return !(child instanceof CommonNode) && child.type === "#text";
|
|
67
|
+
}
|
|
68
|
+
function collectContributions(capabilities) {
|
|
69
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
70
|
+
const objectProps = /* @__PURE__ */ new Map();
|
|
71
|
+
const ownerProps = /* @__PURE__ */ new Map();
|
|
72
|
+
const slideProps = /* @__PURE__ */ new Map();
|
|
73
|
+
const valueSerializers = [];
|
|
74
|
+
for (const mod of capabilities) {
|
|
75
|
+
const rawCodegen = mod.codegen;
|
|
76
|
+
if (rawCodegen === void 0) continue;
|
|
77
|
+
if (isObjectCodegenContribution(rawCodegen)) {
|
|
78
|
+
for (const [kind, handler] of Object.entries(rawCodegen.declarations)) declarations.set(kind, handler);
|
|
79
|
+
if (rawCodegen.objectProps !== void 0) for (const [prop, serializer] of Object.entries(rawCodegen.objectProps)) objectProps.set(prop, serializer);
|
|
80
|
+
if (rawCodegen.ownerProps !== void 0) for (const [prop, serializer] of Object.entries(rawCodegen.ownerProps)) ownerProps.set(prop, serializer);
|
|
81
|
+
if (rawCodegen.valueSerializers !== void 0) valueSerializers.push(...rawCodegen.valueSerializers);
|
|
82
|
+
} else if (isSlideCodegenContribution(rawCodegen)) {
|
|
83
|
+
for (const [prop, serializer] of Object.entries(rawCodegen.slideProps)) slideProps.set(prop, serializer);
|
|
84
|
+
if (rawCodegen.valueSerializers !== void 0) valueSerializers.push(...rawCodegen.valueSerializers);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
declarations,
|
|
89
|
+
objectProps,
|
|
90
|
+
ownerProps,
|
|
91
|
+
slideProps,
|
|
92
|
+
valueSerializers
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function failAt(path, code, message) {
|
|
96
|
+
throw new CodegenError([{
|
|
97
|
+
severity: "error",
|
|
98
|
+
path,
|
|
99
|
+
code,
|
|
100
|
+
message
|
|
101
|
+
}]);
|
|
102
|
+
}
|
|
103
|
+
function childPathLabel(node, index) {
|
|
104
|
+
return node.id === void 0 ? `${node.type}[${index + 1}]` : `${node.type}[${node.id}]`;
|
|
105
|
+
}
|
|
106
|
+
function collectMorphKeysFromValue(value, out, seen, visitedObjects) {
|
|
107
|
+
if (typeof value !== "object" || value === null) return;
|
|
108
|
+
if (isMorphKey(value)) {
|
|
109
|
+
if (!seen.has(value)) {
|
|
110
|
+
seen.add(value);
|
|
111
|
+
out.push(value);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (value instanceof CommonNode || value instanceof Uint8Array || value instanceof URL || isTheme(value) || isSlideLayoutDefinition(value) || isFont(value)) return;
|
|
116
|
+
if (visitedObjects.has(value)) return;
|
|
117
|
+
visitedObjects.add(value);
|
|
118
|
+
if (Array.isArray(value)) {
|
|
119
|
+
for (const item of value) collectMorphKeysFromValue(item, out, seen, visitedObjects);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const entry of Object.values(value)) collectMorphKeysFromValue(entry, out, seen, visitedObjects);
|
|
123
|
+
}
|
|
124
|
+
function collectMorphKeysFromTree(root) {
|
|
125
|
+
const out = [];
|
|
126
|
+
const seen = /* @__PURE__ */ new Set();
|
|
127
|
+
const visitedObjects = /* @__PURE__ */ new Set();
|
|
128
|
+
const visit = (node) => {
|
|
129
|
+
collectMorphKeysFromValue(node.props, out, seen, visitedObjects);
|
|
130
|
+
for (const child of node.children) if (child instanceof CommonNode) visit(child);
|
|
131
|
+
};
|
|
132
|
+
visit(root);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function fontDedupKey(fontValue) {
|
|
136
|
+
const faces = (fontValue.faces ?? []).map((face) => ({
|
|
137
|
+
weight: face.weight ?? null,
|
|
138
|
+
style: face.style ?? null,
|
|
139
|
+
dataLen: face.data?.byteLength ?? null
|
|
140
|
+
}));
|
|
141
|
+
return JSON.stringify({
|
|
142
|
+
family: fontValue.family,
|
|
143
|
+
substitute: fontValue.substitute ?? false,
|
|
144
|
+
embeddable: fontValue.embeddable ?? true,
|
|
145
|
+
faces
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function isDefined(value) {
|
|
149
|
+
return value !== void 0;
|
|
150
|
+
}
|
|
151
|
+
const knownNativePlaceholderKeys = /* @__PURE__ */ new Set([
|
|
152
|
+
"type",
|
|
153
|
+
"explicitType",
|
|
154
|
+
"idx",
|
|
155
|
+
"sz",
|
|
156
|
+
"orient",
|
|
157
|
+
"hasCustomPrompt"
|
|
158
|
+
]);
|
|
159
|
+
function isNativePlaceholderRedundant(nativeRef, layoutSpec) {
|
|
160
|
+
if (!isRecord(nativeRef)) return false;
|
|
161
|
+
for (const key of Object.keys(nativeRef)) if (nativeRef[key] !== void 0 && !knownNativePlaceholderKeys.has(key)) return false;
|
|
162
|
+
return nativeRef["type"] === layoutSpec.type && nativeRef["explicitType"] !== false === (layoutSpec.explicitType !== false) && nativeRef["idx"] === layoutSpec.idx && nativeRef["sz"] === layoutSpec.sz && nativeRef["orient"] === layoutSpec.orient && nativeRef["hasCustomPrompt"] === true === (layoutSpec.hasCustomPrompt === true);
|
|
163
|
+
}
|
|
164
|
+
function stripRedundantNativePlaceholder(entries, layoutPlaceholders) {
|
|
165
|
+
if (layoutPlaceholders === void 0) return entries;
|
|
166
|
+
let placeholderKey;
|
|
167
|
+
let nativePlaceholderValue;
|
|
168
|
+
for (const [key, value] of entries) if (key === "placeholder" && typeof value === "string") placeholderKey = value;
|
|
169
|
+
else if (key === "nativePlaceholder" && value !== void 0) nativePlaceholderValue = value;
|
|
170
|
+
if (placeholderKey === void 0 || nativePlaceholderValue === void 0) return entries;
|
|
171
|
+
const layoutSpec = layoutPlaceholders[placeholderKey];
|
|
172
|
+
if (layoutSpec === void 0 || !isNativePlaceholderRedundant(nativePlaceholderValue, layoutSpec)) return entries;
|
|
173
|
+
return entries.filter(([key]) => key !== "nativePlaceholder");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Creates a synchronous source code generator wired with the provided capability modules.
|
|
177
|
+
*/
|
|
178
|
+
function createCodegen(capabilities) {
|
|
179
|
+
const registry = collectContributions(capabilities);
|
|
180
|
+
return function codegen(document, options) {
|
|
181
|
+
if (!(document instanceof CommonNode) || document.type !== "deck") failAt("deck", "invalid-document", "Expected a Deck root CommonNode");
|
|
182
|
+
const parsedOptions = codegenOptionsSchema.safeParse(options);
|
|
183
|
+
if (!parsedOptions.success) failAt("deck", "invalid-options", "Codegen options.target must be \"vanilla\" or \"react\"");
|
|
184
|
+
const target = parsedOptions.data.target;
|
|
185
|
+
const entry = target === "vanilla" ? "deck.ts" : "deck.tsx";
|
|
186
|
+
const allocator = new IdentifierAllocator();
|
|
187
|
+
const assets = new AssetRegistry(allocator);
|
|
188
|
+
const sdkImports = /* @__PURE__ */ new Set();
|
|
189
|
+
const nodeFsImports = /* @__PURE__ */ new Set();
|
|
190
|
+
const useImport = (symbol, from = "sdk") => {
|
|
191
|
+
if (from === "node:fs") nodeFsImports.add(symbol);
|
|
192
|
+
else sdkImports.add(symbol);
|
|
193
|
+
return symbol;
|
|
194
|
+
};
|
|
195
|
+
const morphKeys = collectMorphKeysFromTree(document);
|
|
196
|
+
const morphBuckets = [];
|
|
197
|
+
const morphScopeVarByKey = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const key of morphKeys) {
|
|
199
|
+
const label = getMorphKeyLabel(key);
|
|
200
|
+
let bucket = morphBuckets.find((candidate) => !candidate.labels.has(label));
|
|
201
|
+
if (bucket === void 0) {
|
|
202
|
+
const baseName = morphBuckets.length === 0 ? "morphScope" : `morphScope${morphBuckets.length + 1}`;
|
|
203
|
+
bucket = {
|
|
204
|
+
varName: allocator.allocate(baseName),
|
|
205
|
+
labels: /* @__PURE__ */ new Set()
|
|
206
|
+
};
|
|
207
|
+
morphBuckets.push(bucket);
|
|
208
|
+
}
|
|
209
|
+
bucket.labels.add(label);
|
|
210
|
+
morphScopeVarByKey.set(key, bucket.varName);
|
|
211
|
+
}
|
|
212
|
+
if (morphBuckets.length > 0) useImport("createMorphScope");
|
|
213
|
+
const fontVarByIdentity = /* @__PURE__ */ new Map();
|
|
214
|
+
const fontDeclarations = [];
|
|
215
|
+
const themeVarByInstance = /* @__PURE__ */ new Map();
|
|
216
|
+
const themeDeclarations = [];
|
|
217
|
+
const layoutIdentByContainer = /* @__PURE__ */ new Map();
|
|
218
|
+
const layoutIdentByDefinition = /* @__PURE__ */ new Map();
|
|
219
|
+
const layoutDefinitionCounts = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const child of document.children) {
|
|
221
|
+
if (!(child instanceof SlideMasterContainer)) continue;
|
|
222
|
+
for (const layout of child.layouts) {
|
|
223
|
+
const def = layout.props["layout"];
|
|
224
|
+
if (isSlideLayoutDefinition(def)) layoutDefinitionCounts.set(def, (layoutDefinitionCounts.get(def) ?? 0) + 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
let currentScopeAllocator;
|
|
228
|
+
let currentMotionScopeVars;
|
|
229
|
+
let currentSlideLayoutPlaceholders;
|
|
230
|
+
const serializeFont = (fontValue, ctx, hooks) => {
|
|
231
|
+
const resolvedFaces = (fontValue.faces ?? []).map((face) => {
|
|
232
|
+
const assetVar = face.data === void 0 ? void 0 : ctx.registerFontAsset(face.data, fontValue.family);
|
|
233
|
+
return {
|
|
234
|
+
...face.weight === void 0 ? {} : { weight: face.weight },
|
|
235
|
+
...face.style === void 0 ? {} : { style: face.style },
|
|
236
|
+
...assetVar === void 0 ? {} : { data: expr(assetVar) }
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
const dedupKey = `${fontDedupKey(fontValue)}:${resolvedFaces.map((face) => "data" in face && face.data !== void 0 ? face.data.code : "").join(",")}`;
|
|
240
|
+
const existing = fontVarByIdentity.get(dedupKey);
|
|
241
|
+
if (existing !== void 0) return existing;
|
|
242
|
+
const varName = allocator.allocate(toCamelCaseIdentifier(fontValue.family, "font", "Font"));
|
|
243
|
+
fontVarByIdentity.set(dedupKey, varName);
|
|
244
|
+
const fontFactory = useImport("font");
|
|
245
|
+
const optionsObj = {
|
|
246
|
+
...fontValue.substitute === true ? { substitute: true } : {},
|
|
247
|
+
...fontValue.embeddable === false ? { embeddable: false } : {}
|
|
248
|
+
};
|
|
249
|
+
const args = [JSON.stringify(fontValue.family)];
|
|
250
|
+
const hasOptions = Object.keys(optionsObj).length > 0;
|
|
251
|
+
if (resolvedFaces.length > 0 || hasOptions) args.push(formatTsValue(resolvedFaces, ctx, hooks));
|
|
252
|
+
if (hasOptions) args.push(formatTsValue(optionsObj, ctx, hooks));
|
|
253
|
+
fontDeclarations.push(`const ${varName} = ${fontFactory}(${args.join(", ")});`);
|
|
254
|
+
return varName;
|
|
255
|
+
};
|
|
256
|
+
const serializeTheme = (themeValue, ctx, hooks) => {
|
|
257
|
+
if (themeValue === defaultTheme) return useImport("defaultTheme");
|
|
258
|
+
const existing = themeVarByInstance.get(themeValue);
|
|
259
|
+
if (existing !== void 0) return existing;
|
|
260
|
+
const varName = allocator.allocate(toCamelCaseIdentifier(themeValue.name, "theme", "Theme"));
|
|
261
|
+
themeVarByInstance.set(themeValue, varName);
|
|
262
|
+
const themePayload = {
|
|
263
|
+
name: themeValue.name,
|
|
264
|
+
colors: themeValue.colors,
|
|
265
|
+
fonts: themeValue.fonts,
|
|
266
|
+
...themeValue.formatScheme === void 0 ? {} : { formatScheme: themeValue.formatScheme }
|
|
267
|
+
};
|
|
268
|
+
const formattedPayload = formatTsValue(themePayload, ctx, hooks);
|
|
269
|
+
const defineThemeFn = useImport("defineTheme");
|
|
270
|
+
themeDeclarations.push(`const ${varName} = ${defineThemeFn}(${formattedPayload});`);
|
|
271
|
+
return varName;
|
|
272
|
+
};
|
|
273
|
+
const createValueHooks = (ctx) => {
|
|
274
|
+
const hooks = { serializeSpecial: (value, propPath) => {
|
|
275
|
+
for (const serializer of registry.valueSerializers) {
|
|
276
|
+
const serialized = serializer(value, ctx);
|
|
277
|
+
if (serialized !== void 0) return serialized.code;
|
|
278
|
+
}
|
|
279
|
+
if (value === defaultTheme) return useImport("defaultTheme");
|
|
280
|
+
if (isTheme(value)) return serializeTheme(value, ctx, hooks);
|
|
281
|
+
if (isFont(value)) return serializeFont(value, ctx, hooks);
|
|
282
|
+
if (isMorphKey(value)) {
|
|
283
|
+
const scopeVar = morphScopeVarByKey.get(value);
|
|
284
|
+
if (scopeVar === void 0) ctx.fail("unexpressible-value", "MorphKey handle was not registered in deck scope", propPath);
|
|
285
|
+
return `${scopeVar}.handle(${JSON.stringify(getMorphKeyLabel(value))})`;
|
|
286
|
+
}
|
|
287
|
+
if (isSlideLayoutDefinition(value)) {
|
|
288
|
+
const ident = layoutIdentByDefinition.get(value);
|
|
289
|
+
if (ident === void 0) ctx.fail("unexpressible-value", "SlideLayoutDefinition is missing or mounted multiple times in this deck", propPath);
|
|
290
|
+
return ident;
|
|
291
|
+
}
|
|
292
|
+
if (value instanceof SlideLayoutContainer) {
|
|
293
|
+
const ident = layoutIdentByContainer.get(value);
|
|
294
|
+
if (ident === void 0) ctx.fail("unexpressible-value", "SlideLayout is not owned by any SlideMaster in this deck", propPath);
|
|
295
|
+
return ident;
|
|
296
|
+
}
|
|
297
|
+
} };
|
|
298
|
+
return hooks;
|
|
299
|
+
};
|
|
300
|
+
const makeContext = (path) => {
|
|
301
|
+
let localHooks;
|
|
302
|
+
const getHooks = () => {
|
|
303
|
+
localHooks ??= createValueHooks(ctx);
|
|
304
|
+
return localHooks;
|
|
305
|
+
};
|
|
306
|
+
const ctx = {
|
|
307
|
+
target,
|
|
308
|
+
path,
|
|
309
|
+
useImport,
|
|
310
|
+
registerImageAsset: (bytes, ext) => assets.registerImage(bytes, ext),
|
|
311
|
+
registerFontAsset: (bytes, family, ext) => {
|
|
312
|
+
useImport("readFileSync", "node:fs");
|
|
313
|
+
return assets.registerFont(bytes, family, ext);
|
|
314
|
+
},
|
|
315
|
+
allocateMotionScope: (identity) => {
|
|
316
|
+
if (currentMotionScopeVars === void 0) ctx.fail("invalid-document", "MotionScope can only be used inside a Slide");
|
|
317
|
+
const existing = currentMotionScopeVars.get(identity);
|
|
318
|
+
if (existing !== void 0) return existing;
|
|
319
|
+
const varName = (currentScopeAllocator ?? allocator).allocate("motionScopeHandle");
|
|
320
|
+
currentMotionScopeVars.set(identity, varName);
|
|
321
|
+
return varName;
|
|
322
|
+
},
|
|
323
|
+
emitValueExpr: (value, propPath) => formatTsValue(value, ctx, getHooks(), propPath),
|
|
324
|
+
emitChildNode: (node, index) => emitNode(node, path, index),
|
|
325
|
+
emitRichTextChildren: (children) => emitChildrenList(children, path),
|
|
326
|
+
emitObjectExtraProps: (props) => {
|
|
327
|
+
const result = {};
|
|
328
|
+
for (const [key, serializer] of registry.objectProps) {
|
|
329
|
+
if (!Object.hasOwn(props, key) || props[key] === void 0) continue;
|
|
330
|
+
const subCtx = makeContext(`${path}@${key}`);
|
|
331
|
+
result[key] = serializer(props[key], subCtx);
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
},
|
|
335
|
+
formatProps: (entries) => formatPropsObject(stripRedundantNativePlaceholder(entries, currentSlideLayoutPlaceholders), ctx, getHooks()),
|
|
336
|
+
formatJsxElement: (tag, entries, children = []) => formatJsxElement(tag, stripRedundantNativePlaceholder(entries, currentSlideLayoutPlaceholders), children, ctx, getHooks()),
|
|
337
|
+
formatVanillaCall: (callee, args, children = []) => formatVanillaCall(callee, args, children),
|
|
338
|
+
fail: (code, message, subPath) => {
|
|
339
|
+
failAt(subPath === void 0 || subPath === "" ? path : subPath.startsWith("@") ? `${path}${subPath}` : subPath, code, message);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
return ctx;
|
|
343
|
+
};
|
|
344
|
+
const emitNode = (node, parentPath, index) => {
|
|
345
|
+
const nodePath = `${parentPath}/${childPathLabel(node, index)}`;
|
|
346
|
+
const handler = registry.declarations.get(node.type);
|
|
347
|
+
if (handler === void 0) failAt(nodePath, "unsupported-declaration", `Declaration type ${JSON.stringify(node.type)} is not supported by registered codegen capabilities`);
|
|
348
|
+
const ctx = makeContext(nodePath);
|
|
349
|
+
return target === "vanilla" ? handler.emitVanilla(node, ctx) : handler.emitReact(node, ctx);
|
|
350
|
+
};
|
|
351
|
+
const emitChildrenList = (children, parentPath) => {
|
|
352
|
+
const emitted = [];
|
|
353
|
+
let childNodeIndex = 0;
|
|
354
|
+
for (const child of children) if (child instanceof CommonNode) {
|
|
355
|
+
emitted.push(emitNode(child, parentPath, childNodeIndex));
|
|
356
|
+
childNodeIndex += 1;
|
|
357
|
+
} else if (isDeclarationTextLeaf(child)) {
|
|
358
|
+
if (target === "vanilla") emitted.push(JSON.stringify(child.text));
|
|
359
|
+
else emitted.push(children.length === 1 ? formatJsxTextChild(child.text) : `{${JSON.stringify(child.text)}}`);
|
|
360
|
+
}
|
|
361
|
+
return emitted;
|
|
362
|
+
};
|
|
363
|
+
const resolveOwnerSlotProp = (ownerPath, propName, propValue) => {
|
|
364
|
+
const handler = registry.slideProps.get(propName) ?? registry.ownerProps.get(propName);
|
|
365
|
+
if (handler === void 0) failAt(`${ownerPath}@${propName}`, "unsupported-slide-property", `Property ${JSON.stringify(propName)} on ${ownerPath} is not supported by registered codegen capabilities`);
|
|
366
|
+
return handler(propValue, makeContext(`${ownerPath}@${propName}`));
|
|
367
|
+
};
|
|
368
|
+
const masterNodes = [];
|
|
369
|
+
const bodyNodes = [];
|
|
370
|
+
for (const child of document.children) {
|
|
371
|
+
if (!(child instanceof CommonNode)) {
|
|
372
|
+
if (isDeclarationTextLeaf(child) && child.text.trim() !== "") failAt("deck", "invalid-document", "Deck cannot directly contain text content");
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (child.type === "slide-master") masterNodes.push(child);
|
|
376
|
+
else bodyNodes.push(child);
|
|
377
|
+
}
|
|
378
|
+
for (const [key, value] of Object.entries(document.props)) {
|
|
379
|
+
if (!isDefined(value)) continue;
|
|
380
|
+
if (!coreDeckPropKeys.has(key)) failAt(`deck@${key}`, "invalid-document", `Deck does not support property ${JSON.stringify(key)}`);
|
|
381
|
+
}
|
|
382
|
+
const usesSections = bodyNodes.some((node) => node.type === "section");
|
|
383
|
+
if (usesSections) {
|
|
384
|
+
for (const [index, node] of bodyNodes.entries()) if (node.type !== "section") failAt(`deck/${childPathLabel(node, index)}`, "invalid-document", "When using Section, every slide must belong to a Section");
|
|
385
|
+
} else for (const [index, node] of bodyNodes.entries()) if (node.type !== "slide") failAt(`deck/${childPathLabel(node, index)}`, "invalid-document", "Direct children of Deck must be SlideMaster, Slide, or Section");
|
|
386
|
+
const masterGroupSections = [];
|
|
387
|
+
const masterRefsForDeck = [];
|
|
388
|
+
for (const [masterIndex, masterNode] of masterNodes.entries()) {
|
|
389
|
+
const masterPath = `deck/${childPathLabel(masterNode, masterIndex)}`;
|
|
390
|
+
const masterRawName = masterNode.id ?? masterNode.props["name"];
|
|
391
|
+
const masterVar = target === "vanilla" ? allocator.allocate(toCamelCaseIdentifier(masterRawName, `master${masterIndex + 1}`)) : allocator.allocate(toPascalCaseIdentifier(masterRawName, `Master${masterIndex + 1}`));
|
|
392
|
+
const masterPrefix = target === "vanilla" ? masterVar : `${masterVar.charAt(0).toLowerCase()}${masterVar.slice(1)}`;
|
|
393
|
+
const masterPropsEntries = [];
|
|
394
|
+
for (const [key, value] of Object.entries(masterNode.props)) {
|
|
395
|
+
if (!isDefined(value)) continue;
|
|
396
|
+
if (coreMasterPropKeys.has(key)) masterPropsEntries.push([key, value]);
|
|
397
|
+
else masterPropsEntries.push([key, resolveOwnerSlotProp(masterPath, key, value)]);
|
|
398
|
+
}
|
|
399
|
+
const masterSharedCanvasChildren = [];
|
|
400
|
+
const masterLayouts = [];
|
|
401
|
+
for (const child of masterNode.children) {
|
|
402
|
+
if (!(child instanceof CommonNode)) {
|
|
403
|
+
if (isDeclarationTextLeaf(child) && child.text.trim() !== "") failAt(masterPath, "invalid-document", "SlideMaster cannot directly contain text content");
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (child instanceof SlideLayoutContainer) masterLayouts.push(child);
|
|
407
|
+
else masterSharedCanvasChildren.push(child);
|
|
408
|
+
}
|
|
409
|
+
const layoutDecls = [];
|
|
410
|
+
const layoutExprsForMaster = [];
|
|
411
|
+
for (const [layoutIndex, layoutNode] of masterLayouts.entries()) {
|
|
412
|
+
const layoutPath = `${masterPath}/${childPathLabel(layoutNode, layoutIndex)}`;
|
|
413
|
+
const layoutRawName = layoutNode.id ?? layoutNode.props["name"];
|
|
414
|
+
const layoutIdent = allocator.allocate(toCamelCaseIdentifier(layoutRawName === void 0 ? void 0 : `${masterPrefix}_${layoutRawName}`, `${masterPrefix}Layout${layoutIndex + 1}`, "Layout"));
|
|
415
|
+
layoutIdentByContainer.set(layoutNode, layoutIdent);
|
|
416
|
+
const def = layoutNode.props["layout"];
|
|
417
|
+
if (isSlideLayoutDefinition(def) && layoutDefinitionCounts.get(def) === 1) layoutIdentByDefinition.set(def, layoutIdent);
|
|
418
|
+
const layoutSpecEntries = [];
|
|
419
|
+
for (const [key, value] of Object.entries(layoutNode.props)) {
|
|
420
|
+
if (!isDefined(value) || key === "layout") continue;
|
|
421
|
+
if (coreLayoutPropKeys.has(key)) layoutSpecEntries.push([key, value]);
|
|
422
|
+
else layoutSpecEntries.push([key, resolveOwnerSlotProp(layoutPath, key, value)]);
|
|
423
|
+
}
|
|
424
|
+
const layoutCtx = makeContext(layoutPath);
|
|
425
|
+
const specCode = layoutSpecEntries.length === 0 ? "{}" : layoutCtx.formatProps(layoutSpecEntries);
|
|
426
|
+
const defineLayoutFn = useImport("defineSlideLayout");
|
|
427
|
+
layoutDecls.push(`const ${layoutIdent} = ${defineLayoutFn}(${specCode});`);
|
|
428
|
+
const layoutChildren = [];
|
|
429
|
+
let layoutChildIdx = 0;
|
|
430
|
+
for (const child of layoutNode.children) {
|
|
431
|
+
if (!(child instanceof CommonNode)) {
|
|
432
|
+
if (isDeclarationTextLeaf(child) && child.text.trim() !== "") failAt(layoutPath, "invalid-document", "SlideLayout cannot directly contain text content");
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
layoutChildren.push(emitNode(child, layoutPath, layoutChildIdx));
|
|
436
|
+
layoutChildIdx += 1;
|
|
437
|
+
}
|
|
438
|
+
if (target === "vanilla") {
|
|
439
|
+
const slideLayoutFn = useImport("slideLayout");
|
|
440
|
+
layoutExprsForMaster.push(layoutCtx.formatVanillaCall(slideLayoutFn, [layoutIdent], layoutChildren));
|
|
441
|
+
} else {
|
|
442
|
+
const slideLayoutComp = useImport("SlideLayout");
|
|
443
|
+
layoutExprsForMaster.push(layoutCtx.formatJsxElement(slideLayoutComp, [["layout", expr(layoutIdent)]], layoutChildren));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const allMasterChildren = [...masterSharedCanvasChildren.map((child, idx) => emitNode(child, masterPath, idx)), ...layoutExprsForMaster];
|
|
447
|
+
const masterCtx = makeContext(masterPath);
|
|
448
|
+
let masterDeclCode;
|
|
449
|
+
if (target === "vanilla") {
|
|
450
|
+
const slideMasterFn = useImport("slideMaster");
|
|
451
|
+
const propsArg = masterPropsEntries.length === 0 ? [] : [masterCtx.formatProps(masterPropsEntries)];
|
|
452
|
+
masterDeclCode = `const ${masterVar} = ${masterCtx.formatVanillaCall(slideMasterFn, propsArg, allMasterChildren)};`;
|
|
453
|
+
masterRefsForDeck.push(masterVar);
|
|
454
|
+
} else {
|
|
455
|
+
const slideMasterComp = useImport("SlideMaster");
|
|
456
|
+
const jsxBody = masterCtx.formatJsxElement(slideMasterComp, masterPropsEntries, allMasterChildren);
|
|
457
|
+
masterDeclCode = `function ${masterVar}() {\n return (\n${indentBlock(jsxBody, 4)}\n );\n}`;
|
|
458
|
+
masterRefsForDeck.push(`<${masterVar} />`);
|
|
459
|
+
}
|
|
460
|
+
masterGroupSections.push([...layoutDecls, masterDeclCode].join("\n\n"));
|
|
461
|
+
}
|
|
462
|
+
const slideDeclarations = [];
|
|
463
|
+
const emitSlideDeclaration = (slideNode, slideIndex) => {
|
|
464
|
+
const slidePath = `deck/slide[${slideNode.id ?? String(slideIndex + 1)}]`;
|
|
465
|
+
const slidePropsEntries = [];
|
|
466
|
+
for (const [key, value] of Object.entries(slideNode.props)) {
|
|
467
|
+
if (!isDefined(value)) continue;
|
|
468
|
+
if (key === "layout") {
|
|
469
|
+
if (isSlideLayoutDefinition(value)) {
|
|
470
|
+
if (!layoutIdentByDefinition.has(value)) failAt(`${slidePath}@layout`, "unexpressible-value", "Slide references a SlideLayoutDefinition not uniquely owned by this deck");
|
|
471
|
+
} else if (value instanceof SlideLayoutContainer) {
|
|
472
|
+
if (!layoutIdentByContainer.has(value)) failAt(`${slidePath}@layout`, "unexpressible-value", "Slide references a SlideLayout not owned by this deck");
|
|
473
|
+
} else failAt(`${slidePath}@layout`, "unexpressible-value", "Slide.layout must be a SlideLayout or SlideLayoutDefinition");
|
|
474
|
+
slidePropsEntries.push([key, value]);
|
|
475
|
+
} else if (coreSlidePropKeys.has(key)) slidePropsEntries.push([key, value]);
|
|
476
|
+
else slidePropsEntries.push([key, resolveOwnerSlotProp(slidePath, key, value)]);
|
|
477
|
+
}
|
|
478
|
+
const slideMotionVars = /* @__PURE__ */ new Map();
|
|
479
|
+
currentMotionScopeVars = slideMotionVars;
|
|
480
|
+
currentScopeAllocator = target === "react" ? allocator.fork() : allocator;
|
|
481
|
+
const rawSlideLayout = slideNode.props["layout"];
|
|
482
|
+
currentSlideLayoutPlaceholders = isSlideLayoutDefinition(rawSlideLayout) ? rawSlideLayout.placeholders : rawSlideLayout instanceof SlideLayoutContainer ? rawSlideLayout.props["placeholders"] : void 0;
|
|
483
|
+
const childExprs = [];
|
|
484
|
+
try {
|
|
485
|
+
let childIdx = 0;
|
|
486
|
+
for (const child of slideNode.children) {
|
|
487
|
+
if (!(child instanceof CommonNode)) {
|
|
488
|
+
if (isDeclarationTextLeaf(child) && child.text.trim() !== "") failAt(slidePath, "invalid-document", "Slide cannot directly contain text content");
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
childExprs.push(emitNode(child, slidePath, childIdx));
|
|
492
|
+
childIdx += 1;
|
|
493
|
+
}
|
|
494
|
+
} finally {
|
|
495
|
+
currentMotionScopeVars = void 0;
|
|
496
|
+
currentScopeAllocator = void 0;
|
|
497
|
+
currentSlideLayoutPlaceholders = void 0;
|
|
498
|
+
}
|
|
499
|
+
const slideCtx = makeContext(slidePath);
|
|
500
|
+
if (target === "vanilla") {
|
|
501
|
+
const slideVar = allocator.allocate(toCamelCaseIdentifier(slideNode.id, `slide${slideIndex + 1}`, "Slide"));
|
|
502
|
+
const motionDecls = [...slideMotionVars.values()].map((handleVar) => `const ${handleVar} = ${useImport("createMotionScopeHandle")}();`);
|
|
503
|
+
const slideFn = useImport("slide");
|
|
504
|
+
const propsObj = slideCtx.formatProps(slidePropsEntries);
|
|
505
|
+
const slideDecl = `const ${slideVar} = ${slideCtx.formatVanillaCall(slideFn, [propsObj], childExprs)};`;
|
|
506
|
+
slideDeclarations.push([...motionDecls, slideDecl].join("\n"));
|
|
507
|
+
return slideVar;
|
|
508
|
+
}
|
|
509
|
+
const slideComponent = allocator.allocate(toPascalCaseIdentifier(slideNode.id, `Slide${slideIndex + 1}`, "Slide"));
|
|
510
|
+
const motionDecls = [...slideMotionVars.values()].map((handleVar) => `const ${handleVar} = ${useImport("useMotionScope")}();`);
|
|
511
|
+
const slideComp = useImport("Slide");
|
|
512
|
+
const slideJsx = slideCtx.formatJsxElement(slideComp, slidePropsEntries, childExprs);
|
|
513
|
+
const bodyLines = [
|
|
514
|
+
...motionDecls,
|
|
515
|
+
"return (",
|
|
516
|
+
indentBlock(slideJsx, 2),
|
|
517
|
+
");"
|
|
518
|
+
];
|
|
519
|
+
slideDeclarations.push(`function ${slideComponent}() {\n${indentBlock(bodyLines.join("\n"), 2)}\n}`);
|
|
520
|
+
return `<${slideComponent} />`;
|
|
521
|
+
};
|
|
522
|
+
const bodyRefsForDeck = [];
|
|
523
|
+
let slideCounter = 0;
|
|
524
|
+
if (usesSections) for (const [secIndex, sectionNode] of bodyNodes.entries()) {
|
|
525
|
+
const rawSectionName = sectionNode.props["name"];
|
|
526
|
+
const sectionPath = typeof rawSectionName === "string" && rawSectionName.trim() !== "" ? `deck/section[${rawSectionName}]` : `deck/section[${secIndex + 1}]`;
|
|
527
|
+
for (const [key, value] of Object.entries(sectionNode.props)) {
|
|
528
|
+
if (!isDefined(value)) continue;
|
|
529
|
+
if (key !== "name") failAt(`${sectionPath}@${key}`, "invalid-document", `Section does not support property ${JSON.stringify(key)}`);
|
|
530
|
+
}
|
|
531
|
+
if (typeof rawSectionName !== "string" || rawSectionName.trim() === "") failAt(sectionPath, "invalid-document", "Section.name must be a non-empty string");
|
|
532
|
+
const sectionSlideRefs = [];
|
|
533
|
+
for (const [memberIdx, member] of sectionNode.children.entries()) {
|
|
534
|
+
if (!(member instanceof CommonNode)) {
|
|
535
|
+
if (isDeclarationTextLeaf(member) && member.text.trim() !== "") failAt(sectionPath, "invalid-document", "Section can only contain Slide declarations");
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (member.type !== "slide") failAt(`${sectionPath}/${childPathLabel(member, memberIdx)}`, "invalid-document", "Section can only contain Slide declarations");
|
|
539
|
+
sectionSlideRefs.push(emitSlideDeclaration(member, slideCounter));
|
|
540
|
+
slideCounter += 1;
|
|
541
|
+
}
|
|
542
|
+
const secCtx = makeContext(sectionPath);
|
|
543
|
+
if (target === "vanilla") {
|
|
544
|
+
const sectionFn = useImport("section");
|
|
545
|
+
const arg = secCtx.formatProps([["name", rawSectionName]]);
|
|
546
|
+
bodyRefsForDeck.push(secCtx.formatVanillaCall(sectionFn, [arg], sectionSlideRefs));
|
|
547
|
+
} else {
|
|
548
|
+
const sectionComp = useImport("Section");
|
|
549
|
+
bodyRefsForDeck.push(secCtx.formatJsxElement(sectionComp, [["name", rawSectionName]], sectionSlideRefs));
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
else for (const slideNode of bodyNodes) {
|
|
553
|
+
bodyRefsForDeck.push(emitSlideDeclaration(slideNode, slideCounter));
|
|
554
|
+
slideCounter += 1;
|
|
555
|
+
}
|
|
556
|
+
const deckPropsEntries = [];
|
|
557
|
+
for (const [key, value] of Object.entries(document.props)) {
|
|
558
|
+
if (!isDefined(value)) continue;
|
|
559
|
+
deckPropsEntries.push([key, value]);
|
|
560
|
+
}
|
|
561
|
+
const deckCtx = makeContext("deck");
|
|
562
|
+
const deckChildren = [...masterRefsForDeck, ...bodyRefsForDeck];
|
|
563
|
+
let section4Code;
|
|
564
|
+
if (target === "vanilla") {
|
|
565
|
+
const deckFn = useImport("deck");
|
|
566
|
+
const deckArgs = deckPropsEntries.length === 0 ? [] : [deckCtx.formatProps(deckPropsEntries)];
|
|
567
|
+
section4Code = `export default ${deckCtx.formatVanillaCall(deckFn, deckArgs, deckChildren)};`;
|
|
568
|
+
} else {
|
|
569
|
+
const deckComp = useImport("Deck");
|
|
570
|
+
const deckJsx = deckCtx.formatJsxElement(deckComp, deckPropsEntries, deckChildren);
|
|
571
|
+
section4Code = `export default function GeneratedDeck() {\n return (\n${indentBlock(deckJsx, 4)}\n );\n}`;
|
|
572
|
+
}
|
|
573
|
+
const importLines = [];
|
|
574
|
+
if (nodeFsImports.size > 0) {
|
|
575
|
+
const sortedFs = [...nodeFsImports].toSorted();
|
|
576
|
+
importLines.push(`import { ${sortedFs.join(", ")} } from "node:fs";`);
|
|
577
|
+
}
|
|
578
|
+
if (sdkImports.size > 0) {
|
|
579
|
+
const sortedSdk = [...sdkImports].toSorted();
|
|
580
|
+
const moduleSpecifier = `@officedk/pptxdk/${target}`;
|
|
581
|
+
const singleLine = `import { ${sortedSdk.join(", ")} } from "${moduleSpecifier}";`;
|
|
582
|
+
importLines.push(singleLine.length <= 80 ? singleLine : `import {\n${indentBlock(sortedSdk.join(",\n"))},\n} from "${moduleSpecifier}";`);
|
|
583
|
+
}
|
|
584
|
+
const assetDeclarations = assets.entries.map((asset) => {
|
|
585
|
+
const urlExpr = `new URL(${JSON.stringify(`./${asset.relPath}`)}, import.meta.url)`;
|
|
586
|
+
if (asset.kind === "image") return `const ${asset.varName} = ${urlExpr};`;
|
|
587
|
+
return `const ${asset.varName} = new Uint8Array(\n readFileSync(${urlExpr}),\n);`;
|
|
588
|
+
});
|
|
589
|
+
const morphDeclarations = morphBuckets.map((bucket) => `const ${bucket.varName} = createMorphScope();`);
|
|
590
|
+
const entrySource = `${[
|
|
591
|
+
[
|
|
592
|
+
importLines.join("\n"),
|
|
593
|
+
assetDeclarations.join("\n"),
|
|
594
|
+
fontDeclarations.join("\n"),
|
|
595
|
+
themeDeclarations.join("\n"),
|
|
596
|
+
morphDeclarations.join("\n")
|
|
597
|
+
].filter((block) => block !== "").join("\n\n"),
|
|
598
|
+
masterGroupSections.join("\n\n"),
|
|
599
|
+
slideDeclarations.join("\n\n"),
|
|
600
|
+
section4Code
|
|
601
|
+
].filter((section) => section !== "").join("\n\n")}\n`;
|
|
602
|
+
const files = { [entry]: entrySource };
|
|
603
|
+
for (const asset of assets.entries) files[asset.relPath] = new Uint8Array(asset.bytes);
|
|
604
|
+
return Object.freeze({
|
|
605
|
+
target,
|
|
606
|
+
entry,
|
|
607
|
+
files: Object.freeze(files)
|
|
608
|
+
});
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
export { createCodegen };
|