@officedk/pptxdk 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +21 -0
  2. package/dist/build-zrZuX4fK.d.ts +3 -0
  3. package/dist/build.d.ts +35 -0
  4. package/dist/build.js +128 -0
  5. package/dist/capabilities/dist/all.js +34 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +84 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +32 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +142 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2403 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1119 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +192 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +592 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +60 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +168 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +119 -0
  38. package/dist/capabilities/dist/font/font-engine.js +834 -0
  39. package/dist/capabilities/dist/font/font-import.js +766 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +72 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +74 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +41 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +649 -0
  46. package/dist/capabilities/dist/group/group-xml.js +8 -0
  47. package/dist/capabilities/dist/group/group.js +260 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +164 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +244 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +984 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +147 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +552 -0
  57. package/dist/capabilities/dist/line/line-codegen.js +89 -0
  58. package/dist/capabilities/dist/line/line-declaration.js +72 -0
  59. package/dist/capabilities/dist/line/line-elements.js +12 -0
  60. package/dist/capabilities/dist/line/line-import.js +504 -0
  61. package/dist/capabilities/dist/line/line-xml.js +9 -0
  62. package/dist/capabilities/dist/line/line.js +331 -0
  63. package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
  64. package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
  65. package/dist/capabilities/dist/masters/masters.js +250 -0
  66. package/dist/capabilities/dist/motion/motion-api.js +757 -0
  67. package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
  68. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  69. package/dist/capabilities/dist/motion/motion-import.js +1568 -0
  70. package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
  71. package/dist/capabilities/dist/motion/motion-query.js +423 -0
  72. package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
  73. package/dist/capabilities/dist/motion/motion.js +1617 -0
  74. package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
  75. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  76. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  77. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  78. package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
  79. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  80. package/dist/capabilities/dist/notes/notes.js +194 -0
  81. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
  82. package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
  83. package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
  84. package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
  85. package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
  86. package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
  87. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  88. package/dist/capabilities/dist/shape/shape-import.js +628 -0
  89. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  90. package/dist/capabilities/dist/shape/shape.js +320 -0
  91. package/dist/capabilities/dist/shared/geometry.js +1681 -0
  92. package/dist/capabilities/dist/shared/identity.js +205 -0
  93. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  94. package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
  95. package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
  96. package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
  97. package/dist/capabilities/dist/shared/text-schemas.js +241 -0
  98. package/dist/capabilities/dist/shared/text-service.js +2252 -0
  99. package/dist/capabilities/dist/shared/visual.js +1197 -0
  100. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  101. package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
  102. package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
  103. package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
  104. package/dist/capabilities/dist/table/table-codegen.js +125 -0
  105. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  106. package/dist/capabilities/dist/table/table-elements.js +27 -0
  107. package/dist/capabilities/dist/table/table-import.js +606 -0
  108. package/dist/capabilities/dist/table/table-schemas.js +334 -0
  109. package/dist/capabilities/dist/table/table-xml.js +30 -0
  110. package/dist/capabilities/dist/table/table.js +739 -0
  111. package/dist/capabilities/dist/text/text-codegen.js +198 -0
  112. package/dist/capabilities/dist/text/text-declaration.js +27 -0
  113. package/dist/capabilities/dist/text/text-elements.js +54 -0
  114. package/dist/capabilities/dist/text/text-import.js +1224 -0
  115. package/dist/capabilities/dist/text/text-xml.js +9 -0
  116. package/dist/capabilities/dist/text/text.js +320 -0
  117. package/dist/capabilities/dist/transition/transition-api.js +136 -0
  118. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  119. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  120. package/dist/capabilities/dist/transition/transition.js +260 -0
  121. package/dist/capability-BbKW9w4O.d.ts +2131 -0
  122. package/dist/cli.js +20 -0
  123. package/dist/codegen/dist/assets.js +79 -0
  124. package/dist/codegen/dist/codegen.js +691 -0
  125. package/dist/codegen/dist/identifiers.js +203 -0
  126. package/dist/codegen/dist/index.js +3 -0
  127. package/dist/codegen/dist/printer.js +143 -0
  128. package/dist/codegen/dist/types.js +77 -0
  129. package/dist/core/dist/author-ids.js +51 -0
  130. package/dist/core/dist/author-schemas.js +330 -0
  131. package/dist/core/dist/block-flex-layout.js +801 -0
  132. package/dist/core/dist/build.js +4 -0
  133. package/dist/core/dist/capability.js +15 -0
  134. package/dist/core/dist/declaration.js +16 -0
  135. package/dist/core/dist/diagnostics.js +353 -0
  136. package/dist/core/dist/document-internals.js +26 -0
  137. package/dist/core/dist/document.js +417 -0
  138. package/dist/core/dist/font-seal.js +204 -0
  139. package/dist/core/dist/geometry-schemas.js +256 -0
  140. package/dist/core/dist/grid-layout.js +449 -0
  141. package/dist/core/dist/host.js +40 -0
  142. package/dist/core/dist/index.js +15 -0
  143. package/dist/core/dist/input-values.js +61 -0
  144. package/dist/core/dist/layout-protocol.js +61 -0
  145. package/dist/core/dist/layout-schemas.js +201 -0
  146. package/dist/core/dist/layout.js +340 -0
  147. package/dist/core/dist/masters.js +194 -0
  148. package/dist/core/dist/morph.js +30 -0
  149. package/dist/core/dist/placeholders.js +275 -0
  150. package/dist/core/dist/query.js +190 -0
  151. package/dist/core/dist/resolution.js +12 -0
  152. package/dist/core/dist/resolve.js +2246 -0
  153. package/dist/core/dist/stage-options.js +300 -0
  154. package/dist/core/dist/theme.js +1023 -0
  155. package/dist/core/dist/transform-geometry.js +72 -0
  156. package/dist/document-41spD7bq.d.ts +1350 -0
  157. package/dist/emit/dist/emit.js +957 -0
  158. package/dist/emit/dist/index.js +5 -0
  159. package/dist/emit/dist/ooxml.js +661 -0
  160. package/dist/emit/dist/shape-tree.js +12 -0
  161. package/dist/import/dist/alternate-content.js +54 -0
  162. package/dist/import/dist/diagnostics.js +157 -0
  163. package/dist/import/dist/fonts.js +309 -0
  164. package/dist/import/dist/import.js +513 -0
  165. package/dist/import/dist/index.js +16 -0
  166. package/dist/import/dist/masters.js +1293 -0
  167. package/dist/import/dist/mechanism.js +10 -0
  168. package/dist/import/dist/namespaces.js +61 -0
  169. package/dist/import/dist/notes-masters.js +300 -0
  170. package/dist/import/dist/opc.js +233 -0
  171. package/dist/import/dist/resources.js +166 -0
  172. package/dist/import/dist/sections.js +139 -0
  173. package/dist/import/dist/themes.js +777 -0
  174. package/dist/import/dist/visual.js +821 -0
  175. package/dist/import/dist/xml-fragments.js +277 -0
  176. package/dist/import/dist/xml-reader.js +267 -0
  177. package/dist/index-1ag7U9Jt.d.ts +63 -0
  178. package/dist/index-BEwhk7c8.d.ts +72 -0
  179. package/dist/index-cK2KtukZ.d.ts +161 -0
  180. package/dist/index-v77CTJev.d.ts +55 -0
  181. package/dist/index.d.ts +8 -0
  182. package/dist/index.js +82 -0
  183. package/dist/node.d.ts +53 -0
  184. package/dist/node.js +225 -0
  185. package/dist/pptxdk/src/cli-commands.js +907 -0
  186. package/dist/pptxdk/src/compose.js +53 -0
  187. package/dist/pptxdk/src/slide.js +9 -0
  188. package/dist/preview/dist/index.js +342 -0
  189. package/dist/preview/dist/options.js +40 -0
  190. package/dist/preview/dist/svg-guard.js +1089 -0
  191. package/dist/preview.d.ts +12 -0
  192. package/dist/preview.js +29 -0
  193. package/dist/react/dist/append.js +66 -0
  194. package/dist/react/dist/document-adapter.js +404 -0
  195. package/dist/react/dist/elements.js +82 -0
  196. package/dist/react/dist/from-vanilla.js +57 -0
  197. package/dist/react/dist/index.js +89 -0
  198. package/dist/react/dist/mount.js +34 -0
  199. package/dist/react/dist/reconciler.js +290 -0
  200. package/dist/react.d.ts +235 -0
  201. package/dist/react.js +31 -0
  202. package/dist/transition-6n8GZxSg.d.ts +9 -0
  203. package/dist/vanilla.d.ts +4 -0
  204. package/dist/vanilla.js +15 -0
  205. package/package.json +79 -3
  206. package/README.md +0 -3
