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

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 (112) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +6 -2
  3. package/dist/MagicPill/MagicPill.js +194 -2
  4. package/dist/MagicPill/MagicPill.mjs +194 -2
  5. package/dist/MagicPill/choreography.js +132 -2
  6. package/dist/MagicPill/choreography.mjs +125 -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 +90 -2
  14. package/dist/Pill/PillPanel.mjs +89 -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 +125 -35
  54. package/dist/utils/inputModality.js +23 -0
  55. package/dist/utils/inputModality.mjs +22 -0
  56. package/dist/utils/react.js +23 -2
  57. package/dist/utils/react.mjs +21 -2
  58. package/dist/utils/url.js +22 -2
  59. package/dist/utils/url.mjs +22 -2
  60. package/package.json +3 -2
  61. package/dist/MagicPill/MagicPill.js.map +0 -1
  62. package/dist/MagicPill/MagicPill.mjs.map +0 -1
  63. package/dist/MagicPill/choreography.js.map +0 -1
  64. package/dist/MagicPill/choreography.mjs.map +0 -1
  65. package/dist/Pill/Pill.js.map +0 -1
  66. package/dist/Pill/Pill.mjs.map +0 -1
  67. package/dist/Pill/PillAction.js.map +0 -1
  68. package/dist/Pill/PillAction.mjs.map +0 -1
  69. package/dist/Pill/PillContext.js.map +0 -1
  70. package/dist/Pill/PillContext.mjs.map +0 -1
  71. package/dist/Pill/PillPanel.js.map +0 -1
  72. package/dist/Pill/PillPanel.mjs.map +0 -1
  73. package/dist/Pill/parts.js.map +0 -1
  74. package/dist/Pill/parts.mjs.map +0 -1
  75. package/dist/PillNavbar/PillNavbar.js.map +0 -1
  76. package/dist/PillNavbar/PillNavbar.mjs.map +0 -1
  77. package/dist/PillNavbar/matchPath.js.map +0 -1
  78. package/dist/PillNavbar/matchPath.mjs.map +0 -1
  79. package/dist/PillNotification/PillNotification.js.map +0 -1
  80. package/dist/PillNotification/PillNotification.mjs.map +0 -1
  81. package/dist/icons/ArrowIcon.js.map +0 -1
  82. package/dist/icons/ArrowIcon.mjs.map +0 -1
  83. package/dist/icons/BoxIcon.js.map +0 -1
  84. package/dist/icons/BoxIcon.mjs.map +0 -1
  85. package/dist/icons/CheckIcon.js.map +0 -1
  86. package/dist/icons/CheckIcon.mjs.map +0 -1
  87. package/dist/icons/CloseIcon.js.map +0 -1
  88. package/dist/icons/CloseIcon.mjs.map +0 -1
  89. package/dist/icons/CouponIcon.js.map +0 -1
  90. package/dist/icons/CouponIcon.mjs.map +0 -1
  91. package/dist/icons/DocumentIcon.js.map +0 -1
  92. package/dist/icons/DocumentIcon.mjs.map +0 -1
  93. package/dist/icons/HelpIcon.js.map +0 -1
  94. package/dist/icons/HelpIcon.mjs.map +0 -1
  95. package/dist/icons/InfoIcon.js.map +0 -1
  96. package/dist/icons/InfoIcon.mjs.map +0 -1
  97. package/dist/icons/MailIcon.js.map +0 -1
  98. package/dist/icons/MailIcon.mjs.map +0 -1
  99. package/dist/icons/PhoneIcon.js.map +0 -1
  100. package/dist/icons/PhoneIcon.mjs.map +0 -1
  101. package/dist/icons/PlusIcon.js.map +0 -1
  102. package/dist/icons/PlusIcon.mjs.map +0 -1
  103. package/dist/icons/UndoIcon.js.map +0 -1
  104. package/dist/icons/UndoIcon.mjs.map +0 -1
  105. package/dist/store/store.js.map +0 -1
  106. package/dist/store/store.mjs.map +0 -1
  107. package/dist/store/usePillQueue.js.map +0 -1
  108. package/dist/store/usePillQueue.mjs.map +0 -1
  109. package/dist/utils/react.js.map +0 -1
  110. package/dist/utils/react.mjs.map +0 -1
  111. package/dist/utils/url.js.map +0 -1
  112. package/dist/utils/url.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -29,10 +29,25 @@ Work towards 9.0.0, the first release with a stable API. It's a breaking release
