magic-pill 9.0.0-next.0 → 9.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +4 -1
  3. package/dist/MagicPill/MagicPill.js +185 -2
  4. package/dist/MagicPill/MagicPill.mjs +185 -2
  5. package/dist/MagicPill/choreography.js +91 -2
  6. package/dist/MagicPill/choreography.mjs +85 -2
  7. package/dist/Pill/Pill.js +106 -2
  8. package/dist/Pill/Pill.mjs +106 -2
  9. package/dist/Pill/PillAction.js +67 -2
  10. package/dist/Pill/PillAction.mjs +67 -2
  11. package/dist/Pill/PillContext.js +26 -2
  12. package/dist/Pill/PillContext.mjs +24 -2
  13. package/dist/Pill/PillPanel.js +88 -2
  14. package/dist/Pill/PillPanel.mjs +87 -2
  15. package/dist/Pill/parts.js +46 -2
  16. package/dist/Pill/parts.mjs +43 -2
  17. package/dist/PillNavbar/PillNavbar.js +44 -2
  18. package/dist/PillNavbar/PillNavbar.mjs +44 -2
  19. package/dist/PillNavbar/matchPath.js +34 -2
  20. package/dist/PillNavbar/matchPath.mjs +34 -2
  21. package/dist/PillNotification/PillNotification.js +64 -2
  22. package/dist/PillNotification/PillNotification.mjs +63 -2
  23. package/dist/icons/ArrowIcon.js +21 -2
  24. package/dist/icons/ArrowIcon.mjs +21 -2
  25. package/dist/icons/BoxIcon.js +21 -2
  26. package/dist/icons/BoxIcon.mjs +21 -2
  27. package/dist/icons/CheckIcon.js +17 -2
  28. package/dist/icons/CheckIcon.mjs +17 -2
  29. package/dist/icons/CloseIcon.js +17 -2
  30. package/dist/icons/CloseIcon.mjs +17 -2
  31. package/dist/icons/CouponIcon.js +17 -2
  32. package/dist/icons/CouponIcon.mjs +17 -2
  33. package/dist/icons/DocumentIcon.js +17 -2
  34. package/dist/icons/DocumentIcon.mjs +17 -2
  35. package/dist/icons/HelpIcon.js +17 -2
  36. package/dist/icons/HelpIcon.mjs +17 -2
  37. package/dist/icons/InfoIcon.js +17 -2
  38. package/dist/icons/InfoIcon.mjs +17 -2
  39. package/dist/icons/MailIcon.js +17 -2
  40. package/dist/icons/MailIcon.mjs +17 -2
  41. package/dist/icons/PhoneIcon.js +21 -2
  42. package/dist/icons/PhoneIcon.mjs +21 -2
  43. package/dist/icons/PlusIcon.js +17 -2
  44. package/dist/icons/PlusIcon.mjs +17 -2
  45. package/dist/icons/UndoIcon.js +21 -2
  46. package/dist/icons/UndoIcon.mjs +21 -2
  47. package/dist/index.js +50 -1
  48. package/dist/index.mjs +24 -1
  49. package/dist/store/store.js +104 -2
  50. package/dist/store/store.mjs +102 -2
  51. package/dist/store/usePillQueue.js +17 -2
  52. package/dist/store/usePillQueue.mjs +17 -2
  53. package/dist/styles.css +46 -17
  54. package/dist/utils/react.js +23 -2
  55. package/dist/utils/react.mjs +21 -2
  56. package/dist/utils/url.js +22 -2
  57. package/dist/utils/url.mjs +22 -2
  58. package/package.json +3 -2
  59. package/dist/MagicPill/MagicPill.js.map +0 -1
  60. package/dist/MagicPill/MagicPill.mjs.map +0 -1
  61. package/dist/MagicPill/choreography.js.map +0 -1
  62. package/dist/MagicPill/choreography.mjs.map +0 -1
  63. package/dist/Pill/Pill.js.map +0 -1
  64. package/dist/Pill/Pill.mjs.map +0 -1
  65. package/dist/Pill/PillAction.js.map +0 -1
  66. package/dist/Pill/PillAction.mjs.map +0 -1
  67. package/dist/Pill/PillContext.js.map +0 -1
  68. package/dist/Pill/PillContext.mjs.map +0 -1
  69. package/dist/Pill/PillPanel.js.map +0 -1
  70. package/dist/Pill/PillPanel.mjs.map +0 -1
  71. package/dist/Pill/parts.js.map +0 -1
  72. package/dist/Pill/parts.mjs.map +0 -1
  73. package/dist/PillNavbar/PillNavbar.js.map +0 -1
  74. package/dist/PillNavbar/PillNavbar.mjs.map +0 -1
  75. package/dist/PillNavbar/matchPath.js.map +0 -1
  76. package/dist/PillNavbar/matchPath.mjs.map +0 -1
  77. package/dist/PillNotification/PillNotification.js.map +0 -1
  78. package/dist/PillNotification/PillNotification.mjs.map +0 -1
  79. package/dist/icons/ArrowIcon.js.map +0 -1
  80. package/dist/icons/ArrowIcon.mjs.map +0 -1
  81. package/dist/icons/BoxIcon.js.map +0 -1
  82. package/dist/icons/BoxIcon.mjs.map +0 -1
  83. package/dist/icons/CheckIcon.js.map +0 -1
  84. package/dist/icons/CheckIcon.mjs.map +0 -1
  85. package/dist/icons/CloseIcon.js.map +0 -1
  86. package/dist/icons/CloseIcon.mjs.map +0 -1
  87. package/dist/icons/CouponIcon.js.map +0 -1
  88. package/dist/icons/CouponIcon.mjs.map +0 -1
  89. package/dist/icons/DocumentIcon.js.map +0 -1
  90. package/dist/icons/DocumentIcon.mjs.map +0 -1
  91. package/dist/icons/HelpIcon.js.map +0 -1
  92. package/dist/icons/HelpIcon.mjs.map +0 -1
  93. package/dist/icons/InfoIcon.js.map +0 -1
  94. package/dist/icons/InfoIcon.mjs.map +0 -1
  95. package/dist/icons/MailIcon.js.map +0 -1
  96. package/dist/icons/MailIcon.mjs.map +0 -1
  97. package/dist/icons/PhoneIcon.js.map +0 -1
  98. package/dist/icons/PhoneIcon.mjs.map +0 -1
  99. package/dist/icons/PlusIcon.js.map +0 -1
  100. package/dist/icons/PlusIcon.mjs.map +0 -1
  101. package/dist/icons/UndoIcon.js.map +0 -1
  102. package/dist/icons/UndoIcon.mjs.map +0 -1
  103. package/dist/store/store.js.map +0 -1
  104. package/dist/store/store.mjs.map +0 -1
  105. package/dist/store/usePillQueue.js.map +0 -1
  106. package/dist/store/usePillQueue.mjs.map +0 -1
  107. package/dist/utils/react.js.map +0 -1
  108. package/dist/utils/react.mjs.map +0 -1
  109. package/dist/utils/url.js.map +0 -1
  110. package/dist/utils/url.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -33,6 +33,14 @@ Work towards 9.0.0, the first release with a stable API. It's a breaking release
