@officedk/pptxdk 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +21 -0
  2. package/dist/build-zrZuX4fK.d.ts +3 -0
  3. package/dist/build.d.ts +35 -0
  4. package/dist/build.js +128 -0
  5. package/dist/capabilities/dist/all.js +34 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +84 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +32 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +142 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +79 -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 +2403 -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 +1088 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1119 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -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 +192 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +592 -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 +60 -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 +168 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +119 -0
  38. package/dist/capabilities/dist/font/font-engine.js +834 -0
  39. package/dist/capabilities/dist/font/font-import.js +766 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +72 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +74 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +41 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +649 -0
  46. package/dist/capabilities/dist/group/group-xml.js +8 -0
  47. package/dist/capabilities/dist/group/group.js +260 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +164 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +244 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +984 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +147 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +552 -0
  57. package/dist/capabilities/dist/line/line-codegen.js +89 -0
  58. package/dist/capabilities/dist/line/line-declaration.js +72 -0
  59. package/dist/capabilities/dist/line/line-elements.js +12 -0
  60. package/dist/capabilities/dist/line/line-import.js +504 -0
  61. package/dist/capabilities/dist/line/line-xml.js +9 -0
  62. package/dist/capabilities/dist/line/line.js +331 -0
  63. package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
  64. package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
  65. package/dist/capabilities/dist/masters/masters.js +250 -0
  66. package/dist/capabilities/dist/motion/motion-api.js +757 -0
  67. package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
  68. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  69. package/dist/capabilities/dist/motion/motion-import.js +1568 -0
  70. package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
  71. package/dist/capabilities/dist/motion/motion-query.js +423 -0
  72. package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
  73. package/dist/capabilities/dist/motion/motion.js +1617 -0
  74. package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
  75. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  76. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  77. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  78. package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
  79. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  80. package/dist/capabilities/dist/notes/notes.js +194 -0
  81. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
  82. package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
  83. package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
  84. package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
  85. package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
  86. package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
  87. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  88. package/dist/capabilities/dist/shape/shape-import.js +628 -0
  89. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  90. package/dist/capabilities/dist/shape/shape.js +320 -0
  91. package/dist/capabilities/dist/shared/geometry.js +1681 -0
  92. package/dist/capabilities/dist/shared/identity.js +205 -0
  93. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  94. package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
  95. package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
  96. package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
  97. package/dist/capabilities/dist/shared/text-schemas.js +241 -0
  98. package/dist/capabilities/dist/shared/text-service.js +2252 -0
  99. package/dist/capabilities/dist/shared/visual.js +1197 -0
  100. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  101. package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
  102. package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
  103. package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
  104. package/dist/capabilities/dist/table/table-codegen.js +125 -0
  105. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  106. package/dist/capabilities/dist/table/table-elements.js +27 -0
  107. package/dist/capabilities/dist/table/table-import.js +606 -0
  108. package/dist/capabilities/dist/table/table-schemas.js +334 -0
  109. package/dist/capabilities/dist/table/table-xml.js +30 -0
  110. package/dist/capabilities/dist/table/table.js +739 -0
  111. package/dist/capabilities/dist/text/text-codegen.js +198 -0
  112. package/dist/capabilities/dist/text/text-declaration.js +27 -0
  113. package/dist/capabilities/dist/text/text-elements.js +54 -0
  114. package/dist/capabilities/dist/text/text-import.js +1224 -0
  115. package/dist/capabilities/dist/text/text-xml.js +9 -0
  116. package/dist/capabilities/dist/text/text.js +320 -0
  117. package/dist/capabilities/dist/transition/transition-api.js +136 -0
  118. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  119. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  120. package/dist/capabilities/dist/transition/transition.js +260 -0
  121. package/dist/capability-BbKW9w4O.d.ts +2131 -0
  122. package/dist/cli.js +20 -0
  123. package/dist/codegen/dist/assets.js +79 -0
  124. package/dist/codegen/dist/codegen.js +691 -0
  125. package/dist/codegen/dist/identifiers.js +203 -0
  126. package/dist/codegen/dist/index.js +3 -0
  127. package/dist/codegen/dist/printer.js +143 -0
  128. package/dist/codegen/dist/types.js +77 -0
  129. package/dist/core/dist/author-ids.js +51 -0
  130. package/dist/core/dist/author-schemas.js +330 -0
  131. package/dist/core/dist/block-flex-layout.js +801 -0
  132. package/dist/core/dist/build.js +4 -0
  133. package/dist/core/dist/capability.js +15 -0
  134. package/dist/core/dist/declaration.js +16 -0
  135. package/dist/core/dist/diagnostics.js +353 -0
  136. package/dist/core/dist/document-internals.js +26 -0
  137. package/dist/core/dist/document.js +417 -0
  138. package/dist/core/dist/font-seal.js +204 -0
  139. package/dist/core/dist/geometry-schemas.js +256 -0
  140. package/dist/core/dist/grid-layout.js +449 -0
  141. package/dist/core/dist/host.js +40 -0
  142. package/dist/core/dist/index.js +15 -0
  143. package/dist/core/dist/input-values.js +61 -0
  144. package/dist/core/dist/layout-protocol.js +61 -0
  145. package/dist/core/dist/layout-schemas.js +201 -0
  146. package/dist/core/dist/layout.js +340 -0
  147. package/dist/core/dist/masters.js +194 -0
  148. package/dist/core/dist/morph.js +30 -0
  149. package/dist/core/dist/placeholders.js +275 -0
  150. package/dist/core/dist/query.js +190 -0
  151. package/dist/core/dist/resolution.js +12 -0
  152. package/dist/core/dist/resolve.js +2246 -0
  153. package/dist/core/dist/stage-options.js +300 -0
  154. package/dist/core/dist/theme.js +1023 -0
  155. package/dist/core/dist/transform-geometry.js +72 -0
  156. package/dist/document-41spD7bq.d.ts +1350 -0
  157. package/dist/emit/dist/emit.js +957 -0
  158. package/dist/emit/dist/index.js +5 -0
  159. package/dist/emit/dist/ooxml.js +661 -0
  160. package/dist/emit/dist/shape-tree.js +12 -0
  161. package/dist/import/dist/alternate-content.js +54 -0
  162. package/dist/import/dist/diagnostics.js +157 -0
  163. package/dist/import/dist/fonts.js +309 -0
  164. package/dist/import/dist/import.js +513 -0
  165. package/dist/import/dist/index.js +16 -0
  166. package/dist/import/dist/masters.js +1293 -0
  167. package/dist/import/dist/mechanism.js +10 -0
  168. package/dist/import/dist/namespaces.js +61 -0
  169. package/dist/import/dist/notes-masters.js +300 -0
  170. package/dist/import/dist/opc.js +233 -0
  171. package/dist/import/dist/resources.js +166 -0
  172. package/dist/import/dist/sections.js +139 -0
  173. package/dist/import/dist/themes.js +777 -0
  174. package/dist/import/dist/visual.js +821 -0
  175. package/dist/import/dist/xml-fragments.js +277 -0
  176. package/dist/import/dist/xml-reader.js +267 -0
  177. package/dist/index-1ag7U9Jt.d.ts +63 -0
  178. package/dist/index-BEwhk7c8.d.ts +72 -0
  179. package/dist/index-cK2KtukZ.d.ts +161 -0
  180. package/dist/index-v77CTJev.d.ts +55 -0
  181. package/dist/index.d.ts +8 -0
  182. package/dist/index.js +82 -0
  183. package/dist/node.d.ts +53 -0
  184. package/dist/node.js +225 -0
  185. package/dist/pptxdk/src/cli-commands.js +907 -0
  186. package/dist/pptxdk/src/compose.js +53 -0
  187. package/dist/pptxdk/src/slide.js +9 -0
  188. package/dist/preview/dist/index.js +342 -0
  189. package/dist/preview/dist/options.js +40 -0
  190. package/dist/preview/dist/svg-guard.js +1089 -0
  191. package/dist/preview.d.ts +12 -0
  192. package/dist/preview.js +29 -0
  193. package/dist/react/dist/append.js +66 -0
  194. package/dist/react/dist/document-adapter.js +404 -0
  195. package/dist/react/dist/elements.js +82 -0
  196. package/dist/react/dist/from-vanilla.js +57 -0
  197. package/dist/react/dist/index.js +89 -0
  198. package/dist/react/dist/mount.js +34 -0
  199. package/dist/react/dist/reconciler.js +290 -0
  200. package/dist/react.d.ts +235 -0
  201. package/dist/react.js +31 -0
  202. package/dist/transition-6n8GZxSg.d.ts +9 -0
  203. package/dist/vanilla.d.ts +4 -0
  204. package/dist/vanilla.js +15 -0
  205. package/package.json +79 -3
  206. package/README.md +0 -3
