@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,918 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { linearGradientSchema, radialGradientSchema, shadowSchema, visualStyleSchema } from "../../../core/dist/theme.js";
3
+ import "../../../core/dist/capability.js";
4
+ import { pxToEmu, resolvedColorXml, xmlEscape } from "../../../emit/dist/ooxml.js";
5
+ import "../../../emit/dist/index.js";
6
+ import { A_NS, P_NS } from "../../../import/dist/namespaces.js";
7
+ import { arrowTypeSchema, readBlipFill as readBlipFill$1, readDrawingColor, readEffectList, readGradientFill, readLineBorder, readTransformXml } from "../../../import/dist/visual.js";
8
+ import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
9
+ import "../../../import/dist/index.js";
10
+ import { decodeImageToPngBytes, readImage } from "../image/image-decode.js";
11
+ import { evaluateGeometry, readCustomGeometryXml, readPresetGeometryXml, resolveGeometry, resolvedGeometryXml, shadeHex } from "./geometry.js";
12
+ import { z } from "zod";
13
+ // ../capabilities/dist/shared/visual.js
14
+ const imageRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
15
+ function linearGradient(angle, ...stops) {
16
+ return {
17
+ type: "linear-gradient",
18
+ angle,
19
+ stops: stops.map((stop, index) => typeof stop === "object" && stop !== null && "position" in stop ? stop : {
20
+ color: stop,
21
+ position: stops.length === 1 ? 0 : index / (stops.length - 1)
22
+ })
23
+ };
24
+ }
25
+ function radialGradient(...stops) {
26
+ return {
27
+ type: "radial-gradient",
28
+ stops: stops.map((stop, index) => typeof stop === "object" && stop !== null && "position" in stop ? stop : {
29
+ color: stop,
30
+ position: stops.length === 1 ? 0 : index / (stops.length - 1)
31
+ })
32
+ };
33
+ }
34
+ const lineEndStyleSchema = z.strictObject({
35
+ startArrow: arrowTypeSchema.optional(),
36
+ endArrow: arrowTypeSchema.optional()
37
+ }).readonly();
38
+ Object.keys(lineEndStyleSchema.unwrap().shape);
39
+ Object.keys(visualStyleSchema.unwrap().shape);
40
+ function invalid(code, message) {
41
+ throw new CapabilityError(code, message);
42
+ }
43
+ function isRecord(value) {
44
+ return typeof value === "object" && value !== null && !Array.isArray(value);
45
+ }
46
+ function finite(value, label) {
47
+ if (typeof value !== "number" || !Number.isFinite(value)) invalid("invalid-visual-style", `${label} must be a finite number`);
48
+ return value;
49
+ }
50
+ function emu(value, label, allowZero = true, signed = false) {
51
+ const converted = pxToEmu(value);
52
+ if (!Number.isSafeInteger(converted) || !signed && converted < (allowZero ? 0 : 1) || !signed && converted > 2147483647) invalid("invalid-visual-style", `${label} must be within writable DrawingML range after conversion`);
53
+ return converted;
54
+ }
55
+ function lineWidthEmu(value) {
56
+ const converted = pxToEmu(value);
57
+ if (!Number.isSafeInteger(converted) || converted < 1 || converted > 20116800) invalid("invalid-visual-style", "borderWidth must be within the DrawingML line width range of 1 to 20116800 EMU after conversion");
58
+ return converted;
59
+ }
60
+ function withOpacity(color, opacity) {
61
+ return opacity === void 0 ? color : {
62
+ ...color,
63
+ alpha: (color.alpha ?? 1) * opacity
64
+ };
65
+ }
66
+ function roundSvgNumber(value) {
67
+ const rounded = Math.round(value * 1e6) / 1e6;
68
+ return Object.is(rounded, -0) ? "0" : String(rounded);
69
+ }
70
+ function resolveShadow(theme, value, label) {
71
+ if (!isRecord(value)) invalid("invalid-shadow", `${label} must be a shadow object`);
72
+ const parsed = shadowSchema.safeParse(value);
73
+ if (!parsed.success) {
74
+ const issue = parsed.error.issues[0];
75
+ if (issue?.code === "unrecognized_keys" && issue.keys[0] !== void 0) invalid("invalid-shadow", `${label} contains unsupported parameter ${issue.keys[0]}`);
76
+ const key = String(issue?.path[0] ?? "value");
77
+ if (key === "blur" || key === "distance") {
78
+ if (typeof value[key] !== "number" || !Number.isFinite(value[key])) finite(value[key], `${label}.${key}`);
79
+ invalid("invalid-shadow", `${label}.blur and distance must be non-negative lengths`);
80
+ }
81
+ if (key === "angle") finite(value[key], `${label}.angle`);
82
+ invalid("invalid-shadow", issue?.message ?? `${label} is invalid`);
83
+ }
84
+ const blur = parsed.data.blur ?? 4;
85
+ const distance = parsed.data.distance ?? 0;
86
+ const angle = parsed.data.angle ?? 90;
87
+ emu(blur, `${label}.blur`);
88
+ emu(distance, `${label}.distance`);
89
+ const colorValue = parsed.data.color ?? {
90
+ color: "#000000",
91
+ alpha: .35
92
+ };
93
+ return {
94
+ color: theme.resolveColor(colorValue),
95
+ blur,
96
+ distance,
97
+ angle
98
+ };
99
+ }
100
+ function textShadowXml(theme, value) {
101
+ if (value === void 0 || value === "none") return "";
102
+ const shadow = resolveShadow(theme, value, "textShadow");
103
+ const direction = Math.round((shadow.angle % 360 + 360) % 360 * 6e4);
104
+ return `<a:effectLst><a:outerShdw blurRad="${emu(shadow.blur, "textShadow.blur")}" dist="${emu(shadow.distance, "textShadow.distance")}" dir="${direction}" algn="ctr" rotWithShape="0">${resolvedColorXml(shadow.color)}</a:outerShdw></a:effectLst>`;
105
+ }
106
+ const gradientSchema = z.union([linearGradientSchema, radialGradientSchema]).refine((value) => value.stops.length >= 2);
107
+ /** Resolves and validates a linear or radial gradient declaration against a ThemeContext. */
108
+ function resolveGradientSpec(theme, image, opacity) {
109
+ const parsed = gradientSchema.safeParse(image);
110
+ if (!parsed.success) {
111
+ const issue = parsed.error.issues[0];
112
+ if (issue?.path[0] === "angle" && isRecord(image)) finite(image["angle"], "backgroundImage.angle");
113
+ if (issue?.path[0] === "stops" && isRecord(image) && Array.isArray(image["stops"])) {
114
+ const idx = typeof issue.path[1] === "number" ? issue.path[1] : void 0;
115
+ if (idx !== void 0 && issue.path[2] === "position") {
116
+ const stop = image["stops"][idx];
117
+ if (isRecord(stop)) finite(stop["position"], `backgroundImage.stops[${idx}].position`);
118
+ }
119
+ }
120
+ invalid("invalid-gradient", "backgroundImage must be a linear or radial gradient with at least two color stops");
121
+ }
122
+ const stops = parsed.data.stops.map((stop, index) => {
123
+ if (stop.position < 0 || stop.position > 1) invalid("invalid-gradient", `position for gradient stop ${index + 1} must be between 0 and 1`);
124
+ const color = withOpacity(theme.resolveColor(stop.color), opacity);
125
+ return {
126
+ position: stop.position,
127
+ color
128
+ };
129
+ });
130
+ if (parsed.data.type === "radial-gradient") return {
131
+ kind: "radial-gradient",
132
+ stops
133
+ };
134
+ return {
135
+ kind: "linear-gradient",
136
+ angle: parsed.data.angle,
137
+ stops
138
+ };
139
+ }
140
+ /** Emits DrawingML `<a:gradFill>` from a closed resolved gradient specification. */
141
+ function gradientFillXml(gradient) {
142
+ const stops = gradient.stops.map((stop) => `<a:gs pos="${Math.round(stop.position * 1e5)}">${resolvedColorXml(stop.color)}</a:gs>`).join("");
143
+ switch (gradient.kind) {
144
+ case "radial-gradient": return `<a:gradFill rotWithShape="1"><a:gsLst>${stops}</a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill>`;
145
+ case "linear-gradient": return `<a:gradFill rotWithShape="1"><a:gsLst>${stops}</a:gsLst><a:lin ang="${Math.round(((gradient.angle - 90) % 360 + 360) % 360 * 6e4)}" scaled="0"/></a:gradFill>`;
146
+ default: return gradient;
147
+ }
148
+ }
149
+ function gradientStopsSvg(stops) {
150
+ return [...stops].sort((a, b) => a.position - b.position).map((stop) => `<stop offset="${roundSvgNumber(stop.position * 100)}%" stop-color="#${stop.color.hex}" stop-opacity="${roundSvgNumber(stop.color.alpha ?? 1)}"/>`).join("");
151
+ }
152
+ /** Generates deterministic SVG `<linearGradient>` or `<radialGradient>` definition markup. */
153
+ function gradientDefSvg(id, gradient) {
154
+ const stops = gradientStopsSvg(gradient.stops);
155
+ switch (gradient.kind) {
156
+ case "linear-gradient": {
157
+ const rad = gradient.angle * Math.PI / 180;
158
+ const dx = Math.sin(rad);
159
+ const dy = -Math.cos(rad);
160
+ const halfSpan = (Math.abs(dx) + Math.abs(dy)) / 2;
161
+ return `<linearGradient id="${id}" gradientUnits="objectBoundingBox" x1="${roundSvgNumber(.5 - dx * halfSpan)}" y1="${roundSvgNumber(.5 - dy * halfSpan)}" x2="${roundSvgNumber(.5 + dx * halfSpan)}" y2="${roundSvgNumber(.5 + dy * halfSpan)}">${stops}</linearGradient>`;
162
+ }
163
+ case "radial-gradient": return `<radialGradient id="${id}" gradientUnits="objectBoundingBox" cx="0.5" cy="0.5" r="0.707107">${stops}</radialGradient>`;
164
+ default: return gradient;
165
+ }
166
+ }
167
+ function rotationUnits(style) {
168
+ if (style["rotate"] === void 0) return {
169
+ degrees: 0,
170
+ units: void 0
171
+ };
172
+ const degrees = finite(style["rotate"], "rotate");
173
+ const units = Math.round((degrees % 360 + 360) % 360 * 6e4);
174
+ if (!Number.isSafeInteger(units) || units < 0 || units > 216e5) invalid("invalid-visual-style", "rotate exceeds writable DrawingML range after conversion");
175
+ return {
176
+ degrees,
177
+ units
178
+ };
179
+ }
180
+ function resolveVisualFill(theme, style, explicitFill, opacity, isImageObject) {
181
+ if (isImageObject) return { kind: "none" };
182
+ if (explicitFill !== void 0 && (style["backgroundColor"] !== void 0 || style["backgroundImage"] !== void 0)) invalid("unsupported-style-combination", "Shape.fill cannot be set together with style.backgroundColor or backgroundImage");
183
+ if (explicitFill !== void 0) return {
184
+ kind: "solid",
185
+ color: withOpacity(theme.resolveColor(explicitFill), opacity)
186
+ };
187
+ const background = style["backgroundColor"];
188
+ const image = style["backgroundImage"];
189
+ if (background !== void 0 && image !== void 0) invalid("unsupported-style-combination", "backgroundColor and backgroundImage cannot be set simultaneously");
190
+ if (image !== void 0) {
191
+ if (isRecord(image) && Object.hasOwn(image, "image")) {
192
+ const unknown = Object.keys(image).find((key) => key !== "image");
193
+ if (unknown !== void 0) invalid("invalid-visual-style", `backgroundImage contains unsupported parameter ${unknown}`);
194
+ return {
195
+ kind: "image",
196
+ image: readImage(image["image"]),
197
+ ...opacity === void 0 ? {} : { opacity }
198
+ };
199
+ }
200
+ return resolveGradientSpec(theme, image, opacity);
201
+ }
202
+ if (background === void 0) return { kind: "none" };
203
+ return {
204
+ kind: "solid",
205
+ color: withOpacity(theme.resolveColor(background), opacity)
206
+ };
207
+ }
208
+ function resolveVisualBorder(theme, style, opacity) {
209
+ const color = style["borderColor"];
210
+ const width = style["borderWidth"] === void 0 ? 1 : finite(style["borderWidth"], "borderWidth");
211
+ if (width < 0) invalid("invalid-visual-style", "borderWidth must be a non-negative number");
212
+ const parsedBorder = visualStyleSchema.safeParse(style["borderStyle"] === void 0 ? {} : { borderStyle: style["borderStyle"] });
213
+ if (!parsedBorder.success) invalid("invalid-visual-style", "borderStyle must be solid, dashed, or dotted");
214
+ const parsedLineEnds = lineEndStyleSchema.safeParse({
215
+ ...style["startArrow"] === void 0 ? {} : { startArrow: style["startArrow"] },
216
+ ...style["endArrow"] === void 0 ? {} : { endArrow: style["endArrow"] }
217
+ });
218
+ if (!parsedLineEnds.success) invalid("invalid-visual-style", `${String(parsedLineEnds.error.issues[0]?.path[0] ?? "startArrow")} must be none, triangle, stealth, arrow, diamond, or oval`);
219
+ if (color === void 0 || width === 0) return;
220
+ lineWidthEmu(width);
221
+ return {
222
+ color: withOpacity(theme.resolveColor(color), opacity),
223
+ width,
224
+ style: parsedBorder.data.borderStyle ?? "solid",
225
+ ...parsedLineEnds.data.startArrow === void 0 ? {} : { startArrow: parsedLineEnds.data.startArrow },
226
+ ...parsedLineEnds.data.endArrow === void 0 ? {} : { endArrow: parsedLineEnds.data.endArrow }
227
+ };
228
+ }
229
+ /** Determines whether a Box style specifies visible fill, border, or shadow. */
230
+ function hasVisibleBoxStyle(style) {
231
+ if (style === void 0 || typeof style !== "object" || style === null) return false;
232
+ const borderWidth = style["borderWidth"] === void 0 ? 1 : style["borderWidth"];
233
+ return style["backgroundColor"] !== void 0 || style["backgroundImage"] !== void 0 || style["borderColor"] !== void 0 && borderWidth > 0 || style["boxShadow"] !== void 0;
234
+ }
235
+ /**
236
+ * Validates and resolves visual styles, geometry, fill, border, shadow, softEdge, and transforms
237
+ * into a closed strongly-typed model consumed exhaustively by emitVisualModel and paintVisualModel.
238
+ */
239
+ function resolveVisualModel(options) {
240
+ const { theme, style, box } = options;
241
+ const warnings = [];
242
+ for (const [name, value] of [["flipH", options.flipH], ["flipV", options.flipV]]) if (value !== void 0 && typeof value !== "boolean") invalid("invalid-visual-style", `${name} must be a boolean`);
243
+ const opacity = style["opacity"] === void 0 ? void 0 : finite(style["opacity"], "opacity");
244
+ if (opacity !== void 0 && (opacity < 0 || opacity > 1)) invalid("invalid-visual-style", "opacity must be a number between 0 and 1");
245
+ if (options.image && (style["backgroundColor"] !== void 0 || style["backgroundImage"] !== void 0 || style["borderRadius"] !== void 0)) invalid("unsupported-style-combination", "Image does not support background fill or borderRadius");
246
+ const radius = style["borderRadius"] === void 0 ? void 0 : finite(style["borderRadius"], "borderRadius");
247
+ if (radius !== void 0 && radius < 0) invalid("invalid-visual-style", "borderRadius must be a non-negative length");
248
+ const fill = resolveVisualFill(theme, style, options.fill, opacity, Boolean(options.image));
249
+ const border = resolveVisualBorder(theme, style, opacity);
250
+ const boxShadow = style["boxShadow"] === void 0 ? void 0 : resolveShadow(theme, style["boxShadow"], "boxShadow");
251
+ let softEdge;
252
+ if (style["softEdge"] !== void 0) {
253
+ const rawSoft = finite(style["softEdge"], "softEdge");
254
+ if (rawSoft < 0) invalid("invalid-visual-style", "softEdge must be a non-negative length");
255
+ if (rawSoft > 0) {
256
+ emu(rawSoft, "softEdge", false);
257
+ softEdge = rawSoft;
258
+ }
259
+ }
260
+ const hasVisibleStyle = options.fill !== void 0 && !options.image || hasVisibleBoxStyle(style);
261
+ const layoutOnlyWhenInvisible = Boolean(options.layoutOnlyWhenInvisible);
262
+ const resolvedGeometry = resolveGeometry({
263
+ geometry: options.geometry,
264
+ borderRadius: layoutOnlyWhenInvisible && !hasVisibleStyle ? void 0 : radius,
265
+ box
266
+ });
267
+ warnings.push(...resolvedGeometry.warnings);
268
+ const rotation = rotationUnits(style);
269
+ return {
270
+ box,
271
+ geometry: resolvedGeometry.geometry,
272
+ geometryName: resolvedGeometry.name,
273
+ fill,
274
+ ...border === void 0 ? {} : { border },
275
+ ...opacity === void 0 ? {} : { opacity },
276
+ ...boxShadow === void 0 ? {} : { boxShadow },
277
+ ...softEdge === void 0 ? {} : { softEdge },
278
+ rotate: rotation.degrees,
279
+ ...rotation.units === void 0 ? {} : { rotationUnits: rotation.units },
280
+ flipH: Boolean(options.flipH),
281
+ flipV: Boolean(options.flipV),
282
+ hasVisibleStyle,
283
+ layoutOnlyWhenInvisible,
284
+ warnings
285
+ };
286
+ }
287
+ function emitFillXml(fill, registerResource) {
288
+ switch (fill.kind) {
289
+ case "none": return "<a:noFill/>";
290
+ case "solid": return solidFillMechanism.emit(fill, void 0).xml;
291
+ case "linear-gradient":
292
+ case "radial-gradient": return gradientFillMechanism.emit(fill, void 0).xml;
293
+ case "image": return imageFillMechanism.emit(fill, registerResource).xml;
294
+ default: return fill;
295
+ }
296
+ }
297
+ function emitBorderXml(border) {
298
+ if (border === void 0) return "<a:ln><a:noFill/></a:ln>";
299
+ let dash;
300
+ switch (border.style) {
301
+ case "solid":
302
+ dash = void 0;
303
+ break;
304
+ case "dashed":
305
+ dash = "dash";
306
+ break;
307
+ case "dotted":
308
+ dash = "sysDot";
309
+ break;
310
+ default: return border.style;
311
+ }
312
+ const headEnd = border.startArrow === void 0 ? "" : `<a:headEnd type="${border.startArrow}"/>`;
313
+ const tailEnd = border.endArrow === void 0 ? "" : `<a:tailEnd type="${border.endArrow}"/>`;
314
+ return `<a:ln w="${lineWidthEmu(border.width)}"><a:solidFill>${resolvedColorXml(border.color)}</a:solidFill>${dash === void 0 ? "" : `<a:prstDash val="${dash}"/>`}${headEnd}${tailEnd}</a:ln>`;
315
+ }
316
+ function emitEffectsXml(model) {
317
+ const items = [];
318
+ if (model.boxShadow !== void 0) {
319
+ const shadow = model.boxShadow;
320
+ const dir = Math.round((shadow.angle % 360 + 360) % 360 * 6e4);
321
+ items.push(`<a:outerShdw blurRad="${emu(shadow.blur, "boxShadow.blur")}" dist="${emu(shadow.distance, "boxShadow.distance")}" dir="${dir}" algn="ctr" rotWithShape="0">${resolvedColorXml(shadow.color)}</a:outerShdw>`);
322
+ }
323
+ if (model.softEdge !== void 0 && model.softEdge > 0) items.push(`<a:softEdge rad="${emu(model.softEdge, "softEdge", false)}"/>`);
324
+ return items.length === 0 ? "" : `<a:effectLst>${items.join("")}</a:effectLst>`;
325
+ }
326
+ /** Serializes a ResolvedVisualModel into PresentationML `<p:spPr>` XML. */
327
+ function emitVisualModel(model, registerResource, options) {
328
+ const { box } = model;
329
+ return {
330
+ xml: `<p:spPr>${model.layoutOnlyWhenInvisible && !model.hasVisibleStyle ? "" : `<a:xfrm${model.rotationUnits === void 0 || model.rotationUnits === 0 ? "" : ` rot="${model.rotationUnits}"`}${model.flipH ? " flipH=\"1\"" : ""}${model.flipV ? " flipV=\"1\"" : ""}><a:off x="${emu(box.x, "x", true, true)}" y="${emu(box.y, "y", true, true)}"/><a:ext cx="${emu(box.width, "width", false)}" cy="${emu(box.height, "height", false)}"/></a:xfrm>`}${resolvedGeometryXml(model.geometry)}${options?.omitFill ? "" : emitFillXml(model.fill, registerResource)}${emitBorderXml(model.border)}${emitEffectsXml(model)}</p:spPr>`,
331
+ ...model.opacity === void 0 ? {} : { opacity: model.opacity },
332
+ warnings: model.warnings,
333
+ hasVisibleStyle: model.hasVisibleStyle,
334
+ geometryName: model.geometryName,
335
+ geometry: model.geometry
336
+ };
337
+ }
338
+ /**
339
+ * Serializes `<p:spPr>` for a master, layout, or bound slide placeholder, emitting only
340
+ * transform, geometry, fill, border, and effect elements declared on that layer.
341
+ */
342
+ function emitPlaceholderVisualSpPr(model, flags, registerResource) {
343
+ let xfrmXml = "";
344
+ if (flags.hasBox || flags.hasRotate || flags.hasFlipH || flags.hasFlipV) {
345
+ const rotAttr = flags.hasRotate ? ` rot="${model.rotationUnits ?? 0}"` : "";
346
+ const flipHAttr = flags.hasFlipH && model.flipH ? " flipH=\"1\"" : "";
347
+ const flipVAttr = flags.hasFlipV && model.flipV ? " flipV=\"1\"" : "";
348
+ if (flags.hasBox) {
349
+ const { box } = model;
350
+ xfrmXml = `<a:xfrm${rotAttr}${flipHAttr}${flipVAttr}><a:off x="${emu(box.x, "x", true, true)}" y="${emu(box.y, "y", true, true)}"/><a:ext cx="${emu(box.width, "width", false)}" cy="${emu(box.height, "height", false)}"/></a:xfrm>`;
351
+ } else xfrmXml = `<a:xfrm${rotAttr}${flipHAttr}${flipVAttr}/>`;
352
+ }
353
+ const geomXml = flags.hasGeometryOrRadius || flags.hasBox && flags.includeDefaultRectWhenHasBox === true ? resolvedGeometryXml(model.geometry) : "";
354
+ const fillXml = flags.hasFill ? emitFillXml(model.fill, registerResource) : "";
355
+ const borderXml = flags.hasBorder ? emitBorderXml(model.border) : "";
356
+ const effectsXml = flags.hasEffects ? emitEffectsXml(model) : "";
357
+ const inner = `${xfrmXml}${geomXml}${fillXml}${borderXml}${effectsXml}`;
358
+ return inner === "" ? "<p:spPr/>" : `<p:spPr>${inner}</p:spPr>`;
359
+ }
360
+ /** Returns the SVG transform string (flip around box center, then rotate around box center). */
361
+ function visualSvgTransform(model) {
362
+ const cx = model.box.x + model.box.width / 2;
363
+ const cy = model.box.y + model.box.height / 2;
364
+ return `translate(${roundSvgNumber(cx)} ${roundSvgNumber(cy)}) rotate(${roundSvgNumber(model.rotate)}) scale(${model.flipH ? -1 : 1} ${model.flipV ? -1 : 1}) translate(${roundSvgNumber(-cx)} ${roundSvgNumber(-cy)})`;
365
+ }
366
+ function normalizeVec(dx, dy) {
367
+ const len = Math.hypot(dx, dy);
368
+ if (len <= 1e-9) return void 0;
369
+ return {
370
+ x: dx / len,
371
+ y: dy / len
372
+ };
373
+ }
374
+ function splitSubpaths(commands) {
375
+ const result = [];
376
+ let current;
377
+ let start = {
378
+ x: 0,
379
+ y: 0
380
+ };
381
+ for (const command of commands) {
382
+ if (command.op === "M") {
383
+ current = [command];
384
+ result.push(current);
385
+ start = {
386
+ x: command.x,
387
+ y: command.y
388
+ };
389
+ continue;
390
+ }
391
+ if (current === void 0) {
392
+ current = [{
393
+ op: "M",
394
+ x: start.x,
395
+ y: start.y
396
+ }];
397
+ result.push(current);
398
+ }
399
+ current.push(command);
400
+ if (command.op === "Z") current = void 0;
401
+ }
402
+ return result;
403
+ }
404
+ function arrowShortenLength(arrow, strokeWidth) {
405
+ const w = Math.max(1, strokeWidth);
406
+ const length = Math.max(6, w * 3.5);
407
+ switch (arrow) {
408
+ case "none": return 0;
409
+ case "triangle": return .85 * length;
410
+ case "stealth": return .65 * length;
411
+ case "arrow": return .5 * w;
412
+ case "diamond":
413
+ case "oval": return 0;
414
+ default: return arrow;
415
+ }
416
+ }
417
+ function arrowHeadSvg(arrow, tip, dir, strokeHex, strokeAlpha, strokeWidth) {
418
+ if (arrow === "none") return "";
419
+ const w = Math.max(1, strokeWidth);
420
+ const length = Math.max(6, w * 3.5);
421
+ const halfWidth = Math.max(3, w * 1.75);
422
+ const deg = roundSvgNumber(Math.atan2(dir.y, dir.x) * 180 / Math.PI);
423
+ const tx = roundSvgNumber(tip.x);
424
+ const ty = roundSvgNumber(tip.y);
425
+ const alpha = roundSvgNumber(strokeAlpha);
426
+ const transform = `translate(${tx} ${ty}) rotate(${deg})`;
427
+ switch (arrow) {
428
+ case "triangle": return `<path d="M 0 0 L ${roundSvgNumber(-length)} ${roundSvgNumber(-halfWidth)} L ${roundSvgNumber(-length)} ${roundSvgNumber(halfWidth)} Z" fill="#${strokeHex}" fill-opacity="${alpha}" stroke="none" transform="${transform}"/>`;
429
+ case "stealth": return `<path d="M 0 0 L ${roundSvgNumber(-length)} ${roundSvgNumber(-halfWidth)} L ${roundSvgNumber(-.65 * length)} 0 L ${roundSvgNumber(-length)} ${roundSvgNumber(halfWidth)} Z" fill="#${strokeHex}" fill-opacity="${alpha}" stroke="none" transform="${transform}"/>`;
430
+ case "arrow": return `<path d="M ${roundSvgNumber(-length)} ${roundSvgNumber(-halfWidth)} L 0 0 L ${roundSvgNumber(-length)} ${roundSvgNumber(halfWidth)}" fill="none" stroke="#${strokeHex}" stroke-opacity="${alpha}" stroke-width="${roundSvgNumber(w)}" stroke-linecap="round" stroke-linejoin="round" transform="${transform}"/>`;
431
+ case "diamond": return `<path d="M ${roundSvgNumber(length * .5)} 0 L 0 ${roundSvgNumber(-halfWidth)} L ${roundSvgNumber(-length * .5)} 0 L 0 ${roundSvgNumber(halfWidth)} Z" fill="#${strokeHex}" fill-opacity="${alpha}" stroke="none" transform="${transform}"/>`;
432
+ case "oval": return `<ellipse cx="0" cy="0" rx="${roundSvgNumber(length * .45)}" ry="${roundSvgNumber(halfWidth * .8)}" fill="#${strokeHex}" fill-opacity="${alpha}" stroke="none" transform="${transform}"/>`;
433
+ default: return arrow;
434
+ }
435
+ }
436
+ function commandsToSvgPath(commands) {
437
+ return commands.map((command) => {
438
+ switch (command.op) {
439
+ case "Z": return "Z";
440
+ case "M":
441
+ case "L": return `${command.op}${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
442
+ case "Q": return `Q${roundSvgNumber(command.x1)} ${roundSvgNumber(command.y1)} ${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
443
+ case "C": return `C${roundSvgNumber(command.x1)} ${roundSvgNumber(command.y1)} ${roundSvgNumber(command.x2)} ${roundSvgNumber(command.y2)} ${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
444
+ default: return command;
445
+ }
446
+ }).join(" ");
447
+ }
448
+ function extractOpenSubpathEnds(subpath) {
449
+ const first = subpath[0];
450
+ const last = subpath.at(-1);
451
+ if (first === void 0 || first.op !== "M" || last === void 0) return;
452
+ if (last.op === "Z" || subpath.length < 2) return;
453
+ const startPoint = {
454
+ x: first.x,
455
+ y: first.y
456
+ };
457
+ let startTangent;
458
+ let firstSegLen = 0;
459
+ for (let i = 1; i < subpath.length; i += 1) {
460
+ const cmd = subpath[i];
461
+ if (cmd.op === "L") {
462
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
463
+ startTangent = normalizeVec(cmd.x - startPoint.x, cmd.y - startPoint.y);
464
+ if (startTangent !== void 0) break;
465
+ } else if (cmd.op === "Q") {
466
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
467
+ startTangent = normalizeVec(cmd.x1 - startPoint.x, cmd.y1 - startPoint.y) ?? normalizeVec(cmd.x - startPoint.x, cmd.y - startPoint.y);
468
+ if (startTangent !== void 0) break;
469
+ } else if (cmd.op === "C") {
470
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
471
+ startTangent = normalizeVec(cmd.x1 - startPoint.x, cmd.y1 - startPoint.y) ?? normalizeVec(cmd.x2 - startPoint.x, cmd.y2 - startPoint.y) ?? normalizeVec(cmd.x - startPoint.x, cmd.y - startPoint.y);
472
+ if (startTangent !== void 0) break;
473
+ }
474
+ }
475
+ if (last.op === "M") return void 0;
476
+ const endPoint = {
477
+ x: last.x,
478
+ y: last.y
479
+ };
480
+ let endTangent;
481
+ let lastSegLen = 0;
482
+ for (let i = subpath.length - 1; i >= 1; i -= 1) {
483
+ const cmd = subpath[i];
484
+ const prevCmd = subpath[i - 1];
485
+ if (prevCmd.op === "Z") continue;
486
+ const prevPoint = {
487
+ x: prevCmd.x,
488
+ y: prevCmd.y
489
+ };
490
+ if (cmd.op === "L") {
491
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
492
+ endTangent = normalizeVec(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
493
+ if (endTangent !== void 0) break;
494
+ } else if (cmd.op === "Q") {
495
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
496
+ endTangent = normalizeVec(endPoint.x - cmd.x1, endPoint.y - cmd.y1) ?? normalizeVec(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
497
+ if (endTangent !== void 0) break;
498
+ } else if (cmd.op === "C") {
499
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
500
+ endTangent = normalizeVec(endPoint.x - cmd.x2, endPoint.y - cmd.y2) ?? normalizeVec(endPoint.x - cmd.x1, endPoint.y - cmd.y1) ?? normalizeVec(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
501
+ if (endTangent !== void 0) break;
502
+ }
503
+ }
504
+ if (startTangent === void 0 || endTangent === void 0) return;
505
+ return {
506
+ startPoint,
507
+ startTangent,
508
+ firstSegLen,
509
+ endPoint,
510
+ endTangent,
511
+ lastSegLen,
512
+ segCount: subpath.length - 1
513
+ };
514
+ }
515
+ function shortenOpenSubpath(subpath, startShorten, endShorten, ends) {
516
+ const canShortenStart = startShorten > 0 && (ends.segCount === 1 ? ends.firstSegLen > (startShorten + endShorten) * 1.5 : ends.firstSegLen > startShorten * 1.5);
517
+ const canShortenEnd = endShorten > 0 && (ends.segCount === 1 ? ends.lastSegLen > (startShorten + endShorten) * 1.5 : ends.lastSegLen > endShorten * 1.5);
518
+ if (!canShortenStart && !canShortenEnd) return subpath;
519
+ const next = [...subpath];
520
+ if (canShortenStart) {
521
+ const first = next[0];
522
+ if (first.op === "M") next[0] = {
523
+ op: "M",
524
+ x: first.x + ends.startTangent.x * startShorten,
525
+ y: first.y + ends.startTangent.y * startShorten
526
+ };
527
+ }
528
+ if (canShortenEnd) {
529
+ const lastIdx = next.length - 1;
530
+ const last = next[lastIdx];
531
+ if (last.op === "L" || last.op === "Q" || last.op === "C") next[lastIdx] = {
532
+ ...last,
533
+ x: last.x - ends.endTangent.x * endShorten,
534
+ y: last.y - ends.endTangent.y * endShorten
535
+ };
536
+ }
537
+ return next;
538
+ }
539
+ function borderAttributes(border) {
540
+ if (border === void 0) return "stroke=\"none\" stroke-width=\"0\"";
541
+ const w = Math.max(1, border.width);
542
+ let dashAttr = "";
543
+ switch (border.style) {
544
+ case "solid":
545
+ dashAttr = "";
546
+ break;
547
+ case "dashed":
548
+ dashAttr = ` stroke-dasharray="${roundSvgNumber(w * 4)} ${roundSvgNumber(w * 3)}"`;
549
+ break;
550
+ case "dotted":
551
+ dashAttr = ` stroke-dasharray="${roundSvgNumber(w)} ${roundSvgNumber(w * 2)}"`;
552
+ break;
553
+ default: return border.style;
554
+ }
555
+ return `stroke="#${border.color.hex}" stroke-opacity="${roundSvgNumber(border.color.alpha ?? 1)}" stroke-width="${roundSvgNumber(border.width)}"${dashAttr}`;
556
+ }
557
+ function subpathFillHex(baseHex, fillMode) {
558
+ switch (fillMode) {
559
+ case "norm": return baseHex;
560
+ case "lighten": return shadeHex(baseHex, .6, .4);
561
+ case "lightenLess": return shadeHex(baseHex, .8, .2);
562
+ case "darken": return shadeHex(baseHex, .6, 0);
563
+ case "darkenLess": return shadeHex(baseHex, .8, 0);
564
+ default: return fillMode;
565
+ }
566
+ }
567
+ function shadeOverlayAttrs(fillMode) {
568
+ switch (fillMode) {
569
+ case "norm": return;
570
+ case "lighten": return "fill=\"#FFFFFF\" fill-opacity=\"0.35\"";
571
+ case "lightenLess": return "fill=\"#FFFFFF\" fill-opacity=\"0.2\"";
572
+ case "darken": return "fill=\"#000000\" fill-opacity=\"0.3\"";
573
+ case "darkenLess": return "fill=\"#000000\" fill-opacity=\"0.15\"";
574
+ default: return fillMode;
575
+ }
576
+ }
577
+ function resolveSubpathFill(fill, fillDefId, fillMode) {
578
+ if (fillMode === "none") return {
579
+ fillAttr: "fill=\"none\"",
580
+ overlayAttr: void 0,
581
+ hasFill: false
582
+ };
583
+ switch (fill.kind) {
584
+ case "none": return {
585
+ fillAttr: "fill=\"none\"",
586
+ overlayAttr: void 0,
587
+ hasFill: false
588
+ };
589
+ case "solid": return {
590
+ fillAttr: solidFillMechanism.paint(fill, { fillMode }).svg,
591
+ overlayAttr: void 0,
592
+ hasFill: true
593
+ };
594
+ case "linear-gradient":
595
+ case "radial-gradient":
596
+ case "image": return {
597
+ fillAttr: `fill="url(#${fillDefId})" fill-opacity="1"`,
598
+ overlayAttr: shadeOverlayAttrs(fillMode),
599
+ hasFill: true
600
+ };
601
+ default: return fill;
602
+ }
603
+ }
604
+ function renderEvaluatedGeometryElements(model, fillDefId, overrideAttrs) {
605
+ const evaluated = evaluateGeometry(model.geometry, model.box);
606
+ const { border } = model;
607
+ const strokeAttr = borderAttributes(border);
608
+ const startArrow = border?.startArrow ?? "none";
609
+ const endArrow = border?.endArrow ?? "none";
610
+ return evaluated.paths.map((pathItem) => {
611
+ if (overrideAttrs !== void 0) {
612
+ if (pathItem.fillMode === "none" && (!pathItem.stroke || border === void 0)) return "";
613
+ return `<path d="${pathItem.d}" ${overrideAttrs}/>`;
614
+ }
615
+ const { fillAttr, overlayAttr, hasFill } = resolveSubpathFill(model.fill, fillDefId, pathItem.fillMode);
616
+ const allowStroke = pathItem.stroke && border !== void 0;
617
+ const subpaths = splitSubpaths(pathItem.commands);
618
+ const hasOpenSubpath = subpaths.some((sp) => sp.at(-1)?.op !== "Z");
619
+ if (!(allowStroke && hasOpenSubpath && (startArrow !== "none" || endArrow !== "none"))) {
620
+ const base = `<path d="${pathItem.d}" ${fillAttr} ${allowStroke ? strokeAttr : "stroke=\"none\" stroke-width=\"0\""}/>`;
621
+ return overlayAttr === void 0 ? base : `${base}<path d="${pathItem.d}" ${overlayAttr} stroke="none" stroke-width="0"/>`;
622
+ }
623
+ const fragments = [];
624
+ if (hasFill) {
625
+ fragments.push(`<path d="${pathItem.d}" ${fillAttr} stroke="none"/>`);
626
+ if (overlayAttr !== void 0) fragments.push(`<path d="${pathItem.d}" ${overlayAttr} stroke="none"/>`);
627
+ }
628
+ const startShorten = arrowShortenLength(startArrow, border.width);
629
+ const endShorten = arrowShortenLength(endArrow, border.width);
630
+ const strokeAlpha = border.color.alpha ?? 1;
631
+ for (const subpath of subpaths) {
632
+ const ends = extractOpenSubpathEnds(subpath);
633
+ if (ends === void 0) {
634
+ fragments.push(`<path d="${commandsToSvgPath(subpath)}" fill="none" ${strokeAttr}/>`);
635
+ continue;
636
+ }
637
+ const shortened = shortenOpenSubpath(subpath, startShorten, endShorten, ends);
638
+ fragments.push(`<path d="${commandsToSvgPath(shortened)}" fill="none" ${strokeAttr}/>`);
639
+ if (startArrow !== "none") fragments.push(arrowHeadSvg(startArrow, ends.startPoint, {
640
+ x: -ends.startTangent.x,
641
+ y: -ends.startTangent.y
642
+ }, border.color.hex, strokeAlpha, border.width));
643
+ if (endArrow !== "none") fragments.push(arrowHeadSvg(endArrow, ends.endPoint, ends.endTangent, border.color.hex, strokeAlpha, border.width));
644
+ }
645
+ return fragments.join("");
646
+ }).join("");
647
+ }
648
+ /**
649
+ * Renders a closed ResolvedVisualModel into deterministic SVG markup with scoped `<defs>`,
650
+ * linear/radial gradients, image `<pattern>`, rounded corners, dashed/dotted strokes,
651
+ * open-path tangent arrows, screen-space `boxShadow`, and feathered `softEdge` masks.
652
+ */
653
+ function paintVisualModel(options) {
654
+ const { model, slideNumber, objectId } = options;
655
+ const { box } = model;
656
+ const prefix = `obj-s${slideNumber}-o${objectId}`;
657
+ const defs = [];
658
+ let fillDefId;
659
+ switch (model.fill.kind) {
660
+ case "none":
661
+ case "solid": break;
662
+ case "linear-gradient":
663
+ case "radial-gradient":
664
+ fillDefId = `${prefix}-fill`;
665
+ defs.push(gradientFillMechanism.paint(model.fill, { id: fillDefId }).svg);
666
+ break;
667
+ case "image":
668
+ fillDefId = `${prefix}-fill`;
669
+ defs.push(imageFillMechanism.paint(model.fill, {
670
+ id: fillDefId,
671
+ box
672
+ }).svg);
673
+ break;
674
+ default: return model.fill;
675
+ }
676
+ let content = renderEvaluatedGeometryElements(model, fillDefId);
677
+ if (model.softEdge !== void 0 && model.softEdge > 0) {
678
+ const r = model.softEdge;
679
+ const minSide = Math.min(box.width, box.height);
680
+ const borderPad = model.border === void 0 ? 0 : model.border.width;
681
+ const pad = Math.ceil(r * 2 + borderPad + 8);
682
+ const maskX = roundSvgNumber(box.x - pad);
683
+ const maskY = roundSvgNumber(box.y - pad);
684
+ const maskW = roundSvgNumber(box.width + pad * 2);
685
+ const maskH = roundSvgNumber(box.height + pad * 2);
686
+ const blurId = `${prefix}-soft-blur`;
687
+ const maskId = `${prefix}-soft-mask`;
688
+ const innerStrokeWidth = r >= minSide / 2 ? 0 : Math.min(r, minSide * .45);
689
+ const maskAttrs = innerStrokeWidth > 0 ? `fill="white" stroke="black" stroke-width="${roundSvgNumber(innerStrokeWidth)}" filter="url(#${blurId})"` : `fill="white" stroke="none" filter="url(#${blurId})"`;
690
+ const maskShapes = renderEvaluatedGeometryElements(model, fillDefId, maskAttrs);
691
+ defs.push(`<filter id="${blurId}" filterUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}"><feGaussianBlur stdDeviation="${roundSvgNumber(r / 2)}"/></filter>`);
692
+ defs.push(`<mask id="${maskId}" maskUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}">${maskShapes}</mask>`);
693
+ content = `<g mask="url(#${maskId})">${content}</g>`;
694
+ }
695
+ let layer = `<g transform="${visualSvgTransform(model)}">${content}</g>`;
696
+ if (model.boxShadow !== void 0) {
697
+ const shadow = model.boxShadow;
698
+ const cx = box.x + box.width / 2;
699
+ const cy = box.y + box.height / 2;
700
+ const halfDiag = Math.hypot(box.width, box.height) / 2;
701
+ const rad = shadow.angle * Math.PI / 180;
702
+ const dx = shadow.distance * Math.cos(rad);
703
+ const dy = shadow.distance * Math.sin(rad);
704
+ const sigma = shadow.blur / 2;
705
+ const borderPad = model.border === void 0 ? 0 : model.border.width;
706
+ const pad = shadow.blur * 3 + Math.abs(dx) + Math.abs(dy) + borderPad + 16;
707
+ const minX = roundSvgNumber(cx - halfDiag - pad);
708
+ const minY = roundSvgNumber(cy - halfDiag - pad);
709
+ const filterSize = roundSvgNumber((halfDiag + pad) * 2);
710
+ const shadowId = `${prefix}-shadow`;
711
+ defs.push(`<filter id="${shadowId}" filterUnits="userSpaceOnUse" x="${minX}" y="${minY}" width="${filterSize}" height="${filterSize}"><feDropShadow dx="${roundSvgNumber(dx)}" dy="${roundSvgNumber(dy)}" stdDeviation="${roundSvgNumber(sigma)}" flood-color="#${shadow.color.hex}" flood-opacity="${roundSvgNumber(shadow.color.alpha ?? 1)}"/></filter>`);
712
+ layer = `<g filter="url(#${shadowId})">${layer}</g>`;
713
+ }
714
+ return { svg: `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${layer}` };
715
+ }
716
+ /** Reads DrawingML `<a:blipFill>` embedded image bytes and validates them against supported decoders. */
717
+ function readBlipFill(blipFillCursor, pkg, location, diagnostics) {
718
+ return readBlipFill$1(blipFillCursor, pkg, location, diagnostics, (bytes) => {
719
+ readImage(bytes);
720
+ });
721
+ }
722
+ /**
723
+ * Reads PresentationML `<p:spPr>` geometry, fills, borders, and effects (without requiring `<a:xfrm>`).
724
+ * Used both by full-shape import and placeholder import where transform overrides may be absent.
725
+ */
726
+ function readSpPrAppearance(spPrCursor, pkg, fallbackUnits, location, diagnostics) {
727
+ let geometry;
728
+ let backgroundColor;
729
+ let backgroundImage;
730
+ let opacity;
731
+ let border = {};
732
+ let effects = {};
733
+ for (const child of spPrCursor.remainingElementChildren()) {
734
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
735
+ diagnostics.push({
736
+ code: "unconsumed-xml",
737
+ category: "unsupported",
738
+ disposition: "omitted",
739
+ kind: "element",
740
+ location: {
741
+ ...location,
742
+ xpath: child.xpath
743
+ },
744
+ namespaceUri: child.namespaceUri,
745
+ localName: child.localName
746
+ });
747
+ continue;
748
+ }
749
+ switch (child.localName) {
750
+ case "prstGeom":
751
+ geometry = readPresetGeometryXml(child, location, diagnostics);
752
+ break;
753
+ case "custGeom":
754
+ geometry = readCustomGeometryXml(child, fallbackUnits, location, diagnostics);
755
+ break;
756
+ case "noFill": break;
757
+ case "solidFill":
758
+ backgroundColor = readDrawingColor(child, location, diagnostics);
759
+ break;
760
+ case "gradFill":
761
+ backgroundImage = readGradientFill(child, location, diagnostics);
762
+ break;
763
+ case "blipFill": {
764
+ const blip = readBlipFill(child, pkg, location, diagnostics);
765
+ if (blip !== void 0) {
766
+ backgroundImage = { image: blip.image };
767
+ if (blip.opacity !== void 0) opacity = blip.opacity;
768
+ }
769
+ break;
770
+ }
771
+ case "ln":
772
+ border = readLineBorder(child, location, diagnostics);
773
+ break;
774
+ case "effectLst":
775
+ effects = readEffectList(child, location, diagnostics);
776
+ break;
777
+ case "extLst":
778
+ child.ignoreEmptyChild(A_NS, "ext");
779
+ break;
780
+ default: diagnostics.push({
781
+ code: "unsupported-mechanism",
782
+ category: "unsupported",
783
+ disposition: "omitted",
784
+ location: {
785
+ ...location,
786
+ xpath: child.xpath
787
+ },
788
+ namespaceUri: child.namespaceUri,
789
+ localName: child.localName,
790
+ mechanismHint: child.localName
791
+ });
792
+ }
793
+ }
794
+ const style = {
795
+ ...backgroundColor === void 0 ? {} : { backgroundColor },
796
+ ...backgroundImage === void 0 ? {} : { backgroundImage },
797
+ ...border.borderColor === void 0 ? {} : { borderColor: border.borderColor },
798
+ ...border.borderWidth === void 0 ? {} : { borderWidth: border.borderWidth },
799
+ ...border.borderStyle === void 0 ? {} : { borderStyle: border.borderStyle },
800
+ ...border.startArrow === void 0 ? {} : { startArrow: border.startArrow },
801
+ ...border.endArrow === void 0 ? {} : { endArrow: border.endArrow },
802
+ ...opacity === void 0 ? {} : { opacity },
803
+ ...effects.boxShadow === void 0 ? {} : { boxShadow: effects.boxShadow },
804
+ ...effects.softEdge === void 0 ? {} : { softEdge: effects.softEdge }
805
+ };
806
+ return {
807
+ ...geometry === void 0 ? {} : { geometry },
808
+ style
809
+ };
810
+ }
811
+ /**
812
+ * Reads PresentationML `<p:spPr>` geometry, transform, fills, borders, and effects.
813
+ * Isolates unsupported visual elements/fills by emitting a localized ImportDiagnostic
814
+ * and omitting only the unsupported visual attribute while keeping geometry and text intact.
815
+ */
816
+ function readSpPrVisuals(spPrCursor, pkg, location, diagnostics) {
817
+ let transform;
818
+ const xfrmCursor = spPrCursor.child(A_NS, "xfrm");
819
+ if (xfrmCursor !== void 0) transform = readTransformXml(xfrmCursor, location, diagnostics);
820
+ if (transform === void 0) {
821
+ if (xfrmCursor === void 0) diagnostics.push({
822
+ code: "corrupt-part",
823
+ category: "corrupt-input",
824
+ disposition: "omitted",
825
+ location: {
826
+ ...location,
827
+ xpath: spPrCursor.xpath
828
+ }
829
+ });
830
+ return;
831
+ }
832
+ const appearance = readSpPrAppearance(spPrCursor, pkg, {
833
+ w: transform.cxEmu,
834
+ h: transform.cyEmu
835
+ }, location, diagnostics);
836
+ const style = {
837
+ ...appearance.style,
838
+ ...transform.rotate === void 0 ? {} : { rotate: transform.rotate }
839
+ };
840
+ return {
841
+ transform,
842
+ ...appearance.geometry === void 0 ? {} : { geometry: appearance.geometry },
843
+ style
844
+ };
845
+ }
846
+ function readFillSubElement(context) {
847
+ const diagnostics = [];
848
+ const spPrCursor = context.cursor.child(P_NS, "spPr");
849
+ if (spPrCursor === void 0) return { diagnostics };
850
+ readSpPrVisuals(spPrCursor, context.package, {
851
+ part: context.part,
852
+ slideIndex: context.slideIndex
853
+ }, diagnostics);
854
+ return { diagnostics };
855
+ }
856
+ /** Native canvas mechanism for DrawingML `<a:solidFill>`. */
857
+ const solidFillMechanism = defineCanvasMechanism({
858
+ key: "solid-fill",
859
+ role: "canvas",
860
+ emit(fill, _context) {
861
+ return { xml: `<a:solidFill>${resolvedColorXml(fill.color)}</a:solidFill>` };
862
+ },
863
+ paint(fill, context) {
864
+ return { svg: `fill="#${subpathFillHex(fill.color.hex, context.fillMode)}" fill-opacity="${roundSvgNumber(fill.color.alpha ?? 1)}"` };
865
+ },
866
+ import: {
867
+ target: "shape-tree",
868
+ localName: "sp",
869
+ matches: () => false,
870
+ read: readFillSubElement
871
+ }
872
+ });
873
+ /** Native canvas mechanism for DrawingML `<a:gradFill>` (linear and radial gradients). */
874
+ const gradientFillMechanism = defineCanvasMechanism({
875
+ key: "gradient-fill",
876
+ role: "canvas",
877
+ emit(fill, _context) {
878
+ return { xml: gradientFillXml(fill) };
879
+ },
880
+ paint(fill, context) {
881
+ return { svg: gradientDefSvg(context.id, fill) };
882
+ },
883
+ import: {
884
+ target: "shape-tree",
885
+ localName: "sp",
886
+ matches: () => false,
887
+ read: readFillSubElement
888
+ }
889
+ });
890
+ /** Native canvas mechanism for DrawingML `<a:blipFill>` shape image fills. */
891
+ const imageFillMechanism = defineCanvasMechanism({
892
+ key: "image-fill",
893
+ role: "canvas",
894
+ emit(fill, registerResource) {
895
+ if (registerResource === void 0) invalid("image-resource-failure", "Cannot emit image background fill without resource registrar");
896
+ const relationshipId = registerResource({
897
+ bytes: fill.image.bytes,
898
+ extension: fill.image.extension,
899
+ contentType: fill.image.contentType,
900
+ relationshipType: imageRelationship
901
+ });
902
+ const alpha = fill.opacity === void 0 ? "" : `<a:alphaModFix amt="${Math.round(fill.opacity * 1e5)}"/>`;
903
+ return { xml: `<a:blipFill rotWithShape="1"><a:blip r:embed="${xmlEscape(relationshipId)}">${alpha}</a:blip><a:stretch><a:fillRect/></a:stretch></a:blipFill>` };
904
+ },
905
+ paint(fill, context) {
906
+ const pngBytes = decodeImageToPngBytes(fill.image);
907
+ const base64 = Buffer.from(pngBytes).toString("base64");
908
+ const imgOpacity = roundSvgNumber(fill.opacity ?? 1);
909
+ return { svg: `<pattern id="${context.id}" patternUnits="userSpaceOnUse" x="${roundSvgNumber(context.box.x)}" y="${roundSvgNumber(context.box.y)}" width="${roundSvgNumber(context.box.width)}" height="${roundSvgNumber(context.box.height)}"><image x="0" y="0" width="${roundSvgNumber(context.box.width)}" height="${roundSvgNumber(context.box.height)}" preserveAspectRatio="none" opacity="${imgOpacity}" href="data:image/png;base64,${base64}"/></pattern>` };
910
+ },
911
+ import: {
912
+ target: "shape-tree",
913
+ localName: "sp",
914
+ matches: () => false,
915
+ read: readFillSubElement
916
+ }
917
+ });
918
+ export { arrowTypeSchema, emitPlaceholderVisualSpPr, emitVisualModel, gradientDefSvg, gradientFillMechanism, gradientFillXml, hasVisibleBoxStyle, imageFillMechanism, lineEndStyleSchema, linearGradient, paintVisualModel, radialGradient, readBlipFill, readDrawingColor, readEffectList, readGradientFill, readLineBorder, readSpPrAppearance, readSpPrVisuals, readTransformXml, resolveGradientSpec, resolveShadow, resolveVisualModel, solidFillMechanism, textShadowXml, visualSvgTransform };