magic-pill 9.3.0 → 9.4.0-next.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +114 -3
  3. package/dist/MagicPill/MagicPill.d.mts +51 -1
  4. package/dist/MagicPill/MagicPill.d.ts +51 -1
  5. package/dist/MagicPill/MagicPill.js +53 -4
  6. package/dist/MagicPill/MagicPill.mjs +55 -6
  7. package/dist/MagicPill/flag.js +1 -59
  8. package/dist/MagicPill/flag.mjs +1 -58
  9. package/dist/Pill/PillProgress.d.mts +12 -0
  10. package/dist/Pill/PillProgress.d.ts +12 -0
  11. package/dist/Pill/PillProgress.js +42 -0
  12. package/dist/Pill/PillProgress.mjs +42 -0
  13. package/dist/Pill/goo.js +576 -0
  14. package/dist/Pill/goo.mjs +566 -0
  15. package/dist/Pill/morph.js +11 -4
  16. package/dist/Pill/morph.mjs +10 -5
  17. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  18. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  19. package/dist/PillNavbar/PillNavbar.js +3 -2
  20. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  21. package/dist/PillNavbar/room.d.mts +3 -0
  22. package/dist/PillNavbar/room.d.ts +2 -0
  23. package/dist/PillNavbar/room.js +89 -17
  24. package/dist/PillNavbar/room.mjs +89 -18
  25. package/dist/index.d.mts +3 -2
  26. package/dist/index.d.ts +3 -2
  27. package/dist/index.js +2 -0
  28. package/dist/index.mjs +2 -1
  29. package/dist/satellites/Actions.d.mts +12 -0
  30. package/dist/satellites/Actions.d.ts +11 -0
  31. package/dist/satellites/Actions.js +181 -0
  32. package/dist/satellites/Actions.mjs +177 -0
  33. package/dist/satellites/Orbitals.js +585 -0
  34. package/dist/satellites/Orbitals.mjs +585 -0
  35. package/dist/satellites/Satellites.js +634 -0
  36. package/dist/satellites/Satellites.mjs +634 -0
  37. package/dist/satellites/layout.js +209 -0
  38. package/dist/satellites/layout.mjs +209 -0
  39. package/dist/satellites/measure.js +25 -0
  40. package/dist/satellites/measure.mjs +24 -0
  41. package/dist/satellites/orbits.js +139 -0
  42. package/dist/satellites/orbits.mjs +136 -0
  43. package/dist/satellites/types.d.mts +58 -0
  44. package/dist/satellites/types.d.ts +58 -0
  45. package/dist/satellites.d.mts +5 -0
  46. package/dist/satellites.d.ts +5 -0
  47. package/dist/satellites.js +14 -0
  48. package/dist/satellites.mjs +12 -0
  49. package/dist/store/store.d.mts +103 -0
  50. package/dist/store/store.d.ts +103 -0
  51. package/dist/store/store.js +52 -1
  52. package/dist/store/store.mjs +52 -2
  53. package/dist/styles.css +322 -8
  54. package/package.json +11 -1
