@officedk/pptxdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/build.d.ts +94 -0
  4. package/dist/build.js +148 -0
  5. package/dist/capabilities/dist/all.js +32 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +51 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +31 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +138 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +77 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2272 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1078 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1124 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +190 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +519 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +48 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +148 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +289 -0
  38. package/dist/capabilities/dist/font/font-family.js +10 -0
  39. package/dist/capabilities/dist/font/font-import.js +302 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +25 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +51 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +42 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +319 -0
  46. package/dist/capabilities/dist/group/group-xml.js +7 -0
  47. package/dist/capabilities/dist/group/group.js +211 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +94 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +221 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +778 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +149 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +472 -0
  57. package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
  58. package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
  59. package/dist/capabilities/dist/masters/masters.js +250 -0
  60. package/dist/capabilities/dist/motion/motion-api.js +527 -0
  61. package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
  62. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  63. package/dist/capabilities/dist/motion/motion-import.js +1033 -0
  64. package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
  65. package/dist/capabilities/dist/motion/motion-query.js +420 -0
  66. package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
  67. package/dist/capabilities/dist/motion/motion.js +1372 -0
  68. package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
  69. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  70. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  71. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  72. package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
  73. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  74. package/dist/capabilities/dist/notes/notes.js +191 -0
  75. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
  76. package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
  77. package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
  78. package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
  79. package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
  80. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  81. package/dist/capabilities/dist/shape/shape-import.js +579 -0
  82. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  83. package/dist/capabilities/dist/shape/shape.js +337 -0
  84. package/dist/capabilities/dist/shared/geometry.js +1423 -0
  85. package/dist/capabilities/dist/shared/identity.js +205 -0
  86. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  87. package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
  88. package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
  89. package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
  90. package/dist/capabilities/dist/shared/style-parse.js +11 -0
  91. package/dist/capabilities/dist/shared/text-schemas.js +216 -0
  92. package/dist/capabilities/dist/shared/text-service.js +1883 -0
  93. package/dist/capabilities/dist/shared/visual.js +918 -0
  94. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  95. package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
  96. package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
  97. package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
  98. package/dist/capabilities/dist/table/table-codegen.js +81 -0
  99. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  100. package/dist/capabilities/dist/table/table-elements.js +27 -0
  101. package/dist/capabilities/dist/table/table-import.js +539 -0
  102. package/dist/capabilities/dist/table/table-schemas.js +279 -0
  103. package/dist/capabilities/dist/table/table-xml.js +37 -0
  104. package/dist/capabilities/dist/table/table.js +662 -0
  105. package/dist/capabilities/dist/text/text-codegen.js +129 -0
  106. package/dist/capabilities/dist/text/text-declaration.js +19 -0
  107. package/dist/capabilities/dist/text/text-elements.js +38 -0
  108. package/dist/capabilities/dist/text/text-import.js +1077 -0
  109. package/dist/capabilities/dist/text/text-xml.js +9 -0
  110. package/dist/capabilities/dist/text/text.js +335 -0
  111. package/dist/capabilities/dist/transition/transition-api.js +139 -0
  112. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  113. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  114. package/dist/capabilities/dist/transition/transition.js +260 -0
  115. package/dist/capability-D_xeNVIw.d.ts +29496 -0
  116. package/dist/cli.js +20 -0
  117. package/dist/codegen/dist/assets.js +78 -0
  118. package/dist/codegen/dist/codegen.js +611 -0
  119. package/dist/codegen/dist/identifiers.js +193 -0
  120. package/dist/codegen/dist/index.js +3 -0
  121. package/dist/codegen/dist/printer.js +143 -0
  122. package/dist/codegen/dist/types.js +49 -0
  123. package/dist/core/dist/author-ids.js +48 -0
  124. package/dist/core/dist/author-schemas.js +313 -0
  125. package/dist/core/dist/block-flex-layout.js +749 -0
  126. package/dist/core/dist/build.js +4 -0
  127. package/dist/core/dist/capability.js +13 -0
  128. package/dist/core/dist/declaration.js +15 -0
  129. package/dist/core/dist/diagnostics.js +21 -0
  130. package/dist/core/dist/document-internals.js +13 -0
  131. package/dist/core/dist/document.js +408 -0
  132. package/dist/core/dist/geometry-schemas.js +249 -0
  133. package/dist/core/dist/grid-layout.js +445 -0
  134. package/dist/core/dist/host.js +40 -0
  135. package/dist/core/dist/index.js +15 -0
  136. package/dist/core/dist/input-values.js +45 -0
  137. package/dist/core/dist/layout-protocol.js +66 -0
  138. package/dist/core/dist/layout-schemas.js +208 -0
  139. package/dist/core/dist/layout.js +299 -0
  140. package/dist/core/dist/masters.js +169 -0
  141. package/dist/core/dist/morph.js +30 -0
  142. package/dist/core/dist/placeholders.js +213 -0
  143. package/dist/core/dist/query.js +155 -0
  144. package/dist/core/dist/resolution.js +11 -0
  145. package/dist/core/dist/resolve.js +1827 -0
  146. package/dist/core/dist/stage-options.js +67 -0
  147. package/dist/core/dist/theme.js +931 -0
  148. package/dist/document-BHPUODPP.d.ts +27759 -0
  149. package/dist/emit/dist/emit.js +936 -0
  150. package/dist/emit/dist/index.js +5 -0
  151. package/dist/emit/dist/ooxml.js +606 -0
  152. package/dist/emit/dist/shape-tree.js +12 -0
  153. package/dist/import/dist/alternate-content.js +54 -0
  154. package/dist/import/dist/diagnostics.js +153 -0
  155. package/dist/import/dist/fonts.js +250 -0
  156. package/dist/import/dist/import.js +504 -0
  157. package/dist/import/dist/index.js +16 -0
  158. package/dist/import/dist/masters.js +1153 -0
  159. package/dist/import/dist/mechanism.js +10 -0
  160. package/dist/import/dist/namespaces.js +60 -0
  161. package/dist/import/dist/notes-masters.js +300 -0
  162. package/dist/import/dist/opc.js +233 -0
  163. package/dist/import/dist/resources.js +166 -0
  164. package/dist/import/dist/sections.js +139 -0
  165. package/dist/import/dist/themes.js +671 -0
  166. package/dist/import/dist/visual.js +761 -0
  167. package/dist/import/dist/xml-fragments.js +36 -0
  168. package/dist/import/dist/xml-reader.js +267 -0
  169. package/dist/index-B5m3hqjC.d.ts +7 -0
  170. package/dist/index-CCy-Yo8G.d.ts +1208 -0
  171. package/dist/index-DpxcZ4Gs.d.ts +725 -0
  172. package/dist/index.d.ts +7 -0
  173. package/dist/index.js +70 -0
  174. package/dist/node.d.ts +53 -0
  175. package/dist/node.js +194 -0
  176. package/dist/pptxdk/src/cli-commands.js +913 -0
  177. package/dist/pptxdk/src/compose.js +44 -0
  178. package/dist/pptxdk/src/slide.js +9 -0
  179. package/dist/preview/dist/index.js +240 -0
  180. package/dist/preview/dist/options.js +53 -0
  181. package/dist/preview-Cfw0QdMM.d.ts +86 -0
  182. package/dist/preview.d.ts +3 -0
  183. package/dist/preview.js +27 -0
  184. package/dist/react/dist/append.js +66 -0
  185. package/dist/react/dist/document-adapter.js +65 -0
  186. package/dist/react/dist/elements.js +59 -0
  187. package/dist/react/dist/index.js +68 -0
  188. package/dist/react/dist/reconciler.js +290 -0
  189. package/dist/react.d.ts +145 -0
  190. package/dist/react.js +27 -0
  191. package/dist/transition-Cips9wma.d.ts +82 -0
  192. package/dist/vanilla.d.ts +4 -0
  193. package/dist/vanilla.js +14 -0
  194. package/package.json +78 -3
