expressive-charts 0.2.0 → 0.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 (46) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +10 -10
  3. package/dist/define-DeZLs1h7.js +95 -0
  4. package/dist/define-DeZLs1h7.js.map +1 -0
  5. package/dist/drawing-Dz_IvJPB.d.cts +208 -0
  6. package/dist/drawing-Dz_IvJPB.d.ts +208 -0
  7. package/dist/effect-CdH5449m.d.ts +232 -0
  8. package/dist/effect-uYC8Vs6_.d.cts +232 -0
  9. package/dist/expressive-charts.css +8 -1
  10. package/dist/expressive-charts.css.d.cts +1 -0
  11. package/dist/expressive-charts.css.d.ts +1 -0
  12. package/dist/expressive-charts.global.js +50 -47
  13. package/dist/expressive-charts.global.js.map +1 -1
  14. package/dist/icons/sport.cjs +211 -152
  15. package/dist/icons/sport.cjs.map +1 -1
  16. package/dist/icons/sport.d.cts +5 -7
  17. package/dist/icons/sport.d.ts +5 -7
  18. package/dist/icons/sport.js +122 -71
  19. package/dist/icons/sport.js.map +1 -1
  20. package/dist/index.cjs +12647 -9513
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +929 -859
  23. package/dist/index.d.ts +929 -859
  24. package/dist/index.js +10452 -7822
  25. package/dist/index.js.map +1 -1
  26. package/dist/path-data-DnEckjY8.js +123 -0
  27. package/dist/path-data-DnEckjY8.js.map +1 -0
  28. package/dist/testing.cjs +2034 -1222
  29. package/dist/testing.cjs.map +1 -1
  30. package/dist/testing.d.cts +137 -141
  31. package/dist/testing.d.ts +137 -141
  32. package/dist/testing.js +696 -501
  33. package/dist/testing.js.map +1 -1
  34. package/dist/transition-DSRt2DH3.js +2053 -0
  35. package/dist/transition-DSRt2DH3.js.map +1 -0
  36. package/package.json +18 -6
  37. package/dist/chunk-CVXP2L2J.js +0 -1182
  38. package/dist/chunk-CVXP2L2J.js.map +0 -1
  39. package/dist/chunk-N5IF2RO2.js +0 -66
  40. package/dist/chunk-N5IF2RO2.js.map +0 -1
  41. package/dist/chunk-V5IUTXRW.js +0 -571
  42. package/dist/chunk-V5IUTXRW.js.map +0 -1
  43. package/dist/drawing-DWZIXIeR.d.cts +0 -194
  44. package/dist/drawing-DWZIXIeR.d.ts +0 -194
  45. package/dist/effect-CZUckY0l.d.ts +0 -245
  46. package/dist/effect-CcGdU41j.d.cts +0 -245
