phoria2 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -3
  2. package/dist/charts.js +476 -459
  3. package/dist/charts.js.map +1 -1
  4. package/dist/core.js +1192 -963
  5. package/dist/core.js.map +1 -1
  6. package/dist/edit.js +75 -75
  7. package/dist/edit.js.map +1 -1
  8. package/dist/explain.js +1 -1
  9. package/dist/gltf.js +84 -84
  10. package/dist/gltf.js.map +1 -1
  11. package/dist/keyboard.js +188 -0
  12. package/dist/keyboard.js.map +1 -0
  13. package/dist/motion.js +35 -35
  14. package/dist/motion.js.map +1 -1
  15. package/dist/particles.js +191 -118
  16. package/dist/particles.js.map +1 -1
  17. package/dist/passes.js +16 -16
  18. package/dist/passes.js.map +1 -1
  19. package/dist/phoria2.js +1 -1
  20. package/dist/picking.js +30 -14
  21. package/dist/picking.js.map +1 -1
  22. package/dist/snapshot.js +1 -1
  23. package/dist/tooltip.js +1 -1
  24. package/dist/types/View.d.ts +11 -0
  25. package/dist/types/area.d.ts +18 -0
  26. package/dist/types/geometry/Geometry.d.ts +16 -0
  27. package/dist/types/index.d.ts +2 -0
  28. package/dist/types/material/Material.d.ts +15 -0
  29. package/dist/types/material/Texture.d.ts +18 -2
  30. package/dist/types/particles/Emitter.d.ts +39 -2
  31. package/dist/types/scene/drawables.d.ts +23 -2
  32. package/dist/types/webgl/resources.d.ts +12 -2
  33. package/dist/types/webgl/shaders.d.ts +7 -2
  34. package/llms-full.txt +48 -1
  35. package/package.json +1 -1
  36. package/schema/scene.schema.json +48 -0
  37. package/src/View.js +16 -0
  38. package/src/area.js +131 -0
  39. package/src/charts/marks.js +29 -2
  40. package/src/geometry/Geometry.js +16 -1
  41. package/src/index.js +1 -0
  42. package/src/material/Material.js +9 -2
  43. package/src/material/Texture.js +55 -2
  44. package/src/particles/Emitter.js +121 -10
  45. package/src/scene/drawables.js +68 -4
  46. package/src/watch.js +8 -1
  47. package/src/webgl/WebGLRenderer.js +36 -5
  48. package/src/webgl/picking.js +22 -1
  49. package/src/webgl/resources.js +168 -14
  50. package/src/webgl/shaders.js +110 -11
package/dist/charts.js CHANGED
@@ -1,26 +1,26 @@
1
- import { $ as e, At as t, Ft as n, Ot as r, Q as i, Tt as a, V as o, Z as s, _t as c, ct as l, et as u, kt as d, l as f, m as p, n as m, nt as h, rt as g, tt as _ } from "./core.js";
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";
2
2
  // src/charts/axes.js
