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,347 @@
|
|
|
1
|
+
import { parseDuration, prefersReducedMotion } from "../utils/timing.mjs";
|
|
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 || 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 = 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
|
+
export { SPLIT, dropShadow, gooAmount, playSplit, splitEasing, springEasing, tuckedOffset };
|
package/dist/Pill/morph.js
CHANGED
|
@@ -133,7 +133,7 @@ function planExit(start, timings, exit) {
|
|
|
133
133
|
easing: "ease-in"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
|
-
scale: "0",
|
|
136
|
+
scale: start.to ?? "0",
|
|
137
137
|
visibility: "visible"
|
|
138
138
|
}
|
|
139
139
|
],
|
|
@@ -166,9 +166,11 @@ function playExit(element, timings) {
|
|
|
166
166
|
const content = fadingContent(element);
|
|
167
167
|
const opacity = content.length > 0 ? getComputedStyle(content[0]).opacity : "0";
|
|
168
168
|
const exit = require_timing.parseDuration(style.getPropertyValue("--_mp-exit"), 300);
|
|
169
|
+
const to = style.getPropertyValue("--_mp-exit-scale").trim() || void 0;
|
|
169
170
|
const plan = planExit({
|
|
170
171
|
scale,
|
|
171
|
-
content: Number(opacity) > 0 ? opacity : void 0
|
|
172
|
+
content: Number(opacity) > 0 ? opacity : void 0,
|
|
173
|
+
to
|
|
172
174
|
}, timings, exit);
|
|
173
175
|
if (!plan) return [];
|
|
174
176
|
const animations = [element.animate(plan.pill.keyframes, plan.pill.options)];
|
package/dist/Pill/morph.mjs
CHANGED
|
@@ -133,7 +133,7 @@ function planExit(start, timings, exit) {
|
|
|
133
133
|
easing: "ease-in"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
|
-
scale: "0",
|
|
136
|
+
scale: start.to ?? "0",
|
|
137
137
|
visibility: "visible"
|
|
138
138
|
}
|
|
139
139
|
],
|
|
@@ -166,9 +166,11 @@ function playExit(element, timings) {
|
|
|
166
166
|
const content = fadingContent(element);
|
|
167
167
|
const opacity = content.length > 0 ? getComputedStyle(content[0]).opacity : "0";
|
|
168
168
|
const exit = parseDuration(style.getPropertyValue("--_mp-exit"), 300);
|
|
169
|
+
const to = style.getPropertyValue("--_mp-exit-scale").trim() || void 0;
|
|
169
170
|
const plan = planExit({
|
|
170
171
|
scale,
|
|
171
|
-
content: Number(opacity) > 0 ? opacity : void 0
|
|
172
|
+
content: Number(opacity) > 0 ? opacity : void 0,
|
|
173
|
+
to
|
|
172
174
|
}, timings, exit);
|
|
173
175
|
if (!plan) return [];
|
|
174
176
|
const animations = [element.animate(plan.pill.keyframes, plan.pill.options)];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
|
|
2
2
|
import { LinkComponent } from "../Pill/types.mjs";
|
|
3
3
|
import { NavMatch } from "./matchPath.mjs";
|
|
4
|
+
import { NavLabels } from "./room.mjs";
|
|
4
5
|
interface NavItemBase {
|
|
5
6
|
label: string;
|
|
6
7
|
icon?: ReactNode;
|
|
@@ -43,6 +44,13 @@ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "
|
|
|
43
44
|
*/
|
|
44
45
|
pathname?: string;
|
|
45
46
|
linkComponent?: LinkComponent;
|
|
47
|
+
/**
|
|
48
|
+
* Which labels show at rest: the current page's ("current"), none
|
|
49
|
+
* ("closed"), or the current page's while the pill has room for it
|
|
50
|
+
* ("auto", the default: it folds next to an electron on a narrow screen).
|
|
51
|
+
* An item pointed at or focused shows its label in every case.
|
|
52
|
+
*/
|
|
53
|
+
labels?: NavLabels;
|
|
46
54
|
/** Default "Main". */
|
|
47
55
|
"aria-label"?: string;
|
|
48
56
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
|
|
2
2
|
import { LinkComponent } from "../Pill/types.js";
|
|
3
3
|
import { NavMatch } from "./matchPath.js";
|
|
4
|
+
import { NavLabels } from "./room.js";
|
|
4
5
|
interface NavItemBase {
|
|
5
6
|
label: string;
|
|
6
7
|
icon?: ReactNode;
|
|
@@ -43,6 +44,13 @@ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "
|
|
|
43
44
|
*/
|
|
44
45
|
pathname?: string;
|
|
45
46
|
linkComponent?: LinkComponent;
|
|
47
|
+
/**
|
|
48
|
+
* Which labels show at rest: the current page's ("current"), none
|
|
49
|
+
* ("closed"), or the current page's while the pill has room for it
|
|
50
|
+
* ("auto", the default: it folds next to an electron on a narrow screen).
|
|
51
|
+
* An item pointed at or focused shows its label in every case.
|
|
52
|
+
*/
|
|
53
|
+
labels?: NavLabels;
|
|
46
54
|
/** Default "Main". */
|
|
47
55
|
"aria-label"?: string;
|
|
48
56
|
}
|
|
@@ -27,10 +27,10 @@ const isLink = (item) => item.href !== void 0;
|
|
|
27
27
|
* A <nav> of icon links, actions and panel triggers. The active link shows its
|
|
28
28
|
* label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
|
|
29
29
|
*/
|
|
30
|
-
const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
|
|
30
|
+
const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, labels = "auto", "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
|
|
31
31
|
const navRef = (0, react.useRef)(null);
|
|
32
32
|
const ref = (0, react.useMemo)(() => require_react.mergeRefs(navRef, forwardedRef), [forwardedRef]);
|
|
33
|
-
require_room.useRoom(navRef);
|
|
33
|
+
require_room.useRoom(navRef, labels);
|
|
34
34
|
const locationPathname = useLocationPathname(pathname === void 0);
|
|
35
35
|
const links = items.filter(isLink);
|
|
36
36
|
const active = links[require_matchPath.findActiveIndex(pathname ?? locationPathname, links)];
|
|
@@ -62,6 +62,7 @@ const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname,
|
|
|
62
62
|
...rest,
|
|
63
63
|
ref,
|
|
64
64
|
"data-mp": "navbar",
|
|
65
|
+
"data-labels": labels,
|
|
65
66
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map(renderItem) })
|
|
66
67
|
});
|
|
67
68
|
});
|
|
@@ -27,10 +27,10 @@ const isLink = (item) => item.href !== void 0;
|
|
|
27
27
|
* A <nav> of icon links, actions and panel triggers. The active link shows its
|
|
28
28
|
* label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
|
|
29
29
|
*/
|
|
30
|
-
const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
|
|
30
|
+
const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, labels = "auto", "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
|
|
31
31
|
const navRef = useRef(null);
|
|
32
32
|
const ref = useMemo(() => mergeRefs(navRef, forwardedRef), [forwardedRef]);
|
|
33
|
-
useRoom(navRef);
|
|
33
|
+
useRoom(navRef, labels);
|
|
34
34
|
const locationPathname = useLocationPathname(pathname === void 0);
|
|
35
35
|
const links = items.filter(isLink);
|
|
36
36
|
const active = links[findActiveIndex(pathname ?? locationPathname, links)];
|
|
@@ -62,6 +62,7 @@ const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkCompone
|
|
|
62
62
|
...rest,
|
|
63
63
|
ref,
|
|
64
64
|
"data-mp": "navbar",
|
|
65
|
+
"data-labels": labels,
|
|
65
66
|
children: /* @__PURE__ */ jsx(PillActions, { children: items.map(renderItem) })
|
|
66
67
|
});
|
|
67
68
|
});
|
package/dist/PillNavbar/room.js
CHANGED
|
@@ -4,35 +4,62 @@ let react = require("react");
|
|
|
4
4
|
|
|
5
5
|
// src/PillNavbar/room.ts
|
|
6
6
|
const ACTION = "[data-mp=\"action\"]";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
* on a copy, removed before anything is painted: the labels on screen may be
|
|
10
|
-
* moving, and the app's own styles count.
|
|
11
|
-
*/
|
|
12
|
-
function fitsWith(navbar, item) {
|
|
13
|
-
const pill = navbar.closest("[data-mp=\"pill\"]");
|
|
14
|
-
if (!pill) return true;
|
|
15
|
-
const index = [...navbar.querySelectorAll(ACTION)].indexOf(item);
|
|
7
|
+
/** A copy of the pill with its navbar, laid out next to it, hidden, to measure. Removed by the caller. */
|
|
8
|
+
function layOutCopy(pill, prepare) {
|
|
16
9
|
const copy = pill.cloneNode(false);
|
|
17
10
|
for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
|
|
18
11
|
copy.querySelectorAll("[id], [name]").forEach((node) => {
|
|
19
12
|
node.removeAttribute("id");
|
|
20
13
|
node.removeAttribute("name");
|
|
21
14
|
});
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const navbar = copy.querySelector("[data-mp=\"navbar\"]");
|
|
16
|
+
if (!navbar) return null;
|
|
17
|
+
navbar.removeAttribute("data-tight");
|
|
18
|
+
prepare(navbar);
|
|
26
19
|
copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
|
|
27
20
|
node.style.flexShrink = "0";
|
|
28
21
|
});
|
|
29
22
|
copy.inert = true;
|
|
30
23
|
copy.style.visibility = "hidden";
|
|
31
24
|
pill.after(copy);
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
return {
|
|
26
|
+
copy,
|
|
27
|
+
navbar
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether the navbar still fits its pill with this item's label open (or as
|
|
32
|
+
* it is at rest, with no item; `unfold`: with the current page's label open
|
|
33
|
+
* even if it's folded). Laid out on a copy, removed before anything is
|
|
34
|
+
* painted: the labels on screen may be moving, and the app's own styles count.
|
|
35
|
+
*/
|
|
36
|
+
function fitsWith(navbar, item, { unfold = false } = {}) {
|
|
37
|
+
const pill = navbar.closest("[data-mp=\"pill\"]");
|
|
38
|
+
if (!pill) return true;
|
|
39
|
+
const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
|
|
40
|
+
const laidOut = layOutCopy(pill, (copied) => {
|
|
41
|
+
if (unfold) copied.removeAttribute("data-folded");
|
|
42
|
+
if (index >= 0) copied.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
|
|
43
|
+
});
|
|
44
|
+
if (!laidOut) return true;
|
|
45
|
+
const fits = isInside(laidOut.navbar, laidOut.copy);
|
|
46
|
+
laidOut.copy.remove();
|
|
34
47
|
return fits;
|
|
35
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* How wide the pill is with all its navbar's labels folded, or its own width
|
|
51
|
+
* if it has no navbar that can fold them (`labels="current"`). The
|
|
52
|
+
* satellites ask, to know whether an electron fits next to it.
|
|
53
|
+
*/
|
|
54
|
+
function foldedWidth(pill) {
|
|
55
|
+
const navbar = pill.querySelector("[data-mp=\"navbar\"]");
|
|
56
|
+
if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
|
|
57
|
+
const laidOut = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""));
|
|
58
|
+
if (!laidOut) return pill.offsetWidth;
|
|
59
|
+
const width = laidOut.copy.offsetWidth;
|
|
60
|
+
laidOut.copy.remove();
|
|
61
|
+
return width;
|
|
62
|
+
}
|
|
36
63
|
/** Whether the navbar ends before the pill's padding does. */
|
|
37
64
|
function isInside(navbar, pill) {
|
|
38
65
|
const style = getComputedStyle(pill);
|
|
@@ -45,9 +72,53 @@ const isHorizontal = (navbar) => {
|
|
|
45
72
|
};
|
|
46
73
|
/**
|
|
47
74
|
* Writes `data-tight` on the navbar while the item pointed at (or focused with
|
|
48
|
-
* the keyboard) has no room for its label next to the open ones
|
|
75
|
+
* the keyboard) has no room for its label next to the open ones, and
|
|
76
|
+
* `data-folded` while the current page's label folds at rest (`labels`).
|
|
49
77
|
*/
|
|
50
|
-
function useRoom(ref) {
|
|
78
|
+
function useRoom(ref, labels = "auto") {
|
|
79
|
+
(0, react.useEffect)(() => {
|
|
80
|
+
const navbar = ref.current;
|
|
81
|
+
if (!navbar) return;
|
|
82
|
+
const fold = (folded) => {
|
|
83
|
+
if (folded) navbar.setAttribute("data-folded", "");
|
|
84
|
+
else navbar.removeAttribute("data-folded");
|
|
85
|
+
};
|
|
86
|
+
if (labels !== "auto") {
|
|
87
|
+
fold(labels === "closed");
|
|
88
|
+
return () => fold(false);
|
|
89
|
+
}
|
|
90
|
+
const pill = navbar.closest("[data-mp=\"pill\"]");
|
|
91
|
+
let frame = 0;
|
|
92
|
+
const update = () => {
|
|
93
|
+
cancelAnimationFrame(frame);
|
|
94
|
+
frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
|
|
95
|
+
};
|
|
96
|
+
fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
|
|
97
|
+
const mutations = new MutationObserver(update);
|
|
98
|
+
mutations.observe(navbar, {
|
|
99
|
+
subtree: true,
|
|
100
|
+
attributes: true,
|
|
101
|
+
attributeFilter: ["aria-current"]
|
|
102
|
+
});
|
|
103
|
+
if (pill) mutations.observe(pill, {
|
|
104
|
+
attributes: true,
|
|
105
|
+
attributeFilter: [
|
|
106
|
+
"style",
|
|
107
|
+
"data-orientation",
|
|
108
|
+
"data-presence"
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
|
|
112
|
+
if (pill) sizes?.observe(pill);
|
|
113
|
+
window.addEventListener("resize", update);
|
|
114
|
+
return () => {
|
|
115
|
+
cancelAnimationFrame(frame);
|
|
116
|
+
mutations.disconnect();
|
|
117
|
+
sizes?.disconnect();
|
|
118
|
+
window.removeEventListener("resize", update);
|
|
119
|
+
fold(false);
|
|
120
|
+
};
|
|
121
|
+
}, [ref, labels]);
|
|
51
122
|
(0, react.useEffect)(() => {
|
|
52
123
|
const navbar = ref.current;
|
|
53
124
|
if (!navbar) return;
|
|
@@ -81,4 +152,5 @@ function useRoom(ref) {
|
|
|
81
152
|
}
|
|
82
153
|
|
|
83
154
|
exports.fitsWith = fitsWith;
|
|
155
|
+
exports.foldedWidth = foldedWidth;
|
|
84
156
|
exports.useRoom = useRoom;
|