29
29
  - every rule sits in a `magic-pill` cascade layer and targets `data-mp` attributes, so your own CSS overrides it without `!important` and no class names collide;
30
30
  - it loads no fonts (it uses your page's fonts unless you set `--mp-font-text`/`--mp-font-accent`);
31
31
  - it's sized in `rem`, fits phone screens and safe areas, and supports reduced motion and forced colours
32
+ - the pill pops in and scales out from its centre; `--mp-scale-origin` changes that (e.g. `bottom` to come out of the edge a bottom pill sits on)
32
33
 
33
34
  - A migration guide from 8.x, [MIGRATING.md](./MIGRATING.md), shipped in the package
34
35
  - 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
36
 
37
+ ### Changed
38
+ - 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)
39
+ - Size, measured and checked in CI: the quick start (`MagicPill` + `pill()`) adds about 5.3 kB of gzipped JavaScript and 2.3 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
40
+
41
+ ### Fixed (since 9.0.0-next.0)
42
+ - 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"]`
43
+ - 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
44
+ - On touchscreens, a tapped action no longer stays open: labels open on hover only on devices that can really hover. Keyboard focus, an expanded panel and the current page still open them everywhere
45
+ - When a notification takes the pill over (from the navbar, or the next one in the queue), its message no longer wraps one word per line while the pill grows: `<MagicPill>` shows new content closed first, then the pill opens around it
46
+ - Long text no longer looks clipped while the pill changes size. When the pill closes, its content fades out first, then the pill shrinks; when it opens, the pill grows first, then the content fades in
47
+ - When the app removes the host's base layer (e.g. `{showNavbar && <PillNavbar … />}`), the pill closes around it into a circle, then scales out, instead of losing its content at once and collapsing into a narrow oval
48
+ - The pill scales from its centre instead of the edge it sits on (see `--mp-scale-origin`)
49
+ - On touchscreens, a notification whose panel was opened and closed no longer stays until the next tap elsewhere. The countdown pauses for keyboard focus and for a mouse or pen hovering, not for a tap, and after a tap the panel gives the focus back without showing it as keyboard focus
50
+
36
51
  ### Removed
37
52
  - 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