33
33
  - A migration guide from 8.x, [MIGRATING.md](./MIGRATING.md), shipped in the package
34
34
  - The README is rewritten for v9: quick start, notifications, the host and its base layer, the primitive, React Server Components, styling and tokens, accessibility and security
35
35
 
36
+ ### Changed
37
+ - The published JavaScript is readable (not minified) and has no source maps. Your app bundles exactly the same amount of code (your bundler minifies it), and the package is about 40% smaller to install (196 kB unpacked instead of 331 kB in 9.0.0-next.0)
38
+ - Size, measured and checked in CI: the quick start (`MagicPill` + `pill()`) adds about 4.9 kB of gzipped JavaScript and 2.2 kB of gzipped CSS to an app (both minified, as your bundler does); a hand-written `Pill` with its parts, about 1.4 kB of JavaScript
39
+
40
+ ### Fixed (since 9.0.0-next.0)
41
+ - Global resets on links and buttons, such as `a { color: inherit }` or `button { background: none }`, no longer blank out the pill's actions: their look now lives on an inner `[data-mp="action-body"]`
42
+ - In a narrow container, an inline pill wraps its message instead of cutting off its action. While the pill grows, the message still stays on one line
43
+
36
44
  ### Removed
37
45
  - The 8.x API: the `pillData` prop and `mode`, the types (`MagicPillType`, `Mode`, `NotificationIcon`, `CTAIcon`, `MagicPillNotification*`, `MagicPillNavbar*`), the 15 handlers (`updateMode` … `handleActiveNavItem`), `Icons`, `CTAIcons`, `getIconComponent` and `defaultPillData`
38
46
  - The 8.x stylesheet: its `.magicPill`/`.CTA`/… classes, the `--mp__*` variables and the Google Fonts `@import`. The `magic-pill/magicpill.css` and `magic-pill/dist/magicpill.css` paths now serve the new stylesheet
package/README.md CHANGED
@@ -27,6 +27,7 @@ On top of it come ready-made **templates** (a notification, a navbar) and a **co
27
27
  - [X] Accessible: screen reader announcements, keyboard focus pauses the countdown, focus handling for panels and modals
28
28
  - [X] Works in any React 18+ app, including React Server Components (Next.js App Router), with any router
29
29
  - [X] Styles you can override without `!important`, design tokens, no fonts loaded behind your back
30
+ - [X] Tiny: the quick start adds about **7 kB gzipped** to your app (4.9 kB of JavaScript + 2.2 kB of CSS, minified by your bundler), checked in CI. Unused parts are tree-shaken.
30
31
  - [X] Written in TypeScript, zero runtime dependencies
31
32
 
32
33
  ## Installation
@@ -319,8 +320,9 @@ Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-
319
320
 
320
321
  ## Styling
321
322
  - **Easy to override:** every rule sits in a `magic-pill` cascade layer. Any CSS of yours that isn't in a layer wins, whatever its specificity, with no `!important`.
322
- - **No collisions:** parts are selected by `data-mp` attributes (`[data-mp="pill"]`, `"icon"`, `"divider"`, `"message"`, `"actions"`, `"action"`, `"action-icon"`, `"label"`, `"panel"`, `"panel-title"`, `"panel-body"`, `"panel-footer"`, `"navbar"`), and states by `data-presence`, `data-placement`, `data-orientation` and `data-variant`. There are no class names of ours to clash with yours.
323
+ - **No collisions:** parts are selected by `data-mp` attributes (`[data-mp="pill"]`, `"icon"`, `"divider"`, `"message"`, `"actions"`, `"action"`, `"action-body"`, `"action-icon"`, `"label"`, `"panel"`, `"panel-title"`, `"panel-body"`, `"panel-footer"`, `"navbar"`), and states by `data-presence`, `data-placement`, `data-orientation` and `data-variant`. There are no class names of ours to clash with yours.
323
324
  - **Classes:** every part takes a `className`; templates and `<MagicPill>` take `classNames`.
325
+ - **Global resets are safe:** an action's look lives on its inner `[data-mp="action-body"]`, so app-wide rules such as `a { color: inherit }` or `button { background: none }` don't break it. To restyle an action, target `[data-mp="action-body"]`.
324
326
  - **Tailwind CSS v4:** declare the layer order once, before your imports, so utilities win: `@layer theme, base, magic-pill, components, utilities;`.
325
327
  - **Your own variants:** `variant="brand"` gives `data-variant="brand"`, so you can write `[data-variant="brand"] { --mp-surface: #4b2bd6; }`.
326
328
 
@@ -376,6 +378,7 @@ npm install
376
378
  npm run typecheck # TypeScript
377
379
  npm test # Vitest test suite
378
380
  npm run build # Builds dist/ with tsdown
