expressive-charts 0.5.0 → 0.7.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,5 +1,5 @@
1
- import { A as easeInOutCubic, C as tween, D as mediaReducedMotion, E as defaultScaling, F as defaultClock, I as manualClock, L as report, M as linear, N as unease, O as motion, P as createClock, S as describeArc, T as createMotion, _ as FLAT, a as mergeFields, b as describeLine, c as describeValue$1, d as describe, f as describeShape, g as transformPath, h as shapeOutline, j as easeOutCubic, k as scaleDuration, l as isMarkEffect, m as parsePath, n as playTransition, o as EFFECT_SLOTS, p as formatPath, r as createRunner, s as createRegistry, t as isTransitionEffect, u as resolveEffects, v as cubicPieces, w as TIMINGS, x as describeBar, y as describePoint } from "./transition-Bu1NsQor.js";
2
- import { d as normalizeAngle, n as formatNumber } from "./path-data-DnEckjY8.js";
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-romki_A6.js";
2
+ import { a as TAU$2, c as boundsOf, d as normalizeAngle, f as pointOn, l as extremes, n as formatNumber } from "./path-data-DnEckjY8.js";
3
3
  import { t as defineIcon } from "./define-DeZLs1h7.js";
4
4
  // src/core/animated.ts
5
5
  const interpolateNumber = (a, b) => (t) => a * (1 - t) + 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$14(options);
80
+ checkOptions$15(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$14(options) {
223
+ function checkOptions$15(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)}.`);
@@ -421,9 +421,9 @@ function samplesAlong(mark, points) {
421
421
  ...p.at === void 0 ? {} : { at: p.at }
422
422
  }
423
423
  })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
424
- return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
424
+ return mark.gaps && mark.gaps.length > 0 ? gapped$1(samples, mark.gaps) : samples;
425
425
  }
426
- function gapped(samples, gaps) {
426
+ function gapped$1(samples, gaps) {
427
427
  const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
428
428
  let next = 0;
429
429
  return samples.map((sample, k) => {
@@ -555,16 +555,8 @@ function linear$1(value) {
555
555
  return rounded === 0 ? "0" : String(rounded);
556
556
  }
557
557
  // src/charts/render/text.ts
558
- const ASCENT$1 = 1.05;
559
- const SIDE = .16;
560
558
  function textBox(placement, measure, className, size) {
561
- const width = measure(placement.text.replace(/\d/g, "0"), className, size);
562
- return {
563
- x: (placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2) - SIDE * size,
564
- y: placement.y - ASCENT$1 * size,
565
- width: width + 2 * SIDE * size,
566
- height: 1.3 * size
567
- };
559
+ return boxAround(placement, placement.anchor, measure(placement.text.replace(/\d/g, "0"), className, size), size);
568
560
  }
569
561
  function placeText(element, placement) {
570
562
  setAttributes(element, {
@@ -574,7 +566,6 @@ function placeText(element, placement) {
574
566
  });
575
567
  if (element.textContent !== placement.text) element.textContent = placement.text;
576
568
  }
577
- const AVERAGE_WIDTH = .6;
578
569
  function textMeasure(svg) {
579
570
  const cache = /* @__PURE__ */ new Map();
580
571
  const measure = (text, className, size) => {
@@ -1670,7 +1661,7 @@ function mix$3(colors, emphasis) {
1670
1661
  // src/charts/render/layer.ts
1671
1662
  const FOLLOW = "ec-follow";
1672
1663
  let clipIds = 0;
1673
- function svgLayer(group, follow) {
1664
+ function svgLayer(group, follow, parts) {
1674
1665
  const into = () => {
1675
1666
  if (!follow) return group;
1676
1667
  const last = group.lastElementChild;
@@ -1709,13 +1700,13 @@ function svgLayer(group, follow) {
1709
1700
  d
1710
1701
  }, into());
1711
1702
  let current = { ...paint };
1712
- paintPath(element, current);
1703
+ paintPath(element, current, parts);
1713
1704
  return {
1714
1705
  update(next, nextPaint) {
1715
1706
  element.setAttribute("d", next);
1716
1707
  if (nextPaint) {
1717
1708
  current = mergeFields(current, nextPaint);
1718
- paintPath(element, current);
1709
+ paintPath(element, current, parts);
1719
1710
  }
1720
1711
  },
1721
1712
  remove: () => element.remove()
@@ -1759,14 +1750,17 @@ function drawShape(shape, parent) {
1759
1750
  stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
1760
1751
  });
1761
1752
  }
1762
- function paintPath(element, paint) {
1753
+ function paintPath(element, paint, parts) {
1754
+ const { part } = paint;
1763
1755
  setAttributes(element, {
1764
1756
  "stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
1765
1757
  opacity: paint.opacity,
1766
1758
  "stroke-linecap": paint.linecap,
1767
- "stroke-linejoin": "round"
1759
+ "stroke-linejoin": "round",
1760
+ "data-part": part
1768
1761
  });
1769
1762
  setStyles(element, {
1763
+ ...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
1770
1764
  fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
1771
1765
  stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
1772
1766
  });
@@ -1783,6 +1777,7 @@ function styleText(element, style) {
1783
1777
  // src/charts/render/surface.ts
1784
1778
  function svgSurface(options) {
1785
1779
  const { overlay } = options;
1780
+ const measure = options.measure ?? textMeasure(overlay);
1786
1781
  const orders = /* @__PURE__ */ new WeakMap();
1787
1782
  const groups = /* @__PURE__ */ new Map();
1788
1783
  const hidden = /* @__PURE__ */ new Set();
@@ -1810,7 +1805,7 @@ function svgSurface(options) {
1810
1805
  live.add(group);
1811
1806
  const owner = live;
1812
1807
  return {
1813
- ...svgLayer(group, () => transforms.get(key)),
1808
+ ...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
1814
1809
  clear() {
1815
1810
  group.remove();
1816
1811
  owner.delete(group);
@@ -1818,6 +1813,12 @@ function svgSurface(options) {
1818
1813
  }
1819
1814
  };
1820
1815
  },
1816
+ box: (text, { at, anchor = "start" }) => textBox({
1817
+ x: at.x,
1818
+ y: at.y,
1819
+ anchor,
1820
+ text
1821
+ }, measure, "ec-text", TEXT_SIZE),
1821
1822
  mark(key) {
1822
1823
  const handle = options.mark(key);
1823
1824
  return {
@@ -1835,7 +1836,10 @@ function svgSurface(options) {
1835
1836
  const live = groups.get(key);
1836
1837
  if (!live) return;
1837
1838
  const styles = markColorStyles(options.colors(key));
1838
- for (const group of live) setStyles(group, styles);
1839
+ for (const group of live) {
1840
+ setStyles(group, styles);
1841
+ for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
1842
+ }
1839
1843
  },
1840
1844
  hide(key, hide) {
1841
1845
  if (hide) hidden.add(key);
@@ -1913,13 +1917,13 @@ function decimals(value) {
1913
1917
  const point = text.indexOf(".");
1914
1918
  return point < 0 ? 0 : Math.min(6, text.length - point - 1);
1915
1919
  }
1916
- function round$4(value, digits) {
1920
+ function round$5(value, digits) {
1917
1921
  const factor = 10 ** digits;
1918
1922
  const rounded = Math.round(value * factor) / factor;
1919
1923
  return rounded === 0 ? 0 : rounded;
1920
1924
  }
1921
1925
  function percent(share) {
1922
- return `${round$4(share * 100, 0)}%`;
1926
+ return `${round$5(share * 100, 0)}%`;
1923
1927
  }
1924
1928
  // src/charts/interaction.ts
1925
1929
  function pointerHover(svg, options) {
@@ -2272,6 +2276,14 @@ function keyboardFocus(svg, options) {
2272
2276
  last = keys;
2273
2277
  return had === void 0 ? void 0 : current;
2274
2278
  },
2279
+ moveTabStop(key) {
2280
+ listen();
2281
+ const keys = options.order();
2282
+ if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
2283
+ tabStop = key;
2284
+ applyTabIndex(keys);
2285
+ return true;
2286
+ },
2275
2287
  destroy() {
2276
2288
  current = void 0;
2277
2289
  focused = void 0;
@@ -2529,6 +2541,7 @@ function chartHover(options) {
2529
2541
  focus(key) {
2530
2542
  if (options.live(key)) keyboard.focus(key);
2531
2543
  },
2544
+ moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
2532
2545
  leave,
2533
2546
  destroy() {
2534
2547
  destroyed = true;
@@ -3114,7 +3127,7 @@ function chartTooltip(svg, options) {
3114
3127
  if (x > left && x < right && y > top && y < bottom) return true;
3115
3128
  if (!shape) return false;
3116
3129
  const origin = layer.getBoundingClientRect();
3117
- return inside$1(shape, x - origin.left, y - origin.top);
3130
+ return inside$2(shape, x - origin.left, y - origin.top);
3118
3131
  };
3119
3132
  const letThrough = (on) => {
3120
3133
  through = on;
@@ -3209,7 +3222,7 @@ function chartTooltip(svg, options) {
3209
3222
  top: dy + near.top,
3210
3223
  bottom: dy + near.bottom
3211
3224
  };
3212
- shape = span(bridge, {
3225
+ shape = span$1(bridge, {
3213
3226
  left,
3214
3227
  top,
3215
3228
  ...size
@@ -3303,12 +3316,12 @@ function chartTooltip(svg, options) {
3303
3316
  }
3304
3317
  };
3305
3318
  }
3306
- function inside$1({ top, bottom, upper, lower }, x, y) {
3319
+ function inside$2({ top, bottom, upper, lower }, x, y) {
3307
3320
  if (y <= top || y >= bottom) return false;
3308
3321
  const t = (y - top) / (bottom - top);
3309
3322
  return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
3310
3323
  }
3311
- function span(bridge, box, mark, side) {
3324
+ function span$1(bridge, box, mark, side) {
3312
3325
  bridge.hidden = mark === void 0;
3313
3326
  if (!mark) return void 0;
3314
3327
  const edge = {
@@ -3390,7 +3403,7 @@ function viewBox$1(svg) {
3390
3403
  const STAGE$2 = 500;
3391
3404
  function barChart$1(target, options, env) {
3392
3405
  const container = resolveTarget$2(target, "barChart");
3393
- checkOptions$13(options);
3406
+ checkOptions$14(options);
3394
3407
  let current = options;
3395
3408
  const motion = chartMotion(options.motion, env.motion);
3396
3409
  let effects = resolveEffects(options.on, env.presets);
@@ -3449,6 +3462,7 @@ function barChart$1(target, options, env) {
3449
3462
  const find = (key) => records.get(key) ?? leaving.get(key);
3450
3463
  const surface = svgSurface({
3451
3464
  overlay,
3465
+ measure,
3452
3466
  mark: (key) => ({
3453
3467
  set: (style) => {
3454
3468
  find(key)?.handle.set(style);
@@ -3459,7 +3473,7 @@ function barChart$1(target, options, env) {
3459
3473
  hover.restyled(key);
3460
3474
  }
3461
3475
  }),
3462
- colors: (key) => find(key)?.parts[0]?.colors
3476
+ colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
3463
3477
  });
3464
3478
  const runner = createRunner({
3465
3479
  effects,
@@ -3701,7 +3715,7 @@ function barChart$1(target, options, env) {
3701
3715
  value: now[series] ?? 0
3702
3716
  }));
3703
3717
  const total = values.reduce((sum, v) => sum + v.value, 0);
3704
- const text = record.count === void 0 ? row.value.text : format(current)(round$4(total, record.count));
3718
+ const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
3705
3719
  return placeRow(frame, {
3706
3720
  key: row.key,
3707
3721
  datum: row.datum,
@@ -3958,7 +3972,7 @@ function barChart$1(target, options, env) {
3958
3972
  ...current,
3959
3973
  ...next
3960
3974
  };
3961
- checkOptions$13(merged);
3975
+ checkOptions$14(merged);
3962
3976
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
3963
3977
  const nextLayout = layout(merged, swapped);
3964
3978
  const nextTable = tableFor(merged, nextLayout);
@@ -4006,6 +4020,15 @@ function barChart$1(target, options, env) {
4006
4020
  if (!destroyed) hover.leave();
4007
4021
  },
4008
4022
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.shown.label, record.label), ...chartLabel(record.key, "value", record.shown.value, record.value)]),
4023
+ paintOf(key) {
4024
+ const record = records.get(key);
4025
+ const first = record?.shown.geometry.segments?.[0];
4026
+ return record && {
4027
+ color: byCategory(current) ? key : first?.series ?? first?.key ?? key,
4028
+ drawn: true
4029
+ };
4030
+ },
4031
+ moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
4009
4032
  destroy() {
4010
4033
  if (destroyed) return;
4011
4034
  destroyed = true;
@@ -4038,7 +4061,7 @@ function barChart$1(target, options, env) {
4038
4061
  }
4039
4062
  });
4040
4063
  }
4041
- function checkOptions$13(options) {
4064
+ function checkOptions$14(options) {
4042
4065
  checkChartOptions(options, "barChart");
4043
4066
  const { colorBy, room } = options;
4044
4067
  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)}.`);
@@ -4171,26 +4194,8 @@ function joinedStarts(values) {
4171
4194
  });
4172
4195
  }
