@pixerate/editor 0.47.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/agent/index.cjs +246 -29
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +18 -6
  4. package/dist/agent/index.d.ts +18 -6
  5. package/dist/agent/index.js +226 -9
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/{builtins-xs7rK6ys.d.cts → builtins-1kqwLUnb.d.cts} +1 -1
  8. package/dist/{builtins-D2nMtw2W.d.ts → builtins-BKYlHH1s.d.ts} +1 -1
  9. package/dist/chart/index.cjs +214 -3541
  10. package/dist/chart/index.cjs.map +1 -1
  11. package/dist/chart/index.d.cts +4 -494
  12. package/dist/chart/index.d.ts +4 -494
  13. package/dist/chart/index.js +135 -3462
  14. package/dist/chart/index.js.map +1 -1
  15. package/dist/{chunk-5VXI5GED.js → chunk-2CJ3LPYQ.js} +3 -3
  16. package/dist/{chunk-ZFBBVGCI.js → chunk-EKYHKQPG.js} +243 -243
  17. package/dist/{chunk-ZFBBVGCI.js.map → chunk-EKYHKQPG.js.map} +1 -1
  18. package/dist/chunk-HXUL3LS7.js +113 -0
  19. package/dist/chunk-HXUL3LS7.js.map +1 -0
  20. package/dist/{chunk-REAGGLXS.js → chunk-JQ3BB3E6.js} +2 -2
  21. package/dist/chunk-LTUM52X6.js +4074 -0
  22. package/dist/chunk-LTUM52X6.js.map +1 -0
  23. package/dist/{chunk-J3R2OWOE.cjs → chunk-MUCYWI6W.cjs} +608 -15
  24. package/dist/chunk-MUCYWI6W.cjs.map +1 -0
  25. package/dist/chunk-PIMCHMZE.cjs +521 -0
  26. package/dist/chunk-PIMCHMZE.cjs.map +1 -0
  27. package/dist/{chunk-TK2XZK6Z.js → chunk-PKBWLEL7.js} +594 -1
  28. package/dist/chunk-PKBWLEL7.js.map +1 -0
  29. package/dist/chunk-PRSJJZBS.cjs +4074 -0
  30. package/dist/chunk-PRSJJZBS.cjs.map +1 -0
  31. package/dist/chunk-U6IZKC7B.cjs +113 -0
  32. package/dist/chunk-U6IZKC7B.cjs.map +1 -0
  33. package/dist/{chunk-SQC26VQV.cjs → chunk-UN33YOXW.cjs} +191 -191
  34. package/dist/{chunk-SQC26VQV.cjs.map → chunk-UN33YOXW.cjs.map} +1 -1
  35. package/dist/{chunk-PQFAHT5O.js → chunk-VKPEPWKZ.js} +27 -94
  36. package/dist/chunk-VKPEPWKZ.js.map +1 -0
  37. package/dist/{chunk-H4PICYNL.cjs → chunk-WXEHCVJQ.cjs} +113 -180
  38. package/dist/chunk-WXEHCVJQ.cjs.map +1 -0
  39. package/dist/{chunk-LYGEEDNR.cjs → chunk-XP5IUZUO.cjs} +242 -242
  40. package/dist/chunk-XP5IUZUO.cjs.map +1 -0
  41. package/dist/{chunk-C3NWJE3K.js → chunk-XUUD43OV.js} +11 -672
  42. package/dist/chunk-XUUD43OV.js.map +1 -0
  43. package/dist/{chunk-BBRK6MOI.cjs → chunk-YU4WQE5M.cjs} +100 -100
  44. package/dist/{chunk-BBRK6MOI.cjs.map → chunk-YU4WQE5M.cjs.map} +1 -1
  45. package/dist/commands/index.d.cts +1 -1
  46. package/dist/commands/index.d.ts +1 -1
  47. package/dist/controller-ChjCCMLl.d.cts +822 -0
  48. package/dist/controller-DtbEo3om.d.ts +822 -0
  49. package/dist/extensions/index.cjs +32 -4
  50. package/dist/extensions/index.cjs.map +1 -1
  51. package/dist/extensions/index.d.cts +4 -2
  52. package/dist/extensions/index.d.ts +4 -2
  53. package/dist/extensions/index.js +31 -3
  54. package/dist/{index-QrqMmZ75.d.cts → index-DoHqT1mq.d.cts} +203 -7
  55. package/dist/{index-CSUCQYAH.d.ts → index-YLZ0fKqE.d.ts} +203 -7
  56. package/dist/index.cjs +37 -12
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +9 -7
  59. package/dist/index.d.ts +9 -7
  60. package/dist/index.js +31 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/spreadsheet/index.cjs +4 -4
  63. package/dist/spreadsheet/index.js +3 -3
  64. package/package.json +1 -1
  65. package/dist/chunk-C3NWJE3K.js.map +0 -1
  66. package/dist/chunk-H4PICYNL.cjs.map +0 -1
  67. package/dist/chunk-J3R2OWOE.cjs.map +0 -1
  68. package/dist/chunk-LYGEEDNR.cjs.map +0 -1
  69. package/dist/chunk-NEOO6QJD.cjs +0 -1182
  70. package/dist/chunk-NEOO6QJD.cjs.map +0 -1
  71. package/dist/chunk-PQFAHT5O.js.map +0 -1
  72. package/dist/chunk-TK2XZK6Z.js.map +0 -1
  73. package/dist/types-BVqWm3d1.d.cts +0 -320
  74. package/dist/types-BVqWm3d1.d.ts +0 -320
  75. /package/dist/{chunk-5VXI5GED.js.map → chunk-2CJ3LPYQ.js.map} +0 -0
  76. /package/dist/{chunk-REAGGLXS.js.map → chunk-JQ3BB3E6.js.map} +0 -0
