@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,203 @@
|
|
|
1
|
+
// ../codegen/dist/identifiers.js
|
|
2
|
+
const reservedIdentifiers = /* @__PURE__ */ new Set([
|
|
3
|
+
"break",
|
|
4
|
+
"case",
|
|
5
|
+
"catch",
|
|
6
|
+
"class",
|
|
7
|
+
"const",
|
|
8
|
+
"continue",
|
|
9
|
+
"debugger",
|
|
10
|
+
"default",
|
|
11
|
+
"delete",
|
|
12
|
+
"do",
|
|
13
|
+
"else",
|
|
14
|
+
"enum",
|
|
15
|
+
"export",
|
|
16
|
+
"extends",
|
|
17
|
+
"false",
|
|
18
|
+
"finally",
|
|
19
|
+
"for",
|
|
20
|
+
"function",
|
|
21
|
+
"if",
|
|
22
|
+
"implements",
|
|
23
|
+
"import",
|
|
24
|
+
"in",
|
|
25
|
+
"instanceof",
|
|
26
|
+
"interface",
|
|
27
|
+
"let",
|
|
28
|
+
"new",
|
|
29
|
+
"null",
|
|
30
|
+
"package",
|
|
31
|
+
"private",
|
|
32
|
+
"protected",
|
|
33
|
+
"public",
|
|
34
|
+
"return",
|
|
35
|
+
"static",
|
|
36
|
+
"super",
|
|
37
|
+
"switch",
|
|
38
|
+
"this",
|
|
39
|
+
"throw",
|
|
40
|
+
"true",
|
|
41
|
+
"try",
|
|
42
|
+
"typeof",
|
|
43
|
+
"undefined",
|
|
44
|
+
"var",
|
|
45
|
+
"void",
|
|
46
|
+
"while",
|
|
47
|
+
"with",
|
|
48
|
+
"yield",
|
|
49
|
+
"await",
|
|
50
|
+
"async",
|
|
51
|
+
"as",
|
|
52
|
+
"from",
|
|
53
|
+
"of",
|
|
54
|
+
"type",
|
|
55
|
+
"declare",
|
|
56
|
+
"satisfies",
|
|
57
|
+
"Object",
|
|
58
|
+
"Array",
|
|
59
|
+
"Map",
|
|
60
|
+
"Set",
|
|
61
|
+
"URL",
|
|
62
|
+
"Uint8Array",
|
|
63
|
+
"Math",
|
|
64
|
+
"Number",
|
|
65
|
+
"String",
|
|
66
|
+
"Boolean",
|
|
67
|
+
"Symbol",
|
|
68
|
+
"Error",
|
|
69
|
+
"Promise",
|
|
70
|
+
"globalThis",
|
|
71
|
+
"process",
|
|
72
|
+
"console",
|
|
73
|
+
"readFileSync",
|
|
74
|
+
"deck",
|
|
75
|
+
"slide",
|
|
76
|
+
"slideMaster",
|
|
77
|
+
"slideLayout",
|
|
78
|
+
"defineSlideLayout",
|
|
79
|
+
"section",
|
|
80
|
+
"defineTheme",
|
|
81
|
+
"defaultTheme",
|
|
82
|
+
"darker",
|
|
83
|
+
"lighter",
|
|
84
|
+
"createMorphScope",
|
|
85
|
+
"font",
|
|
86
|
+
"linearGradient",
|
|
87
|
+
"radialGradient",
|
|
88
|
+
"transitions",
|
|
89
|
+
"preset",
|
|
90
|
+
"path",
|
|
91
|
+
"blockArc",
|
|
92
|
+
"createMotionScopeHandle",
|
|
93
|
+
"step",
|
|
94
|
+
"motionScope",
|
|
95
|
+
"after",
|
|
96
|
+
"appear",
|
|
97
|
+
"fade",
|
|
98
|
+
"wipe",
|
|
99
|
+
"zoom",
|
|
100
|
+
"fly",
|
|
101
|
+
"floatUp",
|
|
102
|
+
"floatDown",
|
|
103
|
+
"spinIn",
|
|
104
|
+
"stretch",
|
|
105
|
+
"spin",
|
|
106
|
+
"fillColor",
|
|
107
|
+
"breathe",
|
|
108
|
+
"disappear",
|
|
109
|
+
"fadeOut",
|
|
110
|
+
"wipeOut",
|
|
111
|
+
"flyOut",
|
|
112
|
+
"zoomOut",
|
|
113
|
+
"floatOut",
|
|
114
|
+
"spinOut",
|
|
115
|
+
"collapse",
|
|
116
|
+
"onStep",
|
|
117
|
+
"repeat",
|
|
118
|
+
"text",
|
|
119
|
+
"paragraph",
|
|
120
|
+
"span",
|
|
121
|
+
"slideNumber",
|
|
122
|
+
"notes",
|
|
123
|
+
"image",
|
|
124
|
+
"placeholder",
|
|
125
|
+
"shape",
|
|
126
|
+
"box",
|
|
127
|
+
"group",
|
|
128
|
+
"table",
|
|
129
|
+
"row",
|
|
130
|
+
"cell",
|
|
131
|
+
"chart",
|
|
132
|
+
"Deck",
|
|
133
|
+
"Slide",
|
|
134
|
+
"SlideMaster",
|
|
135
|
+
"SlideLayout",
|
|
136
|
+
"Section",
|
|
137
|
+
"Text",
|
|
138
|
+
"P",
|
|
139
|
+
"Span",
|
|
140
|
+
"SlideNumber",
|
|
141
|
+
"Notes",
|
|
142
|
+
"Image",
|
|
143
|
+
"Placeholder",
|
|
144
|
+
"Shape",
|
|
145
|
+
"Box",
|
|
146
|
+
"Group",
|
|
147
|
+
"Table",
|
|
148
|
+
"Row",
|
|
149
|
+
"Cell",
|
|
150
|
+
"Chart",
|
|
151
|
+
"Step",
|
|
152
|
+
"MotionScope",
|
|
153
|
+
"useMotionScope",
|
|
154
|
+
"GeneratedDeck"
|
|
155
|
+
]);
|
|
156
|
+
function splitAsciiWords(raw) {
|
|
157
|
+
const normalized = raw.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/[^A-Za-z0-9]+/gu, " ").trim();
|
|
158
|
+
if (normalized === "") return [];
|
|
159
|
+
return normalized.split(/\s+/u).filter((word) => word.length > 0);
|
|
160
|
+
}
|
|
161
|
+
function slugifyAscii(raw) {
|
|
162
|
+
return splitAsciiWords(raw).map((word) => word.toLowerCase()).join("-");
|
|
163
|
+
}
|
|
164
|
+
function toCamelCaseIdentifier(raw, fallbackBase, suffix = "") {
|
|
165
|
+
const words = raw === void 0 ? [] : splitAsciiWords(raw);
|
|
166
|
+
if (words.length === 0) return fallbackBase;
|
|
167
|
+
const camel = words.map((word, index) => {
|
|
168
|
+
const lower = word.toLowerCase();
|
|
169
|
+
if (index === 0) return lower;
|
|
170
|
+
return `${lower.charAt(0).toUpperCase()}${lower.slice(1)}`;
|
|
171
|
+
}).join("");
|
|
172
|
+
const prefixed = /^[A-Za-z_]/u.test(camel) ? camel : `${fallbackBase}${camel}`;
|
|
173
|
+
if (suffix !== "" && !prefixed.toLowerCase().endsWith(suffix.toLowerCase())) return `${prefixed}${suffix}`;
|
|
174
|
+
return prefixed;
|
|
175
|
+
}
|
|
176
|
+
function toPascalCaseIdentifier(raw, fallbackBase, suffix = "") {
|
|
177
|
+
const camel = toCamelCaseIdentifier(raw, fallbackBase, suffix);
|
|
178
|
+
const pascal = `${camel.charAt(0).toUpperCase()}${camel.slice(1)}`;
|
|
179
|
+
return /^[A-Z]/u.test(pascal) ? pascal : `${fallbackBase}${pascal}`;
|
|
180
|
+
}
|
|
181
|
+
/** Deterministic identifier allocator preventing collisions with keywords, globals, and SDK imports. */
|
|
182
|
+
var IdentifierAllocator = class IdentifierAllocator {
|
|
183
|
+
#used;
|
|
184
|
+
constructor(initialReserved = []) {
|
|
185
|
+
this.#used = /* @__PURE__ */ new Set([...reservedIdentifiers, ...initialReserved]);
|
|
186
|
+
}
|
|
187
|
+
allocate(baseCandidate) {
|
|
188
|
+
const clean = /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(baseCandidate) ? baseCandidate : "item";
|
|
189
|
+
if (!this.#used.has(clean)) {
|
|
190
|
+
this.#used.add(clean);
|
|
191
|
+
return clean;
|
|
192
|
+
}
|
|
193
|
+
let counter = 2;
|
|
194
|
+
while (this.#used.has(`${clean}${counter}`)) counter += 1;
|
|
195
|
+
const allocated = `${clean}${counter}`;
|
|
196
|
+
this.#used.add(allocated);
|
|
197
|
+
return allocated;
|
|
198
|
+
}
|
|
199
|
+
fork() {
|
|
200
|
+
return new IdentifierAllocator(this.#used);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
export { IdentifierAllocator, slugifyAscii, toCamelCaseIdentifier, toPascalCaseIdentifier };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createCodegen } from "./codegen.js";
|
|
2
|
+
import { CodegenError, codegenDiagnosticCodeSchema, codegenDiagnosticSchema, codegenOptionsSchema, codegenTargetSchema, defineObjectCodegen, defineSlideCodegen, expr } from "./types.js";
|
|
3
|
+
export { CodegenError, codegenDiagnosticCodeSchema, codegenDiagnosticSchema, codegenOptionsSchema, codegenTargetSchema, createCodegen, defineObjectCodegen, defineSlideCodegen, expr };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { isSchemeColorName } from "../../core/dist/theme.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { isCodegenExpr } from "./types.js";
|
|
4
|
+
// ../codegen/dist/printer.js
|
|
5
|
+
const identifierKeyPattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
6
|
+
const multilineThreshold = 72;
|
|
7
|
+
function indentBlock(text, spaces = 2) {
|
|
8
|
+
const prefix = " ".repeat(spaces);
|
|
9
|
+
return text.split("\n").map((line) => line === "" ? "" : `${prefix}${line}`).join("\n");
|
|
10
|
+
}
|
|
11
|
+
function isPlainRecord(value) {
|
|
12
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
13
|
+
const proto = Object.getPrototypeOf(value);
|
|
14
|
+
return proto === Object.prototype || proto === null;
|
|
15
|
+
}
|
|
16
|
+
function formatPropertyKey(key) {
|
|
17
|
+
return identifierKeyPattern.test(key) ? key : JSON.stringify(key);
|
|
18
|
+
}
|
|
19
|
+
function formatNumberLiteral(value) {
|
|
20
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
21
|
+
}
|
|
22
|
+
function tryFormatThemeShade(record, ctx) {
|
|
23
|
+
const keys = Object.keys(record).filter((key) => record[key] !== void 0);
|
|
24
|
+
if (keys.length < 2 || keys.length > 3) return void 0;
|
|
25
|
+
const slot = record["slot"];
|
|
26
|
+
const lumMod = record["lumMod"];
|
|
27
|
+
const lumOff = record["lumOff"];
|
|
28
|
+
if (typeof slot !== "string" || !isSchemeColorName(slot) || typeof lumMod !== "number" || !Number.isFinite(lumMod)) return;
|
|
29
|
+
for (const key of keys) if (key !== "slot" && key !== "lumMod" && key !== "lumOff") return;
|
|
30
|
+
if (typeof lumOff === "number" && Number.isFinite(lumOff) && Math.abs(lumMod + lumOff - 1) < 1e-12) return `${ctx.useImport("lighter")}(${JSON.stringify(slot)}, ${formatNumberLiteral(lumOff)})`;
|
|
31
|
+
if (lumOff === void 0) {
|
|
32
|
+
const amount = Number((1 - lumMod).toFixed(12));
|
|
33
|
+
if (1 - amount === lumMod) return `${ctx.useImport("darker")}(${JSON.stringify(slot)}, ${formatNumberLiteral(amount)})`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Formats an arbitrary author value as a TypeScript expression, throwing `CodegenError`
|
|
38
|
+
* via `ctx.fail("unexpressible-value", ...)` on non-finite numbers or unserializable objects.
|
|
39
|
+
*/
|
|
40
|
+
function formatTsValue(value, ctx, hooks, propPath = "") {
|
|
41
|
+
if (isCodegenExpr(value)) return value.code;
|
|
42
|
+
if (value === null) return "null";
|
|
43
|
+
if (value === void 0) return "undefined";
|
|
44
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
45
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
46
|
+
if (typeof value === "number") {
|
|
47
|
+
if (!Number.isFinite(value)) ctx.fail("unexpressible-value", `Non-finite number ${String(value)} cannot be expressed in TypeScript`, propPath);
|
|
48
|
+
return formatNumberLiteral(value);
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === "bigint" || typeof value === "symbol") ctx.fail("unexpressible-value", `Unsupported ${typeof value} value cannot be expressed in TypeScript`, propPath);
|
|
51
|
+
if (typeof value === "function") ctx.fail("unexpressible-value", "Function value cannot be expressed in generated source", propPath);
|
|
52
|
+
const special = hooks.serializeSpecial(value, propPath);
|
|
53
|
+
if (special !== void 0) return special;
|
|
54
|
+
if (value instanceof URL) return `new URL(${JSON.stringify(value.href)})`;
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
if (value.length === 0) return "[]";
|
|
57
|
+
const items = value.map((item, index) => formatTsValue(item, ctx, hooks, `${propPath}[${index}]`));
|
|
58
|
+
const singleLine = `[${items.join(", ")}]`;
|
|
59
|
+
if (!singleLine.includes("\n") && singleLine.length <= multilineThreshold) return singleLine;
|
|
60
|
+
return `[\n${indentBlock(items.join(",\n"))},\n]`;
|
|
61
|
+
}
|
|
62
|
+
if (!isPlainRecord(value)) ctx.fail("unexpressible-value", `Unsupported non-plain object value cannot be expressed in generated source`, propPath);
|
|
63
|
+
const shadeExpr = tryFormatThemeShade(value, ctx);
|
|
64
|
+
if (shadeExpr !== void 0) return shadeExpr;
|
|
65
|
+
const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0);
|
|
66
|
+
if (entries.length === 0) return "{}";
|
|
67
|
+
const formattedEntries = entries.map(([key, entryValue]) => {
|
|
68
|
+
const nextPath = propPath === "" ? `@${key}` : `${propPath}.${key}`;
|
|
69
|
+
return `${formatPropertyKey(key)}: ${formatTsValue(entryValue, ctx, hooks, nextPath)}`;
|
|
70
|
+
});
|
|
71
|
+
const singleLine = `{ ${formattedEntries.join(", ")} }`;
|
|
72
|
+
if (!singleLine.includes("\n") && singleLine.length <= multilineThreshold) return singleLine;
|
|
73
|
+
return `{\n${indentBlock(formattedEntries.join(",\n"))},\n}`;
|
|
74
|
+
}
|
|
75
|
+
function formatPropsObject(entries, ctx, hooks, basePath = "") {
|
|
76
|
+
const defined = entries.filter(([, value]) => value !== void 0);
|
|
77
|
+
if (defined.length === 0) return "{}";
|
|
78
|
+
const formatted = defined.map(([key, value]) => {
|
|
79
|
+
const nextPath = basePath === "" ? `@${key}` : `${basePath}.${key}`;
|
|
80
|
+
return `${formatPropertyKey(key)}: ${formatTsValue(value, ctx, hooks, nextPath)}`;
|
|
81
|
+
});
|
|
82
|
+
const singleLine = `{ ${formatted.join(", ")} }`;
|
|
83
|
+
if (!singleLine.includes("\n") && singleLine.length <= multilineThreshold) return singleLine;
|
|
84
|
+
return `{\n${indentBlock(formatted.join(",\n"))},\n}`;
|
|
85
|
+
}
|
|
86
|
+
const bareJsxUnsafeChars = /[&{}<>\r\n\t]/u;
|
|
87
|
+
/**
|
|
88
|
+
* Formats a `#text` declaration leaf for JSX children without losing leading/trailing spaces,
|
|
89
|
+
* repeated spaces, line breaks, or JSX-reserved characters.
|
|
90
|
+
*/
|
|
91
|
+
function formatJsxTextChild(text) {
|
|
92
|
+
if (text.length > 0 && text.trim() === text && !bareJsxUnsafeChars.test(text) && !/\s{2,}/u.test(text)) return text;
|
|
93
|
+
return `{${JSON.stringify(text)}}`;
|
|
94
|
+
}
|
|
95
|
+
function isSimpleJsxStringAttr(value) {
|
|
96
|
+
if (/["\\&\r\n\t]/u.test(value)) return false;
|
|
97
|
+
for (const ch of value) {
|
|
98
|
+
const code = ch.codePointAt(0);
|
|
99
|
+
if (code !== void 0 && (code < 32 || code === 127)) return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function formatJsxAttributes(entries, ctx, hooks, basePath = "") {
|
|
104
|
+
const attrs = [];
|
|
105
|
+
for (const [key, value] of entries) {
|
|
106
|
+
if (value === void 0) continue;
|
|
107
|
+
const nextPath = basePath === "" ? `@${key}` : `${basePath}.${key}`;
|
|
108
|
+
if (isCodegenExpr(value)) {
|
|
109
|
+
attrs.push(`${key}={${value.code}}`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (value === true) {
|
|
113
|
+
attrs.push(key);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (typeof value === "string" && isSimpleJsxStringAttr(value)) {
|
|
117
|
+
attrs.push(`${key}=${JSON.stringify(value)}`);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
attrs.push(`${key}={${formatTsValue(value, ctx, hooks, nextPath)}}`);
|
|
121
|
+
}
|
|
122
|
+
return attrs;
|
|
123
|
+
}
|
|
124
|
+
function formatJsxElement(tag, entries, children, ctx, hooks, basePath = "") {
|
|
125
|
+
const attrs = formatJsxAttributes(entries, ctx, hooks, basePath);
|
|
126
|
+
const inlineAttrs = attrs.join(" ");
|
|
127
|
+
const hasMultilineAttr = attrs.some((attr) => attr.includes("\n"));
|
|
128
|
+
const openTag = attrs.length === 0 ? `<${tag}` : !hasMultilineAttr && tag.length + inlineAttrs.length + 2 <= 80 ? `<${tag} ${inlineAttrs}` : `<${tag}\n${indentBlock(attrs.join("\n"))}\n`;
|
|
129
|
+
if (children.length === 0) return openTag.endsWith("\n") ? `${openTag}/>` : `${openTag} />`;
|
|
130
|
+
const head = openTag.endsWith("\n") ? `${openTag}>` : `${openTag}>`;
|
|
131
|
+
if (children.length === 1 && !children[0].includes("\n") && !head.includes("\n") && head.length + children[0].length + tag.length + 4 <= 80) return `${head}${children[0]}</${tag}>`;
|
|
132
|
+
return `${head}\n${indentBlock((children.length > 1 ? children.map((child) => child.startsWith("<") || child.startsWith("{") ? child : `{${JSON.stringify(child)}}`) : children).join("\n"))}\n</${tag}>`;
|
|
133
|
+
}
|
|
134
|
+
function formatVanillaCall(callee, args, children) {
|
|
135
|
+
const callArgs = args.join(", ");
|
|
136
|
+
const hasMultilineArg = args.some((arg) => arg.includes("\n"));
|
|
137
|
+
const baseCall = args.length === 0 ? `${callee}()` : !hasMultilineArg && callee.length + callArgs.length + 2 <= 80 ? `${callee}(${callArgs})` : `${callee}(\n${indentBlock(args.join(",\n"))},\n)`;
|
|
138
|
+
if (children.length === 0) return baseCall;
|
|
139
|
+
const singleLineChildren = children.join(", ");
|
|
140
|
+
if (!baseCall.includes("\n") && !singleLineChildren.includes("\n") && baseCall.length + singleLineChildren.length + 10 <= 80) return `${baseCall}.append(${singleLineChildren})`;
|
|
141
|
+
return `${baseCall}.append(\n${indentBlock(children.join(",\n"))},\n)`;
|
|
142
|
+
}
|
|
143
|
+
export { formatJsxAttributes, formatJsxElement, formatJsxTextChild, formatPropsObject, formatTsValue, formatVanillaCall, indentBlock };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ../codegen/dist/types.js
|
|
3
|
+
const rawCodegenTargetSchema = z.enum(["vanilla", "react"]);
|
|
4
|
+
/** Supported author source generation syntax targets. */
|
|
5
|
+
const codegenTargetSchema = rawCodegenTargetSchema;
|
|
6
|
+
/** Options controlling `codegen` target syntax output. */
|
|
7
|
+
const codegenOptionsSchema = z.object({ target: rawCodegenTargetSchema }).readonly();
|
|
8
|
+
const codegenDiagnosticCodeSchema = z.enum([
|
|
9
|
+
"invalid-document",
|
|
10
|
+
"invalid-options",
|
|
11
|
+
"unsupported-declaration",
|
|
12
|
+
"unsupported-slide-property",
|
|
13
|
+
"unexpressible-value"
|
|
14
|
+
]);
|
|
15
|
+
const codegenDiagnosticSchema = z.discriminatedUnion("code", [
|
|
16
|
+
z.strictObject({
|
|
17
|
+
code: z.literal("invalid-document"),
|
|
18
|
+
path: z.string(),
|
|
19
|
+
message: z.string(),
|
|
20
|
+
field: z.string().optional()
|
|
21
|
+
}),
|
|
22
|
+
z.strictObject({
|
|
23
|
+
code: z.literal("invalid-options"),
|
|
24
|
+
path: z.string(),
|
|
25
|
+
message: z.string(),
|
|
26
|
+
field: z.string().optional()
|
|
27
|
+
}),
|
|
28
|
+
z.strictObject({
|
|
29
|
+
code: z.literal("unsupported-declaration"),
|
|
30
|
+
path: z.string(),
|
|
31
|
+
message: z.string(),
|
|
32
|
+
field: z.string().optional(),
|
|
33
|
+
declaration: z.string()
|
|
34
|
+
}),
|
|
35
|
+
z.strictObject({
|
|
36
|
+
code: z.literal("unsupported-slide-property"),
|
|
37
|
+
path: z.string(),
|
|
38
|
+
message: z.string(),
|
|
39
|
+
field: z.string()
|
|
40
|
+
}),
|
|
41
|
+
z.strictObject({
|
|
42
|
+
code: z.literal("unexpressible-value"),
|
|
43
|
+
path: z.string(),
|
|
44
|
+
message: z.string(),
|
|
45
|
+
field: z.string().optional()
|
|
46
|
+
})
|
|
47
|
+
]);
|
|
48
|
+
/** Structured error thrown when an editable document cannot be expressed in generated source. */
|
|
49
|
+
var CodegenError = class extends Error {
|
|
50
|
+
diagnostics;
|
|
51
|
+
constructor(diagnostics) {
|
|
52
|
+
const first = diagnostics[0];
|
|
53
|
+
super(first === void 0 ? "Codegen failed" : `${first.path}: ${first.message} (${first.code})`);
|
|
54
|
+
this.name = "CodegenError";
|
|
55
|
+
this.diagnostics = Object.freeze([...diagnostics]);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const codegenExprBrand = Symbol("CodegenExpr");
|
|
59
|
+
/** Marks a raw TypeScript/JSX expression string produced by a capability serializer. */
|
|
60
|
+
function expr(code) {
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
[codegenExprBrand]: true,
|
|
63
|
+
code
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function isCodegenExpr(value) {
|
|
67
|
+
return typeof value === "object" && value !== null && codegenExprBrand in value && typeof value.code === "string";
|
|
68
|
+
}
|
|
69
|
+
/** Typed helper for authoring object capability `codegen` contributions. */
|
|
70
|
+
function defineObjectCodegen(contribution) {
|
|
71
|
+
return Object.freeze(contribution);
|
|
72
|
+
}
|
|
73
|
+
/** Typed helper for authoring slide capability `codegen` contributions. */
|
|
74
|
+
function defineSlideCodegen(contribution) {
|
|
75
|
+
return Object.freeze(contribution);
|
|
76
|
+
}
|
|
77
|
+
export { CodegenError, codegenDiagnosticCodeSchema, codegenDiagnosticSchema, codegenOptionsSchema, codegenTargetSchema, defineObjectCodegen, defineSlideCodegen, expr, isCodegenExpr };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { componentLabel, isDeclarationNode } from "./declaration.js";
|
|
2
|
+
import { BuildError } from "./diagnostics.js";
|
|
3
|
+
import { readInternalDeclarationProps } from "./document-internals.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ../core/dist/author-ids.js
|
|
6
|
+
/** Non-empty trimmed author identifier unique within its naming scope. */
|
|
7
|
+
const authorIdSchema = z.string().refine((value) => value.trim() !== "", { message: "id must be a non-empty string" });
|
|
8
|
+
/**
|
|
9
|
+
* Reads a declared author id, rejecting present but invalid values.
|
|
10
|
+
*
|
|
11
|
+
* Anonymous nodes omit the id. Present values must be non-empty strings; the formal build reports
|
|
12
|
+
* them once through the same path as other declaration errors.
|
|
13
|
+
*/
|
|
14
|
+
function readAuthorId(value, path) {
|
|
15
|
+
if (value === void 0) return void 0;
|
|
16
|
+
const parsed = authorIdSchema.safeParse(value);
|
|
17
|
+
if (!parsed.success) throw new BuildError([{
|
|
18
|
+
code: "invalid-prop",
|
|
19
|
+
path,
|
|
20
|
+
field: "id",
|
|
21
|
+
expected: "non-empty string",
|
|
22
|
+
message: "id must be a non-empty string"
|
|
23
|
+
}]);
|
|
24
|
+
return parsed.data;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates author ids on one page using the same scopes the author query traverses.
|
|
28
|
+
*
|
|
29
|
+
* A node's own id belongs to its parent scope; its descendants belong to a new scope only when the
|
|
30
|
+
* node declares an id. Anonymous layout nodes therefore stay transparent, while each page is the
|
|
31
|
+
* root author scope.
|
|
32
|
+
*/
|
|
33
|
+
function validateAuthorIdScopes(node, path, scope) {
|
|
34
|
+
node.children.forEach((child, index) => {
|
|
35
|
+
if (!isDeclarationNode(child)) return;
|
|
36
|
+
const childPath = `${path}/${componentLabel(child, index)}`;
|
|
37
|
+
const id = readAuthorId(readInternalDeclarationProps(child)["id"], childPath);
|
|
38
|
+
if (id !== void 0) {
|
|
39
|
+
if (scope.has(id)) throw new BuildError([{
|
|
40
|
+
code: "duplicate-id",
|
|
41
|
+
path: childPath,
|
|
42
|
+
field: "id",
|
|
43
|
+
identifier: id,
|
|
44
|
+
message: `Duplicate author id ${JSON.stringify(id)} in the same scope`
|
|
45
|
+
}]);
|
|
46
|
+
scope.add(id);
|
|
47
|
+
}
|
|
48
|
+
validateAuthorIdScopes(child, childPath, id === void 0 ? scope : /* @__PURE__ */ new Set());
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { authorIdSchema, readAuthorId, validateAuthorIdScopes };
|