381
+ npm run size # What an app ships, against the size budget (after a build)
379
382
  ```
380
383
 
381
384
  4. You're good to go! For easier development, we recommend creating a Next.js app and creating a symbolic link between the app and the package. Now, when you're making changes to the code in src/, the changes should be reflected in your Next.js app.
@@ -1,2 +1,185 @@
1
- "use client";let e=require("react");const t=require("../Pill/Pill.js"),n=require("../Pill/parts.js"),r=require("../PillNotification/PillNotification.js"),i=require("../store/store.js"),a=require("../store/usePillQueue.js"),o=require("../utils/react.js"),s=require("./choreography.js");let c=require("react/jsx-runtime");const l={position:`absolute`,width:1,height:1,margin:-1,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,whiteSpace:`nowrap`,border:0},u=e=>e!=null&&e!==!1;function d(){let[t,n]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{let e=()=>n(document.visibilityState===`hidden`);return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),t}const f=(0,e.forwardRef)(function({name:f=`main`,children:p,duration:m=5e3,idle:h=`hidden`,idleIcon:g,linkComponent:_,classNames:v,placement:y=`bottom`,variant:b,onMouseEnter:x,onMouseLeave:S,onFocus:C,onBlur:w,...T},E){let D=i.getStore(f),{current:O}=a.usePillQueue(f),k=(0,e.useRef)(null),A=(0,e.useMemo)(()=>o.mergeRefs(k,E),[E]);(0,e.useEffect)(()=>D.registerHost(),[D]);let j=u(p),M=(0,e.useMemo)(()=>O?{kind:`notification`,item:O}:j?s.BASE:h===`rest`?s.IDLE:s.NONE,[O,j,h]),[N,P]=(0,e.useState)(()=>({scene:M.kind===`notification`?s.NONE:M,presence:M.kind===`base`?`compact`:M.kind===`idle`?`rest`:`hidden`})),F=(0,e.useRef)(N);F.current=N,(0,e.useEffect)(()=>{let e=s.planSteps(F.current,M,s.readTimings(k.current)),t=[],n=0;return e.forEach((r,i)=>{n+=r.delay;let a=e[i+1];if(a&&a.delay===0)return;let o=()=>P({scene:r.scene,presence:r.presence});n===0?o():t.push(setTimeout(o,n))}),()=>t.forEach(clearTimeout)},[M]);let[I,L]=(0,e.useState)(!1),[R,z]=(0,e.useState)(!1),B=d();(0,e.useEffect)(()=>{N.presence===`hidden`&&(L(!1),z(!1))},[N.presence]);let V=N.scene.kind===`notification`&&s.isOpen(N.presence)?N.scene.item:null,H=I||R||B||N.presence===`panel`;(0,e.useEffect)(()=>{if(!V||H)return;let e=V.input.duration??m;if(!Number.isFinite(e))return;let t=setTimeout(()=>D.dismiss(V.id,`timeout`),e);return()=>clearTimeout(t)},[V,H,m,D]);let[U,W]=(0,e.useState)(null);(0,e.useEffect)(()=>{if(!V)return;let{announce:e}=V.input;if(e===!1)return;let t=k.current,n=typeof e==`string`?e:(t?.querySelector(`[data-mp="message"]`)??t)?.textContent?.trim()??``;n&&W(e=>e?.key===V?e:{key:V,text:n})},[V]);let G=e=>{let{scene:t,presence:n}=F.current;e===`hidden`?t.kind===`notification`&&D.dismiss(t.item.id,`dismissed`):s.isOpen(e)&&s.isOpen(n)&&P({scene:t,presence:e})},K=e=>{switch(e.kind){case`base`:return p;case`idle`:return/* @__PURE__ */ (0,c.jsx)(n.PillIcon,{children:g});case`notification`:{let{id:t,input:n}=e.item;return n.render?n.render({id:t,dismiss:()=>D.dismiss(t,`dismissed`)}):/* @__PURE__ */ (0,c.jsx)(r.NotificationContent,{icon:n.icon,message:n.message,action:n.action,panel:n.panel,linkComponent:_,classNames:v,onAction:e=>{e.defaultPrevented||D.dismiss(t,`action`)}},t)}default:return null}},q=N.scene.kind===`notification`?N.scene.item.input.variant??b:b;return/* @__PURE__ */ (0,c.jsxs)(c.Fragment,{children:[/* @__PURE__ */ (0,c.jsx)(t,{...T,ref:A,placement:y,variant:q,presence:N.presence,onPresenceChange:G,onMouseEnter:e=>{x?.(e),L(!0)},onMouseLeave:e=>{S?.(e),L(!1)},onFocus:e=>{C?.(e),z(!0)},onBlur:e=>{w?.(e),z(e.currentTarget.contains(e.relatedTarget))},children:K(N.scene)}),/* @__PURE__ */ (0,c.jsx)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,"data-mp":`announcer`,style:l,children:U&&/* @__PURE__ */ (0,c.jsx)(`span`,{children:U.text},U.key.id+U.text)})]})});module.exports=f;
2
- //# sourceMappingURL=MagicPill.js.map
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_Pill = require("../Pill/Pill.js");
5
+ const require_parts = require("../Pill/parts.js");
6
+ const require_PillNotification = require("../PillNotification/PillNotification.js");
7
+ const require_store = require("../store/store.js");
8
+ const require_usePillQueue = require("../store/usePillQueue.js");
9
+ const require_react = require("../utils/react.js");
10
+ const require_choreography = require("./choreography.js");
11
+ let react_jsx_runtime = require("react/jsx-runtime");
12
+
13
+ // src/MagicPill/MagicPill.tsx
14
+ const DEFAULT_DURATION = 5e3;
15
+ const VISUALLY_HIDDEN = {
16
+ position: "absolute",
17
+ width: 1,
18
+ height: 1,
19
+ margin: -1,
20
+ padding: 0,
21
+ overflow: "hidden",
22
+ clip: "rect(0 0 0 0)",
23
+ whiteSpace: "nowrap",
24
+ border: 0
25
+ };
26
+ const hasContent = (node) => node !== void 0 && node !== null && node !== false;
27
+ function useDocumentHidden() {
28
+ const [hidden, setHidden] = (0, react.useState)(false);
29
+ (0, react.useEffect)(() => {
30
+ const update = () => setHidden(document.visibilityState === "hidden");
31
+ update();
32
+ document.addEventListener("visibilitychange", update);
33
+ return () => document.removeEventListener("visibilitychange", update);
34
+ }, []);
35
+ return hidden;
36
+ }
37
+ /**
38
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
39
+ * notifications fed by pill(name), and a live region that announces them.
40
+ */
41
+ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, linkComponent, classNames, placement = "bottom", variant, onMouseEnter, onMouseLeave, onFocus, onBlur, ...rest }, forwardedRef) {
42
+ const store = require_store.getStore(name);
43
+ const { current } = require_usePillQueue.usePillQueue(name);
44
+ const rootRef = (0, react.useRef)(null);
45
+ const ref = (0, react.useMemo)(() => require_react.mergeRefs(rootRef, forwardedRef), [forwardedRef]);
46
+ (0, react.useEffect)(() => store.registerHost(), [store]);
47
+ const hasBase = hasContent(children);
48
+ const target = (0, react.useMemo)(() => current ? {
49
+ kind: "notification",
50
+ item: current
51
+ } : hasBase ? require_choreography.BASE : idle === "rest" ? require_choreography.IDLE : require_choreography.NONE, [
52
+ current,
53
+ hasBase,
54
+ idle
55
+ ]);
56
+ const [displayed, setDisplayed] = (0, react.useState)(() => ({
57
+ scene: target.kind === "notification" ? require_choreography.NONE : target,
58
+ presence: target.kind === "base" ? "compact" : target.kind === "idle" ? "rest" : "hidden"
59
+ }));
60
+ const displayedRef = (0, react.useRef)(displayed);
61
+ displayedRef.current = displayed;
62
+ (0, react.useEffect)(() => {
63
+ const steps = require_choreography.planSteps(displayedRef.current, target, require_choreography.readTimings(rootRef.current));
64
+ const timers = [];
65
+ let at = 0;
66
+ steps.forEach((step, index) => {
67
+ at += step.delay;
68
+ const next = steps[index + 1];
69
+ if (next && next.delay === 0) return;
70
+ const apply = () => setDisplayed({
71
+ scene: step.scene,
72
+ presence: step.presence
73
+ });
74
+ if (at === 0) apply();
75
+ else timers.push(setTimeout(apply, at));
76
+ });
77
+ return () => timers.forEach(clearTimeout);
78
+ }, [target]);
79
+ const [hovered, setHovered] = (0, react.useState)(false);
80
+ const [focused, setFocused] = (0, react.useState)(false);
81
+ const documentHidden = useDocumentHidden();
82
+ (0, react.useEffect)(() => {
83
+ if (displayed.presence === "hidden") {
84
+ setHovered(false);
85
+ setFocused(false);
86
+ }
87
+ }, [displayed.presence]);
88
+ const shown = displayed.scene.kind === "notification" && require_choreography.isOpen(displayed.presence) ? displayed.scene.item : null;
89
+ const paused = hovered || focused || documentHidden || displayed.presence === "panel";
90
+ (0, react.useEffect)(() => {
91
+ if (!shown || paused) return;
92
+ const ms = shown.input.duration ?? duration;
93
+ if (!Number.isFinite(ms)) return;
94
+ const timer = setTimeout(() => store.dismiss(shown.id, "timeout"), ms);
95
+ return () => clearTimeout(timer);
96
+ }, [
97
+ shown,
98
+ paused,
99
+ duration,
100
+ store
101
+ ]);
102
+ const [announcement, setAnnouncement] = (0, react.useState)(null);
103
+ (0, react.useEffect)(() => {
104
+ if (!shown) return;
105
+ const { announce } = shown.input;
106
+ if (announce === false) return;
107
+ const root = rootRef.current;
108
+ const text = typeof announce === "string" ? announce : (root?.querySelector("[data-mp=\"message\"]") ?? root)?.textContent?.trim() ?? "";
109
+ if (text) setAnnouncement((previous) => previous?.key === shown ? previous : {
110
+ key: shown,
111
+ text
112
+ });
113
+ }, [shown]);
114
+ const handlePresenceChange = (next) => {
115
+ const { scene, presence } = displayedRef.current;
116
+ if (next === "hidden") {
117
+ if (scene.kind === "notification") store.dismiss(scene.item.id, "dismissed");
118
+ return;
119
+ }
120
+ if (require_choreography.isOpen(next) && require_choreography.isOpen(presence)) setDisplayed({
121
+ scene,
122
+ presence: next
123
+ });
124
+ };
125
+ const renderScene = (scene) => {
126
+ switch (scene.kind) {
127
+ case "base": return children;
128
+ case "idle": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, { children: idleIcon });
129
+ case "notification": {
130
+ const { id, input } = scene.item;
131
+ if (input.render) return input.render({
132
+ id,
133
+ dismiss: () => store.dismiss(id, "dismissed")
134
+ });
135
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillNotification.NotificationContent, {
136
+ icon: input.icon,
137
+ message: input.message,
138
+ action: input.action,
139
+ panel: input.panel,
140
+ linkComponent,
141
+ classNames,
142
+ onAction: (event) => {
143
+ if (!event.defaultPrevented) store.dismiss(id, "action");
144
+ }
145
+ }, id);
146
+ }
147
+ default: return null;
148
+ }
149
+ };
150
+ const sceneVariant = displayed.scene.kind === "notification" ? displayed.scene.item.input.variant ?? variant : variant;
151
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
152
+ ...rest,
153
+ ref,
154
+ placement,
155
+ variant: sceneVariant,
156
+ presence: displayed.presence,
157
+ onPresenceChange: handlePresenceChange,
158
+ onMouseEnter: (event) => {
159
+ onMouseEnter?.(event);
160
+ setHovered(true);
161
+ },
162
+ onMouseLeave: (event) => {
163
+ onMouseLeave?.(event);
164
+ setHovered(false);
165
+ },
166
+ onFocus: (event) => {
167
+ onFocus?.(event);
168
+ setFocused(true);
169
+ },
170
+ onBlur: (event) => {
171
+ onBlur?.(event);
172
+ setFocused(event.currentTarget.contains(event.relatedTarget));
173
+ },
174
+ children: renderScene(displayed.scene)
175
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
176
+ role: "status",
177
+ "aria-live": "polite",
178
+ "aria-atomic": "true",
179
+ "data-mp": "announcer",
180
+ style: VISUALLY_HIDDEN,
181
+ children: announcement && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: announcement.text }, announcement.key.id + announcement.text)
182
+ })] });
183
+ });
184
+
185
+ module.exports = MagicPill;
@@ -1,2 +1,185 @@
1
- "use client";import{forwardRef as e,useEffect as t,useMemo as n,useRef as r,useState as i}from"react";import a from"../Pill/Pill.mjs";import{PillIcon as o}from"../Pill/parts.mjs";import{NotificationContent as s}from"../PillNotification/PillNotification.mjs";import{getStore as c}from"../store/store.mjs";import{usePillQueue as l}from"../store/usePillQueue.mjs";import{mergeRefs as u}from"../utils/react.mjs";import{BASE as d,IDLE as f,NONE as p,isOpen as m,planSteps as h,readTimings as g}from"./choreography.mjs";import{Fragment as _,jsx as v,jsxs as y}from"react/jsx-runtime";const b={position:`absolute`,width:1,height:1,margin:-1,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,whiteSpace:`nowrap`,border:0},x=e=>e!=null&&e!==!1;function S(){let[e,n]=i(!1);return t(()=>{let e=()=>n(document.visibilityState===`hidden`);return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}const C=e(function({name:e=`main`,children:C,duration:w=5e3,idle:T=`hidden`,idleIcon:E,linkComponent:D,classNames:O,placement:k=`bottom`,variant:A,onMouseEnter:j,onMouseLeave:M,onFocus:N,onBlur:P,...F},I){let L=c(e),{current:R}=l(e),z=r(null),B=n(()=>u(z,I),[I]);t(()=>L.registerHost(),[L]);let V=x(C),H=n(()=>R?{kind:`notification`,item:R}:V?d:T===`rest`?f:p,[R,V,T]),[U,W]=i(()=>({scene:H.kind===`notification`?p:H,presence:H.kind===`base`?`compact`:H.kind===`idle`?`rest`:`hidden`})),G=r(U);G.current=U,t(()=>{let e=h(G.current,H,g(z.current)),t=[],n=0;return e.forEach((r,i)=>{n+=r.delay;let a=e[i+1];if(a&&a.delay===0)return;let o=()=>W({scene:r.scene,presence:r.presence});n===0?o():t.push(setTimeout(o,n))}),()=>t.forEach(clearTimeout)},[H]);let[K,q]=i(!1),[J,Y]=i(!1),X=S();t(()=>{U.presence===`hidden`&&(q(!1),Y(!1))},[U.presence]);let Z=U.scene.kind===`notification`&&m(U.presence)?U.scene.item:null,Q=K||J||X||U.presence===`panel`;t(()=>{if(!Z||Q)return;let e=Z.input.duration??w;if(!Number.isFinite(e))return;let t=setTimeout(()=>L.dismiss(Z.id,`timeout`),e);return()=>clearTimeout(t)},[Z,Q,w,L]);let[$,ee]=i(null);t(()=>{if(!Z)return;let{announce:e}=Z.input;if(e===!1)return;let t=z.current,n=typeof e==`string`?e:(t?.querySelector(`[data-mp="message"]`)??t)?.textContent?.trim()??``;n&&ee(e=>e?.key===Z?e:{key:Z,text:n})},[Z]);let te=e=>{let{scene:t,presence:n}=G.current;e===`hidden`?t.kind===`notification`&&L.dismiss(t.item.id,`dismissed`):m(e)&&m(n)&&W({scene:t,presence:e})},ne=e=>{switch(e.kind){case`base`:return C;case`idle`:return/* @__PURE__ */ v(o,{children:E});case`notification`:{let{id:t,input:n}=e.item;return n.render?n.render({id:t,dismiss:()=>L.dismiss(t,`dismissed`)}):/* @__PURE__ */ v(s,{icon:n.icon,message:n.message,action:n.action,panel:n.panel,linkComponent:D,classNames:O,onAction:e=>{e.defaultPrevented||L.dismiss(t,`action`)}},t)}default:return null}},re=U.scene.kind===`notification`?U.scene.item.input.variant??A:A;return/* @__PURE__ */ y(_,{children:[/* @__PURE__ */ v(a,{...F,ref:B,placement:k,variant:re,presence:U.presence,onPresenceChange:te,onMouseEnter:e=>{j?.(e),q(!0)},onMouseLeave:e=>{M?.(e),q(!1)},onFocus:e=>{N?.(e),Y(!0)},onBlur:e=>{P?.(e),Y(e.currentTarget.contains(e.relatedTarget))},children:ne(U.scene)}),/* @__PURE__ */ v(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,"data-mp":`announcer`,style:b,children:$&&/* @__PURE__ */ v(`span`,{children:$.text},$.key.id+$.text)})]})});export{C as default};
2
- //# sourceMappingURL=MagicPill.mjs.map
1
+ "use client";
2
+
3
+ import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
4
+ import Pill from "../Pill/Pill.mjs";
5
+ import { PillIcon } from "../Pill/parts.mjs";
6
+ import { NotificationContent } from "../PillNotification/PillNotification.mjs";
7
+ import { getStore } from "../store/store.mjs";
8
+ import { usePillQueue } from "../store/usePillQueue.mjs";
9
+ import { mergeRefs } from "../utils/react.mjs";
10
+ import { BASE, IDLE, NONE, isOpen, planSteps, readTimings } from "./choreography.mjs";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+
13
+ // src/MagicPill/MagicPill.tsx
14
+ const DEFAULT_DURATION = 5e3;
15
+ const VISUALLY_HIDDEN = {
16
+ position: "absolute",
17
+ width: 1,
18
+ height: 1,
19
+ margin: -1,
20
+ padding: 0,
21
+ overflow: "hidden",
22
+ clip: "rect(0 0 0 0)",
23
+ whiteSpace: "nowrap",
24
+ border: 0
25
+ };
26
+ const hasContent = (node) => node !== void 0 && node !== null && node !== false;
27
+ function useDocumentHidden() {
28
+ const [hidden, setHidden] = useState(false);
29
+ useEffect(() => {
30
+ const update = () => setHidden(document.visibilityState === "hidden");
31
+ update();
32
+ document.addEventListener("visibilitychange", update);
33
+ return () => document.removeEventListener("visibilitychange", update);
34
+ }, []);
35
+ return hidden;
36
+ }
37
+ /**
38
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
39
+ * notifications fed by pill(name), and a live region that announces them.
40
+ */
41
+ const MagicPill = forwardRef(function MagicPill({ name = "main", children, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, linkComponent, classNames, placement = "bottom", variant, onMouseEnter, onMouseLeave, onFocus, onBlur, ...rest }, forwardedRef) {
42
+ const store = getStore(name);
43
+ const { current } = usePillQueue(name);
44
+ const rootRef = useRef(null);
45
+ const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);
46
+ useEffect(() => store.registerHost(), [store]);
47
+ const hasBase = hasContent(children);
48
+ const target = useMemo(() => current ? {
49
+ kind: "notification",
50
+ item: current
51
+ } : hasBase ? BASE : idle === "rest" ? IDLE : NONE, [
52
+ current,
53
+ hasBase,
54
+ idle
55
+ ]);
56
+ const [displayed, setDisplayed] = useState(() => ({
57
+ scene: target.kind === "notification" ? NONE : target,
58
+ presence: target.kind === "base" ? "compact" : target.kind === "idle" ? "rest" : "hidden"
59
+ }));
60
+ const displayedRef = useRef(displayed);
61
+ displayedRef.current = displayed;
62
+ useEffect(() => {
63
+ const steps = planSteps(displayedRef.current, target, readTimings(rootRef.current));
64
+ const timers = [];
65
+ let at = 0;
66
+ steps.forEach((step, index) => {
67
+ at += step.delay;
68
+ const next = steps[index + 1];
69
+ if (next && next.delay === 0) return;
70
+ const apply = () => setDisplayed({
71
+ scene: step.scene,
72
+ presence: step.presence
73
+ });
74
+ if (at === 0) apply();
75
+ else timers.push(setTimeout(apply, at));
76
+ });
77
+ return () => timers.forEach(clearTimeout);
78
+ }, [target]);
79
+ const [hovered, setHovered] = useState(false);
80
+ const [focused, setFocused] = useState(false);
81
+ const documentHidden = useDocumentHidden();
82
+ useEffect(() => {
83
+ if (displayed.presence === "hidden") {
84
+ setHovered(false);
85
+ setFocused(false);
86
+ }
87
+ }, [displayed.presence]);
88
+ const shown = displayed.scene.kind === "notification" && isOpen(displayed.presence) ? displayed.scene.item : null;
89
+ const paused = hovered || focused || documentHidden || displayed.presence === "panel";
90
+ useEffect(() => {
91
+ if (!shown || paused) return;
92
+ const ms = shown.input.duration ?? duration;
93
+ if (!Number.isFinite(ms)) return;
94
+ const timer = setTimeout(() => store.dismiss(shown.id, "timeout"), ms);
95
+ return () => clearTimeout(timer);
96
+ }, [
97
+ shown,
98
+ paused,
99
+ duration,
100
+ store
101
+ ]);
102
+ const [announcement, setAnnouncement] = useState(null);
103
+ useEffect(() => {
104
+ if (!shown) return;
105
+ const { announce } = shown.input;
106
+ if (announce === false) return;
107
+ const root = rootRef.current;
108
+ const text = typeof announce === "string" ? announce : (root?.querySelector("[data-mp=\"message\"]") ?? root)?.textContent?.trim() ?? "";
109
+ if (text) setAnnouncement((previous) => previous?.key === shown ? previous : {
110
+ key: shown,
111
+ text
112
+ });
113
+ }, [shown]);
114
+ const handlePresenceChange = (next) => {
115
+ const { scene, presence } = displayedRef.current;
116
+ if (next === "hidden") {
117
+ if (scene.kind === "notification") store.dismiss(scene.item.id, "dismissed");
118
+ return;
119
+ }
120
+ if (isOpen(next) && isOpen(presence)) setDisplayed({
121
+ scene,
122
+ presence: next
123
+ });
124
+ };
125
+ const renderScene = (scene) => {
126
+ switch (scene.kind) {
127
+ case "base": return children;
128
+ case "idle": return /* @__PURE__ */ jsx(PillIcon, { children: idleIcon });
129
+ case "notification": {
130
+ const { id, input } = scene.item;
131
+ if (input.render) return input.render({
132
+ id,
133
+ dismiss: () => store.dismiss(id, "dismissed")
134
+ });
135
+ return /* @__PURE__ */ jsx(NotificationContent, {
136
+ icon: input.icon,
137
+ message: input.message,
138
+ action: input.action,
139
+ panel: input.panel,
140
+ linkComponent,
141
+ classNames,
142
+ onAction: (event) => {
143
+ if (!event.defaultPrevented) store.dismiss(id, "action");
144
+ }
145
+ }, id);
146
+ }
147
+ default: return null;
148
+ }
149
+ };
150
+ const sceneVariant = displayed.scene.kind === "notification" ? displayed.scene.item.input.variant ?? variant : variant;
151
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Pill, {
152
+ ...rest,
153
+ ref,
154
+ placement,
155
+ variant: sceneVariant,
156
+ presence: displayed.presence,
157
+ onPresenceChange: handlePresenceChange,
158
+ onMouseEnter: (event) => {
159
+ onMouseEnter?.(event);
160
+ setHovered(true);
161
+ },
162
+ onMouseLeave: (event) => {
163
+ onMouseLeave?.(event);
164
+ setHovered(false);
165
+ },
166
+ onFocus: (event) => {
167
+ onFocus?.(event);
168
+ setFocused(true);
169
+ },
170
+ onBlur: (event) => {
171
+ onBlur?.(event);
172
+ setFocused(event.currentTarget.contains(event.relatedTarget));
173
+ },
174
+ children: renderScene(displayed.scene)
175
+ }), /* @__PURE__ */ jsx("div", {
176
+ role: "status",
177
+ "aria-live": "polite",
178
+ "aria-atomic": "true",
179
+ "data-mp": "announcer",
180
+ style: VISUALLY_HIDDEN,
181
+ children: announcement && /* @__PURE__ */ jsx("span", { children: announcement.text }, announcement.key.id + announcement.text)
182
+ })] });
183
+ });
184
+
185
+ export { MagicPill as default };
@@ -1,2 +1,91 @@
1
- const e=Object.freeze({kind:`none`}),t=Object.freeze({kind:`base`}),n=Object.freeze({kind:`idle`}),r=/* @__PURE__ */ new Set([`compact`,`expanded`,`panel`]),i=e=>r.has(e),a=e=>e.kind===`notification`?`notification:${e.item.id}`:e.kind,o=e=>e.kind===`none`?`hidden`:e.kind===`idle`?`rest`:`compact`;function s(e,t){let n=/^\s*([\d.]+)(ms|s)\s*$/.exec(e);if(!n)return t;let r=Number.parseFloat(n[1]);return n[2]===`s`?r*1e3:r}exports.BASE=t,exports.IDLE=n,exports.NONE=e,exports.isOpen=i,exports.parseDuration=s,exports.planSteps=function(e,t,n){let r=[],{scene:s,presence:c}=e,l=(e,t,n=s)=>{r.push({delay:e,presence:t,scene:n}),c=t,s=n};if(a(s)!==a(t)){if(t.kind===`none`)return c!==`hidden`&&l(0,`hidden`),l(n.reduced?n.exit:n.change+n.exit,`hidden`,t),r;i(c)?n.reduced?(l(0,`hidden`),l(n.exit,`hidden`,t)):(l(0,`rest`),l(n.change,`rest`,t)):l(0,c,t)}else s!==t&&l(0,c,t);let u=o(t);return u===`hidden`||u===`rest`?c!==u&&l(0,u):i(c)||(c===`hidden`&&!n.reduced?(l(0,`rest`),l(n.enter,`compact`)):l(0,`compact`)),r},exports.readTimings=function(e){let t=e?getComputedStyle(e):null,n=(e,n)=>s(t?.getPropertyValue(e)??``,n),r=typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;return r?{enter:0,change:0,exit:150,reduced:r}:{enter:n(`--_mp-enter`,500),change:n(`--_mp-change`,250),exit:n(`--_mp-exit`,300),reduced:r}};
2
- //# sourceMappingURL=choreography.js.map
1
+ // src/MagicPill/choreography.ts
2
+ const NONE = Object.freeze({ kind: "none" });
3
+ const BASE = Object.freeze({ kind: "base" });
4
+ const IDLE = Object.freeze({ kind: "idle" });
5
+ const OPEN_LEVELS = /* @__PURE__ */ new Set([
6
+ "compact",
7
+ "expanded",
8
+ "panel"
9
+ ]);
10
+ const isOpen = (presence) => OPEN_LEVELS.has(presence);
11
+ const sceneKey = (scene) => scene.kind === "notification" ? `notification:${scene.item.id}` : scene.kind;
12
+ /** Where each scene settles: the base and notifications are pills, idle is a circle. */
13
+ const settledPresence = (scene) => scene.kind === "none" ? "hidden" : scene.kind === "idle" ? "rest" : "compact";
14
+ /**
15
+ * The steps from what's displayed to the target scene:
16
+ * - new content: collapse to the circle, swap the content there, grow back;
17
+ * - nothing left to show: hide (the stylesheet shrinks, then scales out), then drop the content;
18
+ * - from hidden: pop in as a circle, then grow into the pill.
19
+ * Open levels the user chose (expanded, panel) are kept while the scene stays the same.
20
+ */
21
+ function planSteps(current, target, timings) {
22
+ const steps = [];
23
+ let { scene, presence } = current;
24
+ const go = (delay, nextPresence, nextScene = scene) => {
25
+ steps.push({
26
+ delay,
27
+ presence: nextPresence,
28
+ scene: nextScene
29
+ });
30
+ presence = nextPresence;
31
+ scene = nextScene;
32
+ };
33
+ if (sceneKey(scene) !== sceneKey(target)) {
34
+ if (target.kind === "none") {
35
+ if (presence !== "hidden") go(0, "hidden");
36
+ go(timings.reduced ? timings.exit : timings.change + timings.exit, "hidden", target);
37
+ return steps;
38
+ }
39
+ if (isOpen(presence)) {
40
+ if (timings.reduced) {
41
+ go(0, "hidden");
42
+ go(timings.exit, "hidden", target);
43
+ } else {
44
+ go(0, "rest");
45
+ go(timings.change, "rest", target);
46
+ }
47
+ } else go(0, presence, target);
48
+ } else if (scene !== target) go(0, presence, target);
49
+ const settled = settledPresence(target);
50
+ if (settled === "hidden" || settled === "rest") {
51
+ if (presence !== settled) go(0, settled);
52
+ } else if (!isOpen(presence)) {
53
+ if (presence === "hidden" && !timings.reduced) {
54
+ go(0, "rest");
55
+ go(timings.enter, "compact");
56
+ } else go(0, "compact");
57
+ }
58
+ return steps;
59
+ }
60
+ /** "500ms" or "0.5s" → 500; anything else → the fallback. */
61
+ function parseDuration(value, fallback) {
62
+ const match = /^\s*([\d.]+)(ms|s)\s*$/.exec(value);
63
+ if (!match) return fallback;
64
+ const amount = Number.parseFloat(match[1]);
65
+ return match[2] === "s" ? amount * 1e3 : amount;
66
+ }
67
+ /** The timings the stylesheet uses for this pill, or its defaults (e.g. when unstyled). */
68
+ function readTimings(element) {
69
+ const style = element ? getComputedStyle(element) : null;
70
+ const read = (name, fallback) => parseDuration(style?.getPropertyValue(name) ?? "", fallback);
71
+ const reduced = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
72
+ return reduced ? {
73
+ enter: 0,
74
+ change: 0,
75
+ exit: 150,
76
+ reduced
77
+ } : {
78
+ enter: read("--_mp-enter", 500),
79
+ change: read("--_mp-change", 250),
80
+ exit: read("--_mp-exit", 300),
81
+ reduced
82
+ };
83
+ }
84
+
85
+ exports.BASE = BASE;
86
+ exports.IDLE = IDLE;
87
+ exports.NONE = NONE;
88
+ exports.isOpen = isOpen;
89
+ exports.parseDuration = parseDuration;
90
+ exports.planSteps = planSteps;
91
+ exports.readTimings = readTimings;
@@ -1,2 +1,85 @@
1
- const e=Object.freeze({kind:`none`}),t=Object.freeze({kind:`base`}),n=Object.freeze({kind:`idle`}),r=/* @__PURE__ */ new Set([`compact`,`expanded`,`panel`]),i=e=>r.has(e),a=e=>e.kind===`notification`?`notification:${e.item.id}`:e.kind,o=e=>e.kind===`none`?`hidden`:e.kind===`idle`?`rest`:`compact`;function s(e,t,n){let r=[],{scene:s,presence:c}=e,l=(e,t,n=s)=>{r.push({delay:e,presence:t,scene:n}),c=t,s=n};if(a(s)!==a(t)){if(t.kind===`none`)return c!==`hidden`&&l(0,`hidden`),l(n.reduced?n.exit:n.change+n.exit,`hidden`,t),r;i(c)?n.reduced?(l(0,`hidden`),l(n.exit,`hidden`,t)):(l(0,`rest`),l(n.change,`rest`,t)):l(0,c,t)}else s!==t&&l(0,c,t);let u=o(t);return u===`hidden`||u===`rest`?c!==u&&l(0,u):i(c)||(c===`hidden`&&!n.reduced?(l(0,`rest`),l(n.enter,`compact`)):l(0,`compact`)),r}function c(e,t){let n=/^\s*([\d.]+)(ms|s)\s*$/.exec(e);if(!n)return t;let r=Number.parseFloat(n[1]);return n[2]===`s`?r*1e3:r}function l(e){let t=e?getComputedStyle(e):null,n=(e,n)=>c(t?.getPropertyValue(e)??``,n),r=typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;return r?{enter:0,change:0,exit:150,reduced:r}:{enter:n(`--_mp-enter`,500),change:n(`--_mp-change`,250),exit:n(`--_mp-exit`,300),reduced:r}}export{t as BASE,n as IDLE,e as NONE,i as isOpen,c as parseDuration,s as planSteps,l as readTimings};
2
- //# sourceMappingURL=choreography.mjs.map
1
+ // src/MagicPill/choreography.ts
2
+ const NONE = Object.freeze({ kind: "none" });
3
+ const BASE = Object.freeze({ kind: "base" });
4
+ const IDLE = Object.freeze({ kind: "idle" });
5
+ const OPEN_LEVELS = /* @__PURE__ */ new Set([
6
+ "compact",
7
+ "expanded",
8
+ "panel"
9
+ ]);
10
+ const isOpen = (presence) => OPEN_LEVELS.has(presence);
11
+ const sceneKey = (scene) => scene.kind === "notification" ? `notification:${scene.item.id}` : scene.kind;
12
+ /** Where each scene settles: the base and notifications are pills, idle is a circle. */
13
+ const settledPresence = (scene) => scene.kind === "none" ? "hidden" : scene.kind === "idle" ? "rest" : "compact";
14
+ /**
15
+ * The steps from what's displayed to the target scene:
16
+ * - new content: collapse to the circle, swap the content there, grow back;
17
+ * - nothing left to show: hide (the stylesheet shrinks, then scales out), then drop the content;
18
+ * - from hidden: pop in as a circle, then grow into the pill.
19
+ * Open levels the user chose (expanded, panel) are kept while the scene stays the same.
20
+ */
21
+ function planSteps(current, target, timings) {
22
+ const steps = [];
23
+ let { scene, presence } = current;
24
+ const go = (delay, nextPresence, nextScene = scene) => {
25
+ steps.push({
26
+ delay,
27
+ presence: nextPresence,
28
+ scene: nextScene
29
+ });
30
+ presence = nextPresence;
31
+ scene = nextScene;
32
+ };
33
+ if (sceneKey(scene) !== sceneKey(target)) {
34
+ if (target.kind === "none") {
35
+ if (presence !== "hidden") go(0, "hidden");
36
+ go(timings.reduced ? timings.exit : timings.change + timings.exit, "hidden", target);
37
+ return steps;
38
+ }
39
+ if (isOpen(presence)) {
40
+ if (timings.reduced) {
41
+ go(0, "hidden");
42
+ go(timings.exit, "hidden", target);
43
+ } else {
44
+ go(0, "rest");
45
+ go(timings.change, "rest", target);
46
+ }
47
+ } else go(0, presence, target);
48
+ } else if (scene !== target) go(0, presence, target);
49
+ const settled = settledPresence(target);
50
+ if (settled === "hidden" || settled === "rest") {
51
+ if (presence !== settled) go(0, settled);
52
+ } else if (!isOpen(presence)) {
53
+ if (presence === "hidden" && !timings.reduced) {
54
+ go(0, "rest");
55
+ go(timings.enter, "compact");
56
+ } else go(0, "compact");
57
+ }
58
+ return steps;
59
+ }
60
+ /** "500ms" or "0.5s" → 500; anything else → the fallback. */
61
+ function parseDuration(value, fallback) {
62
+ const match = /^\s*([\d.]+)(ms|s)\s*$/.exec(value);
63
+ if (!match) return fallback;
64
+ const amount = Number.parseFloat(match[1]);
65
+ return match[2] === "s" ? amount * 1e3 : amount;
66
+ }
67
+ /** The timings the stylesheet uses for this pill, or its defaults (e.g. when unstyled). */
68
+ function readTimings(element) {
69
+ const style = element ? getComputedStyle(element) : null;
70
+ const read = (name, fallback) => parseDuration(style?.getPropertyValue(name) ?? "", fallback);
71
+ const reduced = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
72
+ return reduced ? {
73
+ enter: 0,
74
+ change: 0,
75
+ exit: 150,
76
+ reduced
77
+ } : {
78
+ enter: read("--_mp-enter", 500),
79
+ change: read("--_mp-change", 250),
80
+ exit: read("--_mp-exit", 300),
81
+ reduced
82
+ };
83
+ }
84
+
85
+ export { BASE, IDLE, NONE, isOpen, parseDuration, planSteps, readTimings };