expressive-charts 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -677,7 +677,7 @@ function pathData(segments, closed = false) {
677
677
  }
678
678
  // src/core/geometry/walk.ts
679
679
  const clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
680
- const NONE$1 = Object.freeze([]);
680
+ const NONE$1 = /* @__PURE__ */ Object.freeze([]);
681
681
  function createWalk(segments, gaps = NONE$1) {
682
682
  const first = segments[0];
683
683
  const last = segments[segments.length - 1];
@@ -874,7 +874,7 @@ function checkCount(n, multiple) {
874
874
  }
875
875
  }
876
876
  // src/core/geometry/describe/mark.ts
877
- function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, segments }) {
877
+ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, nearbyLabels, segments }) {
878
878
  return {
879
879
  key,
880
880
  ...series === void 0 ? {} : { series },
@@ -891,6 +891,7 @@ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot
891
891
  center,
892
892
  pivot,
893
893
  ...labelBounds === void 0 ? {} : { labelBounds },
894
+ ...nearbyLabels === void 0 ? {} : { nearbyLabels },
894
895
  ...segments === void 0 ? {} : { segments }
895
896
  };
896
897
  }
@@ -898,15 +899,15 @@ function finite(builder, field, value) {
898
899
  if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
899
900
  return value;
900
901
  }
901
- function labelBoxes$1(builder, boxes) {
902
+ function labelBoxes$1(builder, boxes, field = "labelBounds") {
902
903
  if (!boxes) return boxes;
903
904
  for (let i = 0; i < boxes.length; i++) {
904
905
  const { x, y, width, height } = boxes[i];
905
906
  if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
906
- finite(builder, `labelBounds[${i}].x`, x);
907
- finite(builder, `labelBounds[${i}].y`, y);
908
- size(builder, `labelBounds[${i}].width`, width);
909
- size(builder, `labelBounds[${i}].height`, height);
907
+ finite(builder, `${field}[${i}].x`, x);
908
+ finite(builder, `${field}[${i}].y`, y);
909
+ size(builder, `${field}[${i}].width`, width);
910
+ size(builder, `${field}[${i}].height`, height);
910
911
  }
911
912
  return boxes;
912
913
  }
@@ -945,7 +946,8 @@ function describeArc(spec) {
945
946
  bounds: boundsOf(sides.flat().flatMap(extremes)),
946
947
  center: walk.point(.5),
947
948
  pivot: center,
948
- labelBounds: labelBoxes$1("arc", spec.labelBounds)
949
+ labelBounds: labelBoxes$1("arc", spec.labelBounds),
950
+ nearbyLabels: labelBoxes$1("arc", spec.nearbyLabels, "nearbyLabels")
949
951
  });
950
952
  }
951
953
  // src/core/geometry/describe/bar.ts
@@ -965,6 +967,7 @@ function describeBar(spec) {
965
967
  const radius = size("bar", "radius", spec.radius ?? 0);
966
968
  const gap = size("bar", "gap", spec.gap ?? 0);
967
969
  const labelBounds = labelBoxes$1("bar", spec.labelBounds);
970
+ const nearbyLabels = labelBoxes$1("bar", spec.nearbyLabels, "nearbyLabels");
968
971
  const horizontal = baseline === "left" || baseline === "right";
969
972
  const length = horizontal ? width : height;
970
973
  const thickness = horizontal ? height : width;
@@ -1029,6 +1032,7 @@ function describeBar(spec) {
1029
1032
  height
1030
1033
  },
1031
1034
  labelBounds,
1035
+ nearbyLabels,
1032
1036
  segments
1033
1037
  });
1034
1038
  }
@@ -1083,7 +1087,8 @@ function describeLine(spec) {
1083
1087
  },
1084
1088
  center: walk.point(.5),
1085
1089
  pivot: first,
1086
- labelBounds: labelBoxes$1("line", spec.labelBounds)
1090
+ labelBounds: labelBoxes$1("line", spec.labelBounds),
1091
+ nearbyLabels: labelBoxes$1("line", spec.nearbyLabels, "nearbyLabels")
1087
1092
  });
1088
1093
  }
1089
1094
  function gapsAt(breaks, segments) {
@@ -1131,7 +1136,8 @@ function describePoint(spec) {
1131
1136
  },
1132
1137
  center,
1133
1138
  pivot: center,
1134
- labelBounds: labelBoxes$1("point", spec.labelBounds)
1139
+ labelBounds: labelBoxes$1("point", spec.labelBounds),
1140
+ nearbyLabels: labelBoxes$1("point", spec.nearbyLabels, "nearbyLabels")
1135
1141
  });
1136
1142
  }
1137
1143
  // src/core/geometry/flatten.ts
@@ -1208,9 +1214,8 @@ function flattenPath(commands) {
1208
1214
  return subpaths;
1209
1215
  }
1210
1216
  function bezier(...p) {
1211
- const bend = (a, b, c) => Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
1212
1217
  const cubic = p.length === 4;
1213
- const n = pieces(1, cubic ? 6 * Math.max(bend(p[0], p[1], p[2]), bend(p[1], p[2], p[3])) : 2 * bend(p[0], p[1], p[2]));
1218
+ const n = cubic ? cubicPieces(p[0], p[1], p[2], p[3]) : pieces(1, 2 * bend(p[0], p[1], p[2]));
1214
1219
  const points = [p[0]];
1215
1220
  for (let k = 1; k < n; k++) {
1216
1221
  const t = k / n;
@@ -1234,6 +1239,12 @@ function bezier(...p) {
1234
1239
  points.push(p[p.length - 1]);
1235
1240
  return points;
1236
1241
  }
1242
+ function cubicPieces(p0, p1, p2, p3) {
1243
+ return pieces(1, 6 * Math.max(bend(p0, p1, p2), bend(p1, p2, p3)));
1244
+ }
1245
+ function bend(a, b, c) {
1246
+ return Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
1247
+ }
1237
1248
  function pieces(span, second) {
1238
1249
  const n = Math.ceil(span * Math.sqrt(second / (8 * FLAT)));
1239
1250
  return Number.isFinite(n) ? Math.min(MAX_PIECES, Math.max(1, n)) : MAX_PIECES;
@@ -1682,7 +1693,8 @@ function describeShape(spec) {
1682
1693
  length
1683
1694
  ].every(Number.isFinite)) throw new RangeError(`describe.shape: d must stay finite${m ? " once moved by matrix" : ""}, got ${show$2(d)}.`);
1684
1695
  const labelBounds = labelBoxes$1("shape", spec.labelBounds);
1685
- if (subpaths.every(closes) && length > 0) {
1696
+ const nearbyLabels = labelBoxes$1("shape", spec.nearbyLabels, "nearbyLabels");
1697
+ if (subpaths.every(closes$1) && length > 0) {
1686
1698
  const center = {
1687
1699
  x: box.x + box.width / 2,
1688
1700
  y: box.y + box.height / 2
@@ -1696,7 +1708,8 @@ function describeShape(spec) {
1696
1708
  bounds: box,
1697
1709
  center,
1698
1710
  pivot: center,
1699
- labelBounds
1711
+ labelBounds,
1712
+ nearbyLabels
1700
1713
  });
1701
1714
  }
1702
1715
  const { segments, gaps } = joined(subpaths);
@@ -1716,10 +1729,11 @@ function describeShape(spec) {
1716
1729
  },
1717
1730
  center: walk.point(.5),
1718
1731
  pivot: walk.start,
1719
- labelBounds
1732
+ labelBounds,
1733
+ nearbyLabels
1720
1734
  });
1721
1735
  }
1722
- const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
1736
+ const closes$1 = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
1723
1737
  function joined(subpaths) {
1724
1738
  const segments = [];
1725
1739
  const across = [];
@@ -1916,7 +1930,7 @@ function offset(point, angle, distance) {
1916
1930
  // src/core/geometry/samples.ts
1917
1931
  const MAX_GRID = 4096;
1918
1932
  const REFINE = 48;
1919
- const GOLDEN = (Math.sqrt(5) - 1) / 2;
1933
+ const GOLDEN = /* @__PURE__ */ (() => (Math.sqrt(5) - 1) / 2)();
1920
1934
  function samplesAlong(mark, points) {
1921
1935
  if (typeof mark !== "object" || mark === null || typeof mark.path !== "function" || !Number.isFinite(mark.length)) throw new TypeError("samplesAlong needs a MarkGeometry, as describe builds it.");
1922
1936
  if (!Array.isArray(points)) throw new TypeError("samplesAlong needs an array of points { x, y, value, at? }.");
@@ -1940,9 +1954,9 @@ function samplesAlong(mark, points) {
1940
1954
  ...p.at === void 0 ? {} : { at: p.at }
1941
1955
  }
1942
1956
  })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
1943
- return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
1957
+ return mark.gaps && mark.gaps.length > 0 ? gapped$1(samples, mark.gaps) : samples;
1944
1958
  }
