phoria2 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +9 -6
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +436 -436
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +1240 -862
  7. package/dist/core.js.map +1 -1
  8. package/dist/debug.js +297 -0
  9. package/dist/debug.js.map +1 -0
  10. package/dist/edit.js +40 -40
  11. package/dist/edit.js.map +1 -1
  12. package/dist/explain.js +32 -13
  13. package/dist/explain.js.map +1 -1
  14. package/dist/gltf.js +128 -128
  15. package/dist/gltf.js.map +1 -1
  16. package/dist/keyboard.js +19 -19
  17. package/dist/keyboard.js.map +1 -1
  18. package/dist/motion.js +35 -35
  19. package/dist/motion.js.map +1 -1
  20. package/dist/particles.js +36 -36
  21. package/dist/particles.js.map +1 -1
  22. package/dist/passes.js +116 -104
  23. package/dist/passes.js.map +1 -1
  24. package/dist/phoria2.js +1 -1
  25. package/dist/picking.js +90 -71
  26. package/dist/picking.js.map +1 -1
  27. package/dist/snapshot.js +1 -1
  28. package/dist/tooltip.js +1 -1
  29. package/dist/types/View.d.ts +16 -0
  30. package/dist/types/debug.d.ts +74 -0
  31. package/dist/types/explain.d.ts +4 -0
  32. package/dist/types/frame.d.ts +5 -0
  33. package/dist/types/material/Material.d.ts +52 -0
  34. package/dist/types/watch.d.ts +8 -1
  35. package/dist/types/webgl/hooks.d.ts +48 -0
  36. package/dist/types/webgl/passes.d.ts +4 -0
  37. package/dist/types/webgl/programs.d.ts +15 -5
  38. package/dist/types/webgl/shaders.d.ts +36 -5
  39. package/llms-full.txt +227 -0
  40. package/llms.txt +1 -1
  41. package/package.json +1 -1
  42. package/schema/scene.schema.json +27 -0
  43. package/src/View.js +105 -7
  44. package/src/debug.js +283 -0
  45. package/src/explain.js +19 -0
  46. package/src/frame.js +7 -2
  47. package/src/material/Material.js +121 -2
  48. package/src/scene/drawables.js +21 -4
  49. package/src/watch.js +18 -2
  50. package/src/webgl/WebGLRenderer.js +19 -2
  51. package/src/webgl/hooks.js +121 -0
  52. package/src/webgl/passes.js +17 -2
  53. package/src/webgl/picking.js +23 -2
  54. package/src/webgl/programs.js +20 -9
  55. package/src/webgl/resources.js +1 -1
  56. package/src/webgl/shaders.js +443 -35
package/dist/charts.js CHANGED
@@ -1,163 +1,163 @@
1
- import { $ as e, At as t, Et as n, It as r, Q as i, V as a, Z as o, et as s, it as c, jt as l, kt as u, l as d, lt as f, m as p, n as m, rt as h, st as g, tt as _, vt as v } from "./core.js";
1
+ import { At as e, Bt as t, Ft as n, Nt as r, Pt as i, St as a, W as o, at as s, ct as c, dt as l, it as u, l as d, m as f, n as p, nt as m, pt as h, rt as g, st as _, tt as v } from "./core.js";
2
2
  // src/charts/axes.js
3
3
  var y = .97, b = .08, x = /* @__PURE__ */ new Float32Array(16);
