expressive-charts 0.12.0 → 1.0.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.js CHANGED
@@ -1,6 +1,6 @@
1
- import { A as TIMINGS, B as createClock, C as flattenPath, D as describeArc, E as describeBar, F as scaleDuration, H as manualClock, I as easeInOutCubic, L as easeOutCubic, M as defaultScaling, N as mediaReducedMotion, O as loopOutline, P as motion, R as linear, S as cubicPieces, T as describeLine, U as report, V as defaultClock, _ as formatPath, a as AVERAGE_WIDTH, b as transformPath, d as createRegistry, f as describeValue$1, g as describeShape, h as describe, j as createMotion, k as tween, l as mergeFields, m as resolveEffects, n as playTransition, o as TEXT_SIZE, p as isMarkEffect, r as createRunner, s as boxAround, t as isTransitionEffect, u as EFFECT_SLOTS, v as parsePath, w as describePoint, x as FLAT, y as shapeOutline, z as unease } from "./transition-BFd3ktZY.js";
1
+ import { A as tween, B as unease, C as flattenPath, D as describeArc, E as describeBar, F as motion, H as defaultClock, I as scaleDuration, L as easeInOutCubic, M as createMotion, N as defaultScaling, O as labelBoxes$1, P as mediaReducedMotion, R as easeOutCubic, S as cubicPieces, T as describeLine, U as manualClock, V as createClock, W as report, _ as formatPath, a as AVERAGE_WIDTH, b as transformPath, d as createRegistry, f as describeValue$1, g as describeShape, h as describe, j as TIMINGS, k as loopOutline, l as mergeFields, m as resolveEffects, n as playTransition, o as TEXT_SIZE, p as isMarkEffect, r as createRunner, s as boxAround, t as isTransitionEffect, u as EFFECT_SLOTS, v as parsePath, w as describePoint, x as FLAT, y as shapeOutline, z as linear } from "./transition-BxWp6BVX.js";
2
2
  import { a as TAU$2, c as boundsOf, d as normalizeAngle, f as pointOn, l as extremes, n as formatNumber } from "./path-data-Cfjk04X8.js";
3
- import { t as defineIcon } from "./define-DeZLs1h7.js";
3
+ import { t as defineIcon } from "./define-ClDM4DNz.js";
4
4
  // src/core/animated.ts
5
5
  const interpolateNumber = (a, b) => (t) => a * (1 - t) + b * t;