@@ -0,0 +1,576 @@
1
+ const require_timing = require("../utils/timing.js");
2
+
3
+ // src/Pill/goo.ts
4
+ /** The id of the moving pill's animations, so that a new split or join can stop the last one. */
5
+ const SPLIT = "mp-split";
6
+ /** How sticky the goo is by default: the blur behind the neck, in px (`--mp-goo`). */
7
+ const DEFAULT_GOO = 12;
8
+ const POP = "cubic-bezier(0.34, 1.56, 0.64, 1)";
9
+ const SMOOTH = "cubic-bezier(0.42, 0, 0.58, 1)";
10
+ /**
11
+ * A spring as a CSS `linear()` curve: it overshoots, then settles with a
12
+ * little wobble. The prototype's "bouncy" curve, the default for a split.
13
+ */
14
+ function springEasing(points = 40) {
15
+ const values = [];
16
+ for (let index = 0; index <= points; index++) {
17
+ const t = index / points;
18
+ const value = t === 1 ? 1 : 1 - Math.exp(-6 * t) * Math.cos(2 * Math.PI * 1.35 * t);
19
+ values.push(String(Number(value.toFixed(4))));
20
+ }
21
+ return `linear(${values.join(", ")})`;
22
+ }
23
+ const BOUNCY = springEasing();
24
+ /** `--mp-ease-split`: `bouncy` (default), `pop`, `smooth`, or any CSS easing. */
25
+ function splitEasing(token) {
26
+ const value = token.trim();
27
+ if (value === "" || value === "bouncy") return BOUNCY;
28
+ if (value === "pop") return POP;
29
+ if (value === "smooth") return SMOOTH;
30
+ return value;
31
+ }
32
+ /** How much goo the motion needs at progress `k` (0 to 1): none at the ends, all of it while the neck forms. */
33
+ function gooAmount(k) {
34
+ const step = (from, to, x) => {
35
+ const t = Math.min(1, Math.max(0, (x - from) / (to - from)));
36
+ return t * t * (3 - 2 * t);
37
+ };
38
+ return step(0, .12, k) * (1 - step(.72, 1, k));
39
+ }
40
+ /**
41
+ * Where the moving pill is tucked in: centred on the anchor's edge minus half
42
+ * its own size, so that it's hidden behind the anchor's end and comes out of
43
+ * it. It starts at `start` of its size (`--mp-electron-start`, 1 by default),
44
+ * smaller when it wouldn't fit inside the anchor (a flag, wider than the
45
+ * sidebar it comes out of), so that it can hide there. Pure, so it can be tested.
46
+ */
47
+ function tuckedOffset(anchor, moving, start = 1) {
48
+ const anchorX = anchor.left + anchor.width / 2;
49
+ const anchorY = anchor.top + anchor.height / 2;
50
+ const movingX = moving.left + moving.width / 2;
51
+ const movingY = moving.top + moving.height / 2;
52
+ const dx = movingX - anchorX;
53
+ const dy = movingY - anchorY;
54
+ const fits = (size, room) => size * start <= room * 1.05;
55
+ let scale = start;
56
+ if (!fits(moving.width, anchor.width)) scale = Math.min(scale, anchor.width / moving.width);
57
+ if (!fits(moving.height, anchor.height)) scale = Math.min(scale, anchor.height / moving.height);
58
+ scale = Math.max(.2, scale);
59
+ if (Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2)) {
60
+ const sign = Math.sign(dx) || 1;
61
+ return {
62
+ x: anchorX + sign * anchor.width / 2 - sign * moving.width * scale / 2 - movingX,
63
+ y: 0,
64
+ scale
65
+ };
66
+ }
67
+ const sign = Math.sign(dy) || 1;
68
+ return {
69
+ x: 0,
70
+ y: anchorY + sign * anchor.height / 2 - sign * moving.height * scale / 2 - movingY,
71
+ scale
72
+ };
73
+ }
74
+ /** The first outer shadow of a computed `box-shadow` (a theme's rim is inset, and skipped). */
75
+ function dropShadow(boxShadow) {
76
+ if (!boxShadow || boxShadow === "none") return null;
77
+ const parts = [];
78
+ let depth = 0;
79
+ let current = "";
80
+ for (const character of boxShadow) {
81
+ if (character === "(") depth++;
82
+ if (character === ")") depth--;
83
+ if (character === "," && depth === 0) {
84
+ parts.push(current.trim());
85
+ current = "";
86
+ } else current += character;
87
+ }
88
+ parts.push(current.trim());
89
+ for (const part of parts) {
90
+ if (/\binset\b/.test(part)) continue;
91
+ const color = /[a-z-]+\([^)]*\)|#[0-9a-f]{3,8}\b/i.exec(part)?.[0] ?? "rgb(0 0 0 / 0.3)";
92
+ const lengths = part.replace(color, "").match(/-?[\d.]+px/g)?.map((length) => Number.parseFloat(length)) ?? [];
93
+ if (lengths.length < 2) continue;
94
+ return {
95
+ color,
96
+ x: lengths[0],
97
+ y: lengths[1],
98
+ blur: lengths[2] ?? 0
99
+ };
100
+ }
101
+ return null;
102
+ }
103
+ const running = /* @__PURE__ */ new WeakMap();
104
+ let overlays = 0;
105
+ const SVG = "http://www.w3.org/2000/svg";
106
+ /** The overlay: a filter (blur, threshold, the anchor's inside cut out, a fill, a shadow) and two shapes. */
107
+ function createOverlay(zIndex, color, shadow) {
108
+ const id = `mp-goo-${++overlays}`;
109
+ const root = document.createElement("div");
110
+ root.setAttribute("data-mp", "goo");
111
+ root.setAttribute("aria-hidden", "true");
112
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${zIndex};`;
113
+ const svg = document.createElementNS(SVG, "svg");
114
+ svg.setAttribute("width", "0");
115
+ svg.setAttribute("height", "0");
116
+ svg.style.position = "absolute";
117
+ const filter = document.createElementNS(SVG, "filter");
118
+ filter.id = id;
119
+ for (const [name, value] of Object.entries({
120
+ x: "-50%",
121
+ y: "-50%",
122
+ width: "200%",
123
+ height: "200%",
124
+ "color-interpolation-filters": "sRGB"
125
+ })) filter.setAttribute(name, value);
126
+ filter.innerHTML = `
127
+ <feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
128
+ <feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
129
+ <feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0" result="anchor"/>
130
+ <feMorphology in="anchor" operator="erode" radius="1" result="inside"/>
131
+ <feComposite in="goo" in2="inside" operator="out" result="cut"/>
132
+ <feFlood result="color"/>
133
+ <feComposite in="color" in2="cut" operator="in" result="fill"/>
134
+ <feGaussianBlur in="cut" stdDeviation="${shadow ? shadow.blur / 2 : 0}" result="spread"/>
135
+ <feOffset in="spread" dx="${shadow?.x ?? 0}" dy="${shadow?.y ?? 0}" result="offset"/>
136
+ <feFlood result="shade"/>
137
+ <feComposite in="shade" in2="offset" operator="in" result="shadow"/>
138
+ <feComposite in="shadow" in2="cut" operator="out" result="outside"/>
139
+ <feMerge><feMergeNode in="outside"/><feMergeNode in="fill"/></feMerge>`;
140
+ const [fill, shade] = filter.querySelectorAll("feFlood");
141
+ fill.style.setProperty("flood-color", color);
142
+ shade.style.setProperty("flood-color", shadow?.color ?? "transparent");
143
+ svg.append(filter);
144
+ const layer = document.createElement("div");
145
+ layer.style.cssText = `position:absolute;inset:0;filter:url(#${id});`;
146
+ const shape = (marker) => {
147
+ const element = document.createElement("div");
148
+ element.style.cssText = `position:absolute;left:0;top:0;background:${marker};`;
149
+ layer.append(element);
150
+ return element;
151
+ };
152
+ const anchor = shape("rgb(0 0 255)");
153
+ const moving = shape("rgb(255 0 0)");
154
+ root.append(svg, layer);
155
+ document.body.append(root);
156
+ return {
157
+ root,
158
+ layer,
159
+ blur: filter.querySelector("feGaussianBlur"),
160
+ anchor,
161
+ moving
162
+ };
163
+ }
164
+ /**
165
+ * Puts the overlay around the two pills (with `margin` for the blur and the
166
+ * shadow), and each shape where its pill is, with its rounded corners at its
167
+ * current scale (`radius`: read once, at its full size).
168
+ */
169
+ function placeAll(overlay, pills, radii, margin) {
170
+ const a = pills.anchor.getBoundingClientRect();
171
+ const m = pills.moving.getBoundingClientRect();
172
+ const left = Math.min(a.left, m.left) - margin;
173
+ const top = Math.min(a.top, m.top) - margin;
174
+ const root = overlay.root.style;
175
+ root.transform = `translate(${left}px, ${top}px)`;
176
+ root.width = `${Math.max(a.right, m.right) + margin - left}px`;
177
+ root.height = `${Math.max(a.bottom, m.bottom) + margin - top}px`;
178
+ const put = (shape, rect, element, radius) => {
179
+ const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
180
+ shape.style.width = `${rect.width}px`;
181
+ shape.style.height = `${rect.height}px`;
182
+ shape.style.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
183
+ shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
184
+ };
185
+ put(overlay.anchor, a, pills.anchor, radii.anchor);
186
+ put(overlay.moving, m, pills.moving, radii.moving);
187
+ }
188
+ const OWN_LOOK = {
189
+ transition: "none",
190
+ "background-color": "transparent",
191
+ "background-image": "none",
192
+ "box-shadow": "none"
193
+ };
194
+ const BLUR = ["backdrop-filter", "-webkit-backdrop-filter"];
195
+ const GLASS_FADE = 120;
196
+ const overlaps = (a, b) => a.left < b.right + 1 && a.right > b.left - 1 && a.top < b.bottom + 1 && a.bottom > b.top - 1;
197
+ const readNumber = (style, name, fallback) => {
198
+ const value = Number.parseFloat(style.getPropertyValue(name));
199
+ return Number.isFinite(value) ? value : fallback;
200
+ };
201
+ /**
202
+ * Plays a split (the moving pill comes out of the anchor's edge, from where
203
+ * it's tucked in to where it sits) or a join (the other way, after `delay`).
204
+ * Reads `--mp-goo`, `--mp-electron-start` and `--mp-ease-split` on the
205
+ * moving pill. Does nothing with reduced motion. Returns a function that
206
+ * stops it at once.
207
+ */
208
+ function playSplit(anchor, moving, kind, timing) {
209
+ running.get(moving)?.();
210
+ for (const animation of moving.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
211
+ if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof moving.animate !== "function") return () => {};
212
+ const style = getComputedStyle(moving);
213
+ const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
214
+ const start = readNumber(style, "--mp-electron-start", 1);
215
+ const fade = require_timing.parseDuration(style.getPropertyValue("--_mp-fade"), 150);
216
+ const easing = kind === "split" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
217
+ let overlay = null;
218
+ const radii = {
219
+ anchor: 0,
220
+ moving: 0
221
+ };
222
+ let margin = 0;
223
+ const placeShapes = () => {
224
+ if (overlay) placeAll(overlay, {
225
+ anchor,
226
+ moving
227
+ }, radii, margin);
228
+ };
229
+ let glass = kind === "join";
230
+ const saved = /* @__PURE__ */ new Map();
231
+ let frame = 0;
232
+ let begun = false;
233
+ let stopped = false;
234
+ const hideOwnLook = () => {
235
+ for (const [name, value] of Object.entries(OWN_LOOK)) {
236
+ if (!saved.has(name)) saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
237
+ moving.style.setProperty(name, value, "important");
238
+ }
239
+ };
240
+ const setGlass = (on) => {
241
+ if (on === glass) return;
242
+ glass = on;
243
+ if (on) {
244
+ for (const name of BLUR) restore(name);
245
+ moving.animate([{
246
+ backdropFilter: "none",
247
+ offset: 0
248
+ }], {
249
+ id: SPLIT,
250
+ duration: GLASS_FADE,
251
+ easing: "ease-out"
252
+ });
253
+ } else moving.animate([{
254
+ backdropFilter: "none",
255
+ offset: 1
256
+ }], {
257
+ id: SPLIT,
258
+ duration: GLASS_FADE,
259
+ easing: "ease-in",
260
+ fill: "forwards"
261
+ });
262
+ };
263
+ const restore = (name) => {
264
+ const [value, priority] = saved.get(name) ?? ["", ""];
265
+ if (value) moving.style.setProperty(name, value, priority);
266
+ else moving.style.removeProperty(name);
267
+ };
268
+ const restoreOwnLook = () => {
269
+ if (saved.size === 0) return;
270
+ for (const name of saved.keys()) if (name !== "transition") restore(name);
271
+ getComputedStyle(moving).backgroundColor;
272
+ restore("transition");
273
+ saved.clear();
274
+ };
275
+ const move = () => {
276
+ const tucked = tuckedOffset(anchor.getBoundingClientRect(), moving.getBoundingClientRect(), start);
277
+ const out = {
278
+ translate: "0px 0px",
279
+ scale: "1",
280
+ transformOrigin: "center"
281
+ };
282
+ const tuck = {
283
+ translate: `${tucked.x}px ${tucked.y}px`,
284
+ scale: String(tucked.scale),
285
+ transformOrigin: "center"
286
+ };
287
+ const options = {
288
+ id: SPLIT,
289
+ duration: timing.duration,
290
+ fill: kind === "split" ? "backwards" : "forwards"
291
+ };
292
+ try {
293
+ moving.animate(kind === "split" ? [tuck, out] : [out, tuck], {
294
+ ...options,
295
+ easing
296
+ });
297
+ } catch {
298
+ moving.animate(kind === "split" ? [tuck, out] : [out, tuck], {
299
+ ...options,
300
+ easing: POP
301
+ });
302
+ }
303
+ const content = [...moving.children].filter((child) => !["panel", "outgoing"].includes(child.getAttribute("data-mp") ?? ""));
304
+ const total = timing.duration + fade;
305
+ for (const child of content) if (kind === "split") child.animate([
306
+ { opacity: 0 },
307
+ {
308
+ opacity: 0,
309
+ offset: timing.duration * .8 / total
310
+ },
311
+ { opacity: 1 }
312
+ ], {
313
+ id: SPLIT,
314
+ duration: total
315
+ });
316
+ else child.animate([{ opacity: 1 }, { opacity: 0 }], {
317
+ id: SPLIT,
318
+ duration: Math.max(1, fade),
319
+ fill: "forwards"
320
+ });
321
+ };
322
+ const begin = () => {
323
+ begun = true;
324
+ move();
325
+ if (goo <= 0) return;
326
+ const zIndex = (Number.parseInt(style.zIndex, 10) || 50) - 1;
327
+ saved.set("transition", [moving.style.getPropertyValue("transition"), moving.style.getPropertyPriority("transition")]);
328
+ moving.style.setProperty("transition", "none", "important");
329
+ const own = getComputedStyle(moving);
330
+ const shadow = dropShadow(own.boxShadow);
331
+ overlay = createOverlay(zIndex, own.backgroundColor, shadow);
332
+ radii.anchor = Number.parseFloat(getComputedStyle(anchor).borderTopLeftRadius) || 0;
333
+ radii.moving = Number.parseFloat(own.borderTopLeftRadius) || 0;
334
+ margin = goo * 3 + (shadow ? shadow.blur + Math.max(Math.abs(shadow.x), Math.abs(shadow.y)) : 0) + 8;
335
+ placeShapes();
336
+ hideOwnLook();
337
+ if (kind === "split") for (const name of BLUR) {
338
+ saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
339
+ moving.style.setProperty(name, "none", "important");
340
+ }
341
+ };
342
+ const stop = () => {
343
+ if (stopped) return;
344
+ stopped = true;
345
+ cancelAnimationFrame(frame);
346
+ overlay?.root.remove();
347
+ overlay = null;
348
+ restoreOwnLook();
349
+ running.delete(moving);
350
+ };
351
+ const startedAt = performance.now();
352
+ const draw = (now) => {
353
+ if (stopped) return;
354
+ const elapsed = now - startedAt;
355
+ if (!begun && elapsed >= timing.delay) begin();
356
+ if (begun && overlay) {
357
+ const k = Math.min(1, Math.max(0, (elapsed - timing.delay) / timing.duration));
358
+ overlay.blur.setAttribute("stdDeviation", (goo * gooAmount(k)).toFixed(2));
359
+ placeShapes();
360
+ setGlass(!overlaps(moving.getBoundingClientRect(), anchor.getBoundingClientRect()));
361
+ }
362
+ if (elapsed >= timing.delay + timing.duration) {
363
+ stop();
364
+ return;
365
+ }
366
+ frame = requestAnimationFrame(draw);
367
+ };
368
+ if (timing.delay <= 0) begin();
369
+ frame = requestAnimationFrame(draw);
370
+ running.set(moving, stop);
371
+ return stop;
372
+ }
373
+ /** Inside the anchor at its nearest edge, as a flag goes into its sidebar (`--mp-electron-start`). */
374
+ const atEdgeOf = (anchor) => (rect, element) => tuckedOffset(anchor.getBoundingClientRect(), rect, readNumber(getComputedStyle(element), "--mp-electron-start", 1));
375
+ /** Inside the anchor at a point of the screen (where a pill closing to a circle ends), small. */
376
+ const atPoint = (x, y, scale = .3) => (rect) => ({
377
+ x: x - (rect.left + rect.width / 2),
378
+ y: y - (rect.top + rect.height / 2),
379
+ scale
380
+ });
381
+ const budding = /* @__PURE__ */ new WeakMap();
382
+ /**
383
+ * Pills budding out of another (or going back into it), one after the other,
384
+ * as the concept drew an electron's orbitals: from inside it, small and
385
+ * see-through, to their spot. The pills draw themselves the whole time (their
386
+ * glass, rim and shadow stay, no colour switch at the end); one overlay under
387
+ * them draws only the necks between them and the anchor: the goo of the
388
+ * moment, every pill's inside cut out of it. An electron's orbitals, an
389
+ * electron out of its host or out of the one next to it, the page's actions.
390
+ */
391
+ function playOrbit(electron, items, kind, timing) {
392
+ for (const { element } of items) {
393
+ budding.get(element)?.();
394
+ for (const animation of element.getAnimations?.() ?? []) if (animation.id === "mp-split") animation.cancel();
395
+ }
396
+ if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof electron.animate !== "function" || items.length === 0) return () => {};
397
+ const style = getComputedStyle(electron);
398
+ const easing = kind === "open" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
399
+ const centre = electron.getBoundingClientRect();
400
+ const cx = centre.left + centre.width / 2;
401
+ const cy = centre.top + centre.height / 2;
402
+ const longest = Math.max(...items.map(({ delay }) => delay)) + timing.duration;
403
+ for (const { element, delay, shown = 1, from = atPoint(cx, cy), opaque = false } of items) {
404
+ if (shown <= 0) continue;
405
+ const start = from(element.getBoundingClientRect(), element);
406
+ const end = getComputedStyle(element).scale;
407
+ const inside = {
408
+ translate: `${start.x}px ${start.y}px`,
409
+ scale: String(start.scale),
410
+ opacity: opaque ? shown : 0
411
+ };
412
+ const out = {
413
+ translate: "0px 0px",
414
+ scale: end === "none" ? "1" : end,
415
+ opacity: shown
416
+ };
417
+ const frames = kind === "open" ? [
418
+ inside,
419
+ {
420
+ ...out,
421
+ offset: .35
422
+ },
423
+ out
424
+ ] : [
425
+ out,
426
+ {
427
+ ...out,
428
+ offset: .65
429
+ },
430
+ inside
431
+ ];
432
+ const options = {
433
+ id: SPLIT,
434
+ duration: timing.duration,
435
+ delay,
436
+ fill: kind === "open" ? "backwards" : "forwards"
437
+ };
438
+ const ends = (kind === "open" ? [inside, out] : [out, inside]).map(({ translate, scale }) => ({
439
+ translate,
440
+ scale
441
+ }));
442
+ try {
443
+ element.animate(ends, {
444
+ ...options,
445
+ easing
446
+ });
447
+ } catch {
448
+ element.animate(ends, {
449
+ ...options,
450
+ easing: POP
451
+ });
452
+ }
453
+ if (!opaque) element.animate(frames.map(({ opacity, offset }) => offset === void 0 ? { opacity } : {
454
+ opacity,
455
+ offset
456
+ }), {
457
+ ...options,
458
+ easing: "linear"
459
+ });
460
+ else if (kind === "close") element.animate([
461
+ { opacity: shown },
462
+ {
463
+ opacity: shown,
464
+ offset: .85
465
+ },
466
+ { opacity: 0 }
467
+ ], {
468
+ ...options,
469
+ easing: "linear"
470
+ });
471
+ }
472
+ const stop = playNecks([electron, ...items.filter(({ shown = 1 }) => shown > 0).map(({ element }) => element)], longest);
473
+ const stopAll = () => {
474
+ stop();
475
+ for (const { element } of items) if (budding.get(element) === stopAll) budding.delete(element);
476
+ };
477
+ for (const { element } of items) budding.set(element, stopAll);
478
+ return stopAll;
479
+ }
480
+ /**
481
+ * The necks between pills, for `duration` ms: the goo of the moment under
482
+ * them, every pill's inside cut out of it, in the first one's colour. The
483
+ * pills draw themselves. Pills sliding past each other (or out of one
484
+ * another) seem to melt together as they meet and part.
485
+ */
486
+ function playNecks(pills, duration) {
487
+ if (pills.length < 2 || duration <= 0 || require_timing.prefersReducedMotion() || typeof document === "undefined") return () => {};
488
+ const style = getComputedStyle(pills[0]);
489
+ const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
490
+ if (goo <= 0) return () => {};
491
+ const longest = duration;
492
+ const id = `mp-goo-${++overlays}`;
493
+ const root = document.createElement("div");
494
+ root.setAttribute("data-mp", "goo");
495
+ root.setAttribute("aria-hidden", "true");
496
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${(Number.parseInt(style.zIndex, 10) || 50) - 1};`;
497
+ const svg = document.createElementNS(SVG, "svg");
498
+ svg.setAttribute("width", "0");
499
+ svg.setAttribute("height", "0");
500
+ svg.style.position = "absolute";
501
+ const filter = document.createElementNS(SVG, "filter");
502
+ filter.id = id;
503
+ for (const [name, value] of Object.entries({
504
+ x: "-50%",
505
+ y: "-50%",
506
+ width: "200%",
507
+ height: "200%",
508
+ "color-interpolation-filters": "sRGB"
509
+ })) filter.setAttribute(name, value);
510
+ filter.innerHTML = `
511
+ <feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
512
+ <feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
513
+ <feMorphology in="SourceAlpha" operator="erode" radius="1" result="inside"/>
514
+ <feComposite in="goo" in2="inside" operator="out" result="necks"/>
515
+ <feFlood result="color"/>
516
+ <feComposite in="color" in2="necks" operator="in"/>`;
517
+ filter.querySelector("feFlood").style.setProperty("flood-color", style.backgroundColor);
518
+ svg.append(filter);
519
+ const layer = document.createElement("div");
520
+ layer.style.cssText = `position:absolute;inset:0;filter:url(#${id});`;
521
+ const radii = pills.map((pill) => Number.parseFloat(getComputedStyle(pill).borderTopLeftRadius) || 0);
522
+ const shapes = pills.map(() => {
523
+ const shape = document.createElement("div");
524
+ shape.style.cssText = "position:absolute;left:0;top:0;background:#000;";
525
+ layer.append(shape);
526
+ return shape;
527
+ });
528
+ root.append(svg, layer);
529
+ document.body.append(root);
530
+ const blur = filter.querySelector("feGaussianBlur");
531
+ const margin = goo * 3 + 8;
532
+ let frame = 0;
533
+ let stopped = false;
534
+ const stop = () => {
535
+ if (stopped) return;
536
+ stopped = true;
537
+ cancelAnimationFrame(frame);
538
+ root.remove();
539
+ };
540
+ const startedAt = performance.now();
541
+ const draw = (now) => {
542
+ if (stopped) return;
543
+ const elapsed = now - startedAt;
544
+ const rects = pills.map((pill) => pill.getBoundingClientRect());
545
+ const left = Math.min(...rects.map((rect) => rect.left)) - margin;
546
+ const top = Math.min(...rects.map((rect) => rect.top)) - margin;
547
+ root.style.transform = `translate(${left}px, ${top}px)`;
548
+ root.style.width = `${Math.max(...rects.map((rect) => rect.right)) + margin - left}px`;
549
+ root.style.height = `${Math.max(...rects.map((rect) => rect.bottom)) + margin - top}px`;
550
+ rects.forEach((rect, index) => {
551
+ const scale = pills[index].offsetWidth > 0 ? rect.width / pills[index].offsetWidth : 1;
552
+ const shape = shapes[index].style;
553
+ shape.width = `${rect.width}px`;
554
+ shape.height = `${rect.height}px`;
555
+ shape.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
556
+ shape.borderRadius = `${Math.min(radii[index] * scale, rect.width / 2, rect.height / 2)}px`;
557
+ });
558
+ blur.setAttribute("stdDeviation", (goo * gooAmount(Math.min(1, elapsed / longest))).toFixed(2));
559
+ if (elapsed >= longest) return stop();
560
+ frame = requestAnimationFrame(draw);
561
+ };
562
+ frame = requestAnimationFrame(draw);
563
+ return stop;
564
+ }
565
+
566
+ exports.SPLIT = SPLIT;
567
+ exports.atEdgeOf = atEdgeOf;
568
+ exports.atPoint = atPoint;
569
+ exports.dropShadow = dropShadow;
570
+ exports.gooAmount = gooAmount;
571
+ exports.playNecks = playNecks;
572
+ exports.playOrbit = playOrbit;
573
+ exports.playSplit = playSplit;
574
+ exports.splitEasing = splitEasing;
575
+ exports.springEasing = springEasing;
576
+ exports.tuckedOffset = tuckedOffset;