4
- function S(e, t, n) {
5
- let i = t.worldPosition;
6
- r(x, e.worldMatrix);
7
- let a = x[0] * i[0] + x[4] * i[1] + x[8] * i[2] + x[12], o = x[1] * i[0] + x[5] * i[1] + x[9] * i[2] + x[13] - n, s = x[2] * i[0] + x[6] * i[1] + x[10] * i[2] + x[14], c = Math.hypot(a, o, s) || 1;
4
+ function S(e, n, r) {
5
+ let i = n.worldPosition;
6
+ t(x, e.worldMatrix);
7
+ let a = x[0] * i[0] + x[4] * i[1] + x[8] * i[2] + x[12], o = x[1] * i[0] + x[5] * i[1] + x[9] * i[2] + x[13] - r, s = x[2] * i[0] + x[6] * i[1] + x[10] * i[2] + x[14], c = Math.hypot(a, o, s) || 1;
8
8
  return [
9
9
  a / c,
10
10
  o / c,
11
11
  s / c
12
12
  ];
13
13
  }
14
- function C({ box: t, axes: n, theme: r, overlap: a }) {
15
- let [o, s, c] = t, l = new h({
14
+ function C({ box: e, axes: t, theme: n, overlap: r }) {
15
+ let [i, a, o] = e, s = new _({
16
16
  name: "axes",
17
17
  pickable: !1
18
- }), u = (e) => S(l, e, s / 2), d = r === "light" ? "#c3c8d2" : "#3a3d47", p = (e) => {
18
+ }), c = (e) => S(s, e, a / 2), l = n === "light" ? "#c3c8d2" : "#3a3d47", u = (e) => {
19
19
  let t = e.channel?.axis?.ticks;
20
20
  if (!Array.isArray(t)) return e.scale.kind === "band" ? e.scale.ticks() : e.scale.ticks(t ?? 5);
21
21
  let [n, r] = e.scale.range, i = Math.min(n, r), a = Math.max(n, r);
22
22
  return t.filter((t) => e.scale(t) >= i - 1e-9 && e.scale(t) <= a + 1e-9);
23
- }, m = (e) => e && e.scale.kind !== "band" && e.channel?.axis !== !1 ? p(e) : [], g = m(n.x), _ = m(n.y), v = m(n.z), x = (t, r) => {
24
- let i = [], a = (e, t) => i.push(...e, ...t), p = (e) => r < 0 ? -e / 2 : e / 2;
25
- if (t === "y") {
26
- let e = r < 0 ? 0 : s;
27
- for (let t of g) {
28
- let r = n.x.scale(t);
29
- a([
23
+ }, d = (e) => e && e.scale.kind !== "band" && e.channel?.axis !== !1 ? u(e) : [], f = d(t.x), p = d(t.y), v = d(t.z), x = (e, n) => {
24
+ let r = [], u = (e, t) => r.push(...e, ...t), d = (e) => n < 0 ? -e / 2 : e / 2;
25
+ if (e === "y") {
26
+ let e = n < 0 ? 0 : a;
27
+ for (let n of f) {
28
+ let r = t.x.scale(n);
29
+ u([
30
30
  r,
31
31
  e,
32
- -c / 2
32
+ -o / 2
33
33
  ], [
34
34
  r,
35
35
  e,
36
- c / 2
36
+ o / 2
37
37
  ]);
38
38
  }
39
- for (let t of v) {
40
- let r = n.z.scale(t);
41
- a([
42
- -o / 2,
39
+ for (let n of v) {
40
+ let r = t.z.scale(n);
41
+ u([
42
+ -i / 2,
43
43
  e,
44
44
  r
45
45
  ], [
46
- o / 2,
46
+ i / 2,
47
47
  e,
48
48
  r
49
49
  ]);
50
50
  }
51
- w(a, [
52
- -o / 2,
51
+ w(u, [
52
+ -i / 2,
53
53
  e,
54
- -c / 2
54
+ -o / 2
55
55
  ], [
56
- o / 2,
56
+ i / 2,
57
57
  e,
58
- -c / 2
58
+ -o / 2
59
59
  ], [
60
- o / 2,
60
+ i / 2,
61
61
  e,
62
- c / 2
62
+ o / 2
63
63
  ], [
64
- -o / 2,
64
+ -i / 2,
65
65
  e,
66
- c / 2
66
+ o / 2
67
67
  ]);
68
- } else if (t === "x") {
69
- let e = p(o);
70
- for (let t of _) {
71
- let r = n.y.scale(t);
72
- a([
68
+ } else if (e === "x") {
69
+ let e = d(i);
70
+ for (let n of p) {
71
+ let r = t.y.scale(n);
72
+ u([
73
73
  e,
74
74
  r,
75
- -c / 2
75
+ -o / 2
76
76
  ], [
77
77
  e,
78
78
  r,
79
- c / 2
79
+ o / 2
80
80
  ]);
81
81
  }
82
- for (let t of v) {
83
- let r = n.z.scale(t);
84
- a([
82
+ for (let n of v) {
83
+ let r = t.z.scale(n);
84
+ u([
85
85
  e,
86
86
  0,
87
87
  r
88
88
  ], [
89
89
  e,
90
- s,
90
+ a,
91
91
  r
92
92
  ]);
93
93
  }
94
- w(a, [
94
+ w(u, [
95
95
  e,
96
96
  0,
97
- -c / 2
97
+ -o / 2
98
98
  ], [
99
99
  e,
100
- s,
101
- -c / 2
100
+ a,
101
+ -o / 2
102
102
  ], [
103
103
  e,
104
- s,
105
- c / 2
104
+ a,
105
+ o / 2
106
106
  ], [
107
107
  e,
108
108
  0,
109
- c / 2
109
+ o / 2
110
110
  ]);
111
111
  } else {
112
- let e = p(c);
113
- for (let t of _) {
114
- let r = n.y.scale(t);
115
- a([
116
- -o / 2,
112
+ let e = d(o);
113
+ for (let n of p) {
114
+ let r = t.y.scale(n);
115
+ u([
116
+ -i / 2,
117
117
  r,
118
118
  e
119
119
  ], [
120
- o / 2,
120
+ i / 2,
121
121
  r,
122
122
  e
123
123
  ]);
124
124
  }
125
- for (let t of g) {
126
- let r = n.x.scale(t);
127
- a([
125
+ for (let n of f) {
126
+ let r = t.x.scale(n);
127
+ u([
128
128
  r,
129
129
  0,
130
130
  e
131
131
  ], [
132
132
  r,
133
- s,
133
+ a,
134
134
  e
135
135
  ]);
136
136
  }
137
- w(a, [
138
- -o / 2,
137
+ w(u, [
138
+ -i / 2,
139
139
  0,
140
140
  e
141
141
  ], [
142
- o / 2,
142
+ i / 2,
143
143
  0,
144
144
  e
145
145
  ], [
146
- o / 2,
147
- s,
146
+ i / 2,
147
+ a,
148
148
  e
149
149
  ], [
150
- -o / 2,
151
- s,
150
+ -i / 2,
151
+ a,
152
152
  e
153
153
  ]);
154
154
  }
155
- let m = "xyz".indexOf(t);
156
- l.add(new e({
157
- geometry: new f({ positions: i }),
158
- material: { color: d },
155
+ let m = "xyz".indexOf(e);
156
+ s.add(new g({
157
+ geometry: new h({ positions: r }),
158
+ material: { color: l },
159
159
  pickable: !1,
160
- showFrom: (e) => -r * u(e)[m] > b
160
+ showFrom: (e) => -n * c(e)[m] > b
161
161
  }));
162
162
  };
163
163
  for (let e of [
@@ -165,70 +165,70 @@ function C({ box: t, axes: n, theme: r, overlap: a }) {
165
165
  "y",
166
166
  "z"
167
167
  ]) for (let t of [-1, 1]) x(e, t);
168
- let C = Math.max(o, s, c) * .04, T = (e) => `phoria-axis-${e} phoria-${r}`, E = (e, t, r) => {
169
- let o = n[e];
170
- if (!o || o.channel?.axis === !1) return;
171
- let s = "xyz".indexOf(e), c = p(o);
172
- for (let e of t) {
173
- let t = l.add(new h({ showFrom: (t) => {
174
- let n = u(t);
175
- return Math.abs(n[s]) < y && e.when(n);
168
+ let C = Math.max(i, a, o) * .04, T = (e) => `phoria-axis-${e} phoria-${n}`, E = (e, n, i) => {
169
+ let a = t[e];
170
+ if (!a || a.channel?.axis === !1) return;
171
+ let o = "xyz".indexOf(e), l = u(a);
172
+ for (let e of n) {
173
+ let t = s.add(new _({ showFrom: (t) => {
174
+ let n = c(t);
175
+ return Math.abs(n[o]) < y && e.when(n);
176
176
  } }));
177
- for (let n of c) t.add(new i({
178
- text: o.scale.format(n),
179
- position: e.at(o.scale(n), C),
180
- place: r,
177
+ for (let n of l) t.add(new m({
178
+ text: a.scale.format(n),
179
+ position: e.at(a.scale(n), C),
180
+ place: i,
181
181
  className: T("tick"),
182
182
  priority: 1,
183
- overlap: a
183
+ overlap: r
184
184
  }));
185
- o.title && t.add(new i({
186
- text: o.title,
185
+ a.title && t.add(new m({
186
+ text: a.title,
187
187
  position: e.title(C),
188
- place: r,
188
+ place: i,
189
189
  className: T("title"),
190
190
  priority: 2,
191
- overlap: a
191
+ overlap: r
192
192
  }));
193
193
  }
194
194
  }, D = (e) => e[1] >= -.08, O = (e) => e >= -.1 ? 1 : -1;
195
- return E("x", [-1, 1].flatMap((e) => [0, s].map((t) => ({
195
+ return E("x", [-1, 1].flatMap((e) => [0, a].map((t) => ({
196
196
  when: (n) => t === 0 === D(n) && O(n[2]) === e,
197
197
  at: (n, r) => [
198
198
  n,
199
199
  t,
200
- e * (c / 2 + r)
200
+ e * (o / 2 + r)
201
201
  ],
202
202
  title: (n) => [
203
203
  0,
204
204
  t,
205
- e * (c / 2 + n * 3.5)
205
+ e * (o / 2 + n * 3.5)
206
206
  ]
207
- }))), "below"), E("z", [-1, 1].flatMap((e) => [0, s].map((t) => ({
207
+ }))), "below"), E("z", [-1, 1].flatMap((e) => [0, a].map((t) => ({
208
208
  when: (n) => t === 0 === D(n) && O(n[0]) === e,
209
209
  at: (n, r) => [
210
- e * (o / 2 + r),
210
+ e * (i / 2 + r),
211
211
  t,
212
212
  n
213
213
  ],
214
214
  title: (n) => [
215
- e * (o / 2 + n * 4),
215
+ e * (i / 2 + n * 4),
216
216
  t,
217
217
  0
218
218
  ]
219
219
  }))), "below"), E("y", [-1, 1].flatMap((e) => [-1, 1].map((t) => ({
220
220
  when: (n) => O(n[0]) === -e && O(n[2]) === t,
221
221
  at: (n, r) => [
222
- e * (o / 2 + r),
222
+ e * (i / 2 + r),
223
223
  n,
224
- t * c / 2
224
+ t * o / 2
225
225
  ],
226
226
  title: (n) => [
227
- e * (o / 2 + n),
228
- s + n * 2,
229
- t * c / 2
227
+ e * (i / 2 + n),
228
+ a + n * 2,
229
+ t * o / 2
230
230
  ]
231
- }))), "left"), l;
231
+ }))), "left"), s;
232
232
  }
233
233
  function w(e, t, n, r, i) {
234
234
  e(t, n), e(n, r), e(r, i), e(i, t);
@@ -239,13 +239,13 @@ function E(e, t) {
239
239
  let n = e / Math.max(1, t), r = 10 ** Math.floor(Math.log(n) / T), i = n / r;
240
240
  return r * (i >= 7.07 ? 10 : i >= 3.16 ? 5 : i >= 1.41 ? 2 : 1);
241
241
  }
242
- function D(e, t, n = !1) {
242
+ function D(e, t, i = !1) {
243
243
  if (typeof e == "function") return e;
244
244
  if (e && typeof e == "object") {
245
- let t = n ? new Intl.DateTimeFormat(void 0, e) : new Intl.NumberFormat(void 0, e);
245
+ let t = i ? new Intl.DateTimeFormat(void 0, e) : new Intl.NumberFormat(void 0, e);
246
246
  return (e) => t.format(e);
247
247
  }
248
- return e !== void 0 && l("charts", `'format' must be Intl format options or a function, got ${u(e)}`), t;
248
+ return e !== void 0 && n("charts", `'format' must be Intl format options or a function, got ${r(e)}`), t;
249
249
  }
250
250
  function O(e, t) {
251
251
  let n = Math.max(0, Math.min(6, -Math.floor(Math.log(e || 1) / T))), r = new Intl.NumberFormat(void 0, { maximumFractionDigits: n }), i = new Intl.NumberFormat(void 0, {
@@ -255,7 +255,7 @@ function O(e, t) {
255
255
  return (e) => (a ? i : r).format(e);
256
256
  }
257
257
  function k(e, t) {
258
- return Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number" && Number.isFinite(e)) || l("charts", `'${t}' must be [min, max] numbers, got ${u(e)}`), [e[0], e[1]];
258
+ return Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number" && Number.isFinite(e)) || n("charts", `'${t}' must be [min, max] numbers, got ${r(e)}`), [e[0], e[1]];
259
259
  }
260
260
  function A({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i = !1, format: a }) {
261
261
  let [o, s] = k(e, "domain"), [c, l] = k(t, "range");
@@ -273,28 +273,28 @@ function A({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i
273
273
  return n;
274
274
  }, d.format = D(a, O(E(s - o, 5), Math.max(Math.abs(o), Math.abs(s)))), d;
275
275
  }
276
- function j({ domain: e, range: t = [0, 1], format: n }) {
277
- let [r, i] = k(e, "domain");
278
- (r <= 0 || i <= 0) && l("charts", `a log scale needs a domain above 0, got [${r}, ${i}] - use a linear scale for zero or negative values`);
279
- let a = A({
280
- domain: [Math.log10(r), Math.log10(i)],
276
+ function j({ domain: e, range: t = [0, 1], format: r }) {
277
+ let [i, a] = k(e, "domain");
278
+ (i <= 0 || a <= 0) && n("charts", `a log scale needs a domain above 0, got [${i}, ${a}] - use a linear scale for zero or negative values`);
279
+ let o = A({
280
+ domain: [Math.log10(i), Math.log10(a)],
281
281
  range: t
282
- }), o = ((e) => a(Math.log10(e)));
283
- return o.kind = "log", o.domain = [r, i], o.range = a.range, o.invert = (e) => 10 ** a.invert?.(e), o.ticks = () => {
282
+ }), s = ((e) => o(Math.log10(e)));
283
+ return s.kind = "log", s.domain = [i, a], s.range = o.range, s.invert = (e) => 10 ** o.invert?.(e), s.ticks = () => {
284
284
  let e = [];
285
- for (let t = Math.floor(Math.log10(r)); t <= Math.ceil(Math.log10(i)); t++) for (let n of [
285
+ for (let t = Math.floor(Math.log10(i)); t <= Math.ceil(Math.log10(a)); t++) for (let n of [
286
286
  1,
287
287
  2,
288
288
  5
289
289
  ]) {
290
- let a = n * 10 ** t;
291
- a >= r * .999 && a <= i * 1.001 && e.push(a);
290
+ let r = n * 10 ** t;
291
+ r >= i * .999 && r <= a * 1.001 && e.push(r);
292
292
  }
293
293
  return e;
294
- }, o.format = D(n, (e) => new Intl.NumberFormat(void 0, {
294
+ }, s.format = D(r, (e) => new Intl.NumberFormat(void 0, {
295
295
  notation: "compact",
296
296
  maximumFractionDigits: 1
297
- }).format(e)), o;
297
+ }).format(e)), s;
298
298
  }
299
299
  var M = 1e3, N = 60 * M, P = 60 * N, F = 24 * P, I = [
300
300
  [M, "s"],
@@ -390,7 +390,7 @@ var M = 1e3, N = 60 * M, P = 60 * N, F = 24 * P, I = [
390
390
  };
391
391
  function L(e) {
392
392
  let t = e instanceof Date ? e : new Date(e);
393
- return Number.isNaN(t.getTime()) && l("charts", `${u(e)} isn't a date - use Date objects, timestamps or ISO strings like '2026-10-25'`), t;
393
+ return Number.isNaN(t.getTime()) && n("charts", `${r(e)} isn't a date - use Date objects, timestamps or ISO strings like '2026-10-25'`), t;
394
394
  }
395
395
  function ne({ domain: e, range: t = [0, 1], format: n }) {
396
396
  let r = L(e[0]).getTime(), i = L(e[1]).getTime(), a = A({
@@ -419,13 +419,13 @@ function ne({ domain: e, range: t = [0, 1], format: n }) {
419
419
  let l = new Intl.DateTimeFormat(void 0, te[s(6)[1]]);
420
420
  return c.format = D(n, (e) => l.format(L(e)), !0), c;
421
421
  }
422
- function re({ domain: e, range: t = [0, 1], padding: n = .2, format: r }) {
423
- Array.isArray(e) || l("charts", `a band scale's domain is a list of categories, got ${u(e)}`);
424
- let [i, a] = k(t, "range"), o = new Map(e.map((e, t) => [String(e), t])), s = (a - i) / Math.max(1, e.length), c = ((e) => {
425
- let t = o.get(String(e));
426
- return t === void 0 ? NaN : i + s * (t + .5);
422
+ function re({ domain: e, range: t = [0, 1], padding: i = .2, format: a }) {
423
+ Array.isArray(e) || n("charts", `a band scale's domain is a list of categories, got ${r(e)}`);
424
+ let [o, s] = k(t, "range"), c = new Map(e.map((e, t) => [String(e), t])), l = (s - o) / Math.max(1, e.length), u = ((e) => {
425
+ let t = c.get(String(e));
426
+ return t === void 0 ? NaN : o + l * (t + .5);
427
427
  });
428
- return c.kind = "band", c.domain = e, c.range = [i, a], c.step = s, c.bandwidth = Math.abs(s) * (1 - n), c.ticks = () => e, c.format = D(r, (e) => String(e)), c;
428
+ return u.kind = "band", u.domain = e, u.range = [o, s], u.step = l, u.bandwidth = Math.abs(l) * (1 - i), u.ticks = () => e, u.format = D(a, (e) => String(e)), u;
429
429
  }
430
430
  var R = {
431
431
  category: [
@@ -476,31 +476,31 @@ var R = {
476
476
  "#2166ac"
477
477
  ]
478
478
  };
479
- function z({ domain: e, scheme: t, range: n, kind: r }) {
480
- t !== void 0 && !(t in R) && l("charts", `colour scheme '${t}' isn't one we have - use ${Object.keys(R).map((e) => `'${e}'`).join(", ")}, or a range of colours`);
481
- let i = r ? r === "sequential" : e.length === 2 && e.every((e) => typeof e == "number");
482
- i && (e.length < 2 || e.some((e) => typeof e != "number")) && l("charts", `a sequential colour scale needs two or more numbers in its domain, got ${u(e)}`);
483
- let a = (n ?? R[t ?? (i ? "viridis" : "category")]).map((e) => v.fromInput(e, "charts")), o;
484
- if (i) {
479
+ function z({ domain: e, scheme: t, range: i, kind: o }) {
480
+ t !== void 0 && !(t in R) && n("charts", `colour scheme '${t}' isn't one we have - use ${Object.keys(R).map((e) => `'${e}'`).join(", ")}, or a range of colours`);
481
+ let s = o ? o === "sequential" : e.length === 2 && e.every((e) => typeof e == "number");
482
+ s && (e.length < 2 || e.some((e) => typeof e != "number")) && n("charts", `a sequential colour scale needs two or more numbers in its domain, got ${r(e)}`);
483
+ let c = (i ?? R[t ?? (s ? "viridis" : "category")]).map((e) => a.fromInput(e, "charts")), l;
484
+ if (s) {
485
485
  let t = (t) => {
486
486
  let n = e.length - 1, r = 0;
487
487
  for (; r < n - 1 && t > e[r + 1];) r++;
488
488
  let i = (t - e[r]) / (e[r + 1] - e[r] || 1);
489
489
  return Math.min(1, Math.max(0, (r + i) / n));
490
490
  };
491
- o = ((e) => {
492
- if (a.length < 2) return a[0].clone();
493
- let n = t(e) * (a.length - 1), r = Math.min(a.length - 2, Math.floor(n));
494
- return a[r].clone().lerp(a[r + 1], n - r);
495
- }), o.kind = "sequential", o.colors = () => [];
491
+ l = ((e) => {
492
+ if (c.length < 2) return c[0].clone();
493
+ let n = t(e) * (c.length - 1), r = Math.min(c.length - 2, Math.floor(n));
494
+ return c[r].clone().lerp(c[r + 1], n - r);
495
+ }), l.kind = "sequential", l.colors = () => [];
496
496
  } else {
497
497
  let t = new Map(e.map((e, t) => [String(e), t]));
498
- o = ((e) => a[(t.get(String(e)) ?? 0) % a.length].clone()), o.kind = "categorical", o.colors = () => e.map((e) => ({
498
+ l = ((e) => c[(t.get(String(e)) ?? 0) % c.length].clone()), l.kind = "categorical", l.colors = () => e.map((e) => ({
499
499
  value: e,
500
- color: o(e)
500
+ color: l(e)
501
501
  }));
502
502
  }
503
- return o.domain = e, o.range = a.map((e) => e.getStyle()), o;
503
+ return l.domain = e, l.range = c.map((e) => e.getStyle()), l;
504
504
  }
505
505
  function B(e) {
506
506
  let t = [...new Map(e.map((e) => [e instanceof Date ? e.getTime() : e, e])).values()];
@@ -624,7 +624,7 @@ function oe(e) {
624
624
  return n;
625
625
  }
626
626
  function se(e, t) {
627
- let n = new o({
627
+ let n = new v({
628
628
  geometry: d(1),
629
629
  material: { roughness: .55 },
630
630
  count: e,
@@ -640,15 +640,15 @@ function le(e) {
640
640
  let t = !!e.spec.channels.size?.field, n = Math.min(...e.box) / 40, r = e.spec.channels.opacity?.value, i = {
641
641
  roughness: .4,
642
642
  ...r === void 0 ? {} : { opacity: r }
643
- }, a = t ? new o({
644
- geometry: p({
643
+ }, a = t ? new v({
644
+ geometry: f({
645
645
  radius: 1,
646
646
  detail: 1
647
647
  }),
648
648
  material: i,
649
649
  count: 64,
650
650
  labels: H(e, "above")
651
- }) : new _({
651
+ }) : new s({
652
652
  geometry: G(64),
653
653
  material: {
654
654
  size: e.spec.channels.size?.value ?? n * 1.4,
@@ -661,7 +661,7 @@ function le(e) {
661
661
  labels: H(e, "above")
662
662
  });
663
663
  t && (a.count = 0);
664
- let s = {
664
+ let o = {
665
665
  nodes: [a],
666
666
  layout(n) {
667
667
  let { x: r, y: i, z: a } = e.scales, o = e.spec.channels, s = t ? 7 : 6, c = new Float32Array(n.length * s);
@@ -687,13 +687,13 @@ function le(e) {
687
687
  let r = e.length / n.stride;
688
688
  if (a.data = n.rows, t) {
689
689
  if (r > a.instanceMatrices.length / 16) {
690
- let e = new o({
690
+ let e = new v({
691
691
  geometry: a.geometry,
692
692
  material: a.material,
693
693
  count: r * 2,
694
694
  labels: a.labels
695
695
  });
696
- a.parent?.add(e), a.parent?.remove(a), s.nodes[0] = a = e;
696
+ a.parent?.add(e), a.parent?.remove(a), o.nodes[0] = a = e;
697
697
  }
698
698
  a.count = r;
699
699
  for (let t = 0; t < r; t++) {
@@ -716,15 +716,15 @@ function le(e) {
716
716
  }
717
717
  let i = a.geometry;
718
718
  r > i.vertexCount && (a.geometry = G(r * 2));
719
- let c = a.geometry.positions, l = a.geometry.colors;
720
- for (let t = 0; t < r; t++) c.set(e.subarray(t * 6, t * 6 + 3), t * 3), l.set(e.subarray(t * 6 + 3, t * 6 + 6), t * 3);
719
+ let s = a.geometry.positions, c = a.geometry.colors;
720
+ for (let t = 0; t < r; t++) s.set(e.subarray(t * 6, t * 6 + 3), t * 3), c.set(e.subarray(t * 6 + 3, t * 6 + 6), t * 3);
721
721
  a.geometry.drawCount = r, a.geometry.needsUpdate(), a.geometry !== i && i.dispose();
722
722
  },
723
723
  enter(e) {
724
724
  t ? e[3] = 0 : e[1] = 0;
725
725
  }
726
726
  };
727
- return s;
727
+ return o;
728
728
  }
729
729
  var W = null;
730
730
  function ue() {
@@ -734,22 +734,22 @@ function ue() {
734
734
  let r = Math.hypot(n + .5 - 32, t + .5 - 32) / 32, i = r < .78 ? 1 : 1 - (r - .78) / .22 * .38, a = Math.min(1, Math.max(0, (1 - r) * 32 / 1.5)), o = (t * 64 + n) * 4;
735
735
  e[o] = e[o + 1] = e[o + 2] = Math.round(i * 255), e[o + 3] = Math.round(a * 255);
736
736
  }
737
- return W = new g({ image: {
737
+ return W = new l({ image: {
738
738
  data: e,
739
739
  width: 64,
740
740
  height: 64
741
741
  } });
742
742
  }
743
743
  function G(e) {
744
- let t = new f({
744
+ let t = new h({
745
745
  positions: new Float32Array(e * 3),
746
746
  colors: new Float32Array(e * 3)
747
747
  });
748
748
  return t.drawCount = 0, t;
749
749
  }
750
- function de(t, n) {
751
- let r = new e({
752
- geometry: new f({ positions: [
750
+ function de(e, t) {
751
+ let n = new g({
752
+ geometry: new h({ positions: [
753
753
  0,
754
754
  0,
755
755
  0,
@@ -762,16 +762,16 @@ function de(t, n) {
762
762
  vertexColors: !0
763
763
  },
764
764
  pickable: !1
765
- }), i = new _({
765
+ }), r = new s({
766
766
  geometry: G(8),
767
767
  material: {
768
768
  size: 7,
769
769
  sizeAttenuation: !1,
770
770
  vertexColors: !0
771
771
  },
772
- labels: H(t, "above")
773
- }), a = n ? new s({
774
- geometry: new f({ positions: [
772
+ labels: H(e, "above")
773
+ }), i = t ? new u({
774
+ geometry: new h({ positions: [
775
775
  0,
776
776
  0,
777
777
  0,
@@ -791,22 +791,22 @@ function de(t, n) {
791
791
  pickable: !1
792
792
  }) : null;
793
793
  return {
794
- nodes: a ? [
795
- a,
796
- r,
797
- i
798
- ] : [r, i],
799
- layout(e) {
800
- let { x: n, y: r, z: i } = t.scales, a = t.spec.channels, o = a.color?.field ? a.color : a.detail ?? (a.z?.field ? a.z : null), s = /* @__PURE__ */ new Map();
801
- for (let t of e) {
802
- let e = o ? String(o.get(t)) : "";
803
- s.has(e) || s.set(e, []), s.get(e).push(t);
794
+ nodes: i ? [
795
+ i,
796
+ n,
797
+ r
798
+ ] : [n, r],
799
+ layout(t) {
800
+ let { x: n, y: r, z: i } = e.scales, a = e.spec.channels, o = a.color?.field ? a.color : a.detail ?? (a.z?.field ? a.z : null), s = /* @__PURE__ */ new Map();
801
+ for (let e of t) {
802
+ let t = o ? String(o.get(e)) : "";
803
+ s.has(t) || s.set(t, []), s.get(t).push(e);
804
804
  }
805
805
  let c = [...s.values()].map((e) => e.sort((e, t) => n(a.x.get(e)) - n(a.x.get(t)))), l = /* @__PURE__ */ new Map(), u = c.flat(), d = new Float32Array(u.length * 4), f = 0;
806
- for (let e of c) for (let o of e) {
807
- let e = a.x.get(o), s = Number(a.y.get(o)) || 0, c = V(a, o, s), u = t.spec.options.stack ? l.get(c) ?? 0 : 0;
808
- t.spec.options.stack && l.set(c, u + s), d.set([
809
- n(e),
806
+ for (let t of c) for (let o of t) {
807
+ let t = a.x.get(o), s = Number(a.y.get(o)) || 0, c = V(a, o, s), u = e.spec.options.stack ? l.get(c) ?? 0 : 0;
808
+ e.spec.options.stack && l.set(c, u + s), d.set([
809
+ n(t),
810
810
  r(u + s),
811
811
  U(i, a.z, o),
812
812
  r(u)
@@ -819,22 +819,22 @@ function de(t, n) {
819
819
  stride: 4,
820
820
  shape: {
821
821
  lengths: c.map((e) => e.length),
822
- colors: c.map((e) => t.rgb(e[0]))
822
+ colors: c.map((t) => e.rgb(t[0]))
823
823
  }
824
824
  };
825
825
  },
826
826
  apply(e, t) {
827
- let { lengths: n, colors: o } = t.shape, s = [], c = [], l = [], u = [], d = [], f = [], p = [], m = 0;
828
- n.forEach((t, n) => {
827
+ let { lengths: a, colors: o } = t.shape, s = [], c = [], l = [], u = [], d = [], f = [], p = [], m = 0;
828
+ a.forEach((t, n) => {
829
829
  let r = o[n];
830
830
  for (let n = 0; n < t; n++, m++) {
831
- let [t, i, o, h] = e.subarray(m * 4, m * 4 + 4);
832
- if (l.push(t, i, o), u.push(...r), n > 0 && (s.push(...e.subarray((m - 1) * 4, (m - 1) * 4 + 3), t, i, o), c.push(...r, ...r)), a) {
831
+ let [t, a, o, h] = e.subarray(m * 4, m * 4 + 4);
832
+ if (l.push(t, a, o), u.push(...r), n > 0 && (s.push(...e.subarray((m - 1) * 4, (m - 1) * 4 + 3), t, a, o), c.push(...r, ...r)), i) {
833
833
  let e = f.length / 3;
834
- d.push(t, i, o, t, h, o), f.push(...r, ...r), n > 0 && p.push(e - 2, e - 1, e, e - 1, e + 1, e);
834
+ d.push(t, a, o, t, h, o), f.push(...r, ...r), n > 0 && p.push(e - 2, e - 1, e, e - 1, e + 1, e);
835
835
  }
836
836
  }
837
- }), r.geometry = K(r.geometry, s.length ? {
837
+ }), n.geometry = K(n.geometry, s.length ? {
838
838
  positions: s,
839
839
  colors: c
840
840
  } : { positions: [
@@ -844,7 +844,7 @@ function de(t, n) {
844
844
  0,
845
845
  0,
846
846
  0
847
- ] }), i.geometry = K(i.geometry, {
847
+ ] }), r.geometry = K(r.geometry, {
848
848
  positions: l.length ? l : [
849
849
  0,
850
850
  0,
@@ -855,7 +855,7 @@ function de(t, n) {
855
855
  0,
856
856
  0
857
857
  ]
858
- }), i.geometry.drawCount = l.length / 3, i.material.size = Math.max(...n, 0) > 40 ? 4 : 7, i.data = t.rows, a && (a.geometry = K(a.geometry, p.length ? {
858
+ }), r.geometry.drawCount = l.length / 3, r.material.size = Math.max(...a, 0) > 40 ? 4 : 7, r.data = t.rows, i && (i.geometry = K(i.geometry, p.length ? {
859
859
  positions: d,
860
860
  colors: f,
861
861
  indices: p
@@ -874,11 +874,11 @@ function de(t, n) {
874
874
  };
875
875
  }
876
876
  function K(e, t) {
877
- return e.dispose(), new f(t);
877
+ return e.dispose(), new h(t);
878
878
  }
879
879
  function fe(e) {
880
- let t = new s({
881
- geometry: new f({ positions: [
880
+ let t = new u({
881
+ geometry: new h({ positions: [
882
882
  0,
883
883
  0,
884
884
  0,
@@ -898,19 +898,19 @@ function fe(e) {
898
898
  return {
899
899
  nodes: [t],
900
900
  layout(t) {
901
- let { x: n, y: r, z: i } = e.scales, a = e.spec.channels, o = B(t.map((e) => a.x.get(e))), s = B(t.map((e) => a.z.get(e))), c = new Map(t.map((e) => [`${+a.x.get(e)}|${+a.z.get(e)}|${a.x.get(e)}|${a.z.get(e)}`, e])), u = (e, t) => c.get(`${+e}|${+t}|${e}|${t}`), d = o.length * s.length - c.size;
901
+ let { x: r, y: i, z: a } = e.scales, o = e.spec.channels, s = B(t.map((e) => o.x.get(e))), c = B(t.map((e) => o.z.get(e))), l = new Map(t.map((e) => [`${+o.x.get(e)}|${+o.z.get(e)}|${o.x.get(e)}|${o.z.get(e)}`, e])), u = (e, t) => l.get(`${+e}|${+t}|${e}|${t}`), d = s.length * c.length - l.size;
902
902
  if (d > 0) {
903
- let e = o.flatMap((e) => s.map((t) => [e, t])).find(([e, t]) => !u(e, t));
904
- l("chart()", `a surface needs a value for every x and z pair - ${d} of ${o.length * s.length} are missing (first: x ${e[0]}, z ${e[1]})`);
903
+ let e = s.flatMap((e) => c.map((t) => [e, t])).find(([e, t]) => !u(e, t));
904
+ n("chart()", `a surface needs a value for every x and z pair - ${d} of ${s.length * c.length} are missing (first: x ${e[0]}, z ${e[1]})`);
905
905
  }
906
- let f = [], p = new Float32Array(o.length * s.length * 6), m = 0;
907
- for (let t of s) for (let s of o) {
908
- let o = u(s, t);
909
- f.push(o), p.set([
910
- n(s),
911
- r(Number(a.y.get(o)) || 0),
912
- i(t),
913
- ...e.rgb(o)
906
+ let f = [], p = new Float32Array(s.length * c.length * 6), m = 0;
907
+ for (let t of c) for (let n of s) {
908
+ let s = u(n, t);
909
+ f.push(s), p.set([
910
+ r(n),
911
+ i(Number(o.y.get(s)) || 0),
912
+ a(t),
913
+ ...e.rgb(s)
914
914
  ], m++ * 6);
915
915
  }
916
916
  return {
@@ -919,8 +919,8 @@ function fe(e) {
919
919
  state: p,
920
920
  stride: 6,
921
921
  shape: {
922
- nx: o.length,
923
- nz: s.length
922
+ nx: s.length,
923
+ nz: c.length
924
924
  }
925
925
  };
926
926
  },
@@ -952,19 +952,19 @@ var me = [
952
952
  2.5,
953
953
  4.5
954
954
  ];
955
- function he(t) {
956
- let n = t.spec.options, r = _e(t), i = t.spec.link, a = n.source ?? "source", s = n.target ?? "target", c = /* @__PURE__ */ new Map(), d = (e) => new o({
957
- geometry: p({
955
+ function he(e) {
956
+ let t = e.spec.options, i = _e(e), o = e.spec.link, c = t.source ?? "source", l = t.target ?? "target", u = /* @__PURE__ */ new Map(), d = (t) => new v({
957
+ geometry: f({
958
958
  radius: 1,
959
959
  detail: 2
960
960
  }),
961
961
  material: { roughness: .35 },
962
- count: e,
963
- labels: H(t, "above")
964
- }), m = d(Math.max(8, t.spec.rows.length * 2));
965
- m.count = 0;
966
- let h = me.map((t) => new e({
967
- geometry: new f({ positions: [
962
+ count: t,
963
+ labels: H(e, "above")
964
+ }), p = d(Math.max(8, e.spec.rows.length * 2));
965
+ p.count = 0;
966
+ let m = me.map((e) => new g({
967
+ geometry: new h({ positions: [
968
968
  0,
969
969
  0,
970
970
  0,
@@ -973,59 +973,59 @@ function he(t) {
973
973
  0
974
974
  ] }),
975
975
  material: {
976
- width: t,
976
+ width: e,
977
977
  vertexColors: !0
978
978
  },
979
979
  data: []
980
- })), g = new e({
981
- geometry: new f({ positions: [] }),
980
+ })), _ = new g({
981
+ geometry: new h({ positions: [] }),
982
982
  material: {
983
983
  width: 4,
984
984
  color: "#7fd3ff"
985
985
  },
986
986
  pickable: !1,
987
987
  visible: !1
988
- }), y = i.flow ? new _({
989
- geometry: new f({ positions: [] }),
988
+ }), y = o.flow ? new s({
989
+ geometry: new h({ positions: [] }),
990
990
  material: {
991
- size: .012 * Math.min(...t.box),
991
+ size: .012 * Math.min(...e.box),
992
992
  color: "#bff0ff"
993
993
  },
994
994
  pickable: !1
995
995
  }) : null, b = [], x = [], S = [], C = [], w = null, T = {
996
996
  nodes: [
997
- ...h,
998
- g,
999
- m,
997
+ ...m,
998
+ _,
999
+ p,
1000
1000
  ...y ? [y] : []
1001
1001
  ],
1002
- layout(e) {
1003
- let n = e.map(r), i = new Map(n.map((e, t) => [e, t]));
1004
- S = t.spec.links.filter((e, n) => {
1005
- let o = e[a], c = e[s];
1006
- return (o === void 0 || c === void 0) && l("chart()", `link ${n} has no '${o === void 0 ? a : s}' - links name their ends with source: '${a}', target: '${s}' (set 'source' and 'target' to your field names)`), t.spec.rows.some((e) => r(e) === o) || l("chart()", `link ${n}: ${a} ${u(o)} names no node`), t.spec.rows.some((e) => r(e) === c) || l("chart()", `link ${n}: ${s} ${u(c)} names no node`), i.has(o) && i.has(c);
1002
+ layout(t) {
1003
+ let a = t.map(i), o = new Map(a.map((e, t) => [e, t]));
1004
+ S = e.spec.links.filter((t, a) => {
1005
+ let s = t[c], u = t[l];
1006
+ return (s === void 0 || u === void 0) && n("chart()", `link ${a} has no '${s === void 0 ? c : l}' - links name their ends with source: '${c}', target: '${l}' (set 'source' and 'target' to your field names)`), e.spec.rows.some((e) => i(e) === s) || n("chart()", `link ${a}: ${c} ${r(s)} names no node`), e.spec.rows.some((e) => i(e) === u) || n("chart()", `link ${a}: ${l} ${r(u)} names no node`), o.has(s) && o.has(u);
1007
1007
  });
1008
- let o = N(e, n, S.map((e) => [i.get(e[a]), i.get(e[s])])), c = new Float32Array(e.length * 7);
1009
- return e.forEach((e, n) => c.set([
1010
- ...o[n],
1011
- t.size ? t.size(t.spec.channels.size.get(e)) : .06 * Math.min(...t.box),
1012
- ...t.rgb(e)
1008
+ let s = N(t, a, S.map((e) => [o.get(e[c]), o.get(e[l])])), u = new Float32Array(t.length * 7);
1009
+ return t.forEach((t, n) => u.set([
1010
+ ...s[n],
1011
+ e.size ? e.size(e.spec.channels.size.get(t)) : .06 * Math.min(...e.box),
1012
+ ...e.rgb(t)
1013
1013
  ], n * 7)), {
1014
- rows: e,
1015
- keys: n,
1016
- state: c,
1014
+ rows: t,
1015
+ keys: a,
1016
+ state: u,
1017
1017
  stride: 7,
1018
- shape: { pairs: S.map((e) => [e[a], e[s]]) }
1018
+ shape: { pairs: S.map((e) => [e[c], e[l]]) }
1019
1019
  };
1020
1020
  },
1021
1021
  apply(e, t) {
1022
1022
  let n = e.length / t.stride;
1023
- if (C = t.rows, w !== null && !C.some((e) => r(e) === w) && (w = null, g.visible = !1), n > m.instanceMatrices.length / 16) {
1023
+ if (C = t.rows, w !== null && !C.some((e) => i(e) === w) && (w = null, _.visible = !1), n > p.instanceMatrices.length / 16) {
1024
1024
  let e = d(n * 2);
1025
- E && e.on("hover", D), m.parent?.add(e), m.parent?.remove(m), m.dispose(), T.nodes[T.nodes.indexOf(m)] = e, m = e;
1025
+ E && e.on("hover", D), p.parent?.add(e), p.parent?.remove(p), p.dispose(), T.nodes[T.nodes.indexOf(p)] = e, p = e;
1026
1026
  }
1027
- m.count = n, m.data = t.rows;
1028
- let o = t.rows.map(r), c = new Map(o.map((e, t) => [e, t]));
1027
+ p.count = n, p.data = t.rows;
1028
+ let r = t.rows.map(i), a = new Map(r.map((e, t) => [e, t]));
1029
1029
  x = [];
1030
1030
  for (let t = 0; t < n; t++) {
1031
1031
  let [n, r, i, a, o, s, c] = e.subarray(t * 7, t * 7 + 7);
@@ -1033,7 +1033,7 @@ function he(t) {
1033
1033
  n,
1034
1034
  r,
1035
1035
  i
1036
- ]), m.setInstance(t, {
1036
+ ]), p.setInstance(t, {
1037
1037
  position: [
1038
1038
  n,
1039
1039
  r,
@@ -1047,24 +1047,24 @@ function he(t) {
1047
1047
  ])
1048
1048
  });
1049
1049
  }
1050
- let l = me.map(() => ({
1050
+ let s = me.map(() => ({
1051
1051
  positions: [],
1052
1052
  colors: [],
1053
1053
  rows: []
1054
1054
  }));
1055
1055
  b = [], S.forEach((e, t) => {
1056
- let n = c.get(e[a]), r = c.get(e[s]);
1056
+ let n = a.get(e[c]), r = a.get(e[l]);
1057
1057
  if (n === void 0 || r === void 0) return;
1058
- let o = l[A(e)], u = j(e);
1059
- o.positions.push(...x[n], ...x[r]), o.colors.push(...u, ...u), o.rows.push(e), i.flow && b.push({
1058
+ let i = s[A(e)], u = j(e);
1059
+ i.positions.push(...x[n], ...x[r]), i.colors.push(...u, ...u), i.rows.push(e), o.flow && b.push({
1060
1060
  a: n,
1061
1061
  b: r,
1062
1062
  speed: M(e),
1063
1063
  phase: t * .618 % 1
1064
1064
  });
1065
- }), h.forEach((e, t) => {
1066
- let n = l[t];
1067
- e.geometry.dispose(), e.geometry = new f(n.positions.length ? {
1065
+ }), m.forEach((e, t) => {
1066
+ let n = s[t];
1067
+ e.geometry.dispose(), e.geometry = new h(n.positions.length ? {
1068
1068
  positions: n.positions,
1069
1069
  colors: n.colors
1070
1070
  } : { positions: [
@@ -1087,68 +1087,68 @@ function he(t) {
1087
1087
  n.phase = (n.phase + e * n.speed) % 1;
1088
1088
  let i = x[n.a], a = x[n.b];
1089
1089
  for (let e = 0; e < 3; e++) t[r * 3 + e] = i[e] + (a[e] - i[e]) * n.phase;
1090
- }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new f({ positions: t }));
1090
+ }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new h({ positions: t }));
1091
1091
  },
1092
1092
  tooltipRows(e) {
1093
- return h.includes(e.node) ? "link" : "node";
1093
+ return m.includes(e.node) ? "link" : "node";
1094
1094
  }
1095
- }, E = (n.highlight ?? "neighbours") === "neighbours";
1096
- E && m.on("hover", D);
1097
- function D(e) {
1098
- let n = e && e.node === m && e.instance !== null ? r(C[e.instance]) : null;
1095
+ }, E = (t.highlight ?? "neighbours") === "neighbours";
1096
+ E && p.on("hover", D);
1097
+ function D(t) {
1098
+ let n = t && t.node === p && t.instance !== null ? i(C[t.instance]) : null;
1099
1099
  if (n !== w) {
1100
- w = n, g.visible = n !== null, n !== null && O(n);
1101
- for (let e = 0; e < m.count; e++) m.setColor(e, k(e, t.rgb(C[e])));
1100
+ w = n, _.visible = n !== null, n !== null && O(n);
1101
+ for (let t = 0; t < p.count; t++) p.setColor(t, k(t, e.rgb(C[t])));
1102
1102
  }
1103
1103
  }
1104
1104
  function O(e) {
1105
1105
  let t = [];
1106
1106
  for (let n of S) {
1107
- if (n[a] !== e && n[s] !== e) continue;
1108
- let i = C.findIndex((e) => r(e) === n[a]), o = C.findIndex((e) => r(e) === n[s]);
1109
- i >= 0 && o >= 0 && t.push(...x[i], ...x[o]);
1107
+ if (n[c] !== e && n[l] !== e) continue;
1108
+ let r = C.findIndex((e) => i(e) === n[c]), a = C.findIndex((e) => i(e) === n[l]);
1109
+ r >= 0 && a >= 0 && t.push(...x[r], ...x[a]);
1110
1110
  }
1111
- g.geometry.dispose(), g.geometry = new f({ positions: t });
1111
+ _.geometry.dispose(), _.geometry = new h({ positions: t });
1112
1112
  }
1113
- function k(e, n) {
1113
+ function k(t, n) {
1114
1114
  if (w === null || !E) return n;
1115
- let i = r(C[e]);
1116
- return i === w || S.some((e) => e[a] === w && e[s] === i || e[s] === w && e[a] === i) ? n : new v().setSRGB(n[0], n[1], n[2]).lerp(t.theme === "light" ? "#ffffff" : "#202024", .65).toSRGB();
1115
+ let r = i(C[t]);
1116
+ return r === w || S.some((e) => e[c] === w && e[l] === r || e[l] === w && e[c] === r) ? n : new a().setSRGB(n[0], n[1], n[2]).lerp(e.theme === "light" ? "#ffffff" : "#202024", .65).toSRGB();
1117
1117
  }
1118
- function A(e) {
1119
- let n = i.width;
1118
+ function A(t) {
1119
+ let n = o.width;
1120
1120
  if (!n) return 0;
1121
1121
  if (n.field === null) return n.value >= 3.5 ? 2 : +(n.value >= 2);
1122
- let r = t.spec.links.map((e) => Number(n.get(e)) || 0), a = Math.max(...r) || 1;
1123
- return Math.min(2, Math.floor((Number(n.get(e)) || 0) / a * 2.999));
1122
+ let r = e.spec.links.map((e) => Number(n.get(e)) || 0), i = Math.max(...r) || 1;
1123
+ return Math.min(2, Math.floor((Number(n.get(t)) || 0) / i * 2.999));
1124
1124
  }
1125
- function j(e) {
1126
- let n = i.color, r = t.theme === "light" ? "#9aa3b2" : "#4a5266";
1127
- return n ? n.field === null ? v.fromInput(n.value).toSRGB() : t.linkColor(n.get(e)).toSRGB() : v.fromInput(r).toSRGB();
1125
+ function j(t) {
1126
+ let n = o.color, r = e.theme === "light" ? "#9aa3b2" : "#4a5266";
1127
+ return n ? n.field === null ? a.fromInput(n.value).toSRGB() : e.linkColor(n.get(t)).toSRGB() : a.fromInput(r).toSRGB();
1128
1128
  }
1129
- function M(e) {
1130
- let n = i.flow;
1129
+ function M(t) {
1130
+ let n = o.flow;
1131
1131
  if (n.field === null) return .4;
1132
- let r = Math.max(...t.spec.links.map((e) => Number(n.get(e)) || 0)) || 1;
1133
- return .15 + .6 * (Number(n.get(e)) || 0) / r;
1132
+ let r = Math.max(...e.spec.links.map((e) => Number(n.get(e)) || 0)) || 1;
1133
+ return .15 + .6 * (Number(n.get(t)) || 0) / r;
1134
1134
  }
1135
- function N(e, r, i) {
1136
- let [a, o, s] = t.box, c = n.layout ?? "force";
1137
- if (c === "given") {
1138
- let { x: n, y: r, z: i } = t.scales, a = t.spec.channels;
1139
- return e.map((e) => [
1140
- n && a.x ? n(a.x.get(e)) : 0,
1141
- r && a.y ? r(a.y.get(e)) : o / 2,
1142
- i && a.z ? i(a.z.get(e)) : 0
1135
+ function N(i, a, o) {
1136
+ let [s, c, l] = e.box, u = t.layout ?? "force";
1137
+ if (u === "given") {
1138
+ let { x: t, y: n, z: r } = e.scales, a = e.spec.channels;
1139
+ return i.map((e) => [
1140
+ t && a.x ? t(a.x.get(e)) : 0,
1141
+ n && a.y ? n(a.y.get(e)) : c / 2,
1142
+ r && a.z ? r(a.z.get(e)) : 0
1143
1143
  ]);
1144
1144
  }
1145
- if (c && typeof c == "object" && "tiers" in c) return ge(e, r, i, c, [
1146
- a,
1147
- o,
1148
- s
1145
+ if (u && typeof u == "object" && "tiers" in u) return ge(i, a, o, u, [
1146
+ s,
1147
+ c,
1148
+ l
1149
1149
  ]);
1150
- c !== "force" && l("chart()", `layout ${u(c)} - expected 'force', 'given' or { tiers: 'field' }`);
1151
- let d = P(r, i), f = [
1150
+ u !== "force" && n("chart()", `layout ${r(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1151
+ let d = P(a, o), f = [
1152
1152
  Infinity,
1153
1153
  Infinity,
1154
1154
  Infinity
@@ -1158,40 +1158,40 @@ function he(t) {
1158
1158
  -Infinity
1159
1159
  ];
1160
1160
  for (let e of d) for (let t = 0; t < 3; t++) f[t] = Math.min(f[t], e[t]), p[t] = Math.max(p[t], e[t]);
1161
- let m = Math.max(...p.map((e, t) => e - f[t]), 1e-6), h = Math.min(a, n.flat ? s : Math.min(o, s)) * .9 / m, g = p.map((e, t) => (e + f[t]) / 2);
1161
+ let m = Math.max(...p.map((e, t) => e - f[t]), 1e-6), h = Math.min(s, t.flat ? l : Math.min(c, l)) * .9 / m, g = p.map((e, t) => (e + f[t]) / 2);
1162
1162
  return d.map((e) => [
1163
1163
  (e[0] - g[0]) * h,
1164
- n.flat ? 0 : (e[1] - g[1]) * h + o / 2,
1164
+ t.flat ? 0 : (e[1] - g[1]) * h + c / 2,
1165
1165
  (e[2] - g[2]) * h
1166
1166
  ]);
1167
1167
  }
1168
- function P(e, t) {
1169
- let r = e.length, i = pe(n.seed ?? 1), a = n.flat ? [0, 2] : [
1168
+ function P(e, n) {
1169
+ let r = e.length, i = pe(t.seed ?? 1), a = t.flat ? [0, 2] : [
1170
1170
  0,
1171
1171
  1,
1172
1172
  2
1173
- ], o = e.some((e) => c.has(e)), s = n.steps ?? (o ? 60 : 300), l = e.map(() => []);
1174
- for (let [e, n] of t) l[e].push(n), l[n].push(e);
1175
- let u = new Float32Array(r * r).fill(Infinity), d = 1;
1173
+ ], o = e.some((e) => u.has(e)), s = t.steps ?? (o ? 60 : 300), c = e.map(() => []);
1174
+ for (let [e, t] of n) c[e].push(t), c[t].push(e);
1175
+ let l = new Float32Array(r * r).fill(Infinity), d = 1;
1176
1176
  for (let e = 0; e < r; e++) {
1177
1177
  let t = [e];
1178
- u[e * r + e] = 0;
1178
+ l[e * r + e] = 0;
1179
1179
  for (let n = 0; n < t.length; n++) {
1180
- let i = t[n], a = u[e * r + i] + 1;
1181
- for (let n of l[i]) u[e * r + n] === Infinity && (u[e * r + n] = a, d = Math.max(d, a), t.push(n));
1180
+ let i = t[n], a = l[e * r + i] + 1;
1181
+ for (let n of c[i]) l[e * r + n] === Infinity && (l[e * r + n] = a, d = Math.max(d, a), t.push(n));
1182
1182
  }
1183
1183
  }
1184
- let f = e.map((t, a) => {
1185
- if (c.has(t)) return [...c.get(t)];
1186
- let o = l[a].find((t) => c.has(e[t])), s = o === void 0 ? [
1184
+ let f = e.map((n, a) => {
1185
+ if (u.has(n)) return [...u.get(n)];
1186
+ let o = c[a].find((t) => u.has(e[t])), s = o === void 0 ? [
1187
1187
  0,
1188
1188
  0,
1189
1189
  0
1190
- ] : c.get(e[o]), u = o === void 0 ? Math.sqrt(r) : .5;
1190
+ ] : u.get(e[o]), l = o === void 0 ? Math.sqrt(r) : .5;
1191
1191
  return [
1192
- s[0] + (i() - .5) * u,
1193
- n.flat ? 0 : s[1] + (i() - .5) * u,
1194
- s[2] + (i() - .5) * u
1192
+ s[0] + (i() - .5) * l,
1193
+ t.flat ? 0 : s[1] + (i() - .5) * l,
1194
+ s[2] + (i() - .5) * l
1195
1195
  ];
1196
1196
  }), p = [
1197
1197
  0,
@@ -1203,32 +1203,32 @@ function he(t) {
1203
1203
  let t = 0;
1204
1204
  for (let n = 0; n < r; n++) {
1205
1205
  if (e === n) continue;
1206
- let i = u[e * r + n], a = i === Infinity ? d + 1 : i, o = 1 / (a * a), s = f[e][0] - f[n][0], c = f[e][1] - f[n][1], l = f[e][2] - f[n][2], m = Math.hypot(s, c, l) || 1e-6;
1207
- p[0] += o * (f[n][0] + a * s / m), p[1] += o * (f[n][1] + a * c / m), p[2] += o * (f[n][2] + a * l / m), t += o;
1206
+ let i = l[e * r + n], a = i === Infinity ? d + 1 : i, o = 1 / (a * a), s = f[e][0] - f[n][0], c = f[e][1] - f[n][1], u = f[e][2] - f[n][2], m = Math.hypot(s, c, u) || 1e-6;
1207
+ p[0] += o * (f[n][0] + a * s / m), p[1] += o * (f[n][1] + a * c / m), p[2] += o * (f[n][2] + a * u / m), t += o;
1208
1208
  }
1209
1209
  if (t) for (let n of a) f[e][n] = p[n] / t;
1210
1210
  }
1211
- return c = new Map(e.map((e, t) => [e, f[t]])), f;
1211
+ return u = new Map(e.map((e, t) => [e, f[t]])), f;
1212
1212
  }
1213
1213
  return T;
1214
1214
  }
1215
- function ge(e, t, n, r, [i, a, o]) {
1216
- let s = r.tiers;
1215
+ function ge(e, t, r, i, [a, o, s]) {
1216
+ let c = i.tiers;
1217
1217
  if (!e.length) return [];
1218
- s in e[0] || l("chart()", `layout: { tiers: '${s}' } - '${s}' isn't a node field`);
1219
- let c = r.order ?? [...new Set(e.map((e) => e[s]))], u = e.map((e) => Math.max(0, c.indexOf(e[s]))), d = Math.max(...u) + 1, f = Array(e.length).fill(0), p = Array(e.length), m = Math.min(i, o) / 2 * .92;
1218
+ c in e[0] || n("chart()", `layout: { tiers: '${c}' } - '${c}' isn't a node field`);
1219
+ let l = i.order ?? [...new Set(e.map((e) => e[c]))], u = e.map((e) => Math.max(0, l.indexOf(e[c]))), d = Math.max(...u) + 1, f = Array(e.length).fill(0), p = Array(e.length), m = Math.min(a, s) / 2 * .92;
1220
1220
  for (let t = 0; t < d; t++) {
1221
- let r = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
1222
- let i = n.filter(([t, n]) => t === e || n === e).map(([t, n]) => t === e ? n : t).filter((e) => u[e] < t);
1223
- return i.length ? i.reduce((e, t) => e + f[t], 0) / i.length : r.indexOf(e);
1221
+ let n = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
1222
+ let i = r.filter(([t, n]) => t === e || n === e).map(([t, n]) => t === e ? n : t).filter((e) => u[e] < t);
1223
+ return i.length ? i.reduce((e, t) => e + f[t], 0) / i.length : n.indexOf(e);
1224
1224
  };
1225
- t > 0 && r.sort((e, t) => i(e) - i(t));
1226
- let o = r.length === 1 ? 0 : t === 0 ? m * .25 : m * (.35 + .65 * t / Math.max(1, d - 1));
1227
- r.forEach((e, n) => {
1228
- f[e] = (n + .5) / r.length * Math.PI * 2, p[e] = [
1229
- Math.cos(f[e]) * o,
1230
- a * (1 - t / Math.max(1, d - 1)),
1231
- Math.sin(f[e]) * o
1225
+ t > 0 && n.sort((e, t) => i(e) - i(t));
1226
+ let a = n.length === 1 ? 0 : t === 0 ? m * .25 : m * (.35 + .65 * t / Math.max(1, d - 1));
1227
+ n.forEach((e, r) => {
1228
+ f[e] = (r + .5) / n.length * Math.PI * 2, p[e] = [
1229
+ Math.cos(f[e]) * a,
1230
+ o * (1 - t / Math.max(1, d - 1)),
1231
+ Math.sin(f[e]) * a
1232
1232
  ];
1233
1233
  });
1234
1234
  }
@@ -1236,7 +1236,7 @@ function ge(e, t, n, r, [i, a, o]) {
1236
1236
  }
1237
1237
  function _e(e) {
1238
1238
  let t = e.spec.channels.key;
1239
- return t ? (e) => t.get(e) : (e.spec.rows.length && !("id" in e.spec.rows[0]) && l("chart()", "network nodes need an 'id' field, or key: 'yourIdField' - links name nodes by it"), (e) => e.id);
1239
+ return t ? (e) => t.get(e) : (e.spec.rows.length && !("id" in e.spec.rows[0]) && n("chart()", "network nodes need an 'id' field, or key: 'yourIdField' - links name nodes by it"), (e) => e.id);
1240
1240
  }
1241
1241
  // src/charts/spec.js
1242
1242
  var q = [
@@ -1333,79 +1333,79 @@ var q = [
1333
1333
  sort: "sort with scale: { domain: [...] } in the order you want",
1334
1334
  stack: "stacking is the chart's option: stack: true"
1335
1335
  };
1336
- function Se(e) {
1337
- (!e || typeof e != "object" || Array.isArray(e)) && l("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${u(e)}`);
1338
- for (let n of Object.keys(e)) Y.includes(n) || l("chart()", `unknown option '${n}' - ${ye[n] ?? `expected ${Y.filter((e) => e[0] !== "$").join(", ")}${t(n, Y)}`}`);
1339
- typeof e.width == "number" && e.width > 1 && l("chart()", "'width' is a bar's share of its band (0-1); in Vega-Lite it is pixels - here the canvas sets the size");
1340
- let r = Ce(e.mark), { rows: i, links: a } = we(e.data, r), o = Te(i), s = { ...e.encoding ?? {} };
1341
- for (let e of Object.keys(s)) !J.includes(e) && e !== "tooltip" && l("chart()", `encoding '${e}' isn't a channel we have - channels are ${J.join(", ")}, tooltip`);
1342
- let c = {};
1343
- for (let t of J) {
1344
- let n = e[t] ?? s[t];
1345
- n != null && (c[t] = X(t, n, i, o));
1336
+ function Se(t) {
1337
+ (!t || typeof t != "object" || Array.isArray(t)) && n("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(t)}`);
1338
+ for (let e of Object.keys(t)) Y.includes(e) || n("chart()", `unknown option '${e}' - ${ye[e] ?? `expected ${Y.filter((e) => e[0] !== "$").join(", ")}${i(e, Y)}`}`);
1339
+ typeof t.width == "number" && t.width > 1 && n("chart()", "'width' is a bar's share of its band (0-1); in Vega-Lite it is pixels - here the canvas sets the size");
1340
+ let a = Ce(t.mark), { rows: o, links: s } = we(t.data, a), c = Te(o), l = { ...t.encoding ?? {} };
1341
+ for (let e of Object.keys(l)) !J.includes(e) && e !== "tooltip" && n("chart()", `encoding '${e}' isn't a channel we have - channels are ${J.join(", ")}, tooltip`);
1342
+ let u = {};
1343
+ for (let e of J) {
1344
+ let n = t[e] ?? l[e];
1345
+ n != null && (u[e] = X(e, n, o, c));
1346
1346
  }
1347
- if (r === "network") for (let t of [
1347
+ if (a === "network") for (let e of [
1348
1348
  "x",
1349
1349
  "y",
1350
1350
  "z"
1351
- ]) c[t] && e.layout !== "given" && l("chart()", `${t} on a 'network' places its nodes - add layout: 'given' to use positions from the data`);
1352
- else for (let e of r === "surface" ? [
1351
+ ]) u[e] && t.layout !== "given" && n("chart()", `${e} on a 'network' places its nodes - add layout: 'given' to use positions from the data`);
1352
+ else for (let e of a === "surface" ? [
1353
1353
  "x",
1354
1354
  "z",
1355
1355
  "y"
1356
- ] : ["x", "y"]) c[e] || l("chart()", `a '${r}' chart needs ${e} - e.g. ${e}: '${o[0] ?? "field"}'`), r !== "point" && c[e].field === null && l("chart()", `${e} on a '${r}' chart lays its marks out along a scale - it needs a field, not a constant value - e.g. ${e}: '${o[0] ?? "field"}'`);
1357
- let d = e.tooltip ?? s.tooltip, f = typeof e.mark == "object" ? e.mark.tooltip : void 0, p = ke(d ?? (f !== !1 && void 0), c, i, o), m = {};
1358
- if (e.link !== void 0) {
1359
- r !== "network" && l("chart()", "'link' sets a network's link channels - it needs mark: 'network'");
1360
- let t = Te(a);
1361
- for (let [n, r] of Object.entries(e.link)) [
1356
+ ] : ["x", "y"]) u[e] || n("chart()", `a '${a}' chart needs ${e} - e.g. ${e}: '${c[0] ?? "field"}'`), a !== "point" && u[e].field === null && n("chart()", `${e} on a '${a}' chart lays its marks out along a scale - it needs a field, not a constant value - e.g. ${e}: '${c[0] ?? "field"}'`);
1357
+ let d = t.tooltip ?? l.tooltip, f = typeof t.mark == "object" ? t.mark.tooltip : void 0, p = ke(d ?? (f !== !1 && void 0), u, o, c), m = {};
1358
+ if (t.link !== void 0) {
1359
+ a !== "network" && n("chart()", "'link' sets a network's link channels - it needs mark: 'network'");
1360
+ let e = Te(s);
1361
+ for (let [r, i] of Object.entries(t.link)) [
1362
1362
  "width",
1363
1363
  "color",
1364
1364
  "opacity",
1365
1365
  "flow",
1366
1366
  "tooltip"
1367
- ].includes(n) || l("chart()", `link has no '${n}' - link channels are width, color, opacity, flow, tooltip`), n !== "tooltip" && (m[n] = X(`link.${n}`, r, a, t));
1368
- e.link.tooltip !== void 0 && (m.tooltip = ke(e.link.tooltip, {}, a, t));
1367
+ ].includes(r) || n("chart()", `link has no '${r}' - link channels are width, color, opacity, flow, tooltip`), r !== "tooltip" && (m[r] = X(`link.${r}`, i, s, e));
1368
+ t.link.tooltip !== void 0 && (m.tooltip = ke(t.link.tooltip, {}, s, e));
1369
1369
  }
1370
1370
  let h = {};
1371
- for (let t of Y) !J.includes(t) && ![
1371
+ for (let e of Y) !J.includes(e) && ![
1372
1372
  "mark",
1373
1373
  "data",
1374
1374
  "encoding",
1375
1375
  "tooltip",
1376
1376
  "link"
1377
- ].includes(t) && e[t] !== void 0 && (h[t] = e[t]);
1378
- return h.steps !== void 0 && (!Number.isInteger(h.steps) || h.steps < 1) && l("chart()", `'steps' is how many steps the force layout takes, a whole number of 1 or more, got ${u(h.steps)}`), h.seed !== void 0 && n("chart()", "seed", h.seed), h.legend?.ticks !== void 0 && De("legend", h.legend.ticks), h.box === void 0 || Array.isArray(h.box) && h.box.length === 3 && h.box.every((e) => e > 0) || l("chart()", `'box' is the chart's size in the scene, [x, y, z] above 0, got ${u(h.box)}`), {
1379
- mark: r,
1380
- rows: i,
1381
- links: a,
1382
- fields: o,
1383
- channels: c,
1377
+ ].includes(e) && t[e] !== void 0 && (h[e] = t[e]);
1378
+ return h.steps !== void 0 && (!Number.isInteger(h.steps) || h.steps < 1) && n("chart()", `'steps' is how many steps the force layout takes, a whole number of 1 or more, got ${r(h.steps)}`), h.seed !== void 0 && e("chart()", "seed", h.seed), h.legend?.ticks !== void 0 && De("legend", h.legend.ticks), h.box === void 0 || Array.isArray(h.box) && h.box.length === 3 && h.box.every((e) => e > 0) || n("chart()", `'box' is the chart's size in the scene, [x, y, z] above 0, got ${r(h.box)}`), {
1379
+ mark: a,
1380
+ rows: o,
1381
+ links: s,
1382
+ fields: c,
1383
+ channels: u,
1384
1384
  tooltip: p,
1385
1385
  link: m,
1386
1386
  options: h
1387
1387
  };
1388
1388
  }
1389
1389
  function Ce(e) {
1390
- let n = e;
1391
- if (n && typeof n == "object") {
1392
- for (let e of Object.keys(n)) e !== "type" && e !== "tooltip" && l("chart()", `mark option '${e}' isn't supported - use the chart's options (width, stack, ...) or style the chart's nodes`);
1393
- n = n.type;
1390
+ let t = e;
1391
+ if (t && typeof t == "object") {
1392
+ for (let e of Object.keys(t)) e !== "type" && e !== "tooltip" && n("chart()", `mark option '${e}' isn't supported - use the chart's options (width, stack, ...) or style the chart's nodes`);
1393
+ t = t.type;
1394
1394
  }
1395
- if (typeof n != "string" && l("chart()", `'mark' is required: one of ${q.map((e) => `'${e}'`).join(", ")}`), !q.includes(n)) {
1396
- let e = be[n];
1397
- (n === "pie" || n === "arc" || n === "donut") && l("chart()", "pie and donut charts aren't supported - in 3D they distort values; use mark: 'bar'"), l("chart()", `mark '${n}' - ${e ? `use '${e}'` : `expected one of ${q.map((e) => `'${e}'`).join(", ")}${t(n, q)}`}`);
1395
+ if (typeof t != "string" && n("chart()", `'mark' is required: one of ${q.map((e) => `'${e}'`).join(", ")}`), !q.includes(t)) {
1396
+ let e = be[t];
1397
+ (t === "pie" || t === "arc" || t === "donut") && n("chart()", "pie and donut charts aren't supported - in 3D they distort values; use mark: 'bar'"), n("chart()", `mark '${t}' - ${e ? `use '${e}'` : `expected one of ${q.map((e) => `'${e}'`).join(", ")}${i(t, q)}`}`);
1398
1398
  }
1399
- return n;
1399
+ return t;
1400
1400
  }
1401
1401
  function we(e, t) {
1402
- if (e && typeof e == "object" && !Array.isArray(e) && "url" in e && l("chart()", "data: { url } isn't loaded for you - fetch the rows and pass data: rows"), t === "network") return e && Array.isArray(e.nodes) && Array.isArray(e.links) || l("chart()", `a network's data is { nodes: [...], links: [...] }, got ${u(e)}`), {
1402
+ if (e && typeof e == "object" && !Array.isArray(e) && "url" in e && n("chart()", "data: { url } isn't loaded for you - fetch the rows and pass data: rows"), t === "network") return e && Array.isArray(e.nodes) && Array.isArray(e.links) || n("chart()", `a network's data is { nodes: [...], links: [...] }, got ${r(e)}`), {
1403
1403
  rows: e.nodes,
1404
1404
  links: e.links
1405
1405
  };
1406
- let n = Array.isArray(e) ? e : e && Array.isArray(e.values) ? e.values : null;
1407
- return n || l("chart()", `'data' must be an array of rows (objects), or { values: [...] }, got ${u(e)}`), n.some((e) => !e || typeof e != "object") && l("chart()", "every row in 'data' must be an object, such as { month: 'Jan', sales: 41 }"), {
1408
- rows: n,
1406
+ let i = Array.isArray(e) ? e : e && Array.isArray(e.values) ? e.values : null;
1407
+ return i || n("chart()", `'data' must be an array of rows (objects), or { values: [...] }, got ${r(e)}`), i.some((e) => !e || typeof e != "object") && n("chart()", "every row in 'data' must be an object, such as { month: 'Jan', sales: 41 }"), {
1408
+ rows: i,
1409
1409
  links: []
1410
1410
  };
1411
1411
  }
@@ -1418,53 +1418,53 @@ function Ee(e, t) {
1418
1418
  let n = e.find((e) => e[t] !== null && e[t] !== void 0)?.[t];
1419
1419
  return typeof n == "number" ? "quantitative" : n instanceof Date || typeof n == "string" && /^\d{4}-\d{2}(-\d{2})?([T ][\d:.]+Z?)?$/.test(n) ? "temporal" : "nominal";
1420
1420
  }
1421
- function X(e, n, r, i) {
1422
- let a = "chart()", o;
1423
- if (typeof n == "string") i.includes(n) ? o = { field: n } : /color|colour/.test(e) && Oe(n) ? o = { value: n } : l(a, `${e}: field '${n}' isn't in the data - fields are ${i.join(", ") || "(none)"}${t(n, i)}`);
1424
- else if (typeof n == "number" && [
1421
+ function X(e, t, a, o) {
1422
+ let s = "chart()", c;
1423
+ if (typeof t == "string") o.includes(t) ? c = { field: t } : /color|colour/.test(e) && Oe(t) ? c = { value: t } : n(s, `${e}: field '${t}' isn't in the data - fields are ${o.join(", ") || "(none)"}${i(t, o)}`);
1424
+ else if (typeof t == "number" && [
1425
1425
  "size",
1426
1426
  "opacity",
1427
1427
  "link.width",
1428
1428
  "link.opacity",
1429
1429
  "link.flow"
1430
- ].includes(e)) o = { value: n };
1431
- else if (n && typeof n == "object" && !Array.isArray(n)) {
1432
- o = n;
1433
- for (let t of Object.keys(o)) ve.includes(t) || l(a, `${e}: '${t}' - ${xe[t] ?? `unknown; a channel takes ${ve.join(", ")}`}`);
1434
- o.field !== void 0 && !i.includes(o.field) && l(a, `${e}: field '${o.field}' isn't in the data - fields are ${i.join(", ") || "(none)"}${t(String(o.field), i)}`), o.field === void 0 && o.value === void 0 && l(a, `${e} needs a field (or a constant value)`);
1435
- } else return e === "size" && Array.isArray(n) && l(a, "'size' is a channel - the chart's size in the scene is 'box: [x, y, z]'"), l(a, `${e} must be a field name or { field, ... }, got ${u(n)}`);
1436
- o.axis?.ticks !== void 0 && De(`${e}: axis`, o.axis.ticks);
1437
- let s = o.field ?? null, c = o.type ?? (s ? Ee(r, s) : "nominal");
1430
+ ].includes(e)) c = { value: t };
1431
+ else if (t && typeof t == "object" && !Array.isArray(t)) {
1432
+ c = t;
1433
+ for (let t of Object.keys(c)) ve.includes(t) || n(s, `${e}: '${t}' - ${xe[t] ?? `unknown; a channel takes ${ve.join(", ")}`}`);
1434
+ c.field !== void 0 && !o.includes(c.field) && n(s, `${e}: field '${c.field}' isn't in the data - fields are ${o.join(", ") || "(none)"}${i(String(c.field), o)}`), c.field === void 0 && c.value === void 0 && n(s, `${e} needs a field (or a constant value)`);
1435
+ } else return e === "size" && Array.isArray(t) && n(s, "'size' is a channel - the chart's size in the scene is 'box: [x, y, z]'"), n(s, `${e} must be a field name or { field, ... }, got ${r(t)}`);
1436
+ c.axis?.ticks !== void 0 && De(`${e}: axis`, c.axis.ticks);
1437
+ let l = c.field ?? null, u = c.type ?? (l ? Ee(a, l) : "nominal");
1438
1438
  [
1439
1439
  "quantitative",
1440
1440
  "nominal",
1441
1441
  "ordinal",
1442
1442
  "temporal"
1443
- ].includes(c) || l(a, `${e}: type '${c}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${t(String(c), [
1443
+ ].includes(u) || n(s, `${e}: type '${u}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${i(String(u), [
1444
1444
  "quantitative",
1445
1445
  "nominal",
1446
1446
  "ordinal",
1447
1447
  "temporal"
1448
1448
  ])}`);
1449
- let d = s === null ? () => o.value : c === "temporal" ? (e) => L(e[s]) : (e) => e[s];
1449
+ let d = l === null ? () => c.value : u === "temporal" ? (e) => L(e[l]) : (e) => e[l];
1450
1450
  return {
1451
- field: s,
1452
- value: o.value,
1453
- type: c,
1454
- title: o.title ?? s ?? e,
1455
- format: o.format,
1456
- scale: o.scale ?? {},
1457
- axis: o.axis ?? {},
1451
+ field: l,
1452
+ value: c.value,
1453
+ type: u,
1454
+ title: c.title ?? l ?? e,
1455
+ format: c.format,
1456
+ scale: c.scale ?? {},
1457
+ axis: c.axis ?? {},
1458
1458
  get: d,
1459
- priority: o.priority
1459
+ priority: c.priority
1460
1460
  };
1461
1461
  }
1462
1462
  function De(e, t) {
1463
- Array.isArray(t) || Number.isInteger(t) && t > 0 || l("chart()", `${e} ticks are a list of the values to mark, such as [0, 25, 50, 75, 100], or about how many, got ${u(t)}`);
1463
+ Array.isArray(t) || Number.isInteger(t) && t > 0 || n("chart()", `${e} ticks are a list of the values to mark, such as [0, 25, 50, 75, 100], or about how many, got ${r(t)}`);
1464
1464
  }
1465
1465
  function Oe(e) {
1466
1466
  try {
1467
- return v.fromInput(e), !0;
1467
+ return a.fromInput(e), !0;
1468
1468
  } catch {
1469
1469
  return !1;
1470
1470
  }
@@ -1495,7 +1495,7 @@ var Me = c.filter((e) => ![
1495
1495
  function Ne(e) {
1496
1496
  return new Z(e);
1497
1497
  }
1498
- var Z = class e extends h {
1498
+ var Z = class e extends _ {
1499
1499
  static type = "chart";
1500
1500
  static get OPTIONS() {
1501
1501
  return c;
@@ -1514,10 +1514,10 @@ var Z = class e extends h {
1514
1514
  #u = null;
1515
1515
  #d = null;
1516
1516
  constructor(e) {
1517
- (!e || typeof e != "object" || Array.isArray(e)) && l("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${u(e)}`);
1518
- let t = {}, n = {};
1519
- for (let [r, i] of Object.entries(e)) (Me.includes(r) ? t : n)[r] = i;
1520
- e.children && l("chart()", "a chart makes its own children - add other nodes to a Group beside it"), super(t), je(), this.#e = n, this.#i = {}, this.#f(!0), this.onUpdate((e, t) => this.#_(t));
1517
+ (!e || typeof e != "object" || Array.isArray(e)) && n("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(e)}`);
1518
+ let t = {}, i = {};
1519
+ for (let [n, r] of Object.entries(e)) (Me.includes(n) ? t : i)[n] = r;
1520
+ e.children && n("chart()", "a chart makes its own children - add other nodes to a Group beside it"), super(t), je(), this.#e = i, this.#i = {}, this.#f(!0), this.onUpdate((e, t) => this.#_(t));
1521
1521
  }
1522
1522
  get spec() {
1523
1523
  let e = this.#t;
@@ -1544,7 +1544,7 @@ var Z = class e extends h {
1544
1544
  }, this.#f(!0), this;
1545
1545
  }
1546
1546
  filter(e) {
1547
- return e !== null && typeof e != "function" && l("Chart", `filter() takes (row) => boolean, or null, got ${u(e)}`), this.#c = e, this.#f(!0), this;
1547
+ return e !== null && typeof e != "function" && n("Chart", `filter() takes (row) => boolean, or null, got ${r(e)}`), this.#c = e, this.#f(!0), this;
1548
1548
  }
1549
1549
  explain() {
1550
1550
  let e = this.#t, t = [
@@ -1596,24 +1596,24 @@ var Z = class e extends h {
1596
1596
  return m.userData = structuredClone(this.userData), m.matrixAutoUpdate = this.matrixAutoUpdate, m.matrixAutoUpdate || m.matrix.copy(this.matrix), m;
1597
1597
  }
1598
1598
  #f(e) {
1599
- let t = Se(this.#e), n = t.options, r = t.channels;
1599
+ let t = Se(this.#e), r = t.options, i = t.channels;
1600
1600
  this.#t = t;
1601
- let a = n.box ?? Ie(t), o = n.theme ?? "dark";
1602
- o !== "dark" && o !== "light" && l("chart()", `theme '${o}' - expected 'dark' or 'light'`);
1603
- let s = n.overlap ?? "dim";
1601
+ let o = r.box ?? Ie(t), s = r.theme ?? "dark";
1602
+ s !== "dark" && s !== "light" && n("chart()", `theme '${s}' - expected 'dark' or 'light'`);
1603
+ let c = r.overlap ?? "dim";
1604
1604
  [
1605
1605
  "dim",
1606
1606
  "hide",
1607
1607
  "show"
1608
- ].includes(s) || l("chart()", `overlap '${s}' - expected 'dim', 'hide' or 'show'`);
1609
- let c = t.rows.filter((e) => (!this.#c || this.#c(e)) && (!r.color?.field || !this.#s.has(String(r.color.get(e)))));
1610
- this.scales = Be(t, a);
1611
- let u = this.scales.color, d = v.fromInput(r.color?.field ? R.category[0] : r.color?.value ?? R.category[0], "chart()").toSRGB(), f = t.link.color?.field ? Re(t.link.color, t.links.map((e) => t.link.color.get(e))) : null;
1608
+ ].includes(c) || n("chart()", `overlap '${c}' - expected 'dim', 'hide' or 'show'`);
1609
+ let l = t.rows.filter((e) => (!this.#c || this.#c(e)) && (!i.color?.field || !this.#s.has(String(i.color.get(e)))));
1610
+ this.scales = Be(t, o);
1611
+ let u = this.scales.color, d = a.fromInput(i.color?.field ? R.category[0] : i.color?.value ?? R.category[0], "chart()").toSRGB(), f = t.link.color?.field ? Re(t.link.color, t.links.map((e) => t.link.color.get(e))) : null;
1612
1612
  Object.assign(this.#i, {
1613
1613
  spec: t,
1614
- box: a,
1615
- theme: o,
1616
- overlap: s,
1614
+ box: o,
1615
+ theme: s,
1616
+ overlap: c,
1617
1617
  scales: this.scales,
1618
1618
  size: this.scales.size ?? null,
1619
1619
  rgb: (e) => u ? u(ze(t, e)).toSRGB() : d,
@@ -1622,17 +1622,17 @@ var Z = class e extends h {
1622
1622
  });
1623
1623
  let p = JSON.stringify([
1624
1624
  t.mark,
1625
- Object.entries(r).map(([e, t]) => [
1625
+ Object.entries(i).map(([e, t]) => [
1626
1626
  e,
1627
1627
  t.field,
1628
1628
  t.type
1629
1629
  ]),
1630
- a,
1631
1630
  o,
1632
1631
  s,
1633
- n.stack,
1634
- n.layout,
1635
- n.flat,
1632
+ c,
1633
+ r.stack,
1634
+ r.layout,
1635
+ r.flat,
1636
1636
  Object.keys(t.link)
1637
1637
  ]);
1638
1638
  if (p !== this.#r) {
@@ -1640,45 +1640,45 @@ var Z = class e extends h {
1640
1640
  for (let e of this.#n.nodes) this.add(e);
1641
1641
  this.#l = this.#u = null, this.#d = null;
1642
1642
  }
1643
- this.#a && this.remove(this.#a), this.#a = t.mark === "network" && n.layout !== "given" ? null : this.add(C({
1644
- box: a,
1645
- theme: o,
1646
- overlap: s,
1643
+ this.#a && this.remove(this.#a), this.#a = t.mark === "network" && r.layout !== "given" ? null : this.add(C({
1644
+ box: o,
1645
+ theme: s,
1646
+ overlap: c,
1647
1647
  axes: He(t, this.scales)
1648
- })), this.#o && this.remove(this.#o), this.#o = n.title ? this.add(new i({
1649
- text: String(n.title),
1648
+ })), this.#o && this.remove(this.#o), this.#o = r.title ? this.add(new m({
1649
+ text: String(r.title),
1650
1650
  position: [
1651
1651
  0,
1652
- a[1] * 1.12,
1653
- -a[2] / 2
1652
+ o[1] * 1.12,
1653
+ -o[2] / 2
1654
1654
  ],
1655
- className: `phoria-axis-title phoria-${o}`,
1655
+ className: `phoria-axis-title phoria-${s}`,
1656
1656
  overlap: "show"
1657
- })) : null, this.#p(t, o), this.tooltip = t.tooltip === null && !t.link.tooltip ? null : (e) => this.#m(e);
1658
- let m = n.highlight;
1659
- this.highlight = m === !1 ? null : v.fromInput(m === void 0 || m === "neighbours" || m === "node" ? "#ffffff" : m, "chart()"), this.#h(this.#n.layout(c), e && n.transition !== !1);
1657
+ })) : null, this.#p(t, s), this.tooltip = t.tooltip === null && !t.link.tooltip ? null : (e) => this.#m(e);
1658
+ let h = r.highlight;
1659
+ this.highlight = h === !1 ? null : a.fromInput(h === void 0 || h === "neighbours" || h === "node" ? "#ffffff" : h, "chart()"), this.#h(this.#n.layout(l), e && r.transition !== !1);
1660
1660
  }
1661
1661
  #p(e, t) {
1662
1662
  this.overlay?.remove(), this.overlay = null;
1663
- let n = e.channels.color, r = e.options.legend;
1664
- if (!n?.field || r === !1 || !this.scales.color || typeof document > "u") return;
1665
- let i = ie(this.scales.color, {
1666
- title: n.title,
1663
+ let i = e.channels.color, a = e.options.legend;
1664
+ if (!i?.field || a === !1 || !this.scales.color || typeof document > "u") return;
1665
+ let o = ie(this.scales.color, {
1666
+ title: i.title,
1667
1667
  theme: t,
1668
- position: r?.position,
1669
- ticks: r?.ticks,
1670
- format: (e) => $(n, e),
1668
+ position: a?.position,
1669
+ ticks: a?.ticks,
1670
+ format: (e) => $(i, e),
1671
1671
  onToggle: (e, t) => {
1672
1672
  t ? this.#s.delete(String(e)) : this.#s.add(String(e)), this.#f(!0);
1673
1673
  }
1674
1674
  });
1675
- i.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1675
+ o.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1676
1676
  this.#s.has(String(this.scales.color?.domain[t])) && e.classList.add("off");
1677
1677
  });
1678
- let a = r?.container;
1679
- if (a) {
1680
- let e = typeof a == "string" ? document.querySelector(a) : a;
1681
- e || l("chart()", `legend container ${u(a)} not found`), i.classList.remove(`phoria-legend-${r?.position ?? "top-right"}`), Object.assign(i.style, {
1678
+ let s = a?.container;
1679
+ if (s) {
1680
+ let e = typeof s == "string" ? document.querySelector(s) : s;
1681
+ e || n("chart()", `legend container ${r(s)} not found`), o.classList.remove(`phoria-legend-${a?.position ?? "top-right"}`), Object.assign(o.style, {
1682
1682
  position: "static",
1683
1683
  flexDirection: "row",
1684
1684
  flexWrap: "wrap",
@@ -1686,8 +1686,8 @@ var Z = class e extends h {
1686
1686
  columnGap: "12px",
1687
1687
  maxHeight: "none",
1688
1688
  overflow: "visible"
1689
- }), e.replaceChildren(i);
1690
- } else this.overlay = i;
1689
+ }), e.replaceChildren(o);
1690
+ } else this.overlay = o;
1691
1691
  }
1692
1692
  #m(e) {
1693
1693
  let t = this.#t, n = e.datum;
@@ -1745,17 +1745,17 @@ var Z = class e extends h {
1745
1745
  #_(e) {
1746
1746
  let t = this.root.motionReduced === !0;
1747
1747
  t || this.#n?.tick?.(e);
1748
- let n = this.#d;
1749
- if (!n) return;
1750
- let r = this.#e.transition ?? {}, i = r.duration ?? .5, o = a[r.ease ?? "out"];
1751
- o || l("chart()", `transition ease '${r.ease}' - expected ${Object.keys(a).map((e) => `'${e}'`).join(", ")}`), n.t = t ? 1 : Math.min(1, n.t + e / i);
1752
- let s = o(n.t), c = new Float32Array(n.from.length);
1753
- for (let e = 0; e < c.length; e++) c[e] = n.from[e] + (n.to[e] - n.from[e]) * s;
1754
- if (n.t < 1) return this.#g(c, n.frame, n.frame);
1755
- this.#d = null, this.#g(n.final.state, n.final, n.final);
1748
+ let r = this.#d;
1749
+ if (!r) return;
1750
+ let i = this.#e.transition ?? {}, a = i.duration ?? .5, s = o[i.ease ?? "out"];
1751
+ s || n("chart()", `transition ease '${i.ease}' - expected ${Object.keys(o).map((e) => `'${e}'`).join(", ")}`), r.t = t ? 1 : Math.min(1, r.t + e / a);
1752
+ let c = s(r.t), l = new Float32Array(r.from.length);
1753
+ for (let e = 0; e < l.length; e++) l[e] = r.from[e] + (r.to[e] - r.from[e]) * c;
1754
+ if (r.t < 1) return this.#g(l, r.frame, r.frame);
1755
+ this.#d = null, this.#g(r.final.state, r.final, r.final);
1756
1756
  }
1757
1757
  };
1758
- m(Z);
1758
+ p(Z);
1759
1759
  function Pe(e, t) {
1760
1760
  let n = (e) => JSON.stringify(e ? {
1761
1761
  lengths: e.lengths,