53
  - 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.5 kB gzipped** to your app (5.3 kB of JavaScript + 2.3 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
 
@@ -339,12 +341,13 @@ Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-
339
341
  | `--mp-offset` / `--mp-z-index` | `1.5rem` from the viewport edges (plus safe areas) / `50` |
340
342
  | `--mp-backdrop` | the overlay's backdrop |
341
343
  | `--mp-duration-enter` / `--mp-duration-change` / `--mp-duration-exit` | `500ms` / `250ms` / `300ms` |
344
+ | `--mp-scale-origin` | `center`: where the pill pops in from and scales out to (e.g. `bottom` to come out of the edge) |
342
345
 
343
346
  The pill fits small screens: sizes are in `rem`, fixed pills stay inside the viewport and its safe areas, and long panels scroll.
344
347
 
345
348
  ## Accessibility
346
349
  - **Announcements:** each `<MagicPill>` has a polite live region that reads notifications out (or your `announce` text). A hidden pill leaves the accessibility tree.
347
- - **Time to act:** the countdown pauses on hover and keyboard focus, and while a panel is open.
350
+ - **Time to act:** the countdown pauses while a mouse hovers the pill, on keyboard focus, and while a panel is open. A tap doesn't pause it.
348
351
  - **Panels and modals:** they take and give back the focus, and close on Escape. The overlay is a native modal `<dialog>`.
349
352
  - **Accessible names:** every action has one (`label` is required), and icons are hidden from assistive technology.
350
353
  - **Motion and contrast:** with `prefers-reduced-motion`, shape changes become short fades. In forced-colours mode, the shapes keep visible outlines.
@@ -376,6 +379,7 @@ npm install
376
379
  npm run typecheck # TypeScript
377
380
  npm test # Vitest test suite
378
381
  npm run build # Builds dist/ with tsdown
382
+ npm run size # What an app ships, against the size budget (after a build)
379
383
  ```
380
384
 
381
385
  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,194 @@
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_inputModality = require("../utils/inputModality.js");
9
+ const require_usePillQueue = require("../store/usePillQueue.js");
10
+ const require_react = require("../utils/react.js");
11
+ const require_choreography = require("./choreography.js");
12
+ let react_jsx_runtime = require("react/jsx-runtime");
13
+
14
+ // src/MagicPill/MagicPill.tsx
15
+ const DEFAULT_DURATION = 5e3;
16
+ const VISUALLY_HIDDEN = {
17
+ position: "absolute",
18
+ width: 1,
19
+ height: 1,
20
+ margin: -1,
21
+ padding: 0,
22
+ overflow: "hidden",
23
+ clip: "rect(0 0 0 0)",
24
+ whiteSpace: "nowrap",
25
+ border: 0
26
+ };
27
+ const hasContent = (node) => node !== void 0 && node !== null && node !== false;
28
+ function useDocumentHidden() {
29
+ const [hidden, setHidden] = (0, react.useState)(false);
30
+ (0, react.useEffect)(() => {
31
+ const update = () => setHidden(document.visibilityState === "hidden");
32
+ update();
33
+ document.addEventListener("visibilitychange", update);
34
+ return () => document.removeEventListener("visibilitychange", update);
35
+ }, []);
36
+ return hidden;
37
+ }
38
+ /**
39
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
40
+ * notifications fed by pill(name), and a live region that announces them.
41
+ */
42
+ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, linkComponent, classNames, placement = "bottom", variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
43
+ const store = require_store.getStore(name);
44
+ const { current } = require_usePillQueue.usePillQueue(name);
45
+ const rootRef = (0, react.useRef)(null);
46
+ const ref = (0, react.useMemo)(() => require_react.mergeRefs(rootRef, forwardedRef), [forwardedRef]);
47
+ (0, react.useEffect)(() => store.registerHost(), [store]);
48
+ (0, react.useEffect)(require_inputModality.trackInputModality, []);
49
+ const hasBase = hasContent(children);
50
+ const lastBase = (0, react.useRef)(children);
51
+ if (hasBase) lastBase.current = children;
52
+ const target = (0, react.useMemo)(() => current ? {
53
+ kind: "notification",
54
+ item: current
55
+ } : hasBase ? require_choreography.BASE : idle === "rest" ? require_choreography.IDLE : require_choreography.NONE, [
56
+ current,
57
+ hasBase,
58
+ idle
59
+ ]);
60
+ const [displayed, setDisplayed] = (0, react.useState)(() => ({
61
+ scene: target.kind === "notification" ? require_choreography.NONE : target,
62
+ presence: target.kind === "base" ? "compact" : target.kind === "idle" ? "rest" : "hidden"
63
+ }));
64
+ const displayedRef = (0, react.useRef)(displayed);
65
+ displayedRef.current = displayed;
66
+ const followUps = (0, react.useRef)([]);
67
+ (0, react.useEffect)(() => {
68
+ const next = followUps.current.shift();
69
+ if (!next) return;
70
+ rootRef.current?.offsetWidth;
71
+ setDisplayed(next);
72
+ }, [displayed]);
73
+ (0, react.useEffect)(() => {
74
+ const current = displayedRef.current;
75
+ const timers = require_choreography.batchSteps(current, require_choreography.planSteps(current, target, require_choreography.readTimings(rootRef.current))).map(({ at, states }) => {
76
+ const apply = () => {
77
+ followUps.current = states.slice(1);
78
+ setDisplayed(states[0]);
79
+ };
80
+ if (at > 0) return setTimeout(apply, at);
81
+ apply();
82
+ });
83
+ return () => {
84
+ timers.forEach(clearTimeout);
85
+ followUps.current = [];
86
+ };
87
+ }, [target]);
88
+ const [hovered, setHovered] = (0, react.useState)(false);
89
+ const [focused, setFocused] = (0, react.useState)(false);
90
+ const documentHidden = useDocumentHidden();
91
+ (0, react.useEffect)(() => {
92
+ if (displayed.presence === "hidden") {
93
+ setHovered(false);
94
+ setFocused(false);
95
+ }
96
+ }, [displayed.presence]);
97
+ const shown = displayed.scene.kind === "notification" && require_choreography.isOpen(displayed.presence) ? displayed.scene.item : null;
98
+ const paused = hovered || focused || documentHidden || displayed.presence === "panel";
99
+ (0, react.useEffect)(() => {
100
+ if (!shown || paused) return;
101
+ const ms = shown.input.duration ?? duration;
102
+ if (!Number.isFinite(ms)) return;
103
+ const timer = setTimeout(() => store.dismiss(shown.id, "timeout"), ms);
104
+ return () => clearTimeout(timer);
105
+ }, [
106
+ shown,
107
+ paused,
108
+ duration,
109
+ store
110
+ ]);
111
+ const [announcement, setAnnouncement] = (0, react.useState)(null);
112
+ (0, react.useEffect)(() => {
113
+ if (!shown) return;
114
+ const { announce } = shown.input;
115
+ if (announce === false) return;
116
+ const root = rootRef.current;
117
+ const text = typeof announce === "string" ? announce : (root?.querySelector("[data-mp=\"message\"]") ?? root)?.textContent?.trim() ?? "";
118
+ if (text) setAnnouncement((previous) => previous?.key === shown ? previous : {
119
+ key: shown,
120
+ text
121
+ });
122
+ }, [shown]);
123
+ const handlePresenceChange = (next) => {
124
+ const { scene, presence } = displayedRef.current;
125
+ if (next === "hidden") {
126
+ if (scene.kind === "notification") store.dismiss(scene.item.id, "dismissed");
127
+ return;
128
+ }
129
+ if (require_choreography.isOpen(next) && require_choreography.isOpen(presence)) setDisplayed({
130
+ scene,
131
+ presence: next
132
+ });
133
+ };
134
+ const renderScene = (scene) => {
135
+ switch (scene.kind) {
136
+ case "base": return hasBase ? children : lastBase.current;
137
+ case "idle": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, { children: idleIcon });
138
+ case "notification": {
139
+ const { id, input } = scene.item;
140
+ if (input.render) return input.render({
141
+ id,
142
+ dismiss: () => store.dismiss(id, "dismissed")
143
+ });
144
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillNotification.NotificationContent, {
145
+ icon: input.icon,
146
+ message: input.message,
147
+ action: input.action,
148
+ panel: input.panel,
149
+ linkComponent,
150
+ classNames,
151
+ onAction: (event) => {
152
+ if (!event.defaultPrevented) store.dismiss(id, "action");
153
+ }
154
+ }, id);
155
+ }
156
+ default: return null;
157
+ }
158
+ };
159
+ const sceneVariant = displayed.scene.kind === "notification" ? displayed.scene.item.input.variant ?? variant : variant;
160
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
161
+ ...rest,
162
+ ref,
163
+ placement,
164
+ variant: sceneVariant,
165
+ presence: displayed.presence,
166
+ onPresenceChange: handlePresenceChange,
167
+ onPointerEnter: (event) => {
168
+ onPointerEnter?.(event);
169
+ if (event.pointerType !== "touch") setHovered(true);
170
+ },
171
+ onPointerLeave: (event) => {
172
+ onPointerLeave?.(event);
173
+ setHovered(false);
174
+ },
175
+ onFocus: (event) => {
176
+ onFocus?.(event);
177
+ if (require_inputModality.getInputModality() === "keyboard") setFocused(true);
178
+ },
179
+ onBlur: (event) => {
180
+ onBlur?.(event);
181
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
182
+ },
183
+ children: renderScene(displayed.scene)
184
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
185
+ role: "status",
186
+ "aria-live": "polite",
187
+ "aria-atomic": "true",
188
+ "data-mp": "announcer",
189
+ style: VISUALLY_HIDDEN,
190
+ children: announcement && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: announcement.text }, announcement.key.id + announcement.text)
191
+ })] });
192
+ });
193
+
194
+ module.exports = MagicPill;
@@ -1,2 +1,194 @@
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 { getInputModality, trackInputModality } from "../utils/inputModality.mjs";
9
+ import { usePillQueue } from "../store/usePillQueue.mjs";
10
+ import { mergeRefs } from "../utils/react.mjs";
11
+ import { BASE, IDLE, NONE, batchSteps, isOpen, planSteps, readTimings } from "./choreography.mjs";
12
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+
14
+ // src/MagicPill/MagicPill.tsx
15
+ const DEFAULT_DURATION = 5e3;
16
+ const VISUALLY_HIDDEN = {
17
+ position: "absolute",
18
+ width: 1,
19
+ height: 1,
20
+ margin: -1,
21
+ padding: 0,
22
+ overflow: "hidden",
23
+ clip: "rect(0 0 0 0)",
24
+ whiteSpace: "nowrap",
25
+ border: 0
26
+ };
27
+ const hasContent = (node) => node !== void 0 && node !== null && node !== false;
28
+ function useDocumentHidden() {
29
+ const [hidden, setHidden] = useState(false);
30
+ useEffect(() => {
31
+ const update = () => setHidden(document.visibilityState === "hidden");
32
+ update();
33
+ document.addEventListener("visibilitychange", update);
34
+ return () => document.removeEventListener("visibilitychange", update);
35
+ }, []);
36
+ return hidden;
37
+ }
38
+ /**
39
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
40
+ * notifications fed by pill(name), and a live region that announces them.
41
+ */
42
+ const MagicPill = forwardRef(function MagicPill({ name = "main", children, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, linkComponent, classNames, placement = "bottom", variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
43
+ const store = getStore(name);
44
+ const { current } = usePillQueue(name);
45
+ const rootRef = useRef(null);
46
+ const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);
47
+ useEffect(() => store.registerHost(), [store]);
48
+ useEffect(trackInputModality, []);
49
+ const hasBase = hasContent(children);
50
+ const lastBase = useRef(children);
51
+ if (hasBase) lastBase.current = children;
52
+ const target = useMemo(() => current ? {
53
+ kind: "notification",
54
+ item: current
55
+ } : hasBase ? BASE : idle === "rest" ? IDLE : NONE, [
56
+ current,
57
+ hasBase,
58
+ idle
59
+ ]);
60
+ const [displayed, setDisplayed] = useState(() => ({
61
+ scene: target.kind === "notification" ? NONE : target,
62
+ presence: target.kind === "base" ? "compact" : target.kind === "idle" ? "rest" : "hidden"
63
+ }));
64
+ const displayedRef = useRef(displayed);
65
+ displayedRef.current = displayed;
66
+ const followUps = useRef([]);
67
+ useEffect(() => {
68
+ const next = followUps.current.shift();
69
+ if (!next) return;
70
+ rootRef.current?.offsetWidth;
71
+ setDisplayed(next);
72
+ }, [displayed]);
73
+ useEffect(() => {
74
+ const current = displayedRef.current;
75
+ const timers = batchSteps(current, planSteps(current, target, readTimings(rootRef.current))).map(({ at, states }) => {
76
+ const apply = () => {
77
+ followUps.current = states.slice(1);
78
+ setDisplayed(states[0]);
79
+ };
80
+ if (at > 0) return setTimeout(apply, at);
81
+ apply();
82
+ });
83
+ return () => {
84
+ timers.forEach(clearTimeout);
85
+ followUps.current = [];
86
+ };
87
+ }, [target]);
88
+ const [hovered, setHovered] = useState(false);
89
+ const [focused, setFocused] = useState(false);
90
+ const documentHidden = useDocumentHidden();
91
+ useEffect(() => {
92
+ if (displayed.presence === "hidden") {
93
+ setHovered(false);
94
+ setFocused(false);
95
+ }
96
+ }, [displayed.presence]);
97
+ const shown = displayed.scene.kind === "notification" && isOpen(displayed.presence) ? displayed.scene.item : null;
98
+ const paused = hovered || focused || documentHidden || displayed.presence === "panel";
99
+ useEffect(() => {
100
+ if (!shown || paused) return;
101
+ const ms = shown.input.duration ?? duration;
102
+ if (!Number.isFinite(ms)) return;
103
+ const timer = setTimeout(() => store.dismiss(shown.id, "timeout"), ms);
104
+ return () => clearTimeout(timer);
105
+ }, [
106
+ shown,
107
+ paused,
108
+ duration,
109
+ store
110
+ ]);
111
+ const [announcement, setAnnouncement] = useState(null);
112
+ useEffect(() => {
113
+ if (!shown) return;
114
+ const { announce } = shown.input;
115
+ if (announce === false) return;
116
+ const root = rootRef.current;
117
+ const text = typeof announce === "string" ? announce : (root?.querySelector("[data-mp=\"message\"]") ?? root)?.textContent?.trim() ?? "";
118
+ if (text) setAnnouncement((previous) => previous?.key === shown ? previous : {
119
+ key: shown,
120
+ text
121
+ });
122
+ }, [shown]);
123
+ const handlePresenceChange = (next) => {
124
+ const { scene, presence } = displayedRef.current;
125
+ if (next === "hidden") {
126
+ if (scene.kind === "notification") store.dismiss(scene.item.id, "dismissed");
127
+ return;
128
+ }
129
+ if (isOpen(next) && isOpen(presence)) setDisplayed({
130
+ scene,
131
+ presence: next
132
+ });
133
+ };
134
+ const renderScene = (scene) => {
135
+ switch (scene.kind) {
136
+ case "base": return hasBase ? children : lastBase.current;
137
+ case "idle": return /* @__PURE__ */ jsx(PillIcon, { children: idleIcon });
138
+ case "notification": {
139
+ const { id, input } = scene.item;
140
+ if (input.render) return input.render({
141
+ id,
142
+ dismiss: () => store.dismiss(id, "dismissed")
143
+ });
144
+ return /* @__PURE__ */ jsx(NotificationContent, {
145
+ icon: input.icon,
146
+ message: input.message,
147
+ action: input.action,
148
+ panel: input.panel,
149
+ linkComponent,
150
+ classNames,
151
+ onAction: (event) => {
152
+ if (!event.defaultPrevented) store.dismiss(id, "action");
153
+ }
154
+ }, id);
155
+ }
156
+ default: return null;
157
+ }
158
+ };
159
+ const sceneVariant = displayed.scene.kind === "notification" ? displayed.scene.item.input.variant ?? variant : variant;
160
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Pill, {
161
+ ...rest,
162
+ ref,
163
+ placement,
164
+ variant: sceneVariant,
165
+ presence: displayed.presence,
166
+ onPresenceChange: handlePresenceChange,
167
+ onPointerEnter: (event) => {
168
+ onPointerEnter?.(event);
169
+ if (event.pointerType !== "touch") setHovered(true);
170
+ },
171
+ onPointerLeave: (event) => {
172
+ onPointerLeave?.(event);
173
+ setHovered(false);
174
+ },
175
+ onFocus: (event) => {
176
+ onFocus?.(event);
177
+ if (getInputModality() === "keyboard") setFocused(true);
178
+ },
179
+ onBlur: (event) => {
180
+ onBlur?.(event);
181
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
182
+ },
183
+ children: renderScene(displayed.scene)
184
+ }), /* @__PURE__ */ jsx("div", {
185
+ role: "status",
186
+ "aria-live": "polite",
187
+ "aria-atomic": "true",
188
+ "data-mp": "announcer",
189
+ style: VISUALLY_HIDDEN,
190
+ children: announcement && /* @__PURE__ */ jsx("span", { children: announcement.text }, announcement.key.id + announcement.text)
191
+ })] });
192
+ });
193
+
194
+ export { MagicPill as default };
@@ -1,2 +1,132 @@
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: fade it out, 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.fade + 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.fade + 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
+ /**
61
+ * Groups the steps by the time they're due. Steps due at the same time
62
+ * collapse into the last one, except new content swapped in while the pill
63
+ * is closed: it's shown closed first, so the stylesheet can transition it
64
+ * open (otherwise it appears at the circle's width and wraps word by word).
65
+ */
66
+ function batchSteps(current, steps) {
67
+ const batches = [];
68
+ let at = 0;
69
+ let scene = current.scene;
70
+ let unshown = false;
71
+ for (const { delay, scene: nextScene, presence } of steps) {
72
+ at += delay;
73
+ const state = {
74
+ scene: nextScene,
75
+ presence
76
+ };
77
+ const swapped = nextScene !== scene;
78
+ scene = nextScene;
79
+ const batch = batches[batches.length - 1];
80
+ if (batch && batch.at === at) {
81
+ if (unshown && isOpen(presence)) {
82
+ batch.states.push(state);
83
+ unshown = false;
84
+ } else {
85
+ batch.states[batch.states.length - 1] = state;
86
+ unshown = (unshown || swapped) && !isOpen(presence);
87
+ }
88
+ } else {
89
+ batches.push({
90
+ at,
91
+ states: [state]
92
+ });
93
+ unshown = swapped && !isOpen(presence);
94
+ }
95
+ }
96
+ return batches;
97
+ }
98
+ /** "500ms" or "0.5s" → 500; anything else → the fallback. */
99
+ function parseDuration(value, fallback) {
100
+ const match = /^\s*([\d.]+)(ms|s)\s*$/.exec(value);
101
+ if (!match) return fallback;
102
+ const amount = Number.parseFloat(match[1]);
103
+ return match[2] === "s" ? amount * 1e3 : amount;
104
+ }
105
+ /** The timings the stylesheet uses for this pill, or its defaults (e.g. when unstyled). */
106
+ function readTimings(element) {
107
+ const style = element ? getComputedStyle(element) : null;
108
+ const read = (name, fallback) => parseDuration(style?.getPropertyValue(name) ?? "", fallback);
109
+ const reduced = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
110
+ return reduced ? {
111
+ enter: 0,
112
+ fade: 0,
113
+ change: 0,
114
+ exit: 150,
115
+ reduced
116
+ } : {
117
+ enter: read("--_mp-enter", 500),
118
+ fade: read("--_mp-fade", 150),
119
+ change: read("--_mp-change", 250),
120
+ exit: read("--_mp-exit", 300),
121
+ reduced
122
+ };
123
+ }
124
+
125
+ exports.BASE = BASE;
126
+ exports.IDLE = IDLE;
127
+ exports.NONE = NONE;
128
+ exports.batchSteps = batchSteps;
129
+ exports.isOpen = isOpen;
130
+ exports.parseDuration = parseDuration;
131
+ exports.planSteps = planSteps;
132
+ exports.readTimings = readTimings;