expressive-charts 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +6 -6
- package/dist/{drawing-Ypmq-2h6.d.ts → drawing-OmQV-0BB.d.cts} +8 -2
- package/dist/{drawing-Ypmq-2h6.d.cts → drawing-OmQV-0BB.d.ts} +8 -2
- package/dist/{effect-D8W4ZmmG.d.cts → effect-DYCLY_6e.d.cts} +2 -2
- package/dist/{effect-DyzluQD1.d.ts → effect-HCWnmB72.d.ts} +2 -2
- package/dist/expressive-charts.global.js +10 -10
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.d.cts +1 -1
- package/dist/icons/sport.d.ts +1 -1
- package/dist/index.cjs +476 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -17
- package/dist/index.d.ts +64 -17
- package/dist/index.js +476 -110
- package/dist/index.js.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -392,7 +392,7 @@ function animated(initial, interpolate, options = {}) {
|
|
|
392
392
|
// src/core/playback.ts
|
|
393
393
|
const SEEK_MS = 350;
|
|
394
394
|
function playback(options) {
|
|
395
|
-
checkOptions$
|
|
395
|
+
checkOptions$15(options);
|
|
396
396
|
const { from, to, duration, onFrame } = options;
|
|
397
397
|
const ease = options.ease ?? linear;
|
|
398
398
|
const timing = options.timing ?? "playback";
|
|
@@ -535,7 +535,7 @@ function playback(options) {
|
|
|
535
535
|
}
|
|
536
536
|
};
|
|
537
537
|
}
|
|
538
|
-
function checkOptions$
|
|
538
|
+
function checkOptions$15(options) {
|
|
539
539
|
if (typeof options !== "object" || options === null) throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
|
|
540
540
|
const { from, to, duration, ease, timing, onFrame, clock, motion } = options;
|
|
541
541
|
for (const [name, value] of [["from", from], ["to", to]]) if (!isFiniteNumber(value)) throw new RangeError(`playback: ${name} must be a finite number, got ${String(value)}.`);
|
|
@@ -3757,7 +3757,7 @@ function mix$3(colors, emphasis) {
|
|
|
3757
3757
|
// src/charts/render/layer.ts
|
|
3758
3758
|
const FOLLOW = "ec-follow";
|
|
3759
3759
|
let clipIds = 0;
|
|
3760
|
-
function svgLayer(group, follow) {
|
|
3760
|
+
function svgLayer(group, follow, parts) {
|
|
3761
3761
|
const into = () => {
|
|
3762
3762
|
if (!follow) return group;
|
|
3763
3763
|
const last = group.lastElementChild;
|
|
@@ -3796,13 +3796,13 @@ function svgLayer(group, follow) {
|
|
|
3796
3796
|
d
|
|
3797
3797
|
}, into());
|
|
3798
3798
|
let current = { ...paint };
|
|
3799
|
-
paintPath(element, current);
|
|
3799
|
+
paintPath(element, current, parts);
|
|
3800
3800
|
return {
|
|
3801
3801
|
update(next, nextPaint) {
|
|
3802
3802
|
element.setAttribute("d", next);
|
|
3803
3803
|
if (nextPaint) {
|
|
3804
3804
|
current = mergeFields(current, nextPaint);
|
|
3805
|
-
paintPath(element, current);
|
|
3805
|
+
paintPath(element, current, parts);
|
|
3806
3806
|
}
|
|
3807
3807
|
},
|
|
3808
3808
|
remove: () => element.remove()
|
|
@@ -3846,14 +3846,17 @@ function drawShape(shape, parent) {
|
|
|
3846
3846
|
stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
|
|
3847
3847
|
});
|
|
3848
3848
|
}
|
|
3849
|
-
function paintPath(element, paint) {
|
|
3849
|
+
function paintPath(element, paint, parts) {
|
|
3850
|
+
const { part } = paint;
|
|
3850
3851
|
setAttributes(element, {
|
|
3851
3852
|
"stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
|
|
3852
3853
|
opacity: paint.opacity,
|
|
3853
3854
|
"stroke-linecap": paint.linecap,
|
|
3854
|
-
"stroke-linejoin": "round"
|
|
3855
|
+
"stroke-linejoin": "round",
|
|
3856
|
+
"data-part": part
|
|
3855
3857
|
});
|
|
3856
3858
|
setStyles(element, {
|
|
3859
|
+
...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
|
|
3857
3860
|
fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
|
|
3858
3861
|
stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
|
|
3859
3862
|
});
|
|
@@ -3898,7 +3901,7 @@ function svgSurface(options) {
|
|
|
3898
3901
|
live.add(group);
|
|
3899
3902
|
const owner = live;
|
|
3900
3903
|
return {
|
|
3901
|
-
...svgLayer(group, () => transforms.get(key)),
|
|
3904
|
+
...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
|
|
3902
3905
|
clear() {
|
|
3903
3906
|
group.remove();
|
|
3904
3907
|
owner.delete(group);
|
|
@@ -3929,7 +3932,10 @@ function svgSurface(options) {
|
|
|
3929
3932
|
const live = groups.get(key);
|
|
3930
3933
|
if (!live) return;
|
|
3931
3934
|
const styles = markColorStyles(options.colors(key));
|
|
3932
|
-
for (const group of live)
|
|
3935
|
+
for (const group of live) {
|
|
3936
|
+
setStyles(group, styles);
|
|
3937
|
+
for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
|
|
3938
|
+
}
|
|
3933
3939
|
},
|
|
3934
3940
|
hide(key, hide) {
|
|
3935
3941
|
if (hide) hidden.add(key);
|
|
@@ -4366,6 +4372,14 @@ function keyboardFocus(svg, options) {
|
|
|
4366
4372
|
last = keys;
|
|
4367
4373
|
return had === void 0 ? void 0 : current;
|
|
4368
4374
|
},
|
|
4375
|
+
moveTabStop(key) {
|
|
4376
|
+
listen();
|
|
4377
|
+
const keys = options.order();
|
|
4378
|
+
if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
|
|
4379
|
+
tabStop = key;
|
|
4380
|
+
applyTabIndex(keys);
|
|
4381
|
+
return true;
|
|
4382
|
+
},
|
|
4369
4383
|
destroy() {
|
|
4370
4384
|
current = void 0;
|
|
4371
4385
|
focused = void 0;
|
|
@@ -4623,6 +4637,7 @@ function chartHover(options) {
|
|
|
4623
4637
|
focus(key) {
|
|
4624
4638
|
if (options.live(key)) keyboard.focus(key);
|
|
4625
4639
|
},
|
|
4640
|
+
moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
|
|
4626
4641
|
leave,
|
|
4627
4642
|
destroy() {
|
|
4628
4643
|
destroyed = true;
|
|
@@ -5208,7 +5223,7 @@ function chartTooltip(svg, options) {
|
|
|
5208
5223
|
if (x > left && x < right && y > top && y < bottom) return true;
|
|
5209
5224
|
if (!shape) return false;
|
|
5210
5225
|
const origin = layer.getBoundingClientRect();
|
|
5211
|
-
return inside$
|
|
5226
|
+
return inside$2(shape, x - origin.left, y - origin.top);
|
|
5212
5227
|
};
|
|
5213
5228
|
const letThrough = (on) => {
|
|
5214
5229
|
through = on;
|
|
@@ -5397,7 +5412,7 @@ function chartTooltip(svg, options) {
|
|
|
5397
5412
|
}
|
|
5398
5413
|
};
|
|
5399
5414
|
}
|
|
5400
|
-
function inside$
|
|
5415
|
+
function inside$2({ top, bottom, upper, lower }, x, y) {
|
|
5401
5416
|
if (y <= top || y >= bottom) return false;
|
|
5402
5417
|
const t = (y - top) / (bottom - top);
|
|
5403
5418
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
@@ -5484,7 +5499,7 @@ function viewBox$1(svg) {
|
|
|
5484
5499
|
const STAGE$2 = 500;
|
|
5485
5500
|
function barChart$1(target, options, env) {
|
|
5486
5501
|
const container = resolveTarget$2(target, "barChart");
|
|
5487
|
-
checkOptions$
|
|
5502
|
+
checkOptions$14(options);
|
|
5488
5503
|
let current = options;
|
|
5489
5504
|
const motion = chartMotion(options.motion, env.motion);
|
|
5490
5505
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -5554,7 +5569,7 @@ function barChart$1(target, options, env) {
|
|
|
5554
5569
|
hover.restyled(key);
|
|
5555
5570
|
}
|
|
5556
5571
|
}),
|
|
5557
|
-
colors: (key) => find(key)?.parts[0]?.colors
|
|
5572
|
+
colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
|
|
5558
5573
|
});
|
|
5559
5574
|
const runner = createRunner({
|
|
5560
5575
|
effects,
|
|
@@ -6053,7 +6068,7 @@ function barChart$1(target, options, env) {
|
|
|
6053
6068
|
...current,
|
|
6054
6069
|
...next
|
|
6055
6070
|
};
|
|
6056
|
-
checkOptions$
|
|
6071
|
+
checkOptions$14(merged);
|
|
6057
6072
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
6058
6073
|
const nextLayout = layout(merged, swapped);
|
|
6059
6074
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -6109,6 +6124,7 @@ function barChart$1(target, options, env) {
|
|
|
6109
6124
|
drawn: true
|
|
6110
6125
|
};
|
|
6111
6126
|
},
|
|
6127
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
6112
6128
|
destroy() {
|
|
6113
6129
|
if (destroyed) return;
|
|
6114
6130
|
destroyed = true;
|
|
@@ -6141,7 +6157,7 @@ function barChart$1(target, options, env) {
|
|
|
6141
6157
|
}
|
|
6142
6158
|
});
|
|
6143
6159
|
}
|
|
6144
|
-
function checkOptions$
|
|
6160
|
+
function checkOptions$14(options) {
|
|
6145
6161
|
checkChartOptions(options, "barChart");
|
|
6146
6162
|
const { colorBy, room } = options;
|
|
6147
6163
|
if (room !== void 0 && !(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`barChart: room must be a number of px, 0 or more, got ${String(room)}.`);
|
|
@@ -6445,7 +6461,7 @@ const TAU = 2 * Math.PI;
|
|
|
6445
6461
|
const VISIBLE$1 = .5;
|
|
6446
6462
|
function donutChart$1(target, options, env) {
|
|
6447
6463
|
const container = resolveTarget$2(target, "donutChart");
|
|
6448
|
-
checkOptions$
|
|
6464
|
+
checkOptions$13(options);
|
|
6449
6465
|
let current = options;
|
|
6450
6466
|
const motion = chartMotion(options.motion, env.motion);
|
|
6451
6467
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -7017,7 +7033,7 @@ function donutChart$1(target, options, env) {
|
|
|
7017
7033
|
...current,
|
|
7018
7034
|
...next
|
|
7019
7035
|
};
|
|
7020
|
-
checkOptions$
|
|
7036
|
+
checkOptions$13(merged);
|
|
7021
7037
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
7022
7038
|
const nextLayout = layout(merged, swapped);
|
|
7023
7039
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -7073,6 +7089,7 @@ function donutChart$1(target, options, env) {
|
|
|
7073
7089
|
color: key,
|
|
7074
7090
|
drawn: true
|
|
7075
7091
|
} : void 0,
|
|
7092
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
7076
7093
|
destroy() {
|
|
7077
7094
|
if (destroyed) return;
|
|
7078
7095
|
destroyed = true;
|
|
@@ -7103,7 +7120,7 @@ function donutChart$1(target, options, env) {
|
|
|
7103
7120
|
}
|
|
7104
7121
|
});
|
|
7105
7122
|
}
|
|
7106
|
-
function checkOptions$
|
|
7123
|
+
function checkOptions$13(options) {
|
|
7107
7124
|
checkChartOptions(options, "donutChart");
|
|
7108
7125
|
const { center, sort } = options;
|
|
7109
7126
|
if (center !== void 0 && center !== false && typeof center !== "function") throw new TypeError("donutChart: center must be false or a function that returns the text for the total.");
|
|
@@ -7646,6 +7663,17 @@ function lineEncoding(options) {
|
|
|
7646
7663
|
curve
|
|
7647
7664
|
};
|
|
7648
7665
|
}
|
|
7666
|
+
function checkRoom(room) {
|
|
7667
|
+
const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
7668
|
+
if (typeof room !== "object" || room === null || Array.isArray(room)) {
|
|
7669
|
+
if (room !== void 0 && !px(room)) throw new RangeError(`lineChart: room must be a number of px, 0 or more, got ${typeof room === "object" ? JSON.stringify(room) : String(room)}.`);
|
|
7670
|
+
return;
|
|
7671
|
+
}
|
|
7672
|
+
for (const side of ["right", "top"]) {
|
|
7673
|
+
const value = room[side];
|
|
7674
|
+
if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
|
|
7675
|
+
}
|
|
7676
|
+
}
|
|
7649
7677
|
function layoutLines(input) {
|
|
7650
7678
|
const { width, measure } = input;
|
|
7651
7679
|
const height = input.height ?? HEIGHT;
|
|
@@ -7662,9 +7690,11 @@ function layoutLines(input) {
|
|
|
7662
7690
|
const xValues = ticked.map((tick) => tick.value);
|
|
7663
7691
|
const xTexts = ticked.map((tick) => tick.text);
|
|
7664
7692
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
7693
|
+
const room = typeof input.room === "number" ? { right: input.room } : input.room;
|
|
7665
7694
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
7666
7695
|
const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
|
|
7667
|
-
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (
|
|
7696
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
|
|
7697
|
+
const top = TOP + (room?.top ?? 0);
|
|
7668
7698
|
const frame = {
|
|
7669
7699
|
scale: {
|
|
7670
7700
|
lo: domain.lo,
|
|
@@ -7675,8 +7705,8 @@ function layoutLines(input) {
|
|
|
7675
7705
|
xHi,
|
|
7676
7706
|
left,
|
|
7677
7707
|
right: Math.max(left, width - right),
|
|
7678
|
-
top
|
|
7679
|
-
bottom: Math.max(
|
|
7708
|
+
top,
|
|
7709
|
+
bottom: Math.max(top, height - AXIS),
|
|
7680
7710
|
width,
|
|
7681
7711
|
height
|
|
7682
7712
|
}
|
|
@@ -8107,6 +8137,7 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
|
|
|
8107
8137
|
// src/charts/line.ts
|
|
8108
8138
|
const STAGE = 500;
|
|
8109
8139
|
const RING = 2;
|
|
8140
|
+
const DOT_RING = 2;
|
|
8110
8141
|
const VISIBLE = .5;
|
|
8111
8142
|
function lineChart$1(target, options, env) {
|
|
8112
8143
|
const container = resolveTarget$2(target, "lineChart");
|
|
@@ -8248,8 +8279,8 @@ function lineChart$1(target, options, env) {
|
|
|
8248
8279
|
function layout(opts, using = effects) {
|
|
8249
8280
|
const encoding = lineEncoding(opts);
|
|
8250
8281
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
8251
|
-
const { room
|
|
8252
|
-
|
|
8282
|
+
const { room } = opts;
|
|
8283
|
+
checkRoom(room);
|
|
8253
8284
|
const next = layoutLines({
|
|
8254
8285
|
data: opts.data,
|
|
8255
8286
|
encoding,
|
|
@@ -9307,6 +9338,11 @@ function lineChart$1(target, options, env) {
|
|
|
9307
9338
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
9308
9339
|
hover.sync();
|
|
9309
9340
|
runner.enter(liveMarks().map(input));
|
|
9341
|
+
function stopFor(key) {
|
|
9342
|
+
const row = rows.get(key);
|
|
9343
|
+
if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
|
|
9344
|
+
return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
|
|
9345
|
+
}
|
|
9310
9346
|
return linkable(hover.link, {
|
|
9311
9347
|
element: svg,
|
|
9312
9348
|
async update(next) {
|
|
@@ -9376,30 +9412,40 @@ function lineChart$1(target, options, env) {
|
|
|
9376
9412
|
on: events.on,
|
|
9377
9413
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
9378
9414
|
focus(key) {
|
|
9379
|
-
|
|
9380
|
-
|
|
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);
|
|
9415
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9416
|
+
if (stop !== void 0) hover.focus(stop);
|
|
9388
9417
|
},
|
|
9389
9418
|
leave() {
|
|
9390
9419
|
if (!destroyed) hover.leave();
|
|
9391
9420
|
},
|
|
9392
9421
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
9393
9422
|
paintOf(key) {
|
|
9394
|
-
const
|
|
9395
|
-
|
|
9396
|
-
color:
|
|
9397
|
-
drawn:
|
|
9423
|
+
const line = lines.get(key);
|
|
9424
|
+
if (line) return {
|
|
9425
|
+
color: line.series,
|
|
9426
|
+
drawn: true,
|
|
9427
|
+
...line.end.getAttribute("visibility") === "hidden" ? {} : {
|
|
9428
|
+
end: DOT_RADIUS,
|
|
9429
|
+
ring: DOT_RING
|
|
9430
|
+
}
|
|
9398
9431
|
};
|
|
9432
|
+
const point = points.get(key);
|
|
9433
|
+
return point && (point.group.classList.contains("ec-alone") ? {
|
|
9434
|
+
color: point.series,
|
|
9435
|
+
drawn: true,
|
|
9436
|
+
ring: DOT_RING
|
|
9437
|
+
} : {
|
|
9438
|
+
color: point.series,
|
|
9439
|
+
drawn: false
|
|
9440
|
+
});
|
|
9399
9441
|
},
|
|
9400
9442
|
standsFor(key) {
|
|
9401
9443
|
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
9402
9444
|
},
|
|
9445
|
+
moveTabStop(key) {
|
|
9446
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9447
|
+
return stop !== void 0 && hover.moveTabStop(stop);
|
|
9448
|
+
},
|
|
9403
9449
|
destroy() {
|
|
9404
9450
|
if (destroyed) return;
|
|
9405
9451
|
destroyed = true;
|
|
@@ -9842,7 +9888,7 @@ function keepsCircles(m) {
|
|
|
9842
9888
|
const tiny = 1e-4 * Math.max(u, v);
|
|
9843
9889
|
return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
|
|
9844
9890
|
}
|
|
9845
|
-
function scaleOf$
|
|
9891
|
+
function scaleOf$2(m) {
|
|
9846
9892
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
9847
9893
|
}
|
|
9848
9894
|
function boxIn(m, rect) {
|
|
@@ -10057,7 +10103,7 @@ function cssMatrix(m) {
|
|
|
10057
10103
|
const NEAR = .5;
|
|
10058
10104
|
const MOST = 32;
|
|
10059
10105
|
function sliceOf$1(commands, m) {
|
|
10060
|
-
const scale = scaleOf$
|
|
10106
|
+
const scale = scaleOf$2(m);
|
|
10061
10107
|
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
10062
10108
|
const near = NEAR / scale;
|
|
10063
10109
|
const subpaths = flattenPath(commands);
|
|
@@ -10170,7 +10216,7 @@ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <=
|
|
|
10170
10216
|
1
|
|
10171
10217
|
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
10172
10218
|
function moved(own, m) {
|
|
10173
|
-
const scale = scaleOf$
|
|
10219
|
+
const scale = scaleOf$2(m);
|
|
10174
10220
|
const center = matrix.apply(m, own.center);
|
|
10175
10221
|
const corner = matrix.apply(m, {
|
|
10176
10222
|
x: own.center.x + own.outer * Math.cos(own.start),
|
|
@@ -10391,7 +10437,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
10391
10437
|
"graphics-object"
|
|
10392
10438
|
]);
|
|
10393
10439
|
function expressive$1(target, options, env) {
|
|
10394
|
-
checkOptions$
|
|
10440
|
+
checkOptions$12(options);
|
|
10395
10441
|
const motion = chartMotion(options.motion, env.motion);
|
|
10396
10442
|
let effects = resolveEffects(options.on, env.presets);
|
|
10397
10443
|
let given = options.on;
|
|
@@ -10536,7 +10582,7 @@ function expressive$1(target, options, env) {
|
|
|
10536
10582
|
series,
|
|
10537
10583
|
x: round$1(center.x),
|
|
10538
10584
|
y: round$1(center.y),
|
|
10539
|
-
r: round$1(Math.max(0, r) * scaleOf$
|
|
10585
|
+
r: round$1(Math.max(0, r) * scaleOf$2(m))
|
|
10540
10586
|
});
|
|
10541
10587
|
} else {
|
|
10542
10588
|
const commands = shapeOutline(tag, attribute);
|
|
@@ -10573,9 +10619,9 @@ function expressive$1(target, options, env) {
|
|
|
10573
10619
|
}
|
|
10574
10620
|
function widthOf(stroke, m, at) {
|
|
10575
10621
|
const width = stroke?.width ?? 1;
|
|
10576
|
-
if (!stroke?.screen) return width * scaleOf$
|
|
10622
|
+
if (!stroke?.screen) return width * scaleOf$2(m);
|
|
10577
10623
|
const screen = at.screen(at.common);
|
|
10578
|
-
const scale = screen ? scaleOf$
|
|
10624
|
+
const scale = screen ? scaleOf$2(screen) : 0;
|
|
10579
10625
|
return scale > 0 ? width / scale : width;
|
|
10580
10626
|
}
|
|
10581
10627
|
function transformOf(element, at) {
|
|
@@ -10724,7 +10770,7 @@ function expressive$1(target, options, env) {
|
|
|
10724
10770
|
set: (style) => find(key)?.handle.set(style),
|
|
10725
10771
|
reset: () => find(key)?.handle.reset()
|
|
10726
10772
|
}),
|
|
10727
|
-
colors: (key) => find(key)?.mark
|
|
10773
|
+
colors: (key, part) => partOf(find(key)?.mark, part)?.colors
|
|
10728
10774
|
});
|
|
10729
10775
|
const runner = createRunner({
|
|
10730
10776
|
effects,
|
|
@@ -11267,7 +11313,7 @@ function expressive$1(target, options, env) {
|
|
|
11267
11313
|
}
|
|
11268
11314
|
});
|
|
11269
11315
|
}
|
|
11270
|
-
function checkOptions$
|
|
11316
|
+
function checkOptions$12(options) {
|
|
11271
11317
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
11272
11318
|
if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
|
|
11273
11319
|
for (const name of [
|
|
@@ -11279,6 +11325,11 @@ function checkOptions$11(options) {
|
|
|
11279
11325
|
]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
|
|
11280
11326
|
if (options.baseline !== void 0 && options.baseline !== "auto" && !isBaseline(options.baseline)) throw new RangeError(`expressive: baseline must be "left", "right", "top", "bottom" or "auto", got ${String(options.baseline)}.`);
|
|
11281
11327
|
}
|
|
11328
|
+
function partOf(mark, key) {
|
|
11329
|
+
if (key === void 0) return mark?.parts[0];
|
|
11330
|
+
const segment = mark?.geometry.segments?.find((s) => s.key === key);
|
|
11331
|
+
return segment && mark.parts.find((p) => p.series === segment.series);
|
|
11332
|
+
}
|
|
11282
11333
|
function ownSeries(mark) {
|
|
11283
11334
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
11284
11335
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -11722,7 +11773,7 @@ function pointsOf(first) {
|
|
|
11722
11773
|
function lineOf(key, element, first, m) {
|
|
11723
11774
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
11724
11775
|
if (!straight(first)) {
|
|
11725
|
-
const scaled = width * scaleOf(m);
|
|
11776
|
+
const scaled = width * scaleOf$1(m);
|
|
11726
11777
|
return describeShape({
|
|
11727
11778
|
key,
|
|
11728
11779
|
series: key,
|
|
@@ -11738,7 +11789,7 @@ function lineOf(key, element, first, m) {
|
|
|
11738
11789
|
series: key,
|
|
11739
11790
|
points: points.map(({ point }) => matrix.apply(m, point)),
|
|
11740
11791
|
...breaks.length > 0 ? { breaks } : {},
|
|
11741
|
-
width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
|
|
11792
|
+
width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
|
|
11742
11793
|
});
|
|
11743
11794
|
}
|
|
11744
11795
|
function sliceOf(key, item, m) {
|
|
@@ -11746,7 +11797,7 @@ function sliceOf(key, item, m) {
|
|
|
11746
11797
|
x: number(item.x),
|
|
11747
11798
|
y: number(item.y)
|
|
11748
11799
|
});
|
|
11749
|
-
const s = scaleOf(m);
|
|
11800
|
+
const s = scaleOf$1(m);
|
|
11750
11801
|
const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
|
|
11751
11802
|
return describeArc({
|
|
11752
11803
|
key,
|
|
@@ -11767,7 +11818,7 @@ function pointOf(key, item, m) {
|
|
|
11767
11818
|
key,
|
|
11768
11819
|
x: center.x,
|
|
11769
11820
|
y: center.y,
|
|
11770
|
-
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
|
|
11821
|
+
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
|
|
11771
11822
|
});
|
|
11772
11823
|
}
|
|
11773
11824
|
function boxOf(item) {
|
|
@@ -11782,7 +11833,7 @@ function boxOf(item) {
|
|
|
11782
11833
|
height: Math.abs(height)
|
|
11783
11834
|
};
|
|
11784
11835
|
}
|
|
11785
|
-
function scaleOf(m) {
|
|
11836
|
+
function scaleOf$1(m) {
|
|
11786
11837
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
11787
11838
|
}
|
|
11788
11839
|
function number(value) {
|
|
@@ -11933,12 +11984,12 @@ function describeEffect(value) {
|
|
|
11933
11984
|
return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
|
|
11934
11985
|
}
|
|
11935
11986
|
// src/charts/switch.ts
|
|
11936
|
-
const DURATION$
|
|
11987
|
+
const DURATION$8 = 950;
|
|
11937
11988
|
const OUT_BY = .4;
|
|
11938
11989
|
const HALF = .5;
|
|
11939
11990
|
function chartSwitch$1(target, options, env) {
|
|
11940
11991
|
const host = resolveTarget$2(target, "chartSwitch");
|
|
11941
|
-
const names = checkOptions$
|
|
11992
|
+
const names = checkOptions$11(options);
|
|
11942
11993
|
const effect = options.transition;
|
|
11943
11994
|
const colors = toColorAssignment(options.colors);
|
|
11944
11995
|
const motion = env.motion;
|
|
@@ -11982,7 +12033,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11982
12033
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
11983
12034
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
11984
12035
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
11985
|
-
const surfaceFor = (paints) => ({ group(key, order) {
|
|
12036
|
+
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
11986
12037
|
const group = svgElement("g", {
|
|
11987
12038
|
class: "ec-run",
|
|
11988
12039
|
"data-key": key
|
|
@@ -11991,11 +12042,91 @@ function chartSwitch$1(target, options, env) {
|
|
|
11991
12042
|
orders.set(group, order);
|
|
11992
12043
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
11993
12044
|
runsLayer.insertBefore(group, above ?? null);
|
|
12045
|
+
const layer = svgLayer(group);
|
|
11994
12046
|
return {
|
|
11995
|
-
...
|
|
12047
|
+
...extras[order]?.wrap(layer, group) ?? layer,
|
|
11996
12048
|
clear: () => group.remove()
|
|
11997
12049
|
};
|
|
11998
12050
|
} });
|
|
12051
|
+
function extrasFor(rings, ends, dotColors) {
|
|
12052
|
+
const [ringA, ringB] = rings;
|
|
12053
|
+
const [endA, endB] = ends;
|
|
12054
|
+
if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
|
|
12055
|
+
const dots = [];
|
|
12056
|
+
if (endA && endB) {
|
|
12057
|
+
const element = endDot();
|
|
12058
|
+
const draw = (s) => placeDot(element, {
|
|
12059
|
+
at: {
|
|
12060
|
+
x: mix$1(endA.at.x, endB.at.x, s),
|
|
12061
|
+
y: mix$1(endA.at.y, endB.at.y, s)
|
|
12062
|
+
},
|
|
12063
|
+
r: mix$1(endA.r, endB.r, s),
|
|
12064
|
+
ring: mix$1(endA.ring, endB.ring, s)
|
|
12065
|
+
});
|
|
12066
|
+
dots.push({
|
|
12067
|
+
element,
|
|
12068
|
+
draw
|
|
12069
|
+
});
|
|
12070
|
+
} else [[
|
|
12071
|
+
endA,
|
|
12072
|
+
fadeOut,
|
|
12073
|
+
dotColors[0]
|
|
12074
|
+
], [
|
|
12075
|
+
endB,
|
|
12076
|
+
fadeIn,
|
|
12077
|
+
dotColors[1]
|
|
12078
|
+
]].forEach(([end, opacity, color]) => {
|
|
12079
|
+
if (!end) return;
|
|
12080
|
+
const element = endDot();
|
|
12081
|
+
setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
|
|
12082
|
+
placeDot(element, end);
|
|
12083
|
+
dots.push({
|
|
12084
|
+
element,
|
|
12085
|
+
draw: (s) => setAttributes(element, { opacity: opacity(s) })
|
|
12086
|
+
});
|
|
12087
|
+
});
|
|
12088
|
+
const ringed = ringA > 0 || ringB > 0;
|
|
12089
|
+
let width = ringA;
|
|
12090
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
12091
|
+
return {
|
|
12092
|
+
wrap(layer, group) {
|
|
12093
|
+
shapes.clear();
|
|
12094
|
+
const raise = () => {
|
|
12095
|
+
for (const dot of dots) group.appendChild(dot.element);
|
|
12096
|
+
};
|
|
12097
|
+
raise();
|
|
12098
|
+
return {
|
|
12099
|
+
...layer,
|
|
12100
|
+
path(d, paint) {
|
|
12101
|
+
const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
|
|
12102
|
+
const handle = layer.path(d, ring ? {
|
|
12103
|
+
...paint,
|
|
12104
|
+
stroke: "surface",
|
|
12105
|
+
width
|
|
12106
|
+
} : paint);
|
|
12107
|
+
raise();
|
|
12108
|
+
if (!ring) return handle;
|
|
12109
|
+
shapes.set(handle, d);
|
|
12110
|
+
return {
|
|
12111
|
+
update(next, nextPaint) {
|
|
12112
|
+
shapes.set(handle, next);
|
|
12113
|
+
handle.update(next, nextPaint);
|
|
12114
|
+
},
|
|
12115
|
+
remove() {
|
|
12116
|
+
shapes.delete(handle);
|
|
12117
|
+
handle.remove();
|
|
12118
|
+
}
|
|
12119
|
+
};
|
|
12120
|
+
}
|
|
12121
|
+
};
|
|
12122
|
+
},
|
|
12123
|
+
draw(s) {
|
|
12124
|
+
width = mix$1(ringA, ringB, s);
|
|
12125
|
+
for (const [handle, d] of shapes) handle.update(d, { width });
|
|
12126
|
+
for (const dot of dots) dot.draw(s);
|
|
12127
|
+
}
|
|
12128
|
+
};
|
|
12129
|
+
}
|
|
11999
12130
|
let current = options.initial;
|
|
12000
12131
|
let active;
|
|
12001
12132
|
let destroyed = false;
|
|
@@ -12021,15 +12152,23 @@ function chartSwitch$1(target, options, env) {
|
|
|
12021
12152
|
}
|
|
12022
12153
|
function readFocus(from) {
|
|
12023
12154
|
const element = focused();
|
|
12024
|
-
|
|
12025
|
-
const keyed = element.closest("[data-key]");
|
|
12155
|
+
const inside = element !== null && from.container.contains(element);
|
|
12156
|
+
const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
|
|
12026
12157
|
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
12027
|
-
|
|
12158
|
+
if (!inside && key === null) return void 0;
|
|
12159
|
+
return {
|
|
12160
|
+
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
12161
|
+
focused: inside
|
|
12162
|
+
};
|
|
12028
12163
|
}
|
|
12029
12164
|
function restoreFocus(to, memory) {
|
|
12030
12165
|
if (!memory) return;
|
|
12031
12166
|
const now = focused();
|
|
12032
|
-
|
|
12167
|
+
const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
|
|
12168
|
+
if (!memory.focused || away) {
|
|
12169
|
+
for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
|
|
12170
|
+
return;
|
|
12171
|
+
}
|
|
12033
12172
|
const inside = () => to.chart.element.contains(focused());
|
|
12034
12173
|
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
12035
12174
|
to.chart.focus(key);
|
|
@@ -12157,12 +12296,15 @@ function chartSwitch$1(target, options, env) {
|
|
|
12157
12296
|
function prepare(a, b) {
|
|
12158
12297
|
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
12159
12298
|
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
12299
|
+
const scaleA = scaleOf(toA);
|
|
12300
|
+
const scaleB = scaleOf(toB);
|
|
12160
12301
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
12161
12302
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
12162
12303
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
12163
12304
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
12164
12305
|
const pairs = [];
|
|
12165
12306
|
const paints = [];
|
|
12307
|
+
const extras = [];
|
|
12166
12308
|
for (const mark of to) {
|
|
12167
12309
|
const partner = fromByKey.get(mark.key);
|
|
12168
12310
|
if (!partner) continue;
|
|
@@ -12174,14 +12316,18 @@ function chartSwitch$1(target, options, env) {
|
|
|
12174
12316
|
to: will.drawn ? mark : dot$1(mark)
|
|
12175
12317
|
});
|
|
12176
12318
|
paints.push(will.color);
|
|
12319
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
|
|
12177
12320
|
}
|
|
12178
12321
|
const drawings = [];
|
|
12179
|
-
|
|
12322
|
+
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
12323
|
+
for (const each of extras) each?.draw(s);
|
|
12324
|
+
});
|
|
12325
|
+
const fade = (view, mark, scale, opacity) => {
|
|
12180
12326
|
const paint = paintOf(view, mark);
|
|
12181
|
-
if (paint.drawn) drawings.push(fadeMark(mark, paint
|
|
12327
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
|
|
12182
12328
|
};
|
|
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);
|
|
12329
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
|
|
12330
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
|
|
12185
12331
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
12186
12332
|
const labelsA = a.chart.labels();
|
|
12187
12333
|
const labelsB = b.chart.labels();
|
|
@@ -12201,7 +12347,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12201
12347
|
});
|
|
12202
12348
|
return {
|
|
12203
12349
|
pairs,
|
|
12204
|
-
surface: surfaceFor(paints),
|
|
12350
|
+
surface: surfaceFor(paints, extras),
|
|
12205
12351
|
scene: {
|
|
12206
12352
|
draw: (s) => {
|
|
12207
12353
|
for (const draw of drawings) draw(s);
|
|
@@ -12214,18 +12360,36 @@ function chartSwitch$1(target, options, env) {
|
|
|
12214
12360
|
}
|
|
12215
12361
|
};
|
|
12216
12362
|
}
|
|
12217
|
-
function fadeMark(mark,
|
|
12363
|
+
function fadeMark(mark, paint, scale, opacity) {
|
|
12218
12364
|
const group = svgElement("g", {
|
|
12219
12365
|
class: "ec-switch-fade",
|
|
12220
12366
|
"data-key": mark.key
|
|
12221
12367
|
}, fadesLayer);
|
|
12222
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
|
|
12223
|
-
|
|
12368
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
|
|
12369
|
+
const ring = ringOf(paint, scale);
|
|
12370
|
+
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
12371
|
+
fill: "mark",
|
|
12372
|
+
...ring > 0 ? {
|
|
12373
|
+
stroke: "surface",
|
|
12374
|
+
width: ring
|
|
12375
|
+
} : {}
|
|
12376
|
+
} : {
|
|
12224
12377
|
stroke: "mark",
|
|
12225
12378
|
width: mark.thickness
|
|
12226
12379
|
});
|
|
12380
|
+
const end = endOf(paint, mark, scale);
|
|
12381
|
+
if (end) placeDot(group.appendChild(endDot()), end);
|
|
12227
12382
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
12228
12383
|
}
|
|
12384
|
+
function endDot() {
|
|
12385
|
+
const element = doc.createElementNS(SVG_NS$2, "circle");
|
|
12386
|
+
element.setAttribute("class", "ec-switch-end");
|
|
12387
|
+
setStyles(element, {
|
|
12388
|
+
fill: cssColor("mark"),
|
|
12389
|
+
stroke: cssColor("surface")
|
|
12390
|
+
});
|
|
12391
|
+
return element;
|
|
12392
|
+
}
|
|
12229
12393
|
function copyLabel(label, m) {
|
|
12230
12394
|
const text = label.element.cloneNode(true);
|
|
12231
12395
|
for (const name of [
|
|
@@ -12356,7 +12520,7 @@ function drive(begin, at, env) {
|
|
|
12356
12520
|
const begun = unease(begin);
|
|
12357
12521
|
let running;
|
|
12358
12522
|
running = tween({
|
|
12359
|
-
duration: DURATION$
|
|
12523
|
+
duration: DURATION$8,
|
|
12360
12524
|
timing: "transition",
|
|
12361
12525
|
ease: linear,
|
|
12362
12526
|
update: (k) => {
|
|
@@ -12427,12 +12591,29 @@ function dot$1(mark) {
|
|
|
12427
12591
|
r: 0
|
|
12428
12592
|
});
|
|
12429
12593
|
}
|
|
12594
|
+
const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
|
|
12595
|
+
function endOf(paint, mark, scale) {
|
|
12596
|
+
return paint.drawn && paint.end !== void 0 ? {
|
|
12597
|
+
at: mark.end,
|
|
12598
|
+
r: paint.end * scale,
|
|
12599
|
+
ring: (paint.ring ?? 0) * scale
|
|
12600
|
+
} : void 0;
|
|
12601
|
+
}
|
|
12602
|
+
function placeDot(element, end) {
|
|
12603
|
+
setAttributes(element, {
|
|
12604
|
+
cx: end.at.x,
|
|
12605
|
+
cy: end.at.y,
|
|
12606
|
+
r: end.r,
|
|
12607
|
+
"stroke-width": end.ring
|
|
12608
|
+
});
|
|
12609
|
+
}
|
|
12430
12610
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
12611
|
+
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
12431
12612
|
function mapMark(mark, m) {
|
|
12432
12613
|
if (isIdentity(m)) return mark;
|
|
12433
12614
|
const point = (p) => matrix.apply(m, p);
|
|
12434
12615
|
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
12435
|
-
const scale =
|
|
12616
|
+
const scale = scaleOf(m);
|
|
12436
12617
|
const { outline } = mark;
|
|
12437
12618
|
return {
|
|
12438
12619
|
key: mark.key,
|
|
@@ -12482,7 +12663,7 @@ function isView(value, container) {
|
|
|
12482
12663
|
"destroy"
|
|
12483
12664
|
].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
|
|
12484
12665
|
}
|
|
12485
|
-
function checkOptions$
|
|
12666
|
+
function checkOptions$11(options) {
|
|
12486
12667
|
if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
|
|
12487
12668
|
const { views, initial, transition, announce } = options;
|
|
12488
12669
|
if (typeof views !== "object" || views === null) throw new TypeError("chartSwitch needs views: by name, a function that draws each view's chart in the container it's given.");
|
|
@@ -12515,7 +12696,7 @@ let switches = 0;
|
|
|
12515
12696
|
function motionSwitch$1(target, motion, options = {}) {
|
|
12516
12697
|
const parent = resolveTarget$1(target);
|
|
12517
12698
|
checkMotion(motion);
|
|
12518
|
-
checkOptions$
|
|
12699
|
+
checkOptions$10(options);
|
|
12519
12700
|
const labels = {
|
|
12520
12701
|
...LABELS$1,
|
|
12521
12702
|
...options.labels
|
|
@@ -12599,7 +12780,7 @@ function resolveTarget$1(target) {
|
|
|
12599
12780
|
function checkMotion(motion) {
|
|
12600
12781
|
if (typeof motion !== "object" || motion === null || typeof motion.chooseMode !== "function" || typeof motion.subscribe !== "function") throw new TypeError("motionSwitch needs a Motion, such as the page-wide `motion` or one from createMotion().");
|
|
12601
12782
|
}
|
|
12602
|
-
function checkOptions$
|
|
12783
|
+
function checkOptions$10(options) {
|
|
12603
12784
|
const { label, labels, hints, persist } = options;
|
|
12604
12785
|
if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
|
|
12605
12786
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
@@ -12616,7 +12797,7 @@ const LABELS = {
|
|
|
12616
12797
|
function playButton(target, playback, options = {}) {
|
|
12617
12798
|
const parent = resolveTarget(target);
|
|
12618
12799
|
checkPlayback(playback);
|
|
12619
|
-
checkOptions$
|
|
12800
|
+
checkOptions$9(options);
|
|
12620
12801
|
const labels = {
|
|
12621
12802
|
...LABELS,
|
|
12622
12803
|
...options.labels
|
|
@@ -12657,7 +12838,7 @@ function resolveTarget(target) {
|
|
|
12657
12838
|
function checkPlayback(playback) {
|
|
12658
12839
|
if (typeof playback !== "object" || playback === null || typeof playback.play !== "function" || typeof playback.pause !== "function" || typeof playback.subscribe !== "function") throw new TypeError("playButton needs a Playback, from playback().");
|
|
12659
12840
|
}
|
|
12660
|
-
function checkOptions$
|
|
12841
|
+
function checkOptions$9(options) {
|
|
12661
12842
|
const { labels } = options;
|
|
12662
12843
|
if (labels === void 0) return;
|
|
12663
12844
|
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)}.`);
|
|
@@ -12709,7 +12890,7 @@ const gaits = {
|
|
|
12709
12890
|
const SPEED = 360;
|
|
12710
12891
|
const SHORTEST = 260;
|
|
12711
12892
|
const LONGEST = 4e3;
|
|
12712
|
-
const MIN_WALK$
|
|
12893
|
+
const MIN_WALK$3 = .5;
|
|
12713
12894
|
const FIT = .85;
|
|
12714
12895
|
const MIN_SMOOTHING = 2;
|
|
12715
12896
|
const IDENTITY = [
|
|
@@ -12727,12 +12908,12 @@ const ORIENTS = [
|
|
|
12727
12908
|
];
|
|
12728
12909
|
const RIDES = ["center", "on"];
|
|
12729
12910
|
function travel(icon, options = {}) {
|
|
12730
|
-
checkOptions$
|
|
12911
|
+
checkOptions$8(icon, options);
|
|
12731
12912
|
function plan(mark, ctx) {
|
|
12732
12913
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
12733
12914
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
12734
12915
|
const walk = pick(mark, options.along);
|
|
12735
|
-
if (!walk || !(drawn(walk) >= MIN_WALK$
|
|
12916
|
+
if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
|
|
12736
12917
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
12737
12918
|
if (!(scale > 0)) return void 0;
|
|
12738
12919
|
return trip(walk, resolved, scale, options);
|
|
@@ -12880,7 +13061,7 @@ function heading(walk, distance, window, leg) {
|
|
|
12880
13061
|
}
|
|
12881
13062
|
return walk.angle(distance / length);
|
|
12882
13063
|
}
|
|
12883
|
-
function checkOptions$
|
|
13064
|
+
function checkOptions$8(icon, options) {
|
|
12884
13065
|
if (!(typeof icon === "string" && icon !== "") && (typeof icon !== "object" || icon === null || typeof icon.name !== "string")) throw new TypeError(`travel needs an icon or an icon's name, got ${icon === null ? "null" : typeof icon}.`);
|
|
12885
13066
|
const { along, gait, size, orient, ride } = options;
|
|
12886
13067
|
if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
|
|
@@ -12890,12 +13071,12 @@ function checkOptions$7(icon, options) {
|
|
|
12890
13071
|
if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
|
|
12891
13072
|
}
|
|
12892
13073
|
// src/effects/flash.ts
|
|
12893
|
-
const DURATION$
|
|
13074
|
+
const DURATION$7 = 900;
|
|
12894
13075
|
const PEAK = .25;
|
|
12895
13076
|
const WIDTH$2 = 8;
|
|
12896
13077
|
const OPACITY$2 = .35;
|
|
12897
13078
|
function flash(options = {}) {
|
|
12898
|
-
checkOptions$
|
|
13079
|
+
checkOptions$7(options);
|
|
12899
13080
|
const width = options.width ?? WIDTH$2;
|
|
12900
13081
|
const opacity = options.opacity ?? OPACITY$2;
|
|
12901
13082
|
const { color } = options;
|
|
@@ -12912,7 +13093,7 @@ function flash(options = {}) {
|
|
|
12912
13093
|
async run(_mark, ctx) {
|
|
12913
13094
|
if (ctx.signal.aborted) return;
|
|
12914
13095
|
await ctx.tween({
|
|
12915
|
-
duration: DURATION$
|
|
13096
|
+
duration: DURATION$7,
|
|
12916
13097
|
timing: "effect",
|
|
12917
13098
|
ease: linear,
|
|
12918
13099
|
update: (p) => show(ctx, p)
|
|
@@ -12939,14 +13120,14 @@ function easeOut(x) {
|
|
|
12939
13120
|
const s = (lo + hi) / 2;
|
|
12940
13121
|
return 3 * s * s - 2 * s * s * s;
|
|
12941
13122
|
}
|
|
12942
|
-
function checkOptions$
|
|
13123
|
+
function checkOptions$7(options) {
|
|
12943
13124
|
const { width, opacity, color } = options;
|
|
12944
13125
|
if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`flash: width must be more than 0 px, got ${String(width)}.`);
|
|
12945
13126
|
if (opacity !== void 0 && !(typeof opacity === "number" && opacity > 0 && opacity <= 1)) throw new RangeError(`flash: opacity must be more than 0 and at most 1, got ${String(opacity)}.`);
|
|
12946
13127
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`flash: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
12947
13128
|
}
|
|
12948
13129
|
// src/effects/wiggle.ts
|
|
12949
|
-
const DURATION$
|
|
13130
|
+
const DURATION$6 = 450;
|
|
12950
13131
|
const SWINGS = [
|
|
12951
13132
|
1,
|
|
12952
13133
|
-.5,
|
|
@@ -12957,7 +13138,7 @@ const MIN_REACH = .5;
|
|
|
12957
13138
|
const SAMPLES = 64;
|
|
12958
13139
|
const MAX_ANGLE = Math.PI / 12;
|
|
12959
13140
|
function wiggle(options = {}) {
|
|
12960
|
-
checkOptions$
|
|
13141
|
+
checkOptions$6(options);
|
|
12961
13142
|
const swing = options.swing ?? SWING;
|
|
12962
13143
|
return {
|
|
12963
13144
|
kind: "geometry",
|
|
@@ -12976,7 +13157,7 @@ function wiggle(options = {}) {
|
|
|
12976
13157
|
show();
|
|
12977
13158
|
});
|
|
12978
13159
|
await ctx.tween({
|
|
12979
|
-
duration: DURATION$
|
|
13160
|
+
duration: DURATION$6,
|
|
12980
13161
|
timing: "effect",
|
|
12981
13162
|
ease: linear,
|
|
12982
13163
|
update: (p) => {
|
|
@@ -13002,19 +13183,19 @@ function rock(t) {
|
|
|
13002
13183
|
const index = Math.floor(position);
|
|
13003
13184
|
return SWINGS[index] * Math.sin(Math.PI * (position - index));
|
|
13004
13185
|
}
|
|
13005
|
-
function checkOptions$
|
|
13186
|
+
function checkOptions$6(options) {
|
|
13006
13187
|
const { swing } = options;
|
|
13007
13188
|
if (swing !== void 0 && !(typeof swing === "number" && swing > 0 && swing <= SWING)) throw new RangeError(`wiggle: swing must be more than 0 and at most ${SWING} px, got ${String(swing)}.`);
|
|
13008
13189
|
}
|
|
13009
13190
|
// src/effects/pulse.ts
|
|
13010
|
-
const DURATION$
|
|
13191
|
+
const DURATION$5 = 600;
|
|
13011
13192
|
const TIMES = 2;
|
|
13012
13193
|
const MAX_TIMES = 6;
|
|
13013
13194
|
const WIDTH$1 = 12;
|
|
13014
13195
|
const OPACITY$1 = .4;
|
|
13015
13196
|
const LIMIT = 5e3;
|
|
13016
13197
|
function pulse(options = {}) {
|
|
13017
|
-
checkOptions$
|
|
13198
|
+
checkOptions$5(options);
|
|
13018
13199
|
const times = options.times ?? TIMES;
|
|
13019
13200
|
const width = options.width ?? WIDTH$1;
|
|
13020
13201
|
const { color } = options;
|
|
@@ -13032,11 +13213,11 @@ function pulse(options = {}) {
|
|
|
13032
13213
|
let total = 0;
|
|
13033
13214
|
for (let i = 0; i < times; i++) {
|
|
13034
13215
|
if (ctx.signal.aborted) return;
|
|
13035
|
-
const length = ctx.motion.duration(DURATION$
|
|
13216
|
+
const length = ctx.motion.duration(DURATION$5, "effect");
|
|
13036
13217
|
if (total + length >= LIMIT) return;
|
|
13037
13218
|
total += length;
|
|
13038
13219
|
await ctx.tween({
|
|
13039
|
-
duration: DURATION$
|
|
13220
|
+
duration: DURATION$5,
|
|
13040
13221
|
timing: "effect",
|
|
13041
13222
|
ease: linear,
|
|
13042
13223
|
update: (t) => show(ctx, t)
|
|
@@ -13047,20 +13228,20 @@ function pulse(options = {}) {
|
|
|
13047
13228
|
clear() {}
|
|
13048
13229
|
};
|
|
13049
13230
|
}
|
|
13050
|
-
function checkOptions$
|
|
13231
|
+
function checkOptions$5(options) {
|
|
13051
13232
|
const { times, width, color } = options;
|
|
13052
13233
|
if (times !== void 0 && !(Number.isInteger(times) && times >= 1 && times <= MAX_TIMES)) throw new RangeError(`pulse: times must be a whole number from 1 to ${MAX_TIMES}, got ${String(times)}.`);
|
|
13053
13234
|
if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`pulse: width must be more than 0 px, got ${String(width)}.`);
|
|
13054
13235
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`pulse: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
13055
13236
|
}
|
|
13056
13237
|
// src/effects/trace.ts
|
|
13057
|
-
const DURATION$
|
|
13238
|
+
const DURATION$4 = 500;
|
|
13058
13239
|
const WIDTH = 3;
|
|
13059
13240
|
const OPACITY = .5;
|
|
13060
|
-
const MIN_WALK$
|
|
13241
|
+
const MIN_WALK$2 = .5;
|
|
13061
13242
|
function trace(options = {}) {
|
|
13062
|
-
checkOptions$
|
|
13063
|
-
const duration = options.duration ?? DURATION$
|
|
13243
|
+
checkOptions$4(options);
|
|
13244
|
+
const duration = options.duration ?? DURATION$4;
|
|
13064
13245
|
const paint = {
|
|
13065
13246
|
stroke: options.color ?? "mark",
|
|
13066
13247
|
width: options.width ?? WIDTH,
|
|
@@ -13072,7 +13253,7 @@ function trace(options = {}) {
|
|
|
13072
13253
|
let progress = 0;
|
|
13073
13254
|
let path;
|
|
13074
13255
|
const draw = () => {
|
|
13075
|
-
if (!(current.length >= MIN_WALK$
|
|
13256
|
+
if (!(current.length >= MIN_WALK$2)) {
|
|
13076
13257
|
path?.remove();
|
|
13077
13258
|
path = void 0;
|
|
13078
13259
|
return;
|
|
@@ -13096,7 +13277,7 @@ function trace(options = {}) {
|
|
|
13096
13277
|
async run(mark, ctx) {
|
|
13097
13278
|
if (ctx.signal.aborted) return;
|
|
13098
13279
|
const show = stroke(mark, ctx);
|
|
13099
|
-
if (!(mark.length >= MIN_WALK$
|
|
13280
|
+
if (!(mark.length >= MIN_WALK$2)) {
|
|
13100
13281
|
show(1);
|
|
13101
13282
|
return;
|
|
13102
13283
|
}
|
|
@@ -13113,13 +13294,82 @@ function trace(options = {}) {
|
|
|
13113
13294
|
clear() {}
|
|
13114
13295
|
};
|
|
13115
13296
|
}
|
|
13116
|
-
function checkOptions$
|
|
13297
|
+
function checkOptions$4(options) {
|
|
13117
13298
|
const { color, width, opacity, duration } = options;
|
|
13118
13299
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
13119
13300
|
if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
|
|
13120
13301
|
if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
|
|
13121
13302
|
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
13122
13303
|
}
|
|
13304
|
+
// src/effects/draw-in.ts
|
|
13305
|
+
const DURATION$3 = 750;
|
|
13306
|
+
const FAINT = .3;
|
|
13307
|
+
const MIN_WALK$1 = .5;
|
|
13308
|
+
function drawIn(options = {}) {
|
|
13309
|
+
checkOptions$3(options);
|
|
13310
|
+
const duration = options.duration ?? DURATION$3;
|
|
13311
|
+
const faint = options.faint ?? FAINT;
|
|
13312
|
+
return {
|
|
13313
|
+
kind: "geometry",
|
|
13314
|
+
async run(mark, ctx) {
|
|
13315
|
+
if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
|
|
13316
|
+
let current = mark;
|
|
13317
|
+
let progress = 0;
|
|
13318
|
+
let done = false;
|
|
13319
|
+
const paths = [];
|
|
13320
|
+
const draw = (repaint) => {
|
|
13321
|
+
const { segments } = current;
|
|
13322
|
+
const parts = segments ?? [current];
|
|
13323
|
+
const reached = progress * walk(current);
|
|
13324
|
+
let from = 0;
|
|
13325
|
+
parts.forEach((piece, i) => {
|
|
13326
|
+
const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
|
|
13327
|
+
from += piece.length;
|
|
13328
|
+
const d = piece.slice(0, easeInOutCubic(share));
|
|
13329
|
+
const paint = {
|
|
13330
|
+
stroke: "mark",
|
|
13331
|
+
width: piece.thickness,
|
|
13332
|
+
linecap: "butt",
|
|
13333
|
+
...segments && { part: piece.key }
|
|
13334
|
+
};
|
|
13335
|
+
const path = paths[i];
|
|
13336
|
+
if (!path) paths[i] = ctx.layer.path(d, paint);
|
|
13337
|
+
else path.update(d, repaint ? {
|
|
13338
|
+
part: void 0,
|
|
13339
|
+
...paint
|
|
13340
|
+
} : void 0);
|
|
13341
|
+
});
|
|
13342
|
+
for (const path of paths.splice(parts.length)) path.remove();
|
|
13343
|
+
};
|
|
13344
|
+
ctx.onChange((next) => {
|
|
13345
|
+
current = next;
|
|
13346
|
+
if (!done) draw(true);
|
|
13347
|
+
});
|
|
13348
|
+
ctx.mark.set({ opacity: faint });
|
|
13349
|
+
draw(false);
|
|
13350
|
+
await ctx.tween({
|
|
13351
|
+
duration,
|
|
13352
|
+
timing: "effect",
|
|
13353
|
+
ease: linear,
|
|
13354
|
+
update: (p) => {
|
|
13355
|
+
progress = p;
|
|
13356
|
+
draw(false);
|
|
13357
|
+
}
|
|
13358
|
+
}).finished;
|
|
13359
|
+
done = true;
|
|
13360
|
+
for (const path of paths) path.remove();
|
|
13361
|
+
ctx.mark.set({ opacity: void 0 });
|
|
13362
|
+
},
|
|
13363
|
+
end() {},
|
|
13364
|
+
clear() {}
|
|
13365
|
+
};
|
|
13366
|
+
}
|
|
13367
|
+
const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
|
|
13368
|
+
function checkOptions$3(options) {
|
|
13369
|
+
const { duration, faint } = options;
|
|
13370
|
+
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`drawIn: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
13371
|
+
if (faint !== void 0 && !(typeof faint === "number" && faint >= 0 && faint <= 1)) throw new RangeError(`drawIn: faint must be from 0 to 1, got ${String(faint)}.`);
|
|
13372
|
+
}
|
|
13123
13373
|
// src/effects/caption.ts
|
|
13124
13374
|
const PAST_END = 10;
|
|
13125
13375
|
const PAST_LABEL = 6;
|
|
@@ -13140,9 +13390,9 @@ function captionPlace(mark, text) {
|
|
|
13140
13390
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
13141
13391
|
}
|
|
13142
13392
|
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, {
|
|
13393
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
13394
|
+
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
13395
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
13146
13396
|
x: x - from.x,
|
|
13147
13397
|
y: y - from.y,
|
|
13148
13398
|
width,
|
|
@@ -13184,7 +13434,7 @@ const grow = ({ x, y, width, height }, by) => ({
|
|
|
13184
13434
|
width: width + 2 * by,
|
|
13185
13435
|
height: height + 2 * by
|
|
13186
13436
|
});
|
|
13187
|
-
function placed(from, toward, distance) {
|
|
13437
|
+
function placed$1(from, toward, distance) {
|
|
13188
13438
|
const cos = Math.cos(toward);
|
|
13189
13439
|
const sin = Math.sin(toward);
|
|
13190
13440
|
const point = offset(from, toward, distance);
|
|
@@ -13424,7 +13674,7 @@ function reference(compareTo, data) {
|
|
|
13424
13674
|
const gaps = gapsOf(related.samples, place);
|
|
13425
13675
|
return {
|
|
13426
13676
|
place,
|
|
13427
|
-
valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
|
|
13677
|
+
valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
|
|
13428
13678
|
bends: points.map((point) => point.u)
|
|
13429
13679
|
};
|
|
13430
13680
|
}
|
|
@@ -13446,7 +13696,7 @@ function gapsOf(samples, place) {
|
|
|
13446
13696
|
}
|
|
13447
13697
|
return merged;
|
|
13448
13698
|
}
|
|
13449
|
-
function inside(gaps, u) {
|
|
13699
|
+
function inside$1(gaps, u) {
|
|
13450
13700
|
let lo = 0;
|
|
13451
13701
|
let hi = gaps.length;
|
|
13452
13702
|
while (lo < hi) {
|
|
@@ -13553,6 +13803,8 @@ const DURATION = 950;
|
|
|
13553
13803
|
const POINTS = 160;
|
|
13554
13804
|
const ALIGNS = ["unroll", "drop"];
|
|
13555
13805
|
const SAME_T = 1e-9;
|
|
13806
|
+
const SAME_X = .01;
|
|
13807
|
+
const VERTICES = 1e3;
|
|
13556
13808
|
const GRID = 9;
|
|
13557
13809
|
const CHECKS = 8;
|
|
13558
13810
|
function morph(options = {}) {
|
|
@@ -13592,6 +13844,8 @@ function morph(options = {}) {
|
|
|
13592
13844
|
function drawing(from, to, layer, points, align) {
|
|
13593
13845
|
const closed = from.outline.closed;
|
|
13594
13846
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
13847
|
+
const across = closed ? void 0 : acrossX(from, to, points);
|
|
13848
|
+
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
13595
13849
|
const a = from.outline.sample(points);
|
|
13596
13850
|
const b = to.outline.sample(points);
|
|
13597
13851
|
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
@@ -13629,20 +13883,25 @@ function gapped(from, to, layer, a, b) {
|
|
|
13629
13883
|
to: to.path(t)
|
|
13630
13884
|
});
|
|
13631
13885
|
stops.sort((x, y) => x.t - y.t);
|
|
13886
|
+
return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
|
|
13887
|
+
const t = (stops[k].t + stop.t) / 2;
|
|
13888
|
+
return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
13889
|
+
}));
|
|
13890
|
+
}
|
|
13891
|
+
function piecewise(from, to, layer, stops, kinds) {
|
|
13632
13892
|
const runs = [
|
|
13633
13893
|
[],
|
|
13634
13894
|
[],
|
|
13635
13895
|
[]
|
|
13636
13896
|
];
|
|
13637
|
-
for (let k = 0; k
|
|
13638
|
-
const
|
|
13639
|
-
const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
13897
|
+
for (let k = 0; k < kinds.length; k++) {
|
|
13898
|
+
const kind = kinds[k];
|
|
13640
13899
|
if (kind === 3) continue;
|
|
13641
13900
|
const last = runs[kind][runs[kind].length - 1];
|
|
13642
13901
|
if (last && last[1] === k) last[1] = k + 1;
|
|
13643
13902
|
else runs[kind].push([k, k + 1]);
|
|
13644
13903
|
}
|
|
13645
|
-
const
|
|
13904
|
+
const order = [
|
|
13646
13905
|
0,
|
|
13647
13906
|
1,
|
|
13648
13907
|
2
|
|
@@ -13655,7 +13914,7 @@ function gapped(from, to, layer, a, b) {
|
|
|
13655
13914
|
p,
|
|
13656
13915
|
1 - p
|
|
13657
13916
|
];
|
|
13658
|
-
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] :
|
|
13917
|
+
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] : order.map((kind) => [runs[kind].map((run) => along(stops, run, p)).join(""), opacities[kind]]);
|
|
13659
13918
|
pieces.forEach(([d, opacity], i) => {
|
|
13660
13919
|
if (paths[i]) paths[i].update(d, {
|
|
13661
13920
|
width,
|
|
@@ -13676,6 +13935,113 @@ function along(stops, [first, last], p) {
|
|
|
13676
13935
|
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
13677
13936
|
return d;
|
|
13678
13937
|
}
|
|
13938
|
+
function acrossX(from, to, points) {
|
|
13939
|
+
const a = courseOf(from);
|
|
13940
|
+
const b = a && courseOf(to);
|
|
13941
|
+
if (!a || !b || a.way !== b.way) return void 0;
|
|
13942
|
+
const all = [
|
|
13943
|
+
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
13944
|
+
...corners(a).map((s) => [s, 1]),
|
|
13945
|
+
...corners(b).map((s) => [s, 2])
|
|
13946
|
+
].sort((x, y) => x[0] - y[0]);
|
|
13947
|
+
const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
|
|
13948
|
+
const merged = [];
|
|
13949
|
+
for (const [s, whose] of all) {
|
|
13950
|
+
var _stop, _stop2;
|
|
13951
|
+
let stop = merged[merged.length - 1];
|
|
13952
|
+
if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
|
|
13953
|
+
if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
|
|
13954
|
+
if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
|
|
13955
|
+
}
|
|
13956
|
+
const last = merged.length - 1;
|
|
13957
|
+
if (last < 1) return void 0;
|
|
13958
|
+
const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
|
|
13959
|
+
const [onA, onB] = [shareOn(1), shareOn(2)];
|
|
13960
|
+
const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
|
|
13961
|
+
const stops = merged.map(([t], k) => ({
|
|
13962
|
+
t,
|
|
13963
|
+
from: pointsA[k],
|
|
13964
|
+
to: pointsB[k]
|
|
13965
|
+
}));
|
|
13966
|
+
const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
|
|
13967
|
+
return {
|
|
13968
|
+
stops,
|
|
13969
|
+
kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
|
|
13970
|
+
};
|
|
13971
|
+
}
|
|
13972
|
+
function courseOf(mark) {
|
|
13973
|
+
const subpaths = flattenPath(parsePath(mark.outline.d));
|
|
13974
|
+
const points = [];
|
|
13975
|
+
const before = [];
|
|
13976
|
+
let next = 0;
|
|
13977
|
+
let from = 0;
|
|
13978
|
+
const stretch = (to) => {
|
|
13979
|
+
if (!(to > from)) {
|
|
13980
|
+
points.push(mark.path(from));
|
|
13981
|
+
return true;
|
|
13982
|
+
}
|
|
13983
|
+
const subpath = subpaths[next++];
|
|
13984
|
+
if (!subpath) return false;
|
|
13985
|
+
points.push(subpath.start);
|
|
13986
|
+
for (const segment of subpath.segments) {
|
|
13987
|
+
if (segment.kind !== "line") return false;
|
|
13988
|
+
points.push(segment.to);
|
|
13989
|
+
}
|
|
13990
|
+
return true;
|
|
13991
|
+
};
|
|
13992
|
+
for (const [start, end] of mark.gaps ?? []) {
|
|
13993
|
+
if (!stretch(start)) return void 0;
|
|
13994
|
+
before.push(points.length - 1);
|
|
13995
|
+
from = end;
|
|
13996
|
+
}
|
|
13997
|
+
if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
|
|
13998
|
+
const x0 = points[0].x;
|
|
13999
|
+
const span = points[points.length - 1].x - x0;
|
|
14000
|
+
const way = Math.sign(span);
|
|
14001
|
+
for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
|
|
14002
|
+
const shares = points.map((point) => (point.x - x0) / span);
|
|
14003
|
+
return {
|
|
14004
|
+
points,
|
|
14005
|
+
shares,
|
|
14006
|
+
gaps: before.map((i) => [shares[i], shares[i + 1]]),
|
|
14007
|
+
span,
|
|
14008
|
+
way
|
|
14009
|
+
};
|
|
14010
|
+
}
|
|
14011
|
+
function corners(course) {
|
|
14012
|
+
const { points, shares, gaps } = course;
|
|
14013
|
+
if (points.length <= VERTICES) return shares;
|
|
14014
|
+
const columns = VERTICES / 4;
|
|
14015
|
+
const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
|
|
14016
|
+
const kept = gaps.flat();
|
|
14017
|
+
for (let first = 0, i = 1; i <= points.length; i++) {
|
|
14018
|
+
if (i < points.length && column(i) === column(first)) continue;
|
|
14019
|
+
let [low, high] = [first, first];
|
|
14020
|
+
for (let k = first; k < i; k++) {
|
|
14021
|
+
if (points[k].y < points[low].y) low = k;
|
|
14022
|
+
if (points[k].y > points[high].y) high = k;
|
|
14023
|
+
}
|
|
14024
|
+
kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
|
|
14025
|
+
first = i;
|
|
14026
|
+
}
|
|
14027
|
+
return Array.from(new Set(kept));
|
|
14028
|
+
}
|
|
14029
|
+
function placed(course, shares) {
|
|
14030
|
+
const { points, shares: at } = course;
|
|
14031
|
+
let i = 0;
|
|
14032
|
+
return shares.map((s) => {
|
|
14033
|
+
while (i + 2 < points.length && at[i + 1] <= s) i++;
|
|
14034
|
+
const width = at[i + 1] - at[i];
|
|
14035
|
+
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
14036
|
+
});
|
|
14037
|
+
}
|
|
14038
|
+
function inside(gaps) {
|
|
14039
|
+
let k = 0;
|
|
14040
|
+
return (s) => {
|
|
14041
|
+
while (k < gaps.length && gaps[k][1] <= s) k++;
|
|
14042
|
+
return k < gaps.length && gaps[k][0] < s;
|
|
14043
|
+
};
|
|
14044
|
+
}
|
|
13679
14045
|
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
13680
14046
|
const holesA = holesOf(from.outline, count);
|
|
13681
14047
|
const holesB = holesOf(to.outline, count);
|
|
@@ -14470,7 +14836,7 @@ function configure(options) {
|
|
|
14470
14836
|
}
|
|
14471
14837
|
}
|
|
14472
14838
|
// src/index.ts
|
|
14473
|
-
const VERSION = "0.
|
|
14839
|
+
const VERSION = "0.7.0";
|
|
14474
14840
|
const env = {
|
|
14475
14841
|
presets: presetRegistry,
|
|
14476
14842
|
icons: iconRegistry,
|
|
@@ -14516,6 +14882,7 @@ exports.defineIcon = defineIcon;
|
|
|
14516
14882
|
exports.delta = delta;
|
|
14517
14883
|
exports.describe = describe;
|
|
14518
14884
|
exports.donutChart = donutChart;
|
|
14885
|
+
exports.drawIn = drawIn;
|
|
14519
14886
|
exports.easeInOutCubic = easeInOutCubic;
|
|
14520
14887
|
exports.easeOutCubic = easeOutCubic;
|
|
14521
14888
|
exports.expressive = expressive;
|