expressive-charts 0.5.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.js CHANGED
@@ -1,5 +1,5 @@
1
- import { A as easeInOutCubic, C as tween, D as mediaReducedMotion, E as defaultScaling, F as defaultClock, I as manualClock, L as report, M as linear, N as unease, O as motion, P as createClock, S as describeArc, T as createMotion, _ as FLAT, a as mergeFields, b as describeLine, c as describeValue$1, d as describe, f as describeShape, g as transformPath, h as shapeOutline, j as easeOutCubic, k as scaleDuration, l as isMarkEffect, m as parsePath, n as playTransition, o as EFFECT_SLOTS, p as formatPath, r as createRunner, s as createRegistry, t as isTransitionEffect, u as resolveEffects, v as cubicPieces, w as TIMINGS, x as describeBar, y as describePoint } from "./transition-Bu1NsQor.js";
2
- import { d as normalizeAngle, n as formatNumber } from "./path-data-DnEckjY8.js";
1
+ import { A as TIMINGS, B as createClock, C as flattenPath, D as describeArc, E as describeBar, F as scaleDuration, H as manualClock, I as easeInOutCubic, L as easeOutCubic, M as defaultScaling, N as mediaReducedMotion, O as loopOutline, P as motion, R as linear, S as cubicPieces, T as describeLine, U as report, V as defaultClock, _ as formatPath, a as AVERAGE_WIDTH, b as transformPath, d as createRegistry, f as describeValue$1, g as describeShape, h as describe, j as createMotion, k as tween, l as mergeFields, m as resolveEffects, n as playTransition, o as TEXT_SIZE, p as isMarkEffect, r as createRunner, s as boxAround, t as isTransitionEffect, u as EFFECT_SLOTS, v as parsePath, w as describePoint, x as FLAT, y as shapeOutline, z as unease } from "./transition-romki_A6.js";
2
+ import { a as TAU$2, c as boundsOf, d as normalizeAngle, f as pointOn, l as extremes, n as formatNumber } from "./path-data-DnEckjY8.js";
3
3
  import { t as defineIcon } from "./define-DeZLs1h7.js";
4
4
  // src/core/animated.ts
5
5
  const interpolateNumber = (a, b) => (t) => a * (1 - t) + b * t;
@@ -421,9 +421,9 @@ function samplesAlong(mark, points) {
421
421
  ...p.at === void 0 ? {} : { at: p.at }
422
422
  }
423
423
  })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
424
- return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
424
+ return mark.gaps && mark.gaps.length > 0 ? gapped$1(samples, mark.gaps) : samples;
425
425
  }
