expressive-charts 0.3.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 +40 -1
  2. package/README.md +6 -6
  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 +2 -0
  10. package/dist/expressive-charts.css.d.cts +1 -2
  11. package/dist/expressive-charts.css.d.ts +1 -2
  12. package/dist/expressive-charts.global.js +45 -47
  13. package/dist/expressive-charts.global.js.map +1 -1
  14. package/dist/icons/sport.cjs +211 -156
  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 +12632 -9979
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +913 -871
  23. package/dist/index.d.ts +913 -871
  24. package/dist/index.js +10444 -8232
  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 +2030 -1252
  29. package/dist/testing.cjs.map +1 -1
  30. package/dist/testing.d.cts +135 -139
  31. package/dist/testing.d.ts +135 -139
  32. package/dist/testing.js +696 -499
  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 +6 -6
  37. package/dist/chunk-7A7LXXT4.js +0 -70
  38. package/dist/chunk-7A7LXXT4.js.map +0 -1
  39. package/dist/chunk-CJUQHEX6.js +0 -618
  40. package/dist/chunk-CJUQHEX6.js.map +0 -1
  41. package/dist/chunk-N2BLUETM.js +0 -1194
  42. package/dist/chunk-N2BLUETM.js.map +0 -1
  43. package/dist/drawing-CdTgixMY.d.cts +0 -206
  44. package/dist/drawing-CdTgixMY.d.ts +0 -206
  45. package/dist/effect-Bu3MHHeg.d.ts +0 -247
  46. package/dist/effect-D4vmdYP4.d.cts +0 -247
