magic-pill 9.4.0-next.1 → 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.
- package/CHANGELOG.md +17 -0
- package/dist/MagicPill/MagicPill.d.mts +9 -1
- package/dist/MagicPill/MagicPill.d.ts +9 -1
- package/dist/MagicPill/MagicPill.js +3 -1
- package/dist/MagicPill/MagicPill.mjs +3 -1
- package/dist/Pill/goo.js +238 -15
- package/dist/Pill/goo.mjs +235 -16
- package/dist/Pill/morph.js +8 -3
- package/dist/Pill/morph.mjs +7 -4
- package/dist/satellites/Actions.js +138 -16
- package/dist/satellites/Actions.mjs +139 -18
- package/dist/satellites/Orbitals.js +76 -45
- package/dist/satellites/Orbitals.mjs +77 -46
- package/dist/satellites/Satellites.js +284 -50
- package/dist/satellites/Satellites.mjs +285 -51
- package/dist/satellites/layout.js +83 -30
- package/dist/satellites/layout.mjs +83 -30
- package/dist/satellites/types.d.mts +4 -0
- package/dist/satellites/types.d.ts +4 -0
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/store/store.js +1 -1
- package/dist/store/store.mjs +1 -1
- package/dist/styles.css +170 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,10 +6,27 @@
|
|
|
6
6
|
- **Beta:** the Electron, in an optional entry, `magic-pill/satellites`: a small round pill that splits out of the host to keep a background activity in reach. `pill().electron()`, `updateElectron()` and `endElectron()`; on `<MagicPill>`, `satellites`, `pathname`, `electronSide`, `electronLine`, `keepElectronsOut`, `electronEnding` and `arrange`. It's tucked into the pill on the page that started it and while a notification has the pill, a tap goes back to that page, and the pill and its electrons stay centred as a group
|
|
7
7
|
- **Beta:** an electron's orbitals, its quick actions fanned out around it (`orbitals` on `pill().electron()`): opened by a long press (slide to one and release to run it), hovering with a mouse, or a tap (`orbitalsOpenOn`, with a first orbital going back), and the keyboard as a menu. On an arc away from the screen's edge, clear of the pill and the other electrons; when they don't all fit, a wheel that turns with the mouse wheel, a drag along it or the arrow keys, and stays open until a tap away. `orbitalLabels`, `orbitalsStayOpen`, `backLabel`, and the tokens `--mp-orbital-size`, `--mp-orbital-distance`, `--mp-orbital-spread`, `--mp-orbital-stagger`, `--mp-hover-delay` and `--mp-long-press`
|
|
8
8
|
- **Beta:** the page's actions, the design's wide atom: `usePillActions()` (from `magic-pill/satellites`) and `pill().setActions()` set one or more actions for the current page, next to the pill. `actionsStyle` (`"detached"`, a pill of their own that comes out of the host with the goo, or `"inside"`, after a divider), `actionsSide` (`"start"`, `"end"` or `"beside"`), `actionsOrientation` (`"auto"`, turning across when room runs out, `"horizontal"`, `"vertical"`) and `actionsLabel` on `<MagicPill>`
|
|
9
|
+
- **Beta:** `actionsWheel` on `<MagicPill>`: short of room, the page's actions show what fits and the others turn in, like the orbitals' wheel (a mouse wheel, a drag, a swipe or the arrow keys, each one snapping into place, the ends that hide some fading out), instead of turning across; in the pill, the cut starts right at the divider. And `nearestToPill` (`"actions"`, the default, or `"electrons"`): which are nearer the pill on a side they share
|
|
9
10
|
- `labels` on `<PillNavbar>`: which labels show at rest. `"auto"` (the default) shows the current page's while the pill has room for it and folds it when it doesn't, `"current"` always shows it, `"closed"` shows none. An electron stays in the pill's row when the navbar can fold to make room, and only goes above it when it still doesn't fit
|
|
10
11
|
- `PillProgress`: a progress ring around a value or an icon, in the text colour (`--mp-progress-size`, `--mp-progress-width`)
|
|
11
12
|
- The split's tokens, for a sidebar's flag: `--mp-duration-split` and `--mp-duration-join` (the enter and exit durations by default), `--mp-ease-split` (`bouncy`, the default, `pop`, `smooth` or any CSS easing), `--mp-goo` (`12`; `0` for no neck) and `--mp-electron-start` (`1`)
|
|
12
13
|
|
|
14
|
+
### Fixed
|
|
15
|
+
- Opening an electron's orbitals no longer stutters: each orbital's goo ran an SVG filter over the whole screen; it now only covers the two pills it joins (60 frames a second where it fell to about 30, with frames of up to 180 ms)
|
|
16
|
+
- Two electrons given an empty `id` are two electrons, instead of one flickering between them
|
|
17
|
+
- The page's actions grow away from the pill when an action's label opens on hover, instead of over it
|
|
18
|
+
- When the host changes placement or turns, its electrons and actions tuck in while it travels and come out at its new place; one that changes side or row (or actions that turn) goes back into the pill and out again, instead of sliding across it or jumping
|
|
19
|
+
- An electron's orbitals bulge out of its centre one after the other and fold back into it, quicker than they came and in the other order, as the design drew them. Next to another electron, two of them used to slide sideways into each other above it, merge and vanish; the electron's shadow flickered as they opened, and on the glass themes they switched colour at the end. On their way back, they're out of reach (a pointer over them can't hold them); when their electron ends from one of them, they're in at once; on their way out, one under the pointer doesn't light up
|
|
20
|
+
- With the orbitals open (they stay open after an action), a press on the electron slides onto one at once, instead of waiting for a long press again: it only worked once until a tap away
|
|
21
|
+
- For a notification, the electrons and the actions go into the pill with it, once their content has faded, instead of staying out while it closes and then chasing it; back from the notification, they come out once the pill has grown back, not out of a half-grown pill
|
|
22
|
+
- Beside the pill, the actions and the electrons make a row of their own, clear of each other and kept on the screen (on a phone, four actions covered the second electron and could run off the screen); automatic actions turn across there when the row is too long, and a row that still doesn't fit wraps into a further one
|
|
23
|
+
- The actions slide with the group (gathered to spread, another satellite coming or going), instead of jumping; and whether they turn across is decided again once a resize settles, not only after a render
|
|
24
|
+
- An orbital's label is a small pill of the electron's look (its theme and colours), instead of always light on dark
|
|
25
|
+
- A navbar too long for its pill scrolls inside it, instead of its last items being cut off: a sidebar's, and a horizontal one once its labels have folded; where the browser has scroll-driven animations, the ends that hide some fade out
|
|
26
|
+
- An electron and the page's actions come out of the pill and go back into it as the orbitals do, drawing themselves the whole way: on the glass themes they no longer switch colour at the end; changing sides, they no longer flicker between going in and coming out. For a notification, they go into the pill's centre as it closes to a circle
|
|
27
|
+
- The actions go into the pill and come out of it with the goo when `actionsStyle` changes, instead of disappearing; turned while they were in, they come out turned, instead of at their old shape first. Two satellites passing each other (`nearestToPill` changed) melt together as they meet
|
|
28
|
+
- An electron's orbitals keep clear of the page's actions, as they do of the other electrons
|
|
29
|
+
|
|
13
30
|
### Changed
|
|
14
31
|
- A navbar whose current page's label has no room folds it (`labels="auto"`, the new default), instead of the pill cutting its last items off. `labels="current"` keeps the old behaviour
|
|
15
32
|
- A sidebar's flag comes out of the sidebar's edge as a droplet, with goo: a neck forms between them, stretches and snaps, on a bouncy curve, and it goes back into the sidebar the same way. It no longer pops in at its spot with a short bridge, nor scales in and out. With reduced motion it still fades. On the glass themes, its blur waits until it's clear of the sidebar
|
|
@@ -2,7 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { LinkComponent, PillProps } from "../Pill/types.mjs";
|
|
3
3
|
import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.mjs";
|
|
4
4
|
import { SwapMode } from "./choreography.mjs";
|
|
5
|
-
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.mjs";
|
|
5
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.mjs";
|
|
6
6
|
export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
|
|
7
7
|
/** Default "main". Two hosts with the same name warn in development. */
|
|
8
8
|
name?: string;
|
|
@@ -79,6 +79,14 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
|
|
|
79
79
|
actionsSide?: ActionsSide;
|
|
80
80
|
/** The page's actions run like the pill, turning across when room runs out (default), or horizontal, or vertical (beta). */
|
|
81
81
|
actionsOrientation?: ActionsOrientation;
|
|
82
|
+
/**
|
|
83
|
+
* Short of room, the page's actions show what fits and turn the rest in a
|
|
84
|
+
* wheel (a mouse wheel, a drag, the arrow keys), instead of turning across.
|
|
85
|
+
* Default false (beta).
|
|
86
|
+
*/
|
|
87
|
+
actionsWheel?: boolean;
|
|
88
|
+
/** On a side they share, the page's actions are nearer the pill (default), or the electrons (beta). */
|
|
89
|
+
nearestToPill?: NearestToPill;
|
|
82
90
|
/** The page's actions' accessible name. Default "Page actions" (beta). */
|
|
83
91
|
actionsLabel?: string;
|
|
84
92
|
}
|
|
@@ -2,7 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { LinkComponent, PillProps } from "../Pill/types.js";
|
|
3
3
|
import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.js";
|
|
4
4
|
import { SwapMode } from "./choreography.js";
|
|
5
|
-
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.js";
|
|
5
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.js";
|
|
6
6
|
export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
|
|
7
7
|
/** Default "main". Two hosts with the same name warn in development. */
|
|
8
8
|
name?: string;
|
|
@@ -79,6 +79,14 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
|
|
|
79
79
|
actionsSide?: ActionsSide;
|
|
80
80
|
/** The page's actions run like the pill, turning across when room runs out (default), or horizontal, or vertical (beta). */
|
|
81
81
|
actionsOrientation?: ActionsOrientation;
|
|
82
|
+
/**
|
|
83
|
+
* Short of room, the page's actions show what fits and turn the rest in a
|
|
84
|
+
* wheel (a mouse wheel, a drag, the arrow keys), instead of turning across.
|
|
85
|
+
* Default false (beta).
|
|
86
|
+
*/
|
|
87
|
+
actionsWheel?: boolean;
|
|
88
|
+
/** On a side they share, the page's actions are nearer the pill (default), or the electrons (beta). */
|
|
89
|
+
nearestToPill?: NearestToPill;
|
|
82
90
|
/** The page's actions' accessible name. Default "Page actions" (beta). */
|
|
83
91
|
actionsLabel?: string;
|
|
84
92
|
}
|
|
@@ -83,7 +83,7 @@ const notificationIn = ({ scene, presence }) => scene.kind === "notification" &&
|
|
|
83
83
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
84
84
|
* notifications fed by pill(name), and a live region that announces them.
|
|
85
85
|
*/
|
|
86
|
-
const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
|
+
const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsWheel = false, nearestToPill = "actions", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
87
87
|
const store = require_store.getStore(name);
|
|
88
88
|
const { current } = require_usePillQueue.usePillQueue(name);
|
|
89
89
|
const rootRef = (0, react.useRef)(null);
|
|
@@ -274,6 +274,8 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
|
|
|
274
274
|
actionsStyle,
|
|
275
275
|
actionsSide,
|
|
276
276
|
actionsOrientation,
|
|
277
|
+
actionsWheel,
|
|
278
|
+
nearestToPill,
|
|
277
279
|
actionsLabel
|
|
278
280
|
} : void 0;
|
|
279
281
|
const inside = satellites && satelliteHost && actionsStyle === "inside" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(satellites.Inside, { host: satelliteHost }) : null;
|
|
@@ -83,7 +83,7 @@ const notificationIn = ({ scene, presence }) => scene.kind === "notification" &&
|
|
|
83
83
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
84
84
|
* notifications fed by pill(name), and a live region that announces them.
|
|
85
85
|
*/
|
|
86
|
-
const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
|
+
const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsWheel = false, nearestToPill = "actions", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
87
87
|
const store = getStore(name);
|
|
88
88
|
const { current } = usePillQueue(name);
|
|
89
89
|
const rootRef = useRef(null);
|
|
@@ -274,6 +274,8 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
|
|
|
274
274
|
actionsStyle,
|
|
275
275
|
actionsSide,
|
|
276
276
|
actionsOrientation,
|
|
277
|
+
actionsWheel,
|
|
278
|
+
nearestToPill,
|
|
277
279
|
actionsLabel
|
|
278
280
|
} : void 0;
|
|
279
281
|
const inside = satellites && satelliteHost && actionsStyle === "inside" ? /* @__PURE__ */ jsx(satellites.Inside, { host: satelliteHost }) : null;
|
package/dist/Pill/goo.js
CHANGED
|
@@ -109,7 +109,7 @@ function createOverlay(zIndex, color, shadow) {
|
|
|
109
109
|
const root = document.createElement("div");
|
|
110
110
|
root.setAttribute("data-mp", "goo");
|
|
111
111
|
root.setAttribute("aria-hidden", "true");
|
|
112
|
-
root.style.cssText = `position:fixed;
|
|
112
|
+
root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${zIndex};`;
|
|
113
113
|
const svg = document.createElementNS(SVG, "svg");
|
|
114
114
|
svg.setAttribute("width", "0");
|
|
115
115
|
svg.setAttribute("height", "0");
|
|
@@ -161,15 +161,29 @@ function createOverlay(zIndex, color, shadow) {
|
|
|
161
161
|
moving
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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);
|
|
173
187
|
}
|
|
174
188
|
const OWN_LOOK = {
|
|
175
189
|
transition: "none",
|
|
@@ -201,6 +215,17 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
201
215
|
const fade = require_timing.parseDuration(style.getPropertyValue("--_mp-fade"), 150);
|
|
202
216
|
const easing = kind === "split" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
|
|
203
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
|
+
};
|
|
204
229
|
let glass = kind === "join";
|
|
205
230
|
const saved = /* @__PURE__ */ new Map();
|
|
206
231
|
let frame = 0;
|
|
@@ -302,9 +327,12 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
302
327
|
saved.set("transition", [moving.style.getPropertyValue("transition"), moving.style.getPropertyPriority("transition")]);
|
|
303
328
|
moving.style.setProperty("transition", "none", "important");
|
|
304
329
|
const own = getComputedStyle(moving);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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();
|
|
308
336
|
hideOwnLook();
|
|
309
337
|
if (kind === "split") for (const name of BLUR) {
|
|
310
338
|
saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
|
|
@@ -328,8 +356,7 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
328
356
|
if (begun && overlay) {
|
|
329
357
|
const k = Math.min(1, Math.max(0, (elapsed - timing.delay) / timing.duration));
|
|
330
358
|
overlay.blur.setAttribute("stdDeviation", (goo * gooAmount(k)).toFixed(2));
|
|
331
|
-
|
|
332
|
-
place(overlay.moving, moving);
|
|
359
|
+
placeShapes();
|
|
333
360
|
setGlass(!overlaps(moving.getBoundingClientRect(), anchor.getBoundingClientRect()));
|
|
334
361
|
}
|
|
335
362
|
if (elapsed >= timing.delay + timing.duration) {
|
|
@@ -343,10 +370,206 @@ function playSplit(anchor, moving, kind, timing) {
|
|
|
343
370
|
running.set(moving, stop);
|
|
344
371
|
return stop;
|
|
345
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
|
+
}
|
|
346
565
|
|
|
347
566
|
exports.SPLIT = SPLIT;
|
|
567
|
+
exports.atEdgeOf = atEdgeOf;
|
|
568
|
+
exports.atPoint = atPoint;
|
|
348
569
|
exports.dropShadow = dropShadow;
|
|
349
570
|
exports.gooAmount = gooAmount;
|
|
571
|
+
exports.playNecks = playNecks;
|
|
572
|
+
exports.playOrbit = playOrbit;
|
|
350
573
|
exports.playSplit = playSplit;
|
|
351
574
|
exports.splitEasing = splitEasing;
|
|
352
575
|
exports.springEasing = springEasing;
|