expressive-charts 0.12.0 → 0.13.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.
package/dist/index.cjs CHANGED
@@ -392,7 +392,7 @@ function animated(initial, interpolate, options = {}) {
392
392
  // src/core/playback.ts
393
393
  const SEEK_MS = 350;
394
394
  function playback(options) {
395
- checkOptions$15(options);
395
+ checkOptions$16(options);
396
396
  const { from, to, duration, onFrame } = options;
397
397
  const ease = options.ease ?? linear;
398
398
  const timing = options.timing ?? "playback";
@@ -535,7 +535,7 @@ function playback(options) {
535
535
  }
536
536
  };
537
537
  }
538
- function checkOptions$15(options) {
538
+ function checkOptions$16(options) {
539
539
  if (typeof options !== "object" || options === null) throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
540
540
  const { from, to, duration, ease, timing, onFrame, clock, motion } = options;
541
541
  for (const [name, value] of [["from", from], ["to", to]]) if (!isFiniteNumber(value)) throw new RangeError(`playback: ${name} must be a finite number, got ${String(value)}.`);
@@ -2678,6 +2678,7 @@ function textMeasure(svg) {
2678
2678
  if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
2679
2679
  probe.textContent = text;
2680
2680
  width = probe.getComputedTextLength();
2681
+ if (width > 0 && leavesSpacingOut(svg)) width += spacingIn(probe, text);
2681
2682
  }
2682
2683
  probe.remove();
2683
2684
  if (!(width > 0)) return text.length * size * AVERAGE_WIDTH;
@@ -2686,6 +2687,34 @@ function textMeasure(svg) {
2686
2687
  };
2687
2688
  return Object.assign(measure, { clear: () => cache.clear() });
2688
2689
  }
2690
+ const unspaced = /* @__PURE__ */ new WeakMap();
2691
+ const TEST_SPACING = 8;
2692
+ function leavesSpacingOut(svg) {
2693
+ const doc = svg.ownerDocument;
2694
+ let found = unspaced.get(doc);
2695
+ if (found !== void 0) return found;
2696
+ const probe = svgElement("text", {
2697
+ visibility: "hidden",
2698
+ "aria-hidden": "true"
2699
+ }, svg);
2700
+ if (typeof probe.getEndPositionOfChar !== "function") found = false;
2701
+ else {
2702
+ probe.style.setProperty("letter-spacing", `${TEST_SPACING}px`, "important");
2703
+ probe.textContent = "00";
2704
+ const spacing = px(styleOf(probe)?.letterSpacing);
2705
+ const length = probe.getComputedTextLength();
2706
+ if (spacing > 0 && length > 0) found = probe.getEndPositionOfChar(1).x - probe.getStartPositionOfChar(0).x - length > spacing / 2;
2707
+ }
2708
+ probe.remove();
2709
+ if (found !== void 0) unspaced.set(doc, found);
2710
+ return found ?? false;
2711
+ }
2712
+ function spacingIn(probe, text) {
2713
+ const style = styleOf(probe);
2714
+ return px(style?.letterSpacing) * (Array.from(text).length - 1) + px(style?.wordSpacing) * (text.split(/[  ]/).length - 1);
2715
+ }
2716
+ const styleOf = (element) => element.ownerDocument.defaultView?.getComputedStyle(element);
2717
+ const px = (value) => Number.parseFloat(value ?? "") || 0;
2689
2718
  // src/charts/bar-layout.ts
2690
2719
  const ROW = 34;
2691
2720
  const BAR = 20;
@@ -5556,7 +5585,7 @@ function viewBox$1(svg) {
5556
5585
  const STAGE$2 = 500;
5557
5586
  function barChart$1(target, options, env) {
5558
5587
  const container = resolveTarget$2(target, "barChart");
5559
- checkOptions$14(options);
5588
+ checkOptions$15(options);
5560
5589
  let current = options;
5561
5590
  const motion = chartMotion(options.motion, env.motion);
5562
5591
  let effects = resolveEffects(options.on, env.presets);
@@ -6152,7 +6181,7 @@ function barChart$1(target, options, env) {
6152
6181
  ...current,
6153
6182
  ...next
6154
6183
  };
6155
- checkOptions$14(merged);
6184
+ checkOptions$15(merged);
6156
6185
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
6157
6186
  const nextLayout = layout(merged, swapped);
6158
6187
  const nextTable = tableFor(merged, nextLayout);
@@ -6244,7 +6273,7 @@ function barChart$1(target, options, env) {
6244
6273
  }
6245
6274
  });
6246
6275
  }