@@ -1,1194 +0,0 @@
1
- // src/core/report.ts
2
- function report(error) {
3
- const platform = globalThis.reportError;
4
- if (typeof platform === "function") platform(error);
5
- else console.error(error);
6
- }
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 id2 = requestAnimationFrame(callback);
77
- return () => cancelAnimationFrame(id2);
78
- }
79
- const id = setTimeout(() => callback(now()), 16);
80
- return () => clearTimeout(id);
81
- }
82
- };
83
- }
84
- var defaultClock = /* @__PURE__ */ createClock();
85
-
86
- // src/core/easing.ts
87
- var linear = (t) => t;
88
- var easeInOutCubic = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
89
- var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
90
- function unease(s) {
91
- return s < 0.5 ? Math.cbrt(s / 4) : 1 - Math.cbrt(2 * (1 - s)) / 2;
92
- }
93
-
94
- // src/core/motion.ts
95
- var defaultScaling = {
96
- presentation: {
97
- feedback: { factor: 1 },
98
- transition: { factor: 1 },
99
- effect: { factor: 1 },
100
- playback: { factor: 1 },
101
- stagger: { factor: 1 }
102
- },
103
- analysis: {
104
- feedback: { factor: 1 },
105
- transition: { factor: 0.35, max: 200 },
106
- effect: { factor: 0.35, min: 140, max: 300 },
107
- playback: { factor: 0.3 },
108
- // Analysis has no staging, so marks don't wait for each other.
109
- stagger: { factor: 0 }
110
- }
111
- };
112
- var MODES = ["presentation", "analysis", "off"];
113
- var TIMINGS = ["feedback", "transition", "effect", "playback", "stagger"];
114
- function createMotion(options = {}) {
115
- let requested = checkMode(options.mode ?? "presentation");
116
- let viewerChoice;
117
- const scaling = mergeScaling(options.scaling);
118
- const reduced = options.reducedMotion ?? mediaReducedMotion();
119
- const listeners = /* @__PURE__ */ new Set();
120
- let stopWatching;
121
- const effective = () => viewerChoice ?? (reduced.matches ? "off" : requested);
122
- const notify = () => {
123
- for (const listener of [...listeners]) {
124
- if (!listeners.has(listener)) continue;
125
- try {
126
- listener();
127
- } catch (error) {
128
- report(error);
129
- }
130
- }
131
- };
132
- return {
133
- get mode() {
134
- return effective();
135
- },
136
- get staged() {
137
- return effective() === "presentation";
138
- },
139
- get requested() {
140
- return requested;
141
- },
142
- get viewerChoice() {
143
- return viewerChoice;
144
- },
145
- get prefersReduced() {
146
- return reduced.matches;
147
- },
148
- duration(base, timing = "transition") {
149
- const mode = effective();
150
- return mode === "off" ? 0 : scaleDuration(base, scaling[mode][timing]);
151
- },
152
- setMode(mode) {
153
- checkMode(mode);
154
- if (mode === requested) return;
155
- requested = mode;
156
- notify();
157
- },
158
- chooseMode(mode) {
159
- checkMode(mode);
160
- if (mode === viewerChoice) return;
161
- viewerChoice = mode;
162
- notify();
163
- },
164
- clearChoice() {
165
- if (viewerChoice === void 0) return;
166
- viewerChoice = void 0;
167
- notify();
168
- },
169
- subscribe(listener) {
170
- const entry = () => listener();
171
- listeners.add(entry);
172
- stopWatching ?? (stopWatching = reduced.subscribe(notify));
173
- return () => {
174
- if (!listeners.delete(entry) || listeners.size > 0) return;
175
- stopWatching?.();
176
- stopWatching = void 0;
177
- };
178
- }
179
- };
180
- }
181
- function scaleDuration(base, rule) {
182
- if (!(base > 0)) return 0;
183
- const floor = Math.min(base, rule.min ?? 0);
184
- const ceiling = rule.max ?? Infinity;
185
- return Math.min(Math.max(base * rule.factor, floor), ceiling);
186
- }
187
- function mediaReducedMotion(query = "(prefers-reduced-motion: reduce)") {
188
- let list;
189
- const lookup = () => {
190
- if (list === void 0) {
191
- try {
192
- list = typeof matchMedia === "function" ? matchMedia(query) : null;
193
- } catch {
194
- list = null;
195
- }
196
- }
197
- return list;
198
- };
199
- return {
200
- get matches() {
201
- return lookup()?.matches ?? false;
202
- },
203
- subscribe(listener) {
204
- const media = lookup();
205
- if (!media) return () => {
206
- };
207
- const onChange = () => listener();
208
- if (typeof media.addEventListener === "function") {
209
- media.addEventListener("change", onChange);
210
- return () => media.removeEventListener("change", onChange);
211
- }
212
- media.addListener(onChange);
213
- return () => media.removeListener(onChange);
214
- }
215
- };
216
- }
217
- function checkMode(mode) {
218
- if (!MODES.includes(mode)) {
219
- throw new TypeError(`Unknown motion mode "${String(mode)}". Use one of: ${MODES.join(", ")}.`);
220
- }
221
- return mode;
222
- }
223
- function mergeScaling(overrides = {}) {
224
- const merge = (mode) => {
225
- const table = { ...defaultScaling[mode] };
226
- for (const timing of TIMINGS) {
227
- const rule = overrides[mode]?.[timing];
228
- if (rule) table[timing] = rule;
229
- }
230
- return table;
231
- };
232
- return { presentation: merge("presentation"), analysis: merge("analysis") };
233
- }
234
- var motion = /* @__PURE__ */ createMotion();
235
-
236
- // src/core/tween.ts
237
- function tween(options, env = {}) {
238
- const clock = env.clock ?? defaultClock;
239
- const view = env.motion ?? motion;
240
- const timing = options.timing ?? "transition";
241
- const ease = options.ease ?? easeInOutCubic;
242
- const duration = view.duration(options.duration, timing);
243
- const delay = options.delay ? view.duration(options.delay, timing) : 0;
244
- const { update, signal } = options;
245
- const start = clock.now();
246
- let state = "running";
247
- let unsubscribe;
248
- let resolve;
249
- const finished = new Promise((r) => {
250
- resolve = r;
251
- });
252
- const settle = (result) => {
253
- state = result;
254
- unsubscribe?.();
255
- unsubscribe = void 0;
256
- signal?.removeEventListener("abort", cancel);
257
- resolve(result);
258
- };
259
- function cancel() {
260
- if (state === "running") settle("cancelled");
261
- }
262
- let finishing = false;
263
- function finish() {
264
- if (state !== "running" || finishing) return;
265
- finishing = true;
266
- step(1);
267
- if (state === "running") settle("done");
268
- }
269
- function step(progress) {
270
- try {
271
- update(ease(progress));
272
- } catch (error) {
273
- cancel();
274
- throw error;
275
- }
276
- }
277
- const onFrame = (now) => {
278
- if (view.mode === "off") {
279
- finish();
280
- return;
281
- }
282
- const elapsed = now - start - delay;
283
- if (elapsed >= duration) finish();
284
- else if (elapsed > 0) step(elapsed / duration);
285
- };
286
- const handle = {
287
- finished,
288
- get state() {
289
- return state;
290
- },
291
- cancel,
292
- finish
293
- };
294
- if (signal?.aborted) {
295
- settle("cancelled");
296
- return handle;
297
- }
298
- signal?.addEventListener("abort", cancel, { once: true });
299
- if (duration <= 0 && delay <= 0) {
300
- finish();
301
- return handle;
302
- }
303
- step(0);
304
- if (state === "running") unsubscribe = clock.onFrame(onFrame);
305
- return handle;
306
- }
307
-
308
- // src/core/animated.ts
309
- var interpolateNumber = (a, b) => (t) => a * (1 - t) + b * t;
310
- var interpolatePoint = (a, b) => (t) => ({
311
- x: a.x * (1 - t) + b.x * t,
312
- y: a.y * (1 - t) + b.y * t
313
- });
314
- function interpolateRecord(a, b) {
315
- const keys = [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])];
316
- return (t) => {
317
- if (t === 1) return { ...b };
318
- const out = {};
319
- for (const key of keys) out[key] = (a[key] ?? 0) * (1 - t) + (b[key] ?? 0) * t;
320
- return out;
321
- };
322
- }
323
- function animated(initial, interpolate, options = {}) {
324
- const { onChange, ...env } = options;
325
- let value = initial;
326
- let target = initial;
327
- let running;
328
- let moving = false;
329
- const assign = (next) => {
330
- value = next;
331
- onChange?.(next);
332
- };
333
- const halt = () => {
334
- const current = running;
335
- running = void 0;
336
- moving = false;
337
- current?.cancel();
338
- };
339
- return {
340
- get value() {
341
- return value;
342
- },
343
- get target() {
344
- return running?.state === "cancelled" ? value : target;
345
- },
346
- get animating() {
347
- return running?.state === "running";
348
- },
349
- to(next, animate) {
350
- const interrupted = running?.state === "running" && moving && !(animate.delay && animate.delay > 0);
351
- halt();
352
- target = next;
353
- const blend = interpolate(value, next);
354
- let started = false;
355
- const current = tween(
356
- {
357
- duration: animate.duration,
358
- timing: animate.timing,
359
- ease: animate.ease ?? (interrupted ? easeOutCubic : easeInOutCubic),
360
- delay: animate.delay,
361
- signal: animate.signal,
362
- update: (progress) => {
363
- if (started) moving = true;
364
- started = true;
365
- assign(blend(progress));
366
- }
367
- },
368
- env
369
- );
370
- running = current;
371
- return current.finished;
372
- },
373
- set(next) {
374
- halt();
375
- target = next;
376
- assign(next);
377
- },
378
- stop() {
379
- halt();
380
- target = value;
381
- }
382
- };
383
- }
384
-
385
- // src/core/playback.ts
386
- var SEEK_MS = 350;
387
- function playback(options) {
388
- checkOptions(options);
389
- const { from, to, duration, onFrame } = options;
390
- const ease = options.ease ?? linear;
391
- const timing = options.timing ?? "playback";
392
- const clock = options.clock ?? defaultClock;
393
- const view = options.motion ?? motion;
394
- const low = Math.min(from, to);
395
- const high = Math.max(from, to);
396
- let position = to;
397
- let playing = false;
398
- let destroyed = false;
399
- let move;
400
- let generation = 0;
401
- const listeners = /* @__PURE__ */ new Set();
402
- const notify = (event) => {
403
- for (const listener of [...listeners]) {
404
- if (!listeners.has(listener)) continue;
405
- try {
406
- listener(event);
407
- } catch (error) {
408
- report(error);
409
- }
410
- }
411
- };
412
- const halt = () => {
413
- const current = move;
414
- move = void 0;
415
- current?.stop();
416
- return current?.moved ?? false;
417
- };
418
- const stopPlaying = () => {
419
- if (!playing) return;
420
- playing = false;
421
- notify("pause");
422
- };
423
- const fail = (error) => {
424
- generation++;
425
- halt();
426
- stopPlaying();
427
- throw error;
428
- };
429
- const assign = (x) => {
430
- if (x === position) return;
431
- position = x;
432
- try {
433
- onFrame(x);
434
- } catch (error) {
435
- fail(error);
436
- }
437
- };
438
- const glide = (target, ms, curve, landed) => {
439
- const mine = generation;
440
- if (!(ms > 0)) {
441
- assign(target);
442
- if (generation === mine) landed();
443
- return;
444
- }
445
- const origin = position;
446
- const start = clock.now();
447
- const current = {
448
- moved: false,
449
- stop: clock.onFrame((now) => {
450
- const t = view.mode === "off" ? 1 : (now - start) / ms;
451
- if (t < 1) {
452
- current.moved = true;
453
- let progress;
454
- try {
455
- progress = curve(t);
456
- } catch (error) {
457
- return fail(error);
458
- }
459
- assign(origin + (target - origin) * progress);
460
- return;
461
- }
462
- halt();
463
- assign(target);
464
- if (generation === mine) landed();
465
- })
466
- };
467
- move = current;
468
- };
469
- const landedAtEnd = () => {
470
- playing = false;
471
- notify("end");
472
- };
473
- return {
474
- get position() {
475
- return position;
476
- },
477
- get playing() {
478
- return playing;
479
- },
480
- play() {
481
- if (destroyed || playing) return;
482
- const mine = ++generation;
483
- halt();
484
- playing = true;
485
- notify("play");
486
- if (generation !== mine) return;
487
- const whole = view.duration(duration, timing);
488
- if (whole > 0 && position === to) {
489
- assign(from);
490
- if (generation !== mine) return;
491
- }
492
- glide(to, whole * Math.abs(to - position) / Math.abs(to - from), ease, landedAtEnd);
493
- },
494
- pause() {
495
- if (destroyed || !playing) return;
496
- generation++;
497
- halt();
498
- stopPlaying();
499
- },
500
- seek(x, seekOptions = {}) {
501
- checkSeek(x, seekOptions);
502
- if (destroyed) return;
503
- const mine = ++generation;
504
- const moving = halt();
505
- stopPlaying();
506
- if (generation !== mine) return;
507
- notify("seek");
508
- if (generation !== mine) return;
509
- const ms = seekOptions.animate === false ? 0 : view.duration(SEEK_MS, "transition");
510
- glide(Math.min(Math.max(x, low), high), ms, moving ? easeOutCubic : easeInOutCubic, () => {
511
- });
512
- },
513
- subscribe(listener) {
514
- if (typeof listener !== "function") throw new TypeError(`playback.subscribe needs a function, got ${typeof listener}.`);
515
- if (destroyed) return () => {
516
- };
517
- const entry = (event) => listener(event);
518
- listeners.add(entry);
519
- return () => {
520
- listeners.delete(entry);
521
- };
522
- },
523
- destroy() {
524
- if (destroyed) return;
525
- destroyed = true;
526
- generation++;
527
- halt();
528
- stopPlaying();
529
- listeners.clear();
530
- }
531
- };
532
- }
533
- function checkOptions(options) {
534
- if (typeof options !== "object" || options === null) {
535
- throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
536
- }
537
- const { from, to, duration, ease, timing, onFrame, clock, motion: motion2 } = options;
538
- for (const [name, value] of [["from", from], ["to", to]]) {
539
- if (!isFiniteNumber(value)) throw new RangeError(`playback: ${name} must be a finite number, got ${String(value)}.`);
540
- }
541
- if (from === to) throw new RangeError(`playback: from and to must differ, got ${from} for both.`);
542
- if (!isFiniteNumber(duration) || duration < 0) {
543
- throw new RangeError(`playback: duration must be a non-negative number of ms, got ${String(duration)}.`);
544
- }
545
- if (typeof onFrame !== "function") throw new TypeError(`playback: onFrame must be a function, got ${typeof onFrame}.`);
546
- if (ease !== void 0 && typeof ease !== "function") throw new TypeError(`playback: ease must be a function, got ${typeof ease}.`);
547
- if (timing !== void 0 && !TIMINGS.includes(timing)) {
548
- throw new RangeError(`playback: timing must be one of ${TIMINGS.join(", ")}, got ${JSON.stringify(timing) ?? String(timing)}.`);
549
- }
550
- if (clock !== void 0 && (typeof clock?.now !== "function" || typeof clock.onFrame !== "function")) {
551
- throw new TypeError("playback: clock must be a Clock, such as one from createClock() or manualClock().");
552
- }
553
- if (motion2 !== void 0 && typeof motion2?.duration !== "function") {
554
- throw new TypeError("playback: motion must be a Motion, such as the page-wide `motion` or one from createMotion().");
555
- }
556
- }
557
- function checkSeek(x, options) {
558
- if (!isFiniteNumber(x)) throw new RangeError(`playback.seek needs a finite number, got ${String(x)}.`);
559
- if (typeof options !== "object" || options === null) throw new TypeError("playback.seek's options must be an object, such as { animate: false }.");
560
- if (options.animate !== void 0 && typeof options.animate !== "boolean") {
561
- throw new TypeError(`playback.seek: animate must be true or false, got ${String(options.animate)}.`);
562
- }
563
- }
564
- function isFiniteNumber(value) {
565
- return typeof value === "number" && Number.isFinite(value);
566
- }
567
-
568
- // src/core/registry.ts
569
- function createRegistry(options) {
570
- const { kind, hint } = options;
571
- const entries = /* @__PURE__ */ new Map();
572
- const registry = {
573
- get: (name) => entries.get(name),
574
- resolve(name) {
575
- const value = entries.get(name);
576
- if (value !== void 0) return value;
577
- const known = entries.size > 0 ? [...entries.keys()].join(", ") : "none";
578
- throw new RangeError(`Unknown ${kind} "${String(name)}". Registered ${kind}s: ${known}.${hint ? ` ${hint}` : ""}`);
579
- },
580
- register(name, value) {
581
- if (typeof name !== "string" || name === "") throw new TypeError(`A ${kind} needs a non-empty string name, got ${JSON.stringify(name)}.`);
582
- if (value === void 0) throw new TypeError(`Registering ${kind} "${name}" needs a value.`);
583
- entries.set(name, value);
584
- },
585
- names: () => [...entries.keys()]
586
- };
587
- for (const [name, value] of Object.entries(options.entries ?? {})) registry.register(name, value);
588
- return registry;
589
- }
590
- var EFFECT_SLOTS = ["hover", "enter", "update", "exit", "decorate"];
591
- function resolveEffects(on, presets) {
592
- const effects = {};
593
- for (const slot of Object.keys(on ?? {})) {
594
- if (!EFFECT_SLOTS.includes(slot)) {
595
- throw new TypeError(`on.${slot} isn't an effect slot. Use one of: ${EFFECT_SLOTS.join(", ")}.`);
596
- }
597
- }
598
- for (const slot of EFFECT_SLOTS) {
599
- const option = on?.[slot];
600
- if (option === void 0) continue;
601
- if (typeof option === "string") {
602
- const effect = presets.resolve(option)();
603
- if (!isMarkEffect(effect)) throw new TypeError(`Preset "${option}" for on.${slot} didn't return a mark effect; it returned ${describeValue(effect)}.`);
604
- effects[slot] = effect;
605
- } else {
606
- if (!isMarkEffect(option)) throw new TypeError(`on.${slot} needs a mark effect (kind "geometry" or "data") or a preset name, got ${describeValue(option)}.`);
607
- effects[slot] = option;
608
- }
609
- }
610
- return effects;
611
- }
612
- function isMarkEffect(value) {
613
- if (typeof value !== "object" || value === null) return false;
614
- const effect = value;
615
- return (effect.kind === "geometry" || effect.kind === "data") && typeof effect.run === "function" && typeof effect.end === "function" && typeof effect.clear === "function";
616
- }
617
- function describeValue(value) {
618
- if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
619
- const kind = value.kind;
620
- if (kind === "transition") return "a transition effect, which runs between two charts rather than on one mark";
621
- if (kind === "geometry" || kind === "data") return `a ${kind} effect without run(), end() and clear()`;
622
- return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
623
- }
624
-
625
- // src/core/merge.ts
626
- function mergeFields(current, next) {
627
- const result = { ...current };
628
- for (const [field, value] of Object.entries(next ?? {})) {
629
- if (value === void 0) delete result[field];
630
- else result[field] = value;
631
- }
632
- return result;
633
- }
634
-
635
- // src/core/runner.ts
636
- function runScope(options) {
637
- const { clock, motion: motion2, layer, mark } = options;
638
- const controller = new AbortController();
639
- let listeners = [];
640
- const context = {
641
- signal: controller.signal,
642
- motion: motion2,
643
- mark,
644
- layer,
645
- icons: options.icons,
646
- batch: options.batch,
647
- ...options.previous ? { previous: options.previous } : {},
648
- tween(tweenOptions) {
649
- const own = tweenOptions.signal;
650
- const running = tween({ ...tweenOptions, signal: own ?? controller.signal }, { clock, motion: motion2 });
651
- if (own && own !== controller.signal) {
652
- if (controller.signal.aborted) running.cancel();
653
- else controller.signal.addEventListener("abort", () => running.cancel(), { once: true });
654
- }
655
- return running;
656
- },
657
- onChange(listener) {
658
- listeners.push(listener);
659
- }
660
- };
661
- return {
662
- context,
663
- abort() {
664
- controller.abort();
665
- },
666
- change(geometry, data) {
667
- for (const listener of [...listeners]) listener(geometry, data);
668
- },
669
- clear() {
670
- controller.abort();
671
- layer.clear();
672
- mark.reset();
673
- listeners = [];
674
- }
675
- };
676
- }
677
- var SLOTS = ["decorate", "enter", "update", "exit", "hover"];
678
- var NO_ICONS = { get: () => void 0 };
679
- var INERT = { place() {
680
- }, update() {
681
- }, remove() {
682
- } };
683
- function createRunner(options) {
684
- const { surface } = options;
685
- let effects = options.effects;
686
- const motion2 = options.motion ?? motion;
687
- const clock = options.clock ?? defaultClock;
688
- const icons = options.icons ?? NO_ICONS;
689
- const entries = /* @__PURE__ */ new Map();
690
- const hovered = /* @__PURE__ */ new Set();
691
- let transitioning = false;
692
- let destroyed = false;
693
- let order = 0;
694
- const unsubscribe = motion2.subscribe(() => {
695
- if (motion2.mode === "off") endRunning();
696
- });
697
- function track(input) {
698
- const key = input.mark.key;
699
- const entry = entries.get(key);
700
- if (entry) {
701
- entry.mark = input.mark;
702
- entry.data = input.data;
703
- return entry;
704
- }
705
- const created = { key, mark: input.mark, data: input.data, resting: input.data, runs: /* @__PURE__ */ new Map(), applied: {}, handle: void 0, exiting: void 0 };
706
- entries.set(key, created);
707
- return created;
708
- }
709
- function start(entry, slot, data, batch, more = {}) {
710
- const { previous, done } = more;
711
- const effect = effects[slot];
712
- if (!effect) {
713
- done?.();
714
- return;
715
- }
716
- const current = entry.runs.get(slot);
717
- if (current) clearRun(current);
718
- const run = {
719
- entry,
720
- slot,
721
- order: more.order ?? ++order,
722
- effect,
723
- data,
724
- batch,
725
- previous,
726
- style: {},
727
- state: "running",
728
- done,
729
- scope: runScope({
730
- clock,
731
- motion: motion2,
732
- icons,
733
- batch,
734
- previous,
735
- layer: runLayer(entry.key, slot, () => run.order, () => run.state !== "cleared"),
736
- mark: runMark(() => run)
737
- })
738
- };
739
- entry.runs.set(slot, run);
740
- const mark = more.mark ?? entry.mark;
741
- const ctx = run.scope.context;
742
- try {
743
- if (more.end || motion2.mode === "off") {
744
- if (effect.kind === "data") effect.end(mark, data, ctx);
745
- else effect.end(mark, ctx);
746
- finish(run);
747
- } else {
748
- const running = effect.kind === "data" ? effect.run(mark, data, ctx) : effect.run(mark, ctx);
749
- Promise.resolve(running).then(
750
- () => finish(run),
751
- (error) => fail(run, error)
752
- );
753
- }
754
- } catch (error) {
755
- fail(run, error);
756
- }
757
- }
758
- function finish(run) {
759
- if (run.state !== "running") return;
760
- run.state = "ended";
761
- release(run);
762
- }
763
- function fail(run, error) {
764
- const { signal } = run.scope.context;
765
- if (signal.aborted && (error === signal.reason || error?.name === "AbortError")) return;
766
- report(error);
767
- clearRun(run);
768
- }
769
- function release(run) {
770
- const done = run.done;
771
- run.done = void 0;
772
- done?.();
773
- }
774
- function clearRun(run) {
775
- if (run.state === "cleared") return;
776
- run.state = "cleared";
777
- const { entry } = run;
778
- if (entry.runs.get(run.slot) === run) entry.runs.delete(run.slot);
779
- run.scope.abort();
780
- try {
781
- run.effect.clear(run.scope.context);
782
- } catch (error) {
783
- report(error);
784
- }
785
- run.scope.clear();
786
- release(run);
787
- }
788
- function runLayer(key, slot, order2, live) {
789
- let group;
790
- const target = () => live() ? group ?? (group = surface.group(key, slot, order2())) : void 0;
791
- return {
792
- icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT,
793
- path: (d, paint) => target()?.path(d, paint) ?? INERT,
794
- text: (content, style) => target()?.text(content, style) ?? INERT,
795
- clear() {
796
- const drawn = group;
797
- group = void 0;
798
- drawn?.clear();
799
- }
800
- };
801
- }
802
- function runMark(own) {
803
- return {
804
- set(style) {
805
- const run = own();
806
- if (run.state === "cleared") return;
807
- run.style = mergeFields(run.style, style);
808
- applyStyle(run.entry);
809
- },
810
- reset() {
811
- const run = own();
812
- if (Object.keys(run.style).length === 0) return;
813
- run.style = {};
814
- applyStyle(run.entry);
815
- }
816
- };
817
- }
818
- function applyStyle(entry) {
819
- const runs = [...entry.runs.values()].sort((a, b) => a.order - b.order);
820
- const next = Object.assign({}, ...runs.map((run) => run.style));
821
- const applied = entry.applied;
822
- entry.applied = next;
823
- if (Object.keys(next).length === 0) {
824
- if (Object.keys(applied).length > 0) handle(entry).reset();
825
- return;
826
- }
827
- const changes = {};
828
- let changed = false;
829
- for (const field of /* @__PURE__ */ new Set([...Object.keys(applied), ...Object.keys(next)])) {
830
- if (applied[field] === next[field]) continue;
831
- changes[field] = next[field];
832
- changed = true;
833
- }
834
- if (changed) handle(entry).set(changes);
835
- }
836
- function handle(entry) {
837
- return entry.handle ?? (entry.handle = surface.mark(entry.key));
838
- }
839
- function forget(entry) {
840
- if (entries.get(entry.key) === entry) entries.delete(entry.key);
841
- hovered.delete(entry.key);
842
- const exited = entry.exiting;
843
- entry.exiting = void 0;
844
- for (const run of [...entry.runs.values()]) clearRun(run);
845
- entry.handle = void 0;
846
- exited?.();
847
- }
848
- function cancelExit(entry) {
849
- const exited = entry.exiting;
850
- if (!exited) return;
851
- entry.exiting = void 0;
852
- const run = entry.runs.get("exit");
853
- if (run) clearRun(run);
854
- exited();
855
- }
856
- function endRunning() {
857
- for (const entry of [...entries.values()]) {
858
- for (const run of [...entry.runs.values()]) {
859
- if (run.state !== "running" || entry.runs.get(run.slot) !== run) continue;
860
- const done = run.done;
861
- run.done = void 0;
862
- start(entry, run.slot, latestData(entry, run), run.batch, { previous: run.previous, done, order: run.order });
863
- }
864
- }
865
- }
866
- function clearSlot(slot) {
867
- const orders = /* @__PURE__ */ new Map();
868
- for (const entry of [...entries.values()]) {
869
- const run = entry.runs.get(slot);
870
- if (!run) continue;
871
- orders.set(entry, run.order);
872
- clearRun(run);
873
- }
874
- return orders;
875
- }
876
- function latestData(entry, run) {
877
- const previous = run.data.previous;
878
- return previous && !entry.data.previous ? withPrevious(entry.data, previous) : entry.data;
879
- }
880
- return {
881
- enter(marks) {
882
- if (destroyed) return;
883
- marks.forEach((input, index) => {
884
- const entry = track(input);
885
- entry.resting = input.data;
886
- cancelExit(entry);
887
- const batch = { index, count: marks.length };
888
- start(entry, "decorate", input.data, batch);
889
- start(entry, "enter", input.data, batch);
890
- });
891
- },
892
- update(marks) {
893
- if (destroyed) return;
894
- const changing = new Set(marks.map((input) => input.mark.key));
895
- for (const entry of [...entries.values()]) {
896
- const run = entry.runs.get("update");
897
- if (run && !changing.has(entry.key)) clearRun(run);
898
- }
899
- marks.forEach((input, index) => {
900
- const known = entries.get(input.mark.key);
901
- const previous = input.from ?? known?.mark;
902
- const data = known && !input.data.previous ? withPrevious(input.data, known.resting) : input.data;
903
- const entry = track(input);
904
- entry.resting = input.data;
905
- start(entry, "update", data, { index, count: marks.length }, { previous });
906
- });
907
- },
908
- exit(marks) {
909
- if (destroyed) return Promise.resolve();
910
- const exits = marks.map((input, index) => {
911
- const entry = track(input);
912
- cancelExit(entry);
913
- hovered.delete(entry.key);
914
- for (const run of [...entry.runs.values()]) clearRun(run);
915
- return new Promise((resolve) => {
916
- entry.exiting = resolve;
917
- if (!effects.exit) {
918
- forget(entry);
919
- return;
920
- }
921
- start(entry, "exit", input.data, { index, count: marks.length }, {
922
- done: () => {
923
- if (entry.exiting && entries.get(entry.key) === entry) forget(entry);
924
- }
925
- });
926
- });
927
- });
928
- return Promise.all(exits).then(() => void 0);
929
- },
930
- hover(marks) {
931
- if (destroyed) return;
932
- marks.forEach((input, index) => {
933
- const entry = track(input);
934
- if (entry.exiting) return;
935
- hovered.add(entry.key);
936
- if (!transitioning) start(entry, "hover", input.data, { index, count: marks.length });
937
- });
938
- },
939
- leave(keys = [...hovered]) {
940
- for (const key of keys) {
941
- hovered.delete(key);
942
- const run = entries.get(key)?.runs.get("hover");
943
- if (run) clearRun(run);
944
- }
945
- },
946
- change(mark, data) {
947
- const entry = entries.get(mark.key);
948
- if (!entry) return;
949
- entry.mark = mark;
950
- if (data) {
951
- entry.data = data;
952
- if (!transitioning) entry.resting = data;
953
- }
954
- for (const run of [...entry.runs.values()]) {
955
- if (run.state === "cleared") continue;
956
- try {
957
- run.scope.change(mark, latestData(entry, run));
958
- } catch (error) {
959
- report(error);
960
- clearRun(run);
961
- }
962
- }
963
- },
964
- interrupt() {
965
- if (destroyed) return;
966
- transitioning = true;
967
- for (const entry of [...entries.values()]) {
968
- const run = entry.runs.get("hover");
969
- if (run) clearRun(run);
970
- }
971
- },
972
- settle() {
973
- if (!transitioning) return;
974
- transitioning = false;
975
- for (const entry of entries.values()) if (!entry.exiting) entry.resting = entry.data;
976
- const keys = [...hovered];
977
- keys.forEach((key, index) => {
978
- const entry = entries.get(key);
979
- if (entry) start(entry, "hover", entry.data, { index, count: keys.length });
980
- });
981
- },
982
- swap(next, marks) {
983
- if (destroyed) return;
984
- const changed = SLOTS.filter((slot) => next[slot] !== effects[slot]);
985
- effects = next;
986
- for (const slot of changed) {
987
- if (slot === "decorate") {
988
- const orders = clearSlot(slot);
989
- marks.forEach((input, index) => {
990
- const entry = entries.get(input.mark.key) ?? track(input);
991
- if (!entry.exiting) start(entry, slot, input.data, { index, count: marks.length }, { mark: input.mark, order: orders.get(entry) });
992
- });
993
- } else if (slot === "hover") {
994
- clearSlot(slot);
995
- if (transitioning) continue;
996
- const keys = [...hovered];
997
- keys.forEach((key, index) => {
998
- const entry = entries.get(key);
999
- if (entry) start(entry, slot, entry.data, { index, count: keys.length });
1000
- });
1001
- } else {
1002
- for (const entry of [...entries.values()]) {
1003
- const run = entry.runs.get(slot);
1004
- if (!run) continue;
1005
- const done = run.done;
1006
- run.done = void 0;
1007
- const data = latestData(entry, run);
1008
- clearRun(run);
1009
- start(entry, slot, data, run.batch, { previous: run.previous, done, order: run.order, end: true });
1010
- }
1011
- }
1012
- }
1013
- },
1014
- destroy() {
1015
- if (destroyed) return;
1016
- destroyed = true;
1017
- transitioning = false;
1018
- unsubscribe();
1019
- for (const entry of [...entries.values()]) forget(entry);
1020
- hovered.clear();
1021
- }
1022
- };
1023
- }
1024
- function withPrevious(data, previous) {
1025
- return { datum: data.datum, samples: data.samples, related: (series) => data.related(series), previous };
1026
- }
1027
-
1028
- // src/core/transition.ts
1029
- var NO_ICONS2 = { get: () => void 0 };
1030
- var NO_MARK = { set() {
1031
- }, reset() {
1032
- } };
1033
- var INERT2 = { place() {
1034
- }, update() {
1035
- }, remove() {
1036
- } };
1037
- function playTransition(pairs, options) {
1038
- const { effect, surface } = options;
1039
- if (!isTransitionEffect(effect)) throw new TypeError(`playTransition needs a transition effect (kind "transition" with run, end and clear), got ${describeEffect(effect)}.`);
1040
- const start = options.start ?? 0;
1041
- if (!(typeof start === "number" && start >= 0 && start <= 1)) throw new RangeError(`playTransition: start must be a number from 0 to 1, got ${String(start)}.`);
1042
- const motion2 = options.motion ?? motion;
1043
- const clock = options.clock ?? defaultClock;
1044
- const icons = options.icons ?? NO_ICONS2;
1045
- const count = pairs.length;
1046
- const runs = [];
1047
- let cleared = false;
1048
- let waiting = count;
1049
- let resolve;
1050
- const finished = new Promise((r) => {
1051
- resolve = r;
1052
- });
1053
- let unsubscribe = count > 0 ? motion2.subscribe(() => {
1054
- if (motion2.mode === "off") endRunning();
1055
- }) : void 0;
1056
- const settled = () => {
1057
- if (--waiting > 0) return;
1058
- unsubscribe?.();
1059
- unsubscribe = void 0;
1060
- resolve();
1061
- };
1062
- function begin(pair, index, done) {
1063
- const scope = runScope({
1064
- clock,
1065
- motion: motion2,
1066
- icons,
1067
- batch: { index, count },
1068
- layer: pairLayer(pair.to.key, index, () => run.state !== "cleared"),
1069
- mark: NO_MARK
1070
- });
1071
- const run = { pair, index, scope, context: { ...scope.context, start }, state: "running", done };
1072
- runs[index] = run;
1073
- const { from, to } = pair;
1074
- try {
1075
- if (motion2.mode === "off") {
1076
- effect.end(from, to, run.context);
1077
- finish(run);
1078
- } else {
1079
- Promise.resolve(effect.run(from, to, run.context)).then(
1080
- () => finish(run),
1081
- (error) => fail(run, error)
1082
- );
1083
- }
1084
- } catch (error) {
1085
- fail(run, error);
1086
- }
1087
- }
1088
- function finish(run) {
1089
- if (run.state !== "running") return;
1090
- run.state = "ended";
1091
- release(run);
1092
- }
1093
- function fail(run, error) {
1094
- const { signal } = run.context;
1095
- if (signal.aborted && (error === signal.reason || error?.name === "AbortError")) return;
1096
- report(error);
1097
- clearRun(run);
1098
- }
1099
- function release(run) {
1100
- const done = run.done;
1101
- run.done = void 0;
1102
- done?.();
1103
- }
1104
- function clearRun(run) {
1105
- if (run.state === "cleared") return;
1106
- run.state = "cleared";
1107
- run.scope.abort();
1108
- try {
1109
- effect.clear(run.context);
1110
- } catch (error) {
1111
- report(error);
1112
- }
1113
- run.scope.clear();
1114
- release(run);
1115
- }
1116
- function endRunning() {
1117
- for (const run of [...runs]) {
1118
- if (run.state !== "running") continue;
1119
- const done = run.done;
1120
- run.done = void 0;
1121
- clearRun(run);
1122
- begin(run.pair, run.index, done);
1123
- }
1124
- }
1125
- function pairLayer(key, order, live) {
1126
- let group;
1127
- const target = () => live() ? group ?? (group = surface.group(key, order)) : void 0;
1128
- return {
1129
- icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT2,
1130
- path: (d, paint) => target()?.path(d, paint) ?? INERT2,
1131
- text: (content, style) => target()?.text(content, style) ?? INERT2,
1132
- clear() {
1133
- const drawn = group;
1134
- group = void 0;
1135
- drawn?.clear();
1136
- }
1137
- };
1138
- }
1139
- pairs.forEach((pair, index) => begin(pair, index, settled));
1140
- if (count === 0) resolve();
1141
- return {
1142
- finished,
1143
- clear() {
1144
- if (cleared) return;
1145
- cleared = true;
1146
- for (const run of [...runs]) clearRun(run);
1147
- }
1148
- };
1149
- }
1150
- function isTransitionEffect(value) {
1151
- if (typeof value !== "object" || value === null) return false;
1152
- const effect = value;
1153
- return effect.kind === "transition" && typeof effect.run === "function" && typeof effect.end === "function" && typeof effect.clear === "function";
1154
- }
1155
- function describeEffect(value) {
1156
- if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
1157
- const kind = value.kind;
1158
- if (kind === "geometry" || kind === "data") return `a ${kind} effect, which plays on one mark: put it in a chart's \`on\` option`;
1159
- if (kind === "transition") return "a transition effect without run(), end() and clear()";
1160
- return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
1161
- }
1162
-
1163
- export {
1164
- report,
1165
- createClock,
1166
- manualClock,
1167
- defaultClock,
1168
- linear,
1169
- easeInOutCubic,
1170
- easeOutCubic,
1171
- unease,
1172
- defaultScaling,
1173
- createMotion,
1174
- scaleDuration,
1175
- mediaReducedMotion,
1176
- motion,
1177
- tween,
1178
- interpolateNumber,
1179
- interpolatePoint,
1180
- interpolateRecord,
1181
- animated,
1182
- playback,
1183
- createRegistry,
1184
- EFFECT_SLOTS,
1185
- resolveEffects,
1186
- isMarkEffect,
1187
- describeValue,
1188
- mergeFields,
1189
- runScope,
1190
- createRunner,
1191
- playTransition,
1192
- isTransitionEffect
1193
- };
1194
- //# sourceMappingURL=chunk-N2BLUETM.js.map