@@ -0,0 +1,1197 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { borderObjectShape, borderValueSchema, imageBackgroundSchema, linearGradientSchema, radialGradientSchema, shadowSchema, visualStyleShape } 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 lineEndStyleObjectSchema = z.strictObject({
35
+ startArrow: arrowTypeSchema.optional(),
36
+ endArrow: arrowTypeSchema.optional()
37
+ });
38
+ lineEndStyleObjectSchema.readonly();
39
+ const rawLineStrokeObjectSchema = z.strictObject({
40
+ ...borderObjectShape,
41
+ startArrow: arrowTypeSchema.optional(),
42
+ endArrow: arrowTypeSchema.optional()
43
+ }).readonly();
44
+ const lineStrokeValueSchema = z.union([z.literal("none"), rawLineStrokeObjectSchema]);
45
+ Object.keys(lineEndStyleObjectSchema.shape);
46
+ Object.keys(visualStyleShape);
47
+ function invalid(code, message) {
48
+ throw new CapabilityError(code, message);
49
+ }
50
+ function isRecord(value) {
51
+ return typeof value === "object" && value !== null && !Array.isArray(value);
52
+ }
53
+ function finite(value, label) {
54
+ if (typeof value !== "number" || !Number.isFinite(value)) invalid("invalid-visual-style", `${label} must be a finite number`);
55
+ return value;
56
+ }
57
+ function emu(value, label, allowZero = true, signed = false) {
58
+ const converted = pxToEmu(value);
59
+ if (!allowZero && !signed) {
60
+ if (!Number.isFinite(value) || value === 0 || converted === 0) invalid("invalid-visual-style", `Computed ${label} is 0px; ${label} must be greater than 0px`);
61
+ if (value < 0 || converted < 1) invalid("invalid-visual-style", `Computed ${label} is ${value}px; ${label} must be greater than 0px`);
62
+ }
63
+ 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`);
64
+ return converted;
65
+ }
66
+ /** Validates that a visible object box has valid DrawingML EMU extents during resolve. */
67
+ function assertVisualBoxExtent(box, options) {
68
+ emu(box.x, "x", true, true);
69
+ emu(box.y, "y", true, true);
70
+ if (options?.allowSingleZeroExtent === true) {
71
+ const cx = emu(box.width, "width", true);
72
+ const cy = emu(box.height, "height", true);
73
+ if (cx === 0 && cy === 0) invalid("invalid-visual-style", "Computed width and height are both 0px; at least one axis must be greater than 0px");
74
+ return;
75
+ }
76
+ emu(box.width, "width", false);
77
+ emu(box.height, "height", false);
78
+ }
79
+ function lineWidthEmu(value) {
80
+ const converted = pxToEmu(value);
81
+ 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");
82
+ return converted;
83
+ }
84
+ function withOpacity(color, opacity) {
85
+ return opacity === void 0 ? color : {
86
+ ...color,
87
+ alpha: (color.alpha ?? 1) * opacity
88
+ };
89
+ }
90
+ function roundSvgNumber(value) {
91
+ const rounded = Math.round(value * 1e6) / 1e6;
92
+ return Object.is(rounded, -0) ? "0" : String(rounded);
93
+ }
94
+ function resolveShadow(theme, value, label) {
95
+ if (!isRecord(value)) invalid("invalid-shadow", `${label} must be a shadow object`);
96
+ const parsed = shadowSchema.safeParse(value);
97
+ if (!parsed.success) {
98
+ const issue = parsed.error.issues[0];
99
+ if (issue?.code === "unrecognized_keys" && issue.keys[0] !== void 0) invalid("invalid-shadow", `${label} contains unsupported parameter ${issue.keys[0]}`);
100
+ const key = String(issue?.path[0] ?? "value");
101
+ if (key === "blur" || key === "distance") {
102
+ if (typeof value[key] !== "number" || !Number.isFinite(value[key])) finite(value[key], `${label}.${key}`);
103
+ invalid("invalid-shadow", `${label}.blur and distance must be non-negative lengths`);
104
+ }
105
+ if (key === "angle") finite(value[key], `${label}.angle`);
106
+ if (key === "color") invalid("invalid-color", issue?.message ?? `${label}.color is invalid`);
107
+ invalid("invalid-shadow", issue?.message ?? `${label} is invalid`);
108
+ }
109
+ const blur = parsed.data.blur ?? 4;
110
+ const distance = parsed.data.distance ?? 0;
111
+ const angle = parsed.data.angle ?? 90;
112
+ emu(blur, `${label}.blur`);
113
+ emu(distance, `${label}.distance`);
114
+ const colorValue = parsed.data.color ?? {
115
+ color: "#000000",
116
+ alpha: .35
117
+ };
118
+ return {
119
+ color: theme.resolveColor(colorValue),
120
+ blur,
121
+ distance,
122
+ angle
123
+ };
124
+ }
125
+ function textShadowXml(theme, value) {
126
+ if (value === void 0 || value === "none") return "";
127
+ const shadow = resolveShadow(theme, value, "textShadow");
128
+ const direction = Math.round((shadow.angle % 360 + 360) % 360 * 6e4);
129
+ 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>`;
130
+ }
131
+ const gradientSchema = z.union([linearGradientSchema, radialGradientSchema]).refine((value) => value.stops.length >= 2);
132
+ /** Resolves and validates a linear or radial gradient declaration against a ThemeContext. */
133
+ function resolveGradientSpec(theme, image, opacity) {
134
+ const parsed = gradientSchema.safeParse(image);
135
+ if (!parsed.success) {
136
+ const issue = parsed.error.issues[0];
137
+ if (issue?.path[0] === "angle" && isRecord(image)) finite(image["angle"], "backgroundImage.angle");
138
+ if (issue?.path[0] === "stops" && isRecord(image) && Array.isArray(image["stops"])) {
139
+ const idx = typeof issue.path[1] === "number" ? issue.path[1] : void 0;
140
+ if (idx !== void 0 && issue.path[2] === "position") {
141
+ const stop = image["stops"][idx];
142
+ if (isRecord(stop)) finite(stop["position"], `backgroundImage.stops[${idx}].position`);
143
+ }
144
+ }
145
+ if (parsed.error.issues.some((entry) => entry.path[0] === "stops" && entry.path[2] === "color" || entry.code === "invalid_union" && entry.errors.some((branch) => branch.some((sub) => sub.path[0] === "stops" && sub.path[2] === "color")))) invalid("invalid-color", "Gradient stop color is invalid");
146
+ invalid("invalid-gradient", "backgroundImage must be a linear or radial gradient with at least two color stops");
147
+ }
148
+ const stops = parsed.data.stops.map((stop, index) => {
149
+ if (stop.position < 0 || stop.position > 1) invalid("invalid-gradient", `position for gradient stop ${index + 1} must be between 0 and 1`);
150
+ const color = withOpacity(theme.resolveColor(stop.color), opacity);
151
+ return {
152
+ position: stop.position,
153
+ color
154
+ };
155
+ });
156
+ if (parsed.data.type === "radial-gradient") return {
157
+ kind: "radial-gradient",
158
+ stops
159
+ };
160
+ return {
161
+ kind: "linear-gradient",
162
+ angle: parsed.data.angle,
163
+ stops
164
+ };
165
+ }
166
+ /** Emits DrawingML `<a:gradFill>` from a closed resolved gradient specification. */
167
+ function gradientFillXml(gradient) {
168
+ const stops = gradient.stops.map((stop) => `<a:gs pos="${Math.round(stop.position * 1e5)}">${resolvedColorXml(stop.color)}</a:gs>`).join("");
169
+ switch (gradient.kind) {
170
+ 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>`;
171
+ 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>`;
172
+ default: return gradient;
173
+ }
174
+ }
175
+ function gradientStopsSvg(stops) {
176
+ 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("");
177
+ }
178
+ function isFinitePositiveBox(box) {
179
+ return Number.isFinite(box.x) && Number.isFinite(box.y) && Number.isFinite(box.width) && Number.isFinite(box.height) && box.width > 1e-6 && box.height > 1e-6;
180
+ }
181
+ function isFiniteSingleZeroBox(box) {
182
+ return Number.isFinite(box.x) && Number.isFinite(box.y) && Number.isFinite(box.width) && Number.isFinite(box.height) && box.width >= 0 && box.height >= 0 && (box.width > 1e-6 || box.height > 1e-6);
183
+ }
184
+ /** Generates deterministic SVG `<linearGradient>` or `<radialGradient>` definition markup. */
185
+ function gradientDefSvg(id, gradient) {
186
+ const stops = gradientStopsSvg(gradient.stops);
187
+ switch (gradient.kind) {
188
+ case "linear-gradient": {
189
+ const rad = (Number.isFinite(gradient.angle) ? gradient.angle : 0) * Math.PI / 180;
190
+ const dx = Math.sin(rad);
191
+ const dy = -Math.cos(rad);
192
+ const halfSpan = (Math.abs(dx) + Math.abs(dy)) / 2;
193
+ const x1Val = .5 - dx * halfSpan;
194
+ const y1Val = .5 - dy * halfSpan;
195
+ const x2Val = .5 + dx * halfSpan;
196
+ const y2Val = .5 + dy * halfSpan;
197
+ const validVec = Number.isFinite(x1Val) && Number.isFinite(y1Val) && Number.isFinite(x2Val) && Number.isFinite(y2Val) && Math.hypot(x2Val - x1Val, y2Val - y1Val) > 1e-6;
198
+ return `<linearGradient id="${id}" gradientUnits="objectBoundingBox" x1="${validVec ? roundSvgNumber(x1Val) : "0"}" y1="${validVec ? roundSvgNumber(y1Val) : "0"}" x2="${validVec ? roundSvgNumber(x2Val) : "1"}" y2="${validVec ? roundSvgNumber(y2Val) : "0"}">${stops}</linearGradient>`;
199
+ }
200
+ case "radial-gradient": return `<radialGradient id="${id}" gradientUnits="objectBoundingBox" cx="0.5" cy="0.5" r="0.707107">${stops}</radialGradient>`;
201
+ default: return gradient;
202
+ }
203
+ }
204
+ function rotationUnits(style) {
205
+ if (style["rotate"] === void 0) return {
206
+ degrees: 0,
207
+ units: void 0
208
+ };
209
+ const degrees = finite(style["rotate"], "rotate");
210
+ const units = Math.round((degrees % 360 + 360) % 360 * 6e4);
211
+ if (!Number.isSafeInteger(units) || units < 0 || units > 216e5) invalid("invalid-visual-style", "rotate exceeds writable DrawingML range after conversion");
212
+ return {
213
+ degrees,
214
+ units
215
+ };
216
+ }
217
+ function resolveImageFillSource(source) {
218
+ if (isRecord(source) && typeof source["externalUrl"] === "string") return {
219
+ kind: "external",
220
+ externalUrl: source["externalUrl"]
221
+ };
222
+ if (source instanceof URL && (source.protocol === "http:" || source.protocol === "https:")) return {
223
+ kind: "external",
224
+ externalUrl: source.toString()
225
+ };
226
+ if (typeof source === "string" && (source.startsWith("http://") || source.startsWith("https://"))) return {
227
+ kind: "external",
228
+ externalUrl: source
229
+ };
230
+ return {
231
+ kind: "embedded",
232
+ ...readImage(source)
233
+ };
234
+ }
235
+ function resolvePositionCoordinate(value) {
236
+ if (value === void 0) return .5;
237
+ if (typeof value === "number") return Math.max(0, Math.min(1, value));
238
+ const parsed = Number.parseFloat(value.slice(0, -1));
239
+ return Number.isFinite(parsed) ? Math.max(0, Math.min(1, parsed / 100)) : .5;
240
+ }
241
+ function resolveImageBackgroundPosition(position) {
242
+ if (position === void 0) return {
243
+ x: .5,
244
+ y: .5
245
+ };
246
+ if (typeof position === "string") switch (position) {
247
+ case "center": return {
248
+ x: .5,
249
+ y: .5
250
+ };
251
+ case "top": return {
252
+ x: .5,
253
+ y: 0
254
+ };
255
+ case "bottom": return {
256
+ x: .5,
257
+ y: 1
258
+ };
259
+ case "left": return {
260
+ x: 0,
261
+ y: .5
262
+ };
263
+ case "right": return {
264
+ x: 1,
265
+ y: .5
266
+ };
267
+ case "top left": return {
268
+ x: 0,
269
+ y: 0
270
+ };
271
+ case "top right": return {
272
+ x: 1,
273
+ y: 0
274
+ };
275
+ case "bottom left": return {
276
+ x: 0,
277
+ y: 1
278
+ };
279
+ case "bottom right": return {
280
+ x: 1,
281
+ y: 1
282
+ };
283
+ default: return position;
284
+ }
285
+ return {
286
+ x: resolvePositionCoordinate(position.x),
287
+ y: resolvePositionCoordinate(position.y)
288
+ };
289
+ }
290
+ /** Validates and resolves `{ image, fit?, position?, opacity? }` background declarations. */
291
+ function resolveImageBackgroundSpec(spec, opacity) {
292
+ const parsed = imageBackgroundSchema.safeParse(spec);
293
+ if (!parsed.success) {
294
+ const issue = parsed.error.issues[0];
295
+ if (issue?.code === "unrecognized_keys" && issue.keys[0] !== void 0) invalid("invalid-visual-style", `background image contains unsupported parameter ${issue.keys[0]}`);
296
+ invalid("invalid-visual-style", issue?.message ?? "Invalid image background declaration");
297
+ }
298
+ const source = resolveImageFillSource(parsed.data.image);
299
+ const combinedOpacity = (parsed.data.opacity ?? 1) * (opacity ?? 1);
300
+ return {
301
+ kind: "image",
302
+ source,
303
+ fit: parsed.data.fit ?? "fill",
304
+ position: resolveImageBackgroundPosition(parsed.data.position),
305
+ ...combinedOpacity < 1 ? { opacity: combinedOpacity } : {}
306
+ };
307
+ }
308
+ /** Resolves a unified `BackgroundValue` (`"none"`, color, gradient, or `{ image, fit?, position?, opacity? }`). */
309
+ function resolveBackgroundValue(theme, value, opacity) {
310
+ if (value === void 0 || value === "none") return { kind: "none" };
311
+ if (isRecord(value) && Object.hasOwn(value, "image")) return resolveImageBackgroundSpec(value, opacity);
312
+ if (isRecord(value) && (value["type"] === "linear-gradient" || value["type"] === "radial-gradient")) return resolveGradientSpec(theme, value, opacity);
313
+ return {
314
+ kind: "solid",
315
+ color: withOpacity(theme.resolveColor(value), opacity)
316
+ };
317
+ }
318
+ function resolveVisualFill(theme, style, opacity) {
319
+ try {
320
+ return resolveBackgroundValue(theme, style["background"], opacity);
321
+ } catch (error) {
322
+ if (error instanceof CapabilityError && error.details?.["field"] === void 0 && Object.hasOwn(style, "background") && style["background"] !== void 0) throw new CapabilityError(error.code, error.message, error.path, {
323
+ ...error.details,
324
+ field: "style.background"
325
+ });
326
+ throw error;
327
+ }
328
+ }
329
+ function resolveStrokeValue(theme, rawStroke, opacity, schema, label) {
330
+ if (rawStroke === void 0 || rawStroke === "none") return;
331
+ const parsed = schema.safeParse(rawStroke);
332
+ if (!parsed.success || parsed.data === "none") {
333
+ const issue = parsed.success ? void 0 : parsed.error.issues[0];
334
+ if (issue?.code === "unrecognized_keys" && issue.keys[0] !== void 0) invalid("invalid-visual-style", `${label} contains unsupported property ${issue.keys[0]}`);
335
+ if (issue?.path[0] === "color" || issue?.code === "invalid_union" && issue.errors.some((branch) => branch.some((sub) => sub.path[0] === "color"))) invalid("invalid-color", issue?.message ?? `Invalid ${label} color`);
336
+ invalid("invalid-visual-style", issue?.message ?? `Invalid ${label} declaration`);
337
+ }
338
+ const width = parsed.data.width ?? 1;
339
+ if (width === 0) return;
340
+ lineWidthEmu(width);
341
+ const startArrow = parsed.data.startArrow;
342
+ const endArrow = parsed.data.endArrow;
343
+ return {
344
+ color: withOpacity(theme.resolveColor(parsed.data.color), opacity),
345
+ width,
346
+ style: parsed.data.style ?? "solid",
347
+ ...startArrow === void 0 ? {} : { startArrow },
348
+ ...endArrow === void 0 ? {} : { endArrow }
349
+ };
350
+ }
351
+ /** Validates and resolves top-level `Line.stroke` into a closed `ResolvedBorder` (defaulting to solid `tx1` 1px when omitted). */
352
+ function resolveLineStroke(theme, rawStroke, opacity) {
353
+ return resolveStrokeValue(theme, rawStroke === void 0 ? {
354
+ color: "tx1",
355
+ width: 1,
356
+ style: "solid"
357
+ } : rawStroke, opacity, lineStrokeValueSchema, "stroke");
358
+ }
359
+ function resolveVisualBorder(theme, style, opacity) {
360
+ if (!Object.hasOwn(style, "border") || style["border"] === void 0) return;
361
+ return resolveStrokeValue(theme, style["border"], opacity, borderValueSchema, "border");
362
+ }
363
+ /** Determines whether a Box style specifies visible fill, border, or shadow. */
364
+ function hasVisibleBoxStyle(style) {
365
+ if (style === void 0 || typeof style !== "object" || style === null) return false;
366
+ const hasNewBorder = style["border"] !== void 0 && style["border"] !== "none" && !(typeof style["border"] === "object" && style["border"] !== null && style["border"]["width"] === 0);
367
+ return style["background"] !== void 0 && style["background"] !== "none" || hasNewBorder || style["boxShadow"] !== void 0 && style["boxShadow"] !== "none";
368
+ }
369
+ /**
370
+ * Validates and resolves visual styles, geometry, fill, border, shadow, softEdge, and transforms
371
+ * into a closed strongly-typed model consumed exhaustively by emitVisualModel and paintVisualModel.
372
+ */
373
+ function resolveVisualModel(options) {
374
+ const { theme, style, box } = options;
375
+ for (const [name, value] of [["flipH", style["flipH"]], ["flipV", style["flipV"]]]) if (value !== void 0 && typeof value !== "boolean") invalid("invalid-visual-style", `${name} must be a boolean`);
376
+ const flipH = Boolean(style["flipH"]);
377
+ const flipV = Boolean(style["flipV"]);
378
+ const opacity = style["opacity"] === void 0 ? void 0 : finite(style["opacity"], "opacity");
379
+ if (opacity !== void 0 && (opacity < 0 || opacity > 1)) invalid("invalid-visual-style", "opacity must be a number between 0 and 1");
380
+ if (options.image && style["borderRadius"] !== void 0) invalid("unsupported-style-combination", "Image does not support borderRadius");
381
+ const radius = style["borderRadius"] === void 0 ? void 0 : finite(style["borderRadius"], "borderRadius");
382
+ if (radius !== void 0 && radius < 0) invalid("invalid-visual-style", "borderRadius must be a non-negative length");
383
+ const fill = resolveVisualFill(theme, style, opacity);
384
+ const border = options.borderOverride !== void 0 ? options.borderOverride ?? void 0 : resolveVisualBorder(theme, style, opacity);
385
+ const explicitNoShadow = style["boxShadow"] === "none";
386
+ const boxShadow = style["boxShadow"] === void 0 || explicitNoShadow ? void 0 : resolveShadow(theme, style["boxShadow"], "boxShadow");
387
+ let softEdge;
388
+ if (style["softEdge"] !== void 0) {
389
+ const rawSoft = finite(style["softEdge"], "softEdge");
390
+ if (rawSoft < 0) invalid("invalid-visual-style", "softEdge must be a non-negative length");
391
+ if (rawSoft > 0) {
392
+ emu(rawSoft, "softEdge", false);
393
+ softEdge = rawSoft;
394
+ }
395
+ }
396
+ const hasVisibleStyle = hasVisibleBoxStyle(style) || border !== void 0;
397
+ const layoutOnlyWhenInvisible = Boolean(options.layoutOnlyWhenInvisible);
398
+ const resolvedGeometry = resolveGeometry({
399
+ geometry: options.geometry,
400
+ borderRadius: layoutOnlyWhenInvisible && !hasVisibleStyle ? void 0 : radius,
401
+ box
402
+ });
403
+ const rotation = rotationUnits(style);
404
+ return {
405
+ box,
406
+ geometry: resolvedGeometry.geometry,
407
+ geometryName: resolvedGeometry.name,
408
+ fill,
409
+ ...border === void 0 ? {} : { border },
410
+ ...opacity === void 0 ? {} : { opacity },
411
+ ...boxShadow === void 0 ? {} : { boxShadow },
412
+ ...explicitNoShadow ? { explicitNoShadow: true } : {},
413
+ ...softEdge === void 0 ? {} : { softEdge },
414
+ rotate: rotation.degrees,
415
+ ...rotation.units === void 0 ? {} : { rotationUnits: rotation.units },
416
+ flipH,
417
+ flipV,
418
+ hasVisibleStyle,
419
+ layoutOnlyWhenInvisible
420
+ };
421
+ }
422
+ function emitFillXml(fill, registerResource, box) {
423
+ switch (fill.kind) {
424
+ case "none": return "<a:noFill/>";
425
+ case "solid": return solidFillMechanism.emit(fill, void 0).xml;
426
+ case "linear-gradient":
427
+ case "radial-gradient": return gradientFillMechanism.emit(fill, void 0).xml;
428
+ case "image": return emitImageFillXml(fill, registerResource, box);
429
+ default: return fill;
430
+ }
431
+ }
432
+ function emitBorderXml(border) {
433
+ if (border === void 0) return "<a:ln><a:noFill/></a:ln>";
434
+ let dash;
435
+ switch (border.style) {
436
+ case "solid":
437
+ dash = void 0;
438
+ break;
439
+ case "dashed":
440
+ dash = "dash";
441
+ break;
442
+ case "dotted":
443
+ dash = "sysDot";
444
+ break;
445
+ default: return border.style;
446
+ }
447
+ const headEnd = border.startArrow === void 0 ? "" : `<a:headEnd type="${border.startArrow}"/>`;
448
+ const tailEnd = border.endArrow === void 0 ? "" : `<a:tailEnd type="${border.endArrow}"/>`;
449
+ 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>`;
450
+ }
451
+ function emitEffectsXml(model, options) {
452
+ const items = [];
453
+ if (model.boxShadow !== void 0) {
454
+ const shadow = model.boxShadow;
455
+ const dir = Math.round((shadow.angle % 360 + 360) % 360 * 6e4);
456
+ 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>`);
457
+ }
458
+ if (model.softEdge !== void 0 && model.softEdge > 0) items.push(`<a:softEdge rad="${emu(model.softEdge, "softEdge", false)}"/>`);
459
+ if (items.length > 0) return `<a:effectLst>${items.join("")}</a:effectLst>`;
460
+ return options?.explicitEmptyWhenCleared && model.explicitNoShadow ? "<a:effectLst/>" : "";
461
+ }
462
+ /** Serializes a ResolvedVisualModel into PresentationML `<p:spPr>` XML. */
463
+ function emitVisualModel(model, registerResource, options) {
464
+ const { box } = model;
465
+ const allowSingleZeroExtent = Boolean(options?.allowSingleZeroExtent);
466
+ if (allowSingleZeroExtent && !(model.layoutOnlyWhenInvisible && !model.hasVisibleStyle)) assertVisualBoxExtent(box, { allowSingleZeroExtent: true });
467
+ return {
468
+ 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", allowSingleZeroExtent)}" cy="${emu(box.height, "height", allowSingleZeroExtent)}"/></a:xfrm>`}${resolvedGeometryXml(model.geometry)}${options?.omitFill ? "" : emitFillXml(model.fill, registerResource, box)}${emitBorderXml(model.border)}${emitEffectsXml(model)}</p:spPr>`,
469
+ ...model.opacity === void 0 ? {} : { opacity: model.opacity },
470
+ hasVisibleStyle: model.hasVisibleStyle,
471
+ geometryName: model.geometryName,
472
+ geometry: model.geometry
473
+ };
474
+ }
475
+ /**
476
+ * Serializes `<p:spPr>` for a master, layout, or bound slide placeholder, emitting only
477
+ * transform, geometry, fill, border, and effect elements declared on that layer.
478
+ */
479
+ function emitPlaceholderVisualSpPr(model, flags, registerResource) {
480
+ let xfrmXml = "";
481
+ if (flags.hasBox || flags.hasRotate || flags.hasFlipH || flags.hasFlipV) {
482
+ const rotAttr = flags.hasRotate ? ` rot="${model.rotationUnits ?? 0}"` : "";
483
+ const flipHAttr = flags.hasFlipH ? model.flipH ? " flipH=\"1\"" : " flipH=\"0\"" : "";
484
+ const flipVAttr = flags.hasFlipV ? model.flipV ? " flipV=\"1\"" : " flipV=\"0\"" : "";
485
+ if (flags.hasBox) {
486
+ const { box } = model;
487
+ 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>`;
488
+ } else xfrmXml = `<a:xfrm${rotAttr}${flipHAttr}${flipVAttr}/>`;
489
+ }
490
+ const geomXml = flags.hasGeometryOrRadius || flags.hasBox && flags.includeDefaultRectWhenHasBox === true ? resolvedGeometryXml(model.geometry) : "";
491
+ const fillXml = flags.hasFill ? emitFillXml(model.fill, registerResource, model.box) : "";
492
+ const borderXml = flags.hasBorder ? emitBorderXml(model.border) : "";
493
+ const effectsXml = flags.hasEffects ? emitEffectsXml(model, { explicitEmptyWhenCleared: true }) : "";
494
+ const inner = `${xfrmXml}${geomXml}${fillXml}${borderXml}${effectsXml}`;
495
+ return inner === "" ? "<p:spPr/>" : `<p:spPr>${inner}</p:spPr>`;
496
+ }
497
+ /** Returns the SVG transform string (flip around box center, then rotate around box center). */
498
+ function visualSvgTransform(model) {
499
+ const cx = model.box.x + model.box.width / 2;
500
+ const cy = model.box.y + model.box.height / 2;
501
+ return `translate(${roundSvgNumber(cx)} ${roundSvgNumber(cy)}) rotate(${roundSvgNumber(model.rotate)}) scale(${model.flipH ? -1 : 1} ${model.flipV ? -1 : 1}) translate(${roundSvgNumber(-cx)} ${roundSvgNumber(-cy)})`;
502
+ }
503
+ function normalizeVec(dx, dy) {
504
+ const len = Math.hypot(dx, dy);
505
+ if (len <= 1e-9) return void 0;
506
+ return {
507
+ x: dx / len,
508
+ y: dy / len
509
+ };
510
+ }
511
+ function splitSubpaths(commands) {
512
+ const result = [];
513
+ let current;
514
+ let start = {
515
+ x: 0,
516
+ y: 0
517
+ };
518
+ for (const command of commands) {
519
+ if (command.op === "M") {
520
+ current = [command];
521
+ result.push(current);
522
+ start = {
523
+ x: command.x,
524
+ y: command.y
525
+ };
526
+ continue;
527
+ }
528
+ if (current === void 0) {
529
+ current = [{
530
+ op: "M",
531
+ x: start.x,
532
+ y: start.y
533
+ }];
534
+ result.push(current);
535
+ }
536
+ current.push(command);
537
+ if (command.op === "Z") current = void 0;
538
+ }
539
+ return result;
540
+ }
541
+ function arrowShortenLength(arrow, strokeWidth) {
542
+ const w = Math.max(1, strokeWidth);
543
+ const length = Math.max(6, w * 3.5);
544
+ switch (arrow) {
545
+ case "none": return 0;
546
+ case "triangle": return .85 * length;
547
+ case "stealth": return .65 * length;
548
+ case "arrow": return .5 * w;
549
+ case "diamond":
550
+ case "oval": return 0;
551
+ default: return arrow;
552
+ }
553
+ }
554
+ function arrowHeadSvg(arrow, tip, dir, strokeHex, strokeAlpha, strokeWidth) {
555
+ if (arrow === "none") return "";
556
+ const w = Math.max(1, strokeWidth);
557
+ const length = Math.max(6, w * 3.5);
558
+ const halfWidth = Math.max(3, w * 1.75);
559
+ const deg = roundSvgNumber(Math.atan2(dir.y, dir.x) * 180 / Math.PI);
560
+ const tx = roundSvgNumber(tip.x);
561
+ const ty = roundSvgNumber(tip.y);
562
+ const alpha = roundSvgNumber(strokeAlpha);
563
+ const transform = `translate(${tx} ${ty}) rotate(${deg})`;
564
+ switch (arrow) {
565
+ 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}"/>`;
566
+ 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}"/>`;
567
+ 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}"/>`;
568
+ 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}"/>`;
569
+ 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}"/>`;
570
+ default: return arrow;
571
+ }
572
+ }
573
+ function commandsToSvgPath(commands) {
574
+ return commands.map((command) => {
575
+ switch (command.op) {
576
+ case "Z": return "Z";
577
+ case "M":
578
+ case "L": return `${command.op}${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
579
+ case "Q": return `Q${roundSvgNumber(command.x1)} ${roundSvgNumber(command.y1)} ${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
580
+ case "C": return `C${roundSvgNumber(command.x1)} ${roundSvgNumber(command.y1)} ${roundSvgNumber(command.x2)} ${roundSvgNumber(command.y2)} ${roundSvgNumber(command.x)} ${roundSvgNumber(command.y)}`;
581
+ default: return command;
582
+ }
583
+ }).join(" ");
584
+ }
585
+ function extractOpenSubpathEnds(subpath) {
586
+ const first = subpath[0];
587
+ const last = subpath.at(-1);
588
+ if (first === void 0 || first.op !== "M" || last === void 0) return;
589
+ if (last.op === "Z" || subpath.length < 2) return;
590
+ const startPoint = {
591
+ x: first.x,
592
+ y: first.y
593
+ };
594
+ let startTangent;
595
+ let firstSegLen = 0;
596
+ for (let i = 1; i < subpath.length; i += 1) {
597
+ const cmd = subpath[i];
598
+ if (cmd.op === "L") {
599
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
600
+ startTangent = normalizeVec(cmd.x - startPoint.x, cmd.y - startPoint.y);
601
+ if (startTangent !== void 0) break;
602
+ } else if (cmd.op === "Q") {
603
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
604
+ startTangent = normalizeVec(cmd.x1 - startPoint.x, cmd.y1 - startPoint.y) ?? normalizeVec(cmd.x - startPoint.x, cmd.y - startPoint.y);
605
+ if (startTangent !== void 0) break;
606
+ } else if (cmd.op === "C") {
607
+ if (i === 1) firstSegLen = Math.hypot(cmd.x - startPoint.x, cmd.y - startPoint.y);
608
+ 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);
609
+ if (startTangent !== void 0) break;
610
+ }
611
+ }
612
+ if (last.op === "M") return void 0;
613
+ const endPoint = {
614
+ x: last.x,
615
+ y: last.y
616
+ };
617
+ let endTangent;
618
+ let lastSegLen = 0;
619
+ for (let i = subpath.length - 1; i >= 1; i -= 1) {
620
+ const cmd = subpath[i];
621
+ const prevCmd = subpath[i - 1];
622
+ if (prevCmd.op === "Z") continue;
623
+ const prevPoint = {
624
+ x: prevCmd.x,
625
+ y: prevCmd.y
626
+ };
627
+ if (cmd.op === "L") {
628
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
629
+ endTangent = normalizeVec(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
630
+ if (endTangent !== void 0) break;
631
+ } else if (cmd.op === "Q") {
632
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
633
+ endTangent = normalizeVec(endPoint.x - cmd.x1, endPoint.y - cmd.y1) ?? normalizeVec(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
634
+ if (endTangent !== void 0) break;
635
+ } else if (cmd.op === "C") {
636
+ if (i === subpath.length - 1) lastSegLen = Math.hypot(endPoint.x - prevPoint.x, endPoint.y - prevPoint.y);
637
+ 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);
638
+ if (endTangent !== void 0) break;
639
+ }
640
+ }
641
+ if (startTangent === void 0 || endTangent === void 0) return;
642
+ return {
643
+ startPoint,
644
+ startTangent,
645
+ firstSegLen,
646
+ endPoint,
647
+ endTangent,
648
+ lastSegLen,
649
+ segCount: subpath.length - 1
650
+ };
651
+ }
652
+ function shortenOpenSubpath(subpath, startShorten, endShorten, ends) {
653
+ const canShortenStart = startShorten > 0 && (ends.segCount === 1 ? ends.firstSegLen > (startShorten + endShorten) * 1.5 : ends.firstSegLen > startShorten * 1.5);
654
+ const canShortenEnd = endShorten > 0 && (ends.segCount === 1 ? ends.lastSegLen > (startShorten + endShorten) * 1.5 : ends.lastSegLen > endShorten * 1.5);
655
+ if (!canShortenStart && !canShortenEnd) return subpath;
656
+ const next = [...subpath];
657
+ if (canShortenStart) {
658
+ const first = next[0];
659
+ if (first.op === "M") next[0] = {
660
+ op: "M",
661
+ x: first.x + ends.startTangent.x * startShorten,
662
+ y: first.y + ends.startTangent.y * startShorten
663
+ };
664
+ }
665
+ if (canShortenEnd) {
666
+ const lastIdx = next.length - 1;
667
+ const last = next[lastIdx];
668
+ if (last.op === "L" || last.op === "Q" || last.op === "C") next[lastIdx] = {
669
+ ...last,
670
+ x: last.x - ends.endTangent.x * endShorten,
671
+ y: last.y - ends.endTangent.y * endShorten
672
+ };
673
+ }
674
+ return next;
675
+ }
676
+ function borderAttributes(border) {
677
+ if (border === void 0) return "stroke=\"none\" stroke-width=\"0\"";
678
+ const w = Math.max(1, border.width);
679
+ let dashAttr = "";
680
+ switch (border.style) {
681
+ case "solid":
682
+ dashAttr = "";
683
+ break;
684
+ case "dashed":
685
+ dashAttr = ` stroke-dasharray="${roundSvgNumber(w * 4)} ${roundSvgNumber(w * 3)}"`;
686
+ break;
687
+ case "dotted":
688
+ dashAttr = ` stroke-dasharray="${roundSvgNumber(w)} ${roundSvgNumber(w * 2)}"`;
689
+ break;
690
+ default: return border.style;
691
+ }
692
+ return `stroke="#${border.color.hex}" stroke-opacity="${roundSvgNumber(border.color.alpha ?? 1)}" stroke-width="${roundSvgNumber(border.width)}"${dashAttr}`;
693
+ }
694
+ function subpathFillHex(baseHex, fillMode) {
695
+ switch (fillMode) {
696
+ case "norm": return baseHex;
697
+ case "lighten": return shadeHex(baseHex, .6, .4);
698
+ case "lightenLess": return shadeHex(baseHex, .8, .2);
699
+ case "darken": return shadeHex(baseHex, .6, 0);
700
+ case "darkenLess": return shadeHex(baseHex, .8, 0);
701
+ default: return fillMode;
702
+ }
703
+ }
704
+ function shadeOverlayAttrs(fillMode) {
705
+ switch (fillMode) {
706
+ case "norm": return;
707
+ case "lighten": return "fill=\"#FFFFFF\" fill-opacity=\"0.35\"";
708
+ case "lightenLess": return "fill=\"#FFFFFF\" fill-opacity=\"0.2\"";
709
+ case "darken": return "fill=\"#000000\" fill-opacity=\"0.3\"";
710
+ case "darkenLess": return "fill=\"#000000\" fill-opacity=\"0.15\"";
711
+ default: return fillMode;
712
+ }
713
+ }
714
+ function resolveSubpathFill(fill, fillDefId, fillMode) {
715
+ if (fillMode === "none") return {
716
+ fillAttr: "fill=\"none\"",
717
+ overlayAttr: void 0,
718
+ hasFill: false
719
+ };
720
+ switch (fill.kind) {
721
+ case "none": return {
722
+ fillAttr: "fill=\"none\"",
723
+ overlayAttr: void 0,
724
+ hasFill: false
725
+ };
726
+ case "solid": return {
727
+ fillAttr: solidFillMechanism.paint(fill, { fillMode }).svg,
728
+ overlayAttr: void 0,
729
+ hasFill: true
730
+ };
731
+ case "linear-gradient":
732
+ case "radial-gradient":
733
+ case "image": return {
734
+ fillAttr: `fill="url(#${fillDefId})" fill-opacity="1"`,
735
+ overlayAttr: shadeOverlayAttrs(fillMode),
736
+ hasFill: true
737
+ };
738
+ default: return fill;
739
+ }
740
+ }
741
+ function renderEvaluatedGeometryElements(model, fillDefId, overrideAttrs) {
742
+ const evaluated = evaluateGeometry(model.geometry, model.box);
743
+ const { border } = model;
744
+ const strokeAttr = borderAttributes(border);
745
+ const startArrow = border?.startArrow ?? "none";
746
+ const endArrow = border?.endArrow ?? "none";
747
+ return evaluated.paths.map((pathItem) => {
748
+ if (overrideAttrs !== void 0) {
749
+ if (pathItem.fillMode === "none" && (!pathItem.stroke || border === void 0)) return "";
750
+ return `<path d="${pathItem.d}" ${overrideAttrs}/>`;
751
+ }
752
+ const { fillAttr, overlayAttr, hasFill } = resolveSubpathFill(model.fill, fillDefId, pathItem.fillMode);
753
+ const allowStroke = pathItem.stroke && border !== void 0;
754
+ const subpaths = splitSubpaths(pathItem.commands);
755
+ const hasOpenSubpath = subpaths.some((sp) => sp.at(-1)?.op !== "Z");
756
+ if (!(allowStroke && hasOpenSubpath && (startArrow !== "none" || endArrow !== "none"))) {
757
+ const base = `<path d="${pathItem.d}" ${fillAttr} ${allowStroke ? strokeAttr : "stroke=\"none\" stroke-width=\"0\""}/>`;
758
+ return overlayAttr === void 0 ? base : `${base}<path d="${pathItem.d}" ${overlayAttr} stroke="none" stroke-width="0"/>`;
759
+ }
760
+ const fragments = [];
761
+ if (hasFill) {
762
+ fragments.push(`<path d="${pathItem.d}" ${fillAttr} stroke="none"/>`);
763
+ if (overlayAttr !== void 0) fragments.push(`<path d="${pathItem.d}" ${overlayAttr} stroke="none"/>`);
764
+ }
765
+ const startShorten = arrowShortenLength(startArrow, border.width);
766
+ const endShorten = arrowShortenLength(endArrow, border.width);
767
+ const strokeAlpha = border.color.alpha ?? 1;
768
+ for (const subpath of subpaths) {
769
+ const ends = extractOpenSubpathEnds(subpath);
770
+ if (ends === void 0) {
771
+ fragments.push(`<path d="${commandsToSvgPath(subpath)}" fill="none" ${strokeAttr}/>`);
772
+ continue;
773
+ }
774
+ const shortened = shortenOpenSubpath(subpath, startShorten, endShorten, ends);
775
+ fragments.push(`<path d="${commandsToSvgPath(shortened)}" fill="none" ${strokeAttr}/>`);
776
+ if (startArrow !== "none") fragments.push(arrowHeadSvg(startArrow, ends.startPoint, {
777
+ x: -ends.startTangent.x,
778
+ y: -ends.startTangent.y
779
+ }, border.color.hex, strokeAlpha, border.width));
780
+ if (endArrow !== "none") fragments.push(arrowHeadSvg(endArrow, ends.endPoint, ends.endTangent, border.color.hex, strokeAlpha, border.width));
781
+ }
782
+ return fragments.join("");
783
+ }).join("");
784
+ }
785
+ /**
786
+ * Renders a closed ResolvedVisualModel into deterministic SVG markup with scoped `<defs>`,
787
+ * linear/radial gradients, image `<pattern>`, rounded corners, dashed/dotted strokes,
788
+ * open-path tangent arrows, screen-space `boxShadow`, and feathered `softEdge` masks.
789
+ */
790
+ function paintVisualModel(options) {
791
+ const { model, slideNumber, objectId } = options;
792
+ const { box } = model;
793
+ if (!(options.allowSingleZeroExtent ? isFiniteSingleZeroBox(box) : isFinitePositiveBox(box))) return {
794
+ svg: "",
795
+ ...model.fill.kind === "image" && model.fill.source.kind === "external" ? { placeholders: [{ url: model.fill.source.externalUrl }] } : {}
796
+ };
797
+ const prefix = `obj-s${slideNumber}-o${objectId}`;
798
+ const defs = [];
799
+ let fillDefId;
800
+ switch (model.fill.kind) {
801
+ case "none":
802
+ case "solid": break;
803
+ case "linear-gradient":
804
+ case "radial-gradient":
805
+ fillDefId = `${prefix}-fill`;
806
+ defs.push(gradientFillMechanism.paint(model.fill, { id: fillDefId }).svg);
807
+ break;
808
+ case "image": {
809
+ const candidateId = `${prefix}-fill`;
810
+ const patternSvg = imageFillMechanism.paint(model.fill, {
811
+ id: candidateId,
812
+ box,
813
+ ...options.registerRasterResource === void 0 ? {} : { registerRasterResource: options.registerRasterResource }
814
+ }).svg;
815
+ if (patternSvg !== "") {
816
+ fillDefId = candidateId;
817
+ defs.push(patternSvg);
818
+ }
819
+ break;
820
+ }
821
+ default: return model.fill;
822
+ }
823
+ let content = renderEvaluatedGeometryElements(model, fillDefId);
824
+ if (model.softEdge !== void 0 && model.softEdge > 0) {
825
+ const r = model.softEdge;
826
+ const minSide = Math.min(box.width, box.height);
827
+ const borderPad = model.border === void 0 ? 0 : model.border.width;
828
+ const pad = Math.ceil(r * 2 + borderPad + 8);
829
+ const maskX = roundSvgNumber(box.x - pad);
830
+ const maskY = roundSvgNumber(box.y - pad);
831
+ const maskW = roundSvgNumber(box.width + pad * 2);
832
+ const maskH = roundSvgNumber(box.height + pad * 2);
833
+ const blurId = `${prefix}-soft-blur`;
834
+ const maskId = `${prefix}-soft-mask`;
835
+ const innerStrokeWidth = r >= minSide / 2 ? 0 : Math.min(r, minSide * .45);
836
+ const maskAttrs = innerStrokeWidth > 0 ? `fill="white" stroke="black" stroke-width="${roundSvgNumber(innerStrokeWidth)}" filter="url(#${blurId})"` : `fill="white" stroke="none" filter="url(#${blurId})"`;
837
+ const maskShapes = renderEvaluatedGeometryElements(model, fillDefId, maskAttrs);
838
+ defs.push(`<filter id="${blurId}" filterUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}"><feGaussianBlur stdDeviation="${roundSvgNumber(r / 2)}"/></filter>`);
839
+ defs.push(`<mask id="${maskId}" maskUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}">${maskShapes}</mask>`);
840
+ content = `<g mask="url(#${maskId})">${content}</g>`;
841
+ }
842
+ let layer = `<g transform="${visualSvgTransform(model)}">${content}</g>`;
843
+ if (model.boxShadow !== void 0) {
844
+ const shadow = model.boxShadow;
845
+ const cx = box.x + box.width / 2;
846
+ const cy = box.y + box.height / 2;
847
+ const halfDiag = Math.hypot(box.width, box.height) / 2;
848
+ const rad = shadow.angle * Math.PI / 180;
849
+ const dx = shadow.distance * Math.cos(rad);
850
+ const dy = shadow.distance * Math.sin(rad);
851
+ const sigma = shadow.blur / 2;
852
+ const borderPad = model.border === void 0 ? 0 : model.border.width;
853
+ const pad = shadow.blur * 3 + Math.abs(dx) + Math.abs(dy) + borderPad + 16;
854
+ const minX = roundSvgNumber(cx - halfDiag - pad);
855
+ const minY = roundSvgNumber(cy - halfDiag - pad);
856
+ const filterSize = roundSvgNumber((halfDiag + pad) * 2);
857
+ const shadowId = `${prefix}-shadow`;
858
+ 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>`);
859
+ layer = `<g filter="url(#${shadowId})">${layer}</g>`;
860
+ }
861
+ return {
862
+ svg: `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${layer}`,
863
+ ...model.fill.kind === "image" && model.fill.source.kind === "external" ? { placeholders: [{ url: model.fill.source.externalUrl }] } : {}
864
+ };
865
+ }
866
+ /** Reads DrawingML `<a:blipFill>` embedded image bytes and validates them against supported decoders. */
867
+ function readBlipFill(blipFillCursor, pkg, location, diagnostics) {
868
+ return readBlipFill$1(blipFillCursor, pkg, location, diagnostics, (bytes) => {
869
+ readImage(bytes);
870
+ });
871
+ }
872
+ /**
873
+ * Reads PresentationML `<p:spPr>` geometry, fills, borders, and effects (without requiring `<a:xfrm>`).
874
+ * Used both by full-shape import and placeholder import where transform overrides may be absent.
875
+ */
876
+ function readSpPrAppearance(spPrCursor, pkg, fallbackUnits, location, diagnostics, options) {
877
+ let geometry;
878
+ let background;
879
+ let hasNoFill = false;
880
+ let hasEmptyEffectLst = false;
881
+ let border = {};
882
+ let effects = {};
883
+ for (const child of spPrCursor.remainingElementChildren()) {
884
+ if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
885
+ diagnostics.push({
886
+ code: "unconsumed-xml",
887
+ category: "unsupported",
888
+ disposition: "omitted",
889
+ kind: "element",
890
+ location: {
891
+ ...location,
892
+ xpath: child.xpath
893
+ },
894
+ namespaceUri: child.namespaceUri,
895
+ localName: child.localName
896
+ });
897
+ continue;
898
+ }
899
+ switch (child.localName) {
900
+ case "prstGeom":
901
+ geometry = readPresetGeometryXml(child, location, diagnostics);
902
+ break;
903
+ case "custGeom":
904
+ geometry = readCustomGeometryXml(child, fallbackUnits, location, diagnostics);
905
+ break;
906
+ case "noFill":
907
+ hasNoFill = true;
908
+ break;
909
+ case "solidFill":
910
+ background = readDrawingColor(child, location, diagnostics);
911
+ break;
912
+ case "gradFill":
913
+ background = readGradientFill(child, location, diagnostics);
914
+ break;
915
+ case "blipFill": {
916
+ const blip = readBlipFill(child, pkg, location, diagnostics);
917
+ if (blip !== void 0) background = {
918
+ image: blip.image,
919
+ ...blip.opacity === void 0 ? {} : { opacity: blip.opacity }
920
+ };
921
+ break;
922
+ }
923
+ case "ln":
924
+ border = readLineBorder(child, location, diagnostics);
925
+ break;
926
+ case "effectLst":
927
+ hasEmptyEffectLst = child.element.children.length === 0;
928
+ effects = readEffectList(child, location, diagnostics);
929
+ break;
930
+ case "extLst":
931
+ child.ignoreEmptyChild(A_NS, "ext");
932
+ break;
933
+ default: diagnostics.push({
934
+ code: "unsupported-mechanism",
935
+ category: "unsupported",
936
+ disposition: "omitted",
937
+ location: {
938
+ ...location,
939
+ xpath: child.xpath
940
+ },
941
+ namespaceUri: child.namespaceUri,
942
+ localName: child.localName,
943
+ mechanismHint: child.localName
944
+ });
945
+ }
946
+ }
947
+ const resolvedBackground = background ?? (hasNoFill ? "none" : void 0);
948
+ const resolvedBorder = border.borderColor !== void 0 ? {
949
+ color: border.borderColor,
950
+ ...border.borderWidth === void 0 ? {} : { width: border.borderWidth },
951
+ ...border.borderStyle === void 0 ? {} : { style: border.borderStyle }
952
+ } : border.noFill === true ? "none" : void 0;
953
+ const borderArrows = border.startArrow !== void 0 || border.endArrow !== void 0 ? {
954
+ ...border.startArrow === void 0 ? {} : { startArrow: border.startArrow },
955
+ ...border.endArrow === void 0 ? {} : { endArrow: border.endArrow }
956
+ } : void 0;
957
+ const resolvedBoxShadow = effects.boxShadow ?? (options?.preservePlaceholderClears === true && hasEmptyEffectLst && effects.softEdge === void 0 ? "none" : void 0);
958
+ const style = {
959
+ ...resolvedBackground === void 0 ? {} : { background: resolvedBackground },
960
+ ...resolvedBorder === void 0 ? {} : { border: resolvedBorder },
961
+ ...resolvedBoxShadow === void 0 ? {} : { boxShadow: resolvedBoxShadow },
962
+ ...effects.softEdge === void 0 ? {} : { softEdge: effects.softEdge }
963
+ };
964
+ return {
965
+ ...geometry === void 0 ? {} : { geometry },
966
+ style,
967
+ ...borderArrows === void 0 ? {} : { borderArrows }
968
+ };
969
+ }
970
+ /**
971
+ * Reads PresentationML `<p:spPr>` geometry, transform, fills, borders, and effects.
972
+ * Isolates unsupported visual elements/fills by emitting a localized ImportDiagnostic
973
+ * and omitting only the unsupported visual attribute while keeping geometry and text intact.
974
+ */
975
+ function readSpPrVisuals(spPrCursor, pkg, location, diagnostics) {
976
+ let transform;
977
+ const xfrmCursor = spPrCursor.child(A_NS, "xfrm");
978
+ if (xfrmCursor !== void 0) transform = readTransformXml(xfrmCursor, location, diagnostics);
979
+ if (transform === void 0) {
980
+ if (xfrmCursor === void 0) diagnostics.push({
981
+ code: "corrupt-part",
982
+ category: "corrupt-input",
983
+ disposition: "omitted",
984
+ location: {
985
+ ...location,
986
+ xpath: spPrCursor.xpath
987
+ }
988
+ });
989
+ return;
990
+ }
991
+ const appearance = readSpPrAppearance(spPrCursor, pkg, {
992
+ w: transform.cxEmu,
993
+ h: transform.cyEmu
994
+ }, location, diagnostics);
995
+ const style = {
996
+ ...appearance.style,
997
+ ...transform.rotate === void 0 ? {} : { rotate: transform.rotate },
998
+ ...transform.flipH === true ? { flipH: true } : {},
999
+ ...transform.flipV === true ? { flipV: true } : {}
1000
+ };
1001
+ return {
1002
+ transform,
1003
+ ...appearance.geometry === void 0 ? {} : { geometry: appearance.geometry },
1004
+ style,
1005
+ ...appearance.borderArrows === void 0 ? {} : { borderArrows: appearance.borderArrows }
1006
+ };
1007
+ }
1008
+ function readFillSubElement(context) {
1009
+ const diagnostics = [];
1010
+ const spPrCursor = context.cursor.child(P_NS, "spPr");
1011
+ if (spPrCursor === void 0) return { diagnostics };
1012
+ readSpPrVisuals(spPrCursor, context.package, {
1013
+ part: context.part,
1014
+ slideIndex: context.slideIndex
1015
+ }, diagnostics);
1016
+ return { diagnostics };
1017
+ }
1018
+ /** Native canvas mechanism for DrawingML `<a:solidFill>`. */
1019
+ const solidFillMechanism = defineCanvasMechanism({
1020
+ key: "solid-fill",
1021
+ role: "canvas",
1022
+ emit(fill, _context) {
1023
+ return { xml: `<a:solidFill>${resolvedColorXml(fill.color)}</a:solidFill>` };
1024
+ },
1025
+ paint(fill, context) {
1026
+ return { svg: `fill="#${subpathFillHex(fill.color.hex, context.fillMode)}" fill-opacity="${roundSvgNumber(fill.color.alpha ?? 1)}"` };
1027
+ },
1028
+ import: {
1029
+ target: "shape-tree",
1030
+ localName: "sp",
1031
+ matches: () => false,
1032
+ read: readFillSubElement
1033
+ }
1034
+ });
1035
+ /** Native canvas mechanism for DrawingML `<a:gradFill>` (linear and radial gradients). */
1036
+ const gradientFillMechanism = defineCanvasMechanism({
1037
+ key: "gradient-fill",
1038
+ role: "canvas",
1039
+ emit(fill, _context) {
1040
+ return { xml: gradientFillXml(fill) };
1041
+ },
1042
+ paint(fill, context) {
1043
+ return { svg: gradientDefSvg(context.id, fill) };
1044
+ },
1045
+ import: {
1046
+ target: "shape-tree",
1047
+ localName: "sp",
1048
+ matches: () => false,
1049
+ read: readFillSubElement
1050
+ }
1051
+ });
1052
+ function formatOoxmlRectAttrs(rect) {
1053
+ const attrs = [];
1054
+ if (rect.l !== 0) attrs.push(`l="${rect.l}"`);
1055
+ if (rect.t !== 0) attrs.push(`t="${rect.t}"`);
1056
+ if (rect.r !== 0) attrs.push(`r="${rect.r}"`);
1057
+ if (rect.b !== 0) attrs.push(`b="${rect.b}"`);
1058
+ return attrs.length === 0 ? "" : ` ${attrs.join(" ")}`;
1059
+ }
1060
+ /** Emits DrawingML `<a:blipFill>` XML for embedded or external image background fills. */
1061
+ function emitImageFillXml(fill, registerResource, box) {
1062
+ if (registerResource === void 0) invalid("image-resource-failure", "Cannot emit image background fill without resource registrar");
1063
+ const relationshipId = fill.source.kind === "external" ? registerResource({
1064
+ externalTarget: fill.source.externalUrl,
1065
+ relationshipType: imageRelationship
1066
+ }) : registerResource({
1067
+ bytes: fill.source.bytes,
1068
+ extension: fill.source.extension,
1069
+ contentType: fill.source.contentType,
1070
+ relationshipType: imageRelationship
1071
+ });
1072
+ const relAttr = fill.source.kind === "external" ? `r:link="${xmlEscape(relationshipId)}"` : `r:embed="${xmlEscape(relationshipId)}"`;
1073
+ const alpha = fill.opacity === void 0 ? "" : `<a:alphaModFix amt="${Math.round(fill.opacity * 1e5)}"/>`;
1074
+ const blipXml = alpha === "" ? `<a:blip ${relAttr}/>` : `<a:blip ${relAttr}>${alpha}</a:blip>`;
1075
+ let srcRectXml = "";
1076
+ let fillRectXml = "<a:fillRect/>";
1077
+ if (fill.source.kind === "embedded" && fill.source.width > 0 && fill.source.height > 0 && box !== void 0 && box.width > 0 && box.height > 0) {
1078
+ const imgRatio = fill.source.width / fill.source.height;
1079
+ const boxRatio = box.width / box.height;
1080
+ if (fill.fit === "cover") {
1081
+ let l = 0;
1082
+ let t = 0;
1083
+ let r = 0;
1084
+ let b = 0;
1085
+ if (imgRatio > boxRatio) {
1086
+ const cropX = 1 - boxRatio / imgRatio;
1087
+ l = Math.round(cropX * fill.position.x * 1e5);
1088
+ r = Math.round(cropX * (1 - fill.position.x) * 1e5);
1089
+ } else if (imgRatio < boxRatio) {
1090
+ const cropY = 1 - imgRatio / boxRatio;
1091
+ t = Math.round(cropY * fill.position.y * 1e5);
1092
+ b = Math.round(cropY * (1 - fill.position.y) * 1e5);
1093
+ }
1094
+ const attrs = formatOoxmlRectAttrs({
1095
+ l,
1096
+ t,
1097
+ r,
1098
+ b
1099
+ });
1100
+ if (attrs !== "") srcRectXml = `<a:srcRect${attrs}/>`;
1101
+ } else if (fill.fit === "contain") {
1102
+ let l = 0;
1103
+ let t = 0;
1104
+ let r = 0;
1105
+ let b = 0;
1106
+ if (imgRatio > boxRatio) {
1107
+ const insY = 1 - boxRatio / imgRatio;
1108
+ t = Math.round(insY * fill.position.y * 1e5);
1109
+ b = Math.round(insY * (1 - fill.position.y) * 1e5);
1110
+ } else if (imgRatio < boxRatio) {
1111
+ const insX = 1 - imgRatio / boxRatio;
1112
+ l = Math.round(insX * fill.position.x * 1e5);
1113
+ r = Math.round(insX * (1 - fill.position.x) * 1e5);
1114
+ }
1115
+ const attrs = formatOoxmlRectAttrs({
1116
+ l,
1117
+ t,
1118
+ r,
1119
+ b
1120
+ });
1121
+ if (attrs !== "") fillRectXml = `<a:fillRect${attrs}/>`;
1122
+ }
1123
+ }
1124
+ return `<a:blipFill rotWithShape="1">${blipXml}${srcRectXml}<a:stretch>${fillRectXml}</a:stretch></a:blipFill>`;
1125
+ }
1126
+ /** Renders deterministic SVG `<pattern>` markup for embedded or external image background fills. */
1127
+ function paintImageFillSvg(fill, id, box, registerRasterResource) {
1128
+ if (!isFinitePositiveBox(box)) return "";
1129
+ const bx = roundSvgNumber(box.x);
1130
+ const by = roundSvgNumber(box.y);
1131
+ const bw = roundSvgNumber(box.width);
1132
+ const bh = roundSvgNumber(box.height);
1133
+ const opacity = fill.opacity ?? 1;
1134
+ const imgOpacity = roundSvgNumber(opacity);
1135
+ if (fill.source.kind === "external") return `<pattern id="${id}" patternUnits="userSpaceOnUse" x="${bx}" y="${by}" width="${bw}" height="${bh}"><rect x="0" y="0" width="${bw}" height="${bh}" fill="#F1F5F9" fill-opacity="${imgOpacity}"/></pattern>`;
1136
+ let pngBytes;
1137
+ try {
1138
+ pngBytes = decodeImageToPngBytes(fill.source);
1139
+ } catch (error) {
1140
+ if (error instanceof CapabilityError && error.details?.["field"] === void 0) throw new CapabilityError(error.code, error.message, error.path, {
1141
+ ...error.details,
1142
+ field: "style.background"
1143
+ });
1144
+ throw error;
1145
+ }
1146
+ const href = registerRasterResource !== void 0 ? registerRasterResource({
1147
+ contentType: "image/png",
1148
+ bytes: pngBytes
1149
+ }) : `data:image/png;base64,${Buffer.from(pngBytes).toString("base64")}`;
1150
+ let drawX = 0;
1151
+ let drawY = 0;
1152
+ let drawW = box.width;
1153
+ let drawH = box.height;
1154
+ if (fill.fit !== "fill" && fill.source.width > 0 && fill.source.height > 0 && box.width > 0 && box.height > 0) {
1155
+ const imgRatio = fill.source.width / fill.source.height;
1156
+ const boxRatio = box.width / box.height;
1157
+ if (fill.fit === "cover") {
1158
+ if (imgRatio > boxRatio) {
1159
+ drawH = box.height;
1160
+ drawW = box.height * imgRatio;
1161
+ } else {
1162
+ drawW = box.width;
1163
+ drawH = box.width / imgRatio;
1164
+ }
1165
+ } else if (fill.fit === "contain") {
1166
+ if (imgRatio > boxRatio) {
1167
+ drawW = box.width;
1168
+ drawH = box.width / imgRatio;
1169
+ } else {
1170
+ drawH = box.height;
1171
+ drawW = box.height * imgRatio;
1172
+ }
1173
+ }
1174
+ drawX = (box.width - drawW) * fill.position.x;
1175
+ drawY = (box.height - drawH) * fill.position.y;
1176
+ }
1177
+ const opacityAttr = opacity === 1 ? "" : ` opacity="${imgOpacity}"`;
1178
+ return `<pattern id="${id}" patternUnits="userSpaceOnUse" x="${bx}" y="${by}" width="${bw}" height="${bh}"><image x="${roundSvgNumber(drawX)}" y="${roundSvgNumber(drawY)}" width="${roundSvgNumber(drawW)}" height="${roundSvgNumber(drawH)}" preserveAspectRatio="none"${opacityAttr} href="${href}"/></pattern>`;
1179
+ }
1180
+ /** Native canvas mechanism for DrawingML `<a:blipFill>` shape image fills. */
1181
+ const imageFillMechanism = defineCanvasMechanism({
1182
+ key: "image-fill",
1183
+ role: "canvas",
1184
+ emit(fill, registerResource) {
1185
+ return { xml: emitImageFillXml(fill, registerResource) };
1186
+ },
1187
+ paint(fill, context) {
1188
+ return { svg: paintImageFillSvg(fill, context.id, context.box, context.registerRasterResource) };
1189
+ },
1190
+ import: {
1191
+ target: "shape-tree",
1192
+ localName: "sp",
1193
+ matches: () => false,
1194
+ read: readFillSubElement
1195
+ }
1196
+ });
1197
+ export { arrowTypeSchema, assertVisualBoxExtent, emitFillXml, emitImageFillXml, emitPlaceholderVisualSpPr, emitVisualModel, gradientDefSvg, gradientFillMechanism, gradientFillXml, hasVisibleBoxStyle, imageFillMechanism, lineStrokeValueSchema, linearGradient, paintImageFillSvg, paintVisualModel, radialGradient, readBlipFill, readDrawingColor, readEffectList, readGradientFill, readLineBorder, readSpPrAppearance, readSpPrVisuals, readTransformXml, resolveBackgroundValue, resolveGradientSpec, resolveImageBackgroundPosition, resolveImageBackgroundSpec, resolveLineStroke, resolveShadow, resolveVisualModel, solidFillMechanism, textShadowXml, visualSvgTransform };