3
- var v = .97, y = .08, b = /* @__PURE__ */ new Float32Array(16);
4
- function x(e, t, r) {
3
+ var y = .97, b = .08, x = /* @__PURE__ */ new Float32Array(16);
4
+ function S(e, t, n) {
5
5
  let i = t.worldPosition;
6
- n(b, e.worldMatrix);
7
- let a = b[0] * i[0] + b[4] * i[1] + b[8] * i[2] + b[12], o = b[1] * i[0] + b[5] * i[1] + b[9] * i[2] + b[13] - r, s = b[2] * i[0] + b[6] * i[1] + b[10] * i[2] + b[14], c = Math.hypot(a, o, s) || 1;
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;
8
8
  return [
9
9
  a / c,
10
10
  o / c,
11
11
  s / c
12
12
  ];
13
13
  }
14
- function S({ box: t, axes: n, theme: r, overlap: a }) {
15
- let [o, s, c] = t, u = new h({
14
+ function C({ box: t, axes: n, theme: r, overlap: a }) {
15
+ let [o, s, c] = t, l = new h({
16
16
  name: "axes",
17
17
  pickable: !1
18
- }), d = (e) => x(u, e, s / 2), f = r === "light" ? "#c3c8d2" : "#3a3d47", p = (e) => {
18
+ }), u = (e) => S(l, e, s / 2), d = r === "light" ? "#c3c8d2" : "#3a3d47", p = (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), b = m(n.z), S = (t, r) => {
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
24
  let i = [], a = (e, t) => i.push(...e, ...t), p = (e) => r < 0 ? -e / 2 : e / 2;
25
25
  if (t === "y") {
26
26
  let e = r < 0 ? 0 : s;
@@ -36,7 +36,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
36
36
  c / 2
37
37
  ]);
38
38
  }
39
- for (let t of b) {
39
+ for (let t of v) {
40
40
  let r = n.z.scale(t);
41
41
  a([
42
42
  -o / 2,
@@ -48,7 +48,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
48
48
  r
49
49
  ]);
50
50
  }
51
- C(a, [
51
+ w(a, [
52
52
  -o / 2,
53
53
  e,
54
54
  -c / 2
@@ -79,7 +79,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
79
79
  c / 2
80
80
  ]);
81
81
  }
82
- for (let t of b) {
82
+ for (let t of v) {
83
83
  let r = n.z.scale(t);
84
84
  a([
85
85
  e,
@@ -91,7 +91,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
91
91
  r
92
92
  ]);
93
93
  }
94
- C(a, [
94
+ w(a, [
95
95
  e,
96
96
  0,
97
97
  -c / 2
@@ -134,7 +134,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
134
134
  e
135
135
  ]);
136
136
  }
137
- C(a, [
137
+ w(a, [
138
138
  -o / 2,
139
139
  0,
140
140
  e
@@ -153,30 +153,30 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
153
153
  ]);
154
154
  }
155
155
  let m = "xyz".indexOf(t);
156
- u.add(new e({
157
- geometry: new l({ positions: i }),
158
- material: { color: f },
156
+ l.add(new e({
157
+ geometry: new f({ positions: i }),
158
+ material: { color: d },
159
159
  pickable: !1,
160
- showFrom: (e) => -r * d(e)[m] > y
160
+ showFrom: (e) => -r * u(e)[m] > b
161
161
  }));
162
162
  };
163
163
  for (let e of [
164
164
  "x",
165
165
  "y",
166
166
  "z"
167
- ]) for (let t of [-1, 1]) S(e, t);
168
- let w = Math.max(o, s, c) * .04, T = (e) => `phoria-axis-${e} phoria-${r}`, E = (e, t, r) => {
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
169
  let o = n[e];
170
170
  if (!o || o.channel?.axis === !1) return;
171
171
  let s = "xyz".indexOf(e), c = p(o);
172
172
  for (let e of t) {
173
- let t = u.add(new h({ showFrom: (t) => {
174
- let n = d(t);
175
- return Math.abs(n[s]) < v && e.when(n);
173
+ let t = l.add(new h({ showFrom: (t) => {
174
+ let n = u(t);
175
+ return Math.abs(n[s]) < y && e.when(n);
176
176
  } }));
177
177
  for (let n of c) t.add(new i({
178
178
  text: o.scale.format(n),
179
- position: e.at(o.scale(n), w),
179
+ position: e.at(o.scale(n), C),
180
180
  place: r,
181
181
  className: T("tick"),
182
182
  priority: 1,
@@ -184,7 +184,7 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
184
184
  }));
185
185
  o.title && t.add(new i({
186
186
  text: o.title,
187
- position: e.title(w),
187
+ position: e.title(C),
188
188
  place: r,
189
189
  className: T("title"),
190
190
  priority: 2,
@@ -228,39 +228,39 @@ function S({ box: t, axes: n, theme: r, overlap: a }) {
228
228
  s + n * 2,
229
229
  t * c / 2
230
230
  ]
231
- }))), "left"), u;
231
+ }))), "left"), l;
232
232
  }
233
- function C(e, t, n, r, i) {
233
+ function w(e, t, n, r, i) {
234
234
  e(t, n), e(n, r), e(r, i), e(i, t);
235
235
  }
236
236
  // src/charts/scales.js
237
- var w = Math.log(10);
238
- function T(e, t) {
239
- let n = e / Math.max(1, t), r = 10 ** Math.floor(Math.log(n) / w), i = n / r;
237
+ var T = Math.log(10);
238
+ function E(e, t) {
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 E(e, n, i = !1) {
242
+ function D(e, t, n = !1) {
243
243
  if (typeof e == "function") return e;
244
244
  if (e && typeof e == "object") {
245
- let t = i ? new Intl.DateTimeFormat(void 0, e) : new Intl.NumberFormat(void 0, e);
245
+ let t = n ? 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 && t("charts", `'format' must be Intl format options or a function, got ${r(e)}`), n;
248
+ return e !== void 0 && l("charts", `'format' must be Intl format options or a function, got ${u(e)}`), t;
249
249
  }
250
- function D(e, t) {
251
- let n = Math.max(0, Math.min(6, -Math.floor(Math.log(e || 1) / w))), r = new Intl.NumberFormat(void 0, { maximumFractionDigits: n }), i = new Intl.NumberFormat(void 0, {
250
+ function O(e, t) {
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, {
252
252
  notation: "compact",
253
253
  maximumFractionDigits: 1
254
254
  }), a = Math.abs(t) >= 1e4 && e >= Math.abs(t) / 100;
255
255
  return (e) => (a ? i : r).format(e);
256
256
  }
257
- function O(e, n) {
258
- return Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number" && Number.isFinite(e)) || t("charts", `'${n}' must be [min, max] numbers, got ${r(e)}`), [e[0], e[1]];
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]];
259
259
  }
260
- function k({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i = !1, format: a }) {
261
- let [o, s] = O(e, "domain"), [c, l] = O(t, "range");
260
+ function A({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i = !1, format: a }) {
261
+ let [o, s] = k(e, "domain"), [c, l] = k(t, "range");
262
262
  if (r && (o = Math.min(0, o), s = Math.max(0, s)), o === s && (o -= o ? Math.abs(o) * .5 : 1, s += s ? Math.abs(s) * .5 : 1), n) {
263
- let e = T(s - o, 5);
263
+ let e = E(s - o, 5);
264
264
  o = Math.floor(o / e) * e, s = Math.ceil(s / e) * e;
265
265
  }
266
266
  let u = (l - c) / (s - o), d = ((e) => {
@@ -268,93 +268,93 @@ function k({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i
268
268
  return i ? Math.min(Math.max(t, Math.min(c, l)), Math.max(c, l)) : t;
269
269
  });
270
270
  return d.kind = "linear", d.domain = [o, s], d.range = [c, l], d.invert = (e) => o + (e - c) / u, d.ticks = (e = 5) => {
271
- let t = T(s - o, e), n = [];
271
+ let t = E(s - o, e), n = [];
272
272
  for (let e = Math.ceil(o / t) * t; e <= s + t * 1e-9; e += t) n.push(+e.toFixed(12));
273
273
  return n;
274
- }, d.format = E(a, D(T(s - o, 5), Math.max(Math.abs(o), Math.abs(s)))), d;
274
+ }, d.format = D(a, O(E(s - o, 5), Math.max(Math.abs(o), Math.abs(s)))), d;
275
275
  }
276
- function A({ domain: e, range: n = [0, 1], format: r }) {
277
- let [i, a] = O(e, "domain");
278
- (i <= 0 || a <= 0) && t("charts", `a log scale needs a domain above 0, got [${i}, ${a}] - use a linear scale for zero or negative values`);
279
- let o = k({
280
- domain: [Math.log10(i), Math.log10(a)],
281
- range: n
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 = () => {
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)],
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 = () => {
284
284
  let e = [];
285
- for (let t = Math.floor(Math.log10(i)); t <= Math.ceil(Math.log10(a)); t++) for (let n of [
285
+ for (let t = Math.floor(Math.log10(r)); t <= Math.ceil(Math.log10(i)); t++) for (let n of [
286
286
  1,
287
287
  2,
288
288
  5
289
289
  ]) {
290
- let r = n * 10 ** t;
291
- r >= i * .999 && r <= a * 1.001 && e.push(r);
290
+ let a = n * 10 ** t;
291
+ a >= r * .999 && a <= i * 1.001 && e.push(a);
292
292
  }
293
293
  return e;
294
- }, s.format = E(r, (e) => new Intl.NumberFormat(void 0, {
294
+ }, o.format = D(n, (e) => new Intl.NumberFormat(void 0, {
295
295
  notation: "compact",
296
296
  maximumFractionDigits: 1
297
- }).format(e)), s;
297
+ }).format(e)), o;
298
298
  }
299
- var j = 1e3, M = 60 * j, N = 60 * M, P = 24 * N, F = [
300
- [j, "s"],
301
- [5 * j, "s"],
302
- [15 * j, "s"],
303
- [30 * j, "s"],
304
- [M, "m"],
305
- [5 * M, "m"],
306
- [15 * M, "m"],
307
- [30 * M, "m"],
308
- [N, "h"],
309
- [3 * N, "h"],
310
- [6 * N, "h"],
311
- [12 * N, "h"],
312
- [P, "d"],
313
- [2 * P, "d"],
314
- [7 * P, "w"],
315
- [30 * P, "M"],
316
- [91 * P, "Q"],
317
- [365 * P, "Y"]
299
+ var M = 1e3, N = 60 * M, P = 60 * N, F = 24 * P, I = [
300
+ [M, "s"],
301
+ [5 * M, "s"],
302
+ [15 * M, "s"],
303
+ [30 * M, "s"],
304
+ [N, "m"],
305
+ [5 * N, "m"],
306
+ [15 * N, "m"],
307
+ [30 * N, "m"],
308
+ [P, "h"],
309
+ [3 * P, "h"],
310
+ [6 * P, "h"],
311
+ [12 * P, "h"],
312
+ [F, "d"],
313
+ [2 * F, "d"],
314
+ [7 * F, "w"],
315
+ [30 * F, "M"],
316
+ [91 * F, "Q"],
317
+ [365 * F, "Y"]
318
318
  ], ee = {
319
319
  s: [
320
320
  (e) => e.getSeconds(),
321
321
  (e, t) => e.setSeconds(t),
322
- j
322
+ M
323
323
  ],
324
324
  m: [
325
325
  (e) => e.getMinutes(),
326
326
  (e, t) => e.setMinutes(t),
327
- M
327
+ N
328
328
  ],
329
329
  h: [
330
330
  (e) => e.getHours(),
331
331
  (e, t) => e.setHours(t),
332
- N
332
+ P
333
333
  ],
334
334
  d: [
335
335
  (e) => e.getDate(),
336
336
  (e, t) => e.setDate(t),
337
- P
337
+ F
338
338
  ],
339
339
  w: [
340
340
  (e) => e.getDate(),
341
341
  (e, t) => e.setDate(t),
342
- P
342
+ F
343
343
  ],
344
344
  M: [
345
345
  (e) => e.getMonth(),
346
346
  (e, t) => e.setMonth(t),
347
- 30 * P
347
+ 30 * F
348
348
  ],
349
349
  Q: [
350
350
  (e) => e.getMonth(),
351
351
  (e, t) => e.setMonth(t),
352
- 30 * P
352
+ 30 * F
353
353
  ],
354
354
  Y: [
355
355
  (e) => e.getFullYear(),
356
356
  (e, t) => e.setFullYear(t),
357
- 365 * P
357
+ 365 * F
358
358
  ]
359
359
  }, te = {
360
360
  s: {
@@ -388,15 +388,15 @@ var j = 1e3, M = 60 * j, N = 60 * M, P = 24 * N, F = [
388
388
  },
389
389
  Y: { year: "numeric" }
390
390
  };
391
- function I(e) {
392
- let n = e instanceof Date ? e : new Date(e);
393
- return Number.isNaN(n.getTime()) && t("charts", `${r(e)} isn't a date - use Date objects, timestamps or ISO strings like '2026-10-25'`), n;
391
+ function L(e) {
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;
394
394
  }
395
395
  function ne({ domain: e, range: t = [0, 1], format: n }) {
396
- let r = I(e[0]).getTime(), i = I(e[1]).getTime(), a = k({
396
+ let r = L(e[0]).getTime(), i = L(e[1]).getTime(), a = A({
397
397
  domain: [r, i],
398
398
  range: t
399
- }), o = Math.max(1, i - r), s = (e) => F.find(([t]) => o / t <= e) ?? F[F.length - 1], c = ((e) => a(I(e).getTime()));
399
+ }), o = Math.max(1, i - r), s = (e) => I.find(([t]) => o / t <= e) ?? I[I.length - 1], c = ((e) => a(L(e).getTime()));
400
400
  c.kind = "time", c.domain = [new Date(r), new Date(i)], c.range = a.range, c.invert = (e) => new Date(a.invert?.(e)), c.ticks = (e = 5) => {
401
401
  let [t, n] = s(e), [a, c, l] = ee[n], u = Math.max(1, Math.round(t / l));
402
402
  if (n === "Y") {
@@ -417,17 +417,17 @@ function ne({ domain: e, range: t = [0, 1], format: n }) {
417
417
  return p;
418
418
  };
419
419
  let l = new Intl.DateTimeFormat(void 0, te[s(6)[1]]);
420
- return c.format = E(n, (e) => l.format(I(e)), !0), c;
420
+ return c.format = D(n, (e) => l.format(L(e)), !0), c;
421
421
  }
422
- function re({ domain: e, range: n = [0, 1], padding: i = .2, format: a }) {
423
- Array.isArray(e) || t("charts", `a band scale's domain is a list of categories, got ${r(e)}`);
424
- let [o, s] = O(n, "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);
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);
427
427
  });
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 = E(a, (e) => String(e)), u;
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;
429
429
  }
430
- var L = {
430
+ var R = {
431
431
  category: [
432
432
  "#4e79a7",
433
433
  "#f28e2b",
@@ -476,33 +476,33 @@ var L = {
476
476
  "#2166ac"
477
477
  ]
478
478
  };
479
- function R({ domain: e, scheme: n, range: i, kind: a }) {
480
- n !== void 0 && !(n in L) && t("charts", `colour scheme '${n}' isn't one we have - use ${Object.keys(L).map((e) => `'${e}'`).join(", ")}, or a range of colours`);
481
- let o = a ? a === "sequential" : e.length === 2 && e.every((e) => typeof e == "number");
482
- o && (e.length < 2 || e.some((e) => typeof e != "number")) && t("charts", `a sequential colour scale needs two or more numbers in its domain, got ${r(e)}`);
483
- let s = (i ?? L[n ?? (o ? "viridis" : "category")]).map((e) => c.fromInput(e, "charts")), l;
484
- if (o) {
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) {
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
- l = ((e) => {
492
- if (s.length < 2) return s[0].clone();
493
- let n = t(e) * (s.length - 1), r = Math.min(s.length - 2, Math.floor(n));
494
- return s[r].clone().lerp(s[r + 1], n - r);
495
- }), l.kind = "sequential", l.colors = () => [];
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 = () => [];
496
496
  } else {
497
497
  let t = new Map(e.map((e, t) => [String(e), t]));
498
- l = ((e) => s[(t.get(String(e)) ?? 0) % s.length].clone()), l.kind = "categorical", l.colors = () => e.map((e) => ({
498
+ o = ((e) => a[(t.get(String(e)) ?? 0) % a.length].clone()), o.kind = "categorical", o.colors = () => e.map((e) => ({
499
499
  value: e,
500
- color: l(e)
500
+ color: o(e)
501
501
  }));
502
502
  }
503
- return l.domain = e, l.range = s.map((e) => e.getStyle()), l;
503
+ return o.domain = e, o.range = a.map((e) => e.getStyle()), o;
504
504
  }
505
- function z(e) {
505
+ function B(e) {
506
506
  let t = [...new Map(e.map((e) => [e instanceof Date ? e.getTime() : e, e])).values()];
507
507
  return typeof t[0] == "number" || t[0] instanceof Date ? t.sort((e, t) => +e - t) : t;
508
508
  }
@@ -520,7 +520,7 @@ function ie(e, { title: t, theme: n, position: r = "top-right", format: i, ticks
520
520
  r.className = "phoria-legend-swatch", r.style.background = n.getStyle(), e.append(r, i(t)), e.addEventListener("click", () => o?.(t, !e.classList.toggle("off"))), s.append(e);
521
521
  }
522
522
  else {
523
- let t = e.domain[0], n = e.domain[e.domain.length - 1], r = k({
523
+ let t = e.domain[0], n = e.domain[e.domain.length - 1], r = A({
524
524
  domain: [t, n],
525
525
  range: [0, 100]
526
526
  }), o = document.createElement("div");
@@ -543,12 +543,12 @@ function ie(e, { title: t, theme: n, position: r = "top-right", format: i, ticks
543
543
  return s;
544
544
  }
545
545
  // src/charts/marks.js
546
- function B(e, t, n) {
546
+ function V(e, t, n) {
547
547
  let r = e.x?.get(t);
548
548
  return `${r instanceof Date ? r.getTime() : r}|${e.z ? e.z.get(t) : ""}|${n < 0 ? "-" : "+"}`;
549
549
  }
550
550
  var ae = (e) => `phoria-value phoria-${e.theme}`;
551
- function V(e, t) {
551
+ function H(e, t) {
552
552
  let n = e.spec.channels.label;
553
553
  if (!n) return null;
554
554
  let r = n.priority, i = typeof r == "function" ? r : typeof r == "string" ? (e) => Number(e[r]) || 0 : r ?? 0;
@@ -561,21 +561,21 @@ function V(e, t) {
561
561
  overlap: e.overlap
562
562
  };
563
563
  }
564
- var H = (e, t, n) => e && t ? e(t.get(n)) : 0;
564
+ var U = (e, t, n) => e && t ? e(t.get(n)) : 0;
565
565
  function oe(e) {
566
- let t = U(64, e), n = {
566
+ let t = se(64, e), n = {
567
567
  nodes: [t],
568
568
  layout(t) {
569
569
  let { x: n, y: r, z: i } = e.scales, a = e.spec.channels, o = e.spec.options.width ?? .7, s = (n.bandwidth ?? e.box[0] / 20) * o / .8, c = i?.bandwidth === void 0 ? Math.min(s, e.box[2] * .8) : i.bandwidth * o / .8, l = r(Math.max(r.domain[0], Math.min(0, r.domain[1]))), u = /* @__PURE__ */ new Map(), d = new Float32Array(t.length * 9);
570
570
  return t.forEach((t, o) => {
571
571
  let f = Number(a.y.get(t)) || 0, p = l, m = r(f);
572
572
  if (e.spec.options.stack) {
573
- let e = B(a, t, f), n = u.get(e) ?? 0;
573
+ let e = V(a, t, f), n = u.get(e) ?? 0;
574
574
  p = r(n), m = r(n + f), u.set(e, n + f);
575
575
  }
576
576
  d.set([
577
- H(n, a.x, t),
578
- H(i, a.z, t),
577
+ U(n, a.x, t),
578
+ U(i, a.z, t),
579
579
  p,
580
580
  m,
581
581
  s,
@@ -584,7 +584,7 @@ function oe(e) {
584
584
  ], o * 9);
585
585
  }), {
586
586
  rows: t,
587
- keys: W(e, t),
587
+ keys: ce(e, t),
588
588
  state: d,
589
589
  stride: 9
590
590
  };
@@ -592,7 +592,7 @@ function oe(e) {
592
592
  apply(r, i) {
593
593
  let a = r.length / i.stride;
594
594
  if (a > t.instanceMatrices.length / 16) {
595
- let r = U(a * 2, e);
595
+ let r = se(a * 2, e);
596
596
  t.parent?.add(r), t.parent?.remove(t), t.dispose(), n.nodes[0] = t = r;
597
597
  }
598
598
  t.count = a, t.data = i.rows;
@@ -623,50 +623,53 @@ function oe(e) {
623
623
  };
624
624
  return n;
625
625
  }
626
- function U(e, t) {
627
- let n = new s({
628
- geometry: f(1),
626
+ function se(e, t) {
627
+ let n = new o({
628
+ geometry: d(1),
629
629
  material: { roughness: .55 },
630
630
  count: e,
631
- labels: V(t, "above")
631
+ labels: H(t, "above")
632
632
  });
633
633
  return n.count = 0, n;
634
634
  }
635
- function W(e, t) {
635
+ function ce(e, t) {
636
636
  let n = e.spec.channels.key;
637
637
  return n ? t.map((e) => n.get(e)) : t.length && t[0] && "id" in t[0] ? t.map((e) => e.id) : t.map((e, t) => t);
638
638
  }
639
- function se(e) {
639
+ 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 s({
643
+ }, a = t ? new o({
644
644
  geometry: p({
645
645
  radius: 1,
646
646
  detail: 1
647
647
  }),
648
648
  material: i,
649
649
  count: 64,
650
- labels: V(e, "above")
650
+ labels: H(e, "above")
651
651
  }) : new _({
652
652
  geometry: G(64),
653
653
  material: {
654
654
  size: e.spec.channels.size?.value ?? n * 1.4,
655
655
  vertexColors: !0,
656
+ map: ue(),
657
+ depthWrite: !1,
656
658
  ...i
657
659
  },
658
- labels: V(e, "above")
660
+ sort: !0,
661
+ labels: H(e, "above")
659
662
  });
660
663
  t && (a.count = 0);
661
- let o = {
664
+ let s = {
662
665
  nodes: [a],
663
666
  layout(n) {
664
667
  let { x: r, y: i, z: a } = e.scales, o = e.spec.channels, s = t ? 7 : 6, c = new Float32Array(n.length * s);
665
668
  return n.forEach((n, l) => {
666
669
  let u = [
667
- H(r, o.x, n),
668
- H(i, o.y, n),
669
- H(a, o.z, n)
670
+ U(r, o.x, n),
671
+ U(i, o.y, n),
672
+ U(a, o.z, n)
670
673
  ];
671
674
  c.set(t ? [
672
675
  ...u,
@@ -675,7 +678,7 @@ function se(e) {
675
678
  ] : [...u, ...e.rgb(n)], l * s);
676
679
  }), {
677
680
  rows: n,
678
- keys: W(e, n),
681
+ keys: ce(e, n),
679
682
  state: c,
680
683
  stride: s
681
684
  };
@@ -684,13 +687,13 @@ function se(e) {
684
687
  let r = e.length / n.stride;
685
688
  if (a.data = n.rows, t) {
686
689
  if (r > a.instanceMatrices.length / 16) {
687
- let e = new s({
690
+ let e = new o({
688
691
  geometry: a.geometry,
689
692
  material: a.material,
690
693
  count: r * 2,
691
694
  labels: a.labels
692
695
  });
693
- a.parent?.add(e), a.parent?.remove(a), o.nodes[0] = a = e;
696
+ a.parent?.add(e), a.parent?.remove(a), s.nodes[0] = a = e;
694
697
  }
695
698
  a.count = r;
696
699
  for (let t = 0; t < r; t++) {
@@ -721,18 +724,32 @@ function se(e) {
721
724
  t ? e[3] = 0 : e[1] = 0;
722
725
  }
723
726
  };
724
- return o;
727
+ return s;
728
+ }
729
+ var W = null;
730
+ function ue() {
731
+ if (W) return W;
732
+ let e = /* @__PURE__ */ new Uint8Array(16384);
733
+ for (let t = 0; t < 64; t++) for (let n = 0; n < 64; n++) {
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
+ e[o] = e[o + 1] = e[o + 2] = Math.round(i * 255), e[o + 3] = Math.round(a * 255);
736
+ }
737
+ return W = new g({ image: {
738
+ data: e,
739
+ width: 64,
740
+ height: 64
741
+ } });
725
742
  }
726
743
  function G(e) {
727
- let t = new l({
744
+ let t = new f({
728
745
  positions: new Float32Array(e * 3),
729
746
  colors: new Float32Array(e * 3)
730
747
  });
731
748
  return t.drawCount = 0, t;
732
749
  }
733
- function ce(t, n) {
750
+ function de(t, n) {
734
751
  let r = new e({
735
- geometry: new l({ positions: [
752
+ geometry: new f({ positions: [
736
753
  0,
737
754
  0,
738
755
  0,
@@ -752,9 +769,9 @@ function ce(t, n) {
752
769
  sizeAttenuation: !1,
753
770
  vertexColors: !0
754
771
  },
755
- labels: V(t, "above")
756
- }), a = n ? new u({
757
- geometry: new l({ positions: [
772
+ labels: H(t, "above")
773
+ }), a = n ? new s({
774
+ geometry: new f({ positions: [
758
775
  0,
759
776
  0,
760
777
  0,
@@ -787,11 +804,11 @@ function ce(t, n) {
787
804
  }
788
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;
789
806
  for (let e of c) for (let o of e) {
790
- let e = a.x.get(o), s = Number(a.y.get(o)) || 0, c = B(a, o, s), u = t.spec.options.stack ? l.get(c) ?? 0 : 0;
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;
791
808
  t.spec.options.stack && l.set(c, u + s), d.set([
792
809
  n(e),
793
810
  r(u + s),
794
- H(i, a.z, o),
811
+ U(i, a.z, o),
795
812
  r(u)
796
813
  ], f * 4), f++;
797
814
  }
@@ -857,11 +874,11 @@ function ce(t, n) {
857
874
  };
858
875
  }
859
876
  function K(e, t) {
860
- return e.dispose(), new l(t);
877
+ return e.dispose(), new f(t);
861
878
  }
862
- function le(e) {
863
- let n = new u({
864
- geometry: new l({ positions: [
879
+ function fe(e) {
880
+ let t = new s({
881
+ geometry: new f({ positions: [
865
882
  0,
866
883
  0,
867
884
  0,
@@ -879,21 +896,21 @@ function le(e) {
879
896
  }
880
897
  });
881
898
  return {
882
- nodes: [n],
883
- layout(n) {
884
- let { x: r, y: i, z: a } = e.scales, o = e.spec.channels, s = z(n.map((e) => o.x.get(e))), c = z(n.map((e) => o.z.get(e))), l = new Map(n.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;
899
+ nodes: [t],
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;
885
902
  if (d > 0) {
886
- let e = s.flatMap((e) => c.map((t) => [e, t])).find(([e, t]) => !u(e, t));
887
- t("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]})`);
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]})`);
888
905
  }
889
- let f = [], p = new Float32Array(s.length * c.length * 6), m = 0;
890
- for (let t of c) for (let n of s) {
891
- let s = u(n, t);
892
- f.push(s), p.set([
893
- r(n),
894
- i(Number(o.y.get(s)) || 0),
895
- a(t),
896
- ...e.rgb(s)
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)
897
914
  ], m++ * 6);
898
915
  }
899
916
  return {
@@ -902,52 +919,52 @@ function le(e) {
902
919
  state: p,
903
920
  stride: 6,
904
921
  shape: {
905
- nx: s.length,
906
- nz: c.length
922
+ nx: o.length,
923
+ nz: s.length
907
924
  }
908
925
  };
909
926
  },
910
- apply(e, t) {
911
- let { nx: r, nz: i } = t.shape, a = [], o = [], s = [];
927
+ apply(e, n) {
928
+ let { nx: r, nz: i } = n.shape, a = [], o = [], s = [];
912
929
  for (let t = 0; t < r * i; t++) a.push(...e.subarray(t * 6, t * 6 + 3)), o.push(...e.subarray(t * 6 + 3, t * 6 + 6));
913
930
  for (let e = 0; e < i - 1; e++) for (let t = 0; t < r - 1; t++) {
914
931
  let n = e * r + t, i = n + 1, a = n + r, o = a + 1;
915
932
  s.push(n, a, i, i, a, o);
916
933
  }
917
- n.geometry = K(n.geometry, {
934
+ t.geometry = K(t.geometry, {
918
935
  positions: a,
919
936
  colors: o,
920
937
  indices: s
921
- }), n.data = t.rows;
938
+ }), t.data = n.rows;
922
939
  }
923
940
  };
924
941
  }
925
942
  // src/charts/network.js
926
- function ue(e) {
943
+ function pe(e) {
927
944
  return () => {
928
945
  e = e + 1831565813 | 0;
929
946
  let t = Math.imul(e ^ e >>> 15, 1 | e);
930
947
  return t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t, ((t ^ t >>> 14) >>> 0) / 4294967296;
931
948
  };
932
949
  }
933
- var de = [
950
+ var me = [
934
951
  1.2,
935
952
  2.5,
936
953
  4.5
937
954
  ];
938
- function fe(n) {
939
- let i = n.spec.options, a = me(n), o = n.spec.link, u = i.source ?? "source", d = i.target ?? "target", f = /* @__PURE__ */ new Map(), m = (e) => new s({
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({
940
957
  geometry: p({
941
958
  radius: 1,
942
959
  detail: 2
943
960
  }),
944
961
  material: { roughness: .35 },
945
962
  count: e,
946
- labels: V(n, "above")
947
- }), h = m(Math.max(8, n.spec.rows.length * 2));
948
- h.count = 0;
949
- let g = de.map((t) => new e({
950
- geometry: new l({ positions: [
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: [
951
968
  0,
952
969
  0,
953
970
  0,
@@ -960,55 +977,55 @@ function fe(n) {
960
977
  vertexColors: !0
961
978
  },
962
979
  data: []
963
- })), v = new e({
964
- geometry: new l({ positions: [] }),
980
+ })), g = new e({
981
+ geometry: new f({ positions: [] }),
965
982
  material: {
966
983
  width: 4,
967
984
  color: "#7fd3ff"
968
985
  },
969
986
  pickable: !1,
970
987
  visible: !1
971
- }), y = o.flow ? new _({
972
- geometry: new l({ positions: [] }),
988
+ }), y = i.flow ? new _({
989
+ geometry: new f({ positions: [] }),
973
990
  material: {
974
- size: .012 * Math.min(...n.box),
991
+ size: .012 * Math.min(...t.box),
975
992
  color: "#bff0ff"
976
993
  },
977
994
  pickable: !1
978
995
  }) : null, b = [], x = [], S = [], C = [], w = null, T = {
979
996
  nodes: [
980
- ...g,
981
- v,
982
- h,
997
+ ...h,
998
+ g,
999
+ m,
983
1000
  ...y ? [y] : []
984
1001
  ],
985
1002
  layout(e) {
986
- let i = e.map(a), o = new Map(i.map((e, t) => [e, t]));
987
- S = n.spec.links.filter((e, i) => {
988
- let s = e[u], c = e[d];
989
- return (s === void 0 || c === void 0) && t("chart()", `link ${i} has no '${s === void 0 ? u : d}' - links name their ends with source: '${u}', target: '${d}' (set 'source' and 'target' to your field names)`), n.spec.rows.some((e) => a(e) === s) || t("chart()", `link ${i}: ${u} ${r(s)} names no node`), n.spec.rows.some((e) => a(e) === c) || t("chart()", `link ${i}: ${d} ${r(c)} names no node`), o.has(s) && o.has(c);
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);
990
1007
  });
991
- let s = N(e, i, S.map((e) => [o.get(e[u]), o.get(e[d])])), c = new Float32Array(e.length * 7);
992
- return e.forEach((e, t) => c.set([
993
- ...s[t],
994
- n.size ? n.size(n.spec.channels.size.get(e)) : .06 * Math.min(...n.box),
995
- ...n.rgb(e)
996
- ], t * 7)), {
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)
1013
+ ], n * 7)), {
997
1014
  rows: e,
998
- keys: i,
1015
+ keys: n,
999
1016
  state: c,
1000
1017
  stride: 7,
1001
- shape: { pairs: S.map((e) => [e[u], e[d]]) }
1018
+ shape: { pairs: S.map((e) => [e[a], e[s]]) }
1002
1019
  };
1003
1020
  },
1004
1021
  apply(e, t) {
1005
1022
  let n = e.length / t.stride;
1006
- if (C = t.rows, w !== null && !C.some((e) => a(e) === w) && (w = null, v.visible = !1), n > h.instanceMatrices.length / 16) {
1007
- let e = m(n * 2);
1008
- E && e.on("hover", D), h.parent?.add(e), h.parent?.remove(h), h.dispose(), T.nodes[T.nodes.indexOf(h)] = e, h = e;
1023
+ if (C = t.rows, w !== null && !C.some((e) => r(e) === w) && (w = null, g.visible = !1), n > m.instanceMatrices.length / 16) {
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;
1009
1026
  }
1010
- h.count = n, h.data = t.rows;
1011
- let r = t.rows.map(a), i = new Map(r.map((e, t) => [e, t]));
1027
+ m.count = n, m.data = t.rows;
1028
+ let o = t.rows.map(r), c = new Map(o.map((e, t) => [e, t]));
1012
1029
  x = [];
1013
1030
  for (let t = 0; t < n; t++) {
1014
1031
  let [n, r, i, a, o, s, c] = e.subarray(t * 7, t * 7 + 7);
@@ -1016,7 +1033,7 @@ function fe(n) {
1016
1033
  n,
1017
1034
  r,
1018
1035
  i
1019
- ]), h.setInstance(t, {
1036
+ ]), m.setInstance(t, {
1020
1037
  position: [
1021
1038
  n,
1022
1039
  r,
@@ -1030,24 +1047,24 @@ function fe(n) {
1030
1047
  ])
1031
1048
  });
1032
1049
  }
1033
- let s = de.map(() => ({
1050
+ let l = me.map(() => ({
1034
1051
  positions: [],
1035
1052
  colors: [],
1036
1053
  rows: []
1037
1054
  }));
1038
1055
  b = [], S.forEach((e, t) => {
1039
- let n = i.get(e[u]), r = i.get(e[d]);
1056
+ let n = c.get(e[a]), r = c.get(e[s]);
1040
1057
  if (n === void 0 || r === void 0) return;
1041
- let a = s[A(e)], c = j(e);
1042
- a.positions.push(...x[n], ...x[r]), a.colors.push(...c, ...c), a.rows.push(e), o.flow && b.push({
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({
1043
1060
  a: n,
1044
1061
  b: r,
1045
1062
  speed: M(e),
1046
1063
  phase: t * .618 % 1
1047
1064
  });
1048
- }), g.forEach((e, t) => {
1049
- let n = s[t];
1050
- e.geometry.dispose(), e.geometry = new l(n.positions.length ? {
1065
+ }), h.forEach((e, t) => {
1066
+ let n = l[t];
1067
+ e.geometry.dispose(), e.geometry = new f(n.positions.length ? {
1051
1068
  positions: n.positions,
1052
1069
  colors: n.colors
1053
1070
  } : { positions: [
@@ -1070,68 +1087,68 @@ function fe(n) {
1070
1087
  n.phase = (n.phase + e * n.speed) % 1;
1071
1088
  let i = x[n.a], a = x[n.b];
1072
1089
  for (let e = 0; e < 3; e++) t[r * 3 + e] = i[e] + (a[e] - i[e]) * n.phase;
1073
- }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new l({ positions: t }));
1090
+ }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new f({ positions: t }));
1074
1091
  },
1075
1092
  tooltipRows(e) {
1076
- return g.includes(e.node) ? "link" : "node";
1093
+ return h.includes(e.node) ? "link" : "node";
1077
1094
  }
1078
- }, E = (i.highlight ?? "neighbours") === "neighbours";
1079
- E && h.on("hover", D);
1095
+ }, E = (n.highlight ?? "neighbours") === "neighbours";
1096
+ E && m.on("hover", D);
1080
1097
  function D(e) {
1081
- let t = e && e.node === h && e.instance !== null ? a(C[e.instance]) : null;
1082
- if (t !== w) {
1083
- w = t, v.visible = t !== null, t !== null && O(t);
1084
- for (let e = 0; e < h.count; e++) h.setColor(e, k(e, n.rgb(C[e])));
1098
+ let n = e && e.node === m && e.instance !== null ? r(C[e.instance]) : null;
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])));
1085
1102
  }
1086
1103
  }
1087
1104
  function O(e) {
1088
1105
  let t = [];
1089
1106
  for (let n of S) {
1090
- if (n[u] !== e && n[d] !== e) continue;
1091
- let r = C.findIndex((e) => a(e) === n[u]), i = C.findIndex((e) => a(e) === n[d]);
1092
- r >= 0 && i >= 0 && t.push(...x[r], ...x[i]);
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]);
1093
1110
  }
1094
- v.geometry.dispose(), v.geometry = new l({ positions: t });
1111
+ g.geometry.dispose(), g.geometry = new f({ positions: t });
1095
1112
  }
1096
- function k(e, t) {
1097
- if (w === null || !E) return t;
1098
- let r = a(C[e]);
1099
- return r === w || S.some((e) => e[u] === w && e[d] === r || e[d] === w && e[u] === r) ? t : new c().setSRGB(t[0], t[1], t[2]).lerp(n.theme === "light" ? "#ffffff" : "#202024", .65).toSRGB();
1113
+ function k(e, n) {
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();
1100
1117
  }
1101
1118
  function A(e) {
1102
- let t = o.width;
1103
- if (!t) return 0;
1104
- if (t.field === null) return t.value >= 3.5 ? 2 : +(t.value >= 2);
1105
- let r = n.spec.links.map((e) => Number(t.get(e)) || 0), i = Math.max(...r) || 1;
1106
- return Math.min(2, Math.floor((Number(t.get(e)) || 0) / i * 2.999));
1119
+ let n = i.width;
1120
+ if (!n) return 0;
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));
1107
1124
  }
1108
1125
  function j(e) {
1109
- let t = o.color, r = n.theme === "light" ? "#9aa3b2" : "#4a5266";
1110
- return t ? t.field === null ? c.fromInput(t.value).toSRGB() : n.linkColor(t.get(e)).toSRGB() : c.fromInput(r).toSRGB();
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();
1111
1128
  }
1112
1129
  function M(e) {
1113
- let t = o.flow;
1114
- if (t.field === null) return .4;
1115
- let r = Math.max(...n.spec.links.map((e) => Number(t.get(e)) || 0)) || 1;
1116
- return .15 + .6 * (Number(t.get(e)) || 0) / r;
1130
+ let n = i.flow;
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;
1117
1134
  }
1118
- function N(e, a, o) {
1119
- let [s, c, l] = n.box, u = i.layout ?? "force";
1120
- if (u === "given") {
1121
- let { x: t, y: r, z: i } = n.scales, a = n.spec.channels;
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;
1122
1139
  return e.map((e) => [
1123
- t && a.x ? t(a.x.get(e)) : 0,
1124
- r && a.y ? r(a.y.get(e)) : c / 2,
1140
+ n && a.x ? n(a.x.get(e)) : 0,
1141
+ r && a.y ? r(a.y.get(e)) : o / 2,
1125
1142
  i && a.z ? i(a.z.get(e)) : 0
1126
1143
  ]);
1127
1144
  }
1128
- if (u && typeof u == "object" && "tiers" in u) return pe(e, a, o, u, [
1129
- s,
1130
- c,
1131
- l
1145
+ if (c && typeof c == "object" && "tiers" in c) return ge(e, r, i, c, [
1146
+ a,
1147
+ o,
1148
+ s
1132
1149
  ]);
1133
- u !== "force" && t("chart()", `layout ${r(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1134
- let d = P(a, o), f = [
1150
+ c !== "force" && l("chart()", `layout ${u(c)} - expected 'force', 'given' or { tiers: 'field' }`);
1151
+ let d = P(r, i), f = [
1135
1152
  Infinity,
1136
1153
  Infinity,
1137
1154
  Infinity
@@ -1141,85 +1158,85 @@ function fe(n) {
1141
1158
  -Infinity
1142
1159
  ];
1143
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]);
1144
- let m = Math.max(...p.map((e, t) => e - f[t]), 1e-6), h = Math.min(s, i.flat ? l : Math.min(c, l)) * .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(a, n.flat ? s : Math.min(o, s)) * .9 / m, g = p.map((e, t) => (e + f[t]) / 2);
1145
1162
  return d.map((e) => [
1146
1163
  (e[0] - g[0]) * h,
1147
- i.flat ? 0 : (e[1] - g[1]) * h + c / 2,
1164
+ n.flat ? 0 : (e[1] - g[1]) * h + o / 2,
1148
1165
  (e[2] - g[2]) * h
1149
1166
  ]);
1150
1167
  }
1151
1168
  function P(e, t) {
1152
- let n = e.length, r = ue(i.seed ?? 1), a = i.flat ? [0, 2] : [
1169
+ let r = e.length, i = pe(n.seed ?? 1), a = n.flat ? [0, 2] : [
1153
1170
  0,
1154
1171
  1,
1155
1172
  2
1156
- ], o = e.some((e) => f.has(e)), s = i.steps ?? (o ? 60 : 300), c = e.map(() => []);
1157
- for (let [e, n] of t) c[e].push(n), c[n].push(e);
1158
- let l = new Float32Array(n * n).fill(Infinity), u = 1;
1159
- for (let e = 0; e < n; e++) {
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;
1176
+ for (let e = 0; e < r; e++) {
1160
1177
  let t = [e];
1161
- l[e * n + e] = 0;
1162
- for (let r = 0; r < t.length; r++) {
1163
- let i = t[r], a = l[e * n + i] + 1;
1164
- for (let r of c[i]) l[e * n + r] === Infinity && (l[e * n + r] = a, u = Math.max(u, a), t.push(r));
1178
+ u[e * r + e] = 0;
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));
1165
1182
  }
1166
1183
  }
1167
- let d = e.map((t, a) => {
1168
- if (f.has(t)) return [...f.get(t)];
1169
- let o = c[a].find((t) => f.has(e[t])), s = o === void 0 ? [
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 ? [
1170
1187
  0,
1171
1188
  0,
1172
1189
  0
1173
- ] : f.get(e[o]), l = o === void 0 ? Math.sqrt(n) : .5;
1190
+ ] : c.get(e[o]), u = o === void 0 ? Math.sqrt(r) : .5;
1174
1191
  return [
1175
- s[0] + (r() - .5) * l,
1176
- i.flat ? 0 : s[1] + (r() - .5) * l,
1177
- s[2] + (r() - .5) * l
1192
+ s[0] + (i() - .5) * u,
1193
+ n.flat ? 0 : s[1] + (i() - .5) * u,
1194
+ s[2] + (i() - .5) * u
1178
1195
  ];
1179
1196
  }), p = [
1180
1197
  0,
1181
1198
  0,
1182
1199
  0
1183
1200
  ];
1184
- for (let e = 0; e < s; e++) for (let e = 0; e < n; e++) {
1201
+ for (let e = 0; e < s; e++) for (let e = 0; e < r; e++) {
1185
1202
  p.fill(0);
1186
1203
  let t = 0;
1187
- for (let r = 0; r < n; r++) {
1188
- if (e === r) continue;
1189
- let i = l[e * n + r], a = i === Infinity ? u + 1 : i, o = 1 / (a * a), s = d[e][0] - d[r][0], c = d[e][1] - d[r][1], f = d[e][2] - d[r][2], m = Math.hypot(s, c, f) || 1e-6;
1190
- p[0] += o * (d[r][0] + a * s / m), p[1] += o * (d[r][1] + a * c / m), p[2] += o * (d[r][2] + a * f / m), t += o;
1204
+ for (let n = 0; n < r; n++) {
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;
1191
1208
  }
1192
- if (t) for (let n of a) d[e][n] = p[n] / t;
1209
+ if (t) for (let n of a) f[e][n] = p[n] / t;
1193
1210
  }
1194
- return f = new Map(e.map((e, t) => [e, d[t]])), d;
1211
+ return c = new Map(e.map((e, t) => [e, f[t]])), f;
1195
1212
  }
1196
1213
  return T;
1197
1214
  }
1198
- function pe(e, n, r, i, [a, o, s]) {
1199
- let c = i.tiers;
1215
+ function ge(e, t, n, r, [i, a, o]) {
1216
+ let s = r.tiers;
1200
1217
  if (!e.length) return [];
1201
- c in e[0] || t("chart()", `layout: { tiers: '${c}' } - '${c}' isn't a node field`);
1202
- 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;
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;
1203
1220
  for (let t = 0; t < d; t++) {
1204
- let n = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
1205
- let i = r.filter(([t, n]) => t === e || n === e).map(([t, n]) => t === e ? n : t).filter((e) => u[e] < t);
1206
- return i.length ? i.reduce((e, t) => e + f[t], 0) / i.length : n.indexOf(e);
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);
1207
1224
  };
1208
- t > 0 && n.sort((e, t) => i(e) - i(t));
1209
- let a = n.length === 1 ? 0 : t === 0 ? m * .25 : m * (.35 + .65 * t / Math.max(1, d - 1));
1210
- n.forEach((e, r) => {
1211
- f[e] = (r + .5) / n.length * Math.PI * 2, p[e] = [
1212
- Math.cos(f[e]) * a,
1213
- o * (1 - t / Math.max(1, d - 1)),
1214
- Math.sin(f[e]) * a
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
1215
1232
  ];
1216
1233
  });
1217
1234
  }
1218
1235
  return p;
1219
1236
  }
1220
- function me(e) {
1221
- let n = e.spec.channels.key;
1222
- return n ? (e) => n.get(e) : (e.spec.rows.length && !("id" in e.spec.rows[0]) && t("chart()", "network nodes need an 'id' field, or key: 'yourIdField' - links name nodes by it"), (e) => e.id);
1237
+ function _e(e) {
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);
1223
1240
  }
1224
1241
  // src/charts/spec.js
1225
1242
  var q = [
@@ -1263,7 +1280,7 @@ var q = [
1263
1280
  "$schema",
1264
1281
  "description",
1265
1282
  ...J
1266
- ], he = [
1283
+ ], ve = [
1267
1284
  "field",
1268
1285
  "type",
1269
1286
  "title",
@@ -1273,7 +1290,7 @@ var q = [
1273
1290
  "value",
1274
1291
  "priority",
1275
1292
  "legend"
1276
- ], ge = {
1293
+ ], ye = {
1277
1294
  series: "phoria2 charts map fields to channels instead of listing series - e.g. { mark: 'bar', x: 'month', y: 'sales', color: 'region' }",
1278
1295
  xAxis: "axes come from the channels - use x: { field, axis: { title } }",
1279
1296
  yAxis: "axes come from the channels - use y: { field, axis: { title } }",
@@ -1293,7 +1310,7 @@ var q = [
1293
1310
  colors: "use color: { field, scale: { range: [...] } }",
1294
1311
  nodes: "a network's nodes and links go in data: { nodes, links }",
1295
1312
  links: "a network's nodes and links go in data: { nodes, links }"
1296
- }, _e = {
1313
+ }, be = {
1297
1314
  scatter: "point",
1298
1315
  scatter3d: "point",
1299
1316
  circle: "point",
@@ -1308,7 +1325,7 @@ var q = [
1308
1325
  ribbon: "area",
1309
1326
  lines: "line",
1310
1327
  rect: "bar"
1311
- }, ve = {
1328
+ }, xe = {
1312
1329
  overlap: "set overlap on the chart - { overlap: 'dim' | 'hide' | 'show' } - it applies to all the chart's labels",
1313
1330
  aggregate: "aggregate the rows first (e.g. sum per month) - charts draw rows as given",
1314
1331
  bin: "bin the rows first - charts draw rows as given",
@@ -1316,39 +1333,39 @@ var q = [
1316
1333
  sort: "sort with scale: { domain: [...] } in the order you want",
1317
1334
  stack: "stacking is the chart's option: stack: true"
1318
1335
  };
1319
- function ye(e) {
1320
- (!e || typeof e != "object" || Array.isArray(e)) && t("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(e)}`);
1321
- for (let n of Object.keys(e)) Y.includes(n) || t("chart()", `unknown option '${n}' - ${ge[n] ?? `expected ${Y.filter((e) => e[0] !== "$").join(", ")}${d(n, Y)}`}`);
1322
- typeof e.width == "number" && e.width > 1 && t("chart()", "'width' is a bar's share of its band (0-1); in Vega-Lite it is pixels - here the canvas sets the size");
1323
- let n = be(e.mark), { rows: i, links: o } = xe(e.data, n), s = Se(i), c = { ...e.encoding ?? {} };
1324
- for (let e of Object.keys(c)) !J.includes(e) && e !== "tooltip" && t("chart()", `encoding '${e}' isn't a channel we have - channels are ${J.join(", ")}, tooltip`);
1325
- let l = {};
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 = {};
1326
1343
  for (let t of J) {
1327
- let n = e[t] ?? c[t];
1328
- n != null && (l[t] = X(t, n, i, s));
1344
+ let n = e[t] ?? s[t];
1345
+ n != null && (c[t] = X(t, n, i, o));
1329
1346
  }
1330
- if (n === "network") for (let n of [
1347
+ if (r === "network") for (let t of [
1331
1348
  "x",
1332
1349
  "y",
1333
1350
  "z"
1334
- ]) l[n] && e.layout !== "given" && t("chart()", `${n} on a 'network' places its nodes - add layout: 'given' to use positions from the data`);
1335
- else for (let e of n === "surface" ? [
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" ? [
1336
1353
  "x",
1337
1354
  "z",
1338
1355
  "y"
1339
- ] : ["x", "y"]) l[e] || t("chart()", `a '${n}' chart needs ${e} - e.g. ${e}: '${s[0] ?? "field"}'`), n !== "point" && l[e].field === null && t("chart()", `${e} on a '${n}' chart lays its marks out along a scale - it needs a field, not a constant value - e.g. ${e}: '${s[0] ?? "field"}'`);
1340
- let u = e.tooltip ?? c.tooltip, f = typeof e.mark == "object" ? e.mark.tooltip : void 0, p = Ee(u ?? (f !== !1 && void 0), l, i, s), m = {};
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 = {};
1341
1358
  if (e.link !== void 0) {
1342
- n !== "network" && t("chart()", "'link' sets a network's link channels - it needs mark: 'network'");
1343
- let r = Se(o);
1344
- for (let [n, i] of Object.entries(e.link)) [
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)) [
1345
1362
  "width",
1346
1363
  "color",
1347
1364
  "opacity",
1348
1365
  "flow",
1349
1366
  "tooltip"
1350
- ].includes(n) || t("chart()", `link has no '${n}' - link channels are width, color, opacity, flow, tooltip`), n !== "tooltip" && (m[n] = X(`link.${n}`, i, o, r));
1351
- e.link.tooltip !== void 0 && (m.tooltip = Ee(e.link.tooltip, {}, o, r));
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));
1352
1369
  }
1353
1370
  let h = {};
1354
1371
  for (let t of Y) !J.includes(t) && ![
@@ -1358,101 +1375,101 @@ function ye(e) {
1358
1375
  "tooltip",
1359
1376
  "link"
1360
1377
  ].includes(t) && e[t] !== void 0 && (h[t] = e[t]);
1361
- return h.steps !== void 0 && (!Number.isInteger(h.steps) || h.steps < 1) && t("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 && a("chart()", "seed", h.seed), h.legend?.ticks !== void 0 && we("legend", h.legend.ticks), h.box === void 0 || Array.isArray(h.box) && h.box.length === 3 && h.box.every((e) => e > 0) || t("chart()", `'box' is the chart's size in the scene, [x, y, z] above 0, got ${r(h.box)}`), {
1362
- mark: n,
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,
1363
1380
  rows: i,
1364
- links: o,
1365
- fields: s,
1366
- channels: l,
1381
+ links: a,
1382
+ fields: o,
1383
+ channels: c,
1367
1384
  tooltip: p,
1368
1385
  link: m,
1369
1386
  options: h
1370
1387
  };
1371
1388
  }
1372
- function be(e) {
1389
+ function Ce(e) {
1373
1390
  let n = e;
1374
1391
  if (n && typeof n == "object") {
1375
- for (let e of Object.keys(n)) e !== "type" && e !== "tooltip" && t("chart()", `mark option '${e}' isn't supported - use the chart's options (width, stack, ...) or style the chart's nodes`);
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`);
1376
1393
  n = n.type;
1377
1394
  }
1378
- if (typeof n != "string" && t("chart()", `'mark' is required: one of ${q.map((e) => `'${e}'`).join(", ")}`), !q.includes(n)) {
1379
- let e = _e[n];
1380
- (n === "pie" || n === "arc" || n === "donut") && t("chart()", "pie and donut charts aren't supported - in 3D they distort values; use mark: 'bar'"), t("chart()", `mark '${n}' - ${e ? `use '${e}'` : `expected one of ${q.map((e) => `'${e}'`).join(", ")}${d(n, q)}`}`);
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)}`}`);
1381
1398
  }
1382
1399
  return n;
1383
1400
  }
1384
- function xe(e, n) {
1385
- if (e && typeof e == "object" && !Array.isArray(e) && "url" in e && t("chart()", "data: { url } isn't loaded for you - fetch the rows and pass data: rows"), n === "network") return e && Array.isArray(e.nodes) && Array.isArray(e.links) || t("chart()", `a network's data is { nodes: [...], links: [...] }, got ${r(e)}`), {
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)}`), {
1386
1403
  rows: e.nodes,
1387
1404
  links: e.links
1388
1405
  };
1389
- let i = Array.isArray(e) ? e : e && Array.isArray(e.values) ? e.values : null;
1390
- return i || t("chart()", `'data' must be an array of rows (objects), or { values: [...] }, got ${r(e)}`), i.some((e) => !e || typeof e != "object") && t("chart()", "every row in 'data' must be an object, such as { month: 'Jan', sales: 41 }"), {
1391
- rows: i,
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,
1392
1409
  links: []
1393
1410
  };
1394
1411
  }
1395
- function Se(e) {
1412
+ function Te(e) {
1396
1413
  let t = /* @__PURE__ */ new Set();
1397
1414
  for (let n of e.slice(0, 50)) for (let e of Object.keys(n)) t.add(e);
1398
1415
  return [...t];
1399
1416
  }
1400
- function Ce(e, t) {
1417
+ function Ee(e, t) {
1401
1418
  let n = e.find((e) => e[t] !== null && e[t] !== void 0)?.[t];
1402
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";
1403
1420
  }
1404
- function X(e, n, i, a) {
1405
- let o = "chart()", s;
1406
- if (typeof n == "string") a.includes(n) ? s = { field: n } : /color|colour/.test(e) && Te(n) ? s = { value: n } : t(o, `${e}: field '${n}' isn't in the data - fields are ${a.join(", ") || "(none)"}${d(n, a)}`);
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)}`);
1407
1424
  else if (typeof n == "number" && [
1408
1425
  "size",
1409
1426
  "opacity",
1410
1427
  "link.width",
1411
1428
  "link.opacity",
1412
1429
  "link.flow"
1413
- ].includes(e)) s = { value: n };
1430
+ ].includes(e)) o = { value: n };
1414
1431
  else if (n && typeof n == "object" && !Array.isArray(n)) {
1415
- s = n;
1416
- for (let n of Object.keys(s)) he.includes(n) || t(o, `${e}: '${n}' - ${ve[n] ?? `unknown; a channel takes ${he.join(", ")}`}`);
1417
- s.field !== void 0 && !a.includes(s.field) && t(o, `${e}: field '${s.field}' isn't in the data - fields are ${a.join(", ") || "(none)"}${d(String(s.field), a)}`), s.field === void 0 && s.value === void 0 && t(o, `${e} needs a field (or a constant value)`);
1418
- } else return e === "size" && Array.isArray(n) && t(o, "'size' is a channel - the chart's size in the scene is 'box: [x, y, z]'"), t(o, `${e} must be a field name or { field, ... }, got ${r(n)}`);
1419
- s.axis?.ticks !== void 0 && we(`${e}: axis`, s.axis.ticks);
1420
- let c = s.field ?? null, l = s.type ?? (c ? Ce(i, c) : "nominal");
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");
1421
1438
  [
1422
1439
  "quantitative",
1423
1440
  "nominal",
1424
1441
  "ordinal",
1425
1442
  "temporal"
1426
- ].includes(l) || t(o, `${e}: type '${l}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${d(String(l), [
1443
+ ].includes(c) || l(a, `${e}: type '${c}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${t(String(c), [
1427
1444
  "quantitative",
1428
1445
  "nominal",
1429
1446
  "ordinal",
1430
1447
  "temporal"
1431
1448
  ])}`);
1432
- let u = c === null ? () => s.value : l === "temporal" ? (e) => I(e[c]) : (e) => e[c];
1449
+ let d = s === null ? () => o.value : c === "temporal" ? (e) => L(e[s]) : (e) => e[s];
1433
1450
  return {
1434
- field: c,
1435
- value: s.value,
1436
- type: l,
1437
- title: s.title ?? c ?? e,
1438
- format: s.format,
1439
- scale: s.scale ?? {},
1440
- axis: s.axis ?? {},
1441
- get: u,
1442
- priority: s.priority
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 ?? {},
1458
+ get: d,
1459
+ priority: o.priority
1443
1460
  };
1444
1461
  }
1445
- function we(e, n) {
1446
- Array.isArray(n) || Number.isInteger(n) && n > 0 || t("chart()", `${e} ticks are a list of the values to mark, such as [0, 25, 50, 75, 100], or about how many, got ${r(n)}`);
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)}`);
1447
1464
  }
1448
- function Te(e) {
1465
+ function Oe(e) {
1449
1466
  try {
1450
- return c.fromInput(e), !0;
1467
+ return v.fromInput(e), !0;
1451
1468
  } catch {
1452
1469
  return !1;
1453
1470
  }
1454
1471
  }
1455
- function Ee(e, t, n, r) {
1472
+ function ke(e, t, n, r) {
1456
1473
  if (e === !1 || e === null) return null;
1457
1474
  if (typeof e == "function") return e;
1458
1475
  if (e === void 0 || e === !0) {
@@ -1463,25 +1480,25 @@ function Ee(e, t, n, r) {
1463
1480
  return i.map((e) => a(e) || X("tooltip", e, n, r));
1464
1481
  }
1465
1482
  // src/charts/style.js
1466
- var De = "\n/* ticks are bare text: the padding is breathing room, so the overlap the label layout allows never runs them together */\n:where(.phoria-axis-tick) { padding: 0 4px; color: #8b909c; font: 11px/1.2 system-ui, sans-serif; font-variant-numeric: tabular-nums; }\n:where(.phoria-axis-title) { color: #c8ccd4; font: 600 12px/1.2 system-ui, sans-serif; }\n:where(.phoria-value) { padding: 1px 5px; border-radius: 4px; background: rgba(16, 16, 20, 0.72); color: #eee;\n font: 11px/1.3 system-ui, sans-serif; font-variant-numeric: tabular-nums; }\n:where(.phoria-light.phoria-axis-tick) { color: #5d6370; }\n:where(.phoria-light.phoria-axis-title) { color: #2b2f37; }\n:where(.phoria-light.phoria-value) { background: rgba(255, 255, 255, 0.85); color: #222; }\n:where(.phoria-legend) { position: absolute; display: flex; flex-direction: column; gap: 3px; padding: 8px 10px;\n border-radius: 8px; background: rgba(20, 20, 24, 0.78); color: #e6e6e6; font: 12px/1.3 system-ui, sans-serif;\n pointer-events: auto; max-height: calc(100% - 24px); overflow: auto; }\n:where(.phoria-light.phoria-legend) { background: rgba(255, 255, 255, 0.88); color: #222; }\n:where(.phoria-legend-top-right) { top: 12px; right: 12px; }\n:where(.phoria-legend-top-left) { top: 12px; left: 12px; }\n:where(.phoria-legend-bottom-right) { bottom: 12px; right: 12px; }\n:where(.phoria-legend-bottom-left) { bottom: 12px; left: 12px; }\n:where(.phoria-legend-title) { opacity: 0.7; font-size: 11px; margin-bottom: 2px; }\n:where(.phoria-legend-item) { display: flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none;\n color: inherit; font: inherit; text-align: left; cursor: pointer; }\n:where(.phoria-legend-item.off) { opacity: 0.35; }\n:where(.phoria-legend-swatch) { width: 10px; height: 10px; border-radius: 2px; flex: none; }\n/* a number key is up to 140px tall and gives way in a short view, so the legend never scrolls; its\n values share one grid cell, so the widest sets the key's width, each raised to its place */\n:where(.phoria-legend-key) { display: flex; gap: 6px; margin: 6px 0; flex: 0 1 140px; min-height: 48px; }\n:where(.phoria-legend-ramp) { width: 10px; border-radius: 2px; flex: none; }\n:where(.phoria-legend-scale) { display: grid; font-size: 11px; font-variant-numeric: tabular-nums; }\n:where(.phoria-legend-scale > span) { grid-area: 1 / 1; align-self: end; position: relative; transform: translateY(50%);\n white-space: nowrap; opacity: 0.8; }\n";
1467
- function Oe() {
1483
+ var Ae = "\n/* ticks are bare text: the padding is breathing room, so the overlap the label layout allows never runs them together */\n:where(.phoria-axis-tick) { padding: 0 4px; color: #8b909c; font: 11px/1.2 system-ui, sans-serif; font-variant-numeric: tabular-nums; }\n:where(.phoria-axis-title) { color: #c8ccd4; font: 600 12px/1.2 system-ui, sans-serif; }\n:where(.phoria-value) { padding: 1px 5px; border-radius: 4px; background: rgba(16, 16, 20, 0.72); color: #eee;\n font: 11px/1.3 system-ui, sans-serif; font-variant-numeric: tabular-nums; }\n:where(.phoria-light.phoria-axis-tick) { color: #5d6370; }\n:where(.phoria-light.phoria-axis-title) { color: #2b2f37; }\n:where(.phoria-light.phoria-value) { background: rgba(255, 255, 255, 0.85); color: #222; }\n:where(.phoria-legend) { position: absolute; display: flex; flex-direction: column; gap: 3px; padding: 8px 10px;\n border-radius: 8px; background: rgba(20, 20, 24, 0.78); color: #e6e6e6; font: 12px/1.3 system-ui, sans-serif;\n pointer-events: auto; max-height: calc(100% - 24px); overflow: auto; }\n:where(.phoria-light.phoria-legend) { background: rgba(255, 255, 255, 0.88); color: #222; }\n:where(.phoria-legend-top-right) { top: 12px; right: 12px; }\n:where(.phoria-legend-top-left) { top: 12px; left: 12px; }\n:where(.phoria-legend-bottom-right) { bottom: 12px; right: 12px; }\n:where(.phoria-legend-bottom-left) { bottom: 12px; left: 12px; }\n:where(.phoria-legend-title) { opacity: 0.7; font-size: 11px; margin-bottom: 2px; }\n:where(.phoria-legend-item) { display: flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none;\n color: inherit; font: inherit; text-align: left; cursor: pointer; }\n:where(.phoria-legend-item.off) { opacity: 0.35; }\n:where(.phoria-legend-swatch) { width: 10px; height: 10px; border-radius: 2px; flex: none; }\n/* a number key is up to 140px tall and gives way in a short view, so the legend never scrolls; its\n values share one grid cell, so the widest sets the key's width, each raised to its place */\n:where(.phoria-legend-key) { display: flex; gap: 6px; margin: 6px 0; flex: 0 1 140px; min-height: 48px; }\n:where(.phoria-legend-ramp) { width: 10px; border-radius: 2px; flex: none; }\n:where(.phoria-legend-scale) { display: grid; font-size: 11px; font-variant-numeric: tabular-nums; }\n:where(.phoria-legend-scale > span) { grid-area: 1 / 1; align-self: end; position: relative; transform: translateY(50%);\n white-space: nowrap; opacity: 0.8; }\n";
1484
+ function je() {
1468
1485
  if (typeof document > "u" || document.getElementById("phoria-chart-style")) return;
1469
1486
  let e = document.createElement("style");
1470
- e.id = "phoria-chart-style", e.textContent = De, document.head.prepend(e);
1487
+ e.id = "phoria-chart-style", e.textContent = Ae, document.head.prepend(e);
1471
1488
  }
1472
1489
  // src/charts/Chart.js
1473
- var ke = g.filter((e) => ![
1490
+ var Me = c.filter((e) => ![
1474
1491
  "children",
1475
1492
  "tooltip",
1476
1493
  "highlight"
1477
1494
  ].includes(e));
1478
- function Ae(e) {
1495
+ function Ne(e) {
1479
1496
  return new Z(e);
1480
1497
  }
1481
1498
  var Z = class e extends h {
1482
1499
  static type = "chart";
1483
1500
  static get OPTIONS() {
1484
- return g;
1501
+ return c;
1485
1502
  }
1486
1503
  scales = {};
1487
1504
  #e;
@@ -1497,10 +1514,10 @@ var Z = class e extends h {
1497
1514
  #u = null;
1498
1515
  #d = null;
1499
1516
  constructor(e) {
1500
- (!e || typeof e != "object" || Array.isArray(e)) && t("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(e)}`);
1501
- let n = {}, i = {};
1502
- for (let [t, r] of Object.entries(e)) (ke.includes(t) ? n : i)[t] = r;
1503
- e.children && t("chart()", "a chart makes its own children - add other nodes to a Group beside it"), super(n), Oe(), this.#e = i, this.#i = {}, this.#f(!0), this.onUpdate((e, t) => this.#_(t));
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));
1504
1521
  }
1505
1522
  get spec() {
1506
1523
  let e = this.#t;
@@ -1527,7 +1544,7 @@ var Z = class e extends h {
1527
1544
  }, this.#f(!0), this;
1528
1545
  }
1529
1546
  filter(e) {
1530
- return e !== null && typeof e != "function" && t("Chart", `filter() takes (row) => boolean, or null, got ${r(e)}`), this.#c = e, this.#f(!0), this;
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;
1531
1548
  }
1532
1549
  explain() {
1533
1550
  let e = this.#t, t = [
@@ -1579,89 +1596,89 @@ var Z = class e extends h {
1579
1596
  return m.userData = structuredClone(this.userData), m.matrixAutoUpdate = this.matrixAutoUpdate, m.matrixAutoUpdate || m.matrix.copy(this.matrix), m;
1580
1597
  }
1581
1598
  #f(e) {
1582
- let n = ye(this.#e), r = n.options, a = n.channels;
1583
- this.#t = n;
1584
- let o = r.box ?? Ne(n), s = r.theme ?? "dark";
1585
- s !== "dark" && s !== "light" && t("chart()", `theme '${s}' - expected 'dark' or 'light'`);
1586
- let l = r.overlap ?? "dim";
1599
+ let t = Se(this.#e), n = t.options, r = t.channels;
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";
1587
1604
  [
1588
1605
  "dim",
1589
1606
  "hide",
1590
1607
  "show"
1591
- ].includes(l) || t("chart()", `overlap '${l}' - expected 'dim', 'hide' or 'show'`);
1592
- let u = n.rows.filter((e) => (!this.#c || this.#c(e)) && (!a.color?.field || !this.#s.has(String(a.color.get(e)))));
1593
- this.scales = Le(n, o);
1594
- let d = this.scales.color, f = c.fromInput(a.color?.field ? L.category[0] : a.color?.value ?? L.category[0], "chart()").toSRGB(), p = n.link.color?.field ? Fe(n.link.color, n.links.map((e) => n.link.color.get(e))) : null;
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;
1595
1612
  Object.assign(this.#i, {
1596
- spec: n,
1597
- box: o,
1598
- theme: s,
1599
- overlap: l,
1613
+ spec: t,
1614
+ box: a,
1615
+ theme: o,
1616
+ overlap: s,
1600
1617
  scales: this.scales,
1601
1618
  size: this.scales.size ?? null,
1602
- rgb: (e) => d ? d(Ie(n, e)).toSRGB() : f,
1619
+ rgb: (e) => u ? u(ze(t, e)).toSRGB() : d,
1603
1620
  format: $,
1604
- linkColor: (e) => p(e)
1621
+ linkColor: (e) => f(e)
1605
1622
  });
1606
- let m = JSON.stringify([
1607
- n.mark,
1608
- Object.entries(a).map(([e, t]) => [
1623
+ let p = JSON.stringify([
1624
+ t.mark,
1625
+ Object.entries(r).map(([e, t]) => [
1609
1626
  e,
1610
1627
  t.field,
1611
1628
  t.type
1612
1629
  ]),
1630
+ a,
1613
1631
  o,
1614
1632
  s,
1615
- l,
1616
- r.stack,
1617
- r.layout,
1618
- r.flat,
1619
- Object.keys(n.link)
1633
+ n.stack,
1634
+ n.layout,
1635
+ n.flat,
1636
+ Object.keys(t.link)
1620
1637
  ]);
1621
- if (m !== this.#r) {
1622
- this.#r = m, this.#n && this.remove(...this.#n.nodes), this.#n = Me(n.mark, this.#i);
1638
+ if (p !== this.#r) {
1639
+ this.#r = p, this.#n && this.remove(...this.#n.nodes), this.#n = Fe(t.mark, this.#i);
1623
1640
  for (let e of this.#n.nodes) this.add(e);
1624
1641
  this.#l = this.#u = null, this.#d = null;
1625
1642
  }
1626
- this.#a && this.remove(this.#a), this.#a = n.mark === "network" && r.layout !== "given" ? null : this.add(S({
1627
- box: o,
1628
- theme: s,
1629
- overlap: l,
1630
- axes: ze(n, this.scales)
1631
- })), this.#o && this.remove(this.#o), this.#o = r.title ? this.add(new i({
1632
- text: String(r.title),
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,
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),
1633
1650
  position: [
1634
1651
  0,
1635
- o[1] * 1.12,
1636
- -o[2] / 2
1652
+ a[1] * 1.12,
1653
+ -a[2] / 2
1637
1654
  ],
1638
- className: `phoria-axis-title phoria-${s}`,
1655
+ className: `phoria-axis-title phoria-${o}`,
1639
1656
  overlap: "show"
1640
- })) : null, this.#p(n, s), this.tooltip = n.tooltip === null && !n.link.tooltip ? null : (e) => this.#m(e);
1641
- let h = r.highlight;
1642
- this.highlight = h === !1 ? null : c.fromInput(h === void 0 || h === "neighbours" || h === "node" ? "#ffffff" : h, "chart()"), this.#h(this.#n.layout(u), e && r.transition !== !1);
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);
1643
1660
  }
1644
- #p(e, n) {
1661
+ #p(e, t) {
1645
1662
  this.overlay?.remove(), this.overlay = null;
1646
- let i = e.channels.color, a = e.options.legend;
1647
- if (!i?.field || a === !1 || !this.scales.color || typeof document > "u") return;
1648
- let o = ie(this.scales.color, {
1649
- title: i.title,
1650
- theme: n,
1651
- position: a?.position,
1652
- ticks: a?.ticks,
1653
- format: (e) => $(i, e),
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,
1667
+ theme: t,
1668
+ position: r?.position,
1669
+ ticks: r?.ticks,
1670
+ format: (e) => $(n, e),
1654
1671
  onToggle: (e, t) => {
1655
1672
  t ? this.#s.delete(String(e)) : this.#s.add(String(e)), this.#f(!0);
1656
1673
  }
1657
1674
  });
1658
- o.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1675
+ i.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1659
1676
  this.#s.has(String(this.scales.color?.domain[t])) && e.classList.add("off");
1660
1677
  });
1661
- let s = a?.container;
1662
- if (s) {
1663
- let e = typeof s == "string" ? document.querySelector(s) : s;
1664
- e || t("chart()", `legend container ${r(s)} not found`), o.classList.remove(`phoria-legend-${a?.position ?? "top-right"}`), Object.assign(o.style, {
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, {
1665
1682
  position: "static",
1666
1683
  flexDirection: "row",
1667
1684
  flexWrap: "wrap",
@@ -1669,8 +1686,8 @@ var Z = class e extends h {
1669
1686
  columnGap: "12px",
1670
1687
  maxHeight: "none",
1671
1688
  overflow: "visible"
1672
- }), e.replaceChildren(o);
1673
- } else this.overlay = o;
1689
+ }), e.replaceChildren(i);
1690
+ } else this.overlay = i;
1674
1691
  }
1675
1692
  #m(e) {
1676
1693
  let t = this.#t, n = e.datum;
@@ -1712,7 +1729,7 @@ var Z = class e extends h {
1712
1729
  keys: [...e.keys, ...d.map((e) => r.keys[e])],
1713
1730
  state: s
1714
1731
  };
1715
- } else if (r && i && i.length === e.state.length && r.stride === a && je(r.shape, e.shape)) o = i.slice(), s = e.state;
1732
+ } else if (r && i && i.length === e.state.length && r.stride === a && Pe(r.shape, e.shape)) o = i.slice(), s = e.state;
1716
1733
  else return this.#g(e.state, e, e);
1717
1734
  this.#d = {
1718
1735
  from: o,
@@ -1726,20 +1743,20 @@ var Z = class e extends h {
1726
1743
  this.#n.apply(e, t), this.#l = e.slice(), this.#u = n;
1727
1744
  }
1728
1745
  #_(e) {
1729
- let n = this.root.motionReduced === !0;
1730
- n || this.#n?.tick?.(e);
1731
- let r = this.#d;
1732
- if (!r) return;
1733
- let i = this.#e.transition ?? {}, a = i.duration ?? .5, s = o[i.ease ?? "out"];
1734
- s || t("chart()", `transition ease '${i.ease}' - expected ${Object.keys(o).map((e) => `'${e}'`).join(", ")}`), r.t = n ? 1 : Math.min(1, r.t + e / a);
1735
- let c = s(r.t), l = new Float32Array(r.from.length);
1736
- for (let e = 0; e < l.length; e++) l[e] = r.from[e] + (r.to[e] - r.from[e]) * c;
1737
- if (r.t < 1) return this.#g(l, r.frame, r.frame);
1738
- this.#d = null, this.#g(r.final.state, r.final, r.final);
1746
+ let t = this.root.motionReduced === !0;
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);
1739
1756
  }
1740
1757
  };
1741
1758
  m(Z);
1742
- function je(e, t) {
1759
+ function Pe(e, t) {
1743
1760
  let n = (e) => JSON.stringify(e ? {
1744
1761
  lengths: e.lengths,
1745
1762
  nx: e.nx,
@@ -1747,10 +1764,10 @@ function je(e, t) {
1747
1764
  } : null);
1748
1765
  return n(e) === n(t);
1749
1766
  }
1750
- function Me(e, t) {
1751
- return e === "bar" ? oe(t) : e === "point" ? se(t) : e === "line" || e === "area" ? ce(t, e === "area") : e === "surface" ? le(t) : fe(t);
1767
+ function Fe(e, t) {
1768
+ return e === "bar" ? oe(t) : e === "point" ? le(t) : e === "line" || e === "area" ? de(t, e === "area") : e === "surface" ? fe(t) : he(t);
1752
1769
  }
1753
- function Ne(e) {
1770
+ function Ie(e) {
1754
1771
  let t = !!e.channels.z;
1755
1772
  return e.mark === "surface" ? [
1756
1773
  10,
@@ -1782,29 +1799,29 @@ function Q(e) {
1782
1799
  }
1783
1800
  return t === Infinity ? [0, 1] : [t, n];
1784
1801
  }
1785
- function Pe(e) {
1802
+ function Le(e) {
1786
1803
  return {
1787
1804
  scheme: e.scale.scheme,
1788
1805
  range: e.scale.range
1789
1806
  };
1790
1807
  }
1791
- function Fe(e, t, n) {
1792
- return e.type === "quantitative" ? R({
1808
+ function Re(e, t, n) {
1809
+ return e.type === "quantitative" ? z({
1793
1810
  kind: "sequential",
1794
1811
  domain: e.scale.domain ?? Q(t),
1795
- ...Pe(e),
1812
+ ...Le(e),
1796
1813
  scheme: e.scale.scheme ?? n
1797
- }) : R({
1814
+ }) : z({
1798
1815
  kind: "categorical",
1799
- domain: e.scale.domain ?? z(t),
1800
- ...Pe(e)
1816
+ domain: e.scale.domain ?? B(t),
1817
+ ...Le(e)
1801
1818
  });
1802
1819
  }
1803
- function Ie(e, t) {
1820
+ function ze(e, t) {
1804
1821
  let n = e.channels.color;
1805
1822
  return n?.field ? n.get(t) : e.channels.y.get(t);
1806
1823
  }
1807
- function Le(e, t) {
1824
+ function Be(e, t) {
1808
1825
  let [n, r, i] = t, a = e.channels, o = e.rows, s = {}, c = {
1809
1826
  x: [-n / 2, n / 2],
1810
1827
  y: [0, r],
@@ -1822,22 +1839,22 @@ function Le(e, t) {
1822
1839
  format: (n.axis && n.axis.format) ?? n.format
1823
1840
  };
1824
1841
  if (n.type === "nominal" || n.type === "ordinal" || e.mark === "bar" && t !== "y") s[t] = re({
1825
- domain: n.scale.domain ?? z(i),
1842
+ domain: n.scale.domain ?? B(i),
1826
1843
  padding: .2,
1827
1844
  ...l
1828
1845
  });
1829
1846
  else if (n.type === "temporal") {
1830
- let [e, r] = Q(i.map((e) => I(e).getTime()));
1847
+ let [e, r] = Q(i.map((e) => L(e).getTime()));
1831
1848
  s[t] = ne({
1832
1849
  domain: n.scale.domain ?? [e, r],
1833
1850
  ...l
1834
1851
  });
1835
1852
  } else {
1836
1853
  let r = n.scale.domain ?? Q(i);
1837
- t === "y" && e.options.stack && (r = Q([0, ...Re(e)])), s[t] = n.scale.type === "log" ? A({
1854
+ t === "y" && e.options.stack && (r = Q([0, ...Ve(e)])), s[t] = n.scale.type === "log" ? j({
1838
1855
  domain: r,
1839
1856
  ...l
1840
- }) : k({
1857
+ }) : A({
1841
1858
  domain: r,
1842
1859
  nice: n.scale.nice ?? !0,
1843
1860
  zero: n.scale.zero ?? (t === "y" && ["bar", "area"].includes(e.mark)),
@@ -1848,27 +1865,27 @@ function Le(e, t) {
1848
1865
  let l = a.color;
1849
1866
  if (l?.field || e.mark === "surface") {
1850
1867
  let t = l?.field ? l : a.y, n = e.options.legend?.ticks;
1851
- s.color = Fe(t, [...o.map((e) => t.get(e)), ...t.type === "quantitative" && Array.isArray(n) ? n : []], e.mark === "surface" && !l?.field ? "viridis" : void 0);
1868
+ s.color = Re(t, [...o.map((e) => t.get(e)), ...t.type === "quantitative" && Array.isArray(n) ? n : []], e.mark === "surface" && !l?.field ? "viridis" : void 0);
1852
1869
  }
1853
1870
  let u = a.size;
1854
1871
  if (u?.field) {
1855
1872
  let n = Math.min(...t) / 40, r = e.mark === "network" ? [n * .6, n * 1.8] : [n * .5, n * 2];
1856
- s.size = k({
1873
+ s.size = A({
1857
1874
  domain: Q(o.map((e) => u.get(e))),
1858
1875
  range: u.scale.range ?? r
1859
1876
  });
1860
1877
  }
1861
1878
  return s;
1862
1879
  }
1863
- function Re(e) {
1880
+ function Ve(e) {
1864
1881
  let t = e.channels, n = /* @__PURE__ */ new Map();
1865
1882
  for (let r of e.rows) {
1866
- let e = Number(t.y.get(r)) || 0, i = B(t, r, e);
1883
+ let e = Number(t.y.get(r)) || 0, i = V(t, r, e);
1867
1884
  n.set(i, (n.get(i) ?? 0) + e);
1868
1885
  }
1869
1886
  return [...n.values()];
1870
1887
  }
1871
- function ze(e, t) {
1888
+ function He(e, t) {
1872
1889
  let n = {};
1873
1890
  for (let r of [
1874
1891
  "x",
@@ -1884,10 +1901,10 @@ function ze(e, t) {
1884
1901
  }
1885
1902
  return n;
1886
1903
  }
1887
- var Be = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }), Ve = new Intl.NumberFormat(void 0, {
1904
+ var Ue = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }), We = new Intl.NumberFormat(void 0, {
1888
1905
  notation: "compact",
1889
1906
  maximumFractionDigits: 1
1890
- }), He = new Intl.DateTimeFormat(void 0, {
1907
+ }), Ge = new Intl.DateTimeFormat(void 0, {
1891
1908
  year: "numeric",
1892
1909
  month: "short",
1893
1910
  day: "numeric"
@@ -1895,8 +1912,8 @@ var Be = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }), Ve = new I
1895
1912
  function $(e, t) {
1896
1913
  if (t == null) return "";
1897
1914
  let n = e.format;
1898
- return typeof n == "function" ? String(n(t)) : t instanceof Date ? n ? new Intl.DateTimeFormat(void 0, n).format(t) : He.format(t) : typeof t == "number" ? n ? new Intl.NumberFormat(void 0, n).format(t) : (Math.abs(t) >= 1e4 ? Ve : Be).format(t) : String(t);
1915
+ return typeof n == "function" ? String(n(t)) : t instanceof Date ? n ? new Intl.DateTimeFormat(void 0, n).format(t) : Ge.format(t) : typeof t == "number" ? n ? new Intl.NumberFormat(void 0, n).format(t) : (Math.abs(t) >= 1e4 ? We : Ue).format(t) : String(t);
1899
1916
  }
1900
- export { Z as Chart, L as SCHEMES, Ae as chart, $ as formatValue, re as scaleBand, R as scaleColor, k as scaleLinear, A as scaleLog, ne as scaleTime, T as tickStep };
1917
+ export { Z as Chart, R as SCHEMES, Ne as chart, $ as formatValue, re as scaleBand, z as scaleColor, A as scaleLinear, j as scaleLog, ne as scaleTime, E as tickStep };
1901
1918
 
1902
1919
  //# sourceMappingURL=charts.js.map