6247
- function checkOptions$14(options) {
6276
+ function checkOptions$15(options) {
6248
6277
  checkChartOptions(options, "barChart");
6249
6278
  const { colorBy, room } = options;
6250
6279
  if (room !== void 0 && !(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`barChart: room must be a number of px, 0 or more, got ${String(room)}.`);
@@ -6548,7 +6577,7 @@ const TAU = 2 * Math.PI;
6548
6577
  const VISIBLE$1 = .5;
6549
6578
  function donutChart$1(target, options, env) {
6550
6579
  const container = resolveTarget$2(target, "donutChart");
6551
- checkOptions$13(options);
6580
+ checkOptions$14(options);
6552
6581
  let current = options;
6553
6582
  const motion = chartMotion(options.motion, env.motion);
6554
6583
  let effects = resolveEffects(options.on, env.presets);
@@ -7122,7 +7151,7 @@ function donutChart$1(target, options, env) {
7122
7151
  ...current,
7123
7152
  ...next
7124
7153
  };
7125
- checkOptions$13(merged);
7154
+ checkOptions$14(merged);
7126
7155
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
7127
7156
  const nextLayout = layout(merged, swapped);
7128
7157
  const nextTable = tableFor(merged, nextLayout);
@@ -7210,7 +7239,7 @@ function donutChart$1(target, options, env) {
7210
7239
  }
7211
7240
  });
7212
7241
  }
7213
- function checkOptions$13(options) {
7242
+ function checkOptions$14(options) {
7214
7243
  checkChartOptions(options, "donutChart");
7215
7244
  const { center, sort } = options;
7216
7245
  if (center !== void 0 && center !== false && typeof center !== "function") throw new TypeError("donutChart: center must be false or a function that returns the text for the total.");
@@ -10679,6 +10708,7 @@ function watchHost(doc, clock, onChanges) {
10679
10708
  }
10680
10709
  // src/charts/adapter/expressive.ts
10681
10710
  const SVG_NS = "http://www.w3.org/2000/svg";
10711
+ const GEOMETRY_ORDER = "Since 0.13.0 geometry is called with (datum, element, key), not (element, datum, key).";
10682
10712
  const SHAPES$1 = /* @__PURE__ */ new Set([
10683
10713
  "circle",
10684
10714
  "ellipse",
@@ -10696,7 +10726,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
10696
10726
  const insides = /* @__PURE__ */ new WeakMap();
10697
10727
  const insidesOf = (port) => port ? insides.get(port) : void 0;
10698
10728
  function expressive$1(target, options, env) {
10699
- checkOptions$12(options);
10729
+ checkOptions$13(options);
10700
10730
  const motion = chartMotion(options.motion, env.motion);
10701
10731
  let effects = resolveEffects(options.on, env.presets);
10702
10732
  let given = options.on;
@@ -10778,12 +10808,18 @@ function expressive$1(target, options, env) {
10778
10808
  }
10779
10809
  function givenMark(key, pieces, index, at) {
10780
10810
  const first = pieces[0];
10781
- const geometry = options.geometry(first.element, first.datum, key);
10782
- if (typeof geometry !== "object" || geometry === null || geometry.key !== key) throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in.`);
10811
+ let geometry;
10812
+ try {
10813
+ geometry = options.geometry(first.datum, first.element, key);
10814
+ } catch (error) {
10815
+ throw Object.assign(/* @__PURE__ */ new TypeError(`expressive: geometry for "${key}" threw. ${GEOMETRY_ORDER} Its error: ${error instanceof Error ? error.message : String(error)}`), { cause: error });
10816
+ }
10817
+ if (typeof geometry !== "object" || geometry === null || geometry.key !== key) throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in. ${GEOMETRY_ORDER}`);
10818
+ const parts = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
10783
10819
  return {
10784
10820
  key,
10785
10821
  geometry,
10786
- parts: pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at)),
10822
+ parts,
10787
10823
  index
10788
10824
  };
10789
10825
  }
@@ -10805,13 +10841,14 @@ function expressive$1(target, options, env) {
10805
10841
  function rectMark(key, pieces, edge, index, at) {
10806
10842
  const { geometry, order } = describeRects(key, pieces.map((p) => p.rect), edge);
10807
10843
  const segments = geometry.segments ?? [];
10844
+ const parts = order.map((j, n) => {
10845
+ const segment = segments[n];
10846
+ return part(pieces[j], segment && segment.length >= .5 ? { d: segment.outline.d } : void 0, at);
10847
+ });
10808
10848
  return {
10809
10849
  key,
10810
- geometry,
10811
- parts: order.map((j, n) => {
10812
- const segment = segments[n];
10813
- return part(pieces[j], segment && segment.length >= .5 ? { d: segment.outline.d } : void 0, at);
10814
- }),
10850
+ geometry: labelled(geometry, parts[0]),
10851
+ parts,
10815
10852
  index,
10816
10853
  rect: {
10817
10854
  edge,
@@ -10870,12 +10907,15 @@ function expressive$1(target, options, env) {
10870
10907
  }];
10871
10908
  return {
10872
10909
  key,
10873
- geometry,
10910
+ geometry: labelled(geometry, piece),
10874
10911
  parts,
10875
10912
  index,
10876
10913
  ...tag === "circle" ? { circle: true } : {}
10877
10914
  };
10878
10915
  }
10916
+ function labelled(geometry, first) {
10917
+ return options.labelBounds ? withLabels(geometry, options.labelBounds(first.datum, first.element)) : geometry;
10918
+ }
10879
10919
  function widthOf(stroke, m, at) {
10880
10920
  const width = stroke?.width ?? 1;
10881
10921
  if (!stroke?.screen) return width * scaleOf$2(m);
@@ -11508,10 +11548,11 @@ function expressive$1(target, options, env) {
11508
11548
  if (destroyed) return;
11509
11549
  const reading = read(next ?? source);
11510
11550
  if (next !== void 0) source = next;
11511
- runner.interrupt();
11512
11551
  const diff = apply(reading);
11513
11552
  watchMarks();
11514
11553
  dropGone();
11554
+ const again = hovered?.effects ? diff.changed.flatMap(({ record }) => hovered.keys.includes(record.key) ? [record] : []) : [];
11555
+ runner.leave(again.map((record) => record.key));
11515
11556
  const exited = runner.exit(diff.exiting.map(input));
11516
11557
  emitEach("exit", diff.exiting);
11517
11558
  if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) runner.update(diff.changed.map(({ record, from }) => ({
@@ -11538,7 +11579,7 @@ function expressive$1(target, options, env) {
11538
11579
  for (const record of order) if (!entering.has(record)) following.add(record);
11539
11580
  }
11540
11581
  for (const record of following) runner.change(record.mark.geometry, record.mark.data);
11541
- runner.settle();
11582
+ runner.hover(again.filter((record) => hovered?.effects && hovered.keys.includes(record.key) && records.get(record.key) === record).map(input));
11542
11583
  keyboard?.sync();
11543
11584
  for (const listener of refreshed) listener();
11544
11585
  exited.then(() => {
@@ -11595,7 +11636,7 @@ function expressive$1(target, options, env) {
11595
11636
  }
11596
11637
  });
11597
11638
  }
11598
- function checkOptions$12(options) {
11639
+ function checkOptions$13(options) {
11599
11640
  if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
11600
11641
  if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
11601
11642
  for (const name of [
@@ -11603,6 +11644,7 @@ function checkOptions$12(options) {
11603
11644
  "segment",
11604
11645
  "value",
11605
11646
  "geometry",
11647
+ "labelBounds",
11606
11648
  "markLabel"
11607
11649
  ]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
11608
11650
  if (options.baseline !== void 0 && options.baseline !== "auto" && !isBaseline(options.baseline)) throw new RangeError(`expressive: baseline must be "left", "right", "top", "bottom" or "auto", got ${String(options.baseline)}.`);
@@ -11612,6 +11654,19 @@ function partOf(mark, key) {
11612
11654
  const segment = mark?.geometry.segments?.find((s) => s.key === key);
11613
11655
  return segment && mark.parts.find((p) => p.series === segment.series);
11614
11656
  }
11657
+ function withLabels(geometry, boxes) {
11658
+ if (!Array.isArray(boxes)) throw new TypeError(`expressive: labelBounds for "${geometry.key}" must return a list of boxes { x, y, width, height }, got ${describeValue(boxes)}.`);
11659
+ const copies = boxes.map((box) => ({
11660
+ x: box?.x,
11661
+ y: box?.y,
11662
+ width: box?.width,
11663
+ height: box?.height
11664
+ }));
11665
+ return {
11666
+ ...geometry,
11667
+ labelBounds: labelBoxes$1(`shape, for expressive's labelBounds for "${geometry.key}"`, copies)
11668
+ };
11669
+ }
11615
11670
  function ownSeries(mark) {
11616
11671
  const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
11617
11672
  return [...new Set(names.filter((name) => name !== void 0))];
@@ -11970,15 +12025,19 @@ function fromVegaView$1(view, options, env) {
11970
12025
  if (options.sample !== void 0 && typeof options.sample !== "function") throw new TypeError("fromVegaView: sample must be a function.");
11971
12026
  let current = readView();
11972
12027
  const { mark: _mark, sample: _sample, ...rest } = options;
12028
+ const read = /* @__PURE__ */ new WeakMap();
11973
12029
  const attachment = expressive$1(current.elements, {
11974
12030
  ...rest,
11975
12031
  datum: (element) => itemOf(element).datum,
11976
- geometry: (_element, _datum, key) => {
12032
+ geometry: (datum, element, key) => {
11977
12033
  const geometry = current.geometry.get(key);
11978
12034
  if (!geometry) throw new TypeError(`fromVegaView: no geometry for "${key}". Its key must be the same for every item of a mark.`);
11979
- return geometry;
12035
+ if (!options.labelBounds) return geometry;
12036
+ const labelled = withLabels(geometry, options.labelBounds(datum, element));
12037
+ read.set(labelled, geometry);
12038
+ return labelled;
11980
12039
  },
11981
- ...options.samples || !options.sample ? {} : { samples: (_datum, mark) => current.samples.get(mark) ?? [] },
12040
+ ...options.samples || !options.sample ? {} : { samples: (_datum, mark) => current.samples.get(read.get(mark) ?? mark) ?? [] },
11982
12041
  ...options.value || !options.sample ? {} : { value: (_datum, element) => current.values.get(element) }
11983
12042
  }, env);
11984
12043
  const clock = env.clock ?? defaultClock;
@@ -12484,7 +12543,7 @@ const OUT_BY = .4;
12484
12543
  const HALF = .5;
12485
12544
  function chartSwitch$1(target, options, env) {
12486
12545
  const host = resolveTarget$2(target, "chartSwitch");
12487
- const names = checkOptions$11(options);
12546
+ const names = checkOptions$12(options);
12488
12547
  const effect = options.transition;
12489
12548
  const colors = toColorAssignment(options.colors);
12490
12549
  const motion = env.motion;
@@ -13330,7 +13389,7 @@ function isView(value, container) {
13330
13389
  "destroy"
13331
13390
  ].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
13332
13391
  }
13333
- function checkOptions$11(options) {
13392
+ function checkOptions$12(options) {
13334
13393
  if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
13335
13394
  const { views, initial, transition, announce } = options;
13336
13395
  if (typeof views !== "object" || views === null) throw new TypeError("chartSwitch needs views: by name, a function that draws each view's chart in the container it's given.");
@@ -13360,10 +13419,11 @@ const HINTS = {
13360
13419
  reduced: "Your device asks for reduced motion, so motion is off. Picking a mode here overrides it."
13361
13420
  };
13362
13421
  let switches = 0;
13363
- function motionSwitch$1(target, motion, options = {}) {
13422
+ function motionSwitch$1(target, options) {
13364
13423
  const parent = resolveTarget$1(target);
13424
+ const motion = options?.motion;
13365
13425
  checkMotion(motion);
13366
- checkOptions$10(options);
13426
+ checkOptions$11(options);
13367
13427
  const labels = {
13368
13428
  ...LABELS$1,
13369
13429
  ...options.labels
@@ -13447,7 +13507,7 @@ function resolveTarget$1(target) {
13447
13507
  function checkMotion(motion) {
13448
13508
  if (typeof motion !== "object" || motion === null || typeof motion.chooseMode !== "function" || typeof motion.subscribe !== "function") throw new TypeError("motionSwitch needs a Motion, such as the page-wide `motion` or one from createMotion().");
13449
13509
  }
13450
- function checkOptions$10(options) {
13510
+ function checkOptions$11(options) {
13451
13511
  const { label, labels, hints, persist } = options;
13452
13512
  if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
13453
13513
  for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
@@ -13464,7 +13524,7 @@ const LABELS = {
13464
13524
  function playButton(target, playback, options = {}) {
13465
13525
  const parent = resolveTarget(target);
13466
13526
  checkPlayback(playback);
13467
- checkOptions$9(options);
13527
+ checkOptions$10(options);
13468
13528
  const labels = {
13469
13529
  ...LABELS,
13470
13530
  ...options.labels
@@ -13505,7 +13565,7 @@ function resolveTarget(target) {
13505
13565
  function checkPlayback(playback) {
13506
13566
  if (typeof playback !== "object" || playback === null || typeof playback.play !== "function" || typeof playback.pause !== "function" || typeof playback.subscribe !== "function") throw new TypeError("playButton needs a Playback, from playback().");
13507
13567
  }
13508
- function checkOptions$9(options) {
13568
+ function checkOptions$10(options) {
13509
13569
  const { labels } = options;
13510
13570
  if (labels === void 0) return;
13511
13571
  for (const [key, text] of Object.entries(labels)) if (typeof text !== "string" || text.trim() === "") throw new TypeError(`playButton: labels.${key} must be a string with some text, got ${JSON.stringify(text) ?? String(text)}.`);
@@ -13575,7 +13635,7 @@ const ORIENTS = [
13575
13635
  ];
13576
13636
  const RIDES = ["center", "on"];
13577
13637
  function travel(icon, options = {}) {
13578
- checkOptions$8(icon, options);
13638
+ checkOptions$9(icon, options);
13579
13639
  function plan(mark, ctx) {
13580
13640
  const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
13581
13641
  if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
@@ -13728,7 +13788,7 @@ function heading(walk, distance, window, leg) {
13728
13788
  }
13729
13789
  return walk.angle(distance / length);
13730
13790
  }
13731
- function checkOptions$8(icon, options) {
13791
+ function checkOptions$9(icon, options) {
13732
13792
  if (!(typeof icon === "string" && icon !== "") && (typeof icon !== "object" || icon === null || typeof icon.name !== "string")) throw new TypeError(`travel needs an icon or an icon's name, got ${icon === null ? "null" : typeof icon}.`);
13733
13793
  const { along, gait, size, orient, ride } = options;
13734
13794
  if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
@@ -13740,11 +13800,11 @@ function checkOptions$8(icon, options) {
13740
13800
  // src/effects/flash.ts
13741
13801
  const DURATION$7 = 900;
13742
13802
  const PEAK = .25;
13743
- const WIDTH$2 = 8;
13803
+ const WIDTH$3 = 8;
13744
13804
  const OPACITY$2 = .35;
13745
13805
  function flash(options = {}) {
13746
- checkOptions$7(options);
13747
- const width = options.width ?? WIDTH$2;
13806
+ checkOptions$8(options);
13807
+ const width = options.width ?? WIDTH$3;
13748
13808
  const opacity = options.opacity ?? OPACITY$2;
13749
13809
  const { color } = options;
13750
13810
  const show = (ctx, progress) => {
@@ -13787,7 +13847,7 @@ function easeOut(x) {
13787
13847
  const s = (lo + hi) / 2;
13788
13848
  return 3 * s * s - 2 * s * s * s;
13789
13849
  }
13790
- function checkOptions$7(options) {
13850
+ function checkOptions$8(options) {
13791
13851
  const { width, opacity, color } = options;
13792
13852
  if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`flash: width must be more than 0 px, got ${String(width)}.`);
13793
13853
  if (opacity !== void 0 && !(typeof opacity === "number" && opacity > 0 && opacity <= 1)) throw new RangeError(`flash: opacity must be more than 0 and at most 1, got ${String(opacity)}.`);
@@ -13805,7 +13865,7 @@ const MIN_REACH = .5;
13805
13865
  const SAMPLES = 64;
13806
13866
  const MAX_ANGLE = Math.PI / 12;
13807
13867
  function wiggle(options = {}) {
13808
- checkOptions$6(options);
13868
+ checkOptions$7(options);
13809
13869
  const swing = options.swing ?? SWING;
13810
13870
  return {
13811
13871
  kind: "geometry",
@@ -13850,7 +13910,7 @@ function rock(t) {
13850
13910
  const index = Math.floor(position);
13851
13911
  return SWINGS[index] * Math.sin(Math.PI * (position - index));
13852
13912
  }
13853
- function checkOptions$6(options) {
13913
+ function checkOptions$7(options) {
13854
13914
  const { swing } = options;
13855
13915
  if (swing !== void 0 && !(typeof swing === "number" && swing > 0 && swing <= SWING)) throw new RangeError(`wiggle: swing must be more than 0 and at most ${SWING} px, got ${String(swing)}.`);
13856
13916
  }
@@ -13858,13 +13918,13 @@ function checkOptions$6(options) {
13858
13918
  const DURATION$5 = 600;
13859
13919
  const TIMES = 2;
13860
13920
  const MAX_TIMES = 6;
13861
- const WIDTH$1 = 12;
13921
+ const WIDTH$2 = 12;
13862
13922
  const OPACITY$1 = .4;
13863
13923
  const LIMIT = 5e3;
13864
13924
  function pulse(options = {}) {
13865
- checkOptions$5(options);
13925
+ checkOptions$6(options);
13866
13926
  const times = options.times ?? TIMES;
13867
- const width = options.width ?? WIDTH$1;
13927
+ const width = options.width ?? WIDTH$2;
13868
13928
  const { color } = options;
13869
13929
  const show = (ctx, t) => {
13870
13930
  const visible = t > 0 && t < 1;
@@ -13895,7 +13955,7 @@ function pulse(options = {}) {
13895
13955
  clear() {}
13896
13956
  };
13897
13957
  }
13898
- function checkOptions$5(options) {
13958
+ function checkOptions$6(options) {
13899
13959
  const { times, width, color } = options;
13900
13960
  if (times !== void 0 && !(Number.isInteger(times) && times >= 1 && times <= MAX_TIMES)) throw new RangeError(`pulse: times must be a whole number from 1 to ${MAX_TIMES}, got ${String(times)}.`);
13901
13961
  if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`pulse: width must be more than 0 px, got ${String(width)}.`);
@@ -13903,15 +13963,15 @@ function checkOptions$5(options) {
13903
13963
  }
13904
13964
  // src/effects/trace.ts
13905
13965
  const DURATION$4 = 500;
13906
- const WIDTH = 3;
13966
+ const WIDTH$1 = 3;
13907
13967
  const OPACITY = .5;
13908
13968
  const MIN_WALK$2 = .5;
13909
13969
  function trace(options = {}) {
13910
- checkOptions$4(options);
13970
+ checkOptions$5(options);
13911
13971
  const duration = options.duration ?? DURATION$4;
13912
13972
  const paint = {
13913
13973
  stroke: options.color ?? "mark",
13914
- width: options.width ?? WIDTH,
13974
+ width: options.width ?? WIDTH$1,
13915
13975
  opacity: options.opacity ?? OPACITY,
13916
13976
  linecap: "round"
13917
13977
  };
@@ -13961,7 +14021,7 @@ function trace(options = {}) {
13961
14021
  clear() {}
13962
14022
  };
13963
14023
  }
13964
- function checkOptions$4(options) {
14024
+ function checkOptions$5(options) {
13965
14025
  const { color, width, opacity, duration } = options;
13966
14026
  if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
13967
14027
  if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
@@ -13973,7 +14033,7 @@ const DURATION$3 = 750;
13973
14033
  const FAINT = .3;
13974
14034
  const MIN_WALK$1 = .5;
13975
14035
  function drawIn(options = {}) {
13976
- checkOptions$3(options);
14036
+ checkOptions$4(options);
13977
14037
  const duration = options.duration ?? DURATION$3;
13978
14038
  const faint = options.faint ?? FAINT;
13979
14039
  return {
@@ -14032,7 +14092,7 @@ function drawIn(options = {}) {
14032
14092
  };
14033
14093
  }
14034
14094
  const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
14035
- function checkOptions$3(options) {
14095
+ function checkOptions$4(options) {
14036
14096
  const { duration, faint } = options;
14037
14097
  if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`drawIn: duration must be 0 ms or more, got ${String(duration)}.`);
14038
14098
  if (faint !== void 0 && !(typeof faint === "number" && faint >= 0 && faint <= 1)) throw new RangeError(`drawIn: faint must be from 0 to 1, got ${String(faint)}.`);
@@ -14219,7 +14279,7 @@ const signed = (change) => {
14219
14279
  return wording.format(change);
14220
14280
  };
14221
14281
  function delta(options = {}) {
14222
- checkOptions$2(options);
14282
+ checkOptions$3(options);
14223
14283
  const value = options.value ?? lastSample;
14224
14284
  const format = options.format ?? signed;
14225
14285
  const color = options.color ?? "text";
@@ -14251,7 +14311,7 @@ function delta(options = {}) {
14251
14311
  clear() {}
14252
14312
  };
14253
14313
  }
14254
- function checkOptions$2(options) {
14314
+ function checkOptions$3(options) {
14255
14315
  const { value, format, color } = options;
14256
14316
  if (value !== void 0 && typeof value !== "function") throw new TypeError(`delta: value must be a function that reads the mark's value from its data, got ${typeof value}.`);
14257
14317
  if (format !== void 0 && typeof format !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format}.`);
@@ -14287,7 +14347,7 @@ const MIN_WALK = .5;
14287
14347
  const TIE = 1e-9;
14288
14348
  const WHENS = ["below", "above"];
14289
14349
  function threshold(options) {
14290
- checkOptions$1(options);
14350
+ checkOptions$2(options);
14291
14351
  const { compareTo } = options;
14292
14352
  const when = options.when ?? "below";
14293
14353
  const color = options.color ?? "negative";
@@ -14458,13 +14518,57 @@ function firstAbove(values, x) {
14458
14518
  }
14459
14519
  return lo;
14460
14520
  }
14461
- function checkOptions$1(options) {
14521
+ function checkOptions$2(options) {
14462
14522
  const { compareTo, when, color } = options ?? {};
14463
14523
  if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show(compareTo)}.`);
14464
14524
  if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${show(when)}.`);
14465
14525
  if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`threshold: color must be a theme token or a CSS colour, got ${show(color)}.`);
14466
14526
  }
14467
14527
  const show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
14528
+ // src/effects/outline.ts
14529
+ const COLOR$1 = "text";
14530
+ const WIDTH = 2;
14531
+ function outline(options = {}) {
14532
+ checkOptions$1(options);
14533
+ const paint = {
14534
+ stroke: options.color ?? COLOR$1,
14535
+ width: options.width ?? WIDTH
14536
+ };
14537
+ const draw = (mark, ctx) => {
14538
+ const path = ctx.layer.path(mark.outline.d, paint);
14539
+ ctx.onChange((next) => path.update(next.outline.d));
14540
+ };
14541
+ return {
14542
+ kind: "geometry",
14543
+ async run(mark, ctx) {
14544
+ if (!ctx.signal.aborted) draw(mark, ctx);
14545
+ },
14546
+ end: draw,
14547
+ clear() {}
14548
+ };
14549
+ }
14550
+ function checkOptions$1(options) {
14551
+ const { color, width } = options;
14552
+ if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`outline: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
14553
+ if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`outline: width must be more than 0 px, got ${String(width)}.`);
14554
+ }
14555
+ // src/effects/wait.ts
14556
+ function wait(duration) {
14557
+ if (!(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`wait: duration must be 0 ms or more, got ${String(duration)}.`);
14558
+ return {
14559
+ kind: "geometry",
14560
+ async run(_mark, ctx) {
14561
+ if (ctx.signal.aborted) return;
14562
+ await ctx.tween({
14563
+ duration,
14564
+ timing: "effect",
14565
+ update() {}
14566
+ }).finished;
14567
+ },
14568
+ end() {},
14569
+ clear() {}
14570
+ };
14571
+ }
14468
14572
  // src/effects/morph.ts
14469
14573
  const DURATION = 950;
14470
14574
  const POINTS = 160;
@@ -15151,8 +15255,16 @@ const GAITS = [
15151
15255
  "step",
15152
15256
  "slide"
15153
15257
  ];
15154
- const LINECAPS = ["butt", "round"];
15155
- const LINEJOINS = ["miter", "round"];
15258
+ const LINECAPS = [
15259
+ "butt",
15260
+ "round",
15261
+ "square"
15262
+ ];
15263
+ const LINEJOINS = [
15264
+ "miter",
15265
+ "round",
15266
+ "bevel"
15267
+ ];
15156
15268
  const FILL_RULES = ["nonzero", "evenodd"];
15157
15269
  const PATH_DATA = /^\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\-\s]*$/;
15158
15270
  function defineIcon(spec) {
@@ -15210,8 +15322,8 @@ function checkShape(shape, field, fail, finite) {
15210
15322
  if (value !== void 0 && (typeof value !== "string" || value === "")) fail(`${field}.${paint}`, `must be a colour, got ${String(value)}`);
15211
15323
  }
15212
15324
  if (shape.width !== void 0 && finite(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);
15213
- if (shape.linecap !== void 0 && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);
15214
- if (shape.linejoin !== void 0 && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);
15325
+ if (shape.linecap !== void 0 && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt, round or square, got ${String(shape.linecap)}`);
15326
+ if (shape.linejoin !== void 0 && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter, round or bevel, got ${String(shape.linejoin)}`);
15215
15327
  if (shape.fillRule !== void 0 && !FILL_RULES.includes(shape.fillRule)) fail(`${field}.fillRule`, `must be nonzero or evenodd, got ${String(shape.fillRule)}`);
15216
15328
  for (const key of [
15217
15329
  "opacity",
@@ -15409,8 +15521,8 @@ function inherit(parent, attributes) {
15409
15521
  fill: paint("fill", parent.fill),
15410
15522
  stroke: paint("stroke", parent.stroke),
15411
15523
  width: width >= 0 ? width : parent.width,
15412
- linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
15413
- linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
15524
+ linecap: linecap === "butt" || linecap === "round" || linecap === "square" ? linecap : parent.linecap,
15525
+ linejoin: linejoin === "miter" || linejoin === "round" || linejoin === "bevel" ? linejoin : parent.linejoin,
15414
15526
  fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
15415
15527
  opacity: parent.opacity * (alpha(attributes.get("opacity")) ?? 1),
15416
15528
  fillOpacity: alpha(attributes.get("fill-opacity")) ?? parent.fillOpacity,
@@ -15556,7 +15668,7 @@ function configure(options) {
15556
15668
  }
15557
15669
  }
15558
15670
  // src/index.ts
15559
- const VERSION = "0.12.0";
15671
+ const VERSION = "0.13.0";
15560
15672
  const env = {
15561
15673
  presets: presetRegistry,
15562
15674
  icons: iconRegistry,
@@ -15583,8 +15695,14 @@ function expressive(target, options) {
15583
15695
  function fromVegaView(view, options) {
15584
15696
  return fromVegaView$1(view, options, env);
15585
15697
  }
15586
- function motionSwitch(target, motion$1 = motion, options) {
15587
- return motionSwitch$1(target, motion$1, options);
15698
+ function motionSwitch(target, second, third) {
15699
+ const old = third !== void 0 || second !== void 0 && (typeof second !== "object" || second === null || "chooseMode" in second);
15700
+ const options = (old ? third : second) ?? {};
15701
+ const motion$1 = old && second !== void 0 ? second : options.motion ?? motion;
15702
+ return motionSwitch$1(target, {
15703
+ ...options,
15704
+ motion: motion$1
15705
+ });
15588
15706
  }
15589
15707
  exports.VERSION = VERSION;
15590
15708
  exports.animated = animated;
@@ -15627,6 +15745,7 @@ exports.motion = motion;
15627
15745
  exports.motionSwitch = motionSwitch;
15628
15746
  exports.offset = offset;
15629
15747
  exports.only = only;
15748
+ exports.outline = outline;
15630
15749
  exports.parallel = parallel;
15631
15750
  exports.playButton = playButton;
15632
15751
  exports.playback = playback;
@@ -15642,6 +15761,7 @@ exports.threshold = threshold;
15642
15761
  exports.trace = trace;
15643
15762
  exports.travel = travel;
15644
15763
  exports.tween = tween;
15764
+ exports.wait = wait;
15645
15765
  exports.wiggle = wiggle;
15646
15766
 
15647
15767
  //# sourceMappingURL=index.cjs.map