@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,2246 @@
|
|
|
1
|
+
import { readAuthorId, validateAuthorIdScopes } from "./author-ids.js";
|
|
2
|
+
import { parseDeckProps, parseLinkTarget, parseSectionProps, parseSlideCoreProps, xml10StringSchema } from "./author-schemas.js";
|
|
3
|
+
import { componentLabel, declarationIdentity, isDeclarationNode } from "./declaration.js";
|
|
4
|
+
import { BuildError, CapabilityError, capabilityErrorToDiagnostic, toBuildDiagnostic, zodIssueToBuildDiagnostic } from "./diagnostics.js";
|
|
5
|
+
import { readInternalDeclarationProps } from "./document-internals.js";
|
|
6
|
+
import { LayoutPass, validateBoundObjectCapability } from "./layout.js";
|
|
7
|
+
import { footerPlaceholdersSchema, isSlideLayoutDefinition, slideLayoutDataPropsSchema, slideMasterDataPropsSchema } from "./masters.js";
|
|
8
|
+
import { getMorphKeyLabel, isMorphKey } from "./morph.js";
|
|
9
|
+
import { masterTextStyleCategoryForRole, matchMasterPlaceholderSpec, nativePlaceholderRefSchema, resolvePlaceholderBoxFromLayers } from "./placeholders.js";
|
|
10
|
+
import { createBuildQuery } from "./query.js";
|
|
11
|
+
import { registerInternalResolution } from "./resolution.js";
|
|
12
|
+
import { resolveOptionsSchema } from "./stage-options.js";
|
|
13
|
+
import { createThemeContext, defaultColorMap, defineTheme, isFont, isTheme, textStyleFrom } from "./theme.js";
|
|
14
|
+
import { computeTransformedGeometry } from "./transform-geometry.js";
|
|
15
|
+
// ../core/dist/resolve.js
|
|
16
|
+
function createScopeRegistry() {
|
|
17
|
+
return {
|
|
18
|
+
targetsByAuthorId: /* @__PURE__ */ new Map(),
|
|
19
|
+
deferredTasks: [],
|
|
20
|
+
postFlushSyncs: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function diagnostic(path, code, message, details) {
|
|
24
|
+
return toBuildDiagnostic(path, code, message, details);
|
|
25
|
+
}
|
|
26
|
+
function deepFreeze(value) {
|
|
27
|
+
if (typeof value !== "object" || value === null || ArrayBuffer.isView(value)) return value;
|
|
28
|
+
if (!Object.isFrozen(value)) Object.freeze(value);
|
|
29
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function reportBox(box) {
|
|
33
|
+
return {
|
|
34
|
+
x: Math.round(box.x * 100) / 100,
|
|
35
|
+
y: Math.round(box.y * 100) / 100,
|
|
36
|
+
width: Math.round(box.width * 100) / 100,
|
|
37
|
+
height: Math.round(box.height * 100) / 100
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function projectObservation(observation, layoutDerivedObjectIds, transformsById, ancestorTransforms = []) {
|
|
41
|
+
const box = observation.box !== void 0 && layoutDerivedObjectIds.has(observation.id) ? reportBox(observation.box) : observation.box;
|
|
42
|
+
const rawOwn = transformsById.get(observation.id);
|
|
43
|
+
const ownTransform = rawOwn === void 0 ? void 0 : {
|
|
44
|
+
box: box ?? rawOwn.box,
|
|
45
|
+
angle: rawOwn.angle,
|
|
46
|
+
flipH: rawOwn.flipH,
|
|
47
|
+
flipV: rawOwn.flipV
|
|
48
|
+
};
|
|
49
|
+
const chain = ownTransform === void 0 ? ancestorTransforms : [ownTransform, ...ancestorTransforms];
|
|
50
|
+
const transformed = box === void 0 ? void 0 : computeTransformedGeometry(box, chain, ownTransform);
|
|
51
|
+
const members = observation.members === void 0 ? void 0 : observation.members.map((member) => projectObservation(member, layoutDerivedObjectIds, transformsById, chain));
|
|
52
|
+
return {
|
|
53
|
+
...observation,
|
|
54
|
+
...box === void 0 || box === observation.box ? {} : { box },
|
|
55
|
+
...transformed === void 0 ? {} : {
|
|
56
|
+
bounds: transformed.bounds,
|
|
57
|
+
...transformed.corners === void 0 ? {} : { corners: transformed.corners },
|
|
58
|
+
...transformed.transform === void 0 ? {} : { transform: transformed.transform }
|
|
59
|
+
},
|
|
60
|
+
...members === void 0 ? {} : { members }
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function projectObservations(observations, layoutDerivedObjectIds, transformsById) {
|
|
64
|
+
return observations.map((observation) => projectObservation(observation, layoutDerivedObjectIds, transformsById));
|
|
65
|
+
}
|
|
66
|
+
function isObjectCapability(module) {
|
|
67
|
+
return "bind" in module;
|
|
68
|
+
}
|
|
69
|
+
function nonWhitespaceText(children) {
|
|
70
|
+
return children.some((child) => !isDeclarationNode(child) && child.text.trim() !== "");
|
|
71
|
+
}
|
|
72
|
+
function childNodes(children) {
|
|
73
|
+
return children.filter(isDeclarationNode);
|
|
74
|
+
}
|
|
75
|
+
function capabilityChild(child) {
|
|
76
|
+
if (!isDeclarationNode(child)) return {
|
|
77
|
+
type: "#text",
|
|
78
|
+
text: child.text
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
type: child.type,
|
|
82
|
+
props: readInternalDeclarationProps(child),
|
|
83
|
+
children: child.children.map(capabilityChild),
|
|
84
|
+
...child.pageAffiliated === true ? { pageAffiliated: true } : {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function capabilityLabel(child, index) {
|
|
88
|
+
if (!("props" in child)) return `text[${index + 1}]`;
|
|
89
|
+
const identity = declarationIdentity(readInternalDeclarationProps(child));
|
|
90
|
+
const label = typeof identity === "string" && identity.trim() !== "" ? identity : String(index + 1);
|
|
91
|
+
return `${child.type}[${label}]`;
|
|
92
|
+
}
|
|
93
|
+
function isHiddenByStyle(node) {
|
|
94
|
+
const style = readInternalDeclarationProps(node)["style"];
|
|
95
|
+
return typeof style === "object" && style !== null && !Array.isArray(style) && "display" in style && style.display === "none";
|
|
96
|
+
}
|
|
97
|
+
function collectExplicitObjectNamesFromChildren(children, modules, names) {
|
|
98
|
+
for (const child of children) {
|
|
99
|
+
if (!isDeclarationNode(child) || isHiddenByStyle(child)) continue;
|
|
100
|
+
const module = modules.get(child.type);
|
|
101
|
+
if (module !== void 0 && "compileDeclaration" in module) {
|
|
102
|
+
if (module.children === "owned") continue;
|
|
103
|
+
collectExplicitObjectNamesFromChildren(child.children, modules, names);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const rawName = readInternalDeclarationProps(child)["name"];
|
|
107
|
+
if (typeof rawName === "string" && rawName.trim() !== "") names.add(rawName);
|
|
108
|
+
collectExplicitObjectNamesFromChildren(child.children, modules, names);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function collectExplicitObjectNames(slides, modules, extraChildren = []) {
|
|
112
|
+
const names = /* @__PURE__ */ new Set();
|
|
113
|
+
for (const slide of slides) collectExplicitObjectNamesFromChildren(slide.node.children, modules, names);
|
|
114
|
+
collectExplicitObjectNamesFromChildren(extraChildren, modules, names);
|
|
115
|
+
return names;
|
|
116
|
+
}
|
|
117
|
+
function nativeObjectName(key, document) {
|
|
118
|
+
let name = document.morphNames.get(key);
|
|
119
|
+
if (name === void 0) {
|
|
120
|
+
do
|
|
121
|
+
name = `!!morph-${document.nextMorphName++}`;
|
|
122
|
+
while (document.reservedObjectNames.has(name));
|
|
123
|
+
document.morphNames.set(key, name);
|
|
124
|
+
}
|
|
125
|
+
return name;
|
|
126
|
+
}
|
|
127
|
+
function validateResolveOptions(options) {
|
|
128
|
+
const parsed = resolveOptionsSchema.safeParse(options);
|
|
129
|
+
if (parsed.success) return;
|
|
130
|
+
const issue = parsed.error.issues[0];
|
|
131
|
+
if (issue === void 0) return;
|
|
132
|
+
if (issue.path.length === 0 && issue.code === "unrecognized_keys") {
|
|
133
|
+
const key = issue.keys[0] ?? "unknown";
|
|
134
|
+
throw new BuildError([diagnostic("resolve", "unknown-parameter", `Resolve options contain unknown parameter ${key}`, {
|
|
135
|
+
prop: key,
|
|
136
|
+
field: key,
|
|
137
|
+
scope: "options"
|
|
138
|
+
})]);
|
|
139
|
+
}
|
|
140
|
+
if (issue.path[0] === "signal") throw new BuildError([diagnostic("resolve.signal", "invalid-options", "Resolve options signal must be an AbortSignal", {
|
|
141
|
+
field: "signal",
|
|
142
|
+
expected: "AbortSignal"
|
|
143
|
+
})]);
|
|
144
|
+
throw new BuildError([diagnostic("resolve", "invalid-options", "Resolve options must be an object", { expected: "object" })]);
|
|
145
|
+
}
|
|
146
|
+
function unknownPropertyKey(props, allowed) {
|
|
147
|
+
const allowedSet = new Set(allowed);
|
|
148
|
+
return Object.keys(props).find((key) => !allowedSet.has(key));
|
|
149
|
+
}
|
|
150
|
+
function resolveSlides(container, modules, defaultDeckTheme) {
|
|
151
|
+
const decks = childNodes(container.children);
|
|
152
|
+
if (decks.length !== 1 || decks[0]?.type !== "deck") throw new BuildError([diagnostic("deck", "document-root", "Build content must have exactly one Deck root component")]);
|
|
153
|
+
const deck = decks[0];
|
|
154
|
+
if (deck === void 0) throw new BuildError([diagnostic("deck", "document-root", "Missing Deck root component")]);
|
|
155
|
+
if (nonWhitespaceText(container.children)) throw new BuildError([diagnostic("deck", "unexpected-text", "No text allowed outside the Deck root component")]);
|
|
156
|
+
if (nonWhitespaceText(deck.children)) throw new BuildError([diagnostic("deck", "unexpected-text", "Deck can only contain SlideMaster, Slide, and Section components")]);
|
|
157
|
+
const topLevel = childNodes(deck.children);
|
|
158
|
+
if (topLevel.length === 0 || topLevel.length !== deck.children.filter(isDeclarationNode).length) throw new BuildError([diagnostic("deck", "missing-slide", "Deck requires at least one Slide")]);
|
|
159
|
+
const masterNodes = topLevel.filter((node) => node.type === "slide-master");
|
|
160
|
+
const slideOrSectionNodes = topLevel.filter((node) => node.type !== "slide-master");
|
|
161
|
+
const authorIds = /* @__PURE__ */ new Set();
|
|
162
|
+
const slideProperties = [...modules.slideModules.values()].flatMap((module) => module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp]));
|
|
163
|
+
const slidePropertySet = new Set(slideProperties);
|
|
164
|
+
const knownTrimmedSlideProps = /* @__PURE__ */ new Set([
|
|
165
|
+
"transition",
|
|
166
|
+
"advanceAfter",
|
|
167
|
+
"motion"
|
|
168
|
+
]);
|
|
169
|
+
const masters = [];
|
|
170
|
+
const layoutKeyByNode = /* @__PURE__ */ new Map();
|
|
171
|
+
const layoutKeysByDefinition = /* @__PURE__ */ new Map();
|
|
172
|
+
const layoutIdByKey = /* @__PURE__ */ new Map();
|
|
173
|
+
let defaultBlankLayoutKey;
|
|
174
|
+
let firstLayoutKey;
|
|
175
|
+
let globalLayoutCounter = 0;
|
|
176
|
+
for (const [masterIndex, masterNode] of masterNodes.entries()) {
|
|
177
|
+
const rawMasterPath = `deck/slide-master[${masterIndex + 1}]`;
|
|
178
|
+
const masterProps = readInternalDeclarationProps(masterNode);
|
|
179
|
+
const masterAuthorId = readAuthorId(masterProps["id"], rawMasterPath);
|
|
180
|
+
const masterKey = `master-${masterIndex + 1}`;
|
|
181
|
+
const masterId = masterAuthorId ?? masterKey;
|
|
182
|
+
const masterPath = `deck/slide-master[${masterAuthorId ?? masterIndex + 1}]`;
|
|
183
|
+
const unknownMasterProp = unknownPropertyKey(masterProps, [
|
|
184
|
+
"id",
|
|
185
|
+
"name",
|
|
186
|
+
"preserve",
|
|
187
|
+
"theme",
|
|
188
|
+
"colorMap",
|
|
189
|
+
"style",
|
|
190
|
+
"background",
|
|
191
|
+
"headerFooter",
|
|
192
|
+
"footerPlaceholders",
|
|
193
|
+
"placeholders",
|
|
194
|
+
"textStyles",
|
|
195
|
+
...slideProperties
|
|
196
|
+
]);
|
|
197
|
+
if (unknownMasterProp !== void 0) {
|
|
198
|
+
if (knownTrimmedSlideProps.has(unknownMasterProp)) throw new BuildError([diagnostic(masterPath, "missing-capability", `No capability module registered for SlideMaster.${unknownMasterProp}`, {
|
|
199
|
+
capability: unknownMasterProp,
|
|
200
|
+
field: unknownMasterProp
|
|
201
|
+
})]);
|
|
202
|
+
throw new BuildError([diagnostic(masterPath, "unknown-parameter", `SlideMaster contains unknown parameter ${unknownMasterProp}`, {
|
|
203
|
+
prop: unknownMasterProp,
|
|
204
|
+
field: unknownMasterProp,
|
|
205
|
+
scope: "props"
|
|
206
|
+
})]);
|
|
207
|
+
}
|
|
208
|
+
const masterDataInput = {};
|
|
209
|
+
for (const key of [
|
|
210
|
+
"id",
|
|
211
|
+
"name",
|
|
212
|
+
"preserve",
|
|
213
|
+
"colorMap",
|
|
214
|
+
"style",
|
|
215
|
+
"background",
|
|
216
|
+
"headerFooter",
|
|
217
|
+
"footerPlaceholders",
|
|
218
|
+
"placeholders",
|
|
219
|
+
"textStyles"
|
|
220
|
+
]) if (Object.hasOwn(masterProps, key)) masterDataInput[key] = masterProps[key];
|
|
221
|
+
const parsedMaster = slideMasterDataPropsSchema.safeParse(masterDataInput);
|
|
222
|
+
if (!parsedMaster.success) {
|
|
223
|
+
const firstIssue = parsedMaster.error.issues[0];
|
|
224
|
+
throw new BuildError([zodIssueToBuildDiagnostic(masterPath, "invalid-slide-master", "Invalid SlideMaster declaration", firstIssue)]);
|
|
225
|
+
}
|
|
226
|
+
let masterTheme;
|
|
227
|
+
const rawMasterTheme = masterProps["theme"];
|
|
228
|
+
if (rawMasterTheme === void 0) masterTheme = defaultDeckTheme;
|
|
229
|
+
else if (isTheme(rawMasterTheme)) masterTheme = rawMasterTheme;
|
|
230
|
+
else try {
|
|
231
|
+
masterTheme = defineTheme(rawMasterTheme);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (error instanceof CapabilityError) throw new BuildError([capabilityErrorToDiagnostic(error, masterPath)]);
|
|
234
|
+
throw new BuildError([diagnostic(masterPath, "invalid-theme", error instanceof Error ? error.message : String(error), { field: "theme" })]);
|
|
235
|
+
}
|
|
236
|
+
if (masterAuthorId !== void 0) {
|
|
237
|
+
if (!xml10StringSchema.safeParse(masterAuthorId).success) throw new BuildError([diagnostic(masterPath, "invalid-xml-character", "SlideMaster.id contains characters not allowed in XML 1.0", { field: "id" })]);
|
|
238
|
+
if (authorIds.has(masterAuthorId)) throw new BuildError([diagnostic(masterPath, "duplicate-author-id", `Duplicate author id ${JSON.stringify(masterAuthorId)} in the deck`, {
|
|
239
|
+
field: "id",
|
|
240
|
+
identifier: masterAuthorId
|
|
241
|
+
})]);
|
|
242
|
+
authorIds.add(masterAuthorId);
|
|
243
|
+
}
|
|
244
|
+
if (parsedMaster.data.name !== void 0 && !xml10StringSchema.safeParse(parsedMaster.data.name).success) throw new BuildError([diagnostic(masterPath, "invalid-xml-character", "SlideMaster.name contains characters not allowed in XML 1.0")]);
|
|
245
|
+
for (const phSpec of Object.values(parsedMaster.data.placeholders ?? {})) for (const phText of [phSpec.name, phSpec.promptText]) {
|
|
246
|
+
if (phText === void 0) continue;
|
|
247
|
+
if (!xml10StringSchema.safeParse(phText).success) throw new BuildError([diagnostic(masterPath, "invalid-xml-character", "SlideMaster placeholder text contains characters not allowed in XML 1.0")]);
|
|
248
|
+
}
|
|
249
|
+
if (nonWhitespaceText(masterNode.children)) throw new BuildError([diagnostic(masterPath, "unexpected-text", "SlideMaster cannot directly contain text")]);
|
|
250
|
+
const masterChildren = childNodes(masterNode.children);
|
|
251
|
+
const layoutNodes = [];
|
|
252
|
+
const masterCanvasNodes = [];
|
|
253
|
+
for (const child of masterChildren) if (child.type === "slide-layout") layoutNodes.push(child);
|
|
254
|
+
else masterCanvasNodes.push(child);
|
|
255
|
+
if (layoutNodes.length === 0) throw new BuildError([diagnostic(masterPath, "empty-slide-master", "SlideMaster requires at least one SlideLayout")]);
|
|
256
|
+
const masterLayoutIds = /* @__PURE__ */ new Set();
|
|
257
|
+
const resolvedLayouts = [];
|
|
258
|
+
for (const [layoutIndex, layoutNode] of layoutNodes.entries()) {
|
|
259
|
+
const rawLayoutPath = `${masterPath}/slide-layout[${layoutIndex + 1}]`;
|
|
260
|
+
const layoutProps = readInternalDeclarationProps(layoutNode);
|
|
261
|
+
const rawLayoutDef = layoutProps["layout"];
|
|
262
|
+
let layoutDef;
|
|
263
|
+
if (rawLayoutDef !== void 0) {
|
|
264
|
+
if (!isSlideLayoutDefinition(rawLayoutDef)) throw new BuildError([diagnostic(rawLayoutPath, "invalid-slide-layout", "SlideLayout.layout must be created by defineSlideLayout()")]);
|
|
265
|
+
layoutDef = rawLayoutDef;
|
|
266
|
+
}
|
|
267
|
+
const effectiveLayoutProps = { ...layoutDef?.props };
|
|
268
|
+
for (const [key, value] of Object.entries(layoutProps)) {
|
|
269
|
+
if (key === "layout" || value === void 0) continue;
|
|
270
|
+
effectiveLayoutProps[key] = value;
|
|
271
|
+
}
|
|
272
|
+
const unknownLayoutProp = unknownPropertyKey(effectiveLayoutProps, [
|
|
273
|
+
"id",
|
|
274
|
+
"name",
|
|
275
|
+
"type",
|
|
276
|
+
"preserve",
|
|
277
|
+
"matchingName",
|
|
278
|
+
"userDrawn",
|
|
279
|
+
"showMasterShapes",
|
|
280
|
+
"showMasterPlaceholderAnimations",
|
|
281
|
+
"placeholders",
|
|
282
|
+
"colorMapOverride",
|
|
283
|
+
"themeOverride",
|
|
284
|
+
"style",
|
|
285
|
+
"background",
|
|
286
|
+
"headerFooter",
|
|
287
|
+
"footerPlaceholders",
|
|
288
|
+
...slideProperties
|
|
289
|
+
]);
|
|
290
|
+
if (unknownLayoutProp !== void 0) {
|
|
291
|
+
if (knownTrimmedSlideProps.has(unknownLayoutProp)) throw new BuildError([diagnostic(rawLayoutPath, "missing-capability", `No capability module registered for SlideLayout.${unknownLayoutProp}`, {
|
|
292
|
+
capability: unknownLayoutProp,
|
|
293
|
+
field: unknownLayoutProp
|
|
294
|
+
})]);
|
|
295
|
+
throw new BuildError([diagnostic(rawLayoutPath, "unknown-parameter", `SlideLayout contains unknown parameter ${unknownLayoutProp}`, {
|
|
296
|
+
prop: unknownLayoutProp,
|
|
297
|
+
field: unknownLayoutProp,
|
|
298
|
+
scope: "props"
|
|
299
|
+
})]);
|
|
300
|
+
}
|
|
301
|
+
const layoutDataInput = {};
|
|
302
|
+
for (const key of [
|
|
303
|
+
"id",
|
|
304
|
+
"name",
|
|
305
|
+
"type",
|
|
306
|
+
"preserve",
|
|
307
|
+
"matchingName",
|
|
308
|
+
"userDrawn",
|
|
309
|
+
"showMasterShapes",
|
|
310
|
+
"showMasterPlaceholderAnimations",
|
|
311
|
+
"placeholders",
|
|
312
|
+
"colorMapOverride",
|
|
313
|
+
"themeOverride",
|
|
314
|
+
"style",
|
|
315
|
+
"background",
|
|
316
|
+
"headerFooter",
|
|
317
|
+
"footerPlaceholders"
|
|
318
|
+
]) if (Object.hasOwn(effectiveLayoutProps, key)) layoutDataInput[key] = effectiveLayoutProps[key];
|
|
319
|
+
const parsedLayout = slideLayoutDataPropsSchema.safeParse(layoutDataInput);
|
|
320
|
+
if (!parsedLayout.success) {
|
|
321
|
+
const firstIssue = parsedLayout.error.issues[0];
|
|
322
|
+
throw new BuildError([zodIssueToBuildDiagnostic(rawLayoutPath, "invalid-slide-layout", "Invalid SlideLayout declaration", firstIssue)]);
|
|
323
|
+
}
|
|
324
|
+
const layoutAuthorId = readAuthorId(parsedLayout.data.id, rawLayoutPath);
|
|
325
|
+
const layoutId = layoutAuthorId ?? `layout-${layoutIndex + 1}`;
|
|
326
|
+
const layoutPath = `${masterPath}/slide-layout[${layoutAuthorId ?? layoutIndex + 1}]`;
|
|
327
|
+
if (layoutAuthorId !== void 0) {
|
|
328
|
+
if (masterLayoutIds.has(layoutAuthorId)) throw new BuildError([diagnostic(layoutPath, "duplicate-author-id", `Duplicate SlideLayout.id ${JSON.stringify(layoutAuthorId)} in ${masterPath}`, {
|
|
329
|
+
field: "id",
|
|
330
|
+
identifier: layoutAuthorId
|
|
331
|
+
})]);
|
|
332
|
+
masterLayoutIds.add(layoutAuthorId);
|
|
333
|
+
}
|
|
334
|
+
for (const textField of [
|
|
335
|
+
parsedLayout.data.id,
|
|
336
|
+
parsedLayout.data.name,
|
|
337
|
+
parsedLayout.data.matchingName
|
|
338
|
+
]) {
|
|
339
|
+
if (textField === void 0) continue;
|
|
340
|
+
if (!xml10StringSchema.safeParse(textField).success) throw new BuildError([diagnostic(layoutPath, "invalid-xml-character", "SlideLayout text property contains characters not allowed in XML 1.0")]);
|
|
341
|
+
}
|
|
342
|
+
for (const phSpec of Object.values(parsedLayout.data.placeholders ?? {})) for (const phText of [phSpec.name, phSpec.promptText]) {
|
|
343
|
+
if (phText === void 0) continue;
|
|
344
|
+
if (!xml10StringSchema.safeParse(phText).success) throw new BuildError([diagnostic(layoutPath, "invalid-xml-character", "SlideLayout placeholder text contains characters not allowed in XML 1.0")]);
|
|
345
|
+
}
|
|
346
|
+
validateAuthorIdScopes(layoutNode, layoutPath, /* @__PURE__ */ new Set());
|
|
347
|
+
if (nonWhitespaceText(layoutNode.children)) throw new BuildError([diagnostic(layoutPath, "unexpected-text", "SlideLayout cannot directly contain text")]);
|
|
348
|
+
const layoutKey = `layout-${++globalLayoutCounter}`;
|
|
349
|
+
layoutKeyByNode.set(layoutNode, layoutKey);
|
|
350
|
+
if (layoutDef !== void 0) {
|
|
351
|
+
const existing = layoutKeysByDefinition.get(layoutDef) ?? [];
|
|
352
|
+
existing.push(layoutKey);
|
|
353
|
+
layoutKeysByDefinition.set(layoutDef, existing);
|
|
354
|
+
}
|
|
355
|
+
layoutIdByKey.set(layoutKey, layoutId);
|
|
356
|
+
firstLayoutKey ??= layoutKey;
|
|
357
|
+
if (parsedLayout.data.type === "blank" && defaultBlankLayoutKey === void 0) defaultBlankLayoutKey = layoutKey;
|
|
358
|
+
const layoutData = {
|
|
359
|
+
id: layoutId,
|
|
360
|
+
...parsedLayout.data.name === void 0 ? {} : { name: parsedLayout.data.name },
|
|
361
|
+
...parsedLayout.data.type === void 0 ? {} : { type: parsedLayout.data.type },
|
|
362
|
+
...parsedLayout.data.preserve === void 0 ? {} : { preserve: parsedLayout.data.preserve },
|
|
363
|
+
...parsedLayout.data.matchingName === void 0 ? {} : { matchingName: parsedLayout.data.matchingName },
|
|
364
|
+
...parsedLayout.data.userDrawn === void 0 ? {} : { userDrawn: parsedLayout.data.userDrawn },
|
|
365
|
+
...parsedLayout.data.showMasterShapes === void 0 ? {} : { showMasterShapes: parsedLayout.data.showMasterShapes },
|
|
366
|
+
...parsedLayout.data.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsedLayout.data.showMasterPlaceholderAnimations },
|
|
367
|
+
...parsedLayout.data.colorMapOverride === void 0 ? {} : { colorMapOverride: parsedLayout.data.colorMapOverride },
|
|
368
|
+
...parsedLayout.data.themeOverride === void 0 ? {} : { themeOverride: parsedLayout.data.themeOverride },
|
|
369
|
+
...parsedLayout.data.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.data.headerFooter }
|
|
370
|
+
};
|
|
371
|
+
const reservedFooterIndices = [];
|
|
372
|
+
for (const footerSource of [parsedMaster.data.footerPlaceholders, parsedLayout.data.footerPlaceholders]) {
|
|
373
|
+
if (footerSource === void 0) continue;
|
|
374
|
+
if (footerSource.dateTime !== void 0) reservedFooterIndices.push(footerSource.dateTime.idx ?? 2);
|
|
375
|
+
if (footerSource.footer !== void 0) reservedFooterIndices.push(footerSource.footer.idx ?? 3);
|
|
376
|
+
if (footerSource.slideNumber !== void 0) reservedFooterIndices.push(footerSource.slideNumber.idx ?? 4);
|
|
377
|
+
}
|
|
378
|
+
const normalizedLayoutPlaceholders = normalizeLayoutPlaceholderIndices(parsedLayout.data.placeholders, reservedFooterIndices);
|
|
379
|
+
const layoutSlideProps = normalizedLayoutPlaceholders === void 0 ? {} : { placeholders: normalizedLayoutPlaceholders };
|
|
380
|
+
for (const prop of slidePropertySet) {
|
|
381
|
+
if (prop === "background") continue;
|
|
382
|
+
if (Object.hasOwn(effectiveLayoutProps, prop)) layoutSlideProps[prop] = effectiveLayoutProps[prop];
|
|
383
|
+
}
|
|
384
|
+
const effectiveLayoutBackground = parsedLayout.data.style?.background ?? parsedLayout.data.background;
|
|
385
|
+
resolvedLayouts.push({
|
|
386
|
+
node: layoutNode,
|
|
387
|
+
key: layoutKey,
|
|
388
|
+
path: layoutPath,
|
|
389
|
+
data: layoutData,
|
|
390
|
+
...normalizedLayoutPlaceholders === void 0 ? {} : { placeholders: normalizedLayoutPlaceholders },
|
|
391
|
+
...parsedLayout.data.style === void 0 ? {} : { style: parsedLayout.data.style },
|
|
392
|
+
...effectiveLayoutBackground === void 0 ? {} : { background: effectiveLayoutBackground },
|
|
393
|
+
...parsedLayout.data.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.data.headerFooter },
|
|
394
|
+
...parsedLayout.data.footerPlaceholders === void 0 ? {} : { footerPlaceholders: parsedLayout.data.footerPlaceholders },
|
|
395
|
+
props: layoutSlideProps
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (masterCanvasNodes.length > 0) validateAuthorIdScopes({
|
|
399
|
+
type: "slide-master",
|
|
400
|
+
props: masterProps,
|
|
401
|
+
children: masterCanvasNodes
|
|
402
|
+
}, masterPath, new Set(masterLayoutIds));
|
|
403
|
+
const masterSlideProps = parsedMaster.data.placeholders === void 0 ? {} : { placeholders: parsedMaster.data.placeholders };
|
|
404
|
+
for (const prop of slidePropertySet) {
|
|
405
|
+
if (prop === "background") continue;
|
|
406
|
+
if (Object.hasOwn(masterProps, prop)) masterSlideProps[prop] = masterProps[prop];
|
|
407
|
+
}
|
|
408
|
+
const masterStyleProp = masterProps["style"];
|
|
409
|
+
const effectiveMasterBackground = parsedMaster.data.style?.background ?? parsedMaster.data.background;
|
|
410
|
+
masters.push({
|
|
411
|
+
node: masterNode,
|
|
412
|
+
canvasChildren: masterCanvasNodes,
|
|
413
|
+
key: masterKey,
|
|
414
|
+
id: masterId,
|
|
415
|
+
path: masterPath,
|
|
416
|
+
...parsedMaster.data.name === void 0 ? {} : { name: parsedMaster.data.name },
|
|
417
|
+
...parsedMaster.data.preserve === void 0 ? {} : { preserve: parsedMaster.data.preserve },
|
|
418
|
+
theme: masterTheme,
|
|
419
|
+
colorMap: parsedMaster.data.colorMap ?? defaultColorMap,
|
|
420
|
+
...parsedMaster.data.colorMap === void 0 ? {} : { explicitColorMap: parsedMaster.data.colorMap },
|
|
421
|
+
...masterStyleProp !== void 0 && typeof masterStyleProp === "object" && masterStyleProp !== null && !Array.isArray(masterStyleProp) ? { style: masterStyleProp } : {},
|
|
422
|
+
...parsedMaster.data.placeholders === void 0 ? {} : { placeholders: parsedMaster.data.placeholders },
|
|
423
|
+
...parsedMaster.data.textStyles === void 0 ? {} : { textStyles: parsedMaster.data.textStyles },
|
|
424
|
+
...effectiveMasterBackground === void 0 ? {} : { background: effectiveMasterBackground },
|
|
425
|
+
...parsedMaster.data.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.data.headerFooter },
|
|
426
|
+
...parsedMaster.data.footerPlaceholders === void 0 ? {} : { footerPlaceholders: parsedMaster.data.footerPlaceholders },
|
|
427
|
+
props: masterSlideProps,
|
|
428
|
+
layouts: resolvedLayouts
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
const sectioned = slideOrSectionNodes.some((node) => node.type === "section");
|
|
432
|
+
const candidates = [];
|
|
433
|
+
const sections = [];
|
|
434
|
+
if (sectioned) for (const [index, node] of slideOrSectionNodes.entries()) {
|
|
435
|
+
if (node.type !== "section") throw new BuildError([diagnostic(`deck/${componentLabel(node, index)}`, "mixed-sections", "When using Section, every slide must belong to a Section")]);
|
|
436
|
+
const { name } = parseSectionProps(readInternalDeclarationProps(node), index);
|
|
437
|
+
if (nonWhitespaceText(node.children)) throw new BuildError([diagnostic(`deck/section[${name}]`, "unexpected-section-text", "Section can only contain Slide components")]);
|
|
438
|
+
const sectionIndex = sections.length;
|
|
439
|
+
const section = {
|
|
440
|
+
name,
|
|
441
|
+
slideIndexes: []
|
|
442
|
+
};
|
|
443
|
+
sections.push(section);
|
|
444
|
+
for (const [memberIndex, member] of childNodes(node.children).entries()) {
|
|
445
|
+
if (member.type !== "slide") throw new BuildError([diagnostic(`deck/section[${name}]/${componentLabel(member, memberIndex)}`, "nested-section", "Section can only contain Slide components and cannot nest Section components")]);
|
|
446
|
+
candidates.push({
|
|
447
|
+
node: member,
|
|
448
|
+
section: name,
|
|
449
|
+
sectionIndex
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else for (const [index, node] of slideOrSectionNodes.entries()) {
|
|
454
|
+
if (node.type !== "slide") throw new BuildError([diagnostic(`deck/${componentLabel(node, index)}`, "unexpected-declaration", "Direct children of Deck must be SlideMaster, Slide, or Section")]);
|
|
455
|
+
candidates.push({ node });
|
|
456
|
+
}
|
|
457
|
+
if (candidates.length === 0 && masters.length === 0) throw new BuildError([diagnostic("deck", "missing-slide", "Deck requires at least one Slide")]);
|
|
458
|
+
return {
|
|
459
|
+
masters,
|
|
460
|
+
layoutIdByKey,
|
|
461
|
+
slides: candidates.map(({ node, section, sectionIndex }, index) => {
|
|
462
|
+
const slideProps = readInternalDeclarationProps(node);
|
|
463
|
+
const { id, name, hidden, showMasterPlaceholderAnimations, showMasterShapes, colorMapOverride, themeOverride } = parseSlideCoreProps(slideProps, index, slideProperties);
|
|
464
|
+
const authorId = id;
|
|
465
|
+
if (authorIds.has(authorId)) throw new BuildError([diagnostic(`deck/slide[${authorId}]`, "duplicate-author-id", `Duplicate Slide.id ${JSON.stringify(authorId)} in the deck`, {
|
|
466
|
+
field: "id",
|
|
467
|
+
identifier: authorId
|
|
468
|
+
})]);
|
|
469
|
+
authorIds.add(authorId);
|
|
470
|
+
validateAuthorIdScopes(node, `deck/slide[${id}]`, /* @__PURE__ */ new Set());
|
|
471
|
+
let layoutKey;
|
|
472
|
+
const rawLayout = slideProps["layout"];
|
|
473
|
+
if (rawLayout === void 0) {
|
|
474
|
+
if (masters.length > 0) layoutKey = defaultBlankLayoutKey ?? firstLayoutKey;
|
|
475
|
+
} else if (isSlideLayoutDefinition(rawLayout)) {
|
|
476
|
+
const keys = layoutKeysByDefinition.get(rawLayout);
|
|
477
|
+
const targetLabel = rawLayout.id ?? rawLayout.name ?? "<unnamed>";
|
|
478
|
+
if (keys === void 0 || keys.length === 0) throw new BuildError([diagnostic(`deck/slide[${id}]`, "foreign-slide-layout", `Slide ${JSON.stringify(id)} references slide layout ${JSON.stringify(targetLabel)}, which is not owned by this deck`, {
|
|
479
|
+
field: "layout",
|
|
480
|
+
reference: targetLabel,
|
|
481
|
+
targetKind: "layout"
|
|
482
|
+
})]);
|
|
483
|
+
if (keys.length > 1) throw new BuildError([diagnostic(`deck/slide[${id}]`, "ambiguous-slide-layout", `Slide ${JSON.stringify(id)} references slide layout ${JSON.stringify(targetLabel)} mounted multiple times in this deck`, {
|
|
484
|
+
field: "layout",
|
|
485
|
+
reference: targetLabel,
|
|
486
|
+
targetKind: "layout"
|
|
487
|
+
})]);
|
|
488
|
+
layoutKey = keys[0];
|
|
489
|
+
} else if (isDeclarationNode(rawLayout)) {
|
|
490
|
+
if (rawLayout.type !== "slide-layout") throw new BuildError([diagnostic(`deck/slide[${id}]`, "invalid-slide-layout", "Slide.layout must be a SlideLayout or defineSlideLayout specification", { field: "layout" })]);
|
|
491
|
+
const matchedKey = layoutKeyByNode.get(rawLayout);
|
|
492
|
+
if (matchedKey === void 0) {
|
|
493
|
+
const rawLayoutProps = readInternalDeclarationProps(rawLayout);
|
|
494
|
+
const rawTarget = rawLayoutProps["id"] ?? rawLayoutProps["name"];
|
|
495
|
+
const targetLabel = typeof rawTarget === "string" ? rawTarget : "<unnamed>";
|
|
496
|
+
throw new BuildError([diagnostic(`deck/slide[${id}]`, "foreign-slide-layout", `Slide ${JSON.stringify(id)} references slide layout ${JSON.stringify(targetLabel)}, which is not owned by this deck`, {
|
|
497
|
+
field: "layout",
|
|
498
|
+
reference: targetLabel,
|
|
499
|
+
targetKind: "layout"
|
|
500
|
+
})]);
|
|
501
|
+
}
|
|
502
|
+
layoutKey = matchedKey;
|
|
503
|
+
} else throw new BuildError([diagnostic(`deck/slide[${id}]`, "invalid-slide-layout", "Slide.layout must be a SlideLayout or defineSlideLayout specification", { field: "layout" })]);
|
|
504
|
+
const resolved = {
|
|
505
|
+
node,
|
|
506
|
+
id,
|
|
507
|
+
...name === void 0 ? {} : { name },
|
|
508
|
+
...authorId === void 0 ? {} : { authorId },
|
|
509
|
+
index: index + 1,
|
|
510
|
+
...layoutKey === void 0 ? {} : { layoutKey },
|
|
511
|
+
hasExplicitLayout: rawLayout !== void 0,
|
|
512
|
+
...colorMapOverride === void 0 ? {} : { colorMapOverride },
|
|
513
|
+
...themeOverride === void 0 ? {} : { themeOverride },
|
|
514
|
+
...section === void 0 ? {} : { section },
|
|
515
|
+
...hidden === void 0 ? {} : { hidden },
|
|
516
|
+
...showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations },
|
|
517
|
+
...showMasterShapes === void 0 ? {} : { showMasterShapes }
|
|
518
|
+
};
|
|
519
|
+
if (sectionIndex !== void 0) sections[sectionIndex]?.slideIndexes.push(index + 1);
|
|
520
|
+
return resolved;
|
|
521
|
+
}),
|
|
522
|
+
sections: sections.map(({ name, slideIndexes }) => ({
|
|
523
|
+
name,
|
|
524
|
+
slideIndexes
|
|
525
|
+
}))
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function validateLink(value, context, path) {
|
|
529
|
+
let parsed;
|
|
530
|
+
try {
|
|
531
|
+
parsed = parseLinkTarget(value, path);
|
|
532
|
+
} catch (error) {
|
|
533
|
+
if (error instanceof CapabilityError) {
|
|
534
|
+
context.slide.diagnostics.push(diagnostic(path, error.code, error.message));
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
if (parsed === void 0) return void 0;
|
|
540
|
+
if ("id" in parsed) {
|
|
541
|
+
const targetIndex = context.document.slideIndexById.get(parsed.id);
|
|
542
|
+
if (targetIndex === void 0) {
|
|
543
|
+
context.slide.diagnostics.push(diagnostic(path, "missing-link-target", `No target slide with author id ${JSON.stringify(parsed.id)}`));
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (targetIndex !== context.slide.index) context.slide.linkedSlideIndexes.add(targetIndex);
|
|
547
|
+
return {
|
|
548
|
+
target: { id: parsed.id },
|
|
549
|
+
summary: `slide:${parsed.id}`
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
if ("url" in parsed) {
|
|
553
|
+
let url;
|
|
554
|
+
try {
|
|
555
|
+
url = new URL(parsed.url);
|
|
556
|
+
} catch {
|
|
557
|
+
context.slide.diagnostics.push(diagnostic(path, "invalid-link", "link.url must be an absolute URL"));
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
return {
|
|
561
|
+
target: { url: url.href },
|
|
562
|
+
summary: `url:${url.href}`
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
target: { action: "home" },
|
|
567
|
+
summary: "home"
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function recordResourceClaims(claims, document, diagnostics, path) {
|
|
571
|
+
for (const claim of claims ?? []) {
|
|
572
|
+
const claimKey = `${claim.kind}\u0000${claim.key}`;
|
|
573
|
+
const existing = document.resourceClaims.get(claimKey);
|
|
574
|
+
if (existing !== void 0 && existing.identity !== claim.identity) diagnostics.push(diagnostic(path, "conflicting-resource", `Resource ${claim.key} has conflicting definition with ${existing.path}`));
|
|
575
|
+
else document.resourceClaims.set(claimKey, {
|
|
576
|
+
identity: claim.identity,
|
|
577
|
+
path: existing?.path ?? path,
|
|
578
|
+
characters: (existing?.characters ?? "") + (claim.characters ?? "")
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function recordFontUsages(claims, document, ownerPath) {
|
|
583
|
+
for (const claim of claims ?? []) {
|
|
584
|
+
const key = `${claim.family.trim().toLowerCase()}\u0000${claim.weight}\u0000${claim.style}`;
|
|
585
|
+
const claimPath = claim.path === void 0 ? ownerPath : claim.path.startsWith("deck/") ? claim.path : `${ownerPath}/${claim.path}`;
|
|
586
|
+
const existing = document.fontUsages.get(key);
|
|
587
|
+
if (existing === void 0) {
|
|
588
|
+
document.fontUsages.set(key, {
|
|
589
|
+
family: claim.family,
|
|
590
|
+
weight: claim.weight,
|
|
591
|
+
style: claim.style,
|
|
592
|
+
hasResource: claim.hasResource,
|
|
593
|
+
...claim.substitute ? { substitute: true } : {},
|
|
594
|
+
...claim.embeddable === void 0 ? {} : { embeddable: claim.embeddable },
|
|
595
|
+
missingGlyphs: new Set(claim.missingGlyphs ?? []),
|
|
596
|
+
paths: /* @__PURE__ */ new Set([claimPath])
|
|
597
|
+
});
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (claim.hasResource && !existing.hasResource) {
|
|
601
|
+
existing.hasResource = true;
|
|
602
|
+
if (claim.embeddable !== void 0) existing.embeddable = claim.embeddable;
|
|
603
|
+
} else if (claim.embeddable === false && existing.embeddable !== false) existing.embeddable = false;
|
|
604
|
+
if (claim.substitute) {
|
|
605
|
+
existing.substitute = true;
|
|
606
|
+
existing.embeddable = false;
|
|
607
|
+
}
|
|
608
|
+
for (const glyph of claim.missingGlyphs ?? []) existing.missingGlyphs.add(glyph);
|
|
609
|
+
existing.paths.add(claimPath);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function summarizeDocumentFonts(fontUsages) {
|
|
613
|
+
return [...fontUsages.values()].map((entry) => ({
|
|
614
|
+
family: entry.family,
|
|
615
|
+
weight: entry.weight,
|
|
616
|
+
style: entry.style,
|
|
617
|
+
hasResource: entry.hasResource,
|
|
618
|
+
...entry.substitute ? { substitute: true } : {},
|
|
619
|
+
...entry.embeddable === void 0 ? {} : { embeddable: entry.embeddable },
|
|
620
|
+
...entry.missingGlyphs.size > 0 ? { missingGlyphs: [...entry.missingGlyphs] } : {},
|
|
621
|
+
paths: [...entry.paths]
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
624
|
+
function recordObjectMorph(args) {
|
|
625
|
+
const { morphKey, morphName, nativeKind, observationName, hasOutput, slide, declarationType, path } = args;
|
|
626
|
+
if (morphKey === void 0 || morphName === void 0) return;
|
|
627
|
+
if (!hasOutput) slide.diagnostics.push(diagnostic(path, "morph-needs-object", "morphKey can only be used with capabilities that produce native objects"));
|
|
628
|
+
else if (observationName !== morphName) slide.diagnostics.push(diagnostic(path, "unsupported-morph-object", `${declarationType} did not write morphKey to native object name, cannot participate in Morph matching`));
|
|
629
|
+
else if (!slide.morphObjects.has(morphKey)) slide.morphObjects.set(morphKey, {
|
|
630
|
+
kind: nativeKind,
|
|
631
|
+
name: morphName,
|
|
632
|
+
path
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
function createObjectResolveContext(args) {
|
|
636
|
+
const { resolveContext, id, path, layoutBox, layoutSizedAxes, theme, placeholder, insideGroup, restrictsMemberContinuity, morphName, link, scope, onChildrenResolved } = args;
|
|
637
|
+
return {
|
|
638
|
+
id,
|
|
639
|
+
path,
|
|
640
|
+
theme,
|
|
641
|
+
options: resolveContext.options,
|
|
642
|
+
slideNumber: resolveContext.slideNumber,
|
|
643
|
+
...layoutBox === void 0 ? {} : { layoutBox },
|
|
644
|
+
...layoutSizedAxes === void 0 ? {} : { layoutSizedAxes },
|
|
645
|
+
...placeholder === void 0 ? {} : { placeholder },
|
|
646
|
+
...morphName === void 0 ? {} : { morphName },
|
|
647
|
+
...link === void 0 ? {} : { link },
|
|
648
|
+
resolveTargetObject(targetAuthorId) {
|
|
649
|
+
return scope.targetsByAuthorId.get(targetAuthorId);
|
|
650
|
+
},
|
|
651
|
+
resolveChildren(nested) {
|
|
652
|
+
const resolved = resolveChildrenPass(nested, resolveContext, path, insideGroup || restrictsMemberContinuity);
|
|
653
|
+
onChildrenResolved?.(resolved);
|
|
654
|
+
return { objects: resolved.objects };
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function registerScopeTarget(scope, authorId, spid, emitsObject, resolvedObj) {
|
|
659
|
+
if (authorId === void 0 || !emitsObject || resolvedObj.observation.box === void 0) return;
|
|
660
|
+
scope.targetsByAuthorId.set(authorId, {
|
|
661
|
+
spid,
|
|
662
|
+
kind: resolvedObj.observation.kind,
|
|
663
|
+
box: resolvedObj.observation.box,
|
|
664
|
+
...resolvedObj.transform === void 0 ? {} : { transform: resolvedObj.transform },
|
|
665
|
+
...resolvedObj.connectionSites === void 0 ? {} : { connectionSites: resolvedObj.connectionSites }
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function commitLeafResolution(args) {
|
|
669
|
+
const { context, child, index, path, authorId, order, id, bound, layoutBox, theme, placeholder, emitsObject, morphKey, morphName, resolvedLink, resolvedObj } = args;
|
|
670
|
+
recordObjectMorph({
|
|
671
|
+
morphKey,
|
|
672
|
+
morphName,
|
|
673
|
+
nativeKind: bound.contract.nativeKind,
|
|
674
|
+
observationName: resolvedObj.observation.name,
|
|
675
|
+
hasOutput: emitsObject,
|
|
676
|
+
slide: context.slide,
|
|
677
|
+
declarationType: child.type,
|
|
678
|
+
path
|
|
679
|
+
});
|
|
680
|
+
for (const extension of resolvedObj.extensions) context.document.usedExtensions.add(extension);
|
|
681
|
+
recordResourceClaims(resolvedObj.resourceClaims, context.document, context.slide.diagnostics, path);
|
|
682
|
+
recordFontUsages(resolvedObj.fontUsages, context.document, path);
|
|
683
|
+
for (const annotation of resolvedObj.annotations ?? []) context.slide.contributions.push({
|
|
684
|
+
...annotation,
|
|
685
|
+
path,
|
|
686
|
+
targetId: id,
|
|
687
|
+
order,
|
|
688
|
+
declaration: child
|
|
689
|
+
});
|
|
690
|
+
const gridArea = context.layout.gridAreas.get(child);
|
|
691
|
+
const observation = {
|
|
692
|
+
...resolvedObj.observation,
|
|
693
|
+
id,
|
|
694
|
+
path,
|
|
695
|
+
...authorId === void 0 ? {} : { authorId },
|
|
696
|
+
...gridArea === void 0 ? {} : { gridArea },
|
|
697
|
+
...placeholder?.key === void 0 ? {} : resolvedObj.observation.placeholder === void 0 ? { placeholder: placeholder.key } : {},
|
|
698
|
+
...resolvedLink === void 0 ? {} : { link: resolvedLink.summary }
|
|
699
|
+
};
|
|
700
|
+
if (layoutBox !== void 0) context.slide.layoutDerivedObjectIds.add(id);
|
|
701
|
+
if (resolvedObj.transform !== void 0) context.slide.transformsById.set(id, resolvedObj.transform);
|
|
702
|
+
const contentNode = {
|
|
703
|
+
...authorId === void 0 ? {} : { authorId },
|
|
704
|
+
path,
|
|
705
|
+
reference: {
|
|
706
|
+
kind: "object",
|
|
707
|
+
id: observation.id
|
|
708
|
+
},
|
|
709
|
+
children: subPartContentNodes(resolvedObj.parts)
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
entry: {
|
|
713
|
+
layer: {
|
|
714
|
+
declarationType: child.type,
|
|
715
|
+
...authorId === void 0 ? {} : { authorId },
|
|
716
|
+
sourceOrder: [index],
|
|
717
|
+
zIndex: paintOrder(bound.contract),
|
|
718
|
+
path,
|
|
719
|
+
objectId: observation.id,
|
|
720
|
+
paintObjectId: observation.id,
|
|
721
|
+
theme,
|
|
722
|
+
...resolvedObj.observation.box === void 0 ? {} : { box: resolvedObj.observation.box },
|
|
723
|
+
...resolvedObj.transform === void 0 ? {} : { transform: resolvedObj.transform },
|
|
724
|
+
emitsObject,
|
|
725
|
+
hasObservation: true,
|
|
726
|
+
childComposition: "leaf",
|
|
727
|
+
...resolvedLink === void 0 ? {} : { resolvedLink },
|
|
728
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
729
|
+
extensions: resolvedObj.extensions,
|
|
730
|
+
memberLayers: [],
|
|
731
|
+
siblingLayers: [],
|
|
732
|
+
emit: (emitContext) => resolvedObj.emit(emitContext),
|
|
733
|
+
...resolvedObj.paint === void 0 ? {} : { paint: (paintContext) => resolvedObj.paint(paintContext) }
|
|
734
|
+
},
|
|
735
|
+
objects: [observation],
|
|
736
|
+
reference: {
|
|
737
|
+
kind: "object",
|
|
738
|
+
id: observation.id
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
contentNode
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function resolveChildrenPass(children, context, parentPath, insideGroup = false, inheritedScope) {
|
|
745
|
+
const isScopeRoot = inheritedScope === void 0;
|
|
746
|
+
const scope = inheritedScope ?? createScopeRegistry();
|
|
747
|
+
const deferredBeforePass = scope.deferredTasks.length;
|
|
748
|
+
const entries = [];
|
|
749
|
+
const content = [];
|
|
750
|
+
const syncEntries = (targetObjects, targetReferences, targetLayers) => {
|
|
751
|
+
entries.sort((left, right) => left.layer.zIndex - right.layer.zIndex || compareSourceOrder(left.layer.sourceOrder, right.layer.sourceOrder));
|
|
752
|
+
targetObjects.splice(0, targetObjects.length, ...entries.flatMap(({ objects }) => objects));
|
|
753
|
+
targetReferences.splice(0, targetReferences.length, ...entries.map(({ reference }) => reference));
|
|
754
|
+
targetLayers.splice(0, targetLayers.length, ...entries.map(({ layer }) => layer));
|
|
755
|
+
};
|
|
756
|
+
children.forEach((child, index) => {
|
|
757
|
+
if (!("props" in child)) {
|
|
758
|
+
if (child.text.trim() !== "") context.slide.diagnostics.push(diagnostic(`${parentPath}/${capabilityLabel(child, index)}`, "unexpected-text", "Native object container cannot directly contain text"));
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (context.layout.hidden.has(child)) return;
|
|
762
|
+
const path = `${parentPath}/${capabilityLabel(child, index)}`;
|
|
763
|
+
const authorId = readAuthorId(readInternalDeclarationProps(child)["id"], path);
|
|
764
|
+
const order = context.slide.nextNodeOrder++;
|
|
765
|
+
const module = context.modules.declarations.get(child.type);
|
|
766
|
+
if (module === void 0) {
|
|
767
|
+
context.slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if ("compileDeclaration" in module) {
|
|
771
|
+
if (module.children === "owned") return;
|
|
772
|
+
try {
|
|
773
|
+
for (const annotation of module.compileDeclaration(child, {
|
|
774
|
+
path,
|
|
775
|
+
theme: context.theme,
|
|
776
|
+
slideNumber: context.slideNumber
|
|
777
|
+
})) context.slide.contributions.push({
|
|
778
|
+
...annotation,
|
|
779
|
+
path,
|
|
780
|
+
order,
|
|
781
|
+
declaration: child
|
|
782
|
+
});
|
|
783
|
+
} catch (error) {
|
|
784
|
+
context.slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path === void 0 ? path : `${path}/${error.path}`, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
785
|
+
}
|
|
786
|
+
const deferredBefore = scope.deferredTasks.length;
|
|
787
|
+
const childResolved = resolveChildrenPass(child.children, context, path, insideGroup, scope);
|
|
788
|
+
const childContentStart = content.length;
|
|
789
|
+
content.push(...childResolved.content);
|
|
790
|
+
const wrappedEntries = [];
|
|
791
|
+
for (const entry of childResolved.entries) {
|
|
792
|
+
const wrapped = {
|
|
793
|
+
...entry,
|
|
794
|
+
layer: {
|
|
795
|
+
...entry.layer,
|
|
796
|
+
sourceOrder: [index, ...entry.layer.sourceOrder]
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
wrappedEntries.push(wrapped);
|
|
800
|
+
entries.push(wrapped);
|
|
801
|
+
}
|
|
802
|
+
if (scope.deferredTasks.length > deferredBefore) {
|
|
803
|
+
const childCount = childResolved.content.length;
|
|
804
|
+
const entryStart = entries.length - wrappedEntries.length;
|
|
805
|
+
scope.postFlushSyncs.push(() => {
|
|
806
|
+
content.splice(childContentStart, childCount, ...childResolved.content);
|
|
807
|
+
const refreshed = childResolved.entries.map((entry) => ({
|
|
808
|
+
...entry,
|
|
809
|
+
layer: {
|
|
810
|
+
...entry.layer,
|
|
811
|
+
sourceOrder: [index, ...entry.layer.sourceOrder]
|
|
812
|
+
}
|
|
813
|
+
}));
|
|
814
|
+
entries.splice(entryStart, wrappedEntries.length, ...refreshed);
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if (!isObjectCapability(module)) {
|
|
820
|
+
context.slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
const layoutBox = context.layout.boxes.get(child);
|
|
824
|
+
const layoutSizedAxes = context.layout.sizedAxes.get(child);
|
|
825
|
+
const placeholder = context.placeholderContexts.get(child);
|
|
826
|
+
const theme = placeholder !== void 0 ? placeholder.masterTheme : context.layout.themes.get(child) ?? context.theme;
|
|
827
|
+
try {
|
|
828
|
+
const bound = context.layout.bound.get(child) ?? validateBoundObjectCapability(module.bind(child, {
|
|
829
|
+
path,
|
|
830
|
+
theme,
|
|
831
|
+
options: context.options,
|
|
832
|
+
slideNumber: context.slideNumber,
|
|
833
|
+
...placeholder === void 0 ? {} : { placeholder }
|
|
834
|
+
}));
|
|
835
|
+
if (bound.container !== void 0) {
|
|
836
|
+
resolveBoundContainer({
|
|
837
|
+
child,
|
|
838
|
+
index,
|
|
839
|
+
path,
|
|
840
|
+
authorId,
|
|
841
|
+
order,
|
|
842
|
+
bound,
|
|
843
|
+
container: bound.container,
|
|
844
|
+
theme,
|
|
845
|
+
context,
|
|
846
|
+
insideGroup,
|
|
847
|
+
layers: entries,
|
|
848
|
+
content,
|
|
849
|
+
parentScope: scope
|
|
850
|
+
});
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const id = context.slide.nextId++;
|
|
854
|
+
const requestedMorphKey = bound.native?.morphKey;
|
|
855
|
+
const hasExplicitName = bound.native?.hasExplicitName === true;
|
|
856
|
+
const emitsObject = bound.native?.emitsObject !== false;
|
|
857
|
+
let morphKey;
|
|
858
|
+
let morphName;
|
|
859
|
+
if (requestedMorphKey !== void 0) {
|
|
860
|
+
if (!isMorphKey(requestedMorphKey)) context.slide.diagnostics.push(diagnostic(path, "invalid-morph-key", "morphKey must be created by createMorphScope().handle(name)"));
|
|
861
|
+
else if (insideGroup) context.slide.diagnostics.push(diagnostic(path, "morph-inside-group", "Morph only matches top-level slide objects; place morphKey on Group to move the entire group"));
|
|
862
|
+
else if (!emitsObject) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "morphKey can only be used with capabilities that produce native objects"));
|
|
863
|
+
else if (hasExplicitName) context.slide.diagnostics.push(diagnostic(path, "morph-object-name-conflict", "Both morphKey and name claim native object names; specify only one"));
|
|
864
|
+
else {
|
|
865
|
+
morphKey = requestedMorphKey;
|
|
866
|
+
morphName = nativeObjectName(morphKey, context.document);
|
|
867
|
+
if (context.slide.morphObjects.get(morphKey) !== void 0) context.slide.diagnostics.push(diagnostic(path, "duplicate-morph-key", `Morph handle "${getMorphKeyLabel(morphKey)}" reused on this slide; can only be declared once per slide`));
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const rawLink = bound.native?.link;
|
|
871
|
+
const resolvedLink = rawLink === void 0 ? void 0 : emitsObject ? validateLink(rawLink, context, path) : (context.slide.diagnostics.push(diagnostic(path, "link-needs-object", "Only elements producing native objects can attach click links")), void 0);
|
|
872
|
+
if (bound.contract.excludedFromLayout === true) {
|
|
873
|
+
const contentSlot = content.length;
|
|
874
|
+
const placeholderContent = {
|
|
875
|
+
...authorId === void 0 ? {} : { authorId },
|
|
876
|
+
path,
|
|
877
|
+
reference: {
|
|
878
|
+
kind: "object",
|
|
879
|
+
id
|
|
880
|
+
},
|
|
881
|
+
children: []
|
|
882
|
+
};
|
|
883
|
+
content.push(placeholderContent);
|
|
884
|
+
const placeholderEntry = {
|
|
885
|
+
layer: {
|
|
886
|
+
declarationType: child.type,
|
|
887
|
+
...authorId === void 0 ? {} : { authorId },
|
|
888
|
+
sourceOrder: [index],
|
|
889
|
+
zIndex: paintOrder(bound.contract),
|
|
890
|
+
path,
|
|
891
|
+
objectId: id,
|
|
892
|
+
paintObjectId: id,
|
|
893
|
+
theme,
|
|
894
|
+
emitsObject,
|
|
895
|
+
hasObservation: false,
|
|
896
|
+
childComposition: "leaf",
|
|
897
|
+
extensions: [],
|
|
898
|
+
memberLayers: [],
|
|
899
|
+
siblingLayers: [],
|
|
900
|
+
emit: () => ({ xml: "" })
|
|
901
|
+
},
|
|
902
|
+
objects: [],
|
|
903
|
+
reference: {
|
|
904
|
+
kind: "object",
|
|
905
|
+
id
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
entries.push(placeholderEntry);
|
|
909
|
+
scope.deferredTasks.push(() => {
|
|
910
|
+
try {
|
|
911
|
+
const resolvedObj = bound.resolve(createObjectResolveContext({
|
|
912
|
+
resolveContext: context,
|
|
913
|
+
id,
|
|
914
|
+
path,
|
|
915
|
+
layoutBox: void 0,
|
|
916
|
+
layoutSizedAxes: void 0,
|
|
917
|
+
theme,
|
|
918
|
+
placeholder,
|
|
919
|
+
insideGroup,
|
|
920
|
+
restrictsMemberContinuity: bound.contract.nativeKind === "grpSp",
|
|
921
|
+
morphName,
|
|
922
|
+
link: resolvedLink,
|
|
923
|
+
scope
|
|
924
|
+
}));
|
|
925
|
+
const committed = commitLeafResolution({
|
|
926
|
+
context,
|
|
927
|
+
child,
|
|
928
|
+
index,
|
|
929
|
+
path,
|
|
930
|
+
authorId,
|
|
931
|
+
order,
|
|
932
|
+
id,
|
|
933
|
+
bound,
|
|
934
|
+
layoutBox: void 0,
|
|
935
|
+
theme,
|
|
936
|
+
placeholder,
|
|
937
|
+
emitsObject,
|
|
938
|
+
morphKey,
|
|
939
|
+
morphName,
|
|
940
|
+
resolvedLink,
|
|
941
|
+
resolvedObj
|
|
942
|
+
});
|
|
943
|
+
placeholderEntry.layer = committed.entry.layer;
|
|
944
|
+
placeholderEntry.objects = committed.entry.objects;
|
|
945
|
+
placeholderEntry.reference = committed.entry.reference;
|
|
946
|
+
content[contentSlot] = committed.contentNode;
|
|
947
|
+
} catch (error) {
|
|
948
|
+
context.slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path === void 0 ? path : `${path}/${error.path}`, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
const resolvedObj = bound.resolve(createObjectResolveContext({
|
|
954
|
+
resolveContext: context,
|
|
955
|
+
id,
|
|
956
|
+
path,
|
|
957
|
+
layoutBox,
|
|
958
|
+
layoutSizedAxes,
|
|
959
|
+
theme,
|
|
960
|
+
placeholder,
|
|
961
|
+
insideGroup,
|
|
962
|
+
restrictsMemberContinuity: bound.contract.nativeKind === "grpSp",
|
|
963
|
+
morphName,
|
|
964
|
+
link: resolvedLink,
|
|
965
|
+
scope
|
|
966
|
+
}));
|
|
967
|
+
registerScopeTarget(scope, authorId, id, emitsObject, resolvedObj);
|
|
968
|
+
const committed = commitLeafResolution({
|
|
969
|
+
context,
|
|
970
|
+
child,
|
|
971
|
+
index,
|
|
972
|
+
path,
|
|
973
|
+
authorId,
|
|
974
|
+
order,
|
|
975
|
+
id,
|
|
976
|
+
bound,
|
|
977
|
+
layoutBox,
|
|
978
|
+
theme,
|
|
979
|
+
placeholder,
|
|
980
|
+
emitsObject,
|
|
981
|
+
morphKey,
|
|
982
|
+
morphName,
|
|
983
|
+
resolvedLink,
|
|
984
|
+
resolvedObj
|
|
985
|
+
});
|
|
986
|
+
content.push(committed.contentNode);
|
|
987
|
+
entries.push(committed.entry);
|
|
988
|
+
} catch (error) {
|
|
989
|
+
context.slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path === void 0 ? path : `${path}/${error.path}`, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
const objects = [];
|
|
993
|
+
const references = [];
|
|
994
|
+
const sortedLayers = [];
|
|
995
|
+
if (isScopeRoot) {
|
|
996
|
+
for (const task of scope.deferredTasks) task();
|
|
997
|
+
for (const sync of scope.postFlushSyncs) sync();
|
|
998
|
+
} else if (scope.deferredTasks.length > deferredBeforePass) scope.postFlushSyncs.push(() => {
|
|
999
|
+
syncEntries(objects, references, sortedLayers);
|
|
1000
|
+
});
|
|
1001
|
+
syncEntries(objects, references, sortedLayers);
|
|
1002
|
+
return {
|
|
1003
|
+
objects,
|
|
1004
|
+
references,
|
|
1005
|
+
content,
|
|
1006
|
+
layers: sortedLayers,
|
|
1007
|
+
entries
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
function resolveBoundContainer(args) {
|
|
1011
|
+
const { child, index, path, authorId, order, bound, container, theme, context, insideGroup, layers, content, parentScope } = args;
|
|
1012
|
+
const box = context.layout.boxes.get(child);
|
|
1013
|
+
const layoutSizedAxes = context.layout.sizedAxes.get(child);
|
|
1014
|
+
if (box === void 0) {
|
|
1015
|
+
context.slide.diagnostics.push(diagnostic(path, "layout-unavailable", "Container is missing layout result"));
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const enclosesChildren = container.childComposition === "members";
|
|
1019
|
+
const restrictsMemberContinuity = container.restrictsMemberContinuity === true || bound.contract.nativeKind === "grpSp";
|
|
1020
|
+
const layoutId = container.observesLayout !== false && box !== void 0 ? context.slide.nextId++ : void 0;
|
|
1021
|
+
const emitsObject = container.emitsObject;
|
|
1022
|
+
const requestedMorphKey = bound.native?.morphKey;
|
|
1023
|
+
const hasExplicitName = bound.native?.hasExplicitName === true;
|
|
1024
|
+
const rawLink = bound.native?.link;
|
|
1025
|
+
const containerLink = rawLink === void 0 ? void 0 : emitsObject ? validateLink(rawLink, context, path) : (context.slide.diagnostics.push(diagnostic(path, "link-needs-object", "Transparent container does not produce clickable objects; attach link to a visible container or object")), void 0);
|
|
1026
|
+
let morphKey;
|
|
1027
|
+
let morphName;
|
|
1028
|
+
if (requestedMorphKey !== void 0) {
|
|
1029
|
+
if (!isMorphKey(requestedMorphKey)) context.slide.diagnostics.push(diagnostic(path, "invalid-morph-key", "morphKey must be created by createMorphScope().handle(name)"));
|
|
1030
|
+
else if (insideGroup) context.slide.diagnostics.push(diagnostic(path, "morph-inside-group", "Morph only matches top-level slide objects; place morphKey on Group to move the entire group"));
|
|
1031
|
+
else if (!emitsObject) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "Only containers generating native objects can participate in Morph"));
|
|
1032
|
+
else if (hasExplicitName) context.slide.diagnostics.push(diagnostic(path, "morph-object-name-conflict", "Both morphKey and name claim native object names; specify only one"));
|
|
1033
|
+
else {
|
|
1034
|
+
morphKey = requestedMorphKey;
|
|
1035
|
+
morphName = nativeObjectName(morphKey, context.document);
|
|
1036
|
+
if (context.slide.morphObjects.has(morphKey)) context.slide.diagnostics.push(diagnostic(path, "duplicate-morph-key", `Morph handle "${getMorphKeyLabel(morphKey)}" reused on this slide; can only be declared once per slide`));
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
let containerObservation;
|
|
1040
|
+
let memberResolved;
|
|
1041
|
+
let memberLayers = [];
|
|
1042
|
+
let containerLayer;
|
|
1043
|
+
const objectId = context.slide.nextId++;
|
|
1044
|
+
try {
|
|
1045
|
+
const resolvedObj = bound.resolve(createObjectResolveContext({
|
|
1046
|
+
resolveContext: context,
|
|
1047
|
+
id: objectId,
|
|
1048
|
+
path,
|
|
1049
|
+
layoutBox: box,
|
|
1050
|
+
layoutSizedAxes,
|
|
1051
|
+
theme,
|
|
1052
|
+
placeholder: void 0,
|
|
1053
|
+
insideGroup,
|
|
1054
|
+
restrictsMemberContinuity,
|
|
1055
|
+
morphName,
|
|
1056
|
+
link: containerLink,
|
|
1057
|
+
scope: parentScope,
|
|
1058
|
+
onChildrenResolved: (resolved) => {
|
|
1059
|
+
memberResolved = resolved;
|
|
1060
|
+
}
|
|
1061
|
+
}));
|
|
1062
|
+
const gridArea = context.layout.gridAreas.get(child);
|
|
1063
|
+
if (emitsObject) {
|
|
1064
|
+
containerObservation = {
|
|
1065
|
+
...resolvedObj.observation,
|
|
1066
|
+
id: objectId,
|
|
1067
|
+
path,
|
|
1068
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1069
|
+
...gridArea === void 0 ? {} : { gridArea },
|
|
1070
|
+
...containerLink === void 0 ? {} : { link: containerLink.summary }
|
|
1071
|
+
};
|
|
1072
|
+
registerScopeTarget(parentScope, authorId, objectId, true, resolvedObj);
|
|
1073
|
+
if (box !== void 0) context.slide.layoutDerivedObjectIds.add(objectId);
|
|
1074
|
+
if (resolvedObj.transform !== void 0) context.slide.transformsById.set(objectId, resolvedObj.transform);
|
|
1075
|
+
recordObjectMorph({
|
|
1076
|
+
morphKey,
|
|
1077
|
+
morphName,
|
|
1078
|
+
nativeKind: bound.contract.nativeKind,
|
|
1079
|
+
observationName: resolvedObj.observation.name,
|
|
1080
|
+
hasOutput: true,
|
|
1081
|
+
slide: context.slide,
|
|
1082
|
+
declarationType: child.type,
|
|
1083
|
+
path
|
|
1084
|
+
});
|
|
1085
|
+
for (const extension of resolvedObj.extensions) context.document.usedExtensions.add(extension);
|
|
1086
|
+
recordResourceClaims(resolvedObj.resourceClaims, context.document, context.slide.diagnostics, path);
|
|
1087
|
+
recordFontUsages(resolvedObj.fontUsages, context.document, path);
|
|
1088
|
+
} else if (morphKey !== void 0) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "Only containers generating native objects can participate in Morph"));
|
|
1089
|
+
for (const annotation of resolvedObj.annotations ?? []) context.slide.contributions.push({
|
|
1090
|
+
...annotation,
|
|
1091
|
+
path,
|
|
1092
|
+
...containerObservation === void 0 ? {} : { targetId: containerObservation.id },
|
|
1093
|
+
order,
|
|
1094
|
+
declaration: child
|
|
1095
|
+
});
|
|
1096
|
+
memberLayers = enclosesChildren ? memberResolved?.layers ?? [] : [];
|
|
1097
|
+
containerLayer = {
|
|
1098
|
+
declarationType: child.type,
|
|
1099
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1100
|
+
sourceOrder: [index],
|
|
1101
|
+
zIndex: paintOrder(bound.contract),
|
|
1102
|
+
path,
|
|
1103
|
+
objectId: containerObservation?.id ?? objectId,
|
|
1104
|
+
paintObjectId: layoutId ?? objectId,
|
|
1105
|
+
theme,
|
|
1106
|
+
...containerObservation?.box === void 0 ? {} : { box: containerObservation.box },
|
|
1107
|
+
...resolvedObj.transform === void 0 ? {} : { transform: resolvedObj.transform },
|
|
1108
|
+
emitsObject,
|
|
1109
|
+
hasObservation: containerObservation !== void 0,
|
|
1110
|
+
childComposition: enclosesChildren ? "members" : "siblings",
|
|
1111
|
+
...containerLink === void 0 ? {} : { resolvedLink: containerLink },
|
|
1112
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
1113
|
+
extensions: resolvedObj.extensions,
|
|
1114
|
+
memberLayers,
|
|
1115
|
+
siblingLayers: [],
|
|
1116
|
+
emit: (emitContext) => resolvedObj.emit(emitContext),
|
|
1117
|
+
...resolvedObj.paint === void 0 ? {} : { paint: (paintContext) => resolvedObj.paint(paintContext) }
|
|
1118
|
+
};
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
context.slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path === void 0 ? path : `${path}/${error.path}`, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
1121
|
+
}
|
|
1122
|
+
const childScope = authorId === void 0 ? parentScope : void 0;
|
|
1123
|
+
const deferredBeforeChildren = childScope?.deferredTasks.length ?? 0;
|
|
1124
|
+
const resolvedChildren = enclosesChildren ? memberResolved ?? {
|
|
1125
|
+
objects: [],
|
|
1126
|
+
references: [],
|
|
1127
|
+
content: [],
|
|
1128
|
+
layers: memberLayers,
|
|
1129
|
+
entries: []
|
|
1130
|
+
} : resolveChildrenPass(container.children, context, path, insideGroup || restrictsMemberContinuity, childScope);
|
|
1131
|
+
const siblingLayers = enclosesChildren ? [] : [...resolvedChildren.layers];
|
|
1132
|
+
const finalLayer = containerLayer !== void 0 ? {
|
|
1133
|
+
...containerLayer,
|
|
1134
|
+
...!enclosesChildren ? { siblingLayers } : {}
|
|
1135
|
+
} : {
|
|
1136
|
+
declarationType: child.type,
|
|
1137
|
+
sourceOrder: [index],
|
|
1138
|
+
zIndex: paintOrder(bound.contract),
|
|
1139
|
+
path,
|
|
1140
|
+
objectId,
|
|
1141
|
+
paintObjectId: layoutId ?? objectId,
|
|
1142
|
+
theme,
|
|
1143
|
+
emitsObject,
|
|
1144
|
+
hasObservation: false,
|
|
1145
|
+
childComposition: enclosesChildren ? "members" : "siblings",
|
|
1146
|
+
extensions: [],
|
|
1147
|
+
memberLayers: enclosesChildren ? resolvedChildren.layers : [],
|
|
1148
|
+
siblingLayers,
|
|
1149
|
+
emit: () => ({ xml: "" })
|
|
1150
|
+
};
|
|
1151
|
+
const layerObservedObjects = [...containerObservation === void 0 ? [] : [containerObservation], ...enclosesChildren ? [] : resolvedChildren.objects];
|
|
1152
|
+
if (layoutId !== void 0 && box !== void 0) {
|
|
1153
|
+
const gridTracks = context.layout.gridTracks.get(child);
|
|
1154
|
+
const layoutGridArea = context.layout.gridAreas.get(child);
|
|
1155
|
+
const layoutChildren = [...containerObservation === void 0 ? [] : [{
|
|
1156
|
+
kind: "object",
|
|
1157
|
+
id: containerObservation.id
|
|
1158
|
+
}], ...resolvedChildren.references];
|
|
1159
|
+
context.slide.layouts.push({
|
|
1160
|
+
id: layoutId,
|
|
1161
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1162
|
+
path,
|
|
1163
|
+
box: reportBox(box),
|
|
1164
|
+
...layoutGridArea === void 0 ? {} : { gridArea: layoutGridArea },
|
|
1165
|
+
...gridTracks === void 0 ? {} : {
|
|
1166
|
+
columnWidths: gridTracks.columnWidths,
|
|
1167
|
+
rowHeights: gridTracks.rowHeights
|
|
1168
|
+
},
|
|
1169
|
+
children: layoutChildren
|
|
1170
|
+
});
|
|
1171
|
+
const contentStart = content.length;
|
|
1172
|
+
const initialChildContentLen = resolvedChildren.content.length;
|
|
1173
|
+
content.push({
|
|
1174
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1175
|
+
path,
|
|
1176
|
+
reference: {
|
|
1177
|
+
kind: "layout",
|
|
1178
|
+
id: layoutId,
|
|
1179
|
+
objectIds: containerObservation === void 0 ? [] : [containerObservation.id]
|
|
1180
|
+
},
|
|
1181
|
+
children: resolvedChildren.content
|
|
1182
|
+
});
|
|
1183
|
+
const containerEntry = {
|
|
1184
|
+
layer: finalLayer,
|
|
1185
|
+
objects: layerObservedObjects,
|
|
1186
|
+
reference: {
|
|
1187
|
+
kind: "layout",
|
|
1188
|
+
id: layoutId
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
layers.push(containerEntry);
|
|
1192
|
+
if (!enclosesChildren && childScope !== void 0 && childScope.deferredTasks.length > deferredBeforeChildren) childScope.postFlushSyncs.push(() => {
|
|
1193
|
+
siblingLayers.splice(0, siblingLayers.length, ...resolvedChildren.layers);
|
|
1194
|
+
layerObservedObjects.splice(0, layerObservedObjects.length, ...containerObservation === void 0 ? [] : [containerObservation], ...resolvedChildren.objects);
|
|
1195
|
+
layoutChildren.splice(0, layoutChildren.length, ...containerObservation === void 0 ? [] : [{
|
|
1196
|
+
kind: "object",
|
|
1197
|
+
id: containerObservation.id
|
|
1198
|
+
}], ...resolvedChildren.references);
|
|
1199
|
+
if (initialChildContentLen === resolvedChildren.content.length) content[contentStart] = {
|
|
1200
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1201
|
+
path,
|
|
1202
|
+
reference: {
|
|
1203
|
+
kind: "layout",
|
|
1204
|
+
id: layoutId,
|
|
1205
|
+
objectIds: containerObservation === void 0 ? [] : [containerObservation.id]
|
|
1206
|
+
},
|
|
1207
|
+
children: resolvedChildren.content
|
|
1208
|
+
};
|
|
1209
|
+
});
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const contentStart = content.length;
|
|
1213
|
+
const initialChildContentLen = resolvedChildren.content.length;
|
|
1214
|
+
if (containerObservation !== void 0) content.push({
|
|
1215
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1216
|
+
path,
|
|
1217
|
+
reference: {
|
|
1218
|
+
kind: "object",
|
|
1219
|
+
id: containerObservation.id
|
|
1220
|
+
},
|
|
1221
|
+
children: resolvedChildren.content
|
|
1222
|
+
});
|
|
1223
|
+
else content.push(...resolvedChildren.content);
|
|
1224
|
+
const containerEntry = {
|
|
1225
|
+
layer: finalLayer,
|
|
1226
|
+
objects: layerObservedObjects,
|
|
1227
|
+
reference: containerObservation !== void 0 ? {
|
|
1228
|
+
kind: "object",
|
|
1229
|
+
id: containerObservation.id
|
|
1230
|
+
} : {
|
|
1231
|
+
kind: "layout",
|
|
1232
|
+
id: objectId
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
layers.push(containerEntry);
|
|
1236
|
+
if (!enclosesChildren && childScope !== void 0 && childScope.deferredTasks.length > deferredBeforeChildren) childScope.postFlushSyncs.push(() => {
|
|
1237
|
+
siblingLayers.splice(0, siblingLayers.length, ...resolvedChildren.layers);
|
|
1238
|
+
layerObservedObjects.splice(0, layerObservedObjects.length, ...containerObservation === void 0 ? [] : [containerObservation], ...resolvedChildren.objects);
|
|
1239
|
+
if (containerObservation !== void 0) content[contentStart] = {
|
|
1240
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1241
|
+
path,
|
|
1242
|
+
reference: {
|
|
1243
|
+
kind: "object",
|
|
1244
|
+
id: containerObservation.id
|
|
1245
|
+
},
|
|
1246
|
+
children: resolvedChildren.content
|
|
1247
|
+
};
|
|
1248
|
+
else content.splice(contentStart, initialChildContentLen, ...resolvedChildren.content);
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
function compareSourceOrder(left, right) {
|
|
1252
|
+
for (let index = 0; index < Math.min(left.length, right.length); index += 1) {
|
|
1253
|
+
const difference = left[index] - right[index];
|
|
1254
|
+
if (difference !== 0) return difference;
|
|
1255
|
+
}
|
|
1256
|
+
return left.length - right.length;
|
|
1257
|
+
}
|
|
1258
|
+
function paintOrder(contract) {
|
|
1259
|
+
const value = contract?.layoutStyle.zIndex;
|
|
1260
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
1261
|
+
}
|
|
1262
|
+
function subPartContentNodes(parts) {
|
|
1263
|
+
if (parts === void 0 || parts.length === 0) return [];
|
|
1264
|
+
return parts.map((part) => ({
|
|
1265
|
+
...part.authorId === void 0 ? {} : { authorId: part.authorId },
|
|
1266
|
+
...part.path === void 0 ? {} : { path: part.path },
|
|
1267
|
+
reference: {
|
|
1268
|
+
kind: "part",
|
|
1269
|
+
...part.kind === void 0 ? {} : { partKind: part.kind },
|
|
1270
|
+
...part.path === void 0 ? {} : { path: part.path },
|
|
1271
|
+
...part.box === void 0 ? {} : { box: part.box },
|
|
1272
|
+
...part.text === void 0 ? {} : { text: part.text },
|
|
1273
|
+
...part.textMetrics === void 0 ? {} : { textMetrics: part.textMetrics }
|
|
1274
|
+
},
|
|
1275
|
+
children: subPartContentNodes(part.parts)
|
|
1276
|
+
}));
|
|
1277
|
+
}
|
|
1278
|
+
function resolveContributions(children, contributions) {
|
|
1279
|
+
let resolved = contributions;
|
|
1280
|
+
const applied = /* @__PURE__ */ new Set();
|
|
1281
|
+
for (const contribution of contributions) {
|
|
1282
|
+
const capability = contribution.capability;
|
|
1283
|
+
if (applied.has(capability)) continue;
|
|
1284
|
+
const resolver = contribution.resolveContributions;
|
|
1285
|
+
if (resolver === void 0) continue;
|
|
1286
|
+
const owned = resolved.filter((candidate) => candidate.capability === capability);
|
|
1287
|
+
if (owned.length === 0) continue;
|
|
1288
|
+
applied.add(capability);
|
|
1289
|
+
const effective = resolver(children, owned);
|
|
1290
|
+
const next = [];
|
|
1291
|
+
let inserted = false;
|
|
1292
|
+
for (const candidate of resolved) if (candidate.capability !== capability) next.push(candidate);
|
|
1293
|
+
else if (!inserted) {
|
|
1294
|
+
next.push(...effective);
|
|
1295
|
+
inserted = true;
|
|
1296
|
+
}
|
|
1297
|
+
resolved = next;
|
|
1298
|
+
}
|
|
1299
|
+
return resolved;
|
|
1300
|
+
}
|
|
1301
|
+
function collectOwnedContributions(children, modules, slide, parentPath, order, hidden, theme, slideNumber) {
|
|
1302
|
+
children.forEach((child, index) => {
|
|
1303
|
+
if (!("props" in child)) return;
|
|
1304
|
+
const path = `${parentPath}/${capabilityLabel(child, index)}`;
|
|
1305
|
+
const module = modules.get(child.type);
|
|
1306
|
+
if (module !== void 0 && "compileDeclaration" in module && module.children === "owned") {
|
|
1307
|
+
try {
|
|
1308
|
+
for (const annotation of module.compileDeclaration(child, {
|
|
1309
|
+
path,
|
|
1310
|
+
theme,
|
|
1311
|
+
slideNumber
|
|
1312
|
+
})) slide.contributions.push({
|
|
1313
|
+
...annotation,
|
|
1314
|
+
path,
|
|
1315
|
+
order: order.value++
|
|
1316
|
+
});
|
|
1317
|
+
} catch (error) {
|
|
1318
|
+
slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path === void 0 ? path : `${path}/${error.path}`, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
1319
|
+
}
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (child.pageAffiliated === true) {
|
|
1323
|
+
if (module === void 0 && hidden.has(child)) slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
collectOwnedContributions(child.children, modules, slide, path, order, hidden, theme, slideNumber);
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
function collectNestedPlaceholders(children, modules, parentPath, allowDirect, diagnostics, onDirect) {
|
|
1330
|
+
children.forEach((child, index) => {
|
|
1331
|
+
if (!("props" in child)) return;
|
|
1332
|
+
const childPath = `${parentPath}/${capabilityLabel(child, index)}`;
|
|
1333
|
+
const module = modules.declarations.get(child.type);
|
|
1334
|
+
if (module !== void 0 && "compileDeclaration" in module) {
|
|
1335
|
+
if (module.children === "owned") return;
|
|
1336
|
+
collectNestedPlaceholders(child.children, modules, childPath, allowDirect, diagnostics, onDirect);
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
const childProps = readInternalDeclarationProps(child);
|
|
1340
|
+
if (childProps["placeholder"] !== void 0 || childProps["nativePlaceholder"] !== void 0) {
|
|
1341
|
+
if (allowDirect) onDirect?.(child, childPath);
|
|
1342
|
+
else diagnostics.push(diagnostic(childPath, "placeholder-inside-container", "Placeholders can only be bound directly on Slide"));
|
|
1343
|
+
}
|
|
1344
|
+
collectNestedPlaceholders(child.children, modules, childPath, false, diagnostics);
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
function buildSlidePlaceholderContexts(args) {
|
|
1348
|
+
const { slideId, slidePath, dimensions, hasExplicitLayout, layoutSpec, masterSpec, placeholderTheme, children, rawPlaceholdersProp, modules, diagnostics } = args;
|
|
1349
|
+
const contexts = /* @__PURE__ */ new WeakMap();
|
|
1350
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
1351
|
+
if (rawPlaceholdersProp !== void 0 && !hasExplicitLayout) diagnostics.push(diagnostic(slidePath, "placeholder-requires-layout", `Slide ${JSON.stringify(slideId)} declares placeholders without a bound SlideLayout`));
|
|
1352
|
+
collectNestedPlaceholders(children, modules, slidePath, true, diagnostics, (child, childPath) => {
|
|
1353
|
+
const childProps = readInternalDeclarationProps(child);
|
|
1354
|
+
const rawKey = childProps["placeholder"];
|
|
1355
|
+
const rawNativePh = childProps["nativePlaceholder"];
|
|
1356
|
+
let parsedNativePh;
|
|
1357
|
+
if (rawNativePh !== void 0) {
|
|
1358
|
+
const parsed = nativePlaceholderRefSchema.safeParse(rawNativePh);
|
|
1359
|
+
if (!parsed.success) {
|
|
1360
|
+
diagnostics.push(zodIssueToBuildDiagnostic(childPath, "invalid-slide-placeholder", "Invalid nativePlaceholder specification", parsed.error.issues[0], "nativePlaceholder"));
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
parsedNativePh = parsed.data;
|
|
1364
|
+
}
|
|
1365
|
+
if (rawKey !== void 0) {
|
|
1366
|
+
if (typeof rawKey !== "string" || rawKey.trim() === "") {
|
|
1367
|
+
diagnostics.push(diagnostic(childPath, "invalid-slide-placeholder", "placeholder key must be a non-empty string"));
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (seenKeys.has(rawKey)) {
|
|
1371
|
+
diagnostics.push(diagnostic(childPath, "duplicate-slide-placeholder", `Placeholder ${JSON.stringify(rawKey)} can only be bound once per slide`));
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
seenKeys.add(rawKey);
|
|
1375
|
+
}
|
|
1376
|
+
if (!hasExplicitLayout && parsedNativePh === void 0) {
|
|
1377
|
+
diagnostics.push(diagnostic(childPath, "placeholder-requires-layout", `Placeholder ${JSON.stringify(rawKey)} requires a bound SlideLayout`));
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
const layoutPlaceholder = typeof rawKey === "string" ? layoutSpec?.placeholders?.[rawKey] : void 0;
|
|
1381
|
+
if (layoutPlaceholder === void 0 && parsedNativePh === void 0) {
|
|
1382
|
+
const layoutLabel = layoutSpec?.id ?? layoutSpec?.name ?? "<unnamed>";
|
|
1383
|
+
diagnostics.push(diagnostic(childPath, "unknown-slide-placeholder", `SlideLayout ${JSON.stringify(layoutLabel)} does not define placeholder ${JSON.stringify(rawKey)}`));
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
if (masterSpec === void 0) {
|
|
1387
|
+
diagnostics.push(diagnostic(childPath, "placeholder-requires-layout", `Placeholder ${JSON.stringify(rawKey)} requires a SlideLayout owned by a SlideMaster`));
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
const nativeRefSize = layoutPlaceholder?.size;
|
|
1391
|
+
const nativeRef = parsedNativePh ?? {
|
|
1392
|
+
type: layoutPlaceholder.type,
|
|
1393
|
+
...layoutPlaceholder.explicitType === void 0 ? {} : { explicitType: layoutPlaceholder.explicitType },
|
|
1394
|
+
...layoutPlaceholder.idx === void 0 ? {} : { idx: layoutPlaceholder.idx },
|
|
1395
|
+
...nativeRefSize === void 0 ? {} : { size: nativeRefSize },
|
|
1396
|
+
...layoutPlaceholder.orient === void 0 ? {} : { orient: layoutPlaceholder.orient },
|
|
1397
|
+
...layoutPlaceholder.hasCustomPrompt === void 0 ? {} : { hasCustomPrompt: layoutPlaceholder.hasCustomPrompt }
|
|
1398
|
+
};
|
|
1399
|
+
const role = layoutPlaceholder?.type ?? nativeRef.type;
|
|
1400
|
+
const masterPlaceholder = matchMasterPlaceholderSpec(masterSpec.placeholders, role);
|
|
1401
|
+
contexts.set(child, {
|
|
1402
|
+
...typeof rawKey === "string" ? { key: rawKey } : {},
|
|
1403
|
+
nativeRef,
|
|
1404
|
+
masterTheme: placeholderTheme ?? masterSpec.themeContext,
|
|
1405
|
+
slideDimensions: dimensions,
|
|
1406
|
+
...masterSpec.textStyles === void 0 ? {} : { masterTextStyles: masterSpec.textStyles },
|
|
1407
|
+
...masterPlaceholder === void 0 ? {} : { masterPlaceholder },
|
|
1408
|
+
...layoutPlaceholder === void 0 ? {} : { layoutPlaceholder }
|
|
1409
|
+
});
|
|
1410
|
+
});
|
|
1411
|
+
return contexts;
|
|
1412
|
+
}
|
|
1413
|
+
function resolveOwnerSlideCapabilities(args) {
|
|
1414
|
+
const { type, props, path, modules, dimensions, document, options, theme } = args;
|
|
1415
|
+
const slideCapabilities = [];
|
|
1416
|
+
const capabilities = {};
|
|
1417
|
+
const continuityByDeclaration = /* @__PURE__ */ new Map();
|
|
1418
|
+
const diagnostics = [];
|
|
1419
|
+
const input = {
|
|
1420
|
+
type,
|
|
1421
|
+
props,
|
|
1422
|
+
children: []
|
|
1423
|
+
};
|
|
1424
|
+
for (const module of modules.slideModules.values()) {
|
|
1425
|
+
const hasSlideProps = (module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp])).some((property) => Object.hasOwn(props, property));
|
|
1426
|
+
if (!hasSlideProps) continue;
|
|
1427
|
+
try {
|
|
1428
|
+
const boundSlide = validateBoundSlideCapability(module.bindSlide(input, {
|
|
1429
|
+
path,
|
|
1430
|
+
dimensions,
|
|
1431
|
+
theme,
|
|
1432
|
+
options,
|
|
1433
|
+
slideNumber: 0,
|
|
1434
|
+
contributions: []
|
|
1435
|
+
}));
|
|
1436
|
+
continuityByDeclaration.set(module.declaration, boundSlide.continuity?.matchSourceKinds);
|
|
1437
|
+
const resolvedSlideCap = boundSlide.resolveSlide({
|
|
1438
|
+
path,
|
|
1439
|
+
dimensions,
|
|
1440
|
+
contributions: [],
|
|
1441
|
+
children: [],
|
|
1442
|
+
theme,
|
|
1443
|
+
options,
|
|
1444
|
+
slideNumber: 0
|
|
1445
|
+
});
|
|
1446
|
+
if (resolvedSlideCap.observation !== void 0) capabilities[module.declaration] = resolvedSlideCap.observation;
|
|
1447
|
+
for (const extension of resolvedSlideCap.extensions) document.usedExtensions.add(extension);
|
|
1448
|
+
recordResourceClaims(resolvedSlideCap.resourceClaims, document, diagnostics, path);
|
|
1449
|
+
recordFontUsages(resolvedSlideCap.fontUsages, document, path);
|
|
1450
|
+
slideCapabilities.push({
|
|
1451
|
+
declaration: module.declaration,
|
|
1452
|
+
slot: module.slot,
|
|
1453
|
+
hasSlideProps,
|
|
1454
|
+
path,
|
|
1455
|
+
theme,
|
|
1456
|
+
extensions: resolvedSlideCap.extensions,
|
|
1457
|
+
emit: (emitContext) => resolvedSlideCap.emit(emitContext),
|
|
1458
|
+
...resolvedSlideCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedSlideCap.paint(paintContext) }
|
|
1459
|
+
});
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path ?? path, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (diagnostics.length > 0) throw new BuildError(diagnostics);
|
|
1465
|
+
return {
|
|
1466
|
+
slideCapabilities,
|
|
1467
|
+
capabilities,
|
|
1468
|
+
continuityByDeclaration
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
function isCustomColorMap(colorMap) {
|
|
1472
|
+
return Object.keys(defaultColorMap).some((slot) => colorMap[slot] !== defaultColorMap[slot]);
|
|
1473
|
+
}
|
|
1474
|
+
function resolveSlideDeclaration(parsed, modules, dimensions, document, options, documentTheme, layoutIdByKey, layoutByKey, masterByKey, inheritedContinuity, inheritedBackground, masterLayers, layoutLayers, inheritance) {
|
|
1475
|
+
const { node, id, name, authorId, index, layoutKey, hasExplicitLayout, section, hidden = false, showMasterShapes } = parsed;
|
|
1476
|
+
const slide = {
|
|
1477
|
+
index,
|
|
1478
|
+
nextId: 2,
|
|
1479
|
+
nextNodeOrder: 0,
|
|
1480
|
+
diagnostics: [],
|
|
1481
|
+
layouts: [],
|
|
1482
|
+
contributions: [],
|
|
1483
|
+
morphObjects: /* @__PURE__ */ new Map(),
|
|
1484
|
+
matchContinuityKinds: false,
|
|
1485
|
+
linkedSlideIndexes: /* @__PURE__ */ new Set(),
|
|
1486
|
+
layoutDerivedObjectIds: /* @__PURE__ */ new Set(),
|
|
1487
|
+
transformsById: /* @__PURE__ */ new Map()
|
|
1488
|
+
};
|
|
1489
|
+
const path = `deck/slide[${id}]`;
|
|
1490
|
+
if (nonWhitespaceText(node.children)) slide.diagnostics.push(diagnostic(path, "unexpected-text", "Slide cannot directly contain text"));
|
|
1491
|
+
const children = node.children.map(capabilityChild);
|
|
1492
|
+
const layoutSpec = layoutKey === void 0 ? void 0 : layoutByKey.get(layoutKey);
|
|
1493
|
+
const masterSpec = layoutSpec === void 0 ? void 0 : masterByKey.get(layoutSpec.masterKey);
|
|
1494
|
+
const nodeProps = readInternalDeclarationProps(node);
|
|
1495
|
+
const placeholderContexts = buildSlidePlaceholderContexts({
|
|
1496
|
+
slideId: id,
|
|
1497
|
+
slidePath: path,
|
|
1498
|
+
dimensions,
|
|
1499
|
+
hasExplicitLayout,
|
|
1500
|
+
layoutSpec,
|
|
1501
|
+
masterSpec,
|
|
1502
|
+
placeholderTheme: documentTheme.withTextStyle({}),
|
|
1503
|
+
children,
|
|
1504
|
+
rawPlaceholdersProp: nodeProps["placeholders"],
|
|
1505
|
+
modules,
|
|
1506
|
+
diagnostics: slide.diagnostics
|
|
1507
|
+
});
|
|
1508
|
+
if (slide.diagnostics.length > 0) throw new BuildError(slide.diagnostics);
|
|
1509
|
+
let theme;
|
|
1510
|
+
try {
|
|
1511
|
+
theme = documentTheme.with(textStyleFrom(nodeProps["style"]));
|
|
1512
|
+
} catch (error) {
|
|
1513
|
+
if (!(error instanceof CapabilityError)) throw error;
|
|
1514
|
+
throw new BuildError([diagnostic(path, error.code, error.message)]);
|
|
1515
|
+
}
|
|
1516
|
+
const layout = new LayoutPass(modules.declarations, dimensions, index, options).run(children, path, theme, nodeProps["style"], (element) => placeholderContexts.get(element));
|
|
1517
|
+
collectOwnedContributions(children, modules.declarations, slide, path, { value: 0 }, layout.hidden, theme, index);
|
|
1518
|
+
const resolvedChildren = resolveChildrenPass(children, {
|
|
1519
|
+
document,
|
|
1520
|
+
slide,
|
|
1521
|
+
modules,
|
|
1522
|
+
dimensions,
|
|
1523
|
+
options,
|
|
1524
|
+
theme,
|
|
1525
|
+
layout,
|
|
1526
|
+
slideNumber: index,
|
|
1527
|
+
placeholderContexts
|
|
1528
|
+
}, path);
|
|
1529
|
+
let contributions = slide.contributions;
|
|
1530
|
+
try {
|
|
1531
|
+
contributions = resolveContributions(children, slide.contributions);
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path ?? path, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
1534
|
+
}
|
|
1535
|
+
const capabilities = {};
|
|
1536
|
+
let footer;
|
|
1537
|
+
const slideCapabilities = [];
|
|
1538
|
+
const input = {
|
|
1539
|
+
type: node.type,
|
|
1540
|
+
props: nodeProps,
|
|
1541
|
+
children: node.children.map(capabilityChild)
|
|
1542
|
+
};
|
|
1543
|
+
const slideStyle = nodeProps["style"];
|
|
1544
|
+
const hasSlideStyleBackground = typeof slideStyle === "object" && slideStyle !== null && !Array.isArray(slideStyle) && Object.hasOwn(slideStyle, "background") && slideStyle["background"] !== void 0;
|
|
1545
|
+
if (hasSlideStyleBackground && ![...modules.slideModules.values()].some((module) => module.consumesOwnerBackgroundStyle === true)) slide.diagnostics.push(diagnostic(path, "missing-capability", "No capability module registered for Slide.style.background", {
|
|
1546
|
+
capability: "slide-background",
|
|
1547
|
+
field: "style.background"
|
|
1548
|
+
}));
|
|
1549
|
+
for (const module of modules.slideModules.values()) {
|
|
1550
|
+
const slideProps = module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp]);
|
|
1551
|
+
const hasStyleBackground = module.consumesOwnerBackgroundStyle === true && hasSlideStyleBackground;
|
|
1552
|
+
const hasSlideProps = slideProps.some((property) => Object.hasOwn(nodeProps, property)) || hasStyleBackground;
|
|
1553
|
+
if (!module.always && !hasSlideProps) {
|
|
1554
|
+
if (inheritedContinuity?.get(module.declaration) === true) slide.matchContinuityKinds = true;
|
|
1555
|
+
continue;
|
|
1556
|
+
}
|
|
1557
|
+
try {
|
|
1558
|
+
const boundSlide = validateBoundSlideCapability(module.bindSlide(input, {
|
|
1559
|
+
path,
|
|
1560
|
+
dimensions,
|
|
1561
|
+
theme,
|
|
1562
|
+
options,
|
|
1563
|
+
slideNumber: index,
|
|
1564
|
+
contributions,
|
|
1565
|
+
...inheritance === void 0 ? {} : { inheritance }
|
|
1566
|
+
}));
|
|
1567
|
+
if ((boundSlide.continuity?.matchSourceKinds ?? inheritedContinuity?.get(module.declaration)) === true) slide.matchContinuityKinds = true;
|
|
1568
|
+
const resolvedSlideCap = boundSlide.resolveSlide({
|
|
1569
|
+
path,
|
|
1570
|
+
dimensions,
|
|
1571
|
+
contributions,
|
|
1572
|
+
children,
|
|
1573
|
+
theme,
|
|
1574
|
+
options,
|
|
1575
|
+
slideNumber: index,
|
|
1576
|
+
...inheritance === void 0 ? {} : { inheritance }
|
|
1577
|
+
});
|
|
1578
|
+
if (resolvedSlideCap.observation !== void 0) capabilities[module.declaration] = resolvedSlideCap.observation;
|
|
1579
|
+
if (resolvedSlideCap.footer !== void 0) footer = resolvedSlideCap.footer;
|
|
1580
|
+
for (const extension of resolvedSlideCap.extensions) document.usedExtensions.add(extension);
|
|
1581
|
+
recordResourceClaims(resolvedSlideCap.resourceClaims, document, slide.diagnostics, path);
|
|
1582
|
+
recordFontUsages(resolvedSlideCap.fontUsages, document, path);
|
|
1583
|
+
slideCapabilities.push({
|
|
1584
|
+
declaration: module.declaration,
|
|
1585
|
+
slot: module.slot,
|
|
1586
|
+
hasSlideProps,
|
|
1587
|
+
path,
|
|
1588
|
+
theme,
|
|
1589
|
+
extensions: resolvedSlideCap.extensions,
|
|
1590
|
+
emit: (emitContext) => resolvedSlideCap.emit(emitContext),
|
|
1591
|
+
...resolvedSlideCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedSlideCap.paint(paintContext) }
|
|
1592
|
+
});
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
slide.diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path ?? path, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
for (const contribution of contributions) {
|
|
1598
|
+
if (contribution.optional) continue;
|
|
1599
|
+
const consumer = modules.slideModules.get(contribution.capability);
|
|
1600
|
+
if (consumer === void 0 || !consumer.always && !(consumer.slideProps ?? (consumer.slideProp === void 0 ? [] : [consumer.slideProp])).some((property) => Object.hasOwn(nodeProps, property))) slide.diagnostics.push(diagnostic(contribution.path, "missing-capability", `No capability module registered for ${contribution.capability}`));
|
|
1601
|
+
}
|
|
1602
|
+
if (slide.diagnostics.length > 0) throw new BuildError(slide.diagnostics);
|
|
1603
|
+
const projectedObjects = projectObservations(resolvedChildren.objects, slide.layoutDerivedObjectIds, slide.transformsById);
|
|
1604
|
+
const sortedLayouts = [...slide.layouts].sort((left, right) => left.id - right.id);
|
|
1605
|
+
const layoutId = layoutKey === void 0 ? void 0 : layoutIdByKey.get(layoutKey);
|
|
1606
|
+
const observation = {
|
|
1607
|
+
id,
|
|
1608
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1609
|
+
index,
|
|
1610
|
+
path,
|
|
1611
|
+
...layoutId === void 0 ? {} : { layout: layoutId },
|
|
1612
|
+
...section === void 0 ? {} : { section },
|
|
1613
|
+
...hidden ? { hidden: true } : {},
|
|
1614
|
+
...parsed.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsed.showMasterPlaceholderAnimations },
|
|
1615
|
+
objects: projectedObjects,
|
|
1616
|
+
...sortedLayouts.length > 0 && { layouts: sortedLayouts },
|
|
1617
|
+
...footer !== void 0 && { footer },
|
|
1618
|
+
...Object.keys(capabilities).length > 0 && { capabilities }
|
|
1619
|
+
};
|
|
1620
|
+
const effectiveThemeOverride = parsed.themeOverride ?? layoutSpec?.themeOverride;
|
|
1621
|
+
const effectiveColorMapOverride = parsed.colorMapOverride ?? layoutSpec?.colorMapOverride;
|
|
1622
|
+
const hasCustomColorMap = masterSpec !== void 0 && isCustomColorMap(masterSpec.colorMap);
|
|
1623
|
+
return {
|
|
1624
|
+
observation,
|
|
1625
|
+
morphObjects: slide.morphObjects,
|
|
1626
|
+
matchContinuityKinds: slide.matchContinuityKinds,
|
|
1627
|
+
linkedSlideIndexes: slide.linkedSlideIndexes,
|
|
1628
|
+
internal: {
|
|
1629
|
+
id,
|
|
1630
|
+
...name === void 0 ? {} : { name },
|
|
1631
|
+
...authorId === void 0 ? {} : { authorId },
|
|
1632
|
+
index,
|
|
1633
|
+
theme,
|
|
1634
|
+
...layoutKey === void 0 ? {} : { layoutKey },
|
|
1635
|
+
...parsed.colorMapOverride === void 0 ? {} : { colorMapOverride: parsed.colorMapOverride },
|
|
1636
|
+
...parsed.themeOverride === void 0 ? {} : { themeOverride: parsed.themeOverride },
|
|
1637
|
+
...effectiveThemeOverride === void 0 ? {} : { effectiveThemeOverride },
|
|
1638
|
+
...effectiveColorMapOverride === void 0 ? {} : { effectiveColorMapOverride },
|
|
1639
|
+
...hasCustomColorMap ? { hasCustomColorMap: true } : {},
|
|
1640
|
+
...section === void 0 ? {} : { section },
|
|
1641
|
+
hidden,
|
|
1642
|
+
...parsed.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsed.showMasterPlaceholderAnimations },
|
|
1643
|
+
...showMasterShapes === void 0 ? {} : { showMasterShapes },
|
|
1644
|
+
...inheritedBackground === void 0 ? {} : { inheritedBackground },
|
|
1645
|
+
...masterLayers === void 0 ? {} : { masterLayers },
|
|
1646
|
+
...layoutLayers === void 0 ? {} : { layoutLayers },
|
|
1647
|
+
content: resolvedChildren.content,
|
|
1648
|
+
layers: resolvedChildren.layers,
|
|
1649
|
+
slideCapabilities
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function resolveSharedCanvasLayers(args) {
|
|
1654
|
+
const { children, path, style, modules, dimensions, options, theme, document, initialNextId = 2 } = args;
|
|
1655
|
+
if (children.length === 0) {
|
|
1656
|
+
if (style !== void 0) new LayoutPass(modules.declarations, dimensions, 1, options).run([], path, theme, style);
|
|
1657
|
+
return {
|
|
1658
|
+
layers: [],
|
|
1659
|
+
objects: []
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
const state = {
|
|
1663
|
+
index: 1,
|
|
1664
|
+
nextId: initialNextId,
|
|
1665
|
+
nextNodeOrder: 0,
|
|
1666
|
+
diagnostics: [],
|
|
1667
|
+
layouts: [],
|
|
1668
|
+
contributions: [],
|
|
1669
|
+
morphObjects: /* @__PURE__ */ new Map(),
|
|
1670
|
+
matchContinuityKinds: false,
|
|
1671
|
+
linkedSlideIndexes: /* @__PURE__ */ new Set(),
|
|
1672
|
+
layoutDerivedObjectIds: /* @__PURE__ */ new Set(),
|
|
1673
|
+
transformsById: /* @__PURE__ */ new Map()
|
|
1674
|
+
};
|
|
1675
|
+
const resolved = resolveChildrenPass(children, {
|
|
1676
|
+
document,
|
|
1677
|
+
slide: state,
|
|
1678
|
+
modules,
|
|
1679
|
+
dimensions,
|
|
1680
|
+
options,
|
|
1681
|
+
theme,
|
|
1682
|
+
layout: new LayoutPass(modules.declarations, dimensions, 1, options).run(children, path, theme, style),
|
|
1683
|
+
slideNumber: 1,
|
|
1684
|
+
placeholderContexts: /* @__PURE__ */ new Map()
|
|
1685
|
+
}, path);
|
|
1686
|
+
for (const [, morphObj] of state.morphObjects) state.diagnostics.push(diagnostic(morphObj.path, "morph-on-master", "Morph handles are only supported on Slide objects"));
|
|
1687
|
+
for (const contribution of state.contributions) {
|
|
1688
|
+
if (contribution.optional) continue;
|
|
1689
|
+
state.diagnostics.push(diagnostic(contribution.path, "unsupported-declaration", `${contribution.capability} declarations are only supported inside Slide`));
|
|
1690
|
+
}
|
|
1691
|
+
if (state.diagnostics.length > 0) throw new BuildError(state.diagnostics);
|
|
1692
|
+
return {
|
|
1693
|
+
layers: resolved.layers,
|
|
1694
|
+
objects: projectObservations(resolved.objects, state.layoutDerivedObjectIds, state.transformsById)
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
function resolveMasterOrLayoutSlideCapability(args) {
|
|
1698
|
+
const { module, targetType, props, path, dimensions, theme, options, slideNumber, document } = args;
|
|
1699
|
+
try {
|
|
1700
|
+
const input = {
|
|
1701
|
+
type: targetType,
|
|
1702
|
+
props,
|
|
1703
|
+
children: []
|
|
1704
|
+
};
|
|
1705
|
+
const resolvedCap = validateBoundSlideCapability(module.bindSlide(input, {
|
|
1706
|
+
path,
|
|
1707
|
+
dimensions,
|
|
1708
|
+
theme,
|
|
1709
|
+
options,
|
|
1710
|
+
slideNumber,
|
|
1711
|
+
contributions: []
|
|
1712
|
+
})).resolveSlide({
|
|
1713
|
+
path,
|
|
1714
|
+
dimensions,
|
|
1715
|
+
contributions: [],
|
|
1716
|
+
children: [],
|
|
1717
|
+
theme,
|
|
1718
|
+
options,
|
|
1719
|
+
slideNumber
|
|
1720
|
+
});
|
|
1721
|
+
for (const extension of resolvedCap.extensions) document.usedExtensions.add(extension);
|
|
1722
|
+
const claimDiagnostics = [];
|
|
1723
|
+
recordResourceClaims(resolvedCap.resourceClaims, document, claimDiagnostics, path);
|
|
1724
|
+
recordFontUsages(resolvedCap.fontUsages, document, path);
|
|
1725
|
+
if (claimDiagnostics.length > 0) throw new BuildError(claimDiagnostics);
|
|
1726
|
+
return {
|
|
1727
|
+
declaration: module.declaration,
|
|
1728
|
+
slot: module.slot,
|
|
1729
|
+
hasSlideProps: true,
|
|
1730
|
+
path,
|
|
1731
|
+
theme,
|
|
1732
|
+
extensions: resolvedCap.extensions,
|
|
1733
|
+
emit: (emitContext) => resolvedCap.emit(emitContext),
|
|
1734
|
+
...resolvedCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedCap.paint(paintContext) }
|
|
1735
|
+
};
|
|
1736
|
+
} catch (error) {
|
|
1737
|
+
if (error instanceof BuildError) throw error;
|
|
1738
|
+
throw new BuildError([error instanceof CapabilityError ? diagnostic(error.path ?? path, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error))]);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
function normalizeLayoutPlaceholderIndices(placeholders, reservedIndices = []) {
|
|
1742
|
+
if (placeholders === void 0) return void 0;
|
|
1743
|
+
const entries = Object.entries(placeholders);
|
|
1744
|
+
if (entries.length <= 1) return placeholders;
|
|
1745
|
+
const usedIndices = /* @__PURE__ */ new Set();
|
|
1746
|
+
let unindexedCount = 0;
|
|
1747
|
+
for (const [, spec] of entries) if (spec.idx === void 0) unindexedCount += 1;
|
|
1748
|
+
else usedIndices.add(spec.idx);
|
|
1749
|
+
if (unindexedCount === 0 || unindexedCount === 1 && !usedIndices.has(0)) return placeholders;
|
|
1750
|
+
for (const reserved of reservedIndices) usedIndices.add(reserved);
|
|
1751
|
+
let primaryKey;
|
|
1752
|
+
if (!usedIndices.has(0)) {
|
|
1753
|
+
const primaryTitle = entries.find(([, spec]) => spec.idx === void 0 && (spec.type === "title" || spec.type === "ctrTitle"));
|
|
1754
|
+
const firstUnindexed = entries.find(([, spec]) => spec.idx === void 0);
|
|
1755
|
+
primaryKey = (primaryTitle ?? firstUnindexed)?.[0];
|
|
1756
|
+
if (primaryKey !== void 0) usedIndices.add(0);
|
|
1757
|
+
}
|
|
1758
|
+
let nextIdx = 1;
|
|
1759
|
+
const updated = {};
|
|
1760
|
+
for (const [key, spec] of entries) {
|
|
1761
|
+
if (spec.idx !== void 0 || key === primaryKey) {
|
|
1762
|
+
updated[key] = spec;
|
|
1763
|
+
continue;
|
|
1764
|
+
}
|
|
1765
|
+
while (usedIndices.has(nextIdx)) nextIdx += 1;
|
|
1766
|
+
usedIndices.add(nextIdx);
|
|
1767
|
+
updated[key] = Object.freeze({
|
|
1768
|
+
...spec,
|
|
1769
|
+
idx: nextIdx
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
return Object.freeze(updated);
|
|
1773
|
+
}
|
|
1774
|
+
function buildResolvedPlaceholders(placeholders, masterPlaceholders, masterTextStyles, dimensions) {
|
|
1775
|
+
if (placeholders === void 0) return [];
|
|
1776
|
+
const result = [];
|
|
1777
|
+
for (const [key, spec] of Object.entries(placeholders)) {
|
|
1778
|
+
const masterPh = masterPlaceholders === void 0 ? void 0 : matchMasterPlaceholderSpec(masterPlaceholders, spec.type);
|
|
1779
|
+
const resolvedBox = resolvePlaceholderBoxFromLayers([masterPh, spec], dimensions);
|
|
1780
|
+
const box = typeof resolvedBox.x === "number" && typeof resolvedBox.y === "number" && typeof resolvedBox.width === "number" && typeof resolvedBox.height === "number" ? {
|
|
1781
|
+
x: resolvedBox.x,
|
|
1782
|
+
y: resolvedBox.y,
|
|
1783
|
+
width: resolvedBox.width,
|
|
1784
|
+
height: resolvedBox.height
|
|
1785
|
+
} : void 0;
|
|
1786
|
+
const category = masterTextStyleCategoryForRole(spec.type);
|
|
1787
|
+
const masterTxLevel1 = masterTextStyles?.[category]?.[1];
|
|
1788
|
+
const rawMerged = {};
|
|
1789
|
+
for (const layer of [
|
|
1790
|
+
masterTxLevel1,
|
|
1791
|
+
masterPh?.style,
|
|
1792
|
+
masterPh?.listStyles?.[1],
|
|
1793
|
+
spec.style,
|
|
1794
|
+
spec.listStyles?.[1]
|
|
1795
|
+
]) if (layer !== void 0) Object.assign(rawMerged, layer);
|
|
1796
|
+
const mergedStyle = {};
|
|
1797
|
+
for (const [styleKey, styleValue] of Object.entries(rawMerged)) {
|
|
1798
|
+
if (styleValue === void 0) continue;
|
|
1799
|
+
mergedStyle[styleKey] = (styleKey === "fontFamily" || styleKey === "eastAsianFontFamily") && isFont(styleValue) ? styleValue.family : styleValue;
|
|
1800
|
+
}
|
|
1801
|
+
const idx = spec.idx ?? masterPh?.idx;
|
|
1802
|
+
const size = spec.size ?? masterPh?.size;
|
|
1803
|
+
result.push({
|
|
1804
|
+
key,
|
|
1805
|
+
type: spec.type,
|
|
1806
|
+
...idx === void 0 ? {} : { idx },
|
|
1807
|
+
...size === void 0 ? {} : { size },
|
|
1808
|
+
...box === void 0 ? {} : { box },
|
|
1809
|
+
...Object.keys(mergedStyle).length === 0 ? {} : { style: mergedStyle }
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
return result;
|
|
1813
|
+
}
|
|
1814
|
+
function deriveFooterPlaceholdersFromMap(placeholders) {
|
|
1815
|
+
if (placeholders === void 0) return void 0;
|
|
1816
|
+
const result = {};
|
|
1817
|
+
for (const spec of Object.values(placeholders)) {
|
|
1818
|
+
const slot = spec.type === "dt" ? "dateTime" : spec.type === "ftr" ? "footer" : spec.type === "sldNum" ? "slideNumber" : void 0;
|
|
1819
|
+
if (slot === void 0 || result[slot] !== void 0) continue;
|
|
1820
|
+
const mergedStyle = spec.style !== void 0 || spec.listStyles?.[1] !== void 0 ? {
|
|
1821
|
+
...spec.style,
|
|
1822
|
+
...spec.listStyles?.[1]
|
|
1823
|
+
} : void 0;
|
|
1824
|
+
const sizeVal = spec.size;
|
|
1825
|
+
result[slot] = {
|
|
1826
|
+
...spec.idx === void 0 ? {} : { idx: spec.idx },
|
|
1827
|
+
...sizeVal === "full" || sizeVal === "half" || sizeVal === "quarter" ? { size: sizeVal } : {},
|
|
1828
|
+
...spec.promptText === void 0 ? {} : { text: spec.promptText },
|
|
1829
|
+
...mergedStyle === void 0 ? {} : { style: mergedStyle },
|
|
1830
|
+
visible: false
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
const parsed = footerPlaceholdersSchema.safeParse(result);
|
|
1834
|
+
if (!parsed.success) return void 0;
|
|
1835
|
+
return Object.keys(parsed.data).length > 0 ? parsed.data : void 0;
|
|
1836
|
+
}
|
|
1837
|
+
function resolveDocument(container, modules, options) {
|
|
1838
|
+
const decks = childNodes(container.children);
|
|
1839
|
+
if (decks.length !== 1 || decks[0]?.type !== "deck") throw new BuildError([diagnostic("deck", "document-root", "Build content must have exactly one Deck root component")]);
|
|
1840
|
+
const deck = decks[0];
|
|
1841
|
+
const deckProps = readInternalDeclarationProps(deck);
|
|
1842
|
+
const { width, height, title } = parseDeckProps(deckProps);
|
|
1843
|
+
const size = {
|
|
1844
|
+
width,
|
|
1845
|
+
height
|
|
1846
|
+
};
|
|
1847
|
+
let theme;
|
|
1848
|
+
try {
|
|
1849
|
+
theme = createThemeContext(deckProps["theme"], deckProps["style"]);
|
|
1850
|
+
} catch (error) {
|
|
1851
|
+
if (!(error instanceof CapabilityError)) throw error;
|
|
1852
|
+
throw new BuildError([diagnostic("deck", error.code, error.message, error.details)]);
|
|
1853
|
+
}
|
|
1854
|
+
const { masters: parsedMasters, layoutIdByKey, slides, sections } = resolveSlides(container, modules, theme.theme);
|
|
1855
|
+
const mastersModule = modules.slideModules.get("slide-masters");
|
|
1856
|
+
if (parsedMasters.length > 0 && mastersModule === void 0) throw new BuildError([diagnostic(parsedMasters[0].path, "missing-capability", "No capability module registered for slide-masters")]);
|
|
1857
|
+
const slideRequiringMasters = slides.find((slide) => slide.colorMapOverride !== void 0 || slide.themeOverride !== void 0);
|
|
1858
|
+
if (slideRequiringMasters !== void 0 && mastersModule === void 0) throw new BuildError([diagnostic(`deck/slide[${slideRequiringMasters.id}]`, "missing-capability", "No capability module registered for slide-masters")]);
|
|
1859
|
+
let boundSections;
|
|
1860
|
+
if (sections.length > 0) {
|
|
1861
|
+
const sectionsModule = [...modules.slideModules.values()].find((module) => module.bindSections !== void 0);
|
|
1862
|
+
if (sectionsModule === void 0) throw new BuildError([diagnostic("deck/section[1]", "missing-capability", "No capability module registered for section")]);
|
|
1863
|
+
boundSections = sectionsModule.bindSections(sections);
|
|
1864
|
+
}
|
|
1865
|
+
const slideIndexById = new Map(slides.map((slide) => [slide.id, slide.index]));
|
|
1866
|
+
const sharedCanvasRoots = [...parsedMasters.flatMap((m) => m.canvasChildren), ...parsedMasters.flatMap((m) => m.layouts.flatMap((l) => childNodes(l.node.children)))];
|
|
1867
|
+
const document = {
|
|
1868
|
+
usedExtensions: new Set(boundSections?.extensions ?? []),
|
|
1869
|
+
resourceClaims: /* @__PURE__ */ new Map(),
|
|
1870
|
+
fontUsages: /* @__PURE__ */ new Map(),
|
|
1871
|
+
morphNames: /* @__PURE__ */ new Map(),
|
|
1872
|
+
nextMorphName: 1,
|
|
1873
|
+
reservedObjectNames: collectExplicitObjectNames(slides, modules.declarations, sharedCanvasRoots),
|
|
1874
|
+
slideIndexById
|
|
1875
|
+
};
|
|
1876
|
+
const bgModule = [...modules.slideModules.values()].find((module) => module.slot === "background" && module.consumesOwnerBackgroundStyle === true) ?? [...modules.slideModules.values()].find((module) => module.slot === "background");
|
|
1877
|
+
const footerModule = [...modules.slideModules.values()].find((module) => module.slot === "shape-tree" && module.declaration === "footer-placeholder");
|
|
1878
|
+
const resolvedMasters = [];
|
|
1879
|
+
const masterObservations = [];
|
|
1880
|
+
const masterByKey = /* @__PURE__ */ new Map();
|
|
1881
|
+
const masterByLayoutKey = /* @__PURE__ */ new Map();
|
|
1882
|
+
const layoutByKey = /* @__PURE__ */ new Map();
|
|
1883
|
+
const parsedLayoutByKey = /* @__PURE__ */ new Map();
|
|
1884
|
+
const continuityByLayoutKey = /* @__PURE__ */ new Map();
|
|
1885
|
+
for (const parsedMaster of parsedMasters) {
|
|
1886
|
+
let masterThemeBase;
|
|
1887
|
+
try {
|
|
1888
|
+
masterThemeBase = createThemeContext(parsedMaster.theme, deckProps["style"], { colorMap: parsedMaster.colorMap });
|
|
1889
|
+
if (parsedMaster.style !== void 0) masterThemeBase = masterThemeBase.withTextStyle(textStyleFrom(parsedMaster.style, masterThemeBase));
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
if (!(error instanceof CapabilityError)) throw error;
|
|
1892
|
+
throw new BuildError([diagnostic(parsedMaster.path, error.code, error.message)]);
|
|
1893
|
+
}
|
|
1894
|
+
const masterCapResult = resolveOwnerSlideCapabilities({
|
|
1895
|
+
type: "slide-master",
|
|
1896
|
+
props: parsedMaster.props,
|
|
1897
|
+
path: parsedMaster.path,
|
|
1898
|
+
modules,
|
|
1899
|
+
dimensions: size,
|
|
1900
|
+
document,
|
|
1901
|
+
options,
|
|
1902
|
+
theme: masterThemeBase
|
|
1903
|
+
});
|
|
1904
|
+
let masterBackground;
|
|
1905
|
+
if (parsedMaster.background !== void 0) {
|
|
1906
|
+
if (bgModule === void 0) throw new BuildError([diagnostic(parsedMaster.path, "missing-capability", "No capability module registered for SlideMaster.background")]);
|
|
1907
|
+
masterBackground = resolveMasterOrLayoutSlideCapability({
|
|
1908
|
+
module: bgModule,
|
|
1909
|
+
targetType: "slide-master",
|
|
1910
|
+
props: { background: parsedMaster.background },
|
|
1911
|
+
path: parsedMaster.path,
|
|
1912
|
+
dimensions: size,
|
|
1913
|
+
theme: masterThemeBase,
|
|
1914
|
+
options,
|
|
1915
|
+
slideNumber: 1,
|
|
1916
|
+
document
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
let masterFooterPlaceholders;
|
|
1920
|
+
if (parsedMaster.footerPlaceholders !== void 0) {
|
|
1921
|
+
if (footerModule === void 0) throw new BuildError([diagnostic(parsedMaster.path, "missing-capability", "No capability module registered for SlideMaster.footerPlaceholders")]);
|
|
1922
|
+
masterFooterPlaceholders = resolveMasterOrLayoutSlideCapability({
|
|
1923
|
+
module: footerModule,
|
|
1924
|
+
targetType: "slide-master",
|
|
1925
|
+
props: { footerPlaceholders: parsedMaster.footerPlaceholders },
|
|
1926
|
+
path: parsedMaster.path,
|
|
1927
|
+
dimensions: size,
|
|
1928
|
+
theme: masterThemeBase,
|
|
1929
|
+
options,
|
|
1930
|
+
slideNumber: 1,
|
|
1931
|
+
document
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
const masterPlaceholderVisuals = parsedMaster.placeholders !== void 0 && mastersModule !== void 0 ? resolveMasterOrLayoutSlideCapability({
|
|
1935
|
+
module: mastersModule,
|
|
1936
|
+
targetType: "slide-master",
|
|
1937
|
+
props: { placeholders: parsedMaster.placeholders },
|
|
1938
|
+
path: parsedMaster.path,
|
|
1939
|
+
dimensions: size,
|
|
1940
|
+
theme: masterThemeBase,
|
|
1941
|
+
options,
|
|
1942
|
+
slideNumber: 1,
|
|
1943
|
+
document
|
|
1944
|
+
}) : void 0;
|
|
1945
|
+
const masterShared = resolveSharedCanvasLayers({
|
|
1946
|
+
children: parsedMaster.canvasChildren.map(capabilityChild),
|
|
1947
|
+
path: parsedMaster.path,
|
|
1948
|
+
style: readInternalDeclarationProps(parsedMaster.node)["style"],
|
|
1949
|
+
modules,
|
|
1950
|
+
dimensions: size,
|
|
1951
|
+
options,
|
|
1952
|
+
theme: masterThemeBase,
|
|
1953
|
+
document,
|
|
1954
|
+
initialNextId: 2 + Object.keys(parsedMaster.placeholders ?? {}).length
|
|
1955
|
+
});
|
|
1956
|
+
const masterPlaceholders = buildResolvedPlaceholders(parsedMaster.placeholders, void 0, parsedMaster.textStyles, size);
|
|
1957
|
+
const resolvedLayouts = [];
|
|
1958
|
+
const observedLayouts = [];
|
|
1959
|
+
for (const parsedLayout of parsedMaster.layouts) {
|
|
1960
|
+
parsedLayoutByKey.set(parsedLayout.key, {
|
|
1961
|
+
master: parsedMaster,
|
|
1962
|
+
layout: parsedLayout
|
|
1963
|
+
});
|
|
1964
|
+
let layoutThemeBase = masterThemeBase;
|
|
1965
|
+
if (parsedLayout.data.themeOverride !== void 0 || parsedLayout.data.colorMapOverride !== void 0) layoutThemeBase = layoutThemeBase.withNativeOverrides(parsedLayout.data.themeOverride, parsedLayout.data.colorMapOverride);
|
|
1966
|
+
if (parsedLayout.style !== void 0) try {
|
|
1967
|
+
layoutThemeBase = layoutThemeBase.withTextStyle(textStyleFrom(parsedLayout.style, layoutThemeBase));
|
|
1968
|
+
} catch (error) {
|
|
1969
|
+
if (!(error instanceof CapabilityError)) throw error;
|
|
1970
|
+
throw new BuildError([diagnostic(parsedLayout.path, error.code, error.message)]);
|
|
1971
|
+
}
|
|
1972
|
+
const layoutCapResult = resolveOwnerSlideCapabilities({
|
|
1973
|
+
type: "slide-layout",
|
|
1974
|
+
props: parsedLayout.props,
|
|
1975
|
+
path: parsedLayout.path,
|
|
1976
|
+
modules,
|
|
1977
|
+
dimensions: size,
|
|
1978
|
+
document,
|
|
1979
|
+
options,
|
|
1980
|
+
theme: layoutThemeBase
|
|
1981
|
+
});
|
|
1982
|
+
const mergedContinuity = new Map(masterCapResult.continuityByDeclaration);
|
|
1983
|
+
for (const [decl, match] of layoutCapResult.continuityByDeclaration) if (match !== void 0) mergedContinuity.set(decl, match);
|
|
1984
|
+
continuityByLayoutKey.set(parsedLayout.key, mergedContinuity);
|
|
1985
|
+
let layoutBackground;
|
|
1986
|
+
if (parsedLayout.background !== void 0) {
|
|
1987
|
+
if (bgModule === void 0) throw new BuildError([diagnostic(parsedLayout.path, "missing-capability", "No capability module registered for SlideLayout.background")]);
|
|
1988
|
+
layoutBackground = resolveMasterOrLayoutSlideCapability({
|
|
1989
|
+
module: bgModule,
|
|
1990
|
+
targetType: "slide-layout",
|
|
1991
|
+
props: { background: parsedLayout.background },
|
|
1992
|
+
path: parsedLayout.path,
|
|
1993
|
+
dimensions: size,
|
|
1994
|
+
theme: layoutThemeBase,
|
|
1995
|
+
options,
|
|
1996
|
+
slideNumber: 1,
|
|
1997
|
+
document
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
let layoutFooterPlaceholders;
|
|
2001
|
+
if (parsedLayout.footerPlaceholders !== void 0) {
|
|
2002
|
+
if (footerModule === void 0) throw new BuildError([diagnostic(parsedLayout.path, "missing-capability", "No capability module registered for SlideLayout.footerPlaceholders")]);
|
|
2003
|
+
layoutFooterPlaceholders = resolveMasterOrLayoutSlideCapability({
|
|
2004
|
+
module: footerModule,
|
|
2005
|
+
targetType: "slide-layout",
|
|
2006
|
+
props: { footerPlaceholders: parsedLayout.footerPlaceholders },
|
|
2007
|
+
path: parsedLayout.path,
|
|
2008
|
+
dimensions: size,
|
|
2009
|
+
theme: layoutThemeBase,
|
|
2010
|
+
options,
|
|
2011
|
+
slideNumber: 1,
|
|
2012
|
+
document
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
const layoutPlaceholderVisuals = parsedLayout.placeholders !== void 0 && mastersModule !== void 0 ? resolveMasterOrLayoutSlideCapability({
|
|
2016
|
+
module: mastersModule,
|
|
2017
|
+
targetType: "slide-layout",
|
|
2018
|
+
props: { placeholders: parsedLayout.placeholders },
|
|
2019
|
+
path: parsedLayout.path,
|
|
2020
|
+
dimensions: size,
|
|
2021
|
+
theme: layoutThemeBase,
|
|
2022
|
+
options,
|
|
2023
|
+
slideNumber: 1,
|
|
2024
|
+
document
|
|
2025
|
+
}) : void 0;
|
|
2026
|
+
const layoutShared = resolveSharedCanvasLayers({
|
|
2027
|
+
children: parsedLayout.node.children.map(capabilityChild),
|
|
2028
|
+
path: parsedLayout.path,
|
|
2029
|
+
style: parsedLayout.style,
|
|
2030
|
+
modules,
|
|
2031
|
+
dimensions: size,
|
|
2032
|
+
options,
|
|
2033
|
+
theme: layoutThemeBase,
|
|
2034
|
+
document,
|
|
2035
|
+
initialNextId: 2 + Object.keys(parsedLayout.placeholders ?? {}).length
|
|
2036
|
+
});
|
|
2037
|
+
const layoutPlaceholders = buildResolvedPlaceholders(parsedLayout.placeholders, parsedMaster.placeholders, parsedMaster.textStyles, size);
|
|
2038
|
+
const resolvedLayout = {
|
|
2039
|
+
key: parsedLayout.key,
|
|
2040
|
+
masterKey: parsedMaster.key,
|
|
2041
|
+
...parsedLayout.data,
|
|
2042
|
+
...parsedLayout.placeholders === void 0 ? {} : { placeholders: parsedLayout.placeholders },
|
|
2043
|
+
...layoutBackground === void 0 ? {} : { background: layoutBackground },
|
|
2044
|
+
...layoutFooterPlaceholders === void 0 ? {} : { footerPlaceholders: layoutFooterPlaceholders },
|
|
2045
|
+
...layoutPlaceholderVisuals === void 0 ? {} : { placeholderVisuals: layoutPlaceholderVisuals },
|
|
2046
|
+
...layoutShared.layers.length === 0 ? {} : { layers: layoutShared.layers },
|
|
2047
|
+
...layoutCapResult.slideCapabilities.length > 0 ? { slideCapabilities: layoutCapResult.slideCapabilities } : {}
|
|
2048
|
+
};
|
|
2049
|
+
resolvedLayouts.push(resolvedLayout);
|
|
2050
|
+
layoutByKey.set(parsedLayout.key, resolvedLayout);
|
|
2051
|
+
observedLayouts.push({
|
|
2052
|
+
...parsedLayout.data,
|
|
2053
|
+
objects: layoutShared.objects,
|
|
2054
|
+
placeholders: layoutPlaceholders,
|
|
2055
|
+
...Object.keys(layoutCapResult.capabilities).length > 0 ? { capabilities: layoutCapResult.capabilities } : {}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
const resolvedMaster = {
|
|
2059
|
+
key: parsedMaster.key,
|
|
2060
|
+
id: parsedMaster.id,
|
|
2061
|
+
...parsedMaster.name === void 0 ? {} : { name: parsedMaster.name },
|
|
2062
|
+
...parsedMaster.preserve === void 0 ? {} : { preserve: parsedMaster.preserve },
|
|
2063
|
+
theme: parsedMaster.theme,
|
|
2064
|
+
themeContext: masterThemeBase,
|
|
2065
|
+
colorMap: parsedMaster.colorMap,
|
|
2066
|
+
...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
|
|
2067
|
+
...masterBackground === void 0 ? {} : { background: masterBackground },
|
|
2068
|
+
...masterFooterPlaceholders === void 0 ? {} : { footerPlaceholders: masterFooterPlaceholders },
|
|
2069
|
+
...masterPlaceholderVisuals === void 0 ? {} : { placeholderVisuals: masterPlaceholderVisuals },
|
|
2070
|
+
...masterShared.layers.length === 0 ? {} : { layers: masterShared.layers },
|
|
2071
|
+
...parsedMaster.placeholders === void 0 ? {} : { placeholders: parsedMaster.placeholders },
|
|
2072
|
+
...parsedMaster.textStyles === void 0 ? {} : { textStyles: parsedMaster.textStyles },
|
|
2073
|
+
...masterCapResult.slideCapabilities.length > 0 ? { slideCapabilities: masterCapResult.slideCapabilities } : {},
|
|
2074
|
+
layouts: resolvedLayouts
|
|
2075
|
+
};
|
|
2076
|
+
masterByKey.set(parsedMaster.key, resolvedMaster);
|
|
2077
|
+
resolvedMasters.push(resolvedMaster);
|
|
2078
|
+
for (const resolvedLayout of resolvedLayouts) masterByLayoutKey.set(resolvedLayout.key, resolvedMaster);
|
|
2079
|
+
masterObservations.push({
|
|
2080
|
+
id: parsedMaster.id,
|
|
2081
|
+
...parsedMaster.name === void 0 ? {} : { name: parsedMaster.name },
|
|
2082
|
+
...parsedMaster.preserve === void 0 ? {} : { preserve: parsedMaster.preserve },
|
|
2083
|
+
...parsedMaster.explicitColorMap === void 0 ? {} : { colorMap: parsedMaster.explicitColorMap },
|
|
2084
|
+
...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
|
|
2085
|
+
objects: masterShared.objects,
|
|
2086
|
+
placeholders: masterPlaceholders,
|
|
2087
|
+
...Object.keys(masterCapResult.capabilities).length > 0 ? { capabilities: masterCapResult.capabilities } : {},
|
|
2088
|
+
layouts: observedLayouts
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
const resolvedSlides = slides.map((parsedSlide) => {
|
|
2092
|
+
const boundMaster = parsedSlide.layoutKey === void 0 ? void 0 : masterByLayoutKey.get(parsedSlide.layoutKey);
|
|
2093
|
+
const boundLayout = parsedSlide.layoutKey === void 0 ? void 0 : layoutByKey.get(parsedSlide.layoutKey);
|
|
2094
|
+
let slideThemeBase;
|
|
2095
|
+
if (boundMaster !== void 0) {
|
|
2096
|
+
slideThemeBase = createThemeContext(boundMaster.theme, deckProps["style"], { colorMap: boundMaster.colorMap });
|
|
2097
|
+
if (boundLayout?.themeOverride !== void 0 || boundLayout?.colorMapOverride !== void 0) slideThemeBase = slideThemeBase.withNativeOverrides(boundLayout.themeOverride, boundLayout.colorMapOverride);
|
|
2098
|
+
} else slideThemeBase = theme;
|
|
2099
|
+
if (parsedSlide.themeOverride !== void 0 || parsedSlide.colorMapOverride !== void 0) slideThemeBase = slideThemeBase.withNativeOverrides(parsedSlide.themeOverride, parsedSlide.colorMapOverride);
|
|
2100
|
+
const parsedOwner = parsedSlide.layoutKey === void 0 ? void 0 : parsedLayoutByKey.get(parsedSlide.layoutKey);
|
|
2101
|
+
const parsedMaster = parsedOwner?.master;
|
|
2102
|
+
const parsedLayout = parsedOwner?.layout;
|
|
2103
|
+
const slideNodeProps = readInternalDeclarationProps(parsedSlide.node);
|
|
2104
|
+
const slideStyleObj = slideNodeProps["style"];
|
|
2105
|
+
const hasSlideStyleBackground = typeof slideStyleObj === "object" && slideStyleObj !== null && !Array.isArray(slideStyleObj) && Object.hasOwn(slideStyleObj, "background") && slideStyleObj["background"] !== void 0;
|
|
2106
|
+
let inheritedBackground;
|
|
2107
|
+
if (!Object.hasOwn(slideNodeProps, "background") && !hasSlideStyleBackground && parsedSlide.layoutKey !== void 0 && bgModule !== void 0) {
|
|
2108
|
+
const inheritedDecl = parsedLayout?.background ?? parsedMaster?.background;
|
|
2109
|
+
if (inheritedDecl !== void 0) inheritedBackground = resolveMasterOrLayoutSlideCapability({
|
|
2110
|
+
module: bgModule,
|
|
2111
|
+
targetType: "slide",
|
|
2112
|
+
props: { background: inheritedDecl },
|
|
2113
|
+
path: `deck/slide[${parsedSlide.id}]`,
|
|
2114
|
+
dimensions: size,
|
|
2115
|
+
theme: slideThemeBase,
|
|
2116
|
+
options,
|
|
2117
|
+
slideNumber: parsedSlide.index,
|
|
2118
|
+
document
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
const masterFooter = parsedMaster?.footerPlaceholders ?? deriveFooterPlaceholdersFromMap(parsedMaster?.placeholders);
|
|
2122
|
+
const layoutFooter = parsedLayout?.footerPlaceholders ?? deriveFooterPlaceholdersFromMap(parsedLayout?.placeholders);
|
|
2123
|
+
const inheritance = parsedMaster !== void 0 || parsedLayout !== void 0 ? {
|
|
2124
|
+
...parsedMaster === void 0 ? {} : { master: {
|
|
2125
|
+
...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
|
|
2126
|
+
...masterFooter === void 0 ? {} : { footerPlaceholders: masterFooter }
|
|
2127
|
+
} },
|
|
2128
|
+
...parsedLayout === void 0 ? {} : { layout: {
|
|
2129
|
+
...parsedLayout.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.headerFooter },
|
|
2130
|
+
...layoutFooter === void 0 ? {} : { footerPlaceholders: layoutFooter }
|
|
2131
|
+
} }
|
|
2132
|
+
} : void 0;
|
|
2133
|
+
const slideShowsMaster = parsedSlide.showMasterShapes ?? true;
|
|
2134
|
+
const layoutShowsMaster = boundLayout?.showMasterShapes ?? true;
|
|
2135
|
+
const activeMasterLayers = slideShowsMaster && layoutShowsMaster && (boundMaster?.layers?.length ?? 0) > 0 ? boundMaster.layers : void 0;
|
|
2136
|
+
const activeLayoutLayers = slideShowsMaster && (boundLayout?.layers?.length ?? 0) > 0 ? boundLayout.layers : void 0;
|
|
2137
|
+
return resolveSlideDeclaration(parsedSlide, modules, size, document, options, slideThemeBase, layoutIdByKey, layoutByKey, masterByKey, parsedSlide.layoutKey === void 0 ? void 0 : continuityByLayoutKey.get(parsedSlide.layoutKey), inheritedBackground, activeMasterLayers, activeLayoutLayers, inheritance);
|
|
2138
|
+
});
|
|
2139
|
+
const morphDiagnostics = [];
|
|
2140
|
+
for (let index = 0; index < slides.length; index += 1) {
|
|
2141
|
+
const current = slides[index];
|
|
2142
|
+
const currentResult = resolvedSlides[index];
|
|
2143
|
+
if (current === void 0 || currentResult === void 0 || !currentResult.matchContinuityKinds) continue;
|
|
2144
|
+
const sourceIndexes = /* @__PURE__ */ new Set();
|
|
2145
|
+
if (!current.hidden) {
|
|
2146
|
+
let priorVisible = index - 1;
|
|
2147
|
+
while (priorVisible >= 0 && slides[priorVisible]?.hidden === true) priorVisible -= 1;
|
|
2148
|
+
if (priorVisible >= 0) sourceIndexes.add(priorVisible);
|
|
2149
|
+
}
|
|
2150
|
+
for (let sourceIndex = 0; sourceIndex < resolvedSlides.length; sourceIndex += 1) if (sourceIndex !== index && resolvedSlides[sourceIndex]?.linkedSlideIndexes.has(current.index)) sourceIndexes.add(sourceIndex);
|
|
2151
|
+
for (const [key, object] of currentResult.morphObjects) for (const sourceIndex of sourceIndexes) {
|
|
2152
|
+
const source = resolvedSlides[sourceIndex]?.morphObjects.get(key);
|
|
2153
|
+
if (source === void 0 || source.kind === object.kind) continue;
|
|
2154
|
+
morphDiagnostics.push(diagnostic(object.path, "morph-object-kind-mismatch", `Native object ${object.name} (handle "${getMorphKeyLabel(key)}") corresponds to ${source.kind} on source slide ${slides[sourceIndex]?.id} and ${object.kind} on current slide; only matching native object kinds are supported`));
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
if (morphDiagnostics.length > 0) throw new BuildError(morphDiagnostics);
|
|
2158
|
+
const slideObservations = resolvedSlides.map(({ observation }) => observation);
|
|
2159
|
+
const report = deepFreeze({
|
|
2160
|
+
evidence: "generation",
|
|
2161
|
+
...typeof title === "string" ? { title } : {},
|
|
2162
|
+
dimensions: {
|
|
2163
|
+
width: size.width,
|
|
2164
|
+
height: size.height
|
|
2165
|
+
},
|
|
2166
|
+
extensions: [...document.usedExtensions],
|
|
2167
|
+
fonts: summarizeDocumentFonts(document.fontUsages),
|
|
2168
|
+
...masterObservations.length > 0 ? { masters: masterObservations } : {},
|
|
2169
|
+
slides: slideObservations
|
|
2170
|
+
});
|
|
2171
|
+
const query = createBuildQuery(resolvedSlides.map((slide, index) => ({
|
|
2172
|
+
observation: report.slides[index],
|
|
2173
|
+
dimensions: report.dimensions,
|
|
2174
|
+
content: slide.internal.content
|
|
2175
|
+
})));
|
|
2176
|
+
const resolution = Object.freeze({
|
|
2177
|
+
report,
|
|
2178
|
+
slides: query.slides,
|
|
2179
|
+
slide: (id) => query.slide(id)
|
|
2180
|
+
});
|
|
2181
|
+
const internal = {
|
|
2182
|
+
dimensions: size,
|
|
2183
|
+
...typeof title === "string" ? { title } : {},
|
|
2184
|
+
theme,
|
|
2185
|
+
...resolvedMasters.length > 0 ? { masters: resolvedMasters } : {},
|
|
2186
|
+
...mastersModule?.mastersCanvas === void 0 ? {} : { mastersCanvas: mastersModule.mastersCanvas },
|
|
2187
|
+
...mastersModule?.mastersEmitDriver === void 0 ? {} : { mastersEmitDriver: mastersModule.mastersEmitDriver },
|
|
2188
|
+
sections,
|
|
2189
|
+
...boundSections === void 0 ? {} : { sectionsEmitter: boundSections },
|
|
2190
|
+
slides: resolvedSlides.map(({ internal: slideInternal }) => slideInternal),
|
|
2191
|
+
resourceClaims: document.resourceClaims
|
|
2192
|
+
};
|
|
2193
|
+
registerInternalResolution(resolution, internal);
|
|
2194
|
+
return resolution;
|
|
2195
|
+
}
|
|
2196
|
+
function normalizeDeclarationInput(input) {
|
|
2197
|
+
if (isDeclarationNode(input)) return { children: [input] };
|
|
2198
|
+
if (typeof input === "object" && input !== null && "children" in input && Array.isArray(input.children)) return input;
|
|
2199
|
+
return { children: [] };
|
|
2200
|
+
}
|
|
2201
|
+
function createResolver(modules) {
|
|
2202
|
+
const bound = bindCapabilityModules(modules);
|
|
2203
|
+
return function resolve(declaration, options = {}) {
|
|
2204
|
+
validateResolveOptions(options);
|
|
2205
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
2206
|
+
return resolveDocument(normalizeDeclarationInput(declaration), bound, options);
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
function validateBoundSlideCapability(bound) {
|
|
2210
|
+
if (typeof bound !== "object" || bound === null) throw new CapabilityError("invalid-capability-binding", "Slide capability bindSlide() must return a resolveSlide handler");
|
|
2211
|
+
if (typeof bound.resolveSlide !== "function") throw new CapabilityError("invalid-capability-binding", "Slide capability bindSlide() must return a resolveSlide handler");
|
|
2212
|
+
return bound;
|
|
2213
|
+
}
|
|
2214
|
+
function bindCapabilityModules(modules) {
|
|
2215
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
2216
|
+
const slideModules = /* @__PURE__ */ new Map();
|
|
2217
|
+
for (const module of modules) {
|
|
2218
|
+
if (typeof module !== "object" || module === null) throw new BuildError([diagnostic("build.modules", "invalid-capability-module", "Capability module must be an object")]);
|
|
2219
|
+
const slideModule = "bindSlide" in module && typeof module.bindSlide === "function" && !("bind" in module) && !("parse" in module) ? module : void 0;
|
|
2220
|
+
const objectModule = "bind" in module && typeof module.bind === "function" && !("parse" in module) && !("bindSlide" in module) ? module : void 0;
|
|
2221
|
+
if (slideModule === void 0 && objectModule === void 0) {
|
|
2222
|
+
const rawDeclaration = module.declaration;
|
|
2223
|
+
const declarationLabel = typeof rawDeclaration === "string" && rawDeclaration.trim() !== "" ? rawDeclaration : "<unknown>";
|
|
2224
|
+
throw new BuildError([diagnostic("build.modules", "invalid-capability-module", `Capability module ${declarationLabel} must implement the bound bind() or bindSlide() contract`)]);
|
|
2225
|
+
}
|
|
2226
|
+
if (typeof module.declaration !== "string" || module.declaration.trim() === "") throw new BuildError([diagnostic("build.modules", "invalid-capability-module", "Capability module declaration must be a non-empty string")]);
|
|
2227
|
+
if (slideModule !== void 0) {
|
|
2228
|
+
if (slideModules.has(slideModule.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
|
|
2229
|
+
slideModules.set(slideModule.declaration, slideModule);
|
|
2230
|
+
for (const transparent of slideModule.transparentDeclarations ?? []) {
|
|
2231
|
+
if (typeof transparent.declaration !== "string" || transparent.declaration.trim() === "") throw new BuildError([diagnostic("build.modules", "invalid-capability-module", "Capability module declaration must be a non-empty string")]);
|
|
2232
|
+
if (!("compileDeclaration" in transparent) || typeof transparent.compileDeclaration !== "function") throw new BuildError([diagnostic("build.modules", "invalid-capability-module", `Transparent declaration ${transparent.declaration} must implement compileDeclaration()`)]);
|
|
2233
|
+
if (declarations.has(transparent.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
|
|
2234
|
+
declarations.set(transparent.declaration, transparent);
|
|
2235
|
+
}
|
|
2236
|
+
} else if (objectModule !== void 0) {
|
|
2237
|
+
if (declarations.has(objectModule.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
|
|
2238
|
+
declarations.set(objectModule.declaration, objectModule);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
return {
|
|
2242
|
+
declarations,
|
|
2243
|
+
slideModules
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
export { createResolver };
|