magic-pill 9.4.0-next.4 → 9.4.0-rc.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 CHANGED
@@ -17,6 +17,20 @@
17
17
  - 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` (`0.15`, a droplet)
18
18
 
19
19
  ### Fixed
20
+ - A notification in rows whose message just fits on one line keeps it there: its body took the message's width rounded to the pixel, a hair short, and the message wrapped into two short lines in a box as wide as the one line (a sidebar's notification)
21
+ - A flag's goo has less to draw at every frame: the sidebar's shape under it is cut short around the flag, instead of the sidebar's full height that the filter could still run over, clipped or not (Safari)
22
+ - A sidebar's flag no longer wraps its text as it comes out: out of the sidebar as a circle, its message faded in squeezed to nothing, a word a line, before the flag opened to its width
23
+ - From a longer list of the page's actions to a shorter one (four to two), their pill shrinks over the ones leaving, then they go. They used to vanish at once, the pill shrinking after
24
+ - The page's actions no longer flicker as they go from one list to another (two actions to four, and back): for a frame, they sat by their other edge, as long as the size difference
25
+ - The goo between pills fades with them: orbitals fading into their electron (and an upload going back into its pill) drew their necks to each other at full strength, left over for a moment once they had gone
26
+ - An electron's orbitals close once, from where they are: closed while still coming out (the page scrolling, the pointer leaving), they used to jump to their spots first; asked to close again while closing (the pointer moving, a tap away), they started over and sprang back out each time
27
+ - Beside a pill at the bottom of the screen, the satellites are held by their bottom edge, as the pill is: Safari's toolbar moving the pill (scrolling, a new page coming) moves them with it at once. They stayed where they were, under the address bar, until the next pass, then caught up
28
+ - The page's actions switched into the pill go into it at their size, shrinking only as the droplet, and the pill then grows to hold them, the satellites that stay out waiting and then moving once (an electron no longer changes spot twice, planned from the pill before they had opened in it). Switched out, the pill folds them away in step with its slide, its far edge staying put, and they come out of it once it has settled: it used to slide over an electron beside it, and the electron moved twice
29
+ - Opening a panel next to the satellites: they go beside the panel, sliding along as it opens, or, when the room they take would cut it short (on a phone), into the pill, and the panel then takes that room, centred. They used to be placed beside the navbar under the panel, and the panel covered them
30
+ - The satellites slide along their side whenever they move in their row (the group gathering or spreading, the pill resizing, Safari's toolbar): they used to go down to a circle or a droplet and back past a few pixels, as if they were leaving
31
+ - A satellite going back into the pill (an electron on its own page, the page's actions hidden) goes into it where it is: the pill and the other satellites wait, and move once it's in. The pill used to open its label and slide at once, over it, and it shrank behind the pill
32
+ - A satellite coming out of a pill that's still changing size (its navbar folding its label for it, on a phone) waits for the pill to settle and comes out of its edge then, with the goo: it used to come out at once under the pill still long, and grow on its own once the pill had shrunk away
33
+ - A navbar's label opened by the pointer or the keyboard no longer covers the satellites: the electrons and the page's actions make room as it grows and come back as it closes, the group staying centred (with `labels="auto"` they were planned from the pill with its current page's label only, and it grew over them). They also keep their gap at rest: the pill with its label open measured its end padding twice, 7 px too far on each side
20
34
  - An electron coming out next to a navbar that folds its label for it (`labels="auto"`, on a phone) stays in the pill's row again, the label folding as the electron grows out of it: the pill used to jump shorter before the electron was there (its room capped it before the label had folded), and since the satellites plan from the pill open or folded, an electron that would fit beside the folded pill went above it instead
21
35
  - Switching the page's actions into the pill (`actionsStyle`) no longer shows them twice: their own pill goes back into the host as when they hide, then they open in the pill. Out of it, they fold away in the pill before their own pill comes out of it, from the pill's edge (it showed at full size at once). In the pill, they open out of nothing as they come and fold away before they go, the pill following its content: it used to jump to its new length at once, and the navbar takes their room back as they fold away
22
36
  - An electron's orbitals follow it while they're out: when it moves with the pill (on a phone, Safari's toolbar folding as the page scrolls; the group re-centring), they stayed where they had opened, apart from it, and went back in towards where it had been. They move with it at every frame, on the same arc, their opening or closing going on
@@ -61,6 +75,16 @@
61
75
  - A navbar's current label no longer folds while the pill is a circle on its way to another placement: the pill opened at its new place with the label folded, and grew by it with a jump once open
62
76
  - An electron (or the page's actions) going back into the pill as the group gathers again goes to the pill's end where it now is, instead of where it was when it set off: it ended inside the pill, over its last item, with a doubled shadow at its end
63
77
  - With electrons or actions out, a pill changing placement goes there through the circle in one movement, from and to any placement: it used to jump across the screen as it closed (to or from the top and bottom, the start and end placements, between the bottom and a side), laid out for its new placement while still at its old one. Next to another pill of the same side, it no longer flashes aside as it sets off
78
+ - A satellite going into the pill (or coming out of it) does so inside the pill: the page's actions standing upright beside it went in level with their own middle, above the pill, by the electron, and came out there too
79
+ - **Beta:** leaving a page, its actions go into the pill at once, with the electrons, at their size until they're in: they stood still while an electron went in, turned into a circle in one frame, and only then went in
80
+ - **Beta:** a satellite told to go back in while it's still coming out goes in from where it's drawn: the page's actions, switched into the pill as they came out, went in as a dot off to the side of the pill, showing where they had waited
81
+ - **Beta:** the page's actions opening in the pill: the pill re-centres in step with them, so its far end (and an electron beside it) moves once, by the difference. Its slide ran ahead of its growth: its far end went 25 px in, then back
82
+ - **Beta:** the page's actions in the pill resize their row for another list (two, then four), the pill and the satellites following, and a shorter list shrinks over the ones leaving before they go, as their own pill does: it changed in one frame
83
+ - **Beta:** the page's actions going to the other side of the pill with another list go into the pill at the size they had, and come out on the other side at their new size: they took the new size at once where they were, over the pill
84
+ - **Beta:** the page's actions turning from a column to a row slide to their spot from the circle they closed to: once a circle, they went back up to the column's top and slid down again
85
+ - **Beta:** a panel opening with no room for the electrons beside it waits for them to go into the pill, then opens to its full length in one motion: it opened part way as they went in, then widened again once they were in
86
+ - A panel closing gives the focus back to its trigger before the pill measures the size it closes to, so it closes in one motion with the label the focus opens: it closed without it, then grew again as the label opened (an electron beside it went in, then out again)
87
+ - A form in the pill itself, short of room, gives its submit button's live label ("Adding you…") the room while it's sent, and the field takes it back once it's done or refused, in one resize each way: the label was folded and cut, then squeezed as it opened
64
88
 
65
89
  ### Changed
66
90
  - **Beta:** `actionsWheel` is on by default for the page's actions in the pill (`actionsStyle="inside"`): short of room, they show what fits next to the navbar and turn the rest in their wheel; `false` shows them all. Still off by default for a pill of their own
@@ -260,6 +260,7 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
260
260
  vertical: isVertical,
261
261
  pathname,
262
262
  notifying: target.kind === "notification" || displayed.scene.kind === "notification" || hasBase && !require_choreography.isOpen(displayed.presence),
263
+ panel: displayed.presence === "panel",
263
264
  linkComponent,
264
265
  variant,
265
266
  theme: rest.theme,
@@ -260,6 +260,7 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
260
260
  vertical: isVertical,
261
261
  pathname,
262
262
  notifying: target.kind === "notification" || displayed.scene.kind === "notification" || hasBase && !isOpen(displayed.presence),
263
+ panel: displayed.presence === "panel",
263
264
  linkComponent,
264
265
  variant,
265
266
  theme: rest.theme,
@@ -21,15 +21,19 @@ const PillPanel = (0, react.forwardRef)(function PillPanel({ name, title, titleA
21
21
  const panelRef = (0, react.useRef)(null);
22
22
  const ref = (0, react.useMemo)(() => require_react.mergeRefs(panelRef, forwardedRef), [forwardedRef]);
23
23
  const wasOpenRef = (0, react.useRef)(isOpen);
24
+ const wasShownRef = (0, react.useRef)(isOpen);
24
25
  (0, react.useEffect)(require_inputModality.trackInputModality, []);
25
26
  (0, react.useEffect)(() => {
26
27
  const wasOpen = wasOpenRef.current;
27
28
  wasOpenRef.current = isOpen;
28
29
  if (isOpen && !wasOpen) panelRef.current?.focus({ preventScroll: true });
29
- else if (!isOpen && wasOpen) {
30
- const active = document.activeElement;
31
- if (!active || active === document.body || rootRef.current?.contains(active)) panelTriggerRef.current?.focus(require_inputModality.getInputModality() === "pointer" ? { focusVisible: false } : void 0);
32
- }
30
+ }, [isOpen]);
31
+ require_react.useIsomorphicLayoutEffect(() => {
32
+ const wasShown = wasShownRef.current;
33
+ wasShownRef.current = isOpen;
34
+ if (isOpen || !wasShown) return;
35
+ const active = document.activeElement;
36
+ if (!active || active === document.body || rootRef.current?.contains(active)) panelTriggerRef.current?.focus(require_inputModality.getInputModality() === "pointer" ? { focusVisible: false } : void 0);
33
37
  }, [
34
38
  isOpen,
35
39
  panelTriggerRef,
@@ -5,7 +5,7 @@ import PillAction from "./PillAction.mjs";
5
5
  import { useInternalPill } from "./PillContext.mjs";
6
6
  import CloseIcon from "../icons/CloseIcon.mjs";
7
7
  import { getInputModality, trackInputModality } from "../utils/inputModality.mjs";
8
- import { mergeRefs } from "../utils/react.mjs";
8
+ import { mergeRefs, useIsomorphicLayoutEffect } from "../utils/react.mjs";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
10
 
11
11
  // src/Pill/PillPanel.tsx
@@ -21,15 +21,19 @@ const PillPanel = forwardRef(function PillPanel({ name, title, titleAction, foot
21
21
  const panelRef = useRef(null);
22
22
  const ref = useMemo(() => mergeRefs(panelRef, forwardedRef), [forwardedRef]);
23
23
  const wasOpenRef = useRef(isOpen);
24
+ const wasShownRef = useRef(isOpen);
24
25
  useEffect(trackInputModality, []);
25
26
  useEffect(() => {
26
27
  const wasOpen = wasOpenRef.current;
27
28
  wasOpenRef.current = isOpen;
28
29
  if (isOpen && !wasOpen) panelRef.current?.focus({ preventScroll: true });
29
- else if (!isOpen && wasOpen) {
30
- const active = document.activeElement;
31
- if (!active || active === document.body || rootRef.current?.contains(active)) panelTriggerRef.current?.focus(getInputModality() === "pointer" ? { focusVisible: false } : void 0);
32
- }
30
+ }, [isOpen]);
31
+ useIsomorphicLayoutEffect(() => {
32
+ const wasShown = wasShownRef.current;
33
+ wasShownRef.current = isOpen;
34
+ if (isOpen || !wasShown) return;
35
+ const active = document.activeElement;
36
+ if (!active || active === document.body || rootRef.current?.contains(active)) panelTriggerRef.current?.focus(getInputModality() === "pointer" ? { focusVisible: false } : void 0);
33
37
  }, [
34
38
  isOpen,
35
39
  panelTriggerRef,
package/dist/Pill/goo.js CHANGED
@@ -64,18 +64,23 @@ function tuckedOffset(anchor, moving, start = 1) {
64
64
  if (!fits(moving.width, anchor.width)) scale = Math.min(scale, anchor.width / moving.width);
65
65
  if (!fits(moving.height, anchor.height)) scale = Math.min(scale, anchor.height / moving.height);
66
66
  scale = Math.max(.1, scale);
67
- if (Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2)) {
67
+ const sideways = Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2);
68
+ const within = (centre, start, room, size) => size >= room ? start + room / 2 : Math.min(Math.max(centre, start + size / 2), start + room - size / 2);
69
+ if (sideways) {
68
70
  const sign = Math.sign(dx) || 1;
71
+ const edge = anchorX + sign * anchor.width / 2;
72
+ const y = within(movingY, anchor.top, anchor.height, moving.height * scale) - movingY;
69
73
  return {
70
- x: anchorX + sign * anchor.width / 2 - sign * moving.width * scale / 2 - movingX,
71
- y: 0,
74
+ x: edge - sign * moving.width * scale / 2 - movingX,
75
+ y,
72
76
  scale
73
77
  };
74
78
  }
75
79
  const sign = Math.sign(dy) || 1;
80
+ const edge = anchorY + sign * anchor.height / 2;
76
81
  return {
77
- x: 0,
78
- y: anchorY + sign * anchor.height / 2 - sign * moving.height * scale / 2 - movingY,
82
+ x: within(movingX, anchor.left, anchor.width, moving.width * scale) - movingX,
83
+ y: edge - sign * moving.height * scale / 2 - movingY,
79
84
  scale
80
85
  };
81
86
  }
@@ -208,14 +213,20 @@ function placeAll(overlay, pills, radii, margin) {
208
213
  root.transform = `translate(${left}px, ${top}px)`;
209
214
  root.width = `${right - left}px`;
210
215
  root.height = `${bottom - top}px`;
211
- const put = (shape, rect, element, radius) => {
216
+ const put = (shape, rect, element, radius, cut = false) => {
212
217
  const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
213
- shape.style.width = `${rect.width}px`;
214
- shape.style.height = `${rect.height}px`;
215
- shape.style.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
216
- shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
218
+ const corner = Math.min(radius * scale, rect.width / 2, rect.height / 2);
219
+ const spare = cut ? margin + corner : Number.POSITIVE_INFINITY;
220
+ const x = Math.max(rect.left, left - spare);
221
+ const y = Math.max(rect.top, top - spare);
222
+ const width = Math.max(0, Math.min(rect.right, right + spare) - x);
223
+ const height = Math.max(0, Math.min(rect.bottom, bottom + spare) - y);
224
+ shape.style.width = `${width}px`;
225
+ shape.style.height = `${height}px`;
226
+ shape.style.transform = `translate(${x - left}px, ${y - top}px)`;
227
+ shape.style.borderRadius = `${corner}px`;
217
228
  };
218
- put(overlay.anchor, a, pills.anchor, radii.anchor);
229
+ put(overlay.anchor, a, pills.anchor, radii.anchor, true);
219
230
  put(overlay.moving, m, pills.moving, radii.moving);
220
231
  }
221
232
  const OWN_LOOK = {
@@ -334,7 +345,11 @@ function playSplit(anchor, moving, kind, timing) {
334
345
  easing: POP
335
346
  });
336
347
  }
337
- const content = [...moving.children].filter((child) => !["panel", "outgoing"].includes(child.getAttribute("data-mp") ?? ""));
348
+ const circle = kind === "split" && ["rest", "hidden"].includes(moving.dataset.presence ?? "");
349
+ const content = [...moving.children].filter((child) => {
350
+ const part = child.getAttribute("data-mp") ?? "";
351
+ return !["panel", "outgoing"].includes(part) && (!circle || part === "icon");
352
+ });
338
353
  const total = timing.duration + fade;
339
354
  for (const child of content) if (kind === "split") child.animate([
340
355
  { opacity: 0 },
@@ -434,6 +449,16 @@ const budding = /* @__PURE__ */ new WeakMap();
434
449
  * electron out of its host or out of the one next to it, the page's actions.
435
450
  */
436
451
  function playOrbit(electron, items, kind, timing) {
452
+ const drawn = /* @__PURE__ */ new Map();
453
+ for (const { element } of items) {
454
+ if (kind !== "close" || !(element.getAnimations?.() ?? []).some((animation) => animation.id === "mp-split" && animation.playState === "running")) continue;
455
+ const now = getComputedStyle(element);
456
+ drawn.set(element, {
457
+ translate: !now.translate || now.translate === "none" ? "0px 0px" : now.translate,
458
+ scale: !now.scale || now.scale === "none" ? "1" : now.scale,
459
+ opacity: Number.parseFloat(now.opacity) || 0
460
+ });
461
+ }
437
462
  for (const { element } of items) {
438
463
  budding.get(element)?.();
439
464
  for (const animation of element.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
@@ -469,7 +494,8 @@ function playOrbit(electron, items, kind, timing) {
469
494
  scale: String(start.scale),
470
495
  opacity: opaque ? shown : 0
471
496
  };
472
- const out = {
497
+ const here = drawn.get(element);
498
+ const out = here ?? {
473
499
  translate: "0px 0px",
474
500
  scale: end === "none" ? "1" : end,
475
501
  opacity: shown
@@ -493,7 +519,7 @@ function playOrbit(electron, items, kind, timing) {
493
519
  id: SPLIT,
494
520
  duration: timing.duration,
495
521
  delay,
496
- fill: kind === "open" ? "backwards" : "forwards"
522
+ fill: kind === "open" ? "backwards" : "both"
497
523
  };
498
524
  const ends = (kind === "open" ? [inside, out] : [out, inside]).map(({ translate, scale }) => ({
499
525
  translate,
@@ -518,17 +544,20 @@ function playOrbit(electron, items, kind, timing) {
518
544
  ...options,
519
545
  easing: "linear"
520
546
  });
521
- else if (kind === "close") element.animate([
522
- { opacity: shown },
523
- {
524
- opacity: shown,
525
- offset: .85
526
- },
527
- { opacity: 0 }
528
- ], {
529
- ...options,
530
- easing: "linear"
531
- });
547
+ else if (kind === "close") {
548
+ const seen = here ? Math.min(here.opacity, shown) : shown;
549
+ element.animate([
550
+ { opacity: seen },
551
+ {
552
+ opacity: seen,
553
+ offset: .85
554
+ },
555
+ { opacity: 0 }
556
+ ], {
557
+ ...options,
558
+ easing: "linear"
559
+ });
560
+ }
532
561
  if (droplet) {
533
562
  const content = kind === "open" ? [
534
563
  { opacity: 0 },
@@ -628,6 +657,7 @@ function playNecks(pills, duration) {
628
657
  shape.height = `${rect.height}px`;
629
658
  shape.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
630
659
  shape.borderRadius = `${Math.min(radii[index] * scale, rect.width / 2, rect.height / 2)}px`;
660
+ shape.opacity = getComputedStyle(pills[index]).opacity;
631
661
  });
632
662
  blur.setAttribute("stdDeviation", (goo * gooAmount(Math.min(1, elapsed / longest))).toFixed(2));
633
663
  if (elapsed >= longest) return stop();
package/dist/Pill/goo.mjs CHANGED
@@ -64,18 +64,23 @@ function tuckedOffset(anchor, moving, start = 1) {
64
64
  if (!fits(moving.width, anchor.width)) scale = Math.min(scale, anchor.width / moving.width);
65
65
  if (!fits(moving.height, anchor.height)) scale = Math.min(scale, anchor.height / moving.height);
66
66
  scale = Math.max(.1, scale);
67
- if (Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2)) {
67
+ const sideways = Math.abs(dx) / (anchor.width / 2 + moving.width / 2) >= Math.abs(dy) / (anchor.height / 2 + moving.height / 2);
68
+ const within = (centre, start, room, size) => size >= room ? start + room / 2 : Math.min(Math.max(centre, start + size / 2), start + room - size / 2);
69
+ if (sideways) {
68
70
  const sign = Math.sign(dx) || 1;
71
+ const edge = anchorX + sign * anchor.width / 2;
72
+ const y = within(movingY, anchor.top, anchor.height, moving.height * scale) - movingY;
69
73
  return {
70
- x: anchorX + sign * anchor.width / 2 - sign * moving.width * scale / 2 - movingX,
71
- y: 0,
74
+ x: edge - sign * moving.width * scale / 2 - movingX,
75
+ y,
72
76
  scale
73
77
  };
74
78
  }
75
79
  const sign = Math.sign(dy) || 1;
80
+ const edge = anchorY + sign * anchor.height / 2;
76
81
  return {
77
- x: 0,
78
- y: anchorY + sign * anchor.height / 2 - sign * moving.height * scale / 2 - movingY,
82
+ x: within(movingX, anchor.left, anchor.width, moving.width * scale) - movingX,
83
+ y: edge - sign * moving.height * scale / 2 - movingY,
79
84
  scale
80
85
  };
81
86
  }
@@ -208,14 +213,20 @@ function placeAll(overlay, pills, radii, margin) {
208
213
  root.transform = `translate(${left}px, ${top}px)`;
209
214
  root.width = `${right - left}px`;
210
215
  root.height = `${bottom - top}px`;
211
- const put = (shape, rect, element, radius) => {
216
+ const put = (shape, rect, element, radius, cut = false) => {
212
217
  const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
213
- shape.style.width = `${rect.width}px`;
214
- shape.style.height = `${rect.height}px`;
215
- shape.style.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
216
- shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
218
+ const corner = Math.min(radius * scale, rect.width / 2, rect.height / 2);
219
+ const spare = cut ? margin + corner : Number.POSITIVE_INFINITY;
220
+ const x = Math.max(rect.left, left - spare);
221
+ const y = Math.max(rect.top, top - spare);
222
+ const width = Math.max(0, Math.min(rect.right, right + spare) - x);
223
+ const height = Math.max(0, Math.min(rect.bottom, bottom + spare) - y);
224
+ shape.style.width = `${width}px`;
225
+ shape.style.height = `${height}px`;
226
+ shape.style.transform = `translate(${x - left}px, ${y - top}px)`;
227
+ shape.style.borderRadius = `${corner}px`;
217
228
  };
218
- put(overlay.anchor, a, pills.anchor, radii.anchor);
229
+ put(overlay.anchor, a, pills.anchor, radii.anchor, true);
219
230
  put(overlay.moving, m, pills.moving, radii.moving);
220
231
  }
221
232
  const OWN_LOOK = {
@@ -334,7 +345,11 @@ function playSplit(anchor, moving, kind, timing) {
334
345
  easing: POP
335
346
  });
336
347
  }
337
- const content = [...moving.children].filter((child) => !["panel", "outgoing"].includes(child.getAttribute("data-mp") ?? ""));
348
+ const circle = kind === "split" && ["rest", "hidden"].includes(moving.dataset.presence ?? "");
349
+ const content = [...moving.children].filter((child) => {
350
+ const part = child.getAttribute("data-mp") ?? "";
351
+ return !["panel", "outgoing"].includes(part) && (!circle || part === "icon");
352
+ });
338
353
  const total = timing.duration + fade;
339
354
  for (const child of content) if (kind === "split") child.animate([
340
355
  { opacity: 0 },
@@ -434,6 +449,16 @@ const budding = /* @__PURE__ */ new WeakMap();
434
449
  * electron out of its host or out of the one next to it, the page's actions.
435
450
  */
436
451
  function playOrbit(electron, items, kind, timing) {
452
+ const drawn = /* @__PURE__ */ new Map();
453
+ for (const { element } of items) {
454
+ if (kind !== "close" || !(element.getAnimations?.() ?? []).some((animation) => animation.id === "mp-split" && animation.playState === "running")) continue;
455
+ const now = getComputedStyle(element);
456
+ drawn.set(element, {
457
+ translate: !now.translate || now.translate === "none" ? "0px 0px" : now.translate,
458
+ scale: !now.scale || now.scale === "none" ? "1" : now.scale,
459
+ opacity: Number.parseFloat(now.opacity) || 0
460
+ });
461
+ }
437
462
  for (const { element } of items) {
438
463
  budding.get(element)?.();
439
464
  for (const animation of element.getAnimations?.({ subtree: true }) ?? []) if (animation.id === "mp-split") animation.cancel();
@@ -469,7 +494,8 @@ function playOrbit(electron, items, kind, timing) {
469
494
  scale: String(start.scale),
470
495
  opacity: opaque ? shown : 0
471
496
  };
472
- const out = {
497
+ const here = drawn.get(element);
498
+ const out = here ?? {
473
499
  translate: "0px 0px",
474
500
  scale: end === "none" ? "1" : end,
475
501
  opacity: shown
@@ -493,7 +519,7 @@ function playOrbit(electron, items, kind, timing) {
493
519
  id: SPLIT,
494
520
  duration: timing.duration,
495
521
  delay,
496
- fill: kind === "open" ? "backwards" : "forwards"
522
+ fill: kind === "open" ? "backwards" : "both"
497
523
  };
498
524
  const ends = (kind === "open" ? [inside, out] : [out, inside]).map(({ translate, scale }) => ({
499
525
  translate,
@@ -518,17 +544,20 @@ function playOrbit(electron, items, kind, timing) {
518
544
  ...options,
519
545
  easing: "linear"
520
546
  });
521
- else if (kind === "close") element.animate([
522
- { opacity: shown },
523
- {
524
- opacity: shown,
525
- offset: .85
526
- },
527
- { opacity: 0 }
528
- ], {
529
- ...options,
530
- easing: "linear"
531
- });
547
+ else if (kind === "close") {
548
+ const seen = here ? Math.min(here.opacity, shown) : shown;
549
+ element.animate([
550
+ { opacity: seen },
551
+ {
552
+ opacity: seen,
553
+ offset: .85
554
+ },
555
+ { opacity: 0 }
556
+ ], {
557
+ ...options,
558
+ easing: "linear"
559
+ });
560
+ }
532
561
  if (droplet) {
533
562
  const content = kind === "open" ? [
534
563
  { opacity: 0 },
@@ -628,6 +657,7 @@ function playNecks(pills, duration) {
628
657
  shape.height = `${rect.height}px`;
629
658
  shape.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
630
659
  shape.borderRadius = `${Math.min(radii[index] * scale, rect.width / 2, rect.height / 2)}px`;
660
+ shape.opacity = getComputedStyle(pills[index]).opacity;
631
661
  });
632
662
  blur.setAttribute("stdDeviation", (goo * gooAmount(Math.min(1, elapsed / longest))).toFixed(2));
633
663
  if (elapsed >= longest) return stop();
@@ -440,6 +440,44 @@ function readPanel(pill) {
440
440
  };
441
441
  }
442
442
  /**
443
+ * A panel opening, held at its start (`holdOpening`) while what makes room for it moves out of the
444
+ * way (an electron going into the pill, magic-pill/satellites), then played again (`replayOpening`)
445
+ * to the size it has once that room is free: one motion. It opened part way as the electron went
446
+ * in, then widened again once it was in (A36).
447
+ */
448
+ function holdOpening(element) {
449
+ let held = false;
450
+ for (const animation of element.getAnimations?.({ subtree: true }) ?? []) {
451
+ if (animation.id !== "mp-morph") continue;
452
+ animation.pause();
453
+ animation.currentTime = 0;
454
+ held = true;
455
+ }
456
+ return held;
457
+ }
458
+ /** The opening `holdOpening` held, from where it's held to the pill's size now. Whether one was held. */
459
+ function replayOpening(element) {
460
+ if ((element.getAnimations?.({ subtree: true }) ?? []).filter((animation) => animation.id === "mp-morph" && animation.playState === "paused").length === 0) return false;
461
+ const from = readSize(element);
462
+ cancel(element, MORPH, true);
463
+ if (require_timing.prefersReducedMotion()) return true;
464
+ const to = readSettledSize(element);
465
+ const panel = readPanel(element);
466
+ const plan = planMorph(from, to, "compact", "panel", readMorphTimings(element), panel?.box);
467
+ if (!plan) return true;
468
+ const options = {
469
+ ...plan.options,
470
+ id: MORPH
471
+ };
472
+ element.animate(plan.pill, options);
473
+ if (plan.panel && panel) {
474
+ panel.element.animate(plan.panel, options);
475
+ const footer = panel.element.querySelector("[data-mp=\"panel-footer\"]");
476
+ if (footer) footer.animate([{ position: "relative" }, { position: "relative" }], options);
477
+ }
478
+ return true;
479
+ }
480
+ /**
443
481
  * Animates the pill's size on each presence change. Off for `unstyled` pills,
444
482
  * with reduced motion, and where the Web Animations API is missing.
445
483
  */
@@ -627,10 +665,12 @@ exports.PlacementWatch = PlacementWatch;
627
665
  exports.animateMove = animateMove;
628
666
  exports.cancel = cancel;
629
667
  exports.captureSwap = captureSwap;
668
+ exports.holdOpening = holdOpening;
630
669
  exports.onCopy = onCopy;
631
670
  exports.planExit = planExit;
632
671
  exports.planMorph = planMorph;
633
672
  exports.planSwap = planSwap;
634
673
  exports.playSwap = playSwap;
635
674
  exports.readMorphTimings = readMorphTimings;
675
+ exports.replayOpening = replayOpening;
636
676
  exports.useSizeMorph = useSizeMorph;
@@ -440,6 +440,44 @@ function readPanel(pill) {
440
440
  };
441
441
  }
442
442
  /**
443
+ * A panel opening, held at its start (`holdOpening`) while what makes room for it moves out of the
444
+ * way (an electron going into the pill, magic-pill/satellites), then played again (`replayOpening`)
445
+ * to the size it has once that room is free: one motion. It opened part way as the electron went
446
+ * in, then widened again once it was in (A36).
447
+ */
448
+ function holdOpening(element) {
449
+ let held = false;
450
+ for (const animation of element.getAnimations?.({ subtree: true }) ?? []) {
451
+ if (animation.id !== "mp-morph") continue;
452
+ animation.pause();
453
+ animation.currentTime = 0;
454
+ held = true;
455
+ }
456
+ return held;
457
+ }
458
+ /** The opening `holdOpening` held, from where it's held to the pill's size now. Whether one was held. */
459
+ function replayOpening(element) {
460
+ if ((element.getAnimations?.({ subtree: true }) ?? []).filter((animation) => animation.id === "mp-morph" && animation.playState === "paused").length === 0) return false;
461
+ const from = readSize(element);
462
+ cancel(element, MORPH, true);
463
+ if (prefersReducedMotion()) return true;
464
+ const to = readSettledSize(element);
465
+ const panel = readPanel(element);
466
+ const plan = planMorph(from, to, "compact", "panel", readMorphTimings(element), panel?.box);
467
+ if (!plan) return true;
468
+ const options = {
469
+ ...plan.options,
470
+ id: MORPH
471
+ };
472
+ element.animate(plan.pill, options);
473
+ if (plan.panel && panel) {
474
+ panel.element.animate(plan.panel, options);
475
+ const footer = panel.element.querySelector("[data-mp=\"panel-footer\"]");
476
+ if (footer) footer.animate([{ position: "relative" }, { position: "relative" }], options);
477
+ }
478
+ return true;
479
+ }
480
+ /**
443
481
  * Animates the pill's size on each presence change. Off for `unstyled` pills,
444
482
  * with reduced motion, and where the Web Animations API is missing.
445
483
  */
@@ -618,4 +656,4 @@ var PlacementWatch = class extends Component {
618
656
  }
619
657
  };
620
658
 
621
- export { EASING, EXIT, ExitWatch, MORPH, MOVE, PlacementWatch, animateMove, cancel, captureSwap, onCopy, planExit, planMorph, planSwap, playSwap, readMorphTimings, useSizeMorph };
659
+ export { EASING, EXIT, ExitWatch, MORPH, MOVE, PlacementWatch, animateMove, cancel, captureSwap, holdOpening, onCopy, planExit, planMorph, planSwap, playSwap, readMorphTimings, replayOpening, useSizeMorph };
@@ -37,13 +37,14 @@ function useLabelMorph(buttonRef, label) {
37
37
  const text = buttonRef.current?.querySelector("[data-mp=\"label\"] > span");
38
38
  if (!text) return;
39
39
  text.getAnimations?.().forEach((animation) => animation.cancel());
40
- const width = text.offsetWidth;
40
+ const width = text.scrollWidth;
41
41
  const from = previous.current;
42
42
  previous.current = {
43
43
  label,
44
44
  width
45
45
  };
46
46
  if (!from || from.label === label || !from.width || !text.animate || require_timing.prefersReducedMotion()) return;
47
+ if (text.parentElement && getComputedStyle(text.parentElement).opacity !== "1") return;
47
48
  text.animate([{
48
49
  width: `${from.width}px`,
49
50
  opacity: 0,
@@ -37,13 +37,14 @@ function useLabelMorph(buttonRef, label) {
37
37
  const text = buttonRef.current?.querySelector("[data-mp=\"label\"] > span");
38
38
  if (!text) return;
39
39
  text.getAnimations?.().forEach((animation) => animation.cancel());
40
- const width = text.offsetWidth;
40
+ const width = text.scrollWidth;
41
41
  const from = previous.current;
42
42
  previous.current = {
43
43
  label,
44
44
  width
45
45
  };
46
46
  if (!from || from.label === label || !from.width || !text.animate || prefersReducedMotion()) return;
47
+ if (text.parentElement && getComputedStyle(text.parentElement).opacity !== "1") return;
47
48
  text.animate([{
48
49
  width: `${from.width}px`,
49
50
  opacity: 0,
@@ -15,6 +15,7 @@ function useFormRoom(formRef) {
15
15
  const field = form.querySelector("[data-mp=\"field\"]");
16
16
  const submit = form.querySelector("[data-mp=\"action\"][type=\"submit\"][data-expanded]");
17
17
  if (!field || !submit) return form.removeAttribute("data-tight");
18
+ if (form.getAttribute("aria-busy") === "true") return;
18
19
  const least = LEAST * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
19
20
  const max = Number.parseFloat(getComputedStyle(pill).maxInlineSize);
20
21
  let room = Number.isFinite(max) ? max - pill.offsetWidth : Number.POSITIVE_INFINITY;
@@ -15,6 +15,7 @@ function useFormRoom(formRef) {
15
15
  const field = form.querySelector("[data-mp=\"field\"]");
16
16
  const submit = form.querySelector("[data-mp=\"action\"][type=\"submit\"][data-expanded]");
17
17
  if (!field || !submit) return form.removeAttribute("data-tight");
18
+ if (form.getAttribute("aria-busy") === "true") return;
18
19
  const least = LEAST * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
19
20
  const max = Number.parseFloat(getComputedStyle(pill).maxInlineSize);
20
21
  let room = Number.isFinite(max) ? max - pill.offsetWidth : Number.POSITIVE_INFINITY;
@@ -81,7 +81,8 @@ function unfoldedWidth(pill) {
81
81
  if (!navbar || navbar.dataset.labels !== "auto") return void 0;
82
82
  const { copy } = layOutCopy(pill, (copied) => copied.removeAttribute("data-folded"), true);
83
83
  const style = getComputedStyle(copy);
84
- const width = Math.max(copy.offsetWidth, copy.scrollWidth + (Number.parseFloat(style.paddingRight) || 0));
84
+ const overflows = copy.scrollWidth > copy.clientWidth + .5;
85
+ const width = Math.max(copy.offsetWidth, overflows ? copy.scrollWidth + (Number.parseFloat(style.paddingRight) || 0) : 0);
85
86
  copy.remove();
86
87
  return width;
87
88
  }
@@ -81,7 +81,8 @@ function unfoldedWidth(pill) {
81
81
  if (!navbar || navbar.dataset.labels !== "auto") return void 0;
82
82
  const { copy } = layOutCopy(pill, (copied) => copied.removeAttribute("data-folded"), true);
83
83
  const style = getComputedStyle(copy);
84
- const width = Math.max(copy.offsetWidth, copy.scrollWidth + (Number.parseFloat(style.paddingRight) || 0));
84
+ const overflows = copy.scrollWidth > copy.clientWidth + .5;
85
+ const width = Math.max(copy.offsetWidth, overflows ? copy.scrollWidth + (Number.parseFloat(style.paddingRight) || 0) : 0);
85
86
  copy.remove();
86
87
  return width;
87
88
  }
@@ -41,7 +41,7 @@ function measure(body) {
41
41
  const parts = [...actions.children].map((child) => child.getBoundingClientRect());
42
42
  if (parts.length > 0) {
43
43
  const content = Math.max(...parts.map((part) => part.right)) - Math.min(...parts.map((part) => part.left));
44
- result.body = Math.ceil(Math.max(message.offsetWidth, content - under));
44
+ result.body = Math.ceil(Math.max(message.getBoundingClientRect().width, content - under));
45
45
  }
46
46
  return result;
47
47
  }, open);
@@ -41,7 +41,7 @@ function measure(body) {
41
41
  const parts = [...actions.children].map((child) => child.getBoundingClientRect());
42
42
  if (parts.length > 0) {
43
43
  const content = Math.max(...parts.map((part) => part.right)) - Math.min(...parts.map((part) => part.left));
44
- result.body = Math.ceil(Math.max(message.offsetWidth, content - under));
44
+ result.body = Math.ceil(Math.max(message.getBoundingClientRect().width, content - under));
45
45
  }
46
46
  return result;
47
47
  }, open);
package/dist/forms.css CHANGED
@@ -246,9 +246,23 @@
246
246
  inline-size: 15rem;
247
247
  }
248
248
 
249
+ /* Its label isn't cut short: the field gives the room (B16: squeezed
250
+ with it, the live label shrank as it opened, then jumped) */
251
+ & [data-mp="action"][type="submit"] {
252
+ flex-shrink: 0;
253
+ }
254
+
255
+ /* Being sent, it can give it all: what it holds goes with it, rather
256
+ than showing past its edge (it's read-only meanwhile) */
257
+ &[aria-busy="true"] [data-mp="field"] {
258
+ overflow: clip;
259
+ }
260
+
249
261
  /* Short of room (PillForm/room.ts): the button folds its label, still
250
- its name; the field keeps room to type in */
251
- &[data-tight] [data-mp="action"][type="submit"][data-expanded]:not(:focus-visible) {
262
+ its name; the field keeps room to type in. Not while it's being sent:
263
+ its live label ("Adding you…") says what's happening then, and the
264
+ field, read-only, yields it the room (B16) */
265
+ &[data-tight]:not([aria-busy="true"]) [data-mp="action"][type="submit"][data-expanded]:not(:focus-visible) {
252
266
  & [data-mp="action-body"] {
253
267
  padding-inline-end: calc((var(--_mp-action-size) - 1.25rem) / 2);
254
268
  }