magic-pill 9.1.0 → 9.2.0

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
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [9.2.0] - 2026-11-26
6
+ Placement changes through the circle, and new layouts for notifications: in rows on any host, and as cards or flags in a sidebar. One default changes: a pill whose placement changes now closes to a circle, travels, and opens at its new place; `moveThroughCircle={false}` keeps the old travel at full size. Nothing else to change in your code.
7
+
8
+ ### Added
9
+ - `moveThroughCircle` on `<Pill>` and `<MagicPill>` (default `true`), see Changed
10
+ - Notifications in rows: `notificationLayout="rows"` on `<MagicPill>`, `layout: "rows"` on a notification (it wins over the host's), or `layout="rows"` on `<PillNotification>`. The actions go under the message when they need the room (the message wraps, or there's an action and a panel's trigger), lined up with it; one action beside a short message stays on its line. On every host. A sidebar slides to and from a notification in rows with `swap="always"`, turning as it goes
11
+ - Notifications as cards, in a sidebar: `notificationLayout="card"` or `layout: "card"`. A column of the sidebar's width, at least `--mp-card-width` (`12.5rem`): the icon on top, the divider across, the message centred, the actions full width with their labels. The sidebar stays vertical, through the circle, or sliding with `swap="always"`. A horizontal host shows it in one row
12
+ - A sidebar's flag: `notificationLayout="flag"` or `layout: "flag"`, on a `left` or `right` host with a base layer. The sidebar stays, usable, and the notification comes out of its edge as a pill of its own (`data-layout="flag"`), next to the navbar item it's about (`at`, its `href`) or in the middle. It pauses while pointed at or focused, slides to the next one and moves to its section, and opens its panel beside the sidebar. Its motion, a pop out of the sidebar with a short bridge while they part, will follow the Electron's once it's designed. Elsewhere, a flag shows in the pill itself
13
+ - Navbar links carry `data-href`, their item's `href` as given (the rendered one may carry the app's base path)
14
+
15
+ ### Changed
16
+ - A pill whose placement (or orientation) changes goes there through the circle: it closes to a circle where it is, the circle travels, and it opens at its new place, instead of travelling at full size while its content is laid out for the new place. Nothing jumps, even from the bottom of the screen to a side, where it turns vertical inside the circle. `moveThroughCircle={false}` travels at full size as before; with reduced motion it still changes place at once
17
+ - A sidebar host (`placement="left"` or `"right"`) shows its notifications as horizontal pills, like any other host: it turns horizontal while it's a circle, and back once they're gone. Between its base layer and a notification, it goes through the circle even with `swap="always"`, unless the notification is in rows or a card
18
+
19
+ ### Fixed
20
+ - A vertical pill at rest is a circle: it kept the width of its hidden content (an oval as wide as the sidebar's labels)
21
+ - A pill that hides plays its whole exit on iOS: when the page scrolled and Safari's toolbar folded away at the same time, the viewport's change restyled the page and cut the exit's transitions short, so the pill vanished at once. The exit (the content fading, the scale and the visibility) is now played by script on top of the stylesheet, with the same timings; a pill asked back mid-way grows back from where it was, as before
22
+ - Form fields draw their focus ring for the keyboard only: browsers matched `:focus-visible` on text fields, lists, steppers and code fields even after a click or a tap. A field focused with a pointer now gets `data-pointer-focus`, and `forms.css` leaves it without a ring (the caret shows where typing goes). Tabbing to a field still draws it. An app's own global `:focus-visible` outline no longer shows on the bare controls either (text fields, the stepper's value, a list's options): browsers drew it after a click, and with the keyboard it doubled the field's ring
23
+
24
+ ## [9.1.1] - 2026-11-26
25
+ A fix for Next.js apps. Nothing to change in your code.
26
+
27
+ ### Fixed
28
+ - `magic-pill/forms.css` builds with Next.js's Turbopack (and anything else that uses Lightning CSS): 9.1.0 failed the whole build with "Invalid pseudo class after pseudo element". The open list's rule now reads `select:open::picker(select)`, with the same effect, and a test keeps every stylesheet clear of it
29
+
5
30
  ## [9.1.0] - 2026-11-25
6
31
  Themes (frosted glass, Liquid Glass, yours), forms and a calendar, scenes, and pills that make room for each other. Nothing to change in your code: forms, themes and the calendar are optional, each with its own stylesheet.
7
32
 
package/README.md CHANGED
@@ -117,6 +117,8 @@ const id = pill().notify({
117
117
  | `panel` | `{ title?, titleAction?, content, footer?, trigger?, closeLabel?, closeExpanded? }` | A "Learn more" action that grows the pill into a panel. `trigger` defaults to `{ icon: <PlusIcon />, label: "Learn more" }` and takes `expanded` too, `closeLabel` to `"Close"`: like the other labels, it shows on hover and focus, or all the time with `closeExpanded`. `titleAction` and `footer`: see [the panel](#the-primitive). |
118
118
  | `variant` | `"neutral"` · `"success"` · `"danger"` · any string | Defaults to the host's variant. |
119
119
  | `duration` | `number` (ms) | Defaults to the host's (5000). `Infinity` keeps it until dismissed. |
120
+ | `layout` | `"pill"` · `"rows"` · `"card"` · `"flag"` | Defaults to the host's `notificationLayout`. `"rows"` puts the actions under the message when they need the room: when the message wraps, or with an action and a panel. Under it, they line up with the message. `"card"`, in a sidebar: a column of the sidebar's width (at least `--mp-card-width`, `12.5rem`), the icon on top, the actions full width with their labels; a horizontal host shows it in one row. `"flag"`, in a `left` or `right` sidebar with a base layer: a pill of its own out of the sidebar's edge, while the sidebar stays (see below). |
121
+ | `at` | `string` | `"flag"` only: the `href` of the navbar item it's about, to come out next to it (matched as the navbar matches the current page). Default: the middle of the sidebar. |
120
122
  | `id` | `string` | Notifying again with the same id updates the notification in place. |
121
123
  | `announce` | `string` · `false` | What screen readers hear. Defaults to the message's text. |
122
124
  | `onDismiss` | `(id, reason) => void` | `reason` is `"timeout"`, `"action"`, `"dismissed"` or `"cleared"`. |
@@ -182,6 +184,7 @@ pill().notify({
182
184
  | `duration` | `5000` | Default display time for notifications. |
183
185
  | `idle` | `"hidden"` | With no base layer and nothing queued: `"hidden"`, or `"rest"` for a small resting circle showing `idleIcon`. |
184
186
  | `idleIcon` | none | The icon of the resting circle. |
187
+ | `notificationLayout` | `"pill"` | How notifications are laid out: in one row, `"rows"` (the actions under the message when they need the room), or, in a sidebar, `"card"` or `"flag"` (see `layout` above). A notification's own `layout` wins. |
185
188
  | `swap` | `"queue"` | Where new content slides into the open pill (out through the top, in from the bottom, the other way round for a top pill) instead of closing it to a circle and growing back: `"queue"` between notifications, `"always"` also between the base layer and notifications, `"never"` nowhere. |
186
189
  | `linkComponent` | `<a>` | Renders notification actions that have an `href`, e.g. Next's `Link`. |
187
190
  | `classNames` | none | Classes for the notification's parts: `icon`, `divider`, `message`, `actions`, `action`, `panel`. |
@@ -260,6 +263,9 @@ Give each host a name, and target it with `pill(name)`:
260
263
  pill("sidebar").notify({ message: "3 new posts" });
261
264
  pill("assistant").notify({ icon: <HelpIcon />, message: "Need a hand?", duration: Infinity });
262
265
  ```
266
+ A sidebar's notifications are pills like the others: it turns horizontal for them while it's a circle, and back once they're gone. Between its base layer and a notification it goes through the circle, even with `swap="always"`, unless the notification is in `rows` (it slides, turning as it goes) or a `card`: a card stays in the sidebar's column, and slides like any other content.
267
+
268
+ **A flag** (`notificationLayout="flag"`, `left`/`right` sidebars) leaves the sidebar where it is, usable: the notification comes out of its edge as a pill of its own (`[data-layout="flag"]`), next to the section it's about (`at`), and goes back into it. Pointing at it or focusing it pauses it; the next one slides in it, and it moves to its own section. Its panel opens beside the sidebar, in the middle of the screen. Its motion (a pop out of the sidebar, with a short bridge while they part) will follow the Electron's once it's designed.
263
269
 
264
270
  ## The primitive
265
271
  Everything above is built from `<Pill>` and its parts, and you can use them directly. A `<Pill>` you write yourself isn't connected to `pill()`: you control it with props.
@@ -279,11 +285,12 @@ import { Pill, PillActions, PillAction, PhoneIcon, MailIcon, DocumentIcon } from
279
285
 
280
286
  | `<Pill>` prop | Values | Default |
281
287
  |---|---|---|
282
- | `placement` | `"inline"` (in the page flow), `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-start"`, `"top-end"`, `"bottom-start"`, `"bottom-end"` (fixed; `start`/`end` follow the text direction), `"overlay"` (a modal `<dialog>`). Change it and the pill travels to its new place (e.g. with the scroll, or for a guided tour), except to or from `"overlay"`. | `"inline"` |
288
+ | `placement` | `"inline"` (in the page flow), `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-start"`, `"top-end"`, `"bottom-start"`, `"bottom-end"` (fixed; `start`/`end` follow the text direction), `"overlay"` (a modal `<dialog>`). Change it and the pill travels to its new place (e.g. with the scroll, or for a guided tour), through the circle (see `moveThroughCircle`), except to or from `"overlay"`. | `"inline"` |
283
289
  | `presence` / `defaultPresence` / `onPresenceChange` | `"hidden"`, `"rest"` (a circle with the icon only), `"compact"`, `"expanded"` (every action label shown), `"panel"` | `"compact"` |
284
290
  | `closeOnBackdropClick` | `boolean`, for the `"overlay"` placement: a click outside the modal does what Escape does (closes its panel if it's open, the modal otherwise). Call `event.preventDefault()` in your `onClick` to keep it open | `false` |
285
291
  | `backdrop` | `"plain"`, `"glow"`, or any string, for the `"overlay"` placement: what's behind the modal (see below) | `"plain"` |
286
292
  | `ladder` | `boolean`, for the fixed placements: pills with the same placement line up like the rungs of a ladder (see below). `false` leaves this one out: it stays in its spot and the others ignore it | `true` |
293
+ | `moveThroughCircle` | `boolean`, for the fixed placements: when the placement (or the orientation) changes, the pill closes to a circle where it is, the circle travels, and the pill opens at its new place, so its content never jumps on the way (from the bottom to a side, it turns vertical inside the circle). `false` travels at full size. At once with reduced motion | `true` |
287
294
  | `scene` / `sceneChange` | A name for what the pill shows: when it changes, the pill goes from one content to the other instead of jumping (see below). `"circle"`, `"slide"` or `"none"` | none / `"circle"` |
288
295
  | `orientation` | `"horizontal"`, `"vertical"` | `"vertical"` for `left`/`right` |
289
296
  | `variant` | `"neutral"`, `"success"`, `"danger"`, or any string (see [Styling](#styling)) | `"neutral"` |
@@ -473,7 +480,7 @@ import "magic-pill/calendar.css";
473
480
 
474
481
  With the keyboard: the arrows, Home and End (the week), Page Up and Page Down (the month; the year with Shift), Enter, and Escape, which closes it alone. The title goes up to the months, then to the years. It looks like open lists do (`--mp-list`, `--mp-on-list`): made of the fields, of the form's `look`, or of the pill's glass; of the pill itself when it's `inline`; `--mp-calendar-cell` (`2.25rem`) is its days' size. Weeks start on Monday.
475
482
 
476
- > **Your app's resets:** CSS like `input { border: 1px solid }` that isn't in a layer also reaches the pill's fields. Their look is on what surrounds the controls, so they only need to stay bare: scope such rules, or put them in a layer.
483
+ > **Your app's resets:** CSS like `input { border: 1px solid }` that isn't in a layer also reaches the pill's fields. Their look is on what surrounds the controls, so they only need to stay bare: scope such rules, or put them in a layer. A global `:focus-visible` outline is the exception, already handled: the focus ring is drawn around the field, for the keyboard only (not after a click or a tap), and the bare control never draws one of its own.
477
484
 
478
485
  ## Icons
479
486
  Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-hidden`). Any other icon or SVG works too: icons are just React content.
@@ -514,6 +521,7 @@ Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-
514
521
  | `--mp-text-size` / `--mp-title-size` | fluid, about 1rem / 1.5–2rem |
515
522
  | `--mp-padding` / `--mp-gap` / `--mp-action-size` | `0.875rem` / `1rem` / `2.75rem` |
516
523
  | `--mp-max-width` / `--mp-message-width` / `--mp-panel-width` | `48rem` / `24rem` / `32rem` |
524
+ | `--mp-card-width` | `12.5rem`: a sidebar's notification card, at the least (it keeps the sidebar's width if that's wider) |
517
525
  | `--mp-radius-panel` / `--mp-shadow` | `2.5rem` / a soft drop shadow |
518
526
  | `--mp-offset` / `--mp-z-index` | `1.5rem` from the viewport edges (plus safe areas) / `50` |
519
527
  | `--mp-backdrop` / `--mp-backdrop-blur` | the overlay's backdrop: `rgb(20 20 20 / 0.4)` / no blur |
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
2
  import { LinkComponent, PillProps } from "../Pill/types.mjs";
3
- import { PillNotificationClassNames } from "../PillNotification/PillNotification.mjs";
3
+ import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.mjs";
4
4
  import { SwapMode } from "./choreography.mjs";
5
5
  export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
6
6
  /** Default "main". Two hosts with the same name warn in development. */
@@ -28,6 +28,14 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
28
28
  * between the base layer and notifications ("always"), or nowhere ("never").
29
29
  */
30
30
  swap?: SwapMode;
31
+ /**
32
+ * How notifications are laid out: in one row (default), with their actions
33
+ * under the message when they need the room (`rows`), or, in a sidebar
34
+ * (`left`/`right`), as a card in its column (`card`) or in a flag out of its
35
+ * edge, while the sidebar stays (`flag`). Elsewhere, a card and a flag show
36
+ * in one row. A notification's own `layout` wins.
37
+ */
38
+ notificationLayout?: NotificationLayout;
31
39
  /** Passed to notification actions that have an `href`. */
32
40
  linkComponent?: LinkComponent;
33
41
  classNames?: PillNotificationClassNames;
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
2
  import { LinkComponent, PillProps } from "../Pill/types.js";
3
- import { PillNotificationClassNames } from "../PillNotification/PillNotification.js";
3
+ import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.js";
4
4
  import { SwapMode } from "./choreography.js";
5
5
  export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
6
6
  /** Default "main". Two hosts with the same name warn in development. */
@@ -28,6 +28,14 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
28
28
  * between the base layer and notifications ("always"), or nowhere ("never").
29
29
  */
30
30
  swap?: SwapMode;
31
+ /**
32
+ * How notifications are laid out: in one row (default), with their actions
33
+ * under the message when they need the room (`rows`), or, in a sidebar
34
+ * (`left`/`right`), as a card in its column (`card`) or in a flag out of its
35
+ * edge, while the sidebar stays (`flag`). Elsewhere, a card and a flag show
36
+ * in one row. A notification's own `layout` wins.
37
+ */
38
+ notificationLayout?: NotificationLayout;
31
39
  /** Passed to notification actions that have an `href`. */
32
40
  linkComponent?: LinkComponent;
33
41
  classNames?: PillNotificationClassNames;
@@ -2,15 +2,17 @@
2
2
 
3
3
  let react = require("react");
4
4
  const require_Pill = require("../Pill/Pill.js");
5
- const require_morph = require("../Pill/morph.js");
6
5
  const require_parts = require("../Pill/parts.js");
7
6
  const require_PillNotification = require("../PillNotification/PillNotification.js");
8
7
  const require_store = require("../store/store.js");
9
8
  const require_inputModality = require("../utils/inputModality.js");
10
9
  const require_usePillQueue = require("../store/usePillQueue.js");
11
10
  const require_react = require("../utils/react.js");
11
+ const require_timing = require("../utils/timing.js");
12
12
  const require_visuallyHidden = require("../utils/visuallyHidden.js");
13
13
  const require_choreography = require("./choreography.js");
14
+ const require_flag = require("./flag.js");
15
+ const require_useChoreography = require("./useChoreography.js");
14
16
  let react_jsx_runtime = require("react/jsx-runtime");
15
17
 
16
18
  // src/MagicPill/MagicPill.tsx
@@ -33,14 +35,59 @@ function useDocumentHidden() {
33
35
  return hidden;
34
36
  }
35
37
  /**
38
+ * Pauses a notification while it's pointed at or has the keyboard focus
39
+ * (Y3, L22). The handlers go on the pill that shows it.
40
+ */
41
+ function usePause(rootRef, presence) {
42
+ const [hovered, setHovered] = (0, react.useState)(false);
43
+ const [focused, setFocused] = (0, react.useState)(false);
44
+ (0, react.useEffect)(() => {
45
+ if (presence === "hidden") {
46
+ setHovered(false);
47
+ setFocused(false);
48
+ }
49
+ }, [presence]);
50
+ (0, react.useEffect)(() => {
51
+ const root = rootRef.current;
52
+ if (!focused || !root) return;
53
+ const update = () => {
54
+ if (!root.contains(document.activeElement)) setFocused(false);
55
+ };
56
+ update();
57
+ const observer = new MutationObserver(update);
58
+ observer.observe(root, {
59
+ childList: true,
60
+ subtree: true
61
+ });
62
+ return () => observer.disconnect();
63
+ }, [rootRef, focused]);
64
+ return {
65
+ active: hovered || focused,
66
+ handlers: {
67
+ onPointerEnter: (event) => {
68
+ if (event.pointerType !== "touch") setHovered(true);
69
+ },
70
+ onPointerLeave: () => setHovered(false),
71
+ onFocus: () => {
72
+ if (require_inputModality.getInputModality() === "keyboard") setFocused(true);
73
+ },
74
+ onBlur: (event) => {
75
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
76
+ }
77
+ }
78
+ };
79
+ }
80
+ const notificationIn = ({ scene, presence }) => scene.kind === "notification" && require_choreography.isOpen(presence) ? scene.item : null;
81
+ /**
36
82
  * The batteries-included pill: a <Pill> with a base layer, a queue of
37
83
  * notifications fed by pill(name), and a live region that announces them.
38
84
  */
39
- const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", linkComponent, classNames, placement = "bottom", variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
85
+ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
40
86
  const store = require_store.getStore(name);
41
87
  const { current } = require_usePillQueue.usePillQueue(name);
42
88
  const rootRef = (0, react.useRef)(null);
43
89
  const ref = (0, react.useMemo)(() => require_react.mergeRefs(rootRef, forwardedRef), [forwardedRef]);
90
+ const flagRef = (0, react.useRef)(null);
44
91
  (0, react.useEffect)(() => store.registerHost(), [store]);
45
92
  (0, react.useEffect)(require_inputModality.trackInputModality, []);
46
93
  const hasBase = hasContent(children);
@@ -57,82 +104,103 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
57
104
  });
58
105
  const [isFillingIn, setIsFillingIn] = (0, react.useState)(false);
59
106
  const isWaiting = isFillingIn && hasBase;
60
- const target = (0, react.useMemo)(() => current && !isWaiting ? {
107
+ const onSide = placement === "left" || placement === "right";
108
+ const isVertical = orientation === "vertical" || orientation === void 0 && onSide;
109
+ const layoutOf = (item) => {
110
+ const layout = item.input.layout ?? notificationLayout;
111
+ if (layout === "card" && !isVertical) return "pill";
112
+ if (layout === "flag" && !(isVertical && onSide && hasBase)) return "pill";
113
+ return layout;
114
+ };
115
+ const sceneLayout = (shown) => shown.kind === "notification" ? layoutOf(shown.item) : void 0;
116
+ const isFlag = current !== null && current !== void 0 && layoutOf(current) === "flag";
117
+ const target = (0, react.useMemo)(() => current && !isWaiting && !isFlag ? {
61
118
  kind: "notification",
62
119
  item: current
63
120
  } : hasBase ? base : idle === "rest" ? require_choreography.IDLE : require_choreography.NONE, [
64
121
  current,
65
122
  isWaiting,
123
+ isFlag,
66
124
  hasBase,
67
125
  base,
68
126
  idle
69
127
  ]);
70
- const [displayed, setDisplayed] = (0, react.useState)(() => ({
71
- scene: target.kind === "notification" ? require_choreography.NONE : target,
72
- presence: target.kind === "base" ? "compact" : target.kind === "idle" ? "rest" : "hidden"
73
- }));
74
- const displayedRef = (0, react.useRef)(displayed);
75
- displayedRef.current = displayed;
76
- const followUps = (0, react.useRef)([]);
77
- const capture = (0, react.useRef)(null);
78
- const swapMode = (0, react.useRef)(swap);
79
- swapMode.current = swap;
128
+ const flagTarget = (0, react.useMemo)(() => current && !isWaiting && isFlag ? {
129
+ kind: "notification",
130
+ item: current
131
+ } : require_choreography.NONE, [
132
+ current,
133
+ isWaiting,
134
+ isFlag
135
+ ]);
136
+ const orientationOf = (shown) => isVertical && shown.kind === "notification" && sceneLayout(shown) !== "card" ? "horizontal" : orientation;
137
+ const sidebarWidth = (0, react.useRef)(void 0);
138
+ const [isSliding, setIsSliding] = (0, react.useState)(false);
139
+ const { displayed, setDisplayed, displayedRef } = require_useChoreography.useChoreography(rootRef, target, {
140
+ swapMode: (from, to) => {
141
+ if (!isVertical || swap !== "always") return swap;
142
+ const layout = sceneLayout(to.kind === "notification" ? to : from);
143
+ return layout === "rows" || layout === "card" ? "always" : "queue";
144
+ },
145
+ turns: (from, to) => (orientationOf(from) ?? "") !== (orientationOf(to) ?? ""),
146
+ beforeApply: (from) => {
147
+ if (from.scene.kind === "base" && require_choreography.isOpen(from.presence) && rootRef.current) sidebarWidth.current = rootRef.current.getBoundingClientRect().width;
148
+ },
149
+ onSlide: setIsSliding
150
+ });
151
+ const [flagSpot, setFlagSpot] = (0, react.useState)({ shift: 0 });
152
+ const flagFrom = (0, react.useRef)(null);
153
+ const { displayed: flagDisplayed, setDisplayed: setFlagDisplayed, displayedRef: flagDisplayedRef } = require_useChoreography.useChoreography(flagRef, flagTarget, {
154
+ swapMode: () => swap === "never" ? "never" : "queue",
155
+ beforeApply: (from, next) => {
156
+ if (next.scene.kind !== "notification" || next.scene === from.scene || !rootRef.current) return;
157
+ if (flagRef.current && require_choreography.isOpen(from.presence)) flagFrom.current = flagRef.current.getBoundingClientRect();
158
+ setFlagSpot(require_flag.measureFlagSpot(rootRef.current, next.scene.item.input.at));
159
+ }
160
+ });
161
+ const flagY = flagDisplayed.presence === "panel" ? void 0 : flagSpot.y;
80
162
  (0, react.useLayoutEffect)(() => {
81
- const swapped = capture.current;
82
- capture.current = null;
83
- if (swapped && rootRef.current) require_morph.playSwap(rootRef.current, swapped);
84
- }, [displayed]);
163
+ const from = flagFrom.current;
164
+ flagFrom.current = null;
165
+ const flag = flagRef.current;
166
+ if (!from || !flag || typeof flag.animate !== "function" || require_timing.prefersReducedMotion()) return;
167
+ const to = flag.getBoundingClientRect();
168
+ const shift = from.top + from.height / 2 - (to.top + to.height / 2);
169
+ if (Math.abs(shift) < 1) return;
170
+ const { fade, change } = require_choreography.readTimings(flag);
171
+ flag.animate([{ translate: `0px ${shift}px` }, { translate: "0px 0px" }], {
172
+ duration: fade + change,
173
+ easing: "ease-in-out",
174
+ composite: "add"
175
+ });
176
+ }, [flagSpot, flagY]);
177
+ const flagPresence = (0, react.useRef)(flagDisplayed.presence);
178
+ (0, react.useLayoutEffect)(() => {
179
+ const previous = flagPresence.current;
180
+ flagPresence.current = flagDisplayed.presence;
181
+ const sidebar = rootRef.current;
182
+ const flag = flagRef.current;
183
+ if (!sidebar || !flag || previous === flagDisplayed.presence) return;
184
+ const { enter, fade, change, exit } = require_choreography.readTimings(flag);
185
+ if (previous === "hidden" && flagDisplayed.presence === "rest") require_flag.playBridge(sidebar, flag, flagSpot.y, "split", {
186
+ delay: 0,
187
+ duration: enter
188
+ });
189
+ else if (flagDisplayed.presence === "hidden") require_flag.playBridge(sidebar, flag, flagSpot.y, "join", {
190
+ delay: fade + change,
191
+ duration: exit
192
+ });
193
+ }, [flagDisplayed.presence]);
85
194
  (0, react.useEffect)(() => {
86
195
  const hasForm = () => !!rootRef.current?.querySelector("[data-mp=\"panel\"][data-open] form");
87
196
  setIsFillingIn(displayed.scene.kind === "base" && displayed.presence === "panel" && hasForm());
88
197
  }, [displayed]);
89
- (0, react.useEffect)(() => {
90
- const next = followUps.current.shift();
91
- if (!next) return;
92
- rootRef.current?.offsetWidth;
93
- setDisplayed(next);
94
- }, [displayed]);
95
- (0, react.useEffect)(() => {
96
- const current = displayedRef.current;
97
- const timers = require_choreography.batchSteps(current, require_choreography.planSteps(current, target, require_choreography.readTimings(rootRef.current), swapMode.current)).map(({ at, states }) => {
98
- const apply = () => {
99
- if (require_choreography.isSwap(displayedRef.current, states[0], swapMode.current)) capture.current = require_morph.captureSwap(rootRef.current);
100
- followUps.current = states.slice(1);
101
- setDisplayed(states[0]);
102
- };
103
- if (at > 0) return setTimeout(apply, at);
104
- apply();
105
- });
106
- return () => {
107
- timers.forEach(clearTimeout);
108
- followUps.current = [];
109
- };
110
- }, [target]);
111
- const [hovered, setHovered] = (0, react.useState)(false);
112
- const [focused, setFocused] = (0, react.useState)(false);
198
+ const mainPause = usePause(rootRef, displayed.presence);
199
+ const flagPause = usePause(flagRef, flagDisplayed.presence);
113
200
  const documentHidden = useDocumentHidden();
114
- (0, react.useEffect)(() => {
115
- if (displayed.presence === "hidden") {
116
- setHovered(false);
117
- setFocused(false);
118
- }
119
- }, [displayed.presence]);
120
- (0, react.useEffect)(() => {
121
- const root = rootRef.current;
122
- if (!focused || !root) return;
123
- const update = () => {
124
- if (!root.contains(document.activeElement)) setFocused(false);
125
- };
126
- update();
127
- const observer = new MutationObserver(update);
128
- observer.observe(root, {
129
- childList: true,
130
- subtree: true
131
- });
132
- return () => observer.disconnect();
133
- }, [focused]);
134
- const shown = displayed.scene.kind === "notification" && require_choreography.isOpen(displayed.presence) ? displayed.scene.item : null;
135
- const paused = hovered || focused || documentHidden || displayed.presence === "panel";
201
+ const inFlag = notificationIn(flagDisplayed);
202
+ const shown = notificationIn(displayed) ?? inFlag;
203
+ const paused = documentHidden || (shown !== null && shown === inFlag ? flagPause.active || flagDisplayed.presence === "panel" : mainPause.active || displayed.presence === "panel");
136
204
  (0, react.useEffect)(() => {
137
205
  if (!shown || paused) return;
138
206
  const ms = shown.input.duration ?? duration;
@@ -150,29 +218,29 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
150
218
  if (!shown) return;
151
219
  const { announce } = shown.input;
152
220
  if (announce === false) return;
153
- const text = typeof announce === "string" ? announce : readMessage(rootRef.current);
221
+ const text = typeof announce === "string" ? announce : readMessage(shown === inFlag ? flagRef.current : rootRef.current);
154
222
  if (text) setAnnouncement((previous) => previous?.key === shown ? previous : {
155
223
  key: shown,
156
224
  text
157
225
  });
158
- }, [shown]);
159
- const handlePresenceChange = (next) => {
160
- const { scene, presence } = displayedRef.current;
226
+ }, [shown, inFlag]);
227
+ const presenceHandler = (stateRef, setState) => (next) => {
228
+ const { scene: shownScene, presence } = stateRef.current;
161
229
  if (next === "hidden") {
162
- if (scene.kind === "notification") store.dismiss(scene.item.id, "dismissed");
230
+ if (shownScene.kind === "notification") store.dismiss(shownScene.item.id, "dismissed");
163
231
  return;
164
232
  }
165
- if (require_choreography.isOpen(next) && require_choreography.isOpen(presence)) setDisplayed({
166
- scene,
233
+ if (require_choreography.isOpen(next) && require_choreography.isOpen(presence)) setState({
234
+ scene: shownScene,
167
235
  presence: next
168
236
  });
169
237
  };
170
- const renderScene = (scene) => {
171
- switch (scene.kind) {
172
- case "base": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: lastScenes.current.get(scene.key)?.children ?? lastBase.current }, scene.key);
238
+ const renderScene = (shownScene) => {
239
+ switch (shownScene.kind) {
240
+ case "base": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: lastScenes.current.get(shownScene.key)?.children ?? lastBase.current }, shownScene.key);
173
241
  case "idle": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, { children: idleIcon });
174
242
  case "notification": {
175
- const { id, input } = scene.item;
243
+ const { id, input } = shownScene.item;
176
244
  if (input.render) return input.render({
177
245
  id,
178
246
  dismiss: () => store.dismiss(id, "dismissed")
@@ -182,6 +250,7 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
182
250
  message: input.message,
183
251
  action: input.action,
184
252
  panel: input.panel,
253
+ layout: layoutOf(shownScene.item),
185
254
  linkComponent,
186
255
  classNames,
187
256
  onAction: (event) => {
@@ -195,38 +264,70 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
195
264
  const displayedKey = displayed.scene.kind === "base" ? displayed.scene.key : scene;
196
265
  for (const key of lastScenes.current.keys()) if (key !== scene && key !== displayedKey) lastScenes.current.delete(key);
197
266
  const sceneVariant = displayed.scene.kind === "notification" ? displayed.scene.item.input.variant ?? variant : (lastScenes.current.get(displayedKey) ?? { variant }).variant;
198
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
199
- ...rest,
200
- ref,
201
- placement,
202
- variant: sceneVariant,
203
- presence: displayed.presence,
204
- onPresenceChange: handlePresenceChange,
205
- onPointerEnter: (event) => {
206
- onPointerEnter?.(event);
207
- if (event.pointerType !== "touch") setHovered(true);
208
- },
209
- onPointerLeave: (event) => {
210
- onPointerLeave?.(event);
211
- setHovered(false);
212
- },
213
- onFocus: (event) => {
214
- onFocus?.(event);
215
- if (require_inputModality.getInputModality() === "keyboard") setFocused(true);
216
- },
217
- onBlur: (event) => {
218
- onBlur?.(event);
219
- if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
220
- },
221
- children: renderScene(displayed.scene)
222
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
223
- role: "status",
224
- "aria-live": "polite",
225
- "aria-atomic": "true",
226
- "data-mp": "announcer",
227
- style: require_visuallyHidden.VISUALLY_HIDDEN,
228
- children: announcement && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: announcement.text }, announcement.key.id + announcement.text)
229
- })] });
267
+ const mainLayout = sceneLayout(displayed.scene);
268
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
269
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
270
+ ...rest,
271
+ ref,
272
+ placement,
273
+ orientation: orientationOf(displayed.scene),
274
+ moveThroughCircle: moveThroughCircle !== false && !isSliding,
275
+ "data-layout": mainLayout,
276
+ style: mainLayout === "card" && sidebarWidth.current ? {
277
+ ...rest.style,
278
+ "--_mp-sidebar-width": `${sidebarWidth.current}px`
279
+ } : rest.style,
280
+ variant: sceneVariant,
281
+ presence: displayed.presence,
282
+ onPresenceChange: presenceHandler(displayedRef, setDisplayed),
283
+ onPointerEnter: (event) => {
284
+ onPointerEnter?.(event);
285
+ mainPause.handlers.onPointerEnter(event);
286
+ },
287
+ onPointerLeave: (event) => {
288
+ onPointerLeave?.(event);
289
+ mainPause.handlers.onPointerLeave();
290
+ },
291
+ onFocus: (event) => {
292
+ onFocus?.(event);
293
+ mainPause.handlers.onFocus();
294
+ },
295
+ onBlur: (event) => {
296
+ onBlur?.(event);
297
+ mainPause.handlers.onBlur(event);
298
+ },
299
+ children: renderScene(displayed.scene)
300
+ }),
301
+ (isVertical && onSide && hasBase || flagDisplayed.presence !== "hidden") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
302
+ ref: flagRef,
303
+ placement,
304
+ orientation: "horizontal",
305
+ ladder: false,
306
+ moveThroughCircle: false,
307
+ theme: rest.theme,
308
+ variant: flagDisplayed.scene.kind === "notification" ? flagDisplayed.scene.item.input.variant ?? variant : variant,
309
+ presence: flagDisplayed.presence,
310
+ onPresenceChange: (next) => {
311
+ if (flagRef.current && require_choreography.isOpen(next)) flagFrom.current = flagRef.current.getBoundingClientRect();
312
+ presenceHandler(flagDisplayedRef, setFlagDisplayed)(next);
313
+ },
314
+ "data-layout": "flag",
315
+ style: require_flag.flagStyle({
316
+ shift: flagSpot.shift,
317
+ y: flagY
318
+ }),
319
+ ...flagPause.handlers,
320
+ children: renderScene(flagDisplayed.scene)
321
+ }),
322
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
323
+ role: "status",
324
+ "aria-live": "polite",
325
+ "aria-atomic": "true",
326
+ "data-mp": "announcer",
327
+ style: require_visuallyHidden.VISUALLY_HIDDEN,
328
+ children: announcement && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: announcement.text }, announcement.key.id + announcement.text)
329
+ })
330
+ ] });
230
331
  });
231
332
 
232
333
  module.exports = MagicPill;