magic-pill 9.3.0 → 9.4.0-next.1
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 +12 -0
- package/README.md +114 -3
- package/dist/MagicPill/MagicPill.d.mts +43 -1
- package/dist/MagicPill/MagicPill.d.ts +43 -1
- package/dist/MagicPill/MagicPill.js +51 -4
- package/dist/MagicPill/MagicPill.mjs +53 -6
- package/dist/MagicPill/flag.js +1 -59
- package/dist/MagicPill/flag.mjs +1 -58
- package/dist/Pill/PillProgress.d.mts +12 -0
- package/dist/Pill/PillProgress.d.ts +12 -0
- package/dist/Pill/PillProgress.js +42 -0
- package/dist/Pill/PillProgress.mjs +42 -0
- package/dist/Pill/goo.js +353 -0
- package/dist/Pill/goo.mjs +347 -0
- package/dist/Pill/morph.js +4 -2
- package/dist/Pill/morph.mjs +4 -2
- package/dist/PillNavbar/PillNavbar.d.mts +8 -0
- package/dist/PillNavbar/PillNavbar.d.ts +8 -0
- package/dist/PillNavbar/PillNavbar.js +3 -2
- package/dist/PillNavbar/PillNavbar.mjs +3 -2
- package/dist/PillNavbar/room.d.mts +3 -0
- package/dist/PillNavbar/room.d.ts +2 -0
- package/dist/PillNavbar/room.js +89 -17
- package/dist/PillNavbar/room.mjs +89 -18
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -1
- package/dist/satellites/Actions.d.mts +12 -0
- package/dist/satellites/Actions.d.ts +11 -0
- package/dist/satellites/Actions.js +59 -0
- package/dist/satellites/Actions.mjs +56 -0
- package/dist/satellites/Orbitals.js +554 -0
- package/dist/satellites/Orbitals.mjs +554 -0
- package/dist/satellites/Satellites.js +400 -0
- package/dist/satellites/Satellites.mjs +400 -0
- package/dist/satellites/layout.js +156 -0
- package/dist/satellites/layout.mjs +156 -0
- package/dist/satellites/measure.js +25 -0
- package/dist/satellites/measure.mjs +24 -0
- package/dist/satellites/orbits.js +139 -0
- package/dist/satellites/orbits.mjs +136 -0
- package/dist/satellites/types.d.mts +54 -0
- package/dist/satellites/types.d.ts +54 -0
- package/dist/satellites.d.mts +5 -0
- package/dist/satellites.d.ts +5 -0
- package/dist/satellites.js +14 -0
- package/dist/satellites.mjs +12 -0
- package/dist/store/store.d.mts +103 -0
- package/dist/store/store.d.ts +103 -0
- package/dist/store/store.js +52 -1
- package/dist/store/store.mjs +52 -2
- package/dist/styles.css +168 -7
- package/package.json +11 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export interface PillProgressProps extends ComponentPropsWithoutRef<"span"> {
|
|
3
|
+
/** 0 to 1: how much of the ring is drawn. */
|
|
4
|
+
value: number;
|
|
5
|
+
/**
|
|
6
|
+
* What it measures, for screen readers ("Upload"). Without it, the ring is
|
|
7
|
+
* decorative: the pill around it says what it is (an electron's name).
|
|
8
|
+
*/
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
12
|
+
export declare const PillProgress: import("react").ForwardRefExoticComponent<PillProgressProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export interface PillProgressProps extends ComponentPropsWithoutRef<"span"> {
|
|
3
|
+
/** 0 to 1: how much of the ring is drawn. */
|
|
4
|
+
value: number;
|
|
5
|
+
/**
|
|
6
|
+
* What it measures, for screen readers ("Upload"). Without it, the ring is
|
|
7
|
+
* decorative: the pill around it says what it is (an electron's name).
|
|
8
|
+
*/
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
12
|
+
export declare const PillProgress: import("react").ForwardRefExoticComponent<PillProgressProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
|
|
4
|
+
// src/Pill/PillProgress.tsx
|
|
5
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
6
|
+
const PillProgress = (0, react.forwardRef)(function PillProgress({ value, label, children, ...rest }, ref) {
|
|
7
|
+
const amount = Math.min(1, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
8
|
+
const a11y = label ? {
|
|
9
|
+
role: "progressbar",
|
|
10
|
+
"aria-label": label,
|
|
11
|
+
"aria-valuemin": 0,
|
|
12
|
+
"aria-valuemax": 100,
|
|
13
|
+
"aria-valuenow": Math.round(amount * 100)
|
|
14
|
+
} : {};
|
|
15
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
16
|
+
...a11y,
|
|
17
|
+
...rest,
|
|
18
|
+
ref,
|
|
19
|
+
"data-mp": "progress",
|
|
20
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
21
|
+
viewBox: "0 0 54 54",
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
focusable: "false",
|
|
24
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
25
|
+
"data-mp": "progress-track",
|
|
26
|
+
cx: "27",
|
|
27
|
+
cy: "27",
|
|
28
|
+
r: "24",
|
|
29
|
+
pathLength: "100"
|
|
30
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
31
|
+
"data-mp": "progress-bar",
|
|
32
|
+
cx: "27",
|
|
33
|
+
cy: "27",
|
|
34
|
+
r: "24",
|
|
35
|
+
pathLength: "100",
|
|
36
|
+
strokeDasharray: `${amount * 100} 100`
|
|
37
|
+
})]
|
|
38
|
+
}), children]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.PillProgress = PillProgress;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
// src/Pill/PillProgress.tsx
|
|
5
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
6
|
+
const PillProgress = forwardRef(function PillProgress({ value, label, children, ...rest }, ref) {
|
|
7
|
+
const amount = Math.min(1, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
8
|
+
const a11y = label ? {
|
|
9
|
+
role: "progressbar",
|
|
10
|
+
"aria-label": label,
|
|
11
|
+
"aria-valuemin": 0,
|
|
12
|
+
"aria-valuemax": 100,
|
|
13
|
+
"aria-valuenow": Math.round(amount * 100)
|
|
14
|
+
} : {};
|
|
15
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
16
|
+
...a11y,
|
|
17
|
+
...rest,
|
|
18
|
+
ref,
|
|
19
|
+
"data-mp": "progress",
|
|
20
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
21
|
+
viewBox: "0 0 54 54",
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
focusable: "false",
|
|
24
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
25
|
+
"data-mp": "progress-track",
|
|
26
|
+
cx: "27",
|
|
27
|
+
cy: "27",
|
|
28
|
+
r: "24",
|
|
29
|
+
pathLength: "100"
|
|
30
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
31
|
+
"data-mp": "progress-bar",
|
|
32
|
+
cx: "27",
|
|
33
|
+
cy: "27",
|
|
34
|
+
r: "24",
|
|
35
|
+
pathLength: "100",
|
|
36
|
+
strokeDasharray: `${amount * 100} 100`
|
|
37
|
+
})]
|
|
38
|
+
}), children]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { PillProgress };
|
package/dist/Pill/goo.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
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;inset: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
|
+
/** Puts a shape where a pill is on screen, with its rounded corners at its current scale. */
|
|
165
|
+
function place(shape, element) {
|
|
166
|
+
const rect = element.getBoundingClientRect();
|
|
167
|
+
const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
168
|
+
const radius = Number.parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0;
|
|
169
|
+
shape.style.width = `${rect.width}px`;
|
|
170
|
+
shape.style.height = `${rect.height}px`;
|
|
171
|
+
shape.style.transform = `translate(${rect.left}px, ${rect.top}px)`;
|
|
172
|
+
shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
|
|
173
|
+
}
|
|
174
|
+
const OWN_LOOK = {
|
|
175
|
+
transition: "none",
|
|
176
|
+
"background-color": "transparent",
|
|
177
|
+
"background-image": "none",
|
|
178
|
+
"box-shadow": "none"
|
|
179
|
+
};
|
|
180
|
+
const BLUR = ["backdrop-filter", "-webkit-backdrop-filter"];
|
|
181
|
+
const GLASS_FADE = 120;
|
|
182
|
+
const overlaps = (a, b) => a.left < b.right + 1 && a.right > b.left - 1 && a.top < b.bottom + 1 && a.bottom > b.top - 1;
|
|
183
|
+
const readNumber = (style, name, fallback) => {
|
|
184
|
+
const value = Number.parseFloat(style.getPropertyValue(name));
|
|
185
|
+
return Number.isFinite(value) ? value : fallback;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Plays a split (the moving pill comes out of the anchor's edge, from where
|
|
189
|
+
* it's tucked in to where it sits) or a join (the other way, after `delay`).
|
|
190
|
+
* Reads `--mp-goo`, `--mp-electron-start` and `--mp-ease-split` on the
|
|
191
|
+
* moving pill. Does nothing with reduced motion. Returns a function that
|
|
192
|
+
* stops it at once.
|
|
193
|
+
*/
|
|
194
|
+
function playSplit(anchor, moving, kind, timing) {
|
|
195
|
+
running.get(moving)?.();
|
|
196
|
+
for (const animation of moving.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
|
|
197
|
+
if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof moving.animate !== "function") return () => {};
|
|
198
|
+
const style = getComputedStyle(moving);
|
|
199
|
+
const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
|
|
200
|
+
const start = readNumber(style, "--mp-electron-start", 1);
|
|
201
|
+
const fade = require_timing.parseDuration(style.getPropertyValue("--_mp-fade"), 150);
|
|
202
|
+
const easing = kind === "split" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
|
|
203
|
+
let overlay = null;
|
|
204
|
+
let glass = kind === "join";
|
|
205
|
+
const saved = /* @__PURE__ */ new Map();
|
|
206
|
+
let frame = 0;
|
|
207
|
+
let begun = false;
|
|
208
|
+
let stopped = false;
|
|
209
|
+
const hideOwnLook = () => {
|
|
210
|
+
for (const [name, value] of Object.entries(OWN_LOOK)) {
|
|
211
|
+
if (!saved.has(name)) saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
|
|
212
|
+
moving.style.setProperty(name, value, "important");
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const setGlass = (on) => {
|
|
216
|
+
if (on === glass) return;
|
|
217
|
+
glass = on;
|
|
218
|
+
if (on) {
|
|
219
|
+
for (const name of BLUR) restore(name);
|
|
220
|
+
moving.animate([{
|
|
221
|
+
backdropFilter: "none",
|
|
222
|
+
offset: 0
|
|
223
|
+
}], {
|
|
224
|
+
id: SPLIT,
|
|
225
|
+
duration: GLASS_FADE,
|
|
226
|
+
easing: "ease-out"
|
|
227
|
+
});
|
|
228
|
+
} else moving.animate([{
|
|
229
|
+
backdropFilter: "none",
|
|
230
|
+
offset: 1
|
|
231
|
+
}], {
|
|
232
|
+
id: SPLIT,
|
|
233
|
+
duration: GLASS_FADE,
|
|
234
|
+
easing: "ease-in",
|
|
235
|
+
fill: "forwards"
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
const restore = (name) => {
|
|
239
|
+
const [value, priority] = saved.get(name) ?? ["", ""];
|
|
240
|
+
if (value) moving.style.setProperty(name, value, priority);
|
|
241
|
+
else moving.style.removeProperty(name);
|
|
242
|
+
};
|
|
243
|
+
const restoreOwnLook = () => {
|
|
244
|
+
if (saved.size === 0) return;
|
|
245
|
+
for (const name of saved.keys()) if (name !== "transition") restore(name);
|
|
246
|
+
getComputedStyle(moving).backgroundColor;
|
|
247
|
+
restore("transition");
|
|
248
|
+
saved.clear();
|
|
249
|
+
};
|
|
250
|
+
const move = () => {
|
|
251
|
+
const tucked = tuckedOffset(anchor.getBoundingClientRect(), moving.getBoundingClientRect(), start);
|
|
252
|
+
const out = {
|
|
253
|
+
translate: "0px 0px",
|
|
254
|
+
scale: "1",
|
|
255
|
+
transformOrigin: "center"
|
|
256
|
+
};
|
|
257
|
+
const tuck = {
|
|
258
|
+
translate: `${tucked.x}px ${tucked.y}px`,
|
|
259
|
+
scale: String(tucked.scale),
|
|
260
|
+
transformOrigin: "center"
|
|
261
|
+
};
|
|
262
|
+
const options = {
|
|
263
|
+
id: SPLIT,
|
|
264
|
+
duration: timing.duration,
|
|
265
|
+
fill: kind === "split" ? "backwards" : "forwards"
|
|
266
|
+
};
|
|
267
|
+
try {
|
|
268
|
+
moving.animate(kind === "split" ? [tuck, out] : [out, tuck], {
|
|
269
|
+
...options,
|
|
270
|
+
easing
|
|
271
|
+
});
|
|
272
|
+
} catch {
|
|
273
|
+
moving.animate(kind === "split" ? [tuck, out] : [out, tuck], {
|
|
274
|
+
...options,
|
|
275
|
+
easing: POP
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const content = [...moving.children].filter((child) => !["panel", "outgoing"].includes(child.getAttribute("data-mp") ?? ""));
|
|
279
|
+
const total = timing.duration + fade;
|
|
280
|
+
for (const child of content) if (kind === "split") child.animate([
|
|
281
|
+
{ opacity: 0 },
|
|
282
|
+
{
|
|
283
|
+
opacity: 0,
|
|
284
|
+
offset: timing.duration * .8 / total
|
|
285
|
+
},
|
|
286
|
+
{ opacity: 1 }
|
|
287
|
+
], {
|
|
288
|
+
id: SPLIT,
|
|
289
|
+
duration: total
|
|
290
|
+
});
|
|
291
|
+
else child.animate([{ opacity: 1 }, { opacity: 0 }], {
|
|
292
|
+
id: SPLIT,
|
|
293
|
+
duration: Math.max(1, fade),
|
|
294
|
+
fill: "forwards"
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
const begin = () => {
|
|
298
|
+
begun = true;
|
|
299
|
+
move();
|
|
300
|
+
if (goo <= 0) return;
|
|
301
|
+
const zIndex = (Number.parseInt(style.zIndex, 10) || 50) - 1;
|
|
302
|
+
saved.set("transition", [moving.style.getPropertyValue("transition"), moving.style.getPropertyPriority("transition")]);
|
|
303
|
+
moving.style.setProperty("transition", "none", "important");
|
|
304
|
+
const own = getComputedStyle(moving);
|
|
305
|
+
overlay = createOverlay(zIndex, own.backgroundColor, dropShadow(own.boxShadow));
|
|
306
|
+
place(overlay.anchor, anchor);
|
|
307
|
+
place(overlay.moving, moving);
|
|
308
|
+
hideOwnLook();
|
|
309
|
+
if (kind === "split") for (const name of BLUR) {
|
|
310
|
+
saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
|
|
311
|
+
moving.style.setProperty(name, "none", "important");
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const stop = () => {
|
|
315
|
+
if (stopped) return;
|
|
316
|
+
stopped = true;
|
|
317
|
+
cancelAnimationFrame(frame);
|
|
318
|
+
overlay?.root.remove();
|
|
319
|
+
overlay = null;
|
|
320
|
+
restoreOwnLook();
|
|
321
|
+
running.delete(moving);
|
|
322
|
+
};
|
|
323
|
+
const startedAt = performance.now();
|
|
324
|
+
const draw = (now) => {
|
|
325
|
+
if (stopped) return;
|
|
326
|
+
const elapsed = now - startedAt;
|
|
327
|
+
if (!begun && elapsed >= timing.delay) begin();
|
|
328
|
+
if (begun && overlay) {
|
|
329
|
+
const k = Math.min(1, Math.max(0, (elapsed - timing.delay) / timing.duration));
|
|
330
|
+
overlay.blur.setAttribute("stdDeviation", (goo * gooAmount(k)).toFixed(2));
|
|
331
|
+
place(overlay.anchor, anchor);
|
|
332
|
+
place(overlay.moving, moving);
|
|
333
|
+
setGlass(!overlaps(moving.getBoundingClientRect(), anchor.getBoundingClientRect()));
|
|
334
|
+
}
|
|
335
|
+
if (elapsed >= timing.delay + timing.duration) {
|
|
336
|
+
stop();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
frame = requestAnimationFrame(draw);
|
|
340
|
+
};
|
|
341
|
+
if (timing.delay <= 0) begin();
|
|
342
|
+
frame = requestAnimationFrame(draw);
|
|
343
|
+
running.set(moving, stop);
|
|
344
|
+
return stop;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
exports.SPLIT = SPLIT;
|
|
348
|
+
exports.dropShadow = dropShadow;
|
|
349
|
+
exports.gooAmount = gooAmount;
|
|
350
|
+
exports.playSplit = playSplit;
|
|
351
|
+
exports.splitEasing = splitEasing;
|
|
352
|
+
exports.springEasing = springEasing;
|
|
353
|
+
exports.tuckedOffset = tuckedOffset;
|