phoria2 1.2.0 → 1.4.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 (69) hide show
  1. package/README.md +11 -9
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +527 -510
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +1760 -1170
  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 +60 -60
  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 +155 -155
  15. package/dist/gltf.js.map +1 -1
  16. package/dist/keyboard.js +188 -0
  17. package/dist/keyboard.js.map +1 -0
  18. package/dist/motion.js +35 -35
  19. package/dist/motion.js.map +1 -1
  20. package/dist/particles.js +187 -114
  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 +95 -62
  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 +27 -0
  30. package/dist/types/area.d.ts +18 -0
  31. package/dist/types/debug.d.ts +74 -0
  32. package/dist/types/explain.d.ts +4 -0
  33. package/dist/types/frame.d.ts +5 -0
  34. package/dist/types/geometry/Geometry.d.ts +16 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/material/Material.d.ts +67 -0
  37. package/dist/types/material/Texture.d.ts +18 -2
  38. package/dist/types/particles/Emitter.d.ts +39 -2
  39. package/dist/types/scene/drawables.d.ts +23 -2
  40. package/dist/types/watch.d.ts +8 -1
  41. package/dist/types/webgl/hooks.d.ts +48 -0
  42. package/dist/types/webgl/passes.d.ts +4 -0
  43. package/dist/types/webgl/programs.d.ts +15 -5
  44. package/dist/types/webgl/resources.d.ts +12 -2
  45. package/dist/types/webgl/shaders.d.ts +41 -5
  46. package/llms-full.txt +275 -1
  47. package/llms.txt +1 -1
  48. package/package.json +1 -1
  49. package/schema/scene.schema.json +75 -0
  50. package/src/View.js +121 -7
  51. package/src/area.js +131 -0
  52. package/src/charts/marks.js +29 -2
  53. package/src/debug.js +283 -0
  54. package/src/explain.js +19 -0
  55. package/src/frame.js +7 -2
  56. package/src/geometry/Geometry.js +16 -1
  57. package/src/index.js +1 -0
  58. package/src/material/Material.js +130 -4
  59. package/src/material/Texture.js +55 -2
  60. package/src/particles/Emitter.js +121 -10
  61. package/src/scene/drawables.js +89 -8
  62. package/src/watch.js +26 -3
  63. package/src/webgl/WebGLRenderer.js +55 -7
  64. package/src/webgl/hooks.js +121 -0
  65. package/src/webgl/passes.js +17 -2
  66. package/src/webgl/picking.js +45 -3
  67. package/src/webgl/programs.js +20 -9
  68. package/src/webgl/resources.js +169 -15
  69. package/src/webgl/shaders.js +545 -38
