@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,1423 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { customGeometrySchema, geometryAdjustKeySchema, geometryAdjustSchema, geometrySchema, presetGeometryNameSchema, presetGeometryTuple } from "../../../core/dist/geometry-schemas.js";
3
+ import "../../../core/dist/capability.js";
4
+ import { pxToEmu } from "../../../emit/dist/ooxml.js";
5
+ import "../../../emit/dist/index.js";
6
+ import { A_NS } from "../../../import/dist/namespaces.js";
7
+ import { ooxmlBoolSchema, ooxmlIntSchema, ooxmlPositiveIntSchema } from "../../../import/dist/xml-fragments.js";
8
+ import "../../../import/dist/index.js";
9
+ import { presetDefinitions } from "./preset-definitions.js";
10
+ import { z } from "zod";
11
+ // ../capabilities/dist/shared/geometry.js
12
+ /** Complete DrawingML preset geometry enumeration from ECMA-376 ST_ShapeType. */
13
+ const presetGeometryNames = new Set(presetGeometryTuple);
14
+ function invalidGeometry(message) {
15
+ throw new CapabilityError("invalid-geometry", message);
16
+ }
17
+ function preset(name, adjust) {
18
+ if (!presetGeometryNameSchema.safeParse(name).success) throw new CapabilityError("unsupported-geometry", `Unsupported preset geometry ${String(name)}`);
19
+ if (adjust !== void 0) {
20
+ const parsedAdjust = geometryAdjustSchema.safeParse(adjust);
21
+ if (!parsedAdjust.success) invalidGeometry(`Geometry adjust ${String(parsedAdjust.error.issues[0]?.path[0] ?? "adjust")} must be an integer DrawingML parameter`);
22
+ }
23
+ return {
24
+ type: "preset",
25
+ name,
26
+ ...adjust !== void 0 && { adjust }
27
+ };
28
+ }
29
+ const blockArcOptionsSchema = z.strictObject({
30
+ startAngle: z.number().finite(),
31
+ endAngle: z.number().finite(),
32
+ thickness: z.number().finite()
33
+ }).readonly();
34
+ /**
35
+ * Native blockArc (annular arc segment). Angles are in degrees, measured clockwise from 3 o'clock, consistent with DrawingML;
36
+ * thickness represents the ring width as a fraction of the shape's shorter side.
37
+ */
38
+ function blockArc(options) {
39
+ const parsed = blockArcOptionsSchema.safeParse(options);
40
+ if (!parsed.success) invalidGeometry(`blockArc.${String(parsed.error.issues[0]?.path[0] ?? "options")} must be a finite number`);
41
+ const angle = (degrees) => Math.round((degrees % 360 + 360) % 360 * 6e4);
42
+ return preset("blockArc", {
43
+ adj1: angle(parsed.data.startAngle),
44
+ adj2: angle(parsed.data.endAngle),
45
+ adj3: Math.round(parsed.data.thickness * 1e5)
46
+ });
47
+ }
48
+ const pathOptionsSchema = z.strictObject({
49
+ /** Dimensions of the local coordinate space, similar to an SVG viewBox starting from 0,0. */
50
+ viewBox: z.tuple([z.number().finite().positive(), z.number().finite().positive()]).readonly(),
51
+ fill: z.boolean().optional(),
52
+ stroke: z.boolean().optional(),
53
+ /** Fill rule for SVG path data; see `path`. */
54
+ fillRule: z.enum(["nonzero", "evenodd"]).optional()
55
+ }).readonly();
56
+ const pathDataSchema = z.union([z.string().refine((item) => item.trim() !== ""), z.array(z.string().refine((item) => item.trim() !== "")).min(1).readonly()]);
57
+ /**
58
+ * Creates custom geometry from SVG path data. Multiple subpaths in a single string constitute the same native path; pass an array for separately stroked paths.
59
+ *
60
+ * PPTX does not have fill rules, so different applications interpret them individually. The default `fillRule: "nonzero"` writes paths as-is;
61
+ * in all applications, inner subpaths whose direction opposes the outer contour form holes. When set to `"evenodd"`, subpaths alternate directions according to nesting
62
+ * depth, allowing applications to display even-odd fill results. Subpaths that overlap without nesting, or self-intersecting subpaths, cannot achieve consistency this way.
63
+ */
64
+ function path(data, options) {
65
+ const parsedOptions = pathOptionsSchema.safeParse(options);
66
+ if (!parsedOptions.success) {
67
+ const key = parsedOptions.error.issues[0]?.path[0];
68
+ if (key === "fill") invalidGeometry("path.fill must be a boolean");
69
+ if (key === "stroke") invalidGeometry("path.stroke must be a boolean");
70
+ if (key === "fillRule") invalidGeometry("path.fillRule must be nonzero or evenodd");
71
+ invalidGeometry("path.viewBox must consist of two finite positive numbers");
72
+ }
73
+ const parsedData = pathDataSchema.safeParse(data);
74
+ if (!parsedData.success) {
75
+ if (typeof data !== "string" && !Array.isArray(data)) invalidGeometry("path data must be an SVG string or an array of strings");
76
+ invalidGeometry("path must contain at least one non-empty SVG path");
77
+ }
78
+ const validOptions = parsedOptions.data;
79
+ const list = typeof parsedData.data === "string" ? [parsedData.data] : parsedData.data;
80
+ return {
81
+ type: "custom",
82
+ width: validOptions.viewBox[0],
83
+ height: validOptions.viewBox[1],
84
+ paths: list.map((item) => {
85
+ const commands = parseSvgPath(item);
86
+ return {
87
+ commands: validOptions.fillRule === "evenodd" ? alternateByNesting(commands) : commands,
88
+ ...validOptions.fill !== void 0 && { fill: validOptions.fill },
89
+ ...validOptions.stroke !== void 0 && { stroke: validOptions.stroke }
90
+ };
91
+ })
92
+ };
93
+ }
94
+ /** Splits subpaths by Z commands; when drawing continues after Z, it starts from the previous subpath start point. */
95
+ function subpaths(commands) {
96
+ const result = [];
97
+ let current;
98
+ let start = {
99
+ x: 0,
100
+ y: 0
101
+ };
102
+ for (const command of commands) {
103
+ if (command.op === "M") {
104
+ current = [command];
105
+ result.push(current);
106
+ start = command;
107
+ continue;
108
+ }
109
+ if (current === void 0) {
110
+ current = [{
111
+ op: "M",
112
+ x: start.x,
113
+ y: start.y
114
+ }];
115
+ result.push(current);
116
+ }
117
+ current.push(command);
118
+ if (command.op === "Z") current = void 0;
119
+ }
120
+ return result;
121
+ }
122
+ /** Represents a subpath as a polygon and samples curves. */
123
+ function outline(subpath) {
124
+ const points = [];
125
+ let x = 0;
126
+ let y = 0;
127
+ for (const command of subpath) {
128
+ if (command.op === "Z") continue;
129
+ if (command.op === "C" || command.op === "Q") for (let step = 1; step < 8; step += 1) {
130
+ const t = step / 8;
131
+ const u = 1 - t;
132
+ points.push(command.op === "C" ? {
133
+ x: u * u * u * x + 3 * u * u * t * command.x1 + 3 * u * t * t * command.x2 + t * t * t * command.x,
134
+ y: u * u * u * y + 3 * u * u * t * command.y1 + 3 * u * t * t * command.y2 + t * t * t * command.y
135
+ } : {
136
+ x: u * u * x + 2 * u * t * command.x1 + t * t * command.x,
137
+ y: u * u * y + 2 * u * t * command.y1 + t * t * command.y
138
+ });
139
+ }
140
+ points.push({
141
+ x: command.x,
142
+ y: command.y
143
+ });
144
+ x = command.x;
145
+ y = command.y;
146
+ }
147
+ return points;
148
+ }
149
+ function signedArea(points) {
150
+ let area = 0;
151
+ points.forEach((point, index) => {
152
+ const next = points[(index + 1) % points.length] ?? point;
153
+ area += point.x * next.y - next.x * point.y;
154
+ });
155
+ return area / 2;
156
+ }
157
+ function contains(polygon, point) {
158
+ let inside = false;
159
+ polygon.forEach((a, index) => {
160
+ const b = polygon[(index + polygon.length - 1) % polygon.length] ?? a;
161
+ if (a.y > point.y !== b.y > point.y && point.x < (b.x - a.x) * (point.y - a.y) / (b.y - a.y) + a.x) inside = !inside;
162
+ });
163
+ return inside;
164
+ }
165
+ /** Draws the same subpath in reverse order. */
166
+ function reversed(subpath) {
167
+ const first = subpath[0];
168
+ if (first === void 0 || first.op !== "M") return [...subpath];
169
+ const closed = subpath.at(-1)?.op === "Z";
170
+ const segments = subpath.filter((command) => command.op === "L" || command.op === "C" || command.op === "Q");
171
+ const starts = [];
172
+ let end = first;
173
+ for (const segment of segments) {
174
+ starts.push(end);
175
+ end = segment;
176
+ }
177
+ if (closed && (end.x !== first.x || end.y !== first.y)) {
178
+ segments.push({
179
+ op: "L",
180
+ x: first.x,
181
+ y: first.y
182
+ });
183
+ starts.push(end);
184
+ end = first;
185
+ }
186
+ const result = [{
187
+ op: "M",
188
+ x: end.x,
189
+ y: end.y
190
+ }];
191
+ for (let index = segments.length - 1; index >= 0; index -= 1) {
192
+ const segment = segments[index];
193
+ const to = starts[index];
194
+ if (segment === void 0 || to === void 0) continue;
195
+ if (segment.op === "C") result.push({
196
+ op: "C",
197
+ x1: segment.x2,
198
+ y1: segment.y2,
199
+ x2: segment.x1,
200
+ y2: segment.y1,
201
+ x: to.x,
202
+ y: to.y
203
+ });
204
+ else if (segment.op === "Q") result.push({
205
+ op: "Q",
206
+ x1: segment.x1,
207
+ y1: segment.y1,
208
+ x: to.x,
209
+ y: to.y
210
+ });
211
+ else result.push({
212
+ op: "L",
213
+ x: to.x,
214
+ y: to.y
215
+ });
216
+ }
217
+ if (closed) result.push({ op: "Z" });
218
+ return result;
219
+ }
220
+ /** Outer contours are drawn in one direction, holes are reversed, and islands inside holes restore outer contour direction. */
221
+ function alternateByNesting(commands) {
222
+ const parts = subpaths(commands);
223
+ const outlines = parts.map(outline);
224
+ return parts.flatMap((part, index) => {
225
+ const shape = outlines[index] ?? [];
226
+ const area = signedArea(shape);
227
+ const probe = shape[0];
228
+ if (area === 0 || probe === void 0) return part;
229
+ const depth = outlines.filter((other, otherIndex) => otherIndex !== index && other.length > 2 && contains(other, probe)).length;
230
+ return Math.sign(area) === (depth % 2 === 0 ? 1 : -1) ? part : reversed(part);
231
+ });
232
+ }
233
+ const tokenPattern = /[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/gu;
234
+ function parseSvgPath(data) {
235
+ if (typeof data !== "string" || data.trim() === "") invalidGeometry("SVG path must be a non-empty string");
236
+ const tokens = [];
237
+ let cursor = 0;
238
+ for (const match of data.matchAll(tokenPattern)) {
239
+ const index = match.index;
240
+ if (!/^[\s,]*$/u.test(data.slice(cursor, index))) invalidGeometry(`SVG path contains unsupported character: ${data.slice(cursor, index)}`);
241
+ tokens.push(match[0]);
242
+ cursor = index + match[0].length;
243
+ }
244
+ if (!/^[\s,]*$/u.test(data.slice(cursor)) || tokens.length === 0) invalidGeometry(`SVG path contains unsupported or missing parameter: ${data.slice(cursor)}`);
245
+ const commands = [];
246
+ let index = 0;
247
+ let command = "";
248
+ let x = 0;
249
+ let y = 0;
250
+ let startX = 0;
251
+ let startY = 0;
252
+ let lastControl;
253
+ const isCommand = (token) => token !== void 0 && /^[A-Za-z]$/u.test(token);
254
+ const number = () => {
255
+ const token = tokens[index];
256
+ index += 1;
257
+ if (token === void 0 || isCommand(token)) throw new Error(`Invalid SVG path data: ${data}`);
258
+ const value = Number(token);
259
+ if (!Number.isFinite(value)) invalidGeometry("SVG path coordinate must be a finite number");
260
+ return value;
261
+ };
262
+ const flag = (name) => {
263
+ const token = tokens[index];
264
+ if (token !== "0" && token !== "1") invalidGeometry(`SVG arc ${name} must be a single 0 or 1`);
265
+ index += 1;
266
+ return token === "1";
267
+ };
268
+ while (index < tokens.length) {
269
+ if (isCommand(tokens[index])) {
270
+ command = tokens[index] ?? "";
271
+ index += 1;
272
+ } else if (command === "") invalidGeometry("SVG close command Z cannot be followed by implicit parameters");
273
+ const relative = command === command.toLowerCase();
274
+ const upper = command.toUpperCase();
275
+ const ox = relative ? x : 0;
276
+ const oy = relative ? y : 0;
277
+ switch (upper) {
278
+ case "M":
279
+ x = ox + number();
280
+ y = oy + number();
281
+ startX = x;
282
+ startY = y;
283
+ commands.push({
284
+ op: "M",
285
+ x,
286
+ y
287
+ });
288
+ command = relative ? "l" : "L";
289
+ lastControl = void 0;
290
+ break;
291
+ case "L":
292
+ x = ox + number();
293
+ y = oy + number();
294
+ commands.push({
295
+ op: "L",
296
+ x,
297
+ y
298
+ });
299
+ lastControl = void 0;
300
+ break;
301
+ case "H":
302
+ x = ox + number();
303
+ commands.push({
304
+ op: "L",
305
+ x,
306
+ y
307
+ });
308
+ lastControl = void 0;
309
+ break;
310
+ case "V":
311
+ y = oy + number();
312
+ commands.push({
313
+ op: "L",
314
+ x,
315
+ y
316
+ });
317
+ lastControl = void 0;
318
+ break;
319
+ case "C": {
320
+ const x1 = ox + number();
321
+ const y1 = oy + number();
322
+ const x2 = ox + number();
323
+ const y2 = oy + number();
324
+ x = ox + number();
325
+ y = oy + number();
326
+ commands.push({
327
+ op: "C",
328
+ x1,
329
+ y1,
330
+ x2,
331
+ y2,
332
+ x,
333
+ y
334
+ });
335
+ lastControl = {
336
+ x: x2,
337
+ y: y2,
338
+ kind: "C"
339
+ };
340
+ break;
341
+ }
342
+ case "S": {
343
+ const x1 = lastControl?.kind === "C" ? 2 * x - lastControl.x : x;
344
+ const y1 = lastControl?.kind === "C" ? 2 * y - lastControl.y : y;
345
+ const x2 = ox + number();
346
+ const y2 = oy + number();
347
+ x = ox + number();
348
+ y = oy + number();
349
+ commands.push({
350
+ op: "C",
351
+ x1,
352
+ y1,
353
+ x2,
354
+ y2,
355
+ x,
356
+ y
357
+ });
358
+ lastControl = {
359
+ x: x2,
360
+ y: y2,
361
+ kind: "C"
362
+ };
363
+ break;
364
+ }
365
+ case "Q": {
366
+ const x1 = ox + number();
367
+ const y1 = oy + number();
368
+ x = ox + number();
369
+ y = oy + number();
370
+ commands.push({
371
+ op: "Q",
372
+ x1,
373
+ y1,
374
+ x,
375
+ y
376
+ });
377
+ lastControl = {
378
+ x: x1,
379
+ y: y1,
380
+ kind: "Q"
381
+ };
382
+ break;
383
+ }
384
+ case "T": {
385
+ const x1 = lastControl?.kind === "Q" ? 2 * x - lastControl.x : x;
386
+ const y1 = lastControl?.kind === "Q" ? 2 * y - lastControl.y : y;
387
+ x = ox + number();
388
+ y = oy + number();
389
+ commands.push({
390
+ op: "Q",
391
+ x1,
392
+ y1,
393
+ x,
394
+ y
395
+ });
396
+ lastControl = {
397
+ x: x1,
398
+ y: y1,
399
+ kind: "Q"
400
+ };
401
+ break;
402
+ }
403
+ case "A": {
404
+ const rx = number();
405
+ const ry = number();
406
+ const rotation = number();
407
+ const largeArc = flag("large-arc-flag");
408
+ const sweep = flag("sweep-flag");
409
+ const endX = ox + number();
410
+ const endY = oy + number();
411
+ commands.push(...arcToCubics(x, y, rx, ry, rotation, largeArc, sweep, endX, endY));
412
+ x = endX;
413
+ y = endY;
414
+ lastControl = void 0;
415
+ break;
416
+ }
417
+ case "Z":
418
+ commands.push({ op: "Z" });
419
+ x = startX;
420
+ y = startY;
421
+ lastControl = void 0;
422
+ command = "";
423
+ break;
424
+ default: invalidGeometry(`SVG path command ${command} is not supported`);
425
+ }
426
+ }
427
+ if (commands[0]?.op !== "M") invalidGeometry("SVG path must start with move command M");
428
+ return commands;
429
+ }
430
+ /** Converts elliptical arcs to cubic Bezier curves per SVG implementation note F.6. */
431
+ function arcToCubics(x1, y1, rxInput, ryInput, rotationDegrees, largeArc, sweep, x2, y2) {
432
+ if (x1 === x2 && y1 === y2) return [];
433
+ if (rxInput === 0 || ryInput === 0) return [{
434
+ op: "L",
435
+ x: x2,
436
+ y: y2
437
+ }];
438
+ const phi = rotationDegrees * Math.PI / 180;
439
+ const cos = Math.cos(phi);
440
+ const sin = Math.sin(phi);
441
+ const dx = (x1 - x2) / 2;
442
+ const dy = (y1 - y2) / 2;
443
+ const x1p = cos * dx + sin * dy;
444
+ const y1p = -sin * dx + cos * dy;
445
+ let rx = Math.abs(rxInput);
446
+ let ry = Math.abs(ryInput);
447
+ const lambda = x1p * x1p / (rx * rx) + y1p * y1p / (ry * ry);
448
+ if (lambda > 1) {
449
+ rx *= Math.sqrt(lambda);
450
+ ry *= Math.sqrt(lambda);
451
+ }
452
+ const numerator = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
453
+ const denominator = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
454
+ const factor = (largeArc === sweep ? -1 : 1) * Math.sqrt(Math.max(0, numerator / denominator));
455
+ const cxp = factor * rx * y1p / ry;
456
+ const cyp = -factor * ry * x1p / rx;
457
+ const cx = cos * cxp - sin * cyp + (x1 + x2) / 2;
458
+ const cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
459
+ const angle = (ux, uy, vx, vy) => {
460
+ const sign = ux * vy - uy * vx < 0 ? -1 : 1;
461
+ const dot = (ux * vx + uy * vy) / (Math.hypot(ux, uy) * Math.hypot(vx, vy));
462
+ return sign * Math.acos(Math.min(1, Math.max(-1, dot)));
463
+ };
464
+ const theta1 = angle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
465
+ let delta = angle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry);
466
+ if (!sweep && delta > 0) delta -= 2 * Math.PI;
467
+ if (sweep && delta < 0) delta += 2 * Math.PI;
468
+ const segments = Math.ceil(Math.abs(delta) / (Math.PI / 2));
469
+ const step = delta / segments;
470
+ const kappa = 4 / 3 * Math.tan(step / 4);
471
+ const point = (theta) => ({
472
+ x: cx + rx * Math.cos(theta) * cos - ry * Math.sin(theta) * sin,
473
+ y: cy + rx * Math.cos(theta) * sin + ry * Math.sin(theta) * cos
474
+ });
475
+ const derivative = (theta) => ({
476
+ x: -rx * Math.sin(theta) * cos - ry * Math.cos(theta) * sin,
477
+ y: -rx * Math.sin(theta) * sin + ry * Math.cos(theta) * cos
478
+ });
479
+ const result = [];
480
+ for (let segment = 0; segment < segments; segment += 1) {
481
+ const a = theta1 + segment * step;
482
+ const b = a + step;
483
+ const start = point(a);
484
+ const end = segment === segments - 1 ? {
485
+ x: x2,
486
+ y: y2
487
+ } : point(b);
488
+ const startDerivative = derivative(a);
489
+ const endDerivative = derivative(b);
490
+ result.push({
491
+ op: "C",
492
+ x1: start.x + kappa * startDerivative.x,
493
+ y1: start.y + kappa * startDerivative.y,
494
+ x2: end.x - kappa * endDerivative.x,
495
+ y2: end.y - kappa * endDerivative.y,
496
+ x: end.x,
497
+ y: end.y
498
+ });
499
+ }
500
+ return result;
501
+ }
502
+ function isRecord(value) {
503
+ return typeof value === "object" && value !== null && !Array.isArray(value);
504
+ }
505
+ function finiteGeometryNumber(value, label) {
506
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new CapabilityError("invalid-visual-style", `${label} must be a finite number`);
507
+ return value;
508
+ }
509
+ function pointUnit(value, label) {
510
+ const coordinate = Math.round(finiteGeometryNumber(value, label) * 1e3);
511
+ if (!Number.isSafeInteger(coordinate) || Math.abs(coordinate) > 2147483647) invalidGeometry(`${label} exceeds DrawingML path coordinate range after conversion`);
512
+ return String(coordinate);
513
+ }
514
+ function validatePathCommand(command) {
515
+ switch (command.op) {
516
+ case "M":
517
+ case "L":
518
+ pointUnit(command.x, "path.x");
519
+ pointUnit(command.y, "path.y");
520
+ return;
521
+ case "C":
522
+ pointUnit(command.x1, "path.x1");
523
+ pointUnit(command.y1, "path.y1");
524
+ pointUnit(command.x2, "path.x2");
525
+ pointUnit(command.y2, "path.y2");
526
+ pointUnit(command.x, "path.x");
527
+ pointUnit(command.y, "path.y");
528
+ return;
529
+ case "Q":
530
+ pointUnit(command.x1, "path.x1");
531
+ pointUnit(command.y1, "path.y1");
532
+ pointUnit(command.x, "path.x");
533
+ pointUnit(command.y, "path.y");
534
+ return;
535
+ case "Z": return;
536
+ default: invalidGeometry("Custom path contains unsupported command");
537
+ }
538
+ }
539
+ /** Validates and resolves author Geometry (+ optional borderRadius) into a closed ResolvedGeometry model. */
540
+ function resolveGeometry(options) {
541
+ const { geometry: value, borderRadius: radius, box } = options;
542
+ const warnings = [];
543
+ if (isRecord(value) && value["type"] === "custom") {
544
+ if (radius !== void 0 && radius > 0) throw new CapabilityError("unsupported-style-combination", "borderRadius cannot be used together with custom geometry");
545
+ const parsedCustom = customGeometrySchema.safeParse(value);
546
+ if (!parsedCustom.success) {
547
+ const issue = parsedCustom.error.issues[0];
548
+ if (issue?.path[0] === "width" || issue?.path[0] === "height") {
549
+ if (typeof value[issue.path[0]] !== "number" || !Number.isFinite(value[issue.path[0]])) finiteGeometryNumber(value[issue.path[0]], `geometry.${issue.path[0]}`);
550
+ invalidGeometry("Custom geometry must have a positive viewBox and at least one path");
551
+ }
552
+ invalidGeometry(issue?.message ?? "Custom geometry must have a positive viewBox and at least one path");
553
+ }
554
+ const custom = parsedCustom.data;
555
+ const widthUnits = pointUnit(custom.width, "geometry.width");
556
+ const heightUnits = pointUnit(custom.height, "geometry.height");
557
+ if (Number(widthUnits) === 0 || Number(heightUnits) === 0) invalidGeometry("Custom geometry viewBox must retain positive width and height in path coordinate space after conversion");
558
+ const resolvedPaths = custom.paths.map((item) => {
559
+ for (const command of item.commands) validatePathCommand(command);
560
+ return {
561
+ commands: item.commands,
562
+ fill: item.fill ?? true,
563
+ stroke: item.stroke ?? true
564
+ };
565
+ });
566
+ return {
567
+ geometry: {
568
+ kind: "custom",
569
+ width: custom.width,
570
+ height: custom.height,
571
+ paths: resolvedPaths
572
+ },
573
+ name: "custom",
574
+ warnings
575
+ };
576
+ }
577
+ let rawName;
578
+ const adjust = {};
579
+ if (value === void 0) rawName = radius !== void 0 && radius > 0 ? "roundRect" : "rect";
580
+ else if (typeof value === "string") rawName = value;
581
+ else if (isRecord(value) && value["type"] === "preset" && typeof value["name"] === "string") {
582
+ rawName = value["name"];
583
+ if (value["adjust"] !== void 0) {
584
+ if (!isRecord(value["adjust"])) invalidGeometry("preset.adjust must be an object");
585
+ const parsedAdjust = geometryAdjustSchema.safeParse(value["adjust"]);
586
+ if (!parsedAdjust.success) invalidGeometry(`preset.adjust.${String(parsedAdjust.error.issues[0]?.path[0] ?? "adjust")} must be a finite integer`);
587
+ Object.assign(adjust, parsedAdjust.data);
588
+ }
589
+ } else invalidGeometry("geometry must be a preset name, preset(...), or custom path");
590
+ const parsedPresetName = presetGeometryNameSchema.safeParse(rawName);
591
+ if (!parsedPresetName.success) throw new CapabilityError("unsupported-geometry", `Unsupported preset geometry ${rawName}`);
592
+ let name = parsedPresetName.data;
593
+ if (radius !== void 0 && radius > 0) {
594
+ if (name !== "rect" && name !== "roundRect") throw new CapabilityError("unsupported-style-combination", "borderRadius is only applicable to rect or roundRect geometry");
595
+ name = "roundRect";
596
+ if (adjust["adj"] === void 0) {
597
+ const raw = Math.round(radius / Math.min(box.width, box.height) * 1e5);
598
+ adjust["adj"] = raw;
599
+ if (raw > 5e4) warnings.push({
600
+ code: "geometry-adjustment-range",
601
+ message: "borderRadius exceeds half of the shorter side; preserved original radius and wrote native adjust value"
602
+ });
603
+ }
604
+ }
605
+ for (const [key, amount] of Object.entries(adjust)) if (name === "blockArc" && ((key === "adj1" || key === "adj2") && (amount < 0 || amount > 216e5) || key === "adj3" && (amount < 0 || amount > 5e4))) warnings.push({
606
+ code: "geometry-adjustment-range",
607
+ message: `blockArc.${key} exceeds common preset range; preserved original adjust value`
608
+ });
609
+ return {
610
+ geometry: {
611
+ kind: "preset",
612
+ name,
613
+ adjust
614
+ },
615
+ name,
616
+ warnings
617
+ };
618
+ }
619
+ function pathCommandXml(command) {
620
+ switch (command.op) {
621
+ case "M": return `<a:moveTo><a:pt x="${pointUnit(command.x, "path.x")}" y="${pointUnit(command.y, "path.y")}"/></a:moveTo>`;
622
+ case "L": return `<a:lnTo><a:pt x="${pointUnit(command.x, "path.x")}" y="${pointUnit(command.y, "path.y")}"/></a:lnTo>`;
623
+ case "C": return `<a:cubicBezTo><a:pt x="${pointUnit(command.x1, "path.x1")}" y="${pointUnit(command.y1, "path.y1")}"/><a:pt x="${pointUnit(command.x2, "path.x2")}" y="${pointUnit(command.y2, "path.y2")}"/><a:pt x="${pointUnit(command.x, "path.x")}" y="${pointUnit(command.y, "path.y")}"/></a:cubicBezTo>`;
624
+ case "Q": return `<a:quadBezTo><a:pt x="${pointUnit(command.x1, "path.x1")}" y="${pointUnit(command.y1, "path.y1")}"/><a:pt x="${pointUnit(command.x, "path.x")}" y="${pointUnit(command.y, "path.y")}"/></a:quadBezTo>`;
625
+ case "Z": return "<a:close/>";
626
+ default: return command;
627
+ }
628
+ }
629
+ /** Exhaustively serializes a ResolvedGeometry to DrawingML <a:prstGeom> or <a:custGeom>. */
630
+ function resolvedGeometryXml(geometry) {
631
+ switch (geometry.kind) {
632
+ case "preset": {
633
+ const values = Object.entries(geometry.adjust).map(([key, amount]) => `<a:gd name="${key}" fmla="val ${amount}"/>`).join("");
634
+ return `<a:prstGeom prst="${geometry.name}"><a:avLst>${values}</a:avLst></a:prstGeom>`;
635
+ }
636
+ case "custom": {
637
+ const widthUnits = pointUnit(geometry.width, "geometry.width");
638
+ const heightUnits = pointUnit(geometry.height, "geometry.height");
639
+ return `<a:custGeom><a:avLst/><a:gdLst/><a:ahLst/><a:cxnLst/><a:rect l="l" t="t" r="r" b="b"/><a:pathLst>${geometry.paths.map((pathItem) => {
640
+ const commands = pathItem.commands.map(pathCommandXml).join("");
641
+ return `<a:path w="${widthUnits}" h="${heightUnits}"${pathItem.fill ? "" : " fill=\"none\""}${pathItem.stroke ? "" : " stroke=\"0\""}>${commands}</a:path>`;
642
+ }).join("")}</a:pathLst></a:custGeom>`;
643
+ }
644
+ default: return geometry;
645
+ }
646
+ }
647
+ const drawingAngleToRad = (ang) => ang / 6e4 * (Math.PI / 180);
648
+ const radToDrawingAngle = (rad) => rad * (180 / Math.PI) * 6e4;
649
+ function formatSvgCoord(value) {
650
+ if (Object.is(value, -0) || value === 0) return 0;
651
+ return Math.round(value * 1e6) / 1e6;
652
+ }
653
+ function commandsToSvgD(commands) {
654
+ return commands.map((command) => {
655
+ switch (command.op) {
656
+ case "Z": return "Z";
657
+ case "M":
658
+ case "L": return `${command.op}${formatSvgCoord(command.x)} ${formatSvgCoord(command.y)}`;
659
+ case "Q": return `Q${formatSvgCoord(command.x1)} ${formatSvgCoord(command.y1)} ${formatSvgCoord(command.x)} ${formatSvgCoord(command.y)}`;
660
+ case "C": return `C${formatSvgCoord(command.x1)} ${formatSvgCoord(command.y1)} ${formatSvgCoord(command.x2)} ${formatSvgCoord(command.y2)} ${formatSvgCoord(command.x)} ${formatSvgCoord(command.y)}`;
661
+ default: return command;
662
+ }
663
+ }).join(" ");
664
+ }
665
+ /**
666
+ * Unwraps the DrawingML polar angle onto the continuous eccentric parameter angle of an ellipse
667
+ * with semi-axes (rx, ry), preserving exact winding across arbitrary sweep angles.
668
+ */
669
+ function eccentricAngle(theta, rx, ry) {
670
+ if (rx === ry) return theta;
671
+ const base = Math.atan2(rx * Math.sin(theta), ry * Math.cos(theta));
672
+ return base + 2 * Math.PI * Math.round((theta - base) / (2 * Math.PI));
673
+ }
674
+ function drawingMlArcToLocalCubics(curX, curY, wR, hR, stAng, swAng) {
675
+ if (swAng === 0) return {
676
+ commands: [],
677
+ endX: curX,
678
+ endY: curY
679
+ };
680
+ const rx = Math.max(0, wR);
681
+ const ry = Math.max(0, hR);
682
+ if (rx === 0 && ry === 0) return {
683
+ commands: [],
684
+ endX: curX,
685
+ endY: curY
686
+ };
687
+ const theta1 = drawingAngleToRad(stAng);
688
+ const theta2 = theta1 + drawingAngleToRad(swAng);
689
+ if (rx === 0 || ry === 0) {
690
+ const phi1 = rx === 0 ? Math.sin(theta1) >= 0 ? Math.PI / 2 : -Math.PI / 2 : Math.cos(theta1) >= 0 ? 0 : Math.PI;
691
+ const phi2 = rx === 0 ? Math.sin(theta2) >= 0 ? Math.PI / 2 : -Math.PI / 2 : Math.cos(theta2) >= 0 ? 0 : Math.PI;
692
+ const cx = curX - rx * Math.cos(phi1);
693
+ const cy = curY - ry * Math.sin(phi1);
694
+ const endX = cx + rx * Math.cos(phi2);
695
+ const endY = cy + ry * Math.sin(phi2);
696
+ return {
697
+ commands: [{
698
+ op: "L",
699
+ x: endX,
700
+ y: endY
701
+ }],
702
+ endX,
703
+ endY
704
+ };
705
+ }
706
+ const phi1 = eccentricAngle(theta1, rx, ry);
707
+ const phi2 = eccentricAngle(theta2, rx, ry);
708
+ const deltaPhi = phi2 - phi1;
709
+ const cx = curX - rx * Math.cos(phi1);
710
+ const cy = curY - ry * Math.sin(phi1);
711
+ const segments = Math.max(1, Math.ceil(Math.abs(deltaPhi) / (Math.PI / 2)));
712
+ const step = deltaPhi / segments;
713
+ const kappa = 4 / 3 * Math.tan(step / 4);
714
+ const result = [];
715
+ for (let segment = 0; segment < segments; segment += 1) {
716
+ const a = phi1 + segment * step;
717
+ const b = a + step;
718
+ const paX = cx + rx * Math.cos(a);
719
+ const paY = cy + ry * Math.sin(a);
720
+ const daX = -rx * Math.sin(a);
721
+ const daY = ry * Math.cos(a);
722
+ const pbX = cx + rx * Math.cos(b);
723
+ const pbY = cy + ry * Math.sin(b);
724
+ const dbX = -rx * Math.sin(b);
725
+ const dbY = ry * Math.cos(b);
726
+ result.push({
727
+ op: "C",
728
+ x1: paX + kappa * daX,
729
+ y1: paY + kappa * daY,
730
+ x2: pbX - kappa * dbX,
731
+ y2: pbY - kappa * dbY,
732
+ x: pbX,
733
+ y: pbY
734
+ });
735
+ }
736
+ return {
737
+ commands: result,
738
+ endX: cx + rx * Math.cos(phi2),
739
+ endY: cy + ry * Math.sin(phi2)
740
+ };
741
+ }
742
+ function evaluatePresetGeometry(name, adjust, box) {
743
+ const def = presetDefinitions[name];
744
+ const W = Math.max(1, pxToEmu(box.width));
745
+ const H = Math.max(1, pxToEmu(box.height));
746
+ const ss = Math.min(W, H);
747
+ const ls = Math.max(W, H);
748
+ const builtins = {
749
+ w: W,
750
+ h: H,
751
+ l: 0,
752
+ t: 0,
753
+ r: W,
754
+ b: H,
755
+ hc: W / 2,
756
+ vc: H / 2,
757
+ ss,
758
+ ls,
759
+ cd2: 108e5,
760
+ cd4: 54e5,
761
+ cd8: 27e5,
762
+ "3cd4": 162e5,
763
+ "3cd8": 81e5,
764
+ "5cd8": 135e5,
765
+ "7cd8": 189e5
766
+ };
767
+ const env = /* @__PURE__ */ new Map();
768
+ const arg = (token) => {
769
+ const bound = env.get(token);
770
+ if (bound !== void 0) return bound;
771
+ const builtin = builtins[token];
772
+ if (builtin !== void 0) return builtin;
773
+ const denomMatch = /^(wd|hd|ssd)(\d+)$/u.exec(token);
774
+ if (denomMatch !== null) {
775
+ const kind = denomMatch[1];
776
+ const divisor = Number(denomMatch[2]);
777
+ return kind === "wd" ? W / divisor : kind === "hd" ? H / divisor : ss / divisor;
778
+ }
779
+ const numeric = Number(token);
780
+ if (!Number.isFinite(numeric)) invalidGeometry(`Preset ${name} references unknown guide token ${token}`);
781
+ return numeric;
782
+ };
783
+ const evalFormula = (formula) => {
784
+ const parts = formula.trim().split(/\s+/u);
785
+ const op = parts[0];
786
+ const x = parts[1] === void 0 ? 0 : arg(parts[1]);
787
+ const y = parts[2] === void 0 ? 0 : arg(parts[2]);
788
+ const z = parts[3] === void 0 ? 0 : arg(parts[3]);
789
+ switch (op) {
790
+ case "val": return x;
791
+ case "*/": return z === 0 ? 0 : x * y / z;
792
+ case "+-": return x + y - z;
793
+ case "+/": return z === 0 ? 0 : (x + y) / z;
794
+ case "?:":
795
+ case "ifelse": return x > 0 ? y : z;
796
+ case "abs": return Math.abs(x);
797
+ case "at2": return radToDrawingAngle(Math.atan2(y, x));
798
+ case "cat2": return x * Math.cos(Math.atan2(z, y));
799
+ case "sat2": return x * Math.sin(Math.atan2(z, y));
800
+ case "cos": return x * Math.cos(drawingAngleToRad(y));
801
+ case "sin": return x * Math.sin(drawingAngleToRad(y));
802
+ case "tan": return x * Math.tan(drawingAngleToRad(y));
803
+ case "max": return Math.max(x, y);
804
+ case "min": return Math.min(x, y);
805
+ case "mod": return Math.sqrt(x * x + y * y + z * z);
806
+ case "pin": return y < x ? x : y > z ? z : y;
807
+ case "sqrt": return x <= 0 ? 0 : Math.sqrt(x);
808
+ default: invalidGeometry(`Preset ${name} uses unsupported guide operator ${op}`);
809
+ }
810
+ };
811
+ if (def.av !== void 0) for (const [key, formula] of def.av) env.set(key, evalFormula(formula));
812
+ for (const [key, value] of Object.entries(adjust)) env.set(key, value);
813
+ if (def.gd !== void 0) for (const [key, formula] of def.gd) env.set(key, evalFormula(formula));
814
+ const rectTokens = def.rect ?? [
815
+ "l",
816
+ "t",
817
+ "r",
818
+ "b"
819
+ ];
820
+ const rectL = arg(rectTokens[0]);
821
+ const rectT = arg(rectTokens[1]);
822
+ const rectR = arg(rectTokens[2]);
823
+ const rectB = arg(rectTokens[3]);
824
+ const textRect = {
825
+ x: box.x + rectL / W * box.width,
826
+ y: box.y + rectT / H * box.height,
827
+ width: Math.max(0, (rectR - rectL) / W * box.width),
828
+ height: Math.max(0, (rectB - rectT) / H * box.height)
829
+ };
830
+ return {
831
+ paths: def.paths.map((pathDef) => {
832
+ const pathW = pathDef.w ?? W;
833
+ const pathH = pathDef.h ?? H;
834
+ const scaleX = box.width / pathW;
835
+ const scaleY = box.height / pathH;
836
+ const toPageX = (lx) => box.x + lx * scaleX;
837
+ const toPageY = (ly) => box.y + ly * scaleY;
838
+ const mapCmdToPage = (cmd) => {
839
+ switch (cmd.op) {
840
+ case "Z": return cmd;
841
+ case "M":
842
+ case "L": return {
843
+ op: cmd.op,
844
+ x: toPageX(cmd.x),
845
+ y: toPageY(cmd.y)
846
+ };
847
+ case "Q": return {
848
+ op: "Q",
849
+ x1: toPageX(cmd.x1),
850
+ y1: toPageY(cmd.y1),
851
+ x: toPageX(cmd.x),
852
+ y: toPageY(cmd.y)
853
+ };
854
+ case "C": return {
855
+ op: "C",
856
+ x1: toPageX(cmd.x1),
857
+ y1: toPageY(cmd.y1),
858
+ x2: toPageX(cmd.x2),
859
+ y2: toPageY(cmd.y2),
860
+ x: toPageX(cmd.x),
861
+ y: toPageY(cmd.y)
862
+ };
863
+ }
864
+ };
865
+ const commands = [];
866
+ let curX = 0;
867
+ let curY = 0;
868
+ let subStartX = 0;
869
+ let subStartY = 0;
870
+ for (const cmd of pathDef.cmds) switch (cmd[0]) {
871
+ case "M":
872
+ curX = arg(cmd[1]);
873
+ curY = arg(cmd[2]);
874
+ subStartX = curX;
875
+ subStartY = curY;
876
+ commands.push({
877
+ op: "M",
878
+ x: toPageX(curX),
879
+ y: toPageY(curY)
880
+ });
881
+ break;
882
+ case "L":
883
+ curX = arg(cmd[1]);
884
+ curY = arg(cmd[2]);
885
+ commands.push({
886
+ op: "L",
887
+ x: toPageX(curX),
888
+ y: toPageY(curY)
889
+ });
890
+ break;
891
+ case "Q": {
892
+ const x1 = arg(cmd[1]);
893
+ const y1 = arg(cmd[2]);
894
+ curX = arg(cmd[3]);
895
+ curY = arg(cmd[4]);
896
+ commands.push({
897
+ op: "Q",
898
+ x1: toPageX(x1),
899
+ y1: toPageY(y1),
900
+ x: toPageX(curX),
901
+ y: toPageY(curY)
902
+ });
903
+ break;
904
+ }
905
+ case "C": {
906
+ const x1 = arg(cmd[1]);
907
+ const y1 = arg(cmd[2]);
908
+ const x2 = arg(cmd[3]);
909
+ const y2 = arg(cmd[4]);
910
+ curX = arg(cmd[5]);
911
+ curY = arg(cmd[6]);
912
+ commands.push({
913
+ op: "C",
914
+ x1: toPageX(x1),
915
+ y1: toPageY(y1),
916
+ x2: toPageX(x2),
917
+ y2: toPageY(y2),
918
+ x: toPageX(curX),
919
+ y: toPageY(curY)
920
+ });
921
+ break;
922
+ }
923
+ case "A": {
924
+ const wR = arg(cmd[1]);
925
+ const hR = arg(cmd[2]);
926
+ const stAng = arg(cmd[3]);
927
+ const swAng = arg(cmd[4]);
928
+ const arc = drawingMlArcToLocalCubics(curX, curY, wR, hR, stAng, swAng);
929
+ for (const cubic of arc.commands) commands.push(mapCmdToPage(cubic));
930
+ curX = arc.endX;
931
+ curY = arc.endY;
932
+ break;
933
+ }
934
+ case "Z":
935
+ curX = subStartX;
936
+ curY = subStartY;
937
+ commands.push({ op: "Z" });
938
+ }
939
+ return {
940
+ d: commandsToSvgD(commands),
941
+ commands,
942
+ fillMode: pathDef.fill ?? "norm",
943
+ stroke: pathDef.stroke ?? true
944
+ };
945
+ }),
946
+ textRect
947
+ };
948
+ }
949
+ function evaluateCustomGeometry(geometry, box) {
950
+ const mapX = (value) => box.x + value * box.width / geometry.width;
951
+ const mapY = (value) => box.y + value * box.height / geometry.height;
952
+ return {
953
+ paths: geometry.paths.map((pathItem) => {
954
+ const commands = pathItem.commands.map((command) => {
955
+ switch (command.op) {
956
+ case "Z": return command;
957
+ case "M":
958
+ case "L": return {
959
+ op: command.op,
960
+ x: mapX(command.x),
961
+ y: mapY(command.y)
962
+ };
963
+ case "Q": return {
964
+ op: "Q",
965
+ x1: mapX(command.x1),
966
+ y1: mapY(command.y1),
967
+ x: mapX(command.x),
968
+ y: mapY(command.y)
969
+ };
970
+ case "C": return {
971
+ op: "C",
972
+ x1: mapX(command.x1),
973
+ y1: mapY(command.y1),
974
+ x2: mapX(command.x2),
975
+ y2: mapY(command.y2),
976
+ x: mapX(command.x),
977
+ y: mapY(command.y)
978
+ };
979
+ default: return command;
980
+ }
981
+ });
982
+ return {
983
+ d: commandsToSvgD(commands),
984
+ commands,
985
+ fillMode: pathItem.fill ? "norm" : "none",
986
+ stroke: pathItem.stroke
987
+ };
988
+ }),
989
+ textRect: box
990
+ };
991
+ }
992
+ /** Exhaustively evaluates any ResolvedGeometry into page-space SVG paths and embedded textRect. */
993
+ function evaluateGeometry(geometry, box) {
994
+ switch (geometry.kind) {
995
+ case "preset": return evaluatePresetGeometry(geometry.name, geometry.adjust, box);
996
+ case "custom": return evaluateCustomGeometry(geometry, box);
997
+ default: return geometry;
998
+ }
999
+ }
1000
+ /** Modulates RGB hex color lightness using DrawingML HSL lumMod/lumOff rules. */
1001
+ function shadeHex(hex, lumMod, lumOff) {
1002
+ const [r, g, b] = [
1003
+ 0,
1004
+ 2,
1005
+ 4
1006
+ ].map((start) => Number.parseInt(hex.slice(start, start + 2), 16) / 255);
1007
+ const max = Math.max(r, g, b);
1008
+ const min = Math.min(r, g, b);
1009
+ const lightness = (max + min) / 2;
1010
+ const delta = max - min;
1011
+ const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
1012
+ const hue = delta === 0 ? 0 : max === r ? ((g - b) / delta + 6) % 6 : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4;
1013
+ const shaded = Math.min(1, Math.max(0, lightness * lumMod + lumOff));
1014
+ const chroma = (1 - Math.abs(2 * shaded - 1)) * saturation;
1015
+ const x = chroma * (1 - Math.abs(hue % 2 - 1));
1016
+ const m = shaded - chroma / 2;
1017
+ const [r1, g1, b1] = hue < 1 ? [
1018
+ chroma,
1019
+ x,
1020
+ 0
1021
+ ] : hue < 2 ? [
1022
+ x,
1023
+ chroma,
1024
+ 0
1025
+ ] : hue < 3 ? [
1026
+ 0,
1027
+ chroma,
1028
+ x
1029
+ ] : hue < 4 ? [
1030
+ 0,
1031
+ x,
1032
+ chroma
1033
+ ] : hue < 5 ? [
1034
+ x,
1035
+ 0,
1036
+ chroma
1037
+ ] : [
1038
+ chroma,
1039
+ 0,
1040
+ x
1041
+ ];
1042
+ return [
1043
+ r1,
1044
+ g1,
1045
+ b1
1046
+ ].map((channel) => Math.round((channel + m) * 255).toString(16).padStart(2, "0")).join("").toUpperCase();
1047
+ }
1048
+ const PresetGeomAttrSchema = z.object({ prst: z.string().min(1) });
1049
+ const AdjustGuideAttrSchema = z.object({
1050
+ name: geometryAdjustKeySchema,
1051
+ fmla: z.string().regex(/^val\s+(-?\d+)$/u)
1052
+ });
1053
+ const CustomPathAttrSchema = z.object({
1054
+ w: ooxmlPositiveIntSchema.optional(),
1055
+ h: ooxmlPositiveIntSchema.optional(),
1056
+ fill: z.enum([
1057
+ "none",
1058
+ "norm",
1059
+ "lighten",
1060
+ "lightenLess",
1061
+ "darken",
1062
+ "darkenLess"
1063
+ ]).optional(),
1064
+ stroke: ooxmlBoolSchema.optional()
1065
+ });
1066
+ const CustomPtAttrSchema = z.object({
1067
+ x: ooxmlIntSchema,
1068
+ y: ooxmlIntSchema
1069
+ });
1070
+ const CustomArcAttrSchema = z.object({
1071
+ wR: ooxmlIntSchema,
1072
+ hR: ooxmlIntSchema,
1073
+ stAng: ooxmlIntSchema,
1074
+ swAng: ooxmlIntSchema
1075
+ });
1076
+ /** Reads DrawingML `<a:prstGeom>` (and `<a:avLst>`) into author `Geometry`, emitting localized diagnostics on invalid/unsupported values. */
1077
+ function readPresetGeometryXml(prstGeomCursor, location, diagnostics) {
1078
+ const raw = prstGeomCursor.attrsObject(["prst"]);
1079
+ const parsedAttr = PresetGeomAttrSchema.safeParse(raw);
1080
+ if (!parsedAttr.success) {
1081
+ diagnostics.push({
1082
+ code: "invalid-xml-value",
1083
+ category: "corrupt-input",
1084
+ disposition: "recovered",
1085
+ location: {
1086
+ ...location,
1087
+ xpath: prstGeomCursor.xpath
1088
+ },
1089
+ attributeOrElement: "a:prstGeom/@prst",
1090
+ rawValue: raw["prst"] ?? ""
1091
+ });
1092
+ prstGeomCursor.ignoreEmptyChild(A_NS, "avLst");
1093
+ return "rect";
1094
+ }
1095
+ const parsedName = presetGeometryNameSchema.safeParse(parsedAttr.data.prst);
1096
+ if (!parsedName.success) {
1097
+ diagnostics.push({
1098
+ code: "unsupported-mechanism",
1099
+ category: "unsupported",
1100
+ disposition: "omitted",
1101
+ location: {
1102
+ ...location,
1103
+ xpath: prstGeomCursor.xpath
1104
+ },
1105
+ namespaceUri: A_NS,
1106
+ localName: "prstGeom",
1107
+ mechanismHint: `preset:${parsedAttr.data.prst}`
1108
+ });
1109
+ prstGeomCursor.ignoreEmptyChild(A_NS, "avLst");
1110
+ return "rect";
1111
+ }
1112
+ const adjust = {};
1113
+ const avLst = prstGeomCursor.child(A_NS, "avLst");
1114
+ if (avLst !== void 0) for (const gd of avLst.children(A_NS, "gd")) {
1115
+ const rawGd = gd.attrsObject(["name", "fmla"]);
1116
+ const parsedGd = AdjustGuideAttrSchema.safeParse(rawGd);
1117
+ if (!parsedGd.success) {
1118
+ diagnostics.push({
1119
+ code: "invalid-xml-value",
1120
+ category: "corrupt-input",
1121
+ disposition: "omitted",
1122
+ location: {
1123
+ ...location,
1124
+ xpath: gd.xpath
1125
+ },
1126
+ attributeOrElement: "a:gd",
1127
+ rawValue: JSON.stringify(rawGd)
1128
+ });
1129
+ continue;
1130
+ }
1131
+ const match = /^val\s+(-?\d+)$/u.exec(parsedGd.data.fmla);
1132
+ if (match !== null) {
1133
+ const value = Number(match[1]);
1134
+ if (Number.isSafeInteger(value)) adjust[parsedGd.data.name] = value;
1135
+ }
1136
+ }
1137
+ return Object.keys(adjust).length === 0 ? parsedName.data : {
1138
+ type: "preset",
1139
+ name: parsedName.data,
1140
+ adjust
1141
+ };
1142
+ }
1143
+ function readCustomPoint(ptCursor, location, diagnostics) {
1144
+ const raw = ptCursor.attrsObject(["x", "y"]);
1145
+ const parsed = CustomPtAttrSchema.safeParse(raw);
1146
+ if (!parsed.success) {
1147
+ const isFormulaRef = raw["x"] !== void 0 && !/^-?\d+$/u.test(raw["x"]) || raw["y"] !== void 0 && !/^-?\d+$/u.test(raw["y"]);
1148
+ diagnostics.push(isFormulaRef ? {
1149
+ code: "unsupported-mechanism",
1150
+ category: "unsupported",
1151
+ disposition: "omitted",
1152
+ location: {
1153
+ ...location,
1154
+ xpath: ptCursor.xpath
1155
+ },
1156
+ namespaceUri: A_NS,
1157
+ localName: "pt",
1158
+ mechanismHint: "custom-geometry-guide-reference"
1159
+ } : {
1160
+ code: "invalid-xml-value",
1161
+ category: "corrupt-input",
1162
+ disposition: "omitted",
1163
+ location: {
1164
+ ...location,
1165
+ xpath: ptCursor.xpath
1166
+ },
1167
+ attributeOrElement: "a:pt",
1168
+ rawValue: JSON.stringify(raw)
1169
+ });
1170
+ return;
1171
+ }
1172
+ return {
1173
+ x: parsed.data.x / 1e3,
1174
+ y: parsed.data.y / 1e3
1175
+ };
1176
+ }
1177
+ /** Reads DrawingML `<a:custGeom>` into `CustomGeometry`, reporting localized diagnostics on unsupported guide formulas or invalid paths. */
1178
+ function readCustomGeometryXml(custGeomCursor, fallbackExtentUnits, location, diagnostics) {
1179
+ custGeomCursor.ignoreEmptyChild(A_NS, "avLst");
1180
+ const gdLst = custGeomCursor.child(A_NS, "gdLst");
1181
+ if (gdLst !== void 0) for (const gd of gdLst.children(A_NS, "gd")) {
1182
+ gd.consumeAttr("name");
1183
+ gd.consumeAttr("fmla");
1184
+ }
1185
+ custGeomCursor.ignoreEmptyChild(A_NS, "ahLst");
1186
+ custGeomCursor.ignoreEmptyChild(A_NS, "cxnLst");
1187
+ const rect = custGeomCursor.child(A_NS, "rect");
1188
+ if (rect !== void 0) {
1189
+ rect.consumeAttr("l");
1190
+ rect.consumeAttr("t");
1191
+ rect.consumeAttr("r");
1192
+ rect.consumeAttr("b");
1193
+ }
1194
+ const pathLst = custGeomCursor.child(A_NS, "pathLst");
1195
+ if (pathLst === void 0) {
1196
+ diagnostics.push({
1197
+ code: "invalid-xml-value",
1198
+ category: "corrupt-input",
1199
+ disposition: "omitted",
1200
+ location: {
1201
+ ...location,
1202
+ xpath: custGeomCursor.xpath
1203
+ },
1204
+ attributeOrElement: "a:custGeom/a:pathLst"
1205
+ });
1206
+ return;
1207
+ }
1208
+ const paths = [];
1209
+ let viewWidth;
1210
+ let viewHeight;
1211
+ for (const pathCursor of pathLst.children(A_NS, "path")) {
1212
+ const rawPath = pathCursor.attrsObject([
1213
+ "w",
1214
+ "h",
1215
+ "fill",
1216
+ "stroke"
1217
+ ]);
1218
+ const parsedPath = CustomPathAttrSchema.safeParse(rawPath);
1219
+ if (!parsedPath.success) {
1220
+ diagnostics.push({
1221
+ code: "invalid-xml-value",
1222
+ category: "corrupt-input",
1223
+ disposition: "omitted",
1224
+ location: {
1225
+ ...location,
1226
+ xpath: pathCursor.xpath
1227
+ },
1228
+ attributeOrElement: "a:path",
1229
+ rawValue: JSON.stringify(rawPath)
1230
+ });
1231
+ continue;
1232
+ }
1233
+ const pathWUnits = parsedPath.data.w ?? fallbackExtentUnits.w;
1234
+ const pathHUnits = parsedPath.data.h ?? fallbackExtentUnits.h;
1235
+ const pathWidth = pathWUnits / 1e3;
1236
+ const pathHeight = pathHUnits / 1e3;
1237
+ viewWidth ??= pathWidth;
1238
+ viewHeight ??= pathHeight;
1239
+ const scaleX = pathWidth === viewWidth ? 1 : viewWidth / pathWidth;
1240
+ const scaleY = pathHeight === viewHeight ? 1 : viewHeight / pathHeight;
1241
+ const commands = [];
1242
+ let curX = 0;
1243
+ let curY = 0;
1244
+ let subStartX = 0;
1245
+ let subStartY = 0;
1246
+ let pathFailed = false;
1247
+ for (const cmdCursor of pathCursor.remainingElementChildren()) {
1248
+ if (cmdCursor.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/main") {
1249
+ diagnostics.push({
1250
+ code: "unconsumed-xml",
1251
+ category: "unsupported",
1252
+ disposition: "omitted",
1253
+ kind: "element",
1254
+ location: {
1255
+ ...location,
1256
+ xpath: cmdCursor.xpath
1257
+ },
1258
+ namespaceUri: cmdCursor.namespaceUri,
1259
+ localName: cmdCursor.localName
1260
+ });
1261
+ continue;
1262
+ }
1263
+ switch (cmdCursor.localName) {
1264
+ case "moveTo": {
1265
+ const pt = cmdCursor.child(A_NS, "pt");
1266
+ const coords = pt === void 0 ? void 0 : readCustomPoint(pt, location, diagnostics);
1267
+ if (coords === void 0) {
1268
+ pathFailed = true;
1269
+ break;
1270
+ }
1271
+ curX = coords.x * scaleX;
1272
+ curY = coords.y * scaleY;
1273
+ subStartX = curX;
1274
+ subStartY = curY;
1275
+ commands.push({
1276
+ op: "M",
1277
+ x: curX,
1278
+ y: curY
1279
+ });
1280
+ break;
1281
+ }
1282
+ case "lnTo": {
1283
+ const pt = cmdCursor.child(A_NS, "pt");
1284
+ const coords = pt === void 0 ? void 0 : readCustomPoint(pt, location, diagnostics);
1285
+ if (coords === void 0) {
1286
+ pathFailed = true;
1287
+ break;
1288
+ }
1289
+ curX = coords.x * scaleX;
1290
+ curY = coords.y * scaleY;
1291
+ commands.push({
1292
+ op: "L",
1293
+ x: curX,
1294
+ y: curY
1295
+ });
1296
+ break;
1297
+ }
1298
+ case "cubicBezTo": {
1299
+ const pts = cmdCursor.children(A_NS, "pt");
1300
+ if (pts.length !== 3) {
1301
+ pathFailed = true;
1302
+ break;
1303
+ }
1304
+ const p1 = readCustomPoint(pts[0], location, diagnostics);
1305
+ const p2 = readCustomPoint(pts[1], location, diagnostics);
1306
+ const p3 = readCustomPoint(pts[2], location, diagnostics);
1307
+ if (p1 === void 0 || p2 === void 0 || p3 === void 0) {
1308
+ pathFailed = true;
1309
+ break;
1310
+ }
1311
+ curX = p3.x * scaleX;
1312
+ curY = p3.y * scaleY;
1313
+ commands.push({
1314
+ op: "C",
1315
+ x1: p1.x * scaleX,
1316
+ y1: p1.y * scaleY,
1317
+ x2: p2.x * scaleX,
1318
+ y2: p2.y * scaleY,
1319
+ x: curX,
1320
+ y: curY
1321
+ });
1322
+ break;
1323
+ }
1324
+ case "quadBezTo": {
1325
+ const pts = cmdCursor.children(A_NS, "pt");
1326
+ if (pts.length !== 2) {
1327
+ pathFailed = true;
1328
+ break;
1329
+ }
1330
+ const p1 = readCustomPoint(pts[0], location, diagnostics);
1331
+ const p2 = readCustomPoint(pts[1], location, diagnostics);
1332
+ if (p1 === void 0 || p2 === void 0) {
1333
+ pathFailed = true;
1334
+ break;
1335
+ }
1336
+ curX = p2.x * scaleX;
1337
+ curY = p2.y * scaleY;
1338
+ commands.push({
1339
+ op: "Q",
1340
+ x1: p1.x * scaleX,
1341
+ y1: p1.y * scaleY,
1342
+ x: curX,
1343
+ y: curY
1344
+ });
1345
+ break;
1346
+ }
1347
+ case "arcTo": {
1348
+ const rawArc = cmdCursor.attrsObject([
1349
+ "wR",
1350
+ "hR",
1351
+ "stAng",
1352
+ "swAng"
1353
+ ]);
1354
+ const parsedArc = CustomArcAttrSchema.safeParse(rawArc);
1355
+ if (!parsedArc.success) {
1356
+ diagnostics.push({
1357
+ code: "unsupported-mechanism",
1358
+ category: "unsupported",
1359
+ disposition: "omitted",
1360
+ location: {
1361
+ ...location,
1362
+ xpath: cmdCursor.xpath
1363
+ },
1364
+ namespaceUri: A_NS,
1365
+ localName: "arcTo",
1366
+ mechanismHint: "custom-geometry-arc-guide"
1367
+ });
1368
+ pathFailed = true;
1369
+ break;
1370
+ }
1371
+ const arc = drawingMlArcToLocalCubics(curX / scaleX, curY / scaleY, parsedArc.data.wR / 1e3, parsedArc.data.hR / 1e3, parsedArc.data.stAng, parsedArc.data.swAng);
1372
+ for (const cubic of arc.commands) if (cubic.op === "C") commands.push({
1373
+ op: "C",
1374
+ x1: cubic.x1 * scaleX,
1375
+ y1: cubic.y1 * scaleY,
1376
+ x2: cubic.x2 * scaleX,
1377
+ y2: cubic.y2 * scaleY,
1378
+ x: cubic.x * scaleX,
1379
+ y: cubic.y * scaleY
1380
+ });
1381
+ else if (cubic.op === "L") commands.push({
1382
+ op: "L",
1383
+ x: cubic.x * scaleX,
1384
+ y: cubic.y * scaleY
1385
+ });
1386
+ curX = arc.endX * scaleX;
1387
+ curY = arc.endY * scaleY;
1388
+ break;
1389
+ }
1390
+ case "close":
1391
+ curX = subStartX;
1392
+ curY = subStartY;
1393
+ commands.push({ op: "Z" });
1394
+ break;
1395
+ default: diagnostics.push({
1396
+ code: "unsupported-mechanism",
1397
+ category: "unsupported",
1398
+ disposition: "omitted",
1399
+ location: {
1400
+ ...location,
1401
+ xpath: cmdCursor.xpath
1402
+ },
1403
+ namespaceUri: cmdCursor.namespaceUri,
1404
+ localName: cmdCursor.localName
1405
+ });
1406
+ }
1407
+ }
1408
+ if (pathFailed || commands.length === 0) continue;
1409
+ paths.push({
1410
+ commands,
1411
+ ...parsedPath.data.fill === "none" ? { fill: false } : {},
1412
+ ...parsedPath.data.stroke === false ? { stroke: false } : {}
1413
+ });
1414
+ }
1415
+ if (viewWidth === void 0 || viewHeight === void 0 || viewWidth <= 0 || viewHeight <= 0 || paths.length === 0) return;
1416
+ return {
1417
+ type: "custom",
1418
+ width: viewWidth,
1419
+ height: viewHeight,
1420
+ paths
1421
+ };
1422
+ }
1423
+ export { blockArc, customGeometrySchema, evaluateGeometry, geometryAdjustKeySchema, geometryAdjustSchema, geometrySchema, parseSvgPath, path, pathOptionsSchema, preset, presetGeometryNameSchema, presetGeometryNames, presetGeometryTuple, readCustomGeometryXml, readPresetGeometryXml, resolveGeometry, resolvedGeometryXml, shadeHex };