@martinomagnifico/tablechart 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1407 @@
1
+ //#region src/js/config.ts
2
+ var e = "tablechart", t = "tablechart-plot", n = "tablechart-categories", r = "tablechart-value", i = "tablechart-bar", a = "tablechart-piece", o = "tablechart-rule", s = "tablechart-connector", c = "tablechart-line", l = "tablechart-head", u = "tablechart-badge", d = "tablechart-caption", f = "tablechart-slice", p = "tablechart-divide", m = "tablechart-series", h = "tablechart-area", g = "tablechart-area-fill", _ = "tablechart-name", v = "tablechart-legend", y = "tablechart-point", b = "tablechart-hole", x = "tablechart-centre", S = "tablechart-leader", C = "tablechart-break", w = "is-placed", T = "tablechart-pointer", E = "tablechart-sr", D = "is-shown", O = "tablechart-queued", k = 1e3, A = {
3
+ selector: "[data-chart]",
4
+ aspect: .38,
5
+ barfill: .58,
6
+ ringfill: .42,
7
+ animate: !0,
8
+ labels: "outside",
9
+ legend: !1,
10
+ hover: !0,
11
+ totallabel: "Total",
12
+ threshold: .5,
13
+ replay: !1,
14
+ langattribute: "data-i18n"
15
+ }, j = (e, t) => `${e}:${t}`, M = "http://www.w3.org/2000/svg", N = (e, t = {}) => {
16
+ let n = document.createElementNS(M, e);
17
+ for (let e in t) n.setAttribute(e, String(t[e]));
18
+ return n;
19
+ }, P = (e, t) => [e, ...t.classes].join(" "), F = (e, t) => {
20
+ let n = document.createElement("span");
21
+ return n.className = e, n.inert = !0, t.appendChild(n), n;
22
+ }, I = (e, t, n, r, i) => {
23
+ e.style.left = `${t / r * 100}%`, e.style.top = `${n / i * 100}%`;
24
+ }, L = 0, R = (e, t, n, r) => {
25
+ if (!t.length) return;
26
+ let i = `tablechart-cut-${++L}`, a = N("mask", {
27
+ id: i,
28
+ maskUnits: "userSpaceOnUse"
29
+ });
30
+ a.appendChild(N("rect", {
31
+ x: -n,
32
+ y: -r,
33
+ width: n * 3,
34
+ height: r * 3,
35
+ fill: "white"
36
+ }));
37
+ for (let e of t) e.setAttribute("fill", "black"), a.appendChild(e);
38
+ let o = e.querySelector(":scope > defs");
39
+ o || (o = N("defs"), e.prepend(o)), o.appendChild(a);
40
+ let s = N("g", { mask: `url(#${i})` });
41
+ for (let t of Array.from(e.childNodes)) t !== o && s.appendChild(t);
42
+ e.appendChild(s);
43
+ }, z = 0, B = {
44
+ create: () => null,
45
+ draw(e, t, n) {
46
+ let { segments: r, cx: i, y: a, barWidth: o, svg: s, breakAt: c } = n;
47
+ if (c === null) return;
48
+ let l = a(c), u = o + o * .09 * 2, d = e.getAttribute("data-mark") === "zigzag", f = u * .3, p = (e, t) => {
49
+ let n = e - u / 2;
50
+ if (!d) return [[n, t + f / 2], [n + u, t - f / 2]];
51
+ let r = u / 6, i = [[n, t]];
52
+ for (let e = 0; e < 6; e++) i.push([n + r * (e + 1), t + (e % 2 == 0 ? -3.38 : 3.38)]);
53
+ return i;
54
+ }, m = (e, t = !1) => e.map(([e, t], n) => `${n === 0 ? "M" : "L"} ${e.toFixed(1)} ${t.toFixed(1)}`).join(" ") + (t ? " Z" : ""), h = `tablechart-break-${++z}`, g = N("mask", {
55
+ id: h,
56
+ maskUnits: "userSpaceOnUse"
57
+ });
58
+ g.appendChild(N("rect", {
59
+ x: -k,
60
+ y: -n.height,
61
+ width: k * 3,
62
+ height: n.height * 3,
63
+ fill: "white"
64
+ }));
65
+ let _ = [];
66
+ for (let [e, t] of r.entries()) {
67
+ if (Math.min(t.from, t.to) >= c || Math.max(t.from, t.to) <= c) continue;
68
+ let r = i(e), a = p(r, l - 13), o = p(r, l);
69
+ g.appendChild(N("path", {
70
+ d: m([...a, ...o.slice().reverse()], !0),
71
+ fill: "black"
72
+ })), _.push(a, o);
73
+ let u = j("--after", t.slot);
74
+ for (let e of [a, o]) s.appendChild(N("path", {
75
+ class: C,
76
+ "data-part": "edge",
77
+ "data-note": n.note,
78
+ d: m(e),
79
+ style: u
80
+ }));
81
+ }
82
+ if (!_.length) return;
83
+ let v = Array.from(s.querySelectorAll(`.${C}`)), y = N("g", { mask: `url(#${h})` });
84
+ for (let e of Array.from(s.childNodes)) v.includes(e) || y.appendChild(e);
85
+ let b = N("defs");
86
+ b.appendChild(g), s.prepend(b, y);
87
+ }
88
+ }, V = (e) => (e.split(/[.,]/)[1] || "").length, H = (e, t, n) => new Intl.NumberFormat(n || document.documentElement.lang || void 0, {
89
+ minimumFractionDigits: t,
90
+ maximumFractionDigits: t
91
+ }).format(e), U = (e) => Number.parseFloat((e.match(/-?[\d.,]+/) || ["NaN"])[0].replace(",", ".")), W = (e, t) => {
92
+ let n = document.createElement("span");
93
+ if (n.className = u, n.inert = !0, e.childElementCount > 0) for (let t of Array.from(e.children)) n.appendChild(t.cloneNode(!0));
94
+ else {
95
+ n.textContent = (e.textContent || "").trim();
96
+ let t = e.getAttribute("data-i18n");
97
+ t && n.setAttribute("data-i18n", t);
98
+ }
99
+ return t.appendChild(n), n;
100
+ }, G = (t, n, r, i) => {
101
+ let a = U(t?.textContent || ""), o = Number.isNaN(a) ? !0 : Math.abs(n - a) <= .5, s = {
102
+ label: r,
103
+ computed: n,
104
+ stated: a,
105
+ agrees: o
106
+ };
107
+ i.checks.push(s), o || console.warn(`[${e}] An annotation reads ${a}%, but ${r} is ${n.toFixed(1)}%. The chart shows what you wrote; this is only a check.`);
108
+ }, K = (e, t) => (t - e) / Math.abs(e) * 100, q = (e, t) => {
109
+ let n = (t, n) => {
110
+ let r = Number.parseInt(e.getAttribute(t) ?? "", 10);
111
+ return Number.isFinite(r) ? r - 1 : n;
112
+ };
113
+ return [n("data-from", 0), n("data-to", t - 1)];
114
+ }, ee = {
115
+ create: W,
116
+ draw(t, n, r) {
117
+ let { rows: i, cx: a, y: o, unit: s, labelHeight: u, badgeHeight: d, height: f, svg: p, after: m } = r, [h, g] = q(t, i.length), _ = i[h], v = i[g];
118
+ if (!_ || !v) {
119
+ console.warn(`[${e}] A bracket points at a row that is not there (row ${h + 1} to ${g + 1}, of ${i.length}).`);
120
+ return;
121
+ }
122
+ let y = 7 * s, b = 4 * s, x = a(h), S = a(g), C = Math.min(o(_.value), o(v.value)) - u - b - d * .9, w = (e) => o(e) - u - b, T = `M ${x} ${w(_.value)} L ${x} ${C} L ${S} ${C} L ${S} ${w(v.value) - y}`, E = (w(_.value) - C + Math.abs(S - x) + (w(v.value) - y - C)) / s + 1;
123
+ p.appendChild(N("path", {
124
+ class: c,
125
+ "data-note": r.note,
126
+ d: T,
127
+ style: `--len:${E.toFixed(1)}; ${j("--after", m)}`
128
+ }));
129
+ let D = w(v.value);
130
+ p.appendChild(N("polygon", {
131
+ class: l,
132
+ "data-note": r.note,
133
+ points: `${S},${D} ${S - y * .45},${D - y} ${S + y * .45},${D - y}`,
134
+ style: j("--after", m)
135
+ })), n && (I(n, (x + S) / 2, C, k, f), n.style.setProperty("--after", String(m))), G(n, K(_.value, v.value), `${_.value} to ${v.value}`, r);
136
+ }
137
+ }, te = (e, t, n) => ((t / e) ** (1 / n) - 1) * 100, ne = {
138
+ create: W,
139
+ draw(e, t, n) {
140
+ let { rows: r, cx: i, y: a, unit: o, labelHeight: s, height: u, svg: d, values: f, after: p } = n, m = r[0], h = r[r.length - 1];
141
+ if (!m || !h) return;
142
+ let g = s + 18 * o, _ = 10 * o, v = 10 * o, y = i(0), b = a(m.value) - g, x = i(r.length - 1), S = a(h.value) - g, C = 0;
143
+ r.forEach((e, t) => {
144
+ let n = x === y ? 0 : (i(t) - y) / (x - y), r = b + n * (S - b) - (a(e.value) - g);
145
+ r > C && (C = r);
146
+ }), b -= C, S -= C;
147
+ let w = x - y, T = S - b, E = Math.hypot(w, T) || 1, D = w / E, O = T / E;
148
+ y -= D * _, b -= O * _, x += D * _, S += O * _;
149
+ let A = Number.parseFloat(e.getAttribute("data-at") || "0.5");
150
+ if (t) {
151
+ let e = y + (x - y) * A, n = b + (S - b) * A, c = t.offsetWidth * o / 2, l = n + t.offsetHeight * o / 2 + 8 * o, u = 0;
152
+ r.forEach((t, n) => {
153
+ let r = (f[n]?.offsetWidth || 0) * o / 2;
154
+ if (Math.abs(i(n) - e) >= c + r) return;
155
+ let d = a(t.value) - 7 * o - s;
156
+ u = Math.max(u, l - d);
157
+ }), b -= u, S -= u;
158
+ }
159
+ let M = x - D * v, P = S - O * v, F = Math.hypot(M - y, P - b) / o + 1;
160
+ d.appendChild(N("line", {
161
+ class: c,
162
+ "data-note": n.note,
163
+ x1: y,
164
+ y1: b,
165
+ x2: M,
166
+ y2: P,
167
+ style: `--len:${F.toFixed(1)}; ${j("--after", p)}`
168
+ }));
169
+ let L = -O, R = D, z = v * .42;
170
+ d.appendChild(N("polygon", {
171
+ class: l,
172
+ "data-note": n.note,
173
+ points: [
174
+ `${x},${S}`,
175
+ `${M + L * z},${P + R * z}`,
176
+ `${M - L * z},${P - R * z}`
177
+ ].join(" "),
178
+ style: j("--after", p)
179
+ })), t && (I(t, y + (x - y) * A, b + (S - b) * A, k, u), t.style.setProperty("--after", String(p)));
180
+ let B = Number.parseFloat(e.getAttribute("data-years") || "");
181
+ !Number.isNaN(B) && B > 0 && G(t, te(m.value, h.value, B), `${m.value} to ${h.value} over ${B} years`, n);
182
+ }
183
+ }, re = (e, t, n) => {
184
+ let r = .15, i = Math.min(e * .7 / (t + (t - 1) * r), n), a = t * i + (t - 1) * i * r;
185
+ return {
186
+ size: i,
187
+ gap: i * r,
188
+ offset: (e) => -a / 2 + e * i * 1.15
189
+ };
190
+ }, ie = (e, t, n) => {
191
+ let r = e.series[n], i = e.series.some((e) => e.focus) && !r.focus;
192
+ return {
193
+ "data-series": n + 1,
194
+ ...i && { "data-muted": "" },
195
+ style: `--n:${n}; --m:${+!!i}; --palette:var(--tablechart-color-${n + 1}); ${j("--i", t.slot)}`
196
+ };
197
+ }, J = (e, t) => {
198
+ let n = 0;
199
+ return Array.from({ length: t }, (t, r) => {
200
+ let i = e.cells[r] ?? e.cells[0], a = n;
201
+ return !i.missing && i.value > 0 && (n += i.value), {
202
+ from: a,
203
+ to: n,
204
+ cell: i
205
+ };
206
+ });
207
+ }, ae = (e, t) => J(e, t).at(-1)?.to ?? 0, oe = (e, t, n) => {
208
+ let r = t.series.some((e) => e.focus);
209
+ e.style.setProperty("--n", String(n)), e.style.setProperty("--m", r && !t.series[n].focus ? "1" : "0"), e.style.setProperty("--palette", `var(--tablechart-color-${n + 1})`);
210
+ }, se = (e, t, n, r = {}) => {
211
+ let o = N("g", {
212
+ class: P(i, t),
213
+ "data-kind": "bar",
214
+ "data-row": n + 1,
215
+ ...r,
216
+ "data-stack": "",
217
+ style: j("--i", t.slot)
218
+ });
219
+ return e.svg.appendChild(o), (n, r) => {
220
+ o.appendChild(N("rect", {
221
+ ...r,
222
+ class: P(a, t),
223
+ ...ie(e, t, n)
224
+ }));
225
+ };
226
+ }, ce = 6, le = (e, t, n) => e.some((e) => e.offsetWidth * n > t - ce * n), ue = (e, t, n) => t >= e.offsetHeight * n * 1.6, de = (e, t, n) => t >= e.offsetWidth * n * 1.5, fe = (e, t, n, r, i = .7) => {
227
+ e.style.setProperty(r, "1");
228
+ let a = 1;
229
+ for (let e of t) {
230
+ let { size: t, room: r } = n(e);
231
+ t > r && (a = Math.min(a, r / t));
232
+ }
233
+ let o = a >= i ? a : 0;
234
+ return e.style.setProperty(r, String(o || i)), o;
235
+ }, pe = (e, t) => (e.sort((e, t) => e.y - t.y), e.forEach((n, r) => {
236
+ let i = e[r - 1];
237
+ i && n.y < i.y + t && (n.y = i.y + t);
238
+ }), e), me = {
239
+ segments: (e) => e.map((e) => ({
240
+ ...e,
241
+ from: 0,
242
+ to: e.value,
243
+ kind: "bar"
244
+ })),
245
+ series: !0,
246
+ legend: "box",
247
+ stackable: !0,
248
+ totals: !0,
249
+ aspect: .5,
250
+ minHeight: ({ labelHeight: e, nameHeight: t, rows: n, series: r, stacked: i }) => {
251
+ let a = e * 1.1, o = r > 1 && !i ? a * (r + .15 * (r - 1)) / .7 : a / .58;
252
+ return n * Math.max(o, t * 1.2);
253
+ },
254
+ categories: "beside",
255
+ headroom: () => 0,
256
+ draw(e) {
257
+ let { segments: t, height: n, unit: r, svg: a, values: s, categories: c, config: l, barMax: u } = e, d = e.series.length > 1, f = Math.max(...c.map((e) => e.offsetWidth * r), 0), p = Math.min(f + 10 * r, k * .42), m = k - 4 * r, h = e.stacked ? Math.max(...e.rows.map((t) => ae(t, e.series.length)), 0) || 1 : Math.max(...e.rows.flatMap((t) => t.cells.slice(0, e.series.length).map((e) => Math.abs(e.value))), 0) || 1, g = (e) => e.offsetWidth * r, _ = (e) => e.length ? Math.max(...e.map(g)) + 9 * r : 0, v = e.stacked ? _(e.totals) : d ? _(e.seriesValues.flat()) : 0;
258
+ if (!d) for (let e = 0; e < 3; e++) {
259
+ let e = m - p - v, n = _(t.map((e, t) => ({
260
+ seg: e,
261
+ label: s[t]
262
+ })).filter(({ seg: t, label: n }) => !de(n, Math.abs(t.value) / h * e, r)).map(({ label: e }) => e));
263
+ if (n <= v) break;
264
+ v = n;
265
+ }
266
+ let y = m - p - v, b = (e) => p + Math.abs(e) / h * y, x = n / t.length, S = (e) => (e + .5) * x, C = Math.min(x * l.barfill, u);
267
+ if (e.stacked) {
268
+ e.rows.forEach((t, i) => {
269
+ let a = se(e, t, i, { "data-grow": "right" }), o = S(i) - C / 2, s = J(t, e.series.length);
270
+ s.forEach(({ from: t, to: s, cell: c }, l) => {
271
+ let u = e.seriesValues[l][i];
272
+ if (u.dataset.place = "none", c.missing || s === t) return;
273
+ let d = b(t), f = b(s);
274
+ a(l, {
275
+ x: d,
276
+ y: o,
277
+ width: Math.max(f - d, 1),
278
+ height: C
279
+ }), u.dataset.place = "inside", u.toggleAttribute("data-left-out", !de(u, f - d, r) || u.offsetHeight * r > C), oe(u, e, l), I(u, (d + f) / 2, S(i), k, n);
280
+ });
281
+ let l = e.totals[i];
282
+ l && (l.dataset.place = "after", I(l, b(s.at(-1)?.to ?? 0) + 5 * r, S(i), k, n));
283
+ let u = c[i];
284
+ u && I(u, p - 8 * r, S(i), k, n);
285
+ }), a.appendChild(N("line", {
286
+ class: o,
287
+ x1: p,
288
+ x2: p,
289
+ y1: 0,
290
+ y2: n
291
+ }));
292
+ return;
293
+ }
294
+ if (d) {
295
+ let t = re(x, e.series.length, u);
296
+ e.plot.dataset.grouped = "";
297
+ let s = e.seriesValues.flat().filter((e) => e.dataset.missing === void 0), l = fe(e.plot, s, (e) => ({
298
+ size: e.offsetHeight * r,
299
+ room: t.size + t.gap * .5
300
+ }), "--tablechart-fit");
301
+ e.rows.forEach((o, s) => {
302
+ e.series.forEach((c, u) => {
303
+ let d = o.cells[u] ?? o.cells[0], f = e.seriesValues[u][s];
304
+ if (d.missing) {
305
+ f.dataset.place = "none";
306
+ return;
307
+ }
308
+ let m = b(d.value), h = S(s) + t.offset(u);
309
+ a.appendChild(N("rect", {
310
+ class: P(i, o),
311
+ "data-kind": "bar",
312
+ "data-row": s + 1,
313
+ "data-grow": "right",
314
+ x: p,
315
+ y: h,
316
+ width: Math.max(m - p, 1),
317
+ height: t.size,
318
+ ...ie(e, o, u)
319
+ })), f.dataset.place = "after", f.toggleAttribute("data-left-out", !l), I(f, m + 5 * r, h + t.size / 2, k, n);
320
+ });
321
+ let u = c[s];
322
+ u && I(u, p - 8 * r, S(s), k, n);
323
+ }), a.appendChild(N("line", {
324
+ class: o,
325
+ x1: p,
326
+ x2: p,
327
+ y1: 0,
328
+ y2: n
329
+ }));
330
+ return;
331
+ }
332
+ t.forEach((e, t) => {
333
+ let o = b(e.value), l = S(t);
334
+ a.appendChild(N("rect", {
335
+ class: P(i, e),
336
+ "data-kind": e.kind,
337
+ "data-row": t + 1,
338
+ "data-grow": "right",
339
+ x: p,
340
+ y: l - C / 2,
341
+ width: Math.max(o - p, 1),
342
+ height: C,
343
+ style: j("--i", e.slot)
344
+ }));
345
+ let u = s[t], d = de(u, o - p, r);
346
+ u.dataset.place = d ? "inside" : "after", u.dataset.kind = e.kind, I(u, d ? o - 6 * r - u.offsetWidth * r / 2 : o + 5 * r, l, k, n);
347
+ let f = c[t];
348
+ f && I(f, p - 8 * r, l, k, n);
349
+ }), a.appendChild(N("line", {
350
+ class: o,
351
+ x1: p,
352
+ x2: p,
353
+ y1: 0,
354
+ y2: n
355
+ }));
356
+ }
357
+ }, he = {
358
+ segments: (e) => e.map((e) => ({
359
+ ...e,
360
+ from: 0,
361
+ to: e.value,
362
+ kind: "bar"
363
+ })),
364
+ series: !0,
365
+ legend: "box",
366
+ stackable: !0,
367
+ totals: !0,
368
+ breakable: !0,
369
+ headroom: ({ labelHeight: e, badgeHeight: t, hasAnnotations: n, unit: r }) => e + 4 * r + (n ? t * 1.6 : 0),
370
+ draw(e) {
371
+ let { segments: t, cx: n, y: r, barWidth: a, height: s, unit: c, svg: l, values: u, labels: d } = e, f = r(0);
372
+ if (e.stacked) {
373
+ e.rows.forEach((t, i) => {
374
+ let o = se(e, t, i), l = n(i) - a / 2;
375
+ J(t, e.series.length).forEach(({ from: t, to: u, cell: d }, f) => {
376
+ let p = e.seriesValues[f][i];
377
+ if (p.dataset.place = "none", d.missing || u === t) return;
378
+ let m = r(u), h = r(t);
379
+ o(f, {
380
+ x: l,
381
+ y: m,
382
+ width: a,
383
+ height: Math.max(h - m, 1)
384
+ }), p.dataset.place = "inside", p.toggleAttribute("data-left-out", !ue(p, h - m, c) || p.offsetWidth * c > a - 4 * c), oe(p, e, f), I(p, n(i), (m + h) / 2, k, s);
385
+ });
386
+ let u = e.totals[i], d = J(t, e.series.length).at(-1)?.to ?? 0;
387
+ u && (u.dataset.place = "outside", I(u, n(i), r(d) - 4 * c, k, s));
388
+ }), l.appendChild(N("line", {
389
+ class: o,
390
+ x1: 0,
391
+ x2: k,
392
+ y1: f,
393
+ y2: f
394
+ }));
395
+ return;
396
+ }
397
+ if (e.series.length > 1) {
398
+ let t = re(n(1) - n(0) || n(0) * 2, e.series.length, e.barMax);
399
+ e.plot.dataset.grouped = "";
400
+ let a = e.seriesValues.flat().filter((e) => e.dataset.missing === void 0), u = fe(e.plot, a, (e) => ({
401
+ size: e.offsetWidth * c,
402
+ room: t.size + t.gap * .5
403
+ }), "--tablechart-fit");
404
+ e.rows.forEach((a, o) => {
405
+ e.series.forEach((d, p) => {
406
+ let m = a.cells[p] ?? a.cells[0], h = e.seriesValues[p][o], g = n(o) + t.offset(p);
407
+ if (m.missing) {
408
+ h.dataset.place = "none";
409
+ return;
410
+ }
411
+ let _ = r(m.value);
412
+ l.appendChild(N("rect", {
413
+ class: P(i, a),
414
+ "data-kind": "bar",
415
+ "data-row": o + 1,
416
+ x: g,
417
+ y: _,
418
+ width: t.size,
419
+ height: Math.max(f - _, 1),
420
+ ...ie(e, a, p)
421
+ })), h.dataset.place = "outside", h.toggleAttribute("data-left-out", !u), I(h, g + t.size / 2, _ - 4 * c, k, s);
422
+ });
423
+ }), l.appendChild(N("line", {
424
+ class: o,
425
+ x1: 0,
426
+ x2: k,
427
+ y1: f,
428
+ y2: f
429
+ }));
430
+ return;
431
+ }
432
+ let p = le(u, a, c);
433
+ t.forEach((e, t) => {
434
+ let o = r(e.value);
435
+ if (e.missing) {
436
+ I(u[t], n(t), f - 4 * c, k, s), u[t].dataset.place = "outside";
437
+ return;
438
+ }
439
+ l.appendChild(N("rect", {
440
+ class: P(i, e),
441
+ "data-kind": e.kind,
442
+ "data-row": t + 1,
443
+ x: n(t) - a / 2,
444
+ y: o,
445
+ width: a,
446
+ height: Math.max(f - o, 1),
447
+ style: j("--i", e.slot)
448
+ }));
449
+ let m = f - o, h = d === "inside" && !p && ue(u[t], m, c);
450
+ I(u[t], n(t), h ? o + m / 2 : o - 4 * c, k, s), u[t].dataset.place = h ? "inside" : "outside";
451
+ }), l.appendChild(N("line", {
452
+ class: o,
453
+ x1: 0,
454
+ x2: k,
455
+ y1: f,
456
+ y2: f
457
+ }));
458
+ }
459
+ }, ge = 0, _e = (e) => e.filter((e) => !e.isTotal), ve = {
460
+ aspect: .66,
461
+ centre: !0,
462
+ headroom: () => 0,
463
+ segments: (e) => e.map((e) => ({
464
+ ...e,
465
+ from: 0,
466
+ to: e.value,
467
+ kind: "bar"
468
+ })),
469
+ draw({ rows: e, height: t, unit: n, labelHeight: r, svg: i, values: a, config: o, centre: s }) {
470
+ let c = k / 2, l = t / 2, u = _e(e).reduce((e, t) => e + Math.abs(t.value), 0);
471
+ if (!u) return;
472
+ let d = r * 1.2 + 10 * n, m = Math.max(Math.min(k, t) / 2 - d, 10), h = m * o.ringfill, g = m - h / 2, _ = 2 * Math.PI * g, v = [], y = 0, b = 0;
473
+ if (e.forEach((e, o) => {
474
+ let s = a[o];
475
+ if (e.isTotal) {
476
+ s.dataset.place = "none";
477
+ return;
478
+ }
479
+ let d = Math.abs(e.value) / u * _, p = y / _ * 2 * Math.PI - Math.PI / 2;
480
+ v.push(p), i.appendChild(N("circle", {
481
+ class: P(f, e),
482
+ "data-slice": b + 1,
483
+ "data-row": o + 1,
484
+ cx: c,
485
+ cy: l,
486
+ r: g,
487
+ "stroke-width": h,
488
+ transform: `rotate(-90 ${c} ${l})`,
489
+ "stroke-dasharray": `${d.toFixed(1)} ${(_ - d).toFixed(1)}`,
490
+ "stroke-dashoffset": (-y).toFixed(1),
491
+ style: `--n:${b}; --palette:var(--tablechart-color-${b + 1}); --arc:${d.toFixed(1)}; --circ:${_.toFixed(1)}; ${j("--i", e.slot)}`
492
+ }));
493
+ let x = p + d / _ * Math.PI, C = Math.cos(x), w = Math.sin(x);
494
+ i.appendChild(N("line", {
495
+ class: S,
496
+ x1: c + C * (m + 2 * n),
497
+ y1: l + w * (m + 2 * n),
498
+ x2: c + C * (m + 7 * n),
499
+ y2: l + w * (m + 7 * n),
500
+ "data-row": o + 1,
501
+ style: j("--i", e.slot)
502
+ }));
503
+ let T = m + 9 * n, E = s.offsetWidth * n / 2;
504
+ I(s, c + C * (T + Math.abs(C) * E), l + w * (T + Math.abs(w) * r * .7), k, t), s.dataset.place = "around", y += d, b += 1;
505
+ }), v.length > 1) {
506
+ let e = g - h / 2 - 1, n = g + h / 2 + 1, r = `tablechart-slices-${++ge}`, a = N("mask", {
507
+ id: r,
508
+ maskUnits: "userSpaceOnUse"
509
+ });
510
+ a.appendChild(N("rect", {
511
+ x: 0,
512
+ y: 0,
513
+ width: k,
514
+ height: t,
515
+ fill: "white"
516
+ }));
517
+ for (let t of v) a.appendChild(N("line", {
518
+ class: p,
519
+ x1: c + Math.cos(t) * e,
520
+ y1: l + Math.sin(t) * e,
521
+ x2: c + Math.cos(t) * n,
522
+ y2: l + Math.sin(t) * n
523
+ }));
524
+ let o = N("g", { mask: `url(#${r})` });
525
+ for (let e of Array.from(i.querySelectorAll(`.${f}`))) o.appendChild(e);
526
+ let s = N("defs");
527
+ s.appendChild(a), i.prepend(s, o);
528
+ }
529
+ s && I(s, c, l, k, t);
530
+ }
531
+ }, ye = [
532
+ "circle",
533
+ "square",
534
+ "diamond"
535
+ ], be = (e, t) => {
536
+ let n = e[t]?.marker?.toLowerCase().split(/\s+/) ?? [], r = ye.find((e) => n.includes(e));
537
+ return {
538
+ shape: r ?? ye[Math.floor(t / 2) % ye.length],
539
+ open: n.includes("open") || !n.includes("filled") && !r && t % 2 == 1
540
+ };
541
+ }, xe = (e, t, n, r, i = {}) => {
542
+ if (e === "square") {
543
+ let e = r * .88;
544
+ return N("rect", {
545
+ x: t - e,
546
+ y: n - e,
547
+ width: e * 2,
548
+ height: e * 2,
549
+ ...i
550
+ });
551
+ }
552
+ if (e === "diamond") {
553
+ let e = r * 1.2;
554
+ return N("polygon", {
555
+ points: `${t},${n - e} ${t + e},${n} ${t},${n + e} ${t - e},${n}`,
556
+ ...i
557
+ });
558
+ }
559
+ return N("circle", {
560
+ cx: t,
561
+ cy: n,
562
+ r,
563
+ ...i
564
+ });
565
+ }, Se = (e) => e.map((e) => ({
566
+ ...e,
567
+ from: 0,
568
+ to: e.value,
569
+ kind: "bar"
570
+ })), Ce = (e) => ({
571
+ segments: Se,
572
+ breakable: !0,
573
+ series: !0,
574
+ stackable: !0,
575
+ swatch: e ? "box" : void 0,
576
+ headroom: ({ labelHeight: e, unit: t }) => e * 1.6 + 6 * t,
577
+ footroom: ({ labelHeight: t, unit: n, series: r, focused: i, stacked: a }) => !e && !a && r === 2 && !i ? t + 7 * n : 0,
578
+ draw(t) {
579
+ let { rows: n, series: r, seriesValues: i, names: a, cx: s, y: c, height: l, unit: u, labelHeight: d, svg: f, stacked: p } = t, _ = t.shape === "step", v = c(0), x = r.length > 1, S = r.some((e) => e.focus), C = n.length - 1, w = (e, t) => n[t]?.cells[e] ?? n[t]?.cells[0], T = n.map((e) => p ? J(e, r.length) : null), E = (e, t) => T[t]?.[e].to ?? w(e, t)?.value ?? 0, D = (e, t) => T[t]?.[e].from ?? 0, O = (e, t) => [s(t), c(E(e, t))], A = (e, t) => !w(e, t) || !!w(e, t)?.missing, M = r.map((e, t) => {
580
+ if (!x) return {
581
+ attrs: {},
582
+ ink: ""
583
+ };
584
+ let n = S && !e.focus;
585
+ return {
586
+ attrs: {
587
+ "data-series": t + 1,
588
+ ...n && { "data-muted": "" }
589
+ },
590
+ ink: `--n:${t}; --m:${+!!n}; --palette:var(--tablechart-color-${t + 1}); `
591
+ };
592
+ }), P = (e, t) => j("--i", n[t].slot), F = n.length > 1 ? s(1) - s(0) : s(0) * 2, L = (e) => n.map((t, n) => ({
593
+ i: n,
594
+ next: n < C && !A(e, n + 1)
595
+ })).filter(({ i: t, next: n }) => !A(e, t) && (_ || n));
596
+ if (e && r.forEach((e, t) => {
597
+ let r = N("g", {
598
+ class: h,
599
+ ...M[t].attrs,
600
+ ...p && { "data-stacked": "" },
601
+ style: M[t].ink
602
+ }), i = L(t), a = N("g", {
603
+ class: g,
604
+ style: `--rows:${n.length}; ${i.length ? P(t, _ ? i[0].i : i[0].i + 1) : ""}`
605
+ });
606
+ r.appendChild(a);
607
+ for (let { i: e, next: n } of i) {
608
+ let r = _ ? s(e) - F / 2 : s(e), i = _ ? s(e) + F / 2 : s(e + 1), [o, l] = [c(E(t, e)), c(D(t, e))], [d, f] = _ ? [o, l] : [c(E(t, e + 1)), c(D(t, e + 1))], p = _ ? e + 1 : e + 2, m = _ ? n : e + 1 < C && !A(t, e + 2), h = m ? 1.5 * u : 0, g = (e, t, n, r) => (t - e) / (r - n), v = (e, t, n) => [_ ? e : e + g(t, e, r, i) * h, _ ? n : e + g(e, n, i, s(p)) * h], y = m ? Math.max(...v(d, o, c(E(t, p)))) : d, b = m ? Math.min(...v(f, l, c(D(t, p)))) : f;
609
+ y >= b && (h = 0);
610
+ let x = _ ? [
611
+ [r, l],
612
+ [r, o],
613
+ [i, o],
614
+ [i, y],
615
+ [i + h, y],
616
+ [i + h, b],
617
+ [i, b],
618
+ [i, l]
619
+ ] : [
620
+ [r, l],
621
+ [r, o],
622
+ [i, d],
623
+ [i + h, y],
624
+ [i + h, b],
625
+ [i, f]
626
+ ];
627
+ a.appendChild(N("polygon", {
628
+ points: x.map((e) => e.join(",")).join(" "),
629
+ "data-row": (_ ? e : e + 1) + 1,
630
+ style: P(t, _ ? e : e + 1)
631
+ }));
632
+ }
633
+ f.appendChild(r);
634
+ }), r.forEach((e, t) => {
635
+ let n = 0;
636
+ for (let { i: r, next: i } of L(t)) {
637
+ let a = _ ? [
638
+ [s(r) - F / 2, c(E(t, r))],
639
+ [s(r) + F / 2, c(E(t, r))],
640
+ ...i ? [[s(r) + F / 2, c(E(t, r + 1))]] : []
641
+ ] : [O(t, r), O(t, r + 1)], o = 1;
642
+ for (let e = 1; e < a.length; e++) {
643
+ let [[t, n], [r, i]] = [a[e - 1], a[e]];
644
+ o += Math.hypot(r - t, i - n) / u;
645
+ }
646
+ f.appendChild(N("polyline", {
647
+ class: m,
648
+ ...M[t].attrs,
649
+ points: a.map((e) => e.join(",")).join(" "),
650
+ ...e.line && { "data-line": e.line },
651
+ "data-row": (_ ? r : r + 1) + 1,
652
+ style: `${M[t].ink}--len:${o.toFixed(1)}; --along:${(-n).toFixed(1)}; ${P(t, _ ? r : r + 1)}`
653
+ })), n += o - 1;
654
+ }
655
+ }), !_) {
656
+ let e = r.map((e, t) => x ? be(r, t) : {
657
+ shape: "circle",
658
+ open: !1
659
+ });
660
+ R(f, r.flatMap((t, r) => e[r].open ? n.flatMap((t, n) => {
661
+ if (A(r, n)) return [];
662
+ let [i, a] = O(r, n);
663
+ return [xe(e[r].shape, i, a, 4 * u, {
664
+ class: b,
665
+ "data-row": n + 1,
666
+ ...x && { "data-series": r + 1 },
667
+ style: P(r, n)
668
+ })];
669
+ }) : []), k, l), r.forEach((t, r) => {
670
+ n.forEach((t, n) => {
671
+ if (A(r, n)) return;
672
+ let [i, a] = O(r, n);
673
+ f.appendChild(xe(e[r].shape, i, a, 4 * u, {
674
+ class: y,
675
+ ...M[r].attrs,
676
+ "data-marker": e[r].shape,
677
+ ...e[r].open && { "data-open": "" },
678
+ "data-row": n + 1,
679
+ style: `${M[r].ink}${P(r, n)}`
680
+ }));
681
+ });
682
+ });
683
+ }
684
+ let z = (e, t) => {
685
+ let n = t;
686
+ for (; n < C && !A(e, n + 1) && w(e, n + 1)?.value === w(e, t)?.value;) n++;
687
+ return n;
688
+ }, B = (t, n) => {
689
+ let i = w(t, n);
690
+ if (!i || i.missing || _ && n > 0 && !A(t, n - 1) && w(t, n - 1)?.value === i.value || S && !r[t].focus) return "none";
691
+ if (p) return "middle";
692
+ if (!x || S || r.length > 2) return "above";
693
+ let a = w(1 - t, n);
694
+ return !a || a.missing || i.value > a.value || i.value === a.value && t === 0 || e && O(t, n)[1] + 7 * u + d > v ? "above" : "below";
695
+ }, V = (e, t) => !p && !_ ? x && !S && r.length > 2 : i[e][t].offsetWidth * u > (_ ? z(e, t) - t + 1 : 1) * F - 4 * u ? !0 : p && c(D(e, t)) - c(E(e, t)) < d * 1.2;
696
+ i.forEach((e, t) => {
697
+ e.forEach((e, n) => {
698
+ let r = B(t, n);
699
+ if (e.dataset.place = r === "above" ? "outside" : r, e.toggleAttribute("data-left-out", r !== "none" && V(t, n)), _ && r !== "none" ? e.dataset.rowEnd = String(z(t, n) + 1) : delete e.dataset.rowEnd, r === "none") return;
700
+ let i = e.offsetWidth * u / 2 + 4 * u, a = _ ? (s(n) + s(z(t, n))) / 2 : r === "middle" && n === 0 ? s(n) + i : r === "middle" && n === C ? s(n) - i : s(n), o = c(E(t, n));
701
+ I(e, a, r === "middle" ? (o + c(D(t, n))) / 2 : r === "above" ? o - 7 * u : o + 7 * u, k, l);
702
+ });
703
+ });
704
+ let H = a.map((e, t) => {
705
+ let n = C;
706
+ for (; n > 0 && A(t, n);) n--;
707
+ let [r, i] = O(t, n);
708
+ return {
709
+ name: e,
710
+ x: (_ ? r + F / 2 : r) + 10 * u,
711
+ y: p ? (i + c(D(t, n))) / 2 : i
712
+ };
713
+ }), U = (a[0]?.offsetHeight || 0) * u;
714
+ for (let e of pe(H, U)) I(e.name, e.x, e.y, k, l);
715
+ let W = !e && !p && r.length === 2 && !S ? l - 2 * u : v;
716
+ f.appendChild(N("line", {
717
+ class: o,
718
+ x1: 0,
719
+ x2: s(C) + s(0),
720
+ y1: W,
721
+ y2: W
722
+ }));
723
+ }
724
+ }), we = Ce(!1), Te = Ce(!0), Ee = {
725
+ segments: (e) => {
726
+ let t = 0;
727
+ return e.map((e) => {
728
+ if (e.isTotal) return t = e.value, {
729
+ ...e,
730
+ from: 0,
731
+ to: e.value,
732
+ kind: "total"
733
+ };
734
+ let n = t;
735
+ return t += e.value, {
736
+ ...e,
737
+ from: n,
738
+ to: t,
739
+ kind: e.value >= 0 ? "up" : "down"
740
+ };
741
+ });
742
+ },
743
+ breakable: !0,
744
+ headroom: ({ labelHeight: e, badgeHeight: t, hasAnnotations: n, unit: r }) => e + 6 * r + (n ? t * 1.6 : 0),
745
+ draw({ segments: e, cx: t, y: n, barWidth: r, height: a, unit: c, svg: l, values: u, breakAt: d }) {
746
+ let f = n(0), p = le(u, r, c);
747
+ e.forEach((i, a) => {
748
+ let o = e[a + 1];
749
+ if (!o) return;
750
+ let c = n(i.to), u = t(a) + r / 2, d = t(a + 1) - r / 2;
751
+ l.appendChild(N("line", {
752
+ class: s,
753
+ x1: u,
754
+ x2: d,
755
+ y1: c,
756
+ y2: c,
757
+ "data-row": a + 2,
758
+ style: j("--i", o.slot)
759
+ }));
760
+ }), e.forEach((e, o) => {
761
+ let s = n(Math.max(e.from, e.to)), f = Math.abs(n(e.from) - n(e.to));
762
+ l.appendChild(N("rect", {
763
+ class: P(i, e),
764
+ "data-kind": e.kind,
765
+ "data-row": o + 1,
766
+ "data-grow": e.kind === "down" ? "down" : "up",
767
+ x: t(o) - r / 2,
768
+ y: s,
769
+ width: r,
770
+ height: Math.max(f, 1),
771
+ style: j("--i", e.slot)
772
+ }));
773
+ let m = u[o], h = !(d !== null && Math.min(e.from, e.to) < d && Math.max(e.from, e.to) > d) && !p && ue(m, f, c);
774
+ m.dataset.place = h ? "inside" : "outside", m.dataset.kind = e.kind;
775
+ let g = h ? s + f / 2 : e.kind === "down" ? s + f + m.offsetHeight * c + 3 * c : s - 3 * c;
776
+ I(m, t(o), g, k, a);
777
+ }), l.appendChild(N("line", {
778
+ class: o,
779
+ x1: 0,
780
+ x2: k,
781
+ y1: f,
782
+ y2: f
783
+ }));
784
+ }
785
+ }, Y = {
786
+ enabled: !1,
787
+ log(...t) {
788
+ Y.enabled && console.log(`[${e}]`, ...t);
789
+ }
790
+ }, De = (e) => {
791
+ let t = (e?.textContent || "").trim(), n = t.match(/^(.*?)(-?\d+(?:[.,]\d+)?)(.*)$/);
792
+ return {
793
+ raw: t,
794
+ number: n?.[2] ?? "",
795
+ prefix: n?.[1] ?? "",
796
+ suffix: n?.[3] ?? "",
797
+ missing: !n,
798
+ value: n ? Number.parseFloat(n[2].replace(",", ".")) : 0
799
+ };
800
+ }, Oe = (e, t = "data-i18n") => Array.from(e.querySelectorAll("tbody tr")).map((e, n) => {
801
+ let r = e.querySelector("th"), i = Array.from(e.querySelectorAll("td")).map(De);
802
+ return i.length || i.push(De(null)), {
803
+ ...i[0],
804
+ label: (r?.textContent || "").trim(),
805
+ key: t && r?.getAttribute(t) || null,
806
+ cells: i,
807
+ classes: Array.from(e.classList),
808
+ isTotal: e.getAttribute("data-kind") === "total",
809
+ slot: n
810
+ };
811
+ }), ke = (e) => Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1), Ae = (e) => e === "dashed" || e === "dotted" ? e : null, je = (e, t, n = "data-i18n") => {
812
+ let r = ke(e), i = Math.max(1, ...t.map((e) => e.cells.length));
813
+ return Array.from({ length: i }, (e, t) => {
814
+ let i = r[t];
815
+ return {
816
+ name: (i?.textContent || "").trim(),
817
+ key: n && i?.getAttribute(n) || null,
818
+ focus: i?.getAttribute("data-kind") === "focus",
819
+ marker: i?.getAttribute("data-marker") ?? null,
820
+ line: Ae(i?.getAttribute("data-line"))
821
+ };
822
+ });
823
+ }, Me = (t, n) => {
824
+ if (!n) return;
825
+ let r = /* @__PURE__ */ new Map();
826
+ for (let i of t) {
827
+ let t = i.getAttribute("data-chart-keys") || null;
828
+ if (!t) continue;
829
+ if (r.has(t)) {
830
+ let n = r.get(t) + 1;
831
+ r.set(t, n), console.warn(`[${e}] Two charts on the page have data-chart-keys="${t}". If two charts use the same keys, they get the same translations. This one uses "${t}-${n}".`), t = `${t}-${n}`;
832
+ } else r.set(t, 1);
833
+ i.querySelectorAll("tbody th").forEach((e, r) => {
834
+ e.getAttribute(n) || e.setAttribute(n, `${t}-row${r + 1}`);
835
+ });
836
+ let a = ke(i);
837
+ a.length > 1 && a.forEach((e, r) => {
838
+ e.getAttribute(n) || e.setAttribute(n, `${t}-col${r + 1}`);
839
+ }), Y?.log?.(`Keys for "${t}" written onto ${i.querySelectorAll("tbody th").length} rows`);
840
+ }
841
+ }, Ne = {
842
+ area: Te,
843
+ bar: me,
844
+ column: he,
845
+ donut: ve,
846
+ line: we,
847
+ waterfall: Ee
848
+ }, Pe = {
849
+ "axis-break": B,
850
+ trend: ne,
851
+ bracket: ee
852
+ }, Fe = Object.keys(Pe), Ie = (e) => {
853
+ let t = "";
854
+ for (let n = e.previousSibling; n && (t = (n.textContent ?? "") + t, !t.trim()); n = n.previousSibling);
855
+ return t.trim();
856
+ }, Le = (e) => {
857
+ for (let t of e.querySelectorAll("br")) {
858
+ if (t.previousElementSibling?.classList.contains("tablechart-sr") || /[.!?:;,…]$/.test(Ie(t))) continue;
859
+ let e = document.createElement("span");
860
+ e.className = E, e.textContent = ". ", t.before(e);
861
+ }
862
+ }, Re = (e, t, n) => {
863
+ let r = e.querySelector("table");
864
+ if (!r) return null;
865
+ let i = r.querySelector("tfoot [data-chart-total]");
866
+ if (i) return i.dataset.value = t.dataset.value ?? "0", i;
867
+ let a = (r.tFoot ?? r.createTFoot()).insertRow(), o = document.createElement("th");
868
+ o.scope = "row", o.textContent = n.totallabel;
869
+ let s = e.getAttribute("data-chart-keys");
870
+ s && n.langattribute && o.setAttribute(n.langattribute, `${s}-total`);
871
+ let c = a.insertCell();
872
+ return c.setAttribute("data-chart-total", ""), c.dataset.value = t.dataset.value ?? "0", a.prepend(o), c;
873
+ }, ze = 0, Be = (e) => {
874
+ let t = e.querySelector(":scope > figcaption");
875
+ if (!t) return;
876
+ Le(t);
877
+ let n = (e) => e.hasAttribute("aria-label") || e.hasAttribute("aria-labelledby"), r = (e) => {
878
+ t.id || (t.id = `tablechart-caption-${++ze}`), e.setAttribute("aria-labelledby", t.id);
879
+ };
880
+ e.tagName === "FIGURE" && !n(e) && r(e);
881
+ let i = e.querySelector("table");
882
+ i && !n(i) && !i.querySelector(":scope > caption") && r(i);
883
+ }, Ve = (i, a, o = null) => {
884
+ let s = o ?? (i.getAttribute("data-chart") || "column"), c = Ne[s];
885
+ if (!c) return console.warn(`[${e}] Unknown chart type "${s}". Known types: ${Object.keys(Ne).join(", ")}.`), null;
886
+ let l = Oe(i, a.langattribute);
887
+ if (!l.length) return console.warn(`[${e}] A chart has no rows in its table, so there is nothing to draw.`), null;
888
+ Be(i);
889
+ let u = je(i, l, a.langattribute);
890
+ u.length > 1 && !c.series && (console.warn(`[${e}] A ${s} chart draws one series; only the first of the table's ${u.length} value columns is used.`), u = u.slice(0, 1));
891
+ let d = u.length > 1;
892
+ d && i.style.setProperty("--tablechart-series-count", String(u.length));
893
+ let f = i.hasAttribute("data-chart-stack");
894
+ f && !c.stackable && console.warn(`[${e}] A ${s} chart cannot be stacked.`);
895
+ let p = f && !!c.stackable && d;
896
+ p && l.some((e) => e.cells.slice(0, u.length).some((e) => e.value < 0)) && console.warn(`[${e}] A stacked chart has a value below zero. It takes no room in the stack.`);
897
+ let m = document.createElement("div");
898
+ m.className = t, m.setAttribute("aria-hidden", "true");
899
+ let h = N("svg", {
900
+ role: "presentation",
901
+ focusable: "false"
902
+ });
903
+ m.appendChild(h), i.appendChild(m);
904
+ let g = c.centre ? l.filter((e) => !e.isTotal) : l, y = Math.max(0, ...g.flatMap((e) => e.cells.slice(0, u.length).map((e) => V(e.number)))), b = u.map((e, t) => l.map((e, n) => {
905
+ let i = e.cells[t] ?? e.cells[0], a = F(r, m);
906
+ return a.classList.add(...e.classes), a.dataset.value = String(i.value), i.prefix && (a.dataset.prefix = i.prefix), i.suffix && (a.dataset.suffix = i.suffix), i.missing && (a.dataset.missing = i.raw), d && (a.dataset.series = String(t + 1)), a.dataset.row = String(n + 1), a.style.setProperty("--i", String(e.slot)), a;
907
+ })), S = b[0], C = p && c.totals ? l.map((e, t) => {
908
+ let n = F(r, m);
909
+ n.classList.add(...e.classes), n.dataset.kind = "total", n.dataset.row = String(t + 1), n.dataset.value = String(ae(e, u.length));
910
+ let i = e.cells[0];
911
+ return i.prefix && (n.dataset.prefix = i.prefix), i.suffix && (n.dataset.suffix = i.suffix), n.style.setProperty("--i", String(e.slot)), n;
912
+ }) : [], w = l[l.length - 1], T = u.some((e) => e.focus), E = i.getAttribute("data-chart-legend"), D = d && (E === null ? a.legend || c.legend !== void 0 : E !== "false") ? document.createElement("div") : null;
913
+ D && (D.className = v, D.setAttribute("aria-hidden", "true"), D.inert = !0);
914
+ let O = d ? u.map((e, t) => {
915
+ let n = F(_, D ?? m);
916
+ D && (n.dataset.place = "legend");
917
+ let r = c.legend ?? c.swatch;
918
+ if (r && (n.dataset.swatch = r), n.textContent = e.name, !r && i.dataset.chartShape !== "step") {
919
+ let e = be(u, t);
920
+ n.dataset.marker = e.shape, n.toggleAttribute("data-open", e.open);
921
+ }
922
+ return e.line && !r && (n.dataset.line = e.line), e.key && a.langattribute && n.setAttribute(a.langattribute, e.key), n.dataset.series = String(t + 1), n.style.setProperty("--n", String(t)), n.style.setProperty("--palette", `var(--tablechart-color-${t + 1})`), n.style.setProperty("--m", T && !e.focus ? "1" : "0"), n.style.setProperty("--i", String(w.slot)), n;
923
+ }) : [], k = c.centre ? F(x, m) : null;
924
+ if (k) {
925
+ let e = l.find((e) => e.isTotal), t = e ? e.value : l.reduce((e, t) => e + Math.abs(t.value), 0);
926
+ k.dataset.value = String(t), e && (k.dataset.decimals = String(V(e.number)));
927
+ }
928
+ let A = k && !l.some((e) => e.isTotal) ? Re(i, k, a) : null, j = c.categories === "beside", M = document.createElement("div");
929
+ M.className = n, M.setAttribute("aria-hidden", "true"), M.inert = !0, j ? M.dataset.place = "beside" : c.centre && (M.dataset.place = "key"), M.style.setProperty("--tablechart-columns", String(l.length));
930
+ let P = 0;
931
+ for (let e of l) {
932
+ let t = document.createElement("span");
933
+ t.classList.add(...e.classes), t.textContent = e.label, e.key && a.langattribute && t.setAttribute(a.langattribute, e.key), c.centre && (t.dataset.kind = e.isTotal ? "total" : "slice", e.isTotal || (t.dataset.slice = String(P + 1), t.style.setProperty("--n", String(P)), t.style.setProperty("--palette", `var(--tablechart-color-${P + 1})`), P += 1)), t.style.setProperty("--i", String(e.slot)), t.dataset.row = String(l.indexOf(e) + 1), M.appendChild(t);
934
+ }
935
+ (j ? m : i).appendChild(M), D && i.appendChild(D);
936
+ let I = Array.from(i.querySelectorAll("[data-annotation]")).map((t) => {
937
+ let n = t.getAttribute("data-annotation"), r = Pe[n];
938
+ if (!r) return console.warn(`[${e}] Unknown annotation "${n}". Known annotations: ${Object.keys(Pe).join(", ")}.`), null;
939
+ let i = Number.parseInt(t.getAttribute("data-series") ?? "1", 10), a = i >= 1 && i <= u.length ? i - 1 : 0;
940
+ return i !== a + 1 && console.warn(`[${e}] An annotation reads line ${i}, which the chart does not have; it reads the first.`), {
941
+ spec: t,
942
+ type: r,
943
+ badge: r.create(t, m),
944
+ series: a,
945
+ after: l.length
946
+ };
947
+ }).filter((e) => e !== null);
948
+ a.animate && i.setAttribute("data-animate", "");
949
+ let L = {
950
+ figure: i,
951
+ plot: m,
952
+ svg: h,
953
+ rows: l,
954
+ decimals: y,
955
+ type: c,
956
+ values: S,
957
+ series: u,
958
+ seriesValues: b,
959
+ names: D ? [] : O,
960
+ categories: Array.from(M.children),
961
+ centre: k,
962
+ stacked: p,
963
+ totals: C,
964
+ totalCell: A,
965
+ rowAt: null,
966
+ rowBox: null,
967
+ annotations: I,
968
+ checks: []
969
+ };
970
+ return a.hover && i.getAttribute("data-chart-hover") !== "false" && qe(L), Ge(L, a), L;
971
+ }, He = (e, t, n, r) => {
972
+ let i = getComputedStyle(e), a = (i.getPropertyValue(n).trim() || r).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);
973
+ if (!a) return null;
974
+ let o = Number(a[1]);
975
+ return a[2] === "%" ? o / 100 * k : o * (a[2] === "em" ? Number.parseFloat(i.fontSize) : a[2] === "rem" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 1) * t;
976
+ }, Ue = (e, t) => He(e, t, "--tablechart-bar-max", "60px") ?? Infinity, We = (t, n) => {
977
+ let { plot: r, svg: i, rows: a, type: o, values: s, series: c, seriesValues: l, names: u, annotations: d } = t, f = r.clientWidth;
978
+ if (!f) return !1;
979
+ let p = k / f, m = Number.parseFloat(t.figure.dataset.chartAspect ?? ""), h = k * (m > 0 ? m : o.aspect ?? n.aspect);
980
+ r.classList.add(w);
981
+ let g = (s[0]?.offsetHeight || 0) * p, _ = d[0]?.badge ? d[0].badge.offsetHeight * p : 0, v = Math.max(h, He(t.figure, p, "--tablechart-min-height", "200px") ?? 0, o.minHeight?.({
982
+ labelHeight: g,
983
+ nameHeight: Math.max(0, ...t.categories.map((e) => e.offsetHeight)) * p,
984
+ unit: p,
985
+ rows: a.length,
986
+ series: c.length,
987
+ stacked: t.stacked
988
+ }) ?? 0), y = t.stacked ? a.map((e) => {
989
+ let t = ae(e, c.length);
990
+ return {
991
+ ...e,
992
+ value: t,
993
+ cells: e.cells.map((e, n) => n === 0 ? {
994
+ ...e,
995
+ value: t
996
+ } : e)
997
+ };
998
+ }) : a, x = (o.segments ?? ((e) => e.map((e) => ({
999
+ ...e,
1000
+ from: 0,
1001
+ to: e.value,
1002
+ kind: "bar"
1003
+ }))))(t.stacked ? y.map((e) => ({
1004
+ ...e,
1005
+ cells: [e.cells[0]]
1006
+ })) : a), S = {
1007
+ labelHeight: g,
1008
+ badgeHeight: _,
1009
+ hasAnnotations: d.length > 0,
1010
+ unit: p,
1011
+ series: c.length,
1012
+ focused: c.some((e) => e.focus),
1013
+ stacked: t.stacked
1014
+ }, C = o.headroom?.(S) ?? g, T = 2 * p + (o.footroom?.(S) ?? 0), E = C, D = t.stacked ? Math.max(...y.map((e) => e.value), 0) : Math.max(...x.flatMap((e) => [
1015
+ e.from,
1016
+ e.to,
1017
+ e.value
1018
+ ]), ...a.flatMap((e) => e.cells.slice(0, c.length).map((e) => e.value))), O = v - E - T, A = D * 1.02, j = d.find((e) => e.spec.getAttribute("data-annotation") === "axis-break")?.spec, M = (e) => {
1019
+ let t = Number.parseFloat(j?.getAttribute(e) ?? "");
1020
+ return Number.isFinite(t) ? t : null;
1021
+ }, P = M("data-from") ?? M("data-at"), F = M("data-to"), I = null;
1022
+ if (j && (P !== null || F !== null)) {
1023
+ let t = P ?? 0, n = F ?? A, r = F === null ? t : P === null ? n : (t + n) / 2, i = j.getAttribute("data-size"), a = i?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);
1024
+ i !== null && !a && console.warn(`[${e}] data-size="${i}" is not a percentage, such as 30%. Using the default.`);
1025
+ let s = Math.min(Math.max(a ? Number(a[1]) / 100 : F === null ? .22 : .3, .05), .8), c = x.filter((e) => (e.kind === "up" || e.kind === "down") && Math.max(e.from, e.to) > t && Math.min(e.from, e.to) < n);
1026
+ o.breakable ? t < 0 || n <= t || n > A || t === 0 && n === A ? console.warn(`[${e}] A break from ${t} to ${n} does not fit a scale that runs from 0 to ${D}.`) : c.length ? console.warn(`[${e}] A break from ${t} to ${n} would cut a step that floats. Keep it below or above the steps.`) : I = {
1027
+ lo: t,
1028
+ hi: n,
1029
+ gap: r,
1030
+ share: s
1031
+ } : console.warn(`[${e}] This kind of chart cannot break its scale.`);
1032
+ }
1033
+ let L = I ? I.gap : null, z = v - T, B = (e) => z - e / A * O;
1034
+ if (I) {
1035
+ let { lo: e, hi: t, gap: n, share: r } = I, i = O * r, a = (O - i - 13) / (e + (A - t)), o = i / (t - e);
1036
+ B = (r) => r <= e ? z - r * a : r <= n ? z - e * a - (r - e) * o : r <= t ? z - e * a - (r - e) * o - 13 : z - e * a - i - 13 - (r - t) * a;
1037
+ }
1038
+ let V = u.length ? Math.max(...u.map((e) => e.offsetWidth)) * p + 12 * p : 0, H = t.categories[0]?.parentElement;
1039
+ H && (H.style.paddingRight = V ? `${V / k * 100}%` : "");
1040
+ let U = (k - V) / a.length, W = (e) => (e + .5) * U, G = (e) => e >= 0 && e < a.length ? e : null;
1041
+ t.rowAt = o.centre ? null : o.categories === "beside" ? (e, t) => G(Math.floor(t * p / (v / a.length))) : (e) => G(Math.floor(e * p / U));
1042
+ let K = U / k * 100, q = 100 / a.length;
1043
+ t.rowBox = o.categories === "beside" ? (e) => [
1044
+ 0,
1045
+ e * q,
1046
+ 100,
1047
+ q
1048
+ ] : (e) => [
1049
+ e * K,
1050
+ 0,
1051
+ K,
1052
+ 100
1053
+ ], i.setAttribute("viewBox", `0 0 ${k} ${v}`), i.textContent = "", t.checks = [];
1054
+ let ee = {
1055
+ rows: a,
1056
+ segments: x,
1057
+ cx: W,
1058
+ y: B,
1059
+ barWidth: Math.min(U * n.barfill, Ue(t.figure, p)),
1060
+ barMax: Ue(t.figure, p),
1061
+ height: v,
1062
+ unit: p,
1063
+ labelHeight: g,
1064
+ badgeHeight: _,
1065
+ after: a.length,
1066
+ note: 0,
1067
+ labels: t.figure.dataset.chartLabels === "inside" || t.figure.dataset.chartLabels !== "outside" && n.labels === "inside" ? "inside" : "outside",
1068
+ breakAt: L,
1069
+ stacked: t.stacked,
1070
+ shape: t.figure.dataset.chartShape === "step" ? "step" : "straight",
1071
+ totals: t.totals,
1072
+ svg: i,
1073
+ plot: r,
1074
+ values: s,
1075
+ series: c,
1076
+ seriesValues: l,
1077
+ names: u,
1078
+ categories: t.categories,
1079
+ centre: t.centre,
1080
+ config: n,
1081
+ checks: t.checks
1082
+ };
1083
+ o.draw(ee);
1084
+ let te = t.categories[0]?.parentElement;
1085
+ te && o.categories !== "beside" && fe(te, t.categories.filter((e) => e.offsetParent !== null), (e) => ({
1086
+ size: e.scrollWidth,
1087
+ room: e.clientWidth
1088
+ }), "--tablechart-name-fit");
1089
+ for (let [e, n] of d.entries()) {
1090
+ n.badge?.setAttribute("data-note", String(e + 1));
1091
+ let r = n.series, i = (e) => ({
1092
+ ...e,
1093
+ ...e.cells[r] ?? e.cells[0]
1094
+ });
1095
+ n.type.draw(n.spec, n.badge, {
1096
+ ...ee,
1097
+ ...t.stacked && {
1098
+ rows: y,
1099
+ ...t.totals.length && { values: t.totals }
1100
+ },
1101
+ ...r > 0 && !t.stacked && {
1102
+ rows: a.map(i),
1103
+ segments: x.map((e) => {
1104
+ let t = i(e);
1105
+ return e.kind === "bar" ? {
1106
+ ...t,
1107
+ to: t.value
1108
+ } : t;
1109
+ }),
1110
+ values: l[r]
1111
+ },
1112
+ after: n.after,
1113
+ note: e + 1
1114
+ });
1115
+ }
1116
+ return R(i, d.flatMap(({ badge: e }) => {
1117
+ if (!(e instanceof HTMLElement) || !e.offsetWidth) return [];
1118
+ let t = e.offsetWidth * p, n = e.offsetHeight * p, r = Number.parseFloat(e.style.left) / 100 * k, i = Number.parseFloat(e.style.top) / 100 * v, a = getComputedStyle(e).borderTopLeftRadius, o = a.endsWith("%") ? Number.parseFloat(a) / 100 : null, s = (Number.parseFloat(a) || 0) * p;
1119
+ return [N("rect", {
1120
+ class: b,
1121
+ "data-for": "badge",
1122
+ "data-note": e.dataset.note ?? "",
1123
+ x: r - t / 2,
1124
+ y: i - n / 2,
1125
+ width: t,
1126
+ height: n,
1127
+ rx: o === null ? s : t * o,
1128
+ ry: o === null ? s : n * o,
1129
+ style: ["--after"].map((t) => e.style.getPropertyValue(t) && `${t}:${e.style.getPropertyValue(t)}`).filter(Boolean).join("; ")
1130
+ })];
1131
+ }), k, v), !0;
1132
+ }, Ge = (e, t) => {
1133
+ let n = [
1134
+ ...e.seriesValues.flat(),
1135
+ ...e.totals,
1136
+ ...e.totalCell ? [e.totalCell] : []
1137
+ ];
1138
+ for (let r of e.centre ? [...n, e.centre] : n) {
1139
+ let { missing: n, prefix: i = "", suffix: a = "" } = r.dataset;
1140
+ if (n !== void 0) {
1141
+ r.textContent = n;
1142
+ continue;
1143
+ }
1144
+ r.textContent = i + H(Number.parseFloat(r.dataset.value || "0"), r.dataset.decimals ? Number(r.dataset.decimals) : e.decimals, t.locale) + a;
1145
+ }
1146
+ }, Ke = (e) => {
1147
+ e.plot.remove(), e.categories[0]?.parentElement?.remove(), e.figure.querySelector(`:scope > .${v}`)?.remove();
1148
+ }, X = (e, t) => {
1149
+ e.figure.classList.toggle(D, t), t || e.plot.removeAttribute("data-pointed");
1150
+ }, qe = (e) => {
1151
+ let { plot: t } = e, n = () => [...e.seriesValues.flat(), ...e.totals], r = (e, t) => {
1152
+ let n = Number(e.dataset.row), r = Number(e.dataset.rowEnd ?? n);
1153
+ return t >= n && t <= r;
1154
+ };
1155
+ t.setAttribute("data-hover", "");
1156
+ let i = document.createElement("div");
1157
+ i.className = T, t.prepend(i);
1158
+ let a = () => {
1159
+ t.removeAttribute("data-active");
1160
+ for (let e of n()) e.removeAttribute("data-active");
1161
+ }, o = (o) => {
1162
+ if (!t.classList.contains("is-placed") || !e.rowAt) return;
1163
+ let s = t.getBoundingClientRect(), c = s.width / t.offsetWidth || 1, l = e.rowAt((o.clientX - s.left) / c, (o.clientY - s.top) / c), u = l === null ? null : l + 1, d = (e) => e.dataset.place !== "none", f = u === null ? [] : n().filter((e) => r(e, u) && d(e));
1164
+ if (!n().some((e) => e.hasAttribute("data-left-out") && d(e)) || !f.length) return a();
1165
+ t.setAttribute("data-pointed", ""), t.setAttribute("data-active", String(u));
1166
+ let [p, m, h, g] = e.rowBox?.(u - 1) ?? [
1167
+ 0,
1168
+ 0,
1169
+ 0,
1170
+ 0
1171
+ ];
1172
+ Object.assign(i.style, {
1173
+ left: `${p}%`,
1174
+ top: `${m}%`,
1175
+ width: `${h}%`,
1176
+ height: `${g}%`
1177
+ });
1178
+ for (let e of n()) e.toggleAttribute("data-active", f.includes(e));
1179
+ };
1180
+ t.addEventListener("pointermove", o), t.addEventListener("pointerdown", o), t.addEventListener("pointerleave", (e) => {
1181
+ e.pointerType === "mouse" && a();
1182
+ }), document.addEventListener("pointerdown", (e) => {
1183
+ t.contains(e.target) || a();
1184
+ });
1185
+ }, Je = (e) => e === "id" || e === "style" || e.startsWith("data-chart"), Ye = /^\s*(?:Table)?:\s+/, Xe = (e) => e?.tagName === "P" && Ye.test(e.textContent ?? ""), Ze = (e) => {
1186
+ let t = document.createElement("figcaption");
1187
+ for (let { name: n, value: r } of Array.from(e.attributes)) t.setAttribute(n, r);
1188
+ let n = e.firstChild;
1189
+ n?.nodeType === Node.TEXT_NODE && (n.textContent = (n.textContent ?? "").replace(Ye, ""), n.textContent || n.remove());
1190
+ let r = Array.from(e.childNodes), i = r.findIndex((e) => e.nodeName === "BR");
1191
+ if (t.append(...i === -1 ? r : r.slice(0, i + 1)), i !== -1 && i < r.length - 1) {
1192
+ let e = document.createElement("span");
1193
+ e.append(...r.slice(i + 1)), t.append(e);
1194
+ }
1195
+ return e.remove(), t;
1196
+ }, Qe = /^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/, $e = (e) => {
1197
+ let t = Z(e);
1198
+ return t?.tagName === "P" ? t : e;
1199
+ }, et = (e) => {
1200
+ let t = $e(e).firstChild;
1201
+ if (t?.nodeType !== Node.TEXT_NODE) return null;
1202
+ let n = Qe.exec(t.textContent ?? "");
1203
+ if (!n || !Fe.includes(n[1]) || !n[3] && t.nextSibling) return null;
1204
+ let r = n[2].trim().split(/\s+/).filter(Boolean).map((e) => e.split("="));
1205
+ return {
1206
+ name: n[1],
1207
+ options: r,
1208
+ text: t,
1209
+ length: n[0].length
1210
+ };
1211
+ }, tt = (e) => {
1212
+ if (e?.tagName !== "UL" && e?.tagName !== "OL") return null;
1213
+ let t = Array.from(e.children), n = t.map((e) => e.hasAttribute("data-annotation") ? null : et(e));
1214
+ return !t.length || t.some((e, t) => !n[t] && !e.hasAttribute("data-annotation")) ? null : (t.forEach((e, t) => {
1215
+ let r = n[t], i = $e(e);
1216
+ if (i !== e && i.replaceWith(...i.childNodes), r) {
1217
+ e.setAttribute("data-annotation", r.name);
1218
+ for (let [t, n] of r.options) e.setAttribute(`data-${t}`, n);
1219
+ r.text.textContent = (r.text.textContent ?? "").slice(r.length);
1220
+ }
1221
+ e.children.length && Array.from(e.childNodes).filter((e) => e.nodeType === Node.ELEMENT_NODE || e.textContent?.trim()).forEach((e, t) => {
1222
+ let n = document.createElement("span");
1223
+ t === 0 && e instanceof HTMLElement && e.matches("em, i") ? (n.className = d, n.append(...e.childNodes), e.replaceWith(n)) : e.nodeType === Node.TEXT_NODE && (n.textContent = (e.textContent ?? "").trim(), e.replaceWith(n));
1224
+ });
1225
+ }), e.classList.add("chart-annotations"), e);
1226
+ }, nt = (e, t) => {
1227
+ for (let { name: n, value: r } of Array.from(e.attributes)) (n === "class" || Je(n)) && (t.setAttribute(n, r), e.removeAttribute(n));
1228
+ }, rt = (e) => e.map((e) => {
1229
+ let t = e.closest("p"), n = Xe(t) ? t : e;
1230
+ if (n.tagName !== "TABLE" && n.tagName !== "P") return n;
1231
+ let r = document.createElement("div");
1232
+ nt(e, r), e.classList.length || e.removeAttribute("class");
1233
+ let i = n.tagName === "TABLE" ? n : null, a = n.previousElementSibling, o = n.nextElementSibling, s = i ? Xe(a) ? a : Xe(o) ? o : null : n;
1234
+ i && s === o && (o = o?.nextElementSibling ?? null);
1235
+ let c = o?.classList.contains("chart-annotations") ? o : tt(o);
1236
+ return n.replaceWith(r), s && r.append(Ze(s)), i && r.append(i), c && r.append(c), Y?.log?.(`A ${i ? "table" : "caption"} with chart attributes was wrapped in a figure of its own`), r;
1237
+ }), it = (e, t = []) => {
1238
+ let n = document.createElement("table");
1239
+ if (t.length) {
1240
+ let e = n.createTHead().insertRow();
1241
+ e.append(document.createElement("th"));
1242
+ for (let n of t) {
1243
+ let t = document.createElement("th");
1244
+ t.textContent = n, e.append(t);
1245
+ }
1246
+ }
1247
+ let r = n.createTBody();
1248
+ for (let t of e) {
1249
+ let e = r.insertRow();
1250
+ t.kind === "total" && (e.dataset.kind = "total");
1251
+ let n = document.createElement("th");
1252
+ n.textContent = String(t.label ?? ""), e.append(n);
1253
+ for (let n of t.values ?? [t.value ?? null]) e.insertCell().textContent = n === null ? "" : String(n);
1254
+ }
1255
+ return n;
1256
+ }, at = async (t) => {
1257
+ await Promise.all(t.filter((e) => e.hasAttribute("data-chart-src")).map(async (t) => {
1258
+ let n = t.getAttribute("data-chart-src");
1259
+ for (let e of t.querySelectorAll("table")) e.remove();
1260
+ try {
1261
+ let e = await fetch(n);
1262
+ if (!e.ok) throw Error(`${e.status} ${e.statusText}`);
1263
+ let r = await e.json(), i = Array.isArray(r) ? r : r?.rows;
1264
+ if (!Array.isArray(i)) throw Error("no array of rows in it");
1265
+ let a = Array.isArray(r?.series) ? r.series.map(String) : [], o = t.querySelector(":scope > figcaption"), s = it(i, a);
1266
+ o ? o.after(s) : t.prepend(s), Y?.log?.(`Read ${i.length} rows from "${n}"`);
1267
+ } catch (t) {
1268
+ let r = window.location.protocol === "file:";
1269
+ console.warn(`[${e}] Could not read the chart data in "${n}": ${t.message}.` + (r ? " A page opened from the file system cannot fetch files; open the page from a server instead." : ""));
1270
+ }
1271
+ }));
1272
+ }, Z = (e) => {
1273
+ let t = Array.from(e.childNodes).filter((e) => e.nodeType === Node.ELEMENT_NODE || e.nodeType === Node.TEXT_NODE && e.textContent?.trim());
1274
+ return t.length === 1 && t[0] instanceof HTMLElement ? t[0] : null;
1275
+ }, ot = "strong, b, span.total", st = (e) => {
1276
+ for (let t of e) {
1277
+ for (let e of t.querySelectorAll("tbody tr")) {
1278
+ let t = e.cells[0];
1279
+ if (t?.tagName !== "TD" || e.cells.length < 2) continue;
1280
+ let n = document.createElement("th");
1281
+ for (let { name: e, value: r } of Array.from(t.attributes)) n.setAttribute(e, r);
1282
+ n.append(...t.childNodes), t.replaceWith(n);
1283
+ for (let t = Z(n); t?.matches(ot); t = Z(n)) e.dataset.kind = "total", t.replaceWith(...t.childNodes);
1284
+ }
1285
+ let e = Array.from(t.querySelector("thead tr:last-child")?.children ?? []);
1286
+ for (let t of e.slice(1)) for (let e = Z(t); e?.matches(ot); e = Z(t)) t.setAttribute("data-kind", "focus"), e.replaceWith(...e.childNodes);
1287
+ }
1288
+ }, ct = "data-chart-made", lt = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, ut = (e) => new Promise((t) => setTimeout(t, e)), dt = async (e) => {
1289
+ if (lt()) return;
1290
+ await new Promise(requestAnimationFrame);
1291
+ let t = e.getAnimations().filter((e) => e instanceof CSSAnimation);
1292
+ for (let n = e.parentElement; n && n !== document.body; n = n.parentElement) t.push(...n.getAnimations());
1293
+ let n = 0;
1294
+ for (let e of t) {
1295
+ let t = e.effect?.getComputedTiming(), r = Number(t?.activeDuration ?? 0);
1296
+ if (!t || !Number.isFinite(r)) continue;
1297
+ let i = Number(t.delay ?? 0) + r / 2;
1298
+ n = Math.max(n, i - Number(e.currentTime ?? 0));
1299
+ }
1300
+ n > 0 && await ut(n);
1301
+ }, ft = (e) => {
1302
+ for (let t = e; t && t !== document.body; t = t.parentElement) if (getComputedStyle(t).opacity === "0") return t;
1303
+ return null;
1304
+ }, pt = (e) => new Promise((t) => {
1305
+ let n = ["animationstart", "transitionrun"], r = () => {
1306
+ for (let e of n) document.removeEventListener(e, i, !0);
1307
+ a.disconnect(), t();
1308
+ }, i = (t) => {
1309
+ t.target instanceof Node && t.target.contains(e) && r();
1310
+ }, a = new MutationObserver(() => {
1311
+ getComputedStyle(e).opacity !== "0" && r();
1312
+ });
1313
+ for (let e of n) document.addEventListener(e, i, !0);
1314
+ a.observe(e, {
1315
+ attributes: !0,
1316
+ attributeFilter: ["class", "style"]
1317
+ });
1318
+ }), Q = /* @__PURE__ */ new Set(), $ = null, mt = (e) => {
1319
+ Q.add(e), !$ && ($ = new MutationObserver(() => {
1320
+ for (let e of Q) e.relabel();
1321
+ requestAnimationFrame(() => requestAnimationFrame(() => {
1322
+ for (let e of Q) e.refresh();
1323
+ }));
1324
+ }), $.observe(document.documentElement, {
1325
+ attributes: !0,
1326
+ attributeFilter: ["lang"]
1327
+ }));
1328
+ }, ht = (e) => {
1329
+ Q.delete(e), !(Q.size || !$) && ($.disconnect(), $ = null);
1330
+ }, gt = ["column", "bar"], _t = (e) => {
1331
+ let t = e.getAttribute("data-chart") || "column";
1332
+ if (!gt.includes(t)) return null;
1333
+ let n = getComputedStyle(e).getPropertyValue("--tablechart-type").trim();
1334
+ return gt.includes(n) ? n : t;
1335
+ }, vt = (e, t) => {
1336
+ let n = e, r = _t(n.figure), i = null, a = !1, o = !1, s = async () => {
1337
+ if (!t.animate) return X(n, !0);
1338
+ let e = n.figure.classList.contains("is-shown");
1339
+ if (a && i !== null && !e && !o) {
1340
+ o = !0;
1341
+ let e = lt() ? null : ft(n.figure);
1342
+ e && await pt(e), await dt(n.figure), o = !1, (a || !t.replay) && X(n, !0);
1343
+ } else !a && t.replay && e && X(n, !1);
1344
+ }, c = () => {
1345
+ let e = _t(n.figure);
1346
+ if (!e || e === r) return;
1347
+ let a = Ve(n.figure, t, e);
1348
+ a && (Ke(n), n = a, r = e, i = null);
1349
+ }, l = () => {
1350
+ c();
1351
+ let e = n.plot.clientWidth;
1352
+ !e || e === i || We(n, t) && (i = e, s());
1353
+ }, u = !1, d = new ResizeObserver(() => {
1354
+ u || (u = !0, requestAnimationFrame(() => {
1355
+ u = !1, l();
1356
+ }));
1357
+ }), f = new IntersectionObserver((e) => {
1358
+ for (let t of e) a = t.isIntersecting, s();
1359
+ }, { threshold: t.threshold }), p = () => X(n, !0), m = () => {
1360
+ i = null, l();
1361
+ }, h = {
1362
+ relabel: () => Ge(n, t),
1363
+ refresh: m
1364
+ };
1365
+ c(), l(), d.observe(n.figure), f.observe(n.figure), window.addEventListener("beforeprint", p), mt(h);
1366
+ let g = {
1367
+ figure: n.figure,
1368
+ refresh: m,
1369
+ destroy() {
1370
+ d.disconnect(), f.disconnect(), window.removeEventListener("beforeprint", p), ht(h), n.figure.tablechart === g && delete n.figure.tablechart;
1371
+ }
1372
+ };
1373
+ return n.figure.tablechart = g, g;
1374
+ }, yt = async (e, t) => {
1375
+ let n = rt(e.filter((e) => !e.hasAttribute(ct)));
1376
+ return await at(n), st(n), Me(n, t.langattribute), n;
1377
+ }, bt = (e, t) => {
1378
+ let n = Ve(e, t);
1379
+ return n ? (e.setAttribute(ct, ""), vt(n, t)) : null;
1380
+ }, xt = async (e, t = {}) => {
1381
+ if (e.tablechart) return e.tablechart;
1382
+ let n = {
1383
+ ...A,
1384
+ ...t
1385
+ };
1386
+ n.debug && (Y.enabled = !0);
1387
+ let [r] = await yt([e], n);
1388
+ return r ? bt(r, n) : null;
1389
+ }, St = async (e = {}, t = document) => {
1390
+ let n = {
1391
+ ...A,
1392
+ ...e
1393
+ };
1394
+ n.debug && (Y.enabled = !0);
1395
+ let r = (await yt(Array.from(t.querySelectorAll(n.selector)), n)).map((e) => bt(e, n)).filter((e) => e !== null);
1396
+ return Y.log(`Made ${r.length} chart(s).`), {
1397
+ charts: r,
1398
+ refresh: () => {
1399
+ for (let e of r) e.refresh();
1400
+ },
1401
+ destroy: () => {
1402
+ for (let e of r) e.destroy();
1403
+ }
1404
+ };
1405
+ };
1406
+ //#endregion
1407
+ export { A as _, at as a, We as c, Ke as d, Me as f, D as g, O as h, rt as i, Ge as l, t as m, St as n, st as o, w as p, yt as r, Ve as s, xt as t, X as u };