426
- function gapped(samples, gaps) {
426
+ function gapped$1(samples, gaps) {
427
427
  const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
428
428
  let next = 0;
429
429
  return samples.map((sample, k) => {
@@ -555,16 +555,8 @@ function linear$1(value) {
555
555
  return rounded === 0 ? "0" : String(rounded);
556
556
  }
557
557
  // src/charts/render/text.ts
558
- const ASCENT$1 = 1.05;
559
- const SIDE = .16;
560
558
  function textBox(placement, measure, className, size) {
561
- const width = measure(placement.text.replace(/\d/g, "0"), className, size);
562
- return {
563
- x: (placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2) - SIDE * size,
564
- y: placement.y - ASCENT$1 * size,
565
- width: width + 2 * SIDE * size,
566
- height: 1.3 * size
567
- };
559
+ return boxAround(placement, placement.anchor, measure(placement.text.replace(/\d/g, "0"), className, size), size);
568
560
  }
569
561
  function placeText(element, placement) {
570
562
  setAttributes(element, {
@@ -574,7 +566,6 @@ function placeText(element, placement) {
574
566
  });
575
567
  if (element.textContent !== placement.text) element.textContent = placement.text;
576
568
  }
577
- const AVERAGE_WIDTH = .6;
578
569
  function textMeasure(svg) {
579
570
  const cache = /* @__PURE__ */ new Map();
580
571
  const measure = (text, className, size) => {
@@ -1783,6 +1774,7 @@ function styleText(element, style) {
1783
1774
  // src/charts/render/surface.ts
1784
1775
  function svgSurface(options) {
1785
1776
  const { overlay } = options;
1777
+ const measure = options.measure ?? textMeasure(overlay);
1786
1778
  const orders = /* @__PURE__ */ new WeakMap();
1787
1779
  const groups = /* @__PURE__ */ new Map();
1788
1780
  const hidden = /* @__PURE__ */ new Set();
@@ -1818,6 +1810,12 @@ function svgSurface(options) {
1818
1810
  }
1819
1811
  };
1820
1812
  },
1813
+ box: (text, { at, anchor = "start" }) => textBox({
1814
+ x: at.x,
1815
+ y: at.y,
1816
+ anchor,
1817
+ text
1818
+ }, measure, "ec-text", TEXT_SIZE),
1821
1819
  mark(key) {
1822
1820
  const handle = options.mark(key);
1823
1821
  return {
@@ -1913,13 +1911,13 @@ function decimals(value) {
1913
1911
  const point = text.indexOf(".");
1914
1912
  return point < 0 ? 0 : Math.min(6, text.length - point - 1);
1915
1913
  }
1916
- function round$4(value, digits) {
1914
+ function round$5(value, digits) {
1917
1915
  const factor = 10 ** digits;
1918
1916
  const rounded = Math.round(value * factor) / factor;
1919
1917
  return rounded === 0 ? 0 : rounded;
1920
1918
  }
1921
1919
  function percent(share) {
1922
- return `${round$4(share * 100, 0)}%`;
1920
+ return `${round$5(share * 100, 0)}%`;
1923
1921
  }
1924
1922
  // src/charts/interaction.ts
1925
1923
  function pointerHover(svg, options) {
@@ -3209,7 +3207,7 @@ function chartTooltip(svg, options) {
3209
3207
  top: dy + near.top,
3210
3208
  bottom: dy + near.bottom
3211
3209
  };
3212
- shape = span(bridge, {
3210
+ shape = span$1(bridge, {
3213
3211
  left,
3214
3212
  top,
3215
3213
  ...size
@@ -3308,7 +3306,7 @@ function inside$1({ top, bottom, upper, lower }, x, y) {
3308
3306
  const t = (y - top) / (bottom - top);
3309
3307
  return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
3310
3308
  }
3311
- function span(bridge, box, mark, side) {
3309
+ function span$1(bridge, box, mark, side) {
3312
3310
  bridge.hidden = mark === void 0;
3313
3311
  if (!mark) return void 0;
3314
3312
  const edge = {
@@ -3449,6 +3447,7 @@ function barChart$1(target, options, env) {
3449
3447
  const find = (key) => records.get(key) ?? leaving.get(key);
3450
3448
  const surface = svgSurface({
3451
3449
  overlay,
3450
+ measure,
3452
3451
  mark: (key) => ({
3453
3452
  set: (style) => {
3454
3453
  find(key)?.handle.set(style);
@@ -3701,7 +3700,7 @@ function barChart$1(target, options, env) {
3701
3700
  value: now[series] ?? 0
3702
3701
  }));
3703
3702
  const total = values.reduce((sum, v) => sum + v.value, 0);
3704
- const text = record.count === void 0 ? row.value.text : format(current)(round$4(total, record.count));
3703
+ const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
3705
3704
  return placeRow(frame, {
3706
3705
  key: row.key,
3707
3706
  datum: row.datum,
@@ -4006,6 +4005,14 @@ function barChart$1(target, options, env) {
4006
4005
  if (!destroyed) hover.leave();
4007
4006
  },
4008
4007
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.shown.label, record.label), ...chartLabel(record.key, "value", record.shown.value, record.value)]),
4008
+ paintOf(key) {
4009
+ const record = records.get(key);
4010
+ const first = record?.shown.geometry.segments?.[0];
4011
+ return record && {
4012
+ color: byCategory(current) ? key : first?.series ?? first?.key ?? key,
4013
+ drawn: true
4014
+ };
4015
+ },
4009
4016
  destroy() {
4010
4017
  if (destroyed) return;
4011
4018
  destroyed = true;
@@ -4171,26 +4178,8 @@ function joinedStarts(values) {
4171
4178
  });
4172
4179
  }
4173
4180
  function placeSlices(frame, states, labels, measure) {
4174
- const boxes = labels.map((label) => label ? labelBoxes(label, measure) : void 0);
4175
- const labelled = boxes.flatMap((box, i) => box ? [i] : []);
4176
- const first = labelled[0];
4177
- const last = labelled[labelled.length - 1];
4178
- const before = [];
4179
- const after = [];
4180
- let seen;
4181
- for (let i = 0; i < states.length; i++) {
4182
- before[i] = seen ?? (last === i ? void 0 : last);
4183
- if (boxes[i]) seen = i;
4184
- }
4185
- seen = void 0;
4186
- for (let i = states.length - 1; i >= 0; i--) {
4187
- after[i] = seen ?? (first === i ? void 0 : first);
4188
- if (boxes[i]) seen = i;
4189
- }
4190
- return states.map((state, i) => {
4191
- const sides = before[i] === after[i] ? [before[i]] : [before[i], after[i]];
4192
- return placeSlice(frame, state, labels[i], measure, sides.flatMap((j) => j === void 0 ? [] : boxes[j]));
4193
- });
4181
+ const boxes = labels.map((label) => label ? labelBoxes(label, measure) : []);
4182
+ return states.map((state, i) => placeSlice(frame, state, labels[i], measure, boxes.flatMap((box, j) => j === i ? [] : box)));
4194
4183
  }
4195
4184
  function placeSlice(frame, state, label, measure, nearby) {
4196
4185
  const geometry = describeArc({
@@ -4406,6 +4395,7 @@ function donutChart$1(target, options, env) {
4406
4395
  const find = (key) => records.get(key) ?? leaving.get(key);
4407
4396
  const surface = svgSurface({
4408
4397
  overlay: runs,
4398
+ measure,
4409
4399
  mark: (key) => ({
4410
4400
  set: (style) => {
4411
4401
  find(key)?.handle.set(style);
@@ -4709,7 +4699,7 @@ function donutChart$1(target, options, env) {
4709
4699
  const slices = currentSlices(f);
4710
4700
  for (const { record, slice, label } of slices) show(record, slice, label);
4711
4701
  const total = slices.reduce((sum, { slice }) => sum + slice.value, 0);
4712
- drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$4(total, count)), measure));
4702
+ drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$5(total, count)), measure));
4713
4703
  }
4714
4704
  function counting(total) {
4715
4705
  if (counted?.total !== total) counted = {
@@ -4983,6 +4973,10 @@ function donutChart$1(target, options, env) {
4983
4973
  if (!destroyed) hover.leave();
4984
4974
  },
4985
4975
  labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.drawnLabel?.category, record.label), ...chartLabel(record.key, "value", record.drawnLabel?.share, record.share)]),
4976
+ paintOf: (key) => records.has(key) ? {
4977
+ color: key,
4978
+ drawn: true
4979
+ } : void 0,
4986
4980
  destroy() {
4987
4981
  if (destroyed) return;
4988
4982
  destroyed = true;
@@ -5574,7 +5568,7 @@ function layoutLines(input) {
5574
5568
  const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
5575
5569
  const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
5576
5570
  const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
5577
- const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0);
5571
+ const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (input.room ?? 0));
5578
5572
  const frame = {
5579
5573
  scale: {
5580
5574
  lo: domain.lo,
@@ -6083,7 +6077,7 @@ function lineChart$1(target, options, env) {
6083
6077
  try {
6084
6078
  laidOut = layout(current);
6085
6079
  firstTable = tableFor(current, laidOut);
6086
- names = namesFor(current, laidOut);
6080
+ names = hoverKind === "x" ? namesFor(current, laidOut) : void 0;
6087
6081
  pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
6088
6082
  } catch (error) {
6089
6083
  svg.remove();
@@ -6092,6 +6086,7 @@ function lineChart$1(target, options, env) {
6092
6086
  const findMark = (key) => points.get(key) ?? lines.get(key) ?? leaving.get(key);
6093
6087
  const surface = svgSurface({
6094
6088
  overlay,
6089
+ measure,
6095
6090
  mark: (key) => ({
6096
6091
  set: (style) => {
6097
6092
  findMark(key)?.handle.set(style);
@@ -6157,6 +6152,8 @@ function lineChart$1(target, options, env) {
6157
6152
  function layout(opts, using = effects) {
6158
6153
  const encoding = lineEncoding(opts);
6159
6154
  checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
6155
+ const { room = 0 } = opts;
6156
+ 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)}.`);
6160
6157
  const next = layoutLines({
6161
6158
  data: opts.data,
6162
6159
  encoding,
@@ -6164,7 +6161,8 @@ function lineChart$1(target, options, env) {
6164
6161
  height: opts.height,
6165
6162
  format: format(opts),
6166
6163
  measure,
6167
- label: labeler(opts, true)
6164
+ label: labeler(opts, true),
6165
+ room
6168
6166
  });
6169
6167
  const keys = new Set(next.series);
6170
6168
  for (const row of next.rows) for (const name of next.series) {
@@ -6198,7 +6196,7 @@ function lineChart$1(target, options, env) {
6198
6196
  const label = labeler(current);
6199
6197
  if (!label) return void 0;
6200
6198
  return {
6201
- text: (series, value) => label(series, round$4(value, given[series] ?? decimals(value))),
6199
+ text: (series, value) => label(series, round$5(value, given[series] ?? decimals(value))),
6202
6200
  measure
6203
6201
  };
6204
6202
  }
@@ -6662,23 +6660,42 @@ function lineChart$1(target, options, env) {
6662
6660
  }
6663
6661
  const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
6664
6662
  function nearestPoint(at) {
6663
+ const shown = rowOrder.filter(revealed).flatMap(livePoints);
6665
6664
  let best;
6666
6665
  let far = Infinity;
6667
6666
  let rank = Infinity;
6668
- for (const record of rowOrder) {
6669
- if (!revealed(record)) continue;
6670
- for (const point of livePoints(record)) {
6671
- const { x, y } = point.shown.geometry.center;
6672
- const d = (x - at.x) ** 2 + (y - at.y) ** 2;
6673
- const r = laidOut.series.indexOf(point.series);
6674
- if (d < far || d === far && r < rank) [best, far, rank] = [
6675
- point,
6676
- d,
6677
- r
6678
- ];
6679
- }
6667
+ for (const point of shown) {
6668
+ const d = apart(point.shown.geometry.center, at);
6669
+ const r = laidOut.series.indexOf(point.series);
6670
+ if (d < far || d === far && r < rank) [best, far, rank] = [
6671
+ point,
6672
+ d,
6673
+ r
6674
+ ];
6675
+ }
6676
+ if (!best) return void 0;
6677
+ const center = best.shown.geometry.center;
6678
+ const on = /* @__PURE__ */ new Map();
6679
+ for (const point of shown) {
6680
+ const { center: c } = point.shown.geometry;
6681
+ const known = on.get(point.series);
6682
+ if (apart(c, center) <= 1 && (!known || apart(c, at) < apart(known.shown.geometry.center, at))) on.set(point.series, point);
6683
+ }
6684
+ if (on.size < 2) return best;
6685
+ let pick = best;
6686
+ let near = Infinity;
6687
+ for (const series of laidOut.series) {
6688
+ const point = on.get(series);
6689
+ if (!point) continue;
6690
+ const d = passing(point, at);
6691
+ if (d < near) [pick, near] = [point, d];
6680
6692
  }
6681
- return best;
6693
+ return pick;
6694
+ }
6695
+ function passing(point, at) {
6696
+ const { geometry, data } = point.shown;
6697
+ const line = lines.get(point.series);
6698
+ return (line && strokeNear(line.shown, data.samples[0].at, geometry.center, at, 9)) ?? Math.max(0, Math.hypot(at.x - geometry.center.x, at.y - geometry.center.y) - 4.5);
6682
6699
  }
6683
6700
  function heldPoint(at) {
6684
6701
  const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
@@ -6924,8 +6941,9 @@ function lineChart$1(target, options, env) {
6924
6941
  });
6925
6942
  }
6926
6943
  function labelColumn(record) {
6944
+ if (hoverKind !== "x") return;
6927
6945
  record.column.setAttribute("aria-label", names.get(record.key));
6928
- if (hoverKind === "x") tooltip.describe(record.column, record.row);
6946
+ tooltip.describe(record.column, record.row);
6929
6947
  }
6930
6948
  function announceChange(previous, before) {
6931
6949
  const option = current.announce;
@@ -7207,7 +7225,7 @@ function lineChart$1(target, options, env) {
7207
7225
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
7208
7226
  const nextLayout = layout(merged, swapped);
7209
7227
  const nextTable = tableFor(merged, nextLayout);
7210
- const nextNames = namesFor(merged, nextLayout);
7228
+ const nextNames = kind === "x" ? namesFor(merged, nextLayout) : void 0;
7211
7229
  const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
7212
7230
  if ("colors" in next) colors = toColorAssignment(merged.colors);
7213
7231
  const previous = current;
@@ -7276,6 +7294,16 @@ function lineChart$1(target, options, env) {
7276
7294
  if (!destroyed) hover.leave();
7277
7295
  },
7278
7296
  labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
7297
+ paintOf(key) {
7298
+ const record = lines.get(key) ?? points.get(key);
7299
+ return record && {
7300
+ color: record.series,
7301
+ drawn: record.kind === "line" || record.group.classList.contains("ec-alone")
7302
+ };
7303
+ },
7304
+ standsFor(key) {
7305
+ return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
7306
+ },
7279
7307
  destroy() {
7280
7308
  if (destroyed) return;
7281
7309
  destroyed = true;
@@ -7350,6 +7378,36 @@ function sameData(a, b) {
7350
7378
  function sameAt(a, b) {
7351
7379
  return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
7352
7380
  }
7381
+ function apart(a, b) {
7382
+ return (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
7383
+ }
7384
+ function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
7385
+ const i = samples.findIndex((sample) => sameAt(sample.at, x));
7386
+ if (i < 0 || !(geometry.length > 0)) return void 0;
7387
+ const t = samples[i].t;
7388
+ const span = reach / geometry.length;
7389
+ let near;
7390
+ for (const way of [-1, 1]) {
7391
+ let a = from;
7392
+ for (let j = i;; j += way) {
7393
+ const next = samples[j + way];
7394
+ if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
7395
+ const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
7396
+ const b = geometry.path(to);
7397
+ near = Math.min(near ?? Infinity, toSegment(at, a, b));
7398
+ if (to !== next.t) break;
7399
+ a = b;
7400
+ }
7401
+ }
7402
+ return near;
7403
+ }
7404
+ function toSegment(p, a, b) {
7405
+ const dx = b.x - a.x;
7406
+ const dy = b.y - a.y;
7407
+ const length = dx * dx + dy * dy;
7408
+ const u = length > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / length)) : 0;
7409
+ return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
7410
+ }
7353
7411
  function labelled(values, options) {
7354
7412
  return present(values).map((v) => ({
7355
7413
  series: v.series,
@@ -7421,10 +7479,10 @@ function hoverOf(options) {
7421
7479
  // src/core/geometry/ring.ts
7422
7480
  const ROUND = .5;
7423
7481
  function goesRound(mark) {
7424
- const radius = distance$1(mark.start, mark.pivot);
7425
- return radius > ROUND && Math.abs(distance$1(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$1(mark.end, mark.pivot) - radius) <= ROUND;
7482
+ const radius = distance$2(mark.start, mark.pivot);
7483
+ return radius > ROUND && Math.abs(distance$2(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$2(mark.end, mark.pivot) - radius) <= ROUND;
7426
7484
  }
7427
- const distance$1 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
7485
+ const distance$2 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
7428
7486
  // src/charts/adapter/bars.ts
7429
7487
  const SAME = .5;
7430
7488
  const BASELINES = [
@@ -7473,10 +7531,10 @@ function describeRects(key, parts, baseline) {
7473
7531
  ...box,
7474
7532
  baseline,
7475
7533
  radius: tip.radius,
7476
- gap: Number.isFinite(gap) ? Math.max(0, round$3(gap)) : 0,
7534
+ gap: Number.isFinite(gap) ? Math.max(0, round$4(gap)) : 0,
7477
7535
  ...segments.every((s) => s.series !== void 0) ? { segments: segments.map((s) => ({
7478
7536
  series: s.series,
7479
- size: round$3(s.size)
7537
+ size: round$4(s.size)
7480
7538
  })) } : {}
7481
7539
  }),
7482
7540
  order: order.map((o) => o.index)
@@ -7494,8 +7552,8 @@ function union(boxes) {
7494
7552
  return {
7495
7553
  x,
7496
7554
  y,
7497
- width: round$3(Math.max(...boxes.map((b) => b.x + b.width)) - x),
7498
- height: round$3(Math.max(...boxes.map((b) => b.y + b.height)) - y)
7555
+ width: round$4(Math.max(...boxes.map((b) => b.x + b.width)) - x),
7556
+ height: round$4(Math.max(...boxes.map((b) => b.y + b.height)) - y)
7499
7557
  };
7500
7558
  }
7501
7559
  function commonLine(boxes, nearEdge, farEdge, near, far) {
@@ -7536,7 +7594,7 @@ function spanFrom(mark, baseline) {
7536
7594
  });
7537
7595
  }
7538
7596
  }
7539
- function round$3(value) {
7597
+ function round$4(value) {
7540
7598
  return Math.round(value * 1e3) / 1e3;
7541
7599
  }
7542
7600
  // src/charts/adapter/edits.ts
@@ -7712,13 +7770,13 @@ function boxIn(m, rect) {
7712
7770
  ].map((corner) => matrix.apply(m, corner));
7713
7771
  const xs = corners.map((p) => p.x);
7714
7772
  const ys = corners.map((p) => p.y);
7715
- const x = round$2(Math.min(...xs));
7716
- const y = round$2(Math.min(...ys));
7773
+ const x = round$3(Math.min(...xs));
7774
+ const y = round$3(Math.min(...ys));
7717
7775
  return {
7718
7776
  x,
7719
7777
  y,
7720
- width: round$2(round$2(Math.max(...xs)) - x),
7721
- height: round$2(round$2(Math.max(...ys)) - y)
7778
+ width: round$3(round$3(Math.max(...xs)) - x),
7779
+ height: round$3(round$3(Math.max(...ys)) - y)
7722
7780
  };
7723
7781
  }
7724
7782
  function rectOf(element) {
@@ -7736,6 +7794,7 @@ function rectOf(element) {
7736
7794
  }
7737
7795
  function attributesOf(element) {
7738
7796
  return (name) => {
7797
+ if (!element.hasAttribute(name)) return null;
7739
7798
  const animated = element[name];
7740
7799
  return typeof animated?.baseVal?.value === "number" ? String(animated.baseVal.value) : element.getAttribute(name);
7741
7800
  };
@@ -7763,7 +7822,7 @@ function fromRoot(element, root) {
7763
7822
  for (let node = element; node && node !== root; node = node.parentElement) m = matrix.multiply(ownTransform(node), m);
7764
7823
  return m;
7765
7824
  }
7766
- function round$2(value) {
7825
+ function round$3(value) {
7767
7826
  return Math.round(value * 1e3) / 1e3;
7768
7827
  }
7769
7828
  // src/charts/adapter/host-style.ts
@@ -7815,9 +7874,9 @@ function hostMarkHandle(parts, edits, halos) {
7815
7874
  };
7816
7875
  }
7817
7876
  function hostColors(element, root) {
7818
- const fill = paintOf(element, root, "fill");
7877
+ const fill = paintOf$1(element, root, "fill");
7819
7878
  const paint = fill === NONE ? "stroke" : "fill";
7820
- const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
7879
+ const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
7821
7880
  if (color === void 0 || color === NONE) return void 0;
7822
7881
  return {
7823
7882
  color,
@@ -7842,7 +7901,7 @@ function attributesComputed(root) {
7842
7901
  probed.set(root, computed);
7843
7902
  return computed;
7844
7903
  }
7845
- function paintOf(element, root, property) {
7904
+ function paintOf$1(element, root, property) {
7846
7905
  const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property);
7847
7906
  const computed = kind(raw);
7848
7907
  if (raw && attributesComputed(root)) return computed;
@@ -7855,15 +7914,28 @@ function paintOf(element, root, property) {
7855
7914
  return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
7856
7915
  }
7857
7916
  function strokeWidthOf(element, root) {
7858
- const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue("stroke-width");
7917
+ const style = element.ownerDocument.defaultView?.getComputedStyle?.(element);
7918
+ const raw = style?.getPropertyValue("stroke-width");
7859
7919
  const computed = pixels$1(raw);
7860
- if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return computed;
7920
+ const effect = style?.getPropertyValue("vector-effect").trim().toLowerCase();
7921
+ const declared = element.style?.getPropertyValue("vector-effect") ? effect : element.getAttribute("vector-effect")?.trim().toLowerCase();
7922
+ const screen = (effect && (effect !== "none" || attributesComputed(root)) ? effect : declared) === "non-scaling-stroke";
7923
+ if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return {
7924
+ width: computed,
7925
+ screen
7926
+ };
7861
7927
  for (let node = element; node; node = node === root ? null : node.parentElement) {
7862
7928
  if (node.style?.getPropertyValue("stroke-width")) break;
7863
7929
  const width = pixels$1(node.getAttribute("stroke-width"));
7864
- if (width !== void 0) return width;
7930
+ if (width !== void 0) return {
7931
+ width,
7932
+ screen
7933
+ };
7865
7934
  }
7866
- return computed;
7935
+ return {
7936
+ width: computed,
7937
+ screen
7938
+ };
7867
7939
  }
7868
7940
  function pixels$1(value) {
7869
7941
  const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(?:px\s*)?$/i.exec(value ?? "");
@@ -7885,6 +7957,183 @@ function mix$2(colors, emphasis) {
7885
7957
  function cssMatrix(m) {
7886
7958
  return `matrix(${m.map((v, i) => i < 4 ? Math.round(v * 1e6) / 1e6 : Math.round(v * 1e3) / 1e3).join(", ")})`;
7887
7959
  }
7960
+ // src/charts/adapter/slice.ts
7961
+ const NEAR = .5;
7962
+ const MOST = 32;
7963
+ function sliceOf$1(commands, m) {
7964
+ const scale = scaleOf$1(m);
7965
+ if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
7966
+ const near = NEAR / scale;
7967
+ const subpaths = flattenPath(commands);
7968
+ if (subpaths.length === 0 || subpaths.length > 2 || !subpaths.every(closes)) return void 0;
7969
+ const runs = subpaths.map((subpath) => runsOf(subpath.segments, near));
7970
+ const own = subpaths.length === 2 ? ring(runs[0], runs[1], near) : slice(runs[0], near);
7971
+ return own && moved(own, m);
7972
+ }
7973
+ function ring(a, b, near) {
7974
+ const [first, second] = [a[0], b[0]];
7975
+ if (a.length !== 1 || b.length !== 1 || first?.kind !== "arc" || second?.kind !== "arc") return void 0;
7976
+ const [outer, inner] = first.radius >= second.radius ? [first, second] : [second, first];
7977
+ const whole = (turn, radius) => Math.abs(Math.abs(turn) - TAU$2) * radius <= near;
7978
+ for (const center of [centerOf(outer), outer.arcs[0].center]) {
7979
+ if (!center) continue;
7980
+ const [r1, r0] = [distance$1(outer.from, center), distance$1(inner.from, center)];
7981
+ const [t1, t0] = [turnOf(outer, center), turnOf(inner, center)];
7982
+ 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 {
7983
+ center,
7984
+ inner: r0,
7985
+ outer: r1,
7986
+ start: angleOf(outer.from, center),
7987
+ sweep: Math.sign(t1) * TAU$2
7988
+ };
7989
+ }
7990
+ }
7991
+ function slice(runs, near) {
7992
+ let first = -1;
7993
+ runs.forEach((run, i) => {
7994
+ if (run.kind === "arc" && (first < 0 || run.radius > runs[first].radius)) first = i;
7995
+ });
7996
+ if (first < 0) return void 0;
7997
+ const cycle = [...runs.slice(first), ...runs.slice(0, first)];
7998
+ const outer = cycle[0];
7999
+ const [, side, third, fourth] = cycle;
8000
+ const pie = cycle.length === 3 && side?.kind === "line" && third?.kind === "line";
8001
+ const back = cycle.length === 4 && side?.kind === "line" && third?.kind === "arc" && fourth?.kind === "line" ? third : void 0;
8002
+ if (!pie && !back) return void 0;
8003
+ const [inEnd, inStart] = back ? [back.from, back.to] : [side.to, side.to];
8004
+ const toward = (from, to) => {
8005
+ const length = distance$1(from, to);
8006
+ return length > near ? {
8007
+ x: from.x + (to.x - from.x) * outer.radius / length,
8008
+ y: from.y + (to.y - from.y) * outer.radius / length
8009
+ } : void 0;
8010
+ };
8011
+ const a = toward(outer.from, inStart);
8012
+ const b = toward(outer.to, inEnd);
8013
+ if (!a || !b) return void 0;
8014
+ let center = {
8015
+ x: (a.x + b.x) / 2,
8016
+ y: (a.y + b.y) / 2
8017
+ };
8018
+ if (pie && distance$1(inEnd, center) <= near) center = inEnd;
8019
+ const inner = center === inEnd ? 0 : (distance$1(inEnd, center) + distance$1(inStart, center)) / 2;
8020
+ const sweep = turnOf(outer, center);
8021
+ if (sweep === 0) return void 0;
8022
+ const own = {
8023
+ center,
8024
+ inner,
8025
+ outer: (distance$1(outer.from, center) + distance$1(outer.to, center)) / 2,
8026
+ start: angleOf(outer.from, center),
8027
+ sweep
8028
+ };
8029
+ return checked(own, outer, back, [inEnd, inStart], near) ? own : void 0;
8030
+ }
8031
+ function checked(own, outer, back, [inEnd, inStart], near) {
8032
+ const { center, start, sweep } = own;
8033
+ const at = (radius, angle) => ({
8034
+ x: center.x + radius * Math.cos(angle),
8035
+ y: center.y + radius * Math.sin(angle)
8036
+ });
8037
+ 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));
8038
+ }
8039
+ function turnOf(run, center) {
8040
+ let turn = 0;
8041
+ for (const arc of run.arcs) {
8042
+ const step = normalizeAngle(angleOf(pointOn(arc, 1), center) - angleOf(pointOn(arc, 0), center));
8043
+ turn += step + TAU$2 * Math.round((arc.sweep - step) / TAU$2);
8044
+ }
8045
+ return turn;
8046
+ }
8047
+ function centerOf(run) {
8048
+ const points = [run.from, ...run.arcs.slice(0, -1).map((arc) => pointOn(arc, 1))];
8049
+ if (points.length < 2) return void 0;
8050
+ if (points.length === 2) return {
8051
+ x: (points[0].x + points[1].x) / 2,
8052
+ y: (points[0].y + points[1].y) / 2
8053
+ };
8054
+ const [p, q, r] = [
8055
+ points[0],
8056
+ points[Math.floor(points.length / 3)],
8057
+ points[Math.floor(2 * points.length / 3)]
8058
+ ];
8059
+ const d = 2 * (p.x * (q.y - r.y) + q.x * (r.y - p.y) + r.x * (p.y - q.y));
8060
+ if (!(Math.abs(d) > 0)) return void 0;
8061
+ const [pp, qq, rr] = [
8062
+ p,
8063
+ q,
8064
+ r
8065
+ ].map(({ x, y }) => x * x + y * y);
8066
+ return {
8067
+ x: (pp * (q.y - r.y) + qq * (r.y - p.y) + rr * (p.y - q.y)) / d,
8068
+ y: (pp * (r.x - q.x) + qq * (p.x - r.x) + rr * (q.x - p.x)) / d
8069
+ };
8070
+ }
8071
+ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <= near && run.arcs.every((arc) => [
8072
+ 0,
8073
+ .5,
8074
+ 1
8075
+ ].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
8076
+ function moved(own, m) {
8077
+ const scale = scaleOf$1(m);
8078
+ const center = matrix.apply(m, own.center);
8079
+ const corner = matrix.apply(m, {
8080
+ x: own.center.x + own.outer * Math.cos(own.start),
8081
+ y: own.center.y + own.outer * Math.sin(own.start)
8082
+ });
8083
+ const sweep = m[0] * m[3] - m[1] * m[2] < 0 ? -own.sweep : own.sweep;
8084
+ let start = ((angleOf(corner, center) + Math.PI / 2) % TAU$2 + TAU$2) % TAU$2;
8085
+ if (start > TAU$2 - 1e-9) start = 0;
8086
+ return {
8087
+ cx: round$2(center.x),
8088
+ cy: round$2(center.y),
8089
+ inner: round$2(own.inner * scale),
8090
+ outer: round$2(own.outer * scale),
8091
+ start,
8092
+ end: start + sweep
8093
+ };
8094
+ }
8095
+ function runsOf(segments, near) {
8096
+ const runs = [];
8097
+ const join = (run, arc) => run !== void 0 && Math.sign(run.sweep) === Math.sign(arc.sweep) && Math.abs(run.radius - arc.radius) <= near;
8098
+ for (const segment of segments) {
8099
+ const last = runs[runs.length - 1];
8100
+ if (segment.kind === "line") runs.push({
8101
+ kind: "line",
8102
+ from: segment.from,
8103
+ to: segment.to
8104
+ });
8105
+ else if (last?.kind === "arc" && join(last, segment)) runs[runs.length - 1] = {
8106
+ ...last,
8107
+ arcs: [...last.arcs, segment],
8108
+ to: pointOn(segment, 1),
8109
+ sweep: last.sweep + segment.sweep
8110
+ };
8111
+ else runs.push({
8112
+ kind: "arc",
8113
+ arcs: [segment],
8114
+ from: pointOn(segment, 0),
8115
+ to: pointOn(segment, 1),
8116
+ radius: segment.radius,
8117
+ sweep: segment.sweep
8118
+ });
8119
+ }
8120
+ const [head] = runs;
8121
+ const tail = runs[runs.length - 1];
8122
+ if (runs.length > 1 && head?.kind === "arc" && tail?.kind === "arc" && tail.arcs.every((arc) => join(head, arc))) {
8123
+ runs[0] = {
8124
+ ...head,
8125
+ arcs: [...tail.arcs, ...head.arcs],
8126
+ from: tail.from,
8127
+ sweep: tail.sweep + head.sweep
8128
+ };
8129
+ runs.pop();
8130
+ }
8131
+ return runs;
8132
+ }
8133
+ const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
8134
+ const angleOf = (point, center) => Math.atan2(point.y - center.y, point.x - center.x);
8135
+ const distance$1 = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
8136
+ const round$2 = (value) => Math.round(value * 1e3) / 1e3 + 0;
7888
8137
  // src/charts/adapter/source.ts
7889
8138
  function readSource(source) {
7890
8139
  if (typeof source === "string") {
@@ -8094,7 +8343,7 @@ function expressive$1(target, options, env) {
8094
8343
  common,
8095
8344
  screen: screenMatrices(),
8096
8345
  colors: (element) => colorsOf(element, svg),
8097
- strokeWidth: (element) => strokeWidthOf(element, svg)
8346
+ stroke: (element) => strokeWidthOf(element, svg)
8098
8347
  };
8099
8348
  const named = (mark) => ({
8100
8349
  ...mark,
@@ -8110,7 +8359,7 @@ function expressive$1(target, options, env) {
8110
8359
  const shapes = [];
8111
8360
  keys.forEach((key, index) => {
8112
8361
  const pieces = groups.get(key);
8113
- if (pieces[0].element.localName === "rect") bars.push(index);
8362
+ if (pieces[0].element.localName === "rect" && !turned(pieces, at)) bars.push(index);
8114
8363
  else {
8115
8364
  const mark = shapeMark(key, pieces[0], index, at);
8116
8365
  if (mark) shapes.push(mark);
@@ -8137,9 +8386,12 @@ function expressive$1(target, options, env) {
8137
8386
  index
8138
8387
  };
8139
8388
  }
8389
+ function turned(pieces, at) {
8390
+ return pieces.length === 1 && !axisAligned(transformOf(pieces[0].element, at));
8391
+ }
8140
8392
  function rectPiece(key, piece, at) {
8141
8393
  const m = transformOf(piece.element, at);
8142
- if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar. Describe it with the geometry option.`);
8394
+ if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar's segment. A rect turned on its own is a shape, a mark of its own: give each its own key, or describe the bar with the geometry option.`);
8143
8395
  return {
8144
8396
  ...piece,
8145
8397
  rect: {
@@ -8177,7 +8429,7 @@ function expressive$1(target, options, env) {
8177
8429
  };
8178
8430
  const r = tag === "circle" ? length("r") : 0;
8179
8431
  let geometry;
8180
- let strokeWidth;
8432
+ let stroke;
8181
8433
  if (tag === "circle" && (keepsCircles(m) || !(r > 0))) {
8182
8434
  const center = matrix.apply(m, {
8183
8435
  x: length("cx"),
@@ -8193,20 +8445,28 @@ function expressive$1(target, options, env) {
8193
8445
  } else {
8194
8446
  const commands = shapeOutline(tag, attribute);
8195
8447
  if (commands[0]?.op !== "M" || commands.every((command) => command.op === "M")) return void 0;
8196
- strokeWidth = tag === "circle" ? void 0 : at.strokeWidth(element);
8197
- const width = round$1((strokeWidth ?? 1) * scaleOf$1(m));
8198
- const d = tag === "path" ? attribute("d") ?? "" : formatPath(commands);
8199
- geometry = describeShape({
8448
+ stroke = tag === "circle" ? void 0 : at.stroke(element);
8449
+ const slice = tag === "path" ? sliceOf$1(commands, m) : void 0;
8450
+ if (slice) geometry = describeArc({
8200
8451
  key,
8201
8452
  series,
8202
- d,
8203
- matrix: m,
8204
- width: width > 0 ? width : 1
8453
+ ...slice
8205
8454
  });
8455
+ else {
8456
+ const width = round$1(widthOf(stroke, m, at));
8457
+ const d = tag === "path" ? attribute("d") ?? "" : formatPath(commands);
8458
+ geometry = describeShape({
8459
+ key,
8460
+ series,
8461
+ d,
8462
+ matrix: m,
8463
+ width: width > 0 ? width : 1
8464
+ });
8465
+ }
8206
8466
  }
8207
8467
  const parts = [{
8208
8468
  ...part(piece, outlineOf(geometry, series, 1), at),
8209
- strokeWidth
8469
+ stroke
8210
8470
  }];
8211
8471
  return {
8212
8472
  key,
@@ -8216,6 +8476,13 @@ function expressive$1(target, options, env) {
8216
8476
  ...tag === "circle" ? { circle: true } : {}
8217
8477
  };
8218
8478
  }
8479
+ function widthOf(stroke, m, at) {
8480
+ const width = stroke?.width ?? 1;
8481
+ if (!stroke?.screen) return width * scaleOf$1(m);
8482
+ const screen = at.screen(at.common);
8483
+ const scale = screen ? scaleOf$1(screen) : 0;
8484
+ return scale > 0 ? width / scale : width;
8485
+ }
8219
8486
  function transformOf(element, at) {
8220
8487
  return matrix.multiply(between$1(at.common, element.parentElement ?? at.svg, at.svg, at.screen), ownTransform(element));
8221
8488
  }
@@ -8670,9 +8937,17 @@ function expressive$1(target, options, env) {
8670
8937
  let overlayMoved = false;
8671
8938
  for (const element of changes.ancestors) if (element.contains(ancestor)) overlayMoved = true;
8672
8939
  else for (const record of order) if (record.mark.parts.some((part) => element.contains(part.element))) changed.add(record);
8673
- if (overlayMoved) placeOverlay();
8674
- if (changed.size === 0) return;
8675
- const { records, marks } = reread([...changed]);
8940
+ const rescaled = /* @__PURE__ */ new Set();
8941
+ if (overlayMoved) {
8942
+ placeOverlay();
8943
+ for (const record of order) if (!changed.has(record) && record.mark.parts.some((part) => part.stroke?.screen)) rescaled.add(record);
8944
+ }
8945
+ if (changed.size === 0 && rescaled.size === 0) return;
8946
+ const read = reread([...changed, ...rescaled]);
8947
+ const kept = read.records.flatMap((record, i) => rescaled.has(record) && !geometryChanged(record.mark.geometry, read.marks[i].geometry) ? [] : [i]);
8948
+ if (kept.length === 0) return;
8949
+ const records = kept.map((i) => read.records[i]);
8950
+ const marks = kept.map((i) => read.marks[i]);
8676
8951
  records.forEach((record, i) => {
8677
8952
  const mark = marks[i];
8678
8953
  record.mark = mark;
@@ -8694,7 +8969,7 @@ function expressive$1(target, options, env) {
8694
8969
  common: ancestor,
8695
8970
  screen: screenMatrices(),
8696
8971
  colors: (element) => owners.get(element)?.part.colors,
8697
- strokeWidth: (element) => owners.get(element)?.part.strokeWidth
8972
+ stroke: (element) => owners.get(element)?.part.stroke
8698
8973
  };
8699
8974
  const rowOf = rowsNow();
8700
8975
  const piecesOf = ({ parts }) => parts.map((part) => ({
@@ -8713,16 +8988,17 @@ function expressive$1(target, options, env) {
8713
8988
  marks: withData(marks)
8714
8989
  };
8715
8990
  }
8716
- const rects = new Map(changed.flatMap((record) => record.mark.rect ? [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]] : []));
8717
- const edges = edgesNow(rects);
8718
- for (const record of order) if (record.mark.rect && !rects.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
8991
+ const shapes = new Set(changed.filter((record) => !record.mark.rect || turned(record.mark.parts, at)));
8992
+ const rects = new Map(changed.flatMap((record) => shapes.has(record) ? [] : [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]]));
8993
+ const edges = edgesNow(rects, shapes);
8994
+ for (const record of order) if (record.mark.rect && !rects.has(record) && !shapes.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
8719
8995
  const records = [...rects.keys()];
8720
8996
  const marks = records.map((record) => ({
8721
8997
  ...rectMark(record.key, rects.get(record), edges.get(record), record.mark.index, at),
8722
8998
  label: record.mark.label
8723
8999
  }));
8724
9000
  for (const record of changed) {
8725
- if (record.mark.rect) continue;
9001
+ if (!shapes.has(record)) continue;
8726
9002
  const mark = shapeMark(record.key, piecesOf(record.mark)[0], record.mark.index, at);
8727
9003
  if (!mark) continue;
8728
9004
  records.push(record);
@@ -8736,8 +9012,8 @@ function expressive$1(target, options, env) {
8736
9012
  marks: withData(marks)
8737
9013
  };
8738
9014
  }
8739
- function edgesNow(rects) {
8740
- const bars = order.filter((record) => record.mark.rect);
9015
+ function edgesNow(rects, shapes) {
9016
+ const bars = order.filter((record) => record.mark.rect && !shapes.has(record));
8741
9017
  const kept = new Map(bars.map((record) => [record, record.mark.rect.edge]));
8742
9018
  if (options.baseline !== void 0 && options.baseline !== "auto") return kept;
8743
9019
  const boxes = bars.map((record) => {
@@ -9467,12 +9743,12 @@ function chartSwitch$1(target, options, env) {
9467
9743
  const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
9468
9744
  const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
9469
9745
  const orders = /* @__PURE__ */ new WeakMap();
9470
- const surface = { group(key, order) {
9746
+ const surfaceFor = (paints) => ({ group(key, order) {
9471
9747
  const group = svgElement("g", {
9472
9748
  class: "ec-run",
9473
9749
  "data-key": key
9474
9750
  }, runsLayer);
9475
- setStyles(group, markColorStyles(seriesColors(colors.slot(key))));
9751
+ setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
9476
9752
  orders.set(group, order);
9477
9753
  const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
9478
9754
  runsLayer.insertBefore(group, above ?? null);
@@ -9480,7 +9756,7 @@ function chartSwitch$1(target, options, env) {
9480
9756
  ...svgLayer(group),
9481
9757
  clear: () => group.remove()
9482
9758
  };
9483
- } };
9759
+ } });
9484
9760
  let current = options.initial;
9485
9761
  let active;
9486
9762
  let destroyed = false;
@@ -9508,17 +9784,16 @@ function chartSwitch$1(target, options, env) {
9508
9784
  const element = focused();
9509
9785
  if (!element || !from.container.contains(element)) return void 0;
9510
9786
  const keyed = element.closest("[data-key]");
9511
- return { key: keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") ?? void 0 : void 0 };
9787
+ const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
9788
+ return { keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key] };
9512
9789
  }
9513
9790
  function restoreFocus(to, memory) {
9514
9791
  if (!memory) return;
9515
9792
  const now = focused();
9516
9793
  if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
9517
9794
  const inside = () => to.chart.element.contains(focused());
9518
- if (memory.key !== void 0) to.chart.focus(memory.key);
9519
- if (inside()) return;
9520
- for (const mark of to.chart.marks()) {
9521
- to.chart.focus(mark.key);
9795
+ for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
9796
+ to.chart.focus(key);
9522
9797
  if (inside()) return;
9523
9798
  }
9524
9799
  }
@@ -9556,7 +9831,7 @@ function chartSwitch$1(target, options, env) {
9556
9831
  each.container.setAttribute("inert", "");
9557
9832
  each.chart.element.classList.add("ec-morphing");
9558
9833
  }
9559
- const { pairs, scene } = prepare(from, to);
9834
+ const { pairs, surface, scene } = prepare(from, to);
9560
9835
  const { done, settle } = deferred();
9561
9836
  const session = {
9562
9837
  a: from,
@@ -9567,6 +9842,7 @@ function chartSwitch$1(target, options, env) {
9567
9842
  from: b,
9568
9843
  to: a
9569
9844
  })),
9845
+ surface,
9570
9846
  scene,
9571
9847
  focus: memory,
9572
9848
  progress: 0,
@@ -9593,7 +9869,7 @@ function chartSwitch$1(target, options, env) {
9593
9869
  const started = startClock(clock);
9594
9870
  session.transition = playTransition(session.forward ? session.pairs : session.reversed, {
9595
9871
  effect,
9596
- surface,
9872
+ surface: session.surface,
9597
9873
  start: begin,
9598
9874
  motion,
9599
9875
  clock: started.clock,
@@ -9646,16 +9922,27 @@ function chartSwitch$1(target, options, env) {
9646
9922
  const to = b.chart.marks().map((mark) => mapMark(mark, toB));
9647
9923
  const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
9648
9924
  const toKeys = new Set(to.map((mark) => mark.key));
9649
- const pairs = to.flatMap((mark) => {
9925
+ const pairs = [];
9926
+ const paints = [];
9927
+ for (const mark of to) {
9650
9928
  const partner = fromByKey.get(mark.key);
9651
- return partner ? [{
9652
- from: partner,
9653
- to: mark
9654
- }] : [];
9655
- });
9929
+ if (!partner) continue;
9930
+ const was = paintOf(a, partner);
9931
+ const will = paintOf(b, mark);
9932
+ if (!was.drawn && !will.drawn) continue;
9933
+ pairs.push({
9934
+ from: was.drawn ? partner : dot$1(partner),
9935
+ to: will.drawn ? mark : dot$1(mark)
9936
+ });
9937
+ paints.push(will.color);
9938
+ }
9656
9939
  const drawings = [];
9657
- for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
9658
- for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
9940
+ const fade = (view, mark, opacity) => {
9941
+ const paint = paintOf(view, mark);
9942
+ if (paint.drawn) drawings.push(fadeMark(mark, paint.color, opacity));
9943
+ };
9944
+ for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, fadeOut);
9945
+ for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, fadeIn);
9659
9946
  const id = (label) => `${label.role}\n${label.key}`;
9660
9947
  const labelsA = a.chart.labels();
9661
9948
  const labelsB = b.chart.labels();
@@ -9675,6 +9962,7 @@ function chartSwitch$1(target, options, env) {
9675
9962
  });
9676
9963
  return {
9677
9964
  pairs,
9965
+ surface: surfaceFor(paints),
9678
9966
  scene: {
9679
9967
  draw: (s) => {
9680
9968
  for (const draw of drawings) draw(s);
@@ -9687,12 +9975,12 @@ function chartSwitch$1(target, options, env) {
9687
9975
  }
9688
9976
  };
9689
9977
  }
9690
- function fadeMark(mark, opacity) {
9978
+ function fadeMark(mark, color, opacity) {
9691
9979
  const group = svgElement("g", {
9692
9980
  class: "ec-switch-fade",
9693
9981
  "data-key": mark.key
9694
9982
  }, fadesLayer);
9695
- setStyles(group, markColorStyles(seriesColors(colors.slot(mark.key))));
9983
+ setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
9696
9984
  svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : {
9697
9985
  stroke: "mark",
9698
9986
  width: mark.thickness
@@ -9885,6 +10173,21 @@ const fadeOut = (s) => 1 - clamp$1(s / HALF);
9885
10173
  const fadeIn = (s) => clamp$1((s - HALF) / .5);
9886
10174
  const clamp$1 = (value) => Math.min(1, Math.max(0, value));
9887
10175
  const mix$1 = (x, y, s) => x * (1 - s) + y * s;
10176
+ function paintOf(view, mark) {
10177
+ return view.chart.paintOf?.(mark.key) ?? {
10178
+ color: mark.key,
10179
+ drawn: true
10180
+ };
10181
+ }
10182
+ function dot$1(mark) {
10183
+ return describePoint({
10184
+ key: mark.key,
10185
+ ...mark.series === void 0 ? {} : { series: mark.series },
10186
+ x: mark.center.x,
10187
+ y: mark.center.y,
10188
+ r: 0
10189
+ });
10190
+ }
9888
10191
  const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
9889
10192
  function mapMark(mark, m) {
9890
10193
  if (isIdentity(m)) return mark;
@@ -9906,6 +10209,7 @@ function mapMark(mark, m) {
9906
10209
  return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
9907
10210
  },
9908
10211
  slice: (t0, t1) => path(mark.slice(t0, t1)),
10212
+ ...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
9909
10213
  thickness: mark.thickness * scale,
9910
10214
  outline: {
9911
10215
  d: path(outline.d),
@@ -10582,18 +10886,65 @@ const PAST_END = 10;
10582
10886
  const PAST_LABEL = 6;
10583
10887
  const TEXT = 12.5;
10584
10888
  const CENTRE = .36;
10585
- function captionPlace(mark) {
10889
+ function captionPlace(mark, text) {
10586
10890
  const own = mark.labelBounds ?? [];
10587
- const nearby = mark.nearbyLabels ?? [];
10891
+ const boxes = [
10892
+ ...own,
10893
+ ...mark.nearbyLabels ?? [],
10894
+ ...text?.held ?? []
10895
+ ];
10588
10896
  const heading = mark.angle(1);
10589
- const along = farthest(mark.end, heading, own);
10590
- if (along === void 0 && own.length > 0) {
10897
+ if (farthest(mark.end, heading, own) === void 0) {
10591
10898
  const up = mark.angle(.5) - Math.PI / 2;
10592
- const out = farthest(mark.center, up, own);
10593
- if (out !== void 0) return placed(mark.center, up, Math.max(out, farthest(mark.center, up, nearby) ?? -Infinity));
10899
+ if (farthest(mark.center, up, own) !== void 0) return past(mark.center, up, 0, own, boxes, text);
10594
10900
  }
10595
- return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity, farthest(mark.end, heading, nearby) ?? -Infinity));
10901
+ return past(mark.end, heading, PAST_END, own, boxes, text);
10902
+ }
10903
+ function past(from, toward, least, own, boxes, text) {
10904
+ if (!text) return placed(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
10905
+ const { x, y, width, height } = text.box(placed(from, toward, 0));
10906
+ return placed(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
10907
+ x: x - from.x,
10908
+ y: y - from.y,
10909
+ width,
10910
+ height
10911
+ }, new Set(text.held)));
10596
10912
  }
10913
+ function clearOf(from, toward, distance, boxes, reach, held) {
10914
+ const cos = Math.cos(toward);
10915
+ const sin = Math.sin(toward);
10916
+ const across = centred(cos);
10917
+ const meets = (box) => span(from, cos, sin, {
10918
+ x: box.x - reach.x - reach.width,
10919
+ y: box.y - reach.y - reach.height,
10920
+ width: box.width + reach.width,
10921
+ height: box.height + reach.height
10922
+ });
10923
+ const spans = boxes.map((box) => {
10924
+ const near = grow(box, PAST_LABEL);
10925
+ const band = span(from, cos, sin, near);
10926
+ if (!band && held.has(box)) return meets(box);
10927
+ const within = meets(near);
10928
+ if (!band || !within) return within;
10929
+ const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
10930
+ return [within[0], Math.max(leaving, meets(box)?.[1] ?? -Infinity)];
10931
+ });
10932
+ let at = distance;
10933
+ for (let moved = true; moved;) {
10934
+ moved = false;
10935
+ for (const meets of spans) if (meets && at > meets[0] + 1e-6 && at < meets[1] - 1e-6) {
10936
+ at = meets[1];
10937
+ moved = true;
10938
+ }
10939
+ }
10940
+ return at;
10941
+ }
10942
+ const grow = ({ x, y, width, height }, by) => ({
10943
+ x: x - by,
10944
+ y: y - by,
10945
+ width: width + 2 * by,
10946
+ height: height + 2 * by
10947
+ });
10597
10948
  function placed(from, toward, distance) {
10598
10949
  const cos = Math.cos(toward);
10599
10950
  const sin = Math.sin(toward);
@@ -10617,13 +10968,8 @@ function farthest(from, toward, boxes) {
10617
10968
  const sin = Math.sin(toward);
10618
10969
  const across = centred(cos);
10619
10970
  let exit;
10620
- for (const { x, y, width, height } of boxes) {
10621
- const grown = {
10622
- x: x - PAST_LABEL,
10623
- y: y - PAST_LABEL,
10624
- width: width + 12,
10625
- height: height + 12
10626
- };
10971
+ for (const box of boxes) {
10972
+ const grown = grow(box, PAST_LABEL);
10627
10973
  let leaving = leaves(from, cos, sin, grown);
10628
10974
  if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
10629
10975
  if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
@@ -10631,6 +10977,9 @@ function farthest(from, toward, boxes) {
10631
10977
  return exit;
10632
10978
  }
10633
10979
  function leaves(from, cos, sin, box) {
10980
+ return span(from, cos, sin, box)?.[1];
10981
+ }
10982
+ function span(from, cos, sin, box) {
10634
10983
  let near = 0;
10635
10984
  let far = Infinity;
10636
10985
  for (const [origin, step, lo, hi] of [[
@@ -10653,7 +11002,7 @@ function leaves(from, cos, sin, box) {
10653
11002
  near = Math.max(near, Math.min(a, b));
10654
11003
  far = Math.min(far, Math.max(a, b));
10655
11004
  }
10656
- return far >= near ? far : void 0;
11005
+ return far >= near ? [near, far] : void 0;
10657
11006
  }
10658
11007
  function caption(mark, data, ctx, color, words) {
10659
11008
  let current = mark;
@@ -10661,13 +11010,22 @@ function caption(mark, data, ctx, color, words) {
10661
11010
  let latest = data;
10662
11011
  let progress = 0;
10663
11012
  let handle;
11013
+ const { texts } = ctx;
10664
11014
  const draw = () => {
10665
11015
  if (content === "") {
10666
11016
  handle?.remove();
10667
11017
  handle = void 0;
11018
+ texts?.hold(void 0);
10668
11019
  return;
10669
11020
  }
10670
- const { at, anchor, toward } = captionPlace(current);
11021
+ const { at, anchor, toward } = captionPlace(current, texts && {
11022
+ held: texts.held(),
11023
+ box: (style) => texts.box(content, style)
11024
+ });
11025
+ texts?.hold(texts.box(content, {
11026
+ at,
11027
+ anchor
11028
+ }));
10671
11029
  const style = {
10672
11030
  at: offset(at, toward - Math.PI / 2, -8 * (1 - progress)),
10673
11031
  anchor,
@@ -10955,6 +11313,9 @@ const show = (value) => typeof value === "string" ? JSON.stringify(value) : Stri
10955
11313
  const DURATION = 950;
10956
11314
  const POINTS = 160;
10957
11315
  const ALIGNS = ["unroll", "drop"];
11316
+ const SAME_T = 1e-9;
11317
+ const GRID = 9;
11318
+ const CHECKS = 8;
10958
11319
  function morph(options = {}) {
10959
11320
  checkOptions(options);
10960
11321
  const points = options?.points ?? POINTS;
@@ -10994,11 +11355,12 @@ function drawing(from, to, layer, points, align) {
10994
11355
  if (closed !== to.outline.closed) return crossfade(from, to, layer);
10995
11356
  const a = from.outline.sample(points);
10996
11357
  const b = to.outline.sample(points);
10997
- if (!closed) return stroke(from, to, layer, a, b);
11358
+ if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
10998
11359
  const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
11360
+ const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
10999
11361
  let path;
11000
11362
  return (p) => {
11001
- const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true);
11363
+ const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true) + holes.map((hole) => holeAt(hole, p)).join("");
11002
11364
  if (path) path.update(d);
11003
11365
  else path = layer.path(d, { fill: "mark" });
11004
11366
  };
@@ -11015,6 +11377,214 @@ function stroke(from, to, layer, a, b) {
11015
11377
  });
11016
11378
  };
11017
11379
  }
11380
+ function gapped(from, to, layer, a, b) {
11381
+ const n = a.length;
11382
+ const stops = a.map((point, i) => ({
11383
+ t: i / (n - 1),
11384
+ from: point,
11385
+ to: b[i]
11386
+ }));
11387
+ 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({
11388
+ t,
11389
+ from: from.path(t),
11390
+ to: to.path(t)
11391
+ });
11392
+ stops.sort((x, y) => x.t - y.t);
11393
+ const runs = [
11394
+ [],
11395
+ [],
11396
+ []
11397
+ ];
11398
+ for (let k = 0; k + 1 < stops.length; k++) {
11399
+ const t = (stops[k].t + stops[k + 1].t) / 2;
11400
+ const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
11401
+ if (kind === 3) continue;
11402
+ const last = runs[kind][runs[kind].length - 1];
11403
+ if (last && last[1] === k) last[1] = k + 1;
11404
+ else runs[kind].push([k, k + 1]);
11405
+ }
11406
+ const kinds = [
11407
+ 0,
11408
+ 1,
11409
+ 2
11410
+ ].filter((kind) => runs[kind].length > 0).sort((x, y) => runs[x][0][0] - runs[y][0][0]);
11411
+ const paths = [];
11412
+ return (p) => {
11413
+ const width = p <= 0 ? from.thickness : p >= 1 ? to.thickness : mix(from.thickness, to.thickness, p);
11414
+ const opacities = [
11415
+ void 0,
11416
+ p,
11417
+ 1 - p
11418
+ ];
11419
+ 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]]);
11420
+ pieces.forEach(([d, opacity], i) => {
11421
+ if (paths[i]) paths[i].update(d, {
11422
+ width,
11423
+ opacity
11424
+ });
11425
+ else paths[i] = layer.path(d, {
11426
+ stroke: "mark",
11427
+ width,
11428
+ ...opacity === void 0 ? {} : { opacity }
11429
+ });
11430
+ });
11431
+ for (const path of paths.splice(pieces.length)) path.remove();
11432
+ };
11433
+ }
11434
+ const inGap = (mark, t) => (mark.gaps ?? []).some(([x, y]) => x < t && t < y);
11435
+ function along(stops, [first, last], p) {
11436
+ let d = "";
11437
+ for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
11438
+ return d;
11439
+ }
11440
+ function holePairs(from, to, a, b, [shiftA, shiftB], count) {
11441
+ const holesA = holesOf(from.outline, count);
11442
+ const holesB = holesOf(to.outline, count);
11443
+ const both = Math.min(holesA.length, holesB.length);
11444
+ const pairs = holesA.slice(0, both).map((hole, k) => ({
11445
+ from: hole.points,
11446
+ to: holesB[k].points
11447
+ }));
11448
+ const closes = holesA.length > holesB.length;
11449
+ const [ownHoles, otherHoles, other, own, theirs, ownShift, otherShift] = closes ? [
11450
+ holesA,
11451
+ holesB,
11452
+ to,
11453
+ a,
11454
+ b,
11455
+ shiftA,
11456
+ shiftB
11457
+ ] : [
11458
+ holesB,
11459
+ holesA,
11460
+ from,
11461
+ b,
11462
+ a,
11463
+ shiftB,
11464
+ shiftA
11465
+ ];
11466
+ const n = own.length;
11467
+ const outside = own.map((_, i) => [own[(i + ownShift) % n], theirs[(i + otherShift) % n]]);
11468
+ const inner = ownHoles.slice(0, both).map((hole, k) => hole.points.map((p, i) => [p, otherHoles[k].points[i]]));
11469
+ const area = [theirs, ...otherHoles.map((hole) => hole.points)];
11470
+ for (const hole of ownHoles.slice(both)) {
11471
+ const { end, point } = closing(hole, landing(hole, (closes ? from : to).bounds, other, area), outside, inner);
11472
+ const dot = new Array(count).fill(point);
11473
+ pairs.push(closes ? {
11474
+ from: hole.points,
11475
+ to: dot,
11476
+ end
11477
+ } : {
11478
+ from: dot,
11479
+ to: hole.points,
11480
+ end,
11481
+ opens: true
11482
+ });
11483
+ }
11484
+ return pairs;
11485
+ }
11486
+ function closing(hole, there, outside, inner) {
11487
+ let end = .5;
11488
+ while (end > 1 / 16 && !stays(hole, mixed(hole.center, there, end), end, outside, inner)) end /= 2;
11489
+ return {
11490
+ end,
11491
+ point: mixed(hole.center, there, end)
11492
+ };
11493
+ }
11494
+ function stays(hole, point, end, outside, inner) {
11495
+ for (let j = 1; j < CHECKS; j++) {
11496
+ const t = end * j / CHECKS;
11497
+ const at = (path) => mixed(path[0], path[1], t);
11498
+ const area = [outside.map(at), ...inner.map((ring) => ring.map(at))];
11499
+ if (hole.points.some((p) => windingAt(mixed(p, point, j / CHECKS), area) === 0)) return false;
11500
+ }
11501
+ return true;
11502
+ }
11503
+ function holeAt({ from, to, end, opens }, p) {
11504
+ if (end === void 0) return between(from, to, 0, 0, p, true);
11505
+ const q = opens ? (p - (1 - end)) / end : p / end;
11506
+ return (opens ? q <= 0 : q >= 1) ? "" : between(from, to, 0, 0, q, true);
11507
+ }
11508
+ const mixed = (a, b, t) => ({
11509
+ x: mix(a.x, b.x, t),
11510
+ y: mix(a.y, b.y, t)
11511
+ });
11512
+ function landing(hole, own, other, area) {
11513
+ const place = placeIn(hole.center, own, other.bounds);
11514
+ if (depth(place, area) >= hole.size / 4) return place;
11515
+ const { x, y, width, height } = other.bounds;
11516
+ let best = other.center;
11517
+ let deepest = depth(best, area);
11518
+ for (let i = 0; i < GRID; i++) for (let j = 0; j < GRID; j++) {
11519
+ const point = {
11520
+ x: x + width * (i + .5) / GRID,
11521
+ y: y + height * (j + .5) / GRID
11522
+ };
11523
+ const d = depth(point, area);
11524
+ if (d > deepest) [best, deepest] = [point, d];
11525
+ }
11526
+ return best;
11527
+ }
11528
+ function depth(point, area) {
11529
+ if (windingAt(point, area) === 0) return 0;
11530
+ let nearest = Infinity;
11531
+ for (const ring of area) ring.forEach((p, i) => {
11532
+ const q = ring[(i + 1) % ring.length];
11533
+ const dx = q.x - p.x;
11534
+ const dy = q.y - p.y;
11535
+ 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)));
11536
+ nearest = Math.min(nearest, Math.hypot(point.x - p.x - u * dx, point.y - p.y - u * dy));
11537
+ });
11538
+ return nearest;
11539
+ }
11540
+ function windingAt(point, area) {
11541
+ let winding = 0;
11542
+ for (const ring of area) ring.forEach((p, i) => {
11543
+ const q = ring[(i + 1) % ring.length];
11544
+ const side = (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);
11545
+ if (p.y <= point.y && q.y > point.y && side > 0) winding++;
11546
+ else if (p.y > point.y && q.y <= point.y && side < 0) winding--;
11547
+ });
11548
+ return winding;
11549
+ }
11550
+ function placeIn(point, own, other) {
11551
+ const fraction = (value, start, size) => size > 0 ? (value - start) / size : .5;
11552
+ return {
11553
+ x: other.x + fraction(point.x, own.x, own.width) * other.width,
11554
+ y: other.y + fraction(point.y, own.y, own.height) * other.height
11555
+ };
11556
+ }
11557
+ function holesOf(outline, count) {
11558
+ const loops = flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
11559
+ if (loops.length < 2) return [];
11560
+ const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
11561
+ let longest = 0;
11562
+ lengths.forEach((length, i) => {
11563
+ if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
11564
+ });
11565
+ return loops.filter((_, i) => i !== longest).map((loop) => {
11566
+ const round = loopOutline([loop]).sample(4 * count);
11567
+ const points = round.filter((_, i) => i % 4 === 0);
11568
+ const box = boundsOf(loop.flatMap(extremes));
11569
+ return {
11570
+ points: [points[0], ...points.slice(1).reverse()],
11571
+ area: Math.abs(areaOf(round)),
11572
+ center: {
11573
+ x: box.x + box.width / 2,
11574
+ y: box.y + box.height / 2
11575
+ },
11576
+ size: Math.max(box.width, box.height) / 2
11577
+ };
11578
+ }).sort((x, y) => y.area - x.area);
11579
+ }
11580
+ function areaOf(points) {
11581
+ let sum = 0;
11582
+ points.forEach((p, i) => {
11583
+ const q = points[(i + 1) % points.length];
11584
+ sum += p.x * q.y - q.x * p.y;
11585
+ });
11586
+ return sum / 2;
11587
+ }
11018
11588
  function crossfade(from, to, layer) {
11019
11589
  const paint = (mark, opacity) => ({
11020
11590
  ...mark.outline.closed ? { fill: "mark" } : {
@@ -11048,13 +11618,10 @@ function crossfade(from, to, layer) {
11048
11618
  function between(a, b, shiftA, shiftB, p, closed) {
11049
11619
  const n = a.length;
11050
11620
  let d = "";
11051
- for (let i = 0; i < n; i++) {
11052
- const from = a[(i + shiftA) % n];
11053
- const to = b[(i + shiftB) % n];
11054
- d += `${i === 0 ? "M" : "L"}${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
11055
- }
11621
+ for (let i = 0; i < n; i++) d += `${i === 0 ? "M" : "L"}${at(a[(i + shiftA) % n], b[(i + shiftB) % n], p)}`;
11056
11622
  return closed ? `${d}Z` : d;
11057
11623
  }
11624
+ const at = (from, to, p) => `${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
11058
11625
  const mix = (x, y, p) => x * (1 - p) + y * p;
11059
11626
  function turn(from, to, points) {
11060
11627
  const quarter = points / 4;
@@ -11572,7 +12139,7 @@ function configure(options) {
11572
12139
  }
11573
12140
  }
11574
12141
  // src/index.ts
11575
- const VERSION = "0.5.0";
12142
+ const VERSION = "0.6.0";
11576
12143
  const env = {
11577
12144
  presets: presetRegistry,
11578
12145
  icons: iconRegistry,