@graphysdk/viz-engine 0.0.1 → 1.8.1-beta.1786024899180

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,1951 @@
1
+ import { differenceInDays as Re, isBefore as Ce, isValid as f, isWithinInterval as Le, parse as N } from "date-fns";
2
+ import { isEqual as Ie, isInteger as Ve } from "lodash-es";
3
+ import { desc as xe, op as re, table as O } from "arquero";
4
+ var vr = (e) => e.length > 0;
5
+ function ae(e) {
6
+ return e != null;
7
+ }
8
+ function Mr(e) {
9
+ if (e === null || typeof e != "object") return !1;
10
+ const t = Object.getPrototypeOf(e);
11
+ return t === Object.prototype || t === null;
12
+ }
13
+ var ne = "\0graphy\0_", c = (e) => `${ne}${e}`, Be = { x: c("constantX") }, se = {
14
+ count: c("count"),
15
+ mean: c("mean")
16
+ }, je = { group: c("group") }, Pe = {
17
+ x: c("x"),
18
+ y: c("y"),
19
+ xMin: c("xMin"),
20
+ xMax: c("xMax"),
21
+ yMin: c("yMin"),
22
+ yMax: c("yMax"),
23
+ yRaw: c("yRaw")
24
+ }, Ue = { role: c("stackRole") }, $e = {
25
+ color: c("color"),
26
+ size: c("size"),
27
+ alpha: c("alpha"),
28
+ strokeWidth: c("strokeWidth"),
29
+ lineType: c("lineType")
30
+ }, Ye = {
31
+ y: c("ruleY"),
32
+ x: c("ruleX")
33
+ }, Er = {
34
+ ...Be,
35
+ ...se,
36
+ ...je,
37
+ ...Pe,
38
+ ...Ue,
39
+ ...$e,
40
+ ...Ye
41
+ }, ze = new Set(Object.values(se)), _r = (e) => c(`scaled_${e}`), Tr = (e) => e.startsWith(ne), Ar = (e) => ze.has(e);
42
+ function Fr(e) {
43
+ return {
44
+ type: "mapping",
45
+ mapping: e
46
+ };
47
+ }
48
+ function Dr(e) {
49
+ return ae(e) ? typeof e == "string" ? e : "variable" in e ? e.variable : null : null;
50
+ }
51
+ function Nr(e) {
52
+ if (!(!ae(e) || typeof e == "string") && "value" in e)
53
+ return e.value;
54
+ }
55
+ var G = (e) => e instanceof Date && f(e), wr = (e) => G(e) || e === null, Sr = (e) => typeof e == "string", We = (e) => typeof e == "number" && !Number.isNaN(e) && Number.isFinite(e), Or = (e) => We(e) || e === null, oe = (e) => (Array.isArray(e) ? e : [e]).map((t) => t instanceof Date ? t.toISOString() : String(t ?? "<null>")).join("\0"), kr = (e, t) => e === t ? !0 : G(e) && G(t) ? e.getTime() === t.getTime() : !1, D = process.env.NODE_ENV !== "production", j = !0, Rr = (e) => {
56
+ j = e;
57
+ }, Cr = () => j, Lr = () => {
58
+ let e = null;
59
+ const t = {
60
+ hits: 0,
61
+ misses: 0
62
+ };
63
+ return Object.assign((a, n) => {
64
+ if (!j)
65
+ return D && (t.misses += 1), n();
66
+ if (e && ie(e.args, a))
67
+ return D && (t.hits += 1), e.out;
68
+ D && (t.misses += 1);
69
+ const s = n();
70
+ return e = {
71
+ args: a,
72
+ out: s
73
+ }, s;
74
+ }, {
75
+ stats: t,
76
+ reset: () => {
77
+ e = null;
78
+ }
79
+ });
80
+ }, Ge = () => {
81
+ const e = /* @__PURE__ */ new WeakMap(), t = {
82
+ hits: 0,
83
+ misses: 0
84
+ };
85
+ return Object.assign((a, n, s) => {
86
+ if (!j)
87
+ return D && (t.misses += 1), s();
88
+ const o = e.get(a);
89
+ if (o) {
90
+ for (const l of o) if (ie(l.args, n))
91
+ return D && (t.hits += 1), l.out;
92
+ }
93
+ D && (t.misses += 1);
94
+ const i = s();
95
+ return o ? o.push({
96
+ args: n,
97
+ out: i
98
+ }) : e.set(a, [{
99
+ args: n,
100
+ out: i
101
+ }]), i;
102
+ }, { stats: t });
103
+ }, Ir = (...e) => e.reduce((t, r) => ({
104
+ hits: t.hits + r.hits,
105
+ misses: t.misses + r.misses
106
+ }), {
107
+ hits: 0,
108
+ misses: 0
109
+ }), ie = (e, t) => {
110
+ if (e.length !== t.length) return !1;
111
+ for (let r = 0; r < e.length; r += 1) if (e[r] !== t[r]) return !1;
112
+ return !0;
113
+ }, Ke = class {
114
+ constructor() {
115
+ this.memo = Ge(), this.singletonKey = {};
116
+ }
117
+ get stats() {
118
+ return this.memo.stats;
119
+ }
120
+ compile(e) {
121
+ return this.memo(this.key(e), this.dependencies(e), () => this.run(e));
122
+ }
123
+ key(e) {
124
+ return this.singletonKey;
125
+ }
126
+ }, le = class extends Error {
127
+ constructor(e) {
128
+ super(e.message, e.cause !== void 0 ? { cause: e.cause } : void 0), this.name = new.target.name, this.code = e.code, this.context = e.context, this.suggestion = e.suggestion;
129
+ }
130
+ }, B = class extends le {
131
+ constructor(e) {
132
+ super(e), this.kind = "user-input";
133
+ }
134
+ }, v = class extends le {
135
+ constructor(e) {
136
+ super({
137
+ ...e,
138
+ code: e.code ?? "INTERNAL_INVARIANT"
139
+ }), this.kind = "internal";
140
+ }
141
+ }, ue = (e) => e.type === "lookup", He = (e) => e.type === "text", P = (e) => e.type === "date" || e.type === "datetime" || e.type === "year" || e.type === "month_year" || e.type === "month" || e.type === "day_month" || e.type === "weekly_date_range" || e.type === "weekly_date_range_with_year" || e.type === "quarter" || e.type === "time", qe = (e) => e.type === "decimal" || e.type === "integer" || e.type === "percentage" || e.type === "duration" || e.type === "currency", Vr = (e) => e.type === "currency", xr = (e) => e.type === "month" || e.type === "day_month" || e.type === "weekly_date_range", ce = (e) => {
142
+ if (ue(e)) return ce(e.fallback);
143
+ if (P(e)) return "temporal";
144
+ if (qe(e)) return "numeric";
145
+ if (He(e)) return "categorical";
146
+ throw new v({ message: `No data type found for value format: ${e.type}` });
147
+ }, Br = (e) => ue(e) ? e.fallback : e, Xe = {
148
+ k: 1e3,
149
+ m: 1e6,
150
+ b: 1e9,
151
+ t: 1e12
152
+ }, q = [
153
+ "k",
154
+ "m",
155
+ "b",
156
+ "t"
157
+ ], Qe = new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${q.join("|")})?$`, "i"), Je = /^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/, T = (e) => e === null || e instanceof Date || Array.isArray(e) || typeof e == "boolean" ? !1 : typeof e == "string" ? Qe.test(e) && !Number.isNaN(Number(e.replace(new RegExp(`[,${q.join("")}]`, "gi"), ""))) : !Number.isNaN(Number(e)), de = (e) => T(e) ? !0 : typeof e == "string" ? Je.test(e) : !1, ye = {
158
+ $: "usd",
159
+ "£": "gbp",
160
+ "€": "eur",
161
+ "¥": "jpy",
162
+ "₹": "inr",
163
+ "₱": "php",
164
+ P: "php",
165
+ "₩": "krw",
166
+ "₪": "ils",
167
+ "₫": "vnd",
168
+ "₽": "rub",
169
+ "฿": "thb",
170
+ R$: "brl",
171
+ Rp: "idr",
172
+ RM: "myr",
173
+ "₦": "ngn",
174
+ zł: "pln",
175
+ "₺": "try",
176
+ kr: "dkk",
177
+ Fr: "chf",
178
+ R: "zar",
179
+ "د.إ": "aed",
180
+ "﷼": "sar",
181
+ Ch$: "clp",
182
+ NT$: "twd",
183
+ HK$: "hkd",
184
+ S$: "sgd",
185
+ A$: "aud",
186
+ C$: "cad",
187
+ NZ$: "nzd",
188
+ MX$: "mxn"
189
+ }, fe = (e) => {
190
+ if (typeof e == "string") {
191
+ const t = me(e);
192
+ return t.length ? T(t) : !1;
193
+ }
194
+ return T(e);
195
+ }, Ze = (e) => {
196
+ const t = pe(e), r = t ? ye[t] : void 0;
197
+ if (!r) throw new v({ message: "Could not get currency ISO" });
198
+ return r;
199
+ }, me = (e) => {
200
+ const t = pe(e);
201
+ let r = e;
202
+ if (t) {
203
+ const a = e.indexOf(t);
204
+ a === 0 ? r = e.slice(t.length) : a === e.length - t.length ? r = e.slice(0, e.length - t.length) : e[0] === "-" && a === 1 && (r = `-${e.slice(t.length + 1)}`);
205
+ }
206
+ return T(r) ? r.split(",").join("") : "";
207
+ }, pe = (e) => Object.keys(ye).sort((t, r) => r.length - t.length).find((t) => e.includes(t)), ge = (e) => {
208
+ const t = Object.entries(e);
209
+ return !t.length || !t.some(([, r]) => !C(r));
210
+ }, C = (e) => typeof e == "string" && e.trim() === "" || e === void 0 || e === null || e === "-", be = "en-GB", et = class {
211
+ constructor() {
212
+ this.currentYear = (/* @__PURE__ */ new Date()).getUTCFullYear(), this.previousDate = null, this.previousYear = null;
213
+ }
214
+ incrementYearIfNeeded(e) {
215
+ this.previousYear === null ? this.previousYear = e.getUTCFullYear() : this.previousDate !== null && Ce(new Date(this.currentYear, e.getUTCMonth(), e.getUTCDate()), new Date(this.currentYear, this.previousDate.getUTCMonth(), this.previousDate.getUTCDate())) && this.previousYear++;
216
+ const t = new Date(e.getTime());
217
+ return t.setUTCFullYear(this.previousYear), this.previousDate = t, t;
218
+ }
219
+ }, tt = /^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/, rt = /^\s*(19\d{2}|2[01]\d{2})\s*$/, at = [
220
+ [/\bJan\b/i, "January"],
221
+ [/\bFeb\b/i, "February"],
222
+ [/\bMar\b/i, "March"],
223
+ [/\bApr\b/i, "April"],
224
+ [/\bJun\b/i, "June"],
225
+ [/\bJul\b/i, "July"],
226
+ [/\bAug\b/i, "August"],
227
+ [/\bSept?\b/i, "September"],
228
+ [/\bOct\b/i, "October"],
229
+ [/\bNov\b/i, "November"],
230
+ [/\bDec\b/i, "December"]
231
+ ], nt = {
232
+ "en-US": "MDY",
233
+ "en-GB": "DMY",
234
+ "pt-PT": "DMY",
235
+ ar: "DMY"
236
+ }, he = [
237
+ "/",
238
+ "-",
239
+ ".",
240
+ " "
241
+ ], X = [
242
+ [
243
+ "d",
244
+ "M",
245
+ "yy"
246
+ ],
247
+ [
248
+ "d",
249
+ "MM",
250
+ "yy"
251
+ ],
252
+ [
253
+ "d",
254
+ "MMMM",
255
+ "yy"
256
+ ],
257
+ [
258
+ "dd",
259
+ "M",
260
+ "yy"
261
+ ],
262
+ [
263
+ "dd",
264
+ "MM",
265
+ "yy"
266
+ ],
267
+ [
268
+ "dd",
269
+ "MMMM",
270
+ "yy"
271
+ ],
272
+ [
273
+ "do",
274
+ "MMMM",
275
+ "yy"
276
+ ],
277
+ [
278
+ "d",
279
+ "M",
280
+ "yyyy"
281
+ ],
282
+ [
283
+ "d",
284
+ "MM",
285
+ "yyyy"
286
+ ],
287
+ [
288
+ "d",
289
+ "MMMM",
290
+ "yyyy"
291
+ ],
292
+ [
293
+ "dd",
294
+ "M",
295
+ "yyyy"
296
+ ],
297
+ [
298
+ "dd",
299
+ "MM",
300
+ "yyyy"
301
+ ],
302
+ [
303
+ "dd",
304
+ "MMMM",
305
+ "yyyy"
306
+ ],
307
+ [
308
+ "do",
309
+ "MMMM",
310
+ "yyyy"
311
+ ]
312
+ ], Q = [
313
+ [
314
+ "M",
315
+ "d",
316
+ "yy"
317
+ ],
318
+ [
319
+ "M",
320
+ "dd",
321
+ "yy"
322
+ ],
323
+ [
324
+ "MM",
325
+ "d",
326
+ "yy"
327
+ ],
328
+ [
329
+ "MM",
330
+ "dd",
331
+ "yy"
332
+ ],
333
+ [
334
+ "MMMM",
335
+ "d",
336
+ "yy"
337
+ ],
338
+ [
339
+ "MMMM",
340
+ "dd",
341
+ "yy"
342
+ ],
343
+ [
344
+ "MMMM",
345
+ "do",
346
+ "yy"
347
+ ],
348
+ [
349
+ "M",
350
+ "d",
351
+ "yyyy"
352
+ ],
353
+ [
354
+ "M",
355
+ "dd",
356
+ "yyyy"
357
+ ],
358
+ [
359
+ "MM",
360
+ "d",
361
+ "yyyy"
362
+ ],
363
+ [
364
+ "MM",
365
+ "dd",
366
+ "yyyy"
367
+ ],
368
+ [
369
+ "MMMM",
370
+ "d",
371
+ "yyyy"
372
+ ],
373
+ [
374
+ "MMMM",
375
+ "dd",
376
+ "yyyy"
377
+ ],
378
+ [
379
+ "MMMM",
380
+ "do",
381
+ "yyyy"
382
+ ]
383
+ ], J = [
384
+ [
385
+ "yyyy",
386
+ "M",
387
+ "d"
388
+ ],
389
+ [
390
+ "yyyy",
391
+ "M",
392
+ "dd"
393
+ ],
394
+ [
395
+ "yyyy",
396
+ "MM",
397
+ "d"
398
+ ],
399
+ [
400
+ "yyyy",
401
+ "MM",
402
+ "dd"
403
+ ],
404
+ [
405
+ "yyyy",
406
+ "MMMM",
407
+ "d"
408
+ ],
409
+ [
410
+ "yyyy",
411
+ "MMMM",
412
+ "dd"
413
+ ],
414
+ [
415
+ "yyyy",
416
+ "MMMM",
417
+ "do"
418
+ ]
419
+ ], ve = [
420
+ ["d", "MMMM"],
421
+ ["dd", "MMMM"],
422
+ ["do", "MMMM"],
423
+ ["MMMM", "d"],
424
+ ["MMMM", "dd"],
425
+ ["MMMM", "do"]
426
+ ], st = [
427
+ {
428
+ dateFormat: "MMMM d, yyyy",
429
+ type: "date"
430
+ },
431
+ {
432
+ dateFormat: "MMMM dd, yyyy",
433
+ type: "date"
434
+ },
435
+ {
436
+ dateFormat: "MMMM do, yyyy",
437
+ type: "date"
438
+ },
439
+ {
440
+ dateFormat: "yyyy-MM",
441
+ type: "month_year"
442
+ }
443
+ ], Me = 1900, Ee = 2199, ot = 3, it = 6, lt = 5, ut = 1, ct = 28, dt = /\s*[–—]\s*|\s-\s/, yt = (e) => typeof e == "number" ? Number.isNaN(e) ? !1 : e >= Me && e <= Ee : typeof e == "string" ? rt.test(e) : !1, _e = (e, t) => {
444
+ const r = R(e);
445
+ return !t && T(r) ? pt(r) : typeof r == "string" ? t ? f(N(r, t, /* @__PURE__ */ new Date())) : !!Te(r) || U(r) && f(new Date(r)) : f(r);
446
+ }, R = (e) => {
447
+ if (typeof e != "string") return e;
448
+ let t = e;
449
+ for (const [r, a] of at) t = t.replace(r, a);
450
+ return t;
451
+ }, Te = (e, t = be) => {
452
+ const r = R(e);
453
+ return U(r) ? { type: "datetime" } : Ae(t).find((a) => !P(a) || a.type === "month" && r.length < ot ? !1 : a.dateFormat && f(N(r, a.dateFormat, /* @__PURE__ */ new Date())));
454
+ }, U = (e) => tt.test(e.trim()), jr = (e) => {
455
+ if (e instanceof Date) return f(e) ? e : null;
456
+ if (typeof e != "string" || !U(e)) return null;
457
+ const t = new Date(e.trim());
458
+ return f(t) ? t : null;
459
+ }, ft = (e, t = be) => {
460
+ const [r, a] = e.split(dt);
461
+ if (!r || !a) return;
462
+ const n = R(r).trim(), s = R(a).trim();
463
+ return mt(t).find((o) => {
464
+ if (!P(o) || !o.dateFormat) return !1;
465
+ const i = N(n, o.dateFormat, /* @__PURE__ */ new Date()), l = N(s, o.dateFormat, /* @__PURE__ */ new Date());
466
+ if (!f(i) || !f(l)) return !1;
467
+ const u = new et(), d = u.incrementYearIfNeeded(i), M = u.incrementYearIfNeeded(l), y = Re(M, d);
468
+ return Le(new Date(d.getFullYear(), ut, ct), {
469
+ start: d,
470
+ end: M
471
+ }) && y === lt ? !0 : y === it;
472
+ });
473
+ }, Ae = (e) => {
474
+ const t = {
475
+ date: Fe(e),
476
+ year: [["yyyy"]],
477
+ day_month: ve,
478
+ month_year: [["MMMM", "yyyy"], ["yyyy", "MMMM"]],
479
+ month: [["MMMM"]],
480
+ quarter: [["QQQ", "yyyy"], ["yyyy", "QQQ"]]
481
+ };
482
+ return [...st, ...Object.entries(t).flatMap(([r, a]) => a.flatMap((n) => he.map((s) => ({
483
+ dateFormat: n.join(s),
484
+ type: r
485
+ }))))];
486
+ }, Fe = (e) => nt[e] === "MDY" ? [
487
+ ...Q,
488
+ ...X,
489
+ ...J
490
+ ] : [
491
+ ...X,
492
+ ...Q,
493
+ ...J
494
+ ], mt = (e) => {
495
+ const t = {
496
+ weekly_date_range: ve,
497
+ weekly_date_range_with_year: Fe(e)
498
+ };
499
+ return Object.entries(t).flatMap(([r, a]) => a.flatMap((n) => he.map((s) => ({
500
+ dateFormat: n.join(s),
501
+ type: r
502
+ }))));
503
+ }, pt = (e) => {
504
+ const t = Number(e);
505
+ if (!Ve(t)) return !1;
506
+ const r = new Date(t), a = /* @__PURE__ */ new Date(t * 1e3), n = (s) => f(s) && s.getFullYear() >= Me && s.getFullYear() <= Ee;
507
+ return n(r) || n(a);
508
+ }, gt = /\s*[–—]\s*|\s-\s/, bt = (e, t, r) => {
509
+ if (C(e)) return null;
510
+ switch (t.type) {
511
+ case "decimal":
512
+ case "integer":
513
+ case "duration":
514
+ return Ne(e);
515
+ case "percentage":
516
+ return ht(e);
517
+ case "currency":
518
+ return vt(e);
519
+ case "datetime":
520
+ case "date":
521
+ case "year":
522
+ case "month_year":
523
+ case "month":
524
+ case "day_month":
525
+ case "quarter":
526
+ case "time":
527
+ return De(e, t.dateFormat, r);
528
+ case "weekly_date_range":
529
+ case "weekly_date_range_with_year":
530
+ return Mt(e, t.dateFormat, r);
531
+ case "text":
532
+ return Et(e);
533
+ case "lookup":
534
+ throw new v({ message: "Cannot parse: lookup value formats are produced by transforms, not raw input" });
535
+ default:
536
+ throw new v({ message: `Unhandled value format: ${t.type}` });
537
+ }
538
+ }, De = (e, t, r) => {
539
+ if (e instanceof Date) return f(e) ? e : null;
540
+ const a = R(String(e).trim());
541
+ if (a.length === 0) return null;
542
+ const n = /* @__PURE__ */ new Date();
543
+ if (t) {
544
+ const o = N(a, t, n);
545
+ return f(o) ? Y(o) : null;
546
+ }
547
+ for (const o of Ae(r)) {
548
+ if (!P(o) || !o.dateFormat) continue;
549
+ const i = N(a, o.dateFormat, n);
550
+ if (f(i)) return Y(i);
551
+ }
552
+ const s = new Date(a);
553
+ return _e(s) ? U(a) ? s : Y(s) : null;
554
+ }, Ne = (e) => {
555
+ if (typeof e == "number") return Number.isNaN(e) ? null : e;
556
+ if (typeof e != "string") return null;
557
+ let t = e.trim();
558
+ if (!T(t)) return null;
559
+ let r = 1;
560
+ for (const a of q) if (new RegExp(`${a}$`, "i").test(t)) {
561
+ r = Xe[a], t = t.slice(0, -1);
562
+ break;
563
+ }
564
+ return Number(t.split(",").join("")) * r;
565
+ }, ht = (e) => {
566
+ if (typeof e == "number") return Number.isNaN(e) ? null : e;
567
+ if (typeof e != "string") return null;
568
+ const t = e.trim();
569
+ if (!de(t)) return null;
570
+ const r = Number(t.replace(/%/g, "").replace(/,/g, "")) / 100;
571
+ return Number.isNaN(r) ? null : r;
572
+ }, vt = (e) => {
573
+ if (typeof e == "number") return Number.isNaN(e) ? null : e;
574
+ if (typeof e != "string") return null;
575
+ const t = e.trim();
576
+ return fe(t) ? Ne(me(t)) : null;
577
+ }, Mt = (e, t, r) => {
578
+ const a = String(e).trim().split(gt), [n, s] = [a[0]?.trim(), a[1]?.trim()];
579
+ return !n || !s ? null : De(n, t, r);
580
+ }, Et = (e) => String(e).trim(), Y = (e) => new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes(), e.getSeconds(), e.getMilliseconds())), _t = /* @__PURE__ */ new Set([
581
+ "count",
582
+ "sum",
583
+ "mean",
584
+ "median"
585
+ ]);
586
+ function we(e, t) {
587
+ return _t.has(e) ? "numeric" : t;
588
+ }
589
+ var Tt = "value", Z = "\0__rowMaskIndex", k = {
590
+ numeric: { type: "decimal" },
591
+ categorical: { type: "text" },
592
+ temporal: { type: "datetime" }
593
+ }, At = {
594
+ eq: (e, t) => e[t.__variableName] === t.__value,
595
+ neq: (e, t) => e[t.__variableName] !== t.__value,
596
+ gt: (e, t) => e[t.__variableName] > t.__value,
597
+ gte: (e, t) => e[t.__variableName] >= t.__value,
598
+ lt: (e, t) => e[t.__variableName] < t.__value,
599
+ lte: (e, t) => e[t.__variableName] <= t.__value
600
+ }, Se = (e, t) => e === "count" ? { type: "integer" } : t, K = class g {
601
+ constructor(t = {}) {
602
+ const { table: r, variableMetadata: a } = this.parseVariableMap(t);
603
+ this.table = r, this.variableMetadata = a;
604
+ }
605
+ static fromTrusted(t, r) {
606
+ const a = Object.create(g.prototype);
607
+ return a.table = t, a.variableMetadata = r, a;
608
+ }
609
+ size() {
610
+ return this.table.numRows();
611
+ }
612
+ getVariableNames() {
613
+ return this.table.columnNames();
614
+ }
615
+ hasVariable(t) {
616
+ return this.table.column(t) !== void 0;
617
+ }
618
+ addVariable(t, r, a, n) {
619
+ const s = {
620
+ ...this.variableMetadata,
621
+ [t]: {
622
+ type: r,
623
+ valueFormat: this.resolveAddedVariableFormat(t, r, n)
624
+ }
625
+ }, o = this.normalizeRawValues(r, a), i = this.table.assign(O({ [t]: o }));
626
+ return g.fromTrusted(i, s);
627
+ }
628
+ addConstantVariable(t, r, a, n) {
629
+ const s = {
630
+ ...this.variableMetadata,
631
+ [t]: {
632
+ type: r,
633
+ valueFormat: this.resolveAddedVariableFormat(t, r, n),
634
+ constant: { value: a }
635
+ }
636
+ }, [o] = this.normalizeRawValues(r, [a]), i = this.table.assign(O({ [t]: Array(this.size()).fill(o) }));
637
+ return g.fromTrusted(i, s);
638
+ }
639
+ getConstant(t) {
640
+ return this.variableMetadata[t]?.constant;
641
+ }
642
+ deriveVariable(t, r, a, n) {
643
+ const s = Array.from({ length: this.size() }, (o, i) => a(this.table.object(i)));
644
+ return this.addVariable(t, r, s, n);
645
+ }
646
+ renameVariable(t, r) {
647
+ const a = this.variableMetadata[t];
648
+ if (!a) throw new v({ message: `Variable ${t} not defined` });
649
+ const n = this.table.rename({ [t]: r }), { [t]: s, ...o } = this.variableMetadata, i = {
650
+ ...o,
651
+ [r]: a
652
+ };
653
+ return g.fromTrusted(n, i);
654
+ }
655
+ selectVariables(...t) {
656
+ const r = this.table.select(...t), a = Object.fromEntries(Object.entries(this.variableMetadata).filter(([n]) => t.includes(n)));
657
+ return g.fromTrusted(r, a);
658
+ }
659
+ getType(t) {
660
+ const r = this.variableMetadata[t];
661
+ if (!r) throw new v({ message: `Variable ${t} not defined` });
662
+ return r.type;
663
+ }
664
+ getValueFormat(t) {
665
+ const r = this.variableMetadata[t];
666
+ if (!r) throw new v({ message: `Variable ${t} not defined` });
667
+ return r.valueFormat;
668
+ }
669
+ groupVariableNamesByType() {
670
+ const t = {
671
+ numeric: [],
672
+ categorical: [],
673
+ temporal: []
674
+ };
675
+ for (const [r, { type: a }] of Object.entries(this.variableMetadata)) t[a].push(r);
676
+ return t;
677
+ }
678
+ getValues(t, r) {
679
+ if (!this.hasVariable(t)) throw new v({ message: `Variable '${t}' not defined` });
680
+ const a = this.getType(t);
681
+ if (r?.type !== void 0 && a !== r.type) throw new v({ message: `Variable '${t}' has type '${a}', expected '${r.type}'` });
682
+ let n = this.table.array(t);
683
+ return r?.distinct && (n = this.getDistinctValues(a, n)), r?.skipNulls && (n = this.skipNulls(n)), n;
684
+ }
685
+ filter(t, r, a) {
686
+ const n = At[r], s = this.table.params({
687
+ __variableName: t,
688
+ __value: a
689
+ }).filter(n);
690
+ return g.fromTrusted(s, this.variableMetadata);
691
+ }
692
+ filterByMask(t) {
693
+ if (t.length !== this.size()) throw new v({ message: `Row mask length ${t.length} does not match dataset size ${this.size()}` });
694
+ const r = Array.from({ length: t.length }, (n, s) => s), a = this.table.assign(O({ [Z]: r })).params({
695
+ __indexColumnName: Z,
696
+ __mask: t
697
+ }).filter((n, s) => s.__mask[n[s.__indexColumnName]] === 1).select(...this.table.columnNames());
698
+ return g.fromTrusted(a, this.variableMetadata);
699
+ }
700
+ orderBy(t, r = "asc") {
701
+ const a = this.table.orderby(r === "asc" ? t : xe(t));
702
+ return g.fromTrusted(a, this.variableMetadata);
703
+ }
704
+ getAt(t) {
705
+ return t < 0 || t >= this.size() ? null : this.table.object(t);
706
+ }
707
+ getFirst() {
708
+ return this.getAt(0);
709
+ }
710
+ getLast() {
711
+ return this.getAt(this.size() - 1);
712
+ }
713
+ findLast(t) {
714
+ for (let r = this.size() - 1; r >= 0; r--) {
715
+ const a = this.table.object(r);
716
+ if (t(a)) return a;
717
+ }
718
+ return null;
719
+ }
720
+ groupBy(...t) {
721
+ const r = this.table.groupby(...t);
722
+ return new Ft(t, r, this.variableMetadata);
723
+ }
724
+ rollup(t) {
725
+ const r = this.table.rollup(Object.fromEntries(Object.entries(t).map(([n, s]) => [n, re[s.aggregation](s.variableName)]))), a = {};
726
+ for (const [n, { variableName: s, aggregation: o }] of Object.entries(t)) {
727
+ const i = this.variableMetadata[s], l = i?.type ?? "numeric", u = i?.valueFormat ?? k[l];
728
+ a[n] = {
729
+ type: we(o, l),
730
+ valueFormat: Se(o, u)
731
+ };
732
+ }
733
+ return g.fromTrusted(r, a);
734
+ }
735
+ reshapeFromWideToLong({ keep: t, reshape: r, keyName: a = "key", valueName: n = Tt } = {}) {
736
+ const { numeric: s, categorical: o, temporal: i } = this.groupVariableNamesByType(), l = t ?? [...o, ...i], u = r ?? s.filter((y) => !l.includes(y));
737
+ if (l.includes(a) || l.includes(n)) throw new B({
738
+ code: "INVALID_DATA_SHAPE",
739
+ message: `The variables to keep includes the variables '${a}' or '${n}' to create the key and value variables`
740
+ });
741
+ if (u.length === 0) {
742
+ const y = {};
743
+ for (const w of l) {
744
+ const $ = this.variableMetadata[w];
745
+ $ && (y[w] = {
746
+ type: $.type,
747
+ values: [],
748
+ valueFormat: $.valueFormat
749
+ });
750
+ }
751
+ return y[a] = {
752
+ type: "categorical",
753
+ values: [],
754
+ valueFormat: { type: "text" }
755
+ }, y[n] = {
756
+ type: "numeric",
757
+ values: [],
758
+ valueFormat: { type: "decimal" }
759
+ }, new g(y);
760
+ }
761
+ if (u.filter((y) => this.variableMetadata[y]?.type !== "numeric").length > 0) throw new B({
762
+ code: "INVALID_DATA_SHAPE",
763
+ message: "Only numeric variables can be reshaped"
764
+ });
765
+ const d = this.table.select([...l, ...u]).fold(u, { as: [a, n] }), M = {};
766
+ for (const y of l) {
767
+ const w = this.variableMetadata[y];
768
+ w && (M[y] = w);
769
+ }
770
+ return M[a] = {
771
+ type: "categorical",
772
+ valueFormat: { type: "text" }
773
+ }, M[n] = {
774
+ type: "numeric",
775
+ valueFormat: Dt(this.variableMetadata, u, a)
776
+ }, g.fromTrusted(d, M);
777
+ }
778
+ print() {
779
+ console.table(this.variableMetadata), this.table.print();
780
+ }
781
+ [Symbol.iterator]() {
782
+ return this.table[Symbol.iterator]();
783
+ }
784
+ resolveAddedVariableFormat(t, r, a) {
785
+ if (a !== void 0) return a;
786
+ const n = this.variableMetadata[t];
787
+ return n ? n.valueFormat : k[r];
788
+ }
789
+ parseVariableMap(t) {
790
+ const r = {}, a = {};
791
+ for (const [n, { type: s, values: o, valueFormat: i }] of Object.entries(t))
792
+ r[n] = o, a[n] = {
793
+ type: s,
794
+ valueFormat: i ?? k[s]
795
+ };
796
+ return {
797
+ table: O(r),
798
+ variableMetadata: a
799
+ };
800
+ }
801
+ normalizeRawValues(t, r) {
802
+ switch (t) {
803
+ case "numeric":
804
+ return r.map((a) => typeof a != "number" || Number.isNaN(a) ? null : a);
805
+ case "categorical":
806
+ return r.map((a) => typeof a != "string" ? null : a);
807
+ case "temporal":
808
+ return r.map((a) => !(a instanceof Date) || !f(a) ? null : a);
809
+ default:
810
+ throw new v({ message: `Cannot normalize raw value of unknown type: ${t}` });
811
+ }
812
+ }
813
+ skipNulls(t) {
814
+ return t.filter((r) => r !== null);
815
+ }
816
+ getDistinctValues(t, r) {
817
+ const a = t === "temporal", n = /* @__PURE__ */ new Set(), s = [];
818
+ for (const o of r) {
819
+ const i = a && o instanceof Date ? o.getTime() : o;
820
+ n.has(i) || (n.add(i), s.push(o));
821
+ }
822
+ return s;
823
+ }
824
+ }, Ft = class {
825
+ constructor(e, t, r) {
826
+ this.groupedBy = e, this.grouped = t, this.variableMetadata = r;
827
+ }
828
+ forEach(e) {
829
+ const t = this.grouped.partitions(), r = this.grouped.columnNames(), a = this.groupedBy.map((s) => this.grouped.column(s)).filter((s) => s !== void 0);
830
+ let n = 0;
831
+ for (const s of t) {
832
+ const o = s[0];
833
+ if (o === void 0) continue;
834
+ const i = this.getStableKey(a, o), l = O(Object.fromEntries(r.map((u) => {
835
+ const d = this.grouped.column(u);
836
+ return [u, s.map((M) => d?.get(M))];
837
+ })));
838
+ e(K.fromTrusted(l, this.variableMetadata), i, n++);
839
+ }
840
+ }
841
+ rollup(e) {
842
+ const t = this.grouped.rollup(Object.fromEntries(Object.entries(e).map(([a, n]) => [a, re[n.aggregation](n.variableName)]))), r = Object.fromEntries(this.groupedBy.map((a) => {
843
+ const n = this.variableMetadata[a], s = n?.type ?? "categorical";
844
+ return [a, {
845
+ type: s,
846
+ valueFormat: n?.valueFormat ?? k[s]
847
+ }];
848
+ }));
849
+ for (const [a, { variableName: n, aggregation: s }] of Object.entries(e)) {
850
+ const o = this.variableMetadata[n], i = o?.type ?? "numeric", l = o?.valueFormat ?? k[i];
851
+ r[a] = {
852
+ type: we(s, i),
853
+ valueFormat: Se(s, l)
854
+ };
855
+ }
856
+ return K.fromTrusted(t, r);
857
+ }
858
+ getStableKey(e, t) {
859
+ return oe(e.map((r) => r.get(t)));
860
+ }
861
+ };
862
+ function Dt(e, t, r) {
863
+ const a = t.map((i) => e[i]?.valueFormat ?? { type: "decimal" }), [n, ...s] = a;
864
+ if (!n) return { type: "decimal" };
865
+ for (const i of a) if (i.type === "lookup") throw new B({
866
+ code: "INVALID_DATA_SHAPE",
867
+ message: "Cannot reshape: a source column has a lookup format and lookups cannot nest"
868
+ });
869
+ if (s.every((i) => Ie(i, n)) || n.type === "lookup") return n;
870
+ const o = {};
871
+ for (const [i, l] of t.entries()) {
872
+ const u = oe([l]), d = a[i];
873
+ d && d.type !== "lookup" && (o[u] = d);
874
+ }
875
+ return {
876
+ type: "lookup",
877
+ byVariable: r,
878
+ cases: o,
879
+ fallback: n
880
+ };
881
+ }
882
+ var Nt = class {
883
+ constructor(e) {
884
+ this.label = e, this.items = /* @__PURE__ */ new Map();
885
+ }
886
+ register(e, t) {
887
+ return this.items.set(e, t), this;
888
+ }
889
+ get(e) {
890
+ if (!this.items.has(e)) {
891
+ const t = [...this.items.keys()].map((r) => `'${r}'`).join(", ");
892
+ throw new B({
893
+ code: "UNKNOWN_REGISTERED_TYPE",
894
+ message: `Unknown ${this.label}: '${e}' (available: ${t})`,
895
+ context: {
896
+ kind: this.label,
897
+ requested: e,
898
+ available: [...this.items.keys()]
899
+ },
900
+ suggestion: `Register a custom ${this.label} named '${e}' in the \`plugins\` array, or use one of: ${t}.`
901
+ });
902
+ }
903
+ return this.items.get(e);
904
+ }
905
+ getAll() {
906
+ return [...this.items.values()];
907
+ }
908
+ has(e) {
909
+ return this.items.has(e);
910
+ }
911
+ }, wt = (e, t) => {
912
+ const r = typeof e == "string" ? e.trim() : e;
913
+ if (T(r)) return { type: "decimal" };
914
+ const a = typeof r == "string" && Te(r, t);
915
+ if (a) return a;
916
+ const n = typeof r == "string" && ft(r, t);
917
+ return n || (_e(e) ? { type: "date" } : de(e) ? { type: "percentage" } : fe(e) && typeof e == "string" ? {
918
+ type: "currency",
919
+ iso: Ze(e)
920
+ } : { type: "text" });
921
+ }, St = {
922
+ type: "year",
923
+ dateFormat: "yyyy"
924
+ }, Ot = (e) => {
925
+ const t = e._metadata?.parsingLocale ?? "en-GB", r = {}, a = Ct(e), n = kt(e);
926
+ for (const [s, o] of e.columns.entries()) {
927
+ if (o._metadata?.isHidden) continue;
928
+ const i = a.get(o.key);
929
+ if (C(i)) continue;
930
+ const l = s === n ? St : wt(i, t), u = ce(l);
931
+ r[o.key] = Rt(o.key, e.rows, l, u, t);
932
+ }
933
+ return new K(r);
934
+ }, Pr = class extends Ke {
935
+ dependencies(e) {
936
+ return [e];
937
+ }
938
+ run(e) {
939
+ return Ot(e);
940
+ }
941
+ }, kt = (e) => {
942
+ const t = Lt(e.rows, 5);
943
+ return e.columns.findIndex((r) => {
944
+ const a = t.map((n) => n[r.key]).filter((n) => !C(n));
945
+ return a.length >= 2 && a.every(yt);
946
+ });
947
+ }, Rt = (e, t, r, a, n) => ({
948
+ type: a,
949
+ values: t.reduce((s, o) => (ge(o) || s.push(bt(o[e], r, n)), s), []),
950
+ valueFormat: r
951
+ }), Ct = (e) => {
952
+ const t = /* @__PURE__ */ new Map(), r = new Set(e.columns.map((a) => a.key));
953
+ for (const a of e.rows) {
954
+ for (const n of r) {
955
+ const s = a[n];
956
+ C(s) || (t.set(n, s), r.delete(n));
957
+ }
958
+ if (r.size === 0) break;
959
+ }
960
+ return t;
961
+ }, Lt = (e, t) => {
962
+ const r = [];
963
+ for (const a of e)
964
+ if (ge(a) || r.push(a), r.length === t) return r;
965
+ return r;
966
+ }, It = class {
967
+ constructor() {
968
+ this.transformType = "aggregate";
969
+ }
970
+ apply(e, t) {
971
+ const { options: r } = t, a = {};
972
+ for (const n of r.operations) a[n.as] = {
973
+ variableName: n.variableName,
974
+ aggregation: n.op
975
+ };
976
+ return e.groupBy(...r.groupby).rollup(a);
977
+ }
978
+ }, Vt = class {
979
+ constructor() {
980
+ this.transformType = "constant";
981
+ }
982
+ apply(e, t) {
983
+ const { options: r } = t;
984
+ return e.addConstantVariable(r.variableName, r.type, r.value);
985
+ }
986
+ getIntroducedVariables(e) {
987
+ const { options: t } = e;
988
+ return [t.variableName];
989
+ }
990
+ }, xt = class {
991
+ constructor() {
992
+ this.transformType = "filter";
993
+ }
994
+ apply(e, t) {
995
+ const { options: r } = t;
996
+ return e.filter(r.variableName, r.operator, r.value);
997
+ }
998
+ }, Bt = class {
999
+ constructor() {
1000
+ this.transformType = "reshape";
1001
+ }
1002
+ apply(e, t) {
1003
+ const { options: r } = t;
1004
+ return e.reshapeFromWideToLong({
1005
+ keep: r.keep,
1006
+ reshape: r.reshape,
1007
+ keyName: r.keyName,
1008
+ valueName: r.valueName
1009
+ });
1010
+ }
1011
+ getIntroducedVariables(e) {
1012
+ const { options: t } = e;
1013
+ return [t.keyName ?? "key"];
1014
+ }
1015
+ }, jt = class {
1016
+ constructor() {
1017
+ this.transformType = "sort";
1018
+ }
1019
+ apply(e, t) {
1020
+ const { options: r } = t;
1021
+ return e.orderBy(r.variableName, r.direction ?? "asc");
1022
+ }
1023
+ }, Pt = [
1024
+ new It(),
1025
+ new Vt(),
1026
+ new xt(),
1027
+ new Bt(),
1028
+ new jt()
1029
+ ], Ur = class extends Nt {
1030
+ constructor() {
1031
+ super("transform");
1032
+ for (const e of Pt) this.register(e.transformType, e);
1033
+ }
1034
+ }, $r = [
1035
+ "grey",
1036
+ "red",
1037
+ "orange",
1038
+ "yellow",
1039
+ "green",
1040
+ "cyan",
1041
+ "blue",
1042
+ "purple",
1043
+ "pink"
1044
+ ], Yr = [
1045
+ "cyan",
1046
+ "pink",
1047
+ "purple",
1048
+ "red",
1049
+ "orange",
1050
+ "yellow",
1051
+ "green",
1052
+ "blue"
1053
+ ], Oe = [
1054
+ "#B399FE",
1055
+ "#FC7E91",
1056
+ "#33B6E0",
1057
+ "#FFC849",
1058
+ "#25CDA5",
1059
+ "#FA9B65",
1060
+ "#D93C95",
1061
+ "#845FD8",
1062
+ "#3F8EEB",
1063
+ "#58C8D8",
1064
+ "#F35074",
1065
+ "#6EA0DA"
1066
+ ], b = {
1067
+ red: "#E83562",
1068
+ orange: "#F38650",
1069
+ yellow: "#FBBC30",
1070
+ green: "#31FCB4",
1071
+ cyan: "#40F8FF",
1072
+ blue: "#279EFF",
1073
+ purple: "#B399FD",
1074
+ dark_purple: "#6D48D2",
1075
+ plum: "#C82184",
1076
+ pink: "#FC8497"
1077
+ }, zr = [b.purple, b.dark_purple], Ut = [
1078
+ b.purple,
1079
+ b.pink,
1080
+ b.yellow,
1081
+ b.blue,
1082
+ b.red,
1083
+ b.cyan,
1084
+ b.orange,
1085
+ b.plum,
1086
+ b.green,
1087
+ b.dark_purple
1088
+ ], h = {
1089
+ green: "#B2DDC9",
1090
+ cyan: "#A2D5E2",
1091
+ blue: "#AAC4FF",
1092
+ purple: "#B2A4FF",
1093
+ plum: "#DCA8C7",
1094
+ pink: "#FFCCD3",
1095
+ red: "#FFADAD",
1096
+ orange: "#FFDEB4",
1097
+ yellow: "#FDF7C3"
1098
+ }, $t = [
1099
+ h.green,
1100
+ h.purple,
1101
+ h.red,
1102
+ h.cyan,
1103
+ h.pink,
1104
+ h.blue,
1105
+ h.orange,
1106
+ h.plum,
1107
+ h.yellow
1108
+ ], H = {
1109
+ grey900: "#1c1917",
1110
+ grey800: "#292524",
1111
+ grey700: "#44403c",
1112
+ grey600: "#57534e",
1113
+ grey500: "#78716c",
1114
+ grey400: "#a8a29e",
1115
+ grey300: "#d6d3d1",
1116
+ grey200: "#e7e5e4",
1117
+ grey100: "#f5f5f4",
1118
+ grey50: "#fafaf9",
1119
+ red900: "#7f1d1d",
1120
+ red800: "#991b1b",
1121
+ red700: "#b91c1c",
1122
+ red600: "#dc2626",
1123
+ red500: "#ef4444",
1124
+ red400: "#f87171",
1125
+ red300: "#fca5a5",
1126
+ red200: "#fecaca",
1127
+ red100: "#fee2e2",
1128
+ red50: "#fef2f2",
1129
+ orange900: "#7c2d12",
1130
+ orange800: "#9a3412",
1131
+ orange700: "#c2410c",
1132
+ orange600: "#ea580c",
1133
+ orange500: "#f97316",
1134
+ orange400: "#fb923c",
1135
+ orange300: "#fdba74",
1136
+ orange200: "#fed7aa",
1137
+ orange100: "#ffedd5",
1138
+ orange50: "#fff7ed",
1139
+ yellow900: "#553B0C",
1140
+ yellow800: "#6F4B08",
1141
+ yellow700: "#8D6300",
1142
+ yellow600: "#BD8A00",
1143
+ yellow500: "#E5B400",
1144
+ yellow400: "#FFC800",
1145
+ yellow300: "#FBDA2B",
1146
+ yellow200: "#FEED72",
1147
+ yellow100: "#FEF8B4",
1148
+ yellow50: "#FEFCE2",
1149
+ green900: "#064e3b",
1150
+ green800: "#065f46",
1151
+ green700: "#047857",
1152
+ green600: "#059669",
1153
+ green500: "#10b981",
1154
+ green400: "#34d399",
1155
+ green300: "#6ee7b7",
1156
+ green200: "#a7f3d0",
1157
+ green100: "#d1fae5",
1158
+ green50: "#ecfdf5",
1159
+ cyan900: "#164e63",
1160
+ cyan800: "#155e75",
1161
+ cyan700: "#0e7490",
1162
+ cyan600: "#0891B2",
1163
+ cyan500: "#06b6d4",
1164
+ cyan400: "#22d3ee",
1165
+ cyan300: "#67e8f9",
1166
+ cyan200: "#a5f3fc",
1167
+ cyan100: "#cffafe",
1168
+ cyan50: "#ecfeff",
1169
+ blue900: "#1e3a8a",
1170
+ blue800: "#1e40af",
1171
+ blue700: "#1d4ed8",
1172
+ blue600: "#2563eb",
1173
+ blue500: "#3b82f6",
1174
+ blue400: "#60a5fa",
1175
+ blue300: "#93c5fd",
1176
+ blue200: "#bfdbfe",
1177
+ blue100: "#dbeafe",
1178
+ blue50: "#eff6ff",
1179
+ purple900: "#4c1d95",
1180
+ purple800: "#5b21b6",
1181
+ purple700: "#6d28d9",
1182
+ purple600: "#7c3aed",
1183
+ purple500: "#8b5cf6",
1184
+ purple400: "#a78bfa",
1185
+ purple300: "#c4b5fd",
1186
+ purple200: "#ddd6fe",
1187
+ purple100: "#ede9fe",
1188
+ purple50: "#f5f3ff",
1189
+ pink900: "#751A5E",
1190
+ pink800: "#8F1972",
1191
+ pink700: "#AF1C8A",
1192
+ pink600: "#D326A8",
1193
+ pink500: "#E845BF",
1194
+ pink400: "#F979D9",
1195
+ pink300: "#FCABE8",
1196
+ pink200: "#FED0F3",
1197
+ pink100: "#FFE8F9",
1198
+ pink50: "#FFF4FC"
1199
+ }, Yt = [
1200
+ H.grey200,
1201
+ h.green,
1202
+ h.red,
1203
+ H.grey200
1204
+ ], ee = {
1205
+ dark: {
1206
+ 1: [500],
1207
+ 2: [600, 400],
1208
+ 3: [
1209
+ 600,
1210
+ 400,
1211
+ 200
1212
+ ],
1213
+ 4: [
1214
+ 600,
1215
+ 500,
1216
+ 300,
1217
+ 100
1218
+ ],
1219
+ 5: [
1220
+ 700,
1221
+ 600,
1222
+ 400,
1223
+ 200,
1224
+ 50
1225
+ ],
1226
+ 6: [
1227
+ 600,
1228
+ 500,
1229
+ 400,
1230
+ 300,
1231
+ 200,
1232
+ 100
1233
+ ],
1234
+ 7: [
1235
+ 600,
1236
+ 500,
1237
+ 400,
1238
+ 300,
1239
+ 200,
1240
+ 100,
1241
+ 50
1242
+ ],
1243
+ default: [
1244
+ 700,
1245
+ 600,
1246
+ 500,
1247
+ 400,
1248
+ 300,
1249
+ 200,
1250
+ 100,
1251
+ 50
1252
+ ]
1253
+ },
1254
+ light: {
1255
+ 1: [600],
1256
+ 2: [700, 500],
1257
+ 3: [
1258
+ 800,
1259
+ 600,
1260
+ 400
1261
+ ],
1262
+ 4: [
1263
+ 800,
1264
+ 600,
1265
+ 400,
1266
+ 300
1267
+ ],
1268
+ 5: [
1269
+ 800,
1270
+ 700,
1271
+ 600,
1272
+ 500,
1273
+ 400
1274
+ ],
1275
+ 6: [
1276
+ 800,
1277
+ 700,
1278
+ 600,
1279
+ 500,
1280
+ 400,
1281
+ 300
1282
+ ],
1283
+ 7: [
1284
+ 900,
1285
+ 800,
1286
+ 700,
1287
+ 600,
1288
+ 500,
1289
+ 400,
1290
+ 300
1291
+ ],
1292
+ default: [
1293
+ 900,
1294
+ 800,
1295
+ 700,
1296
+ 600,
1297
+ 500,
1298
+ 400,
1299
+ 300,
1300
+ 200
1301
+ ]
1302
+ }
1303
+ }, p = {
1304
+ cyan: "#22D3EE",
1305
+ pink: "#F377EF",
1306
+ purple: "#6528F7",
1307
+ red: "#FB2576",
1308
+ orange: "#FF9300",
1309
+ yellow: "#FBFF00",
1310
+ green: "#06FF00",
1311
+ blue: "#0079FF"
1312
+ }, I = [
1313
+ p.cyan,
1314
+ p.pink,
1315
+ p.purple,
1316
+ p.red,
1317
+ p.orange,
1318
+ p.yellow,
1319
+ p.green,
1320
+ p.blue
1321
+ ], zt = [
1322
+ p.cyan,
1323
+ p.green,
1324
+ p.red,
1325
+ p.cyan
1326
+ ], V = {
1327
+ start: "#84D1FC",
1328
+ positive: "#84FC89",
1329
+ negative: "#FC8497",
1330
+ total: "#84D1FC"
1331
+ }, Wt = [
1332
+ V.start,
1333
+ V.positive,
1334
+ V.negative,
1335
+ V.total
1336
+ ], Wr = {
1337
+ transform: "linear",
1338
+ reverse: !1,
1339
+ nice: !0,
1340
+ zero: !1,
1341
+ domainMin: null,
1342
+ domainMax: null,
1343
+ range: null,
1344
+ scheme: null,
1345
+ interpolate: "lab",
1346
+ domainMid: null,
1347
+ symmetric: !1
1348
+ }, Gr = {
1349
+ size: [4, 20],
1350
+ alpha: [0.1, 1],
1351
+ strokeWidth: [1, 4]
1352
+ }, Kr = {
1353
+ domainMin: null,
1354
+ domainMax: null,
1355
+ nice: !1,
1356
+ reverse: !1
1357
+ }, Hr = {
1358
+ range: null,
1359
+ domain: null,
1360
+ padding: 0.1,
1361
+ reverse: !1
1362
+ }, te = { palette: { type: "default" } };
1363
+ function Gt(e, t = "light", r) {
1364
+ return ((r !== void 0 ? ee[t][r] : void 0) ?? ee[t].default).map((a) => H[`${e}${a}`]);
1365
+ }
1366
+ function Kt(e) {
1367
+ const t = I.indexOf(p[e]);
1368
+ return t <= 0 ? I : [...I.slice(t), ...I.slice(0, t)];
1369
+ }
1370
+ function qr(e, t) {
1371
+ switch (e.type) {
1372
+ case "default":
1373
+ return Oe;
1374
+ case "graphy":
1375
+ return e.variant === "waterfall" ? Wt : Ut;
1376
+ case "pastel":
1377
+ return e.variant === "waterfall" ? Yt : $t;
1378
+ case "neon":
1379
+ return e.variant === "waterfall" ? zt : Kt(e.base);
1380
+ case "mono":
1381
+ return Gt(e.base, e.variant ?? "light", t);
1382
+ case "custom":
1383
+ return e.colors;
1384
+ }
1385
+ }
1386
+ function Xr(e, t) {
1387
+ if (!t) return e;
1388
+ const r = [...e];
1389
+ for (const [a, n] of Object.entries(t)) {
1390
+ const s = Number(a);
1391
+ if (!Number.isInteger(s) || s < 1) continue;
1392
+ const o = s - 1;
1393
+ o < r.length && (r[o] = n);
1394
+ }
1395
+ return r;
1396
+ }
1397
+ function Qr(e, t, r, a) {
1398
+ if (!t) return;
1399
+ const n = r?.type === "custom" ? a[r.id] : void 0, s = {};
1400
+ for (const [o, i] of Object.entries(t)) {
1401
+ const l = Number(o);
1402
+ if (!(!Number.isInteger(l) || l < 1)) {
1403
+ if (i.hex !== void 0) {
1404
+ s[l] = i.hex;
1405
+ continue;
1406
+ }
1407
+ if (i.id !== void 0) {
1408
+ const u = n?.find((d) => d.id === i.id)?.hex;
1409
+ u !== void 0 ? s[l] = u : e.diagnostics.addWarning({
1410
+ code: "PALETTE_NOT_FOUND",
1411
+ message: `Palette override at slot ${l} with id '${i.id}' did not resolve against the active palette — falling back to palette color.`,
1412
+ context: {
1413
+ requested: i.id,
1414
+ available: n?.map((d) => d.id) ?? []
1415
+ },
1416
+ suggestion: "Define the override id in the active custom palette, or use a hex value instead."
1417
+ });
1418
+ }
1419
+ }
1420
+ }
1421
+ return Object.keys(s).length > 0 ? s : void 0;
1422
+ }
1423
+ function Jr(e, t, r) {
1424
+ if (!t) return te.palette;
1425
+ if (t.type === "custom") {
1426
+ const a = r[t.id];
1427
+ if (!a)
1428
+ return e.diagnostics.addWarning({
1429
+ code: "PALETTE_NOT_FOUND",
1430
+ message: `Custom palette with id "${t.id}" not found — falling back to the default palette.`,
1431
+ context: {
1432
+ requested: t.id,
1433
+ available: Object.keys(r)
1434
+ },
1435
+ suggestion: "Register the palette in customPalettes, or reference an existing palette id."
1436
+ }), te.palette;
1437
+ const n = a.map((s) => s.hex);
1438
+ return {
1439
+ type: "custom",
1440
+ id: t.id,
1441
+ colors: n
1442
+ };
1443
+ }
1444
+ return t;
1445
+ }
1446
+ function m(e, t = {}) {
1447
+ const r = t;
1448
+ return {
1449
+ type: "scale",
1450
+ scaledAesthetic: e,
1451
+ scaleType: "continuous",
1452
+ transform: t.transform,
1453
+ reverse: t.reverse,
1454
+ nice: t.nice,
1455
+ zero: t.zero,
1456
+ clamp: t.clamp,
1457
+ domainMin: t.domainMin ?? null,
1458
+ domainMax: t.domainMax ?? null,
1459
+ range: t.range,
1460
+ scheme: r.scheme ?? null,
1461
+ interpolate: r.interpolate,
1462
+ domainMid: r.domainMid ?? null,
1463
+ symmetric: r.symmetric
1464
+ };
1465
+ }
1466
+ function z(e, t = {}) {
1467
+ return {
1468
+ type: "scale",
1469
+ scaledAesthetic: e,
1470
+ scaleType: "datetime",
1471
+ domainMin: t.domainMin ?? null,
1472
+ domainMax: t.domainMax ?? null,
1473
+ nice: t.nice,
1474
+ reverse: t.reverse,
1475
+ clamp: t.clamp
1476
+ };
1477
+ }
1478
+ function _(e, t = {}) {
1479
+ return {
1480
+ type: "scale",
1481
+ scaledAesthetic: e,
1482
+ scaleType: "discrete",
1483
+ range: t.range,
1484
+ domain: t.domain ?? null,
1485
+ padding: t.padding,
1486
+ reverse: t.reverse
1487
+ };
1488
+ }
1489
+ function x(e, t = {}) {
1490
+ return {
1491
+ type: "scale",
1492
+ scaledAesthetic: e,
1493
+ scaleType: "identity"
1494
+ };
1495
+ }
1496
+ function W(e, t) {
1497
+ return {
1498
+ type: "scale",
1499
+ scaledAesthetic: e,
1500
+ scaleType: "inferred",
1501
+ options: t
1502
+ };
1503
+ }
1504
+ function Ht(e, t = {}) {
1505
+ return {
1506
+ type: "scale",
1507
+ scaledAesthetic: e,
1508
+ scaleType: "palette",
1509
+ palette: t.palette,
1510
+ overrides: t.overrides
1511
+ };
1512
+ }
1513
+ var qt = [
1514
+ "none",
1515
+ "xs",
1516
+ "sm",
1517
+ "md",
1518
+ "lg",
1519
+ "xl",
1520
+ "full"
1521
+ ], Zr = {
1522
+ point: Xt,
1523
+ line: Qt,
1524
+ area: Jt,
1525
+ bar: Zt,
1526
+ rule: er
1527
+ }, ea = (e) => typeof e == "string" && qt.includes(e);
1528
+ function L(e, t) {
1529
+ return {
1530
+ type: "layer",
1531
+ id: t.id,
1532
+ geom: e,
1533
+ mapping: t.aes,
1534
+ stat: t.stat,
1535
+ params: t.params,
1536
+ position: t.position,
1537
+ yScaleType: t.yScaleType,
1538
+ transforms: t.transforms,
1539
+ interactive: t.interactive,
1540
+ dataLabels: t.dataLabels
1541
+ };
1542
+ }
1543
+ function Xt(e = {}) {
1544
+ return L("point", e);
1545
+ }
1546
+ function Qt(e = {}) {
1547
+ return L("line", e);
1548
+ }
1549
+ function Jt(e = {}) {
1550
+ return L("area", e);
1551
+ }
1552
+ function Zt(e = {}) {
1553
+ return L("bar", e);
1554
+ }
1555
+ function er(e = {}) {
1556
+ return L("rule", e);
1557
+ }
1558
+ var ta = ["dimmed", "hovered"], ra = (e) => typeof e == "object" && e !== null && typeof e.light == "string" && typeof e.dark == "string", aa = (e) => typeof e == "object" && e !== null && typeof e.token == "string";
1559
+ function na(e) {
1560
+ return {
1561
+ type: "styles",
1562
+ ...e
1563
+ };
1564
+ }
1565
+ function S(e) {
1566
+ return { token: e };
1567
+ }
1568
+ var A = (e) => {
1569
+ const t = {
1570
+ ...e?.where === void 0 ? {} : { where: e.where },
1571
+ ...e?.state === void 0 ? {} : { state: e.state }
1572
+ };
1573
+ return {
1574
+ ...e?.id === void 0 ? {} : { id: e.id },
1575
+ ...Object.keys(t).length === 0 ? {} : { when: t }
1576
+ };
1577
+ }, F = (e) => e?.layer === void 0 ? {} : { layer: e.layer }, E = { geom: Object.assign((e, t) => ({
1578
+ ...A(t),
1579
+ select: {
1580
+ target: "geom",
1581
+ ...F(t)
1582
+ },
1583
+ declarations: e
1584
+ }), {
1585
+ bar: (e, t) => ({
1586
+ ...A(t),
1587
+ select: {
1588
+ target: "geom",
1589
+ kind: "bar",
1590
+ ...F(t)
1591
+ },
1592
+ declarations: e
1593
+ }),
1594
+ line: (e, t) => ({
1595
+ ...A(t),
1596
+ select: {
1597
+ target: "geom",
1598
+ kind: "line",
1599
+ ...F(t)
1600
+ },
1601
+ declarations: e
1602
+ }),
1603
+ area: (e, t) => ({
1604
+ ...A(t),
1605
+ select: {
1606
+ target: "geom",
1607
+ kind: "area",
1608
+ ...F(t)
1609
+ },
1610
+ declarations: e
1611
+ }),
1612
+ point: (e, t) => ({
1613
+ ...A(t),
1614
+ select: {
1615
+ target: "geom",
1616
+ kind: "point",
1617
+ ...F(t)
1618
+ },
1619
+ declarations: e
1620
+ }),
1621
+ rule: (e, t) => ({
1622
+ ...A(t),
1623
+ select: {
1624
+ target: "geom",
1625
+ kind: "rule",
1626
+ ...F(t)
1627
+ },
1628
+ declarations: e
1629
+ })
1630
+ }) }, tr = Oe[0], rr = Object.freeze({
1631
+ light: "#1D2129",
1632
+ dark: "#FFFFFF"
1633
+ }), ar = "#ffffff", nr = 0.4, sr = {
1634
+ geomColor: tr,
1635
+ ruleColor: rr,
1636
+ pointBorderColor: "#ffffff",
1637
+ hoverAffordanceColor: ar
1638
+ }, ke = [
1639
+ E.geom({
1640
+ color: S("geomColor"),
1641
+ alpha: 1
1642
+ }),
1643
+ E.geom.bar({
1644
+ borderRadius: "sm",
1645
+ borderWidth: 1
1646
+ }),
1647
+ E.geom.line({
1648
+ strokeWidth: 2,
1649
+ lineType: "solid"
1650
+ }),
1651
+ E.geom.area({
1652
+ alpha: 0.3,
1653
+ strokeWidth: 2,
1654
+ lineType: "solid",
1655
+ strokeAlpha: 1
1656
+ }),
1657
+ E.geom.point({
1658
+ size: 8,
1659
+ borderColor: S("pointBorderColor"),
1660
+ borderWidth: 1
1661
+ }),
1662
+ E.geom.rule({
1663
+ color: S("ruleColor"),
1664
+ strokeWidth: 1,
1665
+ lineType: "dashed"
1666
+ }),
1667
+ E.geom({ alpha: nr }, { state: "dimmed" }),
1668
+ E.geom.point({ borderColor: S("hoverAffordanceColor") }, { state: "hovered" }),
1669
+ E.geom.bar({ borderColor: S("hoverAffordanceColor") }, { state: "hovered" })
1670
+ ];
1671
+ for (const e of ke) {
1672
+ Object.freeze(e.select);
1673
+ for (const t of Object.values(e.declarations)) typeof t == "object" && Object.freeze(t);
1674
+ Object.freeze(e.declarations), e.when !== void 0 && Object.freeze(e.when), Object.freeze(e);
1675
+ }
1676
+ var sa = Object.freeze({
1677
+ tokens: Object.freeze(sr),
1678
+ defaults: Object.freeze(ke),
1679
+ overrides: Object.freeze([])
1680
+ }), oa = {
1681
+ cartesian: (e = {}) => ({
1682
+ type: "coord",
1683
+ coordType: "cartesian",
1684
+ params: e
1685
+ }),
1686
+ flip: (e = {}) => ({
1687
+ type: "coord",
1688
+ coordType: "flip",
1689
+ params: e
1690
+ }),
1691
+ polar: (e = {}) => ({
1692
+ type: "coord",
1693
+ coordType: "polar",
1694
+ params: e
1695
+ })
1696
+ }, ia = {
1697
+ x: Object.assign((e) => W("x", e), {
1698
+ continuous: (e) => m("x", e),
1699
+ discrete: (e) => _("x", e),
1700
+ datetime: (e) => z("x", e),
1701
+ log: (e) => m("x", {
1702
+ ...e,
1703
+ transform: "log"
1704
+ }),
1705
+ sqrt: (e) => m("x", {
1706
+ ...e,
1707
+ transform: "sqrt"
1708
+ })
1709
+ }),
1710
+ y: Object.assign((e) => W("y", e), {
1711
+ continuous: (e) => m("y", e),
1712
+ discrete: (e) => _("y", e),
1713
+ datetime: (e) => z("y", e),
1714
+ log: (e) => m("y", {
1715
+ ...e,
1716
+ transform: "log"
1717
+ }),
1718
+ sqrt: (e) => m("y", {
1719
+ ...e,
1720
+ transform: "sqrt"
1721
+ })
1722
+ }),
1723
+ ySecondary: Object.assign((e) => W("ySecondary", e), {
1724
+ continuous: (e) => m("ySecondary", e),
1725
+ discrete: (e) => _("ySecondary", e),
1726
+ datetime: (e) => z("ySecondary", e),
1727
+ log: (e) => m("ySecondary", {
1728
+ ...e,
1729
+ transform: "log"
1730
+ }),
1731
+ sqrt: (e) => m("ySecondary", {
1732
+ ...e,
1733
+ transform: "sqrt"
1734
+ })
1735
+ }),
1736
+ color: {
1737
+ continuous: (e) => m("color", e),
1738
+ discrete: (e) => _("color", e),
1739
+ palette: (e) => Ht("color", e)
1740
+ },
1741
+ size: {
1742
+ continuous: (e) => m("size", e),
1743
+ discrete: (e) => _("size", e),
1744
+ identity: (e) => x("size", e)
1745
+ },
1746
+ alpha: {
1747
+ continuous: (e) => m("alpha", e),
1748
+ discrete: (e) => _("alpha", e),
1749
+ identity: (e) => x("alpha", e)
1750
+ },
1751
+ strokeWidth: {
1752
+ continuous: (e) => m("strokeWidth", e),
1753
+ discrete: (e) => _("strokeWidth", e),
1754
+ identity: (e) => x("strokeWidth", e)
1755
+ },
1756
+ lineType: {
1757
+ discrete: (e) => _("lineType", e),
1758
+ identity: (e) => x("lineType", e)
1759
+ }
1760
+ }, la = {
1761
+ identity: ir,
1762
+ count: lr,
1763
+ smooth: or,
1764
+ mean: ur
1765
+ };
1766
+ function or(e) {
1767
+ return {
1768
+ type: "smooth",
1769
+ method: e.method,
1770
+ order: e.order,
1771
+ bandwidth: e.bandwidth
1772
+ };
1773
+ }
1774
+ function ir() {
1775
+ return { type: "identity" };
1776
+ }
1777
+ function lr() {
1778
+ return { type: "count" };
1779
+ }
1780
+ function ur() {
1781
+ return { type: "mean" };
1782
+ }
1783
+ var ua = {
1784
+ reshape: cr,
1785
+ filter: dr,
1786
+ sort: yr,
1787
+ aggregate: fr,
1788
+ constant: mr
1789
+ };
1790
+ function cr(e = {}) {
1791
+ return {
1792
+ type: "transform",
1793
+ transformType: "reshape",
1794
+ options: e
1795
+ };
1796
+ }
1797
+ function dr(e) {
1798
+ return {
1799
+ type: "transform",
1800
+ transformType: "filter",
1801
+ options: e
1802
+ };
1803
+ }
1804
+ function yr(e) {
1805
+ return {
1806
+ type: "transform",
1807
+ transformType: "sort",
1808
+ options: e
1809
+ };
1810
+ }
1811
+ function fr(e) {
1812
+ return {
1813
+ type: "transform",
1814
+ transformType: "aggregate",
1815
+ options: e
1816
+ };
1817
+ }
1818
+ function mr(e) {
1819
+ return {
1820
+ type: "transform",
1821
+ transformType: "constant",
1822
+ options: e
1823
+ };
1824
+ }
1825
+ function pr(e) {
1826
+ const t = e.layout?.gaps;
1827
+ if (t === void 0) return e;
1828
+ const r = {};
1829
+ for (const a of Object.keys(t)) {
1830
+ const n = t[a];
1831
+ n !== void 0 && (r[a] = typeof n == "number" ? { after: n } : n);
1832
+ }
1833
+ return {
1834
+ ...e,
1835
+ layout: {
1836
+ ...e.layout,
1837
+ gaps: r
1838
+ }
1839
+ };
1840
+ }
1841
+ var ca = [
1842
+ "lilac",
1843
+ "neon_pink",
1844
+ "blackberry",
1845
+ "sun",
1846
+ "iceland",
1847
+ "sunset",
1848
+ "ultraviolet",
1849
+ "purple",
1850
+ "ice_cream",
1851
+ "mint",
1852
+ "cool",
1853
+ "fresh"
1854
+ ];
1855
+ function da(e) {
1856
+ return {
1857
+ type: "config",
1858
+ config: pr(e)
1859
+ };
1860
+ }
1861
+ export {
1862
+ qe as $,
1863
+ qr as A,
1864
+ Ar as At,
1865
+ Pr as B,
1866
+ x as C,
1867
+ je as Ct,
1868
+ Xr as D,
1869
+ se as Dt,
1870
+ m as E,
1871
+ Ue as Et,
1872
+ Oe as F,
1873
+ Mr as Ft,
1874
+ jr as G,
1875
+ Nt as H,
1876
+ zr as I,
1877
+ Xe as J,
1878
+ et as K,
1879
+ $r as L,
1880
+ Kr as M,
1881
+ _r as Mt,
1882
+ Hr as N,
1883
+ ae as Nt,
1884
+ Jr as O,
1885
+ $e as Ot,
1886
+ Gr as P,
1887
+ vr as Pt,
1888
+ ue as Q,
1889
+ Yr as R,
1890
+ W as S,
1891
+ Be as St,
1892
+ z as T,
1893
+ Ye as Tt,
1894
+ K as U,
1895
+ Ot as V,
1896
+ bt as W,
1897
+ Vr as X,
1898
+ He as Y,
1899
+ xr as Z,
1900
+ qt as _,
1901
+ G as _t,
1902
+ ia as a,
1903
+ Ke as at,
1904
+ ea as b,
1905
+ Dr as bt,
1906
+ nr as c,
1907
+ Cr as ct,
1908
+ ta as d,
1909
+ D as dt,
1910
+ P as et,
1911
+ ra as f,
1912
+ kr as ft,
1913
+ S as g,
1914
+ We as gt,
1915
+ na as h,
1916
+ Sr as ht,
1917
+ la as i,
1918
+ le as it,
1919
+ Wr as j,
1920
+ c as jt,
1921
+ Qr as k,
1922
+ Tr as kt,
1923
+ tr as l,
1924
+ Rr as lt,
1925
+ E as m,
1926
+ Or as mt,
1927
+ da as n,
1928
+ v as nt,
1929
+ oa as o,
1930
+ Ge as ot,
1931
+ aa as p,
1932
+ oe as pt,
1933
+ be as q,
1934
+ ua as r,
1935
+ B as rt,
1936
+ sa as s,
1937
+ Lr as st,
1938
+ ca as t,
1939
+ Br as tt,
1940
+ ar as u,
1941
+ Ir as ut,
1942
+ L as v,
1943
+ wr as vt,
1944
+ _ as w,
1945
+ Pe as wt,
1946
+ Ht as x,
1947
+ Fr as xt,
1948
+ Zr as y,
1949
+ Nr as yt,
1950
+ Ur as z
1951
+ };