@@ -0,0 +1,2053 @@
1
+ import { a as TAU, c as boundsOf, f as pointOn, i as pathData, l as extremes, n as formatNumber, o as angleOn, p as polar, r as moveTo, s as arc, t as drawTo, u as line } from "./path-data-DnEckjY8.js";
2
+ // src/core/report.ts
3
+ function report(error) {
4
+ const platform = globalThis.reportError;
5
+ if (typeof platform === "function") platform(error);
6
+ else console.error(error);
7
+ }
8
+ // src/core/clock.ts
9
+ function createClock(source = browserFrames()) {
10
+ const callbacks = /* @__PURE__ */ new Set();
11
+ let cancelFrame;
12
+ const schedule = () => {
13
+ if (!cancelFrame && callbacks.size > 0) cancelFrame = source.request(tick);
14
+ };
15
+ const tick = (now) => {
16
+ cancelFrame = void 0;
17
+ for (const callback of [...callbacks]) {
18
+ if (!callbacks.has(callback)) continue;
19
+ try {
20
+ callback(now);
21
+ } catch (error) {
22
+ report(error);
23
+ }
24
+ }
25
+ schedule();
26
+ };
27
+ return {
28
+ now: () => source.now(),
29
+ onFrame(callback) {
30
+ const entry = (now) => callback(now);
31
+ callbacks.add(entry);
32
+ schedule();
33
+ return () => {
34
+ if (!callbacks.delete(entry)) return;
35
+ if (callbacks.size === 0 && cancelFrame) {
36
+ cancelFrame();
37
+ cancelFrame = void 0;
38
+ }
39
+ };
40
+ }
41
+ };
42
+ }
43
+ function manualClock(start = 0) {
44
+ let time = start;
45
+ let pending;
46
+ const clock = createClock({
47
+ now: () => time,
48
+ request(callback) {
49
+ pending = callback;
50
+ return () => {
51
+ if (pending === callback) pending = void 0;
52
+ };
53
+ }
54
+ });
55
+ return {
56
+ now: clock.now,
57
+ onFrame: clock.onFrame,
58
+ get idle() {
59
+ return pending === void 0;
60
+ },
61
+ advance(ms) {
62
+ if (!(ms >= 0)) throw new RangeError(`manualClock.advance needs a non-negative number of ms, got ${ms}`);
63
+ time += ms;
64
+ const callback = pending;
65
+ pending = void 0;
66
+ callback?.(time);
67
+ }
68
+ };
69
+ }
70
+ function browserFrames() {
71
+ const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
72
+ return {
73
+ now,
74
+ request(callback) {
75
+ if (typeof requestAnimationFrame === "function") {
76
+ const id = requestAnimationFrame(callback);
77
+ return () => cancelAnimationFrame(id);
78
+ }
79
+ const id = setTimeout(() => callback(now()), 16);
80
+ return () => clearTimeout(id);
81
+ }
82
+ };
83
+ }
84
+ const defaultClock = /* @__PURE__ */ createClock();
85
+ // src/core/easing.ts
86
+ const linear = (t) => t;
87
+ const easeInOutCubic = (t) => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
88
+ const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
89
+ function unease(s) {
90
+ return s < .5 ? Math.cbrt(s / 4) : 1 - Math.cbrt(2 * (1 - s)) / 2;
91
+ }
92
+ // src/core/motion.ts
93
+ const defaultScaling = {
94
+ presentation: {
95
+ feedback: { factor: 1 },
96
+ transition: { factor: 1 },
97
+ effect: { factor: 1 },
98
+ playback: { factor: 1 },
99
+ stagger: { factor: 1 }
100
+ },
101
+ analysis: {
102
+ feedback: { factor: 1 },
103
+ transition: {
104
+ factor: .35,
105
+ max: 200
106
+ },
107
+ effect: {
108
+ factor: .35,
109
+ min: 140,
110
+ max: 300
111
+ },
112
+ playback: { factor: .3 },
113
+ stagger: { factor: 0 }
114
+ }
115
+ };
116
+ const MODES = [
117
+ "presentation",
118
+ "analysis",
119
+ "off"
120
+ ];
121
+ const TIMINGS = [
122
+ "feedback",
123
+ "transition",
124
+ "effect",
125
+ "playback",
126
+ "stagger"
127
+ ];
128
+ function createMotion(options = {}) {
129
+ let requested = checkMode(options.mode ?? "presentation");
130
+ let viewerChoice;
131
+ const scaling = mergeScaling(options.scaling);
132
+ const reduced = options.reducedMotion ?? mediaReducedMotion();
133
+ const listeners = /* @__PURE__ */ new Set();
134
+ let stopWatching;
135
+ const effective = () => viewerChoice ?? (reduced.matches ? "off" : requested);
136
+ const notify = () => {
137
+ for (const listener of [...listeners]) {
138
+ if (!listeners.has(listener)) continue;
139
+ try {
140
+ listener();
141
+ } catch (error) {
142
+ report(error);
143
+ }
144
+ }
145
+ };
146
+ return {
147
+ get mode() {
148
+ return effective();
149
+ },
150
+ get staged() {
151
+ return effective() === "presentation";
152
+ },
153
+ get requested() {
154
+ return requested;
155
+ },
156
+ get viewerChoice() {
157
+ return viewerChoice;
158
+ },
159
+ get prefersReduced() {
160
+ return reduced.matches;
161
+ },
162
+ duration(base, timing = "transition") {
163
+ const mode = effective();
164
+ return mode === "off" ? 0 : scaleDuration(base, scaling[mode][timing]);
165
+ },
166
+ setMode(mode) {
167
+ checkMode(mode);
168
+ if (mode === requested) return;
169
+ requested = mode;
170
+ notify();
171
+ },
172
+ chooseMode(mode) {
173
+ checkMode(mode);
174
+ if (mode === viewerChoice) return;
175
+ viewerChoice = mode;
176
+ notify();
177
+ },
178
+ clearChoice() {
179
+ if (viewerChoice === void 0) return;
180
+ viewerChoice = void 0;
181
+ notify();
182
+ },
183
+ subscribe(listener) {
184
+ const entry = () => listener();
185
+ listeners.add(entry);
186
+ stopWatching ?? (stopWatching = reduced.subscribe(notify));
187
+ return () => {
188
+ if (!listeners.delete(entry) || listeners.size > 0) return;
189
+ stopWatching?.();
190
+ stopWatching = void 0;
191
+ };
192
+ }
193
+ };
194
+ }
195
+ function scaleDuration(base, rule) {
196
+ if (!(base > 0)) return 0;
197
+ const floor = Math.min(base, rule.min ?? 0);
198
+ const ceiling = rule.max ?? Infinity;
199
+ return Math.min(Math.max(base * rule.factor, floor), ceiling);
200
+ }
201
+ function mediaReducedMotion(query = "(prefers-reduced-motion: reduce)") {
202
+ let list;
203
+ const lookup = () => {
204
+ if (list === void 0) try {
205
+ list = typeof matchMedia === "function" ? matchMedia(query) : null;
206
+ } catch {
207
+ list = null;
208
+ }
209
+ return list;
210
+ };
211
+ return {
212
+ get matches() {
213
+ return lookup()?.matches ?? false;
214
+ },
215
+ subscribe(listener) {
216
+ const media = lookup();
217
+ if (!media) return () => {};
218
+ const onChange = () => listener();
219
+ if (typeof media.addEventListener === "function") {
220
+ media.addEventListener("change", onChange);
221
+ return () => media.removeEventListener("change", onChange);
222
+ }
223
+ media.addListener(onChange);
224
+ return () => media.removeListener(onChange);
225
+ }
226
+ };
227
+ }
228
+ function checkMode(mode) {
229
+ if (!MODES.includes(mode)) throw new TypeError(`Unknown motion mode "${String(mode)}". Use one of: ${MODES.join(", ")}.`);
230
+ return mode;
231
+ }
232
+ function mergeScaling(overrides = {}) {
233
+ const merge = (mode) => {
234
+ const table = { ...defaultScaling[mode] };
235
+ for (const timing of TIMINGS) {
236
+ const rule = overrides[mode]?.[timing];
237
+ if (rule) table[timing] = rule;
238
+ }
239
+ return table;
240
+ };
241
+ return {
242
+ presentation: merge("presentation"),
243
+ analysis: merge("analysis")
244
+ };
245
+ }
246
+ const motion = /* @__PURE__ */ createMotion();
247
+ // src/core/tween.ts
248
+ function tween(options, env = {}) {
249
+ const clock = env.clock ?? defaultClock;
250
+ const view = env.motion ?? motion;
251
+ const timing = options.timing ?? "transition";
252
+ const ease = options.ease ?? easeInOutCubic;
253
+ const duration = view.duration(options.duration, timing);
254
+ const delay = options.delay ? view.duration(options.delay, timing) : 0;
255
+ const { update, signal } = options;
256
+ const start = clock.now();
257
+ let state = "running";
258
+ let unsubscribe;
259
+ let resolve;
260
+ const finished = new Promise((r) => {
261
+ resolve = r;
262
+ });
263
+ const settle = (result) => {
264
+ state = result;
265
+ unsubscribe?.();
266
+ unsubscribe = void 0;
267
+ signal?.removeEventListener("abort", cancel);
268
+ resolve(result);
269
+ };
270
+ function cancel() {
271
+ if (state === "running") settle("cancelled");
272
+ }
273
+ let finishing = false;
274
+ function finish() {
275
+ if (state !== "running" || finishing) return;
276
+ finishing = true;
277
+ step(1);
278
+ if (state === "running") settle("done");
279
+ }
280
+ function step(progress) {
281
+ try {
282
+ update(ease(progress));
283
+ } catch (error) {
284
+ cancel();
285
+ throw error;
286
+ }
287
+ }
288
+ const onFrame = (now) => {
289
+ if (view.mode === "off") {
290
+ finish();
291
+ return;
292
+ }
293
+ const elapsed = now - start - delay;
294
+ if (elapsed >= duration) finish();
295
+ else if (elapsed > 0) step(elapsed / duration);
296
+ };
297
+ const handle = {
298
+ finished,
299
+ get state() {
300
+ return state;
301
+ },
302
+ cancel,
303
+ finish
304
+ };
305
+ if (signal?.aborted) {
306
+ settle("cancelled");
307
+ return handle;
308
+ }
309
+ signal?.addEventListener("abort", cancel, { once: true });
310
+ if (duration <= 0 && delay <= 0) {
311
+ finish();
312
+ return handle;
313
+ }
314
+ step(0);
315
+ if (state === "running") unsubscribe = clock.onFrame(onFrame);
316
+ return handle;
317
+ }
318
+ // src/core/geometry/walk.ts
319
+ const clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
320
+ const NONE = Object.freeze([]);
321
+ function createWalk(segments, gaps = NONE) {
322
+ const first = segments[0];
323
+ const last = segments[segments.length - 1];
324
+ if (!first || !last) throw new RangeError("A walk needs at least one segment.");
325
+ const cumulative = [0];
326
+ for (const segment of segments) cumulative.push(cumulative[cumulative.length - 1] + segment.length);
327
+ const length = cumulative[segments.length];
328
+ const start = pointOn(first, 0);
329
+ const end = pointOn(last, 1);
330
+ const locate = (d) => {
331
+ if (!(length > 0)) return {
332
+ index: 0,
333
+ u: 0
334
+ };
335
+ if (d >= length) {
336
+ let index = segments.length - 1;
337
+ while (index > 0 && !(segments[index].length > 0)) index--;
338
+ return {
339
+ index,
340
+ u: 1
341
+ };
342
+ }
343
+ let lo = 0;
344
+ let hi = segments.length - 1;
345
+ while (lo < hi) {
346
+ const mid = lo + hi >> 1;
347
+ if (cumulative[mid + 1] > d) hi = mid;
348
+ else lo = mid + 1;
349
+ }
350
+ return {
351
+ index: lo,
352
+ u: Math.min(1, (d - cumulative[lo]) / segments[lo].length)
353
+ };
354
+ };
355
+ const point = (t) => {
356
+ const at = clamp01(t);
357
+ if (at === 0) return start;
358
+ if (at === 1) return end;
359
+ const { index, u } = locate(at * length);
360
+ return pointOn(segments[index], u);
361
+ };
362
+ const draw = (from, to) => {
363
+ let d = moveTo(point(from));
364
+ const a = from * length;
365
+ const b = to * length;
366
+ if (!(b > a)) return d;
367
+ const first = locate(a);
368
+ for (let i = first.index; i < segments.length && cumulative[i] < b; i++) {
369
+ const segment = segments[i];
370
+ if (!(segment.length > 0)) continue;
371
+ const u0 = i === first.index ? first.u : 0;
372
+ const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
373
+ if (u1 > u0) d += drawTo(segment, u0, u1);
374
+ }
375
+ return d;
376
+ };
377
+ const slice = (t0, t1) => {
378
+ const from = clamp01(Math.min(t0, t1));
379
+ const to = clamp01(Math.max(t0, t1));
380
+ if (gaps.length === 0) return draw(from, to);
381
+ let d = "";
382
+ let at = from;
383
+ for (const [a, b] of gaps) {
384
+ if (a >= to) break;
385
+ if (a > at) d += draw(at, a);
386
+ if (b > at) at = b;
387
+ }
388
+ if (to > at) d += draw(at, to);
389
+ return d === "" ? moveTo(point(from)) : d;
390
+ };
391
+ return {
392
+ segments,
393
+ length,
394
+ start,
395
+ end,
396
+ gaps,
397
+ point,
398
+ angle(t) {
399
+ const { index, u } = locate(clamp01(t) * length);
400
+ return angleOn(segments[index], u);
401
+ },
402
+ slice,
403
+ d: gaps.length === 0 ? pathData(segments) : slice(0, 1)
404
+ };
405
+ }
406
+ // src/core/geometry/outline.ts
407
+ function closedOutline(sides) {
408
+ const walks = sides.map((side) => createWalk(side));
409
+ return {
410
+ d: pathData(sides.flat(), true),
411
+ closed: true,
412
+ sample(n) {
413
+ checkCount(n, 4);
414
+ const perSide = n / 4;
415
+ const points = [];
416
+ for (const walk of walks) for (let j = 0; j < perSide; j++) points.push(walk.point(j / perSide));
417
+ return points;
418
+ }
419
+ };
420
+ }
421
+ function loopOutline(loops) {
422
+ const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
423
+ let longest = 0;
424
+ lengths.forEach((length, i) => {
425
+ if (length > lengths[longest]) longest = i;
426
+ });
427
+ const turn = area(loops[longest]) < 0;
428
+ const clockwise = loops.map((loop) => turn ? reversed(loop) : loop);
429
+ const ring = fromUpperLeft(clockwise[longest]);
430
+ const walk = createWalk(ring);
431
+ return {
432
+ d: [ring, ...clockwise.filter((_, i) => i !== longest)].map((loop) => pathData(loop, true)).join(""),
433
+ closed: true,
434
+ sample(n) {
435
+ checkCount(n, 4);
436
+ const perSide = n / 4;
437
+ const points = [];
438
+ for (let side = 0; side < 4; side++) for (let j = 0; j < perSide; j++) points.push(walk.point(side / 4 + j / perSide / 4));
439
+ return points;
440
+ }
441
+ };
442
+ }
443
+ function area(loop) {
444
+ let sum = 0;
445
+ for (const segment of loop) {
446
+ if (segment.kind === "line") {
447
+ sum += segment.from.x * segment.to.y - segment.to.x * segment.from.y;
448
+ continue;
449
+ }
450
+ const { center, radius, start, sweep } = segment;
451
+ const end = start + sweep;
452
+ sum += radius * (center.x * (Math.sin(end) - Math.sin(start)) - center.y * (Math.cos(end) - Math.cos(start))) + radius * radius * sweep;
453
+ }
454
+ return sum / 2;
455
+ }
456
+ function reversed(loop) {
457
+ return loop.map((segment) => segment.kind === "line" ? line(segment.to, segment.from) : arc(segment.center, segment.radius, segment.start + segment.sweep, -segment.sweep)).reverse();
458
+ }
459
+ function fromUpperLeft(loop) {
460
+ let index = 0;
461
+ let u = 0;
462
+ let key = Infinity;
463
+ let top = Infinity;
464
+ const consider = (point, i, at) => {
465
+ const k = point.x + point.y;
466
+ if (k < key - 1e-9 || k <= key + 1e-9 && point.y < top) [index, u, key, top] = [
467
+ i,
468
+ at,
469
+ k,
470
+ point.y
471
+ ];
472
+ };
473
+ loop.forEach((segment, i) => {
474
+ consider(pointOn(segment, 0), i, 0);
475
+ if (segment.kind === "arc") {
476
+ const at = ((segment.sweep >= 0 ? UPPER_LEFT - segment.start : segment.start - UPPER_LEFT) % TAU + TAU) % TAU / Math.abs(segment.sweep);
477
+ if (at < 1) consider(pointOn(segment, at), i, at);
478
+ }
479
+ });
480
+ const [before, after] = split(loop[index], u);
481
+ return [
482
+ after,
483
+ ...loop.slice(index + 1),
484
+ ...loop.slice(0, index),
485
+ before
486
+ ].filter((segment) => segment.length > 0);
487
+ }
488
+ function split(segment, u) {
489
+ if (segment.kind === "line") {
490
+ const at = pointOn(segment, u);
491
+ return [line(segment.from, at), line(at, segment.to)];
492
+ }
493
+ const { center, radius, start, sweep } = segment;
494
+ return [arc(center, radius, start, sweep * u), arc(center, radius, start + sweep * u, sweep * (1 - u))];
495
+ }
496
+ const UPPER_LEFT = -3 * Math.PI / 4;
497
+ function openOutline(walk) {
498
+ return {
499
+ d: walk.d,
500
+ closed: false,
501
+ sample(n) {
502
+ checkCount(n, 1);
503
+ if (n === 1) return [walk.start];
504
+ const points = [];
505
+ for (let j = 0; j < n; j++) points.push(walk.point(j / (n - 1)));
506
+ return points;
507
+ }
508
+ };
509
+ }
510
+ function checkCount(n, multiple) {
511
+ if (!Number.isInteger(n) || n < 0 || n % multiple !== 0) {
512
+ const what = multiple === 1 ? "a whole number ≥ 0" : `a whole multiple of ${multiple}`;
513
+ throw new RangeError(`outline.sample(n): n must be ${what}, got ${n}.`);
514
+ }
515
+ }
516
+ // src/core/geometry/describe/mark.ts
517
+ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, segments }) {
518
+ return {
519
+ key,
520
+ ...series === void 0 ? {} : { series },
521
+ start: walk.start,
522
+ end: walk.end,
523
+ length: walk.length,
524
+ path: (t) => walk.point(t),
525
+ angle: (t) => walk.angle(t),
526
+ slice: (t0, t1) => walk.slice(t0, t1),
527
+ ...walk.gaps.length === 0 ? {} : { gaps: walk.gaps },
528
+ thickness,
529
+ outline,
530
+ bounds,
531
+ center,
532
+ pivot,
533
+ ...labelBounds === void 0 ? {} : { labelBounds },
534
+ ...segments === void 0 ? {} : { segments }
535
+ };
536
+ }
537
+ function finite(builder, field, value) {
538
+ if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
539
+ return value;
540
+ }
541
+ function labelBoxes(builder, boxes) {
542
+ if (!boxes) return boxes;
543
+ for (let i = 0; i < boxes.length; i++) {
544
+ const { x, y, width, height } = boxes[i];
545
+ if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
546
+ finite(builder, `labelBounds[${i}].x`, x);
547
+ finite(builder, `labelBounds[${i}].y`, y);
548
+ size(builder, `labelBounds[${i}].width`, width);
549
+ size(builder, `labelBounds[${i}].height`, height);
550
+ }
551
+ return boxes;
552
+ }
553
+ function size(builder, field, value) {
554
+ if (!(Number.isFinite(value) && value >= 0)) throw new RangeError(`describe.${builder}: ${field} must be a finite number ≥ 0, got ${value}.`);
555
+ return value;
556
+ }
557
+ // src/core/geometry/describe/arc.ts
558
+ function describeArc(spec) {
559
+ const { key, series } = spec;
560
+ const center = {
561
+ x: finite("arc", "cx", spec.cx),
562
+ y: finite("arc", "cy", spec.cy)
563
+ };
564
+ const r0 = Math.min(size("arc", "inner", spec.inner), size("arc", "outer", spec.outer));
565
+ const r1 = Math.max(spec.inner, spec.outer);
566
+ finite("arc", "start", spec.start);
567
+ finite("arc", "end", spec.end);
568
+ const sweep = Math.max(-TAU, Math.min(TAU, spec.end - spec.start));
569
+ const from = spec.start - Math.PI / 2;
570
+ const to = from + sweep;
571
+ const [left, right] = sweep >= 0 ? [r1, r0] : [r0, r1];
572
+ const sides = [
573
+ [arc(center, left, from, sweep)],
574
+ [line(polar(center, left, to), polar(center, right, to), to + (left > right ? Math.PI : 0))],
575
+ [arc(center, right, to, -sweep)],
576
+ [line(polar(center, right, from), polar(center, left, from), from + (left > right ? 0 : Math.PI))]
577
+ ];
578
+ const walk = createWalk([arc(center, (r0 + r1) / 2, from, sweep)]);
579
+ return assemble({
580
+ key,
581
+ series,
582
+ walk,
583
+ thickness: r1 - r0,
584
+ outline: closedOutline(sides),
585
+ bounds: boundsOf(sides.flat().flatMap(extremes)),
586
+ center: walk.point(.5),
587
+ pivot: center,
588
+ labelBounds: labelBoxes("arc", spec.labelBounds)
589
+ });
590
+ }
591
+ // src/core/geometry/describe/bar.ts
592
+ const ANGLE = {
593
+ left: 0,
594
+ right: Math.PI,
595
+ top: Math.PI / 2,
596
+ bottom: -Math.PI / 2
597
+ };
598
+ function describeBar(spec) {
599
+ const { key, series, baseline, x, y, width, height } = spec;
600
+ if (!Object.prototype.hasOwnProperty.call(ANGLE, baseline)) throw new RangeError(`describe.bar: baseline must be left, right, top or bottom, got ${String(baseline)}.`);
601
+ finite("bar", "x", x);
602
+ finite("bar", "y", y);
603
+ size("bar", "width", width);
604
+ size("bar", "height", height);
605
+ const radius = size("bar", "radius", spec.radius ?? 0);
606
+ const gap = size("bar", "gap", spec.gap ?? 0);
607
+ const labelBounds = labelBoxes("bar", spec.labelBounds);
608
+ const horizontal = baseline === "left" || baseline === "right";
609
+ const length = horizontal ? width : height;
610
+ const thickness = horizontal ? height : width;
611
+ const T = thickness;
612
+ const angle = ANGLE[baseline];
613
+ const at = frame(spec);
614
+ const part = (p0, p1, tip, rest) => {
615
+ const rr = Math.max(0, Math.min(tip, p1 - p0, T / 2));
616
+ const outline = closedOutline([
617
+ [line(at(p0, 0), at(p1 - rr, 0), angle)],
618
+ rr > 0 ? [
619
+ arc(at(p1 - rr, rr), rr, angle - Math.PI / 2, Math.PI / 2),
620
+ line(at(p1, rr), at(p1, T - rr), angle + Math.PI / 2),
621
+ arc(at(p1 - rr, T - rr), rr, angle, Math.PI / 2)
622
+ ] : [line(at(p1, 0), at(p1, T), angle + Math.PI / 2)],
623
+ [line(at(p1 - rr, T), at(p0, T), angle + Math.PI)],
624
+ [line(at(p0, T), at(p0, 0), angle - Math.PI / 2)]
625
+ ]);
626
+ const walk = createWalk([line(at(p0, T / 2), at(p1, T / 2), angle)]);
627
+ return assemble({
628
+ ...rest,
629
+ walk,
630
+ thickness,
631
+ outline,
632
+ bounds: rest.bounds ?? boundsOf([at(p0, 0), at(p1, T)]),
633
+ center: at((p0 + p1) / 2, T / 2),
634
+ pivot: walk.start
635
+ });
636
+ };
637
+ const specs = spec.segments ?? [{
638
+ series,
639
+ size: length
640
+ }];
641
+ const seen = /* @__PURE__ */ new Set();
642
+ let cursor = 0;
643
+ const segments = specs.map((segment, index) => {
644
+ size("bar", `segments[${index}].size`, segment.size);
645
+ if (segment.series !== void 0) {
646
+ if (seen.has(segment.series)) throw new Error(`describe.bar: series "${segment.series}" appears twice in the segments of "${key}".`);
647
+ seen.add(segment.series);
648
+ }
649
+ const from = Math.min(cursor, length);
650
+ cursor += segment.size;
651
+ const to = Math.min(cursor, length);
652
+ return {
653
+ segment,
654
+ index,
655
+ p0: Math.min(from + Math.min(gap, from), to),
656
+ p1: to
657
+ };
658
+ }).map(({ segment, index, p0, p1 }) => part(p0, p1, radius - (length - p1), {
659
+ key: segment.series === void 0 ? `${key}/${index}` : `${key}/${segment.series}`,
660
+ series: segment.series
661
+ }));
662
+ return part(0, length, radius, {
663
+ key,
664
+ series,
665
+ bounds: {
666
+ x,
667
+ y,
668
+ width,
669
+ height
670
+ },
671
+ labelBounds,
672
+ segments
673
+ });
674
+ }
675
+ function frame({ x, y, width: w, height: h, baseline }) {
676
+ switch (baseline) {
677
+ case "left": return (p, s) => ({
678
+ x: x + p,
679
+ y: y + s
680
+ });
681
+ case "right": return (p, s) => ({
682
+ x: x + w - p,
683
+ y: y + h - s
684
+ });
685
+ case "top": return (p, s) => ({
686
+ x: x + w - s,
687
+ y: y + p
688
+ });
689
+ case "bottom": return (p, s) => ({
690
+ x: x + s,
691
+ y: y + h - p
692
+ });
693
+ }
694
+ }
695
+ // src/core/geometry/describe/line.ts
696
+ function describeLine(spec) {
697
+ const { key, series, points } = spec;
698
+ const width = size("line", "width", spec.width ?? 1);
699
+ const first = points[0];
700
+ if (!first) throw new RangeError(`describe.line: "${key}" needs at least one point.`);
701
+ points.forEach((p, i) => {
702
+ finite("line", `points[${i}].x`, p.x);
703
+ finite("line", `points[${i}].y`, p.y);
704
+ });
705
+ const breaks = checkBreaks(spec.breaks, points.length);
706
+ const segments = [];
707
+ for (let i = 1; i < points.length; i++) segments.push(line(points[i - 1], points[i], segments[segments.length - 1]?.angle ?? 0));
708
+ if (segments.length === 0) segments.push(line(first, first));
709
+ const walk = createWalk(segments, gapsAt(breaks, segments));
710
+ const box = boundsOf(points);
711
+ const pad = width / 2;
712
+ return assemble({
713
+ key,
714
+ series,
715
+ walk,
716
+ thickness: width,
717
+ outline: openOutline(walk),
718
+ bounds: {
719
+ x: box.x - pad,
720
+ y: box.y - pad,
721
+ width: box.width + width,
722
+ height: box.height + width
723
+ },
724
+ center: walk.point(.5),
725
+ pivot: first,
726
+ labelBounds: labelBoxes("line", spec.labelBounds)
727
+ });
728
+ }
729
+ function gapsAt(breaks, segments) {
730
+ const along = [0];
731
+ for (const segment of segments) along.push(along[along.length - 1] + segment.length);
732
+ const length = along[along.length - 1];
733
+ return breaks.filter((i) => along[i] > along[i - 1]).map((i) => [along[i - 1] / length, along[i] / length]);
734
+ }
735
+ function checkBreaks(breaks, count) {
736
+ if (breaks === void 0) return [];
737
+ if (!Array.isArray(breaks)) throw new RangeError(`describe.line: breaks must be an array of point indices, got ${show$1(breaks)}.`);
738
+ let after = 0;
739
+ breaks.forEach((index, i) => {
740
+ if (!(Number.isInteger(index) && index > after && index < count)) throw new RangeError(`describe.line: breaks[${i}] must be a whole number more than ${after} and less than ${count}, the number of points, got ${show$1(index)}.`);
741
+ after = index;
742
+ });
743
+ return breaks;
744
+ }
745
+ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
746
+ // src/core/geometry/describe/point.ts
747
+ function describePoint(spec) {
748
+ const { key, series } = spec;
749
+ const center = {
750
+ x: finite("point", "x", spec.x),
751
+ y: finite("point", "y", spec.y)
752
+ };
753
+ const r = size("point", "r", spec.r);
754
+ const quarter = Math.PI / 2;
755
+ return assemble({
756
+ key,
757
+ series,
758
+ walk: createWalk([line(center, center)]),
759
+ thickness: 2 * r,
760
+ outline: closedOutline([
761
+ [arc(center, r, -3 * quarter / 2, quarter)],
762
+ [arc(center, r, -quarter / 2, quarter)],
763
+ [arc(center, r, quarter / 2, quarter)],
764
+ [arc(center, r, 3 * quarter / 2, quarter)]
765
+ ]),
766
+ bounds: {
767
+ x: center.x - r,
768
+ y: center.y - r,
769
+ width: 2 * r,
770
+ height: 2 * r
771
+ },
772
+ center,
773
+ pivot: center,
774
+ labelBounds: labelBoxes("point", spec.labelBounds)
775
+ });
776
+ }
777
+ // src/core/geometry/flatten.ts
778
+ const FLAT = .1;
779
+ const MAX_PIECES = 1e4;
780
+ function flattenPath(commands) {
781
+ const subpaths = [];
782
+ let start;
783
+ let pen = {
784
+ x: 0,
785
+ y: 0
786
+ };
787
+ let segments = [];
788
+ let open = false;
789
+ const finish = (closed) => {
790
+ if (open) subpaths.push({
791
+ start,
792
+ end: pen,
793
+ segments,
794
+ closed
795
+ });
796
+ segments = [];
797
+ open = false;
798
+ };
799
+ const to = (point) => {
800
+ if (!open) {
801
+ start = pen;
802
+ open = true;
803
+ }
804
+ pen = point;
805
+ };
806
+ const push = (segment) => {
807
+ if (segment.length !== 0) segments.push(segment);
808
+ };
809
+ const straight = (a, b) => push(line(a, b));
810
+ const through = (points) => {
811
+ for (let k = 1; k < points.length; k++) straight(points[k - 1], points[k]);
812
+ };
813
+ for (let i = 0; i < commands.length; i++) {
814
+ const command = commands[i];
815
+ const from = pen;
816
+ switch (command.op) {
817
+ case "M":
818
+ finish(false);
819
+ pen = command.to;
820
+ if (commands[i + 1] && commands[i + 1].op !== "M") {
821
+ start = pen;
822
+ open = true;
823
+ }
824
+ break;
825
+ case "Z":
826
+ to(start ?? pen);
827
+ straight(from, pen);
828
+ finish(true);
829
+ break;
830
+ case "L":
831
+ to(command.to);
832
+ straight(from, pen);
833
+ break;
834
+ case "C":
835
+ to(command.to);
836
+ through(bezier(from, command.c1, command.c2, command.to));
837
+ break;
838
+ case "Q":
839
+ to(command.to);
840
+ through(bezier(from, command.c, command.to));
841
+ break;
842
+ case "A":
843
+ to(command.to);
844
+ for (const segment of arcSegments(from, command)) push(segment);
845
+ }
846
+ }
847
+ finish(false);
848
+ return subpaths;
849
+ }
850
+ function bezier(...p) {
851
+ const bend = (a, b, c) => Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
852
+ const cubic = p.length === 4;
853
+ const n = pieces(1, cubic ? 6 * Math.max(bend(p[0], p[1], p[2]), bend(p[1], p[2], p[3])) : 2 * bend(p[0], p[1], p[2]));
854
+ const points = [p[0]];
855
+ for (let k = 1; k < n; k++) {
856
+ const t = k / n;
857
+ const s = 1 - t;
858
+ const [a, b, c, d] = cubic ? [
859
+ s * s * s,
860
+ 3 * s * s * t,
861
+ 3 * s * t * t,
862
+ t * t * t
863
+ ] : [
864
+ s * s,
865
+ 2 * s * t,
866
+ t * t,
867
+ 0
868
+ ];
869
+ points.push({
870
+ x: a * p[0].x + b * p[1].x + c * p[2].x + (cubic ? d * p[3].x : 0),
871
+ y: a * p[0].y + b * p[1].y + c * p[2].y + (cubic ? d * p[3].y : 0)
872
+ });
873
+ }
874
+ points.push(p[p.length - 1]);
875
+ return points;
876
+ }
877
+ function pieces(span, second) {
878
+ const n = Math.ceil(span * Math.sqrt(second / (8 * FLAT)));
879
+ return Number.isFinite(n) ? Math.min(MAX_PIECES, Math.max(1, n)) : MAX_PIECES;
880
+ }
881
+ const ROUND = 1e-9;
882
+ function arcSegments(from, command) {
883
+ const { to, large, sweep } = command;
884
+ if (from.x === to.x && from.y === to.y) return [];
885
+ let { rx, ry } = command;
886
+ if (!(rx > 0 && ry > 0)) return [line(from, to)];
887
+ const circle = Math.abs(rx - ry) <= ROUND * Math.max(rx, ry);
888
+ const phi = circle ? 0 : command.rotation * Math.PI / 180;
889
+ const cos = Math.cos(phi);
890
+ const sin = Math.sin(phi);
891
+ const hx = (from.x - to.x) / 2;
892
+ const hy = (from.y - to.y) / 2;
893
+ const x1 = cos * hx + sin * hy;
894
+ const y1 = -sin * hx + cos * hy;
895
+ const reach = x1 * x1 / (rx * rx) + y1 * y1 / (ry * ry);
896
+ if (reach > 1) {
897
+ rx *= Math.sqrt(reach);
898
+ ry *= Math.sqrt(reach);
899
+ }
900
+ const rx2 = rx * rx;
901
+ const ry2 = ry * ry;
902
+ const spread = rx2 * y1 * y1 + ry2 * x1 * x1;
903
+ const k = (large !== sweep ? 1 : -1) * Math.sqrt(Math.max(0, (rx2 * ry2 - spread) / spread));
904
+ const cx1 = k * rx * y1 / ry;
905
+ const cy1 = -k * ry * x1 / rx;
906
+ const center = {
907
+ x: cos * cx1 - sin * cy1 + (from.x + to.x) / 2,
908
+ y: sin * cx1 + cos * cy1 + (from.y + to.y) / 2
909
+ };
910
+ const theta = Math.atan2((y1 - cy1) / ry, (x1 - cx1) / rx);
911
+ let turn = Math.atan2((-y1 - cy1) / ry, (-x1 - cx1) / rx) - theta;
912
+ if (sweep && turn < 0) turn += TAU;
913
+ else if (!sweep && turn > 0) turn -= TAU;
914
+ if (circle) return [arc(center, rx, theta, turn)];
915
+ const n = pieces(Math.abs(turn), Math.max(rx, ry));
916
+ const at = (angle) => {
917
+ const ex = rx * Math.cos(angle);
918
+ const ey = ry * Math.sin(angle);
919
+ return {
920
+ x: center.x + cos * ex - sin * ey,
921
+ y: center.y + sin * ex + cos * ey
922
+ };
923
+ };
924
+ const segments = [];
925
+ let previous = from;
926
+ for (let j = 1; j <= n; j++) {
927
+ const next = j === n ? to : at(theta + turn * j / n);
928
+ segments.push(line(previous, next));
929
+ previous = next;
930
+ }
931
+ return segments;
932
+ }
933
+ // src/core/geometry/path.ts
934
+ const ARITY = {
935
+ M: 2,
936
+ L: 2,
937
+ H: 1,
938
+ V: 1,
939
+ C: 6,
940
+ S: 4,
941
+ Q: 4,
942
+ T: 2,
943
+ A: 7
944
+ };
945
+ const TOKEN = /[\s,]*([A-Za-z]|[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/y;
946
+ const LETTER = /^[A-Za-z]$/;
947
+ function parsePath(d) {
948
+ const tokens = [];
949
+ TOKEN.lastIndex = 0;
950
+ for (let match = TOKEN.exec(d); match; match = TOKEN.exec(d)) tokens.push(match[1]);
951
+ const out = [];
952
+ let pen = {
953
+ x: 0,
954
+ y: 0
955
+ };
956
+ let start = pen;
957
+ let control;
958
+ let command = "";
959
+ let i = 0;
960
+ while (i < tokens.length) {
961
+ if (LETTER.test(tokens[i])) command = tokens[i++];
962
+ else if (command === "" || command === "Z" || command === "z") break;
963
+ const upper = command.toUpperCase();
964
+ if (upper === "Z") {
965
+ out.push({
966
+ op: "Z",
967
+ to: start
968
+ });
969
+ pen = start;
970
+ control = void 0;
971
+ continue;
972
+ }
973
+ const arity = ARITY[upper];
974
+ if (arity === void 0) break;
975
+ const args = [];
976
+ let flagError = false;
977
+ while (args.length < arity && i < tokens.length && !LETTER.test(tokens[i])) {
978
+ const token = tokens[i];
979
+ if (upper === "A" && (args.length === 3 || args.length === 4)) {
980
+ const flag = token[0];
981
+ if (flag !== "0" && flag !== "1") {
982
+ flagError = true;
983
+ break;
984
+ }
985
+ args.push(Number(flag));
986
+ if (token.length > 1) tokens[i] = token.slice(1);
987
+ else i++;
988
+ continue;
989
+ }
990
+ args.push(Number(token));
991
+ i++;
992
+ }
993
+ if (flagError || args.length < arity || !args.every(Number.isFinite)) break;
994
+ const relative = command !== upper;
995
+ const at = (x, y) => relative ? {
996
+ x: pen.x + x,
997
+ y: pen.y + y
998
+ } : {
999
+ x,
1000
+ y
1001
+ };
1002
+ const [a = 0, b = 0, c = 0, e = 0, f = 0, g = 0, h = 0] = args;
1003
+ let next;
1004
+ switch (upper) {
1005
+ case "M":
1006
+ pen = start = at(a, b);
1007
+ out.push({
1008
+ op: "M",
1009
+ to: pen
1010
+ });
1011
+ command = relative ? "l" : "L";
1012
+ break;
1013
+ case "L":
1014
+ out.push({
1015
+ op: "L",
1016
+ to: pen = at(a, b)
1017
+ });
1018
+ break;
1019
+ case "H":
1020
+ out.push({
1021
+ op: "L",
1022
+ to: pen = {
1023
+ x: relative ? pen.x + a : a,
1024
+ y: pen.y
1025
+ }
1026
+ });
1027
+ break;
1028
+ case "V":
1029
+ out.push({
1030
+ op: "L",
1031
+ to: pen = {
1032
+ x: pen.x,
1033
+ y: relative ? pen.y + a : a
1034
+ }
1035
+ });
1036
+ break;
1037
+ case "C":
1038
+ case "S": {
1039
+ const smooth = upper === "S";
1040
+ const c1 = smooth ? control && lastIs(out, "C") ? reflect(control, pen) : pen : at(a, b);
1041
+ next = smooth ? at(a, b) : at(c, e);
1042
+ out.push({
1043
+ op: "C",
1044
+ c1,
1045
+ c2: next,
1046
+ to: pen = smooth ? at(c, e) : at(f, g)
1047
+ });
1048
+ break;
1049
+ }
1050
+ case "Q":
1051
+ case "T": {
1052
+ const smooth = upper === "T";
1053
+ next = smooth ? control && lastIs(out, "Q") ? reflect(control, pen) : pen : at(a, b);
1054
+ out.push({
1055
+ op: "Q",
1056
+ c: next,
1057
+ to: pen = smooth ? at(a, b) : at(c, e)
1058
+ });
1059
+ break;
1060
+ }
1061
+ case "A": out.push({
1062
+ op: "A",
1063
+ rx: Math.abs(a),
1064
+ ry: Math.abs(b),
1065
+ rotation: c,
1066
+ large: e !== 0,
1067
+ sweep: f !== 0,
1068
+ to: pen = at(g, h)
1069
+ });
1070
+ }
1071
+ control = next;
1072
+ }
1073
+ return out;
1074
+ }
1075
+ const lastIs = (commands, op) => commands[commands.length - 1]?.op === op;
1076
+ const reflect = (control, about) => ({
1077
+ x: 2 * about.x - control.x,
1078
+ y: 2 * about.y - control.y
1079
+ });
1080
+ function shapeOutline(tag, attribute) {
1081
+ const num = (name) => {
1082
+ const value = Number.parseFloat(attribute(name) ?? "");
1083
+ return Number.isFinite(value) ? value : 0;
1084
+ };
1085
+ switch (tag) {
1086
+ case "path": return parsePath(attribute("d") ?? "");
1087
+ case "circle": return ellipse(num("cx"), num("cy"), num("r"), num("r"));
1088
+ case "ellipse": return ellipse(num("cx"), num("cy"), num("rx"), num("ry"));
1089
+ case "line": return [{
1090
+ op: "M",
1091
+ to: {
1092
+ x: num("x1"),
1093
+ y: num("y1")
1094
+ }
1095
+ }, {
1096
+ op: "L",
1097
+ to: {
1098
+ x: num("x2"),
1099
+ y: num("y2")
1100
+ }
1101
+ }];
1102
+ case "polyline":
1103
+ case "polygon": {
1104
+ const values = (attribute("points") ?? "").trim().split(/[\s,]+/).filter(Boolean).map(Number);
1105
+ const points = [];
1106
+ for (let i = 0; i + 1 < values.length && Number.isFinite(values[i]) && Number.isFinite(values[i + 1]); i += 2) points.push({
1107
+ x: values[i],
1108
+ y: values[i + 1]
1109
+ });
1110
+ if (points.length < 2) return [];
1111
+ const lines = points.map((to, i) => ({
1112
+ op: i === 0 ? "M" : "L",
1113
+ to
1114
+ }));
1115
+ return tag === "polygon" ? [...lines, {
1116
+ op: "Z",
1117
+ to: points[0]
1118
+ }] : lines;
1119
+ }
1120
+ case "rect": return rect(num("x"), num("y"), num("width"), num("height"), attribute);
1121
+ default: return [];
1122
+ }
1123
+ }
1124
+ function ellipse(cx, cy, rx, ry) {
1125
+ if (!(rx > 0 && ry > 0)) return [];
1126
+ const arc = (x) => ({
1127
+ op: "A",
1128
+ rx,
1129
+ ry,
1130
+ rotation: 0,
1131
+ large: false,
1132
+ sweep: true,
1133
+ to: {
1134
+ x,
1135
+ y: cy
1136
+ }
1137
+ });
1138
+ return [
1139
+ {
1140
+ op: "M",
1141
+ to: {
1142
+ x: cx + rx,
1143
+ y: cy
1144
+ }
1145
+ },
1146
+ arc(cx - rx),
1147
+ arc(cx + rx),
1148
+ {
1149
+ op: "Z",
1150
+ to: {
1151
+ x: cx + rx,
1152
+ y: cy
1153
+ }
1154
+ }
1155
+ ];
1156
+ }
1157
+ function rect(x, y, w, h, attribute) {
1158
+ if (!(w > 0 && h > 0)) return [];
1159
+ const corner = (name) => {
1160
+ const value = Number.parseFloat(attribute(name) ?? "");
1161
+ return value >= 0 ? value : void 0;
1162
+ };
1163
+ const rx = Math.min(corner("rx") ?? corner("ry") ?? 0, w / 2);
1164
+ const ry = Math.min(corner("ry") ?? corner("rx") ?? 0, h / 2);
1165
+ const line = (px, py) => ({
1166
+ op: "L",
1167
+ to: {
1168
+ x: px,
1169
+ y: py
1170
+ }
1171
+ });
1172
+ if (!(rx > 0 && ry > 0)) return [
1173
+ {
1174
+ op: "M",
1175
+ to: {
1176
+ x,
1177
+ y
1178
+ }
1179
+ },
1180
+ line(x + w, y),
1181
+ line(x + w, y + h),
1182
+ line(x, y + h),
1183
+ {
1184
+ op: "Z",
1185
+ to: {
1186
+ x,
1187
+ y
1188
+ }
1189
+ }
1190
+ ];
1191
+ const arc = (px, py) => ({
1192
+ op: "A",
1193
+ rx,
1194
+ ry,
1195
+ rotation: 0,
1196
+ large: false,
1197
+ sweep: true,
1198
+ to: {
1199
+ x: px,
1200
+ y: py
1201
+ }
1202
+ });
1203
+ return [
1204
+ {
1205
+ op: "M",
1206
+ to: {
1207
+ x: x + rx,
1208
+ y
1209
+ }
1210
+ },
1211
+ line(x + w - rx, y),
1212
+ arc(x + w, y + ry),
1213
+ line(x + w, y + h - ry),
1214
+ arc(x + w - rx, y + h),
1215
+ line(x + rx, y + h),
1216
+ arc(x, y + h - ry),
1217
+ line(x, y + ry),
1218
+ arc(x + rx, y),
1219
+ {
1220
+ op: "Z",
1221
+ to: {
1222
+ x: x + rx,
1223
+ y
1224
+ }
1225
+ }
1226
+ ];
1227
+ }
1228
+ function transformPath(commands, m) {
1229
+ const p = (point) => ({
1230
+ x: m[0] * point.x + m[2] * point.y + m[4],
1231
+ y: m[1] * point.x + m[3] * point.y + m[5]
1232
+ });
1233
+ const mirrored = m[0] * m[3] - m[1] * m[2] < 0;
1234
+ return commands.map((command) => {
1235
+ switch (command.op) {
1236
+ case "M":
1237
+ case "L":
1238
+ case "Z": return {
1239
+ op: command.op,
1240
+ to: p(command.to)
1241
+ };
1242
+ case "C": return {
1243
+ op: "C",
1244
+ c1: p(command.c1),
1245
+ c2: p(command.c2),
1246
+ to: p(command.to)
1247
+ };
1248
+ case "Q": return {
1249
+ op: "Q",
1250
+ c: p(command.c),
1251
+ to: p(command.to)
1252
+ };
1253
+ case "A": return {
1254
+ ...command,
1255
+ ...transformEllipse(command, m),
1256
+ sweep: mirrored !== command.sweep,
1257
+ to: p(command.to)
1258
+ };
1259
+ }
1260
+ });
1261
+ }
1262
+ function transformEllipse({ rx, ry, rotation }, m) {
1263
+ const r = rotation * Math.PI / 180;
1264
+ const cos = Math.cos(r);
1265
+ const sin = Math.sin(r);
1266
+ const e11 = (m[0] * cos + m[2] * sin) * rx;
1267
+ const e12 = (m[2] * cos - m[0] * sin) * ry;
1268
+ const e21 = (m[1] * cos + m[3] * sin) * rx;
1269
+ const e22 = (m[3] * cos - m[1] * sin) * ry;
1270
+ const a = e11 * e11 + e12 * e12;
1271
+ const b = e11 * e21 + e12 * e22;
1272
+ const c = e21 * e21 + e22 * e22;
1273
+ const mean = (a + c) / 2;
1274
+ const spread = Math.hypot((a - c) / 2, b);
1275
+ const major = mean + spread;
1276
+ const angle = Math.abs(b) < 1e-12 ? a >= c ? 0 : Math.PI / 2 : Math.atan2(major - a, b);
1277
+ return {
1278
+ rx: Math.sqrt(major),
1279
+ ry: Math.sqrt(Math.max(0, mean - spread)),
1280
+ rotation: angle * 180 / Math.PI
1281
+ };
1282
+ }
1283
+ function formatPath(commands) {
1284
+ const n = formatNumber;
1285
+ const pt = (point) => `${n(point.x)},${n(point.y)}`;
1286
+ return commands.map((command) => {
1287
+ switch (command.op) {
1288
+ case "M":
1289
+ case "L": return `${command.op}${pt(command.to)}`;
1290
+ case "C": return `C${pt(command.c1)} ${pt(command.c2)} ${pt(command.to)}`;
1291
+ case "Q": return `Q${pt(command.c)} ${pt(command.to)}`;
1292
+ case "A": return `A${n(command.rx)},${n(command.ry)} ${n(command.rotation)} ${command.large ? 1 : 0} ${command.sweep ? 1 : 0} ${pt(command.to)}`;
1293
+ case "Z": return "Z";
1294
+ }
1295
+ }).join("");
1296
+ }
1297
+ // src/core/geometry/describe/shape.ts
1298
+ function describeShape(spec) {
1299
+ const { key, series, d } = spec;
1300
+ const width = spec.width ?? 1;
1301
+ if (!(Number.isFinite(width) && width > 0)) throw new RangeError(`describe.shape: width must be a finite number more than 0, got ${width}.`);
1302
+ const m = checkMatrix(spec.matrix);
1303
+ if (typeof d !== "string") throw new RangeError(`describe.shape: d must be path data, a string, got ${show(d)}.`);
1304
+ const commands = parsePath(d);
1305
+ const subpaths = commands[0]?.op === "M" ? flattenPath(m ? transformPath(commands, m) : commands) : [];
1306
+ if (subpaths.length === 0) throw new RangeError(`describe.shape: d must start with a move and draw something after it, got ${show(d)}.`);
1307
+ const points = [];
1308
+ let length = 0;
1309
+ for (const subpath of subpaths) {
1310
+ points.push(subpath.start);
1311
+ for (const segment of subpath.segments) {
1312
+ for (const point of extremes(segment)) points.push(point);
1313
+ length += segment.length;
1314
+ }
1315
+ }
1316
+ const box = boundsOf(points);
1317
+ if (![
1318
+ box.x,
1319
+ box.y,
1320
+ box.width,
1321
+ box.height,
1322
+ length
1323
+ ].every(Number.isFinite)) throw new RangeError(`describe.shape: d must stay finite${m ? " once moved by matrix" : ""}, got ${show(d)}.`);
1324
+ const labelBounds = labelBoxes("shape", spec.labelBounds);
1325
+ if (subpaths.every(closes) && length > 0) {
1326
+ const center = {
1327
+ x: box.x + box.width / 2,
1328
+ y: box.y + box.height / 2
1329
+ };
1330
+ return assemble({
1331
+ key,
1332
+ series,
1333
+ walk: createWalk([line(center, center)]),
1334
+ thickness: Math.min(box.width, box.height),
1335
+ outline: loopOutline(subpaths.map((subpath) => subpath.segments).filter((segments) => segments.length > 0)),
1336
+ bounds: box,
1337
+ center,
1338
+ pivot: center,
1339
+ labelBounds
1340
+ });
1341
+ }
1342
+ const { segments, gaps } = joined(subpaths);
1343
+ const walk = createWalk(segments, gaps);
1344
+ const pad = width / 2;
1345
+ return assemble({
1346
+ key,
1347
+ series,
1348
+ walk,
1349
+ thickness: width,
1350
+ outline: openOutline(walk),
1351
+ bounds: {
1352
+ x: box.x - pad,
1353
+ y: box.y - pad,
1354
+ width: box.width + width,
1355
+ height: box.height + width
1356
+ },
1357
+ center: walk.point(.5),
1358
+ pivot: walk.start,
1359
+ labelBounds
1360
+ });
1361
+ }
1362
+ const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
1363
+ function joined(subpaths) {
1364
+ const segments = [];
1365
+ const across = [];
1366
+ let pen;
1367
+ for (const subpath of subpaths) {
1368
+ if (pen && (pen.x !== subpath.start.x || pen.y !== subpath.start.y)) {
1369
+ across.push(segments.length);
1370
+ segments.push(line(pen, subpath.start));
1371
+ }
1372
+ for (const segment of subpath.segments) segments.push(segment);
1373
+ pen = subpath.end;
1374
+ }
1375
+ if (segments.length === 0) segments.push(line(subpaths[0].start, subpaths[0].start));
1376
+ const along = [0];
1377
+ for (const segment of segments) along.push(along[along.length - 1] + segment.length);
1378
+ const length = along[along.length - 1];
1379
+ return {
1380
+ segments,
1381
+ gaps: across.map((i) => [along[i] / length, along[i + 1] / length])
1382
+ };
1383
+ }
1384
+ function checkMatrix(m) {
1385
+ if (m === void 0) return m;
1386
+ if (!(Array.isArray(m) && m.length === 6 && m.every(Number.isFinite))) throw new RangeError(`describe.shape: matrix must be six finite numbers [a, b, c, d, e, f], got ${show(m)}.`);
1387
+ return m;
1388
+ }
1389
+ function show(value) {
1390
+ if (Array.isArray(value)) return `[${value.map(show).join(", ")}]`;
1391
+ if (typeof value !== "string") return String(value);
1392
+ return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);
1393
+ }
1394
+ // src/core/geometry/describe/index.ts
1395
+ const describe = {
1396
+ bar: describeBar,
1397
+ arc: describeArc,
1398
+ line: describeLine,
1399
+ point: describePoint,
1400
+ shape: describeShape
1401
+ };
1402
+ // src/core/registry.ts
1403
+ function createRegistry(options) {
1404
+ const { kind, hint } = options;
1405
+ const entries = /* @__PURE__ */ new Map();
1406
+ const registry = {
1407
+ get: (name) => entries.get(name),
1408
+ resolve(name) {
1409
+ const value = entries.get(name);
1410
+ if (value !== void 0) return value;
1411
+ const known = entries.size > 0 ? [...entries.keys()].join(", ") : "none";
1412
+ throw new RangeError(`Unknown ${kind} "${String(name)}". Registered ${kind}s: ${known}.${hint ? ` ${hint}` : ""}`);
1413
+ },
1414
+ register(name, value) {
1415
+ if (typeof name !== "string" || name === "") throw new TypeError(`A ${kind} needs a non-empty string name, got ${JSON.stringify(name)}.`);
1416
+ if (value === void 0) throw new TypeError(`Registering ${kind} "${name}" needs a value.`);
1417
+ entries.set(name, value);
1418
+ },
1419
+ names: () => [...entries.keys()]
1420
+ };
1421
+ for (const [name, value] of Object.entries(options.entries ?? {})) registry.register(name, value);
1422
+ return registry;
1423
+ }
1424
+ const EFFECT_SLOTS = [
1425
+ "hover",
1426
+ "enter",
1427
+ "update",
1428
+ "exit",
1429
+ "decorate"
1430
+ ];
1431
+ function resolveEffects(on, presets) {
1432
+ const effects = {};
1433
+ for (const slot of Object.keys(on ?? {})) if (!EFFECT_SLOTS.includes(slot)) throw new TypeError(`on.${slot} isn't an effect slot. Use one of: ${EFFECT_SLOTS.join(", ")}.`);
1434
+ for (const slot of EFFECT_SLOTS) {
1435
+ const option = on?.[slot];
1436
+ if (option === void 0) continue;
1437
+ if (typeof option === "string") {
1438
+ const effect = presets.resolve(option)();
1439
+ if (!isMarkEffect(effect)) throw new TypeError(`Preset "${option}" for on.${slot} didn't return a mark effect; it returned ${describeValue(effect)}.`);
1440
+ effects[slot] = effect;
1441
+ } else {
1442
+ if (!isMarkEffect(option)) throw new TypeError(`on.${slot} needs a mark effect (kind "geometry" or "data") or a preset name, got ${describeValue(option)}.`);
1443
+ effects[slot] = option;
1444
+ }
1445
+ }
1446
+ return effects;
1447
+ }
1448
+ function isMarkEffect(value) {
1449
+ if (typeof value !== "object" || value === null) return false;
1450
+ const effect = value;
1451
+ return (effect.kind === "geometry" || effect.kind === "data") && typeof effect.run === "function" && typeof effect.end === "function" && typeof effect.clear === "function";
1452
+ }
1453
+ function describeValue(value) {
1454
+ if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
1455
+ const kind = value.kind;
1456
+ if (kind === "transition") return "a transition effect, which runs between two charts rather than on one mark";
1457
+ if (kind === "geometry" || kind === "data") return `a ${kind} effect without run(), end() and clear()`;
1458
+ return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
1459
+ }
1460
+ // src/core/merge.ts
1461
+ function mergeFields(current, next) {
1462
+ const result = { ...current };
1463
+ for (const [field, value] of Object.entries(next ?? {})) if (value === void 0) delete result[field];
1464
+ else result[field] = value;
1465
+ return result;
1466
+ }
1467
+ // src/core/runner.ts
1468
+ function runScope(options) {
1469
+ const { clock, motion, layer, mark } = options;
1470
+ const controller = new AbortController();
1471
+ let listeners = [];
1472
+ return {
1473
+ context: {
1474
+ signal: controller.signal,
1475
+ motion,
1476
+ mark,
1477
+ layer,
1478
+ icons: options.icons,
1479
+ batch: options.batch,
1480
+ ...options.previous ? { previous: options.previous } : {},
1481
+ tween(tweenOptions) {
1482
+ const own = tweenOptions.signal;
1483
+ const running = tween({
1484
+ ...tweenOptions,
1485
+ signal: own ?? controller.signal
1486
+ }, {
1487
+ clock,
1488
+ motion
1489
+ });
1490
+ if (own && own !== controller.signal) {
1491
+ if (controller.signal.aborted) running.cancel();
1492
+ else controller.signal.addEventListener("abort", () => running.cancel(), { once: true });
1493
+ }
1494
+ return running;
1495
+ },
1496
+ onChange(listener) {
1497
+ listeners.push(listener);
1498
+ }
1499
+ },
1500
+ abort() {
1501
+ controller.abort();
1502
+ },
1503
+ change(geometry, data) {
1504
+ for (const listener of [...listeners]) listener(geometry, data);
1505
+ },
1506
+ clear() {
1507
+ controller.abort();
1508
+ layer.clear();
1509
+ mark.reset();
1510
+ listeners = [];
1511
+ }
1512
+ };
1513
+ }
1514
+ const SLOTS = [
1515
+ "decorate",
1516
+ "enter",
1517
+ "update",
1518
+ "exit",
1519
+ "hover"
1520
+ ];
1521
+ const NO_ICONS$1 = { get: () => void 0 };
1522
+ const INERT$1 = {
1523
+ place() {},
1524
+ update() {},
1525
+ remove() {}
1526
+ };
1527
+ function createRunner(options) {
1528
+ const { surface } = options;
1529
+ let effects = options.effects;
1530
+ const motion$2 = options.motion ?? motion;
1531
+ const clock = options.clock ?? defaultClock;
1532
+ const icons = options.icons ?? NO_ICONS$1;
1533
+ const entries = /* @__PURE__ */ new Map();
1534
+ const hovered = /* @__PURE__ */ new Set();
1535
+ let transitioning = false;
1536
+ let destroyed = false;
1537
+ let order = 0;
1538
+ const unsubscribe = motion$2.subscribe(() => {
1539
+ if (motion$2.mode === "off") endRunning();
1540
+ });
1541
+ function track(input) {
1542
+ const key = input.mark.key;
1543
+ const entry = entries.get(key);
1544
+ if (entry) {
1545
+ entry.mark = input.mark;
1546
+ entry.data = input.data;
1547
+ return entry;
1548
+ }
1549
+ const created = {
1550
+ key,
1551
+ mark: input.mark,
1552
+ data: input.data,
1553
+ resting: input.data,
1554
+ runs: /* @__PURE__ */ new Map(),
1555
+ applied: {},
1556
+ handle: void 0,
1557
+ exiting: void 0
1558
+ };
1559
+ entries.set(key, created);
1560
+ return created;
1561
+ }
1562
+ function start(entry, slot, data, batch, more = {}) {
1563
+ const { previous, done } = more;
1564
+ const effect = effects[slot];
1565
+ if (!effect) {
1566
+ done?.();
1567
+ return;
1568
+ }
1569
+ const current = entry.runs.get(slot);
1570
+ if (current) clearRun(current);
1571
+ const run = {
1572
+ entry,
1573
+ slot,
1574
+ order: more.order ?? ++order,
1575
+ effect,
1576
+ data,
1577
+ batch,
1578
+ previous,
1579
+ style: {},
1580
+ state: "running",
1581
+ done,
1582
+ scope: runScope({
1583
+ clock,
1584
+ motion: motion$2,
1585
+ icons,
1586
+ batch,
1587
+ previous,
1588
+ layer: runLayer(entry.key, slot, () => run.order, () => run.state !== "cleared"),
1589
+ mark: runMark(() => run)
1590
+ })
1591
+ };
1592
+ entry.runs.set(slot, run);
1593
+ const mark = more.mark ?? entry.mark;
1594
+ const ctx = run.scope.context;
1595
+ try {
1596
+ if (more.end || motion$2.mode === "off") {
1597
+ if (effect.kind === "data") effect.end(mark, data, ctx);
1598
+ else effect.end(mark, ctx);
1599
+ finish(run);
1600
+ } else {
1601
+ const running = effect.kind === "data" ? effect.run(mark, data, ctx) : effect.run(mark, ctx);
1602
+ Promise.resolve(running).then(() => finish(run), (error) => fail(run, error));
1603
+ }
1604
+ } catch (error) {
1605
+ fail(run, error);
1606
+ }
1607
+ }
1608
+ function finish(run) {
1609
+ if (run.state !== "running") return;
1610
+ run.state = "ended";
1611
+ release(run);
1612
+ }
1613
+ function fail(run, error) {
1614
+ const { signal } = run.scope.context;
1615
+ if (signal.aborted && (error === signal.reason || error?.name === "AbortError")) return;
1616
+ report(error);
1617
+ clearRun(run);
1618
+ }
1619
+ function release(run) {
1620
+ const done = run.done;
1621
+ run.done = void 0;
1622
+ done?.();
1623
+ }
1624
+ function clearRun(run) {
1625
+ if (run.state === "cleared") return;
1626
+ run.state = "cleared";
1627
+ const { entry } = run;
1628
+ if (entry.runs.get(run.slot) === run) entry.runs.delete(run.slot);
1629
+ run.scope.abort();
1630
+ try {
1631
+ run.effect.clear(run.scope.context);
1632
+ } catch (error) {
1633
+ report(error);
1634
+ }
1635
+ run.scope.clear();
1636
+ release(run);
1637
+ }
1638
+ function runLayer(key, slot, order, live) {
1639
+ let group;
1640
+ const target = () => live() ? group ?? (group = surface.group(key, slot, order())) : void 0;
1641
+ return {
1642
+ icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT$1,
1643
+ path: (d, paint) => target()?.path(d, paint) ?? INERT$1,
1644
+ text: (content, style) => target()?.text(content, style) ?? INERT$1,
1645
+ clear() {
1646
+ const drawn = group;
1647
+ group = void 0;
1648
+ drawn?.clear();
1649
+ }
1650
+ };
1651
+ }
1652
+ function runMark(own) {
1653
+ return {
1654
+ set(style) {
1655
+ const run = own();
1656
+ if (run.state === "cleared") return;
1657
+ run.style = mergeFields(run.style, style);
1658
+ applyStyle(run.entry);
1659
+ },
1660
+ reset() {
1661
+ const run = own();
1662
+ if (Object.keys(run.style).length === 0) return;
1663
+ run.style = {};
1664
+ applyStyle(run.entry);
1665
+ }
1666
+ };
1667
+ }
1668
+ function applyStyle(entry) {
1669
+ const runs = [...entry.runs.values()].sort((a, b) => a.order - b.order);
1670
+ const next = Object.assign({}, ...runs.map((run) => run.style));
1671
+ const applied = entry.applied;
1672
+ entry.applied = next;
1673
+ if (Object.keys(next).length === 0) {
1674
+ if (Object.keys(applied).length > 0) handle(entry).reset();
1675
+ return;
1676
+ }
1677
+ const changes = {};
1678
+ let changed = false;
1679
+ for (const field of /* @__PURE__ */ new Set([...Object.keys(applied), ...Object.keys(next)])) {
1680
+ if (applied[field] === next[field]) continue;
1681
+ changes[field] = next[field];
1682
+ changed = true;
1683
+ }
1684
+ if (changed) handle(entry).set(changes);
1685
+ }
1686
+ function handle(entry) {
1687
+ return entry.handle ?? (entry.handle = surface.mark(entry.key));
1688
+ }
1689
+ function forget(entry) {
1690
+ if (entries.get(entry.key) === entry) entries.delete(entry.key);
1691
+ hovered.delete(entry.key);
1692
+ const exited = entry.exiting;
1693
+ entry.exiting = void 0;
1694
+ for (const run of [...entry.runs.values()]) clearRun(run);
1695
+ entry.handle = void 0;
1696
+ exited?.();
1697
+ }
1698
+ function cancelExit(entry) {
1699
+ const exited = entry.exiting;
1700
+ if (!exited) return;
1701
+ entry.exiting = void 0;
1702
+ const run = entry.runs.get("exit");
1703
+ if (run) clearRun(run);
1704
+ exited();
1705
+ }
1706
+ function endRunning() {
1707
+ for (const entry of [...entries.values()]) for (const run of [...entry.runs.values()]) {
1708
+ if (run.state !== "running" || entry.runs.get(run.slot) !== run) continue;
1709
+ const done = run.done;
1710
+ run.done = void 0;
1711
+ start(entry, run.slot, latestData(entry, run), run.batch, {
1712
+ previous: run.previous,
1713
+ done,
1714
+ order: run.order
1715
+ });
1716
+ }
1717
+ }
1718
+ function clearSlot(slot) {
1719
+ const orders = /* @__PURE__ */ new Map();
1720
+ for (const entry of [...entries.values()]) {
1721
+ const run = entry.runs.get(slot);
1722
+ if (!run) continue;
1723
+ orders.set(entry, run.order);
1724
+ clearRun(run);
1725
+ }
1726
+ return orders;
1727
+ }
1728
+ function latestData(entry, run) {
1729
+ const previous = run.data.previous;
1730
+ return previous && !entry.data.previous ? withPrevious(entry.data, previous) : entry.data;
1731
+ }
1732
+ return {
1733
+ enter(marks) {
1734
+ if (destroyed) return;
1735
+ marks.forEach((input, index) => {
1736
+ const entry = track(input);
1737
+ entry.resting = input.data;
1738
+ cancelExit(entry);
1739
+ const batch = {
1740
+ index,
1741
+ count: marks.length
1742
+ };
1743
+ start(entry, "decorate", input.data, batch);
1744
+ start(entry, "enter", input.data, batch);
1745
+ });
1746
+ },
1747
+ update(marks) {
1748
+ if (destroyed) return;
1749
+ const changing = new Set(marks.map((input) => input.mark.key));
1750
+ for (const entry of [...entries.values()]) {
1751
+ const run = entry.runs.get("update");
1752
+ if (run && !changing.has(entry.key)) clearRun(run);
1753
+ }
1754
+ marks.forEach((input, index) => {
1755
+ const known = entries.get(input.mark.key);
1756
+ const previous = input.from ?? known?.mark;
1757
+ const data = known && !input.data.previous ? withPrevious(input.data, known.resting) : input.data;
1758
+ const entry = track(input);
1759
+ entry.resting = input.data;
1760
+ start(entry, "update", data, {
1761
+ index,
1762
+ count: marks.length
1763
+ }, { previous });
1764
+ });
1765
+ },
1766
+ exit(marks) {
1767
+ if (destroyed) return Promise.resolve();
1768
+ const exits = marks.map((input, index) => {
1769
+ const entry = track(input);
1770
+ cancelExit(entry);
1771
+ hovered.delete(entry.key);
1772
+ for (const run of [...entry.runs.values()]) clearRun(run);
1773
+ return new Promise((resolve) => {
1774
+ entry.exiting = resolve;
1775
+ if (!effects.exit) {
1776
+ forget(entry);
1777
+ return;
1778
+ }
1779
+ start(entry, "exit", input.data, {
1780
+ index,
1781
+ count: marks.length
1782
+ }, { done: () => {
1783
+ if (entry.exiting && entries.get(entry.key) === entry) forget(entry);
1784
+ } });
1785
+ });
1786
+ });
1787
+ return Promise.all(exits).then(() => void 0);
1788
+ },
1789
+ hover(marks) {
1790
+ if (destroyed) return;
1791
+ marks.forEach((input, index) => {
1792
+ const entry = track(input);
1793
+ if (entry.exiting) return;
1794
+ hovered.add(entry.key);
1795
+ if (!transitioning) start(entry, "hover", input.data, {
1796
+ index,
1797
+ count: marks.length
1798
+ });
1799
+ });
1800
+ },
1801
+ leave(keys = [...hovered]) {
1802
+ for (const key of keys) {
1803
+ hovered.delete(key);
1804
+ const run = entries.get(key)?.runs.get("hover");
1805
+ if (run) clearRun(run);
1806
+ }
1807
+ },
1808
+ change(mark, data) {
1809
+ const entry = entries.get(mark.key);
1810
+ if (!entry) return;
1811
+ entry.mark = mark;
1812
+ if (data) {
1813
+ entry.data = data;
1814
+ if (!transitioning) entry.resting = data;
1815
+ }
1816
+ for (const run of [...entry.runs.values()]) {
1817
+ if (run.state === "cleared") continue;
1818
+ try {
1819
+ run.scope.change(mark, latestData(entry, run));
1820
+ } catch (error) {
1821
+ report(error);
1822
+ clearRun(run);
1823
+ }
1824
+ }
1825
+ },
1826
+ interrupt() {
1827
+ if (destroyed) return;
1828
+ transitioning = true;
1829
+ for (const entry of [...entries.values()]) {
1830
+ const run = entry.runs.get("hover");
1831
+ if (run) clearRun(run);
1832
+ }
1833
+ },
1834
+ settle() {
1835
+ if (!transitioning) return;
1836
+ transitioning = false;
1837
+ for (const entry of entries.values()) if (!entry.exiting) entry.resting = entry.data;
1838
+ const keys = [...hovered];
1839
+ keys.forEach((key, index) => {
1840
+ const entry = entries.get(key);
1841
+ if (entry) start(entry, "hover", entry.data, {
1842
+ index,
1843
+ count: keys.length
1844
+ });
1845
+ });
1846
+ },
1847
+ swap(next, marks) {
1848
+ if (destroyed) return;
1849
+ const changed = SLOTS.filter((slot) => next[slot] !== effects[slot]);
1850
+ effects = next;
1851
+ for (const slot of changed) if (slot === "decorate") {
1852
+ const orders = clearSlot(slot);
1853
+ marks.forEach((input, index) => {
1854
+ const entry = entries.get(input.mark.key) ?? track(input);
1855
+ if (!entry.exiting) start(entry, slot, input.data, {
1856
+ index,
1857
+ count: marks.length
1858
+ }, {
1859
+ mark: input.mark,
1860
+ order: orders.get(entry)
1861
+ });
1862
+ });
1863
+ } else if (slot === "hover") {
1864
+ clearSlot(slot);
1865
+ if (transitioning) continue;
1866
+ const keys = [...hovered];
1867
+ keys.forEach((key, index) => {
1868
+ const entry = entries.get(key);
1869
+ if (entry) start(entry, slot, entry.data, {
1870
+ index,
1871
+ count: keys.length
1872
+ });
1873
+ });
1874
+ } else for (const entry of [...entries.values()]) {
1875
+ const run = entry.runs.get(slot);
1876
+ if (!run) continue;
1877
+ const done = run.done;
1878
+ run.done = void 0;
1879
+ const data = latestData(entry, run);
1880
+ clearRun(run);
1881
+ start(entry, slot, data, run.batch, {
1882
+ previous: run.previous,
1883
+ done,
1884
+ order: run.order,
1885
+ end: true
1886
+ });
1887
+ }
1888
+ },
1889
+ destroy() {
1890
+ if (destroyed) return;
1891
+ destroyed = true;
1892
+ transitioning = false;
1893
+ unsubscribe();
1894
+ for (const entry of [...entries.values()]) forget(entry);
1895
+ hovered.clear();
1896
+ }
1897
+ };
1898
+ }
1899
+ function withPrevious(data, previous) {
1900
+ return {
1901
+ datum: data.datum,
1902
+ samples: data.samples,
1903
+ related: (series) => data.related(series),
1904
+ previous
1905
+ };
1906
+ }
1907
+ // src/core/transition.ts
1908
+ const NO_ICONS = { get: () => void 0 };
1909
+ const NO_MARK = {
1910
+ set() {},
1911
+ reset() {}
1912
+ };
1913
+ const INERT = {
1914
+ place() {},
1915
+ update() {},
1916
+ remove() {}
1917
+ };
1918
+ function playTransition(pairs, options) {
1919
+ const { effect, surface } = options;
1920
+ if (!isTransitionEffect(effect)) throw new TypeError(`playTransition needs a transition effect (kind "transition" with run, end and clear), got ${describeEffect(effect)}.`);
1921
+ const start = options.start ?? 0;
1922
+ if (!(typeof start === "number" && start >= 0 && start <= 1)) throw new RangeError(`playTransition: start must be a number from 0 to 1, got ${String(start)}.`);
1923
+ const motion$1 = options.motion ?? motion;
1924
+ const clock = options.clock ?? defaultClock;
1925
+ const icons = options.icons ?? NO_ICONS;
1926
+ const count = pairs.length;
1927
+ const runs = [];
1928
+ let cleared = false;
1929
+ let waiting = count;
1930
+ let resolve;
1931
+ const finished = new Promise((r) => {
1932
+ resolve = r;
1933
+ });
1934
+ let unsubscribe = count > 0 ? motion$1.subscribe(() => {
1935
+ if (motion$1.mode === "off") endRunning();
1936
+ }) : void 0;
1937
+ const settled = () => {
1938
+ if (--waiting > 0) return;
1939
+ unsubscribe?.();
1940
+ unsubscribe = void 0;
1941
+ resolve();
1942
+ };
1943
+ function begin(pair, index, done) {
1944
+ const scope = runScope({
1945
+ clock,
1946
+ motion: motion$1,
1947
+ icons,
1948
+ batch: {
1949
+ index,
1950
+ count
1951
+ },
1952
+ layer: pairLayer(pair.to.key, index, () => run.state !== "cleared"),
1953
+ mark: NO_MARK
1954
+ });
1955
+ const run = {
1956
+ pair,
1957
+ index,
1958
+ scope,
1959
+ context: {
1960
+ ...scope.context,
1961
+ start
1962
+ },
1963
+ state: "running",
1964
+ done
1965
+ };
1966
+ runs[index] = run;
1967
+ const { from, to } = pair;
1968
+ try {
1969
+ if (motion$1.mode === "off") {
1970
+ effect.end(from, to, run.context);
1971
+ finish(run);
1972
+ } else Promise.resolve(effect.run(from, to, run.context)).then(() => finish(run), (error) => fail(run, error));
1973
+ } catch (error) {
1974
+ fail(run, error);
1975
+ }
1976
+ }
1977
+ function finish(run) {
1978
+ if (run.state !== "running") return;
1979
+ run.state = "ended";
1980
+ release(run);
1981
+ }
1982
+ function fail(run, error) {
1983
+ const { signal } = run.context;
1984
+ if (signal.aborted && (error === signal.reason || error?.name === "AbortError")) return;
1985
+ report(error);
1986
+ clearRun(run);
1987
+ }
1988
+ function release(run) {
1989
+ const done = run.done;
1990
+ run.done = void 0;
1991
+ done?.();
1992
+ }
1993
+ function clearRun(run) {
1994
+ if (run.state === "cleared") return;
1995
+ run.state = "cleared";
1996
+ run.scope.abort();
1997
+ try {
1998
+ effect.clear(run.context);
1999
+ } catch (error) {
2000
+ report(error);
2001
+ }
2002
+ run.scope.clear();
2003
+ release(run);
2004
+ }
2005
+ function endRunning() {
2006
+ for (const run of [...runs]) {
2007
+ if (run.state !== "running") continue;
2008
+ const done = run.done;
2009
+ run.done = void 0;
2010
+ clearRun(run);
2011
+ begin(run.pair, run.index, done);
2012
+ }
2013
+ }
2014
+ function pairLayer(key, order, live) {
2015
+ let group;
2016
+ const target = () => live() ? group ?? (group = surface.group(key, order)) : void 0;
2017
+ return {
2018
+ icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT,
2019
+ path: (d, paint) => target()?.path(d, paint) ?? INERT,
2020
+ text: (content, style) => target()?.text(content, style) ?? INERT,
2021
+ clear() {
2022
+ const drawn = group;
2023
+ group = void 0;
2024
+ drawn?.clear();
2025
+ }
2026
+ };
2027
+ }
2028
+ pairs.forEach((pair, index) => begin(pair, index, settled));
2029
+ if (count === 0) resolve();
2030
+ return {
2031
+ finished,
2032
+ clear() {
2033
+ if (cleared) return;
2034
+ cleared = true;
2035
+ for (const run of [...runs]) clearRun(run);
2036
+ }
2037
+ };
2038
+ }
2039
+ function isTransitionEffect(value) {
2040
+ if (typeof value !== "object" || value === null) return false;
2041
+ const effect = value;
2042
+ return effect.kind === "transition" && typeof effect.run === "function" && typeof effect.end === "function" && typeof effect.clear === "function";
2043
+ }
2044
+ function describeEffect(value) {
2045
+ if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
2046
+ const kind = value.kind;
2047
+ if (kind === "geometry" || kind === "data") return `a ${kind} effect, which plays on one mark: put it in a chart's \`on\` option`;
2048
+ if (kind === "transition") return "a transition effect without run(), end() and clear()";
2049
+ return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
2050
+ }
2051
+ export { linear as A, createMotion as C, scaleDuration as D, motion as E, report as F, createClock as M, defaultClock as N, easeInOutCubic as O, manualClock as P, TIMINGS as S, mediaReducedMotion as T, describePoint as _, mergeFields as a, describeArc as b, describeValue as c, describe as d, describeShape as f, transformPath as g, shapeOutline as h, runScope as i, unease as j, easeOutCubic as k, isMarkEffect as l, parsePath as m, playTransition as n, EFFECT_SLOTS as o, formatPath as p, createRunner as r, createRegistry as s, isTransitionEffect as t, resolveEffects as u, describeLine as v, defaultScaling as w, tween as x, describeBar as y };
2052
+
2053
+ //# sourceMappingURL=transition-DSRt2DH3.js.map