magic-pill 9.4.0-next.2 → 9.4.0-next.4
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 +38 -2
- package/README.md +25 -17
- package/dist/MagicPill/MagicPill.d.mts +16 -2
- package/dist/MagicPill/MagicPill.d.ts +16 -2
- package/dist/MagicPill/MagicPill.js +12 -3
- package/dist/MagicPill/MagicPill.mjs +12 -3
- package/dist/Pill/Pill.js +1 -0
- package/dist/Pill/Pill.mjs +1 -0
- package/dist/Pill/goo.js +110 -35
- package/dist/Pill/goo.mjs +110 -36
- package/dist/Pill/modal.js +3 -1
- package/dist/Pill/modal.mjs +3 -1
- package/dist/Pill/morph.js +64 -10
- package/dist/Pill/morph.mjs +64 -11
- package/dist/Pill/zone.js +1 -2
- package/dist/Pill/zone.mjs +1 -2
- package/dist/PillForm/PillForm.js +6 -1
- package/dist/PillForm/PillForm.mjs +7 -2
- package/dist/PillForm/dates.js +14 -3
- package/dist/PillForm/dates.mjs +14 -3
- package/dist/PillForm/room.js +46 -0
- package/dist/PillForm/room.mjs +46 -0
- package/dist/PillNavbar/PillNavbar.js +3 -1
- package/dist/PillNavbar/PillNavbar.mjs +4 -2
- package/dist/PillNavbar/room.js +99 -24
- package/dist/PillNavbar/room.mjs +98 -25
- package/dist/PillNotification/PillNotification.js +2 -4
- package/dist/PillNotification/PillNotification.mjs +2 -4
- package/dist/PillNotification/RowsBody.js +77 -0
- package/dist/PillNotification/RowsBody.mjs +77 -0
- package/dist/forms.css +14 -0
- package/dist/satellites/Actions.js +181 -6
- package/dist/satellites/Actions.mjs +182 -7
- package/dist/satellites/Orbitals.js +218 -50
- package/dist/satellites/Orbitals.mjs +220 -52
- package/dist/satellites/Satellites.js +495 -107
- package/dist/satellites/Satellites.mjs +498 -111
- package/dist/satellites/handoff.js +36 -0
- package/dist/satellites/handoff.mjs +34 -0
- package/dist/satellites/layout.js +69 -3
- package/dist/satellites/layout.mjs +69 -4
- package/dist/satellites/measure.js +22 -0
- package/dist/satellites/measure.mjs +22 -1
- package/dist/satellites/orbits.js +49 -2
- package/dist/satellites/orbits.mjs +47 -3
- package/dist/satellites/types.d.mts +15 -1
- package/dist/satellites/types.d.ts +15 -1
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/styles.css +103 -15
- package/package.json +1 -1
package/dist/Pill/goo.js
CHANGED
|
@@ -29,6 +29,14 @@ function splitEasing(token) {
|
|
|
29
29
|
if (value === "smooth") return SMOOTH;
|
|
30
30
|
return value;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A droplet's curve (its position and its size together): drawn out slowly, then growing (`DROPLET_GROW`),
|
|
34
|
+
* or the same backwards. `--mp-ease-split`, when an app sets it, picks the curve out instead.
|
|
35
|
+
*/
|
|
36
|
+
function dropletEasing(token, kind) {
|
|
37
|
+
if (kind === "in") return DROPLET_SHRINK;
|
|
38
|
+
return token.trim() ? splitEasing(token) : DROPLET_GROW;
|
|
39
|
+
}
|
|
32
40
|
/** How much goo the motion needs at progress `k` (0 to 1): none at the ends, all of it while the neck forms. */
|
|
33
41
|
function gooAmount(k) {
|
|
34
42
|
const step = (from, to, x) => {
|
|
@@ -55,7 +63,7 @@ function tuckedOffset(anchor, moving, start = 1) {
|
|
|
55
63
|
let scale = start;
|
|
56
64
|
if (!fits(moving.width, anchor.width)) scale = Math.min(scale, anchor.width / moving.width);
|
|
57
65
|
if (!fits(moving.height, anchor.height)) scale = Math.min(scale, anchor.height / moving.height);
|
|
58
|
-
scale = Math.max(.
|
|
66
|
+
scale = Math.max(.1, scale);
|
|
59
67
|
if (Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2)) {
|
|
60
68
|
const sign = Math.sign(dx) || 1;
|
|
61
69
|
return {
|
|
@@ -103,26 +111,43 @@ function dropShadow(boxShadow) {
|
|
|
103
111
|
const running = /* @__PURE__ */ new WeakMap();
|
|
104
112
|
let overlays = 0;
|
|
105
113
|
const SVG = "http://www.w3.org/2000/svg";
|
|
114
|
+
/**
|
|
115
|
+
* The z-index a pill is drawn at: its own, or the one of the nearest element around it that has one
|
|
116
|
+
* (an orbital's menu). 50 (the library's default) when none says.
|
|
117
|
+
*/
|
|
118
|
+
function stackLevel(element) {
|
|
119
|
+
for (let node = element; node; node = node.parentElement) {
|
|
120
|
+
const level = Number.parseInt(getComputedStyle(node).zIndex, 10);
|
|
121
|
+
if (Number.isFinite(level)) return level;
|
|
122
|
+
}
|
|
123
|
+
return 50;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The area a goo filter works on: its layer, a little past it. The layer leaves room for the blur and
|
|
127
|
+
* the shadow already (`margin`); the filter worked on twice its width and height, four times its area,
|
|
128
|
+
* at every frame, and filters cost by the pixel (WebKit's most of all)
|
|
129
|
+
*/
|
|
130
|
+
const FILTER_REGION = {
|
|
131
|
+
x: "-10%",
|
|
132
|
+
y: "-10%",
|
|
133
|
+
width: "120%",
|
|
134
|
+
height: "120%",
|
|
135
|
+
"color-interpolation-filters": "sRGB"
|
|
136
|
+
};
|
|
106
137
|
/** The overlay: a filter (blur, threshold, the anchor's inside cut out, a fill, a shadow) and two shapes. */
|
|
107
138
|
function createOverlay(zIndex, color, shadow) {
|
|
108
139
|
const id = `mp-goo-${++overlays}`;
|
|
109
140
|
const root = document.createElement("div");
|
|
110
141
|
root.setAttribute("data-mp", "goo");
|
|
111
142
|
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};`;
|
|
143
|
+
root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;overflow:hidden;pointer-events:none;z-index:${zIndex};`;
|
|
113
144
|
const svg = document.createElementNS(SVG, "svg");
|
|
114
145
|
svg.setAttribute("width", "0");
|
|
115
146
|
svg.setAttribute("height", "0");
|
|
116
147
|
svg.style.position = "absolute";
|
|
117
148
|
const filter = document.createElementNS(SVG, "filter");
|
|
118
149
|
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);
|
|
150
|
+
for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
|
|
126
151
|
filter.innerHTML = `
|
|
127
152
|
<feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
|
|
128
153
|
<feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
|
|
@@ -165,16 +190,24 @@ function createOverlay(zIndex, color, shadow) {
|
|
|
165
190
|
* Puts the overlay around the two pills (with `margin` for the blur and the
|
|
166
191
|
* shadow), and each shape where its pill is, with its rounded corners at its
|
|
167
192
|
* current scale (`radius`: read once, at its full size).
|
|
193
|
+
*
|
|
194
|
+
* Around the moving pill only, as far as a neck can reach: a sidebar a flag
|
|
195
|
+
* comes out of is as tall as the screen, and the filter ran over all of it at
|
|
196
|
+
* every frame (slow on a phone). Its shape still runs past the overlay, which
|
|
197
|
+
* clips it, so its ends (rounded by the blur) never show.
|
|
168
198
|
*/
|
|
169
199
|
function placeAll(overlay, pills, radii, margin) {
|
|
170
200
|
const a = pills.anchor.getBoundingClientRect();
|
|
171
201
|
const m = pills.moving.getBoundingClientRect();
|
|
172
|
-
const
|
|
173
|
-
const
|
|
202
|
+
const reach = margin;
|
|
203
|
+
const left = Math.max(Math.min(a.left, m.left), m.left - reach) - margin;
|
|
204
|
+
const top = Math.max(Math.min(a.top, m.top), m.top - reach) - margin;
|
|
205
|
+
const right = Math.min(Math.max(a.right, m.right), m.right + reach) + margin;
|
|
206
|
+
const bottom = Math.min(Math.max(a.bottom, m.bottom), m.bottom + reach) + margin;
|
|
174
207
|
const root = overlay.root.style;
|
|
175
208
|
root.transform = `translate(${left}px, ${top}px)`;
|
|
176
|
-
root.width = `${
|
|
177
|
-
root.height = `${
|
|
209
|
+
root.width = `${right - left}px`;
|
|
210
|
+
root.height = `${bottom - top}px`;
|
|
178
211
|
const put = (shape, rect, element, radius) => {
|
|
179
212
|
const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
180
213
|
shape.style.width = `${rect.width}px`;
|
|
@@ -200,8 +233,9 @@ const readNumber = (style, name, fallback) => {
|
|
|
200
233
|
};
|
|
201
234
|
/**
|
|
202
235
|
* 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
|
-
*
|
|
236
|
+
* it's tucked in to where it sits) or a join (the other way, after `delay`),
|
|
237
|
+
* as a droplet: drawn out small, growing to its size, its content showing once
|
|
238
|
+
* it's out. Reads `--mp-goo`, `--mp-electron-start` and `--mp-ease-split` on the
|
|
205
239
|
* moving pill. Does nothing with reduced motion. Returns a function that
|
|
206
240
|
* stops it at once.
|
|
207
241
|
*/
|
|
@@ -211,9 +245,9 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
211
245
|
if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof moving.animate !== "function") return () => {};
|
|
212
246
|
const style = getComputedStyle(moving);
|
|
213
247
|
const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
|
|
214
|
-
const start = readNumber(style, "--mp-electron-start",
|
|
248
|
+
const start = readNumber(style, "--mp-electron-start", DROPLET);
|
|
215
249
|
const fade = require_timing.parseDuration(style.getPropertyValue("--_mp-fade"), 150);
|
|
216
|
-
const easing =
|
|
250
|
+
const easing = dropletEasing(style.getPropertyValue("--mp-ease-split"), kind === "split" ? "out" : "in");
|
|
217
251
|
let overlay = null;
|
|
218
252
|
const radii = {
|
|
219
253
|
anchor: 0,
|
|
@@ -313,11 +347,14 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
313
347
|
id: SPLIT,
|
|
314
348
|
duration: total
|
|
315
349
|
});
|
|
316
|
-
else
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
350
|
+
else {
|
|
351
|
+
const now = Number.parseFloat(getComputedStyle(child).opacity);
|
|
352
|
+
child.animate([{ opacity: Number.isFinite(now) ? now : 1 }, { opacity: 0 }], {
|
|
353
|
+
id: SPLIT,
|
|
354
|
+
duration: Math.max(1, fade),
|
|
355
|
+
fill: "forwards"
|
|
356
|
+
});
|
|
357
|
+
}
|
|
321
358
|
};
|
|
322
359
|
const begin = () => {
|
|
323
360
|
begun = true;
|
|
@@ -370,8 +407,16 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
370
407
|
running.set(moving, stop);
|
|
371
408
|
return stop;
|
|
372
409
|
}
|
|
373
|
-
/**
|
|
374
|
-
const
|
|
410
|
+
/** The size an electron and the page's actions start at as they come out (a droplet), unless `--mp-electron-start` says */
|
|
411
|
+
const DROPLET = .15;
|
|
412
|
+
/** A droplet's size on its way out: drawn out small, then growing to its size; going back, the same backwards */
|
|
413
|
+
const DROPLET_GROW = "cubic-bezier(0.6, 0, 0.35, 1)";
|
|
414
|
+
const DROPLET_SHRINK = "cubic-bezier(0.65, 0, 0.4, 1)";
|
|
415
|
+
/**
|
|
416
|
+
* Inside the anchor at its nearest edge, as a flag goes into its sidebar, at `--mp-electron-start` of
|
|
417
|
+
* its size (`start` by default). `at`: where the anchor is going, if it's moving.
|
|
418
|
+
*/
|
|
419
|
+
const atEdgeOf = (anchor, at, start = 1) => (rect, element) => tuckedOffset(at?.() ?? anchor.getBoundingClientRect(), rect, readNumber(getComputedStyle(element), "--mp-electron-start", start));
|
|
375
420
|
/** Inside the anchor at a point of the screen (where a pill closing to a circle ends), small. */
|
|
376
421
|
const atPoint = (x, y, scale = .3) => (rect) => ({
|
|
377
422
|
x: x - (rect.left + rect.width / 2),
|
|
@@ -391,7 +436,7 @@ const budding = /* @__PURE__ */ new WeakMap();
|
|
|
391
436
|
function playOrbit(electron, items, kind, timing) {
|
|
392
437
|
for (const { element } of items) {
|
|
393
438
|
budding.get(element)?.();
|
|
394
|
-
for (const animation of element.getAnimations?.() ?? []) if (animation.id === "mp-split") animation.cancel();
|
|
439
|
+
for (const animation of element.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
|
|
395
440
|
}
|
|
396
441
|
if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof electron.animate !== "function" || items.length === 0) return () => {};
|
|
397
442
|
const style = getComputedStyle(electron);
|
|
@@ -400,7 +445,22 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
400
445
|
const cx = centre.left + centre.width / 2;
|
|
401
446
|
const cy = centre.top + centre.height / 2;
|
|
402
447
|
const longest = Math.max(...items.map(({ delay }) => delay)) + timing.duration;
|
|
403
|
-
|
|
448
|
+
const anchorLevel = stackLevel(electron);
|
|
449
|
+
const lowered = [];
|
|
450
|
+
for (const { element } of items) {
|
|
451
|
+
if (stackLevel(element) < anchorLevel) continue;
|
|
452
|
+
lowered.push([element, element.style.zIndex]);
|
|
453
|
+
element.style.zIndex = String(anchorLevel - 1);
|
|
454
|
+
}
|
|
455
|
+
let restored = false;
|
|
456
|
+
const restore = () => {
|
|
457
|
+
if (restored) return;
|
|
458
|
+
restored = true;
|
|
459
|
+
clearTimeout(timer);
|
|
460
|
+
for (const [element, zIndex] of lowered) element.style.zIndex = zIndex;
|
|
461
|
+
};
|
|
462
|
+
const timer = lowered.length > 0 ? setTimeout(restore, longest) : void 0;
|
|
463
|
+
for (const { element, delay, shown = 1, from = atPoint(cx, cy), droplet = false, opaque = droplet } of items) {
|
|
404
464
|
if (shown <= 0) continue;
|
|
405
465
|
const start = from(element.getBoundingClientRect(), element);
|
|
406
466
|
const end = getComputedStyle(element).scale;
|
|
@@ -439,10 +499,11 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
439
499
|
translate,
|
|
440
500
|
scale
|
|
441
501
|
}));
|
|
502
|
+
const curve = droplet ? dropletEasing(style.getPropertyValue("--mp-ease-split"), kind === "open" ? "out" : "in") : easing;
|
|
442
503
|
try {
|
|
443
504
|
element.animate(ends, {
|
|
444
505
|
...options,
|
|
445
|
-
easing
|
|
506
|
+
easing: curve
|
|
446
507
|
});
|
|
447
508
|
} catch {
|
|
448
509
|
element.animate(ends, {
|
|
@@ -468,10 +529,28 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
468
529
|
...options,
|
|
469
530
|
easing: "linear"
|
|
470
531
|
});
|
|
532
|
+
if (droplet) {
|
|
533
|
+
const content = kind === "open" ? [
|
|
534
|
+
{ opacity: 0 },
|
|
535
|
+
{
|
|
536
|
+
opacity: 0,
|
|
537
|
+
offset: .7
|
|
538
|
+
},
|
|
539
|
+
{ opacity: 1 }
|
|
540
|
+
] : [{
|
|
541
|
+
opacity: 0,
|
|
542
|
+
offset: .3
|
|
543
|
+
}, { opacity: 0 }];
|
|
544
|
+
for (const child of element.children) child.animate(content, {
|
|
545
|
+
...options,
|
|
546
|
+
easing: "linear"
|
|
547
|
+
});
|
|
548
|
+
}
|
|
471
549
|
}
|
|
472
550
|
const stop = playNecks([electron, ...items.filter(({ shown = 1 }) => shown > 0).map(({ element }) => element)], longest);
|
|
473
551
|
const stopAll = () => {
|
|
474
552
|
stop();
|
|
553
|
+
restore();
|
|
475
554
|
for (const { element } of items) if (budding.get(element) === stopAll) budding.delete(element);
|
|
476
555
|
};
|
|
477
556
|
for (const { element } of items) budding.set(element, stopAll);
|
|
@@ -493,20 +572,15 @@ function playNecks(pills, duration) {
|
|
|
493
572
|
const root = document.createElement("div");
|
|
494
573
|
root.setAttribute("data-mp", "goo");
|
|
495
574
|
root.setAttribute("aria-hidden", "true");
|
|
496
|
-
|
|
575
|
+
const level = Math.min(...pills.map(stackLevel)) - 1;
|
|
576
|
+
root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${level};`;
|
|
497
577
|
const svg = document.createElementNS(SVG, "svg");
|
|
498
578
|
svg.setAttribute("width", "0");
|
|
499
579
|
svg.setAttribute("height", "0");
|
|
500
580
|
svg.style.position = "absolute";
|
|
501
581
|
const filter = document.createElementNS(SVG, "filter");
|
|
502
582
|
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);
|
|
583
|
+
for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
|
|
510
584
|
filter.innerHTML = `
|
|
511
585
|
<feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
|
|
512
586
|
<feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
|
|
@@ -563,6 +637,7 @@ function playNecks(pills, duration) {
|
|
|
563
637
|
return stop;
|
|
564
638
|
}
|
|
565
639
|
|
|
640
|
+
exports.DROPLET = DROPLET;
|
|
566
641
|
exports.SPLIT = SPLIT;
|
|
567
642
|
exports.atEdgeOf = atEdgeOf;
|
|
568
643
|
exports.atPoint = atPoint;
|
package/dist/Pill/goo.mjs
CHANGED
|
@@ -29,6 +29,14 @@ function splitEasing(token) {
|
|
|
29
29
|
if (value === "smooth") return SMOOTH;
|
|
30
30
|
return value;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A droplet's curve (its position and its size together): drawn out slowly, then growing (`DROPLET_GROW`),
|
|
34
|
+
* or the same backwards. `--mp-ease-split`, when an app sets it, picks the curve out instead.
|
|
35
|
+
*/
|
|
36
|
+
function dropletEasing(token, kind) {
|
|
37
|
+
if (kind === "in") return DROPLET_SHRINK;
|
|
38
|
+
return token.trim() ? splitEasing(token) : DROPLET_GROW;
|
|
39
|
+
}
|
|
32
40
|
/** How much goo the motion needs at progress `k` (0 to 1): none at the ends, all of it while the neck forms. */
|
|
33
41
|
function gooAmount(k) {
|
|
34
42
|
const step = (from, to, x) => {
|
|
@@ -55,7 +63,7 @@ function tuckedOffset(anchor, moving, start = 1) {
|
|
|
55
63
|
let scale = start;
|
|
56
64
|
if (!fits(moving.width, anchor.width)) scale = Math.min(scale, anchor.width / moving.width);
|
|
57
65
|
if (!fits(moving.height, anchor.height)) scale = Math.min(scale, anchor.height / moving.height);
|
|
58
|
-
scale = Math.max(.
|
|
66
|
+
scale = Math.max(.1, scale);
|
|
59
67
|
if (Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2)) {
|
|
60
68
|
const sign = Math.sign(dx) || 1;
|
|
61
69
|
return {
|
|
@@ -103,26 +111,43 @@ function dropShadow(boxShadow) {
|
|
|
103
111
|
const running = /* @__PURE__ */ new WeakMap();
|
|
104
112
|
let overlays = 0;
|
|
105
113
|
const SVG = "http://www.w3.org/2000/svg";
|
|
114
|
+
/**
|
|
115
|
+
* The z-index a pill is drawn at: its own, or the one of the nearest element around it that has one
|
|
116
|
+
* (an orbital's menu). 50 (the library's default) when none says.
|
|
117
|
+
*/
|
|
118
|
+
function stackLevel(element) {
|
|
119
|
+
for (let node = element; node; node = node.parentElement) {
|
|
120
|
+
const level = Number.parseInt(getComputedStyle(node).zIndex, 10);
|
|
121
|
+
if (Number.isFinite(level)) return level;
|
|
122
|
+
}
|
|
123
|
+
return 50;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The area a goo filter works on: its layer, a little past it. The layer leaves room for the blur and
|
|
127
|
+
* the shadow already (`margin`); the filter worked on twice its width and height, four times its area,
|
|
128
|
+
* at every frame, and filters cost by the pixel (WebKit's most of all)
|
|
129
|
+
*/
|
|
130
|
+
const FILTER_REGION = {
|
|
131
|
+
x: "-10%",
|
|
132
|
+
y: "-10%",
|
|
133
|
+
width: "120%",
|
|
134
|
+
height: "120%",
|
|
135
|
+
"color-interpolation-filters": "sRGB"
|
|
136
|
+
};
|
|
106
137
|
/** The overlay: a filter (blur, threshold, the anchor's inside cut out, a fill, a shadow) and two shapes. */
|
|
107
138
|
function createOverlay(zIndex, color, shadow) {
|
|
108
139
|
const id = `mp-goo-${++overlays}`;
|
|
109
140
|
const root = document.createElement("div");
|
|
110
141
|
root.setAttribute("data-mp", "goo");
|
|
111
142
|
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};`;
|
|
143
|
+
root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;overflow:hidden;pointer-events:none;z-index:${zIndex};`;
|
|
113
144
|
const svg = document.createElementNS(SVG, "svg");
|
|
114
145
|
svg.setAttribute("width", "0");
|
|
115
146
|
svg.setAttribute("height", "0");
|
|
116
147
|
svg.style.position = "absolute";
|
|
117
148
|
const filter = document.createElementNS(SVG, "filter");
|
|
118
149
|
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);
|
|
150
|
+
for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
|
|
126
151
|
filter.innerHTML = `
|
|
127
152
|
<feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
|
|
128
153
|
<feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
|
|
@@ -165,16 +190,24 @@ function createOverlay(zIndex, color, shadow) {
|
|
|
165
190
|
* Puts the overlay around the two pills (with `margin` for the blur and the
|
|
166
191
|
* shadow), and each shape where its pill is, with its rounded corners at its
|
|
167
192
|
* current scale (`radius`: read once, at its full size).
|
|
193
|
+
*
|
|
194
|
+
* Around the moving pill only, as far as a neck can reach: a sidebar a flag
|
|
195
|
+
* comes out of is as tall as the screen, and the filter ran over all of it at
|
|
196
|
+
* every frame (slow on a phone). Its shape still runs past the overlay, which
|
|
197
|
+
* clips it, so its ends (rounded by the blur) never show.
|
|
168
198
|
*/
|
|
169
199
|
function placeAll(overlay, pills, radii, margin) {
|
|
170
200
|
const a = pills.anchor.getBoundingClientRect();
|
|
171
201
|
const m = pills.moving.getBoundingClientRect();
|
|
172
|
-
const
|
|
173
|
-
const
|
|
202
|
+
const reach = margin;
|
|
203
|
+
const left = Math.max(Math.min(a.left, m.left), m.left - reach) - margin;
|
|
204
|
+
const top = Math.max(Math.min(a.top, m.top), m.top - reach) - margin;
|
|
205
|
+
const right = Math.min(Math.max(a.right, m.right), m.right + reach) + margin;
|
|
206
|
+
const bottom = Math.min(Math.max(a.bottom, m.bottom), m.bottom + reach) + margin;
|
|
174
207
|
const root = overlay.root.style;
|
|
175
208
|
root.transform = `translate(${left}px, ${top}px)`;
|
|
176
|
-
root.width = `${
|
|
177
|
-
root.height = `${
|
|
209
|
+
root.width = `${right - left}px`;
|
|
210
|
+
root.height = `${bottom - top}px`;
|
|
178
211
|
const put = (shape, rect, element, radius) => {
|
|
179
212
|
const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
180
213
|
shape.style.width = `${rect.width}px`;
|
|
@@ -200,8 +233,9 @@ const readNumber = (style, name, fallback) => {
|
|
|
200
233
|
};
|
|
201
234
|
/**
|
|
202
235
|
* 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
|
-
*
|
|
236
|
+
* it's tucked in to where it sits) or a join (the other way, after `delay`),
|
|
237
|
+
* as a droplet: drawn out small, growing to its size, its content showing once
|
|
238
|
+
* it's out. Reads `--mp-goo`, `--mp-electron-start` and `--mp-ease-split` on the
|
|
205
239
|
* moving pill. Does nothing with reduced motion. Returns a function that
|
|
206
240
|
* stops it at once.
|
|
207
241
|
*/
|
|
@@ -211,9 +245,9 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
211
245
|
if (timing.duration <= 0 || prefersReducedMotion() || typeof moving.animate !== "function") return () => {};
|
|
212
246
|
const style = getComputedStyle(moving);
|
|
213
247
|
const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
|
|
214
|
-
const start = readNumber(style, "--mp-electron-start",
|
|
248
|
+
const start = readNumber(style, "--mp-electron-start", DROPLET);
|
|
215
249
|
const fade = parseDuration(style.getPropertyValue("--_mp-fade"), 150);
|
|
216
|
-
const easing =
|
|
250
|
+
const easing = dropletEasing(style.getPropertyValue("--mp-ease-split"), kind === "split" ? "out" : "in");
|
|
217
251
|
let overlay = null;
|
|
218
252
|
const radii = {
|
|
219
253
|
anchor: 0,
|
|
@@ -313,11 +347,14 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
313
347
|
id: SPLIT,
|
|
314
348
|
duration: total
|
|
315
349
|
});
|
|
316
|
-
else
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
350
|
+
else {
|
|
351
|
+
const now = Number.parseFloat(getComputedStyle(child).opacity);
|
|
352
|
+
child.animate([{ opacity: Number.isFinite(now) ? now : 1 }, { opacity: 0 }], {
|
|
353
|
+
id: SPLIT,
|
|
354
|
+
duration: Math.max(1, fade),
|
|
355
|
+
fill: "forwards"
|
|
356
|
+
});
|
|
357
|
+
}
|
|
321
358
|
};
|
|
322
359
|
const begin = () => {
|
|
323
360
|
begun = true;
|
|
@@ -370,8 +407,16 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
370
407
|
running.set(moving, stop);
|
|
371
408
|
return stop;
|
|
372
409
|
}
|
|
373
|
-
/**
|
|
374
|
-
const
|
|
410
|
+
/** The size an electron and the page's actions start at as they come out (a droplet), unless `--mp-electron-start` says */
|
|
411
|
+
const DROPLET = .15;
|
|
412
|
+
/** A droplet's size on its way out: drawn out small, then growing to its size; going back, the same backwards */
|
|
413
|
+
const DROPLET_GROW = "cubic-bezier(0.6, 0, 0.35, 1)";
|
|
414
|
+
const DROPLET_SHRINK = "cubic-bezier(0.65, 0, 0.4, 1)";
|
|
415
|
+
/**
|
|
416
|
+
* Inside the anchor at its nearest edge, as a flag goes into its sidebar, at `--mp-electron-start` of
|
|
417
|
+
* its size (`start` by default). `at`: where the anchor is going, if it's moving.
|
|
418
|
+
*/
|
|
419
|
+
const atEdgeOf = (anchor, at, start = 1) => (rect, element) => tuckedOffset(at?.() ?? anchor.getBoundingClientRect(), rect, readNumber(getComputedStyle(element), "--mp-electron-start", start));
|
|
375
420
|
/** Inside the anchor at a point of the screen (where a pill closing to a circle ends), small. */
|
|
376
421
|
const atPoint = (x, y, scale = .3) => (rect) => ({
|
|
377
422
|
x: x - (rect.left + rect.width / 2),
|
|
@@ -391,7 +436,7 @@ const budding = /* @__PURE__ */ new WeakMap();
|
|
|
391
436
|
function playOrbit(electron, items, kind, timing) {
|
|
392
437
|
for (const { element } of items) {
|
|
393
438
|
budding.get(element)?.();
|
|
394
|
-
for (const animation of element.getAnimations?.() ?? []) if (animation.id === "mp-split") animation.cancel();
|
|
439
|
+
for (const animation of element.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
|
|
395
440
|
}
|
|
396
441
|
if (timing.duration <= 0 || prefersReducedMotion() || typeof electron.animate !== "function" || items.length === 0) return () => {};
|
|
397
442
|
const style = getComputedStyle(electron);
|
|
@@ -400,7 +445,22 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
400
445
|
const cx = centre.left + centre.width / 2;
|
|
401
446
|
const cy = centre.top + centre.height / 2;
|
|
402
447
|
const longest = Math.max(...items.map(({ delay }) => delay)) + timing.duration;
|
|
403
|
-
|
|
448
|
+
const anchorLevel = stackLevel(electron);
|
|
449
|
+
const lowered = [];
|
|
450
|
+
for (const { element } of items) {
|
|
451
|
+
if (stackLevel(element) < anchorLevel) continue;
|
|
452
|
+
lowered.push([element, element.style.zIndex]);
|
|
453
|
+
element.style.zIndex = String(anchorLevel - 1);
|
|
454
|
+
}
|
|
455
|
+
let restored = false;
|
|
456
|
+
const restore = () => {
|
|
457
|
+
if (restored) return;
|
|
458
|
+
restored = true;
|
|
459
|
+
clearTimeout(timer);
|
|
460
|
+
for (const [element, zIndex] of lowered) element.style.zIndex = zIndex;
|
|
461
|
+
};
|
|
462
|
+
const timer = lowered.length > 0 ? setTimeout(restore, longest) : void 0;
|
|
463
|
+
for (const { element, delay, shown = 1, from = atPoint(cx, cy), droplet = false, opaque = droplet } of items) {
|
|
404
464
|
if (shown <= 0) continue;
|
|
405
465
|
const start = from(element.getBoundingClientRect(), element);
|
|
406
466
|
const end = getComputedStyle(element).scale;
|
|
@@ -439,10 +499,11 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
439
499
|
translate,
|
|
440
500
|
scale
|
|
441
501
|
}));
|
|
502
|
+
const curve = droplet ? dropletEasing(style.getPropertyValue("--mp-ease-split"), kind === "open" ? "out" : "in") : easing;
|
|
442
503
|
try {
|
|
443
504
|
element.animate(ends, {
|
|
444
505
|
...options,
|
|
445
|
-
easing
|
|
506
|
+
easing: curve
|
|
446
507
|
});
|
|
447
508
|
} catch {
|
|
448
509
|
element.animate(ends, {
|
|
@@ -468,10 +529,28 @@ function playOrbit(electron, items, kind, timing) {
|
|
|
468
529
|
...options,
|
|
469
530
|
easing: "linear"
|
|
470
531
|
});
|
|
532
|
+
if (droplet) {
|
|
533
|
+
const content = kind === "open" ? [
|
|
534
|
+
{ opacity: 0 },
|
|
535
|
+
{
|
|
536
|
+
opacity: 0,
|
|
537
|
+
offset: .7
|
|
538
|
+
},
|
|
539
|
+
{ opacity: 1 }
|
|
540
|
+
] : [{
|
|
541
|
+
opacity: 0,
|
|
542
|
+
offset: .3
|
|
543
|
+
}, { opacity: 0 }];
|
|
544
|
+
for (const child of element.children) child.animate(content, {
|
|
545
|
+
...options,
|
|
546
|
+
easing: "linear"
|
|
547
|
+
});
|
|
548
|
+
}
|
|
471
549
|
}
|
|
472
550
|
const stop = playNecks([electron, ...items.filter(({ shown = 1 }) => shown > 0).map(({ element }) => element)], longest);
|
|
473
551
|
const stopAll = () => {
|
|
474
552
|
stop();
|
|
553
|
+
restore();
|
|
475
554
|
for (const { element } of items) if (budding.get(element) === stopAll) budding.delete(element);
|
|
476
555
|
};
|
|
477
556
|
for (const { element } of items) budding.set(element, stopAll);
|
|
@@ -493,20 +572,15 @@ function playNecks(pills, duration) {
|
|
|
493
572
|
const root = document.createElement("div");
|
|
494
573
|
root.setAttribute("data-mp", "goo");
|
|
495
574
|
root.setAttribute("aria-hidden", "true");
|
|
496
|
-
|
|
575
|
+
const level = Math.min(...pills.map(stackLevel)) - 1;
|
|
576
|
+
root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${level};`;
|
|
497
577
|
const svg = document.createElementNS(SVG, "svg");
|
|
498
578
|
svg.setAttribute("width", "0");
|
|
499
579
|
svg.setAttribute("height", "0");
|
|
500
580
|
svg.style.position = "absolute";
|
|
501
581
|
const filter = document.createElementNS(SVG, "filter");
|
|
502
582
|
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);
|
|
583
|
+
for (const [name, value] of Object.entries(FILTER_REGION)) filter.setAttribute(name, value);
|
|
510
584
|
filter.innerHTML = `
|
|
511
585
|
<feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
|
|
512
586
|
<feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
|
|
@@ -563,4 +637,4 @@ function playNecks(pills, duration) {
|
|
|
563
637
|
return stop;
|
|
564
638
|
}
|
|
565
639
|
|
|
566
|
-
export { SPLIT, atEdgeOf, atPoint, dropShadow, gooAmount, playNecks, playOrbit, playSplit, splitEasing, springEasing, tuckedOffset };
|
|
640
|
+
export { DROPLET, SPLIT, atEdgeOf, atPoint, dropShadow, gooAmount, playNecks, playOrbit, playSplit, splitEasing, springEasing, tuckedOffset };
|
package/dist/Pill/modal.js
CHANGED
|
@@ -21,6 +21,7 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
|
|
|
21
21
|
const show = () => {
|
|
22
22
|
const dialog = rootRef.current;
|
|
23
23
|
if (!isOverlay || !isVisible || !dialog?.isConnected || typeof dialog.showModal !== "function") return;
|
|
24
|
+
let opening = false;
|
|
24
25
|
if (!dialog.open) {
|
|
25
26
|
dialog.dataset.presence = "hidden";
|
|
26
27
|
dialog.showModal();
|
|
@@ -29,8 +30,9 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
|
|
|
29
30
|
height: dialog.offsetHeight
|
|
30
31
|
};
|
|
31
32
|
dialog.dataset.presence = presence;
|
|
33
|
+
opening = true;
|
|
32
34
|
}
|
|
33
|
-
if (presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
|
|
35
|
+
if (opening || presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
|
|
34
36
|
};
|
|
35
37
|
require_react.useIsomorphicLayoutEffect(() => {
|
|
36
38
|
show();
|
package/dist/Pill/modal.mjs
CHANGED
|
@@ -21,6 +21,7 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
|
|
|
21
21
|
const show = () => {
|
|
22
22
|
const dialog = rootRef.current;
|
|
23
23
|
if (!isOverlay || !isVisible || !dialog?.isConnected || typeof dialog.showModal !== "function") return;
|
|
24
|
+
let opening = false;
|
|
24
25
|
if (!dialog.open) {
|
|
25
26
|
dialog.dataset.presence = "hidden";
|
|
26
27
|
dialog.showModal();
|
|
@@ -29,8 +30,9 @@ function useModal(rootRef, isOverlay, presence, lastSize) {
|
|
|
29
30
|
height: dialog.offsetHeight
|
|
30
31
|
};
|
|
31
32
|
dialog.dataset.presence = presence;
|
|
33
|
+
opening = true;
|
|
32
34
|
}
|
|
33
|
-
if (presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
|
|
35
|
+
if (opening || presence === "rest" || !dialog.contains(document.activeElement)) dialog.focus();
|
|
34
36
|
};
|
|
35
37
|
useIsomorphicLayoutEffect(() => {
|
|
36
38
|
show();
|