@@ -0,0 +1,521 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkPRSJJZBScjs = require('./chunk-PRSJJZBS.cjs');
10
+
11
+ // src/chart/ooxml.ts
12
+ var CHART_OOXML_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
13
+ var CHART_OOXML_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
14
+ var CHART_OOXML_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
15
+ var MAX_POINTS = 1e5;
16
+ function parser(options) {
17
+ const P = _nullishCoalesce(options.DOMParser, () => ( globalThis.DOMParser));
18
+ if (!P) throw new Error("Reading chart XML needs a DOMParser. In Node, pass one (e.g. from jsdom or @xmldom/xmldom) as { DOMParser }.");
19
+ return P;
20
+ }
21
+ var kids = (el, name) => el ? Array.from(el.childNodes).filter((n) => n.nodeType === 1 && (!name || n.localName === name)) : [];
22
+ var kid = (el, name) => kids(el, name)[0];
23
+ var val = (el, name) => _nullishCoalesce(_optionalChain([kid, 'call', _2 => _2(el, name), 'optionalAccess', _3 => _3.getAttribute, 'call', _4 => _4("val")]), () => ( void 0));
24
+ var path = (el, ...names) => names.reduce((e, n) => kid(e, n), _nullishCoalesce(el, () => ( void 0)));
25
+ var find = (el, name) => {
26
+ if (!el) return void 0;
27
+ for (const c of kids(el)) {
28
+ if (c.localName === name) return c;
29
+ const deep = find(c, name);
30
+ if (deep) return deep;
31
+ }
32
+ return void 0;
33
+ };
34
+ var bool = (v, fallback = false) => v === void 0 ? fallback : v === "1" || v === "true";
35
+ var numberOf = (v) => {
36
+ if (v === void 0) return null;
37
+ const n = Number(v);
38
+ return Number.isFinite(n) ? n : null;
39
+ };
40
+ function strings(e) {
41
+ if (!e) return [];
42
+ const cache = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(find(e, "strCache"), () => ( find(e, "numCache"))), () => ( find(e, "strLit"))), () => ( find(e, "numLit")));
43
+ if (cache) {
44
+ const n = Math.min(MAX_POINTS, Number(_nullishCoalesce(val(cache, "ptCount"), () => ( 0))) || 0);
45
+ const out = Array(n).fill("");
46
+ for (const pt of kids(cache, "pt").slice(0, MAX_POINTS)) {
47
+ const i = Number(_nullishCoalesce(pt.getAttribute("idx"), () => ( 0)));
48
+ if (!Number.isInteger(i) || i < 0 || i >= MAX_POINTS) continue;
49
+ while (out.length <= i) out.push("");
50
+ out[i] = _nullishCoalesce(_optionalChain([kid, 'call', _5 => _5(pt, "v"), 'optionalAccess', _6 => _6.textContent]), () => ( ""));
51
+ }
52
+ return out;
53
+ }
54
+ const multi = find(e, "multiLvlStrCache");
55
+ if (multi) {
56
+ const lvl = kid(multi, "lvl");
57
+ return kids(lvl, "pt").map((p) => _nullishCoalesce(_optionalChain([kid, 'call', _7 => _7(p, "v"), 'optionalAccess', _8 => _8.textContent]), () => ( "")));
58
+ }
59
+ const v = _nullishCoalesce(kid(e, "v"), () => ( find(e, "v")));
60
+ return v ? [_nullishCoalesce(v.textContent, () => ( ""))] : [];
61
+ }
62
+ var numbers = (e) => strings(e).map((s) => s.trim() === "" ? null : numberOf(s.trim()));
63
+ function formatCodeOf(e) {
64
+ return find(e, "numCache") ? _nullishCoalesce(_optionalChain([kid, 'call', _9 => _9(find(e, "numCache"), "formatCode"), 'optionalAccess', _10 => _10.textContent]), () => ( void 0)) : void 0;
65
+ }
66
+ function richText(t) {
67
+ if (!t) return void 0;
68
+ const tx = kid(t, "tx");
69
+ const rich2 = kid(tx, "rich");
70
+ if (rich2) return kids(rich2, "p").map((p) => Array.from(p.getElementsByTagNameNS("*", "t")).map((x) => _nullishCoalesce(x.textContent, () => ( ""))).join("")).join("\n");
71
+ const v = find(tx, "v");
72
+ return _nullishCoalesce(_optionalChain([v, 'optionalAccess', _11 => _11.textContent]), () => ( void 0));
73
+ }
74
+ function solidColor(spPr) {
75
+ const fill = _nullishCoalesce(kid(spPr, "solidFill"), () => ( kid(kid(spPr, "ln"), "solidFill")));
76
+ const srgb = kid(fill, "srgbClr");
77
+ const v = _optionalChain([srgb, 'optionalAccess', _12 => _12.getAttribute, 'call', _13 => _13("val")]);
78
+ return v && /^[0-9a-f]{6}$/i.test(v) ? `#${v.toLowerCase()}` : void 0;
79
+ }
80
+ var MARKERS = { circle: "circle", dot: "circle", square: "square", diamond: "diamond", triangle: "triangle", x: "cross", plus: "cross", star: "cross", dash: "square", none: "none" };
81
+ var TREND_IN = { linear: "linear", exp: "exponential", log: "logarithmic", poly: "polynomial", power: "power", movingAvg: "moving-average" };
82
+ var TREND_OUT = { linear: "linear", exponential: "exp", logarithmic: "log", polynomial: "poly", power: "power", "moving-average": "movingAvg" };
83
+ var LEGEND_IN = { b: "bottom", t: "top", l: "left", r: "right", tr: "right" };
84
+ function chartFromOoxml(xml, options = {}) {
85
+ const issues = [];
86
+ const unsupported = [];
87
+ let doc;
88
+ try {
89
+ doc = new (parser(options))().parseFromString(xml, "application/xml");
90
+ } catch (error) {
91
+ return { spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, {}).spec, issues: [{ path: "", message: `The chart XML could not be read: ${error.message}` }], unsupported, lossless: false };
92
+ }
93
+ const root = doc.documentElement;
94
+ if (!root || root.localName !== "chartSpace" || doc.getElementsByTagName("parsererror").length) {
95
+ return { spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, {}).spec, issues: [{ path: "", message: "This is not a chart part: expected a c:chartSpace (or cx:chartSpace) root element." }], unsupported, lossless: false };
96
+ }
97
+ if (_optionalChain([root, 'access', _14 => _14.namespaceURI, 'optionalAccess', _15 => _15.includes, 'call', _16 => _16("chartex")]) || kid(root, "chartData")) return readChartex(root, issues, unsupported);
98
+ const chart = kid(root, "chart");
99
+ const plot = kid(chart, "plotArea");
100
+ const input = { type: "bar" };
101
+ const titleEl = kid(chart, "title");
102
+ if (titleEl && !bool(val(chart, "autoTitleDeleted"))) input.title = _nullishCoalesce(richText(titleEl), () => ( ""));
103
+ const legend = kid(chart, "legend");
104
+ input.legend = { show: !!legend, position: _nullishCoalesce(LEGEND_IN[_nullishCoalesce(val(legend, "legendPos"), () => ( "r"))], () => ( "right")) };
105
+ if (kid(root, "roundedCorners") && bool(val(root, "roundedCorners"))) unsupported.push("rounded corners");
106
+ const valAxes = kids(plot, "valAx");
107
+ const vertical = (a) => ["l", "r"].includes(_nullishCoalesce(val(a, "axPos"), () => ( "")));
108
+ const secondaryPlaced = (a) => val(a, "crosses") === "max" || ["r", "t"].includes(_nullishCoalesce(val(a, "axPos"), () => ( "")));
109
+ const groupValAxis = (g) => {
110
+ const ids = kids(g, "axId").map((a) => a.getAttribute("val"));
111
+ const axes = ids.map((id) => valAxes.find((a) => val(a, "axId") === id)).filter((a) => !!a);
112
+ return _nullishCoalesce(axes.find(vertical), () => ( axes[0]));
113
+ };
114
+ const groups = kids(plot).filter((g) => g.localName.endsWith("Chart"));
115
+ const used = groups.map(groupValAxis).filter((a) => !!a);
116
+ const primaryAxis = _nullishCoalesce(used.find((a) => !secondaryPlaced(a)), () => ( used[0]));
117
+ const series = [];
118
+ let categories = [];
119
+ const types = [];
120
+ let stacking = "none";
121
+ let orientation = "vertical";
122
+ let dataLabels = false;
123
+ let points = false;
124
+ for (const g of groups) {
125
+ const name = g.localName;
126
+ const grouping = _nullishCoalesce(val(g, "grouping"), () => ( "clustered"));
127
+ let type;
128
+ if (/3D/.test(name)) unsupported.push(`3-D ${name.replace(/3DChart$/, "")} chart (drawn flat)`);
129
+ switch (name) {
130
+ case "barChart":
131
+ case "bar3DChart":
132
+ type = "bar";
133
+ if (val(g, "barDir") === "bar") orientation = "horizontal";
134
+ break;
135
+ case "lineChart":
136
+ case "line3DChart":
137
+ type = "line";
138
+ if (kids(g, "ser").some((s) => (_nullishCoalesce(val(kid(s, "marker"), "symbol"), () => ( (bool(val(g, "marker"), true) ? "auto" : "none")))) !== "none")) points = true;
139
+ break;
140
+ case "areaChart":
141
+ case "area3DChart":
142
+ type = "area";
143
+ break;
144
+ case "pieChart":
145
+ case "pie3DChart":
146
+ case "ofPieChart":
147
+ type = "pie";
148
+ if (name === "ofPieChart") unsupported.push("pie-of-pie (drawn as one pie)");
149
+ break;
150
+ case "doughnutChart":
151
+ type = "donut";
152
+ input.innerRadius = Math.min(0.9, Math.max(0, (_nullishCoalesce(numberOf(val(g, "holeSize")), () => ( 50))) / 100));
153
+ break;
154
+ case "scatterChart":
155
+ type = "scatter";
156
+ if (/line/i.test(_nullishCoalesce(val(g, "scatterStyle"), () => ( "")))) points = true;
157
+ break;
158
+ case "bubbleChart":
159
+ type = "bubble";
160
+ break;
161
+ case "radarChart":
162
+ type = "radar";
163
+ break;
164
+ default:
165
+ unsupported.push(`${name.replace(/Chart$/, "")} chart`);
166
+ continue;
167
+ }
168
+ if (grouping === "stacked") stacking = "stacked";
169
+ else if (grouping === "percentStacked") stacking = "percent";
170
+ const gap = numberOf(val(g, "gapWidth"));
171
+ const overlap = numberOf(val(g, "overlap"));
172
+ if (type === "bar") {
173
+ const n = Math.max(1, kids(g, "ser").length);
174
+ const g100 = (_nullishCoalesce(gap, () => ( 150))) / 100;
175
+ const o = Math.max(-1, Math.min(1, (_nullishCoalesce(overlap, () => ( (grouping === "clustered" ? 0 : 100)))) / 100));
176
+ const barsWidth = grouping === "clustered" ? n - (n - 1) * o : 1;
177
+ input.gapWidth = Math.round(Math.max(0, Math.min(0.9, g100 / (barsWidth + g100))) * 100) / 100;
178
+ if (grouping === "clustered") input.overlap = o;
179
+ }
180
+ if (bool(val(kid(g, "dLbls"), "showVal"))) dataLabels = true;
181
+ types.push(type);
182
+ const axis = groupValAxis(g);
183
+ const secondary = !!axis && !!primaryAxis && axis !== primaryAxis;
184
+ for (const s of kids(g, "ser").slice(0, 1e3)) {
185
+ const out = { id: `series-${series.length + 1}`, name: _nullishCoalesce(strings(kid(s, "tx"))[0], () => ( `Series ${series.length + 1}`)), values: [] };
186
+ const color = solidColor(kid(s, "spPr"));
187
+ if (color) out.color = color;
188
+ out.type = type === "bubble" ? void 0 : type;
189
+ if (secondary) out.axis = "secondary";
190
+ const marker = val(kid(s, "marker"), "symbol");
191
+ if (marker && MARKERS[marker] && MARKERS[marker] !== "circle" && (type === "scatter" || MARKERS[marker] !== "none") && (type === "line" || type === "scatter")) out.marker = MARKERS[marker];
192
+ if (bool(val(s, "smooth"))) out.curve = "smooth";
193
+ const sl = kid(s, "dLbls");
194
+ if (sl && val(sl, "showVal") !== void 0) out.dataLabels = bool(val(sl, "showVal"));
195
+ const labelCode = _optionalChain([[kid(sl, "numFmt"), kid(kid(g, "dLbls"), "numFmt")], 'access', _17 => _17.find, 'call', _18 => _18((n) => n && n.getAttribute("sourceLinked") !== "1"), 'optionalAccess', _19 => _19.getAttribute, 'call', _20 => _20("formatCode")]);
196
+ const valueEl = _nullishCoalesce(kid(s, "val"), () => ( kid(s, "yVal")));
197
+ const code = _nullishCoalesce(labelCode, () => ( formatCodeOf(valueEl)));
198
+ if (code && code !== "General") out.format = { code };
199
+ const catEl = _nullishCoalesce(kid(s, "cat"), () => ( kid(s, "xVal")));
200
+ const cats = strings(catEl);
201
+ if (type === "scatter" || type === "bubble") {
202
+ const xs = cats.map((c) => numberOf(c.trim()));
203
+ if (xs.some((x) => x !== null)) out.x = xs;
204
+ }
205
+ if (!categories.length && cats.length) categories = cats;
206
+ out.values = numbers(valueEl);
207
+ if (type === "bubble") out.sizes = numbers(kid(s, "bubbleSize"));
208
+ const dPts = kids(s, "dPt");
209
+ if (dPts.length) {
210
+ const pc = [];
211
+ for (const dp of dPts) {
212
+ const i = Number(val(dp, "idx"));
213
+ const c = solidColor(kid(dp, "spPr"));
214
+ if (Number.isInteger(i) && i >= 0 && i < MAX_POINTS && c) {
215
+ while (pc.length <= i) pc.push(null);
216
+ pc[i] = c;
217
+ }
218
+ }
219
+ if (pc.some(Boolean)) out.pointColors = pc;
220
+ }
221
+ const trends = [];
222
+ for (const t of kids(s, "trendline")) {
223
+ const kind = TREND_IN[_nullishCoalesce(val(t, "trendlineType"), () => ( ""))];
224
+ if (!kind) continue;
225
+ const line = { type: kind };
226
+ const order = numberOf(val(t, "order"));
227
+ const period = numberOf(val(t, "period"));
228
+ if (kind === "polynomial" && order) line.order = order;
229
+ if (kind === "moving-average" && period) line.period = period;
230
+ for (const k of ["forward", "backward", "intercept"]) {
231
+ const n = numberOf(val(t, k));
232
+ if (n !== null && (k === "intercept" || n > 0)) line[k] = n;
233
+ }
234
+ if (bool(val(t, "dispEq"))) line.showEquation = true;
235
+ if (bool(val(t, "dispRSqr"))) line.showR2 = true;
236
+ const tName = _optionalChain([kid, 'call', _21 => _21(t, "name"), 'optionalAccess', _22 => _22.textContent]);
237
+ if (tName) line.name = tName;
238
+ const tc = solidColor(kid(t, "spPr"));
239
+ if (tc) line.color = tc;
240
+ trends.push(line);
241
+ }
242
+ if (trends.length) out.trendlines = trends;
243
+ if (kids(s, "errBars").length) unsupported.push("error bars");
244
+ series.push(out);
245
+ }
246
+ }
247
+ if (!types.length) {
248
+ issues.push({ path: "plotArea", message: unsupported.length ? `The chart type is not supported: ${unsupported.join(", ")}.` : "The chart has no plot groups." });
249
+ return { spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, input).spec, issues, unsupported, lossless: false };
250
+ }
251
+ const first = types[0];
252
+ const combo = types.some((t) => t !== first);
253
+ input.type = combo ? types.includes("bar") ? "bar" : first : first;
254
+ if (!combo) for (const s of series) delete s.type;
255
+ else for (const s of series) if (s.type === input.type) delete s.type;
256
+ if (!combo) {
257
+ for (const s of series) if (s.axis) issues.push({ path: "series", message: `"${s.name}" is on a second value axis.` });
258
+ }
259
+ if (types.some((t) => !_chunkPRSJJZBScjs.isCartesianChart.call(void 0, t)) && combo) unsupported.push("a pie or radar mixed with other chart types");
260
+ input.series = series;
261
+ input.categories = categories.length ? categories : Array.from({ length: Math.max(0, ...series.map((s) => s.values.length)) }, (_, i) => `${i + 1}`);
262
+ input.stacking = stacking;
263
+ input.orientation = orientation;
264
+ input.dataLabels = dataLabels;
265
+ input.points = points || first !== "line";
266
+ if (bool(val(groups[0], "varyColors")) && (first === "bar" || first === "line") && series.length === 1) unsupported.push("one colour per point (vary colours)");
267
+ const readAxis = (a, fallback) => {
268
+ const axis = { ...fallback, format: {} };
269
+ if (!a) return axis;
270
+ axis.show = !bool(val(a, "delete"));
271
+ axis.title = _nullishCoalesce(richText(kid(a, "title")), () => ( ""));
272
+ axis.gridlines = !!kid(a, "majorGridlines");
273
+ const scaling = kid(a, "scaling");
274
+ axis.min = numberOf(val(scaling, "min"));
275
+ axis.max = numberOf(val(scaling, "max"));
276
+ if (val(scaling, "orientation") === "maxMin") unsupported.push("a reversed axis");
277
+ if (kid(scaling, "logBase")) unsupported.push("a logarithmic axis");
278
+ axis.step = numberOf(val(a, "majorUnit"));
279
+ const fmt = kid(a, "numFmt");
280
+ const code = _optionalChain([fmt, 'optionalAccess', _23 => _23.getAttribute, 'call', _24 => _24("formatCode")]);
281
+ if (code && code !== "General" && _optionalChain([fmt, 'optionalAccess', _25 => _25.getAttribute, 'call', _26 => _26("sourceLinked")]) !== "1") axis.format = { code };
282
+ return axis;
283
+ };
284
+ const xy = first === "scatter" || first === "bubble";
285
+ const catAxis = _nullishCoalesce(_nullishCoalesce(kid(plot, "catAx"), () => ( kid(plot, "dateAx"))), () => ( (xy ? valAxes.find((a) => !vertical(a)) : void 0)));
286
+ input.xAxis = readAxis(catAxis, _chunkPRSJJZBScjs.defaultChartAxis.call(void 0, false));
287
+ if (kid(plot, "dateAx")) input.xAxis.kind = "date";
288
+ input.yAxis = readAxis(_nullishCoalesce(_nullishCoalesce(primaryAxis, () => ( valAxes.find(vertical))), () => ( valAxes[0])), _chunkPRSJJZBScjs.defaultChartAxis.call(void 0, true));
289
+ const secondaryAxis = valAxes.find((a) => a !== primaryAxis && (xy ? vertical(a) && a !== primaryAxis : true) && a !== catAxis);
290
+ if (series.some((s) => s.axis === "secondary") && secondaryAxis) input.yAxis2 = readAxis(secondaryAxis, _chunkPRSJJZBScjs.defaultChartAxis.call(void 0, false));
291
+ const { spec, issues: specIssues } = _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, input);
292
+ issues.push(...specIssues);
293
+ const uniq = [...new Set(unsupported)];
294
+ return { spec, issues, unsupported: uniq, lossless: uniq.length === 0 && specIssues.length === 0 };
295
+ }
296
+ function readChartex(root, issues, unsupported) {
297
+ const data = /* @__PURE__ */ new Map();
298
+ for (const d of kids(kid(root, "chartData"), "data")) {
299
+ const id = _nullishCoalesce(d.getAttribute("id"), () => ( String(data.size)));
300
+ const strDim = kids(d, "strDim")[0];
301
+ const numDim = kids(d, "numDim")[0];
302
+ const lvl = (dim) => kids(dim, "lvl")[0];
303
+ const cats = kids(lvl(strDim), "pt").map((p) => _nullishCoalesce(p.textContent, () => ( "")));
304
+ const values = [];
305
+ const nl = lvl(numDim);
306
+ for (const p of kids(nl, "pt")) {
307
+ const i = Number(_nullishCoalesce(p.getAttribute("idx"), () => ( values.length)));
308
+ while (values.length < i) values.push(null);
309
+ values[i] = numberOf((_nullishCoalesce(p.textContent, () => ( ""))).trim());
310
+ }
311
+ data.set(id, { categories: cats, values, code: _nullishCoalesce(_optionalChain([nl, 'optionalAccess', _27 => _27.getAttribute, 'call', _28 => _28("formatCode")]), () => ( void 0)) });
312
+ }
313
+ const chart = kid(root, "chart");
314
+ const region = path(chart, "plotArea", "plotAreaRegion");
315
+ const seriesEls = kids(region, "series");
316
+ const layouts = { waterfall: "waterfall", funnel: "funnel", treemap: "treemap", sunburst: "treemap", boxWhisker: "box", clusteredColumn: "histogram", paretoLine: "histogram" };
317
+ const layout = _nullishCoalesce(_optionalChain([seriesEls, 'access', _29 => _29[0], 'optionalAccess', _30 => _30.getAttribute, 'call', _31 => _31("layoutId")]), () => ( ""));
318
+ const type = layouts[layout];
319
+ if (!type) {
320
+ issues.push({ path: "plotArea", message: `The chart layout "${layout || "unknown"}" is not supported.` });
321
+ return { spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, {}).spec, issues, unsupported: [layout || "unknown chartex layout"], lossless: false };
322
+ }
323
+ if (layout === "sunburst") unsupported.push("sunburst (drawn as a treemap of the innermost level)");
324
+ if (layout === "paretoLine") unsupported.push("pareto line");
325
+ const series = [];
326
+ let categories = [];
327
+ for (const s of seriesEls) {
328
+ if (s.getAttribute("layoutId") === "paretoLine") continue;
329
+ const ref = _nullishCoalesce(_optionalChain([kid, 'call', _32 => _32(s, "dataId"), 'optionalAccess', _33 => _33.getAttribute, 'call', _34 => _34("val")]), () => ( "0"));
330
+ const d = data.get(ref);
331
+ if (!d) continue;
332
+ if (!categories.length) categories = d.categories;
333
+ const out = { id: `series-${series.length + 1}`, name: _nullishCoalesce(strings(kid(s, "tx"))[0], () => ( `Series ${series.length + 1}`)), values: d.values };
334
+ if (d.code && d.code !== "General") out.format = { code: d.code };
335
+ series.push(out);
336
+ }
337
+ const title = richText(kid(chart, "title"));
338
+ const longest = Math.max(0, ...series.map((s) => s.values.length));
339
+ const input = {
340
+ type,
341
+ title: _nullishCoalesce(title, () => ( "")),
342
+ series,
343
+ categories: categories.length >= longest ? categories : Array.from({ length: longest }, (_, i) => _nullishCoalesce(categories[i], () => ( `${i + 1}`)))
344
+ };
345
+ if (type === "waterfall") input.showTotal = false;
346
+ const { spec, issues: specIssues } = _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, input);
347
+ issues.push(...specIssues);
348
+ return { spec, issues, unsupported, lossless: unsupported.length === 0 && specIssues.length === 0 };
349
+ }
350
+ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
351
+ var hex = (color) => {
352
+ if (!color) return null;
353
+ const rgb = _chunkPRSJJZBScjs.parseChartColor.call(void 0, color);
354
+ return rgb ? _chunkPRSJJZBScjs.chartRgbToHex.call(void 0, rgb).slice(1).toUpperCase() : null;
355
+ };
356
+ var fillXml = (color, line = false) => {
357
+ const h = hex(color);
358
+ if (!h) return "";
359
+ return line ? `<c:spPr><a:ln w="28575" cap="rnd"><a:solidFill><a:srgbClr val="${h}"/></a:solidFill><a:round/></a:ln></c:spPr>` : `<c:spPr><a:solidFill><a:srgbClr val="${h}"/></a:solidFill></c:spPr>`;
360
+ };
361
+ var rich = (text) => `<c:tx><c:rich><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>${esc(text)}</a:t></a:r></a:p></c:rich></c:tx><c:overlay val="0"/>`;
362
+ var strLit = (items) => `<c:strLit><c:ptCount val="${items.length}"/>${items.map((s, i) => `<c:pt idx="${i}"><c:v>${esc(s)}</c:v></c:pt>`).join("")}</c:strLit>`;
363
+ var numLit = (items, code = "General") => `<c:numLit><c:formatCode>${esc(code)}</c:formatCode><c:ptCount val="${items.length}"/>${items.map((v, i) => v === null || !Number.isFinite(v) ? "" : `<c:pt idx="${i}"><c:v>${v}</c:v></c:pt>`).join("")}</c:numLit>`;
364
+ var CURRENCY_SYMBOL = { USD: "$", EUR: "\u20AC", GBP: "\xA3", JPY: "\xA5", CNY: "\xA5", INR: "\u20B9" };
365
+ function chartFormatToCode(format) {
366
+ if (format.code) return format.code;
367
+ const d = format.decimals;
368
+ const frac = (n, fallback) => {
369
+ const k = _nullishCoalesce(n, () => ( fallback));
370
+ return k > 0 ? `.${"0".repeat(k)}` : "";
371
+ };
372
+ const wrap = (body) => `${format.prefix ? `"${format.prefix.replace(/"/g, "")}"` : ""}${body}${format.suffix ? `"${format.suffix.replace(/"/g, "")}"` : ""}`;
373
+ switch (format.style) {
374
+ case "percent":
375
+ return wrap(`#,##0${frac(d, 0)}%`);
376
+ case "currency": {
377
+ const code = (format.currency || "USD").toUpperCase();
378
+ const sym = _nullishCoalesce(CURRENCY_SYMBOL[code], () => ( `${code} `));
379
+ return wrap(`"${sym}"#,##0${frac(d, 0)}`);
380
+ }
381
+ case "compact":
382
+ return wrap('#,##0.0,,"M"');
383
+ default:
384
+ return d !== void 0 || format.prefix || format.suffix ? wrap(`#,##0${frac(d, 0)}`) : "General";
385
+ }
386
+ }
387
+ var MARKER_OUT = { circle: "circle", square: "square", diamond: "diamond", triangle: "triangle", cross: "x", none: "none" };
388
+ function chartToOoxml(spec) {
389
+ const issues = [];
390
+ const family = _chunkPRSJJZBScjs.chartFamily.call(void 0, spec);
391
+ let type = spec.type;
392
+ if (family === "waterfall" || family === "histogram" || family === "box" || family === "funnel") {
393
+ issues.push(`${spec.type} charts are written as bar charts: DrawingML has no ${spec.type} type (Office 2016 stores it as chartex).`);
394
+ type = "bar";
395
+ } else if (family === "treemap") {
396
+ issues.push("Treemaps are written as pie charts: DrawingML has no treemap type.");
397
+ type = "pie";
398
+ }
399
+ const visible = spec.series.filter((s) => !s.hidden);
400
+ if (visible.length < spec.series.length) issues.push(`${spec.series.length - visible.length} hidden series ${spec.series.length - visible.length === 1 ? "is" : "are"} left out.`);
401
+ const grouping = spec.stacking === "stacked" ? "stacked" : spec.stacking === "percent" ? "percentStacked" : "standard";
402
+ const ids = { cat: 500000001, val: 500000002, cat2: 500000003, val2: 500000004 };
403
+ const xy = family === "xy" || type === "scatter" || type === "bubble";
404
+ const pieLike = type === "pie" || type === "donut";
405
+ const typed = (s) => pieLike || type === "radar" ? type : type === "bubble" ? "bubble" : xy ? "scatter" : _chunkPRSJJZBScjs.chartSeriesType.call(void 0, { type }, s);
406
+ const groups = [];
407
+ visible.forEach((s) => {
408
+ const kind = typed(s);
409
+ const secondary = !pieLike && s.axis === "secondary";
410
+ let g = groups.find((x) => x.kind === kind && x.secondary === secondary);
411
+ if (!g) groups.push(g = { kind, secondary, series: [] });
412
+ g.series.push({ s, index: spec.series.indexOf(s) });
413
+ });
414
+ if (pieLike && visible.length > 1) issues.push("Only the first series of a pie is drawn; the others are kept in the part.");
415
+ const catLit = strLit(spec.categories);
416
+ let order = 0;
417
+ const serXml = (kind, s, index) => {
418
+ const parts = [`<c:idx val="${index}"/>`, `<c:order val="${order++}"/>`, `<c:tx><c:v>${esc(s.name)}</c:v></c:tx>`];
419
+ const lineLike = kind === "line" || kind === "scatter" || kind === "radar";
420
+ parts.push(fillXml(s.color, lineLike));
421
+ if (kind === "bar" || kind === "bubble") parts.push('<c:invertIfNegative val="0"/>');
422
+ if (lineLike) {
423
+ const marker = _nullishCoalesce(s.marker, () => ( (spec.points || kind === "scatter" ? "circle" : "none")));
424
+ parts.push(`<c:marker><c:symbol val="${MARKER_OUT[marker]}"/>${marker !== "none" ? '<c:size val="5"/>' : ""}</c:marker>`);
425
+ }
426
+ (_nullishCoalesce(s.pointColors, () => ( []))).forEach((c, i) => {
427
+ const h = hex(_nullishCoalesce(c, () => ( void 0)));
428
+ if (h) parts.push(`<c:dPt><c:idx val="${i}"/>${kind === "bar" ? '<c:invertIfNegative val="0"/>' : ""}<c:bubble3D val="0"/><c:spPr><a:solidFill><a:srgbClr val="${h}"/></a:solidFill></c:spPr></c:dPt>`);
429
+ });
430
+ const labels = _nullishCoalesce(s.dataLabels, () => ( spec.dataLabels));
431
+ const code = s.format ? chartFormatToCode(s.format) : void 0;
432
+ if (s.dataLabels !== void 0 || code)
433
+ parts.push(`<c:dLbls>${code ? `<c:numFmt formatCode="${esc(code)}" sourceLinked="0"/>` : ""}<c:showLegendKey val="0"/><c:showVal val="${labels ? 1 : 0}"/><c:showCatName val="0"/><c:showSerName val="0"/><c:showPercent val="0"/><c:showBubbleSize val="0"/></c:dLbls>`);
434
+ if (!pieLike && kind !== "radar")
435
+ for (const t of _nullishCoalesce(s.trendlines, () => ( []))) {
436
+ let x = `<c:trendline>${t.name ? `<c:name>${esc(t.name)}</c:name>` : ""}${fillXml(t.color, true)}<c:trendlineType val="${TREND_OUT[t.type]}"/>`;
437
+ if (t.type === "polynomial") x += `<c:order val="${_nullishCoalesce(t.order, () => ( 2))}"/>`;
438
+ if (t.type === "moving-average") x += `<c:period val="${_nullishCoalesce(t.period, () => ( 2))}"/>`;
439
+ if (t.forward) x += `<c:forward val="${t.forward}"/>`;
440
+ if (t.backward) x += `<c:backward val="${t.backward}"/>`;
441
+ if (t.intercept !== void 0 && t.intercept !== null) x += `<c:intercept val="${t.intercept}"/>`;
442
+ x += `<c:dispRSqr val="${t.showR2 ? 1 : 0}"/><c:dispEq val="${t.showEquation ? 1 : 0}"/></c:trendline>`;
443
+ parts.push(x);
444
+ }
445
+ const valCode = chartFormatToCode(_nullishCoalesce(s.format, () => ( (s.axis === "secondary" ? spec.yAxis2.format : spec.yAxis.format))));
446
+ if (kind === "scatter" || kind === "bubble") {
447
+ const xs = _nullishCoalesce(s.x, () => ( spec.categories.map((_, i) => i + 1)));
448
+ parts.push(`<c:xVal>${numLit(xs)}</c:xVal><c:yVal>${numLit(s.values, valCode)}</c:yVal>`);
449
+ if (kind === "bubble") parts.push(`<c:bubbleSize>${numLit(_nullishCoalesce(s.sizes, () => ( s.values.map(() => 1))))}</c:bubbleSize><c:bubble3D val="0"/>`);
450
+ else parts.push(`<c:smooth val="${(_nullishCoalesce(s.curve, () => ( spec.curve))) === "smooth" ? 1 : 0}"/>`);
451
+ } else {
452
+ parts.push(`<c:cat>${catLit}</c:cat><c:val>${numLit(s.values, valCode)}</c:val>`);
453
+ if (kind === "line") parts.push(`<c:smooth val="${(_nullishCoalesce(s.curve, () => ( spec.curve))) === "smooth" ? 1 : 0}"/>`);
454
+ }
455
+ if ((_nullishCoalesce(s.curve, () => ( spec.curve))) === "step" && lineLike) issues.push(`"${s.name}" uses step lines, which DrawingML cannot express; they are written straight.`);
456
+ if ((_nullishCoalesce(s.curve, () => ( spec.curve))) === "smooth" && kind === "area") issues.push(`"${s.name}" is a smoothed area, which DrawingML cannot express; it is written straight.`);
457
+ return `<c:ser>${parts.join("")}</c:ser>`;
458
+ };
459
+ const dLbls = `<c:dLbls><c:showLegendKey val="0"/><c:showVal val="${spec.dataLabels ? 1 : 0}"/><c:showCatName val="0"/><c:showSerName val="0"/><c:showPercent val="0"/><c:showBubbleSize val="0"/></c:dLbls>`;
460
+ const groupXml = groups.map((g) => {
461
+ const axes2 = g.secondary ? `<c:axId val="${ids.cat2}"/><c:axId val="${ids.val2}"/>` : `<c:axId val="${ids.cat}"/><c:axId val="${ids.val}"/>`;
462
+ const sers = g.series.map(({ s, index }) => serXml(g.kind, s, index)).join("");
463
+ switch (g.kind) {
464
+ case "bar": {
465
+ const n = g.series.length;
466
+ const barsWidth = spec.stacking === "none" ? n - (n - 1) * spec.overlap : 1;
467
+ const gapPct = Math.round(Math.min(500, spec.gapWidth / Math.max(0.01, 1 - spec.gapWidth) * barsWidth * 100));
468
+ const overlapPct = spec.stacking === "none" ? Math.round(spec.overlap * 100) : 100;
469
+ return `<c:barChart><c:barDir val="${spec.orientation === "horizontal" ? "bar" : "col"}"/><c:grouping val="${spec.stacking === "none" ? "clustered" : grouping}"/><c:varyColors val="0"/>${sers}${dLbls}<c:gapWidth val="${gapPct}"/><c:overlap val="${overlapPct}"/>${axes2}</c:barChart>`;
470
+ }
471
+ case "line":
472
+ return `<c:lineChart><c:grouping val="${spec.stacking === "none" ? "standard" : "standard"}"/><c:varyColors val="0"/>${sers}${dLbls}<c:marker val="1"/>${axes2}</c:lineChart>`;
473
+ case "area":
474
+ return `<c:areaChart><c:grouping val="${grouping}"/><c:varyColors val="0"/>${sers}${dLbls}${axes2}</c:areaChart>`;
475
+ case "scatter":
476
+ return `<c:scatterChart><c:scatterStyle val="lineMarker"/><c:varyColors val="0"/>${sers}${dLbls}${axes2}</c:scatterChart>`;
477
+ case "bubble":
478
+ return `<c:bubbleChart><c:varyColors val="0"/>${sers}${dLbls}<c:bubbleScale val="100"/>${axes2}</c:bubbleChart>`;
479
+ case "radar":
480
+ return `<c:radarChart><c:radarStyle val="marker"/><c:varyColors val="0"/>${sers}${dLbls}${axes2}</c:radarChart>`;
481
+ case "donut":
482
+ return `<c:doughnutChart><c:varyColors val="1"/>${sers}${dLbls}<c:firstSliceAng val="0"/><c:holeSize val="${Math.round(Math.max(10, Math.min(90, spec.innerRadius * 100)))}"/></c:doughnutChart>`;
483
+ default:
484
+ return `<c:pieChart><c:varyColors val="1"/>${sers}${dLbls}<c:firstSliceAng val="0"/></c:pieChart>`;
485
+ }
486
+ });
487
+ const scaling = (a) => `<c:scaling><c:orientation val="minMax"/>${a.max !== null ? `<c:max val="${a.max}"/>` : ""}${a.min !== null ? `<c:min val="${a.min}"/>` : ""}</c:scaling>`;
488
+ const title = (a) => a.title ? `<c:title>${rich(a.title)}</c:title>` : "";
489
+ const fmt = (a) => {
490
+ const code = chartFormatToCode(a.format);
491
+ return code !== "General" ? `<c:numFmt formatCode="${esc(code)}" sourceLinked="0"/>` : `<c:numFmt formatCode="${spec.stacking === "percent" ? "0%" : "General"}" sourceLinked="1"/>`;
492
+ };
493
+ const horizontal = spec.orientation === "horizontal";
494
+ const catPos = horizontal ? "l" : "b";
495
+ const valPos = horizontal ? "b" : "l";
496
+ const valAx = (id, cross, a, pos, crosses, catKind = false) => `<c:valAx><c:axId val="${id}"/>${scaling(a)}<c:delete val="${a.show ? 0 : 1}"/><c:axPos val="${pos}"/>${a.gridlines ? "<c:majorGridlines/>" : ""}${title(a)}${fmt(a)}<c:majorTickMark val="out"/><c:minorTickMark val="none"/><c:tickLblPos val="nextTo"/><c:crossAx val="${cross}"/><c:crosses val="${crosses}"/><c:crossBetween val="${catKind ? "midCat" : "between"}"/>${a.step ? `<c:majorUnit val="${a.step}"/>` : ""}</c:valAx>`;
497
+ const catAx = (id, cross, a, pos, hidden = false) => `<c:${a.kind === "date" ? "dateAx" : "catAx"}><c:axId val="${id}"/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="${a.show && !hidden ? 0 : 1}"/><c:axPos val="${pos}"/>${a.gridlines ? "<c:majorGridlines/>" : ""}${title(a)}<c:numFmt formatCode="General" sourceLinked="1"/><c:majorTickMark val="out"/><c:minorTickMark val="none"/><c:tickLblPos val="nextTo"/><c:crossAx val="${cross}"/><c:crosses val="autoZero"/><c:auto val="1"/>${a.kind === "date" ? '<c:lblOffset val="100"/><c:baseTimeUnit val="days"/>' : '<c:lblAlgn val="ctr"/><c:lblOffset val="100"/><c:noMultiLvlLbl val="0"/>'}</c:${a.kind === "date" ? "dateAx" : "catAx"}>`;
498
+ let axes = "";
499
+ if (!pieLike) {
500
+ if (xy) axes = valAx(ids.cat, ids.val, spec.xAxis, "b", "autoZero", true) + valAx(ids.val, ids.cat, spec.yAxis, "l", "autoZero", true);
501
+ else axes = catAx(ids.cat, ids.val, spec.xAxis, catPos) + valAx(ids.val, ids.cat, spec.yAxis, valPos, "autoZero");
502
+ if (groups.some((g) => g.secondary)) axes += catAx(ids.cat2, ids.val2, spec.xAxis, catPos, true) + valAx(ids.val2, ids.cat2, spec.yAxis2, horizontal ? "t" : "r", "max");
503
+ }
504
+ const legendPos = { bottom: "b", top: "t", left: "l", right: "r" }[spec.legend.position];
505
+ const legend = spec.legend.show ? `<c:legend><c:legendPos val="${legendPos}"/><c:overlay val="0"/></c:legend>` : "";
506
+ const titleXml = spec.title ? `<c:title>${rich(spec.title)}</c:title><c:autoTitleDeleted val="0"/>` : '<c:autoTitleDeleted val="1"/>';
507
+ if (spec.subtitle) issues.push("The subtitle is left out: DrawingML charts have one title.");
508
+ if (family === "radar" && spec.series.some((s) => _optionalChain([s, 'access', _35 => _35.trendlines, 'optionalAccess', _36 => _36.length]))) issues.push("Trendlines on a radar chart are left out.");
509
+ const xml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><c:chartSpace xmlns:c="${CHART_OOXML_NS}" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><c:roundedCorners val="0"/><c:chart>${titleXml}<c:plotArea><c:layout/>${groupXml.join("")}${axes}</c:plotArea>${legend}<c:plotVisOnly val="1"/><c:dispBlanksAs val="gap"/></c:chart><c:txPr><a:bodyPr/><a:lstStyle/><a:p><a:pPr><a:defRPr sz="${Math.round(10 * 100)}"/></a:pPr><a:endParaRPr lang="en-US"/></a:p></c:txPr></c:chartSpace>`;
510
+ return { xml, issues: [...new Set(issues)] };
511
+ }
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+ exports.CHART_OOXML_NS = CHART_OOXML_NS; exports.CHART_OOXML_CONTENT_TYPE = CHART_OOXML_CONTENT_TYPE; exports.CHART_OOXML_RELATIONSHIP = CHART_OOXML_RELATIONSHIP; exports.chartFromOoxml = chartFromOoxml; exports.chartFormatToCode = chartFormatToCode; exports.chartToOoxml = chartToOoxml;
521
+ //# sourceMappingURL=chunk-PIMCHMZE.cjs.map