6
6
  const interpolatePoint = (a, b) => (t) => ({
@@ -77,7 +77,7 @@ function animated(initial, interpolate, options = {}) {
77
77
  // src/core/playback.ts
78
78
  const SEEK_MS = 350;
79
79
  function playback(options) {
80
- checkOptions$15(options);
80
+ checkOptions$16(options);
81
81
  const { from, to, duration, onFrame } = options;
82
82
  const ease = options.ease ?? linear;
83
83
  const timing = options.timing ?? "playback";
@@ -220,7 +220,7 @@ function playback(options) {
220
220
  }
221
221
  };
222
222
  }
223
- function checkOptions$15(options) {
223
+ function checkOptions$16(options) {
224
224
  if (typeof options !== "object" || options === null) throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
225
225
  const { from, to, duration, ease, timing, onFrame, clock, motion } = options;
226
226
  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)}.`);
@@ -582,6 +582,7 @@ function textMeasure(svg) {
582
582
  if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
583
583
  probe.textContent = text;
584
584
  width = probe.getComputedTextLength();
585
+ if (width > 0 && leavesSpacingOut(svg)) width += spacingIn(probe, text);
585
586
  }
586
587
  probe.remove();
587
588
  if (!(width > 0)) return text.length * size * AVERAGE_WIDTH;
@@ -590,6 +591,34 @@ function textMeasure(svg) {
590
591
  };
591
592
  return Object.assign(measure, { clear: () => cache.clear() });
592
593
  }
594
+ const unspaced = /* @__PURE__ */ new WeakMap();
595
+ const TEST_SPACING = 8;
596
+ function leavesSpacingOut(svg) {
597
+ const doc = svg.ownerDocument;
598
+ let found = unspaced.get(doc);
599
+ if (found !== void 0) return found;
600
+ const probe = svgElement("text", {
601
+ visibility: "hidden",
602
+ "aria-hidden": "true"
603
+ }, svg);
604
+ if (typeof probe.getEndPositionOfChar !== "function") found = false;
605
+ else {
606
+ probe.style.setProperty("letter-spacing", `${TEST_SPACING}px`, "important");
607
+ probe.textContent = "00";
608
+ const spacing = px(styleOf(probe)?.letterSpacing);
609
+ const length = probe.getComputedTextLength();
610
+ if (spacing > 0 && length > 0) found = probe.getEndPositionOfChar(1).x - probe.getStartPositionOfChar(0).x - length > spacing / 2;
611
+ }
612
+ probe.remove();
613
+ if (found !== void 0) unspaced.set(doc, found);
614
+ return found ?? false;
615
+ }
616
+ function spacingIn(probe, text) {
617
+ const style = styleOf(probe);
618
+ return px(style?.letterSpacing) * (Array.from(text).length - 1) + px(style?.wordSpacing) * (text.split(/[  ]/).length - 1);
619
+ }
620
+ const styleOf = (element) => element.ownerDocument.defaultView?.getComputedStyle(element);
621
+ const px = (value) => Number.parseFloat(value ?? "") || 0;
593
622
  // src/charts/bar-layout.ts
594
623
  const ROW = 34;
595
624
  const BAR = 20;
@@ -3460,7 +3489,7 @@ function viewBox$1(svg) {
3460
3489
  const STAGE$2 = 500;
3461
3490
  function barChart$1(target, options, env) {
3462
3491
  const container = resolveTarget$2(target, "barChart");
3463
- checkOptions$14(options);
3492
+ checkOptions$15(options);
3464
3493
  let current = options;
3465
3494
  const motion = chartMotion(options.motion, env.motion);
3466
3495
  let effects = resolveEffects(options.on, env.presets);
@@ -4056,7 +4085,7 @@ function barChart$1(target, options, env) {
4056
4085
  ...current,
4057
4086
  ...next
4058
4087
  };
4059
- checkOptions$14(merged);
4088
+ checkOptions$15(merged);
4060
4089
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
4061
4090
  const nextLayout = layout(merged, swapped);
4062
4091
  const nextTable = tableFor(merged, nextLayout);
@@ -4148,7 +4177,7 @@ function barChart$1(target, options, env) {
4148
4177
  }
4149
4178
  });
4150
4179
  }
4151
- function checkOptions$14(options) {
4180
+ function checkOptions$15(options) {
4152
4181
  checkChartOptions(options, "barChart");
4153
4182
  const { colorBy, room } = options;
4154
4183
  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)}.`);
@@ -4452,7 +4481,7 @@ const TAU = 2 * Math.PI;
4452
4481
  const VISIBLE$1 = .5;
4453
4482
  function donutChart$1(target, options, env) {
4454
4483
  const container = resolveTarget$2(target, "donutChart");
4455
- checkOptions$13(options);
4484
+ checkOptions$14(options);
4456
4485
  let current = options;
4457
4486
  const motion = chartMotion(options.motion, env.motion);
4458
4487
  let effects = resolveEffects(options.on, env.presets);
@@ -5026,7 +5055,7 @@ function donutChart$1(target, options, env) {
5026
5055
  ...current,
5027
5056
  ...next
5028
5057
  };
5029
- checkOptions$13(merged);
5058
+ checkOptions$14(merged);
5030
5059
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
5031
5060
  const nextLayout = layout(merged, swapped);
5032
5061
  const nextTable = tableFor(merged, nextLayout);
@@ -5114,7 +5143,7 @@ function donutChart$1(target, options, env) {
5114
5143
  }
5115
5144
  });
5116
5145
  }