package/dist/charts.js CHANGED
@@ -1,266 +1,266 @@
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 { 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
- var v = .97, y = .08, b = /* @__PURE__ */ new Float32Array(16);
4
- function x(e, t, r) {
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;
3
+ var y = .97, b = .08, x = /* @__PURE__ */ new Float32Array(16);
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 S({ box: t, axes: n, theme: r, overlap: a }) {
15
- let [o, s, c] = t, u = 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
- }), d = (e) => x(u, e, s / 2), f = 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), b = m(n.z), S = (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 b) {
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
- C(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 b) {
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
- C(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
- C(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
- u.add(new e({
157
- geometry: new l({ positions: i }),
158
- material: { color: f },
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 * d(e)[m] > y
160
+ showFrom: (e) => -n * c(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) => {
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 = u.add(new h({ showFrom: (t) => {
174
- let n = d(t);
175
- return Math.abs(n[s]) < v && e.when(n);
167
+ ]) for (let t of [-1, 1]) x(e, t);
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), w),
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,
187
- position: e.title(w),
188
- place: r,
185
+ a.title && t.add(new m({
186
+ text: a.title,
187
+ position: e.title(C),
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"), u;
231
+ }))), "left"), s;
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, i = !1) {
243
243
  if (typeof e == "function") return e;
244
244
  if (e && typeof e == "object") {
245
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 && t("charts", `'format' must be Intl format options or a function, got ${r(e)}`), n;
248
+ return e !== void 0 && n("charts", `'format' must be Intl format options or a function, got ${r(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)) || n("charts", `'${t}' must be [min, max] numbers, got ${r(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,17 +268,17 @@ 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({
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
280
  domain: [Math.log10(i), Math.log10(a)],
281
- range: n
281
+ range: t
282
282
  }), s = ((e) => o(Math.log10(e)));
283
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 = [];
@@ -291,70 +291,70 @@ function A({ domain: e, range: n = [0, 1], format: r }) {
291
291
  r >= i * .999 && r <= a * 1.001 && e.push(r);
292
292
  }
293
293
  return e;
294
- }, s.format = E(r, (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
297
  }).format(e)), s;
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()) && 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
- 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) => {
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
425
  let t = c.get(String(e));
426
426
  return t === void 0 ? NaN : o + l * (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 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
- var L = {
430
+ var R = {
431
431
  category: [
432
432
  "#4e79a7",
433
433
  "#f28e2b",
@@ -476,12 +476,12 @@ 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: 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++;
@@ -489,20 +489,20 @@ function R({ domain: e, scheme: n, range: i, kind: a }) {
489
489
  return Math.min(1, Math.max(0, (r + i) / n));
490
490
  };
491
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);
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
495
  }), l.kind = "sequential", l.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
+ l = ((e) => c[(t.get(String(e)) ?? 0) % c.length].clone()), l.kind = "categorical", l.colors = () => e.map((e) => ({
499
499
  value: e,
500
500
  color: l(e)
501
501
  }));
502
502
  }
503
- return l.domain = e, l.range = s.map((e) => e.getStyle()), l;
503
+ return l.domain = e, l.range = c.map((e) => e.getStyle()), l;
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,39 +623,42 @@ 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 v({
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({
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
- labels: V(e, "above")
651
- }) : new _({
650
+ labels: H(e, "above")
651
+ }) : new s({
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
664
  let o = {
@@ -664,9 +667,9 @@ function se(e) {
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,7 +687,7 @@ 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 v({
688
691
  geometry: a.geometry,
689
692
  material: a.material,
690
693
  count: r * 2,
@@ -713,8 +716,8 @@ function se(e) {
713
716
  }
714
717
  let i = a.geometry;
715
718
  r > i.vertexCount && (a.geometry = G(r * 2));
716
- let c = a.geometry.positions, l = a.geometry.colors;
717
- 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);
718
721
  a.geometry.drawCount = r, a.geometry.needsUpdate(), a.geometry !== i && i.dispose();
719
722
  },
720
723
  enter(e) {
@@ -723,16 +726,30 @@ function se(e) {
723
726
  };
724
727
  return o;
725
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 l({ image: {
738
+ data: e,
739
+ width: 64,
740
+ height: 64
741
+ } });
742
+ }
726
743
  function G(e) {
727
- let t = new l({
744
+ let t = new h({
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) {
734
- let r = new e({
735
- geometry: new l({ positions: [
750
+ function de(e, t) {
751
+ let n = new g({
752
+ geometry: new h({ positions: [
736
753
  0,
737
754
  0,
738
755
  0,
@@ -745,16 +762,16 @@ function ce(t, n) {
745
762
  vertexColors: !0
746
763
  },
747
764
  pickable: !1
748
- }), i = new _({
765
+ }), r = new s({
749
766
  geometry: G(8),
750
767
  material: {
751
768
  size: 7,
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(e, "above")
773
+ }), i = t ? new u({
774
+ geometry: new h({ positions: [
758
775
  0,
759
776
  0,
760
777
  0,
@@ -774,24 +791,24 @@ function ce(t, n) {
774
791
  pickable: !1
775
792
  }) : null;
776
793
  return {
777
- nodes: a ? [
778
- a,
779
- r,
780
- i
781
- ] : [r, i],
782
- layout(e) {
783
- 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();
784
- for (let t of e) {
785
- let e = o ? String(o.get(t)) : "";
786
- 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);
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
- 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;
791
- t.spec.options.stack && l.set(c, u + s), d.set([
792
- 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),
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
  }
@@ -802,22 +819,22 @@ function ce(t, n) {
802
819
  stride: 4,
803
820
  shape: {
804
821
  lengths: c.map((e) => e.length),
805
- colors: c.map((e) => t.rgb(e[0]))
822
+ colors: c.map((t) => e.rgb(t[0]))
806
823
  }
807
824
  };
808
825
  },
809
826
  apply(e, t) {
810
- let { lengths: n, colors: o } = t.shape, s = [], c = [], l = [], u = [], d = [], f = [], p = [], m = 0;
811
- 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) => {
812
829
  let r = o[n];
813
830
  for (let n = 0; n < t; n++, m++) {
814
- let [t, i, o, h] = e.subarray(m * 4, m * 4 + 4);
815
- 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) {
816
833
  let e = f.length / 3;
817
- 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);
818
835
  }
819
836
  }
820
- }), r.geometry = K(r.geometry, s.length ? {
837
+ }), n.geometry = K(n.geometry, s.length ? {
821
838
  positions: s,
822
839
  colors: c
823
840
  } : { positions: [
@@ -827,7 +844,7 @@ function ce(t, n) {
827
844
  0,
828
845
  0,
829
846
  0
830
- ] }), i.geometry = K(i.geometry, {
847
+ ] }), r.geometry = K(r.geometry, {
831
848
  positions: l.length ? l : [
832
849
  0,
833
850
  0,
@@ -838,7 +855,7 @@ function ce(t, n) {
838
855
  0,
839
856
  0
840
857
  ]
841
- }), 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 ? {
842
859
  positions: d,
843
860
  colors: f,
844
861
  indices: p
@@ -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 h(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 u({
881
+ geometry: new h({ positions: [
865
882
  0,
866
883
  0,
867
884
  0,
@@ -879,12 +896,12 @@ 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: 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;
885
902
  if (d > 0) {
886
903
  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]})`);
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]})`);
888
905
  }
889
906
  let f = [], p = new Float32Array(s.length * c.length * 6), m = 0;
890
907
  for (let t of c) for (let n of s) {
@@ -907,47 +924,47 @@ function le(e) {
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({
940
- 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({
941
958
  radius: 1,
942
959
  detail: 2
943
960
  }),
944
961
  material: { roughness: .35 },
945
- 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: [
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: [
951
968
  0,
952
969
  0,
953
970
  0,
@@ -956,59 +973,59 @@ function fe(n) {
956
973
  0
957
974
  ] }),
958
975
  material: {
959
- width: t,
976
+ width: e,
960
977
  vertexColors: !0
961
978
  },
962
979
  data: []
963
- })), v = new e({
964
- geometry: new l({ positions: [] }),
980
+ })), _ = new g({
981
+ geometry: new h({ 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 = o.flow ? new s({
989
+ geometry: new h({ positions: [] }),
973
990
  material: {
974
- size: .012 * Math.min(...n.box),
991
+ size: .012 * Math.min(...e.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
+ ...m,
998
+ _,
999
+ p,
983
1000
  ...y ? [y] : []
984
1001
  ],
985
- 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);
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);
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)), {
997
- rows: e,
998
- keys: i,
999
- state: c,
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
+ ], n * 7)), {
1014
+ rows: t,
1015
+ keys: a,
1016
+ state: u,
1000
1017
  stride: 7,
1001
- shape: { pairs: S.map((e) => [e[u], e[d]]) }
1018
+ shape: { pairs: S.map((e) => [e[c], e[l]]) }
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) => i(e) === w) && (w = null, _.visible = !1), n > p.instanceMatrices.length / 16) {
1024
+ let e = d(n * 2);
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;
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
+ p.count = n, p.data = t.rows;
1028
+ let r = t.rows.map(i), a = new Map(r.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
+ ]), p.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 s = 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 = a.get(e[c]), r = a.get(e[l]);
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 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({
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) => {
1065
+ }), m.forEach((e, t) => {
1049
1066
  let n = s[t];
1050
- e.geometry.dispose(), e.geometry = new l(n.positions.length ? {
1067
+ e.geometry.dispose(), e.geometry = new h(n.positions.length ? {
1051
1068
  positions: n.positions,
1052
1069
  colors: n.colors
1053
1070
  } : { positions: [
@@ -1070,67 +1087,67 @@ 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 h({ positions: t }));
1074
1091
  },
1075
1092
  tooltipRows(e) {
1076
- return g.includes(e.node) ? "link" : "node";
1093
+ return m.includes(e.node) ? "link" : "node";
1077
1094
  }
1078
- }, E = (i.highlight ?? "neighbours") === "neighbours";
1079
- E && h.on("hover", D);
1080
- 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])));
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
+ if (n !== w) {
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])));
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[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]);
1093
1110
  }
1094
- v.geometry.dispose(), v.geometry = new l({ positions: t });
1111
+ _.geometry.dispose(), _.geometry = new h({ 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(t, n) {
1114
+ if (w === null || !E) return n;
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();
1100
1117
  }
1101
- 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));
1118
+ function A(t) {
1119
+ let n = o.width;
1120
+ if (!n) return 0;
1121
+ if (n.field === null) return n.value >= 3.5 ? 2 : +(n.value >= 2);
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));
1107
1124
  }
1108
- 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();
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();
1111
1128
  }
1112
- 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;
1129
+ function M(t) {
1130
+ let n = o.flow;
1131
+ if (n.field === null) return .4;
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;
1117
1134
  }
1118
- function N(e, a, o) {
1119
- let [s, c, l] = n.box, u = i.layout ?? "force";
1135
+ function N(i, a, o) {
1136
+ let [s, c, l] = e.box, u = t.layout ?? "force";
1120
1137
  if (u === "given") {
1121
- let { x: t, y: r, z: i } = n.scales, a = n.spec.channels;
1122
- return e.map((e) => [
1138
+ let { x: t, y: n, z: r } = e.scales, a = e.spec.channels;
1139
+ return i.map((e) => [
1123
1140
  t && a.x ? t(a.x.get(e)) : 0,
1124
- r && a.y ? r(a.y.get(e)) : c / 2,
1125
- i && a.z ? i(a.z.get(e)) : 0
1141
+ n && a.y ? n(a.y.get(e)) : c / 2,
1142
+ r && a.z ? r(a.z.get(e)) : 0
1126
1143
  ]);
1127
1144
  }
1128
- if (u && typeof u == "object" && "tiers" in u) return pe(e, a, o, u, [
1145
+ if (u && typeof u == "object" && "tiers" in u) return ge(i, a, o, u, [
1129
1146
  s,
1130
1147
  c,
1131
1148
  l
1132
1149
  ]);
1133
- u !== "force" && t("chart()", `layout ${r(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1150
+ u !== "force" && n("chart()", `layout ${r(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1134
1151
  let d = P(a, o), f = [
1135
1152
  Infinity,
1136
1153
  Infinity,
@@ -1141,64 +1158,64 @@ 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(s, t.flat ? l : Math.min(c, l)) * .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
+ t.flat ? 0 : (e[1] - g[1]) * h + c / 2,
1148
1165
  (e[2] - g[2]) * h
1149
1166
  ]);
1150
1167
  }
1151
- function P(e, t) {
1152
- let n = e.length, r = ue(i.seed ?? 1), a = i.flat ? [0, 2] : [
1168
+ function P(e, n) {
1169
+ let r = e.length, i = pe(t.seed ?? 1), a = t.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) => 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
+ 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
+ l[e * r + e] = 0;
1179
+ for (let n = 0; n < t.length; 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));
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((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 ? [
1170
1187
  0,
1171
1188
  0,
1172
1189
  0
1173
- ] : f.get(e[o]), l = o === void 0 ? Math.sqrt(n) : .5;
1190
+ ] : u.get(e[o]), l = 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) * l,
1193
+ t.flat ? 0 : s[1] + (i() - .5) * l,
1194
+ s[2] + (i() - .5) * l
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 = 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;
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 u = 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]) {
1215
+ function ge(e, t, r, i, [a, o, s]) {
1199
1216
  let c = i.tiers;
1200
1217
  if (!e.length) return [];
1201
- c in e[0] || t("chart()", `layout: { tiers: '${c}' } - '${c}' isn't a node field`);
1218
+ c in e[0] || n("chart()", `layout: { tiers: '${c}' } - '${c}' isn't a node field`);
1202
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;
1203
1220
  for (let t = 0; t < d; t++) {
1204
1221
  let n = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
@@ -1217,9 +1234,9 @@ function pe(e, n, r, i, [a, o, s]) {
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]) && n("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,143 +1333,143 @@ 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 = {};
1326
- for (let t of J) {
1327
- let n = e[t] ?? c[t];
1328
- n != null && (l[t] = X(t, n, i, s));
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));
1329
1346
  }
1330
- if (n === "network") for (let n of [
1347
+ if (a === "network") for (let e 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
+ ]) 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" ? [
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 = {};
1341
- 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)) [
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)) [
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(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));
1352
1369
  }
1353
1370
  let h = {};
1354
- for (let t of Y) !J.includes(t) && ![
1371
+ for (let e of Y) !J.includes(e) && ![
1355
1372
  "mark",
1356
1373
  "data",
1357
1374
  "encoding",
1358
1375
  "tooltip",
1359
1376
  "link"
1360
- ].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,
1363
- rows: i,
1364
- links: o,
1365
- fields: s,
1366
- channels: l,
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,
1367
1384
  tooltip: p,
1368
1385
  link: m,
1369
1386
  options: h
1370
1387
  };
1371
1388
  }
1372
- function be(e) {
1373
- let n = e;
1374
- 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`);
1376
- n = n.type;
1389
+ function Ce(e) {
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;
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 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)}`}`);
1381
1398
  }
1382
- return n;
1399
+ return t;
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 && 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)}`), {
1386
1403
  rows: e.nodes,
1387
1404
  links: e.links
1388
1405
  };
1389
1406
  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 }"), {
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 }"), {
1391
1408
  rows: i,
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)}`);
1407
- 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" && [
1408
1425
  "size",
1409
1426
  "opacity",
1410
1427
  "link.width",
1411
1428
  "link.opacity",
1412
1429
  "link.flow"
1413
- ].includes(e)) s = { value: n };
1414
- 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");
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");
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(u) || n(s, `${e}: type '${u}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${i(String(u), [
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 = l === null ? () => c.value : u === "temporal" ? (e) => L(e[l]) : (e) => e[l];
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: 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
+ get: d,
1459
+ priority: c.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 || 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)}`);
1447
1464
  }
1448
- function Te(e) {
1465
+ function Oe(e) {
1449
1466
  try {
1450
- return c.fromInput(e), !0;
1467
+ return a.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
- var Z = class e extends h {
1498
+ var Z = class e extends _ {
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)) && 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));
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" && n("Chart", `filter() takes (row) => boolean, or null, got ${r(e)}`), this.#c = e, this.#f(!0), this;
1531
1548
  }
1532
1549
  explain() {
1533
1550
  let e = this.#t, t = [
@@ -1579,56 +1596,56 @@ 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), r = t.options, i = t.channels;
1600
+ this.#t = t;
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";
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(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;
1595
1612
  Object.assign(this.#i, {
1596
- spec: n,
1613
+ spec: t,
1597
1614
  box: o,
1598
1615
  theme: s,
1599
- overlap: l,
1616
+ overlap: c,
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(i).map(([e, t]) => [
1609
1626
  e,
1610
1627
  t.field,
1611
1628
  t.type
1612
1629
  ]),
1613
1630
  o,
1614
1631
  s,
1615
- l,
1632
+ c,
1616
1633
  r.stack,
1617
1634
  r.layout,
1618
1635
  r.flat,
1619
- Object.keys(n.link)
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({
1643
+ this.#a && this.remove(this.#a), this.#a = t.mark === "network" && r.layout !== "given" ? null : this.add(C({
1627
1644
  box: o,
1628
1645
  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({
1646
+ overlap: c,
1647
+ axes: He(t, this.scales)
1648
+ })), this.#o && this.remove(this.#o), this.#o = r.title ? this.add(new m({
1632
1649
  text: String(r.title),
1633
1650
  position: [
1634
1651
  0,
@@ -1637,17 +1654,17 @@ var Z = class e extends h {
1637
1654
  ],
1638
1655
  className: `phoria-axis-title phoria-${s}`,
1639
1656
  overlap: "show"
1640
- })) : null, this.#p(n, s), this.tooltip = n.tooltip === null && !n.link.tooltip ? null : (e) => this.#m(e);
1657
+ })) : null, this.#p(t, s), this.tooltip = t.tooltip === null && !t.link.tooltip ? null : (e) => this.#m(e);
1641
1658
  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);
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);
1643
1660
  }
1644
- #p(e, n) {
1661
+ #p(e, t) {
1645
1662
  this.overlay?.remove(), this.overlay = null;
1646
1663
  let i = e.channels.color, a = e.options.legend;
1647
1664
  if (!i?.field || a === !1 || !this.scales.color || typeof document > "u") return;
1648
1665
  let o = ie(this.scales.color, {
1649
1666
  title: i.title,
1650
- theme: n,
1667
+ theme: t,
1651
1668
  position: a?.position,
1652
1669
  ticks: a?.ticks,
1653
1670
  format: (e) => $(i, e),
@@ -1661,7 +1678,7 @@ var Z = class e extends h {
1661
1678
  let s = a?.container;
1662
1679
  if (s) {
1663
1680
  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, {
1681
+ e || n("chart()", `legend container ${r(s)} not found`), o.classList.remove(`phoria-legend-${a?.position ?? "top-right"}`), Object.assign(o.style, {
1665
1682
  position: "static",
1666
1683
  flexDirection: "row",
1667
1684
  flexWrap: "wrap",
@@ -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);
1746
+ let t = this.root.motionReduced === !0;
1747
+ t || this.#n?.tick?.(e);
1731
1748
  let r = this.#d;
1732
1749
  if (!r) return;
1733
1750
  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);
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);
1735
1752
  let c = s(r.t), l = new Float32Array(r.from.length);
1736
1753
  for (let e = 0; e < l.length; e++) l[e] = r.from[e] + (r.to[e] - r.from[e]) * c;
1737
1754
  if (r.t < 1) return this.#g(l, r.frame, r.frame);
1738
1755
  this.#d = null, this.#g(r.final.state, r.final, r.final);
1739
1756
  }
1740
1757
  };
1741
- m(Z);
1742
- function je(e, t) {
1758
+ p(Z);
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