@@ -0,0 +1,44 @@
1
+ import { slideBackgroundSchema } from "../../../core/dist/author-schemas.js";
2
+ import "../../../codegen/dist/index.js";
3
+ import { defineSlideCodegen, expr } from "../../../codegen/dist/types.js";
4
+ import "../../../core/dist/capability.js";
5
+ import { serializeImageDescriptorValue } from "../image/image-codegen.js";
6
+ // ../capabilities/dist/slide-background/slide-background-codegen.js
7
+ function isPlainObject(value) {
8
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
9
+ const proto = Object.getPrototypeOf(value);
10
+ return proto === Object.prototype || proto === null;
11
+ }
12
+ /**
13
+ * Serializes `LinearGradient` and `RadialGradient` author values back into `linearGradient(...)`
14
+ * and `radialGradient(...)` calls so gradients in `Slide.background` and `VisualStyle.background`
15
+ * round-trip idiomatically.
16
+ */
17
+ function serializeGradientValue(value, ctx) {
18
+ if (!isPlainObject(value)) return void 0;
19
+ const type = value["type"];
20
+ if (type !== "linear-gradient" && type !== "radial-gradient") return;
21
+ const definedKeys = Object.keys(value).filter((key) => value[key] !== void 0);
22
+ const subPath = ctx.path.includes("@") ? void 0 : "@style.background";
23
+ if (type === "linear-gradient") {
24
+ if (!definedKeys.every((key) => key === "type" || key === "angle" || key === "stops") || typeof value["angle"] !== "number" || !Array.isArray(value["stops"])) return;
25
+ const fn = ctx.useImport("linearGradient");
26
+ const angleExpr = ctx.emitValueExpr(value["angle"], subPath);
27
+ const stopExprs = value["stops"].map((stop) => ctx.emitValueExpr(stop, subPath));
28
+ return expr(ctx.formatVanillaCall(fn, [angleExpr, ...stopExprs]));
29
+ }
30
+ if (!definedKeys.every((key) => key === "type" || key === "stops") || !Array.isArray(value["stops"])) return;
31
+ const fn = ctx.useImport("radialGradient");
32
+ const stopExprs = value["stops"].map((stop) => ctx.emitValueExpr(stop, subPath));
33
+ return expr(ctx.formatVanillaCall(fn, stopExprs));
34
+ }
35
+ /** Source codegen contribution for `Slide.background` / `SlideMaster.background` / `SlideLayout.background` and gradients. */
36
+ const slideBackgroundCodegen = defineSlideCodegen({
37
+ slideProps: { background: (value, ctx) => {
38
+ const parsed = slideBackgroundSchema.safeParse(value);
39
+ if (!parsed.success) ctx.fail("unexpressible-value", parsed.error.issues[0]?.message ?? "Slide.background declaration is invalid");
40
+ return expr(ctx.emitValueExpr(parsed.data));
41
+ } },
42
+ valueSerializers: [serializeGradientValue, serializeImageDescriptorValue]
43
+ });
44
+ export { serializeGradientValue, slideBackgroundCodegen };
@@ -0,0 +1,166 @@
1
+ import { A_NS, P_NS } from "../../../import/dist/namespaces.js";
2
+ import { ooxmlBoolSchema } from "../../../import/dist/xml-fragments.js";
3
+ import { readDrawingColor, readGradientFill } from "../../../import/dist/visual.js";
4
+ import "../../../import/dist/index.js";
5
+ import { readBlipFill } from "../shared/visual.js";
6
+ import { z } from "zod";
7
+ // ../capabilities/dist/slide-background/slide-background-import.js
8
+ const BgAttrsSchema = z.object({ shadeToTitle: ooxmlBoolSchema.optional() });
9
+ const BgPrAttrsSchema = z.object({ rotWithShape: ooxmlBoolSchema.optional() });
10
+ const bgRefAttrsSchema = z.object({ idx: z.enum([
11
+ "1001",
12
+ "1002",
13
+ "1003"
14
+ ]) });
15
+ const processedCommonSlideElements = /* @__PURE__ */ new WeakSet();
16
+ function readBackgroundElement(bgCursor, pkg, location, diagnostics) {
17
+ const rawBgAttrs = bgCursor.attrsObject(["shadeToTitle"]);
18
+ if (!BgAttrsSchema.safeParse(rawBgAttrs).success) diagnostics.push({
19
+ code: "invalid-xml-value",
20
+ category: "corrupt-input",
21
+ disposition: "recovered",
22
+ location: {
23
+ ...location,
24
+ xpath: bgCursor.xpath
25
+ },
26
+ attributeOrElement: "p:bg",
27
+ rawValue: JSON.stringify(rawBgAttrs)
28
+ });
29
+ let result;
30
+ for (const child of bgCursor.remainingElementChildren()) {
31
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/presentationml/2006/main") {
32
+ diagnostics.push({
33
+ code: "unconsumed-xml",
34
+ category: "unsupported",
35
+ disposition: "omitted",
36
+ kind: "element",
37
+ location: {
38
+ ...location,
39
+ xpath: child.xpath
40
+ },
41
+ namespaceUri: child.namespaceUri,
42
+ localName: child.localName
43
+ });
44
+ continue;
45
+ }
46
+ if (child.localName === "bgPr") {
47
+ const rawPrAttrs = child.attrsObject(["rotWithShape"]);
48
+ if (!BgPrAttrsSchema.safeParse(rawPrAttrs).success) diagnostics.push({
49
+ code: "invalid-xml-value",
50
+ category: "corrupt-input",
51
+ disposition: "recovered",
52
+ location: {
53
+ ...location,
54
+ xpath: child.xpath
55
+ },
56
+ attributeOrElement: "p:bgPr",
57
+ rawValue: JSON.stringify(rawPrAttrs)
58
+ });
59
+ child.ignoreEmptyChild(A_NS, "effectLst");
60
+ for (const fillChild of child.remainingElementChildren()) {
61
+ if (fillChild.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
62
+ diagnostics.push({
63
+ code: "unconsumed-xml",
64
+ category: "unsupported",
65
+ disposition: "omitted",
66
+ kind: "element",
67
+ location: {
68
+ ...location,
69
+ xpath: fillChild.xpath
70
+ },
71
+ namespaceUri: fillChild.namespaceUri,
72
+ localName: fillChild.localName
73
+ });
74
+ continue;
75
+ }
76
+ switch (fillChild.localName) {
77
+ case "noFill":
78
+ result = "none";
79
+ break;
80
+ case "solidFill":
81
+ result = readDrawingColor(fillChild, location, diagnostics);
82
+ break;
83
+ case "gradFill":
84
+ result = readGradientFill(fillChild, location, diagnostics);
85
+ break;
86
+ case "blipFill": {
87
+ const blip = readBlipFill(fillChild, pkg, location, diagnostics);
88
+ if (blip !== void 0) result = {
89
+ image: blip.image,
90
+ ...blip.opacity === void 0 ? {} : { opacity: blip.opacity }
91
+ };
92
+ break;
93
+ }
94
+ default: diagnostics.push({
95
+ code: "unsupported-mechanism",
96
+ category: "unsupported",
97
+ disposition: "omitted",
98
+ location: {
99
+ ...location,
100
+ xpath: fillChild.xpath
101
+ },
102
+ namespaceUri: fillChild.namespaceUri,
103
+ localName: fillChild.localName,
104
+ mechanismHint: `background:${fillChild.localName}`
105
+ });
106
+ }
107
+ }
108
+ } else if (child.localName === "bgRef") {
109
+ const rawRefAttrs = child.attrsObject(["idx"]);
110
+ const parsedRefAttrs = bgRefAttrsSchema.safeParse(rawRefAttrs);
111
+ if (!parsedRefAttrs.success) {
112
+ diagnostics.push({
113
+ code: "invalid-xml-value",
114
+ category: "corrupt-input",
115
+ disposition: "omitted",
116
+ location: {
117
+ ...location,
118
+ xpath: child.xpath
119
+ },
120
+ attributeOrElement: "p:bgRef/@idx",
121
+ rawValue: rawRefAttrs["idx"] ?? ""
122
+ });
123
+ child.suppressUnconsumed();
124
+ continue;
125
+ }
126
+ const color = readDrawingColor(child, location, diagnostics);
127
+ result = {
128
+ ref: Number(parsedRefAttrs.data.idx),
129
+ ...color === void 0 ? {} : { color }
130
+ };
131
+ } else diagnostics.push({
132
+ code: "unsupported-mechanism",
133
+ category: "unsupported",
134
+ disposition: "omitted",
135
+ location: {
136
+ ...location,
137
+ xpath: child.xpath
138
+ },
139
+ namespaceUri: child.namespaceUri,
140
+ localName: child.localName,
141
+ mechanismHint: `background:${child.localName}`
142
+ });
143
+ }
144
+ return result;
145
+ }
146
+ /**
147
+ * Shared PresentationML `<p:cSld>/<p:bg>` import handler for slides, slide layouts, and slide masters.
148
+ * Deduplicates by `<p:cSld>` element identity so multiple background mechanisms share one read pass.
149
+ */
150
+ function readSlideBackgroundSlot(context) {
151
+ const cSld = context.slideCursor.child(P_NS, "cSld");
152
+ if (cSld === void 0) return {};
153
+ if (processedCommonSlideElements.has(cSld.element)) return {};
154
+ processedCommonSlideElements.add(cSld.element);
155
+ const bgCursor = cSld.child(P_NS, "bg");
156
+ if (bgCursor === void 0) return {};
157
+ const diagnostics = [];
158
+ const location = {
159
+ part: context.part,
160
+ slideIndex: context.slideIndex
161
+ };
162
+ const background = readBackgroundElement(bgCursor, context.package, location, diagnostics);
163
+ if (background !== void 0) context.slideNode.set({ background });
164
+ return diagnostics.length === 0 ? {} : { diagnostics };
165
+ }
166
+ export { readSlideBackgroundSlot };
@@ -0,0 +1,34 @@
1
+ import { resolvedColorXml, xmlEscape } from "../../../emit/dist/ooxml.js";
2
+ import "../../../emit/dist/index.js";
3
+ import { emitImageFillXml, gradientFillXml } from "../shared/visual.js";
4
+ // ../capabilities/dist/slide-background/slide-background-xml.js
5
+ /** Internal PresentationML slide background wrapper for explicit `"none"` clearing. */
6
+ function slideBackgroundNoneXml() {
7
+ return "<p:bg><p:bgPr><a:noFill/><a:effectLst/></p:bgPr></p:bg>";
8
+ }
9
+ /** Internal PresentationML slide background wrapper for a resolved solid color. */
10
+ function slideBackgroundSolidXml(color) {
11
+ return `<p:bg><p:bgPr><a:solidFill>${resolvedColorXml(color)}</a:solidFill><a:effectLst/></p:bgPr></p:bg>`;
12
+ }
13
+ /** Internal PresentationML slide background wrapper for a resolved gradient. */
14
+ function slideBackgroundGradientXml(gradient) {
15
+ return `<p:bg><p:bgPr>${gradientFillXml(gradient)}<a:effectLst/></p:bgPr></p:bg>`;
16
+ }
17
+ /** Internal PresentationML slide background wrapper for a resolved image fill. */
18
+ function slideBackgroundImageXml(fill, registerResource, box) {
19
+ if (fill.source.kind === "embedded" && fill.fit === "fill" && fill.opacity === void 0) {
20
+ const relationshipId = registerResource({
21
+ bytes: fill.source.bytes,
22
+ extension: fill.source.extension,
23
+ contentType: fill.source.contentType,
24
+ relationshipType: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
25
+ });
26
+ return `<p:bg><p:bgPr><a:blipFill><a:blip r:embed="${xmlEscape(relationshipId)}"/><a:srcRect/><a:stretch><a:fillRect/></a:stretch></a:blipFill><a:effectLst/></p:bgPr></p:bg>`;
27
+ }
28
+ return `<p:bg><p:bgPr>${emitImageFillXml(fill, registerResource, box).replace(/^<a:blipFill rotWithShape="1">/u, "<a:blipFill>")}<a:effectLst/></p:bgPr></p:bg>`;
29
+ }
30
+ /** Internal PresentationML slide background wrapper for a `<p:bgRef>` theme format-scheme reference. */
31
+ function slideBackgroundRefXml(idx, color) {
32
+ return `<p:bg><p:bgRef idx="${idx}">${resolvedColorXml(color)}</p:bgRef></p:bg>`;
33
+ }
34
+ export { slideBackgroundGradientXml, slideBackgroundImageXml, slideBackgroundNoneXml, slideBackgroundRefXml, slideBackgroundSolidXml };
@@ -0,0 +1,238 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { applyFormatColorTransforms } from "../../../core/dist/theme.js";
3
+ import { slideBackgroundSchema } from "../../../core/dist/author-schemas.js";
4
+ import "../../../core/dist/capability.js";
5
+ import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
6
+ import "../../../import/dist/index.js";
7
+ import { readImage } from "../image/image-decode.js";
8
+ import { gradientDefSvg, paintImageFillSvg, resolveGradientSpec, resolveImageBackgroundSpec } from "../shared/visual.js";
9
+ import { slideBackgroundCodegen } from "./slide-background-codegen.js";
10
+ import { readSlideBackgroundSlot } from "./slide-background-import.js";
11
+ import { slideBackgroundGradientXml, slideBackgroundImageXml, slideBackgroundNoneXml, slideBackgroundRefXml, slideBackgroundSolidXml } from "./slide-background-xml.js";
12
+ // ../capabilities/dist/slide-background/slide-background.js
13
+ function resolveFormatColor(theme, refColor, transform) {
14
+ const base = transform.color === "phClr" ? refColor : theme.resolveColor(transform.color);
15
+ return applyFormatColorTransforms(base, transform);
16
+ }
17
+ function resolveBgRefFill(theme, idx, refColor) {
18
+ const bgStyle = theme.formatScheme?.bgFillStyles?.[idx - 1001];
19
+ if (bgStyle === void 0) return {
20
+ kind: "solid",
21
+ color: refColor
22
+ };
23
+ if (bgStyle.kind === "none") return { kind: "none" };
24
+ if (bgStyle.kind === "solid") return {
25
+ kind: "solid",
26
+ color: resolveFormatColor(theme, refColor, bgStyle.color)
27
+ };
28
+ const stops = bgStyle.stops.map((stop) => ({
29
+ position: stop.position,
30
+ color: resolveFormatColor(theme, refColor, stop.color)
31
+ }));
32
+ if (bgStyle.linear !== void 0) return {
33
+ kind: "linear-gradient",
34
+ angle: ((bgStyle.linear.angle + 90) % 360 + 360) % 360,
35
+ stops
36
+ };
37
+ return {
38
+ kind: "radial-gradient",
39
+ stops
40
+ };
41
+ }
42
+ function resolveSlideBackground(theme, background) {
43
+ if (background === void 0) return { kind: "default" };
44
+ if (background === "none") return { kind: "none" };
45
+ const parsed = slideBackgroundSchema.safeParse(background);
46
+ if (!parsed.success) {
47
+ if (typeof background === "string") return {
48
+ kind: "solid",
49
+ color: theme.resolveColor(background)
50
+ };
51
+ if (typeof background === "object" && background !== null && !Array.isArray(background)) {
52
+ const candidate = background;
53
+ if (candidate["type"] === "linear-gradient" || candidate["type"] === "radial-gradient") return resolveGradientSpec(theme, background, void 0);
54
+ if (Object.keys(candidate).length === 1 && Object.hasOwn(candidate, "image")) readImage(candidate["image"]);
55
+ if ("color" in candidate && !("ref" in candidate)) return {
56
+ kind: "solid",
57
+ color: theme.resolveColor(background)
58
+ };
59
+ }
60
+ throw new CapabilityError("invalid-slide-background", parsed.error.issues[0]?.message ?? "Slide.background declaration is invalid");
61
+ }
62
+ const value = parsed.data;
63
+ if (value === "none") return { kind: "none" };
64
+ if (typeof value === "object" && value !== null) {
65
+ if ("image" in value) return resolveImageBackgroundSpec(value, void 0);
66
+ if ("ref" in value) {
67
+ const refColor = theme.resolveColor(value.color ?? "bg1");
68
+ return {
69
+ kind: "ref",
70
+ idx: value.ref,
71
+ refColor,
72
+ fill: resolveBgRefFill(theme, value.ref, refColor)
73
+ };
74
+ }
75
+ if ("type" in value) return resolveGradientSpec(theme, value, void 0);
76
+ }
77
+ return {
78
+ kind: "solid",
79
+ color: theme.resolveColor(value)
80
+ };
81
+ }
82
+ function emitSlideBackground(resolved, emitContext) {
83
+ switch (resolved.kind) {
84
+ case "default": return { xml: "" };
85
+ case "none": return { xml: slideBackgroundNoneXml() };
86
+ case "solid": return { xml: slideBackgroundSolidXml(resolved.color) };
87
+ case "linear-gradient":
88
+ case "radial-gradient": return { xml: slideBackgroundGradientXml(resolved) };
89
+ case "image": return { xml: slideBackgroundImageXml(resolved, (resource) => emitContext.registerResource(resource), {
90
+ x: 0,
91
+ y: 0,
92
+ width: emitContext.dimensions.width,
93
+ height: emitContext.dimensions.height
94
+ }) };
95
+ case "ref": return { xml: slideBackgroundRefXml(resolved.idx, resolved.refColor) };
96
+ default: return resolved;
97
+ }
98
+ }
99
+ function paintSlideBackground(resolved, paintContext, field = "style.background") {
100
+ const { width, height } = paintContext.dimensions;
101
+ switch (resolved.kind) {
102
+ case "default":
103
+ case "none": return { svg: "" };
104
+ case "solid": return { svg: `<rect width="100%" height="100%" fill="#${resolved.color.hex}" fill-opacity="${resolved.color.alpha ?? 1}"/>` };
105
+ case "linear-gradient":
106
+ case "radial-gradient": {
107
+ const gradId = `bg-s${paintContext.slideNumber}-grad`;
108
+ return { svg: `<defs>${gradientDefSvg(gradId, resolved)}</defs><rect x="0" y="0" width="${width}" height="${height}" fill="url(#${gradId})"/>` };
109
+ }
110
+ case "image": {
111
+ const patId = `bg-s${paintContext.slideNumber}-img`;
112
+ let def;
113
+ try {
114
+ def = paintImageFillSvg(resolved, patId, {
115
+ x: 0,
116
+ y: 0,
117
+ width,
118
+ height
119
+ }, paintContext.registerRasterResource);
120
+ } catch (error) {
121
+ const message = error instanceof Error ? error.message : "Failed to decode slide background image for preview";
122
+ throw new CapabilityError("preview-corrupt-image", message, `${paintContext.path}/background`, {
123
+ ...error instanceof CapabilityError ? error.details : void 0,
124
+ field
125
+ });
126
+ }
127
+ return {
128
+ svg: `<defs>${def}</defs><rect x="0" y="0" width="${width}" height="${height}" fill="url(#${patId})"/>`,
129
+ ...resolved.source.kind === "external" ? { placeholders: [{
130
+ path: `${paintContext.path}/background`,
131
+ url: resolved.source.externalUrl
132
+ }] } : {}
133
+ };
134
+ }
135
+ case "ref": switch (resolved.fill.kind) {
136
+ case "none": return { svg: "<rect width=\"100%\" height=\"100%\" fill=\"white\"/>" };
137
+ case "solid": return { svg: `<rect width="100%" height="100%" fill="#${resolved.fill.color.hex}" fill-opacity="${resolved.fill.color.alpha ?? 1}"/>` };
138
+ case "linear-gradient":
139
+ case "radial-gradient": {
140
+ const gradId = `bg-s${paintContext.slideNumber}-grad`;
141
+ return { svg: `<defs>${gradientDefSvg(gradId, resolved.fill)}</defs><rect x="0" y="0" width="${width}" height="${height}" fill="url(#${gradId})"/>` };
142
+ }
143
+ default: return resolved.fill;
144
+ }
145
+ default: return resolved;
146
+ }
147
+ }
148
+ /** Native canvas mechanism for `<p:bg><p:bgPr><a:solidFill>`. */
149
+ const slideBackgroundSolidMechanism = defineCanvasMechanism({
150
+ key: "slide-background-solid",
151
+ role: "canvas",
152
+ emit: (model, context) => emitSlideBackground(model, context),
153
+ paint: (model, context) => paintSlideBackground(model, context),
154
+ import: {
155
+ target: "slide",
156
+ slot: "background",
157
+ read: readSlideBackgroundSlot
158
+ }
159
+ });
160
+ /** Native canvas mechanism for `<p:bg><p:bgPr><a:gradFill>`. */
161
+ const slideBackgroundGradientMechanism = defineCanvasMechanism({
162
+ key: "slide-background-gradient",
163
+ role: "canvas",
164
+ emit: (model, context) => emitSlideBackground(model, context),
165
+ paint: (model, context) => paintSlideBackground(model, context),
166
+ import: {
167
+ target: "slide",
168
+ slot: "background",
169
+ read: readSlideBackgroundSlot
170
+ }
171
+ });
172
+ /** Native canvas mechanism for `<p:bg><p:bgPr><a:blipFill>`. */
173
+ const slideBackgroundImageMechanism = defineCanvasMechanism({
174
+ key: "slide-background-image",
175
+ role: "canvas",
176
+ emit: (model, context) => emitSlideBackground(model, context),
177
+ paint: (model, context) => paintSlideBackground(model, context),
178
+ import: {
179
+ target: "slide",
180
+ slot: "background",
181
+ read: readSlideBackgroundSlot
182
+ }
183
+ });
184
+ /** Native canvas mechanism for `<p:bg><p:bgRef idx="1001..1003">`. */
185
+ const slideBackgroundRefMechanism = defineCanvasMechanism({
186
+ key: "slide-background-ref",
187
+ role: "canvas",
188
+ emit: (model, context) => emitSlideBackground(model, context),
189
+ paint: (model, context) => paintSlideBackground(model, context),
190
+ import: {
191
+ target: "slide",
192
+ slot: "background",
193
+ read: readSlideBackgroundSlot
194
+ }
195
+ });
196
+ /**
197
+ * Bound slide-background module: validates and resolves background declarations once per build
198
+ * and owns both PresentationML `<p:bg>` emission and static preview canvas painting.
199
+ */
200
+ const slideBackgroundCapability = {
201
+ declaration: "slide-background",
202
+ slideProp: "background",
203
+ consumesOwnerBackgroundStyle: true,
204
+ slot: "background",
205
+ always: true,
206
+ codegen: slideBackgroundCodegen,
207
+ mechanisms: [
208
+ slideBackgroundSolidMechanism,
209
+ slideBackgroundGradientMechanism,
210
+ slideBackgroundImageMechanism,
211
+ slideBackgroundRefMechanism
212
+ ],
213
+ bindSlide(input, context) {
214
+ const rawStyle = input.props["style"];
215
+ const styleBackground = typeof rawStyle === "object" && rawStyle !== null && !Array.isArray(rawStyle) ? rawStyle["background"] : void 0;
216
+ const backgroundField = styleBackground !== void 0 ? "style.background" : "background";
217
+ const background = styleBackground ?? input.props["background"];
218
+ try {
219
+ resolveSlideBackground(context.theme, background);
220
+ } catch (error) {
221
+ if (error instanceof CapabilityError) throw new CapabilityError(error.code, error.message, `${context.path}/background`);
222
+ throw error;
223
+ }
224
+ return { resolveSlide(resolveContext) {
225
+ const resolved = resolveSlideBackground(resolveContext.theme, background);
226
+ return {
227
+ extensions: [],
228
+ emit(emitContext) {
229
+ return emitSlideBackground(resolved, emitContext);
230
+ },
231
+ paint(paintContext) {
232
+ return paintSlideBackground(resolved, paintContext, backgroundField);
233
+ }
234
+ };
235
+ } };
236
+ }
237
+ };
238
+ export { slideBackgroundCapability, slideBackgroundGradientMechanism, slideBackgroundImageMechanism, slideBackgroundRefMechanism, slideBackgroundSolidMechanism };
@@ -0,0 +1,125 @@
1
+ import { readInternalDeclarationProps } from "../../../core/dist/document-internals.js";
2
+ import "../../../codegen/dist/index.js";
3
+ import "../../../core/dist/capability.js";
4
+ import { defineObjectCodegen } from "../../../codegen/dist/types.js";
5
+ import { CommonNode } from "../../../core/dist/document.js";
6
+ import { blockRichTextChildKinds, collectRichTextNodeProps, createRichTextCodegenHandler } from "../text/text-codegen.js";
7
+ import { cellAllowedParameters, rowAllowedParameters, rowStyleKeys, tableCellAllStyleKeys, tableCellStyleSchema, tableColumnSchema, tableDeclarationAllowedPropKeys, tableRowStyleSchema, tableStyleKeys, tableStyleSchema, tableTextStyleKeys } from "./table-schemas.js";
8
+ // ../capabilities/dist/table/table-codegen.js
9
+ const tableAllowedPropKeys = new Set(tableDeclarationAllowedPropKeys);
10
+ const rowAllowedPropKeys = new Set(rowAllowedParameters);
11
+ const cellAllowedPropKeys = new Set(cellAllowedParameters);
12
+ const tableCleanStyleKeys = new Set(tableStyleKeys);
13
+ const rowCleanStyleKeys = /* @__PURE__ */ new Set([...tableTextStyleKeys, ...rowStyleKeys]);
14
+ const cellCleanStyleKeys = /* @__PURE__ */ new Set([...tableTextStyleKeys, ...tableCellAllStyleKeys]);
15
+ function isPlainRecord(value) {
16
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
17
+ const proto = Object.getPrototypeOf(value);
18
+ return proto === Object.prototype || proto === null;
19
+ }
20
+ function validateTableNativePlaceholder(node, ctx) {
21
+ const nativePh = readInternalDeclarationProps(node)["nativePlaceholder"];
22
+ if (isPlainRecord(nativePh) && Object.hasOwn(nativePh, "sz") && nativePh["sz"] !== void 0) ctx.fail("unexpressible-value", "Table.nativePlaceholder.sz is no longer supported; use size", "@nativePlaceholder.sz");
23
+ }
24
+ function validateTableLayerStyle(style, layerLabel, allowedKeys, ctx) {
25
+ if (style === void 0) return;
26
+ if (!isPlainRecord(style)) ctx.fail("unexpressible-value", `${layerLabel}.style must be a plain object`, "@style");
27
+ for (const [key, value] of Object.entries(style)) {
28
+ if (value === void 0) continue;
29
+ if (!allowedKeys.has(key)) ctx.fail("unexpressible-value", `${layerLabel}.style does not support property ${JSON.stringify(key)}`, `@style.${key}`);
30
+ }
31
+ const parsed = (layerLabel === "Table" ? tableStyleSchema : layerLabel === "Row" ? tableRowStyleSchema : tableCellStyleSchema).safeParse(style);
32
+ if (!parsed.success) {
33
+ const issue = parsed.error.issues[0];
34
+ const issuePath = issue !== void 0 && issue.path.length > 0 ? `@style.${issue.path.join(".")}` : "@style";
35
+ ctx.fail("unexpressible-value", issue?.message ?? `${layerLabel}.style cannot be expressed`, issuePath);
36
+ }
37
+ }
38
+ function validateTableColumns(node, ctx) {
39
+ const columns = readInternalDeclarationProps(node)["columns"];
40
+ if (!Array.isArray(columns) || columns.length === 0) ctx.fail("invalid-document", "table declaration requires a non-empty columns array", "@columns");
41
+ for (const [index, column] of columns.entries()) {
42
+ if (typeof column === "number" && !Number.isFinite(column)) ctx.fail("unexpressible-value", `Non-finite number ${String(column)} cannot be expressed in TypeScript`, `@columns[${index}]`);
43
+ if (!tableColumnSchema.safeParse(column).success) ctx.fail("invalid-document", `Invalid table column track at index ${index}`, `@columns[${index}]`);
44
+ }
45
+ }
46
+ function emitTableContainerChildren(node, ctx, expectedChildType) {
47
+ const children = [];
48
+ let childIndex = 0;
49
+ for (const child of node.children) {
50
+ if (!(child instanceof CommonNode)) {
51
+ if (child.type === "#text" && "text" in child && child.text.trim() !== "") ctx.fail("invalid-document", `${node.type} declaration cannot directly contain text content`);
52
+ continue;
53
+ }
54
+ if (child.type !== expectedChildType) {
55
+ const label = child.id === void 0 ? `${child.type}[${childIndex + 1}]` : `${child.type}[${child.id}]`;
56
+ ctx.fail("invalid-document", `${node.type} declaration cannot contain ${JSON.stringify(child.type)} child`, `${ctx.path}/${label}`);
57
+ }
58
+ children.push(ctx.emitChildNode(child, childIndex));
59
+ childIndex += 1;
60
+ }
61
+ return children;
62
+ }
63
+ const cellRichTextHandler = createRichTextCodegenHandler({
64
+ vanillaFactory: "cell",
65
+ reactComponent: "Cell",
66
+ allowedPropKeys: cellAllowedPropKeys,
67
+ allowedChildKinds: blockRichTextChildKinds,
68
+ supportObjectExtras: false
69
+ });
70
+ /**
71
+ * Source codegen contribution for native `table`, `row`, and `cell` declarations.
72
+ *
73
+ * Preserves column tracks (`px` / `"auto"` / `"Nfr"`), row order, `rowSpan`/`colSpan`
74
+ * merges, layer-local styles and borders, placeholder bindings, and cell rich text.
75
+ */
76
+ const tableCodegen = defineObjectCodegen({ declarations: {
77
+ table: {
78
+ emitVanilla(node, ctx) {
79
+ validateTableColumns(node, ctx);
80
+ const callee = ctx.useImport("table");
81
+ const propsEntries = collectRichTextNodeProps(node, ctx, tableAllowedPropKeys, true);
82
+ validateTableNativePlaceholder(node, ctx);
83
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Table", tableCleanStyleKeys, ctx);
84
+ const rows = emitTableContainerChildren(node, ctx, "row");
85
+ return ctx.formatVanillaCall(callee, [ctx.formatProps(propsEntries)], rows);
86
+ },
87
+ emitReact(node, ctx) {
88
+ validateTableColumns(node, ctx);
89
+ const tag = ctx.useImport("Table");
90
+ const propsEntries = collectRichTextNodeProps(node, ctx, tableAllowedPropKeys, true);
91
+ validateTableNativePlaceholder(node, ctx);
92
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Table", tableCleanStyleKeys, ctx);
93
+ const rows = emitTableContainerChildren(node, ctx, "row");
94
+ return ctx.formatJsxElement(tag, propsEntries, rows);
95
+ }
96
+ },
97
+ row: {
98
+ emitVanilla(node, ctx) {
99
+ const callee = ctx.useImport("row");
100
+ const propsEntries = collectRichTextNodeProps(node, ctx, rowAllowedPropKeys, false);
101
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Row", rowCleanStyleKeys, ctx);
102
+ const cells = emitTableContainerChildren(node, ctx, "cell");
103
+ const args = propsEntries.length === 0 ? [] : [ctx.formatProps(propsEntries)];
104
+ return ctx.formatVanillaCall(callee, args, cells);
105
+ },
106
+ emitReact(node, ctx) {
107
+ const tag = ctx.useImport("Row");
108
+ const propsEntries = collectRichTextNodeProps(node, ctx, rowAllowedPropKeys, false);
109
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Row", rowCleanStyleKeys, ctx);
110
+ const cells = emitTableContainerChildren(node, ctx, "cell");
111
+ return ctx.formatJsxElement(tag, propsEntries, cells);
112
+ }
113
+ },
114
+ cell: {
115
+ emitVanilla(node, ctx) {
116
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Cell", cellCleanStyleKeys, ctx);
117
+ return cellRichTextHandler.emitVanilla(node, ctx);
118
+ },
119
+ emitReact(node, ctx) {
120
+ validateTableLayerStyle(readInternalDeclarationProps(node)["style"], "Cell", cellCleanStyleKeys, ctx);
121
+ return cellRichTextHandler.emitReact(node, ctx);
122
+ }
123
+ }
124
+ } });
125
+ export { tableCodegen };
@@ -0,0 +1,15 @@
1
+ import { CommonContainer, RichTextContainer } from "../../../core/dist/document.js";
2
+ // ../capabilities/dist/table/table-declaration.js
3
+ /** Creates the editable native table shared by the command factory and the Table JSX element. */
4
+ function createTableNode(props) {
5
+ return new CommonContainer("table", "table", props);
6
+ }
7
+ /** Creates the editable row shared by command authoring and the Row JSX element. */
8
+ function createRowNode(props) {
9
+ return new CommonContainer("row", "row", props);
10
+ }
11
+ /** Creates the editable rich-text cell shared by command authoring and the Cell JSX element. */
12
+ function createCellNode(props) {
13
+ return new RichTextContainer("cell", "cell", props);
14
+ }
15
+ export { createCellNode, createRowNode, createTableNode };
@@ -0,0 +1,27 @@
1
+ import { hostNodeCreator } from "../../../core/dist/host.js";
2
+ import { motionElement } from "../motion/motion-elements.js";
3
+ import { createCellNode, createRowNode, createTableNode } from "./table-declaration.js";
4
+ import { createElement } from "react";
5
+ // ../capabilities/dist/table/table-elements.js
6
+ /** Declares an editable native table in the React root handled by the table module. */
7
+ function Table(props) {
8
+ return motionElement("table", {
9
+ ...props,
10
+ [hostNodeCreator]: createTableNode
11
+ });
12
+ }
13
+ /** Declares a row of a native table; calculated from actual measurement of row content when height is omitted. */
14
+ function Row(props) {
15
+ return createElement("row", {
16
+ ...props,
17
+ [hostNodeCreator]: createRowNode
18
+ }, props.children);
19
+ }
20
+ /** Declares table cell content and horizontal / vertical merge spans. */
21
+ function Cell(props) {
22
+ return createElement("cell", {
23
+ ...props,
24
+ [hostNodeCreator]: createCellNode
25
+ }, props.children);
26
+ }
27
+ export { Cell, Row, Table };