@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,761 @@
1
+ import { schemeColorNameSchema } from "../../core/dist/theme.js";
2
+ import { presetGeometryNameSchema } from "../../core/dist/geometry-schemas.js";
3
+ import "../../core/dist/capability.js";
4
+ import { A_NS, R_NS, emuToPx } from "./namespaces.js";
5
+ import { resolvePartPath } from "./opc.js";
6
+ import { extentEmuFragmentSchema, hexRgb6Schema, offsetEmuFragmentSchema, ooxmlIntSchema, ooxmlNonNegativeIntSchema, transformAttributesFragmentSchema } from "./xml-fragments.js";
7
+ import { z } from "zod";
8
+ // ../import/dist/visual.js
9
+ const arrowTypes = [
10
+ "none",
11
+ "triangle",
12
+ "stealth",
13
+ "arrow",
14
+ "diamond",
15
+ "oval"
16
+ ];
17
+ const arrowTypeSchema = z.enum(arrowTypes);
18
+ const percentValAttrSchema = z.object({ val: ooxmlNonNegativeIntSchema });
19
+ const alphaModFixAttrSchema = z.object({ amt: ooxmlNonNegativeIntSchema });
20
+ const srgbColorAttrSchema = z.object({ val: hexRgb6Schema });
21
+ const schemeColorAttrSchema = z.object({ val: schemeColorNameSchema });
22
+ const sysColorAttrSchema = z.object({
23
+ val: z.string().min(1),
24
+ lastClr: hexRgb6Schema.optional()
25
+ });
26
+ const gradStopAttrSchema = z.object({ pos: ooxmlNonNegativeIntSchema });
27
+ const gradLinAttrSchema = z.object({
28
+ ang: ooxmlIntSchema.optional(),
29
+ scaled: z.enum([
30
+ "0",
31
+ "1",
32
+ "true",
33
+ "false"
34
+ ]).optional()
35
+ });
36
+ const lineAttrSchema = z.object({
37
+ w: ooxmlNonNegativeIntSchema.optional(),
38
+ cap: z.enum([
39
+ "rnd",
40
+ "sq",
41
+ "flat"
42
+ ]).optional(),
43
+ cmpd: z.enum([
44
+ "sng",
45
+ "dbl",
46
+ "thickThin",
47
+ "thinThick",
48
+ "tri"
49
+ ]).optional(),
50
+ algn: z.enum(["ctr", "in"]).optional()
51
+ });
52
+ const dashPresetAttrSchema = z.object({ val: z.string().min(1) });
53
+ const lineEndAttrSchema = z.object({
54
+ type: arrowTypeSchema.optional(),
55
+ w: z.enum([
56
+ "sm",
57
+ "med",
58
+ "lg"
59
+ ]).optional(),
60
+ len: z.enum([
61
+ "sm",
62
+ "med",
63
+ "lg"
64
+ ]).optional()
65
+ });
66
+ const outerShadowAttrSchema = z.object({
67
+ blurRad: ooxmlNonNegativeIntSchema.optional(),
68
+ dist: ooxmlNonNegativeIntSchema.optional(),
69
+ dir: ooxmlIntSchema.optional(),
70
+ algn: z.string().optional(),
71
+ rotWithShape: z.enum([
72
+ "0",
73
+ "1",
74
+ "true",
75
+ "false"
76
+ ]).optional()
77
+ });
78
+ const softEdgeAttrSchema = z.object({ rad: ooxmlNonNegativeIntSchema });
79
+ /** Reads a DrawingML color child (`<a:srgbClr>`, `<a:schemeClr>`, `<a:sysClr>`) with optional alpha and luminance transforms. */
80
+ function readDrawingColor(parentCursor, location, diagnostics) {
81
+ let colorCursor;
82
+ let baseHex;
83
+ let slot;
84
+ for (const child of parentCursor.remainingElementChildren()) {
85
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
86
+ diagnostics.push({
87
+ code: "unconsumed-xml",
88
+ category: "unsupported",
89
+ disposition: "omitted",
90
+ kind: "element",
91
+ location: {
92
+ ...location,
93
+ xpath: child.xpath
94
+ },
95
+ namespaceUri: child.namespaceUri,
96
+ localName: child.localName
97
+ });
98
+ continue;
99
+ }
100
+ if (child.localName === "srgbClr" && colorCursor === void 0) {
101
+ colorCursor = child;
102
+ const raw = child.attrsObject(["val"]);
103
+ const parsed = srgbColorAttrSchema.safeParse(raw);
104
+ if (!parsed.success) {
105
+ diagnostics.push({
106
+ code: "invalid-xml-value",
107
+ category: "corrupt-input",
108
+ disposition: "omitted",
109
+ location: {
110
+ ...location,
111
+ xpath: child.xpath
112
+ },
113
+ attributeOrElement: "a:srgbClr/@val",
114
+ rawValue: raw["val"] ?? ""
115
+ });
116
+ return;
117
+ }
118
+ baseHex = `#${parsed.data.val.toUpperCase()}`;
119
+ } else if (child.localName === "schemeClr" && colorCursor === void 0) {
120
+ colorCursor = child;
121
+ const raw = child.attrsObject(["val"]);
122
+ const parsed = schemeColorAttrSchema.safeParse(raw);
123
+ if (!parsed.success) {
124
+ diagnostics.push({
125
+ code: "invalid-xml-value",
126
+ category: "corrupt-input",
127
+ disposition: "omitted",
128
+ location: {
129
+ ...location,
130
+ xpath: child.xpath
131
+ },
132
+ attributeOrElement: "a:schemeClr/@val",
133
+ rawValue: raw["val"] ?? ""
134
+ });
135
+ return;
136
+ }
137
+ slot = parsed.data.val;
138
+ } else if (child.localName === "sysClr" && colorCursor === void 0) {
139
+ colorCursor = child;
140
+ const raw = child.attrsObject(["val", "lastClr"]);
141
+ const parsed = sysColorAttrSchema.safeParse(raw);
142
+ if (!parsed.success) {
143
+ diagnostics.push({
144
+ code: "invalid-xml-value",
145
+ category: "corrupt-input",
146
+ disposition: "omitted",
147
+ location: {
148
+ ...location,
149
+ xpath: child.xpath
150
+ },
151
+ attributeOrElement: "a:sysClr",
152
+ rawValue: JSON.stringify(raw)
153
+ });
154
+ return;
155
+ }
156
+ const fallback = parsed.data.val === "windowText" ? "000000" : parsed.data.val === "window" ? "FFFFFF" : void 0;
157
+ const hex = parsed.data.lastClr ?? fallback;
158
+ if (hex === void 0) return void 0;
159
+ baseHex = `#${hex.toUpperCase()}`;
160
+ } else diagnostics.push({
161
+ code: "unsupported-mechanism",
162
+ category: "unsupported",
163
+ disposition: "omitted",
164
+ location: {
165
+ ...location,
166
+ xpath: child.xpath
167
+ },
168
+ namespaceUri: child.namespaceUri,
169
+ localName: child.localName,
170
+ mechanismHint: `color:${child.localName}`
171
+ });
172
+ }
173
+ if (colorCursor === void 0) return void 0;
174
+ let alpha;
175
+ let lumMod;
176
+ let lumOff;
177
+ for (const mod of colorCursor.remainingElementChildren()) if (mod.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && mod.localName === "alpha") {
178
+ const parsed = percentValAttrSchema.safeParse(mod.attrsObject(["val"]));
179
+ if (parsed.success) alpha = Math.min(1, Math.max(0, parsed.data.val / 1e5));
180
+ } else if (mod.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && mod.localName === "lumMod") {
181
+ const parsed = percentValAttrSchema.safeParse(mod.attrsObject(["val"]));
182
+ if (parsed.success) lumMod = Math.min(1, Math.max(0, parsed.data.val / 1e5));
183
+ } else if (mod.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && mod.localName === "lumOff") {
184
+ const parsed = percentValAttrSchema.safeParse(mod.attrsObject(["val"]));
185
+ if (parsed.success) lumOff = Math.min(1, Math.max(0, parsed.data.val / 1e5));
186
+ } else diagnostics.push({
187
+ code: "unsupported-mechanism",
188
+ category: "unsupported",
189
+ disposition: "omitted",
190
+ location: {
191
+ ...location,
192
+ xpath: mod.xpath
193
+ },
194
+ namespaceUri: mod.namespaceUri,
195
+ localName: mod.localName,
196
+ mechanismHint: `color-transform:${mod.localName}`
197
+ });
198
+ const baseColor = slot !== void 0 ? lumMod !== void 0 ? {
199
+ slot,
200
+ lumMod,
201
+ ...lumOff === void 0 ? {} : { lumOff }
202
+ } : slot : baseHex;
203
+ if (baseColor === void 0) return void 0;
204
+ if (alpha !== void 0 && alpha < 1) return {
205
+ color: baseColor,
206
+ alpha
207
+ };
208
+ return baseColor;
209
+ }
210
+ /** Parses `<a:xfrm>` offset, extent, rotation, and flips into pixels and raw EMU. */
211
+ function readTransformXml(xfrmCursor, location, diagnostics) {
212
+ const rawXfrm = xfrmCursor.attrsObject([
213
+ "rot",
214
+ "flipH",
215
+ "flipV"
216
+ ]);
217
+ const parsedXfrm = transformAttributesFragmentSchema.safeParse(rawXfrm);
218
+ const off = xfrmCursor.child(A_NS, "off");
219
+ const ext = xfrmCursor.child(A_NS, "ext");
220
+ if (off === void 0 || ext === void 0) {
221
+ diagnostics.push({
222
+ code: "corrupt-part",
223
+ category: "corrupt-input",
224
+ disposition: "omitted",
225
+ location: {
226
+ ...location,
227
+ xpath: xfrmCursor.xpath
228
+ }
229
+ });
230
+ return;
231
+ }
232
+ const parsedOff = offsetEmuFragmentSchema.safeParse(off.attrsObject(["x", "y"]));
233
+ const parsedExt = extentEmuFragmentSchema.safeParse(ext.attrsObject(["cx", "cy"]));
234
+ if (!parsedOff.success || !parsedExt.success) {
235
+ diagnostics.push({
236
+ code: "invalid-xml-value",
237
+ category: "corrupt-input",
238
+ disposition: "omitted",
239
+ location: {
240
+ ...location,
241
+ xpath: xfrmCursor.xpath
242
+ },
243
+ attributeOrElement: "a:xfrm"
244
+ });
245
+ return;
246
+ }
247
+ const rotate = parsedXfrm.success && parsedXfrm.data.rot !== void 0 && parsedXfrm.data.rot !== 0 ? parsedXfrm.data.rot / 6e4 : void 0;
248
+ const flipH = parsedXfrm.success && parsedXfrm.data.flipH === true;
249
+ const flipV = parsedXfrm.success && parsedXfrm.data.flipV === true;
250
+ return {
251
+ x: emuToPx(parsedOff.data.x),
252
+ y: emuToPx(parsedOff.data.y),
253
+ width: emuToPx(parsedExt.data.cx),
254
+ height: emuToPx(parsedExt.data.cy),
255
+ xEmu: parsedOff.data.x,
256
+ yEmu: parsedOff.data.y,
257
+ cxEmu: parsedExt.data.cx,
258
+ cyEmu: parsedExt.data.cy,
259
+ ...rotate === void 0 ? {} : { rotate },
260
+ ...flipH ? { flipH: true } : {},
261
+ ...flipV ? { flipV: true } : {}
262
+ };
263
+ }
264
+ /** Reads DrawingML `<a:gradFill>` into a `LinearGradient` or `RadialGradient`. */
265
+ function readGradientFill(gradFillCursor, location, diagnostics) {
266
+ gradFillCursor.consumeAttr("rotWithShape");
267
+ gradFillCursor.consumeAttr("flip");
268
+ const gsLst = gradFillCursor.child(A_NS, "gsLst");
269
+ const stops = [];
270
+ if (gsLst !== void 0) for (const gs of gsLst.children(A_NS, "gs")) {
271
+ const rawPos = gs.attrsObject(["pos"]);
272
+ const parsedPos = gradStopAttrSchema.safeParse(rawPos);
273
+ const color = readDrawingColor(gs, location, diagnostics);
274
+ if (!parsedPos.success || color === void 0) {
275
+ diagnostics.push({
276
+ code: "invalid-xml-value",
277
+ category: "corrupt-input",
278
+ disposition: "omitted",
279
+ location: {
280
+ ...location,
281
+ xpath: gs.xpath
282
+ },
283
+ attributeOrElement: "a:gs",
284
+ rawValue: JSON.stringify(rawPos)
285
+ });
286
+ continue;
287
+ }
288
+ stops.push({
289
+ position: Math.min(1, Math.max(0, parsedPos.data.pos / 1e5)),
290
+ color
291
+ });
292
+ }
293
+ if (stops.length < 2) {
294
+ diagnostics.push({
295
+ code: "invalid-xml-value",
296
+ category: "corrupt-input",
297
+ disposition: "omitted",
298
+ location: {
299
+ ...location,
300
+ xpath: gradFillCursor.xpath
301
+ },
302
+ attributeOrElement: "a:gradFill/a:gsLst"
303
+ });
304
+ return;
305
+ }
306
+ let result;
307
+ const lin = gradFillCursor.child(A_NS, "lin");
308
+ if (lin !== void 0) {
309
+ const rawLin = lin.attrsObject(["ang", "scaled"]);
310
+ const parsedLin = gradLinAttrSchema.safeParse(rawLin);
311
+ result = {
312
+ type: "linear-gradient",
313
+ angle: (((parsedLin.success ? parsedLin.data.ang ?? 0 : 0) / 6e4 + 90) % 360 + 360) % 360,
314
+ stops
315
+ };
316
+ } else {
317
+ const pathEl = gradFillCursor.child(A_NS, "path");
318
+ if (pathEl !== void 0) {
319
+ pathEl.consumeAttr("path");
320
+ const fillToRect = pathEl.child(A_NS, "fillToRect");
321
+ if (fillToRect !== void 0) {
322
+ fillToRect.consumeAttr("l");
323
+ fillToRect.consumeAttr("t");
324
+ fillToRect.consumeAttr("r");
325
+ fillToRect.consumeAttr("b");
326
+ }
327
+ result = {
328
+ type: "radial-gradient",
329
+ stops
330
+ };
331
+ }
332
+ }
333
+ const tileRect = gradFillCursor.child(A_NS, "tileRect");
334
+ if (tileRect !== void 0) {
335
+ tileRect.consumeAttr("l");
336
+ tileRect.consumeAttr("t");
337
+ tileRect.consumeAttr("r");
338
+ tileRect.consumeAttr("b");
339
+ }
340
+ return result;
341
+ }
342
+ /** Reads DrawingML `<a:blipFill>` embedded image bytes and optional `<a:alphaModFix>` opacity. */
343
+ function readBlipFill(blipFillCursor, pkg, location, diagnostics, validateImageBytes) {
344
+ blipFillCursor.consumeAttr("rotWithShape");
345
+ blipFillCursor.consumeAttr("dpi");
346
+ const srcRect = blipFillCursor.child(A_NS, "srcRect");
347
+ if (srcRect !== void 0) {
348
+ srcRect.consumeAttr("l");
349
+ srcRect.consumeAttr("t");
350
+ srcRect.consumeAttr("r");
351
+ srcRect.consumeAttr("b");
352
+ }
353
+ const stretch = blipFillCursor.child(A_NS, "stretch");
354
+ if (stretch !== void 0) stretch.ignoreEmptyChild(A_NS, "fillRect");
355
+ const blip = blipFillCursor.child(A_NS, "blip");
356
+ if (blip === void 0) {
357
+ diagnostics.push({
358
+ code: "corrupt-part",
359
+ category: "corrupt-input",
360
+ disposition: "omitted",
361
+ location: {
362
+ ...location,
363
+ xpath: blipFillCursor.xpath
364
+ }
365
+ });
366
+ return;
367
+ }
368
+ blip.consumeAttr("cstate");
369
+ const embedId = blip.attr("embed", R_NS);
370
+ const linkId = blip.attr("link", R_NS);
371
+ let opacity;
372
+ const alphaModFix = blip.child(A_NS, "alphaModFix");
373
+ if (alphaModFix !== void 0) {
374
+ const parsedAmt = alphaModFixAttrSchema.safeParse(alphaModFix.attrsObject(["amt"]));
375
+ if (parsedAmt.success) opacity = Math.min(1, Math.max(0, parsedAmt.data.amt / 1e5));
376
+ }
377
+ if (embedId === void 0) {
378
+ diagnostics.push({
379
+ code: "unsupported-mechanism",
380
+ category: "unsupported",
381
+ disposition: "omitted",
382
+ location: {
383
+ ...location,
384
+ xpath: blip.xpath
385
+ },
386
+ namespaceUri: A_NS,
387
+ localName: "blip",
388
+ mechanismHint: linkId !== void 0 ? "linked-image-fill" : "blip-fill"
389
+ });
390
+ return;
391
+ }
392
+ const rels = pkg.readRelationships(location.part);
393
+ diagnostics.push(...rels.diagnostics);
394
+ const rel = rels.entries.find((entry) => entry.Id === embedId);
395
+ if (rel === void 0 || rel.TargetMode === "External") {
396
+ diagnostics.push({
397
+ code: "broken-relationship",
398
+ category: "corrupt-input",
399
+ disposition: "omitted",
400
+ location: {
401
+ ...location,
402
+ xpath: blip.xpath
403
+ },
404
+ relationshipId: embedId
405
+ });
406
+ return;
407
+ }
408
+ const targetPart = resolvePartPath(location.part, rel.Target);
409
+ if (targetPart === void 0 || !pkg.hasPart(targetPart)) {
410
+ diagnostics.push({
411
+ code: "missing-target-part",
412
+ category: "corrupt-input",
413
+ disposition: "omitted",
414
+ location: {
415
+ ...location,
416
+ xpath: blip.xpath
417
+ },
418
+ relationshipId: embedId,
419
+ targetPart: targetPart ?? rel.Target
420
+ });
421
+ return;
422
+ }
423
+ const detachedBytes = pkg.readDetachedBytes(targetPart);
424
+ if (detachedBytes === void 0) return void 0;
425
+ if (validateImageBytes !== void 0) try {
426
+ validateImageBytes(detachedBytes);
427
+ } catch {
428
+ diagnostics.push({
429
+ code: "corrupt-part",
430
+ category: "corrupt-input",
431
+ disposition: "omitted",
432
+ location: { part: targetPart }
433
+ });
434
+ return;
435
+ }
436
+ return {
437
+ image: detachedBytes,
438
+ ...opacity === void 0 ? {} : { opacity }
439
+ };
440
+ }
441
+ /** Reads DrawingML `<a:ln>` stroke width, fill, dash preset, join, and line end arrows. */
442
+ function readLineBorder(lnCursor, location, diagnostics) {
443
+ const rawLn = lnCursor.attrsObject([
444
+ "w",
445
+ "cap",
446
+ "cmpd",
447
+ "algn"
448
+ ]);
449
+ const parsedLn = lineAttrSchema.safeParse(rawLn);
450
+ const width = parsedLn.success && parsedLn.data.w !== void 0 ? emuToPx(parsedLn.data.w) : void 0;
451
+ let borderColor;
452
+ let borderStyle;
453
+ let startArrow;
454
+ let endArrow;
455
+ let hasNoFill = false;
456
+ for (const child of lnCursor.remainingElementChildren()) {
457
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
458
+ diagnostics.push({
459
+ code: "unconsumed-xml",
460
+ category: "unsupported",
461
+ disposition: "omitted",
462
+ kind: "element",
463
+ location: {
464
+ ...location,
465
+ xpath: child.xpath
466
+ },
467
+ namespaceUri: child.namespaceUri,
468
+ localName: child.localName
469
+ });
470
+ continue;
471
+ }
472
+ switch (child.localName) {
473
+ case "noFill":
474
+ hasNoFill = true;
475
+ break;
476
+ case "solidFill":
477
+ borderColor = readDrawingColor(child, location, diagnostics);
478
+ break;
479
+ case "prstDash": {
480
+ const rawDash = child.attrsObject(["val"]);
481
+ const parsedDash = dashPresetAttrSchema.safeParse(rawDash);
482
+ if (parsedDash.success) {
483
+ const val = parsedDash.data.val;
484
+ if (val === "solid") borderStyle = "solid";
485
+ else if (val === "dot" || val === "sysDot") borderStyle = "dotted";
486
+ else if (val === "dash" || val === "lgDash" || val === "dashDot" || val === "lgDashDot" || val === "lgDashDotDot" || val === "sysDash" || val === "sysDashDot" || val === "sysDashDotDot") borderStyle = "dashed";
487
+ else diagnostics.push({
488
+ code: "unsupported-mechanism",
489
+ category: "unsupported",
490
+ disposition: "omitted",
491
+ location: {
492
+ ...location,
493
+ xpath: child.xpath
494
+ },
495
+ namespaceUri: A_NS,
496
+ localName: "prstDash",
497
+ mechanismHint: `dash:${val}`
498
+ });
499
+ }
500
+ break;
501
+ }
502
+ case "headEnd":
503
+ case "tailEnd": {
504
+ const rawEnd = child.attrsObject([
505
+ "type",
506
+ "w",
507
+ "len"
508
+ ]);
509
+ const parsedEnd = lineEndAttrSchema.safeParse(rawEnd);
510
+ if (!parsedEnd.success) {
511
+ diagnostics.push({
512
+ code: "invalid-xml-value",
513
+ category: "corrupt-input",
514
+ disposition: "omitted",
515
+ location: {
516
+ ...location,
517
+ xpath: child.xpath
518
+ },
519
+ attributeOrElement: `a:${child.localName}`,
520
+ rawValue: JSON.stringify(rawEnd)
521
+ });
522
+ break;
523
+ }
524
+ if (parsedEnd.data.type !== void 0) {
525
+ if (child.localName === "headEnd") startArrow = parsedEnd.data.type;
526
+ else endArrow = parsedEnd.data.type;
527
+ }
528
+ break;
529
+ }
530
+ case "round":
531
+ case "miter":
532
+ case "bevel":
533
+ if (child.localName === "miter") child.consumeAttr("lim");
534
+ break;
535
+ default: diagnostics.push({
536
+ code: "unsupported-mechanism",
537
+ category: "unsupported",
538
+ disposition: "omitted",
539
+ location: {
540
+ ...location,
541
+ xpath: child.xpath
542
+ },
543
+ namespaceUri: child.namespaceUri,
544
+ localName: child.localName,
545
+ mechanismHint: `line:${child.localName}`
546
+ });
547
+ }
548
+ }
549
+ if (hasNoFill || borderColor === void 0) return {};
550
+ return {
551
+ borderColor,
552
+ borderWidth: width ?? 1,
553
+ ...borderStyle === void 0 ? {} : { borderStyle },
554
+ ...startArrow === void 0 ? {} : { startArrow },
555
+ ...endArrow === void 0 ? {} : { endArrow }
556
+ };
557
+ }
558
+ /** Reads DrawingML `<a:effectLst>` outer shadow and soft edge while reporting unsupported effects cleanly. */
559
+ function readEffectList(effectLstCursor, location, diagnostics) {
560
+ let boxShadow;
561
+ let softEdge;
562
+ for (const child of effectLstCursor.remainingElementChildren()) {
563
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
564
+ diagnostics.push({
565
+ code: "unconsumed-xml",
566
+ category: "unsupported",
567
+ disposition: "omitted",
568
+ kind: "element",
569
+ location: {
570
+ ...location,
571
+ xpath: child.xpath
572
+ },
573
+ namespaceUri: child.namespaceUri,
574
+ localName: child.localName
575
+ });
576
+ continue;
577
+ }
578
+ if (child.localName === "outerShdw") {
579
+ const raw = child.attrsObject([
580
+ "blurRad",
581
+ "dist",
582
+ "dir",
583
+ "algn",
584
+ "rotWithShape"
585
+ ]);
586
+ const parsed = outerShadowAttrSchema.safeParse(raw);
587
+ const color = readDrawingColor(child, location, diagnostics);
588
+ if (parsed.success) boxShadow = {
589
+ ...color === void 0 ? {} : { color },
590
+ blur: parsed.data.blurRad === void 0 ? 0 : emuToPx(parsed.data.blurRad),
591
+ distance: parsed.data.dist === void 0 ? 0 : emuToPx(parsed.data.dist),
592
+ angle: parsed.data.dir === void 0 ? 0 : parsed.data.dir / 6e4
593
+ };
594
+ } else if (child.localName === "softEdge") {
595
+ const raw = child.attrsObject(["rad"]);
596
+ const parsed = softEdgeAttrSchema.safeParse(raw);
597
+ if (parsed.success && parsed.data.rad > 0) softEdge = emuToPx(parsed.data.rad);
598
+ } else diagnostics.push({
599
+ code: "unsupported-mechanism",
600
+ category: "unsupported",
601
+ disposition: "omitted",
602
+ location: {
603
+ ...location,
604
+ xpath: child.xpath
605
+ },
606
+ namespaceUri: child.namespaceUri,
607
+ localName: child.localName,
608
+ mechanismHint: `effect:${child.localName}`
609
+ });
610
+ }
611
+ return {
612
+ ...boxShadow === void 0 ? {} : { boxShadow },
613
+ ...softEdge === void 0 ? {} : { softEdge }
614
+ };
615
+ }
616
+ function readBasicPlaceholderAppearance(spPr, pkg, _fallbackUnits, location, diagnostics) {
617
+ let prstGeomName;
618
+ let roundRectAdj;
619
+ let backgroundColor;
620
+ let backgroundImage;
621
+ let opacity;
622
+ let border = {};
623
+ let effects = {};
624
+ for (const child of spPr.remainingElementChildren()) {
625
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") continue;
626
+ switch (child.localName) {
627
+ case "prstGeom": {
628
+ prstGeomName = child.attr("prst");
629
+ const avLst = child.child(A_NS, "avLst");
630
+ if (avLst !== void 0) for (const gd of avLst.children(A_NS, "gd")) {
631
+ const name = gd.attr("name");
632
+ const fmla = gd.attr("fmla");
633
+ if (name === "adj" && fmla !== void 0 && fmla.startsWith("val ")) {
634
+ const num = Number(fmla.slice(4));
635
+ if (Number.isSafeInteger(num)) roundRectAdj = num;
636
+ }
637
+ }
638
+ break;
639
+ }
640
+ case "noFill": break;
641
+ case "solidFill":
642
+ backgroundColor = readDrawingColor(child, location, diagnostics);
643
+ break;
644
+ case "gradFill":
645
+ backgroundImage = readGradientFill(child, location, diagnostics);
646
+ break;
647
+ case "blipFill": {
648
+ const blip = readBlipFill(child, pkg, location, diagnostics);
649
+ if (blip !== void 0) {
650
+ backgroundImage = { image: blip.image };
651
+ opacity = blip.opacity;
652
+ }
653
+ break;
654
+ }
655
+ case "ln":
656
+ border = readLineBorder(child, location, diagnostics);
657
+ break;
658
+ case "effectLst":
659
+ effects = readEffectList(child, location, diagnostics);
660
+ break;
661
+ case "extLst": child.ignoreEmptyChild(A_NS, "ext");
662
+ }
663
+ }
664
+ const parsedPrst = prstGeomName === void 0 ? void 0 : presetGeometryNameSchema.safeParse(prstGeomName);
665
+ const geometry = parsedPrst?.success ? roundRectAdj !== void 0 ? {
666
+ type: "preset",
667
+ name: parsedPrst.data,
668
+ adjust: { adj: roundRectAdj }
669
+ } : parsedPrst.data : void 0;
670
+ const style = {
671
+ ...backgroundColor === void 0 ? {} : { backgroundColor },
672
+ ...backgroundImage === void 0 ? {} : { backgroundImage },
673
+ ...border.borderColor === void 0 ? {} : { borderColor: border.borderColor },
674
+ ...border.borderWidth === void 0 ? {} : { borderWidth: border.borderWidth },
675
+ ...border.borderStyle === void 0 ? {} : { borderStyle: border.borderStyle },
676
+ ...opacity === void 0 ? {} : { opacity },
677
+ ...effects.boxShadow === void 0 ? {} : { boxShadow: effects.boxShadow },
678
+ ...effects.softEdge === void 0 ? {} : { softEdge: effects.softEdge }
679
+ };
680
+ return {
681
+ ...geometry === void 0 ? {} : { geometry },
682
+ style
683
+ };
684
+ }
685
+ /**
686
+ * Shared reader for master and layout placeholder `<p:spPr>` transforms, geometry, fills, borders, and effects.
687
+ */
688
+ function readPlaceholderSpPrVisuals(args, options) {
689
+ const { spPr, pkg, location, diagnostics } = args;
690
+ let x;
691
+ let y;
692
+ let width;
693
+ let height;
694
+ let rotate;
695
+ let flipH;
696
+ let flipV;
697
+ let fallbackUnits = {
698
+ w: 0,
699
+ h: 0
700
+ };
701
+ const xfrm = spPr.child(A_NS, "xfrm");
702
+ if (xfrm !== void 0) {
703
+ if (xfrm.child("http://schemas.openxmlformats.org/drawingml/2006/main", "off") !== void 0 && xfrm.child("http://schemas.openxmlformats.org/drawingml/2006/main", "ext") !== void 0) {
704
+ const tf = readTransformXml(xfrm, location, diagnostics);
705
+ if (tf !== void 0) {
706
+ x = tf.x;
707
+ y = tf.y;
708
+ width = tf.width;
709
+ height = tf.height;
710
+ rotate = tf.rotate;
711
+ flipH = tf.flipH;
712
+ flipV = tf.flipV;
713
+ fallbackUnits = {
714
+ w: tf.cxEmu,
715
+ h: tf.cyEmu
716
+ };
717
+ }
718
+ } else {
719
+ const parsedXfrm = transformAttributesFragmentSchema.safeParse(xfrm.attrsObject([
720
+ "rot",
721
+ "flipH",
722
+ "flipV"
723
+ ]));
724
+ if (parsedXfrm.success) {
725
+ if (parsedXfrm.data.rot !== void 0 && parsedXfrm.data.rot !== 0) rotate = parsedXfrm.data.rot / 6e4;
726
+ if (parsedXfrm.data.flipH === true) flipH = true;
727
+ if (parsedXfrm.data.flipV === true) flipV = true;
728
+ }
729
+ }
730
+ }
731
+ const appearance = (options?.readAppearance ?? readBasicPlaceholderAppearance)(spPr, pkg, fallbackUnits, location, diagnostics);
732
+ let borderRadius;
733
+ let exportedGeometry;
734
+ const geom = appearance.geometry;
735
+ if (geom === "roundRect") {
736
+ if (width !== void 0 && height !== void 0) borderRadius = 16667 / 1e5 * Math.min(width, height);
737
+ else exportedGeometry = geom;
738
+ } else if (typeof geom === "object" && geom.type === "preset") {
739
+ if (geom.name === "roundRect") {
740
+ if (width !== void 0 && height !== void 0) {
741
+ const adj = geom.adjust?.["adj"] ?? 16667;
742
+ if (adj > 0) borderRadius = adj / 1e5 * Math.min(width, height);
743
+ } else exportedGeometry = geom;
744
+ } else if (geom.name !== "rect") exportedGeometry = geom;
745
+ } else if (geom !== void 0 && geom !== "rect") exportedGeometry = geom;
746
+ const style = {};
747
+ for (const [key, value] of Object.entries(appearance.style)) if (value !== void 0 && (options?.allowedStyleKeys === void 0 || options.allowedStyleKeys.has(key))) style[key] = value;
748
+ if (borderRadius !== void 0) style["borderRadius"] = borderRadius;
749
+ if (rotate !== void 0) style["rotate"] = rotate;
750
+ return {
751
+ ...x === void 0 ? {} : { x },
752
+ ...y === void 0 ? {} : { y },
753
+ ...width === void 0 ? {} : { width },
754
+ ...height === void 0 ? {} : { height },
755
+ ...exportedGeometry === void 0 ? {} : { geometry: exportedGeometry },
756
+ ...flipH ? { flipH: true } : {},
757
+ ...flipV ? { flipV: true } : {},
758
+ ...Object.keys(style).length === 0 ? {} : { style }
759
+ };
760
+ }
761
+ export { arrowTypeSchema, arrowTypes, readBlipFill, readDrawingColor, readEffectList, readGradientFill, readLineBorder, readPlaceholderSpPrVisuals, readTransformXml };