magic-pill 9.0.0-next.2 → 9.0.0-next.3
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 -3
- package/README.md +14 -7
- package/dist/MagicPill/MagicPill.d.mts +7 -0
- package/dist/MagicPill/MagicPill.d.ts +7 -0
- package/dist/MagicPill/MagicPill.js +19 -4
- package/dist/MagicPill/MagicPill.mjs +21 -6
- package/dist/MagicPill/choreography.d.mts +8 -0
- package/dist/MagicPill/choreography.d.ts +9 -0
- package/dist/MagicPill/choreography.js +19 -13
- package/dist/MagicPill/choreography.mjs +17 -12
- package/dist/Pill/Pill.js +32 -15
- package/dist/Pill/Pill.mjs +33 -16
- package/dist/Pill/PillAction.js +1 -1
- package/dist/Pill/PillAction.mjs +1 -1
- package/dist/Pill/modal.js +55 -0
- package/dist/Pill/modal.mjs +54 -0
- package/dist/Pill/morph.js +405 -0
- package/dist/Pill/morph.mjs +399 -0
- package/dist/Pill/types.d.mts +6 -1
- package/dist/Pill/types.d.ts +6 -1
- package/dist/PillNavbar/matchPath.js +6 -2
- package/dist/PillNavbar/matchPath.mjs +6 -2
- package/dist/PillNotification/PillNotification.d.mts +4 -0
- package/dist/PillNotification/PillNotification.d.ts +4 -0
- package/dist/PillNotification/PillNotification.js +4 -1
- package/dist/PillNotification/PillNotification.mjs +4 -1
- package/dist/styles.css +120 -53
- package/dist/utils/timing.d.ts +1 -0
- package/dist/utils/timing.js +13 -0
- package/dist/utils/timing.mjs +12 -0
- package/package.json +1 -1
package/dist/styles.css
CHANGED
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
@layer behaviour {
|
|
24
24
|
/* ─── Behaviour: kept by `unstyled` pills ──────────────────────────────── */
|
|
25
25
|
|
|
26
|
-
/* Hidden: invisible once the exit transition is over. React also makes it
|
|
27
|
-
|
|
26
|
+
/* Hidden: invisible once the exit transition is over. React also makes it
|
|
27
|
+
inert. Not a <dialog>, which takes the focus as it starts to open */
|
|
28
|
+
[data-mp="pill"][data-presence="hidden"]:not(dialog) {
|
|
28
29
|
visibility: hidden;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -74,11 +75,16 @@
|
|
|
74
75
|
inline-size: fit-content;
|
|
75
76
|
min-block-size: var(--_mp-rest-size);
|
|
76
77
|
max-inline-size: var(--_mp-max-size);
|
|
78
|
+
position: relative;
|
|
77
79
|
margin: 0;
|
|
78
80
|
padding: var(--_mp-padding);
|
|
79
81
|
overflow: hidden;
|
|
80
82
|
border: 0;
|
|
81
|
-
|
|
83
|
+
/* Half the one-line pill's height: round ends on a one-line pill, a
|
|
84
|
+
rounded rectangle when it grows taller (a wrapped message, a panel).
|
|
85
|
+
The browser shrinks it while the pill is smaller, so the size
|
|
86
|
+
animation (morph.ts) keeps the corners right at every frame */
|
|
87
|
+
border-radius: calc(var(--_mp-rest-size) / 2);
|
|
82
88
|
background: var(--_mp-surface);
|
|
83
89
|
color: var(--_mp-on-surface);
|
|
84
90
|
box-shadow: var(--mp-shadow, 0 0.5rem 0.5rem rgb(20 20 20 / 0.45));
|
|
@@ -89,17 +95,11 @@
|
|
|
89
95
|
/* Where the pill pops in from and scales out to: its centre, or e.g.
|
|
90
96
|
bottom to come out of the edge a bottom pill sits on */
|
|
91
97
|
transform-origin: var(--mp-scale-origin, center);
|
|
92
|
-
/*
|
|
93
|
-
|
|
94
|
-
interpolate-size: allow-keywords;
|
|
98
|
+
/* The size itself is animated by script (morph.ts): CSS can't
|
|
99
|
+
transition a size that follows the content */
|
|
95
100
|
transition:
|
|
96
101
|
scale var(--_mp-enter) var(--_mp-ease-enter),
|
|
97
|
-
inline-size var(--_mp-change) ease-in-out,
|
|
98
|
-
block-size var(--_mp-change) ease-in-out,
|
|
99
|
-
max-inline-size var(--_mp-change) ease-in-out,
|
|
100
|
-
max-block-size var(--_mp-change) ease-in-out,
|
|
101
102
|
border-radius var(--_mp-change) ease-in-out,
|
|
102
|
-
padding var(--_mp-change) ease-in-out,
|
|
103
103
|
background-color var(--_mp-change) ease-in-out,
|
|
104
104
|
visibility 0s;
|
|
105
105
|
|
|
@@ -128,17 +128,9 @@
|
|
|
128
128
|
/* Fade the content out, shrink to a circle, scale out, then stop being visible */
|
|
129
129
|
transition:
|
|
130
130
|
scale var(--_mp-exit) ease-in calc(var(--_mp-fade) + var(--_mp-change)),
|
|
131
|
-
inline-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
132
|
-
block-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
133
|
-
max-inline-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
134
|
-
max-block-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
135
131
|
border-radius var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
136
|
-
padding var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
137
132
|
background-color var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
138
133
|
visibility 0s linear calc(var(--_mp-fade) + var(--_mp-change) + var(--_mp-exit));
|
|
139
|
-
/* An open horizontal pill has no height cap (none): without this, the
|
|
140
|
-
circle's cap would clip the content at once, while it still fades */
|
|
141
|
-
transition-behavior: allow-discrete;
|
|
142
134
|
}
|
|
143
135
|
|
|
144
136
|
/* A circle: both axes clamped, whatever the hidden content would need.
|
|
@@ -149,43 +141,27 @@
|
|
|
149
141
|
max-block-size: var(--_mp-rest-size);
|
|
150
142
|
transition:
|
|
151
143
|
scale var(--_mp-enter) var(--_mp-ease-enter),
|
|
152
|
-
inline-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
153
|
-
block-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
154
|
-
max-inline-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
155
|
-
max-block-size var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
156
144
|
border-radius var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
157
|
-
padding var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
158
145
|
background-color var(--_mp-change) ease-in-out var(--_mp-fade),
|
|
159
146
|
visibility 0s;
|
|
160
|
-
transition-behavior: allow-discrete;
|
|
161
147
|
}
|
|
162
148
|
|
|
163
|
-
/* The content is never seen while the pill changes size
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
supported). <MagicPill> renders new content closed first, so it opens
|
|
169
|
-
the same way (L21) */
|
|
149
|
+
/* The content is never seen while the pill changes size: the size
|
|
150
|
+
animation holds the pill's size while it reflows out of sight.
|
|
151
|
+
Closing: it fades out, then the pill shrinks. Opening: the pill
|
|
152
|
+
grows, then it fades in. <MagicPill> renders new content closed
|
|
153
|
+
first, so it opens the same way (L21) */
|
|
170
154
|
& > :not([data-mp="icon"], [data-mp="panel"]) {
|
|
171
155
|
transition:
|
|
172
156
|
opacity var(--_mp-fade) ease-out var(--_mp-change),
|
|
173
|
-
visibility 0s
|
|
174
|
-
white-space 0s linear var(--_mp-change);
|
|
175
|
-
transition-behavior: allow-discrete;
|
|
157
|
+
visibility 0s;
|
|
176
158
|
}
|
|
177
159
|
|
|
178
160
|
&:is([data-presence="rest"], [data-presence="hidden"]) > :not([data-mp="icon"], [data-mp="panel"]) {
|
|
179
161
|
opacity: 0;
|
|
180
162
|
transition:
|
|
181
163
|
opacity var(--_mp-fade) ease-in,
|
|
182
|
-
visibility 0s linear calc(var(--_mp-fade) + var(--_mp-change))
|
|
183
|
-
white-space 0s linear var(--_mp-fade);
|
|
184
|
-
transition-behavior: allow-discrete;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
&:is([data-presence="rest"], [data-presence="hidden"]) > [data-mp="message"] {
|
|
188
|
-
white-space: nowrap;
|
|
164
|
+
visibility 0s linear calc(var(--_mp-fade) + var(--_mp-change));
|
|
189
165
|
}
|
|
190
166
|
|
|
191
167
|
&[data-presence="panel"] {
|
|
@@ -251,16 +227,31 @@
|
|
|
251
227
|
inset: 0;
|
|
252
228
|
margin: auto;
|
|
253
229
|
block-size: fit-content;
|
|
254
|
-
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
255
230
|
|
|
256
|
-
|
|
257
|
-
|
|
231
|
+
&:not([data-presence="rest"], [data-presence="hidden"]) {
|
|
232
|
+
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
258
233
|
}
|
|
259
234
|
}
|
|
260
235
|
|
|
261
|
-
/*
|
|
236
|
+
/* The overlay's backdrop fades in as the pill pops in, and out once
|
|
237
|
+
the content has faded out */
|
|
238
|
+
&::backdrop {
|
|
239
|
+
background: var(--mp-backdrop, rgb(20 20 20 / 0.4));
|
|
240
|
+
transition: opacity var(--_mp-change) ease-out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
&[data-presence="hidden"]::backdrop {
|
|
244
|
+
opacity: 0;
|
|
245
|
+
transition: opacity calc(var(--_mp-change) + var(--_mp-exit)) ease-in-out var(--_mp-fade);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Vertical pills (sidebars). Their items line up along the screen
|
|
249
|
+
edge they sit on (--mp-align: start, center or end, following the
|
|
250
|
+
text direction; centred when the pill isn't on a side) */
|
|
262
251
|
&[data-orientation="vertical"] {
|
|
252
|
+
--_mp-align: var(--mp-align, center);
|
|
263
253
|
flex-direction: column;
|
|
254
|
+
align-items: var(--_mp-align);
|
|
264
255
|
inline-size: auto;
|
|
265
256
|
block-size: fit-content;
|
|
266
257
|
max-inline-size: none;
|
|
@@ -270,10 +261,47 @@
|
|
|
270
261
|
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
271
262
|
}
|
|
272
263
|
|
|
264
|
+
/* A sidebar's panel keeps the panel's width cap, like any other */
|
|
265
|
+
&[data-orientation="vertical"][data-presence="panel"] {
|
|
266
|
+
max-inline-size: var(--_mp-max-size);
|
|
267
|
+
}
|
|
268
|
+
|
|
273
269
|
&[data-orientation="vertical"]:is([data-presence="rest"], [data-presence="hidden"]) {
|
|
274
270
|
block-size: var(--_mp-rest-size);
|
|
275
271
|
}
|
|
276
272
|
|
|
273
|
+
&[data-orientation="vertical"]:is([data-placement="left"]:dir(ltr), [data-placement="right"]:dir(rtl)) {
|
|
274
|
+
--_mp-align: var(--mp-align, start);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* On the right-hand side (left-hand in right-to-left pages), labels
|
|
278
|
+
open towards the middle of the screen, so the icons stay in line
|
|
279
|
+
along the edge: the action reads the other way round (so its
|
|
280
|
+
spacing flips too), the label's text keeps the page's direction */
|
|
281
|
+
&[data-orientation="vertical"]:is([data-placement="right"]:dir(ltr), [data-placement="left"]:dir(rtl)) {
|
|
282
|
+
--_mp-align: var(--mp-align, end);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&[data-orientation="vertical"][data-placement="right"]:dir(ltr) {
|
|
286
|
+
& [data-mp="action-body"] {
|
|
287
|
+
direction: rtl;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
& [data-mp="label"] > * {
|
|
291
|
+
direction: ltr;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
&[data-orientation="vertical"][data-placement="left"]:dir(rtl) {
|
|
296
|
+
& [data-mp="action-body"] {
|
|
297
|
+
direction: ltr;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
& [data-mp="label"] > * {
|
|
301
|
+
direction: rtl;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
277
305
|
/* Parts */
|
|
278
306
|
& [data-mp="icon"] {
|
|
279
307
|
flex: none;
|
|
@@ -319,6 +347,7 @@
|
|
|
319
347
|
|
|
320
348
|
&[data-orientation="vertical"] [data-mp="actions"] {
|
|
321
349
|
flex-direction: column;
|
|
350
|
+
align-items: var(--_mp-align);
|
|
322
351
|
}
|
|
323
352
|
|
|
324
353
|
/* The <a>/<button> stays neutral and the look lives on its inner body:
|
|
@@ -382,25 +411,43 @@
|
|
|
382
411
|
block-size: 1em;
|
|
383
412
|
}
|
|
384
413
|
|
|
385
|
-
/* Labels: folded away (but still the accessible name) until expanded
|
|
414
|
+
/* Labels: folded away (but still the accessible name) until expanded.
|
|
415
|
+
A grid column from 0fr to 1fr animates the label's real width, so
|
|
416
|
+
the pill widens at the same pace as it unfolds */
|
|
386
417
|
& [data-mp="label"] {
|
|
387
|
-
|
|
418
|
+
display: grid;
|
|
419
|
+
grid-template-columns: 0fr;
|
|
420
|
+
max-inline-size: 20rem;
|
|
388
421
|
opacity: 0;
|
|
389
422
|
transition:
|
|
390
|
-
|
|
423
|
+
grid-template-columns var(--_mp-change) ease-in-out,
|
|
391
424
|
opacity var(--_mp-change) ease-in-out,
|
|
392
425
|
margin var(--_mp-change) ease-in-out;
|
|
426
|
+
|
|
427
|
+
& > * {
|
|
428
|
+
min-inline-size: 0;
|
|
429
|
+
overflow: hidden;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/* In a column, the pill is as wide as its widest item: a label folds
|
|
434
|
+
only once the next one has unfolded, so the pill never narrows in
|
|
435
|
+
between (and moving the pointer from item to item keeps it steady) */
|
|
436
|
+
&[data-orientation="vertical"] :is([data-mp="label"], [data-mp="action-body"]) {
|
|
437
|
+
transition-delay: var(--_mp-change);
|
|
393
438
|
}
|
|
394
439
|
|
|
395
440
|
& [data-mp="action"]:is(:focus-visible, [data-expanded], [aria-current="page"], [aria-current="true"]),
|
|
396
441
|
&:is([data-presence="expanded"], [data-presence="panel"]) [data-mp="action"] {
|
|
397
442
|
& [data-mp="action-body"] {
|
|
398
443
|
padding-inline-end: calc(var(--_mp-action-size) / 2.5);
|
|
444
|
+
transition-delay: 0s;
|
|
399
445
|
}
|
|
400
446
|
|
|
401
447
|
& [data-mp="label"] {
|
|
402
|
-
|
|
448
|
+
grid-template-columns: 1fr;
|
|
403
449
|
opacity: 1;
|
|
450
|
+
transition-delay: 0s;
|
|
404
451
|
}
|
|
405
452
|
|
|
406
453
|
& [data-mp="action-icon"] + [data-mp="label"] {
|
|
@@ -414,11 +461,13 @@
|
|
|
414
461
|
& [data-mp="action"]:hover {
|
|
415
462
|
& [data-mp="action-body"] {
|
|
416
463
|
padding-inline-end: calc(var(--_mp-action-size) / 2.5);
|
|
464
|
+
transition-delay: 0s;
|
|
417
465
|
}
|
|
418
466
|
|
|
419
467
|
& [data-mp="label"] {
|
|
420
|
-
|
|
468
|
+
grid-template-columns: 1fr;
|
|
421
469
|
opacity: 1;
|
|
470
|
+
transition-delay: 0s;
|
|
422
471
|
}
|
|
423
472
|
|
|
424
473
|
& [data-mp="action-icon"] + [data-mp="label"] {
|
|
@@ -427,19 +476,32 @@
|
|
|
427
476
|
}
|
|
428
477
|
}
|
|
429
478
|
|
|
430
|
-
/* Panel
|
|
479
|
+
/* Panel: its content fades in over the second half of the pill's
|
|
480
|
+
growth (the size animation fades its clipped edge), and out as the
|
|
481
|
+
pill shrinks, out of the flow so the pill can take its closed size */
|
|
431
482
|
& [data-mp="panel"] {
|
|
432
483
|
display: grid;
|
|
433
484
|
gap: var(--_mp-gap);
|
|
434
485
|
outline: none;
|
|
435
486
|
opacity: 1;
|
|
436
|
-
transition: opacity var(--_mp-change) ease-out var(--_mp-change);
|
|
487
|
+
transition: opacity var(--_mp-change) ease-out calc(var(--_mp-change) / 2);
|
|
437
488
|
|
|
438
489
|
@starting-style {
|
|
439
490
|
opacity: 0;
|
|
440
491
|
}
|
|
441
492
|
}
|
|
442
493
|
|
|
494
|
+
& [data-mp="panel"]:not([data-open]) {
|
|
495
|
+
position: absolute;
|
|
496
|
+
inset-block-start: calc(var(--_mp-padding) * 2.5);
|
|
497
|
+
inset-inline-start: calc(var(--_mp-padding) * 2.5);
|
|
498
|
+
opacity: 0;
|
|
499
|
+
transition:
|
|
500
|
+
opacity var(--_mp-fade) ease-in,
|
|
501
|
+
display 0s linear var(--_mp-fade);
|
|
502
|
+
transition-behavior: allow-discrete;
|
|
503
|
+
}
|
|
504
|
+
|
|
443
505
|
& [data-mp="panel-title"] {
|
|
444
506
|
font-size: var(--mp-title-size, clamp(1.5rem, 1.25rem + 1vw, 2rem));
|
|
445
507
|
font-style: italic;
|
|
@@ -485,6 +547,11 @@
|
|
|
485
547
|
visibility 0s;
|
|
486
548
|
}
|
|
487
549
|
|
|
550
|
+
&::backdrop,
|
|
551
|
+
&[data-presence="hidden"]::backdrop {
|
|
552
|
+
transition: opacity 150ms linear;
|
|
553
|
+
}
|
|
554
|
+
|
|
488
555
|
/* Nothing resizes, so the content doesn't wait: it fades with the
|
|
489
556
|
pill, and the message unwraps at once */
|
|
490
557
|
&:not([data-presence="rest"], [data-presence="hidden"]) > :not([data-mp="icon"], [data-mp="panel"]) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/utils/timing.ts
|
|
2
|
+
/** "500ms" or "0.5s" → 500 (minified CSS writes 150ms as .15s); anything else → the fallback. */
|
|
3
|
+
function parseDuration(value, fallback) {
|
|
4
|
+
const match = /^\s*([\d.]+)(ms|s)\s*$/.exec(value);
|
|
5
|
+
if (!match) return fallback;
|
|
6
|
+
const amount = Number.parseFloat(match[1]);
|
|
7
|
+
return match[2] === "s" ? amount * 1e3 : amount;
|
|
8
|
+
}
|
|
9
|
+
/** The user asked the system for less motion. */
|
|
10
|
+
const prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
11
|
+
|
|
12
|
+
exports.parseDuration = parseDuration;
|
|
13
|
+
exports.prefersReducedMotion = prefersReducedMotion;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/utils/timing.ts
|
|
2
|
+
/** "500ms" or "0.5s" → 500 (minified CSS writes 150ms as .15s); anything else → the fallback. */
|
|
3
|
+
function parseDuration(value, fallback) {
|
|
4
|
+
const match = /^\s*([\d.]+)(ms|s)\s*$/.exec(value);
|
|
5
|
+
if (!match) return fallback;
|
|
6
|
+
const amount = Number.parseFloat(match[1]);
|
|
7
|
+
return match[2] === "s" ? amount * 1e3 : amount;
|
|
8
|
+
}
|
|
9
|
+
/** The user asked the system for less motion. */
|
|
10
|
+
const prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
11
|
+
|
|
12
|
+
export { parseDuration, prefersReducedMotion };
|