@@ -0,0 +1,1827 @@
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 } from "./diagnostics.js";
5
+ import { LayoutPass, validateBoundObjectCapability } from "./layout.js";
6
+ import { footerPlaceholdersSchema, isSlideLayoutDefinition, slideLayoutDataPropsSchema, slideMasterDataPropsSchema } from "./masters.js";
7
+ import { getMorphKeyLabel, isMorphKey } from "./morph.js";
8
+ import { matchMasterPlaceholderSpec, nativePlaceholderRefSchema } from "./placeholders.js";
9
+ import { createBuildQuery } from "./query.js";
10
+ import { registerInternalResolution } from "./resolution.js";
11
+ import { resolveOptionsSchema } from "./stage-options.js";
12
+ import { createThemeContext, defaultColorMap, defineTheme, isTheme, textStyleFrom } from "./theme.js";
13
+ // ../core/dist/resolve.js
14
+ function diagnostic(path, code, message) {
15
+ return {
16
+ severity: "error",
17
+ path,
18
+ code,
19
+ message
20
+ };
21
+ }
22
+ function deepFreeze(value) {
23
+ if (typeof value !== "object" || value === null) return value;
24
+ if (!Object.isFrozen(value)) Object.freeze(value);
25
+ for (const child of Object.values(value)) deepFreeze(child);
26
+ return value;
27
+ }
28
+ function reportBox(box) {
29
+ return {
30
+ x: Math.round(box.x * 100) / 100,
31
+ y: Math.round(box.y * 100) / 100,
32
+ width: Math.round(box.width * 100) / 100,
33
+ height: Math.round(box.height * 100) / 100
34
+ };
35
+ }
36
+ function projectObservation(observation, layoutDerivedObjectIds) {
37
+ const box = observation.box !== void 0 && layoutDerivedObjectIds.has(observation.id) ? reportBox(observation.box) : observation.box;
38
+ const members = observation.members === void 0 ? void 0 : observation.members.map((member) => projectObservation(member, layoutDerivedObjectIds));
39
+ return {
40
+ ...observation,
41
+ ...box === void 0 || box === observation.box ? {} : { box },
42
+ ...members === void 0 ? {} : { members }
43
+ };
44
+ }
45
+ function projectObservations(observations, layoutDerivedObjectIds) {
46
+ return observations.map((observation) => projectObservation(observation, layoutDerivedObjectIds));
47
+ }
48
+ function isObjectCapability(module) {
49
+ return "bind" in module;
50
+ }
51
+ function nonWhitespaceText(children) {
52
+ return children.some((child) => !isDeclarationNode(child) && child.text.trim() !== "");
53
+ }
54
+ function childNodes(children) {
55
+ return children.filter(isDeclarationNode);
56
+ }
57
+ function capabilityChild(child) {
58
+ if (!isDeclarationNode(child)) return {
59
+ type: "#text",
60
+ text: child.text
61
+ };
62
+ return {
63
+ type: child.type,
64
+ props: child.props,
65
+ children: child.children.map(capabilityChild),
66
+ ...child.pageAffiliated === true ? { pageAffiliated: true } : {}
67
+ };
68
+ }
69
+ function capabilityLabel(child, index) {
70
+ if (!("props" in child)) return `text[${index + 1}]`;
71
+ const identity = declarationIdentity(child.props);
72
+ const label = typeof identity === "string" && identity.trim() !== "" ? identity : String(index + 1);
73
+ return `${child.type}[${label}]`;
74
+ }
75
+ function isHiddenByStyle(node) {
76
+ const style = node.props["style"];
77
+ return typeof style === "object" && style !== null && !Array.isArray(style) && "display" in style && style.display === "none";
78
+ }
79
+ function collectExplicitObjectNamesFromChildren(children, modules, names) {
80
+ for (const child of children) {
81
+ if (!isDeclarationNode(child) || isHiddenByStyle(child)) continue;
82
+ const module = modules.get(child.type);
83
+ if (module !== void 0 && "compileDeclaration" in module) {
84
+ if (module.children === "owned") continue;
85
+ collectExplicitObjectNamesFromChildren(child.children, modules, names);
86
+ continue;
87
+ }
88
+ const rawName = child.props["name"];
89
+ if (typeof rawName === "string" && rawName.trim() !== "") names.add(rawName);
90
+ collectExplicitObjectNamesFromChildren(child.children, modules, names);
91
+ }
92
+ }
93
+ function collectExplicitObjectNames(slides, modules, extraChildren = []) {
94
+ const names = /* @__PURE__ */ new Set();
95
+ for (const slide of slides) collectExplicitObjectNamesFromChildren(slide.node.children, modules, names);
96
+ collectExplicitObjectNamesFromChildren(extraChildren, modules, names);
97
+ return names;
98
+ }
99
+ function nativeObjectName(key, document) {
100
+ let name = document.morphNames.get(key);
101
+ if (name === void 0) {
102
+ do
103
+ name = `!!morph-${document.nextMorphName++}`;
104
+ while (document.reservedObjectNames.has(name));
105
+ document.morphNames.set(key, name);
106
+ }
107
+ return name;
108
+ }
109
+ function validateResolveOptions(options) {
110
+ const parsed = resolveOptionsSchema.safeParse(options);
111
+ if (parsed.success) return;
112
+ const issue = parsed.error.issues[0];
113
+ if (issue === void 0) return;
114
+ if (issue.path.length === 0 && issue.code === "unrecognized_keys") throw new BuildError([diagnostic("resolve", "unknown-parameter", `Resolve options contain unknown parameter ${issue.keys[0]}`)]);
115
+ if (issue.path[0] === "signal") throw new BuildError([diagnostic("resolve.signal", "invalid-options", "Resolve options signal must be an AbortSignal")]);
116
+ throw new BuildError([diagnostic("resolve", "invalid-options", "Resolve options must be an object")]);
117
+ }
118
+ function unknownPropertyKey(props, allowed) {
119
+ const allowedSet = new Set(allowed);
120
+ return Object.keys(props).find((key) => !allowedSet.has(key));
121
+ }
122
+ function resolveSlides(container, modules, defaultDeckTheme) {
123
+ const decks = childNodes(container.children);
124
+ if (decks.length !== 1 || decks[0]?.type !== "deck") throw new BuildError([diagnostic("deck", "document-root", "Build content must have exactly one Deck root component")]);
125
+ const deck = decks[0];
126
+ if (deck === void 0) throw new BuildError([diagnostic("deck", "document-root", "Missing Deck root component")]);
127
+ if (nonWhitespaceText(container.children)) throw new BuildError([diagnostic("deck", "unexpected-text", "No text allowed outside the Deck root component")]);
128
+ if (nonWhitespaceText(deck.children)) throw new BuildError([diagnostic("deck", "unexpected-text", "Deck can only contain SlideMaster, Slide, and Section components")]);
129
+ const topLevel = childNodes(deck.children);
130
+ if (topLevel.length === 0 || topLevel.length !== deck.children.filter(isDeclarationNode).length) throw new BuildError([diagnostic("deck", "missing-slide", "Deck requires at least one Slide")]);
131
+ const masterNodes = topLevel.filter((node) => node.type === "slide-master");
132
+ const slideOrSectionNodes = topLevel.filter((node) => node.type !== "slide-master");
133
+ const authorIds = /* @__PURE__ */ new Set();
134
+ const slideProperties = [...modules.slideModules.values()].flatMap((module) => module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp]));
135
+ const slidePropertySet = new Set(slideProperties);
136
+ const knownTrimmedSlideProps = /* @__PURE__ */ new Set([
137
+ "transition",
138
+ "advanceAfter",
139
+ "motion"
140
+ ]);
141
+ const masters = [];
142
+ const layoutKeyByNode = /* @__PURE__ */ new Map();
143
+ const layoutKeysByDefinition = /* @__PURE__ */ new Map();
144
+ const layoutIdByKey = /* @__PURE__ */ new Map();
145
+ let defaultBlankLayoutKey;
146
+ let firstLayoutKey;
147
+ let globalLayoutCounter = 0;
148
+ for (const [masterIndex, masterNode] of masterNodes.entries()) {
149
+ const rawMasterPath = `deck/slide-master[${masterIndex + 1}]`;
150
+ const masterAuthorId = readAuthorId(masterNode.props["id"], rawMasterPath);
151
+ const masterKey = `master-${masterIndex + 1}`;
152
+ const masterId = masterAuthorId ?? masterKey;
153
+ const masterPath = `deck/slide-master[${masterAuthorId ?? masterIndex + 1}]`;
154
+ const unknownMasterProp = unknownPropertyKey(masterNode.props, [
155
+ "id",
156
+ "name",
157
+ "preserve",
158
+ "theme",
159
+ "colorMap",
160
+ "style",
161
+ "background",
162
+ "headerFooter",
163
+ "footerPlaceholders",
164
+ "placeholders",
165
+ "textStyles",
166
+ ...slideProperties
167
+ ]);
168
+ if (unknownMasterProp !== void 0) {
169
+ if (knownTrimmedSlideProps.has(unknownMasterProp)) throw new BuildError([diagnostic(masterPath, "missing-capability", `No capability module registered for SlideMaster.${unknownMasterProp}`)]);
170
+ throw new BuildError([diagnostic(masterPath, "unknown-parameter", `SlideMaster contains unknown parameter ${unknownMasterProp}`)]);
171
+ }
172
+ const masterDataInput = {};
173
+ for (const key of [
174
+ "id",
175
+ "name",
176
+ "preserve",
177
+ "colorMap",
178
+ "background",
179
+ "headerFooter",
180
+ "footerPlaceholders",
181
+ "placeholders",
182
+ "textStyles"
183
+ ]) if (Object.hasOwn(masterNode.props, key)) masterDataInput[key] = masterNode.props[key];
184
+ const parsedMaster = slideMasterDataPropsSchema.safeParse(masterDataInput);
185
+ if (!parsedMaster.success) throw new BuildError([diagnostic(masterPath, "invalid-slide-master", parsedMaster.error.issues[0]?.message ?? "Invalid SlideMaster declaration")]);
186
+ let masterTheme;
187
+ const rawMasterTheme = masterNode.props["theme"];
188
+ if (rawMasterTheme === void 0) masterTheme = defaultDeckTheme;
189
+ else if (isTheme(rawMasterTheme)) masterTheme = rawMasterTheme;
190
+ else try {
191
+ masterTheme = defineTheme(rawMasterTheme);
192
+ } catch (error) {
193
+ if (error instanceof CapabilityError) throw new BuildError([diagnostic(masterPath, error.code, error.message)]);
194
+ throw new BuildError([diagnostic(masterPath, "invalid-theme", error instanceof Error ? error.message : String(error))]);
195
+ }
196
+ if (masterAuthorId !== void 0) {
197
+ if (!xml10StringSchema.safeParse(masterAuthorId).success) throw new BuildError([diagnostic(masterPath, "invalid-xml-character", "SlideMaster.id contains characters not allowed in XML 1.0")]);
198
+ if (authorIds.has(masterAuthorId)) throw new BuildError([diagnostic(masterPath, "duplicate-author-id", `Duplicate author id ${JSON.stringify(masterAuthorId)} in the deck`)]);
199
+ authorIds.add(masterAuthorId);
200
+ }
201
+ 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")]);
202
+ for (const phSpec of Object.values(parsedMaster.data.placeholders ?? {})) for (const phText of [phSpec.name, phSpec.promptText]) {
203
+ if (phText === void 0) continue;
204
+ if (!xml10StringSchema.safeParse(phText).success) throw new BuildError([diagnostic(masterPath, "invalid-xml-character", "SlideMaster placeholder text contains characters not allowed in XML 1.0")]);
205
+ }
206
+ if (nonWhitespaceText(masterNode.children)) throw new BuildError([diagnostic(masterPath, "unexpected-text", "SlideMaster cannot directly contain text")]);
207
+ const masterChildren = childNodes(masterNode.children);
208
+ const layoutNodes = [];
209
+ const masterCanvasNodes = [];
210
+ for (const child of masterChildren) if (child.type === "slide-layout") layoutNodes.push(child);
211
+ else masterCanvasNodes.push(child);
212
+ if (layoutNodes.length === 0) throw new BuildError([diagnostic(masterPath, "empty-slide-master", "SlideMaster requires at least one SlideLayout")]);
213
+ const masterLayoutIds = /* @__PURE__ */ new Set();
214
+ const resolvedLayouts = [];
215
+ for (const [layoutIndex, layoutNode] of layoutNodes.entries()) {
216
+ const rawLayoutPath = `${masterPath}/slide-layout[${layoutIndex + 1}]`;
217
+ const rawLayoutDef = layoutNode.props["layout"];
218
+ let layoutDef;
219
+ if (rawLayoutDef !== void 0) {
220
+ if (!isSlideLayoutDefinition(rawLayoutDef)) throw new BuildError([diagnostic(rawLayoutPath, "invalid-slide-layout", "SlideLayout.layout must be created by defineSlideLayout()")]);
221
+ layoutDef = rawLayoutDef;
222
+ }
223
+ const effectiveLayoutProps = { ...layoutDef?.props };
224
+ for (const [key, value] of Object.entries(layoutNode.props)) {
225
+ if (key === "layout" || value === void 0) continue;
226
+ effectiveLayoutProps[key] = value;
227
+ }
228
+ const unknownLayoutProp = unknownPropertyKey(effectiveLayoutProps, [
229
+ "id",
230
+ "name",
231
+ "type",
232
+ "preserve",
233
+ "matchingName",
234
+ "userDrawn",
235
+ "showMasterShapes",
236
+ "showMasterPlaceholderAnimations",
237
+ "placeholders",
238
+ "colorMapOverride",
239
+ "themeOverride",
240
+ "background",
241
+ "headerFooter",
242
+ "footerPlaceholders",
243
+ ...slideProperties
244
+ ]);
245
+ if (unknownLayoutProp !== void 0) {
246
+ if (knownTrimmedSlideProps.has(unknownLayoutProp)) throw new BuildError([diagnostic(rawLayoutPath, "missing-capability", `No capability module registered for SlideLayout.${unknownLayoutProp}`)]);
247
+ throw new BuildError([diagnostic(rawLayoutPath, "unknown-parameter", `SlideLayout contains unknown parameter ${unknownLayoutProp}`)]);
248
+ }
249
+ const layoutDataInput = {};
250
+ for (const key of [
251
+ "id",
252
+ "name",
253
+ "type",
254
+ "preserve",
255
+ "matchingName",
256
+ "userDrawn",
257
+ "showMasterShapes",
258
+ "showMasterPlaceholderAnimations",
259
+ "placeholders",
260
+ "colorMapOverride",
261
+ "themeOverride",
262
+ "background",
263
+ "headerFooter",
264
+ "footerPlaceholders"
265
+ ]) if (Object.hasOwn(effectiveLayoutProps, key)) layoutDataInput[key] = effectiveLayoutProps[key];
266
+ const parsedLayout = slideLayoutDataPropsSchema.safeParse(layoutDataInput);
267
+ if (!parsedLayout.success) throw new BuildError([diagnostic(rawLayoutPath, "invalid-slide-layout", parsedLayout.error.issues[0]?.message ?? "Invalid SlideLayout declaration")]);
268
+ const layoutAuthorId = readAuthorId(parsedLayout.data.id, rawLayoutPath);
269
+ const layoutId = layoutAuthorId ?? `layout-${layoutIndex + 1}`;
270
+ const layoutPath = `${masterPath}/slide-layout[${layoutAuthorId ?? layoutIndex + 1}]`;
271
+ if (layoutAuthorId !== void 0) {
272
+ if (masterLayoutIds.has(layoutAuthorId)) throw new BuildError([diagnostic(layoutPath, "duplicate-author-id", `Duplicate SlideLayout.id ${JSON.stringify(layoutAuthorId)} in ${masterPath}`)]);
273
+ masterLayoutIds.add(layoutAuthorId);
274
+ }
275
+ for (const textField of [
276
+ parsedLayout.data.id,
277
+ parsedLayout.data.name,
278
+ parsedLayout.data.matchingName
279
+ ]) {
280
+ if (textField === void 0) continue;
281
+ if (!xml10StringSchema.safeParse(textField).success) throw new BuildError([diagnostic(layoutPath, "invalid-xml-character", "SlideLayout text property contains characters not allowed in XML 1.0")]);
282
+ }
283
+ for (const phSpec of Object.values(parsedLayout.data.placeholders ?? {})) for (const phText of [phSpec.name, phSpec.promptText]) {
284
+ if (phText === void 0) continue;
285
+ if (!xml10StringSchema.safeParse(phText).success) throw new BuildError([diagnostic(layoutPath, "invalid-xml-character", "SlideLayout placeholder text contains characters not allowed in XML 1.0")]);
286
+ }
287
+ validateAuthorIdScopes(layoutNode, layoutPath, /* @__PURE__ */ new Set());
288
+ if (nonWhitespaceText(layoutNode.children)) throw new BuildError([diagnostic(layoutPath, "unexpected-text", "SlideLayout cannot directly contain text")]);
289
+ const layoutKey = `layout-${++globalLayoutCounter}`;
290
+ layoutKeyByNode.set(layoutNode, layoutKey);
291
+ if (layoutDef !== void 0) {
292
+ const existing = layoutKeysByDefinition.get(layoutDef) ?? [];
293
+ existing.push(layoutKey);
294
+ layoutKeysByDefinition.set(layoutDef, existing);
295
+ }
296
+ layoutIdByKey.set(layoutKey, layoutId);
297
+ firstLayoutKey ??= layoutKey;
298
+ if (parsedLayout.data.type === "blank" && defaultBlankLayoutKey === void 0) defaultBlankLayoutKey = layoutKey;
299
+ const layoutData = {
300
+ id: layoutId,
301
+ ...parsedLayout.data.name === void 0 ? {} : { name: parsedLayout.data.name },
302
+ ...parsedLayout.data.type === void 0 ? {} : { type: parsedLayout.data.type },
303
+ ...parsedLayout.data.preserve === void 0 ? {} : { preserve: parsedLayout.data.preserve },
304
+ ...parsedLayout.data.matchingName === void 0 ? {} : { matchingName: parsedLayout.data.matchingName },
305
+ ...parsedLayout.data.userDrawn === void 0 ? {} : { userDrawn: parsedLayout.data.userDrawn },
306
+ ...parsedLayout.data.showMasterShapes === void 0 ? {} : { showMasterShapes: parsedLayout.data.showMasterShapes },
307
+ ...parsedLayout.data.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsedLayout.data.showMasterPlaceholderAnimations },
308
+ ...parsedLayout.data.colorMapOverride === void 0 ? {} : { colorMapOverride: parsedLayout.data.colorMapOverride },
309
+ ...parsedLayout.data.themeOverride === void 0 ? {} : { themeOverride: parsedLayout.data.themeOverride },
310
+ ...parsedLayout.data.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.data.headerFooter }
311
+ };
312
+ const reservedFooterIndices = [];
313
+ for (const footerSource of [parsedMaster.data.footerPlaceholders, parsedLayout.data.footerPlaceholders]) {
314
+ if (footerSource === void 0) continue;
315
+ if (footerSource.dateTime !== void 0) reservedFooterIndices.push(footerSource.dateTime.idx ?? 2);
316
+ if (footerSource.footer !== void 0) reservedFooterIndices.push(footerSource.footer.idx ?? 3);
317
+ if (footerSource.slideNumber !== void 0) reservedFooterIndices.push(footerSource.slideNumber.idx ?? 4);
318
+ }
319
+ const normalizedLayoutPlaceholders = normalizeLayoutPlaceholderIndices(parsedLayout.data.placeholders, reservedFooterIndices);
320
+ const layoutSlideProps = normalizedLayoutPlaceholders === void 0 ? {} : { placeholders: normalizedLayoutPlaceholders };
321
+ for (const prop of slidePropertySet) {
322
+ if (prop === "background") continue;
323
+ if (Object.hasOwn(effectiveLayoutProps, prop)) layoutSlideProps[prop] = effectiveLayoutProps[prop];
324
+ }
325
+ resolvedLayouts.push({
326
+ node: layoutNode,
327
+ key: layoutKey,
328
+ path: layoutPath,
329
+ data: layoutData,
330
+ ...normalizedLayoutPlaceholders === void 0 ? {} : { placeholders: normalizedLayoutPlaceholders },
331
+ ...parsedLayout.data.background === void 0 ? {} : { background: parsedLayout.data.background },
332
+ ...parsedLayout.data.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.data.headerFooter },
333
+ ...parsedLayout.data.footerPlaceholders === void 0 ? {} : { footerPlaceholders: parsedLayout.data.footerPlaceholders },
334
+ props: layoutSlideProps
335
+ });
336
+ }
337
+ if (masterCanvasNodes.length > 0) validateAuthorIdScopes({
338
+ type: "slide-master",
339
+ props: masterNode.props,
340
+ children: masterCanvasNodes
341
+ }, masterPath, new Set(masterLayoutIds));
342
+ const masterSlideProps = parsedMaster.data.placeholders === void 0 ? {} : { placeholders: parsedMaster.data.placeholders };
343
+ for (const prop of slidePropertySet) {
344
+ if (prop === "background") continue;
345
+ if (Object.hasOwn(masterNode.props, prop)) masterSlideProps[prop] = masterNode.props[prop];
346
+ }
347
+ const masterStyleProp = masterNode.props["style"];
348
+ masters.push({
349
+ node: masterNode,
350
+ canvasChildren: masterCanvasNodes,
351
+ key: masterKey,
352
+ id: masterId,
353
+ path: masterPath,
354
+ ...parsedMaster.data.name === void 0 ? {} : { name: parsedMaster.data.name },
355
+ ...parsedMaster.data.preserve === void 0 ? {} : { preserve: parsedMaster.data.preserve },
356
+ theme: masterTheme,
357
+ colorMap: parsedMaster.data.colorMap ?? defaultColorMap,
358
+ ...parsedMaster.data.colorMap === void 0 ? {} : { explicitColorMap: parsedMaster.data.colorMap },
359
+ ...masterStyleProp !== void 0 && typeof masterStyleProp === "object" && masterStyleProp !== null && !Array.isArray(masterStyleProp) ? { style: masterStyleProp } : {},
360
+ ...parsedMaster.data.placeholders === void 0 ? {} : { placeholders: parsedMaster.data.placeholders },
361
+ ...parsedMaster.data.textStyles === void 0 ? {} : { textStyles: parsedMaster.data.textStyles },
362
+ ...parsedMaster.data.background === void 0 ? {} : { background: parsedMaster.data.background },
363
+ ...parsedMaster.data.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.data.headerFooter },
364
+ ...parsedMaster.data.footerPlaceholders === void 0 ? {} : { footerPlaceholders: parsedMaster.data.footerPlaceholders },
365
+ props: masterSlideProps,
366
+ layouts: resolvedLayouts
367
+ });
368
+ }
369
+ const sectioned = slideOrSectionNodes.some((node) => node.type === "section");
370
+ const candidates = [];
371
+ const sections = [];
372
+ if (sectioned) for (const [index, node] of slideOrSectionNodes.entries()) {
373
+ if (node.type !== "section") throw new BuildError([diagnostic(`deck/${componentLabel(node, index)}`, "mixed-sections", "When using Section, every slide must belong to a Section")]);
374
+ const { name } = parseSectionProps(node.props, index);
375
+ if (nonWhitespaceText(node.children)) throw new BuildError([diagnostic(`deck/section[${name}]`, "unexpected-section-text", "Section can only contain Slide components")]);
376
+ const sectionIndex = sections.length;
377
+ const section = {
378
+ name,
379
+ slideIndexes: []
380
+ };
381
+ sections.push(section);
382
+ for (const [memberIndex, member] of childNodes(node.children).entries()) {
383
+ 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")]);
384
+ candidates.push({
385
+ node: member,
386
+ section: name,
387
+ sectionIndex
388
+ });
389
+ }
390
+ }
391
+ else for (const [index, node] of slideOrSectionNodes.entries()) {
392
+ if (node.type !== "slide") throw new BuildError([diagnostic(`deck/${componentLabel(node, index)}`, "unexpected-declaration", "Direct children of Deck must be SlideMaster, Slide, or Section")]);
393
+ candidates.push({ node });
394
+ }
395
+ if (candidates.length === 0 && masters.length === 0) throw new BuildError([diagnostic("deck", "missing-slide", "Deck requires at least one Slide")]);
396
+ return {
397
+ masters,
398
+ layoutIdByKey,
399
+ slides: candidates.map(({ node, section, sectionIndex }, index) => {
400
+ const { id, name, hidden, showMasterPlaceholderAnimations, showMasterShapes, colorMapOverride, themeOverride } = parseSlideCoreProps(node.props, index, slideProperties);
401
+ const authorId = id;
402
+ if (authorIds.has(authorId)) throw new BuildError([diagnostic(`deck/slide[${authorId}]`, "duplicate-author-id", `Duplicate Slide.id ${JSON.stringify(authorId)} in the deck`)]);
403
+ authorIds.add(authorId);
404
+ validateAuthorIdScopes(node, `deck/slide[${id}]`, /* @__PURE__ */ new Set());
405
+ let layoutKey;
406
+ const rawLayout = node.props["layout"];
407
+ if (rawLayout === void 0) {
408
+ if (masters.length > 0) layoutKey = defaultBlankLayoutKey ?? firstLayoutKey;
409
+ } else if (isSlideLayoutDefinition(rawLayout)) {
410
+ const keys = layoutKeysByDefinition.get(rawLayout);
411
+ const targetLabel = rawLayout.id ?? rawLayout.name ?? "<unnamed>";
412
+ 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`)]);
413
+ 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`)]);
414
+ layoutKey = keys[0];
415
+ } else if (isDeclarationNode(rawLayout)) {
416
+ if (rawLayout.type !== "slide-layout") throw new BuildError([diagnostic(`deck/slide[${id}]`, "invalid-slide-layout", "Slide.layout must be a SlideLayout or defineSlideLayout specification")]);
417
+ const matchedKey = layoutKeyByNode.get(rawLayout);
418
+ if (matchedKey === void 0) {
419
+ const rawTarget = rawLayout.props["id"] ?? rawLayout.props["name"];
420
+ const targetLabel = typeof rawTarget === "string" ? rawTarget : "<unnamed>";
421
+ 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`)]);
422
+ }
423
+ layoutKey = matchedKey;
424
+ } else throw new BuildError([diagnostic(`deck/slide[${id}]`, "invalid-slide-layout", "Slide.layout must be a SlideLayout or defineSlideLayout specification")]);
425
+ const resolved = {
426
+ node,
427
+ id,
428
+ ...name === void 0 ? {} : { name },
429
+ ...authorId === void 0 ? {} : { authorId },
430
+ index: index + 1,
431
+ ...layoutKey === void 0 ? {} : { layoutKey },
432
+ hasExplicitLayout: rawLayout !== void 0,
433
+ ...colorMapOverride === void 0 ? {} : { colorMapOverride },
434
+ ...themeOverride === void 0 ? {} : { themeOverride },
435
+ ...section === void 0 ? {} : { section },
436
+ ...hidden === void 0 ? {} : { hidden },
437
+ ...showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations },
438
+ ...showMasterShapes === void 0 ? {} : { showMasterShapes }
439
+ };
440
+ if (sectionIndex !== void 0) sections[sectionIndex]?.slideIndexes.push(index + 1);
441
+ return resolved;
442
+ }),
443
+ sections: sections.map(({ name, slideIndexes }) => ({
444
+ name,
445
+ slideIndexes
446
+ }))
447
+ };
448
+ }
449
+ function validateLink(value, context, path) {
450
+ let parsed;
451
+ try {
452
+ parsed = parseLinkTarget(value, path);
453
+ } catch (error) {
454
+ if (error instanceof CapabilityError) {
455
+ context.slide.diagnostics.push(diagnostic(path, error.code, error.message));
456
+ return;
457
+ }
458
+ throw error;
459
+ }
460
+ if (parsed === void 0) return void 0;
461
+ if ("id" in parsed) {
462
+ const targetIndex = context.document.slideIndexById.get(parsed.id);
463
+ if (targetIndex === void 0) {
464
+ context.slide.diagnostics.push(diagnostic(path, "missing-link-target", `No target slide with author id ${JSON.stringify(parsed.id)}`));
465
+ return;
466
+ }
467
+ if (targetIndex !== context.slide.index) context.slide.linkedSlideIndexes.add(targetIndex);
468
+ return {
469
+ target: { id: parsed.id },
470
+ summary: `slide:${parsed.id}`
471
+ };
472
+ }
473
+ if ("url" in parsed) {
474
+ let url;
475
+ try {
476
+ url = new URL(parsed.url);
477
+ } catch {
478
+ context.slide.diagnostics.push(diagnostic(path, "invalid-link", "link.url must be an absolute URL"));
479
+ return;
480
+ }
481
+ return {
482
+ target: { url: url.href },
483
+ summary: `url:${url.href}`
484
+ };
485
+ }
486
+ return {
487
+ target: { action: "home" },
488
+ summary: "home"
489
+ };
490
+ }
491
+ function recordResourceClaims(claims, document, diagnostics, path) {
492
+ for (const claim of claims ?? []) {
493
+ const claimKey = `${claim.kind}\u0000${claim.key}`;
494
+ const existing = document.resourceClaims.get(claimKey);
495
+ if (existing !== void 0 && existing.identity !== claim.identity) diagnostics.push(diagnostic(path, "conflicting-resource", `Resource ${claim.key} has conflicting definition with ${existing.path}`));
496
+ else document.resourceClaims.set(claimKey, {
497
+ identity: claim.identity,
498
+ path: existing?.path ?? path,
499
+ characters: (existing?.characters ?? "") + (claim.characters ?? "")
500
+ });
501
+ }
502
+ }
503
+ function recordCapabilityWarnings(warnings, document, path) {
504
+ for (const warning of warnings ?? []) document.warnings.push({
505
+ severity: "warning",
506
+ path: warning.path === void 0 ? path : `${path}/${warning.path}`,
507
+ code: warning.code,
508
+ message: warning.message
509
+ });
510
+ }
511
+ function checkCanvasOverflow(box, dimensions, document, path) {
512
+ if (box === void 0) return;
513
+ if (box.x < 0 || box.y < 0 || box.x + box.width > dimensions.width || box.y + box.height > dimensions.height) document.warnings.push({
514
+ severity: "warning",
515
+ path,
516
+ code: "overflow",
517
+ message: "Object overflows slide canvas; build retains original declaration"
518
+ });
519
+ }
520
+ function recordObjectMorph(args) {
521
+ const { morphKey, morphName, nativeKind, observationName, hasOutput, slide, declarationType, path } = args;
522
+ if (morphKey === void 0 || morphName === void 0) return;
523
+ if (!hasOutput) slide.diagnostics.push(diagnostic(path, "morph-needs-object", "morphKey can only be used with capabilities that produce native objects"));
524
+ 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`));
525
+ else if (!slide.morphObjects.has(morphKey)) slide.morphObjects.set(morphKey, {
526
+ kind: nativeKind,
527
+ name: morphName,
528
+ path
529
+ });
530
+ }
531
+ function createObjectResolveContext(args) {
532
+ const { resolveContext, id, path, layoutBox, theme, placeholder, insideGroup, restrictsMemberContinuity, morphName, link, onChildrenResolved } = args;
533
+ return {
534
+ id,
535
+ path,
536
+ theme,
537
+ options: resolveContext.options,
538
+ slideNumber: resolveContext.slideNumber,
539
+ ...layoutBox === void 0 ? {} : { layoutBox },
540
+ ...placeholder === void 0 ? {} : { placeholder },
541
+ ...morphName === void 0 ? {} : { morphName },
542
+ ...link === void 0 ? {} : { link },
543
+ resolveChildren(nested) {
544
+ const resolved = resolveChildrenPass(nested, resolveContext, path, insideGroup || restrictsMemberContinuity);
545
+ onChildrenResolved?.(resolved);
546
+ return { objects: resolved.objects };
547
+ }
548
+ };
549
+ }
550
+ function resolveChildrenPass(children, context, parentPath, insideGroup = false) {
551
+ const layers = [];
552
+ const content = [];
553
+ children.forEach((child, index) => {
554
+ if (!("props" in child)) {
555
+ if (child.text.trim() !== "") context.slide.diagnostics.push(diagnostic(`${parentPath}/${capabilityLabel(child, index)}`, "unexpected-text", "Native object container cannot directly contain text"));
556
+ return;
557
+ }
558
+ if (context.layout.hidden.has(child)) return;
559
+ const path = `${parentPath}/${capabilityLabel(child, index)}`;
560
+ const authorId = readAuthorId(child.props["id"], path);
561
+ const order = context.slide.nextNodeOrder++;
562
+ const module = context.modules.declarations.get(child.type);
563
+ if (module === void 0) {
564
+ context.slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
565
+ return;
566
+ }
567
+ if ("compileDeclaration" in module) {
568
+ if (module.children === "owned") return;
569
+ try {
570
+ for (const annotation of module.compileDeclaration(child, {
571
+ path,
572
+ theme: context.theme,
573
+ slideNumber: context.slideNumber
574
+ })) context.slide.contributions.push({
575
+ ...annotation,
576
+ path,
577
+ order,
578
+ declaration: child
579
+ });
580
+ } catch (error) {
581
+ 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)));
582
+ }
583
+ const childResolved = resolveChildrenPass(child.children, context, path, insideGroup);
584
+ content.push(...childResolved.content);
585
+ for (const entry of childResolved.entries) layers.push({
586
+ ...entry,
587
+ layer: {
588
+ ...entry.layer,
589
+ sourceOrder: [index, ...entry.layer.sourceOrder]
590
+ }
591
+ });
592
+ return;
593
+ }
594
+ if (!isObjectCapability(module)) {
595
+ context.slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
596
+ return;
597
+ }
598
+ const layoutBox = context.layout.boxes.get(child);
599
+ const placeholder = context.placeholderContexts.get(child);
600
+ const theme = placeholder !== void 0 ? placeholder.masterTheme : context.layout.themes.get(child) ?? context.theme;
601
+ try {
602
+ const bound = context.layout.bound.get(child) ?? validateBoundObjectCapability(module.bind(child, {
603
+ path,
604
+ theme,
605
+ options: context.options,
606
+ slideNumber: context.slideNumber,
607
+ ...placeholder === void 0 ? {} : { placeholder }
608
+ }));
609
+ if (bound.container !== void 0) {
610
+ resolveBoundContainer({
611
+ child,
612
+ index,
613
+ path,
614
+ authorId,
615
+ order,
616
+ bound,
617
+ container: bound.container,
618
+ theme,
619
+ context,
620
+ insideGroup,
621
+ layers,
622
+ content
623
+ });
624
+ return;
625
+ }
626
+ const id = context.slide.nextId++;
627
+ const requestedMorphKey = bound.native?.morphKey;
628
+ const hasExplicitName = bound.native?.hasExplicitName === true;
629
+ const emitsObject = bound.native?.emitsObject !== false;
630
+ let morphKey;
631
+ let morphName;
632
+ if (requestedMorphKey !== void 0) {
633
+ if (!isMorphKey(requestedMorphKey)) context.slide.diagnostics.push(diagnostic(path, "invalid-morph-key", "morphKey must be created by createMorphScope().handle(name)"));
634
+ 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"));
635
+ else if (!emitsObject) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "morphKey can only be used with capabilities that produce native objects"));
636
+ else if (hasExplicitName) context.slide.diagnostics.push(diagnostic(path, "morph-object-name-conflict", "Both morphKey and name claim native object names; specify only one"));
637
+ else {
638
+ morphKey = requestedMorphKey;
639
+ morphName = nativeObjectName(morphKey, context.document);
640
+ 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`));
641
+ }
642
+ }
643
+ const rawLink = bound.native?.link;
644
+ 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);
645
+ const resolvedObj = bound.resolve(createObjectResolveContext({
646
+ resolveContext: context,
647
+ id,
648
+ path,
649
+ layoutBox,
650
+ theme,
651
+ placeholder,
652
+ insideGroup,
653
+ restrictsMemberContinuity: bound.contract.nativeKind === "grpSp",
654
+ morphName,
655
+ link: resolvedLink
656
+ }));
657
+ recordObjectMorph({
658
+ morphKey,
659
+ morphName,
660
+ nativeKind: bound.contract.nativeKind,
661
+ observationName: resolvedObj.observation.name,
662
+ hasOutput: emitsObject,
663
+ slide: context.slide,
664
+ declarationType: child.type,
665
+ path
666
+ });
667
+ for (const extension of resolvedObj.extensions) context.document.usedExtensions.add(extension);
668
+ recordResourceClaims(resolvedObj.resourceClaims, context.document, context.slide.diagnostics, path);
669
+ recordCapabilityWarnings(resolvedObj.warnings, context.document, path);
670
+ for (const annotation of resolvedObj.annotations ?? []) context.slide.contributions.push({
671
+ ...annotation,
672
+ path,
673
+ targetId: id,
674
+ order,
675
+ declaration: child
676
+ });
677
+ const observation = {
678
+ ...resolvedObj.observation,
679
+ id,
680
+ ...authorId === void 0 ? {} : { authorId },
681
+ ...placeholder?.key === void 0 ? {} : resolvedObj.observation.placeholder === void 0 ? { placeholder: placeholder.key } : {},
682
+ ...resolvedLink === void 0 ? {} : { link: resolvedLink.summary }
683
+ };
684
+ if (layoutBox !== void 0) context.slide.layoutDerivedObjectIds.add(id);
685
+ content.push({
686
+ ...authorId === void 0 ? {} : { authorId },
687
+ reference: {
688
+ kind: "object",
689
+ id: observation.id
690
+ },
691
+ children: subPartContentNodes(resolvedObj.parts)
692
+ });
693
+ checkCanvasOverflow(resolvedObj.observation.box, context.dimensions, context.document, path);
694
+ const layer = {
695
+ declarationType: child.type,
696
+ sourceOrder: [index],
697
+ zIndex: paintOrder(bound.contract),
698
+ path,
699
+ objectId: observation.id,
700
+ paintObjectId: observation.id,
701
+ theme,
702
+ ...resolvedObj.observation.box === void 0 ? {} : { box: resolvedObj.observation.box },
703
+ ...resolvedObj.transform === void 0 ? {} : { transform: resolvedObj.transform },
704
+ emitsObject,
705
+ hasObservation: true,
706
+ childComposition: "leaf",
707
+ ...resolvedLink === void 0 ? {} : { resolvedLink },
708
+ ...morphKey === void 0 ? {} : { morphKey },
709
+ extensions: resolvedObj.extensions,
710
+ memberLayers: [],
711
+ siblingLayers: [],
712
+ emit: (emitContext) => resolvedObj.emit(emitContext),
713
+ ...resolvedObj.paint === void 0 ? {} : { paint: (paintContext) => resolvedObj.paint(paintContext) }
714
+ };
715
+ layers.push({
716
+ layer,
717
+ objects: [observation],
718
+ reference: {
719
+ kind: "object",
720
+ id: observation.id
721
+ }
722
+ });
723
+ } catch (error) {
724
+ 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)));
725
+ }
726
+ });
727
+ layers.sort((left, right) => left.layer.zIndex - right.layer.zIndex || compareSourceOrder(left.layer.sourceOrder, right.layer.sourceOrder));
728
+ return {
729
+ objects: layers.flatMap(({ objects }) => objects),
730
+ references: layers.map(({ reference }) => reference),
731
+ content,
732
+ layers: layers.map(({ layer }) => layer),
733
+ entries: layers
734
+ };
735
+ }
736
+ function resolveBoundContainer(args) {
737
+ const { child, index, path, authorId, order, bound, container, theme, context, insideGroup, layers, content } = args;
738
+ const box = context.layout.boxes.get(child);
739
+ if (box === void 0 && container.layoutMode !== "when-styled") {
740
+ context.slide.diagnostics.push(diagnostic(path, "layout-unavailable", "Container is missing layout result"));
741
+ return;
742
+ }
743
+ const enclosesChildren = container.childComposition === "members";
744
+ const restrictsMemberContinuity = container.restrictsMemberContinuity === true || bound.contract.nativeKind === "grpSp";
745
+ const layoutId = container.observesLayout !== false && box !== void 0 ? context.slide.nextId++ : void 0;
746
+ const emitsObject = container.emitsObject;
747
+ const requestedMorphKey = bound.native?.morphKey;
748
+ const hasExplicitName = bound.native?.hasExplicitName === true;
749
+ const rawLink = bound.native?.link;
750
+ 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);
751
+ let morphKey;
752
+ let morphName;
753
+ if (requestedMorphKey !== void 0) {
754
+ if (!isMorphKey(requestedMorphKey)) context.slide.diagnostics.push(diagnostic(path, "invalid-morph-key", "morphKey must be created by createMorphScope().handle(name)"));
755
+ 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"));
756
+ else if (!emitsObject) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "Only containers generating native objects can participate in Morph"));
757
+ else if (hasExplicitName) context.slide.diagnostics.push(diagnostic(path, "morph-object-name-conflict", "Both morphKey and name claim native object names; specify only one"));
758
+ else {
759
+ morphKey = requestedMorphKey;
760
+ morphName = nativeObjectName(morphKey, context.document);
761
+ 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`));
762
+ }
763
+ }
764
+ let containerObservation;
765
+ let memberResolved;
766
+ let memberLayers = [];
767
+ let containerLayer;
768
+ const objectId = context.slide.nextId++;
769
+ try {
770
+ const resolvedObj = bound.resolve(createObjectResolveContext({
771
+ resolveContext: context,
772
+ id: objectId,
773
+ path,
774
+ layoutBox: box,
775
+ theme,
776
+ placeholder: void 0,
777
+ insideGroup,
778
+ restrictsMemberContinuity,
779
+ morphName,
780
+ link: containerLink,
781
+ onChildrenResolved: (resolved) => {
782
+ memberResolved = resolved;
783
+ }
784
+ }));
785
+ if (emitsObject) {
786
+ containerObservation = {
787
+ ...resolvedObj.observation,
788
+ id: objectId,
789
+ ...authorId === void 0 ? {} : { authorId },
790
+ ...containerLink === void 0 ? {} : { link: containerLink.summary }
791
+ };
792
+ if (box !== void 0) context.slide.layoutDerivedObjectIds.add(objectId);
793
+ if (container.checksCanvasOverflow === false) checkCanvasOverflow(resolvedObj.observation.box, context.dimensions, context.document, path);
794
+ recordObjectMorph({
795
+ morphKey,
796
+ morphName,
797
+ nativeKind: bound.contract.nativeKind,
798
+ observationName: resolvedObj.observation.name,
799
+ hasOutput: true,
800
+ slide: context.slide,
801
+ declarationType: child.type,
802
+ path
803
+ });
804
+ for (const extension of resolvedObj.extensions) context.document.usedExtensions.add(extension);
805
+ recordResourceClaims(resolvedObj.resourceClaims, context.document, context.slide.diagnostics, path);
806
+ } else if (morphKey !== void 0) context.slide.diagnostics.push(diagnostic(path, "morph-needs-object", "Only containers generating native objects can participate in Morph"));
807
+ for (const annotation of resolvedObj.annotations ?? []) context.slide.contributions.push({
808
+ ...annotation,
809
+ path,
810
+ ...containerObservation === void 0 ? {} : { targetId: containerObservation.id },
811
+ order,
812
+ declaration: child
813
+ });
814
+ recordCapabilityWarnings(resolvedObj.warnings, context.document, path);
815
+ memberLayers = enclosesChildren ? memberResolved?.layers ?? [] : [];
816
+ containerLayer = {
817
+ declarationType: child.type,
818
+ sourceOrder: [index],
819
+ zIndex: paintOrder(bound.contract),
820
+ path,
821
+ objectId: containerObservation?.id ?? objectId,
822
+ paintObjectId: layoutId ?? objectId,
823
+ theme,
824
+ ...containerObservation?.box === void 0 ? {} : { box: containerObservation.box },
825
+ ...resolvedObj.transform === void 0 ? {} : { transform: resolvedObj.transform },
826
+ emitsObject,
827
+ hasObservation: containerObservation !== void 0,
828
+ childComposition: enclosesChildren ? "members" : "siblings",
829
+ ...containerLink === void 0 ? {} : { resolvedLink: containerLink },
830
+ ...morphKey === void 0 ? {} : { morphKey },
831
+ extensions: resolvedObj.extensions,
832
+ memberLayers,
833
+ siblingLayers: [],
834
+ emit: (emitContext) => resolvedObj.emit(emitContext),
835
+ ...resolvedObj.paint === void 0 ? {} : { paint: (paintContext) => resolvedObj.paint(paintContext) }
836
+ };
837
+ } catch (error) {
838
+ 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)));
839
+ }
840
+ const resolvedChildren = enclosesChildren ? memberResolved ?? {
841
+ objects: [],
842
+ references: [],
843
+ content: [],
844
+ layers: memberLayers,
845
+ entries: []
846
+ } : resolveChildrenPass(container.children, context, path, insideGroup || restrictsMemberContinuity);
847
+ const finalLayer = containerLayer !== void 0 ? {
848
+ ...containerLayer,
849
+ ...!enclosesChildren ? { siblingLayers: resolvedChildren.layers } : {}
850
+ } : {
851
+ declarationType: child.type,
852
+ sourceOrder: [index],
853
+ zIndex: paintOrder(bound.contract),
854
+ path,
855
+ objectId,
856
+ paintObjectId: layoutId ?? objectId,
857
+ theme,
858
+ emitsObject,
859
+ hasObservation: false,
860
+ childComposition: enclosesChildren ? "members" : "siblings",
861
+ extensions: [],
862
+ memberLayers: enclosesChildren ? resolvedChildren.layers : [],
863
+ siblingLayers: enclosesChildren ? [] : resolvedChildren.layers,
864
+ emit: () => ({ xml: "" })
865
+ };
866
+ const layerObservedObjects = [...containerObservation === void 0 ? [] : [containerObservation], ...enclosesChildren ? [] : resolvedChildren.objects];
867
+ if (layoutId !== void 0 && box !== void 0) {
868
+ context.slide.layouts.push({
869
+ id: layoutId,
870
+ ...authorId === void 0 ? {} : { authorId },
871
+ box: reportBox(box),
872
+ children: [...containerObservation === void 0 ? [] : [{
873
+ kind: "object",
874
+ id: containerObservation.id
875
+ }], ...resolvedChildren.references]
876
+ });
877
+ content.push({
878
+ ...authorId === void 0 ? {} : { authorId },
879
+ reference: {
880
+ kind: "layout",
881
+ id: layoutId,
882
+ objectIds: containerObservation === void 0 ? [] : [containerObservation.id]
883
+ },
884
+ children: resolvedChildren.content
885
+ });
886
+ layers.push({
887
+ layer: finalLayer,
888
+ objects: layerObservedObjects,
889
+ reference: {
890
+ kind: "layout",
891
+ id: layoutId
892
+ }
893
+ });
894
+ return;
895
+ }
896
+ if (containerObservation !== void 0) content.push({
897
+ ...authorId === void 0 ? {} : { authorId },
898
+ reference: {
899
+ kind: "object",
900
+ id: containerObservation.id
901
+ },
902
+ children: resolvedChildren.content
903
+ });
904
+ else content.push(...resolvedChildren.content);
905
+ layers.push({
906
+ layer: finalLayer,
907
+ objects: layerObservedObjects,
908
+ reference: containerObservation !== void 0 ? {
909
+ kind: "object",
910
+ id: containerObservation.id
911
+ } : {
912
+ kind: "layout",
913
+ id: objectId
914
+ }
915
+ });
916
+ }
917
+ function compareSourceOrder(left, right) {
918
+ for (let index = 0; index < Math.min(left.length, right.length); index += 1) {
919
+ const difference = left[index] - right[index];
920
+ if (difference !== 0) return difference;
921
+ }
922
+ return left.length - right.length;
923
+ }
924
+ function paintOrder(contract) {
925
+ const value = contract?.layoutStyle.zIndex;
926
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
927
+ }
928
+ function subPartContentNodes(parts) {
929
+ if (parts === void 0 || parts.length === 0) return [];
930
+ return parts.map((part) => ({
931
+ ...part.authorId === void 0 ? {} : { authorId: part.authorId },
932
+ reference: {
933
+ kind: "part",
934
+ ...part.box === void 0 ? {} : { box: part.box },
935
+ ...part.text === void 0 ? {} : { text: part.text }
936
+ },
937
+ children: subPartContentNodes(part.parts)
938
+ }));
939
+ }
940
+ function resolveContributions(children, contributions) {
941
+ let resolved = contributions;
942
+ const applied = /* @__PURE__ */ new Set();
943
+ for (const contribution of contributions) {
944
+ const capability = contribution.capability;
945
+ if (applied.has(capability)) continue;
946
+ const resolver = contribution.resolveContributions;
947
+ if (resolver === void 0) continue;
948
+ const owned = resolved.filter((candidate) => candidate.capability === capability);
949
+ if (owned.length === 0) continue;
950
+ applied.add(capability);
951
+ const effective = resolver(children, owned);
952
+ const next = [];
953
+ let inserted = false;
954
+ for (const candidate of resolved) if (candidate.capability !== capability) next.push(candidate);
955
+ else if (!inserted) {
956
+ next.push(...effective);
957
+ inserted = true;
958
+ }
959
+ resolved = next;
960
+ }
961
+ return resolved;
962
+ }
963
+ function collectOwnedContributions(children, modules, slide, parentPath, order, hidden, theme, slideNumber) {
964
+ children.forEach((child, index) => {
965
+ if (!("props" in child)) return;
966
+ const path = `${parentPath}/${capabilityLabel(child, index)}`;
967
+ const module = modules.get(child.type);
968
+ if (module !== void 0 && "compileDeclaration" in module && module.children === "owned") {
969
+ try {
970
+ for (const annotation of module.compileDeclaration(child, {
971
+ path,
972
+ theme,
973
+ slideNumber
974
+ })) slide.contributions.push({
975
+ ...annotation,
976
+ path,
977
+ order: order.value++
978
+ });
979
+ } catch (error) {
980
+ 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)));
981
+ }
982
+ return;
983
+ }
984
+ if (child.pageAffiliated === true) {
985
+ if (module === void 0 && hidden.has(child)) slide.diagnostics.push(diagnostic(path, "missing-capability", `No capability module registered for ${child.type}`));
986
+ return;
987
+ }
988
+ collectOwnedContributions(child.children, modules, slide, path, order, hidden, theme, slideNumber);
989
+ });
990
+ }
991
+ function collectNestedPlaceholders(children, modules, parentPath, allowDirect, diagnostics, onDirect) {
992
+ children.forEach((child, index) => {
993
+ if (!("props" in child)) return;
994
+ const childPath = `${parentPath}/${capabilityLabel(child, index)}`;
995
+ const module = modules.declarations.get(child.type);
996
+ if (module !== void 0 && "compileDeclaration" in module) {
997
+ if (module.children === "owned") return;
998
+ collectNestedPlaceholders(child.children, modules, childPath, allowDirect, diagnostics, onDirect);
999
+ return;
1000
+ }
1001
+ if (child.props["placeholder"] !== void 0 || child.props["nativePlaceholder"] !== void 0) {
1002
+ if (allowDirect) onDirect?.(child, childPath);
1003
+ else diagnostics.push(diagnostic(childPath, "placeholder-inside-container", "Placeholders can only be bound directly on Slide"));
1004
+ }
1005
+ collectNestedPlaceholders(child.children, modules, childPath, false, diagnostics);
1006
+ });
1007
+ }
1008
+ function buildSlidePlaceholderContexts(args) {
1009
+ const { slideId, slidePath, hasExplicitLayout, layoutSpec, masterSpec, placeholderTheme, children, rawPlaceholdersProp, modules, diagnostics } = args;
1010
+ const contexts = /* @__PURE__ */ new WeakMap();
1011
+ const seenKeys = /* @__PURE__ */ new Set();
1012
+ if (rawPlaceholdersProp !== void 0 && !hasExplicitLayout) diagnostics.push(diagnostic(slidePath, "placeholder-requires-layout", `Slide ${JSON.stringify(slideId)} declares placeholders without a bound SlideLayout`));
1013
+ collectNestedPlaceholders(children, modules, slidePath, true, diagnostics, (child, childPath) => {
1014
+ const rawKey = child.props["placeholder"];
1015
+ const rawNativePh = child.props["nativePlaceholder"];
1016
+ let parsedNativePh;
1017
+ if (rawNativePh !== void 0) {
1018
+ const parsed = nativePlaceholderRefSchema.safeParse(rawNativePh);
1019
+ if (!parsed.success) {
1020
+ diagnostics.push(diagnostic(childPath, "invalid-slide-placeholder", parsed.error.issues[0]?.message ?? "Invalid nativePlaceholder specification"));
1021
+ return;
1022
+ }
1023
+ parsedNativePh = parsed.data;
1024
+ }
1025
+ if (rawKey !== void 0) {
1026
+ if (typeof rawKey !== "string" || rawKey.trim() === "") {
1027
+ diagnostics.push(diagnostic(childPath, "invalid-slide-placeholder", "placeholder key must be a non-empty string"));
1028
+ return;
1029
+ }
1030
+ if (seenKeys.has(rawKey)) {
1031
+ diagnostics.push(diagnostic(childPath, "duplicate-slide-placeholder", `Placeholder ${JSON.stringify(rawKey)} can only be bound once per slide`));
1032
+ return;
1033
+ }
1034
+ seenKeys.add(rawKey);
1035
+ }
1036
+ if (!hasExplicitLayout && parsedNativePh === void 0) {
1037
+ diagnostics.push(diagnostic(childPath, "placeholder-requires-layout", `Placeholder ${JSON.stringify(rawKey)} requires a bound SlideLayout`));
1038
+ return;
1039
+ }
1040
+ const layoutPlaceholder = typeof rawKey === "string" ? layoutSpec?.placeholders?.[rawKey] : void 0;
1041
+ if (layoutPlaceholder === void 0 && parsedNativePh === void 0) {
1042
+ const layoutLabel = layoutSpec?.id ?? layoutSpec?.name ?? "<unnamed>";
1043
+ diagnostics.push(diagnostic(childPath, "unknown-slide-placeholder", `SlideLayout ${JSON.stringify(layoutLabel)} does not define placeholder ${JSON.stringify(rawKey)}`));
1044
+ return;
1045
+ }
1046
+ if (masterSpec === void 0) {
1047
+ diagnostics.push(diagnostic(childPath, "placeholder-requires-layout", `Placeholder ${JSON.stringify(rawKey)} requires a SlideLayout owned by a SlideMaster`));
1048
+ return;
1049
+ }
1050
+ const nativeRef = parsedNativePh ?? {
1051
+ type: layoutPlaceholder.type,
1052
+ ...layoutPlaceholder.explicitType === void 0 ? {} : { explicitType: layoutPlaceholder.explicitType },
1053
+ ...layoutPlaceholder.idx === void 0 ? {} : { idx: layoutPlaceholder.idx },
1054
+ ...layoutPlaceholder.sz === void 0 ? {} : { sz: layoutPlaceholder.sz },
1055
+ ...layoutPlaceholder.orient === void 0 ? {} : { orient: layoutPlaceholder.orient },
1056
+ ...layoutPlaceholder.hasCustomPrompt === void 0 ? {} : { hasCustomPrompt: layoutPlaceholder.hasCustomPrompt }
1057
+ };
1058
+ const role = layoutPlaceholder?.type ?? nativeRef.type;
1059
+ const masterPlaceholder = matchMasterPlaceholderSpec(masterSpec.placeholders, role);
1060
+ contexts.set(child, {
1061
+ ...typeof rawKey === "string" ? { key: rawKey } : {},
1062
+ nativeRef,
1063
+ masterTheme: placeholderTheme ?? masterSpec.themeContext,
1064
+ ...masterSpec.textStyles === void 0 ? {} : { masterTextStyles: masterSpec.textStyles },
1065
+ ...masterPlaceholder === void 0 ? {} : { masterPlaceholder },
1066
+ ...layoutPlaceholder === void 0 ? {} : { layoutPlaceholder }
1067
+ });
1068
+ });
1069
+ return contexts;
1070
+ }
1071
+ function resolveOwnerSlideCapabilities(args) {
1072
+ const { type, props, path, modules, dimensions, document, options, theme } = args;
1073
+ const slideCapabilities = [];
1074
+ const capabilities = {};
1075
+ const continuityByDeclaration = /* @__PURE__ */ new Map();
1076
+ const diagnostics = [];
1077
+ const input = {
1078
+ type,
1079
+ props,
1080
+ children: []
1081
+ };
1082
+ for (const module of modules.slideModules.values()) {
1083
+ const hasSlideProps = (module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp])).some((property) => Object.hasOwn(props, property));
1084
+ if (!hasSlideProps) continue;
1085
+ try {
1086
+ const boundSlide = validateBoundSlideCapability(module.bindSlide(input, {
1087
+ path,
1088
+ dimensions,
1089
+ theme,
1090
+ options,
1091
+ slideNumber: 0,
1092
+ contributions: []
1093
+ }));
1094
+ continuityByDeclaration.set(module.declaration, boundSlide.continuity?.matchSourceKinds);
1095
+ const resolvedSlideCap = boundSlide.resolveSlide({
1096
+ path,
1097
+ dimensions,
1098
+ contributions: [],
1099
+ children: [],
1100
+ theme,
1101
+ options,
1102
+ slideNumber: 0
1103
+ });
1104
+ if (resolvedSlideCap.observation !== void 0) capabilities[module.declaration] = resolvedSlideCap.observation;
1105
+ for (const extension of resolvedSlideCap.extensions) document.usedExtensions.add(extension);
1106
+ recordResourceClaims(resolvedSlideCap.resourceClaims, document, diagnostics, path);
1107
+ recordCapabilityWarnings(resolvedSlideCap.warnings, document, path);
1108
+ slideCapabilities.push({
1109
+ declaration: module.declaration,
1110
+ slot: module.slot,
1111
+ hasSlideProps,
1112
+ path,
1113
+ theme,
1114
+ extensions: resolvedSlideCap.extensions,
1115
+ emit: (emitContext) => resolvedSlideCap.emit(emitContext),
1116
+ ...resolvedSlideCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedSlideCap.paint(paintContext) }
1117
+ });
1118
+ } catch (error) {
1119
+ diagnostics.push(error instanceof CapabilityError ? diagnostic(error.path ?? path, error.code, error.message) : diagnostic(path, "capability-failure", error instanceof Error ? error.message : String(error)));
1120
+ }
1121
+ }
1122
+ if (diagnostics.length > 0) throw new BuildError(diagnostics);
1123
+ return {
1124
+ slideCapabilities,
1125
+ capabilities,
1126
+ continuityByDeclaration
1127
+ };
1128
+ }
1129
+ function isCustomColorMap(colorMap) {
1130
+ return Object.keys(defaultColorMap).some((slot) => colorMap[slot] !== defaultColorMap[slot]);
1131
+ }
1132
+ function resolveSlideDeclaration(parsed, modules, dimensions, document, options, documentTheme, layoutIdByKey, layoutByKey, masterByKey, inheritedContinuity, inheritedBackground, masterLayers, layoutLayers, inheritance) {
1133
+ const { node, id, name, authorId, index, layoutKey, hasExplicitLayout, section, hidden = false, showMasterShapes } = parsed;
1134
+ const slide = {
1135
+ index,
1136
+ nextId: 2,
1137
+ nextNodeOrder: 0,
1138
+ diagnostics: [],
1139
+ layouts: [],
1140
+ contributions: [],
1141
+ morphObjects: /* @__PURE__ */ new Map(),
1142
+ matchContinuityKinds: false,
1143
+ linkedSlideIndexes: /* @__PURE__ */ new Set(),
1144
+ layoutDerivedObjectIds: /* @__PURE__ */ new Set()
1145
+ };
1146
+ const path = `deck/slide[${id}]`;
1147
+ if (nonWhitespaceText(node.children)) slide.diagnostics.push(diagnostic(path, "unexpected-text", "Slide cannot directly contain text"));
1148
+ const children = node.children.map(capabilityChild);
1149
+ const layoutSpec = layoutKey === void 0 ? void 0 : layoutByKey.get(layoutKey);
1150
+ const masterSpec = layoutSpec === void 0 ? void 0 : masterByKey.get(layoutSpec.masterKey);
1151
+ const placeholderContexts = buildSlidePlaceholderContexts({
1152
+ slideId: id,
1153
+ slidePath: path,
1154
+ hasExplicitLayout,
1155
+ layoutSpec,
1156
+ masterSpec,
1157
+ placeholderTheme: documentTheme.withTextStyle({}),
1158
+ children,
1159
+ rawPlaceholdersProp: node.props["placeholders"],
1160
+ modules,
1161
+ diagnostics: slide.diagnostics
1162
+ });
1163
+ if (slide.diagnostics.length > 0) throw new BuildError(slide.diagnostics);
1164
+ let theme;
1165
+ try {
1166
+ theme = documentTheme.with(node.props["theme"], textStyleFrom(node.props["style"]));
1167
+ } catch (error) {
1168
+ if (!(error instanceof CapabilityError)) throw error;
1169
+ throw new BuildError([diagnostic(path, error.code, error.message)]);
1170
+ }
1171
+ const layout = new LayoutPass(modules.declarations, dimensions, index, options).run(children, path, theme, node.props["style"], (element) => placeholderContexts.get(element));
1172
+ document.warnings.push(...layout.warnings);
1173
+ collectOwnedContributions(children, modules.declarations, slide, path, { value: 0 }, layout.hidden, theme, index);
1174
+ const resolvedChildren = resolveChildrenPass(children, {
1175
+ document,
1176
+ slide,
1177
+ modules,
1178
+ dimensions,
1179
+ options,
1180
+ theme,
1181
+ layout,
1182
+ slideNumber: index,
1183
+ placeholderContexts
1184
+ }, path);
1185
+ let contributions = slide.contributions;
1186
+ try {
1187
+ contributions = resolveContributions(children, slide.contributions);
1188
+ } catch (error) {
1189
+ 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)));
1190
+ }
1191
+ const capabilities = {};
1192
+ const slideCapabilities = [];
1193
+ const input = {
1194
+ type: node.type,
1195
+ props: node.props,
1196
+ children: node.children.map(capabilityChild)
1197
+ };
1198
+ for (const module of modules.slideModules.values()) {
1199
+ const hasSlideProps = (module.slideProps ?? (module.slideProp === void 0 ? [] : [module.slideProp])).some((property) => Object.hasOwn(node.props, property));
1200
+ if (!module.always && !hasSlideProps) {
1201
+ if (inheritedContinuity?.get(module.declaration) === true) slide.matchContinuityKinds = true;
1202
+ continue;
1203
+ }
1204
+ try {
1205
+ const boundSlide = validateBoundSlideCapability(module.bindSlide(input, {
1206
+ path,
1207
+ dimensions,
1208
+ theme,
1209
+ options,
1210
+ slideNumber: index,
1211
+ contributions,
1212
+ ...inheritance === void 0 ? {} : { inheritance }
1213
+ }));
1214
+ if ((boundSlide.continuity?.matchSourceKinds ?? inheritedContinuity?.get(module.declaration)) === true) slide.matchContinuityKinds = true;
1215
+ const resolvedSlideCap = boundSlide.resolveSlide({
1216
+ path,
1217
+ dimensions,
1218
+ contributions,
1219
+ children,
1220
+ theme,
1221
+ options,
1222
+ slideNumber: index,
1223
+ ...inheritance === void 0 ? {} : { inheritance }
1224
+ });
1225
+ if (resolvedSlideCap.observation !== void 0) capabilities[module.declaration] = resolvedSlideCap.observation;
1226
+ for (const extension of resolvedSlideCap.extensions) document.usedExtensions.add(extension);
1227
+ recordResourceClaims(resolvedSlideCap.resourceClaims, document, slide.diagnostics, path);
1228
+ recordCapabilityWarnings(resolvedSlideCap.warnings, document, path);
1229
+ slideCapabilities.push({
1230
+ declaration: module.declaration,
1231
+ slot: module.slot,
1232
+ hasSlideProps,
1233
+ path,
1234
+ theme,
1235
+ extensions: resolvedSlideCap.extensions,
1236
+ emit: (emitContext) => resolvedSlideCap.emit(emitContext),
1237
+ ...resolvedSlideCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedSlideCap.paint(paintContext) }
1238
+ });
1239
+ } catch (error) {
1240
+ 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)));
1241
+ }
1242
+ }
1243
+ for (const contribution of contributions) {
1244
+ if (contribution.optional) continue;
1245
+ const consumer = modules.slideModules.get(contribution.capability);
1246
+ if (consumer === void 0 || !consumer.always && !(consumer.slideProps ?? (consumer.slideProp === void 0 ? [] : [consumer.slideProp])).some((property) => Object.hasOwn(node.props, property))) slide.diagnostics.push(diagnostic(contribution.path, "missing-capability", `No capability module registered for ${contribution.capability}`));
1247
+ }
1248
+ if (slide.diagnostics.length > 0) throw new BuildError(slide.diagnostics);
1249
+ const projectedObjects = projectObservations(resolvedChildren.objects, slide.layoutDerivedObjectIds);
1250
+ const sortedLayouts = [...slide.layouts].sort((left, right) => left.id - right.id);
1251
+ const layoutId = layoutKey === void 0 ? void 0 : layoutIdByKey.get(layoutKey);
1252
+ const observation = {
1253
+ id,
1254
+ ...authorId === void 0 ? {} : { authorId },
1255
+ index,
1256
+ ...layoutId === void 0 ? {} : { layout: layoutId },
1257
+ ...section === void 0 ? {} : { section },
1258
+ ...hidden ? { hidden: true } : {},
1259
+ ...parsed.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsed.showMasterPlaceholderAnimations },
1260
+ objects: projectedObjects,
1261
+ ...sortedLayouts.length > 0 && { layouts: sortedLayouts },
1262
+ ...Object.keys(capabilities).length > 0 && { capabilities }
1263
+ };
1264
+ const effectiveThemeOverride = parsed.themeOverride ?? layoutSpec?.themeOverride;
1265
+ const effectiveColorMapOverride = parsed.colorMapOverride ?? layoutSpec?.colorMapOverride;
1266
+ const hasCustomColorMap = masterSpec !== void 0 && isCustomColorMap(masterSpec.colorMap);
1267
+ return {
1268
+ observation,
1269
+ morphObjects: slide.morphObjects,
1270
+ matchContinuityKinds: slide.matchContinuityKinds,
1271
+ linkedSlideIndexes: slide.linkedSlideIndexes,
1272
+ internal: {
1273
+ id,
1274
+ ...name === void 0 ? {} : { name },
1275
+ ...authorId === void 0 ? {} : { authorId },
1276
+ index,
1277
+ theme,
1278
+ ...layoutKey === void 0 ? {} : { layoutKey },
1279
+ ...parsed.colorMapOverride === void 0 ? {} : { colorMapOverride: parsed.colorMapOverride },
1280
+ ...parsed.themeOverride === void 0 ? {} : { themeOverride: parsed.themeOverride },
1281
+ ...effectiveThemeOverride === void 0 ? {} : { effectiveThemeOverride },
1282
+ ...effectiveColorMapOverride === void 0 ? {} : { effectiveColorMapOverride },
1283
+ ...hasCustomColorMap ? { hasCustomColorMap: true } : {},
1284
+ ...section === void 0 ? {} : { section },
1285
+ hidden,
1286
+ ...parsed.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: parsed.showMasterPlaceholderAnimations },
1287
+ ...showMasterShapes === void 0 ? {} : { showMasterShapes },
1288
+ ...inheritedBackground === void 0 ? {} : { inheritedBackground },
1289
+ ...masterLayers === void 0 ? {} : { masterLayers },
1290
+ ...layoutLayers === void 0 ? {} : { layoutLayers },
1291
+ content: resolvedChildren.content,
1292
+ layers: resolvedChildren.layers,
1293
+ slideCapabilities
1294
+ }
1295
+ };
1296
+ }
1297
+ function resolveSharedCanvasLayers(args) {
1298
+ const { children, path, style, modules, dimensions, options, theme, document, initialNextId = 2 } = args;
1299
+ if (children.length === 0) return [];
1300
+ const state = {
1301
+ index: 1,
1302
+ nextId: initialNextId,
1303
+ nextNodeOrder: 0,
1304
+ diagnostics: [],
1305
+ layouts: [],
1306
+ contributions: [],
1307
+ morphObjects: /* @__PURE__ */ new Map(),
1308
+ matchContinuityKinds: false,
1309
+ linkedSlideIndexes: /* @__PURE__ */ new Set(),
1310
+ layoutDerivedObjectIds: /* @__PURE__ */ new Set()
1311
+ };
1312
+ const layout = new LayoutPass(modules.declarations, dimensions, 1, options).run(children, path, theme, style);
1313
+ document.warnings.push(...layout.warnings);
1314
+ const resolved = resolveChildrenPass(children, {
1315
+ document,
1316
+ slide: state,
1317
+ modules,
1318
+ dimensions,
1319
+ options,
1320
+ theme,
1321
+ layout,
1322
+ slideNumber: 1,
1323
+ placeholderContexts: /* @__PURE__ */ new Map()
1324
+ }, path);
1325
+ for (const [, morphObj] of state.morphObjects) state.diagnostics.push(diagnostic(morphObj.path, "morph-on-master", "Morph handles are only supported on Slide objects"));
1326
+ for (const contribution of state.contributions) {
1327
+ if (contribution.optional) continue;
1328
+ state.diagnostics.push(diagnostic(contribution.path, "unsupported-declaration", `${contribution.capability} declarations are only supported inside Slide`));
1329
+ }
1330
+ if (state.diagnostics.length > 0) throw new BuildError(state.diagnostics);
1331
+ return resolved.layers;
1332
+ }
1333
+ function resolveMasterOrLayoutSlideCapability(args) {
1334
+ const { module, targetType, props, path, dimensions, theme, options, slideNumber, document } = args;
1335
+ try {
1336
+ const input = {
1337
+ type: targetType,
1338
+ props,
1339
+ children: []
1340
+ };
1341
+ const resolvedCap = validateBoundSlideCapability(module.bindSlide(input, {
1342
+ path,
1343
+ dimensions,
1344
+ theme,
1345
+ options,
1346
+ slideNumber,
1347
+ contributions: []
1348
+ })).resolveSlide({
1349
+ path,
1350
+ dimensions,
1351
+ contributions: [],
1352
+ children: [],
1353
+ theme,
1354
+ options,
1355
+ slideNumber
1356
+ });
1357
+ for (const extension of resolvedCap.extensions) document.usedExtensions.add(extension);
1358
+ const claimDiagnostics = [];
1359
+ recordResourceClaims(resolvedCap.resourceClaims, document, claimDiagnostics, path);
1360
+ if (claimDiagnostics.length > 0) throw new BuildError(claimDiagnostics);
1361
+ recordCapabilityWarnings(resolvedCap.warnings, document, path);
1362
+ return {
1363
+ declaration: module.declaration,
1364
+ slot: module.slot,
1365
+ hasSlideProps: true,
1366
+ path,
1367
+ theme,
1368
+ extensions: resolvedCap.extensions,
1369
+ emit: (emitContext) => resolvedCap.emit(emitContext),
1370
+ ...resolvedCap.paint === void 0 ? {} : { paint: (paintContext) => resolvedCap.paint(paintContext) }
1371
+ };
1372
+ } catch (error) {
1373
+ if (error instanceof BuildError) throw error;
1374
+ 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))]);
1375
+ }
1376
+ }
1377
+ function normalizeLayoutPlaceholderIndices(placeholders, reservedIndices = []) {
1378
+ if (placeholders === void 0) return void 0;
1379
+ const entries = Object.entries(placeholders);
1380
+ if (entries.length <= 1) return placeholders;
1381
+ const usedIndices = /* @__PURE__ */ new Set();
1382
+ let unindexedCount = 0;
1383
+ for (const [, spec] of entries) if (spec.idx === void 0) unindexedCount += 1;
1384
+ else usedIndices.add(spec.idx);
1385
+ if (unindexedCount === 0 || unindexedCount === 1 && !usedIndices.has(0)) return placeholders;
1386
+ for (const reserved of reservedIndices) usedIndices.add(reserved);
1387
+ let primaryKey;
1388
+ if (!usedIndices.has(0)) {
1389
+ const primaryTitle = entries.find(([, spec]) => spec.idx === void 0 && (spec.type === "title" || spec.type === "ctrTitle"));
1390
+ const firstUnindexed = entries.find(([, spec]) => spec.idx === void 0);
1391
+ primaryKey = (primaryTitle ?? firstUnindexed)?.[0];
1392
+ if (primaryKey !== void 0) usedIndices.add(0);
1393
+ }
1394
+ let nextIdx = 1;
1395
+ const updated = {};
1396
+ for (const [key, spec] of entries) {
1397
+ if (spec.idx !== void 0 || key === primaryKey) {
1398
+ updated[key] = spec;
1399
+ continue;
1400
+ }
1401
+ while (usedIndices.has(nextIdx)) nextIdx += 1;
1402
+ usedIndices.add(nextIdx);
1403
+ updated[key] = Object.freeze({
1404
+ ...spec,
1405
+ idx: nextIdx
1406
+ });
1407
+ }
1408
+ return Object.freeze(updated);
1409
+ }
1410
+ function deriveFooterPlaceholdersFromMap(placeholders) {
1411
+ if (placeholders === void 0) return void 0;
1412
+ const result = {};
1413
+ for (const spec of Object.values(placeholders)) {
1414
+ const slot = spec.type === "dt" ? "dateTime" : spec.type === "ftr" ? "footer" : spec.type === "sldNum" ? "slideNumber" : void 0;
1415
+ if (slot === void 0 || result[slot] !== void 0) continue;
1416
+ const mergedStyle = spec.style !== void 0 || spec.listStyles?.[1] !== void 0 ? {
1417
+ ...spec.style,
1418
+ ...spec.listStyles?.[1]
1419
+ } : void 0;
1420
+ result[slot] = {
1421
+ ...spec.x === void 0 ? {} : { x: spec.x },
1422
+ ...spec.y === void 0 ? {} : { y: spec.y },
1423
+ ...spec.width === void 0 ? {} : { width: spec.width },
1424
+ ...spec.height === void 0 ? {} : { height: spec.height },
1425
+ ...spec.idx === void 0 ? {} : { idx: spec.idx },
1426
+ ...spec.sz === "full" || spec.sz === "half" || spec.sz === "quarter" ? { size: spec.sz } : {},
1427
+ ...spec.promptText === void 0 ? {} : { text: spec.promptText },
1428
+ ...mergedStyle === void 0 ? {} : { style: mergedStyle },
1429
+ visible: false
1430
+ };
1431
+ }
1432
+ const parsed = footerPlaceholdersSchema.safeParse(result);
1433
+ if (!parsed.success) return void 0;
1434
+ return Object.keys(parsed.data).length > 0 ? parsed.data : void 0;
1435
+ }
1436
+ function resolveDocument(container, modules, options) {
1437
+ const decks = childNodes(container.children);
1438
+ if (decks.length !== 1 || decks[0]?.type !== "deck") throw new BuildError([diagnostic("deck", "document-root", "Build content must have exactly one Deck root component")]);
1439
+ const deck = decks[0];
1440
+ const { width, height, title } = parseDeckProps(deck.props);
1441
+ const size = {
1442
+ width,
1443
+ height
1444
+ };
1445
+ let theme;
1446
+ try {
1447
+ theme = createThemeContext(deck.props["theme"], deck.props["style"]);
1448
+ } catch (error) {
1449
+ if (!(error instanceof CapabilityError)) throw error;
1450
+ throw new BuildError([diagnostic("deck", error.code, error.message)]);
1451
+ }
1452
+ const { masters: parsedMasters, layoutIdByKey, slides, sections } = resolveSlides(container, modules, theme.theme);
1453
+ const mastersModule = modules.slideModules.get("slide-masters");
1454
+ if (parsedMasters.length > 0 && mastersModule === void 0) throw new BuildError([diagnostic(parsedMasters[0].path, "missing-capability", "No capability module registered for slide-masters")]);
1455
+ const slideRequiringMasters = slides.find((slide) => slide.colorMapOverride !== void 0 || slide.themeOverride !== void 0);
1456
+ if (slideRequiringMasters !== void 0 && mastersModule === void 0) throw new BuildError([diagnostic(`deck/slide[${slideRequiringMasters.id}]`, "missing-capability", "No capability module registered for slide-masters")]);
1457
+ let boundSections;
1458
+ if (sections.length > 0) {
1459
+ const sectionsModule = [...modules.slideModules.values()].find((module) => module.bindSections !== void 0);
1460
+ if (sectionsModule === void 0) throw new BuildError([diagnostic("deck/section[1]", "missing-capability", "No capability module registered for section")]);
1461
+ boundSections = sectionsModule.bindSections(sections);
1462
+ }
1463
+ const slideIndexById = new Map(slides.map((slide) => [slide.id, slide.index]));
1464
+ const sharedCanvasRoots = [...parsedMasters.flatMap((m) => m.canvasChildren), ...parsedMasters.flatMap((m) => m.layouts.flatMap((l) => childNodes(l.node.children)))];
1465
+ const document = {
1466
+ usedExtensions: new Set(boundSections?.extensions ?? []),
1467
+ warnings: [],
1468
+ resourceClaims: /* @__PURE__ */ new Map(),
1469
+ morphNames: /* @__PURE__ */ new Map(),
1470
+ nextMorphName: 1,
1471
+ reservedObjectNames: collectExplicitObjectNames(slides, modules.declarations, sharedCanvasRoots),
1472
+ slideIndexById
1473
+ };
1474
+ const bgModule = [...modules.slideModules.values()].find((module) => module.slot === "background" && module.declaration === "slide-background") ?? [...modules.slideModules.values()].find((module) => module.slot === "background");
1475
+ const footerModule = [...modules.slideModules.values()].find((module) => module.slot === "shape-tree" && module.declaration === "footer-placeholder");
1476
+ const resolvedMasters = [];
1477
+ const masterObservations = [];
1478
+ const masterByKey = /* @__PURE__ */ new Map();
1479
+ const masterByLayoutKey = /* @__PURE__ */ new Map();
1480
+ const layoutByKey = /* @__PURE__ */ new Map();
1481
+ const parsedLayoutByKey = /* @__PURE__ */ new Map();
1482
+ const continuityByLayoutKey = /* @__PURE__ */ new Map();
1483
+ for (const parsedMaster of parsedMasters) {
1484
+ const mergedMasterStyle = parsedMaster.style === void 0 ? deck.props["style"] : {
1485
+ ...deck.props["style"],
1486
+ ...parsedMaster.style
1487
+ };
1488
+ let masterThemeBase;
1489
+ try {
1490
+ masterThemeBase = createThemeContext(parsedMaster.theme, mergedMasterStyle, { colorMap: parsedMaster.colorMap });
1491
+ } catch (error) {
1492
+ if (!(error instanceof CapabilityError)) throw error;
1493
+ throw new BuildError([diagnostic(parsedMaster.path, error.code, error.message)]);
1494
+ }
1495
+ const masterCapResult = resolveOwnerSlideCapabilities({
1496
+ type: "slide-master",
1497
+ props: parsedMaster.props,
1498
+ path: parsedMaster.path,
1499
+ modules,
1500
+ dimensions: size,
1501
+ document,
1502
+ options,
1503
+ theme: masterThemeBase
1504
+ });
1505
+ let masterBackground;
1506
+ if (parsedMaster.background !== void 0) {
1507
+ if (bgModule === void 0) throw new BuildError([diagnostic(parsedMaster.path, "missing-capability", "No capability module registered for SlideMaster.background")]);
1508
+ masterBackground = resolveMasterOrLayoutSlideCapability({
1509
+ module: bgModule,
1510
+ targetType: "slide-master",
1511
+ props: { background: parsedMaster.background },
1512
+ path: parsedMaster.path,
1513
+ dimensions: size,
1514
+ theme: masterThemeBase,
1515
+ options,
1516
+ slideNumber: 1,
1517
+ document
1518
+ });
1519
+ }
1520
+ let masterFooterPlaceholders;
1521
+ if (parsedMaster.footerPlaceholders !== void 0) {
1522
+ if (footerModule === void 0) throw new BuildError([diagnostic(parsedMaster.path, "missing-capability", "No capability module registered for SlideMaster.footerPlaceholders")]);
1523
+ masterFooterPlaceholders = resolveMasterOrLayoutSlideCapability({
1524
+ module: footerModule,
1525
+ targetType: "slide-master",
1526
+ props: { footerPlaceholders: parsedMaster.footerPlaceholders },
1527
+ path: parsedMaster.path,
1528
+ dimensions: size,
1529
+ theme: masterThemeBase,
1530
+ options,
1531
+ slideNumber: 1,
1532
+ document
1533
+ });
1534
+ }
1535
+ const masterPlaceholderVisuals = parsedMaster.placeholders !== void 0 && mastersModule !== void 0 ? resolveMasterOrLayoutSlideCapability({
1536
+ module: mastersModule,
1537
+ targetType: "slide-master",
1538
+ props: { placeholders: parsedMaster.placeholders },
1539
+ path: parsedMaster.path,
1540
+ dimensions: size,
1541
+ theme: masterThemeBase,
1542
+ options,
1543
+ slideNumber: 1,
1544
+ document
1545
+ }) : void 0;
1546
+ const masterLayers = resolveSharedCanvasLayers({
1547
+ children: parsedMaster.canvasChildren.map(capabilityChild),
1548
+ path: parsedMaster.path,
1549
+ style: parsedMaster.node.props["style"],
1550
+ modules,
1551
+ dimensions: size,
1552
+ options,
1553
+ theme: masterThemeBase,
1554
+ document,
1555
+ initialNextId: 2 + Object.keys(parsedMaster.placeholders ?? {}).length
1556
+ });
1557
+ const resolvedLayouts = [];
1558
+ const observedLayouts = [];
1559
+ for (const parsedLayout of parsedMaster.layouts) {
1560
+ parsedLayoutByKey.set(parsedLayout.key, {
1561
+ master: parsedMaster,
1562
+ layout: parsedLayout
1563
+ });
1564
+ let layoutThemeBase = masterThemeBase;
1565
+ if (parsedLayout.data.themeOverride !== void 0 || parsedLayout.data.colorMapOverride !== void 0) layoutThemeBase = layoutThemeBase.withNativeOverrides(parsedLayout.data.themeOverride, parsedLayout.data.colorMapOverride);
1566
+ const layoutCapResult = resolveOwnerSlideCapabilities({
1567
+ type: "slide-layout",
1568
+ props: parsedLayout.props,
1569
+ path: parsedLayout.path,
1570
+ modules,
1571
+ dimensions: size,
1572
+ document,
1573
+ options,
1574
+ theme: layoutThemeBase
1575
+ });
1576
+ const mergedContinuity = new Map(masterCapResult.continuityByDeclaration);
1577
+ for (const [decl, match] of layoutCapResult.continuityByDeclaration) if (match !== void 0) mergedContinuity.set(decl, match);
1578
+ continuityByLayoutKey.set(parsedLayout.key, mergedContinuity);
1579
+ let layoutBackground;
1580
+ if (parsedLayout.background !== void 0) {
1581
+ if (bgModule === void 0) throw new BuildError([diagnostic(parsedLayout.path, "missing-capability", "No capability module registered for SlideLayout.background")]);
1582
+ layoutBackground = resolveMasterOrLayoutSlideCapability({
1583
+ module: bgModule,
1584
+ targetType: "slide-layout",
1585
+ props: { background: parsedLayout.background },
1586
+ path: parsedLayout.path,
1587
+ dimensions: size,
1588
+ theme: layoutThemeBase,
1589
+ options,
1590
+ slideNumber: 1,
1591
+ document
1592
+ });
1593
+ }
1594
+ let layoutFooterPlaceholders;
1595
+ if (parsedLayout.footerPlaceholders !== void 0) {
1596
+ if (footerModule === void 0) throw new BuildError([diagnostic(parsedLayout.path, "missing-capability", "No capability module registered for SlideLayout.footerPlaceholders")]);
1597
+ layoutFooterPlaceholders = resolveMasterOrLayoutSlideCapability({
1598
+ module: footerModule,
1599
+ targetType: "slide-layout",
1600
+ props: { footerPlaceholders: parsedLayout.footerPlaceholders },
1601
+ path: parsedLayout.path,
1602
+ dimensions: size,
1603
+ theme: layoutThemeBase,
1604
+ options,
1605
+ slideNumber: 1,
1606
+ document
1607
+ });
1608
+ }
1609
+ const layoutPlaceholderVisuals = parsedLayout.placeholders !== void 0 && mastersModule !== void 0 ? resolveMasterOrLayoutSlideCapability({
1610
+ module: mastersModule,
1611
+ targetType: "slide-layout",
1612
+ props: { placeholders: parsedLayout.placeholders },
1613
+ path: parsedLayout.path,
1614
+ dimensions: size,
1615
+ theme: layoutThemeBase,
1616
+ options,
1617
+ slideNumber: 1,
1618
+ document
1619
+ }) : void 0;
1620
+ const layoutLayers = resolveSharedCanvasLayers({
1621
+ children: parsedLayout.node.children.map(capabilityChild),
1622
+ path: parsedLayout.path,
1623
+ style: parsedLayout.node.props["style"],
1624
+ modules,
1625
+ dimensions: size,
1626
+ options,
1627
+ theme: layoutThemeBase,
1628
+ document,
1629
+ initialNextId: 2 + Object.keys(parsedLayout.placeholders ?? {}).length
1630
+ });
1631
+ const resolvedLayout = {
1632
+ key: parsedLayout.key,
1633
+ masterKey: parsedMaster.key,
1634
+ ...parsedLayout.data,
1635
+ ...parsedLayout.placeholders === void 0 ? {} : { placeholders: parsedLayout.placeholders },
1636
+ ...layoutBackground === void 0 ? {} : { background: layoutBackground },
1637
+ ...layoutFooterPlaceholders === void 0 ? {} : { footerPlaceholders: layoutFooterPlaceholders },
1638
+ ...layoutPlaceholderVisuals === void 0 ? {} : { placeholderVisuals: layoutPlaceholderVisuals },
1639
+ ...layoutLayers.length === 0 ? {} : { layers: layoutLayers },
1640
+ ...layoutCapResult.slideCapabilities.length > 0 ? { slideCapabilities: layoutCapResult.slideCapabilities } : {}
1641
+ };
1642
+ resolvedLayouts.push(resolvedLayout);
1643
+ layoutByKey.set(parsedLayout.key, resolvedLayout);
1644
+ observedLayouts.push({
1645
+ ...parsedLayout.data,
1646
+ ...Object.keys(layoutCapResult.capabilities).length > 0 ? { capabilities: layoutCapResult.capabilities } : {}
1647
+ });
1648
+ }
1649
+ const resolvedMaster = {
1650
+ key: parsedMaster.key,
1651
+ id: parsedMaster.id,
1652
+ ...parsedMaster.name === void 0 ? {} : { name: parsedMaster.name },
1653
+ ...parsedMaster.preserve === void 0 ? {} : { preserve: parsedMaster.preserve },
1654
+ theme: parsedMaster.theme,
1655
+ themeContext: masterThemeBase,
1656
+ colorMap: parsedMaster.colorMap,
1657
+ ...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
1658
+ ...masterBackground === void 0 ? {} : { background: masterBackground },
1659
+ ...masterFooterPlaceholders === void 0 ? {} : { footerPlaceholders: masterFooterPlaceholders },
1660
+ ...masterPlaceholderVisuals === void 0 ? {} : { placeholderVisuals: masterPlaceholderVisuals },
1661
+ ...masterLayers.length === 0 ? {} : { layers: masterLayers },
1662
+ ...parsedMaster.placeholders === void 0 ? {} : { placeholders: parsedMaster.placeholders },
1663
+ ...parsedMaster.textStyles === void 0 ? {} : { textStyles: parsedMaster.textStyles },
1664
+ ...masterCapResult.slideCapabilities.length > 0 ? { slideCapabilities: masterCapResult.slideCapabilities } : {},
1665
+ layouts: resolvedLayouts
1666
+ };
1667
+ masterByKey.set(parsedMaster.key, resolvedMaster);
1668
+ resolvedMasters.push(resolvedMaster);
1669
+ for (const resolvedLayout of resolvedLayouts) masterByLayoutKey.set(resolvedLayout.key, resolvedMaster);
1670
+ masterObservations.push({
1671
+ id: parsedMaster.id,
1672
+ ...parsedMaster.name === void 0 ? {} : { name: parsedMaster.name },
1673
+ ...parsedMaster.preserve === void 0 ? {} : { preserve: parsedMaster.preserve },
1674
+ ...parsedMaster.explicitColorMap === void 0 ? {} : { colorMap: parsedMaster.explicitColorMap },
1675
+ ...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
1676
+ ...Object.keys(masterCapResult.capabilities).length > 0 ? { capabilities: masterCapResult.capabilities } : {},
1677
+ layouts: observedLayouts
1678
+ });
1679
+ }
1680
+ const resolvedSlides = slides.map((parsedSlide) => {
1681
+ const boundMaster = parsedSlide.layoutKey === void 0 ? void 0 : masterByLayoutKey.get(parsedSlide.layoutKey);
1682
+ const boundLayout = parsedSlide.layoutKey === void 0 ? void 0 : layoutByKey.get(parsedSlide.layoutKey);
1683
+ let slideThemeBase;
1684
+ if (boundMaster !== void 0) {
1685
+ slideThemeBase = createThemeContext(boundMaster.theme, deck.props["style"], { colorMap: boundMaster.colorMap });
1686
+ if (boundLayout?.themeOverride !== void 0 || boundLayout?.colorMapOverride !== void 0) slideThemeBase = slideThemeBase.withNativeOverrides(boundLayout.themeOverride, boundLayout.colorMapOverride);
1687
+ } else slideThemeBase = theme;
1688
+ if (parsedSlide.themeOverride !== void 0 || parsedSlide.colorMapOverride !== void 0) slideThemeBase = slideThemeBase.withNativeOverrides(parsedSlide.themeOverride, parsedSlide.colorMapOverride);
1689
+ const parsedOwner = parsedSlide.layoutKey === void 0 ? void 0 : parsedLayoutByKey.get(parsedSlide.layoutKey);
1690
+ const parsedMaster = parsedOwner?.master;
1691
+ const parsedLayout = parsedOwner?.layout;
1692
+ let inheritedBackground;
1693
+ if (!Object.hasOwn(parsedSlide.node.props, "background") && parsedSlide.layoutKey !== void 0 && bgModule !== void 0) {
1694
+ const inheritedDecl = parsedLayout?.background ?? parsedMaster?.background;
1695
+ if (inheritedDecl !== void 0) inheritedBackground = resolveMasterOrLayoutSlideCapability({
1696
+ module: bgModule,
1697
+ targetType: "slide",
1698
+ props: { background: inheritedDecl },
1699
+ path: `deck/slide[${parsedSlide.id}]`,
1700
+ dimensions: size,
1701
+ theme: slideThemeBase,
1702
+ options,
1703
+ slideNumber: parsedSlide.index,
1704
+ document
1705
+ });
1706
+ }
1707
+ const masterFooter = parsedMaster?.footerPlaceholders ?? deriveFooterPlaceholdersFromMap(parsedMaster?.placeholders);
1708
+ const layoutFooter = parsedLayout?.footerPlaceholders ?? deriveFooterPlaceholdersFromMap(parsedLayout?.placeholders);
1709
+ const inheritance = parsedMaster !== void 0 || parsedLayout !== void 0 ? {
1710
+ ...parsedMaster === void 0 ? {} : { master: {
1711
+ ...parsedMaster.headerFooter === void 0 ? {} : { headerFooter: parsedMaster.headerFooter },
1712
+ ...masterFooter === void 0 ? {} : { footerPlaceholders: masterFooter }
1713
+ } },
1714
+ ...parsedLayout === void 0 ? {} : { layout: {
1715
+ ...parsedLayout.headerFooter === void 0 ? {} : { headerFooter: parsedLayout.headerFooter },
1716
+ ...layoutFooter === void 0 ? {} : { footerPlaceholders: layoutFooter }
1717
+ } }
1718
+ } : void 0;
1719
+ const slideShowsMaster = parsedSlide.showMasterShapes ?? true;
1720
+ const layoutShowsMaster = boundLayout?.showMasterShapes ?? true;
1721
+ const activeMasterLayers = slideShowsMaster && layoutShowsMaster && (boundMaster?.layers?.length ?? 0) > 0 ? boundMaster.layers : void 0;
1722
+ const activeLayoutLayers = slideShowsMaster && (boundLayout?.layers?.length ?? 0) > 0 ? boundLayout.layers : void 0;
1723
+ 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);
1724
+ });
1725
+ const morphDiagnostics = [];
1726
+ for (let index = 0; index < slides.length; index += 1) {
1727
+ const current = slides[index];
1728
+ const currentResult = resolvedSlides[index];
1729
+ if (current === void 0 || currentResult === void 0 || !currentResult.matchContinuityKinds) continue;
1730
+ const sourceIndexes = /* @__PURE__ */ new Set();
1731
+ if (!current.hidden) {
1732
+ let priorVisible = index - 1;
1733
+ while (priorVisible >= 0 && slides[priorVisible]?.hidden === true) priorVisible -= 1;
1734
+ if (priorVisible >= 0) sourceIndexes.add(priorVisible);
1735
+ }
1736
+ for (let sourceIndex = 0; sourceIndex < resolvedSlides.length; sourceIndex += 1) if (sourceIndex !== index && resolvedSlides[sourceIndex]?.linkedSlideIndexes.has(current.index)) sourceIndexes.add(sourceIndex);
1737
+ for (const [key, object] of currentResult.morphObjects) for (const sourceIndex of sourceIndexes) {
1738
+ const source = resolvedSlides[sourceIndex]?.morphObjects.get(key);
1739
+ if (source === void 0 || source.kind === object.kind) continue;
1740
+ 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`));
1741
+ }
1742
+ }
1743
+ if (morphDiagnostics.length > 0) throw new BuildError(morphDiagnostics);
1744
+ const slideObservations = resolvedSlides.map(({ observation }) => observation);
1745
+ const report = deepFreeze({
1746
+ evidence: "generation",
1747
+ ...typeof title === "string" ? { title } : {},
1748
+ extensions: [...document.usedExtensions],
1749
+ ...masterObservations.length > 0 ? { masters: masterObservations } : {},
1750
+ slides: slideObservations,
1751
+ diagnostics: document.warnings
1752
+ });
1753
+ const query = createBuildQuery(resolvedSlides.map((slide, index) => ({
1754
+ observation: report.slides[index],
1755
+ content: slide.internal.content
1756
+ })));
1757
+ const resolution = Object.freeze({
1758
+ report,
1759
+ query
1760
+ });
1761
+ const internal = {
1762
+ dimensions: size,
1763
+ ...typeof title === "string" ? { title } : {},
1764
+ theme,
1765
+ ...resolvedMasters.length > 0 ? { masters: resolvedMasters } : {},
1766
+ ...mastersModule?.mastersCanvas === void 0 ? {} : { mastersCanvas: mastersModule.mastersCanvas },
1767
+ ...mastersModule?.mastersEmitDriver === void 0 ? {} : { mastersEmitDriver: mastersModule.mastersEmitDriver },
1768
+ sections,
1769
+ ...boundSections === void 0 ? {} : { sectionsEmitter: boundSections },
1770
+ slides: resolvedSlides.map(({ internal: slideInternal }) => slideInternal),
1771
+ resourceClaims: document.resourceClaims,
1772
+ warnings: [...document.warnings]
1773
+ };
1774
+ registerInternalResolution(resolution, internal);
1775
+ return resolution;
1776
+ }
1777
+ function normalizeDeclarationInput(input) {
1778
+ if (isDeclarationNode(input)) return { children: [input] };
1779
+ if (typeof input === "object" && input !== null && "children" in input && Array.isArray(input.children)) return input;
1780
+ return { children: [] };
1781
+ }
1782
+ function createResolver(modules) {
1783
+ const bound = bindCapabilityModules(modules);
1784
+ return function resolve(declaration, options = {}) {
1785
+ validateResolveOptions(options);
1786
+ if (options.signal?.aborted) throw options.signal.reason;
1787
+ return resolveDocument(normalizeDeclarationInput(declaration), bound, options);
1788
+ };
1789
+ }
1790
+ function validateBoundSlideCapability(bound) {
1791
+ if (typeof bound !== "object" || bound === null) throw new CapabilityError("invalid-capability-binding", "Slide capability bindSlide() must return a resolveSlide handler");
1792
+ if (typeof bound.resolveSlide !== "function") throw new CapabilityError("invalid-capability-binding", "Slide capability bindSlide() must return a resolveSlide handler");
1793
+ return bound;
1794
+ }
1795
+ function bindCapabilityModules(modules) {
1796
+ const declarations = /* @__PURE__ */ new Map();
1797
+ const slideModules = /* @__PURE__ */ new Map();
1798
+ for (const module of modules) {
1799
+ if (typeof module !== "object" || module === null) throw new BuildError([diagnostic("build.modules", "invalid-capability-module", "Capability module must be an object")]);
1800
+ const slideModule = "bindSlide" in module && typeof module.bindSlide === "function" && !("bind" in module) && !("parse" in module) ? module : void 0;
1801
+ const objectModule = "bind" in module && typeof module.bind === "function" && !("parse" in module) && !("bindSlide" in module) ? module : void 0;
1802
+ if (slideModule === void 0 && objectModule === void 0) {
1803
+ const rawDeclaration = module.declaration;
1804
+ const declarationLabel = typeof rawDeclaration === "string" && rawDeclaration.trim() !== "" ? rawDeclaration : "<unknown>";
1805
+ throw new BuildError([diagnostic("build.modules", "invalid-capability-module", `Capability module ${declarationLabel} must implement the bound bind() or bindSlide() contract`)]);
1806
+ }
1807
+ 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")]);
1808
+ if (slideModule !== void 0) {
1809
+ if (slideModules.has(slideModule.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
1810
+ slideModules.set(slideModule.declaration, slideModule);
1811
+ for (const transparent of slideModule.transparentDeclarations ?? []) {
1812
+ 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")]);
1813
+ if (!("compileDeclaration" in transparent) || typeof transparent.compileDeclaration !== "function") throw new BuildError([diagnostic("build.modules", "invalid-capability-module", `Transparent declaration ${transparent.declaration} must implement compileDeclaration()`)]);
1814
+ if (declarations.has(transparent.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
1815
+ declarations.set(transparent.declaration, transparent);
1816
+ }
1817
+ } else if (objectModule !== void 0) {
1818
+ if (declarations.has(objectModule.declaration)) throw new BuildError([diagnostic("build.modules", "duplicate-capability", "Duplicate capability module declaration")]);
1819
+ declarations.set(objectModule.declaration, objectModule);
1820
+ }
1821
+ }
1822
+ return {
1823
+ declarations,
1824
+ slideModules
1825
+ };
1826
+ }
1827
+ export { createResolver };