4173
4196
  function placeSlices(frame, states, labels, measure) {
4174
- const boxes = labels.map((label) => label ? labelBoxes(label, measure) : void 0);
4175
- const labelled = boxes.flatMap((box, i) => box ? [i] : []);
4176
- const first = labelled[0];
4177
- const last = labelled[labelled.length - 1];
4178
- const before = [];
4179
- const after = [];
4180
- let seen;
4181
- for (let i = 0; i < states.length; i++) {
4182
- before[i] = seen ?? (last === i ? void 0 : last);
4183
- if (boxes[i]) seen = i;
4184
- }
4185
- seen = void 0;
4186
- for (let i = states.length - 1; i >= 0; i--) {
4187
- after[i] = seen ?? (first === i ? void 0 : first);
4188
- if (boxes[i]) seen = i;
4189
- }
4190
- return states.map((state, i) => {
4191
- const sides = before[i] === after[i] ? [before[i]] : [before[i], after[i]];
4192
- return placeSlice(frame, state, labels[i], measure, sides.flatMap((j) => j === void 0 ? [] : boxes[j]));
4193
- });
4197
+ const boxes = labels.map((label) => label ? labelBoxes(label, measure) : []);
4198
+ return states.map((state, i) => placeSlice(frame, state, labels[i], measure, boxes.flatMap((box, j) => j === i ? [] : box)));
4194
4199
  }
