@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,340 @@
|
|
|
1
|
+
import "../../../codegen/dist/index.js";
|
|
2
|
+
import { CommonNode } from "../../../core/dist/document.js";
|
|
3
|
+
import { defineObjectCodegen, expr } from "../../../codegen/dist/types.js";
|
|
4
|
+
import { breatheOptionsSchema, effectDelaySchema, effectOptionsSchema, emphasisEffectSchema, entranceEffectSchema, fillColorOptionsSchema, motionDirectionSchema, motionMomentOffsetSchema, motionMomentSchema, motionScopeHandleSchema, motionScopeModeSchema, motionStepAuthorPropsSchema, ownerMotionSchema, repeatCountSchema, spinOptionsSchema } from "./motion-schemas.js";
|
|
5
|
+
// ../capabilities/dist/motion/motion-codegen.js
|
|
6
|
+
const stepAllowedPropKeys = /* @__PURE__ */ new Set(["n", "stepIdentity"]);
|
|
7
|
+
const scopeAllowedPropKeys = /* @__PURE__ */ new Set([
|
|
8
|
+
"scope",
|
|
9
|
+
"mode",
|
|
10
|
+
"each",
|
|
11
|
+
"delay",
|
|
12
|
+
"startAt",
|
|
13
|
+
"publishStart",
|
|
14
|
+
"publishEnd",
|
|
15
|
+
"motion"
|
|
16
|
+
]);
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function subPropPath(ctx, segment) {
|
|
21
|
+
return ctx.path.includes("@") ? `${ctx.path}.${segment}` : `@${segment}`;
|
|
22
|
+
}
|
|
23
|
+
function emitContainerChildren(node, ctx, ownerLabel) {
|
|
24
|
+
const children = [];
|
|
25
|
+
let childIndex = 0;
|
|
26
|
+
for (const child of node.children) if (child instanceof CommonNode) {
|
|
27
|
+
children.push(ctx.emitChildNode(child, childIndex));
|
|
28
|
+
childIndex += 1;
|
|
29
|
+
} else if ("text" in child && typeof child.text === "string" && child.text.trim() !== "") ctx.fail("invalid-document", `${ownerLabel} cannot directly contain text content`);
|
|
30
|
+
return children;
|
|
31
|
+
}
|
|
32
|
+
function serializeMotionMomentValue(value, ctx, propSegment) {
|
|
33
|
+
const parsed = motionMomentSchema.safeParse(value);
|
|
34
|
+
if (!parsed.success) ctx.fail("unexpressible-value", "Expected a valid MotionMoment handle from a motion scope", subPropPath(ctx, propSegment));
|
|
35
|
+
const moment = parsed.data;
|
|
36
|
+
const scopeVar = ctx.allocateMotionScope(moment.scope);
|
|
37
|
+
if (moment.point === "start") return expr(`${scopeVar}.start`);
|
|
38
|
+
if (moment.point === "end") return expr(`${scopeVar}.end`);
|
|
39
|
+
return expr(`${scopeVar}.cue(${JSON.stringify(moment.name)})`);
|
|
40
|
+
}
|
|
41
|
+
function serializeMotionTimingValue(value, ctx, propSegment) {
|
|
42
|
+
if (isRecord(value) && value["type"] === "motion-offset") {
|
|
43
|
+
const rawOffset = value["offsetMs"];
|
|
44
|
+
if (typeof rawOffset === "number" && !Number.isFinite(rawOffset)) ctx.fail("unexpressible-value", `Non-finite number ${String(rawOffset)} cannot be expressed in TypeScript`, subPropPath(ctx, `${propSegment}.offsetMs`));
|
|
45
|
+
const parsed = motionMomentOffsetSchema.safeParse(value);
|
|
46
|
+
if (!parsed.success) ctx.fail("unexpressible-value", "Expected a valid MotionMomentOffset created by after(moment, offsetMs)", subPropPath(ctx, propSegment));
|
|
47
|
+
const offset = parsed.data;
|
|
48
|
+
const afterFn = ctx.useImport("after");
|
|
49
|
+
const momentExpr = serializeMotionMomentValue(offset.moment, ctx, `${propSegment}.moment`);
|
|
50
|
+
const offsetExpr = ctx.emitValueExpr(offset.offsetMs, subPropPath(ctx, `${propSegment}.offsetMs`));
|
|
51
|
+
return expr(`${afterFn}(${momentExpr.code}, ${offsetExpr})`);
|
|
52
|
+
}
|
|
53
|
+
return serializeMotionMomentValue(value, ctx, propSegment);
|
|
54
|
+
}
|
|
55
|
+
function collectStepProps(node, ctx) {
|
|
56
|
+
for (const [key, value] of Object.entries(node.props)) {
|
|
57
|
+
if (value === void 0) continue;
|
|
58
|
+
if (!stepAllowedPropKeys.has(key)) ctx.fail("invalid-document", `Step declaration does not support property ${JSON.stringify(key)}`, `@${key}`);
|
|
59
|
+
}
|
|
60
|
+
const rawN = node.props["n"];
|
|
61
|
+
if (rawN === void 0) return [];
|
|
62
|
+
if (typeof rawN === "number" && !Number.isFinite(rawN)) ctx.fail("unexpressible-value", `Non-finite number ${String(rawN)} cannot be expressed in TypeScript`, "@n");
|
|
63
|
+
const parsed = motionStepAuthorPropsSchema.safeParse({ n: rawN });
|
|
64
|
+
if (!parsed.success || parsed.data.n === void 0) ctx.fail("unexpressible-value", "Step.n must be a positive integer", "@n");
|
|
65
|
+
return [["n", parsed.data.n]];
|
|
66
|
+
}
|
|
67
|
+
function collectScopeProps(node, ctx) {
|
|
68
|
+
for (const [key, value] of Object.entries(node.props)) {
|
|
69
|
+
if (value === void 0) continue;
|
|
70
|
+
if (!scopeAllowedPropKeys.has(key)) ctx.fail("invalid-document", `MotionScope declaration does not support property ${JSON.stringify(key)}`, `@${key}`);
|
|
71
|
+
}
|
|
72
|
+
const parsedScope = motionScopeHandleSchema.safeParse(node.props["scope"]);
|
|
73
|
+
if (!parsedScope.success) ctx.fail("unexpressible-value", "MotionScope requires a handle created by createMotionScopeHandle() or useMotionScope()", "@scope");
|
|
74
|
+
const scopeVar = ctx.allocateMotionScope(parsedScope.data.identity);
|
|
75
|
+
const optionEntries = [];
|
|
76
|
+
const rawMode = node.props["mode"];
|
|
77
|
+
if (rawMode !== void 0) {
|
|
78
|
+
const parsedMode = motionScopeModeSchema.safeParse(rawMode);
|
|
79
|
+
if (!parsedMode.success) ctx.fail("unexpressible-value", "MotionScope.mode must be \"parallel\", \"sequence\", or \"stagger\"", "@mode");
|
|
80
|
+
optionEntries.push(["mode", parsedMode.data]);
|
|
81
|
+
}
|
|
82
|
+
const rawEach = node.props["each"];
|
|
83
|
+
if (rawEach !== void 0) {
|
|
84
|
+
if (typeof rawEach === "number" && !Number.isFinite(rawEach)) ctx.fail("unexpressible-value", `Non-finite number ${String(rawEach)} cannot be expressed in TypeScript`, "@each");
|
|
85
|
+
if (typeof rawEach !== "number" || !Number.isSafeInteger(rawEach) || rawEach < 0) ctx.fail("unexpressible-value", "MotionScope.each must be a non-negative integer", "@each");
|
|
86
|
+
optionEntries.push(["each", rawEach]);
|
|
87
|
+
}
|
|
88
|
+
const rawDelay = node.props["delay"];
|
|
89
|
+
if (rawDelay !== void 0) {
|
|
90
|
+
if (typeof rawDelay === "number" && !Number.isFinite(rawDelay)) ctx.fail("unexpressible-value", `Non-finite number ${String(rawDelay)} cannot be expressed in TypeScript`, "@delay");
|
|
91
|
+
const parsedDelay = effectDelaySchema.safeParse(rawDelay);
|
|
92
|
+
if (!parsedDelay.success) ctx.fail("unexpressible-value", "MotionScope.delay must be a finite non-negative integer in milliseconds", "@delay");
|
|
93
|
+
optionEntries.push(["delay", parsedDelay.data]);
|
|
94
|
+
}
|
|
95
|
+
const rawStartAt = node.props["startAt"];
|
|
96
|
+
if (rawStartAt !== void 0) optionEntries.push(["startAt", serializeMotionTimingValue(rawStartAt, ctx, "startAt")]);
|
|
97
|
+
const rawPublishStart = node.props["publishStart"];
|
|
98
|
+
if (rawPublishStart !== void 0) optionEntries.push(["publishStart", serializeMotionMomentValue(rawPublishStart, ctx, "publishStart")]);
|
|
99
|
+
const rawPublishEnd = node.props["publishEnd"];
|
|
100
|
+
if (rawPublishEnd !== void 0) optionEntries.push(["publishEnd", serializeMotionMomentValue(rawPublishEnd, ctx, "publishEnd")]);
|
|
101
|
+
const rawMotion = node.props["motion"];
|
|
102
|
+
if (rawMotion !== void 0) {
|
|
103
|
+
if (typeof rawMotion !== "boolean") ctx.fail("unexpressible-value", "MotionScope.motion must be a boolean", "@motion");
|
|
104
|
+
optionEntries.push(["motion", rawMotion]);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
scopeVar,
|
|
108
|
+
optionEntries
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function failAtSubPath(ctx, message, subPath) {
|
|
112
|
+
return ctx.fail("unexpressible-value", message, subPath);
|
|
113
|
+
}
|
|
114
|
+
function assertFiniteNumbersInRecord(value, ctx, basePath) {
|
|
115
|
+
if (typeof value === "number") {
|
|
116
|
+
if (!Number.isFinite(value)) failAtSubPath(ctx, `Non-finite number ${String(value)} cannot be expressed in TypeScript`, basePath);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
for (const [index, item] of value.entries()) assertFiniteNumbersInRecord(item, ctx, `${basePath}[${index}]`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!isRecord(value)) return;
|
|
124
|
+
for (const [key, entryValue] of Object.entries(value)) assertFiniteNumbersInRecord(entryValue, ctx, `${basePath}.${key}`);
|
|
125
|
+
}
|
|
126
|
+
function cleanEasing(easing) {
|
|
127
|
+
if (easing === void 0) return void 0;
|
|
128
|
+
const cleaned = {};
|
|
129
|
+
if (easing.accelerate !== void 0) cleaned["accelerate"] = easing.accelerate;
|
|
130
|
+
if (easing.decelerate !== void 0) cleaned["decelerate"] = easing.decelerate;
|
|
131
|
+
return Object.keys(cleaned).length === 0 ? void 0 : cleaned;
|
|
132
|
+
}
|
|
133
|
+
function serializeEffectCall(rawEffect, expectedKind, ctx, effectPath) {
|
|
134
|
+
if (!isRecord(rawEffect) || rawEffect["type"] !== "effect") failAtSubPath(ctx, "Expected a valid animation effect declaration", effectPath);
|
|
135
|
+
assertFiniteNumbersInRecord(rawEffect, ctx, effectPath);
|
|
136
|
+
let effect;
|
|
137
|
+
if (expectedKind === "entrance") {
|
|
138
|
+
const parsed = entranceEffectSchema.safeParse(rawEffect);
|
|
139
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid entrance animation effect", effectPath);
|
|
140
|
+
effect = parsed.data;
|
|
141
|
+
} else if (expectedKind === "emphasis") {
|
|
142
|
+
const parsed = emphasisEffectSchema.safeParse(rawEffect);
|
|
143
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid emphasis animation effect", effectPath);
|
|
144
|
+
effect = parsed.data;
|
|
145
|
+
} else {
|
|
146
|
+
const parsed = rawEffect["kind"] === "entrance" ? entranceEffectSchema.safeParse(rawEffect) : emphasisEffectSchema.safeParse(rawEffect);
|
|
147
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid animation effect", effectPath);
|
|
148
|
+
effect = parsed.data;
|
|
149
|
+
}
|
|
150
|
+
const easing = cleanEasing(effect.easing);
|
|
151
|
+
if (effect.preset === "breathe") {
|
|
152
|
+
if (Object.getOwnPropertySymbols(rawEffect).length > 0 || effect.from !== void 0 || effect.by !== void 0 || effect.intervalMs !== void 0) failAtSubPath(ctx, "breathe() contains unsupported parameters", effectPath);
|
|
153
|
+
const candidate = {
|
|
154
|
+
period: effect.duration,
|
|
155
|
+
from: effect.fromColor,
|
|
156
|
+
to: effect.toColor,
|
|
157
|
+
...effect.delay === 0 ? {} : { delay: effect.delay },
|
|
158
|
+
...easing === void 0 ? {} : { easing }
|
|
159
|
+
};
|
|
160
|
+
const parsed = breatheOptionsSchema.safeParse(candidate);
|
|
161
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid breathe() options", effectPath);
|
|
162
|
+
const fn = ctx.useImport("breathe");
|
|
163
|
+
const entries = [
|
|
164
|
+
["period", parsed.data.period],
|
|
165
|
+
["from", parsed.data.from],
|
|
166
|
+
["to", parsed.data.to],
|
|
167
|
+
...parsed.data.delay === void 0 || parsed.data.delay === 0 ? [] : [["delay", parsed.data.delay]],
|
|
168
|
+
...parsed.data.easing === void 0 ? [] : [["easing", parsed.data.easing]]
|
|
169
|
+
];
|
|
170
|
+
return expr(`${fn}(${ctx.formatProps(entries)})`);
|
|
171
|
+
}
|
|
172
|
+
if (effect.preset === "fillColor") {
|
|
173
|
+
if (effect.from !== void 0 || effect.by !== void 0 || effect.intervalMs !== void 0) failAtSubPath(ctx, "fillColor() contains unsupported parameters", effectPath);
|
|
174
|
+
const candidate = {
|
|
175
|
+
from: effect.fromColor,
|
|
176
|
+
to: effect.toColor,
|
|
177
|
+
...effect.duration === 500 ? {} : { duration: effect.duration },
|
|
178
|
+
...effect.delay === 0 ? {} : { delay: effect.delay },
|
|
179
|
+
...easing === void 0 ? {} : { easing }
|
|
180
|
+
};
|
|
181
|
+
const parsed = fillColorOptionsSchema.safeParse(candidate);
|
|
182
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid fillColor() options", effectPath);
|
|
183
|
+
const fn = ctx.useImport("fillColor");
|
|
184
|
+
const entries = [
|
|
185
|
+
["from", parsed.data.from],
|
|
186
|
+
["to", parsed.data.to],
|
|
187
|
+
...parsed.data.duration === void 0 ? [] : [["duration", parsed.data.duration]],
|
|
188
|
+
...parsed.data.delay === void 0 || parsed.data.delay === 0 ? [] : [["delay", parsed.data.delay]],
|
|
189
|
+
...parsed.data.easing === void 0 ? [] : [["easing", parsed.data.easing]]
|
|
190
|
+
];
|
|
191
|
+
return expr(`${fn}(${ctx.formatProps(entries)})`);
|
|
192
|
+
}
|
|
193
|
+
if (effect.fromColor !== void 0 || effect.toColor !== void 0) failAtSubPath(ctx, `${effect.preset}() does not accept color parameters`, effectPath);
|
|
194
|
+
if (effect.preset === "spin") {
|
|
195
|
+
const omitDefaultFrom = typeof effect.by !== "number" && effect.from === 360;
|
|
196
|
+
const candidate = {
|
|
197
|
+
...effect.from === void 0 || omitDefaultFrom ? {} : { from: effect.from },
|
|
198
|
+
...effect.duration === 1e3 ? {} : { duration: effect.duration },
|
|
199
|
+
...effect.delay === 0 ? {} : { delay: effect.delay },
|
|
200
|
+
...effect.by === void 0 ? {} : { by: effect.by },
|
|
201
|
+
...effect.intervalMs === void 0 ? {} : { intervalMs: effect.intervalMs },
|
|
202
|
+
...easing === void 0 ? {} : { easing }
|
|
203
|
+
};
|
|
204
|
+
const parsed = spinOptionsSchema.safeParse(candidate);
|
|
205
|
+
if (!parsed.success) failAtSubPath(ctx, parsed.error.issues[0]?.message ?? "Invalid spin() options", effectPath);
|
|
206
|
+
const fn = ctx.useImport("spin");
|
|
207
|
+
const entries = [];
|
|
208
|
+
if (parsed.data.from !== void 0) entries.push(["from", parsed.data.from]);
|
|
209
|
+
if (parsed.data.by !== void 0) entries.push(["by", parsed.data.by]);
|
|
210
|
+
if (parsed.data.duration !== void 0) entries.push(["duration", parsed.data.duration]);
|
|
211
|
+
if (parsed.data.delay !== void 0 && parsed.data.delay !== 0) entries.push(["delay", parsed.data.delay]);
|
|
212
|
+
if (parsed.data.intervalMs !== void 0) entries.push(["intervalMs", parsed.data.intervalMs]);
|
|
213
|
+
if (parsed.data.easing !== void 0) entries.push(["easing", parsed.data.easing]);
|
|
214
|
+
return expr(entries.length === 0 ? `${fn}()` : `${fn}(${ctx.formatProps(entries)})`);
|
|
215
|
+
}
|
|
216
|
+
const acceptsDirection = effect.preset === "wipe" || effect.preset === "fly";
|
|
217
|
+
if (!acceptsDirection && effect.from !== void 0) failAtSubPath(ctx, `${effect.preset}() does not accept from parameter`, `${effectPath}.from`);
|
|
218
|
+
if (acceptsDirection && effect.from !== void 0 && !motionDirectionSchema.safeParse(effect.from).success) failAtSubPath(ctx, `${effect.preset}() from must be a valid direction`, `${effectPath}.from`);
|
|
219
|
+
const baseCandidate = {
|
|
220
|
+
...effect.duration === 500 ? {} : { duration: effect.duration },
|
|
221
|
+
...effect.delay === 0 ? {} : { delay: effect.delay },
|
|
222
|
+
...effect.by === void 0 ? {} : { by: effect.by },
|
|
223
|
+
...effect.intervalMs === void 0 ? {} : { intervalMs: effect.intervalMs },
|
|
224
|
+
...easing === void 0 ? {} : { easing }
|
|
225
|
+
};
|
|
226
|
+
const parsedBase = effectOptionsSchema.safeParse(baseCandidate);
|
|
227
|
+
if (!parsedBase.success) failAtSubPath(ctx, parsedBase.error.issues[0]?.message ?? `Invalid ${effect.preset}() options`, effectPath);
|
|
228
|
+
const fn = ctx.useImport(effect.preset);
|
|
229
|
+
const entries = [];
|
|
230
|
+
if (acceptsDirection && effect.from !== void 0 && effect.from !== "bottom") entries.push(["from", effect.from]);
|
|
231
|
+
if (parsedBase.data.duration !== void 0) entries.push(["duration", parsedBase.data.duration]);
|
|
232
|
+
if (parsedBase.data.delay !== void 0 && parsedBase.data.delay !== 0) entries.push(["delay", parsedBase.data.delay]);
|
|
233
|
+
if (parsedBase.data.by !== void 0) entries.push(["by", parsedBase.data.by]);
|
|
234
|
+
if (parsedBase.data.intervalMs !== void 0) entries.push(["intervalMs", parsedBase.data.intervalMs]);
|
|
235
|
+
if (parsedBase.data.easing !== void 0) entries.push(["easing", parsedBase.data.easing]);
|
|
236
|
+
return expr(entries.length === 0 ? `${fn}()` : `${fn}(${ctx.formatProps(entries)})`);
|
|
237
|
+
}
|
|
238
|
+
function serializeEffectDeclarationExpr(rawDeclaration, expectedKind, ctx, declPath) {
|
|
239
|
+
if (isRecord(rawDeclaration) && rawDeclaration["type"] === "repeated-effect") {
|
|
240
|
+
const unknownKey = Object.keys(rawDeclaration).find((key) => key !== "type" && key !== "effect" && key !== "count");
|
|
241
|
+
if (unknownKey !== void 0) failAtSubPath(ctx, `repeat() contains unsupported field ${JSON.stringify(unknownKey)}`, `${declPath}.${unknownKey}`);
|
|
242
|
+
const rawCount = rawDeclaration["count"];
|
|
243
|
+
if (typeof rawCount === "number" && !Number.isFinite(rawCount)) failAtSubPath(ctx, `Non-finite number ${String(rawCount)} cannot be expressed in TypeScript`, `${declPath}.count`);
|
|
244
|
+
const parsedCount = repeatCountSchema.safeParse(rawCount);
|
|
245
|
+
if (!parsedCount.success) failAtSubPath(ctx, parsedCount.error.issues[0]?.message ?? "Invalid repeat count", `${declPath}.count`);
|
|
246
|
+
const innerExpr = serializeEffectCall(rawDeclaration["effect"], expectedKind, ctx, `${declPath}.effect`);
|
|
247
|
+
const repeatFn = ctx.useImport("repeat");
|
|
248
|
+
return expr(ctx.formatVanillaCall(repeatFn, [innerExpr.code, ctx.emitValueExpr(parsedCount.data, `${declPath}.count`)]));
|
|
249
|
+
}
|
|
250
|
+
return serializeEffectCall(rawDeclaration, expectedKind, ctx, declPath);
|
|
251
|
+
}
|
|
252
|
+
function serializeOwnerMotion(value, ctx) {
|
|
253
|
+
if (ctx.path.startsWith("deck/slide[")) ctx.fail("unsupported-slide-property", "Slide does not support owner motion property");
|
|
254
|
+
if (!isRecord(value)) failAtSubPath(ctx, "OwnerMotion must be an object", ctx.path);
|
|
255
|
+
assertFiniteNumbersInRecord(value, ctx, ctx.path);
|
|
256
|
+
const rawSteps = value["steps"];
|
|
257
|
+
if (!Array.isArray(rawSteps)) failAtSubPath(ctx, "OwnerMotion.steps must be an array", `${ctx.path}.steps`);
|
|
258
|
+
const parsedOwner = ownerMotionSchema.safeParse(value);
|
|
259
|
+
if (!parsedOwner.success) {
|
|
260
|
+
const issue = parsedOwner.error.issues[0];
|
|
261
|
+
const issuePath = issue !== void 0 && issue.path.length > 0 ? `${ctx.path}.${issue.path.join(".")}` : ctx.path;
|
|
262
|
+
failAtSubPath(ctx, issue?.message ?? "OwnerMotion declaration is invalid", issuePath);
|
|
263
|
+
}
|
|
264
|
+
const serializedSteps = parsedOwner.data.steps.map((step, stepIdx) => ({
|
|
265
|
+
trigger: step.trigger,
|
|
266
|
+
effects: step.effects.map((item, effectIdx) => {
|
|
267
|
+
const effectExpr = serializeEffectDeclarationExpr(item.effect, void 0, ctx, `${ctx.path}.steps[${stepIdx}].effects[${effectIdx}].effect`);
|
|
268
|
+
return {
|
|
269
|
+
target: item.target,
|
|
270
|
+
effect: effectExpr,
|
|
271
|
+
...item.range === void 0 ? {} : { range: item.range }
|
|
272
|
+
};
|
|
273
|
+
})
|
|
274
|
+
}));
|
|
275
|
+
return expr(ctx.formatProps([["steps", serializedSteps]]));
|
|
276
|
+
}
|
|
277
|
+
function serializeMotionValue(value, ctx) {
|
|
278
|
+
if (!isRecord(value)) return void 0;
|
|
279
|
+
const type = value["type"];
|
|
280
|
+
if (type === "motion-moment") return serializeMotionMomentValue(value, ctx, "moment");
|
|
281
|
+
if (type === "motion-offset") return serializeMotionTimingValue(value, ctx, "timing");
|
|
282
|
+
if (type === "effect" || type === "repeated-effect") return serializeEffectDeclarationExpr(value, void 0, ctx, ctx.path);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Source codegen contribution for `motion-step`, `motion-scope`, object motion properties
|
|
286
|
+
* (`enter`, `emphasis`, `motion`), and owner-level `OwnerMotion`.
|
|
287
|
+
*/
|
|
288
|
+
const motionCodegen = defineObjectCodegen({
|
|
289
|
+
declarations: {
|
|
290
|
+
"motion-step": {
|
|
291
|
+
emitVanilla(node, ctx) {
|
|
292
|
+
const callee = ctx.useImport("step");
|
|
293
|
+
const propsEntries = collectStepProps(node, ctx);
|
|
294
|
+
const args = propsEntries.length === 0 ? [] : [ctx.formatProps(propsEntries)];
|
|
295
|
+
const children = emitContainerChildren(node, ctx, "Step");
|
|
296
|
+
return ctx.formatVanillaCall(callee, args, children);
|
|
297
|
+
},
|
|
298
|
+
emitReact(node, ctx) {
|
|
299
|
+
const tag = ctx.useImport("Step");
|
|
300
|
+
const propsEntries = collectStepProps(node, ctx);
|
|
301
|
+
const children = emitContainerChildren(node, ctx, "Step");
|
|
302
|
+
return ctx.formatJsxElement(tag, propsEntries, children);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
"motion-scope": {
|
|
306
|
+
emitVanilla(node, ctx) {
|
|
307
|
+
const callee = ctx.useImport("motionScope");
|
|
308
|
+
const { scopeVar, optionEntries } = collectScopeProps(node, ctx);
|
|
309
|
+
const args = optionEntries.length === 0 ? [scopeVar] : [scopeVar, ctx.formatProps(optionEntries)];
|
|
310
|
+
const children = emitContainerChildren(node, ctx, "MotionScope");
|
|
311
|
+
return ctx.formatVanillaCall(callee, args, children);
|
|
312
|
+
},
|
|
313
|
+
emitReact(node, ctx) {
|
|
314
|
+
const tag = ctx.useImport("MotionScope");
|
|
315
|
+
const { scopeVar, optionEntries } = collectScopeProps(node, ctx);
|
|
316
|
+
const children = emitContainerChildren(node, ctx, "MotionScope");
|
|
317
|
+
return ctx.formatJsxElement(tag, [["scope", expr(scopeVar)], ...optionEntries], children);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
objectProps: {
|
|
322
|
+
enter(value, ctx) {
|
|
323
|
+
if (Array.isArray(value)) {
|
|
324
|
+
const items = value.map((item, index) => serializeEffectDeclarationExpr(item, "entrance", ctx, `${ctx.path}[${index}]`));
|
|
325
|
+
return expr(ctx.emitValueExpr(items));
|
|
326
|
+
}
|
|
327
|
+
return serializeEffectDeclarationExpr(value, "entrance", ctx, ctx.path);
|
|
328
|
+
},
|
|
329
|
+
emphasis(value, ctx) {
|
|
330
|
+
return serializeEffectDeclarationExpr(value, "emphasis", ctx, ctx.path);
|
|
331
|
+
},
|
|
332
|
+
motion(value, ctx) {
|
|
333
|
+
if (typeof value !== "boolean") ctx.fail("unexpressible-value", "Object motion property must be a boolean");
|
|
334
|
+
return expr(value ? "true" : "false");
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
ownerProps: { motion: serializeOwnerMotion },
|
|
338
|
+
valueSerializers: [serializeMotionValue]
|
|
339
|
+
});
|
|
340
|
+
export { motionCodegen };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { hostNodeCreator } from "../../../core/dist/host.js";
|
|
2
|
+
import { createMotionScopeHandle, createMotionScopeNode, createMotionStepIdentity, createMotionStepNode } from "./motion-api.js";
|
|
3
|
+
import "../box/box-elements.js";
|
|
4
|
+
import { createElement, useState } from "react";
|
|
5
|
+
// ../capabilities/dist/motion/motion-elements.js
|
|
6
|
+
/**
|
|
7
|
+
* Keeps one pure scope identity for the lifetime of this component instance.
|
|
8
|
+
*
|
|
9
|
+
* The React hook only stores the plain handle; scope parent chains, click steps, and inheritance are
|
|
10
|
+
* derived by the build from the document structure, so moving content does not carry React state.
|
|
11
|
+
*/
|
|
12
|
+
function useMotionScope() {
|
|
13
|
+
const [handle] = useState(createMotionScopeHandle);
|
|
14
|
+
return handle;
|
|
15
|
+
}
|
|
16
|
+
/** Explicit orchestration scope only declares timing relationships without creating layout or native objects. */
|
|
17
|
+
function MotionScope(props) {
|
|
18
|
+
const { children, ...declaration } = props;
|
|
19
|
+
return createElement("motion-scope", {
|
|
20
|
+
...declaration,
|
|
21
|
+
[hostNodeCreator]: createMotionScopeNode
|
|
22
|
+
}, children);
|
|
23
|
+
}
|
|
24
|
+
/** A single click triggers a group of objects; declarations with the same number share a click step. */
|
|
25
|
+
function Step(props) {
|
|
26
|
+
const { children, ...declaration } = props;
|
|
27
|
+
const [stepIdentity] = useState(createMotionStepIdentity);
|
|
28
|
+
return createElement("motion-step", {
|
|
29
|
+
...declaration,
|
|
30
|
+
stepIdentity,
|
|
31
|
+
[hostNodeCreator]: createMotionStepNode
|
|
32
|
+
}, children);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Passes local motion props to a native object host.
|
|
36
|
+
*
|
|
37
|
+
* Object capabilities emit only local declarations; inherited scope, step, default entrance, and
|
|
38
|
+
* disabled ancestors are resolved by the formal build from the current document.
|
|
39
|
+
*/
|
|
40
|
+
function motionElement(type, props) {
|
|
41
|
+
return createElement(type, props, props.children);
|
|
42
|
+
}
|
|
43
|
+
export { MotionScope, Step, motionElement, useMotionScope };
|