1945
- function gapped(samples, gaps) {
1959
+ function gapped$1(samples, gaps) {
1946
1960
  const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
1947
1961
  let next = 0;
1948
1962
  return samples.map((sample, k) => {
@@ -2059,6 +2073,22 @@ function mergeFields(current, next) {
2059
2073
  else result[field] = value;
2060
2074
  return result;
2061
2075
  }
2076
+ // src/core/text-box.ts
2077
+ const TEXT_SIZE = 12.5;
2078
+ const AVERAGE_WIDTH = .6;
2079
+ const ASCENT$1 = 1.05;
2080
+ const SIDE = .16;
2081
+ function boxAround(at, anchor, width, size) {
2082
+ return {
2083
+ x: (anchor === "end" ? at.x - width : anchor === "middle" ? at.x - width / 2 : at.x) - SIDE * size,
2084
+ y: at.y - ASCENT$1 * size,
2085
+ width: width + 2 * SIDE * size,
2086
+ height: 1.3 * size
2087
+ };
2088
+ }
2089
+ function estimatedBox(content, style) {
2090
+ return boxAround(style.at, style.anchor, content.length * TEXT_SIZE * AVERAGE_WIDTH, TEXT_SIZE);
2091
+ }
2062
2092
  // src/core/runner.ts
2063
2093
  function runScope(options) {
2064
2094
  const { clock, motion, layer, mark } = options;
@@ -2073,6 +2103,7 @@ function runScope(options) {
2073
2103
  icons: options.icons,
2074
2104
  batch: options.batch,
2075
2105
  ...options.previous ? { previous: options.previous } : {},
2106
+ ...options.texts ? { texts: options.texts } : {},
2076
2107
  tween(tweenOptions) {
2077
2108
  const own = tweenOptions.signal;
2078
2109
  const running = tween({
@@ -2113,6 +2144,8 @@ const SLOTS = [
2113
2144
  "exit",
2114
2145
  "hover"
2115
2146
  ];
2147
+ const byOrder = (a, b) => a.order - b.order;
2148
+ const sameBox = (a, b) => a === b || a !== void 0 && b !== void 0 && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
2116
2149
  const NO_ICONS$1 = { get: () => void 0 };
2117
2150
  const INERT$1 = {
2118
2151
  place() {},
@@ -2130,6 +2163,10 @@ function createRunner(options) {
2130
2163
  let transitioning = false;
2131
2164
  let destroyed = false;
2132
2165
  let order = 0;
2166
+ const box = (content, style) => surface.box ? surface.box(content, style) : estimatedBox(content, style);
2167
+ const texts = /* @__PURE__ */ new Map();
2168
+ let holds = 0;
2169
+ let flushing = false;
2133
2170
  const unsubscribe = motion$3.subscribe(() => {
2134
2171
  if (motion$3.mode === "off") endRunning();
2135
2172
  });
@@ -2181,7 +2218,14 @@ function createRunner(options) {
2181
2218
  batch,
2182
2219
  previous,
2183
2220
  layer: runLayer(entry.key, slot, () => run.order, () => run.state !== "cleared"),
2184
- mark: runMark(() => run)
2221
+ mark: runMark(() => run),
2222
+ texts: {
2223
+ box,
2224
+ held: () => [...texts].flatMap(([other, held]) => held.box && other.order < run.order ? [held.box] : []),
2225
+ hold(next) {
2226
+ if (run.state !== "cleared") hold(run, next);
2227
+ }
2228
+ }
2185
2229
  })
2186
2230
  };
2187
2231
  entry.runs.set(slot, run);
@@ -2228,8 +2272,44 @@ function createRunner(options) {
2228
2272
  report(error);
2229
2273
  }
2230
2274
  run.scope.clear();
2275
+ hold(run, void 0);
2231
2276
  release(run);
2232
2277
  }
2278
+ function tell(run, mark) {
2279
+ try {
2280
+ run.scope.change(mark, latestData(run.entry, run));
2281
+ } catch (error) {
2282
+ report(error);
2283
+ clearRun(run);
2284
+ }
2285
+ }
2286
+ function hold(run, next) {
2287
+ let held = texts.get(run);
2288
+ if (!held) {
2289
+ if (!next) return;
2290
+ texts.set(run, held = {
2291
+ box: void 0,
2292
+ placed: 0,
2293
+ moved: 0
2294
+ });
2295
+ }
2296
+ held.placed = ++holds;
2297
+ if (sameBox(held.box, next)) return;
2298
+ held.box = next;
2299
+ held.moved = holds;
2300
+ if (flushing) return;
2301
+ flushing = true;
2302
+ queueMicrotask(flush);
2303
+ }
2304
+ function flush() {
2305
+ let moved = 0;
2306
+ for (const [run, held] of [...texts].sort(([a], [b]) => byOrder(a, b))) {
2307
+ if (held.box && held.placed < moved) tell(run, run.entry.mark);
2308
+ if (!held.box) texts.delete(run);
2309
+ moved = Math.max(moved, held.moved);
2310
+ }
2311
+ flushing = false;
2312
+ }
2233
2313
  function runLayer(key, slot, order, live) {
2234
2314
  let group;
2235
2315
  const target = () => live() ? group ?? (group = surface.group(key, slot, order())) : void 0;
@@ -2408,15 +2488,7 @@ function createRunner(options) {
2408
2488
  entry.data = data;
2409
2489
  if (!transitioning) entry.resting = data;
2410
2490
  }
2411
- for (const run of [...entry.runs.values()]) {
2412
- if (run.state === "cleared") continue;
2413
- try {
2414
- run.scope.change(mark, latestData(entry, run));
2415
- } catch (error) {
2416
- report(error);
2417
- clearRun(run);
2418
- }
2419
- }
2491
+ for (const run of [...entry.runs.values()].sort(byOrder)) if (run.state !== "cleared") tell(run, mark);
2420
2492
  },
2421
2493
  interrupt() {
2422
2494
  if (destroyed) return;
@@ -2579,16 +2651,8 @@ function linear$1(value) {
2579
2651
  return rounded === 0 ? "0" : String(rounded);
2580
2652
  }
2581
2653
  // src/charts/render/text.ts
2582
- const ASCENT$1 = 1.05;
2583
- const SIDE = .16;
2584
2654
  function textBox(placement, measure, className, size) {
2585
- const width = measure(placement.text.replace(/\d/g, "0"), className, size);
2586
- return {
2587
- x: (placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2) - SIDE * size,
2588
- y: placement.y - ASCENT$1 * size,
2589
- width: width + 2 * SIDE * size,
2590
- height: 1.3 * size
2591
- };
2655
+ return boxAround(placement, placement.anchor, measure(placement.text.replace(/\d/g, "0"), className, size), size);
2592
2656
  }
2593
2657
  function placeText(element, placement) {
2594
2658
  setAttributes(element, {
@@ -2598,7 +2662,6 @@ function placeText(element, placement) {
2598
2662
  });
2599
2663
  if (element.textContent !== placement.text) element.textContent = placement.text;
2600
2664
  }
2601
- const AVERAGE_WIDTH = .6;
2602
2665
  function textMeasure(svg) {
2603
2666
  const cache = /* @__PURE__ */ new Map();
2604
2667
  const measure = (text, className, size) => {
@@ -2990,7 +3053,8 @@ function verticalFrame(input, rows, domain, _values, ticks) {
2990
3053
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
2991
3054
  const { positive, negative } = reach(input, rows);
2992
3055
  const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
2993
- const bottom = AXIS$1 + (domain.lo < 0 ? 18.5 : 0) + negative;
3056
+ const values = domain.lo < 0 ? 18.5 : 0;
3057
+ const bottom = AXIS$1 + values + negative;
2994
3058
  const left = tickWidth + 8 + 2;
2995
3059
  const plot = {
2996
3060
  x: left,
@@ -3007,7 +3071,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
3007
3071
  hi: domain.hi,
3008
3072
  from: base,
3009
3073
  extent: -plot.height,
3010
- label: base + 18
3074
+ label: base + values + 18
3011
3075
  },
3012
3076
  bands: {
3013
3077
  start: plot.x,
@@ -3135,7 +3199,7 @@ const COLOR_TOKENS = [
3135
3199
  "focus",
3136
3200
  "negative"
3137
3201
  ];
3138
- const TOKENS = Object.fromEntries(COLOR_TOKENS.map((name) => [name, themes.light[name]]));
3202
+ const TOKENS = /* @__PURE__ */ Object.fromEntries(/* @__PURE__ */ COLOR_TOKENS.map((name) => [name, themes.light[name]]));
3139
3203
  function seriesColors(slot) {
3140
3204
  const n = (Math.max(1, Math.floor(slot)) - 1) % 8 + 1;
3141
3205
  const [color, strong] = themes.light.series[n - 1];
@@ -3171,8 +3235,7 @@ function declarations(theme, indent) {
3171
3235
  theme.series.forEach(([color, strong], i) => lines.push(`--ec-series-${i + 1}: ${color};`, `--ec-series-${i + 1}-strong: ${strong};`));
3172
3236
  return lines.map((line) => indent + line).join("\n");
3173
3237
  }
3174
- const STYLES = `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
3175
- ${`:where(:root, [data-theme="light"]) {
3238
+ const TOKEN_RULES = /* @__PURE__ */ (() => `:where(:root, [data-theme="light"]) {
3176
3239
  ${declarations(themes.light, " ")}
3177
3240
  }
3178
3241
  @media (prefers-color-scheme: dark) {
@@ -3182,7 +3245,9 @@ ${declarations(themes.dark, " ")}
3182
3245
  }
3183
3246
  :where([data-theme="dark"]) {
3184
3247
  ${declarations(themes.dark, " ")}
3185
- }`}
3248
+ }`)();
3249
+ const STYLES = /* @__PURE__ */ (() => `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
3250
+ ${TOKEN_RULES}
3186
3251
  :where(.ec-chart) { display: block; max-width: 100%; height: auto; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
3187
3252
  :where(.ec-chart text) { font-variant-numeric: tabular-nums; }
3188
3253
  :where(.ec-chart .ec-gridline) { stroke: var(--ec-grid, ${TOKENS.grid}); stroke-width: 1; }
@@ -3201,18 +3266,19 @@ ${declarations(themes.dark, " ")}
3201
3266
  :where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
3202
3267
  :where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
3203
3268
  :where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
3204
- :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
3269
+ :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
3205
3270
  :where(.ec-chart .ec-dot) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; opacity: 0; transition: opacity var(--ec-hover-duration, 100ms) ease-out, fill var(--ec-hover-duration, 100ms) ease-out; }
3206
3271
  :where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
3207
3272
  :where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
3208
3273
  :where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
3209
- :where(.ec-chart .ec-column:focus) { outline: none; }
3274
+ :where(.ec-chart .ec-column:focus, .ec-chart .ec-stop:focus) { outline: none; }
3210
3275
  :where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
3211
3276
  :where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
3212
3277
  :where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
3213
3278
  :where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
3214
3279
  :where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
3215
3280
  :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
3281
+ :where(.ec-chart.ec-hovering .ec-line:not(.ec-hot-line) > .ec-body > *, .ec-chart.ec-hovering .ec-alone:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
3216
3282
  :where(.ec-hovering .ec-run:not(.ec-hot) > .ec-follow) { opacity: var(--ec-dim-opacity, 0.3); }
3217
3283
  :where(.ec-follow) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
3218
3284
  :where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
@@ -3258,7 +3324,7 @@ ${declarations(themes.dark, " ")}
3258
3324
  :where(.ec-table thead th) { color: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12px; font-weight: 600; }
3259
3325
  :where(.ec-table .ec-num) { text-align: right; }
3260
3326
  :where(.ec-table-caption, .ec-visually-hidden) { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
3261
- `;
3327
+ `)();
3262
3328
  const MARKER = "data-expressive-charts";
3263
3329
  const styleOptions = {};
3264
3330
  function injectStyles(doc) {
@@ -3804,6 +3870,7 @@ function styleText(element, style) {
3804
3870
  // src/charts/render/surface.ts
3805
3871
  function svgSurface(options) {
3806
3872
  const { overlay } = options;
3873
+ const measure = options.measure ?? textMeasure(overlay);
3807
3874
  const orders = /* @__PURE__ */ new WeakMap();
3808
3875
  const groups = /* @__PURE__ */ new Map();
3809
3876
  const hidden = /* @__PURE__ */ new Set();
@@ -3839,6 +3906,12 @@ function svgSurface(options) {
3839
3906
  }
3840
3907
  };
3841
3908
  },
3909
+ box: (text, { at, anchor = "start" }) => textBox({
3910
+ x: at.x,
3911
+ y: at.y,
3912
+ anchor,
3913
+ text
3914
+ }, measure, "ec-text", TEXT_SIZE),
3842
3915
  mark(key) {
3843
3916
  const handle = options.mark(key);
3844
3917
  return {
@@ -3934,13 +4007,13 @@ function decimals(value) {
3934
4007
  const point = text.indexOf(".");
3935
4008
  return point < 0 ? 0 : Math.min(6, text.length - point - 1);
3936
4009
  }
3937
- function round$4(value, digits) {
4010
+ function round$5(value, digits) {
3938
4011
  const factor = 10 ** digits;
3939
4012
  const rounded = Math.round(value * factor) / factor;
3940
4013
  return rounded === 0 ? 0 : rounded;
3941
4014
  }
3942
4015
  function percent(share) {
3943
- return `${round$4(share * 100, 0)}%`;
4016
+ return `${round$5(share * 100, 0)}%`;
3944
4017
  }
3945
4018
  // src/charts/interaction.ts
3946
4019
  function pointerHover(svg, options) {
@@ -3950,7 +4023,9 @@ function pointerHover(svg, options) {
3950
4023
  let held;
3951
4024
  let watcher;
3952
4025
  let still;
4026
+ let under;
3953
4027
  const enter = (target, source) => {
4028
+ under = target?.key;
3954
4029
  if (target?.key === current) return;
3955
4030
  leave();
3956
4031
  if (!target) return;
@@ -3975,8 +4050,15 @@ function pointerHover(svg, options) {
3975
4050
  const arrive = (element, x, y) => {
3976
4051
  const tip = tooltipHolding(element);
3977
4052
  if (tip) hold(tip, x, y);
3978
- else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
4053
+ else enter(element && svg.contains(element) ? options.find(element, {
4054
+ x,
4055
+ y
4056
+ }) : void 0, "pointer");
3979
4057
  };
4058
+ const at = (event) => options.find(event.target, {
4059
+ x: event.clientX,
4060
+ y: event.clientY
4061
+ });
3980
4062
  const hold = (tip, x, y) => {
3981
4063
  enter({ key: tip.key }, "pointer");
3982
4064
  const element = tip.element;
@@ -4046,7 +4128,8 @@ function pointerHover(svg, options) {
4046
4128
  const over = (event) => {
4047
4129
  if (event.pointerType === "touch" || resting(event)) return;
4048
4130
  letGo();
4049
- enter(options.find(event.target), "pointer");
4131
+ const target = at(event);
4132
+ if (!options.moves?.() || target?.key !== under) enter(target, "pointer");
4050
4133
  };
4051
4134
  const out = (event) => {
4052
4135
  if (event.pointerType === "touch") return;
@@ -4054,13 +4137,17 @@ function pointerHover(svg, options) {
4054
4137
  arrive(landing(event), event.clientX, event.clientY);
4055
4138
  };
4056
4139
  const move = (event) => {
4057
- if (event.pointerType !== "touch") resting(event);
4140
+ if (event.pointerType === "touch" || resting(event) || !options.moves?.()) return;
4141
+ const target = at(event);
4142
+ if (target?.key === under) return;
4143
+ letGo();
4144
+ enter(target, "pointer");
4058
4145
  };
4059
4146
  const down = (event) => {
4060
4147
  lastPointer = event.pointerType;
4061
4148
  };
4062
4149
  const click = (event) => {
4063
- if (lastPointer === "touch") enter(options.find(event.target), "touch");
4150
+ if (lastPointer === "touch") enter(at(event), "touch");
4064
4151
  };
4065
4152
  const elsewhere = (event) => {
4066
4153
  if (current === void 0 || event.pointerType !== "touch") return;
@@ -4168,15 +4255,19 @@ function keyboardFocus(svg, options) {
4168
4255
  if (key === void 0 || event.altKey || event.ctrlKey || event.metaKey) return;
4169
4256
  const keys = options.order();
4170
4257
  const index = keys.indexOf(key);
4258
+ const moved = (press, fallback) => {
4259
+ const to = options.move?.(key, press);
4260
+ return to !== void 0 && keys.includes(to) ? to : fallback;
4261
+ };
4171
4262
  let next;
4172
4263
  switch (event.key) {
4173
4264
  case "ArrowDown":
4174
4265
  case "ArrowRight":
4175
- next = keys[Math.min(keys.length - 1, index + 1)];
4266
+ next = moved(event.key, keys[Math.min(keys.length - 1, index + 1)]);
4176
4267
  break;
4177
4268
  case "ArrowUp":
4178
4269
  case "ArrowLeft":
4179
- next = keys[Math.max(0, index - 1)];
4270
+ next = moved(event.key, keys[Math.max(0, index - 1)]);
4180
4271
  break;
4181
4272
  case "PageDown":
4182
4273
  case "PageUp": {
@@ -4186,10 +4277,10 @@ function keyboardFocus(svg, options) {
4186
4277
  break;
4187
4278
  }
4188
4279
  case "Home":
4189
- next = keys[0];
4280
+ next = moved(event.key, keys[0]);
4190
4281
  break;
4191
4282
  case "End":
4192
- next = keys[keys.length - 1];
4283
+ next = moved(event.key, keys[keys.length - 1]);
4193
4284
  break;
4194
4285
  case "Escape":
4195
4286
  if (options.escape(key)) event.preventDefault();
@@ -4253,6 +4344,28 @@ function keyboardFocus(svg, options) {
4253
4344
  for (const key of gone) setTabIndex(key, void 0);
4254
4345
  last = keys;
4255
4346
  },
4347
+ retarget(to) {
4348
+ listen();
4349
+ const keys = options.order();
4350
+ const live = new Set(keys);
4351
+ const active = on?.scope.activeElement ?? null;
4352
+ const had = focused?.element === active ? focused.key : last.find((key) => options.element(key) === active);
4353
+ const from = had ?? tabStop;
4354
+ const moved = from === void 0 ? void 0 : to(from);
4355
+ tabStop = moved !== void 0 && live.has(moved) ? moved : keys[0];
4356
+ applyTabIndex(keys);
4357
+ if (had !== void 0) {
4358
+ current = tabStop;
4359
+ if (tabStop !== void 0) options.element(tabStop)?.focus();
4360
+ else {
4361
+ active.blur();
4362
+ focused = void 0;
4363
+ }
4364
+ }
4365
+ for (const key of last) if (!live.has(key)) setTabIndex(key, void 0);
4366
+ last = keys;
4367
+ return had === void 0 ? void 0 : current;
4368
+ },
4256
4369
  destroy() {
4257
4370
  current = void 0;
4258
4371
  focused = void 0;
@@ -4361,6 +4474,7 @@ function chartHover(options) {
4361
4474
  const within = (target, key) => key === target || options.live(target) && marksOf(target).includes(key);
4362
4475
  const interaction = pointerHover(svg, {
4363
4476
  find: options.find,
4477
+ moves: () => options.moves?.() ?? false,
4364
4478
  hover(target, source) {
4365
4479
  if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
4366
4480
  endHover();
@@ -4378,6 +4492,7 @@ function chartHover(options) {
4378
4492
  find: (eventTarget) => options.find(eventTarget)?.key,
4379
4493
  order: options.order,
4380
4494
  page: (key, by) => options.page?.(key, by),
4495
+ move: (key, press) => options.move?.(key, press),
4381
4496
  element: options.element,
4382
4497
  focus(key, visible) {
4383
4498
  ringKey = visible ? key : void 0;
@@ -4497,6 +4612,14 @@ function chartHover(options) {
4497
4612
  });
4498
4613
  },
4499
4614
  sync: () => keyboard.sync(),
4615
+ retarget(to) {
4616
+ const key = keyboard.retarget(to);
4617
+ if (ringKey !== void 0) {
4618
+ ringKey = key;
4619
+ options.ring(ringKey);
4620
+ }
4621
+ linked?.shown();
4622
+ },
4500
4623
  focus(key) {
4501
4624
  if (options.live(key)) keyboard.focus(key);
4502
4625
  },
@@ -5002,8 +5125,9 @@ function geometryChanged$1(from, to) {
5002
5125
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
5003
5126
  }
5004
5127
  function labelsMoved(from, to) {
5005
- const a = from.labelBounds;
5006
- const b = to.labelBounds;
5128
+ return boxesMoved(from.labelBounds, to.labelBounds) || boxesMoved(from.nearbyLabels, to.nearbyLabels);
5129
+ }
5130
+ function boxesMoved(a, b) {
5007
5131
  if (a === b) return false;
5008
5132
  if (!a || !b || a.length !== b.length) return true;
5009
5133
  return a.some((box, i) => box.x !== b[i].x || box.y !== b[i].y || box.width !== b[i].width || box.height !== b[i].height);
@@ -5119,7 +5243,7 @@ function chartTooltip(svg, options) {
5119
5243
  const option = options.option();
5120
5244
  const known = texts.get(row);
5121
5245
  if (known && known.option === option) return known.content;
5122
- const content = text(option, row.datum, summary);
5246
+ const content = text(option, row.datum, summary, row.series);
5123
5247
  texts.set(row, {
5124
5248
  option,
5125
5249
  content
@@ -5179,7 +5303,7 @@ function chartTooltip(svg, options) {
5179
5303
  top: dy + near.top,
5180
5304
  bottom: dy + near.bottom
5181
5305
  };
5182
- shape = span(bridge, {
5306
+ shape = span$1(bridge, {
5183
5307
  left,
5184
5308
  top,
5185
5309
  ...size
@@ -5278,7 +5402,7 @@ function inside$1({ top, bottom, upper, lower }, x, y) {
5278
5402
  const t = (y - top) / (bottom - top);
5279
5403
  return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
5280
5404
  }
5281
- function span(bridge, box, mark, side) {
5405
+ function span$1(bridge, box, mark, side) {
5282
5406
  bridge.hidden = mark === void 0;
5283
5407
  if (!mark) return void 0;
5284
5408
  const edge = {
@@ -5288,13 +5412,13 @@ function span(bridge, box, mark, side) {
5288
5412
  const [upper, lower, top, bottom] = side === "above" ? [
5289
5413
  edge,
5290
5414
  mark,
5291
- box.top + box.height,
5415
+ box.top + box.height - OVERLAP,
5292
5416
  Math.round(mark.top + OVERLAP)
5293
5417
  ] : [
5294
5418
  mark,
5295
5419
  edge,
5296
5420
  Math.round(mark.bottom - OVERLAP),
5297
- box.top
5421
+ box.top + OVERLAP
5298
5422
  ];
5299
5423
  const left = Math.round(Math.min(upper.left, lower.left));
5300
5424
  const width = Math.round(Math.max(upper.right, lower.right)) - left;
@@ -5316,11 +5440,11 @@ function span(bridge, box, mark, side) {
5316
5440
  lower: round(lower)
5317
5441
  };
5318
5442
  }
5319
- function text(option, datum, summary) {
5443
+ function text(option, datum, summary, series) {
5320
5444
  if (option === false) return void 0;
5321
5445
  if (typeof option !== "function") return summary();
5322
5446
  try {
5323
- const result = option(datum);
5447
+ const result = series === void 0 ? option(datum) : option(datum, { series });
5324
5448
  return result === void 0 || result === null || result === "" ? void 0 : String(result);
5325
5449
  } catch (error) {
5326
5450
  report(error);
@@ -5419,6 +5543,7 @@ function barChart$1(target, options, env) {
5419
5543
  const find = (key) => records.get(key) ?? leaving.get(key);
5420
5544
  const surface = svgSurface({
5421
5545
  overlay,
5546
+ measure,
5422
5547
  mark: (key) => ({
5423
5548
  set: (style) => {
5424
5549
  find(key)?.handle.set(style);
@@ -5671,7 +5796,7 @@ function barChart$1(target, options, env) {
5671
5796
  value: now[series] ?? 0
5672
5797
  }));
5673
5798
  const total = values.reduce((sum, v) => sum + v.value, 0);
5674
- const text = record.count === void 0 ? row.value.text : format(current)(round$4(total, record.count));
5799
+ const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
5675
5800
  return placeRow(frame, {
5676
5801
  key: row.key,
5677
5802
  datum: row.datum,
@@ -5976,6 +6101,14 @@ function barChart$1(target, options, env) {
5976
6101
  if (!destroyed) hover.leave();
5977
6102
  },
5978
6103
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.shown.label, record.label), ...chartLabel(record.key, "value", record.shown.value, record.value)]),
6104
+ paintOf(key) {
6105
+ const record = records.get(key);
6106
+ const first = record?.shown.geometry.segments?.[0];
6107
+ return record && {
6108
+ color: byCategory(current) ? key : first?.series ?? first?.key ?? key,
6109
+ drawn: true
6110
+ };
6111
+ },
5979
6112
  destroy() {
5980
6113
  if (destroyed) return;
5981
6114
  destroyed = true;
@@ -6125,7 +6258,7 @@ function layoutDonut(input) {
6125
6258
  return {
6126
6259
  frame,
6127
6260
  total,
6128
- slices: states.map((state, i) => placeSlice(frame, state, labels[i], input.measure)),
6261
+ slices: placeSlices(frame, states, labels, input.measure),
6129
6262
  labels,
6130
6263
  centerText,
6131
6264
  center: placeCenter(frame, centerText, input.measure)
@@ -6140,7 +6273,11 @@ function joinedStarts(values) {
6140
6273
  return start;
6141
6274
  });
6142
6275
  }
6143
- function placeSlice(frame, state, label, measure) {
6276
+ function placeSlices(frame, states, labels, measure) {
6277
+ const boxes = labels.map((label) => label ? labelBoxes(label, measure) : []);
6278
+ return states.map((state, i) => placeSlice(frame, state, labels[i], measure, boxes.flatMap((box, j) => j === i ? [] : box)));
6279
+ }
6280
+ function placeSlice(frame, state, label, measure, nearby) {
6144
6281
  const geometry = describeArc({
6145
6282
  key: state.key,
6146
6283
  series: state.series,
@@ -6150,7 +6287,8 @@ function placeSlice(frame, state, label, measure) {
6150
6287
  outer: frame.outer,
6151
6288
  start: state.start,
6152
6289
  end: state.end,
6153
- labelBounds: label && measure ? labelBoxes(label, measure) : []
6290
+ labelBounds: label && measure ? labelBoxes(label, measure) : [],
6291
+ ...nearby ? { nearbyLabels: nearby } : {}
6154
6292
  });
6155
6293
  return {
6156
6294
  ...state,
@@ -6353,6 +6491,7 @@ function donutChart$1(target, options, env) {
6353
6491
  const find = (key) => records.get(key) ?? leaving.get(key);
6354
6492
  const surface = svgSurface({
6355
6493
  overlay: runs,
6494
+ measure,
6356
6495
  mark: (key) => ({
6357
6496
  set: (style) => {
6358
6497
  find(key)?.handle.set(style);
@@ -6641,9 +6780,10 @@ function donutChart$1(target, options, env) {
6641
6780
  };
6642
6781
  });
6643
6782
  const labels = placeLabels(f, now.map(({ state }) => state), measure);
6644
- return now.map(({ record, state }, i) => ({
6783
+ const slices = placeSlices(f, now.map(({ state }) => state), labels, measure);
6784
+ return now.map(({ record }, i) => ({
6645
6785
  record,
6646
- slice: placeSlice(f, state, labels[i], measure),
6786
+ slice: slices[i],
6647
6787
  label: labels[i]
6648
6788
  }));
6649
6789
  }
@@ -6655,7 +6795,7 @@ function donutChart$1(target, options, env) {
6655
6795
  const slices = currentSlices(f);
6656
6796
  for (const { record, slice, label } of slices) show(record, slice, label);
6657
6797
  const total = slices.reduce((sum, { slice }) => sum + slice.value, 0);
6658
- drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$4(total, count)), measure));
6798
+ drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$5(total, count)), measure));
6659
6799
  }
6660
6800
  function counting(total) {
6661
6801
  if (counted?.total !== total) counted = {
@@ -6929,6 +7069,10 @@ function donutChart$1(target, options, env) {
6929
7069
  if (!destroyed) hover.leave();
6930
7070
  },
6931
7071
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.drawnLabel?.category, record.label), ...chartLabel(record.key, "value", record.drawnLabel?.share, record.share)]),
7072
+ paintOf: (key) => records.has(key) ? {
7073
+ color: key,
7074
+ drawn: true
7075
+ } : void 0,
6932
7076
  destroy() {
6933
7077
  if (destroyed) return;
6934
7078
  destroyed = true;
@@ -7036,6 +7180,165 @@ function mergeRing(shown, next) {
7036
7180
  });
7037
7181
  return out;
7038
7182
  }
7183
+ // src/charts/curve.ts
7184
+ const CURVES = ["linear", "monotone"];
7185
+ function bendOf(curve) {
7186
+ return curve === "monotone" ? 1 : 0;
7187
+ }
7188
+ function lineCurve(xs, values, amount, scales, presence) {
7189
+ const knotOf = new Int32Array(xs.length).fill(-1);
7190
+ const kx = [];
7191
+ const kv = [];
7192
+ const run = [];
7193
+ const kp = [];
7194
+ let runs = 0;
7195
+ let joined = false;
7196
+ for (let i = 0; i < xs.length; i++) {
7197
+ const value = values[i];
7198
+ if (value === void 0) {
7199
+ joined = false;
7200
+ continue;
7201
+ }
7202
+ const k = kx.length - 1;
7203
+ if (joined && xs[i] === kx[k] && value === kv[k]) {
7204
+ knotOf[i] = k;
7205
+ kp[k] = Math.max(kp[k], presence?.[i] ?? 1);
7206
+ continue;
7207
+ }
7208
+ if (!joined || xs[i] === kx[k]) runs++;
7209
+ kx.push(xs[i]);
7210
+ kv.push(value);
7211
+ run.push(runs);
7212
+ kp.push(presence?.[i] ?? 1);
7213
+ knotOf[i] = k + 1;
7214
+ joined = true;
7215
+ }
7216
+ const tangents = amount > 0 ? new Float64Array(kx.length) : void 0;
7217
+ if (tangents) for (let start = 0; start < kx.length;) {
7218
+ let end = start + 1;
7219
+ while (end < kx.length && run[end] === run[start]) end++;
7220
+ monotoneTangents(kx, kv, start, end, tangents);
7221
+ if (presence) fade(kx, kv, kp, start, end, tangents);
7222
+ start = end;
7223
+ }
7224
+ const piece = (from, to) => {
7225
+ const k = knotOf[from];
7226
+ if (k < 0 || knotOf[to] !== k + 1 || run[k + 1] !== run[k]) return void 0;
7227
+ const h = kx[k + 1] - kx[k];
7228
+ const v0 = kv[k];
7229
+ const v1 = kv[k + 1];
7230
+ const slope = (v1 - v0) / h;
7231
+ const [lo, hi] = slope < 0 ? [3 * slope, 0] : [0, 3 * slope];
7232
+ const ease = (tangent) => Math.min(hi, Math.max(lo, amount === 1 ? tangent : slope + amount * (tangent - slope)));
7233
+ const a = tangents ? ease(tangents[k]) : slope;
7234
+ const b = tangents ? ease(tangents[k + 1]) : slope;
7235
+ return [
7236
+ v0,
7237
+ v0 + h * a / 3,
7238
+ v1 - h * b / 3,
7239
+ v1,
7240
+ k
7241
+ ];
7242
+ };
7243
+ return {
7244
+ between(from, to, through = Infinity) {
7245
+ const p = piece(from, to);
7246
+ if (!p || !tangents) return [];
7247
+ const [v0, c1, c2, v1, k] = p;
7248
+ const x0 = kx[k];
7249
+ const h = kx[k + 1] - x0;
7250
+ const left = scales.x(x0);
7251
+ const right = scales.x(kx[k + 1]);
7252
+ const n = Math.min(cubicPieces({
7253
+ x: left,
7254
+ y: scales.y(v0)
7255
+ }, {
7256
+ x: left + (right - left) / 3,
7257
+ y: scales.y(c1)
7258
+ }, {
7259
+ x: right - (right - left) / 3,
7260
+ y: scales.y(c2)
7261
+ }, {
7262
+ x: right,
7263
+ y: scales.y(v1)
7264
+ }), Math.max(1, Math.ceil(Math.abs(right - left) / FLAT)));
7265
+ const bends = [];
7266
+ for (let j = 1; j < n; j++) {
7267
+ const x = x0 + j / n * h;
7268
+ if (!(x < through)) break;
7269
+ bends.push({
7270
+ x,
7271
+ value: cubic(v0, c1, c2, v1, j / n)
7272
+ });
7273
+ }
7274
+ return bends;
7275
+ },
7276
+ valueAt(from, to, x) {
7277
+ const p = piece(from, to);
7278
+ if (!p) return values[from] ?? 0;
7279
+ const [v0, c1, c2, v1, k] = p;
7280
+ return cubic(v0, c1, c2, v1, (x - kx[k]) / (kx[k + 1] - kx[k]));
7281
+ }
7282
+ };
7283
+ }
7284
+ function monotoneTangents(xs, values, start, end, out) {
7285
+ const count = end - start;
7286
+ if (count < 2) {
7287
+ if (count === 1) out[start] = 0;
7288
+ return;
7289
+ }
7290
+ const slope = (k) => (values[k + 1] - values[k]) / (xs[k + 1] - xs[k]);
7291
+ if (count === 2) {
7292
+ out[start] = out[start + 1] = slope(start);
7293
+ return;
7294
+ }
7295
+ for (let k = start + 1; k < end - 1; k++) {
7296
+ const h0 = xs[k] - xs[k - 1];
7297
+ const h1 = xs[k + 1] - xs[k];
7298
+ const s0 = slope(k - 1);
7299
+ const s1 = slope(k);
7300
+ const p = (s0 * h1 + s1 * h0) / (h0 + h1);
7301
+ out[k] = (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), .5 * Math.abs(p)) || 0;
7302
+ }
7303
+ out[start] = (3 * slope(start) - out[start + 1]) / 2;
7304
+ out[end - 1] = (3 * slope(end - 2) - out[end - 2]) / 2;
7305
+ }
7306
+ function fade(xs, values, presence, start, end, tangents) {
7307
+ const kept = [];
7308
+ for (let k = start; k < end; k++) if (presence[k] >= 1) kept.push(k);
7309
+ if (kept.length === end - start || kept.length < 2) return;
7310
+ const kx = kept.map((k) => xs[k]);
7311
+ const kv = kept.map((k) => values[k]);
7312
+ const without = new Float64Array(kept.length);
7313
+ monotoneTangents(kx, kv, 0, kept.length, without);
7314
+ const eased = new Float64Array(end - start);
7315
+ let j = 0;
7316
+ let i = 0;
7317
+ for (let k = start; k < end; k++) {
7318
+ while (j < kx.length - 2 && kx[j + 1] <= xs[k]) j++;
7319
+ const own = kept[i] === k ? i++ : -1;
7320
+ let least = 1;
7321
+ for (let n = Math.max(start, k - 2); n < Math.min(end, k + 3); n++) least = Math.min(least, presence[n]);
7322
+ if (least >= 1) {
7323
+ eased[k - start] = tangents[k];
7324
+ continue;
7325
+ }
7326
+ let slope;
7327
+ if (own >= 0) slope = without[own];
7328
+ else {
7329
+ const h = kx[j + 1] - kx[j];
7330
+ const u = Math.min(1, Math.max(0, (xs[k] - kx[j]) / h));
7331
+ slope = (6 * u * u - 6 * u) * (kv[j] - kv[j + 1]) / h + (3 * u * u - 4 * u + 1) * without[j] + (3 * u * u - 2 * u) * without[j + 1];
7332
+ }
7333
+ eased[k - start] = least * tangents[k] + (1 - least) * slope;
7334
+ }
7335
+ tangents.set(eased, start);
7336
+ }
7337
+ const sign = (x) => x < 0 ? -1 : 1;
7338
+ function cubic(v0, c1, c2, v1, u) {
7339
+ const s = 1 - u;
7340
+ return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
7341
+ }
7039
7342
  // src/charts/time.ts
7040
7343
  const TIME_ZONES = ["UTC", "local"];
7041
7344
  const SECOND = 1e3;
@@ -7051,7 +7354,7 @@ const LONGEST$1 = {
7051
7354
  month: 31 * DAY,
7052
7355
  year: 366 * DAY
7053
7356
  };
7054
- const STEPS = [
7357
+ const STEPS = /* @__PURE__ */ (() => [
7055
7358
  ...[
7056
7359
  1,
7057
7360
  5,
@@ -7099,7 +7402,7 @@ const STEPS = [
7099
7402
  unit: "month",
7100
7403
  count: 3
7101
7404
  }
7102
- ];
7405
+ ])();
7103
7406
  const LEVELS = [
7104
7407
  "year",
7105
7408
  "month",
@@ -7329,6 +7632,8 @@ function lineEncoding(options) {
7329
7632
  if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
7330
7633
  const xFormat = options.xFormat;
7331
7634
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
7635
+ const curve = options.curve ?? "linear";
7636
+ if (!CURVES.includes(curve)) throw new TypeError(`lineChart: curve must be "linear" or "monotone", got ${show$1(curve)}.`);
7332
7637
  return {
7333
7638
  x: accessor(x),
7334
7639
  key: key === void 0 ? void 0 : accessor(key),
@@ -7337,7 +7642,8 @@ function lineEncoding(options) {
7337
7642
  value: accessor(field)
7338
7643
  })),
7339
7644
  timeZone,
7340
- xFormat: options.xFormat
7645
+ xFormat: options.xFormat,
7646
+ curve
7341
7647
  };
7342
7648
  }
7343
7649
  function layoutLines(input) {
@@ -7358,7 +7664,7 @@ function layoutLines(input) {
7358
7664
  const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
7359
7665
  const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
7360
7666
  const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
7361
- const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0);
7667
+ const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (input.room ?? 0));
7362
7668
  const frame = {
7363
7669
  scale: {
7364
7670
  lo: domain.lo,
@@ -7388,7 +7694,8 @@ function layoutLines(input) {
7388
7694
  series,
7389
7695
  yTicks: domain.ticks.map((value, i) => placeYTick(frame, value, yTexts[i])),
7390
7696
  xTicks: spaced(xTicks, xWidths),
7391
- decimals: decimalsBy
7697
+ decimals: decimalsBy,
7698
+ curve: input.encoding.curve
7392
7699
  };
7393
7700
  }
7394
7701
  function positions(frame) {
@@ -7400,7 +7707,7 @@ function positions(frame) {
7400
7707
  y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
7401
7708
  };
7402
7709
  }
7403
- function placeLines(frame, rows, series, through, time = false, labels) {
7710
+ function placeLines(frame, rows, series, through, time = false, labels, bend = 0) {
7404
7711
  const first = rows[0];
7405
7712
  if (!first) return [];
7406
7713
  const at = positions(frame);
@@ -7410,27 +7717,47 @@ function placeLines(frame, rows, series, through, time = false, labels) {
7410
7717
  const next = rows[last + 1];
7411
7718
  const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
7412
7719
  const shown = rows.slice(0, last + 1);
7720
+ const xs = bend > 0 ? rows.map((row) => row.x) : [];
7721
+ const presence = bend > 0 && rows.some((row) => row.presence !== void 0 && row.presence < 1) ? rows.map((row) => row.presence ?? 1) : void 0;
7413
7722
  const datas = /* @__PURE__ */ new Map();
7414
7723
  const related = (own) => (name) => name === own ? void 0 : datas.get(name);
7415
7724
  const traced = series.map((name) => {
7416
7725
  const has = (row) => !row.missing?.has(name);
7726
+ const curve = bend > 0 ? lineCurve(xs, rows.map((row) => has(row) ? row.values[name] ?? 0 : void 0), bend, at, presence) : void 0;
7417
7727
  const vertices = [];
7418
7728
  let gap = false;
7419
- for (const row of shown) if (!has(row)) gap = vertices.length > 0;
7420
- else {
7421
- vertices.push({
7422
- at: row.x,
7423
- value: row.values[name] ?? 0,
7424
- datum: row.datum,
7425
- gapBefore: gap
7426
- });
7427
- gap = false;
7428
- }
7729
+ let before = -1;
7730
+ shown.forEach((row, i) => {
7731
+ if (!has(row)) gap = vertices.length > 0;
7732
+ else {
7733
+ if (curve && before >= 0) for (const b of curve.between(before, i)) vertices.push({
7734
+ at: b.x,
7735
+ value: b.value,
7736
+ datum: rows[before].datum,
7737
+ gapBefore: false
7738
+ });
7739
+ vertices.push({
7740
+ at: row.x,
7741
+ value: row.values[name] ?? 0,
7742
+ datum: row.datum,
7743
+ gapBefore: gap
7744
+ });
7745
+ gap = false;
7746
+ before = i;
7747
+ }
7748
+ });
7429
7749
  if (share !== void 0 && has(end) && has(next)) {
7750
+ if (curve) for (const b of curve.between(last, last + 1, through)) vertices.push({
7751
+ at: b.x,
7752
+ value: b.value,
7753
+ datum: end.datum,
7754
+ gapBefore: false
7755
+ });
7430
7756
  const from = end.values[name] ?? 0;
7757
+ const value = curve ? curve.valueAt(last, last + 1, through) : from + share * ((next.values[name] ?? 0) - from);
7431
7758
  vertices.push({
7432
7759
  at: through,
7433
- value: from + share * ((next.values[name] ?? 0) - from),
7760
+ value,
7434
7761
  datum: end.datum,
7435
7762
  gapBefore: false
7436
7763
  });
@@ -7452,15 +7779,19 @@ function placeLines(frame, rows, series, through, time = false, labels) {
7452
7779
  ...points[points.length - 1],
7453
7780
  text: labels.text(name, vertices[vertices.length - 1].value)
7454
7781
  }))) : [];
7782
+ const boxes = labels ? placed.map((label) => label.text !== "" ? textBox(label, labels.measure, "ec-value", VALUE_SIZE) : void 0) : [];
7455
7783
  return traced.map(({ name, vertices, points }) => {
7456
7784
  const tip = points[points.length - 1];
7457
- const label = labels ? placed[named.findIndex((line) => line.name === name)] ?? {
7785
+ const index = named.findIndex((line) => line.name === name);
7786
+ const label = labels ? placed[index] ?? {
7458
7787
  x: tip.x + LABEL_GAP,
7459
7788
  y: tip.y + VALUE_SIZE * CENTRE$1,
7460
7789
  anchor: "start",
7461
7790
  text: ""
7462
7791
  } : void 0;
7463
- const labelBounds = labels ? label && label.text !== "" ? [textBox(label, labels.measure, "ec-value", VALUE_SIZE)] : [] : void 0;
7792
+ const own = boxes[index];
7793
+ const labelBounds = labels ? own ? [own] : [] : void 0;
7794
+ const nearbyLabels = labels ? boxes.filter((box, i) => box !== void 0 && i !== index) : void 0;
7464
7795
  const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
7465
7796
  const geometry = describeLine({
7466
7797
  key: name,
@@ -7468,7 +7799,8 @@ function placeLines(frame, rows, series, through, time = false, labels) {
7468
7799
  points,
7469
7800
  width: LINE_WIDTH,
7470
7801
  ...breaks.length > 0 ? { breaks } : {},
7471
- ...labelBounds ? { labelBounds } : {}
7802
+ ...labelBounds ? { labelBounds } : {},
7803
+ ...nearbyLabels ? { nearbyLabels } : {}
7472
7804
  });
7473
7805
  let distance = 0;
7474
7806
  const samples = vertices.map((v, j) => {
@@ -7779,6 +8111,7 @@ const VISIBLE = .5;
7779
8111
  function lineChart$1(target, options, env) {
7780
8112
  const container = resolveTarget$2(target, "lineChart");
7781
8113
  checkChartOptions(options, "lineChart");
8114
+ let hoverKind = hoverOf(options);
7782
8115
  let current = options;
7783
8116
  const motion = chartMotion(options.motion, env.motion);
7784
8117
  let effects = resolveEffects(options.on, env.presets);
@@ -7836,10 +8169,12 @@ function lineChart$1(target, options, env) {
7836
8169
  let laidOut;
7837
8170
  let firstTable;
7838
8171
  let names;
8172
+ let pointNames;
7839
8173
  try {
7840
8174
  laidOut = layout(current);
7841
8175
  firstTable = tableFor(current, laidOut);
7842
- names = namesFor(current, laidOut);
8176
+ names = hoverKind === "x" ? namesFor(current, laidOut) : void 0;
8177
+ pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
7843
8178
  } catch (error) {
7844
8179
  svg.remove();
7845
8180
  throw error;
@@ -7847,6 +8182,7 @@ function lineChart$1(target, options, env) {
7847
8182
  const findMark = (key) => points.get(key) ?? lines.get(key) ?? leaving.get(key);
7848
8183
  const surface = svgSurface({
7849
8184
  overlay,
8185
+ measure,
7850
8186
  mark: (key) => ({
7851
8187
  set: (style) => {
7852
8188
  findMark(key)?.handle.set(style);
@@ -7888,6 +8224,11 @@ function lineChart$1(target, options, env) {
7888
8224
  motion,
7889
8225
  onChange: changed
7890
8226
  });
8227
+ const curved = animated(bendOf(laidOut.curve), interpolateNumber, {
8228
+ clock,
8229
+ motion,
8230
+ onChange: changed
8231
+ });
7891
8232
  const yTicks = /* @__PURE__ */ new Map();
7892
8233
  const xTicks = /* @__PURE__ */ new Map();
7893
8234
  let counting = laidOut.decimals;
@@ -7907,6 +8248,8 @@ function lineChart$1(target, options, env) {
7907
8248
  function layout(opts, using = effects) {
7908
8249
  const encoding = lineEncoding(opts);
7909
8250
  checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
8251
+ const { room = 0 } = opts;
8252
+ if (!(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`lineChart: room must be a number of px, 0 or more, got ${String(room)}.`);
7910
8253
  const next = layoutLines({
7911
8254
  data: opts.data,
7912
8255
  encoding,
@@ -7914,7 +8257,8 @@ function lineChart$1(target, options, env) {
7914
8257
  height: opts.height,
7915
8258
  format: format(opts),
7916
8259
  measure,
7917
- label: labeler(opts, true)
8260
+ label: labeler(opts, true),
8261
+ room
7918
8262
  });
7919
8263
  const keys = new Set(next.series);
7920
8264
  for (const row of next.rows) for (const name of next.series) {
@@ -7948,14 +8292,14 @@ function lineChart$1(target, options, env) {
7948
8292
  const label = labeler(current);
7949
8293
  if (!label) return void 0;
7950
8294
  return {
7951
- text: (series, value) => label(series, round$4(value, given[series] ?? decimals(value))),
8295
+ text: (series, value) => label(series, round$5(value, given[series] ?? decimals(value))),
7952
8296
  measure
7953
8297
  };
7954
8298
  }
7955
8299
  function placedFor(next) {
7956
8300
  const states = next.rows.map(restState);
7957
8301
  return {
7958
- lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
8302
+ lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals), bendOf(next.curve)).map((line) => [line.series, line])),
7959
8303
  points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
7960
8304
  };
7961
8305
  }
@@ -8090,6 +8434,7 @@ function lineChart$1(target, options, env) {
8090
8434
  };
8091
8435
  return [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)].map((record) => {
8092
8436
  const { x, values } = stateOf(record);
8437
+ const presence = record.anchor && record.presence.value < 1 ? { presence: record.presence.value } : {};
8093
8438
  return {
8094
8439
  record,
8095
8440
  state: {
@@ -8097,7 +8442,8 @@ function lineChart$1(target, options, env) {
8097
8442
  datum: record.row.datum,
8098
8443
  x,
8099
8444
  values,
8100
- missing: record.row.missing
8445
+ missing: record.row.missing,
8446
+ ...presence
8101
8447
  }
8102
8448
  };
8103
8449
  }).sort((a, b) => a.state.x - b.state.x);
@@ -8212,7 +8558,7 @@ function lineChart$1(target, options, env) {
8212
8558
  function paintLines(frame, states) {
8213
8559
  const drawnLines = [...lineOrder, ...leavingLines()];
8214
8560
  if (states.length === 0 || drawnLines.length === 0) return;
8215
- const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
8561
+ const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting), curved.value);
8216
8562
  showAll(drawnLines.map((line, i) => ({
8217
8563
  record: line,
8218
8564
  placed: placed[i]
@@ -8303,8 +8649,16 @@ function lineChart$1(target, options, env) {
8303
8649
  surface.hide(point.key, hidden);
8304
8650
  }
8305
8651
  }
8652
+ if (stopsLayer) paintStops(frame);
8306
8653
  }
8307
8654
  function showHover(key) {
8655
+ const point = points.get(key);
8656
+ if (point) {
8657
+ if (!revealed(point.row)) return;
8658
+ const { row } = point.row;
8659
+ tooltip.show(point.shown.geometry, about(row, point.series), () => pointSummary(row, point.series, current), point.handle.style.transform);
8660
+ return;
8661
+ }
8308
8662
  const record = rows.get(key);
8309
8663
  if (!record || !revealed(record)) return;
8310
8664
  const marks = livePoints(record);
@@ -8337,9 +8691,10 @@ function lineChart$1(target, options, env) {
8337
8691
  }
8338
8692
  let ringLine;
8339
8693
  function drawRing(key) {
8340
- const record = key === void 0 ? void 0 : rows.get(key);
8694
+ const point = key === void 0 ? void 0 : points.get(key);
8695
+ const record = key === void 0 ? void 0 : point?.row ?? rows.get(key);
8341
8696
  const live = record !== void 0 && revealed(record);
8342
- const marks = live ? livePoints(record) : [];
8697
+ const marks = live ? point ? [point] : livePoints(record) : [];
8343
8698
  if (live && marks.length === 0) {
8344
8699
  ringLine ?? (ringLine = svgElement("line", {
8345
8700
  class: "ec-focus-ring",
@@ -8389,34 +8744,262 @@ function lineChart$1(target, options, env) {
8389
8744
  const record = column ? byColumn.get(column) : void 0;
8390
8745
  return record && rows.get(record.key) === record && revealed(record) ? record : void 0;
8391
8746
  }
8747
+ let stopsLayer;
8748
+ let plotHit;
8749
+ const stops = /* @__PURE__ */ new Map();
8750
+ let stopOrder = [];
8751
+ const byStop = /* @__PURE__ */ new WeakMap();
8752
+ function pointOrder() {
8753
+ const bySeries = new Map(laidOut.series.map((series) => [series, []]));
8754
+ for (const record of rowOrder) for (const point of livePoints(record)) bySeries.get(point.series)?.push(point);
8755
+ return [...bySeries.values()].flat();
8756
+ }
8757
+ const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
8758
+ function nearestPoint(at) {
8759
+ const shown = rowOrder.filter(revealed).flatMap(livePoints);
8760
+ let best;
8761
+ let far = Infinity;
8762
+ let rank = Infinity;
8763
+ for (const point of shown) {
8764
+ const d = apart(point.shown.geometry.center, at);
8765
+ const r = laidOut.series.indexOf(point.series);
8766
+ if (d < far || d === far && r < rank) [best, far, rank] = [
8767
+ point,
8768
+ d,
8769
+ r
8770
+ ];
8771
+ }
8772
+ if (!best) return void 0;
8773
+ const center = best.shown.geometry.center;
8774
+ const on = /* @__PURE__ */ new Map();
8775
+ for (const point of shown) {
8776
+ const { center: c } = point.shown.geometry;
8777
+ const known = on.get(point.series);
8778
+ if (apart(c, center) <= 1 && (!known || apart(c, at) < apart(known.shown.geometry.center, at))) on.set(point.series, point);
8779
+ }
8780
+ if (on.size < 2) return best;
8781
+ let pick = best;
8782
+ let near = Infinity;
8783
+ for (const series of laidOut.series) {
8784
+ const point = on.get(series);
8785
+ if (!point) continue;
8786
+ const d = passing(point, at);
8787
+ if (d < near) [pick, near] = [point, d];
8788
+ }
8789
+ return pick;
8790
+ }
8791
+ function passing(point, at) {
8792
+ const { geometry, data } = point.shown;
8793
+ const line = lines.get(point.series);
8794
+ 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);
8795
+ }
8796
+ function heldPoint(at) {
8797
+ const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
8798
+ if (!point || !revealed(point.row)) return void 0;
8799
+ const { transform } = point.handle.style;
8800
+ let on = at;
8801
+ if (transform) try {
8802
+ on = matrix.apply(invert(transform), at);
8803
+ } catch {
8804
+ return;
8805
+ }
8806
+ const { center } = point.shown.geometry;
8807
+ return (on.x - center.x) ** 2 + (on.y - center.y) ** 2 <= 4.5 ** 2 ? point : void 0;
8808
+ }
8809
+ function pointAt(clientX, clientY) {
8810
+ const at = fromClient(clientX, clientY);
8811
+ return heldPoint(at) ?? nearestPoint(at);
8812
+ }
8813
+ function fromClient(x, y) {
8814
+ const box = svg.getBoundingClientRect();
8815
+ const k = box.width > 0 && drawnFrame.box.width > 0 ? box.width / drawnFrame.box.width : 1;
8816
+ return {
8817
+ x: (x - box.left) / k,
8818
+ y: (y - box.top) / k
8819
+ };
8820
+ }
8821
+ const abouts = /* @__PURE__ */ new WeakMap();
8822
+ function about(row, series) {
8823
+ let bySeries = abouts.get(row);
8824
+ if (!bySeries) abouts.set(row, bySeries = /* @__PURE__ */ new Map());
8825
+ let known = bySeries.get(series);
8826
+ if (!known) bySeries.set(series, known = {
8827
+ datum: row.datum,
8828
+ series
8829
+ });
8830
+ return known;
8831
+ }
8832
+ function syncStops() {
8833
+ if (hoverKind !== "point") return;
8834
+ if (!stopsLayer) {
8835
+ stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
8836
+ svg.insertBefore(stopsLayer, overlay);
8837
+ plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
8838
+ stopsLayer.addEventListener("click", (event) => {
8839
+ const point = pointAt(event.clientX, event.clientY);
8840
+ if (point) stops.get(point.key)?.element.focus();
8841
+ });
8842
+ }
8843
+ const live = pointOrder();
8844
+ const keep = new Set(live.map((point) => point.key));
8845
+ for (const [key, stop] of stops) {
8846
+ if (keep.has(key)) continue;
8847
+ stop.element.remove();
8848
+ stops.delete(key);
8849
+ }
8850
+ const order = live.map((point) => {
8851
+ let stop = stops.get(point.key);
8852
+ if (!stop) {
8853
+ const element = svgElement("g", {
8854
+ class: "ec-stop",
8855
+ "data-key": point.key,
8856
+ role: "img"
8857
+ }, stopsLayer);
8858
+ stop = {
8859
+ element,
8860
+ bounds: svgElement("circle", {
8861
+ r: 8.5,
8862
+ fill: "none"
8863
+ }, element),
8864
+ x: NaN,
8865
+ y: NaN,
8866
+ hidden: void 0
8867
+ };
8868
+ stops.set(point.key, stop);
8869
+ byStop.set(element, point.key);
8870
+ }
8871
+ const name = pointNames?.get(point.key) ?? point.key;
8872
+ if (stop.element.getAttribute("aria-label") !== name) stop.element.setAttribute("aria-label", name);
8873
+ tooltip.describe(stop.element, about(point.row.row, point.series));
8874
+ return stop.element;
8875
+ });
8876
+ orderElements(stopsLayer, stopOrder, order, hover.active);
8877
+ stopOrder = order;
8878
+ }
8879
+ function paintStops(frame) {
8880
+ const { left, right, top, bottom } = frame.box;
8881
+ setAttributes(plotHit, {
8882
+ x: left - DOT_RADIUS,
8883
+ y: top - DOT_RADIUS,
8884
+ width: right - left + 2 * DOT_RADIUS,
8885
+ height: bottom - top + 2 * DOT_RADIUS
8886
+ });
8887
+ for (const [key, stop] of stops) {
8888
+ const point = points.get(key);
8889
+ if (!point) continue;
8890
+ const hidden = !revealed(point.row);
8891
+ if (stop.hidden !== hidden) {
8892
+ stop.hidden = hidden;
8893
+ setAttributes(stop.element, { visibility: hidden ? "hidden" : void 0 });
8894
+ }
8895
+ const { x, y } = point.shown.geometry.center;
8896
+ if (stop.x === x && stop.y === y) continue;
8897
+ stop.x = x;
8898
+ stop.y = y;
8899
+ setAttributes(stop.bounds, {
8900
+ cx: x,
8901
+ cy: y
8902
+ });
8903
+ }
8904
+ }
8905
+ function counterpart(key) {
8906
+ const point = points.get(key);
8907
+ if (point) return point.row.key;
8908
+ const shown = rowOrder.filter(revealed);
8909
+ const i = shown.findIndex((record) => record.key === key);
8910
+ for (let step = 0; i >= 0 && step < shown.length; step++) for (const at of [i + step, i - step]) {
8911
+ const first = shown[at] && livePoints(shown[at])[0];
8912
+ if (first) return first.key;
8913
+ }
8914
+ }
8915
+ function rehover(kind) {
8916
+ if (kind === hoverKind) return;
8917
+ hover.leave();
8918
+ hoverKind = kind;
8919
+ if (kind === "point") {
8920
+ syncStops();
8921
+ paintStops(drawnFrame);
8922
+ } else columnsLayer.removeAttribute("display");
8923
+ hover.retarget(counterpart);
8924
+ if (kind === "point") columnsLayer.setAttribute("display", "none");
8925
+ else {
8926
+ stopsLayer?.remove();
8927
+ stopsLayer = plotHit = void 0;
8928
+ stops.clear();
8929
+ stopOrder = [];
8930
+ }
8931
+ }
8932
+ const hotLines = /* @__PURE__ */ new Map();
8933
+ function heat(key, on) {
8934
+ const series = on ? hoverKind === "point" ? findMark(key)?.series : void 0 : hotLines.get(key);
8935
+ if (series === void 0) return;
8936
+ if (on) hotLines.set(key, series);
8937
+ else hotLines.delete(key);
8938
+ surface.hot(key, on);
8939
+ if (!on && [...hotLines.values()].includes(series)) return;
8940
+ findMark(series)?.group.classList.toggle("ec-hot-line", on);
8941
+ surface.hot(series, on);
8942
+ }
8943
+ function live(key) {
8944
+ const point = hoverKind === "point" ? points.get(key) : void 0;
8945
+ const record = hoverKind === "point" ? point?.row : rows.get(key);
8946
+ return record !== void 0 && revealed(record);
8947
+ }
8392
8948
  const hover = chartHover({
8393
8949
  svg,
8394
8950
  runner,
8395
8951
  events,
8396
- dim: () => false,
8397
- find(eventTarget) {
8398
- const record = liveRowOf(eventTarget);
8399
- return record && { key: record.key };
8400
- },
8401
- live(key) {
8402
- const record = rows.get(key);
8403
- return record !== void 0 && revealed(record);
8952
+ dim: () => hoverKind === "point" && current.dim !== false && hover.key !== void 0,
8953
+ hot: heat,
8954
+ find(eventTarget, pointer) {
8955
+ if (hoverKind === "x") {
8956
+ const record = liveRowOf(eventTarget);
8957
+ return record && { key: record.key };
8958
+ }
8959
+ const element = eventTarget;
8960
+ if (!stopsLayer || typeof element?.closest !== "function" || !stopsLayer.contains(element)) return void 0;
8961
+ if (pointer) {
8962
+ const point = pointAt(pointer.x, pointer.y);
8963
+ return point && { key: point.key };
8964
+ }
8965
+ const stop = element.closest(".ec-stop");
8966
+ const key = stop ? byStop.get(stop) : void 0;
8967
+ return key !== void 0 && live(key) ? { key } : void 0;
8404
8968
  },
8405
- order: () => rowOrder.filter(revealed).map((record) => record.key),
8969
+ moves: () => hoverKind === "point",
8970
+ live,
8971
+ order: () => (hoverKind === "point" ? pointOrder().filter((point) => revealed(point.row)) : rowOrder.filter(revealed)).map((record) => record.key),
8406
8972
  page(key, by) {
8407
- const from = rows.get(key);
8408
- if (!laidOut.time || !from) return void 0;
8409
- const stops = rowOrder.filter(revealed);
8410
- const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
8411
- if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
8412
- for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
8973
+ const point = hoverKind === "point" ? points.get(key) : void 0;
8974
+ const stops = point ? along(point.series).map((p) => ({
8975
+ key: p.key,
8976
+ x: p.row.row.x
8977
+ })) : rowOrder.filter(revealed).map((record) => ({
8978
+ key: record.key,
8979
+ x: record.row.x
8980
+ }));
8981
+ const i = stops.findIndex((stop) => stop.key === key);
8982
+ if (i < 0) return void 0;
8983
+ if (!laidOut.time) return point ? stops[Math.min(stops.length - 1, Math.max(0, i + by * Math.ceil(stops.length / 10)))].key : void 0;
8984
+ const to = monthsOn(stops[i].x, by, lineEncoding(current).timeZone);
8985
+ if (by > 0) return (stops.find((stop) => stop.x >= to) ?? stops[stops.length - 1])?.key;
8986
+ for (let j = stops.length - 1; j >= 0; j--) if (stops[j].x <= to) return stops[j].key;
8413
8987
  return stops[0]?.key;
8414
8988
  },
8989
+ move(key, press) {
8990
+ const point = hoverKind === "point" ? points.get(key) : void 0;
8991
+ if (!point) return void 0;
8992
+ const stops = press === "ArrowUp" || press === "ArrowDown" ? livePoints(point.row).sort((a, b) => a.shown.geometry.center.y - b.shown.geometry.center.y) : along(point.series);
8993
+ const i = stops.indexOf(point);
8994
+ const to = press === "Home" ? 0 : press === "End" ? stops.length - 1 : i + (press === "ArrowDown" || press === "ArrowRight" ? 1 : -1);
8995
+ return stops[Math.max(0, Math.min(stops.length - 1, to))]?.key;
8996
+ },
8415
8997
  marks: (key) => {
8416
8998
  const record = rows.get(key);
8417
- return record ? livePoints(record).map((point) => point.key) : [];
8999
+ if (record) return livePoints(record).map((point) => point.key);
9000
+ return points.has(key) ? [key] : [];
8418
9001
  },
8419
- element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column,
9002
+ element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column ?? stops.get(key)?.element,
8420
9003
  markElement: (key) => findMark(key)?.group,
8421
9004
  onScreen(key) {
8422
9005
  const record = findMark(key);
@@ -8454,6 +9037,7 @@ function lineChart$1(target, options, env) {
8454
9037
  });
8455
9038
  }
8456
9039
  function labelColumn(record) {
9040
+ if (hoverKind !== "x") return;
8457
9041
  record.column.setAttribute("aria-label", names.get(record.key));
8458
9042
  tooltip.describe(record.column, record.row);
8459
9043
  }
@@ -8591,6 +9175,7 @@ function lineChart$1(target, options, env) {
8591
9175
  record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
8592
9176
  }
8593
9177
  for (const record of rowOrder) labelColumn(record);
9178
+ syncStops();
8594
9179
  orderElements(columnsLayer, before.filter((record) => !record.leaving).map((record) => record.column), rowOrder.map((record) => record.column), hover.active);
8595
9180
  orderElements(linesLayer, previousLines.map((line) => line.group), lineOrder.map((line) => line.group), () => null);
8596
9181
  rowChanges = changes;
@@ -8620,7 +9205,7 @@ function lineChart$1(target, options, env) {
8620
9205
  for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
8621
9206
  const goingLines = leavingLines();
8622
9207
  const folding = [...leavingRows.values()];
8623
- const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
9208
+ const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same)) || busy(curved, bendOf(next.curve), same);
8624
9209
  const positions = busy(box, frame.box, sameFields) || [...xTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.x, record.row.x, same) || record.anchor !== void 0 && busy(record.presence, 1, same)) || folding.some((record) => record.anchor !== void 0 && busy(record.presence, 0, same));
8625
9210
  let first;
8626
9211
  let second;
@@ -8638,6 +9223,7 @@ function lineChart$1(target, options, env) {
8638
9223
  else value.set(to);
8639
9224
  };
8640
9225
  move(scale, frame.scale, sameFields, first);
9226
+ move(curved, bendOf(next.curve), same, first);
8641
9227
  move(box, frame.box, sameFields, second);
8642
9228
  for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
8643
9229
  for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
@@ -8714,6 +9300,8 @@ function lineChart$1(target, options, env) {
8714
9300
  });
8715
9301
  lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
8716
9302
  for (const line of lineOrder) lines.set(line.series, line);
9303
+ syncStops();
9304
+ if (hoverKind === "point") columnsLayer.setAttribute("display", "none");
8717
9305
  land();
8718
9306
  }
8719
9307
  const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
@@ -8729,15 +9317,18 @@ function lineChart$1(target, options, env) {
8729
9317
  ...next
8730
9318
  };
8731
9319
  checkChartOptions(merged, "lineChart");
9320
+ const kind = hoverOf(merged);
8732
9321
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
8733
9322
  const nextLayout = layout(merged, swapped);
8734
9323
  const nextTable = tableFor(merged, nextLayout);
8735
- const nextNames = namesFor(merged, nextLayout);
9324
+ const nextNames = kind === "x" ? namesFor(merged, nextLayout) : void 0;
9325
+ const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
8736
9326
  if ("colors" in next) colors = toColorAssignment(merged.colors);
8737
9327
  const previous = current;
8738
9328
  const seriesBefore = laidOut.series;
8739
9329
  current = merged;
8740
9330
  names = nextNames;
9331
+ pointNames = nextPointNames;
8741
9332
  describeChart(svg, current);
8742
9333
  table.render(nextTable);
8743
9334
  const announcing = announcer !== void 0;
@@ -8746,6 +9337,8 @@ function lineChart$1(target, options, env) {
8746
9337
  announcer.destroy();
8747
9338
  announcer = void 0;
8748
9339
  }
9340
+ rehover(kind);
9341
+ hover.syncDim();
8749
9342
  transitions.supersede();
8750
9343
  const swapping = swapped !== effects;
8751
9344
  effects = swapped;
@@ -8784,13 +9377,29 @@ function lineChart$1(target, options, env) {
8784
9377
  marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
8785
9378
  focus(key) {
8786
9379
  if (destroyed) return;
8787
- const record = rows.get(key) ?? points.get(key)?.row;
8788
- if (record) hover.focus(record.key);
9380
+ const row = rows.get(key);
9381
+ if (hoverKind === "x") {
9382
+ const record = row ?? points.get(key)?.row;
9383
+ if (record) hover.focus(record.key);
9384
+ return;
9385
+ }
9386
+ const point = points.get(key) ?? (row && livePoints(row)[0]);
9387
+ if (point) hover.focus(point.key);
8789
9388
  },
8790
9389
  leave() {
8791
9390
  if (!destroyed) hover.leave();
8792
9391
  },
8793
9392
  labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
9393
+ paintOf(key) {
9394
+ const record = lines.get(key) ?? points.get(key);
9395
+ return record && {
9396
+ color: record.series,
9397
+ drawn: record.kind === "line" || record.group.classList.contains("ec-alone")
9398
+ };
9399
+ },
9400
+ standsFor(key) {
9401
+ return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
9402
+ },
8794
9403
  destroy() {
8795
9404
  if (destroyed) return;
8796
9405
  destroyed = true;
@@ -8813,6 +9422,7 @@ function lineChart$1(target, options, env) {
8813
9422
  for (const record of leaving.values()) record.leave?.resolve();
8814
9423
  scale.stop();
8815
9424
  box.stop();
9425
+ curved.stop();
8816
9426
  for (const tick of [...yTicks.values(), ...xTicks.values()]) tick.opacity.stop();
8817
9427
  events.clear();
8818
9428
  rows.clear();
@@ -8864,6 +9474,36 @@ function sameData(a, b) {
8864
9474
  function sameAt(a, b) {
8865
9475
  return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
8866
9476
  }
9477
+ function apart(a, b) {
9478
+ return (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
9479
+ }
9480
+ function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
9481
+ const i = samples.findIndex((sample) => sameAt(sample.at, x));
9482
+ if (i < 0 || !(geometry.length > 0)) return void 0;
9483
+ const t = samples[i].t;
9484
+ const span = reach / geometry.length;
9485
+ let near;
9486
+ for (const way of [-1, 1]) {
9487
+ let a = from;
9488
+ for (let j = i;; j += way) {
9489
+ const next = samples[j + way];
9490
+ if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
9491
+ const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
9492
+ const b = geometry.path(to);
9493
+ near = Math.min(near ?? Infinity, toSegment(at, a, b));
9494
+ if (to !== next.t) break;
9495
+ a = b;
9496
+ }
9497
+ }
9498
+ return near;
9499
+ }
9500
+ function toSegment(p, a, b) {
9501
+ const dx = b.x - a.x;
9502
+ const dy = b.y - a.y;
9503
+ const length = dx * dx + dy * dy;
9504
+ const u = length > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / length)) : 0;
9505
+ return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
9506
+ }
8867
9507
  function labelled(values, options) {
8868
9508
  return present(values).map((v) => ({
8869
9509
  series: v.series,
@@ -8885,35 +9525,60 @@ function summary(row, options) {
8885
9525
  lines: [said(row.values, options).join(" · ")]
8886
9526
  };
8887
9527
  }
9528
+ function pointSummary(row, series, options) {
9529
+ return summaryContent(row.label, labelled(row.values, options).filter((v) => v.series === series), format(options), { total: false });
9530
+ }
9531
+ function worded(options, datum, mark) {
9532
+ if (!options.markLabel) return mark.text;
9533
+ try {
9534
+ const named = options.markLabel(datum, mark);
9535
+ if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
9536
+ } catch (error) {
9537
+ report(error);
9538
+ }
9539
+ return mark.text;
9540
+ }
8888
9541
  function namesFor(options, layout) {
8889
9542
  const formatted = format(options);
8890
9543
  return new Map(layout.rows.map((row) => {
8891
- const values = labelled(row.values, options);
8892
9544
  const text = `${row.label}: ${said(row.values, options).join(", ")}`;
8893
- if (!options.markLabel) return [row.key, text];
8894
- try {
8895
- const named = options.markLabel(row.datum, {
8896
- key: row.key,
8897
- category: row.label,
8898
- values,
8899
- total: total(row.values),
8900
- format: formatted,
8901
- text
8902
- });
8903
- if (named !== void 0 && named !== null && String(named).trim() !== "") return [row.key, String(named)];
8904
- } catch (error) {
8905
- report(error);
8906
- }
8907
- return [row.key, text];
9545
+ return [row.key, worded(options, row.datum, {
9546
+ key: row.key,
9547
+ category: row.label,
9548
+ values: labelled(row.values, options),
9549
+ total: total(row.values),
9550
+ format: formatted,
9551
+ text
9552
+ })];
8908
9553
  }));
8909
9554
  }
9555
+ function pointNamesFor(options, layout) {
9556
+ const formatted = format(options);
9557
+ return new Map(layout.rows.flatMap((row) => labelled(row.values, options).map((value) => {
9558
+ const key = pointKey(value.series, row.key);
9559
+ const text = `${row.label}: ${formatted(value.value)} ${value.label}`;
9560
+ return [key, worded(options, row.datum, {
9561
+ key,
9562
+ category: row.label,
9563
+ values: [value],
9564
+ total: value.value,
9565
+ format: formatted,
9566
+ text
9567
+ })];
9568
+ })));
9569
+ }
9570
+ function hoverOf(options) {
9571
+ const { hover = "x" } = options;
9572
+ if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
9573
+ return hover;
9574
+ }
8910
9575
  // src/core/geometry/ring.ts
8911
9576
  const ROUND = .5;
8912
9577
  function goesRound(mark) {
8913
- const radius = distance$1(mark.start, mark.pivot);
8914
- return radius > ROUND && Math.abs(distance$1(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$1(mark.end, mark.pivot) - radius) <= ROUND;
9578
+ const radius = distance$2(mark.start, mark.pivot);
9579
+ return radius > ROUND && Math.abs(distance$2(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$2(mark.end, mark.pivot) - radius) <= ROUND;
8915
9580
  }
8916
- const distance$1 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
9581
+ const distance$2 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
8917
9582
  // src/charts/adapter/bars.ts
8918
9583
  const SAME = .5;
8919
9584
  const BASELINES = [
@@ -8962,10 +9627,10 @@ function describeRects(key, parts, baseline) {
8962
9627
  ...box,
8963
9628
  baseline,
8964
9629
  radius: tip.radius,
8965
- gap: Number.isFinite(gap) ? Math.max(0, round$3(gap)) : 0,
9630
+ gap: Number.isFinite(gap) ? Math.max(0, round$4(gap)) : 0,
8966
9631
  ...segments.every((s) => s.series !== void 0) ? { segments: segments.map((s) => ({
8967
9632
  series: s.series,
8968
- size: round$3(s.size)
9633
+ size: round$4(s.size)
8969
9634
  })) } : {}
8970
9635
  }),
8971
9636
  order: order.map((o) => o.index)
@@ -8983,8 +9648,8 @@ function union(boxes) {
8983
9648
  return {
8984
9649
  x,
8985
9650
  y,
8986
- width: round$3(Math.max(...boxes.map((b) => b.x + b.width)) - x),
8987
- height: round$3(Math.max(...boxes.map((b) => b.y + b.height)) - y)
9651
+ width: round$4(Math.max(...boxes.map((b) => b.x + b.width)) - x),
9652
+ height: round$4(Math.max(...boxes.map((b) => b.y + b.height)) - y)
8988
9653
  };
8989
9654
  }
8990
9655
  function commonLine(boxes, nearEdge, farEdge, near, far) {
@@ -9025,7 +9690,7 @@ function spanFrom(mark, baseline) {
9025
9690
  });
9026
9691
  }
9027
9692
  }
9028
- function round$3(value) {
9693
+ function round$4(value) {
9029
9694
  return Math.round(value * 1e3) / 1e3;
9030
9695
  }
9031
9696
  // src/charts/adapter/edits.ts
@@ -9201,13 +9866,13 @@ function boxIn(m, rect) {
9201
9866
  ].map((corner) => matrix.apply(m, corner));
9202
9867
  const xs = corners.map((p) => p.x);
9203
9868
  const ys = corners.map((p) => p.y);
9204
- const x = round$2(Math.min(...xs));
9205
- const y = round$2(Math.min(...ys));
9869
+ const x = round$3(Math.min(...xs));
9870
+ const y = round$3(Math.min(...ys));
9206
9871
  return {
9207
9872
  x,
9208
9873
  y,
9209
- width: round$2(round$2(Math.max(...xs)) - x),
9210
- height: round$2(round$2(Math.max(...ys)) - y)
9874
+ width: round$3(round$3(Math.max(...xs)) - x),
9875
+ height: round$3(round$3(Math.max(...ys)) - y)
9211
9876
  };
9212
9877
  }
9213
9878
  function rectOf(element) {
@@ -9225,6 +9890,7 @@ function rectOf(element) {
9225
9890
  }
9226
9891
  function attributesOf(element) {
9227
9892
  return (name) => {
9893
+ if (!element.hasAttribute(name)) return null;
9228
9894
  const animated = element[name];
9229
9895
  return typeof animated?.baseVal?.value === "number" ? String(animated.baseVal.value) : element.getAttribute(name);
9230
9896
  };
@@ -9252,7 +9918,7 @@ function fromRoot(element, root) {
9252
9918
  for (let node = element; node && node !== root; node = node.parentElement) m = matrix.multiply(ownTransform(node), m);
9253
9919
  return m;
9254
9920
  }
9255
- function round$2(value) {
9921
+ function round$3(value) {
9256
9922
  return Math.round(value * 1e3) / 1e3;
9257
9923
  }
9258
9924
  // src/charts/adapter/host-style.ts
@@ -9304,9 +9970,9 @@ function hostMarkHandle(parts, edits, halos) {
9304
9970
  };
9305
9971
  }
9306
9972
  function hostColors(element, root) {
9307
- const fill = paintOf(element, root, "fill");
9973
+ const fill = paintOf$1(element, root, "fill");
9308
9974
  const paint = fill === NONE ? "stroke" : "fill";
9309
- const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
9975
+ const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
9310
9976
  if (color === void 0 || color === NONE) return void 0;
9311
9977
  return {
9312
9978
  color,
@@ -9331,7 +9997,7 @@ function attributesComputed(root) {
9331
9997
  probed.set(root, computed);
9332
9998
  return computed;
9333
9999
  }
9334
- function paintOf(element, root, property) {
10000
+ function paintOf$1(element, root, property) {
9335
10001
  const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property);
9336
10002
  const computed = kind(raw);
9337
10003
  if (raw && attributesComputed(root)) return computed;
@@ -9344,15 +10010,28 @@ function paintOf(element, root, property) {
9344
10010
  return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
9345
10011
  }
9346
10012
  function strokeWidthOf(element, root) {
9347
- const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue("stroke-width");
10013
+ const style = element.ownerDocument.defaultView?.getComputedStyle?.(element);
10014
+ const raw = style?.getPropertyValue("stroke-width");
9348
10015
  const computed = pixels$1(raw);
9349
- if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return computed;
10016
+ const effect = style?.getPropertyValue("vector-effect").trim().toLowerCase();
10017
+ const declared = element.style?.getPropertyValue("vector-effect") ? effect : element.getAttribute("vector-effect")?.trim().toLowerCase();
10018
+ const screen = (effect && (effect !== "none" || attributesComputed(root)) ? effect : declared) === "non-scaling-stroke";
10019
+ if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return {
10020
+ width: computed,
10021
+ screen
10022
+ };
9350
10023
  for (let node = element; node; node = node === root ? null : node.parentElement) {
9351
10024
  if (node.style?.getPropertyValue("stroke-width")) break;
9352
10025
  const width = pixels$1(node.getAttribute("stroke-width"));
9353
- if (width !== void 0) return width;
10026
+ if (width !== void 0) return {
10027
+ width,
10028
+ screen
10029
+ };
9354
10030
  }
9355
- return computed;
10031
+ return {
10032
+ width: computed,
10033
+ screen
10034
+ };
9356
10035
  }
9357
10036
  function pixels$1(value) {
9358
10037
  const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(?:px\s*)?$/i.exec(value ?? "");
@@ -9374,6 +10053,183 @@ function mix$2(colors, emphasis) {
9374
10053
  function cssMatrix(m) {
9375
10054
  return `matrix(${m.map((v, i) => i < 4 ? Math.round(v * 1e6) / 1e6 : Math.round(v * 1e3) / 1e3).join(", ")})`;
9376
10055
  }
10056
+ // src/charts/adapter/slice.ts
10057
+ const NEAR = .5;
10058
+ const MOST = 32;
10059
+ function sliceOf$1(commands, m) {
10060
+ const scale = scaleOf$1(m);
10061
+ if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
10062
+ const near = NEAR / scale;
10063
+ const subpaths = flattenPath(commands);
10064
+ if (subpaths.length === 0 || subpaths.length > 2 || !subpaths.every(closes)) return void 0;
10065
+ const runs = subpaths.map((subpath) => runsOf(subpath.segments, near));
10066
+ const own = subpaths.length === 2 ? ring(runs[0], runs[1], near) : slice(runs[0], near);
10067
+ return own && moved(own, m);
10068
+ }
10069
+ function ring(a, b, near) {
10070
+ const [first, second] = [a[0], b[0]];
10071
+ if (a.length !== 1 || b.length !== 1 || first?.kind !== "arc" || second?.kind !== "arc") return void 0;
10072
+ const [outer, inner] = first.radius >= second.radius ? [first, second] : [second, first];
10073
+ const whole = (turn, radius) => Math.abs(Math.abs(turn) - TAU$2) * radius <= near;
10074
+ for (const center of [centerOf(outer), outer.arcs[0].center]) {
10075
+ if (!center) continue;
10076
+ const [r1, r0] = [distance$1(outer.from, center), distance$1(inner.from, center)];
10077
+ const [t1, t0] = [turnOf(outer, center), turnOf(inner, center)];
10078
+ 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 {
10079
+ center,
10080
+ inner: r0,
10081
+ outer: r1,
10082
+ start: angleOf(outer.from, center),
10083
+ sweep: Math.sign(t1) * TAU$2
10084
+ };
10085
+ }
10086
+ }
10087
+ function slice(runs, near) {
10088
+ let first = -1;
10089
+ runs.forEach((run, i) => {
10090
+ if (run.kind === "arc" && (first < 0 || run.radius > runs[first].radius)) first = i;
10091
+ });
10092
+ if (first < 0) return void 0;
10093
+ const cycle = [...runs.slice(first), ...runs.slice(0, first)];
10094
+ const outer = cycle[0];
10095
+ const [, side, third, fourth] = cycle;
10096
+ const pie = cycle.length === 3 && side?.kind === "line" && third?.kind === "line";
10097
+ const back = cycle.length === 4 && side?.kind === "line" && third?.kind === "arc" && fourth?.kind === "line" ? third : void 0;
10098
+ if (!pie && !back) return void 0;
10099
+ const [inEnd, inStart] = back ? [back.from, back.to] : [side.to, side.to];
10100
+ const toward = (from, to) => {
10101
+ const length = distance$1(from, to);
10102
+ return length > near ? {
10103
+ x: from.x + (to.x - from.x) * outer.radius / length,
10104
+ y: from.y + (to.y - from.y) * outer.radius / length
10105
+ } : void 0;
10106
+ };
10107
+ const a = toward(outer.from, inStart);
10108
+ const b = toward(outer.to, inEnd);
10109
+ if (!a || !b) return void 0;
10110
+ let center = {
10111
+ x: (a.x + b.x) / 2,
10112
+ y: (a.y + b.y) / 2
10113
+ };
10114
+ if (pie && distance$1(inEnd, center) <= near) center = inEnd;
10115
+ const inner = center === inEnd ? 0 : (distance$1(inEnd, center) + distance$1(inStart, center)) / 2;
10116
+ const sweep = turnOf(outer, center);
10117
+ if (sweep === 0) return void 0;
10118
+ const own = {
10119
+ center,
10120
+ inner,
10121
+ outer: (distance$1(outer.from, center) + distance$1(outer.to, center)) / 2,
10122
+ start: angleOf(outer.from, center),
10123
+ sweep
10124
+ };
10125
+ return checked(own, outer, back, [inEnd, inStart], near) ? own : void 0;
10126
+ }
10127
+ function checked(own, outer, back, [inEnd, inStart], near) {
10128
+ const { center, start, sweep } = own;
10129
+ const at = (radius, angle) => ({
10130
+ x: center.x + radius * Math.cos(angle),
10131
+ y: center.y + radius * Math.sin(angle)
10132
+ });
10133
+ 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));
10134
+ }
10135
+ function turnOf(run, center) {
10136
+ let turn = 0;
10137
+ for (const arc of run.arcs) {
10138
+ const step = normalizeAngle(angleOf(pointOn(arc, 1), center) - angleOf(pointOn(arc, 0), center));
10139
+ turn += step + TAU$2 * Math.round((arc.sweep - step) / TAU$2);
10140
+ }
10141
+ return turn;
10142
+ }
10143
+ function centerOf(run) {
10144
+ const points = [run.from, ...run.arcs.slice(0, -1).map((arc) => pointOn(arc, 1))];
10145
+ if (points.length < 2) return void 0;
10146
+ if (points.length === 2) return {
10147
+ x: (points[0].x + points[1].x) / 2,
10148
+ y: (points[0].y + points[1].y) / 2
10149
+ };
10150
+ const [p, q, r] = [
10151
+ points[0],
10152
+ points[Math.floor(points.length / 3)],
10153
+ points[Math.floor(2 * points.length / 3)]
10154
+ ];
10155
+ const d = 2 * (p.x * (q.y - r.y) + q.x * (r.y - p.y) + r.x * (p.y - q.y));
10156
+ if (!(Math.abs(d) > 0)) return void 0;
10157
+ const [pp, qq, rr] = [
10158
+ p,
10159
+ q,
10160
+ r
10161
+ ].map(({ x, y }) => x * x + y * y);
10162
+ return {
10163
+ x: (pp * (q.y - r.y) + qq * (r.y - p.y) + rr * (p.y - q.y)) / d,
10164
+ y: (pp * (r.x - q.x) + qq * (p.x - r.x) + rr * (q.x - p.x)) / d
10165
+ };
10166
+ }
10167
+ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <= near && run.arcs.every((arc) => [
10168
+ 0,
10169
+ .5,
10170
+ 1
10171
+ ].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
10172
+ function moved(own, m) {
10173
+ const scale = scaleOf$1(m);
10174
+ const center = matrix.apply(m, own.center);
10175
+ const corner = matrix.apply(m, {
10176
+ x: own.center.x + own.outer * Math.cos(own.start),
10177
+ y: own.center.y + own.outer * Math.sin(own.start)
10178
+ });
10179
+ const sweep = m[0] * m[3] - m[1] * m[2] < 0 ? -own.sweep : own.sweep;
10180
+ let start = ((angleOf(corner, center) + Math.PI / 2) % TAU$2 + TAU$2) % TAU$2;
10181
+ if (start > TAU$2 - 1e-9) start = 0;
10182
+ return {
10183
+ cx: round$2(center.x),
10184
+ cy: round$2(center.y),
10185
+ inner: round$2(own.inner * scale),
10186
+ outer: round$2(own.outer * scale),
10187
+ start,
10188
+ end: start + sweep
10189
+ };
10190
+ }
10191
+ function runsOf(segments, near) {
10192
+ const runs = [];
10193
+ const join = (run, arc) => run !== void 0 && Math.sign(run.sweep) === Math.sign(arc.sweep) && Math.abs(run.radius - arc.radius) <= near;
10194
+ for (const segment of segments) {
10195
+ const last = runs[runs.length - 1];
10196
+ if (segment.kind === "line") runs.push({
10197
+ kind: "line",
10198
+ from: segment.from,
10199
+ to: segment.to
10200
+ });
10201
+ else if (last?.kind === "arc" && join(last, segment)) runs[runs.length - 1] = {
10202
+ ...last,
10203
+ arcs: [...last.arcs, segment],
10204
+ to: pointOn(segment, 1),
10205
+ sweep: last.sweep + segment.sweep
10206
+ };
10207
+ else runs.push({
10208
+ kind: "arc",
10209
+ arcs: [segment],
10210
+ from: pointOn(segment, 0),
10211
+ to: pointOn(segment, 1),
10212
+ radius: segment.radius,
10213
+ sweep: segment.sweep
10214
+ });
10215
+ }
10216
+ const [head] = runs;
10217
+ const tail = runs[runs.length - 1];
10218
+ if (runs.length > 1 && head?.kind === "arc" && tail?.kind === "arc" && tail.arcs.every((arc) => join(head, arc))) {
10219
+ runs[0] = {
10220
+ ...head,
10221
+ arcs: [...tail.arcs, ...head.arcs],
10222
+ from: tail.from,
10223
+ sweep: tail.sweep + head.sweep
10224
+ };
10225
+ runs.pop();
10226
+ }
10227
+ return runs;
10228
+ }
10229
+ const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
10230
+ const angleOf = (point, center) => Math.atan2(point.y - center.y, point.x - center.x);
10231
+ const distance$1 = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
10232
+ const round$2 = (value) => Math.round(value * 1e3) / 1e3 + 0;
9377
10233
  // src/charts/adapter/source.ts
9378
10234
  function readSource(source) {
9379
10235
  if (typeof source === "string") {
@@ -9583,7 +10439,7 @@ function expressive$1(target, options, env) {
9583
10439
  common,
9584
10440
  screen: screenMatrices(),
9585
10441
  colors: (element) => colorsOf(element, svg),
9586
- strokeWidth: (element) => strokeWidthOf(element, svg)
10442
+ stroke: (element) => strokeWidthOf(element, svg)
9587
10443
  };
9588
10444
  const named = (mark) => ({
9589
10445
  ...mark,
@@ -9599,7 +10455,7 @@ function expressive$1(target, options, env) {
9599
10455
  const shapes = [];
9600
10456
  keys.forEach((key, index) => {
9601
10457
  const pieces = groups.get(key);
9602
- if (pieces[0].element.localName === "rect") bars.push(index);
10458
+ if (pieces[0].element.localName === "rect" && !turned(pieces, at)) bars.push(index);
9603
10459
  else {
9604
10460
  const mark = shapeMark(key, pieces[0], index, at);
9605
10461
  if (mark) shapes.push(mark);
@@ -9626,9 +10482,12 @@ function expressive$1(target, options, env) {
9626
10482
  index
9627
10483
  };
9628
10484
  }
10485
+ function turned(pieces, at) {
10486
+ return pieces.length === 1 && !axisAligned(transformOf(pieces[0].element, at));
10487
+ }
9629
10488
  function rectPiece(key, piece, at) {
9630
10489
  const m = transformOf(piece.element, at);
9631
- 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.`);
10490
+ 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.`);
9632
10491
  return {
9633
10492
  ...piece,
9634
10493
  rect: {
@@ -9666,7 +10525,7 @@ function expressive$1(target, options, env) {
9666
10525
  };
9667
10526
  const r = tag === "circle" ? length("r") : 0;
9668
10527
  let geometry;
9669
- let strokeWidth;
10528
+ let stroke;
9670
10529
  if (tag === "circle" && (keepsCircles(m) || !(r > 0))) {
9671
10530
  const center = matrix.apply(m, {
9672
10531
  x: length("cx"),
@@ -9682,19 +10541,27 @@ function expressive$1(target, options, env) {
9682
10541
  } else {
9683
10542
  const commands = shapeOutline(tag, attribute);
9684
10543
  if (commands[0]?.op !== "M" || commands.every((command) => command.op === "M")) return void 0;
9685
- strokeWidth = tag === "circle" ? void 0 : at.strokeWidth(element);
9686
- const width = round$1((strokeWidth ?? 1) * scaleOf$1(m));
9687
- geometry = describeShape({
10544
+ stroke = tag === "circle" ? void 0 : at.stroke(element);
10545
+ const slice = tag === "path" ? sliceOf$1(commands, m) : void 0;
10546
+ if (slice) geometry = describeArc({
9688
10547
  key,
9689
10548
  series,
9690
- d: tag === "path" ? attribute("d") ?? "" : formatPath(commands),
9691
- matrix: m,
9692
- width: width > 0 ? width : 1
10549
+ ...slice
9693
10550
  });
10551
+ else {
10552
+ const width = round$1(widthOf(stroke, m, at));
10553
+ geometry = describeShape({
10554
+ key,
10555
+ series,
10556
+ d: tag === "path" ? attribute("d") ?? "" : formatPath(commands),
10557
+ matrix: m,
10558
+ width: width > 0 ? width : 1
10559
+ });
10560
+ }
9694
10561
  }
9695
10562
  const parts = [{
9696
10563
  ...part(piece, outlineOf(geometry, series, 1), at),
9697
- strokeWidth
10564
+ stroke
9698
10565
  }];
9699
10566
  return {
9700
10567
  key,
@@ -9704,6 +10571,13 @@ function expressive$1(target, options, env) {
9704
10571
  ...tag === "circle" ? { circle: true } : {}
9705
10572
  };
9706
10573
  }
10574
+ function widthOf(stroke, m, at) {
10575
+ const width = stroke?.width ?? 1;
10576
+ if (!stroke?.screen) return width * scaleOf$1(m);
10577
+ const screen = at.screen(at.common);
10578
+ const scale = screen ? scaleOf$1(screen) : 0;
10579
+ return scale > 0 ? width / scale : width;
10580
+ }
9707
10581
  function transformOf(element, at) {
9708
10582
  return matrix.multiply(between$1(at.common, element.parentElement ?? at.svg, at.svg, at.screen), ownTransform(element));
9709
10583
  }
@@ -10158,9 +11032,17 @@ function expressive$1(target, options, env) {
10158
11032
  let overlayMoved = false;
10159
11033
  for (const element of changes.ancestors) if (element.contains(ancestor)) overlayMoved = true;
10160
11034
  else for (const record of order) if (record.mark.parts.some((part) => element.contains(part.element))) changed.add(record);
10161
- if (overlayMoved) placeOverlay();
10162
- if (changed.size === 0) return;
10163
- const { records, marks } = reread([...changed]);
11035
+ const rescaled = /* @__PURE__ */ new Set();
11036
+ if (overlayMoved) {
11037
+ placeOverlay();
11038
+ for (const record of order) if (!changed.has(record) && record.mark.parts.some((part) => part.stroke?.screen)) rescaled.add(record);
11039
+ }
11040
+ if (changed.size === 0 && rescaled.size === 0) return;
11041
+ const read = reread([...changed, ...rescaled]);
11042
+ const kept = read.records.flatMap((record, i) => rescaled.has(record) && !geometryChanged(record.mark.geometry, read.marks[i].geometry) ? [] : [i]);
11043
+ if (kept.length === 0) return;
11044
+ const records = kept.map((i) => read.records[i]);
11045
+ const marks = kept.map((i) => read.marks[i]);
10164
11046
  records.forEach((record, i) => {
10165
11047
  const mark = marks[i];
10166
11048
  record.mark = mark;
@@ -10182,7 +11064,7 @@ function expressive$1(target, options, env) {
10182
11064
  common: ancestor,
10183
11065
  screen: screenMatrices(),
10184
11066
  colors: (element) => owners.get(element)?.part.colors,
10185
- strokeWidth: (element) => owners.get(element)?.part.strokeWidth
11067
+ stroke: (element) => owners.get(element)?.part.stroke
10186
11068
  };
10187
11069
  const rowOf = rowsNow();
10188
11070
  const piecesOf = ({ parts }) => parts.map((part) => ({
@@ -10201,16 +11083,17 @@ function expressive$1(target, options, env) {
10201
11083
  marks: withData(marks)
10202
11084
  };
10203
11085
  }
10204
- const rects = new Map(changed.flatMap((record) => record.mark.rect ? [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]] : []));
10205
- const edges = edgesNow(rects);
10206
- 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)));
11086
+ const shapes = new Set(changed.filter((record) => !record.mark.rect || turned(record.mark.parts, at)));
11087
+ const rects = new Map(changed.flatMap((record) => shapes.has(record) ? [] : [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]]));
11088
+ const edges = edgesNow(rects, shapes);
11089
+ 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)));
10207
11090
  const records = [...rects.keys()];
10208
11091
  const marks = records.map((record) => ({
10209
11092
  ...rectMark(record.key, rects.get(record), edges.get(record), record.mark.index, at),
10210
11093
  label: record.mark.label
10211
11094
  }));
10212
11095
  for (const record of changed) {
10213
- if (record.mark.rect) continue;
11096
+ if (!shapes.has(record)) continue;
10214
11097
  const mark = shapeMark(record.key, piecesOf(record.mark)[0], record.mark.index, at);
10215
11098
  if (!mark) continue;
10216
11099
  records.push(record);
@@ -10224,8 +11107,8 @@ function expressive$1(target, options, env) {
10224
11107
  marks: withData(marks)
10225
11108
  };
10226
11109
  }
10227
- function edgesNow(rects) {
10228
- const bars = order.filter((record) => record.mark.rect);
11110
+ function edgesNow(rects, shapes) {
11111
+ const bars = order.filter((record) => record.mark.rect && !shapes.has(record));
10229
11112
  const kept = new Map(bars.map((record) => [record, record.mark.rect.edge]));
10230
11113
  if (options.baseline !== void 0 && options.baseline !== "auto") return kept;
10231
11114
  const boxes = bars.map((record) => {
@@ -10811,10 +11694,12 @@ function namesIn(root) {
10811
11694
  }
10812
11695
  const lineItems = (first) => first.mark?.items ?? [first];
10813
11696
  const drawsLine = (first) => lineItems(first).some((item) => item.defined !== false);
11697
+ const straight = (first) => {
11698
+ const interpolate = lineItems(first)[0]?.interpolate;
11699
+ return interpolate === void 0 || interpolate === "linear";
11700
+ };
10814
11701
  function pointsOf(first) {
10815
11702
  const items = lineItems(first);
10816
- const interpolate = items[0]?.interpolate;
10817
- if (interpolate !== void 0 && interpolate !== "linear") throw new TypeError(`fromVegaView: a line is drawn with interpolate "${interpolate}", but only straight lines can be read. Use interpolate "linear" (the default), or describe the curve with expressive()'s geometry option.`);
10818
11703
  const points = [];
10819
11704
  let gap = false;
10820
11705
  for (const item of items) {
@@ -10836,6 +11721,16 @@ function pointsOf(first) {
10836
11721
  }
10837
11722
  function lineOf(key, element, first, m) {
10838
11723
  const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
11724
+ if (!straight(first)) {
11725
+ const scaled = width * scaleOf(m);
11726
+ return describeShape({
11727
+ key,
11728
+ series: key,
11729
+ d: element.getAttribute("d") ?? "",
11730
+ matrix: m,
11731
+ width: scaled > 0 && Number.isFinite(scaled) ? scaled : 1
11732
+ });
11733
+ }
10839
11734
  const points = pointsOf(first);
10840
11735
  const breaks = points.flatMap((p, i) => p.gapBefore ? [i] : []);
10841
11736
  return describeLine({
@@ -11087,12 +11982,12 @@ function chartSwitch$1(target, options, env) {
11087
11982
  const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
11088
11983
  const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
11089
11984
  const orders = /* @__PURE__ */ new WeakMap();
11090
- const surface = { group(key, order) {
11985
+ const surfaceFor = (paints) => ({ group(key, order) {
11091
11986
  const group = svgElement("g", {
11092
11987
  class: "ec-run",
11093
11988
  "data-key": key
11094
11989
  }, runsLayer);
11095
- setStyles(group, markColorStyles(seriesColors(colors.slot(key))));
11990
+ setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
11096
11991
  orders.set(group, order);
11097
11992
  const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
11098
11993
  runsLayer.insertBefore(group, above ?? null);
@@ -11100,7 +11995,7 @@ function chartSwitch$1(target, options, env) {
11100
11995
  ...svgLayer(group),
11101
11996
  clear: () => group.remove()
11102
11997
  };
11103
- } };
11998
+ } });
11104
11999
  let current = options.initial;
11105
12000
  let active;
11106
12001
  let destroyed = false;
@@ -11128,17 +12023,16 @@ function chartSwitch$1(target, options, env) {
11128
12023
  const element = focused();
11129
12024
  if (!element || !from.container.contains(element)) return void 0;
11130
12025
  const keyed = element.closest("[data-key]");
11131
- return { key: keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") ?? void 0 : void 0 };
12026
+ const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
12027
+ return { keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key] };
11132
12028
  }
11133
12029
  function restoreFocus(to, memory) {
11134
12030
  if (!memory) return;
11135
12031
  const now = focused();
11136
12032
  if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
11137
12033
  const inside = () => to.chart.element.contains(focused());
11138
- if (memory.key !== void 0) to.chart.focus(memory.key);
11139
- if (inside()) return;
11140
- for (const mark of to.chart.marks()) {
11141
- to.chart.focus(mark.key);
12034
+ for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
12035
+ to.chart.focus(key);
11142
12036
  if (inside()) return;
11143
12037
  }
11144
12038
  }
@@ -11176,7 +12070,7 @@ function chartSwitch$1(target, options, env) {
11176
12070
  each.container.setAttribute("inert", "");
11177
12071
  each.chart.element.classList.add("ec-morphing");
11178
12072
  }
11179
- const { pairs, scene } = prepare(from, to);
12073
+ const { pairs, surface, scene } = prepare(from, to);
11180
12074
  const { done, settle } = deferred();
11181
12075
  const session = {
11182
12076
  a: from,
@@ -11187,6 +12081,7 @@ function chartSwitch$1(target, options, env) {
11187
12081
  from: b,
11188
12082
  to: a
11189
12083
  })),
12084
+ surface,
11190
12085
  scene,
11191
12086
  focus: memory,
11192
12087
  progress: 0,
@@ -11213,7 +12108,7 @@ function chartSwitch$1(target, options, env) {
11213
12108
  const started = startClock(clock);
11214
12109
  session.transition = playTransition(session.forward ? session.pairs : session.reversed, {
11215
12110
  effect,
11216
- surface,
12111
+ surface: session.surface,
11217
12112
  start: begin,
11218
12113
  motion,
11219
12114
  clock: started.clock,
@@ -11266,16 +12161,27 @@ function chartSwitch$1(target, options, env) {
11266
12161
  const to = b.chart.marks().map((mark) => mapMark(mark, toB));
11267
12162
  const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
11268
12163
  const toKeys = new Set(to.map((mark) => mark.key));
11269
- const pairs = to.flatMap((mark) => {
12164
+ const pairs = [];
12165
+ const paints = [];
12166
+ for (const mark of to) {
11270
12167
  const partner = fromByKey.get(mark.key);
11271
- return partner ? [{
11272
- from: partner,
11273
- to: mark
11274
- }] : [];
11275
- });
12168
+ if (!partner) continue;
12169
+ const was = paintOf(a, partner);
12170
+ const will = paintOf(b, mark);
12171
+ if (!was.drawn && !will.drawn) continue;
12172
+ pairs.push({
12173
+ from: was.drawn ? partner : dot$1(partner),
12174
+ to: will.drawn ? mark : dot$1(mark)
12175
+ });
12176
+ paints.push(will.color);
12177
+ }
11276
12178
  const drawings = [];
11277
- for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
11278
- for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
12179
+ const fade = (view, mark, opacity) => {
12180
+ const paint = paintOf(view, mark);
12181
+ if (paint.drawn) drawings.push(fadeMark(mark, paint.color, opacity));
12182
+ };
12183
+ for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, fadeOut);
12184
+ for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, fadeIn);
11279
12185
  const id = (label) => `${label.role}\n${label.key}`;
11280
12186
  const labelsA = a.chart.labels();
11281
12187
  const labelsB = b.chart.labels();
@@ -11295,6 +12201,7 @@ function chartSwitch$1(target, options, env) {
11295
12201
  });
11296
12202
  return {
11297
12203
  pairs,
12204
+ surface: surfaceFor(paints),
11298
12205
  scene: {
11299
12206
  draw: (s) => {
11300
12207
  for (const draw of drawings) draw(s);
@@ -11307,12 +12214,12 @@ function chartSwitch$1(target, options, env) {
11307
12214
  }
11308
12215
  };
11309
12216
  }
11310
- function fadeMark(mark, opacity) {
12217
+ function fadeMark(mark, color, opacity) {
11311
12218
  const group = svgElement("g", {
11312
12219
  class: "ec-switch-fade",
11313
12220
  "data-key": mark.key
11314
12221
  }, fadesLayer);
11315
- setStyles(group, markColorStyles(seriesColors(colors.slot(mark.key))));
12222
+ setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
11316
12223
  svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : {
11317
12224
  stroke: "mark",
11318
12225
  width: mark.thickness
@@ -11505,6 +12412,21 @@ const fadeOut = (s) => 1 - clamp$1(s / HALF);
11505
12412
  const fadeIn = (s) => clamp$1((s - HALF) / .5);
11506
12413
  const clamp$1 = (value) => Math.min(1, Math.max(0, value));
11507
12414
  const mix$1 = (x, y, s) => x * (1 - s) + y * s;
12415
+ function paintOf(view, mark) {
12416
+ return view.chart.paintOf?.(mark.key) ?? {
12417
+ color: mark.key,
12418
+ drawn: true
12419
+ };
12420
+ }
12421
+ function dot$1(mark) {
12422
+ return describePoint({
12423
+ key: mark.key,
12424
+ ...mark.series === void 0 ? {} : { series: mark.series },
12425
+ x: mark.center.x,
12426
+ y: mark.center.y,
12427
+ r: 0
12428
+ });
12429
+ }
11508
12430
  const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
11509
12431
  function mapMark(mark, m) {
11510
12432
  if (isIdentity(m)) return mark;
@@ -11526,6 +12448,7 @@ function mapMark(mark, m) {
11526
12448
  return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
11527
12449
  },
11528
12450
  slice: (t0, t1) => path(mark.slice(t0, t1)),
12451
+ ...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
11529
12452
  thickness: mark.thickness * scale,
11530
12453
  outline: {
11531
12454
  d: path(outline.d),
@@ -11740,7 +12663,7 @@ function checkOptions$8(options) {
11740
12663
  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)}.`);
11741
12664
  }
11742
12665
  // src/effects/gaits.ts
11743
- const STILL = Object.freeze({
12666
+ const STILL = /* @__PURE__ */ Object.freeze({
11744
12667
  lift: 0,
11745
12668
  spin: 0,
11746
12669
  tilt: 0
@@ -12202,23 +13125,71 @@ const PAST_END = 10;
12202
13125
  const PAST_LABEL = 6;
12203
13126
  const TEXT = 12.5;
12204
13127
  const CENTRE = .36;
12205
- function captionPlace(mark) {
12206
- const boxes = mark.labelBounds ?? [];
13128
+ function captionPlace(mark, text) {
13129
+ const own = mark.labelBounds ?? [];
13130
+ const boxes = [
13131
+ ...own,
13132
+ ...mark.nearbyLabels ?? [],
13133
+ ...text?.held ?? []
13134
+ ];
12207
13135
  const heading = mark.angle(1);
12208
- const along = farthest(mark.end, heading, boxes);
12209
- if (along === void 0 && boxes.length > 0) {
13136
+ if (farthest(mark.end, heading, own) === void 0) {
12210
13137
  const up = mark.angle(.5) - Math.PI / 2;
12211
- const out = farthest(mark.center, up, boxes);
12212
- if (out !== void 0) return placed(mark.center, up, out);
13138
+ if (farthest(mark.center, up, own) !== void 0) return past(mark.center, up, 0, own, boxes, text);
12213
13139
  }
12214
- return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity));
13140
+ return past(mark.end, heading, PAST_END, own, boxes, text);
12215
13141
  }
13142
+ function past(from, toward, least, own, boxes, text) {
13143
+ if (!text) return placed(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
13144
+ const { x, y, width, height } = text.box(placed(from, toward, 0));
13145
+ return placed(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
13146
+ x: x - from.x,
13147
+ y: y - from.y,
13148
+ width,
13149
+ height
13150
+ }, new Set(text.held)));
13151
+ }
13152
+ function clearOf(from, toward, distance, boxes, reach, held) {
13153
+ const cos = Math.cos(toward);
13154
+ const sin = Math.sin(toward);
13155
+ const across = centred(cos);
13156
+ const meets = (box) => span(from, cos, sin, {
13157
+ x: box.x - reach.x - reach.width,
13158
+ y: box.y - reach.y - reach.height,
13159
+ width: box.width + reach.width,
13160
+ height: box.height + reach.height
13161
+ });
13162
+ const spans = boxes.map((box) => {
13163
+ const near = grow(box, PAST_LABEL);
13164
+ const band = span(from, cos, sin, near);
13165
+ if (!band && held.has(box)) return meets(box);
13166
+ const within = meets(near);
13167
+ if (!band || !within) return within;
13168
+ const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
13169
+ return [within[0], Math.max(leaving, meets(box)?.[1] ?? -Infinity)];
13170
+ });
13171
+ let at = distance;
13172
+ for (let moved = true; moved;) {
13173
+ moved = false;
13174
+ for (const meets of spans) if (meets && at > meets[0] + 1e-6 && at < meets[1] - 1e-6) {
13175
+ at = meets[1];
13176
+ moved = true;
13177
+ }
13178
+ }
13179
+ return at;
13180
+ }
13181
+ const grow = ({ x, y, width, height }, by) => ({
13182
+ x: x - by,
13183
+ y: y - by,
13184
+ width: width + 2 * by,
13185
+ height: height + 2 * by
13186
+ });
12216
13187
  function placed(from, toward, distance) {
12217
13188
  const cos = Math.cos(toward);
12218
13189
  const sin = Math.sin(toward);
12219
13190
  const point = offset(from, toward, distance);
12220
13191
  const drop = TEXT * (sin < 0 ? CENTRE * (1 + sin) : CENTRE + .44000000000000006 * sin);
12221
- const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
13192
+ const anchor = centred(cos) ? "middle" : cos > 0 ? "start" : "end";
12222
13193
  return {
12223
13194
  at: {
12224
13195
  x: point.x,
@@ -12228,22 +13199,26 @@ function placed(from, toward, distance) {
12228
13199
  toward
12229
13200
  };
12230
13201
  }
13202
+ function centred(cos) {
13203
+ return Math.abs(cos) <= Math.SQRT1_2 + 1e-9;
13204
+ }
12231
13205
  function farthest(from, toward, boxes) {
12232
13206
  const cos = Math.cos(toward);
12233
13207
  const sin = Math.sin(toward);
13208
+ const across = centred(cos);
12234
13209
  let exit;
12235
- for (const { x, y, width, height } of boxes) {
12236
- const leaving = leaves(from, cos, sin, {
12237
- x: x - PAST_LABEL,
12238
- y: y - PAST_LABEL,
12239
- width: width + 12,
12240
- height: height + 12
12241
- });
13210
+ for (const box of boxes) {
13211
+ const grown = grow(box, PAST_LABEL);
13212
+ let leaving = leaves(from, cos, sin, grown);
13213
+ if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
12242
13214
  if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
12243
13215
  }
12244
13216
  return exit;
12245
13217
  }
12246
13218
  function leaves(from, cos, sin, box) {
13219
+ return span(from, cos, sin, box)?.[1];
13220
+ }
13221
+ function span(from, cos, sin, box) {
12247
13222
  let near = 0;
12248
13223
  let far = Infinity;
12249
13224
  for (const [origin, step, lo, hi] of [[
@@ -12266,7 +13241,7 @@ function leaves(from, cos, sin, box) {
12266
13241
  near = Math.max(near, Math.min(a, b));
12267
13242
  far = Math.min(far, Math.max(a, b));
12268
13243
  }
12269
- return far >= near ? far : void 0;
13244
+ return far >= near ? [near, far] : void 0;
12270
13245
  }
12271
13246
  function caption(mark, data, ctx, color, words) {
12272
13247
  let current = mark;
@@ -12274,13 +13249,22 @@ function caption(mark, data, ctx, color, words) {
12274
13249
  let latest = data;
12275
13250
  let progress = 0;
12276
13251
  let handle;
13252
+ const { texts } = ctx;
12277
13253
  const draw = () => {
12278
13254
  if (content === "") {
12279
13255
  handle?.remove();
12280
13256
  handle = void 0;
13257
+ texts?.hold(void 0);
12281
13258
  return;
12282
13259
  }
12283
- const { at, anchor, toward } = captionPlace(current);
13260
+ const { at, anchor, toward } = captionPlace(current, texts && {
13261
+ held: texts.held(),
13262
+ box: (style) => texts.box(content, style)
13263
+ });
13264
+ texts?.hold(texts.box(content, {
13265
+ at,
13266
+ anchor
13267
+ }));
12284
13268
  const style = {
12285
13269
  at: offset(at, toward - Math.PI / 2, -8 * (1 - progress)),
12286
13270
  anchor,
@@ -12568,6 +13552,9 @@ const show = (value) => typeof value === "string" ? JSON.stringify(value) : Stri
12568
13552
  const DURATION = 950;
12569
13553
  const POINTS = 160;
12570
13554
  const ALIGNS = ["unroll", "drop"];
13555
+ const SAME_T = 1e-9;
13556
+ const GRID = 9;
13557
+ const CHECKS = 8;
12571
13558
  function morph(options = {}) {
12572
13559
  checkOptions(options);
12573
13560
  const points = options?.points ?? POINTS;
@@ -12607,11 +13594,12 @@ function drawing(from, to, layer, points, align) {
12607
13594
  if (closed !== to.outline.closed) return crossfade(from, to, layer);
12608
13595
  const a = from.outline.sample(points);
12609
13596
  const b = to.outline.sample(points);
12610
- if (!closed) return stroke(from, to, layer, a, b);
13597
+ if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
12611
13598
  const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
13599
+ const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
12612
13600
  let path;
12613
13601
  return (p) => {
12614
- const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true);
13602
+ 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("");
12615
13603
  if (path) path.update(d);
12616
13604
  else path = layer.path(d, { fill: "mark" });
12617
13605
  };
@@ -12628,6 +13616,214 @@ function stroke(from, to, layer, a, b) {
12628
13616
  });
12629
13617
  };
12630
13618
  }
13619
+ function gapped(from, to, layer, a, b) {
13620
+ const n = a.length;
13621
+ const stops = a.map((point, i) => ({
13622
+ t: i / (n - 1),
13623
+ from: point,
13624
+ to: b[i]
13625
+ }));
13626
+ 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({
13627
+ t,
13628
+ from: from.path(t),
13629
+ to: to.path(t)
13630
+ });
13631
+ stops.sort((x, y) => x.t - y.t);
13632
+ const runs = [
13633
+ [],
13634
+ [],
13635
+ []
13636
+ ];
13637
+ for (let k = 0; k + 1 < stops.length; k++) {
13638
+ const t = (stops[k].t + stops[k + 1].t) / 2;
13639
+ const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
13640
+ if (kind === 3) continue;
13641
+ const last = runs[kind][runs[kind].length - 1];
13642
+ if (last && last[1] === k) last[1] = k + 1;
13643
+ else runs[kind].push([k, k + 1]);
13644
+ }
13645
+ const kinds = [
13646
+ 0,
13647
+ 1,
13648
+ 2
13649
+ ].filter((kind) => runs[kind].length > 0).sort((x, y) => runs[x][0][0] - runs[y][0][0]);
13650
+ const paths = [];
13651
+ return (p) => {
13652
+ const width = p <= 0 ? from.thickness : p >= 1 ? to.thickness : mix(from.thickness, to.thickness, p);
13653
+ const opacities = [
13654
+ void 0,
13655
+ p,
13656
+ 1 - p
13657
+ ];
13658
+ const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] : kinds.map((kind) => [runs[kind].map((run) => along(stops, run, p)).join(""), opacities[kind]]);
13659
+ pieces.forEach(([d, opacity], i) => {
13660
+ if (paths[i]) paths[i].update(d, {
13661
+ width,
13662
+ opacity
13663
+ });
13664
+ else paths[i] = layer.path(d, {
13665
+ stroke: "mark",
13666
+ width,
13667
+ ...opacity === void 0 ? {} : { opacity }
13668
+ });
13669
+ });
13670
+ for (const path of paths.splice(pieces.length)) path.remove();
13671
+ };
13672
+ }
13673
+ const inGap = (mark, t) => (mark.gaps ?? []).some(([x, y]) => x < t && t < y);
13674
+ function along(stops, [first, last], p) {
13675
+ let d = "";
13676
+ for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
13677
+ return d;
13678
+ }
13679
+ function holePairs(from, to, a, b, [shiftA, shiftB], count) {
13680
+ const holesA = holesOf(from.outline, count);
13681
+ const holesB = holesOf(to.outline, count);
13682
+ const both = Math.min(holesA.length, holesB.length);
13683
+ const pairs = holesA.slice(0, both).map((hole, k) => ({
13684
+ from: hole.points,
13685
+ to: holesB[k].points
13686
+ }));
13687
+ const closes = holesA.length > holesB.length;
13688
+ const [ownHoles, otherHoles, other, own, theirs, ownShift, otherShift] = closes ? [
13689
+ holesA,
13690
+ holesB,
13691
+ to,
13692
+ a,
13693
+ b,
13694
+ shiftA,
13695
+ shiftB
13696
+ ] : [
13697
+ holesB,
13698
+ holesA,
13699
+ from,
13700
+ b,
13701
+ a,
13702
+ shiftB,
13703
+ shiftA
13704
+ ];
13705
+ const n = own.length;
13706
+ const outside = own.map((_, i) => [own[(i + ownShift) % n], theirs[(i + otherShift) % n]]);
13707
+ const inner = ownHoles.slice(0, both).map((hole, k) => hole.points.map((p, i) => [p, otherHoles[k].points[i]]));
13708
+ const area = [theirs, ...otherHoles.map((hole) => hole.points)];
13709
+ for (const hole of ownHoles.slice(both)) {
13710
+ const { end, point } = closing(hole, landing(hole, (closes ? from : to).bounds, other, area), outside, inner);
13711
+ const dot = new Array(count).fill(point);
13712
+ pairs.push(closes ? {
13713
+ from: hole.points,
13714
+ to: dot,
13715
+ end
13716
+ } : {
13717
+ from: dot,
13718
+ to: hole.points,
13719
+ end,
13720
+ opens: true
13721
+ });
13722
+ }
13723
+ return pairs;
13724
+ }
13725
+ function closing(hole, there, outside, inner) {
13726
+ let end = .5;
13727
+ while (end > 1 / 16 && !stays(hole, mixed(hole.center, there, end), end, outside, inner)) end /= 2;
13728
+ return {
13729
+ end,
13730
+ point: mixed(hole.center, there, end)
13731
+ };
13732
+ }
13733
+ function stays(hole, point, end, outside, inner) {
13734
+ for (let j = 1; j < CHECKS; j++) {
13735
+ const t = end * j / CHECKS;
13736
+ const at = (path) => mixed(path[0], path[1], t);
13737
+ const area = [outside.map(at), ...inner.map((ring) => ring.map(at))];
13738
+ if (hole.points.some((p) => windingAt(mixed(p, point, j / CHECKS), area) === 0)) return false;
13739
+ }
13740
+ return true;
13741
+ }
13742
+ function holeAt({ from, to, end, opens }, p) {
13743
+ if (end === void 0) return between(from, to, 0, 0, p, true);
13744
+ const q = opens ? (p - (1 - end)) / end : p / end;
13745
+ return (opens ? q <= 0 : q >= 1) ? "" : between(from, to, 0, 0, q, true);
13746
+ }
13747
+ const mixed = (a, b, t) => ({
13748
+ x: mix(a.x, b.x, t),
13749
+ y: mix(a.y, b.y, t)
13750
+ });
13751
+ function landing(hole, own, other, area) {
13752
+ const place = placeIn(hole.center, own, other.bounds);
13753
+ if (depth(place, area) >= hole.size / 4) return place;
13754
+ const { x, y, width, height } = other.bounds;
13755
+ let best = other.center;
13756
+ let deepest = depth(best, area);
13757
+ for (let i = 0; i < GRID; i++) for (let j = 0; j < GRID; j++) {
13758
+ const point = {
13759
+ x: x + width * (i + .5) / GRID,
13760
+ y: y + height * (j + .5) / GRID
13761
+ };
13762
+ const d = depth(point, area);
13763
+ if (d > deepest) [best, deepest] = [point, d];
13764
+ }
13765
+ return best;
13766
+ }
13767
+ function depth(point, area) {
13768
+ if (windingAt(point, area) === 0) return 0;
13769
+ let nearest = Infinity;
13770
+ for (const ring of area) ring.forEach((p, i) => {
13771
+ const q = ring[(i + 1) % ring.length];
13772
+ const dx = q.x - p.x;
13773
+ const dy = q.y - p.y;
13774
+ 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)));
13775
+ nearest = Math.min(nearest, Math.hypot(point.x - p.x - u * dx, point.y - p.y - u * dy));
13776
+ });
13777
+ return nearest;
13778
+ }
13779
+ function windingAt(point, area) {
13780
+ let winding = 0;
13781
+ for (const ring of area) ring.forEach((p, i) => {
13782
+ const q = ring[(i + 1) % ring.length];
13783
+ const side = (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);
13784
+ if (p.y <= point.y && q.y > point.y && side > 0) winding++;
13785
+ else if (p.y > point.y && q.y <= point.y && side < 0) winding--;
13786
+ });
13787
+ return winding;
13788
+ }
13789
+ function placeIn(point, own, other) {
13790
+ const fraction = (value, start, size) => size > 0 ? (value - start) / size : .5;
13791
+ return {
13792
+ x: other.x + fraction(point.x, own.x, own.width) * other.width,
13793
+ y: other.y + fraction(point.y, own.y, own.height) * other.height
13794
+ };
13795
+ }
13796
+ function holesOf(outline, count) {
13797
+ const loops = flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
13798
+ if (loops.length < 2) return [];
13799
+ const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
13800
+ let longest = 0;
13801
+ lengths.forEach((length, i) => {
13802
+ if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
13803
+ });
13804
+ return loops.filter((_, i) => i !== longest).map((loop) => {
13805
+ const round = loopOutline([loop]).sample(4 * count);
13806
+ const points = round.filter((_, i) => i % 4 === 0);
13807
+ const box = boundsOf(loop.flatMap(extremes));
13808
+ return {
13809
+ points: [points[0], ...points.slice(1).reverse()],
13810
+ area: Math.abs(areaOf(round)),
13811
+ center: {
13812
+ x: box.x + box.width / 2,
13813
+ y: box.y + box.height / 2
13814
+ },
13815
+ size: Math.max(box.width, box.height) / 2
13816
+ };
13817
+ }).sort((x, y) => y.area - x.area);
13818
+ }
13819
+ function areaOf(points) {
13820
+ let sum = 0;
13821
+ points.forEach((p, i) => {
13822
+ const q = points[(i + 1) % points.length];
13823
+ sum += p.x * q.y - q.x * p.y;
13824
+ });
13825
+ return sum / 2;
13826
+ }
12631
13827
  function crossfade(from, to, layer) {
12632
13828
  const paint = (mark, opacity) => ({
12633
13829
  ...mark.outline.closed ? { fill: "mark" } : {
@@ -12661,13 +13857,10 @@ function crossfade(from, to, layer) {
12661
13857
  function between(a, b, shiftA, shiftB, p, closed) {
12662
13858
  const n = a.length;
12663
13859
  let d = "";
12664
- for (let i = 0; i < n; i++) {
12665
- const from = a[(i + shiftA) % n];
12666
- const to = b[(i + shiftB) % n];
12667
- d += `${i === 0 ? "M" : "L"}${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
12668
- }
13860
+ for (let i = 0; i < n; i++) d += `${i === 0 ? "M" : "L"}${at(a[(i + shiftA) % n], b[(i + shiftB) % n], p)}`;
12669
13861
  return closed ? `${d}Z` : d;
12670
13862
  }
13863
+ const at = (from, to, p) => `${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
12671
13864
  const mix = (x, y, p) => x * (1 - p) + y * p;
12672
13865
  function turn(from, to, points) {
12673
13866
  const quarter = points / 4;
@@ -13277,7 +14470,7 @@ function configure(options) {
13277
14470
  }
13278
14471
  }
13279
14472
  // src/index.ts
13280
- const VERSION = "0.4.0";
14473
+ const VERSION = "0.6.0";
13281
14474
  const env = {
13282
14475
  presets: presetRegistry,
13283
14476
  icons: iconRegistry,