@evotecit/officeimo 0.1.21 → 0.1.43

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 (92) hide show
  1. package/README.md +39 -8
  2. package/bundles/officeimo-canopyx-adapter.js +56 -36
  3. package/bundles/officeimo-canopyx-adapter.min.js +1 -1
  4. package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
  5. package/bundles/officeimo-canopyx-adapter.mjs +42 -22
  6. package/bundles/officeimo-canopyx.js +420 -177
  7. package/bundles/officeimo-canopyx.min.js +1 -1
  8. package/bundles/officeimo-canopyx.min.mjs +1 -1
  9. package/bundles/officeimo-canopyx.mjs +346 -103
  10. package/bundles/officeimo-chartforgex-adapter.js +1924 -0
  11. package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
  12. package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
  13. package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
  14. package/bundles/officeimo-chartforgex.js +13594 -0
  15. package/bundles/officeimo-chartforgex.min.js +2 -0
  16. package/bundles/officeimo-chartforgex.min.mjs +2 -0
  17. package/bundles/officeimo-chartforgex.mjs +13487 -0
  18. package/bundles/officeimo-csv.js +12 -7
  19. package/bundles/officeimo-csv.min.js +1 -1
  20. package/bundles/officeimo-csv.min.mjs +1 -1
  21. package/bundles/officeimo-csv.mjs +8 -3
  22. package/bundles/officeimo-datatables-adapter.js +11 -11
  23. package/bundles/officeimo-datatables-adapter.min.js +1 -1
  24. package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
  25. package/bundles/officeimo-datatables-adapter.mjs +7 -7
  26. package/bundles/officeimo-datatables.js +375 -152
  27. package/bundles/officeimo-datatables.min.js +1 -1
  28. package/bundles/officeimo-datatables.min.mjs +1 -1
  29. package/bundles/officeimo-datatables.mjs +311 -88
  30. package/bundles/officeimo-execution.js +14 -9
  31. package/bundles/officeimo-execution.min.js +1 -1
  32. package/bundles/officeimo-execution.min.mjs +1 -1
  33. package/bundles/officeimo-execution.mjs +8 -3
  34. package/bundles/officeimo-pdf.js +286 -120
  35. package/bundles/officeimo-pdf.min.js +1 -1
  36. package/bundles/officeimo-pdf.min.mjs +1 -1
  37. package/bundles/officeimo-pdf.mjs +244 -78
  38. package/bundles/officeimo-xlsx.js +93 -31
  39. package/bundles/officeimo-xlsx.min.js +1 -1
  40. package/bundles/officeimo-xlsx.min.mjs +1 -1
  41. package/bundles/officeimo-xlsx.mjs +75 -13
  42. package/bundles/officeimo.js +373 -150
  43. package/bundles/officeimo.min.js +1 -1
  44. package/bundles/officeimo.min.mjs +1 -1
  45. package/bundles/officeimo.mjs +312 -89
  46. package/dist/core/progress.js +7 -2
  47. package/dist/index.d.ts +1 -1
  48. package/dist/integrations/canopyx/index.js +9 -2
  49. package/dist/integrations/canopyx/source.js +26 -13
  50. package/dist/integrations/chartforgex/capture.d.ts +31 -0
  51. package/dist/integrations/chartforgex/capture.js +103 -0
  52. package/dist/integrations/chartforgex/index.d.ts +13 -0
  53. package/dist/integrations/chartforgex/index.js +88 -0
  54. package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
  55. package/dist/integrations/chartforgex/svg-drawing.js +775 -0
  56. package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
  57. package/dist/integrations/chartforgex/svg-geometry.js +304 -0
  58. package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
  59. package/dist/integrations/chartforgex/svg-image.js +46 -0
  60. package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
  61. package/dist/integrations/chartforgex/svg-markup.js +124 -0
  62. package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
  63. package/dist/integrations/chartforgex/svg-paint.js +146 -0
  64. package/dist/integrations/chartforgex/types.d.ts +77 -0
  65. package/dist/integrations/chartforgex/types.js +1 -0
  66. package/dist/integrations/chartforgex/winansi.d.ts +4 -0
  67. package/dist/integrations/chartforgex/winansi.js +48 -0
  68. package/dist/integrations/chartforgex/workbook.d.ts +12 -0
  69. package/dist/integrations/chartforgex/workbook.js +137 -0
  70. package/dist/pdf/document-drawings.d.ts +1 -1
  71. package/dist/pdf/document-drawings.js +91 -17
  72. package/dist/pdf/document-images.d.ts +7 -1
  73. package/dist/pdf/document-images.js +59 -24
  74. package/dist/pdf/document-types.d.ts +3 -1
  75. package/dist/pdf/document.d.ts +2 -2
  76. package/dist/pdf/document.js +3 -1
  77. package/dist/pdf/drawing-types.d.ts +37 -10
  78. package/dist/pdf/font-resources.d.ts +1 -1
  79. package/dist/pdf/font-resources.js +6 -3
  80. package/dist/pdf/index.d.ts +1 -1
  81. package/dist/pdf/pages.js +15 -0
  82. package/dist/pdf/png.d.ts +11 -2
  83. package/dist/pdf/png.js +50 -23
  84. package/dist/pdf/session.js +3 -2
  85. package/dist/pdf/settings.d.ts +2 -2
  86. package/dist/pdf/settings.js +7 -3
  87. package/dist/xlsx/options.js +1 -1
  88. package/dist/xlsx/types.d.ts +8 -0
  89. package/dist/xlsx/workbook.js +6 -0
  90. package/dist/xlsx/worksheet.d.ts +13 -1
  91. package/dist/xlsx/worksheet.js +60 -9
  92. package/package.json +9 -2