5117
- function checkOptions$13(options) {
5146
+ function checkOptions$14(options) {
5118
5147
  checkChartOptions(options, "donutChart");
5119
5148
  const { center, sort } = options;
5120
5149
  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.");
@@ -8583,6 +8612,7 @@ function watchHost(doc, clock, onChanges) {
8583
8612
  }
8584
8613
  // src/charts/adapter/expressive.ts
8585
8614
  const SVG_NS = "http://www.w3.org/2000/svg";
8615
+ const GEOMETRY_ORDER = "Since 0.13.0 geometry is called with (datum, element, key), not (element, datum, key).";
8586
8616
  const SHAPES$1 = /* @__PURE__ */ new Set([
8587
8617
  "circle",
8588
8618
  "ellipse",
@@ -8600,7 +8630,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
8600
8630
  const insides = /* @__PURE__ */ new WeakMap();
8601
8631
  const insidesOf = (port) => port ? insides.get(port) : void 0;
8602
8632
  function expressive$1(target, options, env) {
8603
- checkOptions$12(options);
8633
+ checkOptions$13(options);
8604
8634
  const motion = chartMotion(options.motion, env.motion);
8605
8635
  let effects = resolveEffects(options.on, env.presets);
8606
8636
  let given = options.on;
@@ -8682,12 +8712,18 @@ function expressive$1(target, options, env) {
8682
8712
  }
8683
8713
  function givenMark(key, pieces, index, at) {
8684
8714
  const first = pieces[0];
8685
- const geometry = options.geometry(first.element, first.datum, key);
8686
- 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.`);
8715
+ let geometry;
8716
+ try {
8717
+ geometry = options.geometry(first.datum, first.element, key);
8718
+ } catch (error) {
8719
+ throw Object.assign(/* @__PURE__ */ new TypeError(`expressive: geometry for "${key}" threw. ${GEOMETRY_ORDER} Its error: ${error instanceof Error ? error.message : String(error)}`), { cause: error });
8720
+ }
8721
+ 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}`);
8722
+ const parts = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
8687
8723
  return {
8688
8724
  key,
8689
8725
  geometry,
8690
- parts: pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at)),
8726
+ parts,
8691
8727
  index
8692
8728
  };
8693
8729
  }
@@ -8709,13 +8745,14 @@ function expressive$1(target, options, env) {
8709
8745
  function rectMark(key, pieces, edge, index, at) {
8710
8746
  const { geometry, order } = describeRects(key, pieces.map((p) => p.rect), edge);
8711
8747
  const segments = geometry.segments ?? [];
8748
+ const parts = order.map((j, n) => {
8749
+ const segment = segments[n];
8750
+ return part(pieces[j], segment && segment.length >= .5 ? { d: segment.outline.d } : void 0, at);
8751
+ });
8712
8752
  return {
8713
8753
  key,
8714
- geometry,
8715
- parts: order.map((j, n) => {
8716
- const segment = segments[n];
8717
- return part(pieces[j], segment && segment.length >= .5 ? { d: segment.outline.d } : void 0, at);
8718
- }),
8754
+ geometry: labelled(geometry, parts[0]),
8755
+ parts,
8719
8756
  index,
8720
8757
  rect: {
8721
8758
  edge,
@@ -8775,12 +8812,15 @@ function expressive$1(target, options, env) {
8775
8812
  }];
8776
8813
  return {
8777
8814
  key,
8778
- geometry,
8815
+ geometry: labelled(geometry, piece),
8779
8816
  parts,
8780
8817
  index,
8781
8818
  ...tag === "circle" ? { circle: true } : {}
8782
8819
  };
8783
8820
  }
8821
+ function labelled(geometry, first) {
8822
+ return options.labelBounds ? withLabels(geometry, options.labelBounds(first.datum, first.element)) : geometry;
8823
+ }
8784
8824
  function widthOf(stroke, m, at) {
8785
8825
  const width = stroke?.width ?? 1;
8786
8826
  if (!stroke?.screen) return width * scaleOf$2(m);
@@ -9413,10 +9453,11 @@ function expressive$1(target, options, env) {
9413
9453
  if (destroyed) return;
9414
9454
  const reading = read(next ?? source);
9415
9455
  if (next !== void 0) source = next;
9416
- runner.interrupt();
9417
9456
  const diff = apply(reading);
9418
9457
  watchMarks();
9419
9458
  dropGone();
9459
+ const again = hovered?.effects ? diff.changed.flatMap(({ record }) => hovered.keys.includes(record.key) ? [record] : []) : [];
9460
+ runner.leave(again.map((record) => record.key));
9420
9461
  const exited = runner.exit(diff.exiting.map(input));
9421
9462
  emitEach("exit", diff.exiting);
9422
9463
  if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) runner.update(diff.changed.map(({ record, from }) => ({
@@ -9443,7 +9484,7 @@ function expressive$1(target, options, env) {
9443
9484
  for (const record of order) if (!entering.has(record)) following.add(record);
9444
9485
  }
9445
9486
  for (const record of following) runner.change(record.mark.geometry, record.mark.data);
9446
- runner.settle();
9487
+ runner.hover(again.filter((record) => hovered?.effects && hovered.keys.includes(record.key) && records.get(record.key) === record).map(input));
9447
9488
  keyboard?.sync();
9448
9489
  for (const listener of refreshed) listener();
9449
9490
  exited.then(() => {
@@ -9500,7 +9541,7 @@ function expressive$1(target, options, env) {
9500
9541
  }
9501
9542
  });
9502
9543
  }
9503
- function checkOptions$12(options) {
9544
+ function checkOptions$13(options) {
9504
9545
  if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
9505
9546
  if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
9506
9547
  for (const name of [
@@ -9508,6 +9549,7 @@ function checkOptions$12(options) {
9508
9549
  "segment",
9509
9550
  "value",
9510
9551
  "geometry",
9552
+ "labelBounds",
9511
9553
  "markLabel"
9512
9554
  ]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
9513
9555
  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)}.`);
@@ -9517,6 +9559,19 @@ function partOf(mark, key) {
9517
9559
  const segment = mark?.geometry.segments?.find((s) => s.key === key);
9518
9560
  return segment && mark.parts.find((p) => p.series === segment.series);
9519
9561
  }
9562
+ function withLabels(geometry, boxes) {
9563
+ 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)}.`);
9564
+ const copies = boxes.map((box) => ({
9565
+ x: box?.x,
9566
+ y: box?.y,
9567
+ width: box?.width,
9568
+ height: box?.height
9569
+ }));
9570
+ return {
9571
+ ...geometry,
9572
+ labelBounds: labelBoxes$1(`shape, for expressive's labelBounds for "${geometry.key}"`, copies)
9573
+ };
9574
+ }
9520
9575
  function ownSeries(mark) {
9521
9576
  const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
9522
9577
  return [...new Set(names.filter((name) => name !== void 0))];
@@ -9875,15 +9930,19 @@ function fromVegaView$1(view, options, env) {
9875
9930
  if (options.sample !== void 0 && typeof options.sample !== "function") throw new TypeError("fromVegaView: sample must be a function.");
9876
9931
  let current = readView();
9877
9932
  const { mark: _mark, sample: _sample, ...rest } = options;
9933
+ const read = /* @__PURE__ */ new WeakMap();
9878
9934
  const attachment = expressive$1(current.elements, {
9879
9935
  ...rest,
9880
9936
  datum: (element) => itemOf(element).datum,
9881
- geometry: (_element, _datum, key) => {
9937
+ geometry: (datum, element, key) => {
9882
9938
  const geometry = current.geometry.get(key);
9883
9939
  if (!geometry) throw new TypeError(`fromVegaView: no geometry for "${key}". Its key must be the same for every item of a mark.`);
9884
- return geometry;
9940
+ if (!options.labelBounds) return geometry;
9941
+ const labelled = withLabels(geometry, options.labelBounds(datum, element));
9942
+ read.set(labelled, geometry);
9943
+ return labelled;
9885
9944
  },
9886
- ...options.samples || !options.sample ? {} : { samples: (_datum, mark) => current.samples.get(mark) ?? [] },
9945
+ ...options.samples || !options.sample ? {} : { samples: (_datum, mark) => current.samples.get(read.get(mark) ?? mark) ?? [] },
9887
9946
  ...options.value || !options.sample ? {} : { value: (_datum, element) => current.values.get(element) }
9888
9947
  }, env);
9889
9948
  const clock = env.clock ?? defaultClock;
@@ -10245,7 +10304,7 @@ const OUT_BY = .4;
10245
10304
  const HALF = .5;
10246
10305
  function chartSwitch$1(target, options, env) {
10247
10306
  const host = resolveTarget$2(target, "chartSwitch");
10248
- const names = checkOptions$11(options);
10307
+ const names = checkOptions$12(options);
10249
10308
  const effect = options.transition;
10250
10309
  const colors = toColorAssignment(options.colors);
10251
10310
  const motion = env.motion;
@@ -11091,7 +11150,7 @@ function isView(value, container) {
11091
11150
  "destroy"
11092
11151
  ].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
11093
11152
  }
11094
- function checkOptions$11(options) {
11153
+ function checkOptions$12(options) {
11095
11154
  if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
11096
11155
  const { views, initial, transition, announce } = options;
11097
11156
  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.");
@@ -11121,10 +11180,11 @@ const HINTS = {
11121
11180
  reduced: "Your device asks for reduced motion, so motion is off. Picking a mode here overrides it."
11122
11181
  };
11123
11182
  let switches = 0;
11124
- function motionSwitch$1(target, motion, options = {}) {
11183
+ function motionSwitch$1(target, options) {
11125
11184
  const parent = resolveTarget$1(target);
11185
+ const motion = options?.motion;
11126
11186
  checkMotion(motion);
11127
- checkOptions$10(options);
11187
+ checkOptions$11(options);
11128
11188
  const labels = {
11129
11189
  ...LABELS$1,
11130
11190
  ...options.labels
@@ -11208,7 +11268,7 @@ function resolveTarget$1(target) {
11208
11268
  function checkMotion(motion) {
11209
11269
  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().");
11210
11270
  }
11211
- function checkOptions$10(options) {
11271
+ function checkOptions$11(options) {
11212
11272
  const { label, labels, hints, persist } = options;
11213
11273
  if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
11214
11274
  for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
@@ -11225,7 +11285,7 @@ const LABELS = {
11225
11285
  function playButton(target, playback, options = {}) {
11226
11286
  const parent = resolveTarget(target);
11227
11287
  checkPlayback(playback);
11228
- checkOptions$9(options);
11288
+ checkOptions$10(options);
11229
11289
  const labels = {
11230
11290
  ...LABELS,
11231
11291
  ...options.labels
@@ -11266,7 +11326,7 @@ function resolveTarget(target) {
11266
11326
  function checkPlayback(playback) {
11267
11327
  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().");
11268
11328
  }
11269
- function checkOptions$9(options) {
11329
+ function checkOptions$10(options) {
11270
11330
  const { labels } = options;
11271
11331
  if (labels === void 0) return;
11272
11332
  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)}.`);
@@ -11336,7 +11396,7 @@ const ORIENTS = [
11336
11396
  ];
11337
11397
  const RIDES = ["center", "on"];
11338
11398
  function travel(icon, options = {}) {
11339
- checkOptions$8(icon, options);
11399
+ checkOptions$9(icon, options);
11340
11400
  function plan(mark, ctx) {
11341
11401
  const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
11342
11402
  if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
@@ -11489,7 +11549,7 @@ function heading(walk, distance, window, leg) {
11489
11549
  }
11490
11550
  return walk.angle(distance / length);
11491
11551
  }
11492
- function checkOptions$8(icon, options) {
11552
+ function checkOptions$9(icon, options) {
11493
11553
  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}.`);
11494
11554
  const { along, gait, size, orient, ride } = options;
11495
11555
  if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
@@ -11501,11 +11561,11 @@ function checkOptions$8(icon, options) {
11501
11561
  // src/effects/flash.ts
11502
11562
  const DURATION$7 = 900;
11503
11563
  const PEAK = .25;
11504
- const WIDTH$2 = 8;
11564
+ const WIDTH$3 = 8;
11505
11565
  const OPACITY$2 = .35;
11506
11566
  function flash(options = {}) {
11507
- checkOptions$7(options);
11508
- const width = options.width ?? WIDTH$2;
11567
+ checkOptions$8(options);
11568
+ const width = options.width ?? WIDTH$3;
11509
11569
  const opacity = options.opacity ?? OPACITY$2;
11510
11570
  const { color } = options;
11511
11571
  const show = (ctx, progress) => {
@@ -11548,7 +11608,7 @@ function easeOut(x) {
11548
11608
  const s = (lo + hi) / 2;
11549
11609
  return 3 * s * s - 2 * s * s * s;
11550
11610
  }
11551
- function checkOptions$7(options) {
11611
+ function checkOptions$8(options) {
11552
11612
  const { width, opacity, color } = options;
11553
11613
  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)}.`);
11554
11614
  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)}.`);
@@ -11566,7 +11626,7 @@ const MIN_REACH = .5;
11566
11626
  const SAMPLES = 64;
11567
11627
  const MAX_ANGLE = Math.PI / 12;
11568
11628
  function wiggle(options = {}) {
11569
- checkOptions$6(options);
11629
+ checkOptions$7(options);
11570
11630
  const swing = options.swing ?? SWING;
11571
11631
  return {
11572
11632
  kind: "geometry",
@@ -11611,7 +11671,7 @@ function rock(t) {
11611
11671
  const index = Math.floor(position);
11612
11672
  return SWINGS[index] * Math.sin(Math.PI * (position - index));
11613
11673
  }
11614
- function checkOptions$6(options) {
11674
+ function checkOptions$7(options) {
11615
11675
  const { swing } = options;
11616
11676
  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)}.`);
11617
11677
  }
@@ -11619,13 +11679,13 @@ function checkOptions$6(options) {
11619
11679
  const DURATION$5 = 600;
11620
11680
  const TIMES = 2;
11621
11681
  const MAX_TIMES = 6;
11622
- const WIDTH$1 = 12;
11682
+ const WIDTH$2 = 12;
11623
11683
  const OPACITY$1 = .4;
11624
11684
  const LIMIT = 5e3;
11625
11685
  function pulse(options = {}) {
11626
- checkOptions$5(options);
11686
+ checkOptions$6(options);
11627
11687
  const times = options.times ?? TIMES;
11628
- const width = options.width ?? WIDTH$1;
11688
+ const width = options.width ?? WIDTH$2;
11629
11689
  const { color } = options;
11630
11690
  const show = (ctx, t) => {
11631
11691
  const visible = t > 0 && t < 1;
@@ -11656,7 +11716,7 @@ function pulse(options = {}) {
11656
11716
  clear() {}
11657
11717
  };
11658
11718
  }
11659
- function checkOptions$5(options) {
11719
+ function checkOptions$6(options) {
11660
11720
  const { times, width, color } = options;
11661
11721
  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)}.`);
11662
11722
  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)}.`);
@@ -11664,15 +11724,15 @@ function checkOptions$5(options) {
11664
11724
  }
11665
11725
  // src/effects/trace.ts
11666
11726
  const DURATION$4 = 500;
11667
- const WIDTH = 3;
11727
+ const WIDTH$1 = 3;
11668
11728
  const OPACITY = .5;
11669
11729
  const MIN_WALK$2 = .5;
11670
11730
  function trace(options = {}) {
11671
- checkOptions$4(options);
11731
+ checkOptions$5(options);
11672
11732
  const duration = options.duration ?? DURATION$4;
11673
11733
  const paint = {
11674
11734
  stroke: options.color ?? "mark",
11675
- width: options.width ?? WIDTH,
11735
+ width: options.width ?? WIDTH$1,
11676
11736
  opacity: options.opacity ?? OPACITY,
11677
11737
  linecap: "round"
11678
11738
  };
@@ -11722,7 +11782,7 @@ function trace(options = {}) {
11722
11782
  clear() {}
11723
11783
  };
11724
11784
  }
11725
- function checkOptions$4(options) {
11785
+ function checkOptions$5(options) {
11726
11786
  const { color, width, opacity, duration } = options;
11727
11787
  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)}.`);
11728
11788
  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)}.`);
@@ -11734,7 +11794,7 @@ const DURATION$3 = 750;
11734
11794
  const FAINT = .3;
11735
11795
  const MIN_WALK$1 = .5;
11736
11796
  function drawIn(options = {}) {
11737
- checkOptions$3(options);
11797
+ checkOptions$4(options);
11738
11798
  const duration = options.duration ?? DURATION$3;
11739
11799
  const faint = options.faint ?? FAINT;
11740
11800
  return {
@@ -11793,7 +11853,7 @@ function drawIn(options = {}) {
11793
11853
  };
11794
11854
  }
11795
11855
  const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
11796
- function checkOptions$3(options) {
11856
+ function checkOptions$4(options) {
11797
11857
  const { duration, faint } = options;
11798
11858
  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)}.`);
11799
11859
  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)}.`);
@@ -11980,7 +12040,7 @@ const signed = (change) => {
11980
12040
  return wording.format(change);
11981
12041
  };
11982
12042
  function delta(options = {}) {
11983
- checkOptions$2(options);
12043
+ checkOptions$3(options);
11984
12044
  const value = options.value ?? lastSample;
11985
12045
  const format = options.format ?? signed;
11986
12046
  const color = options.color ?? "text";
@@ -12012,7 +12072,7 @@ function delta(options = {}) {
12012
12072
  clear() {}
12013
12073
  };
12014
12074
  }
12015
- function checkOptions$2(options) {
12075
+ function checkOptions$3(options) {
12016
12076
  const { value, format, color } = options;
12017
12077
  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}.`);
12018
12078
  if (format !== void 0 && typeof format !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format}.`);
@@ -12048,7 +12108,7 @@ const MIN_WALK = .5;
12048
12108
  const TIE = 1e-9;
12049
12109
  const WHENS = ["below", "above"];
12050
12110
  function threshold(options) {
12051
- checkOptions$1(options);
12111
+ checkOptions$2(options);
12052
12112
  const { compareTo } = options;
12053
12113
  const when = options.when ?? "below";
12054
12114
  const color = options.color ?? "negative";
@@ -12219,13 +12279,57 @@ function firstAbove(values, x) {
12219
12279
  }
12220
12280
  return lo;
12221
12281
  }
12222
- function checkOptions$1(options) {
12282
+ function checkOptions$2(options) {
12223
12283
  const { compareTo, when, color } = options ?? {};
12224
12284
  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)}.`);
12225
12285
  if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${show(when)}.`);
12226
12286
  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)}.`);
12227
12287
  }
12228
12288
  const show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
12289
+ // src/effects/outline.ts
12290
+ const COLOR$1 = "text";
12291
+ const WIDTH = 2;
12292
+ function outline(options = {}) {
12293
+ checkOptions$1(options);
12294
+ const paint = {
12295
+ stroke: options.color ?? COLOR$1,
12296
+ width: options.width ?? WIDTH
12297
+ };
12298
+ const draw = (mark, ctx) => {
12299
+ const path = ctx.layer.path(mark.outline.d, paint);
12300
+ ctx.onChange((next) => path.update(next.outline.d));
12301
+ };
12302
+ return {
12303
+ kind: "geometry",
12304
+ async run(mark, ctx) {
12305
+ if (!ctx.signal.aborted) draw(mark, ctx);
12306
+ },
12307
+ end: draw,
12308
+ clear() {}
12309
+ };
12310
+ }
12311
+ function checkOptions$1(options) {
12312
+ const { color, width } = options;
12313
+ 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)}.`);
12314
+ 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)}.`);
12315
+ }
12316
+ // src/effects/wait.ts
12317
+ function wait(duration) {
12318
+ if (!(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`wait: duration must be 0 ms or more, got ${String(duration)}.`);
12319
+ return {
12320
+ kind: "geometry",
12321
+ async run(_mark, ctx) {
12322
+ if (ctx.signal.aborted) return;
12323
+ await ctx.tween({
12324
+ duration,
12325
+ timing: "effect",
12326
+ update() {}
12327
+ }).finished;
12328
+ },
12329
+ end() {},
12330
+ clear() {}
12331
+ };
12332
+ }
12229
12333
  // src/effects/morph.ts
12230
12334
  const DURATION = 950;
12231
12335
  const POINTS = 160;
@@ -13078,8 +13182,8 @@ function inherit(parent, attributes) {
13078
13182
  fill: paint("fill", parent.fill),
13079
13183
  stroke: paint("stroke", parent.stroke),
13080
13184
  width: width >= 0 ? width : parent.width,
13081
- linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
13082
- linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
13185
+ linecap: linecap === "butt" || linecap === "round" || linecap === "square" ? linecap : parent.linecap,
13186
+ linejoin: linejoin === "miter" || linejoin === "round" || linejoin === "bevel" ? linejoin : parent.linejoin,
13083
13187
  fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
13084
13188
  opacity: parent.opacity * (alpha(attributes.get("opacity")) ?? 1),
13085
13189
  fillOpacity: alpha(attributes.get("fill-opacity")) ?? parent.fillOpacity,
@@ -13225,7 +13329,7 @@ function configure(options) {
13225
13329
  }
13226
13330
  }
13227
13331
  // src/index.ts
13228
- const VERSION = "0.12.0";
13332
+ const VERSION = "1.0.0";
13229
13333
  const env = {
13230
13334
  presets: presetRegistry,
13231
13335
  icons: iconRegistry,
@@ -13252,9 +13356,14 @@ function expressive(target, options) {
13252
13356
  function fromVegaView(view, options) {
13253
13357
  return fromVegaView$1(view, options, env);
13254
13358
  }
13255
- function motionSwitch(target, motion$1 = motion, options) {
13256
- return motionSwitch$1(target, motion$1, options);
13359
+ function motionSwitch(target, options = {}) {
13360
+ if (arguments[2] !== void 0 || typeof options === "object" && options !== null && "chooseMode" in options) throw new TypeError("Since 1.0 motionSwitch takes (target, options), with the motion among the options: motionSwitch(target, { motion, ...options }).");
13361
+ if (typeof options !== "object" || options === null) throw new TypeError(`motionSwitch: options must be an object, got ${options === null ? "null" : typeof options}.`);
13362
+ return motionSwitch$1(target, {
13363
+ ...options,
13364
+ motion: options.motion ?? motion
13365
+ });
13257
13366
  }
13258
- export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, drawIn, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, hostView, iconFromSvg, icons, interpolateNumber, interpolatePoint, interpolateRecord, label, lineChart, linear, link, manualClock, matrix, mediaReducedMotion, morph, motion, motionSwitch, offset, only, parallel, playButton, playback, pulse, registerIcon, registerIcons, registerPreset, samplesAlong, scaleDuration, sequence, stagger, threshold, trace, travel, tween, wiggle };
13367
+ export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, drawIn, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, hostView, iconFromSvg, icons, interpolateNumber, interpolatePoint, interpolateRecord, label, lineChart, linear, link, manualClock, matrix, mediaReducedMotion, morph, motion, motionSwitch, offset, only, outline, parallel, playButton, playback, pulse, registerIcon, registerIcons, registerPreset, samplesAlong, scaleDuration, sequence, stagger, threshold, trace, travel, tween, wait, wiggle };
13259
13368
 
13260
13369
  //# sourceMappingURL=index.js.map