4195
4200
  function placeSlice(frame, state, label, measure, nearby) {
4196
4201
  const geometry = describeArc({
@@ -4360,7 +4365,7 @@ const TAU = 2 * Math.PI;
4360
4365
  const VISIBLE$1 = .5;
4361
4366
  function donutChart$1(target, options, env) {
4362
4367
  const container = resolveTarget$2(target, "donutChart");
4363
- checkOptions$12(options);
4368
+ checkOptions$13(options);
4364
4369
  let current = options;
4365
4370
  const motion = chartMotion(options.motion, env.motion);
4366
4371
  let effects = resolveEffects(options.on, env.presets);
@@ -4406,6 +4411,7 @@ function donutChart$1(target, options, env) {
4406
4411
  const find = (key) => records.get(key) ?? leaving.get(key);
4407
4412
  const surface = svgSurface({
4408
4413
  overlay: runs,
4414
+ measure,
4409
4415
  mark: (key) => ({
4410
4416
  set: (style) => {
4411
4417
  find(key)?.handle.set(style);
@@ -4709,7 +4715,7 @@ function donutChart$1(target, options, env) {
4709
4715
  const slices = currentSlices(f);
4710
4716
  for (const { record, slice, label } of slices) show(record, slice, label);
4711
4717
  const total = slices.reduce((sum, { slice }) => sum + slice.value, 0);
4712
- drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$4(total, count)), measure));
4718
+ drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$5(total, count)), measure));
4713
4719
  }
4714
4720
  function counting(total) {
4715
4721
  if (counted?.total !== total) counted = {
@@ -4931,7 +4937,7 @@ function donutChart$1(target, options, env) {
4931
4937
  ...current,
4932
4938
  ...next
4933
4939
  };
4934
- checkOptions$12(merged);
4940
+ checkOptions$13(merged);
4935
4941
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
4936
4942
  const nextLayout = layout(merged, swapped);
4937
4943
  const nextTable = tableFor(merged, nextLayout);
@@ -4983,6 +4989,11 @@ function donutChart$1(target, options, env) {
4983
4989
  if (!destroyed) hover.leave();
4984
4990
  },
4985
4991
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.drawnLabel?.category, record.label), ...chartLabel(record.key, "value", record.drawnLabel?.share, record.share)]),
4992
+ paintOf: (key) => records.has(key) ? {
4993
+ color: key,
4994
+ drawn: true
4995
+ } : void 0,
4996
+ moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
4986
4997
  destroy() {
4987
4998
  if (destroyed) return;
4988
4999
  destroyed = true;
@@ -5013,7 +5024,7 @@ function donutChart$1(target, options, env) {
5013
5024
  }
5014
5025
  });
5015
5026
  }
5016
- function checkOptions$12(options) {
5027
+ function checkOptions$13(options) {
5017
5028
  checkChartOptions(options, "donutChart");
5018
5029
  const { center, sort } = options;
5019
5030
  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.");
@@ -5556,6 +5567,17 @@ function lineEncoding(options) {
5556
5567
  curve
5557
5568
  };
5558
5569
  }
5570
+ function checkRoom(room) {
5571
+ const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
5572
+ if (typeof room !== "object" || room === null || Array.isArray(room)) {
5573
+ if (room !== void 0 && !px(room)) throw new RangeError(`lineChart: room must be a number of px, 0 or more, got ${typeof room === "object" ? JSON.stringify(room) : String(room)}.`);
5574
+ return;
5575
+ }
5576
+ for (const side of ["right", "top"]) {
5577
+ const value = room[side];
5578
+ if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
5579
+ }
5580
+ }
5559
5581
  function layoutLines(input) {
5560
5582
  const { width, measure } = input;
5561
5583
  const height = input.height ?? HEIGHT;
@@ -5572,9 +5594,11 @@ function layoutLines(input) {
5572
5594
  const xValues = ticked.map((tick) => tick.value);
5573
5595
  const xTexts = ticked.map((tick) => tick.text);
5574
5596
  const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
5597
+ const room = typeof input.room === "number" ? { right: input.room } : input.room;
5575
5598
  const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
5576
5599
  const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
5577
- const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0);
5600
+ const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
5601
+ const top = TOP + (room?.top ?? 0);
5578
5602
  const frame = {
5579
5603
  scale: {
5580
5604
  lo: domain.lo,
@@ -5585,8 +5609,8 @@ function layoutLines(input) {
5585
5609
  xHi,
5586
5610
  left,
5587
5611
  right: Math.max(left, width - right),
5588
- top: TOP,
5589
- bottom: Math.max(TOP, height - AXIS),
5612
+ top,
5613
+ bottom: Math.max(top, height - AXIS),
5590
5614
  width,
5591
5615
  height
5592
5616
  }
@@ -6017,6 +6041,7 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
6017
6041
  // src/charts/line.ts
6018
6042
  const STAGE = 500;
6019
6043
  const RING = 2;
6044
+ const DOT_RING = 2;
6020
6045
  const VISIBLE = .5;
6021
6046
  function lineChart$1(target, options, env) {
6022
6047
  const container = resolveTarget$2(target, "lineChart");
@@ -6083,7 +6108,7 @@ function lineChart$1(target, options, env) {
6083
6108
  try {
6084
6109
  laidOut = layout(current);
6085
6110
  firstTable = tableFor(current, laidOut);
6086
- names = namesFor(current, laidOut);
6111
+ names = hoverKind === "x" ? namesFor(current, laidOut) : void 0;
6087
6112
  pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
6088
6113
  } catch (error) {
6089
6114
  svg.remove();
@@ -6092,6 +6117,7 @@ function lineChart$1(target, options, env) {
6092
6117
  const findMark = (key) => points.get(key) ?? lines.get(key) ?? leaving.get(key);
6093
6118
  const surface = svgSurface({
6094
6119
  overlay,
6120
+ measure,
6095
6121
  mark: (key) => ({
6096
6122
  set: (style) => {
6097
6123
  findMark(key)?.handle.set(style);
@@ -6157,6 +6183,8 @@ function lineChart$1(target, options, env) {
6157
6183
  function layout(opts, using = effects) {
6158
6184
  const encoding = lineEncoding(opts);
6159
6185
  checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
6186
+ const { room } = opts;
6187
+ checkRoom(room);
6160
6188
  const next = layoutLines({
6161
6189
  data: opts.data,
6162
6190
  encoding,
@@ -6164,7 +6192,8 @@ function lineChart$1(target, options, env) {
6164
6192
  height: opts.height,
6165
6193
  format: format(opts),
6166
6194
  measure,
6167
- label: labeler(opts, true)
6195
+ label: labeler(opts, true),
6196
+ room
6168
6197
  });
6169
6198
  const keys = new Set(next.series);
6170
6199
  for (const row of next.rows) for (const name of next.series) {
@@ -6198,7 +6227,7 @@ function lineChart$1(target, options, env) {
6198
6227
  const label = labeler(current);
6199
6228
  if (!label) return void 0;
6200
6229
  return {
6201
- text: (series, value) => label(series, round$4(value, given[series] ?? decimals(value))),
6230
+ text: (series, value) => label(series, round$5(value, given[series] ?? decimals(value))),
6202
6231
  measure
6203
6232
  };
6204
6233
  }
@@ -6662,23 +6691,42 @@ function lineChart$1(target, options, env) {
6662
6691
  }
6663
6692
  const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
6664
6693
  function nearestPoint(at) {
6694
+ const shown = rowOrder.filter(revealed).flatMap(livePoints);
6665
6695
  let best;
6666
6696
  let far = Infinity;
6667
6697
  let rank = Infinity;
6668
- for (const record of rowOrder) {
6669
- if (!revealed(record)) continue;
6670
- for (const point of livePoints(record)) {
6671
- const { x, y } = point.shown.geometry.center;
6672
- const d = (x - at.x) ** 2 + (y - at.y) ** 2;
6673
- const r = laidOut.series.indexOf(point.series);
6674
- if (d < far || d === far && r < rank) [best, far, rank] = [
6675
- point,
6676
- d,
6677
- r
6678
- ];
6679
- }
6698
+ for (const point of shown) {
6699
+ const d = apart(point.shown.geometry.center, at);
6700
+ const r = laidOut.series.indexOf(point.series);
6701
+ if (d < far || d === far && r < rank) [best, far, rank] = [
6702
+ point,
6703
+ d,
6704
+ r
6705
+ ];
6706
+ }
6707
+ if (!best) return void 0;
6708
+ const center = best.shown.geometry.center;
6709
+ const on = /* @__PURE__ */ new Map();
6710
+ for (const point of shown) {
6711
+ const { center: c } = point.shown.geometry;
6712
+ const known = on.get(point.series);
6713
+ if (apart(c, center) <= 1 && (!known || apart(c, at) < apart(known.shown.geometry.center, at))) on.set(point.series, point);
6714
+ }
6715
+ if (on.size < 2) return best;
6716
+ let pick = best;
6717
+ let near = Infinity;
6718
+ for (const series of laidOut.series) {
6719
+ const point = on.get(series);
6720
+ if (!point) continue;
6721
+ const d = passing(point, at);
6722
+ if (d < near) [pick, near] = [point, d];
6680
6723
  }
6681
- return best;
6724
+ return pick;
6725
+ }
6726
+ function passing(point, at) {
6727
+ const { geometry, data } = point.shown;
6728
+ const line = lines.get(point.series);
6729
+ return (line && strokeNear(line.shown, data.samples[0].at, geometry.center, at, 9)) ?? Math.max(0, Math.hypot(at.x - geometry.center.x, at.y - geometry.center.y) - 4.5);
6682
6730
  }
6683
6731
  function heldPoint(at) {
6684
6732
  const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
@@ -6924,8 +6972,9 @@ function lineChart$1(target, options, env) {
6924
6972
  });
6925
6973
  }
6926
6974
  function labelColumn(record) {
6975
+ if (hoverKind !== "x") return;
6927
6976
  record.column.setAttribute("aria-label", names.get(record.key));
6928
- if (hoverKind === "x") tooltip.describe(record.column, record.row);
6977
+ tooltip.describe(record.column, record.row);
6929
6978
  }
6930
6979
  function announceChange(previous, before) {
6931
6980
  const option = current.announce;
@@ -7193,6 +7242,11 @@ function lineChart$1(target, options, env) {
7193
7242
  const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
7194
7243
  hover.sync();
7195
7244
  runner.enter(liveMarks().map(input));
7245
+ function stopFor(key) {
7246
+ const row = rows.get(key);
7247
+ if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
7248
+ return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
7249
+ }
7196
7250
  return linkable(hover.link, {
7197
7251
  element: svg,
7198
7252
  async update(next) {
@@ -7207,7 +7261,7 @@ function lineChart$1(target, options, env) {
7207
7261
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
7208
7262
  const nextLayout = layout(merged, swapped);
7209
7263
  const nextTable = tableFor(merged, nextLayout);
7210
- const nextNames = namesFor(merged, nextLayout);
7264
+ const nextNames = kind === "x" ? namesFor(merged, nextLayout) : void 0;
7211
7265
  const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
7212
7266
  if ("colors" in next) colors = toColorAssignment(merged.colors);
7213
7267
  const previous = current;
@@ -7262,20 +7316,40 @@ function lineChart$1(target, options, env) {
7262
7316
  on: events.on,
7263
7317
  marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
7264
7318
  focus(key) {
7265
- if (destroyed) return;
7266
- const row = rows.get(key);
7267
- if (hoverKind === "x") {
7268
- const record = row ?? points.get(key)?.row;
7269
- if (record) hover.focus(record.key);
7270
- return;
7271
- }
7272
- const point = points.get(key) ?? (row && livePoints(row)[0]);
7273
- if (point) hover.focus(point.key);
7319
+ const stop = destroyed ? void 0 : stopFor(key);
7320
+ if (stop !== void 0) hover.focus(stop);
7274
7321
  },
7275
7322
  leave() {
7276
7323
  if (!destroyed) hover.leave();
7277
7324
  },
7278
7325
  labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
7326
+ paintOf(key) {
7327
+ const line = lines.get(key);
7328
+ if (line) return {
7329
+ color: line.series,
7330
+ drawn: true,
7331
+ ...line.end.getAttribute("visibility") === "hidden" ? {} : {
7332
+ end: DOT_RADIUS,
7333
+ ring: DOT_RING
7334
+ }
7335
+ };
7336
+ const point = points.get(key);
7337
+ return point && (point.group.classList.contains("ec-alone") ? {
7338
+ color: point.series,
7339
+ drawn: true,
7340
+ ring: DOT_RING
7341
+ } : {
7342
+ color: point.series,
7343
+ drawn: false
7344
+ });
7345
+ },
7346
+ standsFor(key) {
7347
+ return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
7348
+ },
7349
+ moveTabStop(key) {
7350
+ const stop = destroyed ? void 0 : stopFor(key);
7351
+ return stop !== void 0 && hover.moveTabStop(stop);
7352
+ },
7279
7353
  destroy() {
7280
7354
  if (destroyed) return;
7281
7355
  destroyed = true;
@@ -7350,6 +7424,36 @@ function sameData(a, b) {
7350
7424
  function sameAt(a, b) {
7351
7425
  return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
7352
7426
  }
7427
+ function apart(a, b) {
7428
+ return (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
7429
+ }
7430
+ function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
7431
+ const i = samples.findIndex((sample) => sameAt(sample.at, x));
7432
+ if (i < 0 || !(geometry.length > 0)) return void 0;
7433
+ const t = samples[i].t;
7434
+ const span = reach / geometry.length;
7435
+ let near;
7436
+ for (const way of [-1, 1]) {
7437
+ let a = from;
7438
+ for (let j = i;; j += way) {
7439
+ const next = samples[j + way];
7440
+ if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
7441
+ const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
7442
+ const b = geometry.path(to);
7443
+ near = Math.min(near ?? Infinity, toSegment(at, a, b));
7444
+ if (to !== next.t) break;
7445
+ a = b;
7446
+ }
7447
+ }
7448
+ return near;
7449
+ }
7450
+ function toSegment(p, a, b) {
7451
+ const dx = b.x - a.x;
7452
+ const dy = b.y - a.y;
7453
+ const length = dx * dx + dy * dy;
7454
+ const u = length > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / length)) : 0;
7455
+ return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
7456
+ }
7353
7457
  function labelled(values, options) {
7354
7458
  return present(values).map((v) => ({
7355
7459
  series: v.series,
@@ -7421,10 +7525,10 @@ function hoverOf(options) {
7421
7525
  // src/core/geometry/ring.ts
7422
7526
  const ROUND = .5;
7423
7527
  function goesRound(mark) {
7424
- const radius = distance$1(mark.start, mark.pivot);
7425
- return radius > ROUND && Math.abs(distance$1(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$1(mark.end, mark.pivot) - radius) <= ROUND;
7528
+ const radius = distance$2(mark.start, mark.pivot);
7529
+ return radius > ROUND && Math.abs(distance$2(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$2(mark.end, mark.pivot) - radius) <= ROUND;
7426
7530
  }
7427
- const distance$1 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
7531
+ const distance$2 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
7428
7532
  // src/charts/adapter/bars.ts
7429
7533
  const SAME = .5;
7430
7534
  const BASELINES = [
@@ -7473,10 +7577,10 @@ function describeRects(key, parts, baseline) {
7473
7577
  ...box,
7474
7578
  baseline,
7475
7579
  radius: tip.radius,
7476
- gap: Number.isFinite(gap) ? Math.max(0, round$3(gap)) : 0,
7580
+ gap: Number.isFinite(gap) ? Math.max(0, round$4(gap)) : 0,
7477
7581
  ...segments.every((s) => s.series !== void 0) ? { segments: segments.map((s) => ({
7478
7582
  series: s.series,
7479
- size: round$3(s.size)
7583
+ size: round$4(s.size)
7480
7584
  })) } : {}
7481
7585
  }),
7482
7586
  order: order.map((o) => o.index)
@@ -7494,8 +7598,8 @@ function union(boxes) {
7494
7598
  return {
7495
7599
  x,
7496
7600
  y,
7497
- width: round$3(Math.max(...boxes.map((b) => b.x + b.width)) - x),
7498
- height: round$3(Math.max(...boxes.map((b) => b.y + b.height)) - y)
7601
+ width: round$4(Math.max(...boxes.map((b) => b.x + b.width)) - x),
7602
+ height: round$4(Math.max(...boxes.map((b) => b.y + b.height)) - y)
7499
7603
  };
7500
7604
  }
7501
7605
  function commonLine(boxes, nearEdge, farEdge, near, far) {
@@ -7536,7 +7640,7 @@ function spanFrom(mark, baseline) {
7536
7640
  });
7537
7641
  }
7538
7642
  }
7539
- function round$3(value) {
7643
+ function round$4(value) {
7540
7644
  return Math.round(value * 1e3) / 1e3;
7541
7645
  }
7542
7646
  // src/charts/adapter/edits.ts
@@ -7688,7 +7792,7 @@ function keepsCircles(m) {
7688
7792
  const tiny = 1e-4 * Math.max(u, v);
7689
7793
  return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
7690
7794
  }
7691
- function scaleOf$1(m) {
7795
+ function scaleOf$2(m) {
7692
7796
  return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
7693
7797
  }
7694
7798
  function boxIn(m, rect) {
@@ -7712,13 +7816,13 @@ function boxIn(m, rect) {
7712
7816
  ].map((corner) => matrix.apply(m, corner));
7713
7817
  const xs = corners.map((p) => p.x);
7714
7818
  const ys = corners.map((p) => p.y);
7715
- const x = round$2(Math.min(...xs));
7716
- const y = round$2(Math.min(...ys));
7819
+ const x = round$3(Math.min(...xs));
7820
+ const y = round$3(Math.min(...ys));
7717
7821
  return {
7718
7822
  x,
7719
7823
  y,
7720
- width: round$2(round$2(Math.max(...xs)) - x),
7721
- height: round$2(round$2(Math.max(...ys)) - y)
7824
+ width: round$3(round$3(Math.max(...xs)) - x),
7825
+ height: round$3(round$3(Math.max(...ys)) - y)
7722
7826
  };
7723
7827
  }
7724
7828
  function rectOf(element) {
@@ -7736,6 +7840,7 @@ function rectOf(element) {
7736
7840
  }
7737
7841
  function attributesOf(element) {
7738
7842
  return (name) => {
7843
+ if (!element.hasAttribute(name)) return null;
7739
7844
  const animated = element[name];
7740
7845
  return typeof animated?.baseVal?.value === "number" ? String(animated.baseVal.value) : element.getAttribute(name);
7741
7846
  };
@@ -7763,7 +7868,7 @@ function fromRoot(element, root) {
7763
7868
  for (let node = element; node && node !== root; node = node.parentElement) m = matrix.multiply(ownTransform(node), m);
7764
7869
  return m;
7765
7870
  }
7766
- function round$2(value) {
7871
+ function round$3(value) {
7767
7872
  return Math.round(value * 1e3) / 1e3;
7768
7873
  }
7769
7874
  // src/charts/adapter/host-style.ts
@@ -7815,9 +7920,9 @@ function hostMarkHandle(parts, edits, halos) {
7815
7920
  };
7816
7921
  }
7817
7922
  function hostColors(element, root) {
7818
- const fill = paintOf(element, root, "fill");
7923
+ const fill = paintOf$1(element, root, "fill");
7819
7924
  const paint = fill === NONE ? "stroke" : "fill";
7820
- const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
7925
+ const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
7821
7926
  if (color === void 0 || color === NONE) return void 0;
7822
7927
  return {
7823
7928
  color,
@@ -7842,7 +7947,7 @@ function attributesComputed(root) {
7842
7947
  probed.set(root, computed);
7843
7948
  return computed;
7844
7949
  }
7845
- function paintOf(element, root, property) {
7950
+ function paintOf$1(element, root, property) {
7846
7951
  const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property);
7847
7952
  const computed = kind(raw);
7848
7953
  if (raw && attributesComputed(root)) return computed;
@@ -7855,15 +7960,28 @@ function paintOf(element, root, property) {
7855
7960
  return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
7856
7961
  }
7857
7962
  function strokeWidthOf(element, root) {
7858
- const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue("stroke-width");
7963
+ const style = element.ownerDocument.defaultView?.getComputedStyle?.(element);
7964
+ const raw = style?.getPropertyValue("stroke-width");
7859
7965
  const computed = pixels$1(raw);
7860
- if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return computed;
7966
+ const effect = style?.getPropertyValue("vector-effect").trim().toLowerCase();
7967
+ const declared = element.style?.getPropertyValue("vector-effect") ? effect : element.getAttribute("vector-effect")?.trim().toLowerCase();
7968
+ const screen = (effect && (effect !== "none" || attributesComputed(root)) ? effect : declared) === "non-scaling-stroke";
7969
+ if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return {
7970
+ width: computed,
7971
+ screen
7972
+ };
7861
7973
  for (let node = element; node; node = node === root ? null : node.parentElement) {
7862
7974
  if (node.style?.getPropertyValue("stroke-width")) break;
7863
7975
  const width = pixels$1(node.getAttribute("stroke-width"));
7864
- if (width !== void 0) return width;
7976
+ if (width !== void 0) return {
7977
+ width,
7978
+ screen
7979
+ };
7865
7980
  }
7866
- return computed;
7981
+ return {
7982
+ width: computed,
7983
+ screen
7984
+ };
7867
7985
  }
7868
7986
  function pixels$1(value) {
7869
7987
  const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(?:px\s*)?$/i.exec(value ?? "");
@@ -7885,6 +8003,183 @@ function mix$2(colors, emphasis) {
7885
8003
  function cssMatrix(m) {
7886
8004
  return `matrix(${m.map((v, i) => i < 4 ? Math.round(v * 1e6) / 1e6 : Math.round(v * 1e3) / 1e3).join(", ")})`;
7887
8005
  }
8006
+ // src/charts/adapter/slice.ts
8007
+ const NEAR = .5;
8008
+ const MOST = 32;
8009
+ function sliceOf$1(commands, m) {
8010
+ const scale = scaleOf$2(m);
8011
+ if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
8012
+ const near = NEAR / scale;
8013
+ const subpaths = flattenPath(commands);
8014
+ if (subpaths.length === 0 || subpaths.length > 2 || !subpaths.every(closes)) return void 0;
8015
+ const runs = subpaths.map((subpath) => runsOf(subpath.segments, near));
8016
+ const own = subpaths.length === 2 ? ring(runs[0], runs[1], near) : slice(runs[0], near);
8017
+ return own && moved(own, m);
8018
+ }
8019
+ function ring(a, b, near) {
8020
+ const [first, second] = [a[0], b[0]];
8021
+ if (a.length !== 1 || b.length !== 1 || first?.kind !== "arc" || second?.kind !== "arc") return void 0;
8022
+ const [outer, inner] = first.radius >= second.radius ? [first, second] : [second, first];
8023
+ const whole = (turn, radius) => Math.abs(Math.abs(turn) - TAU$2) * radius <= near;
8024
+ for (const center of [centerOf(outer), outer.arcs[0].center]) {
8025
+ if (!center) continue;
8026
+ const [r1, r0] = [distance$1(outer.from, center), distance$1(inner.from, center)];
8027
+ const [t1, t0] = [turnOf(outer, center), turnOf(inner, center)];
8028
+ if (r1 > near && r1 - r0 > near && Math.sign(t1) !== Math.sign(t0) && whole(t1, r1) && whole(t0, r0) && onCircle(outer, center, r1, near) && onCircle(inner, center, r0, near)) return {
8029
+ center,
8030
+ inner: r0,
8031
+ outer: r1,
8032
+ start: angleOf(outer.from, center),
8033
+ sweep: Math.sign(t1) * TAU$2
8034
+ };
8035
+ }
8036
+ }
8037
+ function slice(runs, near) {
8038
+ let first = -1;
8039
+ runs.forEach((run, i) => {
8040
+ if (run.kind === "arc" && (first < 0 || run.radius > runs[first].radius)) first = i;
8041
+ });
8042
+ if (first < 0) return void 0;
8043
+ const cycle = [...runs.slice(first), ...runs.slice(0, first)];
8044
+ const outer = cycle[0];
8045
+ const [, side, third, fourth] = cycle;
8046
+ const pie = cycle.length === 3 && side?.kind === "line" && third?.kind === "line";
8047
+ const back = cycle.length === 4 && side?.kind === "line" && third?.kind === "arc" && fourth?.kind === "line" ? third : void 0;
8048
+ if (!pie && !back) return void 0;
8049
+ const [inEnd, inStart] = back ? [back.from, back.to] : [side.to, side.to];
8050
+ const toward = (from, to) => {
8051
+ const length = distance$1(from, to);
8052
+ return length > near ? {
8053
+ x: from.x + (to.x - from.x) * outer.radius / length,
8054
+ y: from.y + (to.y - from.y) * outer.radius / length
8055
+ } : void 0;
8056
+ };
8057
+ const a = toward(outer.from, inStart);
8058
+ const b = toward(outer.to, inEnd);
8059
+ if (!a || !b) return void 0;
8060
+ let center = {
8061
+ x: (a.x + b.x) / 2,
8062
+ y: (a.y + b.y) / 2
8063
+ };
8064
+ if (pie && distance$1(inEnd, center) <= near) center = inEnd;
8065
+ const inner = center === inEnd ? 0 : (distance$1(inEnd, center) + distance$1(inStart, center)) / 2;
8066
+ const sweep = turnOf(outer, center);
8067
+ if (sweep === 0) return void 0;
8068
+ const own = {
8069
+ center,
8070
+ inner,
8071
+ outer: (distance$1(outer.from, center) + distance$1(outer.to, center)) / 2,
8072
+ start: angleOf(outer.from, center),
8073
+ sweep
8074
+ };
8075
+ return checked(own, outer, back, [inEnd, inStart], near) ? own : void 0;
8076
+ }
8077
+ function checked(own, outer, back, [inEnd, inStart], near) {
8078
+ const { center, start, sweep } = own;
8079
+ const at = (radius, angle) => ({
8080
+ x: center.x + radius * Math.cos(angle),
8081
+ y: center.y + radius * Math.sin(angle)
8082
+ });
8083
+ return own.outer > near && own.outer - own.inner > near && distance$1(outer.from, at(own.outer, start)) <= near && distance$1(outer.to, at(own.outer, start + sweep)) <= near && onCircle(outer, center, own.outer, near) && distance$1(inEnd, at(own.inner, start + sweep)) <= near && distance$1(inStart, at(own.inner, start)) <= near && (!back || Math.abs(turnOf(back, center) + sweep) * own.inner <= near && onCircle(back, center, own.inner, near));
8084
+ }
8085
+ function turnOf(run, center) {
8086
+ let turn = 0;
8087
+ for (const arc of run.arcs) {
8088
+ const step = normalizeAngle(angleOf(pointOn(arc, 1), center) - angleOf(pointOn(arc, 0), center));
8089
+ turn += step + TAU$2 * Math.round((arc.sweep - step) / TAU$2);
8090
+ }
8091
+ return turn;
8092
+ }
8093
+ function centerOf(run) {
8094
+ const points = [run.from, ...run.arcs.slice(0, -1).map((arc) => pointOn(arc, 1))];
8095
+ if (points.length < 2) return void 0;
8096
+ if (points.length === 2) return {
8097
+ x: (points[0].x + points[1].x) / 2,
8098
+ y: (points[0].y + points[1].y) / 2
8099
+ };
8100
+ const [p, q, r] = [
8101
+ points[0],
8102
+ points[Math.floor(points.length / 3)],
8103
+ points[Math.floor(2 * points.length / 3)]
8104
+ ];
8105
+ const d = 2 * (p.x * (q.y - r.y) + q.x * (r.y - p.y) + r.x * (p.y - q.y));
8106
+ if (!(Math.abs(d) > 0)) return void 0;
8107
+ const [pp, qq, rr] = [
8108
+ p,
8109
+ q,
8110
+ r
8111
+ ].map(({ x, y }) => x * x + y * y);
8112
+ return {
8113
+ x: (pp * (q.y - r.y) + qq * (r.y - p.y) + rr * (p.y - q.y)) / d,
8114
+ y: (pp * (r.x - q.x) + qq * (p.x - r.x) + rr * (q.x - p.x)) / d
8115
+ };
8116
+ }
8117
+ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <= near && run.arcs.every((arc) => [
8118
+ 0,
8119
+ .5,
8120
+ 1
8121
+ ].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
8122
+ function moved(own, m) {
8123
+ const scale = scaleOf$2(m);
8124
+ const center = matrix.apply(m, own.center);
8125
+ const corner = matrix.apply(m, {
8126
+ x: own.center.x + own.outer * Math.cos(own.start),
8127
+ y: own.center.y + own.outer * Math.sin(own.start)
8128
+ });
8129
+ const sweep = m[0] * m[3] - m[1] * m[2] < 0 ? -own.sweep : own.sweep;
8130
+ let start = ((angleOf(corner, center) + Math.PI / 2) % TAU$2 + TAU$2) % TAU$2;
8131
+ if (start > TAU$2 - 1e-9) start = 0;
8132
+ return {
8133
+ cx: round$2(center.x),
8134
+ cy: round$2(center.y),
8135
+ inner: round$2(own.inner * scale),
8136
+ outer: round$2(own.outer * scale),
8137
+ start,
8138
+ end: start + sweep
8139
+ };
8140
+ }
8141
+ function runsOf(segments, near) {
8142
+ const runs = [];
8143
+ const join = (run, arc) => run !== void 0 && Math.sign(run.sweep) === Math.sign(arc.sweep) && Math.abs(run.radius - arc.radius) <= near;
8144
+ for (const segment of segments) {
8145
+ const last = runs[runs.length - 1];
8146
+ if (segment.kind === "line") runs.push({
8147
+ kind: "line",
8148
+ from: segment.from,
8149
+ to: segment.to
8150
+ });
8151
+ else if (last?.kind === "arc" && join(last, segment)) runs[runs.length - 1] = {
8152
+ ...last,
8153
+ arcs: [...last.arcs, segment],
8154
+ to: pointOn(segment, 1),
8155
+ sweep: last.sweep + segment.sweep
8156
+ };
8157
+ else runs.push({
8158
+ kind: "arc",
8159
+ arcs: [segment],
8160
+ from: pointOn(segment, 0),
8161
+ to: pointOn(segment, 1),
8162
+ radius: segment.radius,
8163
+ sweep: segment.sweep
8164
+ });
8165
+ }
8166
+ const [head] = runs;
8167
+ const tail = runs[runs.length - 1];
8168
+ if (runs.length > 1 && head?.kind === "arc" && tail?.kind === "arc" && tail.arcs.every((arc) => join(head, arc))) {
8169
+ runs[0] = {
8170
+ ...head,
8171
+ arcs: [...tail.arcs, ...head.arcs],
8172
+ from: tail.from,
8173
+ sweep: tail.sweep + head.sweep
8174
+ };
8175
+ runs.pop();
8176
+ }
8177
+ return runs;
8178
+ }
8179
+ const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
8180
+ const angleOf = (point, center) => Math.atan2(point.y - center.y, point.x - center.x);
8181
+ const distance$1 = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
8182
+ const round$2 = (value) => Math.round(value * 1e3) / 1e3 + 0;
7888
8183
  // src/charts/adapter/source.ts
7889
8184
  function readSource(source) {
7890
8185
  if (typeof source === "string") {
@@ -8046,7 +8341,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
8046
8341
  "graphics-object"
8047
8342
  ]);
8048
8343
  function expressive$1(target, options, env) {
8049
- checkOptions$11(options);
8344
+ checkOptions$12(options);
8050
8345
  const motion = chartMotion(options.motion, env.motion);
8051
8346
  let effects = resolveEffects(options.on, env.presets);
8052
8347
  let given = options.on;
@@ -8094,7 +8389,7 @@ function expressive$1(target, options, env) {
8094
8389
  common,
8095
8390
  screen: screenMatrices(),
8096
8391
  colors: (element) => colorsOf(element, svg),
8097
- strokeWidth: (element) => strokeWidthOf(element, svg)
8392
+ stroke: (element) => strokeWidthOf(element, svg)
8098
8393
  };
8099
8394
  const named = (mark) => ({
8100
8395
  ...mark,
@@ -8110,7 +8405,7 @@ function expressive$1(target, options, env) {
8110
8405
  const shapes = [];
8111
8406
  keys.forEach((key, index) => {
8112
8407
  const pieces = groups.get(key);
8113
- if (pieces[0].element.localName === "rect") bars.push(index);
8408
+ if (pieces[0].element.localName === "rect" && !turned(pieces, at)) bars.push(index);
8114
8409
  else {
8115
8410
  const mark = shapeMark(key, pieces[0], index, at);
8116
8411
  if (mark) shapes.push(mark);
@@ -8137,9 +8432,12 @@ function expressive$1(target, options, env) {
8137
8432
  index
8138
8433
  };
8139
8434
  }
8435
+ function turned(pieces, at) {
8436
+ return pieces.length === 1 && !axisAligned(transformOf(pieces[0].element, at));
8437
+ }
8140
8438
  function rectPiece(key, piece, at) {
8141
8439
  const m = transformOf(piece.element, at);
8142
- if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar. Describe it with the geometry option.`);
8440
+ if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar's segment. A rect turned on its own is a shape, a mark of its own: give each its own key, or describe the bar with the geometry option.`);
8143
8441
  return {
8144
8442
  ...piece,
8145
8443
  rect: {
@@ -8177,7 +8475,7 @@ function expressive$1(target, options, env) {
8177
8475
  };
8178
8476
  const r = tag === "circle" ? length("r") : 0;
8179
8477
  let geometry;
8180
- let strokeWidth;
8478
+ let stroke;
8181
8479
  if (tag === "circle" && (keepsCircles(m) || !(r > 0))) {
8182
8480
  const center = matrix.apply(m, {
8183
8481
  x: length("cx"),
@@ -8188,25 +8486,33 @@ function expressive$1(target, options, env) {
8188
8486
  series,
8189
8487
  x: round$1(center.x),
8190
8488
  y: round$1(center.y),
8191
- r: round$1(Math.max(0, r) * scaleOf$1(m))
8489
+ r: round$1(Math.max(0, r) * scaleOf$2(m))
8192
8490
  });
8193
8491
  } else {
8194
8492
  const commands = shapeOutline(tag, attribute);
8195
8493
  if (commands[0]?.op !== "M" || commands.every((command) => command.op === "M")) return void 0;
8196
- strokeWidth = tag === "circle" ? void 0 : at.strokeWidth(element);
8197
- const width = round$1((strokeWidth ?? 1) * scaleOf$1(m));
8198
- const d = tag === "path" ? attribute("d") ?? "" : formatPath(commands);
8199
- geometry = describeShape({
8494
+ stroke = tag === "circle" ? void 0 : at.stroke(element);
8495
+ const slice = tag === "path" ? sliceOf$1(commands, m) : void 0;
8496
+ if (slice) geometry = describeArc({
8200
8497
  key,
8201
8498
  series,
8202
- d,
8203
- matrix: m,
8204
- width: width > 0 ? width : 1
8499
+ ...slice
8205
8500
  });
8501
+ else {
8502
+ const width = round$1(widthOf(stroke, m, at));
8503
+ const d = tag === "path" ? attribute("d") ?? "" : formatPath(commands);
8504
+ geometry = describeShape({
8505
+ key,
8506
+ series,
8507
+ d,
8508
+ matrix: m,
8509
+ width: width > 0 ? width : 1
8510
+ });
8511
+ }
8206
8512
  }
8207
8513
  const parts = [{
8208
8514
  ...part(piece, outlineOf(geometry, series, 1), at),
8209
- strokeWidth
8515
+ stroke
8210
8516
  }];
8211
8517
  return {
8212
8518
  key,
@@ -8216,6 +8522,13 @@ function expressive$1(target, options, env) {
8216
8522
  ...tag === "circle" ? { circle: true } : {}
8217
8523
  };
8218
8524
  }
8525
+ function widthOf(stroke, m, at) {
8526
+ const width = stroke?.width ?? 1;
8527
+ if (!stroke?.screen) return width * scaleOf$2(m);
8528
+ const screen = at.screen(at.common);
8529
+ const scale = screen ? scaleOf$2(screen) : 0;
8530
+ return scale > 0 ? width / scale : width;
8531
+ }
8219
8532
  function transformOf(element, at) {
8220
8533
  return matrix.multiply(between$1(at.common, element.parentElement ?? at.svg, at.svg, at.screen), ownTransform(element));
8221
8534
  }
@@ -8362,7 +8675,7 @@ function expressive$1(target, options, env) {
8362
8675
  set: (style) => find(key)?.handle.set(style),
8363
8676
  reset: () => find(key)?.handle.reset()
8364
8677
  }),
8365
- colors: (key) => find(key)?.mark.parts[0]?.colors
8678
+ colors: (key, part) => partOf(find(key)?.mark, part)?.colors
8366
8679
  });
8367
8680
  const runner = createRunner({
8368
8681
  effects,
@@ -8670,9 +8983,17 @@ function expressive$1(target, options, env) {
8670
8983
  let overlayMoved = false;
8671
8984
  for (const element of changes.ancestors) if (element.contains(ancestor)) overlayMoved = true;
8672
8985
  else for (const record of order) if (record.mark.parts.some((part) => element.contains(part.element))) changed.add(record);
8673
- if (overlayMoved) placeOverlay();
8674
- if (changed.size === 0) return;
8675
- const { records, marks } = reread([...changed]);
8986
+ const rescaled = /* @__PURE__ */ new Set();
8987
+ if (overlayMoved) {
8988
+ placeOverlay();
8989
+ for (const record of order) if (!changed.has(record) && record.mark.parts.some((part) => part.stroke?.screen)) rescaled.add(record);
8990
+ }
8991
+ if (changed.size === 0 && rescaled.size === 0) return;
8992
+ const read = reread([...changed, ...rescaled]);
8993
+ const kept = read.records.flatMap((record, i) => rescaled.has(record) && !geometryChanged(record.mark.geometry, read.marks[i].geometry) ? [] : [i]);
8994
+ if (kept.length === 0) return;
8995
+ const records = kept.map((i) => read.records[i]);
8996
+ const marks = kept.map((i) => read.marks[i]);
8676
8997
  records.forEach((record, i) => {
8677
8998
  const mark = marks[i];
8678
8999
  record.mark = mark;
@@ -8694,7 +9015,7 @@ function expressive$1(target, options, env) {
8694
9015
  common: ancestor,
8695
9016
  screen: screenMatrices(),
8696
9017
  colors: (element) => owners.get(element)?.part.colors,
8697
- strokeWidth: (element) => owners.get(element)?.part.strokeWidth
9018
+ stroke: (element) => owners.get(element)?.part.stroke
8698
9019
  };
8699
9020
  const rowOf = rowsNow();
8700
9021
  const piecesOf = ({ parts }) => parts.map((part) => ({
@@ -8713,16 +9034,17 @@ function expressive$1(target, options, env) {
8713
9034
  marks: withData(marks)
8714
9035
  };
8715
9036
  }
8716
- const rects = new Map(changed.flatMap((record) => record.mark.rect ? [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]] : []));
8717
- const edges = edgesNow(rects);
8718
- for (const record of order) if (record.mark.rect && !rects.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
9037
+ const shapes = new Set(changed.filter((record) => !record.mark.rect || turned(record.mark.parts, at)));
9038
+ const rects = new Map(changed.flatMap((record) => shapes.has(record) ? [] : [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]]));
9039
+ const edges = edgesNow(rects, shapes);
9040
+ for (const record of order) if (record.mark.rect && !rects.has(record) && !shapes.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
8719
9041
  const records = [...rects.keys()];
8720
9042
  const marks = records.map((record) => ({
8721
9043
  ...rectMark(record.key, rects.get(record), edges.get(record), record.mark.index, at),
8722
9044
  label: record.mark.label
8723
9045
  }));
8724
9046
  for (const record of changed) {
8725
- if (record.mark.rect) continue;
9047
+ if (!shapes.has(record)) continue;
8726
9048
  const mark = shapeMark(record.key, piecesOf(record.mark)[0], record.mark.index, at);
8727
9049
  if (!mark) continue;
8728
9050
  records.push(record);
@@ -8736,8 +9058,8 @@ function expressive$1(target, options, env) {
8736
9058
  marks: withData(marks)
8737
9059
  };
8738
9060
  }
8739
- function edgesNow(rects) {
8740
- const bars = order.filter((record) => record.mark.rect);
9061
+ function edgesNow(rects, shapes) {
9062
+ const bars = order.filter((record) => record.mark.rect && !shapes.has(record));
8741
9063
  const kept = new Map(bars.map((record) => [record, record.mark.rect.edge]));
8742
9064
  if (options.baseline !== void 0 && options.baseline !== "auto") return kept;
8743
9065
  const boxes = bars.map((record) => {
@@ -8896,7 +9218,7 @@ function expressive$1(target, options, env) {
8896
9218
  }
8897
9219
  });
8898
9220
  }
8899
- function checkOptions$11(options) {
9221
+ function checkOptions$12(options) {
8900
9222
  if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
8901
9223
  if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
8902
9224
  for (const name of [
@@ -8908,6 +9230,11 @@ function checkOptions$11(options) {
8908
9230
  ]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
8909
9231
  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)}.`);
8910
9232
  }
9233
+ function partOf(mark, key) {
9234
+ if (key === void 0) return mark?.parts[0];
9235
+ const segment = mark?.geometry.segments?.find((s) => s.key === key);
9236
+ return segment && mark.parts.find((p) => p.series === segment.series);
9237
+ }
8911
9238
  function ownSeries(mark) {
8912
9239
  const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
8913
9240
  return [...new Set(names.filter((name) => name !== void 0))];
@@ -9351,7 +9678,7 @@ function pointsOf(first) {
9351
9678
  function lineOf(key, element, first, m) {
9352
9679
  const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
9353
9680
  if (!straight(first)) {
9354
- const scaled = width * scaleOf(m);
9681
+ const scaled = width * scaleOf$1(m);
9355
9682
  return describeShape({
9356
9683
  key,
9357
9684
  series: key,
@@ -9367,7 +9694,7 @@ function lineOf(key, element, first, m) {
9367
9694
  series: key,
9368
9695
  points: points.map(({ point }) => matrix.apply(m, point)),
9369
9696
  ...breaks.length > 0 ? { breaks } : {},
9370
- width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
9697
+ width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
9371
9698
  });
9372
9699
  }
9373
9700
  function sliceOf(key, item, m) {
@@ -9375,7 +9702,7 @@ function sliceOf(key, item, m) {
9375
9702
  x: number(item.x),
9376
9703
  y: number(item.y)
9377
9704
  });
9378
- const s = scaleOf(m);
9705
+ const s = scaleOf$1(m);
9379
9706
  const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
9380
9707
  return describeArc({
9381
9708
  key,
@@ -9396,7 +9723,7 @@ function pointOf(key, item, m) {
9396
9723
  key,
9397
9724
  x: center.x,
9398
9725
  y: center.y,
9399
- r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
9726
+ r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
9400
9727
  });
9401
9728
  }
9402
9729
  function boxOf(item) {
@@ -9411,19 +9738,19 @@ function boxOf(item) {
9411
9738
  height: Math.abs(height)
9412
9739
  };
9413
9740
  }
9414
- function scaleOf(m) {
9741
+ function scaleOf$1(m) {
9415
9742
  return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
9416
9743
  }
9417
9744
  function number(value) {
9418
9745
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
9419
9746
  }
9420
9747
  // src/charts/switch.ts
9421
- const DURATION$7 = 950;
9748
+ const DURATION$8 = 950;
9422
9749
  const OUT_BY = .4;
9423
9750
  const HALF = .5;
9424
9751
  function chartSwitch$1(target, options, env) {
9425
9752
  const host = resolveTarget$2(target, "chartSwitch");
9426
- const names = checkOptions$10(options);
9753
+ const names = checkOptions$11(options);
9427
9754
  const effect = options.transition;
9428
9755
  const colors = toColorAssignment(options.colors);
9429
9756
  const motion = env.motion;
@@ -9467,20 +9794,100 @@ function chartSwitch$1(target, options, env) {
9467
9794
  const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
9468
9795
  const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
9469
9796
  const orders = /* @__PURE__ */ new WeakMap();
9470
- const surface = { group(key, order) {
9797
+ const surfaceFor = (paints, extras) => ({ group(key, order) {
9471
9798
  const group = svgElement("g", {
9472
9799
  class: "ec-run",
9473
9800
  "data-key": key
9474
9801
  }, runsLayer);
9475
- setStyles(group, markColorStyles(seriesColors(colors.slot(key))));
9802
+ setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
9476
9803
  orders.set(group, order);
9477
9804
  const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
9478
9805
  runsLayer.insertBefore(group, above ?? null);
9806
+ const layer = svgLayer(group);
9479
9807
  return {
9480
- ...svgLayer(group),
9808
+ ...extras[order]?.wrap(layer, group) ?? layer,
9481
9809
  clear: () => group.remove()
9482
9810
  };
9483
- } };
9811
+ } });
9812
+ function extrasFor(rings, ends, dotColors) {
9813
+ const [ringA, ringB] = rings;
9814
+ const [endA, endB] = ends;
9815
+ if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
9816
+ const dots = [];
9817
+ if (endA && endB) {
9818
+ const element = endDot();
9819
+ const draw = (s) => placeDot(element, {
9820
+ at: {
9821
+ x: mix$1(endA.at.x, endB.at.x, s),
9822
+ y: mix$1(endA.at.y, endB.at.y, s)
9823
+ },
9824
+ r: mix$1(endA.r, endB.r, s),
9825
+ ring: mix$1(endA.ring, endB.ring, s)
9826
+ });
9827
+ dots.push({
9828
+ element,
9829
+ draw
9830
+ });
9831
+ } else [[
9832
+ endA,
9833
+ fadeOut,
9834
+ dotColors[0]
9835
+ ], [
9836
+ endB,
9837
+ fadeIn,
9838
+ dotColors[1]
9839
+ ]].forEach(([end, opacity, color]) => {
9840
+ if (!end) return;
9841
+ const element = endDot();
9842
+ setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
9843
+ placeDot(element, end);
9844
+ dots.push({
9845
+ element,
9846
+ draw: (s) => setAttributes(element, { opacity: opacity(s) })
9847
+ });
9848
+ });
9849
+ const ringed = ringA > 0 || ringB > 0;
9850
+ let width = ringA;
9851
+ const shapes = /* @__PURE__ */ new Map();
9852
+ return {
9853
+ wrap(layer, group) {
9854
+ shapes.clear();
9855
+ const raise = () => {
9856
+ for (const dot of dots) group.appendChild(dot.element);
9857
+ };
9858
+ raise();
9859
+ return {
9860
+ ...layer,
9861
+ path(d, paint) {
9862
+ const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
9863
+ const handle = layer.path(d, ring ? {
9864
+ ...paint,
9865
+ stroke: "surface",
9866
+ width
9867
+ } : paint);
9868
+ raise();
9869
+ if (!ring) return handle;
9870
+ shapes.set(handle, d);
9871
+ return {
9872
+ update(next, nextPaint) {
9873
+ shapes.set(handle, next);
9874
+ handle.update(next, nextPaint);
9875
+ },
9876
+ remove() {
9877
+ shapes.delete(handle);
9878
+ handle.remove();
9879
+ }
9880
+ };
9881
+ }
9882
+ };
9883
+ },
9884
+ draw(s) {
9885
+ width = mix$1(ringA, ringB, s);
9886
+ for (const [handle, d] of shapes) handle.update(d, { width });
9887
+ for (const dot of dots) dot.draw(s);
9888
+ }
9889
+ };
9890
+ }
9484
9891
  let current = options.initial;
9485
9892
  let active;
9486
9893
  let destroyed = false;
@@ -9506,19 +9913,26 @@ function chartSwitch$1(target, options, env) {
9506
9913
  }
9507
9914
  function readFocus(from) {
9508
9915
  const element = focused();
9509
- if (!element || !from.container.contains(element)) return void 0;
9510
- const keyed = element.closest("[data-key]");
9511
- return { key: keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") ?? void 0 : void 0 };
9916
+ const inside = element !== null && from.container.contains(element);
9917
+ const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
9918
+ const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
9919
+ if (!inside && key === null) return void 0;
9920
+ return {
9921
+ keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
9922
+ focused: inside
9923
+ };
9512
9924
  }
9513
9925
  function restoreFocus(to, memory) {
9514
9926
  if (!memory) return;
9515
9927
  const now = focused();
9516
- if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
9928
+ const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
9929
+ if (!memory.focused || away) {
9930
+ for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
9931
+ return;
9932
+ }
9517
9933
  const inside = () => to.chart.element.contains(focused());
9518
- if (memory.key !== void 0) to.chart.focus(memory.key);
9519
- if (inside()) return;
9520
- for (const mark of to.chart.marks()) {
9521
- to.chart.focus(mark.key);
9934
+ for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
9935
+ to.chart.focus(key);
9522
9936
  if (inside()) return;
9523
9937
  }
9524
9938
  }
@@ -9556,7 +9970,7 @@ function chartSwitch$1(target, options, env) {
9556
9970
  each.container.setAttribute("inert", "");
9557
9971
  each.chart.element.classList.add("ec-morphing");
9558
9972
  }
9559
- const { pairs, scene } = prepare(from, to);
9973
+ const { pairs, surface, scene } = prepare(from, to);
9560
9974
  const { done, settle } = deferred();
9561
9975
  const session = {
9562
9976
  a: from,
@@ -9567,6 +9981,7 @@ function chartSwitch$1(target, options, env) {
9567
9981
  from: b,
9568
9982
  to: a
9569
9983
  })),
9984
+ surface,
9570
9985
  scene,
9571
9986
  focus: memory,
9572
9987
  progress: 0,
@@ -9593,7 +10008,7 @@ function chartSwitch$1(target, options, env) {
9593
10008
  const started = startClock(clock);
9594
10009
  session.transition = playTransition(session.forward ? session.pairs : session.reversed, {
9595
10010
  effect,
9596
- surface,
10011
+ surface: session.surface,
9597
10012
  start: begin,
9598
10013
  motion,
9599
10014
  clock: started.clock,
@@ -9642,20 +10057,38 @@ function chartSwitch$1(target, options, env) {
9642
10057
  function prepare(a, b) {
9643
10058
  const toA = between$1(overlay, a.chart.element, wrapper);
9644
10059
  const toB = between$1(overlay, b.chart.element, wrapper);
10060
+ const scaleA = scaleOf(toA);
10061
+ const scaleB = scaleOf(toB);
9645
10062
  const from = a.chart.marks().map((mark) => mapMark(mark, toA));
9646
10063
  const to = b.chart.marks().map((mark) => mapMark(mark, toB));
9647
10064
  const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
9648
10065
  const toKeys = new Set(to.map((mark) => mark.key));
9649
- const pairs = to.flatMap((mark) => {
10066
+ const pairs = [];
10067
+ const paints = [];
10068
+ const extras = [];
10069
+ for (const mark of to) {
9650
10070
  const partner = fromByKey.get(mark.key);
9651
- return partner ? [{
9652
- from: partner,
9653
- to: mark
9654
- }] : [];
9655
- });
10071
+ if (!partner) continue;
10072
+ const was = paintOf(a, partner);
10073
+ const will = paintOf(b, mark);
10074
+ if (!was.drawn && !will.drawn) continue;
10075
+ pairs.push({
10076
+ from: was.drawn ? partner : dot$1(partner),
10077
+ to: will.drawn ? mark : dot$1(mark)
10078
+ });
10079
+ paints.push(will.color);
10080
+ extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
10081
+ }
9656
10082
  const drawings = [];
9657
- for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
9658
- for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
10083
+ if (extras.some((each) => each !== void 0)) drawings.push((s) => {
10084
+ for (const each of extras) each?.draw(s);
10085
+ });
10086
+ const fade = (view, mark, scale, opacity) => {
10087
+ const paint = paintOf(view, mark);
10088
+ if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
10089
+ };
10090
+ for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
10091
+ for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
9659
10092
  const id = (label) => `${label.role}\n${label.key}`;
9660
10093
  const labelsA = a.chart.labels();
9661
10094
  const labelsB = b.chart.labels();
@@ -9675,6 +10108,7 @@ function chartSwitch$1(target, options, env) {
9675
10108
  });
9676
10109
  return {
9677
10110
  pairs,
10111
+ surface: surfaceFor(paints, extras),
9678
10112
  scene: {
9679
10113
  draw: (s) => {
9680
10114
  for (const draw of drawings) draw(s);
@@ -9687,18 +10121,36 @@ function chartSwitch$1(target, options, env) {
9687
10121
  }
9688
10122
  };
9689
10123
  }
9690
- function fadeMark(mark, opacity) {
10124
+ function fadeMark(mark, paint, scale, opacity) {
9691
10125
  const group = svgElement("g", {
9692
10126
  class: "ec-switch-fade",
9693
10127
  "data-key": mark.key
9694
10128
  }, fadesLayer);
9695
- setStyles(group, markColorStyles(seriesColors(colors.slot(mark.key))));
9696
- svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : {
10129
+ setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
10130
+ const ring = ringOf(paint, scale);
10131
+ svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
10132
+ fill: "mark",
10133
+ ...ring > 0 ? {
10134
+ stroke: "surface",
10135
+ width: ring
10136
+ } : {}
10137
+ } : {
9697
10138
  stroke: "mark",
9698
10139
  width: mark.thickness
9699
10140
  });
10141
+ const end = endOf(paint, mark, scale);
10142
+ if (end) placeDot(group.appendChild(endDot()), end);
9700
10143
  return (s) => setAttributes(group, { opacity: opacity(s) });
9701
10144
  }
10145
+ function endDot() {
10146
+ const element = doc.createElementNS(SVG_NS$2, "circle");
10147
+ element.setAttribute("class", "ec-switch-end");
10148
+ setStyles(element, {
10149
+ fill: cssColor("mark"),
10150
+ stroke: cssColor("surface")
10151
+ });
10152
+ return element;
10153
+ }
9702
10154
  function copyLabel(label, m) {
9703
10155
  const text = label.element.cloneNode(true);
9704
10156
  for (const name of [
@@ -9829,7 +10281,7 @@ function drive(begin, at, env) {
9829
10281
  const begun = unease(begin);
9830
10282
  let running;
9831
10283
  running = tween({
9832
- duration: DURATION$7,
10284
+ duration: DURATION$8,
9833
10285
  timing: "transition",
9834
10286
  ease: linear,
9835
10287
  update: (k) => {
@@ -9885,12 +10337,44 @@ const fadeOut = (s) => 1 - clamp$1(s / HALF);
9885
10337
  const fadeIn = (s) => clamp$1((s - HALF) / .5);
9886
10338
  const clamp$1 = (value) => Math.min(1, Math.max(0, value));
9887
10339
  const mix$1 = (x, y, s) => x * (1 - s) + y * s;
10340
+ function paintOf(view, mark) {
10341
+ return view.chart.paintOf?.(mark.key) ?? {
10342
+ color: mark.key,
10343
+ drawn: true
10344
+ };
10345
+ }
10346
+ function dot$1(mark) {
10347
+ return describePoint({
10348
+ key: mark.key,
10349
+ ...mark.series === void 0 ? {} : { series: mark.series },
10350
+ x: mark.center.x,
10351
+ y: mark.center.y,
10352
+ r: 0
10353
+ });
10354
+ }
10355
+ const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
10356
+ function endOf(paint, mark, scale) {
10357
+ return paint.drawn && paint.end !== void 0 ? {
10358
+ at: mark.end,
10359
+ r: paint.end * scale,
10360
+ ring: (paint.ring ?? 0) * scale
10361
+ } : void 0;
10362
+ }
10363
+ function placeDot(element, end) {
10364
+ setAttributes(element, {
10365
+ cx: end.at.x,
10366
+ cy: end.at.y,
10367
+ r: end.r,
10368
+ "stroke-width": end.ring
10369
+ });
10370
+ }
9888
10371
  const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
10372
+ const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
9889
10373
  function mapMark(mark, m) {
9890
10374
  if (isIdentity(m)) return mark;
9891
10375
  const point = (p) => matrix.apply(m, p);
9892
10376
  const path = (d) => formatPath(transformPath(parsePath(d), m));
9893
- const scale = Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
10377
+ const scale = scaleOf(m);
9894
10378
  const { outline } = mark;
9895
10379
  return {
9896
10380
  key: mark.key,
@@ -9906,6 +10390,7 @@ function mapMark(mark, m) {
9906
10390
  return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
9907
10391
  },
9908
10392
  slice: (t0, t1) => path(mark.slice(t0, t1)),
10393
+ ...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
9909
10394
  thickness: mark.thickness * scale,
9910
10395
  outline: {
9911
10396
  d: path(outline.d),
@@ -9939,7 +10424,7 @@ function isView(value, container) {
9939
10424
  "destroy"
9940
10425
  ].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
9941
10426
  }
9942
- function checkOptions$10(options) {
10427
+ function checkOptions$11(options) {
9943
10428
  if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
9944
10429
  const { views, initial, transition, announce } = options;
9945
10430
  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.");
@@ -9972,7 +10457,7 @@ let switches = 0;
9972
10457
  function motionSwitch$1(target, motion, options = {}) {
9973
10458
  const parent = resolveTarget$1(target);
9974
10459
  checkMotion(motion);
9975
- checkOptions$9(options);
10460
+ checkOptions$10(options);
9976
10461
  const labels = {
9977
10462
  ...LABELS$1,
9978
10463
  ...options.labels
@@ -10056,7 +10541,7 @@ function resolveTarget$1(target) {
10056
10541
  function checkMotion(motion) {
10057
10542
  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().");
10058
10543
  }
10059
- function checkOptions$9(options) {
10544
+ function checkOptions$10(options) {
10060
10545
  const { label, labels, hints, persist } = options;
10061
10546
  if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
10062
10547
  for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
@@ -10073,7 +10558,7 @@ const LABELS = {
10073
10558
  function playButton(target, playback, options = {}) {
10074
10559
  const parent = resolveTarget(target);
10075
10560
  checkPlayback(playback);
10076
- checkOptions$8(options);
10561
+ checkOptions$9(options);
10077
10562
  const labels = {
10078
10563
  ...LABELS,
10079
10564
  ...options.labels
@@ -10114,7 +10599,7 @@ function resolveTarget(target) {
10114
10599
  function checkPlayback(playback) {
10115
10600
  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().");
10116
10601
  }
10117
- function checkOptions$8(options) {
10602
+ function checkOptions$9(options) {
10118
10603
  const { labels } = options;
10119
10604
  if (labels === void 0) return;
10120
10605
  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)}.`);
@@ -10166,7 +10651,7 @@ const gaits = {
10166
10651
  const SPEED = 360;
10167
10652
  const SHORTEST = 260;
10168
10653
  const LONGEST = 4e3;
10169
- const MIN_WALK$2 = .5;
10654
+ const MIN_WALK$3 = .5;
10170
10655
  const FIT = .85;
10171
10656
  const MIN_SMOOTHING = 2;
10172
10657
  const IDENTITY = [
@@ -10184,12 +10669,12 @@ const ORIENTS = [
10184
10669
  ];
10185
10670
  const RIDES = ["center", "on"];
10186
10671
  function travel(icon, options = {}) {
10187
- checkOptions$7(icon, options);
10672
+ checkOptions$8(icon, options);
10188
10673
  function plan(mark, ctx) {
10189
10674
  const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
10190
10675
  if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
10191
10676
  const walk = pick(mark, options.along);
10192
- if (!walk || !(drawn(walk) >= MIN_WALK$2)) return void 0;
10677
+ if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
10193
10678
  const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
10194
10679
  if (!(scale > 0)) return void 0;
10195
10680
  return trip(walk, resolved, scale, options);
@@ -10337,7 +10822,7 @@ function heading(walk, distance, window, leg) {
10337
10822
  }
10338
10823
  return walk.angle(distance / length);
10339
10824
  }
10340
- function checkOptions$7(icon, options) {
10825
+ function checkOptions$8(icon, options) {
10341
10826
  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}.`);
10342
10827
  const { along, gait, size, orient, ride } = options;
10343
10828
  if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
@@ -10347,12 +10832,12 @@ function checkOptions$7(icon, options) {
10347
10832
  if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
10348
10833
  }
10349
10834
  // src/effects/flash.ts
10350
- const DURATION$6 = 900;
10835
+ const DURATION$7 = 900;
10351
10836
  const PEAK = .25;
10352
10837
  const WIDTH$2 = 8;
10353
10838
  const OPACITY$2 = .35;
10354
10839
  function flash(options = {}) {
10355
- checkOptions$6(options);
10840
+ checkOptions$7(options);
10356
10841
  const width = options.width ?? WIDTH$2;
10357
10842
  const opacity = options.opacity ?? OPACITY$2;
10358
10843
  const { color } = options;
@@ -10369,7 +10854,7 @@ function flash(options = {}) {
10369
10854
  async run(_mark, ctx) {
10370
10855
  if (ctx.signal.aborted) return;
10371
10856
  await ctx.tween({
10372
- duration: DURATION$6,
10857
+ duration: DURATION$7,
10373
10858
  timing: "effect",
10374
10859
  ease: linear,
10375
10860
  update: (p) => show(ctx, p)
@@ -10396,14 +10881,14 @@ function easeOut(x) {
10396
10881
  const s = (lo + hi) / 2;
10397
10882
  return 3 * s * s - 2 * s * s * s;
10398
10883
  }
10399
- function checkOptions$6(options) {
10884
+ function checkOptions$7(options) {
10400
10885
  const { width, opacity, color } = options;
10401
10886
  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)}.`);
10402
10887
  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)}.`);
10403
10888
  if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`flash: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
10404
10889
  }
10405
10890
  // src/effects/wiggle.ts
10406
- const DURATION$5 = 450;
10891
+ const DURATION$6 = 450;
10407
10892
  const SWINGS = [
10408
10893
  1,
10409
10894
  -.5,
@@ -10414,7 +10899,7 @@ const MIN_REACH = .5;
10414
10899
  const SAMPLES = 64;
10415
10900
  const MAX_ANGLE = Math.PI / 12;
10416
10901
  function wiggle(options = {}) {
10417
- checkOptions$5(options);
10902
+ checkOptions$6(options);
10418
10903
  const swing = options.swing ?? SWING;
10419
10904
  return {
10420
10905
  kind: "geometry",
@@ -10433,7 +10918,7 @@ function wiggle(options = {}) {
10433
10918
  show();
10434
10919
  });
10435
10920
  await ctx.tween({
10436
- duration: DURATION$5,
10921
+ duration: DURATION$6,
10437
10922
  timing: "effect",
10438
10923
  ease: linear,
10439
10924
  update: (p) => {
@@ -10459,19 +10944,19 @@ function rock(t) {
10459
10944
  const index = Math.floor(position);
10460
10945
  return SWINGS[index] * Math.sin(Math.PI * (position - index));
10461
10946
  }
10462
- function checkOptions$5(options) {
10947
+ function checkOptions$6(options) {
10463
10948
  const { swing } = options;
10464
10949
  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)}.`);
10465
10950
  }
10466
10951
  // src/effects/pulse.ts
10467
- const DURATION$4 = 600;
10952
+ const DURATION$5 = 600;
10468
10953
  const TIMES = 2;
10469
10954
  const MAX_TIMES = 6;
10470
10955
  const WIDTH$1 = 12;
10471
10956
  const OPACITY$1 = .4;
10472
10957
  const LIMIT = 5e3;
10473
10958
  function pulse(options = {}) {
10474
- checkOptions$4(options);
10959
+ checkOptions$5(options);
10475
10960
  const times = options.times ?? TIMES;
10476
10961
  const width = options.width ?? WIDTH$1;
10477
10962
  const { color } = options;
@@ -10489,11 +10974,11 @@ function pulse(options = {}) {
10489
10974
  let total = 0;
10490
10975
  for (let i = 0; i < times; i++) {
10491
10976
  if (ctx.signal.aborted) return;
10492
- const length = ctx.motion.duration(DURATION$4, "effect");
10977
+ const length = ctx.motion.duration(DURATION$5, "effect");
10493
10978
  if (total + length >= LIMIT) return;
10494
10979
  total += length;
10495
10980
  await ctx.tween({
10496
- duration: DURATION$4,
10981
+ duration: DURATION$5,
10497
10982
  timing: "effect",
10498
10983
  ease: linear,
10499
10984
  update: (t) => show(ctx, t)
@@ -10504,20 +10989,20 @@ function pulse(options = {}) {
10504
10989
  clear() {}
10505
10990
  };
10506
10991
  }
10507
- function checkOptions$4(options) {
10992
+ function checkOptions$5(options) {
10508
10993
  const { times, width, color } = options;
10509
10994
  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)}.`);
10510
10995
  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)}.`);
10511
10996
  if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`pulse: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
10512
10997
  }
10513
10998
  // src/effects/trace.ts
10514
- const DURATION$3 = 500;
10999
+ const DURATION$4 = 500;
10515
11000
  const WIDTH = 3;
10516
11001
  const OPACITY = .5;
10517
- const MIN_WALK$1 = .5;
11002
+ const MIN_WALK$2 = .5;
10518
11003
  function trace(options = {}) {
10519
- checkOptions$3(options);
10520
- const duration = options.duration ?? DURATION$3;
11004
+ checkOptions$4(options);
11005
+ const duration = options.duration ?? DURATION$4;
10521
11006
  const paint = {
10522
11007
  stroke: options.color ?? "mark",
10523
11008
  width: options.width ?? WIDTH,
@@ -10529,7 +11014,7 @@ function trace(options = {}) {
10529
11014
  let progress = 0;
10530
11015
  let path;
10531
11016
  const draw = () => {
10532
- if (!(current.length >= MIN_WALK$1)) {
11017
+ if (!(current.length >= MIN_WALK$2)) {
10533
11018
  path?.remove();
10534
11019
  path = void 0;
10535
11020
  return;
@@ -10553,7 +11038,7 @@ function trace(options = {}) {
10553
11038
  async run(mark, ctx) {
10554
11039
  if (ctx.signal.aborted) return;
10555
11040
  const show = stroke(mark, ctx);
10556
- if (!(mark.length >= MIN_WALK$1)) {
11041
+ if (!(mark.length >= MIN_WALK$2)) {
10557
11042
  show(1);
10558
11043
  return;
10559
11044
  }
@@ -10570,31 +11055,147 @@ function trace(options = {}) {
10570
11055
  clear() {}
10571
11056
  };
10572
11057
  }
10573
- function checkOptions$3(options) {
11058
+ function checkOptions$4(options) {
10574
11059
  const { color, width, opacity, duration } = options;
10575
11060
  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)}.`);
10576
11061
  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)}.`);
10577
11062
  if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
10578
11063
  if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
10579
11064
  }
11065
+ // src/effects/draw-in.ts
11066
+ const DURATION$3 = 750;
11067
+ const FAINT = .3;
11068
+ const MIN_WALK$1 = .5;
11069
+ function drawIn(options = {}) {
11070
+ checkOptions$3(options);
11071
+ const duration = options.duration ?? DURATION$3;
11072
+ const faint = options.faint ?? FAINT;
11073
+ return {
11074
+ kind: "geometry",
11075
+ async run(mark, ctx) {
11076
+ if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
11077
+ let current = mark;
11078
+ let progress = 0;
11079
+ let done = false;
11080
+ const paths = [];
11081
+ const draw = (repaint) => {
11082
+ const { segments } = current;
11083
+ const parts = segments ?? [current];
11084
+ const reached = progress * walk(current);
11085
+ let from = 0;
11086
+ parts.forEach((piece, i) => {
11087
+ const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
11088
+ from += piece.length;
11089
+ const d = piece.slice(0, easeInOutCubic(share));
11090
+ const paint = {
11091
+ stroke: "mark",
11092
+ width: piece.thickness,
11093
+ linecap: "butt",
11094
+ ...segments && { part: piece.key }
11095
+ };
11096
+ const path = paths[i];
11097
+ if (!path) paths[i] = ctx.layer.path(d, paint);
11098
+ else path.update(d, repaint ? {
11099
+ part: void 0,
11100
+ ...paint
11101
+ } : void 0);
11102
+ });
11103
+ for (const path of paths.splice(parts.length)) path.remove();
11104
+ };
11105
+ ctx.onChange((next) => {
11106
+ current = next;
11107
+ if (!done) draw(true);
11108
+ });
11109
+ ctx.mark.set({ opacity: faint });
11110
+ draw(false);
11111
+ await ctx.tween({
11112
+ duration,
11113
+ timing: "effect",
11114
+ ease: linear,
11115
+ update: (p) => {
11116
+ progress = p;
11117
+ draw(false);
11118
+ }
11119
+ }).finished;
11120
+ done = true;
11121
+ for (const path of paths) path.remove();
11122
+ ctx.mark.set({ opacity: void 0 });
11123
+ },
11124
+ end() {},
11125
+ clear() {}
11126
+ };
11127
+ }
11128
+ const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
11129
+ function checkOptions$3(options) {
11130
+ const { duration, faint } = options;
11131
+ 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)}.`);
11132
+ 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)}.`);
11133
+ }
10580
11134
  // src/effects/caption.ts
10581
11135
  const PAST_END = 10;
10582
11136
  const PAST_LABEL = 6;
10583
11137
  const TEXT = 12.5;
10584
11138
  const CENTRE = .36;
10585
- function captionPlace(mark) {
11139
+ function captionPlace(mark, text) {
10586
11140
  const own = mark.labelBounds ?? [];
10587
- const nearby = mark.nearbyLabels ?? [];
11141
+ const boxes = [
11142
+ ...own,
11143
+ ...mark.nearbyLabels ?? [],
11144
+ ...text?.held ?? []
11145
+ ];
10588
11146
  const heading = mark.angle(1);
10589
- const along = farthest(mark.end, heading, own);
10590
- if (along === void 0 && own.length > 0) {
11147
+ if (farthest(mark.end, heading, own) === void 0) {
10591
11148
  const up = mark.angle(.5) - Math.PI / 2;
10592
- const out = farthest(mark.center, up, own);
10593
- if (out !== void 0) return placed(mark.center, up, Math.max(out, farthest(mark.center, up, nearby) ?? -Infinity));
11149
+ if (farthest(mark.center, up, own) !== void 0) return past(mark.center, up, 0, own, boxes, text);
11150
+ }
11151
+ return past(mark.end, heading, PAST_END, own, boxes, text);
11152
+ }
11153
+ function past(from, toward, least, own, boxes, text) {
11154
+ if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
11155
+ const { x, y, width, height } = text.box(placed$1(from, toward, 0));
11156
+ return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
11157
+ x: x - from.x,
11158
+ y: y - from.y,
11159
+ width,
11160
+ height
11161
+ }, new Set(text.held)));
11162
+ }
11163
+ function clearOf(from, toward, distance, boxes, reach, held) {
11164
+ const cos = Math.cos(toward);
11165
+ const sin = Math.sin(toward);
11166
+ const across = centred(cos);
11167
+ const meets = (box) => span(from, cos, sin, {
11168
+ x: box.x - reach.x - reach.width,
11169
+ y: box.y - reach.y - reach.height,
11170
+ width: box.width + reach.width,
11171
+ height: box.height + reach.height
11172
+ });
11173
+ const spans = boxes.map((box) => {
11174
+ const near = grow(box, PAST_LABEL);
11175
+ const band = span(from, cos, sin, near);
11176
+ if (!band && held.has(box)) return meets(box);
11177
+ const within = meets(near);
11178
+ if (!band || !within) return within;
11179
+ const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
11180
+ return [within[0], Math.max(leaving, meets(box)?.[1] ?? -Infinity)];
11181
+ });
11182
+ let at = distance;
11183
+ for (let moved = true; moved;) {
11184
+ moved = false;
11185
+ for (const meets of spans) if (meets && at > meets[0] + 1e-6 && at < meets[1] - 1e-6) {
11186
+ at = meets[1];
11187
+ moved = true;
11188
+ }
10594
11189
  }
10595
- return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity, farthest(mark.end, heading, nearby) ?? -Infinity));
11190
+ return at;
10596
11191
  }
10597
- function placed(from, toward, distance) {
11192
+ const grow = ({ x, y, width, height }, by) => ({
11193
+ x: x - by,
11194
+ y: y - by,
11195
+ width: width + 2 * by,
11196
+ height: height + 2 * by
11197
+ });
11198
+ function placed$1(from, toward, distance) {
10598
11199
  const cos = Math.cos(toward);
10599
11200
  const sin = Math.sin(toward);
10600
11201
  const point = offset(from, toward, distance);
@@ -10617,13 +11218,8 @@ function farthest(from, toward, boxes) {
10617
11218
  const sin = Math.sin(toward);
10618
11219
  const across = centred(cos);
10619
11220
  let exit;
10620
- for (const { x, y, width, height } of boxes) {
10621
- const grown = {
10622
- x: x - PAST_LABEL,
10623
- y: y - PAST_LABEL,
10624
- width: width + 12,
10625
- height: height + 12
10626
- };
11221
+ for (const box of boxes) {
11222
+ const grown = grow(box, PAST_LABEL);
10627
11223
  let leaving = leaves(from, cos, sin, grown);
10628
11224
  if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
10629
11225
  if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
@@ -10631,6 +11227,9 @@ function farthest(from, toward, boxes) {
10631
11227
  return exit;
10632
11228
  }
10633
11229
  function leaves(from, cos, sin, box) {
11230
+ return span(from, cos, sin, box)?.[1];
11231
+ }
11232
+ function span(from, cos, sin, box) {
10634
11233
  let near = 0;
10635
11234
  let far = Infinity;
10636
11235
  for (const [origin, step, lo, hi] of [[
@@ -10653,7 +11252,7 @@ function leaves(from, cos, sin, box) {
10653
11252
  near = Math.max(near, Math.min(a, b));
10654
11253
  far = Math.min(far, Math.max(a, b));
10655
11254
  }
10656
- return far >= near ? far : void 0;
11255
+ return far >= near ? [near, far] : void 0;
10657
11256
  }
10658
11257
  function caption(mark, data, ctx, color, words) {
10659
11258
  let current = mark;
@@ -10661,13 +11260,22 @@ function caption(mark, data, ctx, color, words) {
10661
11260
  let latest = data;
10662
11261
  let progress = 0;
10663
11262
  let handle;
11263
+ const { texts } = ctx;
10664
11264
  const draw = () => {
10665
11265
  if (content === "") {
10666
11266
  handle?.remove();
10667
11267
  handle = void 0;
11268
+ texts?.hold(void 0);
10668
11269
  return;
10669
11270
  }
10670
- const { at, anchor, toward } = captionPlace(current);
11271
+ const { at, anchor, toward } = captionPlace(current, texts && {
11272
+ held: texts.held(),
11273
+ box: (style) => texts.box(content, style)
11274
+ });
11275
+ texts?.hold(texts.box(content, {
11276
+ at,
11277
+ anchor
11278
+ }));
10671
11279
  const style = {
10672
11280
  at: offset(at, toward - Math.PI / 2, -8 * (1 - progress)),
10673
11281
  anchor,
@@ -10827,7 +11435,7 @@ function reference(compareTo, data) {
10827
11435
  const gaps = gapsOf(related.samples, place);
10828
11436
  return {
10829
11437
  place,
10830
- valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
11438
+ valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
10831
11439
  bends: points.map((point) => point.u)
10832
11440
  };
10833
11441
  }
@@ -10849,7 +11457,7 @@ function gapsOf(samples, place) {
10849
11457
  }
10850
11458
  return merged;
10851
11459
  }
10852
- function inside(gaps, u) {
11460
+ function inside$1(gaps, u) {
10853
11461
  let lo = 0;
10854
11462
  let hi = gaps.length;
10855
11463
  while (lo < hi) {
@@ -10955,6 +11563,11 @@ const show = (value) => typeof value === "string" ? JSON.stringify(value) : Stri
10955
11563
  const DURATION = 950;
10956
11564
  const POINTS = 160;
10957
11565
  const ALIGNS = ["unroll", "drop"];
11566
+ const SAME_T = 1e-9;
11567
+ const SAME_X = .01;
11568
+ const VERTICES = 1e3;
11569
+ const GRID = 9;
11570
+ const CHECKS = 8;
10958
11571
  function morph(options = {}) {
10959
11572
  checkOptions(options);
10960
11573
  const points = options?.points ?? POINTS;
@@ -10992,13 +11605,16 @@ function morph(options = {}) {
10992
11605
  function drawing(from, to, layer, points, align) {
10993
11606
  const closed = from.outline.closed;
10994
11607
  if (closed !== to.outline.closed) return crossfade(from, to, layer);
11608
+ const across = closed ? void 0 : acrossX(from, to, points);
11609
+ if (across) return piecewise(from, to, layer, across.stops, across.kinds);
10995
11610
  const a = from.outline.sample(points);
10996
11611
  const b = to.outline.sample(points);
10997
- if (!closed) return stroke(from, to, layer, a, b);
11612
+ if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
10998
11613
  const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
11614
+ const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
10999
11615
  let path;
11000
11616
  return (p) => {
11001
- const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true);
11617
+ const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true) + holes.map((hole) => holeAt(hole, p)).join("");
11002
11618
  if (path) path.update(d);
11003
11619
  else path = layer.path(d, { fill: "mark" });
11004
11620
  };
@@ -11015,6 +11631,326 @@ function stroke(from, to, layer, a, b) {
11015
11631
  });
11016
11632
  };
11017
11633
  }
11634
+ function gapped(from, to, layer, a, b) {
11635
+ const n = a.length;
11636
+ const stops = a.map((point, i) => ({
11637
+ t: i / (n - 1),
11638
+ from: point,
11639
+ to: b[i]
11640
+ }));
11641
+ for (const gap of [...from.gaps ?? [], ...to.gaps ?? []]) for (const t of gap) if (t > 0 && t < 1 && stops.every((stop) => Math.abs(stop.t - t) > SAME_T)) stops.push({
11642
+ t,
11643
+ from: from.path(t),
11644
+ to: to.path(t)
11645
+ });
11646
+ stops.sort((x, y) => x.t - y.t);
11647
+ return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
11648
+ const t = (stops[k].t + stop.t) / 2;
11649
+ return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
11650
+ }));
11651
+ }
11652
+ function piecewise(from, to, layer, stops, kinds) {
11653
+ const runs = [
11654
+ [],
11655
+ [],
11656
+ []
11657
+ ];
11658
+ for (let k = 0; k < kinds.length; k++) {
11659
+ const kind = kinds[k];
11660
+ if (kind === 3) continue;
11661
+ const last = runs[kind][runs[kind].length - 1];
11662
+ if (last && last[1] === k) last[1] = k + 1;
11663
+ else runs[kind].push([k, k + 1]);
11664
+ }
11665
+ const order = [
11666
+ 0,
11667
+ 1,
11668
+ 2
11669
+ ].filter((kind) => runs[kind].length > 0).sort((x, y) => runs[x][0][0] - runs[y][0][0]);
11670
+ const paths = [];
11671
+ return (p) => {
11672
+ const width = p <= 0 ? from.thickness : p >= 1 ? to.thickness : mix(from.thickness, to.thickness, p);
11673
+ const opacities = [
11674
+ void 0,
11675
+ p,
11676
+ 1 - p
11677
+ ];
11678
+ const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] : order.map((kind) => [runs[kind].map((run) => along(stops, run, p)).join(""), opacities[kind]]);
11679
+ pieces.forEach(([d, opacity], i) => {
11680
+ if (paths[i]) paths[i].update(d, {
11681
+ width,
11682
+ opacity
11683
+ });
11684
+ else paths[i] = layer.path(d, {
11685
+ stroke: "mark",
11686
+ width,
11687
+ ...opacity === void 0 ? {} : { opacity }
11688
+ });
11689
+ });
11690
+ for (const path of paths.splice(pieces.length)) path.remove();
11691
+ };
11692
+ }
11693
+ const inGap = (mark, t) => (mark.gaps ?? []).some(([x, y]) => x < t && t < y);
11694
+ function along(stops, [first, last], p) {
11695
+ let d = "";
11696
+ for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
11697
+ return d;
11698
+ }
11699
+ function acrossX(from, to, points) {
11700
+ const a = courseOf(from);
11701
+ const b = a && courseOf(to);
11702
+ if (!a || !b || a.way !== b.way) return void 0;
11703
+ const all = [
11704
+ ...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
11705
+ ...corners(a).map((s) => [s, 1]),
11706
+ ...corners(b).map((s) => [s, 2])
11707
+ ].sort((x, y) => x[0] - y[0]);
11708
+ const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
11709
+ const merged = [];
11710
+ for (const [s, whose] of all) {
11711
+ var _stop, _stop2;
11712
+ let stop = merged[merged.length - 1];
11713
+ if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
11714
+ if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
11715
+ if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
11716
+ }
11717
+ const last = merged.length - 1;
11718
+ if (last < 1) return void 0;
11719
+ const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
11720
+ const [onA, onB] = [shareOn(1), shareOn(2)];
11721
+ const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
11722
+ const stops = merged.map(([t], k) => ({
11723
+ t,
11724
+ from: pointsA[k],
11725
+ to: pointsB[k]
11726
+ }));
11727
+ const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
11728
+ return {
11729
+ stops,
11730
+ kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
11731
+ };
11732
+ }
11733
+ function courseOf(mark) {
11734
+ const subpaths = flattenPath(parsePath(mark.outline.d));
11735
+ const points = [];
11736
+ const before = [];
11737
+ let next = 0;
11738
+ let from = 0;
11739
+ const stretch = (to) => {
11740
+ if (!(to > from)) {
11741
+ points.push(mark.path(from));
11742
+ return true;
11743
+ }
11744
+ const subpath = subpaths[next++];
11745
+ if (!subpath) return false;
11746
+ points.push(subpath.start);
11747
+ for (const segment of subpath.segments) {
11748
+ if (segment.kind !== "line") return false;
11749
+ points.push(segment.to);
11750
+ }
11751
+ return true;
11752
+ };
11753
+ for (const [start, end] of mark.gaps ?? []) {
11754
+ if (!stretch(start)) return void 0;
11755
+ before.push(points.length - 1);
11756
+ from = end;
11757
+ }
11758
+ if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
11759
+ const x0 = points[0].x;
11760
+ const span = points[points.length - 1].x - x0;
11761
+ const way = Math.sign(span);
11762
+ for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
11763
+ const shares = points.map((point) => (point.x - x0) / span);
11764
+ return {
11765
+ points,
11766
+ shares,
11767
+ gaps: before.map((i) => [shares[i], shares[i + 1]]),
11768
+ span,
11769
+ way
11770
+ };
11771
+ }
11772
+ function corners(course) {
11773
+ const { points, shares, gaps } = course;
11774
+ if (points.length <= VERTICES) return shares;
11775
+ const columns = VERTICES / 4;
11776
+ const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
11777
+ const kept = gaps.flat();
11778
+ for (let first = 0, i = 1; i <= points.length; i++) {
11779
+ if (i < points.length && column(i) === column(first)) continue;
11780
+ let [low, high] = [first, first];
11781
+ for (let k = first; k < i; k++) {
11782
+ if (points[k].y < points[low].y) low = k;
11783
+ if (points[k].y > points[high].y) high = k;
11784
+ }
11785
+ kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
11786
+ first = i;
11787
+ }
11788
+ return Array.from(new Set(kept));
11789
+ }
11790
+ function placed(course, shares) {
11791
+ const { points, shares: at } = course;
11792
+ let i = 0;
11793
+ return shares.map((s) => {
11794
+ while (i + 2 < points.length && at[i + 1] <= s) i++;
11795
+ const width = at[i + 1] - at[i];
11796
+ return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
11797
+ });
11798
+ }
11799
+ function inside(gaps) {
11800
+ let k = 0;
11801
+ return (s) => {
11802
+ while (k < gaps.length && gaps[k][1] <= s) k++;
11803
+ return k < gaps.length && gaps[k][0] < s;
11804
+ };
11805
+ }
11806
+ function holePairs(from, to, a, b, [shiftA, shiftB], count) {
11807
+ const holesA = holesOf(from.outline, count);
11808
+ const holesB = holesOf(to.outline, count);
11809
+ const both = Math.min(holesA.length, holesB.length);
11810
+ const pairs = holesA.slice(0, both).map((hole, k) => ({
11811
+ from: hole.points,
11812
+ to: holesB[k].points
11813
+ }));
11814
+ const closes = holesA.length > holesB.length;
11815
+ const [ownHoles, otherHoles, other, own, theirs, ownShift, otherShift] = closes ? [
11816
+ holesA,
11817
+ holesB,
11818
+ to,
11819
+ a,
11820
+ b,
11821
+ shiftA,
11822
+ shiftB
11823
+ ] : [
11824
+ holesB,
11825
+ holesA,
11826
+ from,
11827
+ b,
11828
+ a,
11829
+ shiftB,
11830
+ shiftA
11831
+ ];
11832
+ const n = own.length;
11833
+ const outside = own.map((_, i) => [own[(i + ownShift) % n], theirs[(i + otherShift) % n]]);
11834
+ const inner = ownHoles.slice(0, both).map((hole, k) => hole.points.map((p, i) => [p, otherHoles[k].points[i]]));
11835
+ const area = [theirs, ...otherHoles.map((hole) => hole.points)];
11836
+ for (const hole of ownHoles.slice(both)) {
11837
+ const { end, point } = closing(hole, landing(hole, (closes ? from : to).bounds, other, area), outside, inner);
11838
+ const dot = new Array(count).fill(point);
11839
+ pairs.push(closes ? {
11840
+ from: hole.points,
11841
+ to: dot,
11842
+ end
11843
+ } : {
11844
+ from: dot,
11845
+ to: hole.points,
11846
+ end,
11847
+ opens: true
11848
+ });
11849
+ }
11850
+ return pairs;
11851
+ }
11852
+ function closing(hole, there, outside, inner) {
11853
+ let end = .5;
11854
+ while (end > 1 / 16 && !stays(hole, mixed(hole.center, there, end), end, outside, inner)) end /= 2;
11855
+ return {
11856
+ end,
11857
+ point: mixed(hole.center, there, end)
11858
+ };
11859
+ }
11860
+ function stays(hole, point, end, outside, inner) {
11861
+ for (let j = 1; j < CHECKS; j++) {
11862
+ const t = end * j / CHECKS;
11863
+ const at = (path) => mixed(path[0], path[1], t);
11864
+ const area = [outside.map(at), ...inner.map((ring) => ring.map(at))];
11865
+ if (hole.points.some((p) => windingAt(mixed(p, point, j / CHECKS), area) === 0)) return false;
11866
+ }
11867
+ return true;
11868
+ }
11869
+ function holeAt({ from, to, end, opens }, p) {
11870
+ if (end === void 0) return between(from, to, 0, 0, p, true);
11871
+ const q = opens ? (p - (1 - end)) / end : p / end;
11872
+ return (opens ? q <= 0 : q >= 1) ? "" : between(from, to, 0, 0, q, true);
11873
+ }
11874
+ const mixed = (a, b, t) => ({
11875
+ x: mix(a.x, b.x, t),
11876
+ y: mix(a.y, b.y, t)
11877
+ });
11878
+ function landing(hole, own, other, area) {
11879
+ const place = placeIn(hole.center, own, other.bounds);
11880
+ if (depth(place, area) >= hole.size / 4) return place;
11881
+ const { x, y, width, height } = other.bounds;
11882
+ let best = other.center;
11883
+ let deepest = depth(best, area);
11884
+ for (let i = 0; i < GRID; i++) for (let j = 0; j < GRID; j++) {
11885
+ const point = {
11886
+ x: x + width * (i + .5) / GRID,
11887
+ y: y + height * (j + .5) / GRID
11888
+ };
11889
+ const d = depth(point, area);
11890
+ if (d > deepest) [best, deepest] = [point, d];
11891
+ }
11892
+ return best;
11893
+ }
11894
+ function depth(point, area) {
11895
+ if (windingAt(point, area) === 0) return 0;
11896
+ let nearest = Infinity;
11897
+ for (const ring of area) ring.forEach((p, i) => {
11898
+ const q = ring[(i + 1) % ring.length];
11899
+ const dx = q.x - p.x;
11900
+ const dy = q.y - p.y;
11901
+ const u = dx === 0 && dy === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - p.x) * dx + (point.y - p.y) * dy) / (dx * dx + dy * dy)));
11902
+ nearest = Math.min(nearest, Math.hypot(point.x - p.x - u * dx, point.y - p.y - u * dy));
11903
+ });
11904
+ return nearest;
11905
+ }
11906
+ function windingAt(point, area) {
11907
+ let winding = 0;
11908
+ for (const ring of area) ring.forEach((p, i) => {
11909
+ const q = ring[(i + 1) % ring.length];
11910
+ const side = (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);
11911
+ if (p.y <= point.y && q.y > point.y && side > 0) winding++;
11912
+ else if (p.y > point.y && q.y <= point.y && side < 0) winding--;
11913
+ });
11914
+ return winding;
11915
+ }
11916
+ function placeIn(point, own, other) {
11917
+ const fraction = (value, start, size) => size > 0 ? (value - start) / size : .5;
11918
+ return {
11919
+ x: other.x + fraction(point.x, own.x, own.width) * other.width,
11920
+ y: other.y + fraction(point.y, own.y, own.height) * other.height
11921
+ };
11922
+ }
11923
+ function holesOf(outline, count) {
11924
+ const loops = flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
11925
+ if (loops.length < 2) return [];
11926
+ const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
11927
+ let longest = 0;
11928
+ lengths.forEach((length, i) => {
11929
+ if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
11930
+ });
11931
+ return loops.filter((_, i) => i !== longest).map((loop) => {
11932
+ const round = loopOutline([loop]).sample(4 * count);
11933
+ const points = round.filter((_, i) => i % 4 === 0);
11934
+ const box = boundsOf(loop.flatMap(extremes));
11935
+ return {
11936
+ points: [points[0], ...points.slice(1).reverse()],
11937
+ area: Math.abs(areaOf(round)),
11938
+ center: {
11939
+ x: box.x + box.width / 2,
11940
+ y: box.y + box.height / 2
11941
+ },
11942
+ size: Math.max(box.width, box.height) / 2
11943
+ };
11944
+ }).sort((x, y) => y.area - x.area);
11945
+ }
11946
+ function areaOf(points) {
11947
+ let sum = 0;
11948
+ points.forEach((p, i) => {
11949
+ const q = points[(i + 1) % points.length];
11950
+ sum += p.x * q.y - q.x * p.y;
11951
+ });
11952
+ return sum / 2;
11953
+ }
11018
11954
  function crossfade(from, to, layer) {
11019
11955
  const paint = (mark, opacity) => ({
11020
11956
  ...mark.outline.closed ? { fill: "mark" } : {
@@ -11048,13 +11984,10 @@ function crossfade(from, to, layer) {
11048
11984
  function between(a, b, shiftA, shiftB, p, closed) {
11049
11985
  const n = a.length;
11050
11986
  let d = "";
11051
- for (let i = 0; i < n; i++) {
11052
- const from = a[(i + shiftA) % n];
11053
- const to = b[(i + shiftB) % n];
11054
- d += `${i === 0 ? "M" : "L"}${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
11055
- }
11987
+ for (let i = 0; i < n; i++) d += `${i === 0 ? "M" : "L"}${at(a[(i + shiftA) % n], b[(i + shiftB) % n], p)}`;
11056
11988
  return closed ? `${d}Z` : d;
11057
11989
  }
11990
+ const at = (from, to, p) => `${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
11058
11991
  const mix = (x, y, p) => x * (1 - p) + y * p;
11059
11992
  function turn(from, to, points) {
11060
11993
  const quarter = points / 4;
@@ -11572,7 +12505,7 @@ function configure(options) {
11572
12505
  }
11573
12506
  }
11574
12507
  // src/index.ts
11575
- const VERSION = "0.5.0";
12508
+ const VERSION = "0.7.0";
11576
12509
  const env = {
11577
12510
  presets: presetRegistry,
11578
12511
  icons: iconRegistry,
@@ -11602,6 +12535,6 @@ function fromVegaView(view, options) {
11602
12535
  function motionSwitch(target, motion$1 = motion, options) {
11603
12536
  return motionSwitch$1(target, motion$1, options);
11604
12537
  }
11605
- export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, 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 };
12538
+ export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, drawIn, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, 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 };
11606
12539
 
11607
12540
  //# sourceMappingURL=index.js.map