@@ -0,0 +1,1924 @@
1
+ // Generated by OfficeIMO.JavaScript/scripts/bundles.mjs from tsc output. MIT.
2
+ (function (root) {
3
+ "use strict";
4
+ const officeimo = root.OfficeIMO || (root.OfficeIMO = {});
5
+ const cacheKey = Symbol.for("@evotecit/officeimo/modules");
6
+ const _modules = officeimo[cacheKey];
7
+ const _core = key => { const value = _modules && _modules.get(key); if (!value) throw new Error("officeimo-chartforgex-adapter.js needs officeimo.js or officeimo.min.js from the same OfficeIMO build, loaded first."); return value; };
8
+ const _c0 = _core("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00");
9
+ const _c1 = _core("50b3c10b690ceff693c8c5f809195ba6845b20e60f408e791a750d2ecbd5c669");
10
+ const _c2 = _core("42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671");
11
+ const _c3 = _core("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208");
12
+ const _c4 = _core("6c92204b587bb12cfa85c60eb1fd921804dfa51304538c7be3353e2927551b02");
13
+ const _c5 = _core("fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96");
14
+ const _c6 = _core("edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759");
15
+ const _c7 = _core("344fd55ffe1a37b32a8eb6a2bdaa14dff90e0fee0f37282457f9e4c3b7bce1ca");
16
+ const _c8 = _core("d5c945064d81fdd257960f48c421125e106e5f270427d170bb05587dd96a44ea");
17
+ const _c9 = _core("87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3");
18
+ const _c10 = _core("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f");
19
+ const _c11 = _core("32ca4982f963f400829c2e364b7d3479f36d91740dafb32d600f29b5cac487ec");
20
+ const _c12 = _core("6b0244b5ec6d550c705b4e4cbb47997331f1ecd99e2bf8a06f7c646eebbffbf8");
21
+ const _c13 = _core("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070");
22
+ const _c14 = _core("732224f6995c2478cf33a6ed01f3e3d3dcccb159a731d6db9280104bd5040fc5");
23
+ const _c15 = _core("8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a");
24
+ const _c16 = _core("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596");
25
+ const _m3 = _modules.get("2ab57874b786ef4d2b4841b9072fedd27d40c308f72c6548962810139359deb9") ?? (() => {
26
+ const { captureFields } = _c1;
27
+
28
+ const { ExportBudget } = _c2;
29
+
30
+ const { captureCsvOptions: captureCsv } = _c3;
31
+
32
+ const { capturePdfOptions: capturePdf, capturePdfLimits, pdfLimitFields } = _c4;
33
+
34
+ const { captureWorkbookLimits, workbookLimitFields, workbookOptionFields, sheetOptionFields } = _c5;
35
+
36
+ const limitFields = [...new Set([...workbookLimitFields, ...pdfLimitFields])];
37
+ const portableWorkbookFields = workbookOptionFields.filter((key) => key !== "sink");
38
+ /** Shared adapter budgets override only explicitly supplied numeric format ceilings. */
39
+ function captureCommonLimits(input) {
40
+ return input === undefined ? undefined : new ExportBudget(captureFields(input, limitFields)).limits;
41
+ }
42
+ function mergeAdapterLimits(format, common) {
43
+ const result = { ...format };
44
+ for (const [key, value] of Object.entries(common ?? {}))
45
+ if (value !== undefined)
46
+ result[key] = value;
47
+ return result;
48
+ }
49
+ /** Snapshot the format owner's fields before an adapter adds captured columns and stream policy. */
50
+ function captureXlsxOptions(input = {}) {
51
+ const options = captureFields(input, [...portableWorkbookFields, "sheet"]);
52
+ const sheet = options.sheet && captureFields(options.sheet, [...sheetOptionFields, "name"]);
53
+ const footer = sheet?.footer && captureFields(sheet.footer, ["rows", "values", "totals", "style"]);
54
+ return { ...options, ...(sheet === undefined ? {} : { sheet: { ...sheet, ...(footer === undefined ? {} : { footer }) } }),
55
+ ...(options.limits === undefined ? {} : { limits: captureWorkbookLimits(options.limits) }) };
56
+ }
57
+ function captureCsvOptions(input = {}) {
58
+ const options = captureCsv(input);
59
+ return { ...options, ...(options.limits === undefined ? {} : { limits: new ExportBudget(options.limits).limits }) };
60
+ }
61
+ function capturePdfOptions(input = {}) {
62
+ const options = capturePdf(input);
63
+ return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
64
+ }
65
+ const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
66
+ _modules.set("2ab57874b786ef4d2b4841b9072fedd27d40c308f72c6548962810139359deb9", _exports);
67
+ return _exports;
68
+ })();
69
+
70
+ const _m10 = _modules.get("ac8402d3d046ec8f54d00b5207b5342ec15c8d02aca85e597479db0f27d7cd6d") ?? (() => {
71
+ const { NotSupportedError } = _c8;
72
+
73
+ function record(value, name) {
74
+ if (!value || typeof value !== "object" || Array.isArray(value))
75
+ throw new TypeError("Chart capture " + name + " must be an object.");
76
+ return value;
77
+ }
78
+ function text(value, name, required = false) {
79
+ if (value === undefined || value === null) {
80
+ if (required)
81
+ throw new TypeError("Chart capture " + name + " is required.");
82
+ return undefined;
83
+ }
84
+ if (typeof value !== "string")
85
+ throw new TypeError("Chart capture " + name + " must be a string.");
86
+ return value;
87
+ }
88
+ const isoDate = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/;
89
+ /** Dates without an offset are UTC wall-clock values, the way ChartForgeX serializes time axes, never the reader's local time. */
90
+ function isoInstant(value) {
91
+ const normalized = value.replace(" ", "T").replace(/([+-]\d{2})(\d{2})$/, "$1:$2").replace(/(\.\d{3})\d+/, "$1");
92
+ return normalized.length === 10 || /(Z|[+-]\d{2}:\d{2})$/.test(normalized) ? normalized : normalized + "Z";
93
+ }
94
+ function parseDate(value) {
95
+ const normalized = value.trim();
96
+ if (!isoDate.test(normalized))
97
+ return NaN;
98
+ const day = normalized.slice(0, 10);
99
+ const midnight = new Date(day + "T00:00:00Z");
100
+ if (!Number.isFinite(midnight.getTime()) || !midnight.toISOString().startsWith(day + "T"))
101
+ return NaN;
102
+ return Date.parse(isoInstant(normalized));
103
+ }
104
+ /** Read the capture once into owned records, so later caller mutation cannot change an export in progress. */
105
+ function prepareChart(input, maxPoints = 1048575) {
106
+ const capture = record(input, "");
107
+ if (capture.version !== 1)
108
+ throw new NotSupportedError("Only ChartForgeX capture version 1 is supported.");
109
+ const axis = record(capture.x, "x"), kind = axis.kind;
110
+ if (kind !== "date" && kind !== "number" && kind !== "category")
111
+ throw new TypeError("Chart capture x.kind must be date, number or category.");
112
+ const yAxis = capture.y === undefined ? {} : record(capture.y, "y");
113
+ if (!Array.isArray(capture.series))
114
+ throw new TypeError("Chart capture series must be an array.");
115
+ let count = 0;
116
+ const series = Array.from(capture.series, (entry, index) => {
117
+ const value = record(entry, "series[" + index + "]"), points = value.points;
118
+ if (!Array.isArray(points))
119
+ throw new TypeError("Chart capture series[" + index + "].points must be an array.");
120
+ const pointCount = points.length;
121
+ if ((count += pointCount) > maxPoints)
122
+ throw new RangeError("Chart capture has more than " + maxPoints + " points.");
123
+ return {
124
+ id: text(value.id, "series[" + index + "].id", true), name: text(value.name, "series[" + index + "].name", true),
125
+ unit: text(value.unit, "series unit"), format: text(value.format, "series format"),
126
+ points: Array.from({ length: pointCount }, (_, point) => {
127
+ const item = record(points[point], "point"), where = "series[" + index + "].points[" + point + "]";
128
+ const y = item.y;
129
+ if (y !== null && y !== undefined && (typeof y !== "number" || !Number.isFinite(y)))
130
+ throw new TypeError(where + ".y must be a finite number or null.");
131
+ let x = null, key = null;
132
+ const source = item.x;
133
+ if (source !== null && source !== undefined) {
134
+ if (kind === "date") {
135
+ let time = NaN;
136
+ if (typeof source === "string")
137
+ time = parseDate(source);
138
+ if (typeof source === "object") {
139
+ try {
140
+ time = Date.prototype.getTime.call(source);
141
+ }
142
+ catch { /* Not a Date. */ }
143
+ }
144
+ if (!Number.isFinite(time))
145
+ throw new TypeError(where + ".x must be an ISO 8601 date string or a valid Date.");
146
+ x = new Date(time);
147
+ key = time;
148
+ }
149
+ else if (kind === "number") {
150
+ if (typeof source !== "number" || !Number.isFinite(source))
151
+ throw new TypeError(where + ".x must be a finite number.");
152
+ x = key = source;
153
+ }
154
+ else {
155
+ if (typeof source !== "string" && typeof source !== "number")
156
+ throw new TypeError(where + ".x must be a category label.");
157
+ x = key = String(source);
158
+ }
159
+ }
160
+ return { x, key, xCaption: text(item.xCaption, where + ".xCaption"), y: y ?? null, caption: text(item.caption, where + ".caption") };
161
+ })
162
+ };
163
+ });
164
+ const svg = capture.svg;
165
+ const markup = svg && typeof svg === "object" ? svg.outerHTML : svg;
166
+ if (svg != null && typeof markup !== "string")
167
+ throw new TypeError("Chart capture svg must be markup or an element.");
168
+ return {
169
+ title: text(capture.title, "title"), description: text(capture.description, "description"), kind,
170
+ xTitle: text(axis.title, "x.title") || "X", xFormat: text(axis.format, "x.format"),
171
+ yTitle: text(yAxis.title, "y.title") || "Value", yUnit: text(yAxis.unit, "y.unit"), yFormat: text(yAxis.format, "y.format"),
172
+ series, svg: typeof markup === "string" ? markup : undefined
173
+ };
174
+ }
175
+ const _exports = Object.freeze({ prepareChart: prepareChart });
176
+ _modules.set("ac8402d3d046ec8f54d00b5207b5342ec15c8d02aca85e597479db0f27d7cd6d", _exports);
177
+ return _exports;
178
+ })();
179
+
180
+ const _m15 = _modules.get("f54d4d4723150fc5bcef9dc5e60d5b819452cd5007edfa3494a3c876459a0b01") ?? (() => {
181
+ const { OfficeIMOError } = _c8;
182
+
183
+ const { jpegSize } = _c11;
184
+
185
+ const { pngEmbeddableSize } = _c12;
186
+
187
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
188
+ const values = new Int16Array(128).fill(-1);
189
+ for (let i = 0; i < alphabet.length; i++)
190
+ values[alphabet.charCodeAt(i)] = i;
191
+ /** Strict base64 with optional padding and ignorable whitespace; undefined for anything else. */
192
+ function base64(text) {
193
+ const compact = text.replace(/[\t\n\f\r ]+/g, "").replace(/={1,2}$/, "");
194
+ if (compact.length % 4 === 1)
195
+ return undefined;
196
+ const output = new Uint8Array(Math.floor(compact.length * 3 / 4));
197
+ let bits = 0, buffer = 0, offset = 0;
198
+ for (let i = 0; i < compact.length; i++) {
199
+ const code = compact.charCodeAt(i), value = code < 128 ? values[code] : -1;
200
+ if (value < 0)
201
+ return undefined;
202
+ buffer = (buffer << 6 | value) & 0xffffff;
203
+ bits += 6;
204
+ if (bits >= 8) {
205
+ bits -= 8;
206
+ output[offset++] = buffer >> bits & 255;
207
+ }
208
+ }
209
+ return output;
210
+ }
211
+ /** Decode a base64 PNG or JPEG `data:` URL. External references and other image types return undefined. */
212
+ function svgDataImage(href) {
213
+ const match = /^\s*data:image\/(png|jpeg|jpg)(?:;[^,;]*=[^,;]*)*;base64,([\s\S]*)$/i.exec(href);
214
+ if (!match)
215
+ return undefined;
216
+ const data = base64(match[2]);
217
+ if (!data)
218
+ return undefined;
219
+ try {
220
+ const format = match[1].toLowerCase() === "png" ? "png" : "jpeg";
221
+ const { width, height } = format === "png" ? pngEmbeddableSize(data) : jpegSize(data);
222
+ return width && height ? { image: { format, data }, width, height } : undefined;
223
+ }
224
+ catch (error) {
225
+ if (error instanceof OfficeIMOError && error.code === "RESOURCE_LIMIT")
226
+ throw error;
227
+ return undefined;
228
+ }
229
+ }
230
+ const _exports = Object.freeze({ svgDataImage: svgDataImage });
231
+ _modules.set("f54d4d4723150fc5bcef9dc5e60d5b819452cd5007edfa3494a3c876459a0b01", _exports);
232
+ return _exports;
233
+ })();
234
+
235
+ const _m18 = _modules.get("5dab75a1e2b113e5358c4e759fad101ac6fe31a376053e16a415e66ff02f7ff7") ?? (() => {
236
+ const { NotSupportedError } = _c8;
237
+
238
+ const attributePattern = /([A-Za-z_][\w.:-]*)\s*=\s*("([^"]*)"|'([^']*)')/y;
239
+ const entities = { lt: "<", gt: ">", amp: "&", quot: "\"", apos: "'", nbsp: " " };
240
+ function decode(text) {
241
+ return text.indexOf("&") < 0 ? text : text.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[A-Za-z]+);/g, (match, entity) => {
242
+ if (entity[0] === "#") {
243
+ const code = entity[1] === "x" || entity[1] === "X" ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);
244
+ return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "�";
245
+ }
246
+ return entities[entity] ?? match;
247
+ });
248
+ }
249
+ /** A small, non-validating parser for serialized SVG: elements, attributes, text, CDATA and character references.
250
+ * Comments, processing instructions and doctype declarations are skipped; external entities are never resolved. */
251
+ function parseSvgMarkup(markup, maxDepth = 256) {
252
+ if (typeof markup !== "string")
253
+ throw new TypeError("Chart SVG must be serialized markup.");
254
+ const stack = [];
255
+ let root, index = 0;
256
+ const text = (value) => { const top = stack[stack.length - 1]; if (top && value)
257
+ top.children.push(value); };
258
+ while (index < markup.length) {
259
+ const open = markup.indexOf("<", index);
260
+ if (open < 0) {
261
+ text(decode(markup.slice(index)));
262
+ break;
263
+ }
264
+ if (open > index)
265
+ text(decode(markup.slice(index, open)));
266
+ if (markup.startsWith("<!--", open)) {
267
+ const end = markup.indexOf("-->", open + 4);
268
+ if (end < 0)
269
+ throw new TypeError("Chart SVG has an unterminated comment.");
270
+ index = end + 3;
271
+ continue;
272
+ }
273
+ if (markup.startsWith("<![CDATA[", open)) {
274
+ const end = markup.indexOf("]]>", open + 9);
275
+ if (end < 0)
276
+ throw new TypeError("Chart SVG has an unterminated CDATA section.");
277
+ text(markup.slice(open + 9, end));
278
+ index = end + 3;
279
+ continue;
280
+ }
281
+ if (markup[open + 1] === "?") {
282
+ const end = markup.indexOf("?>", open + 2);
283
+ if (end < 0)
284
+ throw new TypeError("Chart SVG has an unterminated processing instruction.");
285
+ index = end + 2;
286
+ continue;
287
+ }
288
+ if (markup[open + 1] === "!") {
289
+ if (/^<!DOCTYPE[^>]*\[/i.test(markup.slice(open, open + 1024)))
290
+ throw new NotSupportedError("Chart SVG with an internal DTD subset is not supported.");
291
+ const end = markup.indexOf(">", open + 2);
292
+ if (end < 0)
293
+ throw new TypeError("Chart SVG has an unterminated declaration.");
294
+ index = end + 1;
295
+ continue;
296
+ }
297
+ if (markup[open + 1] === "/") {
298
+ const end = markup.indexOf(">", open + 2);
299
+ if (end < 0)
300
+ throw new TypeError("Chart SVG has an unterminated end tag.");
301
+ const name = markup.slice(open + 2, end).trim(), top = stack.pop();
302
+ if (!top || top.name !== name)
303
+ throw new TypeError("Chart SVG end tag </" + name + "> does not match its element.");
304
+ const node = top;
305
+ if (stack.length)
306
+ stack[stack.length - 1].children.push(node);
307
+ else
308
+ root = node;
309
+ index = end + 1;
310
+ continue;
311
+ }
312
+ const tag = /^<([A-Za-z_][\w.:-]*)/.exec(markup.slice(open, open + 256));
313
+ if (!tag)
314
+ throw new TypeError("Chart SVG has an invalid start tag.");
315
+ const name = tag[1], attributes = new Map();
316
+ let position = open + tag[0].length, selfClosing = false;
317
+ for (;;) {
318
+ while (position < markup.length && /\s/.test(markup[position]))
319
+ position++;
320
+ const character = markup[position];
321
+ if (character === undefined)
322
+ throw new TypeError("Chart SVG has an unterminated start tag.");
323
+ if (character === ">") {
324
+ position++;
325
+ break;
326
+ }
327
+ if (character === "/" && markup[position + 1] === ">") {
328
+ position += 2;
329
+ selfClosing = true;
330
+ break;
331
+ }
332
+ attributePattern.lastIndex = position;
333
+ const attribute = attributePattern.exec(markup);
334
+ if (!attribute)
335
+ throw new TypeError("Chart SVG has an invalid attribute on <" + name + ">.");
336
+ attributes.set(attribute[1], decode(attribute[3] ?? attribute[4] ?? ""));
337
+ position = attributePattern.lastIndex;
338
+ }
339
+ if (root)
340
+ throw new TypeError("Chart SVG must have one root element.");
341
+ const local = name.slice(name.indexOf(":") + 1), element = { name, local, attributes, children: [] };
342
+ if (selfClosing) {
343
+ if (stack.length)
344
+ stack[stack.length - 1].children.push(element);
345
+ else
346
+ root = element;
347
+ }
348
+ else {
349
+ if (stack.length >= maxDepth)
350
+ throw new NotSupportedError("Chart SVG nesting exceeds " + maxDepth + " levels.");
351
+ stack.push(element);
352
+ }
353
+ index = position;
354
+ }
355
+ if (stack.length)
356
+ throw new TypeError("Chart SVG has an unclosed <" + stack[stack.length - 1].name + "> element.");
357
+ if (!root || root.local !== "svg")
358
+ throw new TypeError("Chart SVG must have an <svg> root element.");
359
+ return root;
360
+ }
361
+ const _exports = Object.freeze({ parseSvgMarkup: parseSvgMarkup });
362
+ _modules.set("5dab75a1e2b113e5358c4e759fad101ac6fe31a376053e16a415e66ff02f7ff7", _exports);
363
+ return _exports;
364
+ })();
365
+
366
+ const _m19 = _modules.get("aa2e4d4a785e0f5ad98b5ca9eb14387d1335d0d7df8005063972b69a7a07eab0") ?? (() => {
367
+ const identity = [1, 0, 0, 1, 0, 0];
368
+ function multiply(m, n) {
369
+ return [m[0] * n[0] + m[2] * n[1], m[1] * n[0] + m[3] * n[1], m[0] * n[2] + m[2] * n[3], m[1] * n[2] + m[3] * n[3],
370
+ m[0] * n[4] + m[2] * n[5] + m[4], m[1] * n[4] + m[3] * n[5] + m[5]];
371
+ }
372
+ function apply(m, x, y) { return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]]; }
373
+ function determinant(m) { return m[0] * m[3] - m[1] * m[2]; }
374
+ function scaleOf(m) { return Math.sqrt(Math.abs(determinant(m))); }
375
+ const numberPattern = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
376
+ function numbers(text) { return (text.match(numberPattern) ?? []).map(Number); }
377
+ /** Parse an SVG transform list. Returns undefined for syntax this reader does not understand. */
378
+ function parseTransform(text) {
379
+ if (text === undefined || !text.trim() || text.trim() === "none")
380
+ return identity;
381
+ let result = identity, rest = text.trim();
382
+ const item = /^([a-zA-Z]+)\s*\(([^)]*)\)\s*,?\s*/;
383
+ while (rest) {
384
+ const match = item.exec(rest);
385
+ if (!match)
386
+ return undefined;
387
+ const name = match[1], input = match[2].trim(), args = [];
388
+ const unitPattern = /([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)([a-z%]*)/gi;
389
+ let end = 0;
390
+ for (const arg of input.matchAll(unitPattern)) {
391
+ const separator = input.slice(end, arg.index);
392
+ if (!/^\s*,?\s*$/.test(separator) || !args.length && separator)
393
+ return undefined;
394
+ const unit = arg[2].toLowerCase(), value = Number(arg[1]);
395
+ const angle = !args.length && (name === "rotate" || name === "skewX" || name === "skewY");
396
+ if (!unit || (unit === "px" && name === "translate"))
397
+ args.push(value);
398
+ else if (angle && unit === "deg")
399
+ args.push(value);
400
+ else if (angle && unit === "rad")
401
+ args.push(value * 180 / Math.PI);
402
+ else if (angle && unit === "grad")
403
+ args.push(value * .9);
404
+ else if (angle && unit === "turn")
405
+ args.push(value * 360);
406
+ else
407
+ return undefined;
408
+ end = arg.index + arg[0].length;
409
+ }
410
+ if (end !== input.length)
411
+ return undefined;
412
+ let next;
413
+ if (name === "matrix" && args.length === 6)
414
+ next = args;
415
+ else if (name === "translate" && (args.length === 1 || args.length === 2))
416
+ next = [1, 0, 0, 1, args[0], args[1] ?? 0];
417
+ else if (name === "scale" && (args.length === 1 || args.length === 2))
418
+ next = [args[0], 0, 0, args[1] ?? args[0], 0, 0];
419
+ else if (name === "rotate" && (args.length === 1 || args.length === 3)) {
420
+ const angle = args[0] * Math.PI / 180, cos = Math.cos(angle), sin = Math.sin(angle), cx = args[1] ?? 0, cy = args[2] ?? 0;
421
+ next = multiply(multiply([1, 0, 0, 1, cx, cy], [cos, sin, -sin, cos, 0, 0]), [1, 0, 0, 1, -cx, -cy]);
422
+ }
423
+ else if (name === "skewX" && args.length === 1)
424
+ next = [1, 0, Math.tan(args[0] * Math.PI / 180), 1, 0, 0];
425
+ else if (name === "skewY" && args.length === 1)
426
+ next = [1, Math.tan(args[0] * Math.PI / 180), 0, 1, 0, 0];
427
+ else
428
+ return undefined;
429
+ result = multiply(result, next);
430
+ rest = rest.slice(match[0].length);
431
+ }
432
+ return result.every(Number.isFinite) ? result : undefined;
433
+ }
434
+ function arc(out, x1, y1, rx, ry, rotation, large, sweep, x2, y2) {
435
+ if (x1 === x2 && y1 === y2)
436
+ return;
437
+ rx = Math.abs(rx);
438
+ ry = Math.abs(ry);
439
+ if (!rx || !ry) {
440
+ out.push({ op: "line", x: x2, y: y2 });
441
+ return;
442
+ }
443
+ const phi = rotation * Math.PI / 180, cos = Math.cos(phi), sin = Math.sin(phi);
444
+ const dx = (x1 - x2) / 2, dy = (y1 - y2) / 2, xp = cos * dx + sin * dy, yp = -sin * dx + cos * dy;
445
+ const lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
446
+ if (lambda > 1) {
447
+ const s = Math.sqrt(lambda);
448
+ rx *= s;
449
+ ry *= s;
450
+ }
451
+ const sign = large === sweep ? -1 : 1, numerator = rx * rx * ry * ry - rx * rx * yp * yp - ry * ry * xp * xp;
452
+ const factor = sign * Math.sqrt(Math.max(0, numerator / (rx * rx * yp * yp + ry * ry * xp * xp)));
453
+ const cxp = factor * rx * yp / ry, cyp = -factor * ry * xp / rx;
454
+ const cx = cos * cxp - sin * cyp + (x1 + x2) / 2, cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
455
+ const angle = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
456
+ const start = angle(1, 0, (xp - cxp) / rx, (yp - cyp) / ry);
457
+ let delta = angle((xp - cxp) / rx, (yp - cyp) / ry, (-xp - cxp) / rx, (-yp - cyp) / ry);
458
+ if (!sweep && delta > 0)
459
+ delta -= 2 * Math.PI;
460
+ else if (sweep && delta < 0)
461
+ delta += 2 * Math.PI;
462
+ const segments = Math.max(1, Math.ceil(Math.abs(delta) / (Math.PI / 2) - 1e-9)), step = delta / segments, k = 4 / 3 * Math.tan(step / 4);
463
+ const point = (t) => [cx + rx * Math.cos(t) * cos - ry * Math.sin(t) * sin, cy + rx * Math.cos(t) * sin + ry * Math.sin(t) * cos];
464
+ const derivative = (t) => [-rx * Math.sin(t) * cos - ry * Math.cos(t) * sin, -rx * Math.sin(t) * sin + ry * Math.cos(t) * cos];
465
+ for (let i = 0; i < segments; i++) {
466
+ const t1 = start + i * step, t2 = t1 + step, [px1, py1] = point(t1), [px2, py2] = i === segments - 1 ? [x2, y2] : point(t2);
467
+ const [d1x, d1y] = derivative(t1), [d2x, d2y] = derivative(t2);
468
+ out.push({ op: "cubic", x1: px1 + k * d1x, y1: py1 + k * d1y, x2: px2 - k * d2x, y2: py2 - k * d2y, x: px2, y: py2 });
469
+ }
470
+ }
471
+ /** Parse SVG path data. Stops at the first malformed segment, as SVG renderers do, and reports whether it did. */
472
+ function parsePathData(d) {
473
+ const out = [], tokens = /([MmLlHhVvCcSsQqTtAaZz])|([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|([\s,]+)|(.)/g;
474
+ const list = [];
475
+ let malformed = false;
476
+ let comma = false;
477
+ for (const match of d.matchAll(tokens)) {
478
+ if (match[4] !== undefined || comma && match[1] !== undefined) {
479
+ malformed = true;
480
+ break;
481
+ }
482
+ const separator = match[3];
483
+ if (separator?.includes(",")) {
484
+ const previous = list.at(-1);
485
+ if (previous === undefined || /^[A-Za-z]$/.test(previous) || separator.indexOf(",") !== separator.lastIndexOf(",")) {
486
+ malformed = true;
487
+ break;
488
+ }
489
+ comma = true;
490
+ continue;
491
+ }
492
+ if (match[1] !== undefined || match[2] !== undefined)
493
+ list.push(match[1] ?? match[2]);
494
+ comma = false;
495
+ }
496
+ malformed ||= comma;
497
+ let i = 0, x = 0, y = 0, startX = 0, startY = 0, command = "", lastControl, lastQuad;
498
+ let open = false;
499
+ const isCommand = (value) => value !== undefined && /^[A-Za-z]$/.test(value);
500
+ const take = () => {
501
+ const value = list[i];
502
+ if (value === undefined || isCommand(value))
503
+ return undefined;
504
+ i++;
505
+ const number = Number(value);
506
+ return Number.isFinite(number) ? number : undefined;
507
+ };
508
+ // Arc flags may be written without separators ("a1 1 0 011 1"): split compact digit runs.
509
+ const flag = () => {
510
+ const raw = list[i];
511
+ if (raw === undefined || isCommand(raw))
512
+ return undefined;
513
+ if (raw === "0" || raw === "1") {
514
+ i++;
515
+ return Number(raw);
516
+ }
517
+ if (/^[01][\d.]/.test(raw)) {
518
+ list[i] = raw.slice(1);
519
+ return Number(raw[0]);
520
+ }
521
+ return undefined;
522
+ };
523
+ while (i < list.length) {
524
+ const token = list[i];
525
+ if (isCommand(token)) {
526
+ command = token;
527
+ i++;
528
+ }
529
+ else if (!command || command === "Z" || command === "z")
530
+ return { commands: out, malformed: true };
531
+ const relative = command === command.toLowerCase(), base = command.toUpperCase();
532
+ if (!out.length && base !== "M")
533
+ return { commands: out, malformed: true };
534
+ const ox = relative ? x : 0, oy = relative ? y : 0;
535
+ if (base === "Z") {
536
+ if (open)
537
+ out.push({ op: "close" });
538
+ x = startX;
539
+ y = startY;
540
+ open = false;
541
+ lastControl = lastQuad = undefined;
542
+ continue;
543
+ }
544
+ const ensure = () => { if (!open) {
545
+ out.push({ op: "move", x, y });
546
+ open = true;
547
+ } };
548
+ if (base === "M") {
549
+ const a = take(), b = take();
550
+ if (a === undefined || b === undefined)
551
+ return { commands: out, malformed: true };
552
+ x = ox + a;
553
+ y = oy + b;
554
+ startX = x;
555
+ startY = y;
556
+ out.push({ op: "move", x, y });
557
+ open = true;
558
+ command = relative ? "l" : "L";
559
+ lastControl = lastQuad = undefined;
560
+ continue;
561
+ }
562
+ if (base === "L" || base === "H" || base === "V") {
563
+ const a = take();
564
+ if (a === undefined)
565
+ return { commands: out, malformed: true };
566
+ const b = base === "L" ? take() : undefined;
567
+ if (base === "L" && b === undefined)
568
+ return { commands: out, malformed: true };
569
+ ensure();
570
+ if (base !== "V")
571
+ x = ox + a;
572
+ if (base !== "H")
573
+ y = oy + (b ?? a);
574
+ out.push({ op: "line", x, y });
575
+ lastControl = lastQuad = undefined;
576
+ continue;
577
+ }
578
+ if (base === "C" || base === "S") {
579
+ const values = [];
580
+ for (let n = base === "C" ? 6 : 4; n > 0; n--) {
581
+ const v = take();
582
+ if (v === undefined)
583
+ return { commands: out, malformed: true };
584
+ values.push(v);
585
+ }
586
+ const [c1x, c1y] = base === "C" ? [ox + values[0], oy + values[1]] : lastControl ? [2 * x - lastControl[0], 2 * y - lastControl[1]] : [x, y];
587
+ const rest = base === "C" ? values.slice(2) : values;
588
+ const c2x = ox + rest[0], c2y = oy + rest[1], ex = ox + rest[2], ey = oy + rest[3];
589
+ ensure();
590
+ out.push({ op: "cubic", x1: c1x, y1: c1y, x2: c2x, y2: c2y, x: ex, y: ey });
591
+ lastControl = [c2x, c2y];
592
+ lastQuad = undefined;
593
+ x = ex;
594
+ y = ey;
595
+ continue;
596
+ }
597
+ if (base === "Q" || base === "T") {
598
+ const values = [];
599
+ for (let n = base === "Q" ? 4 : 2; n > 0; n--) {
600
+ const v = take();
601
+ if (v === undefined)
602
+ return { commands: out, malformed: true };
603
+ values.push(v);
604
+ }
605
+ const [qx, qy] = base === "Q" ? [ox + values[0], oy + values[1]] : lastQuad ? [2 * x - lastQuad[0], 2 * y - lastQuad[1]] : [x, y];
606
+ const ex = ox + values[values.length - 2], ey = oy + values[values.length - 1];
607
+ ensure();
608
+ out.push({ op: "cubic", x1: x + 2 / 3 * (qx - x), y1: y + 2 / 3 * (qy - y), x2: ex + 2 / 3 * (qx - ex), y2: ey + 2 / 3 * (qy - ey), x: ex, y: ey });
609
+ lastQuad = [qx, qy];
610
+ lastControl = undefined;
611
+ x = ex;
612
+ y = ey;
613
+ continue;
614
+ }
615
+ if (base === "A") {
616
+ const rx = take(), ry = take(), rotation = take(), large = flag(), sweep = flag(), a = take(), b = take();
617
+ if (rx === undefined || ry === undefined || rotation === undefined || large === undefined || sweep === undefined || a === undefined || b === undefined)
618
+ return { commands: out, malformed: true };
619
+ ensure();
620
+ arc(out, x, y, rx, ry, rotation, large === 1, sweep === 1, ox + a, oy + b);
621
+ x = ox + a;
622
+ y = oy + b;
623
+ lastControl = lastQuad = undefined;
624
+ continue;
625
+ }
626
+ return { commands: out, malformed: true };
627
+ }
628
+ return { commands: out, malformed };
629
+ }
630
+ const kappa = 0.5522847498307936;
631
+ /** Closed ellipse as four cubic quarters, starting at the rightmost point. */
632
+ function ellipse(cx, cy, rx, ry) {
633
+ const ox = rx * kappa, oy = ry * kappa;
634
+ return [{ op: "move", x: cx + rx, y: cy },
635
+ { op: "cubic", x1: cx + rx, y1: cy + oy, x2: cx + ox, y2: cy + ry, x: cx, y: cy + ry },
636
+ { op: "cubic", x1: cx - ox, y1: cy + ry, x2: cx - rx, y2: cy + oy, x: cx - rx, y: cy },
637
+ { op: "cubic", x1: cx - rx, y1: cy - oy, x2: cx - ox, y2: cy - ry, x: cx, y: cy - ry },
638
+ { op: "cubic", x1: cx + ox, y1: cy - ry, x2: cx + rx, y2: cy - oy, x: cx + rx, y: cy }, { op: "close" }];
639
+ }
640
+ function rectangle(x, y, width, height, rx, ry) {
641
+ rx = Math.min(Math.max(rx, 0), width / 2);
642
+ ry = Math.min(Math.max(ry, 0), height / 2);
643
+ if (!rx || !ry)
644
+ return [{ op: "move", x, y }, { op: "line", x: x + width, y }, { op: "line", x: x + width, y: y + height }, { op: "line", x, y: y + height }, { op: "close" }];
645
+ const ox = rx * (1 - kappa), oy = ry * (1 - kappa), r = x + width, b = y + height;
646
+ return [{ op: "move", x: x + rx, y }, { op: "line", x: r - rx, y }, { op: "cubic", x1: r - ox, y1: y, x2: r, y2: y + oy, x: r, y: y + ry },
647
+ { op: "line", x: r, y: b - ry }, { op: "cubic", x1: r, y1: b - oy, x2: r - ox, y2: b, x: r - rx, y: b },
648
+ { op: "line", x: x + rx, y: b }, { op: "cubic", x1: x + ox, y1: b, x2: x, y2: b - oy, x, y: b - ry },
649
+ { op: "line", x, y: y + ry }, { op: "cubic", x1: x, y1: y + oy, x2: x + ox, y2: y, x: x + rx, y }, { op: "close" }];
650
+ }
651
+ function polyline(points, closed) {
652
+ const out = [];
653
+ for (let i = 0; i + 1 < points.length; i += 2)
654
+ out.push({ op: i ? "line" : "move", x: points[i], y: points[i + 1] });
655
+ if (closed && out.length)
656
+ out.push({ op: "close" });
657
+ return out;
658
+ }
659
+ function transformCommands(commands, m) {
660
+ return commands.map(c => {
661
+ if (c.op === "close")
662
+ return c;
663
+ const [x, y] = apply(m, c.x, c.y);
664
+ if (c.op === "cubic") {
665
+ const [x1, y1] = apply(m, c.x1, c.y1), [x2, y2] = apply(m, c.x2, c.y2);
666
+ return { op: "cubic", x1, y1, x2, y2, x, y };
667
+ }
668
+ return { op: c.op, x, y };
669
+ });
670
+ }
671
+ const _exports = Object.freeze({ identity: identity, multiply: multiply, apply: apply, determinant: determinant, scaleOf: scaleOf, numbers: numbers, parseTransform: parseTransform, parsePathData: parsePathData, ellipse: ellipse, rectangle: rectangle, polyline: polyline, transformCommands: transformCommands });
672
+ _modules.set("aa2e4d4a785e0f5ad98b5ca9eb14387d1335d0d7df8005063972b69a7a07eab0", _exports);
673
+ return _exports;
674
+ })();
675
+
676
+ const _m20 = _modules.get("f2ed937ff699a1d52b7e285a0008b74f6cc95abfd4bdbeb65a6fd71beb3610e5") ?? (() => {
677
+ const named = {
678
+ black: "000000", white: "ffffff", red: "ff0000", green: "008000", blue: "0000ff", yellow: "ffff00", orange: "ffa500", purple: "800080",
679
+ gray: "808080", grey: "808080", silver: "c0c0c0", maroon: "800000", navy: "000080", teal: "008080", olive: "808000", lime: "00ff00",
680
+ aqua: "00ffff", cyan: "00ffff", fuchsia: "ff00ff", magenta: "ff00ff", darkgray: "a9a9a9", darkgrey: "a9a9a9", lightgray: "d3d3d3",
681
+ lightgrey: "d3d3d3", dimgray: "696969", dimgrey: "696969", gainsboro: "dcdcdc", whitesmoke: "f5f5f5", steelblue: "4682b4",
682
+ slategray: "708090", slategrey: "708090", crimson: "dc143c", tomato: "ff6347", gold: "ffd700", indigo: "4b0082", brown: "a52a2a",
683
+ pink: "ffc0cb", coral: "ff7f50", salmon: "fa8072", seagreen: "2e8b57", forestgreen: "228b22", royalblue: "4169e1", darkblue: "00008b",
684
+ darkred: "8b0000", darkgreen: "006400", darkorange: "ff8c00", lightblue: "add8e6", skyblue: "87ceeb", tan: "d2b48c", violet: "ee82ee"
685
+ };
686
+ const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
687
+ function channel(text, scale) {
688
+ const value = parseFloat(text);
689
+ return text.trim().endsWith("%") ? value / 100 * scale : value;
690
+ }
691
+ function alpha(text) {
692
+ if (text === undefined)
693
+ return 1;
694
+ if (text.trim() === "none")
695
+ return 0;
696
+ if (!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?%?$/i.test(text.trim()))
697
+ return undefined;
698
+ return clamp(channel(text, 1), 0, 1);
699
+ }
700
+ function functionArguments(body, legacyAlpha) {
701
+ const [main, slash] = body.split("/");
702
+ const values = main.includes(",") ? main.split(",").map(s => s.trim()).filter(Boolean) : main.trim().split(/\s+/);
703
+ // Legacy rgba(r, g, b, a) and hsla carry alpha as a fourth argument; color(space c1 c2 c3) does not.
704
+ if (legacyAlpha && slash === undefined && values.length === 4)
705
+ return { values: values.slice(0, 3), alpha: values[3] };
706
+ return { values, alpha: slash?.trim() };
707
+ }
708
+ function linearToSrgb(value) {
709
+ const v = clamp(value, 0, 1);
710
+ return 255 * (v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055);
711
+ }
712
+ function fromOklab(l, a, b, opacity) {
713
+ const l1 = Math.pow(l + 0.3963377774 * a + 0.2158037573 * b, 3), m1 = Math.pow(l - 0.1055613458 * a - 0.0638541728 * b, 3);
714
+ const s1 = Math.pow(l - 0.0894841775 * a - 1.2914855480 * b, 3);
715
+ const r = 4.0767416621 * l1 - 3.3077115913 * m1 + 0.2309699292 * s1;
716
+ const g = -1.2684380046 * l1 + 2.6097574011 * m1 - 0.3413193965 * s1;
717
+ const blue = -0.0041960863 * l1 - 0.7034186147 * m1 + 1.7076147010 * s1;
718
+ if (![r, g, blue].every(Number.isFinite))
719
+ return undefined;
720
+ return { r: linearToSrgb(r), g: linearToSrgb(g), b: linearToSrgb(blue), a: opacity };
721
+ }
722
+ function hue(text) {
723
+ const value = parseFloat(text);
724
+ return text.endsWith("turn") ? value * 360 : text.endsWith("rad") ? value * 180 / Math.PI : value;
725
+ }
726
+ /** Parse the CSS color forms a browser's computed style and SVG presentation attributes produce. */
727
+ function parseColor(input) {
728
+ const text = input.trim().toLowerCase();
729
+ if (!text)
730
+ return undefined;
731
+ if (text === "transparent")
732
+ return { r: 0, g: 0, b: 0, a: 0 };
733
+ const hex = /^#([0-9a-f]{3,8})$/.exec(text)?.[1];
734
+ if (hex) {
735
+ if (hex.length === 3 || hex.length === 4) {
736
+ const [r, g, b, a] = [...hex].map(c => parseInt(c + c, 16));
737
+ return { r: r, g: g, b: b, a: a === undefined ? 1 : a / 255 };
738
+ }
739
+ if (hex.length === 6 || hex.length === 8)
740
+ return { r: parseInt(hex.slice(0, 2), 16), g: parseInt(hex.slice(2, 4), 16), b: parseInt(hex.slice(4, 6), 16), a: hex.length === 8 ? parseInt(hex.slice(6), 16) / 255 : 1 };
741
+ return undefined;
742
+ }
743
+ const known = named[text];
744
+ if (known)
745
+ return parseColor("#" + known);
746
+ const call = /^([a-z]+)\((.*)\)$/.exec(text);
747
+ if (!call)
748
+ return undefined;
749
+ const name = call[1], { values, alpha: opacity } = functionArguments(call[2], name !== "color");
750
+ if (values.some(value => !/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(%|deg|rad|turn)?$/.test(value) && value !== "none")) {
751
+ if (name !== "color")
752
+ return undefined;
753
+ }
754
+ const a = alpha(opacity);
755
+ if (a === undefined)
756
+ return undefined;
757
+ const v = values.map(value => value === "none" ? "0" : value);
758
+ if ((name === "rgb" || name === "rgba") && v.length === 3)
759
+ return { r: clamp(channel(v[0], 255), 0, 255), g: clamp(channel(v[1], 255), 0, 255), b: clamp(channel(v[2], 255), 0, 255), a };
760
+ if ((name === "hsl" || name === "hsla") && v.length === 3) {
761
+ const h = ((hue(v[0]) % 360) + 360) % 360 / 360, s = clamp(parseFloat(v[1]) / 100, 0, 1), l = clamp(parseFloat(v[2]) / 100, 0, 1);
762
+ const q = l < .5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
763
+ const tone = (t) => { t = (t + 1) % 1; return 255 * (t < 1 / 6 ? p + (q - p) * 6 * t : t < .5 ? q : t < 2 / 3 ? p + (q - p) * (2 / 3 - t) * 6 : p); };
764
+ return { r: tone(h + 1 / 3), g: tone(h), b: tone(h - 1 / 3), a };
765
+ }
766
+ if (name === "oklab" && v.length === 3)
767
+ return fromOklab(channel(v[0], 1), channel(v[1], .4), channel(v[2], .4), a);
768
+ if (name === "oklch" && v.length === 3) {
769
+ const l = channel(v[0], 1), c = channel(v[1], .4), h = hue(v[2]) * Math.PI / 180;
770
+ return fromOklab(l, c * Math.cos(h), c * Math.sin(h), a);
771
+ }
772
+ if (name === "color" && v.length === 4 && (v[0] === "srgb" || v[0] === "srgb-linear")) {
773
+ const parts = v.slice(1).map(value => channel(value, 1));
774
+ const convert = v[0] === "srgb" ? (x) => clamp(x, 0, 1) * 255 : linearToSrgb;
775
+ if (!parts.every(Number.isFinite))
776
+ return undefined;
777
+ return { r: convert(parts[0]), g: convert(parts[1]), b: convert(parts[2]), a };
778
+ }
779
+ return undefined;
780
+ }
781
+ /** Composite over white, the page colour, and return six-digit hex for the PDF drawing contract. */
782
+ function flatten(color, opacity) {
783
+ const a = clamp(color.a * opacity, 0, 1);
784
+ if (a < 0.002)
785
+ return undefined;
786
+ const mix = (value) => Math.round(clamp(value, 0, 255) * a + 255 * (1 - a)).toString(16).padStart(2, "0").toUpperCase();
787
+ return mix(color.r) + mix(color.g) + mix(color.b);
788
+ }
789
+ /** Inline `style` declarations as a map; later declarations win, `!important` is accepted and dropped. */
790
+ function parseStyle(text) {
791
+ const result = new Map();
792
+ if (!text)
793
+ return result;
794
+ const important = new Set();
795
+ for (const declaration of text.split(";")) {
796
+ const colon = declaration.indexOf(":");
797
+ if (colon < 0)
798
+ continue;
799
+ const name = declaration.slice(0, colon).trim().toLowerCase(), raw = declaration.slice(colon + 1);
800
+ const priority = /!\s*important\s*$/i;
801
+ const value = raw.replace(priority, "").trim(), takesPriority = priority.test(raw);
802
+ if (!name || !value || important.has(name) && !takesPriority)
803
+ continue;
804
+ if (takesPriority)
805
+ important.add(name);
806
+ result.set(name, value);
807
+ }
808
+ return result;
809
+ }
810
+ /** A CSS/SVG length in user units. Percentages resolve against `reference`; `em` against the font size. */
811
+ function length(text, fontSize, reference = 0) {
812
+ if (text === undefined)
813
+ return undefined;
814
+ const match = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)\s*(px|pt|pc|mm|cm|in|em|rem|ex|%)?\s*$/.exec(text);
815
+ if (!match)
816
+ return undefined;
817
+ const value = Number(match[1]), unit = match[2];
818
+ const factor = unit === undefined || unit === "px" ? 1 : unit === "pt" ? 4 / 3 : unit === "pc" ? 16 : unit === "mm" ? 96 / 25.4 : unit === "cm" ? 96 / 2.54 :
819
+ unit === "in" ? 96 : unit === "em" ? fontSize : unit === "rem" ? 16 : unit === "ex" ? fontSize / 2 : reference / 100;
820
+ const result = value * factor;
821
+ return Number.isFinite(result) ? result : undefined;
822
+ }
823
+ const _exports = Object.freeze({ alpha: alpha, parseColor: parseColor, flatten: flatten, parseStyle: parseStyle, length: length });
824
+ _modules.set("f2ed937ff699a1d52b7e285a0008b74f6cc95abfd4bdbeb65a6fd71beb3610e5", _exports);
825
+ return _exports;
826
+ })();
827
+
828
+ const _m21 = _modules.get("121725bdf2bbb700556fc2c27134a47be8f7f0314a1bcffdab5bbc886f1ef089") ?? (() => {
829
+ const { standardCode } = _c13;
830
+
831
+ const replacements = new Map([[0x2212, "-"], [0x2010, "-"], [0x2011, "-"], [0x2012, "-"], [0x2009, " "], [0x200a, " "],
832
+ [0x202f, " "], [0x2007, " "], [0x2002, " "], [0x2003, " "], [0x200b, ""], [0x200e, ""], [0x200f, ""], [0x2060, ""], [0xfeff, ""]]);
833
+ // Latin letters whose stroke or form has no canonical decomposition to a base letter.
834
+ const baseLetters = new Map([[0x141, "L"], [0x142, "l"], [0x110, "D"], [0x111, "d"], [0x126, "H"], [0x127, "h"],
835
+ [0x131, "i"], [0x13f, "L"], [0x140, "l"], [0x166, "T"], [0x167, "t"], [0x180, "b"], [0x197, "I"], [0x1b5, "Z"], [0x1b6, "z"], [0x1e9e, "SS"]]);
836
+ /** A Latin letter outside WinAnsi without its diacritic, for example `Ł` → `L` and `ą` → `a`. */
837
+ function baseLetter(character) {
838
+ const base = baseLetters.get(character.codePointAt(0));
839
+ if (base !== undefined)
840
+ return base;
841
+ if (!/\p{Script=Latin}/u.test(character))
842
+ return undefined;
843
+ const stripped = character.normalize("NFD").replace(/\p{Mark}+/gu, "");
844
+ return stripped && stripped !== character && [...stripped].every(part => standardCode(part.codePointAt(0)) !== undefined) ? stripped : undefined;
845
+ }
846
+ /** Keep text within the standard PDF fonts' WinAnsi repertoire: typographic minus and spaces get their ASCII
847
+ * equivalents, invisible marks are dropped, other Latin letters lose their diacritics and any other character becomes
848
+ * `?`. Every changed letter or `?` is reported through `substituted`. */
849
+ function winAnsiText(text, substituted) {
850
+ let result = "";
851
+ // Canonically equivalent Latin spellings should keep the same WinAnsi accents.
852
+ const composed = text.normalize("NFC").replace(/(\p{Script=Latin})\p{Mark}+/gu, (_sequence, letter) => {
853
+ substituted();
854
+ return letter;
855
+ });
856
+ for (const character of composed) {
857
+ const scalar = character.codePointAt(0);
858
+ if (scalar === 0xad)
859
+ continue; // A soft hyphen is invisible on an unbroken line.
860
+ if (standardCode(scalar) !== undefined) {
861
+ result += character;
862
+ continue;
863
+ }
864
+ if (scalar === 10 || scalar === 13 || scalar === 9) {
865
+ result += character;
866
+ continue;
867
+ }
868
+ const replacement = replacements.get(scalar);
869
+ if (replacement !== undefined) {
870
+ result += replacement;
871
+ continue;
872
+ }
873
+ substituted();
874
+ result += baseLetter(character) ?? "?";
875
+ }
876
+ return result;
877
+ }
878
+ const _exports = Object.freeze({ winAnsiText: winAnsiText });
879
+ _modules.set("121725bdf2bbb700556fc2c27134a47be8f7f0314a1bcffdab5bbc886f1ef089", _exports);
880
+ return _exports;
881
+ })();
882
+
883
+ const _m12 = _modules.get("11cb7de812b31909ea7f244067c0bbb605bdb3c85ca2e304d9b006893fb22eed") ?? (() => {
884
+ const { NotSupportedError, OfficeIMOError } = _c8;
885
+
886
+ const { checkAbort } = _c9;
887
+
888
+ const { pdfNumber } = _c10;
889
+
890
+ const { capturePdfLimits, pdfDrawingLimits, pdfDrawingMaxDepth } = _c4;
891
+
892
+ const { svgDataImage } = _m15;
893
+
894
+ const { parseSvgMarkup } = _m18;
895
+
896
+ const { apply, determinant, ellipse, identity, multiply, numbers, parsePathData, parseTransform, polyline, rectangle, scaleOf, transformCommands } = _m19;
897
+
898
+ const { alpha, flatten, length, parseColor, parseStyle } = _m20;
899
+
900
+ const { winAnsiText } = _m21;
901
+
902
+ const inherited = new Set(["fill", "fill-opacity", "fill-rule", "stroke", "stroke-opacity", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "paint-order",
903
+ "stroke-dasharray", "stroke-dashoffset", "font-size", "font-weight", "font-style", "text-anchor", "dominant-baseline", "alignment-baseline",
904
+ "color", "visibility", "white-space"]);
905
+ const own = ["opacity", "display", "clip-path", "mask", "filter", "marker-start", "marker-mid", "marker-end", "vector-effect", "overflow"];
906
+ const skipped = new Set(["defs", "clipPath", "mask", "marker", "pattern", "linearGradient", "radialGradient", "symbol", "script", "title", "desc",
907
+ "metadata", "filter", "stop", "font", "font-face"]);
908
+ const containers = new Set(["svg", "symbol", "g", "a", "use", "switch"]);
909
+ const shapes = new Set(["path", "rect", "circle", "ellipse", "line", "polyline", "polygon"]);
910
+ const initial = new Map([["fill", "black"], ["stroke", "none"], ["stroke-width", "1"], ["font-size", "16"], ["color", "black"]]);
911
+ const nonUniform = (m) => {
912
+ const tolerance = 1e-6, xScale = Math.hypot(m[0], m[1]), yScale = Math.hypot(m[2], m[3]);
913
+ return Math.abs(xScale - yScale) > tolerance * Math.max(xScale, yScale) ||
914
+ Math.abs(m[0] * m[2] + m[1] * m[3]) > tolerance * xScale * yScale;
915
+ };
916
+ function svgToPdfDrawing(svg, options, version, signal) {
917
+ const limits = options.limits === undefined ? undefined : capturePdfLimits(options.limits);
918
+ const maxElements = limits?.maxDrawingElements ?? pdfDrawingLimits.maxDrawingElements;
919
+ const maxCommands = limits?.maxVectorCommands ?? pdfDrawingLimits.maxVectorCommands;
920
+ const maxWork = Math.max(4096, 16 * Math.max(maxElements, maxCommands));
921
+ let elementCount = 0, commandCount = 0, work = 0;
922
+ const charge = (amount = 1) => {
923
+ checkAbort(signal);
924
+ work += amount;
925
+ if (work > maxWork)
926
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Chart SVG conversion work limit exceeded.");
927
+ };
928
+ const chargeText = (value) => { if (value)
929
+ charge(Math.ceil(value.length / 16)); };
930
+ const addElement = (target, element) => {
931
+ if (++elementCount > maxElements)
932
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxDrawingElements exceeded.");
933
+ target.push(element);
934
+ };
935
+ if (typeof svg === "string")
936
+ charge(Math.ceil(svg.length / 16));
937
+ const root = parseSvgMarkup(svg), ids = new Map(), reported = new Set();
938
+ const fonts = new Set(options.fonts ?? ["regular", "bold", "italic", "boldItalic"]), winAnsi = options.winAnsi !== false;
939
+ const index = (node) => {
940
+ charge();
941
+ const id = node.attributes.get("id");
942
+ if (id !== undefined && !ids.has(id))
943
+ ids.set(id, node);
944
+ for (const child of node.children)
945
+ if (typeof child !== "string")
946
+ index(child);
947
+ };
948
+ index(root);
949
+ // Skippable effects are reported once per code; reject turns the first into an error.
950
+ const diagnose = (code, element) => {
951
+ if (options.unsupported === "reject")
952
+ throw new NotSupportedError("Unsupported chart SVG feature: " + code + (element ? " (<" + element + ">)" : ""));
953
+ if (reported.has(code))
954
+ return;
955
+ reported.add(code);
956
+ const diagnostic = element === undefined ? { code } : { code, element };
957
+ options.onDiagnostic?.(diagnostic);
958
+ };
959
+ const attribute = (node, name) => node.attributes.get(name);
960
+ const viewport = (node, fontSize, fallbackWidth, fallbackHeight, nested = false, size) => {
961
+ const viewBox = attribute(node, "viewBox");
962
+ chargeText(viewBox);
963
+ const box = numbers(viewBox ?? ""), hasBox = box.length === 4 && box[2] > 0 && box[3] > 0;
964
+ const referenceWidth = nested || !hasBox ? fallbackWidth : box[2], referenceHeight = nested || !hasBox ? fallbackHeight : box[3];
965
+ const width = size?.width ?? length(attribute(node, "width"), fontSize, referenceWidth) ?? referenceWidth;
966
+ const height = size?.height ?? length(attribute(node, "height"), fontSize, referenceHeight) ?? referenceHeight;
967
+ if (!hasBox)
968
+ return { width, height, userWidth: width, userHeight: height, originZero: true, matrix: identity };
969
+ const aspect = (attribute(node, "preserveAspectRatio") ?? "xMidYMid meet").trim().split(/\s+/);
970
+ let sx = width / box[2], sy = height / box[3], tx = 0, ty = 0;
971
+ if (aspect[0] !== "none") {
972
+ const scale = aspect[1] === "slice" ? Math.max(sx, sy) : Math.min(sx, sy), align = aspect[0] ?? "xMidYMid";
973
+ tx = (width - box[2] * scale) * (align.includes("xMid") ? .5 : align.includes("xMax") ? 1 : 0);
974
+ ty = (height - box[3] * scale) * (align.includes("YMid") ? .5 : align.includes("YMax") ? 1 : 0);
975
+ sx = sy = scale;
976
+ }
977
+ const matrix = [sx, 0, 0, sy, tx - box[0] * sx, ty - box[1] * sy];
978
+ return { width, height, userWidth: box[2], userHeight: box[3], originZero: box[0] === 0 && box[1] === 0, matrix };
979
+ };
980
+ const outer = viewport(root, 16, 0, 0);
981
+ if (!(outer.width > 0 && outer.height > 0))
982
+ throw new TypeError("Chart SVG needs a positive width and height or viewBox.");
983
+ // Points at 96 CSS px per inch, reduced further only when the drawing would exceed the PDF drawing bounds.
984
+ const unit = Math.min(.75, 14400 / outer.width, 14400 / outer.height);
985
+ const drawingWidth = Math.min(14400, outer.width * unit), drawingHeight = Math.min(14400, outer.height * unit);
986
+ const elements = [];
987
+ function declarations(node) {
988
+ const inline = attribute(node, "style");
989
+ chargeText(inline);
990
+ return parseStyle(inline);
991
+ }
992
+ function localTransform(node, declared, parent, fontSize) {
993
+ const read = (name) => declared.get(name) ?? attribute(node, name);
994
+ const value = read("transform");
995
+ chargeText(value);
996
+ const matrix = parseTransform(value);
997
+ if (!matrix) {
998
+ diagnose("TRANSFORM_UNSUPPORTED", node.local);
999
+ return undefined;
1000
+ }
1001
+ if (matrix[0] === 1 && matrix[1] === 0 && matrix[2] === 0 && matrix[3] === 1)
1002
+ return matrix;
1003
+ const box = read("transform-box") ?? "view-box";
1004
+ if (parent.viewportOriginZero && ["view-box", "initial", "unset"].includes(box)) {
1005
+ const origin = read("transform-origin");
1006
+ if (origin === undefined)
1007
+ return matrix;
1008
+ chargeText(origin);
1009
+ const [first, second, third, extra] = origin.trim().split(/\s+/, 4);
1010
+ const x = length(first, fontSize, parent.userWidth), y = length(second, fontSize, parent.userHeight);
1011
+ if (x !== undefined && y !== undefined && (third === undefined || /^0(?:px)?$/.test(third)) && extra === undefined)
1012
+ return [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4] + x - matrix[0] * x - matrix[2] * y,
1013
+ matrix[5] + y - matrix[1] * x - matrix[3] * y];
1014
+ }
1015
+ diagnose("TRANSFORM_ORIGIN_IGNORED", node.local);
1016
+ return undefined;
1017
+ }
1018
+ function cascade(node, parent) {
1019
+ const declared = declarations(node), values = new Map();
1020
+ let style = parent.style, changed = false;
1021
+ const read = (name) => declared.get(name) ?? attribute(node, name);
1022
+ for (const name of inherited) {
1023
+ const authored = read(name);
1024
+ if (authored === undefined || authored === "inherit" || authored === "unset")
1025
+ continue;
1026
+ const value = authored === "initial" ? initial.get(name) : authored;
1027
+ if (value === parent.style.get(name))
1028
+ continue;
1029
+ if (!changed) {
1030
+ style = new Map(parent.style);
1031
+ changed = true;
1032
+ }
1033
+ if (value === undefined)
1034
+ style.delete(name);
1035
+ else
1036
+ style.set(name, value);
1037
+ }
1038
+ for (const name of own) {
1039
+ const value = read(name);
1040
+ if (value !== undefined)
1041
+ values.set(name, value);
1042
+ }
1043
+ if (values.get("display") === "none")
1044
+ return undefined;
1045
+ const size = read("font-size");
1046
+ const fontSize = size === "initial" ? 16 : size !== undefined ? fontSizeOf(size, parent.fontSize) : parent.fontSize;
1047
+ const transform = localTransform(node, declared, parent, fontSize);
1048
+ const overflow = values.get("overflow")?.trim();
1049
+ const clipOverflowByDefault = node.local === "image" || ((node.local === "svg" || node.local === "symbol") && node !== root);
1050
+ const overflowVisible = overflow === "inherit" ? parent.overflowVisible :
1051
+ overflow === undefined || overflow === "revert" ? !clipOverflowByDefault : /^(?:visible(?:\s+visible)?|initial|unset)$/.test(overflow);
1052
+ const opacityValue = values.get("opacity");
1053
+ const localOpacity = version === 2 && opacityValue?.trim() === "inherit" ? parent.localOpacity : alpha(opacityValue) ?? 1;
1054
+ const groupOpacity = version === 2 && containers.has(node.local) && localOpacity > 0 && localOpacity < 1;
1055
+ if (!groupOpacity && localOpacity < 1 && localOpacity > 0 && node.local !== "image")
1056
+ diagnose("OPACITY_FLATTENED", node.local);
1057
+ const xmlSpace = attribute(node, "xml:space");
1058
+ const context = { ...parent, matrix: multiply(parent.matrix, transform ?? identity),
1059
+ imageTransformValid: parent.imageTransformValid && transform !== undefined, style, fontSize, localOpacity, opacity: parent.opacity * localOpacity,
1060
+ overflowVisible, ...(xmlSpace === undefined ? {} : { xmlSpace }) };
1061
+ return { context, own: values, declared, groupOpacity };
1062
+ }
1063
+ function fontSizeOf(value, parent) {
1064
+ const keywords = { "xx-small": 9, "x-small": 10, small: 13, medium: 16, large: 18, "x-large": 24, "xx-large": 32 };
1065
+ const size = keywords[value.trim()] ?? length(value, parent, parent);
1066
+ return size !== undefined && size > 0 ? size : parent;
1067
+ }
1068
+ function paint(value, context, opacityName, element) {
1069
+ if (value === undefined || value === "none")
1070
+ return undefined;
1071
+ charge(Math.ceil(value.length / 16));
1072
+ let color;
1073
+ const reference = /^url\(\s*["']?#([^"')]+)["']?\s*\)\s*(.*)$/.exec(value.trim());
1074
+ if (reference) {
1075
+ const target = ids.get(reference[1]), fallback = reference[2].trim();
1076
+ if (target && (target.local === "linearGradient" || target.local === "radialGradient")) {
1077
+ color = gradientColor(target);
1078
+ diagnose("GRADIENT_FLATTENED", element);
1079
+ }
1080
+ else if (fallback && fallback !== "none")
1081
+ color = parseColor(fallback);
1082
+ else {
1083
+ diagnose("PAINT_UNSUPPORTED", element);
1084
+ return undefined;
1085
+ }
1086
+ }
1087
+ else if (value.trim().toLowerCase() === "currentcolor") {
1088
+ const current = context.style.get("color") ?? "black";
1089
+ chargeText(current);
1090
+ color = parseColor(current);
1091
+ }
1092
+ else
1093
+ color = parseColor(value);
1094
+ if (!color) {
1095
+ diagnose("COLOR_UNSUPPORTED", element);
1096
+ return undefined;
1097
+ }
1098
+ const effective = (alpha(context.style.get(opacityName)) ?? 1) * context.opacity;
1099
+ if (color.a * effective < 1 && color.a * effective >= .002)
1100
+ diagnose("OPACITY_FLATTENED", element);
1101
+ return flatten(color, effective);
1102
+ }
1103
+ function gradientColor(node) {
1104
+ const seen = new Set();
1105
+ let current = node;
1106
+ while (current && !seen.has(current)) {
1107
+ charge();
1108
+ seen.add(current);
1109
+ for (const child of current.children) {
1110
+ charge();
1111
+ if (typeof child === "string" || child.local !== "stop")
1112
+ continue;
1113
+ const declared = declarations(child);
1114
+ const stop = declared.get("stop-color") ?? attribute(child, "stop-color") ?? "black";
1115
+ charge(Math.ceil(stop.length / 16));
1116
+ const color = parseColor(stop);
1117
+ const opacity = alpha(declared.get("stop-opacity") ?? attribute(child, "stop-opacity")) ?? 1;
1118
+ return color && { ...color, a: color.a * opacity };
1119
+ }
1120
+ const href = (attribute(current, "href") ?? attribute(current, "xlink:href"))?.replace(/^#/, "");
1121
+ current = href === undefined ? undefined : ids.get(href);
1122
+ }
1123
+ return undefined;
1124
+ }
1125
+ // Consecutive paths with identical paint merge into one element, which keeps dense scatter and bar charts within drawing
1126
+ // budgets. Only strokes and simple shapes of one winding merge, so a nonzero fill never gains a hole.
1127
+ const mergeKeys = new WeakMap();
1128
+ function pushPath(target, path, key) {
1129
+ const last = target[target.length - 1];
1130
+ if (key !== undefined && last && last.kind === "path" && mergeKeys.get(last) === key && last.commands.length + path.commands.length <= 4096) {
1131
+ last.commands.push(...path.commands);
1132
+ return;
1133
+ }
1134
+ if (key !== undefined)
1135
+ mergeKeys.set(path, key);
1136
+ addElement(target, path);
1137
+ }
1138
+ function shape(node, context, target, values) {
1139
+ const { userWidth, userHeight } = context;
1140
+ const diagonal = Math.hypot(userWidth, userHeight) / Math.SQRT2;
1141
+ const a = (name, reference = 0) => length(attribute(node, name), context.fontSize, reference) ?? 0;
1142
+ let commands;
1143
+ switch (node.local) {
1144
+ case "rect": {
1145
+ const width = a("width", userWidth), height = a("height", userHeight);
1146
+ if (!(width > 0 && height > 0))
1147
+ return;
1148
+ const rxValue = attribute(node, "rx"), ryValue = attribute(node, "ry");
1149
+ const rx = rxValue === undefined || rxValue === "auto" ? a("ry", userHeight) : a("rx", userWidth);
1150
+ const ry = ryValue === undefined || ryValue === "auto" ? rx : a("ry", userHeight);
1151
+ commands = rectangle(a("x", userWidth), a("y", userHeight), width, height, rx, ry);
1152
+ break;
1153
+ }
1154
+ case "circle": {
1155
+ const r = a("r", diagonal);
1156
+ if (!(r > 0))
1157
+ return;
1158
+ commands = ellipse(a("cx", userWidth), a("cy", userHeight), r, r);
1159
+ break;
1160
+ }
1161
+ case "ellipse": {
1162
+ const rx = a("rx", userWidth), ry = a("ry", userHeight);
1163
+ if (!(rx > 0 && ry > 0))
1164
+ return;
1165
+ commands = ellipse(a("cx", userWidth), a("cy", userHeight), rx, ry);
1166
+ break;
1167
+ }
1168
+ case "line":
1169
+ commands = [{ op: "move", x: a("x1", userWidth), y: a("y1", userHeight) }, { op: "line", x: a("x2", userWidth), y: a("y2", userHeight) }];
1170
+ break;
1171
+ case "polyline":
1172
+ case "polygon": {
1173
+ const points = attribute(node, "points") ?? "";
1174
+ charge(Math.ceil(points.length / 4));
1175
+ commands = polyline(numbers(points), node.local === "polygon");
1176
+ break;
1177
+ }
1178
+ default: {
1179
+ const data = attribute(node, "d") ?? "";
1180
+ charge(Math.ceil(data.length / 4));
1181
+ const parsed = parsePathData(data);
1182
+ if (parsed.malformed)
1183
+ diagnose("PATH_DATA_TRUNCATED", "path");
1184
+ commands = parsed.commands;
1185
+ }
1186
+ }
1187
+ if (!commands.length)
1188
+ return;
1189
+ for (const marker of ["marker-start", "marker-mid", "marker-end"])
1190
+ if (values.get(marker) && values.get(marker) !== "none")
1191
+ diagnose("MARKER_IGNORED", node.local);
1192
+ const fill = node.local === "line" ? undefined : paint(context.style.get("fill"), context, "fill-opacity", node.local);
1193
+ const stroke = paint(context.style.get("stroke"), context, "stroke-opacity", node.local);
1194
+ if (fill === undefined && stroke === undefined)
1195
+ return;
1196
+ const fixedStroke = values.get("vector-effect") === "non-scaling-stroke";
1197
+ const scale = fixedStroke ? unit : scaleOf(context.matrix);
1198
+ const width = (length(context.style.get("stroke-width"), context.fontSize, diagonal) ?? 1) * scale;
1199
+ if (stroke !== undefined && !(width > 0) && fill === undefined)
1200
+ return;
1201
+ commandCount += commands.length;
1202
+ if (commandCount > maxCommands)
1203
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxVectorCommands exceeded.");
1204
+ const path = { kind: "path", commands: transformCommands(commands, context.matrix) };
1205
+ if (fill !== undefined) {
1206
+ path.fill = fill;
1207
+ if (context.style.get("fill-rule") === "evenodd")
1208
+ path.fillRule = "evenodd";
1209
+ }
1210
+ if (stroke !== undefined && width > 0) {
1211
+ if (!fixedStroke && nonUniform(context.matrix))
1212
+ diagnose("STROKE_DISTORTED", node.local);
1213
+ path.stroke = stroke;
1214
+ path.strokeWidth = width;
1215
+ const cap = context.style.get("stroke-linecap"), join = context.style.get("stroke-linejoin");
1216
+ if (cap === "round" || cap === "square")
1217
+ path.lineCap = cap;
1218
+ if (join === "round" || join === "bevel")
1219
+ path.lineJoin = join;
1220
+ else {
1221
+ const limit = Number(context.style.get("stroke-miterlimit") ?? "4");
1222
+ if (limit >= 0 && limit < 1)
1223
+ path.lineJoin = "bevel";
1224
+ else if (limit >= 1 && limit <= 1000000)
1225
+ path.miterLimit = limit;
1226
+ else {
1227
+ diagnose("MITER_LIMIT_UNSUPPORTED", node.local);
1228
+ path.miterLimit = 4;
1229
+ }
1230
+ }
1231
+ const paintOrder = context.style.get("paint-order");
1232
+ if (fill !== undefined && paintOrder && paintOrder !== "normal") {
1233
+ chargeText(paintOrder);
1234
+ const order = paintOrder.split(/\s+/), fillIndex = order.indexOf("fill"), strokeIndex = order.indexOf("stroke");
1235
+ if (strokeIndex >= 0 && (fillIndex < 0 || strokeIndex < fillIndex))
1236
+ diagnose("PAINT_ORDER_IGNORED", node.local);
1237
+ }
1238
+ const dashValue = context.style.get("stroke-dasharray");
1239
+ chargeText(dashValue);
1240
+ const dash = dashValue?.trim();
1241
+ if (dash !== "none" && dash) {
1242
+ const parts = dash.split(/[\s,]+/, 17).map(part => length(part, context.fontSize, diagonal));
1243
+ if (parts.every(part => part !== undefined && part >= 0) && parts.some(part => part > 0)) {
1244
+ const list = parts.map(part => part * scale);
1245
+ const offsetValue = context.style.get("stroke-dashoffset");
1246
+ chargeText(offsetValue);
1247
+ const offset = (length(offsetValue, context.fontSize, diagonal) ?? 0) * scale;
1248
+ if (list.length <= 16 && list.every(part => part <= 14400) && list.some(part => pdfNumber(part) !== "0") && Math.abs(offset) <= 1000000) {
1249
+ path.dash = list;
1250
+ if (offset)
1251
+ path.dashOffset = offset;
1252
+ }
1253
+ else
1254
+ diagnose("DASH_UNSUPPORTED", node.local);
1255
+ }
1256
+ else if (parts.some(part => part === undefined || part < 0))
1257
+ diagnose("DASH_UNSUPPORTED", node.local);
1258
+ }
1259
+ }
1260
+ if (path.fill === undefined && path.stroke === undefined)
1261
+ return;
1262
+ const mergeable = path.fill === undefined ||
1263
+ (path.stroke === undefined || path.stroke === path.fill) && path.fillRule === undefined && ["rect", "circle", "ellipse"].includes(node.local);
1264
+ const det = determinant(context.matrix);
1265
+ pushPath(target, path, mergeable ? JSON.stringify([path.fill, det < 0, path.stroke, path.strokeWidth, path.lineCap, path.lineJoin, path.miterLimit, path.dash, path.dashOffset]) : undefined);
1266
+ }
1267
+ function textRuns(node, context, target) {
1268
+ const runs = [];
1269
+ let x = 0, y = 0, current;
1270
+ let hiddenAdvance = false, hiddenSpace = false;
1271
+ const visible = (at) => at.style.get("visibility") !== "hidden" && at.style.get("visibility") !== "collapse" && at.opacity > 0;
1272
+ const finishRun = () => {
1273
+ const anchor = current?.context.style.get("text-anchor");
1274
+ if (hiddenAdvance && current?.text && (anchor === "middle" || anchor === "end"))
1275
+ diagnose("TEXT_POSITIONS_SIMPLIFIED", "text");
1276
+ };
1277
+ const walk = (element, at, first) => {
1278
+ charge();
1279
+ const preserve = at.xmlSpace === "preserve" || /^pre/.test(at.style.get("white-space") ?? "");
1280
+ const list = (name, reference) => (attribute(element, name) ?? "").trim().split(/[\s,]+/).filter(Boolean)
1281
+ .map(item => length(item, at.fontSize, reference)).filter((item) => item !== undefined);
1282
+ const xs = list("x", at.userWidth), ys = list("y", at.userHeight), dxs = list("dx", at.userWidth), dys = list("dy", at.userHeight);
1283
+ if (xs.length > 1 || ys.length > 1 || dxs.length > 1 || dys.length > 1 || attribute(element, "rotate") !== undefined)
1284
+ diagnose("TEXT_POSITIONS_SIMPLIFIED", element.local);
1285
+ const positioned = first || xs.length > 0 || ys.length > 0 || dxs.length > 0 || dys.length > 0;
1286
+ // Without x, a move is relative to where the unmeasured earlier text ends.
1287
+ if (!first && positioned && !xs.length && current?.text.trim())
1288
+ diagnose("TEXT_POSITIONS_SIMPLIFIED", element.local);
1289
+ if (positioned) {
1290
+ finishRun();
1291
+ if (xs.length) {
1292
+ x = xs[0];
1293
+ hiddenAdvance = false;
1294
+ hiddenSpace = false;
1295
+ }
1296
+ if (ys.length)
1297
+ y = ys[0];
1298
+ x += dxs[0] ?? 0;
1299
+ y += dys[0] ?? 0;
1300
+ current = { x, y, text: "", context: at, preserve };
1301
+ runs.push(current);
1302
+ }
1303
+ for (const child of element.children) {
1304
+ if (typeof child === "string") {
1305
+ charge(1 + Math.ceil(child.length / 16));
1306
+ if (!current)
1307
+ continue;
1308
+ const advances = preserve && child.length > 0 || /[^\t\r\n ]/.test(child);
1309
+ if (!visible(at)) {
1310
+ hiddenAdvance ||= advances;
1311
+ hiddenSpace ||= /[ \t]/.test(child) && /[^\t\r\n ]$/.test(current.text);
1312
+ continue;
1313
+ }
1314
+ if (!advances && !visible(current.context))
1315
+ continue;
1316
+ if (advances) {
1317
+ const lostCollapsedSpace = hiddenSpace && /[^\t\r\n ]$/.test(current.text) && /^[^\t\r\n ]/.test(child);
1318
+ if (hiddenAdvance || lostCollapsedSpace)
1319
+ diagnose("TEXT_POSITIONS_SIMPLIFIED", element.local);
1320
+ hiddenAdvance = hiddenSpace = false;
1321
+ }
1322
+ if (!visible(current.context)) {
1323
+ current.context = at;
1324
+ current.preserve = preserve;
1325
+ }
1326
+ const from = current.context;
1327
+ if (current.preserve !== preserve && /[\t\r\n ]/.test(child))
1328
+ diagnose("TEXT_WHITESPACE_SIMPLIFIED", element.local);
1329
+ if (advances && from.matrix.some((component, i) => component !== at.matrix[i]))
1330
+ diagnose("TEXT_TRANSFORM_IGNORED", element.local);
1331
+ if ((from.style !== at.style || from.fontSize !== at.fontSize || from.opacity !== at.opacity) && /\S/.test(child))
1332
+ diagnose("TEXT_STYLE_MERGED", element.local);
1333
+ current.text += child;
1334
+ continue;
1335
+ }
1336
+ if (child.local !== "tspan" && child.local !== "a") {
1337
+ if (child.local === "textPath")
1338
+ diagnose("TEXT_PATH_IGNORED", "textPath");
1339
+ continue;
1340
+ }
1341
+ const nested = cascade(child, at);
1342
+ if (nested)
1343
+ walk(child, nested.context, false);
1344
+ }
1345
+ };
1346
+ walk(node, context, true);
1347
+ finishRun();
1348
+ for (const run of runs) {
1349
+ const style = run.context.style, { preserve } = run;
1350
+ let text = run.text.replace(/\t/g, " ").replace(/[\r\n]/g, preserve ? " " : "");
1351
+ if (!preserve)
1352
+ text = text.replace(/ {2,}/g, " ");
1353
+ if (run === runs[0] && !preserve)
1354
+ text = text.replace(/^ +/, "");
1355
+ if (run === runs[runs.length - 1] && !preserve)
1356
+ text = text.replace(/ +$/, "");
1357
+ if (!text)
1358
+ continue;
1359
+ if (style.get("visibility") === "hidden" || style.get("visibility") === "collapse")
1360
+ continue;
1361
+ const color = paint(style.get("fill"), run.context, "fill-opacity", "text");
1362
+ if (color === undefined)
1363
+ continue;
1364
+ if ((style.get("stroke") ?? "none") !== "none")
1365
+ diagnose("TEXT_STROKE_IGNORED", "text");
1366
+ const m = run.context.matrix, scale = scaleOf(m);
1367
+ if (nonUniform(m) || determinant(m) < 0)
1368
+ diagnose("TEXT_DISTORTED", "text");
1369
+ const size = run.context.fontSize * scale;
1370
+ if (!(size > 0))
1371
+ continue;
1372
+ const baseline = style.get("dominant-baseline") ?? style.get("alignment-baseline") ?? "auto";
1373
+ const shift = baseline === "middle" || baseline === "central" ? .35 : baseline === "hanging" || baseline === "text-before-edge" || baseline === "text-top" ? .8 :
1374
+ baseline === "text-after-edge" || baseline === "ideographic" || baseline === "text-bottom" ? -.2 : 0;
1375
+ const [px, py] = apply(m, run.x, run.y + shift * run.context.fontSize), rotation = Math.atan2(m[1], m[0]) * 180 / Math.PI;
1376
+ const weight = style.get("font-weight") ?? "normal", italic = /italic|oblique/.test(style.get("font-style") ?? "");
1377
+ const bold = weight === "bold" || weight === "bolder" || Number(weight) >= 600;
1378
+ let slot = bold && italic ? "boldItalic" : bold ? "bold" : italic ? "italic" : "regular";
1379
+ if (!fonts.has(slot))
1380
+ slot = "regular";
1381
+ const anchor = style.get("text-anchor");
1382
+ const painted = winAnsi ? winAnsiText(text, () => diagnose("TEXT_SUBSTITUTED", "text")) : text.normalize("NFC");
1383
+ const element = {
1384
+ kind: "text", text: painted, x: px, y: py, font: slot, fontSize: size, color
1385
+ };
1386
+ if (!element.text)
1387
+ continue;
1388
+ if (anchor === "middle" || anchor === "end")
1389
+ element.anchor = anchor;
1390
+ if (Math.abs(rotation) > 1e-6)
1391
+ element.rotation = Math.round(rotation * 1e6) / 1e6;
1392
+ addElement(target, element);
1393
+ }
1394
+ }
1395
+ function hasText(node) {
1396
+ return node.children.some(child => {
1397
+ charge(typeof child === "string" ? 1 + Math.ceil(child.length / 16) : 1);
1398
+ return typeof child === "string" ? /\S/.test(child) : hasText(child);
1399
+ });
1400
+ }
1401
+ function rectangularClip(matrix, x, y, width, height) {
1402
+ if (width <= 0 || height <= 0)
1403
+ return null;
1404
+ const axisAligned = Math.abs(matrix[1]) <= 1e-9 && Math.abs(matrix[2]) <= 1e-9;
1405
+ const axesSwapped = Math.abs(matrix[0]) <= 1e-9 && Math.abs(matrix[3]) <= 1e-9;
1406
+ if (!axisAligned && !axesSwapped)
1407
+ return undefined;
1408
+ const [x1, y1] = apply(matrix, x, y), [x2, y2] = apply(matrix, x + width, y + height);
1409
+ const left = Math.max(0, Math.min(x1, x2)), top = Math.max(0, Math.min(y1, y2));
1410
+ const right = Math.min(drawingWidth, Math.max(x1, x2)), bottom = Math.min(drawingHeight, Math.max(y1, y2));
1411
+ if (![left, top, right, bottom].every(Number.isFinite))
1412
+ return undefined;
1413
+ if (right <= left || bottom <= top)
1414
+ return null;
1415
+ return { x: left, y: top, width: right - left, height: bottom - top };
1416
+ }
1417
+ function clipFor(value, context, element) {
1418
+ if (value === undefined || value === "none")
1419
+ return undefined;
1420
+ chargeText(value);
1421
+ const id = /^url\(\s*["']?#([^"')]+)["']?\s*\)$/.exec(value.trim())?.[1], clip = id === undefined ? undefined : ids.get(id);
1422
+ if (clip?.local !== "clipPath") {
1423
+ diagnose("CLIP_IGNORED", element);
1424
+ return undefined;
1425
+ }
1426
+ const clipStyle = declarations(clip);
1427
+ const clipVisibility = clipStyle.get("visibility") ?? attribute(clip, "visibility");
1428
+ let rect;
1429
+ let rectStyle = initial;
1430
+ for (const child of clip.children) {
1431
+ charge();
1432
+ if (typeof child === "string")
1433
+ continue;
1434
+ const style = declarations(child);
1435
+ if ((style.get("display") ?? attribute(child, "display")) === "none")
1436
+ continue;
1437
+ const localVisibility = style.get("visibility") ?? attribute(child, "visibility");
1438
+ const visibility = localVisibility === undefined || localVisibility === "inherit" || localVisibility === "unset" ? clipVisibility : localVisibility;
1439
+ if (visibility === "hidden" || visibility === "collapse")
1440
+ continue;
1441
+ if (rect || child.local !== "rect") {
1442
+ diagnose("CLIP_IGNORED", element);
1443
+ return undefined;
1444
+ }
1445
+ rect = child;
1446
+ rectStyle = style;
1447
+ }
1448
+ if (!rect)
1449
+ return null;
1450
+ if (clip.attributes.get("clipPathUnits") === "objectBoundingBox") {
1451
+ diagnose("CLIP_IGNORED", element);
1452
+ return undefined;
1453
+ }
1454
+ const a = (name, reference) => length(rectStyle.get(name) ?? attribute(rect, name), context.fontSize, reference);
1455
+ const width = a("width", context.userWidth) ?? 0, height = a("height", context.userHeight) ?? 0;
1456
+ if (width <= 0 || height <= 0)
1457
+ return null;
1458
+ const rx = a("rx", context.userWidth), ry = a("ry", context.userHeight);
1459
+ if ((rx ?? ry ?? 0) > 0 && (ry ?? rx ?? 0) > 0) {
1460
+ diagnose("CLIP_IGNORED", element);
1461
+ return undefined;
1462
+ }
1463
+ const clipTransform = localTransform(clip, clipStyle, context, context.fontSize);
1464
+ const rectTransform = localTransform(rect, rectStyle, context, context.fontSize);
1465
+ if (!clipTransform || !rectTransform)
1466
+ return undefined;
1467
+ const r = multiply(context.matrix, multiply(clipTransform, rectTransform));
1468
+ const x = a("x", context.userWidth) ?? 0, y = a("y", context.userHeight) ?? 0;
1469
+ const shape = rectangularClip(r, x, y, width, height);
1470
+ if (shape === undefined)
1471
+ diagnose("CLIP_IGNORED", element);
1472
+ return shape;
1473
+ }
1474
+ // One decoded source per distinct data URL, so repeated artwork shares one PDF image.
1475
+ const decoded = new Map();
1476
+ function placeImage(node, context, declared, target) {
1477
+ const m = context.matrix;
1478
+ // Embedded images are placed upright and require a fully resolved transform.
1479
+ if (!context.imageTransformValid || Math.abs(m[1]) > 1e-9 || Math.abs(m[2]) > 1e-9 || !(m[0] > 0) || !(m[3] > 0)) {
1480
+ diagnose("IMAGE_SKIPPED", "image");
1481
+ return;
1482
+ }
1483
+ const href = (attribute(node, "href") ?? attribute(node, "xlink:href"))?.trim();
1484
+ let source = href === undefined ? null : decoded.get(href);
1485
+ if (href !== undefined && source === undefined) {
1486
+ charge(Math.ceil(href.length / 16));
1487
+ source = svgDataImage(href) ?? null;
1488
+ decoded.set(href, source);
1489
+ }
1490
+ if (!source) {
1491
+ diagnose("IMAGE_SKIPPED", "image");
1492
+ return;
1493
+ }
1494
+ const a = (name, reference) => length(declared.get(name) ?? attribute(node, name), context.fontSize, reference);
1495
+ const x = a("x", context.userWidth) ?? 0, y = a("y", context.userHeight) ?? 0;
1496
+ const declaredWidth = a("width", context.userWidth), declaredHeight = a("height", context.userHeight);
1497
+ const width = declaredWidth ?? (declaredHeight === undefined ? source.width : declaredHeight * source.width / source.height);
1498
+ const height = declaredHeight ?? (declaredWidth === undefined ? source.height : declaredWidth * source.height / source.width);
1499
+ if (!(width > 0 && height > 0))
1500
+ return;
1501
+ let placed = { x, y, width, height }, crop;
1502
+ const aspect = attribute(node, "preserveAspectRatio")?.trim().replace(/^defer(?:\s+|$)/, "");
1503
+ const [align = "xMidYMid", fit = "meet"] = (aspect || "xMidYMid meet").split(/\s+/);
1504
+ if (align !== "none") {
1505
+ const sx = width / source.width, sy = height / source.height, scale = fit === "slice" ? Math.max(sx, sy) : Math.min(sx, sy);
1506
+ const fittedWidth = source.width * scale, fittedHeight = source.height * scale;
1507
+ placed = { x: x + (width - fittedWidth) * (align.includes("xMid") ? .5 : align.includes("xMax") ? 1 : 0),
1508
+ y: y + (height - fittedHeight) * (align.includes("YMid") ? .5 : align.includes("YMax") ? 1 : 0), width: fittedWidth, height: fittedHeight };
1509
+ if (fit === "slice" && !context.overflowVisible) {
1510
+ crop = rectangularClip(m, x, y, width, height);
1511
+ if (crop === null)
1512
+ return;
1513
+ }
1514
+ }
1515
+ const [left, top] = apply(m, placed.x, placed.y), [right, bottom] = apply(m, placed.x + placed.width, placed.y + placed.height);
1516
+ const element = { kind: "image", image: source.image, x: left, y: top, width: right - left, height: bottom - top,
1517
+ ...(context.opacity < 1 ? { opacity: context.opacity } : {}) };
1518
+ if (![left, top, element.width, element.height].every(value => Number.isFinite(value) && Math.abs(value) <= 1000000) || !(element.width > 0 && element.height > 0)) {
1519
+ diagnose("IMAGE_SKIPPED", "image");
1520
+ return;
1521
+ }
1522
+ if (crop && context.clipDepth + 1 < pdfDrawingMaxDepth) {
1523
+ const group = [];
1524
+ addElement(group, element);
1525
+ addElement(target, { kind: "group", clip: crop, elements: group });
1526
+ }
1527
+ else {
1528
+ if (crop)
1529
+ diagnose("CLIP_DEPTH_IGNORED", "image");
1530
+ addElement(target, element);
1531
+ }
1532
+ }
1533
+ // A group with one image can use that image's opacity, even through nested rectangular clips.
1534
+ function singleImage(elements, start) {
1535
+ if (elements.length !== start + 1)
1536
+ return false;
1537
+ const element = elements[start];
1538
+ return element.kind === "image" || (element.kind === "group" && singleImage(element.elements, 0));
1539
+ }
1540
+ const active = new Set();
1541
+ function render(node, parent, target, depth, useSize) {
1542
+ charge();
1543
+ if (skipped.has(node.local) && !(node.local === "symbol" && useSize))
1544
+ return;
1545
+ if (depth > 512)
1546
+ throw new NotSupportedError("Chart SVG nesting is too deep.");
1547
+ if (node.local === "image" && version === 1) {
1548
+ diagnose("IMAGE_SKIPPED", "image");
1549
+ return;
1550
+ }
1551
+ if (node.local === "foreignObject") {
1552
+ diagnose("FOREIGN_OBJECT_SKIPPED", "foreignObject");
1553
+ return;
1554
+ }
1555
+ if (node.local === "style") {
1556
+ if (hasText(node))
1557
+ diagnose("STYLESHEET_IGNORED", "style");
1558
+ return;
1559
+ }
1560
+ const cascaded = cascade(node, parent);
1561
+ if (!cascaded || cascaded.context.opacity <= 0)
1562
+ return;
1563
+ let { context } = cascaded;
1564
+ const values = cascaded.own;
1565
+ if (values.get("mask") && values.get("mask") !== "none")
1566
+ diagnose("MASK_IGNORED", node.local);
1567
+ if (values.get("filter") && values.get("filter") !== "none")
1568
+ diagnose("FILTER_IGNORED", node.local);
1569
+ let viewportClip;
1570
+ if ((node.local === "svg" || node.local === "symbol") && node !== root) {
1571
+ const nested = viewport(node, context.fontSize, context.userWidth, context.userHeight, true, useSize);
1572
+ if (!(nested.width > 0 && nested.height > 0))
1573
+ return;
1574
+ const x = length(attribute(node, "x"), context.fontSize, context.userWidth) ?? 0, y = length(attribute(node, "y"), context.fontSize, context.userHeight) ?? 0;
1575
+ const placed = multiply(context.matrix, [1, 0, 0, 1, x, y]);
1576
+ if (!context.overflowVisible) {
1577
+ const clip = rectangularClip(placed, 0, 0, nested.width, nested.height);
1578
+ if (clip === null)
1579
+ return;
1580
+ viewportClip = clip;
1581
+ if (!viewportClip)
1582
+ diagnose("CLIP_IGNORED", node.local);
1583
+ }
1584
+ context = { ...context, userWidth: nested.userWidth, userHeight: nested.userHeight, viewportOriginZero: nested.originZero,
1585
+ matrix: multiply(placed, nested.matrix) };
1586
+ }
1587
+ let clip = clipFor(values.get("clip-path"), context, node.local);
1588
+ if (clip === null)
1589
+ return;
1590
+ if (clip && viewportClip) {
1591
+ const x = Math.max(clip.x, viewportClip.x), y = Math.max(clip.y, viewportClip.y);
1592
+ const width = Math.min(clip.x + clip.width, viewportClip.x + viewportClip.width) - x;
1593
+ const height = Math.min(clip.y + clip.height, viewportClip.y + viewportClip.height) - y;
1594
+ if (width <= 0 || height <= 0)
1595
+ return;
1596
+ clip = { x, y, width, height };
1597
+ }
1598
+ else
1599
+ clip ??= viewportClip;
1600
+ if (clip) {
1601
+ if (context.clipDepth + 1 >= pdfDrawingMaxDepth) {
1602
+ diagnose("CLIP_DEPTH_IGNORED", node.local);
1603
+ clip = undefined;
1604
+ }
1605
+ else
1606
+ context = { ...context, clipDepth: context.clipDepth + 1 };
1607
+ }
1608
+ const output = clip ? [] : target, start = output.length;
1609
+ const visible = context.style.get("visibility") !== "hidden" && context.style.get("visibility") !== "collapse";
1610
+ if (shapes.has(node.local)) {
1611
+ if (visible)
1612
+ shape(node, context, output, values);
1613
+ }
1614
+ else if (node.local === "text")
1615
+ textRuns(node, context, output);
1616
+ else if (node.local === "image") {
1617
+ if (visible)
1618
+ placeImage(node, context, cascaded.declared, output);
1619
+ }
1620
+ else if (node.local === "use") {
1621
+ const href = (attribute(node, "href") ?? attribute(node, "xlink:href"))?.replace(/^#/, ""), referenced = href === undefined ? undefined : ids.get(href);
1622
+ if (!referenced || active.has(referenced))
1623
+ diagnose("USE_UNRESOLVED", "use");
1624
+ else {
1625
+ const x = length(attribute(node, "x"), context.fontSize, context.userWidth) ?? 0, y = length(attribute(node, "y"), context.fontSize, context.userHeight) ?? 0;
1626
+ const placed = { ...context, matrix: multiply(context.matrix, [1, 0, 0, 1, x, y]) };
1627
+ active.add(referenced);
1628
+ const useSize = { width: length(attribute(node, "width"), context.fontSize, context.userWidth),
1629
+ height: length(attribute(node, "height"), context.fontSize, context.userHeight) };
1630
+ render(referenced, placed, output, depth + 1, useSize);
1631
+ active.delete(referenced);
1632
+ }
1633
+ }
1634
+ else if (node.local === "switch") {
1635
+ for (const child of node.children) {
1636
+ charge();
1637
+ if (typeof child === "string")
1638
+ continue;
1639
+ if (["systemLanguage", "requiredExtensions", "requiredFeatures"].some(name => child.attributes.has(name))) {
1640
+ diagnose("SWITCH_CONDITION_IGNORED", child.local);
1641
+ continue;
1642
+ }
1643
+ render(child, context, output, depth + 1);
1644
+ break;
1645
+ }
1646
+ }
1647
+ else if (containers.has(node.local)) {
1648
+ for (const child of node.children) {
1649
+ if (typeof child === "string")
1650
+ charge();
1651
+ else
1652
+ render(child, context, output, depth + 1);
1653
+ }
1654
+ }
1655
+ else
1656
+ diagnose("ELEMENT_SKIPPED", node.local);
1657
+ if (cascaded.groupOpacity && output.length > start && !singleImage(output, start))
1658
+ diagnose("OPACITY_FLATTENED", node.local);
1659
+ if (clip && output.length)
1660
+ addElement(target, { kind: "group", clip, elements: output });
1661
+ }
1662
+ render(root, { matrix: [unit * outer.matrix[0], 0, 0, unit * outer.matrix[3], unit * outer.matrix[4], unit * outer.matrix[5]],
1663
+ userWidth: outer.userWidth, userHeight: outer.userHeight, viewportOriginZero: outer.originZero, clipDepth: 0,
1664
+ overflowVisible: true, imageTransformValid: true, style: initial, fontSize: 16, opacity: 1, localOpacity: 1 }, elements, 0);
1665
+ // Image elements can only be added when rendering version 2.
1666
+ return { version, width: drawingWidth, height: drawingHeight, elements, standardFonts: true };
1667
+ }
1668
+ const _exports = Object.freeze({ svgToPdfDrawing: svgToPdfDrawing });
1669
+ _modules.set("11cb7de812b31909ea7f244067c0bbb605bdb3c85ca2e304d9b006893fb22eed", _exports);
1670
+ return _exports;
1671
+ })();
1672
+
1673
+ const _m23 = _modules.get("7f95b63decec4e2ba1f42fe3a3a9681568d33fb28d1017e9dd158b93eba26d36") ?? (() => {
1674
+ const { ExportCell } = _c14;
1675
+
1676
+ const { NumberFormats } = _c15;
1677
+
1678
+ const { ExportBudget } = _c2;
1679
+
1680
+ const display = (header) => header + " (display)";
1681
+ function dateFormat(chart) {
1682
+ let time = false, seconds = false;
1683
+ for (const series of chart.series)
1684
+ for (const point of series.points) {
1685
+ if (!(point.x instanceof Date))
1686
+ continue;
1687
+ const within = point.x.getTime() % 86400000;
1688
+ if (within % 1000)
1689
+ return "yyyy-mm-dd hh:mm:ss.000";
1690
+ if (within)
1691
+ time = true;
1692
+ if (within % 60000)
1693
+ seconds = true;
1694
+ }
1695
+ return seconds ? "yyyy-mm-dd hh:mm:ss" : time ? "yyyy-mm-dd hh:mm" : "yyyy-mm-dd";
1696
+ }
1697
+ function xColumn(chart) {
1698
+ const header = chart.xTitle;
1699
+ if (chart.kind === "date")
1700
+ return { key: "x", header, type: "date", format: chart.xFormat ?? dateFormat(chart) };
1701
+ if (chart.kind === "number")
1702
+ return { key: "x", header, type: "number", ...(chart.xFormat === undefined ? {} : { format: chart.xFormat }) };
1703
+ return { key: "x", header, type: "string" };
1704
+ }
1705
+ const withUnit = (header, unit) => unit ? header + " (" + unit + ")" : header;
1706
+ /** Whether every series can share one row per x value. */
1707
+ function canWiden(chart) {
1708
+ const captions = new Map();
1709
+ for (const series of chart.series) {
1710
+ const seen = new Set();
1711
+ for (const point of series.points) {
1712
+ if (point.key === null)
1713
+ return false;
1714
+ if (seen.has(point.key))
1715
+ return false;
1716
+ seen.add(point.key);
1717
+ if (point.xCaption !== undefined) {
1718
+ const previous = captions.get(point.key);
1719
+ if (previous !== undefined && previous !== point.xCaption)
1720
+ return false;
1721
+ captions.set(point.key, point.xCaption);
1722
+ }
1723
+ }
1724
+ }
1725
+ return true;
1726
+ }
1727
+ /** Map the chart's series to typed columns in a stable order: x, its caption, then each series' value and caption. */
1728
+ function chartTable(chart, layout = "auto", limits) {
1729
+ if (layout !== "auto" && layout !== "wide" && layout !== "long")
1730
+ throw new TypeError("Chart layout must be auto, wide or long.");
1731
+ const wide = layout !== "long" && canWiden(chart);
1732
+ if (layout === "wide" && !wide)
1733
+ throw new TypeError("A wide chart sheet needs unique x values in every series, consistent x captions, and no missing x values.");
1734
+ const budget = new ExportBudget(limits);
1735
+ const headingRows = chart.title ? 2 : 1;
1736
+ function checkRows(count) {
1737
+ budget.row(count);
1738
+ if (count + headingRows > 1048576)
1739
+ throw new RangeError("Excel supports at most 1,048,576 rows including headings.");
1740
+ }
1741
+ function checkCells(rows, columns) {
1742
+ budget.check("maxCells", (rows + headingRows) * columns);
1743
+ }
1744
+ const x = xColumn(chart), hasXCaption = chart.series.some(series => series.points.some(point => point.xCaption !== undefined));
1745
+ const value = (point, format, column) => point?.y === null || point === undefined ? null :
1746
+ format !== undefined && format !== column ? new ExportCell(point.y, { presentation: { numberFormat: format || NumberFormats.General } }) : point.y;
1747
+ if (!wide) {
1748
+ const yFormat = chart.yFormat, hasCaption = chart.series.some(series => series.points.some(point => point.caption !== undefined));
1749
+ const units = new Set(chart.series.filter(series => series.points.length > 0).map(series => (series.unit ?? chart.yUnit) || undefined));
1750
+ const mixedUnits = units.size > 1;
1751
+ const yHeader = withUnit(chart.yTitle, units.size === 0 ? chart.yUnit : mixedUnits ? undefined : units.values().next().value);
1752
+ const columns = [{ key: "series", header: "Series", type: "string" }, { key: "seriesId", header: "Series ID", type: "string" }, x,
1753
+ ...(hasXCaption ? [{ key: "xCaption", header: display(x.header), type: "string" }] : []),
1754
+ { key: "y", header: yHeader, type: "number", ...(yFormat === undefined ? {} : { format: yFormat }) },
1755
+ ...(hasCaption ? [{ key: "caption", header: display(yHeader), type: "string" }] : []),
1756
+ ...(mixedUnits ? [{ key: "unit", header: "Unit", type: "string" }] : [])];
1757
+ const rowCount = chart.series.reduce((count, series) => count + series.points.length, 0);
1758
+ checkRows(rowCount);
1759
+ checkCells(rowCount, columns.length);
1760
+ function* rows() {
1761
+ for (const series of chart.series)
1762
+ for (const point of series.points)
1763
+ yield [series.name, series.id, point.x, ...(hasXCaption ? [point.xCaption ?? null] : []), value(point, series.format ?? yFormat, yFormat),
1764
+ ...(hasCaption ? [point.caption ?? null] : []), ...(mixedUnits ? [series.unit ?? chart.yUnit ?? null] : [])];
1765
+ }
1766
+ return { columns, rows: rows() };
1767
+ }
1768
+ const captionColumns = chart.series.map(series => series.points.some(point => point.caption !== undefined));
1769
+ const columnCount = 1 + Number(hasXCaption) + chart.series.length + captionColumns.filter(Boolean).length;
1770
+ if (columnCount > 16384)
1771
+ throw new RangeError("Excel supports at most 16,384 columns.");
1772
+ const keys = [], captions = new Map(), values = new Map();
1773
+ const known = new Set();
1774
+ for (const series of chart.series)
1775
+ for (const point of series.points) {
1776
+ if (!known.has(point.key)) {
1777
+ checkRows(keys.length + 1);
1778
+ known.add(point.key);
1779
+ keys.push(point.key);
1780
+ values.set(point.key, point.x);
1781
+ }
1782
+ if (point.xCaption !== undefined && !captions.has(point.key))
1783
+ captions.set(point.key, point.xCaption);
1784
+ }
1785
+ checkCells(keys.length, columnCount);
1786
+ if (chart.kind !== "category")
1787
+ keys.sort((a, b) => a - b);
1788
+ const names = new Map();
1789
+ for (const series of chart.series)
1790
+ names.set(series.name, (names.get(series.name) ?? 0) + 1);
1791
+ const columns = [x, ...(hasXCaption ? [{ key: "xCaption", header: display(x.header), type: "string" }] : [])];
1792
+ const lookups = chart.series.map((series, index) => {
1793
+ const format = series.format ?? chart.yFormat, header = withUnit(series.name + (names.get(series.name) > 1 ? " [" + series.id + "]" : ""), series.unit ?? chart.yUnit);
1794
+ const caption = captionColumns[index];
1795
+ columns.push({ key: "s" + index, header, type: "number", ...(format === undefined ? {} : { format }) });
1796
+ if (caption)
1797
+ columns.push({ key: "s" + index + "Caption", header: display(header), type: "string" });
1798
+ return { caption, format, points: new Map(series.points.map(point => [point.key, point])) };
1799
+ });
1800
+ function* rows() {
1801
+ for (const key of keys) {
1802
+ const row = [values.get(key) ?? null, ...(hasXCaption ? [captions.get(key) ?? null] : [])];
1803
+ for (const lookup of lookups) {
1804
+ const point = lookup.points.get(key);
1805
+ row.push(point?.y ?? null);
1806
+ if (lookup.caption)
1807
+ row.push(point?.caption ?? null);
1808
+ }
1809
+ yield row;
1810
+ }
1811
+ }
1812
+ return { columns, rows: rows() };
1813
+ }
1814
+ const _exports = Object.freeze({ chartTable: chartTable });
1815
+ _modules.set("7f95b63decec4e2ba1f42fe3a3a9681568d33fb28d1017e9dd158b93eba26d36", _exports);
1816
+ return _exports;
1817
+ })();
1818
+
1819
+ const _m0 = _modules.get("ca03c551cbbfd3e6df4aae1a9d773797c3c21b0f36ac3f0a0c049177cf1b6e45") ?? (() => {
1820
+ const { BlobByteSink, checkAbort } = _c0;
1821
+
1822
+ const { captureFields } = _c1;
1823
+
1824
+ const { captureCommonLimits, captureXlsxOptions, mergeAdapterLimits } = _m3;
1825
+
1826
+ const { writeXlsxTo } = _c6;
1827
+
1828
+ const { writePdfDocumentTo } = _c7;
1829
+
1830
+ const { capturePdfLimits } = _c4;
1831
+
1832
+ const { prepareChart } = _m10;
1833
+
1834
+ const { svgToPdfDrawing } = _m12;
1835
+
1836
+ const { chartTable } = _m23;
1837
+
1838
+ const { winAnsiText } = _m21;
1839
+
1840
+
1841
+
1842
+ const slots = ["regular", "bold", "italic", "boldItalic"];
1843
+ const headerFill = "E7EDF5", headerBorder = Object.freeze({ bottom: Object.freeze({ style: "thin", color: "A6B4C8" }) });
1844
+ function chartForgeXDrawing(svg, optionsOrVersion = {}, imageOptions = {}) {
1845
+ const options = optionsOrVersion === 2 ? imageOptions : optionsOrVersion;
1846
+ const selected = captureFields(options, ["unsupported", "fonts", "winAnsi", "limits", "onDiagnostic"]);
1847
+ return optionsOrVersion === 2 ? svgToPdfDrawing(svg, selected, 2) : svgToPdfDrawing(svg, selected, 1);
1848
+ }
1849
+ /** Write a ChartForgeX capture as a typed XLSX sheet of its series, or a PDF with its title, description and vector SVG. */
1850
+ async function writeChartForgeXTo(capture, format, destination, options = {}) {
1851
+ const selected = captureFields(options, ["layout", "signal", "limits", "onProgress", "onDiagnostic", "unsupported", "xlsx", "pdf"]);
1852
+ if (format !== "xlsx" && format !== "pdf")
1853
+ throw new TypeError("ChartForgeX exports are xlsx or pdf.");
1854
+ const { signal, onProgress, onDiagnostic, unsupported } = selected, limits = captureCommonLimits(selected.limits);
1855
+ if (unsupported !== undefined && unsupported !== "skip" && unsupported !== "reject")
1856
+ throw new TypeError("unsupported must be skip or reject.");
1857
+ checkAbort(signal);
1858
+ const chart = prepareChart(capture), stream = { ...(signal ? { signal } : {}), ...(onProgress ? { onProgress } : {}) };
1859
+ if (format === "xlsx") {
1860
+ const input = captureFields(selected.xlsx ?? {}, ["dateMode", "compression", "creator", "created", "modified", "sheetName"]);
1861
+ const { sheetName = "Chart data", ...workbook } = input;
1862
+ const xlsx = captureXlsxOptions(workbook), xlsxLimits = mergeAdapterLimits(xlsx.limits, limits);
1863
+ const table = chartTable(chart, selected.layout, xlsxLimits);
1864
+ return writeXlsxTo(table.rows, destination, { dateMode: "utc", ...xlsx, ...stream, columns: table.columns,
1865
+ ...(chart.title === undefined ? {} : { title: chart.title }), ...(chart.description === undefined ? {} : { description: chart.description }),
1866
+ limits: xlsxLimits,
1867
+ sheet: { name: sheetName, headerFill, headerBorder, headerWrap: true, freezeHeader: true, autoFilter: true, boldHeader: true,
1868
+ autoSize: { minWidth: 8, maxWidth: 48 }, ...(chart.title ? { title: { text: chart.title } } : {}) } });
1869
+ }
1870
+ if (chart.svg === undefined)
1871
+ throw new TypeError("A ChartForgeX PDF needs the chart's SVG markup.");
1872
+ const pdf = captureFields(selected.pdf ?? {}, ["pageSize", "orientation", "margins", "fonts", "tagged", "compression", "pageNumbers", "pageHeader",
1873
+ "pageFooter", "fontSize", "limits"]);
1874
+ const pdfLimits = mergeAdapterLimits(pdf.limits === undefined ? undefined : capturePdfLimits(pdf.limits), limits);
1875
+ // Keep Unicode labels in the embedded regular face when an emphasis face is missing.
1876
+ const faces = pdf.fonts === undefined ? undefined : captureFields(pdf.fonts, slots);
1877
+ const available = faces ? slots.filter(slot => slot === "regular" || faces[slot] !== undefined) : slots;
1878
+ const reported = new Set();
1879
+ const report = (diagnostic) => {
1880
+ if (reported.has(diagnostic.code))
1881
+ return;
1882
+ reported.add(diagnostic.code);
1883
+ onDiagnostic?.(diagnostic);
1884
+ };
1885
+ const drawing = svgToPdfDrawing(chart.svg, { fonts: available, winAnsi: !faces?.regular, limits: pdfLimits, ...(unsupported ? { unsupported } : {}),
1886
+ onDiagnostic: report }, 2, signal);
1887
+ const paintedText = (text) => {
1888
+ if (text === undefined)
1889
+ return undefined;
1890
+ if (faces?.regular)
1891
+ return text.normalize("NFC");
1892
+ return winAnsiText(text, () => {
1893
+ if (unsupported === "reject")
1894
+ throw new TypeError("Chart text needs an embedded font: supply pdf.fonts.regular.");
1895
+ report({ code: "TEXT_SUBSTITUTED" });
1896
+ });
1897
+ };
1898
+ const title = paintedText(chart.title), description = paintedText(chart.description);
1899
+ // The figure alternative stays exact: it is Unicode metadata, not painted text.
1900
+ const alternativeText = chart.description?.trim() ? chart.description : chart.title?.trim() ? chart.title : "Chart";
1901
+ const blocks = [...(description ? [{ kind: "paragraph", text: description }] : []),
1902
+ { kind: "drawing", drawing, alignment: "center", alternativeText }];
1903
+ return writePdfDocumentTo(blocks, destination, { orientation: drawing.width > drawing.height ? "landscape" : "portrait", pageNumbers: false,
1904
+ ...pdf, ...stream, ...(faces ? { fonts: faces } : {}), ...(title ? { title } : {}),
1905
+ ...(chart.title ? { metadataTitle: chart.title } : {}), limits: pdfLimits });
1906
+ }
1907
+ /** Export a ChartForgeX capture as a Blob. No chart runtime, browser layout or server is involved. */
1908
+ async function exportChartForgeX(capture, format, options = {}) {
1909
+ const sink = new BlobByteSink();
1910
+ try {
1911
+ await writeChartForgeXTo(capture, format, sink, options);
1912
+ return sink.toBlob(format === "xlsx" ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "application/pdf");
1913
+ }
1914
+ catch (error) {
1915
+ sink.discard();
1916
+ throw error;
1917
+ }
1918
+ }
1919
+ const _exports = Object.freeze({ PdfFont: _c16.PdfFont, chartForgeXDrawing: chartForgeXDrawing, writeChartForgeXTo: writeChartForgeXTo, exportChartForgeX: exportChartForgeX });
1920
+ _modules.set("ca03c551cbbfd3e6df4aae1a9d773797c3c21b0f36ac3f0a0c049177cf1b6e45", _exports);
1921
+ return _exports;
1922
+ })();
1923
+ Object.assign(officeimo, _m0);
1924
+ })(globalThis);