magic-pill 8.0.3 → 9.0.0-next.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.
Files changed (190) hide show
  1. package/CHANGELOG.md +120 -31
  2. package/MIGRATING.md +224 -0
  3. package/README.md +322 -252
  4. package/dist/MagicPill/MagicPill.d.mts +27 -0
  5. package/dist/MagicPill/MagicPill.d.ts +27 -0
  6. package/dist/MagicPill/MagicPill.js +2 -0
  7. package/dist/MagicPill/MagicPill.js.map +1 -0
  8. package/dist/MagicPill/MagicPill.mjs +2 -0
  9. package/dist/MagicPill/MagicPill.mjs.map +1 -0
  10. package/dist/MagicPill/choreography.js +2 -0
  11. package/dist/MagicPill/choreography.js.map +1 -0
  12. package/dist/MagicPill/choreography.mjs +2 -0
  13. package/dist/MagicPill/choreography.mjs.map +1 -0
  14. package/dist/Pill/Pill.d.mts +7 -0
  15. package/dist/Pill/Pill.d.ts +7 -0
  16. package/dist/Pill/Pill.js +2 -0
  17. package/dist/Pill/Pill.js.map +1 -0
  18. package/dist/Pill/Pill.mjs +2 -0
  19. package/dist/Pill/Pill.mjs.map +1 -0
  20. package/dist/Pill/PillAction.d.mts +7 -0
  21. package/dist/Pill/PillAction.d.ts +7 -0
  22. package/dist/Pill/PillAction.js +2 -0
  23. package/dist/Pill/PillAction.js.map +1 -0
  24. package/dist/Pill/PillAction.mjs +2 -0
  25. package/dist/Pill/PillAction.mjs.map +1 -0
  26. package/dist/Pill/PillContext.d.mts +3 -0
  27. package/dist/Pill/PillContext.d.ts +3 -0
  28. package/dist/Pill/PillContext.js +2 -0
  29. package/dist/Pill/PillContext.js.map +1 -0
  30. package/dist/Pill/PillContext.mjs +2 -0
  31. package/dist/Pill/PillContext.mjs.map +1 -0
  32. package/dist/Pill/PillPanel.d.mts +9 -0
  33. package/dist/Pill/PillPanel.d.ts +9 -0
  34. package/dist/Pill/PillPanel.js +2 -0
  35. package/dist/Pill/PillPanel.js.map +1 -0
  36. package/dist/Pill/PillPanel.mjs +2 -0
  37. package/dist/Pill/PillPanel.mjs.map +1 -0
  38. package/dist/Pill/parts.d.mts +10 -0
  39. package/dist/Pill/parts.d.ts +10 -0
  40. package/dist/Pill/parts.js +2 -0
  41. package/dist/Pill/parts.js.map +1 -0
  42. package/dist/Pill/parts.mjs +2 -0
  43. package/dist/Pill/parts.mjs.map +1 -0
  44. package/dist/Pill/types.d.mts +88 -0
  45. package/dist/Pill/types.d.ts +88 -0
  46. package/dist/PillNavbar/PillNavbar.d.mts +31 -0
  47. package/dist/PillNavbar/PillNavbar.d.ts +31 -0
  48. package/dist/PillNavbar/PillNavbar.js +2 -0
  49. package/dist/PillNavbar/PillNavbar.js.map +1 -0
  50. package/dist/PillNavbar/PillNavbar.mjs +2 -0
  51. package/dist/PillNavbar/PillNavbar.mjs.map +1 -0
  52. package/dist/PillNavbar/matchPath.d.mts +2 -0
  53. package/dist/PillNavbar/matchPath.d.ts +2 -0
  54. package/dist/PillNavbar/matchPath.js +2 -0
  55. package/dist/PillNavbar/matchPath.js.map +1 -0
  56. package/dist/PillNavbar/matchPath.mjs +2 -0
  57. package/dist/PillNavbar/matchPath.mjs.map +1 -0
  58. package/dist/PillNotification/PillNotification.d.mts +51 -0
  59. package/dist/PillNotification/PillNotification.d.ts +51 -0
  60. package/dist/PillNotification/PillNotification.js +2 -0
  61. package/dist/PillNotification/PillNotification.js.map +1 -0
  62. package/dist/PillNotification/PillNotification.mjs +2 -0
  63. package/dist/PillNotification/PillNotification.mjs.map +1 -0
  64. package/dist/icons/ArrowIcon.d.mts +4 -0
  65. package/dist/icons/ArrowIcon.d.ts +4 -0
  66. package/dist/icons/ArrowIcon.js +2 -0
  67. package/dist/icons/ArrowIcon.js.map +1 -0
  68. package/dist/icons/ArrowIcon.mjs +2 -0
  69. package/dist/icons/ArrowIcon.mjs.map +1 -0
  70. package/dist/icons/BoxIcon.d.mts +4 -0
  71. package/dist/icons/BoxIcon.d.ts +4 -0
  72. package/dist/icons/BoxIcon.js +2 -0
  73. package/dist/icons/BoxIcon.js.map +1 -0
  74. package/dist/icons/BoxIcon.mjs +2 -0
  75. package/dist/icons/BoxIcon.mjs.map +1 -0
  76. package/dist/icons/CheckIcon.d.mts +4 -0
  77. package/dist/icons/CheckIcon.d.ts +4 -0
  78. package/dist/icons/CheckIcon.js +2 -0
  79. package/dist/icons/CheckIcon.js.map +1 -0
  80. package/dist/icons/CheckIcon.mjs +2 -0
  81. package/dist/icons/CheckIcon.mjs.map +1 -0
  82. package/dist/icons/CloseIcon.d.mts +4 -0
  83. package/dist/icons/CloseIcon.d.ts +4 -0
  84. package/dist/icons/CloseIcon.js +2 -0
  85. package/dist/icons/CloseIcon.js.map +1 -0
  86. package/dist/icons/CloseIcon.mjs +2 -0
  87. package/dist/icons/CloseIcon.mjs.map +1 -0
  88. package/dist/icons/CouponIcon.d.mts +4 -0
  89. package/dist/icons/CouponIcon.d.ts +4 -0
  90. package/dist/icons/CouponIcon.js +2 -0
  91. package/dist/icons/CouponIcon.js.map +1 -0
  92. package/dist/icons/CouponIcon.mjs +2 -0
  93. package/dist/icons/CouponIcon.mjs.map +1 -0
  94. package/dist/icons/DocumentIcon.d.mts +4 -0
  95. package/dist/icons/DocumentIcon.d.ts +4 -0
  96. package/dist/icons/DocumentIcon.js +2 -0
  97. package/dist/icons/DocumentIcon.js.map +1 -0
  98. package/dist/icons/DocumentIcon.mjs +2 -0
  99. package/dist/icons/DocumentIcon.mjs.map +1 -0
  100. package/dist/icons/HelpIcon.d.mts +4 -0
  101. package/dist/icons/HelpIcon.d.ts +4 -0
  102. package/dist/icons/HelpIcon.js +2 -0
  103. package/dist/icons/HelpIcon.js.map +1 -0
  104. package/dist/icons/HelpIcon.mjs +2 -0
  105. package/dist/icons/HelpIcon.mjs.map +1 -0
  106. package/dist/icons/InfoIcon.d.mts +4 -0
  107. package/dist/icons/InfoIcon.d.ts +4 -0
  108. package/dist/icons/InfoIcon.js +2 -0
  109. package/dist/icons/InfoIcon.js.map +1 -0
  110. package/dist/icons/InfoIcon.mjs +2 -0
  111. package/dist/icons/InfoIcon.mjs.map +1 -0
  112. package/dist/icons/MailIcon.d.mts +4 -0
  113. package/dist/icons/MailIcon.d.ts +4 -0
  114. package/dist/icons/MailIcon.js +2 -0
  115. package/dist/icons/MailIcon.js.map +1 -0
  116. package/dist/icons/MailIcon.mjs +2 -0
  117. package/dist/icons/MailIcon.mjs.map +1 -0
  118. package/dist/icons/PhoneIcon.d.mts +4 -0
  119. package/dist/icons/PhoneIcon.d.ts +4 -0
  120. package/dist/icons/PhoneIcon.js +2 -0
  121. package/dist/icons/PhoneIcon.js.map +1 -0
  122. package/dist/icons/PhoneIcon.mjs +2 -0
  123. package/dist/icons/PhoneIcon.mjs.map +1 -0
  124. package/dist/icons/PlusIcon.d.mts +4 -0
  125. package/dist/icons/PlusIcon.d.ts +4 -0
  126. package/dist/icons/PlusIcon.js +2 -0
  127. package/dist/icons/PlusIcon.js.map +1 -0
  128. package/dist/icons/PlusIcon.mjs +2 -0
  129. package/dist/icons/PlusIcon.mjs.map +1 -0
  130. package/dist/icons/UndoIcon.d.mts +4 -0
  131. package/dist/icons/UndoIcon.d.ts +4 -0
  132. package/dist/icons/UndoIcon.js +2 -0
  133. package/dist/icons/UndoIcon.js.map +1 -0
  134. package/dist/icons/UndoIcon.mjs +2 -0
  135. package/dist/icons/UndoIcon.mjs.map +1 -0
  136. package/dist/icons/types.d.mts +3 -0
  137. package/dist/icons/types.d.ts +3 -0
  138. package/dist/index.d.mts +25 -0
  139. package/dist/index.d.ts +25 -5
  140. package/dist/index.js +1 -2
  141. package/dist/index.mjs +1 -0
  142. package/dist/store/store.d.mts +63 -0
  143. package/dist/store/store.d.ts +63 -0
  144. package/dist/store/store.js +2 -0
  145. package/dist/store/store.js.map +1 -0
  146. package/dist/store/store.mjs +2 -0
  147. package/dist/store/store.mjs.map +1 -0
  148. package/dist/store/usePillQueue.d.mts +6 -0
  149. package/dist/store/usePillQueue.d.ts +6 -0
  150. package/dist/store/usePillQueue.js +2 -0
  151. package/dist/store/usePillQueue.js.map +1 -0
  152. package/dist/store/usePillQueue.mjs +2 -0
  153. package/dist/store/usePillQueue.mjs.map +1 -0
  154. package/dist/styles.css +427 -0
  155. package/dist/utils/react.js +2 -0
  156. package/dist/utils/react.js.map +1 -0
  157. package/dist/utils/react.mjs +2 -0
  158. package/dist/utils/react.mjs.map +1 -0
  159. package/dist/utils/url.js +2 -0
  160. package/dist/utils/url.js.map +1 -0
  161. package/dist/utils/url.mjs +2 -0
  162. package/dist/utils/url.mjs.map +1 -0
  163. package/package.json +37 -24
  164. package/dist/MagicPill.d.ts +0 -8
  165. package/dist/Navbar/Navbar.d.ts +0 -9
  166. package/dist/Notification/Notification.d.ts +0 -9
  167. package/dist/defaultPillData.d.ts +0 -2
  168. package/dist/icons/arrow_label.d.ts +0 -3
  169. package/dist/icons/box_label.d.ts +0 -3
  170. package/dist/icons/checkmark.d.ts +0 -3
  171. package/dist/icons/checkmark_label.d.ts +0 -3
  172. package/dist/icons/coupon.d.ts +0 -3
  173. package/dist/icons/cross_label.d.ts +0 -3
  174. package/dist/icons/info.d.ts +0 -3
  175. package/dist/icons/mail_label.d.ts +0 -3
  176. package/dist/icons/plus_label.d.ts +0 -3
  177. package/dist/icons/questionmark.d.ts +0 -3
  178. package/dist/icons/quotation_label.d.ts +0 -3
  179. package/dist/icons/tel_label.d.ts +0 -3
  180. package/dist/icons/undo_label.d.ts +0 -3
  181. package/dist/index.esm.js +0 -2
  182. package/dist/index.esm.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/magicpill.css +0 -267
  185. package/dist/types/index.d.ts +0 -3
  186. package/dist/types/magicPill.d.ts +0 -50
  187. package/dist/types/navbar.d.ts +0 -27
  188. package/dist/types/notification.d.ts +0 -140
  189. package/dist/utils/handlers.d.ts +0 -19
  190. package/dist/utils/icons.d.ts +0 -18
@@ -0,0 +1,27 @@
1
+ import { ReactNode } from "react";
2
+ import { LinkComponent, PillProps } from "../Pill/types.mjs";
3
+ import { PillNotificationClassNames } from "../PillNotification/PillNotification.mjs";
4
+ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children"> {
5
+ /** Default "main". Two hosts with the same name warn in development. */
6
+ name?: string;
7
+ /**
8
+ * The base layer (e.g. a <PillNavbar>), shown whenever no notification is.
9
+ * Notifications take the pill over, then it returns to this content.
10
+ */
11
+ children?: ReactNode;
12
+ /** Default display time for notifications, in ms. Default 5000. */
13
+ duration?: number;
14
+ /** With no base layer and nothing queued: hide (default) or rest as a circle. */
15
+ idle?: "hidden" | "rest";
16
+ /** The icon shown when `idle="rest"`. */
17
+ idleIcon?: ReactNode;
18
+ /** Passed to notification actions that have an `href`. */
19
+ linkComponent?: LinkComponent;
20
+ classNames?: PillNotificationClassNames;
21
+ }
22
+ /**
23
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
24
+ * notifications fed by pill(name), and a live region that announces them.
25
+ */
26
+ declare const MagicPill: import("react").ForwardRefExoticComponent<MagicPillProps & import("react").RefAttributes<HTMLElement>>;
27
+ export { MagicPill as default };
@@ -0,0 +1,27 @@
1
+ import { ReactNode } from "react";
2
+ import { LinkComponent, PillProps } from "../Pill/types.js";
3
+ import { PillNotificationClassNames } from "../PillNotification/PillNotification.js";
4
+ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children"> {
5
+ /** Default "main". Two hosts with the same name warn in development. */
6
+ name?: string;
7
+ /**
8
+ * The base layer (e.g. a <PillNavbar>), shown whenever no notification is.
9
+ * Notifications take the pill over, then it returns to this content.
10
+ */
11
+ children?: ReactNode;
12
+ /** Default display time for notifications, in ms. Default 5000. */
13
+ duration?: number;
14
+ /** With no base layer and nothing queued: hide (default) or rest as a circle. */
15
+ idle?: "hidden" | "rest";
16
+ /** The icon shown when `idle="rest"`. */
17
+ idleIcon?: ReactNode;
18
+ /** Passed to notification actions that have an `href`. */
19
+ linkComponent?: LinkComponent;
20
+ classNames?: PillNotificationClassNames;
21
+ }
22
+ /**
23
+ * The batteries-included pill: a <Pill> with a base layer, a queue of
24
+ * notifications fed by pill(name), and a live region that announces them.
25
+ */
26
+ declare const MagicPill: import("react").ForwardRefExoticComponent<MagicPillProps & import("react").RefAttributes<HTMLElement>>;
27
+ export { MagicPill as default };
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MagicPill.js","names":["useState","useEffect","forwardRef","getStore","usePillQueue","useRef","useMemo","mergeRefs","BASE","IDLE","NONE","planSteps","readTimings","isOpen","PillIcon","NotificationContent","Pill","react","require_Pill","require_parts","require_PillNotification","require_store","require_usePillQueue","require_react","require_choreography","react_jsx_runtime","VISUALLY_HIDDEN","hasContent","node","useDocumentHidden","hidden","setHidden","update","MagicPill","name","children","duration","idle","idleIcon","linkComponent","classNames","placement","variant","onMouseEnter","onMouseLeave","onFocus","onBlur","rest","forwardedRef","store","current","rootRef","ref","hasBase","target","displayed","setDisplayed","displayedRef","steps","timers","at","step","index","next","apply","hovered","setHovered","focused","setFocused","documentHidden","shown","paused","ms","timer","announcement","setAnnouncement","announce","root","text","previous","handlePresenceChange","scene","presence","renderScene","id","input","event","sceneVariant"],"sources":["../../src/MagicPill/MagicPill.tsx"],"sourcesContent":["\"use client\"\nimport {\n forwardRef,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type FocusEvent,\n type MouseEvent,\n type ReactNode,\n} from \"react\";\n\nimport Pill from \"../Pill/Pill\";\nimport { PillIcon } from \"../Pill/parts\";\nimport type { LinkComponent, PillPresence, PillProps } from \"../Pill/types\";\nimport { NotificationContent, type PillNotificationClassNames } from \"../PillNotification/PillNotification\";\nimport { getStore, type QueuedNotification } from \"../store/store\";\nimport { usePillQueue } from \"../store/usePillQueue\";\nimport { mergeRefs } from \"../utils/react\";\nimport {\n BASE,\n IDLE,\n NONE,\n isOpen,\n planSteps,\n readTimings,\n type Displayed,\n type Scene,\n} from \"./choreography\";\n\nexport interface MagicPillProps\n extends Omit<PillProps, \"presence\" | \"defaultPresence\" | \"onPresenceChange\" | \"children\"> {\n /** Default \"main\". Two hosts with the same name warn in development. */\n name?: string;\n /**\n * The base layer (e.g. a <PillNavbar>), shown whenever no notification is.\n * Notifications take the pill over, then it returns to this content.\n */\n children?: ReactNode;\n /** Default display time for notifications, in ms. Default 5000. */\n duration?: number;\n /** With no base layer and nothing queued: hide (default) or rest as a circle. */\n idle?: \"hidden\" | \"rest\";\n /** The icon shown when `idle=\"rest\"`. */\n idleIcon?: ReactNode;\n /** Passed to notification actions that have an `href`. */\n linkComponent?: LinkComponent;\n classNames?: PillNotificationClassNames;\n}\n\nconst DEFAULT_DURATION = 5000;\n\n// Readable by screen readers, invisible on screen, and independent of the\n// stylesheet (it must work for unstyled pills too)\nconst VISUALLY_HIDDEN: CSSProperties = {\n position: \"absolute\",\n width: 1,\n height: 1,\n margin: -1,\n padding: 0,\n overflow: \"hidden\",\n clip: \"rect(0 0 0 0)\",\n whiteSpace: \"nowrap\",\n border: 0,\n};\n\nconst hasContent = (node: ReactNode) => node !== undefined && node !== null && node !== false;\n\nfunction useDocumentHidden(): boolean {\n const [hidden, setHidden] = useState(false);\n useEffect(() => {\n const update = () => setHidden(document.visibilityState === \"hidden\");\n update();\n document.addEventListener(\"visibilitychange\", update);\n return () => document.removeEventListener(\"visibilitychange\", update);\n }, []);\n return hidden;\n}\n\n/**\n * The batteries-included pill: a <Pill> with a base layer, a queue of\n * notifications fed by pill(name), and a live region that announces them.\n */\nconst MagicPill = forwardRef<HTMLElement, MagicPillProps>(function MagicPill(\n {\n name = \"main\",\n children,\n duration = DEFAULT_DURATION,\n idle = \"hidden\",\n idleIcon,\n linkComponent,\n classNames,\n placement = \"bottom\",\n variant,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n ...rest\n },\n forwardedRef,\n) {\n const store = getStore(name);\n const { current } = usePillQueue(name);\n const rootRef = useRef<HTMLElement | null>(null);\n const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);\n\n useEffect(() => store.registerHost(), [store]);\n\n // What the pill should show now. Stable objects, so a re-render isn't a change.\n const hasBase = hasContent(children);\n const target = useMemo<Scene>(\n () => (current ? { kind: \"notification\", item: current } : hasBase ? BASE : idle === \"rest\" ? IDLE : NONE),\n [current, hasBase, idle],\n );\n\n // What it shows, moved towards the target one timed step at a time\n const [displayed, setDisplayed] = useState<Displayed>(() => ({\n scene: target.kind === \"notification\" ? NONE : target,\n presence: target.kind === \"base\" ? \"compact\" : target.kind === \"idle\" ? \"rest\" : \"hidden\",\n }));\n const displayedRef = useRef(displayed);\n displayedRef.current = displayed;\n\n useEffect(() => {\n const steps = planSteps(displayedRef.current, target, readTimings(rootRef.current));\n const timers: ReturnType<typeof setTimeout>[] = [];\n let at = 0;\n steps.forEach((step, index) => {\n at += step.delay;\n // Steps due at the same time collapse into the last one\n const next = steps[index + 1];\n if (next && next.delay === 0) return;\n const apply = () => setDisplayed({ scene: step.scene, presence: step.presence });\n if (at === 0) {\n apply();\n } else {\n timers.push(setTimeout(apply, at));\n }\n });\n return () => timers.forEach(clearTimeout);\n }, [target]);\n\n // Pauses: pointer, keyboard focus, an open panel, a hidden tab (Y3)\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const documentHidden = useDocumentHidden();\n useEffect(() => {\n // An inert pill loses focus without always firing blur\n if (displayed.presence === \"hidden\") {\n setHovered(false);\n setFocused(false);\n }\n }, [displayed.presence]);\n\n const shown: QueuedNotification | null =\n displayed.scene.kind === \"notification\" && isOpen(displayed.presence) ? displayed.scene.item : null;\n const paused = hovered || focused || documentHidden || displayed.presence === \"panel\";\n\n // The countdown starts once the notification is fully shown, and again from\n // the full duration after each pause, or when its content is updated\n useEffect(() => {\n if (!shown || paused) return;\n const ms = shown.input.duration ?? duration;\n if (!Number.isFinite(ms)) return;\n const timer = setTimeout(() => store.dismiss(shown.id, \"timeout\"), ms);\n return () => clearTimeout(timer);\n }, [shown, paused, duration, store]);\n\n // Announcements go through a separate live region, so the pill itself can\n // leave the accessibility tree when hidden (Y1, Y5)\n const [announcement, setAnnouncement] = useState<{ key: QueuedNotification; text: string } | null>(null);\n useEffect(() => {\n if (!shown) return;\n const { announce } = shown.input;\n if (announce === false) return;\n const root = rootRef.current;\n const text =\n typeof announce === \"string\"\n ? announce\n : (root?.querySelector('[data-mp=\"message\"]') ?? root)?.textContent?.trim() ?? \"\";\n if (text) setAnnouncement((previous) => (previous?.key === shown ? previous : { key: shown, text }));\n }, [shown]);\n\n const handlePresenceChange = (next: PillPresence) => {\n const { scene, presence } = displayedRef.current;\n if (next === \"hidden\") {\n // Escape on an overlay, for instance: that's a dismissal\n if (scene.kind === \"notification\") store.dismiss(scene.item.id, \"dismissed\");\n return;\n }\n if (isOpen(next) && isOpen(presence)) {\n setDisplayed({ scene, presence: next });\n }\n };\n\n const renderScene = (scene: Scene): ReactNode => {\n switch (scene.kind) {\n case \"base\":\n return children;\n case \"idle\":\n return <PillIcon>{idleIcon}</PillIcon>;\n case \"notification\": {\n const { id, input } = scene.item;\n if (input.render) {\n return input.render({ id, dismiss: () => store.dismiss(id, \"dismissed\") });\n }\n return (\n <NotificationContent\n key={id}\n icon={input.icon}\n message={input.message}\n action={input.action}\n panel={input.panel}\n linkComponent={linkComponent}\n classNames={classNames}\n onAction={(event: MouseEvent<HTMLElement>) => {\n if (!event.defaultPrevented) store.dismiss(id, \"action\");\n }}\n />\n );\n }\n default:\n return null;\n }\n };\n\n const sceneVariant =\n displayed.scene.kind === \"notification\" ? (displayed.scene.item.input.variant ?? variant) : variant;\n\n return (\n <>\n <Pill\n {...rest}\n ref={ref}\n placement={placement}\n variant={sceneVariant}\n presence={displayed.presence}\n onPresenceChange={handlePresenceChange}\n onMouseEnter={(event) => {\n onMouseEnter?.(event);\n setHovered(true);\n }}\n onMouseLeave={(event) => {\n onMouseLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event) => {\n onFocus?.(event);\n setFocused(true);\n }}\n onBlur={(event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n // Focus moving between elements inside the pill keeps it paused\n setFocused(event.currentTarget.contains(event.relatedTarget as Node | null));\n }}\n >\n {renderScene(displayed.scene)}\n </Pill>\n <div role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-mp=\"announcer\" style={VISUALLY_HIDDEN}>\n {announcement && <span key={announcement.key.id + announcement.text}>{announcement.text}</span>}\n </div>\n </>\n );\n});\n\nexport default MagicPill;\n"],"mappings":"A,gUAmDA,MAIM0B,EAAiC,CACrC,SAAU,WACV,MAAO,EACP,OAAQ,EACR,OAAQ,GACR,QAAS,EACT,SAAU,SACV,KAAM,gBACN,WAAY,SACZ,OAAQ,CACV,EAEMC,EAAcC,GAAoBA,GAA+B,MAAQA,IAAS,GAExF,SAASC,GAA6B,CACpC,GAAM,CAACC,EAAQC,IAAA,EAAa/B,EAAAA,SAAAA,CAAS,EAAK,EAO1C,OANAC,EAAAA,EAAAA,UAAAA,KAAgB,CACd,IAAM+B,MAAeD,EAAU,SAAS,kBAAoB,QAAQ,EAGpE,OAFAC,EAAO,EACP,SAAS,iBAAiB,mBAAoBA,CAAM,MACvC,SAAS,oBAAoB,mBAAoBA,CAAM,CACtE,EAAG,CAAC,CAAC,EACEF,CACT,CAMA,MAAMG,GAAA,EAAY/B,EAAAA,WAAAA,CAAwC,SACxD,CACEgC,OAAO,OACPC,WACAC,WAAW,IACXC,OAAO,SACPC,WACAC,gBACAC,aACAC,YAAY,SACZC,UACAC,eACAC,eACAC,UACAC,SACA,GAAGC,GAELC,EACA,CACA,IAAMC,EAAQ9C,EAAAA,SAAS+B,CAAI,EACrB,CAAEgB,WAAY9C,EAAAA,aAAa8B,CAAI,EAC/BiB,GAAA,EAAU9C,EAAAA,OAAAA,CAA2B,IAAI,EACzC+C,GAAA,EAAM9C,EAAAA,QAAAA,KAAcC,EAAAA,UAAU4C,EAASH,CAAY,EAAG,CAACA,CAAY,CAAC,GAE1E/C,EAAAA,EAAAA,UAAAA,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AAY5B,EAAU,KAAK,CACxB,CAAA,EACN,iBAAA,EAAA9B,EAAA,IAAA,CAAC,MAAD,CAAK,KAAK,SAAS,YAAU,SAAS,cAAY,OAAO,UAAQ,YAAY,MAAOC,EACjF,SAAAgD,GAAgB,iBAAA,EAAAjD,EAAA,IAAA,CAAC,OAAD,CAAA,SAAqDiD,EAAa,IAAW,EAAlEA,EAAa,IAAI,GAAKA,EAAa,IAA+B,CAC3F,CAAA,CACL,CAAA,CAAA,CAEN,CAAC,E"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MagicPill.mjs","names":["forwardRef","useEffect","useMemo","useRef","useState","Pill","PillIcon","NotificationContent","getStore","usePillQueue","mergeRefs","BASE","IDLE","NONE","isOpen","planSteps","readTimings","Fragment","jsx","jsxs","VISUALLY_HIDDEN","hasContent","node","useDocumentHidden","hidden","setHidden","update","MagicPill","name","children","duration","idle","idleIcon","linkComponent","classNames","placement","variant","onMouseEnter","onMouseLeave","onFocus","onBlur","rest","forwardedRef","store","current","rootRef","ref","hasBase","target","displayed","setDisplayed","displayedRef","steps","timers","at","step","index","next","apply","hovered","setHovered","focused","setFocused","documentHidden","shown","paused","ms","timer","announcement","setAnnouncement","announce","root","text","previous","handlePresenceChange","scene","presence","renderScene","id","input","event","sceneVariant"],"sources":["../../src/MagicPill/MagicPill.tsx"],"sourcesContent":["\"use client\"\nimport {\n forwardRef,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type FocusEvent,\n type MouseEvent,\n type ReactNode,\n} from \"react\";\n\nimport Pill from \"../Pill/Pill\";\nimport { PillIcon } from \"../Pill/parts\";\nimport type { LinkComponent, PillPresence, PillProps } from \"../Pill/types\";\nimport { NotificationContent, type PillNotificationClassNames } from \"../PillNotification/PillNotification\";\nimport { getStore, type QueuedNotification } from \"../store/store\";\nimport { usePillQueue } from \"../store/usePillQueue\";\nimport { mergeRefs } from \"../utils/react\";\nimport {\n BASE,\n IDLE,\n NONE,\n isOpen,\n planSteps,\n readTimings,\n type Displayed,\n type Scene,\n} from \"./choreography\";\n\nexport interface MagicPillProps\n extends Omit<PillProps, \"presence\" | \"defaultPresence\" | \"onPresenceChange\" | \"children\"> {\n /** Default \"main\". Two hosts with the same name warn in development. */\n name?: string;\n /**\n * The base layer (e.g. a <PillNavbar>), shown whenever no notification is.\n * Notifications take the pill over, then it returns to this content.\n */\n children?: ReactNode;\n /** Default display time for notifications, in ms. Default 5000. */\n duration?: number;\n /** With no base layer and nothing queued: hide (default) or rest as a circle. */\n idle?: \"hidden\" | \"rest\";\n /** The icon shown when `idle=\"rest\"`. */\n idleIcon?: ReactNode;\n /** Passed to notification actions that have an `href`. */\n linkComponent?: LinkComponent;\n classNames?: PillNotificationClassNames;\n}\n\nconst DEFAULT_DURATION = 5000;\n\n// Readable by screen readers, invisible on screen, and independent of the\n// stylesheet (it must work for unstyled pills too)\nconst VISUALLY_HIDDEN: CSSProperties = {\n position: \"absolute\",\n width: 1,\n height: 1,\n margin: -1,\n padding: 0,\n overflow: \"hidden\",\n clip: \"rect(0 0 0 0)\",\n whiteSpace: \"nowrap\",\n border: 0,\n};\n\nconst hasContent = (node: ReactNode) => node !== undefined && node !== null && node !== false;\n\nfunction useDocumentHidden(): boolean {\n const [hidden, setHidden] = useState(false);\n useEffect(() => {\n const update = () => setHidden(document.visibilityState === \"hidden\");\n update();\n document.addEventListener(\"visibilitychange\", update);\n return () => document.removeEventListener(\"visibilitychange\", update);\n }, []);\n return hidden;\n}\n\n/**\n * The batteries-included pill: a <Pill> with a base layer, a queue of\n * notifications fed by pill(name), and a live region that announces them.\n */\nconst MagicPill = forwardRef<HTMLElement, MagicPillProps>(function MagicPill(\n {\n name = \"main\",\n children,\n duration = DEFAULT_DURATION,\n idle = \"hidden\",\n idleIcon,\n linkComponent,\n classNames,\n placement = \"bottom\",\n variant,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n ...rest\n },\n forwardedRef,\n) {\n const store = getStore(name);\n const { current } = usePillQueue(name);\n const rootRef = useRef<HTMLElement | null>(null);\n const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);\n\n useEffect(() => store.registerHost(), [store]);\n\n // What the pill should show now. Stable objects, so a re-render isn't a change.\n const hasBase = hasContent(children);\n const target = useMemo<Scene>(\n () => (current ? { kind: \"notification\", item: current } : hasBase ? BASE : idle === \"rest\" ? IDLE : NONE),\n [current, hasBase, idle],\n );\n\n // What it shows, moved towards the target one timed step at a time\n const [displayed, setDisplayed] = useState<Displayed>(() => ({\n scene: target.kind === \"notification\" ? NONE : target,\n presence: target.kind === \"base\" ? \"compact\" : target.kind === \"idle\" ? \"rest\" : \"hidden\",\n }));\n const displayedRef = useRef(displayed);\n displayedRef.current = displayed;\n\n useEffect(() => {\n const steps = planSteps(displayedRef.current, target, readTimings(rootRef.current));\n const timers: ReturnType<typeof setTimeout>[] = [];\n let at = 0;\n steps.forEach((step, index) => {\n at += step.delay;\n // Steps due at the same time collapse into the last one\n const next = steps[index + 1];\n if (next && next.delay === 0) return;\n const apply = () => setDisplayed({ scene: step.scene, presence: step.presence });\n if (at === 0) {\n apply();\n } else {\n timers.push(setTimeout(apply, at));\n }\n });\n return () => timers.forEach(clearTimeout);\n }, [target]);\n\n // Pauses: pointer, keyboard focus, an open panel, a hidden tab (Y3)\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const documentHidden = useDocumentHidden();\n useEffect(() => {\n // An inert pill loses focus without always firing blur\n if (displayed.presence === \"hidden\") {\n setHovered(false);\n setFocused(false);\n }\n }, [displayed.presence]);\n\n const shown: QueuedNotification | null =\n displayed.scene.kind === \"notification\" && isOpen(displayed.presence) ? displayed.scene.item : null;\n const paused = hovered || focused || documentHidden || displayed.presence === \"panel\";\n\n // The countdown starts once the notification is fully shown, and again from\n // the full duration after each pause, or when its content is updated\n useEffect(() => {\n if (!shown || paused) return;\n const ms = shown.input.duration ?? duration;\n if (!Number.isFinite(ms)) return;\n const timer = setTimeout(() => store.dismiss(shown.id, \"timeout\"), ms);\n return () => clearTimeout(timer);\n }, [shown, paused, duration, store]);\n\n // Announcements go through a separate live region, so the pill itself can\n // leave the accessibility tree when hidden (Y1, Y5)\n const [announcement, setAnnouncement] = useState<{ key: QueuedNotification; text: string } | null>(null);\n useEffect(() => {\n if (!shown) return;\n const { announce } = shown.input;\n if (announce === false) return;\n const root = rootRef.current;\n const text =\n typeof announce === \"string\"\n ? announce\n : (root?.querySelector('[data-mp=\"message\"]') ?? root)?.textContent?.trim() ?? \"\";\n if (text) setAnnouncement((previous) => (previous?.key === shown ? previous : { key: shown, text }));\n }, [shown]);\n\n const handlePresenceChange = (next: PillPresence) => {\n const { scene, presence } = displayedRef.current;\n if (next === \"hidden\") {\n // Escape on an overlay, for instance: that's a dismissal\n if (scene.kind === \"notification\") store.dismiss(scene.item.id, \"dismissed\");\n return;\n }\n if (isOpen(next) && isOpen(presence)) {\n setDisplayed({ scene, presence: next });\n }\n };\n\n const renderScene = (scene: Scene): ReactNode => {\n switch (scene.kind) {\n case \"base\":\n return children;\n case \"idle\":\n return <PillIcon>{idleIcon}</PillIcon>;\n case \"notification\": {\n const { id, input } = scene.item;\n if (input.render) {\n return input.render({ id, dismiss: () => store.dismiss(id, \"dismissed\") });\n }\n return (\n <NotificationContent\n key={id}\n icon={input.icon}\n message={input.message}\n action={input.action}\n panel={input.panel}\n linkComponent={linkComponent}\n classNames={classNames}\n onAction={(event: MouseEvent<HTMLElement>) => {\n if (!event.defaultPrevented) store.dismiss(id, \"action\");\n }}\n />\n );\n }\n default:\n return null;\n }\n };\n\n const sceneVariant =\n displayed.scene.kind === \"notification\" ? (displayed.scene.item.input.variant ?? variant) : variant;\n\n return (\n <>\n <Pill\n {...rest}\n ref={ref}\n placement={placement}\n variant={sceneVariant}\n presence={displayed.presence}\n onPresenceChange={handlePresenceChange}\n onMouseEnter={(event) => {\n onMouseEnter?.(event);\n setHovered(true);\n }}\n onMouseLeave={(event) => {\n onMouseLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event) => {\n onFocus?.(event);\n setFocused(true);\n }}\n onBlur={(event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n // Focus moving between elements inside the pill keeps it paused\n setFocused(event.currentTarget.contains(event.relatedTarget as Node | null));\n }}\n >\n {renderScene(displayed.scene)}\n </Pill>\n <div role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-mp=\"announcer\" style={VISUALLY_HIDDEN}>\n {announcement && <span key={announcement.key.id + announcement.text}>{announcement.text}</span>}\n </div>\n </>\n );\n});\n\nexport default MagicPill;\n"],"mappings":"A,kkBAmDA,MAIMoB,EAAiC,CACrC,SAAU,WACV,MAAO,EACP,OAAQ,EACR,OAAQ,GACR,QAAS,EACT,SAAU,SACV,KAAM,gBACN,WAAY,SACZ,OAAQ,CACV,EAEMC,EAAcC,GAAoBA,GAA+B,MAAQA,IAAS,GAExF,SAASC,GAA6B,CACpC,GAAM,CAACC,EAAQC,GAAarB,EAAS,EAAK,EAO1C,OANAH,MAAgB,CACd,IAAMyB,MAAeD,EAAU,SAAS,kBAAoB,QAAQ,EAGpE,OAFAC,EAAO,EACP,SAAS,iBAAiB,mBAAoBA,CAAM,MACvC,SAAS,oBAAoB,mBAAoBA,CAAM,CACtE,EAAG,CAAC,CAAC,EACEF,CACT,CAMA,MAAMG,EAAY3B,EAAwC,SACxD,CACE4B,OAAO,OACPC,WACAC,WAAW,IACXC,OAAO,SACPC,WACAC,gBACAC,aACAC,YAAY,SACZC,UACAC,eACAC,eACAC,UACAC,SACA,GAAGC,GAELC,EACA,CACA,IAAMC,EAAQnC,EAASoB,CAAI,EACrB,CAAEgB,WAAYnC,EAAamB,CAAI,EAC/BiB,EAAU1C,EAA2B,IAAI,EACzC2C,EAAM5C,MAAcQ,EAAUmC,EAASH,CAAY,EAAG,CAACA,CAAY,CAAC,EAE1EzC,MAAgB0C,EAAM,aAAa,EAAG,CAACA,CAAK,CAAC,EAG7C,IAAMI,EAAU1B,EAAWQ,CAAQ,EAC7BmB,EAAS9C,MACN0C,EAAU,CAAE,KAAM,eAAgB,KAAMA,CAAQ,EAAIG,EAAUpC,EAAOoB,IAAS,OAASnB,EAAOC,EACrG,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C,CACvCA,EAAM,kBAAkBrC,EAAM,QAAQmC,EAAI,QAAQ,CACzD,CACD,EAVMA,CAUN,CAEL,CACA,QACE,OAAO,IACX,CACF,EAEMG,GACJhC,EAAU,MAAM,OAAS,eAAkBA,EAAU,MAAM,KAAK,MAAM,SAAWb,EAAWA,EAE9F,MACEjB,kBAAAF,EAAA,CAAA,SAAA,CACEC,kBAACb,EAAD,CACE,GAAIoC,EACCK,MACMX,YACX,QAAS8C,GACT,SAAUhC,EAAU,SACpB,iBAAkByB,GAClB,aAAeM,GAAU,CACvB3C,IAAe2C,CAAK,EACpBpB,EAAW,EAAI,CACjB,EACA,aAAeoB,GAAU,CACvB1C,IAAe0C,CAAK,EACpBpB,EAAW,EAAK,CAClB,EACA,QAAUoB,GAAU,CAClBzC,IAAUyC,CAAK,EACflB,EAAW,EAAI,CACjB,EACA,OAASkB,GAAsC,CAC7CxC,IAASwC,CAAK,EAEdlB,EAAWkB,EAAM,cAAc,SAASA,EAAM,aAA4B,CAAC,CAC7E,EAEC,SAAAH,GAAY5B,EAAU,KAAK,CACxB,CAAA,EACN/B,kBAAC,MAAD,CAAK,KAAK,SAAS,YAAU,SAAS,cAAY,OAAO,UAAQ,YAAY,MAAOE,EACjF,SAAAgD,GAAgBlD,kBAAC,OAAD,CAAA,SAAqDkD,EAAa,IAAW,EAAlEA,EAAa,IAAI,GAAKA,EAAa,IAA+B,CAC3F,CAAA,CACL,CAAA,CAAA,CAEN,CAAC,E"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choreography.js","names":["NONE","BASE","IDLE","OPEN_LEVELS","isOpen","presence","sceneKey","scene","settledPresence","parseDuration","value","fallback","match","amount","current","target","timings","steps","go","delay","nextPresence","nextScene","settled","element","style","read","name","reduced"],"sources":["../../src/MagicPill/choreography.ts"],"sourcesContent":["// Pure planning of the host's shape changes, so it can be tested without timers.\nimport type { PillPresence } from \"../Pill/types\";\nimport type { QueuedNotification } from \"../store/store\";\n\n/** What the host's pill shows. */\nexport type Scene =\n | { kind: \"none\" }\n | { kind: \"base\" }\n | { kind: \"idle\" }\n | { kind: \"notification\"; item: QueuedNotification };\n\nexport const NONE: Scene = Object.freeze({ kind: \"none\" });\nexport const BASE: Scene = Object.freeze({ kind: \"base\" });\nexport const IDLE: Scene = Object.freeze({ kind: \"idle\" });\n\nexport interface Displayed {\n scene: Scene;\n presence: PillPresence;\n}\n\nexport interface Timings {\n /** hidden → rest: the pop */\n enter: number;\n /** rest ↔ compact: the shape change */\n change: number;\n /** rest → hidden: the scale out */\n exit: number;\n /** With prefers-reduced-motion: no circle step, only fades of `exit` ms */\n reduced: boolean;\n}\n\n/** A state to apply `delay` ms after the previous step. */\nexport interface Step extends Displayed {\n delay: number;\n}\n\nconst OPEN_LEVELS: ReadonlySet<PillPresence> = new Set([\"compact\", \"expanded\", \"panel\"]);\nexport const isOpen = (presence: PillPresence) => OPEN_LEVELS.has(presence);\n\nconst sceneKey = (scene: Scene) => (scene.kind === \"notification\" ? `notification:${scene.item.id}` : scene.kind);\n\n/** Where each scene settles: the base and notifications are pills, idle is a circle. */\nconst settledPresence = (scene: Scene): PillPresence =>\n scene.kind === \"none\" ? \"hidden\" : scene.kind === \"idle\" ? \"rest\" : \"compact\";\n\n/**\n * The steps from what's displayed to the target scene:\n * - new content: collapse to the circle, swap the content there, grow back;\n * - nothing left to show: hide (the stylesheet shrinks, then scales out), then drop the content;\n * - from hidden: pop in as a circle, then grow into the pill.\n * Open levels the user chose (expanded, panel) are kept while the scene stays the same.\n */\nexport function planSteps(current: Displayed, target: Scene, timings: Timings): Step[] {\n const steps: Step[] = [];\n let { scene, presence } = current;\n const go = (delay: number, nextPresence: PillPresence, nextScene: Scene = scene) => {\n steps.push({ delay, presence: nextPresence, scene: nextScene });\n presence = nextPresence;\n scene = nextScene;\n };\n\n if (sceneKey(scene) !== sceneKey(target)) {\n if (target.kind === \"none\") {\n if (presence !== \"hidden\") go(0, \"hidden\");\n // Keep the old content on screen until it's out of sight\n go(timings.reduced ? timings.exit : timings.change + timings.exit, \"hidden\", target);\n return steps;\n }\n if (isOpen(presence)) {\n if (timings.reduced) {\n go(0, \"hidden\");\n go(timings.exit, \"hidden\", target);\n } else {\n go(0, \"rest\");\n go(timings.change, \"rest\", target);\n }\n } else {\n go(0, presence, target);\n }\n } else if (scene !== target) {\n // Same notification, new content (update or same id): swap in place\n go(0, presence, target);\n }\n\n const settled = settledPresence(target);\n if (settled === \"hidden\" || settled === \"rest\") {\n if (presence !== settled) go(0, settled);\n } else if (!isOpen(presence)) {\n if (presence === \"hidden\" && !timings.reduced) {\n go(0, \"rest\");\n go(timings.enter, \"compact\");\n } else {\n go(0, \"compact\");\n }\n }\n return steps;\n}\n\n/** \"500ms\" or \"0.5s\" → 500; anything else → the fallback. */\nexport function parseDuration(value: string, fallback: number): number {\n const match = /^\\s*([\\d.]+)(ms|s)\\s*$/.exec(value);\n if (!match) return fallback;\n const amount = Number.parseFloat(match[1]);\n return match[2] === \"s\" ? amount * 1000 : amount;\n}\n\n/** The timings the stylesheet uses for this pill, or its defaults (e.g. when unstyled). */\nexport function readTimings(element: HTMLElement | null): Timings {\n const style = element ? getComputedStyle(element) : null;\n const read = (name: string, fallback: number) => parseDuration(style?.getPropertyValue(name) ?? \"\", fallback);\n const reduced =\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n return reduced\n ? { enter: 0, change: 0, exit: 150, reduced }\n : { enter: read(\"--_mp-enter\", 500), change: read(\"--_mp-change\", 250), exit: read(\"--_mp-exit\", 300), reduced };\n}\n"],"mappings":"AAWA,MAAaA,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAC5CC,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAC5CC,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAuBnDC,kBAAyC,IAAI,IAAI,CAAC,UAAW,WAAY,OAAO,CAAC,EAC1EC,EAAUC,GAA2BF,EAAY,IAAIE,CAAQ,EAEpEC,EAAYC,GAAkBA,EAAM,OAAS,eAAiB,gBAAgBA,EAAM,KAAK,KAAOA,EAAM,KAGtGC,EAAmBD,GACvBA,EAAM,OAAS,OAAS,SAAWA,EAAM,OAAS,OAAS,OAAS,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,EAAU,iBAAiBA,CAAO,EAAI,KAC9CE,GAAQC,EAAcf,IAAqBF,EAAce,GAAO,iBAAiBE,CAAI,GAAK,GAAIf,CAAQ,EACtGgB,EACJ,OAAO,OAAW,KAClB,OAAO,OAAO,YAAe,YAC7B,OAAO,WAAW,kCAAkC,CAAC,CAAC,QACxD,OAAOA,EACH,CAAE,MAAO,EAAG,OAAQ,EAAG,KAAM,IAAKA,SAAQ,EAC1C,CAAE,MAAOF,EAAK,cAAe,GAAG,EAAG,OAAQA,EAAK,eAAgB,GAAG,EAAG,KAAMA,EAAK,aAAc,GAAG,EAAGE,SAAQ,CACnH"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choreography.mjs","names":["NONE","BASE","IDLE","OPEN_LEVELS","isOpen","presence","sceneKey","scene","settledPresence","planSteps","current","target","timings","steps","go","delay","nextPresence","nextScene","settled","parseDuration","value","fallback","match","amount","readTimings","element","style","read","name","reduced"],"sources":["../../src/MagicPill/choreography.ts"],"sourcesContent":["// Pure planning of the host's shape changes, so it can be tested without timers.\nimport type { PillPresence } from \"../Pill/types\";\nimport type { QueuedNotification } from \"../store/store\";\n\n/** What the host's pill shows. */\nexport type Scene =\n | { kind: \"none\" }\n | { kind: \"base\" }\n | { kind: \"idle\" }\n | { kind: \"notification\"; item: QueuedNotification };\n\nexport const NONE: Scene = Object.freeze({ kind: \"none\" });\nexport const BASE: Scene = Object.freeze({ kind: \"base\" });\nexport const IDLE: Scene = Object.freeze({ kind: \"idle\" });\n\nexport interface Displayed {\n scene: Scene;\n presence: PillPresence;\n}\n\nexport interface Timings {\n /** hidden → rest: the pop */\n enter: number;\n /** rest ↔ compact: the shape change */\n change: number;\n /** rest → hidden: the scale out */\n exit: number;\n /** With prefers-reduced-motion: no circle step, only fades of `exit` ms */\n reduced: boolean;\n}\n\n/** A state to apply `delay` ms after the previous step. */\nexport interface Step extends Displayed {\n delay: number;\n}\n\nconst OPEN_LEVELS: ReadonlySet<PillPresence> = new Set([\"compact\", \"expanded\", \"panel\"]);\nexport const isOpen = (presence: PillPresence) => OPEN_LEVELS.has(presence);\n\nconst sceneKey = (scene: Scene) => (scene.kind === \"notification\" ? `notification:${scene.item.id}` : scene.kind);\n\n/** Where each scene settles: the base and notifications are pills, idle is a circle. */\nconst settledPresence = (scene: Scene): PillPresence =>\n scene.kind === \"none\" ? \"hidden\" : scene.kind === \"idle\" ? \"rest\" : \"compact\";\n\n/**\n * The steps from what's displayed to the target scene:\n * - new content: collapse to the circle, swap the content there, grow back;\n * - nothing left to show: hide (the stylesheet shrinks, then scales out), then drop the content;\n * - from hidden: pop in as a circle, then grow into the pill.\n * Open levels the user chose (expanded, panel) are kept while the scene stays the same.\n */\nexport function planSteps(current: Displayed, target: Scene, timings: Timings): Step[] {\n const steps: Step[] = [];\n let { scene, presence } = current;\n const go = (delay: number, nextPresence: PillPresence, nextScene: Scene = scene) => {\n steps.push({ delay, presence: nextPresence, scene: nextScene });\n presence = nextPresence;\n scene = nextScene;\n };\n\n if (sceneKey(scene) !== sceneKey(target)) {\n if (target.kind === \"none\") {\n if (presence !== \"hidden\") go(0, \"hidden\");\n // Keep the old content on screen until it's out of sight\n go(timings.reduced ? timings.exit : timings.change + timings.exit, \"hidden\", target);\n return steps;\n }\n if (isOpen(presence)) {\n if (timings.reduced) {\n go(0, \"hidden\");\n go(timings.exit, \"hidden\", target);\n } else {\n go(0, \"rest\");\n go(timings.change, \"rest\", target);\n }\n } else {\n go(0, presence, target);\n }\n } else if (scene !== target) {\n // Same notification, new content (update or same id): swap in place\n go(0, presence, target);\n }\n\n const settled = settledPresence(target);\n if (settled === \"hidden\" || settled === \"rest\") {\n if (presence !== settled) go(0, settled);\n } else if (!isOpen(presence)) {\n if (presence === \"hidden\" && !timings.reduced) {\n go(0, \"rest\");\n go(timings.enter, \"compact\");\n } else {\n go(0, \"compact\");\n }\n }\n return steps;\n}\n\n/** \"500ms\" or \"0.5s\" → 500; anything else → the fallback. */\nexport function parseDuration(value: string, fallback: number): number {\n const match = /^\\s*([\\d.]+)(ms|s)\\s*$/.exec(value);\n if (!match) return fallback;\n const amount = Number.parseFloat(match[1]);\n return match[2] === \"s\" ? amount * 1000 : amount;\n}\n\n/** The timings the stylesheet uses for this pill, or its defaults (e.g. when unstyled). */\nexport function readTimings(element: HTMLElement | null): Timings {\n const style = element ? getComputedStyle(element) : null;\n const read = (name: string, fallback: number) => parseDuration(style?.getPropertyValue(name) ?? \"\", fallback);\n const reduced =\n typeof window !== \"undefined\" &&\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n return reduced\n ? { enter: 0, change: 0, exit: 150, reduced }\n : { enter: read(\"--_mp-enter\", 500), change: read(\"--_mp-change\", 250), exit: read(\"--_mp-exit\", 300), reduced };\n}\n"],"mappings":"AAWA,MAAaA,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAC5CC,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAC5CC,EAAc,OAAO,OAAO,CAAE,KAAM,MAAO,CAAC,EAuBnDC,kBAAyC,IAAI,IAAI,CAAC,UAAW,WAAY,OAAO,CAAC,EAC1EC,EAAUC,GAA2BF,EAAY,IAAIE,CAAQ,EAEpEC,EAAYC,GAAkBA,EAAM,OAAS,eAAiB,gBAAgBA,EAAM,KAAK,KAAOA,EAAM,KAGtGC,EAAmBD,GACvBA,EAAM,OAAS,OAAS,SAAWA,EAAM,OAAS,OAAS,OAAS,UAStE,SAAgBE,EAAUC,EAAoBC,EAAeC,EAA0B,CACrF,IAAMC,EAAgB,CAAC,EACnB,CAAEN,QAAOF,YAAaK,EACpBI,GAAMC,EAAeC,EAA4BC,EAAmBV,IAAU,CAClFM,EAAM,KAAK,CAAEE,QAAO,SAAUC,EAAc,MAAOC,CAAU,CAAC,EAC9DZ,EAAWW,EACXT,EAAQU,CACV,EAEA,GAAIX,EAASC,CAAK,IAAMD,EAASK,CAAM,EAAG,CACxC,GAAIA,EAAO,OAAS,OAIlB,OAHIN,IAAa,UAAUS,EAAG,EAAG,QAAQ,EAEzCA,EAAGF,EAAQ,QAAUA,EAAQ,KAAOA,EAAQ,OAASA,EAAQ,KAAM,SAAUD,CAAM,EAC5EE,EAELT,EAAOC,CAAQ,EACbO,EAAQ,SACVE,EAAG,EAAG,QAAQ,EACdA,EAAGF,EAAQ,KAAM,SAAUD,CAAM,IAEjCG,EAAG,EAAG,MAAM,EACZA,EAAGF,EAAQ,OAAQ,OAAQD,CAAM,GAGnCG,EAAG,EAAGT,EAAUM,CAAM,CAE1B,MAAWJ,IAAUI,GAEnBG,EAAG,EAAGT,EAAUM,CAAM,EAGxB,IAAMO,EAAUV,EAAgBG,CAAM,EAWtC,OAVIO,IAAY,UAAYA,IAAY,OAClCb,IAAaa,GAASJ,EAAG,EAAGI,CAAO,EAC7Bd,EAAOC,CAAQ,IACrBA,IAAa,UAAY,CAACO,EAAQ,SACpCE,EAAG,EAAG,MAAM,EACZA,EAAGF,EAAQ,MAAO,SAAS,GAE3BE,EAAG,EAAG,SAAS,GAGZD,CACT,CAGA,SAAgBM,EAAcC,EAAeC,EAA0B,CACrE,IAAMC,EAAQ,yBAAyB,KAAKF,CAAK,EACjD,GAAI,CAACE,EAAO,OAAOD,EACnB,IAAME,EAAS,OAAO,WAAWD,EAAM,EAAE,EACzC,OAAOA,EAAM,KAAO,IAAMC,EAAS,IAAOA,CAC5C,CAGA,SAAgBC,EAAYC,EAAsC,CAChE,IAAMC,EAAQD,EAAU,iBAAiBA,CAAO,EAAI,KAC9CE,GAAQC,EAAcP,IAAqBF,EAAcO,GAAO,iBAAiBE,CAAI,GAAK,GAAIP,CAAQ,EACtGQ,EACJ,OAAO,OAAW,KAClB,OAAO,OAAO,YAAe,YAC7B,OAAO,WAAW,kCAAkC,CAAC,CAAC,QACxD,OAAOA,EACH,CAAE,MAAO,EAAG,OAAQ,EAAG,KAAM,IAAKA,SAAQ,EAC1C,CAAE,MAAOF,EAAK,cAAe,GAAG,EAAG,OAAQA,EAAK,eAAgB,GAAG,EAAG,KAAMA,EAAK,aAAc,GAAG,EAAGE,SAAQ,CACnH,C"}
@@ -0,0 +1,7 @@
1
+ import { PillProps } from "./types.mjs";
2
+ /**
3
+ * The pill: a container with the Magic Pill design language. Put any parts
4
+ * (or anything else) inside. Its look and animations follow its data attributes.
5
+ */
6
+ declare const Pill: import("react").ForwardRefExoticComponent<PillProps & import("react").RefAttributes<HTMLElement>>;
7
+ export { Pill as default };
@@ -0,0 +1,7 @@
1
+ import { PillProps } from "./types.js";
2
+ /**
3
+ * The pill: a container with the Magic Pill design language. Put any parts
4
+ * (or anything else) inside. Its look and animations follow its data attributes.
5
+ */
6
+ declare const Pill: import("react").ForwardRefExoticComponent<PillProps & import("react").RefAttributes<HTMLElement>>;
7
+ export = Pill;
@@ -0,0 +1,2 @@
1
+ "use client";let e=require("react");const t=require("./PillContext.js"),n=require("../utils/react.js");let r=require("react/jsx-runtime");const i=e=>e===`left`||e===`right`?`vertical`:`horizontal`,a=(0,e.forwardRef)(function({presence:a,defaultPresence:o=`compact`,onPresenceChange:s,placement:c=`inline`,orientation:l,variant:u=`neutral`,unstyled:d=!1,children:f,onKeyDown:p,...m},h){let[g,_]=(0,e.useState)(o),v=a!==void 0,y=v?a:g,b=l??i(c),x=c===`overlay`,S=y!==`hidden`,C=(0,e.useRef)(null),w=(0,e.useMemo)(()=>n.mergeRefs(C,h),[h]),T=(0,e.useRef)(null),E=(0,e.useId)(),D=(0,e.useRef)(`compact`);(0,e.useEffect)(()=>{y!==`panel`&&y!==`hidden`&&(D.current=y)},[y]);let O=(0,e.useCallback)(e=>{e!==y&&(v||_(e),s?.(e))},[y,v,s]),k=(0,e.useCallback)(()=>{y===`panel`&&O(D.current)},[y,O]);(0,e.useEffect)(()=>{let e=C.current;x&&e&&typeof e.showModal==`function`&&(S&&!e.open?e.showModal():!S&&e.open&&e.close())},[x,S]);let A=e=>{p?.(e),e.defaultPrevented||x||e.key===`Escape`&&y===`panel`&&(e.preventDefault(),e.stopPropagation(),k())},j=e=>{e.preventDefault(),y===`panel`?k():O(`hidden`)},M=()=>{y!==`hidden`&&O(`hidden`)},N=(0,e.useMemo)(()=>({presence:y,setPresence:O,closePanel:k,placement:c,orientation:b,variant:u,panelId:E,panelTriggerRef:T,rootRef:C}),[y,O,k,c,b,u,E]),P=x?`dialog`:`div`;return/* @__PURE__ */ (0,r.jsx)(t.PillContext.Provider,{value:N,children:/* @__PURE__ */ (0,r.jsx)(P,{...m,ref:w,"data-mp":`pill`,"data-presence":y,"data-placement":c,"data-orientation":b,"data-variant":u,"data-unstyled":d?``:void 0,...n.inertProps(!S&&!x),onKeyDown:A,...x?{onCancel:j,onClose:M}:{},children:f})})});module.exports=a;
2
+ //# sourceMappingURL=Pill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pill.js","names":["forwardRef","useState","useRef","useMemo","mergeRefs","useId","useEffect","useCallback","PillContext","inertProps","react","require_PillContext","require_react","react_jsx_runtime","defaultOrientation","placement","Pill","presenceProp","defaultPresence","onPresenceChange","orientation","variant","unstyled","children","onKeyDown","rest","forwardedRef","uncontrolledPresence","setUncontrolledPresence","isControlled","presence","resolvedOrientation","isOverlay","isVisible","rootRef","ref","panelTriggerRef","panelId","returnPresenceRef","setPresence","next","closePanel","dialog","handleKeyDown","event","handleCancel","handleClose","context","Element"],"sources":["../../src/Pill/Pill.tsx"],"sourcesContent":["\"use client\"\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type SyntheticEvent,\n} from \"react\";\n\nimport { PillContext, type InternalPillContextValue } from \"./PillContext\";\nimport type { PillOrientation, PillPresence, PillProps } from \"./types\";\nimport { inertProps, mergeRefs } from \"../utils/react\";\n\nconst defaultOrientation = (placement: PillProps[\"placement\"]): PillOrientation =>\n placement === \"left\" || placement === \"right\" ? \"vertical\" : \"horizontal\";\n\n/**\n * The pill: a container with the Magic Pill design language. Put any parts\n * (or anything else) inside. Its look and animations follow its data attributes.\n */\nconst Pill = forwardRef<HTMLElement, PillProps>(function Pill(\n {\n presence: presenceProp,\n defaultPresence = \"compact\",\n onPresenceChange,\n placement = \"inline\",\n orientation,\n variant = \"neutral\",\n unstyled = false,\n children,\n onKeyDown,\n ...rest\n },\n forwardedRef,\n) {\n const [uncontrolledPresence, setUncontrolledPresence] = useState<PillPresence>(defaultPresence);\n const isControlled = presenceProp !== undefined;\n const presence = isControlled ? presenceProp : uncontrolledPresence;\n const resolvedOrientation = orientation ?? defaultOrientation(placement);\n const isOverlay = placement === \"overlay\";\n const isVisible = presence !== \"hidden\";\n\n const rootRef = useRef<HTMLElement | null>(null);\n const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);\n const panelTriggerRef = useRef<HTMLElement | null>(null);\n const panelId = useId();\n\n // Where closing the panel goes back to: the last visible level other than the panel\n const returnPresenceRef = useRef<PillPresence>(\"compact\");\n useEffect(() => {\n if (presence !== \"panel\" && presence !== \"hidden\") {\n returnPresenceRef.current = presence;\n }\n }, [presence]);\n\n const setPresence = useCallback(\n (next: PillPresence) => {\n if (next === presence) return;\n if (!isControlled) setUncontrolledPresence(next);\n onPresenceChange?.(next);\n },\n [presence, isControlled, onPresenceChange],\n );\n\n const closePanel = useCallback(() => {\n if (presence === \"panel\") setPresence(returnPresenceRef.current);\n }, [presence, setPresence]);\n\n // The overlay is a native modal <dialog>: focus trap, Escape and inert page for free\n useEffect(() => {\n const dialog = rootRef.current as HTMLDialogElement | null;\n if (!isOverlay || !dialog || typeof dialog.showModal !== \"function\") return;\n if (isVisible && !dialog.open) {\n dialog.showModal();\n } else if (!isVisible && dialog.open) {\n dialog.close();\n }\n }, [isOverlay, isVisible]);\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n // A <dialog> reports Escape through its cancel event instead\n if (event.defaultPrevented || isOverlay) return;\n if (event.key === \"Escape\" && presence === \"panel\") {\n event.preventDefault();\n event.stopPropagation();\n closePanel();\n }\n };\n\n // Escape on the modal: close the panel first, then the overlay. The state\n // stays the source of truth, so the browser's own closing is prevented.\n const handleCancel = (event: SyntheticEvent<HTMLDivElement>) => {\n event.preventDefault();\n if (presence === \"panel\") {\n closePanel();\n } else {\n setPresence(\"hidden\");\n }\n };\n\n // The browser may still close the dialog itself (e.g. a repeated Escape)\n const handleClose = () => {\n if (presence !== \"hidden\") setPresence(\"hidden\");\n };\n\n const context = useMemo<InternalPillContextValue>(\n () => ({\n presence,\n setPresence,\n closePanel,\n placement,\n orientation: resolvedOrientation,\n variant,\n panelId,\n panelTriggerRef,\n rootRef,\n }),\n [presence, setPresence, closePanel, placement, resolvedOrientation, variant, panelId],\n );\n\n // Typed as a <div>: the <dialog> only adds the cancel/close events used above\n const Element = (isOverlay ? \"dialog\" : \"div\") as \"div\";\n\n return (\n <PillContext.Provider value={context}>\n <Element\n {...rest}\n ref={ref}\n data-mp=\"pill\"\n data-presence={presence}\n data-placement={placement}\n data-orientation={resolvedOrientation}\n data-variant={variant}\n data-unstyled={unstyled ? \"\" : undefined}\n // Hidden: out of the focus order and the accessibility tree at once,\n // while the exit animation plays (Y5). A closed <dialog> already is.\n {...inertProps(!isVisible && !isOverlay)}\n onKeyDown={handleKeyDown}\n {...(isOverlay ? { onCancel: handleCancel, onClose: handleClose } : {})}\n >\n {children}\n </Element>\n </PillContext.Provider>\n );\n});\n\nexport default Pill;\n"],"mappings":"A,0IAiBA,MAAMc,EAAsBC,GAC1BA,IAAc,QAAUA,IAAc,QAAU,WAAa,aAMzDC,GAAA,EAAOhB,EAAAA,WAAAA,CAAmC,SAC9C,CACE,SAAUiB,EACVC,kBAAkB,UAClBC,mBACAJ,YAAY,SACZK,cACAC,UAAU,UACVC,WAAW,GACXC,WACAC,YACA,GAAGC,GAELC,EACA,CACA,GAAM,CAACC,EAAsBC,IAAA,EAA2B3B,EAAAA,SAAAA,CAAuBiB,CAAe,EACxFW,EAAeZ,IAAiB,IAAA,GAChCa,EAAWD,EAAeZ,EAAeU,EACzCI,EAAsBX,GAAeN,EAAmBC,CAAS,EACjEiB,EAAYjB,IAAc,UAC1BkB,EAAYH,IAAa,SAEzBI,GAAA,EAAUhC,EAAAA,OAAAA,CAA2B,IAAI,EACzCiC,GAAA,EAAMhC,EAAAA,QAAAA,KAAcC,EA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A,YAAagB,EACbV,UACAgB,UACAD,kBACAF,SACF,GACA,CAACJ,EAAUS,EAAaE,EAAY1B,EAAWgB,EAAqBV,EAASgB,CAAO,CACtF,EAGMW,EAAWhB,EAAY,SAAW,MAExC,MACE,iBAAA,EAAAnB,EAAA,IAAA,CAACL,EAAAA,YAAY,SAAb,CAAsB,MAAOuC,EAC3B,SAAA,iBAAA,EAAAlC,EAAA,IAAA,CAACmC,EAAD,CACE,GAAIvB,EACCU,MACL,UAAQ,OACR,gBAAeL,EACf,iBAAgBf,EAChB,mBAAkBgB,EAClB,eAAcV,EACd,gBAAeC,EAAW,GAAK,IAAA,GAG/B,GAAIb,EAAAA,WAAW,CAACwB,GAAa,CAACD,CAAS,EACvC,UAAWW,EACX,GAAKX,EAAY,CAAE,SAAUa,EAAc,QAASC,CAAY,EAAI,CAAC,EAEpEvB,UACM,CAAA,CACW,CAAA,CAE1B,CAAC,E"}
@@ -0,0 +1,2 @@
1
+ "use client";import{forwardRef as e,useCallback as t,useEffect as n,useId as r,useMemo as i,useRef as a,useState as o}from"react";import{PillContext as s}from"./PillContext.mjs";import{inertProps as c,mergeRefs as l}from"../utils/react.mjs";import{jsx as u}from"react/jsx-runtime";const d=e=>e===`left`||e===`right`?`vertical`:`horizontal`,f=e(function({presence:e,defaultPresence:f=`compact`,onPresenceChange:p,placement:m=`inline`,orientation:h,variant:g=`neutral`,unstyled:_=!1,children:v,onKeyDown:y,...b},x){let[S,C]=o(f),w=e!==void 0,T=w?e:S,E=h??d(m),D=m===`overlay`,O=T!==`hidden`,k=a(null),A=i(()=>l(k,x),[x]),j=a(null),M=r(),N=a(`compact`);n(()=>{T!==`panel`&&T!==`hidden`&&(N.current=T)},[T]);let P=t(e=>{e!==T&&(w||C(e),p?.(e))},[T,w,p]),F=t(()=>{T===`panel`&&P(N.current)},[T,P]);n(()=>{let e=k.current;D&&e&&typeof e.showModal==`function`&&(O&&!e.open?e.showModal():!O&&e.open&&e.close())},[D,O]);let I=e=>{y?.(e),e.defaultPrevented||D||e.key===`Escape`&&T===`panel`&&(e.preventDefault(),e.stopPropagation(),F())},L=e=>{e.preventDefault(),T===`panel`?F():P(`hidden`)},R=()=>{T!==`hidden`&&P(`hidden`)},z=i(()=>({presence:T,setPresence:P,closePanel:F,placement:m,orientation:E,variant:g,panelId:M,panelTriggerRef:j,rootRef:k}),[T,P,F,m,E,g,M]),B=D?`dialog`:`div`;return/* @__PURE__ */ u(s.Provider,{value:z,children:/* @__PURE__ */ u(B,{...b,ref:A,"data-mp":`pill`,"data-presence":T,"data-placement":m,"data-orientation":E,"data-variant":g,"data-unstyled":_?``:void 0,...c(!O&&!D),onKeyDown:I,...D?{onCancel:L,onClose:R}:{},children:v})})});export{f as default};
2
+ //# sourceMappingURL=Pill.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pill.mjs","names":["forwardRef","useCallback","useEffect","useId","useMemo","useRef","useState","PillContext","inertProps","mergeRefs","jsx","defaultOrientation","placement","Pill","presenceProp","defaultPresence","onPresenceChange","orientation","variant","unstyled","children","onKeyDown","rest","forwardedRef","uncontrolledPresence","setUncontrolledPresence","isControlled","presence","resolvedOrientation","isOverlay","isVisible","rootRef","ref","panelTriggerRef","panelId","returnPresenceRef","setPresence","next","closePanel","dialog","handleKeyDown","event","handleCancel","handleClose","context","Element"],"sources":["../../src/Pill/Pill.tsx"],"sourcesContent":["\"use client\"\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type SyntheticEvent,\n} from \"react\";\n\nimport { PillContext, type InternalPillContextValue } from \"./PillContext\";\nimport type { PillOrientation, PillPresence, PillProps } from \"./types\";\nimport { inertProps, mergeRefs } from \"../utils/react\";\n\nconst defaultOrientation = (placement: PillProps[\"placement\"]): PillOrientation =>\n placement === \"left\" || placement === \"right\" ? \"vertical\" : \"horizontal\";\n\n/**\n * The pill: a container with the Magic Pill design language. Put any parts\n * (or anything else) inside. Its look and animations follow its data attributes.\n */\nconst Pill = forwardRef<HTMLElement, PillProps>(function Pill(\n {\n presence: presenceProp,\n defaultPresence = \"compact\",\n onPresenceChange,\n placement = \"inline\",\n orientation,\n variant = \"neutral\",\n unstyled = false,\n children,\n onKeyDown,\n ...rest\n },\n forwardedRef,\n) {\n const [uncontrolledPresence, setUncontrolledPresence] = useState<PillPresence>(defaultPresence);\n const isControlled = presenceProp !== undefined;\n const presence = isControlled ? presenceProp : uncontrolledPresence;\n const resolvedOrientation = orientation ?? defaultOrientation(placement);\n const isOverlay = placement === \"overlay\";\n const isVisible = presence !== \"hidden\";\n\n const rootRef = useRef<HTMLElement | null>(null);\n const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);\n const panelTriggerRef = useRef<HTMLElement | null>(null);\n const panelId = useId();\n\n // Where closing the panel goes back to: the last visible level other than the panel\n const returnPresenceRef = useRef<PillPresence>(\"compact\");\n useEffect(() => {\n if (presence !== \"panel\" && presence !== \"hidden\") {\n returnPresenceRef.current = presence;\n }\n }, [presence]);\n\n const setPresence = useCallback(\n (next: PillPresence) => {\n if (next === presence) return;\n if (!isControlled) setUncontrolledPresence(next);\n onPresenceChange?.(next);\n },\n [presence, isControlled, onPresenceChange],\n );\n\n const closePanel = useCallback(() => {\n if (presence === \"panel\") setPresence(returnPresenceRef.current);\n }, [presence, setPresence]);\n\n // The overlay is a native modal <dialog>: focus trap, Escape and inert page for free\n useEffect(() => {\n const dialog = rootRef.current as HTMLDialogElement | null;\n if (!isOverlay || !dialog || typeof dialog.showModal !== \"function\") return;\n if (isVisible && !dialog.open) {\n dialog.showModal();\n } else if (!isVisible && dialog.open) {\n dialog.close();\n }\n }, [isOverlay, isVisible]);\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n // A <dialog> reports Escape through its cancel event instead\n if (event.defaultPrevented || isOverlay) return;\n if (event.key === \"Escape\" && presence === \"panel\") {\n event.preventDefault();\n event.stopPropagation();\n closePanel();\n }\n };\n\n // Escape on the modal: close the panel first, then the overlay. The state\n // stays the source of truth, so the browser's own closing is prevented.\n const handleCancel = (event: SyntheticEvent<HTMLDivElement>) => {\n event.preventDefault();\n if (presence === \"panel\") {\n closePanel();\n } else {\n setPresence(\"hidden\");\n }\n };\n\n // The browser may still close the dialog itself (e.g. a repeated Escape)\n const handleClose = () => {\n if (presence !== \"hidden\") setPresence(\"hidden\");\n };\n\n const context = useMemo<InternalPillContextValue>(\n () => ({\n presence,\n setPresence,\n closePanel,\n placement,\n orientation: resolvedOrientation,\n variant,\n panelId,\n panelTriggerRef,\n rootRef,\n }),\n [presence, setPresence, closePanel, placement, resolvedOrientation, variant, panelId],\n );\n\n // Typed as a <div>: the <dialog> only adds the cancel/close events used above\n const Element = (isOverlay ? \"dialog\" : \"div\") as \"div\";\n\n return (\n <PillContext.Provider value={context}>\n <Element\n {...rest}\n ref={ref}\n data-mp=\"pill\"\n data-presence={presence}\n data-placement={placement}\n data-orientation={resolvedOrientation}\n data-variant={variant}\n data-unstyled={unstyled ? \"\" : undefined}\n // Hidden: out of the focus order and the accessibility tree at once,\n // while the exit animation plays (Y5). A closed <dialog> already is.\n {...inertProps(!isVisible && !isOverlay)}\n onKeyDown={handleKeyDown}\n {...(isOverlay ? { onCancel: handleCancel, onClose: handleClose } : {})}\n >\n {children}\n </Element>\n </PillContext.Provider>\n );\n});\n\nexport default Pill;\n"],"mappings":"A,yRAiBA,MAAMW,EAAsBC,GAC1BA,IAAc,QAAUA,IAAc,QAAU,WAAa,aAMzDC,EAAOb,EAAmC,SAC9C,CACE,SAAUc,EACVC,kBAAkB,UAClBC,mBACAJ,YAAY,SACZK,cACAC,UAAU,UACVC,WAAW,GACXC,WACAC,YACA,GAAGC,GAELC,EACA,CACA,GAAM,CAACC,EAAsBC,GAA2BnB,EAAuBS,CAAe,EACxFW,EAAeZ,IAAiB,IAAA,GAChCa,EAAWD,EAAeZ,EAAeU,EACzCI,EAAsBX,GAAeN,EAAmBC,CAAS,EACjEiB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AAWgB,EAAqBV,EAASgB,CAAO,CACtF,EAGMW,EAAWhB,EAAY,SAAW,MAExC,MACEnB,kBAACH,EAAY,SAAb,CAAsB,MAAOqC,EAC3B,SAAAlC,kBAACmC,EAAD,CACE,GAAIvB,EACCU,MACL,UAAQ,OACR,gBAAeL,EACf,iBAAgBf,EAChB,mBAAkBgB,EAClB,eAAcV,EACd,gBAAeC,EAAW,GAAK,IAAA,GAG/B,GAAIX,EAAW,CAACsB,GAAa,CAACD,CAAS,EACvC,UAAWW,EACX,GAAKX,EAAY,CAAE,SAAUa,EAAc,QAASC,CAAY,EAAI,CAAC,EAEpEvB,UACM,CAAA,CACW,CAAA,CAE1B,CAAC,E"}
@@ -0,0 +1,7 @@
1
+ import { PillActionProps } from "./types.mjs";
2
+ /**
3
+ * The light round button: its icon at rest, icon + bold label when expanded.
4
+ * A <button> with `onClick`, a link with `href`.
5
+ */
6
+ declare const PillAction: import("react").ForwardRefExoticComponent<PillActionProps & import("react").RefAttributes<HTMLElement>>;
7
+ export { PillAction as default };
@@ -0,0 +1,7 @@
1
+ import { PillActionProps } from "./types.js";
2
+ /**
3
+ * The light round button: its icon at rest, icon + bold label when expanded.
4
+ * A <button> with `onClick`, a link with `href`.
5
+ */
6
+ declare const PillAction: import("react").ForwardRefExoticComponent<PillActionProps & import("react").RefAttributes<HTMLElement>>;
7
+ export = PillAction;
@@ -0,0 +1,2 @@
1
+ let e=require("react");const t=require("../utils/url.js"),n=require("../utils/react.js");let r=require("react/jsx-runtime");const i=(0,e.forwardRef)(function(e,i){let{icon:a,label:o,expanded:s}=e,c=a!=null,l={"data-mp":`action`,"data-expanded":s||!c?``:void 0},u=/* @__PURE__ */ (0,r.jsxs)(r.Fragment,{children:[c&&/* @__PURE__ */ (0,r.jsx)(`span`,{"data-mp":`action-icon`,"aria-hidden":`true`,children:a}),/* @__PURE__ */ (0,r.jsx)(`span`,{"data-mp":`label`,children:o})]});if(e.href!==void 0){let{icon:a,label:s,expanded:c,href:d,linkComponent:f,...p}=e,m=i;return t.isSafeHref(d)?f?/* @__PURE__ */ (0,r.jsx)(f,{...p,...l,ref:m,href:d,children:u}):/* @__PURE__ */ (0,r.jsx)(`a`,{...p,...l,ref:m,href:d,children:u}):(n.devWarn(`<PillAction label="${o}"> got an unsafe href and renders without a link. Only relative, http(s):, mailto: and tel: URLs are allowed.`),/* @__PURE__ */ (0,r.jsx)(`a`,{...p,...l,ref:m,"aria-disabled":`true`,children:u}))}let{icon:d,label:f,expanded:p,href:m,...h}=e;return/* @__PURE__ */ (0,r.jsx)(`button`,{type:`button`,...h,...l,ref:i,children:u})});module.exports=i;
2
+ //# sourceMappingURL=PillAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillAction.js","names":["forwardRef","isSafeHref","devWarn","react","require_url","require_react","react_jsx_runtime","PillAction","props","ref","icon","label","expanded","hasIcon","shared","content","_icon","_label","_expanded","href","Link","rest","anchorRef","_href"],"sources":["../../src/Pill/PillAction.tsx"],"sourcesContent":["// No \"use client\": a Server Component can render a link action, with its\n// `linkComponent`, without shipping it to the client.\nimport { forwardRef, type Ref } from \"react\";\n\nimport type { PillActionProps } from \"./types\";\nimport { isSafeHref } from \"../utils/url\";\nimport { devWarn } from \"../utils/react\";\n\n/**\n * The light round button: its icon at rest, icon + bold label when expanded.\n * A <button> with `onClick`, a link with `href`.\n */\nconst PillAction = forwardRef<HTMLElement, PillActionProps>(function PillAction(props, ref) {\n const { icon, label, expanded } = props;\n const hasIcon = icon !== undefined && icon !== null;\n const shared = {\n \"data-mp\": \"action\",\n // Without an icon, the label is all there is to show\n \"data-expanded\": expanded || !hasIcon ? \"\" : undefined,\n };\n const content = (\n <>\n {hasIcon && (\n <span data-mp=\"action-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span data-mp=\"label\">{label}</span>\n </>\n );\n\n if (props.href !== undefined) {\n const { icon: _icon, label: _label, expanded: _expanded, href, linkComponent: Link, ...rest } = props;\n const anchorRef = ref as Ref<HTMLAnchorElement>;\n\n // L16: never render a `javascript:` (or any other unexpected scheme) link\n if (!isSafeHref(href)) {\n devWarn(\n `<PillAction label=\"${label}\"> got an unsafe href and renders without a link. ` +\n \"Only relative, http(s):, mailto: and tel: URLs are allowed.\",\n );\n return (\n <a {...rest} {...shared} ref={anchorRef} aria-disabled=\"true\">\n {content}\n </a>\n );\n }\n\n if (Link) {\n return (\n <Link {...rest} {...shared} ref={anchorRef} href={href}>\n {content}\n </Link>\n );\n }\n\n return (\n <a {...rest} {...shared} ref={anchorRef} href={href}>\n {content}\n </a>\n );\n }\n\n const { icon: _icon, label: _label, expanded: _expanded, href: _href, ...rest } = props;\n return (\n <button type=\"button\" {...rest} {...shared} ref={ref as Ref<HTMLButtonElement>}>\n {content}\n </button>\n );\n});\n\nexport default PillAction;\n"],"mappings":"A,4HAYA,MAAMO,GAAA,EAAaP,EAAAA,WAAAA,CAAyC,SAAoBQ,EAAOC,EAAK,CAC1F,GAAM,CAAEC,OAAMC,QAAOC,YAAaJ,EAC5BK,EAAUH,GAA+B,KACzCI,EAAS,CACb,UAAW,SAEX,gBAAiBF,GAAY,CAACC,EAAU,GAAK,IAAA,EAC/C,EACME,EACJ,iBAAA,EAAAT,EAAA,KAAA,CAAAA,EAAA,SAAA,CAAA,SAAA,CACGO,GACC,iBAAA,EAAAP,EAAA,IAAA,CAAC,OAAD,CAAM,UAAQ,cAAc,cAAY,OACrC,SAAAI,CACG,CAAA,EAER,iBAAA,EAAAJ,EAAA,IAAA,CAAC,OAAD,CAAM,UAAQ,QAAS,SAAAK,CAAY,CAAA,CACnC,CAAA,CAAA,EAGJ,GAAIH,EAAM,OAAS,IAAA,GAAW,CAC5B,GAAM,CAAE,KAAMQ,EAAO,MAAOC,EAAQ,SAAUC,EAAWC,OAAM,cAAeC,EAAM,GAAGC,GAASb,EAC1Fc,EAAYb,EAuBlB,OApBKR,EAAAA,WAAWkB,CAAI,EAYhBC,EAEA,iBAAA,EAAAd,EAAA,IAAA,CAACc,EAAD,CAAM,GAAIC,EAAM,GAAIP,EAAQ,IAAKQ,EAAiBH,OAC/C,SAAAJ,CACG,CAAA,EAKR,iBAAA,EAAAT,EAAA,IAAA,CAAC,IAAD,CAAG,GAAIe,EAAM,GAAIP,EAAQ,IAAKQ,EAAiBH,OAC5C,SAAAJ,CACA,CAAA,GAtBHb,EAAAA,QACE,sBAAsBS,EAAM,8GAE9B,EAEE,iBAAA,EAAAL,EAAA,IAAA,CAAC,IAAD,CAAG,GAAIe,EAAM,GAAIP,EAAQ,IAAKQ,EAAW,gBAAc,OACpD,SAAAP,CACA,CAAA,EAiBT,CAEA,GAAM,CAAE,KAAMC,EAAO,MAAOC,EAAQ,SAAUC,EAAW,KAAMK,EAAO,GAAGF,GAASb,EAClF,MACE,iBAAA,EAAAF,EAAA,IAAA,CAAC,SAAD,CAAQ,KAAK,SAAS,GAAIe,EAAM,GAAIP,EAAaL,MAC9C,SAAAM,CACK,CAAA,CAEZ,CAAC,E"}
@@ -0,0 +1,2 @@
1
+ import{forwardRef as e}from"react";import{isSafeHref as t}from"../utils/url.mjs";import{devWarn as n}from"../utils/react.mjs";import{Fragment as r,jsx as i,jsxs as a}from"react/jsx-runtime";const o=e(function(e,o){let{icon:s,label:c,expanded:l}=e,u=s!=null,d={"data-mp":`action`,"data-expanded":l||!u?``:void 0},f=/* @__PURE__ */ a(r,{children:[u&&/* @__PURE__ */ i(`span`,{"data-mp":`action-icon`,"aria-hidden":`true`,children:s}),/* @__PURE__ */ i(`span`,{"data-mp":`label`,children:c})]});if(e.href!==void 0){let{icon:r,label:a,expanded:s,href:l,linkComponent:u,...p}=e,m=o;return t(l)?i(u||`a`,{...p,...d,ref:m,href:l,children:f}):(n(`<PillAction label="${c}"> got an unsafe href and renders without a link. Only relative, http(s):, mailto: and tel: URLs are allowed.`),/* @__PURE__ */ i(`a`,{...p,...d,ref:m,"aria-disabled":`true`,children:f}))}let{icon:p,label:m,expanded:h,href:g,..._}=e;return/* @__PURE__ */ i(`button`,{type:`button`,..._,...d,ref:o,children:f})});export{o as default};
2
+ //# sourceMappingURL=PillAction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillAction.mjs","names":["forwardRef","isSafeHref","devWarn","Fragment","jsx","jsxs","PillAction","props","ref","icon","label","expanded","hasIcon","shared","content","_icon","_label","_expanded","href","Link","rest","anchorRef","_href"],"sources":["../../src/Pill/PillAction.tsx"],"sourcesContent":["// No \"use client\": a Server Component can render a link action, with its\n// `linkComponent`, without shipping it to the client.\nimport { forwardRef, type Ref } from \"react\";\n\nimport type { PillActionProps } from \"./types\";\nimport { isSafeHref } from \"../utils/url\";\nimport { devWarn } from \"../utils/react\";\n\n/**\n * The light round button: its icon at rest, icon + bold label when expanded.\n * A <button> with `onClick`, a link with `href`.\n */\nconst PillAction = forwardRef<HTMLElement, PillActionProps>(function PillAction(props, ref) {\n const { icon, label, expanded } = props;\n const hasIcon = icon !== undefined && icon !== null;\n const shared = {\n \"data-mp\": \"action\",\n // Without an icon, the label is all there is to show\n \"data-expanded\": expanded || !hasIcon ? \"\" : undefined,\n };\n const content = (\n <>\n {hasIcon && (\n <span data-mp=\"action-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span data-mp=\"label\">{label}</span>\n </>\n );\n\n if (props.href !== undefined) {\n const { icon: _icon, label: _label, expanded: _expanded, href, linkComponent: Link, ...rest } = props;\n const anchorRef = ref as Ref<HTMLAnchorElement>;\n\n // L16: never render a `javascript:` (or any other unexpected scheme) link\n if (!isSafeHref(href)) {\n devWarn(\n `<PillAction label=\"${label}\"> got an unsafe href and renders without a link. ` +\n \"Only relative, http(s):, mailto: and tel: URLs are allowed.\",\n );\n return (\n <a {...rest} {...shared} ref={anchorRef} aria-disabled=\"true\">\n {content}\n </a>\n );\n }\n\n if (Link) {\n return (\n <Link {...rest} {...shared} ref={anchorRef} href={href}>\n {content}\n </Link>\n );\n }\n\n return (\n <a {...rest} {...shared} ref={anchorRef} href={href}>\n {content}\n </a>\n );\n }\n\n const { icon: _icon, label: _label, expanded: _expanded, href: _href, ...rest } = props;\n return (\n <button type=\"button\" {...rest} {...shared} ref={ref as Ref<HTMLButtonElement>}>\n {content}\n </button>\n );\n});\n\nexport default PillAction;\n"],"mappings":"A,8LAYA,MAAMM,EAAaN,EAAyC,SAAoBO,EAAOC,EAAK,CAC1F,GAAM,CAAEC,OAAMC,QAAOC,YAAaJ,EAC5BK,EAAUH,GAA+B,KACzCI,EAAS,CACb,UAAW,SAEX,gBAAiBF,GAAY,CAACC,EAAU,GAAK,IAAA,EAC/C,EACME,EACJT,kBAAAF,EAAA,CAAA,SAAA,CACGS,GACCR,kBAAC,OAAD,CAAM,UAAQ,cAAc,cAAY,OACrC,SAAAK,CACG,CAAA,EAERL,kBAAC,OAAD,CAAM,UAAQ,QAAS,SAAAM,CAAY,CAAA,CACnC,CAAA,CAAA,EAGJ,GAAIH,EAAM,OAAS,IAAA,GAAW,CAC5B,GAAM,CAAE,KAAMQ,EAAO,MAAOC,EAAQ,SAAUC,EAAWC,OAAM,cAAeC,EAAM,GAAGC,GAASb,EAC1Fc,EAAYb,EAuBlB,OApBKP,EAAWiB,CAAI,EAchBd,EAFAe,GASD,IAPC,CAAM,GAAIC,EAAM,GAAIP,EAAQ,IAAKQ,EAAiBH,OAC/C,SAAAJ,CACG,CAAA,GAfRZ,EACE,sBAAsBQ,EAAM,8GAE9B,EAEEN,kBAAC,IAAD,CAAG,GAAIgB,EAAM,GAAIP,EAAQ,IAAKQ,EAAW,gBAAc,OACpD,SAAAP,CACA,CAAA,EAiBT,CAEA,GAAM,CAAE,KAAMC,EAAO,MAAOC,EAAQ,SAAUC,EAAW,KAAMK,EAAO,GAAGF,GAASb,EAClF,MACEH,kBAAC,SAAD,CAAQ,KAAK,SAAS,GAAIgB,EAAM,GAAIP,EAAaL,MAC9C,SAAAM,CACK,CAAA,CAEZ,CAAC,E"}
@@ -0,0 +1,3 @@
1
+ import { PillContextValue } from "./types.mjs";
2
+ /** Read and drive the enclosing <Pill>: what you need to write your own template. */
3
+ export declare function usePill(): PillContextValue;
@@ -0,0 +1,3 @@
1
+ import { PillContextValue } from "./types.js";
2
+ /** Read and drive the enclosing <Pill>: what you need to write your own template. */
3
+ export declare function usePill(): PillContextValue;
@@ -0,0 +1,2 @@
1
+ "use client";let e=require("react");const t=(0,e.createContext)(null);function n(n){let r=(0,e.useContext)(t);if(!r)throw Error(`[magic-pill] ${n} must be rendered inside a <Pill>.`);return r}exports.PillContext=t,exports.useInternalPill=n,exports.usePill=function(){let{presence:e,setPresence:t,placement:r,orientation:i,variant:a}=n(`usePill()`);return{presence:e,setPresence:t,placement:r,orientation:i,variant:a}};
2
+ //# sourceMappingURL=PillContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillContext.js","names":["createContext","useContext","react","PillContext","useInternalPill","component","context","presence","setPresence","placement","orientation","variant"],"sources":["../../src/Pill/PillContext.ts"],"sourcesContent":["\"use client\"\nimport { createContext, useContext } from \"react\";\n\nimport type { PillContextValue } from \"./types\";\n\n/** What the parts need on top of the public value. */\nexport interface InternalPillContextValue extends PillContextValue {\n /** Back to the level the pill had before its panel opened. */\n closePanel: () => void;\n panelId: string;\n /** The trigger that opened the panel, to give focus back to on close. */\n panelTriggerRef: { current: HTMLElement | null };\n rootRef: { current: HTMLElement | null };\n}\n\nexport const PillContext = createContext<InternalPillContextValue | null>(null);\n\nexport function useInternalPill(component: string): InternalPillContextValue {\n const context = useContext(PillContext);\n if (!context) {\n throw new Error(`[magic-pill] ${component} must be rendered inside a <Pill>.`);\n }\n return context;\n}\n\n/** Read and drive the enclosing <Pill>: what you need to write your own template. */\nexport function usePill(): PillContextValue {\n const { presence, setPresence, placement, orientation, variant } = useInternalPill(\"usePill()\");\n return { presence, setPresence, placement, orientation, variant };\n}\n"],"mappings":"A,oCAeA,MAAaG,GAAA,EAAcH,EAAAA,cAAAA,CAA+C,IAAI,EAE9E,SAAgBI,EAAgBC,EAA6C,CAC3E,IAAMC,GAAA,EAAUL,EAAAA,WAAAA,CAAWE,CAAW,EACtC,GAAI,CAACG,EACH,MAAU,MAAM,gBAAgBD,EAAU,mCAAmC,EAE/E,OAAOC,CACT,C,gEAGA,UAA4C,CAC1C,GAAM,CAAEC,WAAUC,cAAaC,YAAWC,cAAaC,WAAYP,EAAgB,WAAW,EAC9F,MAAO,CAAEG,WAAUC,cAAaC,YAAWC,cAAaC,SAAQ,CAClE"}
@@ -0,0 +1,2 @@
1
+ "use client";import{createContext as e,useContext as t}from"react";const n=e(null);function r(e){let r=t(n);if(!r)throw Error(`[magic-pill] ${e} must be rendered inside a <Pill>.`);return r}function i(){let{presence:e,setPresence:t,placement:n,orientation:i,variant:a}=r(`usePill()`);return{presence:e,setPresence:t,placement:n,orientation:i,variant:a}}export{n as PillContext,r as useInternalPill,i as usePill};
2
+ //# sourceMappingURL=PillContext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillContext.mjs","names":["createContext","useContext","PillContext","useInternalPill","component","context","usePill","presence","setPresence","placement","orientation","variant"],"sources":["../../src/Pill/PillContext.ts"],"sourcesContent":["\"use client\"\nimport { createContext, useContext } from \"react\";\n\nimport type { PillContextValue } from \"./types\";\n\n/** What the parts need on top of the public value. */\nexport interface InternalPillContextValue extends PillContextValue {\n /** Back to the level the pill had before its panel opened. */\n closePanel: () => void;\n panelId: string;\n /** The trigger that opened the panel, to give focus back to on close. */\n panelTriggerRef: { current: HTMLElement | null };\n rootRef: { current: HTMLElement | null };\n}\n\nexport const PillContext = createContext<InternalPillContextValue | null>(null);\n\nexport function useInternalPill(component: string): InternalPillContextValue {\n const context = useContext(PillContext);\n if (!context) {\n throw new Error(`[magic-pill] ${component} must be rendered inside a <Pill>.`);\n }\n return context;\n}\n\n/** Read and drive the enclosing <Pill>: what you need to write your own template. */\nexport function usePill(): PillContextValue {\n const { presence, setPresence, placement, orientation, variant } = useInternalPill(\"usePill()\");\n return { presence, setPresence, placement, orientation, variant };\n}\n"],"mappings":"A,mEAeA,MAAaE,EAAcF,EAA+C,IAAI,EAE9E,SAAgBG,EAAgBC,EAA6C,CAC3E,IAAMC,EAAUJ,EAAWC,CAAW,EACtC,GAAI,CAACG,EACH,MAAU,MAAM,gBAAgBD,EAAU,mCAAmC,EAE/E,OAAOC,CACT,CAGA,SAAgBC,GAA4B,CAC1C,GAAM,CAAEC,WAAUC,cAAaC,YAAWC,cAAaC,WAAYR,EAAgB,WAAW,EAC9F,MAAO,CAAEI,WAAUC,cAAaC,YAAWC,cAAaC,SAAQ,CAClE,C"}
@@ -0,0 +1,9 @@
1
+ import { PillButtonActionProps, PillPanelProps } from "./types.mjs";
2
+ /**
3
+ * Content shown when the pill's presence is `panel` (one panel per pill).
4
+ * Labelled by its title, focused when it opens, gives focus back to its
5
+ * trigger when it closes.
6
+ */
7
+ export declare const PillPanel: import("react").ForwardRefExoticComponent<PillPanelProps & import("react").RefAttributes<HTMLDivElement>>;
8
+ /** An action that opens (and closes) the pill's panel. */
9
+ export declare const PillPanelTrigger: import("react").ForwardRefExoticComponent<Omit<PillButtonActionProps, "onClick"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,9 @@
1
+ import { PillButtonActionProps, PillPanelProps } from "./types.js";
2
+ /**
3
+ * Content shown when the pill's presence is `panel` (one panel per pill).
4
+ * Labelled by its title, focused when it opens, gives focus back to its
5
+ * trigger when it closes.
6
+ */
7
+ export declare const PillPanel: import("react").ForwardRefExoticComponent<PillPanelProps & import("react").RefAttributes<HTMLDivElement>>;
8
+ /** An action that opens (and closes) the pill's panel. */
9
+ export declare const PillPanelTrigger: import("react").ForwardRefExoticComponent<Omit<PillButtonActionProps, "onClick"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,2 @@
1
+ "use client";let e=require("react");const t=require("./PillAction.js"),n=require("./PillContext.js"),r=require("../icons/CloseIcon.js"),i=require("../utils/react.js");let a=require("react/jsx-runtime");const o=(0,e.forwardRef)(function({title:o,closeLabel:s=`Close`,closeIcon:c,children:l,...u},d){let{presence:f,closePanel:p,panelId:m,panelTriggerRef:h,rootRef:g}=n.useInternalPill(`<PillPanel>`),_=f===`panel`,v=(0,e.useId)(),y=(0,e.useRef)(null),b=(0,e.useMemo)(()=>i.mergeRefs(y,d),[d]),x=(0,e.useRef)(_);(0,e.useEffect)(()=>{let e=x.current;if(x.current=_,_&&!e)y.current?.focus({preventScroll:!0});else if(!_&&e){let e=document.activeElement;(!e||e===document.body||g.current?.contains(e))&&h.current?.focus()}},[_,h,g]);let S=o!=null;return/* @__PURE__ */ (0,a.jsxs)(`div`,{...u,ref:b,id:m,"data-mp":`panel`,"data-open":_?``:void 0,role:`region`,"aria-labelledby":S?v:void 0,tabIndex:-1,children:[S&&/* @__PURE__ */ (0,a.jsx)(`div`,{id:v,"data-mp":`panel-title`,children:o}),/* @__PURE__ */ (0,a.jsx)(`div`,{"data-mp":`panel-body`,children:l}),/* @__PURE__ */ (0,a.jsx)(`div`,{"data-mp":`panel-footer`,children:/* @__PURE__ */ (0,a.jsx)(t,{icon:c??/* @__PURE__ */ (0,a.jsx)(r,{}),label:s,onClick:p})})]})}),s=(0,e.forwardRef)(function(r,o){let{presence:s,setPresence:c,closePanel:l,panelId:u,panelTriggerRef:d}=n.useInternalPill(`<PillPanelTrigger>`),f=s===`panel`,p=(0,e.useRef)(null),m=(0,e.useMemo)(()=>i.mergeRefs(p,o),[o]),h=()=>{d.current=p.current,f?l():c(`panel`)};return/* @__PURE__ */ (0,a.jsx)(t,{...r,ref:m,"aria-expanded":f,"aria-controls":u,onClick:h})});exports.PillPanel=o,exports.PillPanelTrigger=s;
2
+ //# sourceMappingURL=PillPanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillPanel.js","names":["forwardRef","useInternalPill","useId","useRef","useMemo","mergeRefs","useEffect","PillAction","CloseIcon","react","require_PillAction","require_PillContext","require_CloseIcon","require_react","react_jsx_runtime","PillPanel","title","closeLabel","closeIcon","children","rest","forwardedRef","presence","closePanel","panelId","panelTriggerRef","rootRef","isOpen","titleId","panelRef","ref","wasOpenRef","wasOpen","active","hasTitle","PillPanelTrigger","props","setPresence","triggerRef","toggle"],"sources":["../../src/Pill/PillPanel.tsx"],"sourcesContent":["\"use client\"\nimport { forwardRef, useEffect, useId, useMemo, useRef } from \"react\";\n\nimport PillAction from \"./PillAction\";\nimport { useInternalPill } from \"./PillContext\";\nimport type { PillButtonActionProps, PillPanelProps } from \"./types\";\nimport CloseIcon from \"../icons/CloseIcon\";\nimport { mergeRefs } from \"../utils/react\";\n\n/**\n * Content shown when the pill's presence is `panel` (one panel per pill).\n * Labelled by its title, focused when it opens, gives focus back to its\n * trigger when it closes.\n */\nexport const PillPanel = forwardRef<HTMLDivElement, PillPanelProps>(function PillPanel(\n { title, closeLabel = \"Close\", closeIcon, children, ...rest },\n forwardedRef,\n) {\n const { presence, closePanel, panelId, panelTriggerRef, rootRef } = useInternalPill(\"<PillPanel>\");\n const isOpen = presence === \"panel\";\n const titleId = useId();\n const panelRef = useRef<HTMLDivElement | null>(null);\n const ref = useMemo(() => mergeRefs(panelRef, forwardedRef), [forwardedRef]);\n\n // Only on changes: a pill that starts as a panel doesn't steal the focus\n const wasOpenRef = useRef(isOpen);\n useEffect(() => {\n const wasOpen = wasOpenRef.current;\n wasOpenRef.current = isOpen;\n if (isOpen && !wasOpen) {\n panelRef.current?.focus({ preventScroll: true });\n } else if (!isOpen && wasOpen) {\n // Only when the focus would otherwise be lost (it was in the now hidden panel)\n const active = document.activeElement;\n if (!active || active === document.body || rootRef.current?.contains(active)) {\n panelTriggerRef.current?.focus();\n }\n }\n }, [isOpen, panelTriggerRef, rootRef]);\n\n const hasTitle = title !== undefined && title !== null;\n\n return (\n <div\n {...rest}\n ref={ref}\n id={panelId}\n data-mp=\"panel\"\n data-open={isOpen ? \"\" : undefined}\n role=\"region\"\n aria-labelledby={hasTitle ? titleId : undefined}\n tabIndex={-1}\n >\n {hasTitle && (\n <div id={titleId} data-mp=\"panel-title\">\n {title}\n </div>\n )}\n <div data-mp=\"panel-body\">{children}</div>\n <div data-mp=\"panel-footer\">\n <PillAction icon={closeIcon ?? <CloseIcon />} label={closeLabel} onClick={closePanel} />\n </div>\n </div>\n );\n});\n\n/** An action that opens (and closes) the pill's panel. */\nexport const PillPanelTrigger = forwardRef<HTMLButtonElement, Omit<PillButtonActionProps, \"onClick\">>(\n function PillPanelTrigger(props, forwardedRef) {\n const { presence, setPresence, closePanel, panelId, panelTriggerRef } = useInternalPill(\"<PillPanelTrigger>\");\n const isOpen = presence === \"panel\";\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const ref = useMemo(() => mergeRefs(triggerRef, forwardedRef), [forwardedRef]);\n\n const toggle = () => {\n panelTriggerRef.current = triggerRef.current;\n if (isOpen) {\n closePanel();\n } else {\n setPresence(\"panel\");\n }\n };\n\n return (\n <PillAction {...props} ref={ref} aria-expanded={isOpen} aria-controls={panelId} onClick={toggle} />\n );\n },\n);\n"],"mappings":"A,0MAcA,MAAae,GAAA,EAAYf,EAAAA,WAAAA,CAA2C,SAClE,CAAEgB,QAAOC,aAAa,QAASC,YAAWC,WAAU,GAAGC,GACvDC,EACA,CACA,GAAM,CAAEC,WAAUC,aAAYC,UAASC,kBAAiBC,WAAYzB,EAAAA,gBAAgB,aAAa,EAC3F0B,EAASL,IAAa,QACtBM,GAAA,EAAU1B,EAAAA,MAAAA,CAAM,EAChB2B,GAAA,EAAW1B,EAAAA,OAAAA,CAA8B,IAAI,EAC7C2B,GAAA,EAAM1B,EAAAA,QAAAA,KAAcC,EAAAA,UAAUwB,EAAUR,CAAY,EAAG,CAACA,CAAY,CAAC,EAGrEU,GAAA,EAAa5B,EAAAA,OAAAA,CAAOwB,CAAM,GAChCrB,EAAAA,EAAAA,UAAAA,KAAgB,CACd,IAAM0B,EAAUD,EAAW,QAE3B,GADAA,EAAW,QAAUJ,EACjBA,GAAU,CAACK,EACbH,EAAS,SAAS,MAAM,CAAE,cAAe,EAAK,CAAC,OAC1C,GAAI,CAACF,GAAUK,EAAS,C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iBAAA,EAAAvB,EAAA,IAAA,CAACP,EAAD,CAAY,GAAI6B,EAAYN,MAAK,gBAAeH,EAAQ,gBAAeH,EAAS,QAASe,CAAS,CAAA,CAEtG,CACF,E"}
@@ -0,0 +1,2 @@
1
+ "use client";import{forwardRef as e,useEffect as t,useId as n,useMemo as r,useRef as i}from"react";import a from"./PillAction.mjs";import{useInternalPill as o}from"./PillContext.mjs";import s from"../icons/CloseIcon.mjs";import{mergeRefs as c}from"../utils/react.mjs";import{jsx as l,jsxs as u}from"react/jsx-runtime";const d=e(function({title:e,closeLabel:d=`Close`,closeIcon:f,children:p,...m},h){let{presence:g,closePanel:_,panelId:v,panelTriggerRef:y,rootRef:b}=o(`<PillPanel>`),x=g===`panel`,S=n(),C=i(null),w=r(()=>c(C,h),[h]),T=i(x);t(()=>{let e=T.current;if(T.current=x,x&&!e)C.current?.focus({preventScroll:!0});else if(!x&&e){let e=document.activeElement;(!e||e===document.body||b.current?.contains(e))&&y.current?.focus()}},[x,y,b]);let E=e!=null;return/* @__PURE__ */ u(`div`,{...m,ref:w,id:v,"data-mp":`panel`,"data-open":x?``:void 0,role:`region`,"aria-labelledby":E?S:void 0,tabIndex:-1,children:[E&&/* @__PURE__ */ l(`div`,{id:S,"data-mp":`panel-title`,children:e}),/* @__PURE__ */ l(`div`,{"data-mp":`panel-body`,children:p}),/* @__PURE__ */ l(`div`,{"data-mp":`panel-footer`,children:/* @__PURE__ */ l(a,{icon:f??/* @__PURE__ */ l(s,{}),label:d,onClick:_})})]})}),f=e(function(e,t){let{presence:n,setPresence:s,closePanel:u,panelId:d,panelTriggerRef:f}=o(`<PillPanelTrigger>`),p=n===`panel`,m=i(null),h=r(()=>c(m,t),[t]),g=()=>{f.current=m.current,p?u():s(`panel`)};return/* @__PURE__ */ l(a,{...e,ref:h,"aria-expanded":p,"aria-controls":d,onClick:g})});export{d as PillPanel,f as PillPanelTrigger};
2
+ //# sourceMappingURL=PillPanel.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillPanel.mjs","names":["forwardRef","useEffect","useId","useMemo","useRef","PillAction","useInternalPill","CloseIcon","mergeRefs","jsx","jsxs","PillPanel","title","closeLabel","closeIcon","children","rest","forwardedRef","presence","closePanel","panelId","panelTriggerRef","rootRef","isOpen","titleId","panelRef","ref","wasOpenRef","wasOpen","active","hasTitle","PillPanelTrigger","props","setPresence","triggerRef","toggle"],"sources":["../../src/Pill/PillPanel.tsx"],"sourcesContent":["\"use client\"\nimport { forwardRef, useEffect, useId, useMemo, useRef } from \"react\";\n\nimport PillAction from \"./PillAction\";\nimport { useInternalPill } from \"./PillContext\";\nimport type { PillButtonActionProps, PillPanelProps } from \"./types\";\nimport CloseIcon from \"../icons/CloseIcon\";\nimport { mergeRefs } from \"../utils/react\";\n\n/**\n * Content shown when the pill's presence is `panel` (one panel per pill).\n * Labelled by its title, focused when it opens, gives focus back to its\n * trigger when it closes.\n */\nexport const PillPanel = forwardRef<HTMLDivElement, PillPanelProps>(function PillPanel(\n { title, closeLabel = \"Close\", closeIcon, children, ...rest },\n forwardedRef,\n) {\n const { presence, closePanel, panelId, panelTriggerRef, rootRef } = useInternalPill(\"<PillPanel>\");\n const isOpen = presence === \"panel\";\n const titleId = useId();\n const panelRef = useRef<HTMLDivElement | null>(null);\n const ref = useMemo(() => mergeRefs(panelRef, forwardedRef), [forwardedRef]);\n\n // Only on changes: a pill that starts as a panel doesn't steal the focus\n const wasOpenRef = useRef(isOpen);\n useEffect(() => {\n const wasOpen = wasOpenRef.current;\n wasOpenRef.current = isOpen;\n if (isOpen && !wasOpen) {\n panelRef.current?.focus({ preventScroll: true });\n } else if (!isOpen && wasOpen) {\n // Only when the focus would otherwise be lost (it was in the now hidden panel)\n const active = document.activeElement;\n if (!active || active === document.body || rootRef.current?.contains(active)) {\n panelTriggerRef.current?.focus();\n }\n }\n }, [isOpen, panelTriggerRef, rootRef]);\n\n const hasTitle = title !== undefined && title !== null;\n\n return (\n <div\n {...rest}\n ref={ref}\n id={panelId}\n data-mp=\"panel\"\n data-open={isOpen ? \"\" : undefined}\n role=\"region\"\n aria-labelledby={hasTitle ? titleId : undefined}\n tabIndex={-1}\n >\n {hasTitle && (\n <div id={titleId} data-mp=\"panel-title\">\n {title}\n </div>\n )}\n <div data-mp=\"panel-body\">{children}</div>\n <div data-mp=\"panel-footer\">\n <PillAction icon={closeIcon ?? <CloseIcon />} label={closeLabel} onClick={closePanel} />\n </div>\n </div>\n );\n});\n\n/** An action that opens (and closes) the pill's panel. */\nexport const PillPanelTrigger = forwardRef<HTMLButtonElement, Omit<PillButtonActionProps, \"onClick\">>(\n function PillPanelTrigger(props, forwardedRef) {\n const { presence, setPresence, closePanel, panelId, panelTriggerRef } = useInternalPill(\"<PillPanelTrigger>\");\n const isOpen = presence === \"panel\";\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const ref = useMemo(() => mergeRefs(triggerRef, forwardedRef), [forwardedRef]);\n\n const toggle = () => {\n panelTriggerRef.current = triggerRef.current;\n if (isOpen) {\n closePanel();\n } else {\n setPresence(\"panel\");\n }\n };\n\n return (\n <PillAction {...props} ref={ref} aria-expanded={isOpen} aria-controls={panelId} onClick={toggle} />\n );\n },\n);\n"],"mappings":"A,8TAcA,MAAaW,EAAYX,EAA2C,SAClE,CAAEY,QAAOC,aAAa,QAASC,YAAWC,WAAU,GAAGC,GACvDC,EACA,CACA,GAAM,CAAEC,WAAUC,aAAYC,UAASC,kBAAiBC,WAAYhB,EAAgB,aAAa,EAC3FiB,EAASL,IAAa,QACtBM,EAAUtB,EAAM,EAChBuB,EAAWrB,EAA8B,IAAI,EAC7CsB,EAAMvB,MAAcK,EAAUiB,EAAUR,CAAY,EAAG,CAACA,CAAY,CAAC,EAGrEU,EAAavB,EAAOmB,CAAM,EAChCtB,MAAgB,CACd,IAAM2B,EAAUD,EAAW,QAE3B,GADAA,EAAW,QAAUJ,EACjBA,GAAU,CAACK,EACbH,EAAS,SAAS,MAAM,CAAE,cAAe,EAAK,CAAC,OAC1C,GAAI,CAACF,GAAUK,EAAS,CAE7B,IAAMC,EAAS,SAAS,eACpB,CAACA,GAAUA,IAAW,SAAS,MAAQP,EAAQ,SAAS,SAASO,CAAM,IACzER,EAAgB,SAAS,MAAM,CAEnC,CACF,EAAG,CAACE,EAAQF,EAAiBC,CAAO,CAAC,EAErC,IAAMQ,EAAWlB,GAAiC,KAElD,MACEF,kBAAC,MAAD,CACE,GAAIM,EACCU,MACL,GAAIN,EACJ,UAAQ,QACR,YAAWG,EAAS,GAAK,IAAA,GACzB,KAAK,SACL,kBAAiBO,EAAWN,EAAU,IAAA,GACtC,SAAU,GARZ,SAAA,CAUGM,GACCrB,kBAAC,MAAD,CAAK,GAAIe,EAAS,UAAQ,cACvB,SAAAZ,CACE,CAAA,EAEPH,kBAAC,MAAD,CAAK,UAAQ,aAAcM,UAAc,CAAA,EACzCN,kBAAC,MAAD,CAAK,UAAQ,eACX,SAAAA,kBAACJ,EAAD,CAAY,KAAMS,GAAaL,kBAACF,EAAD,CAAY,CAAA,EAAG,MAAOM,EAAY,QAASM,CAAa,CAAA,CACpF,CAAA,CACF,C,EAET,CAAC,EAGYY,EAAmB/B,EAC9B,SAA0BgC,EAAOf,EAAc,CAC7C,GAAM,CAAEC,WAAUe,cAAad,aAAYC,UAASC,mBAAoBf,EAAgB,oBAAoB,EACtGiB,EAASL,IAAa,QACtBgB,EAAa9B,EAAiC,IAAI,EAClDsB,EAAMvB,MAAcK,EAAU0B,EAAYjB,CAAY,EAAG,CAACA,CAAY,CAAC,EAEvEkB,MAAe,CACnBd,EAAgB,QAAUa,EAAW,QACjCX,EACFJ,EAAW,EAEXc,EAAY,OAAO,CAEvB,EAEA,MACExB,kBAACJ,EAAD,CAAY,GAAI2B,EAAYN,MAAK,gBAAeH,EAAQ,gBAAeH,EAAS,QAASe,CAAS,CAAA,CAEtG,CACF,E"}
@@ -0,0 +1,10 @@
1
+ /** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
2
+ export declare const PillIcon: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
3
+ label?: string;
4
+ } & import("react").RefAttributes<HTMLSpanElement>>;
5
+ /** The thin line between the icon and the message. */
6
+ export declare const PillDivider: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
7
+ /** The message, in the italic serif. Accepts any content. */
8
+ export declare const PillMessage: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
9
+ /** A row (or a column, in a vertical pill) of actions. */
10
+ export declare const PillActions: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,10 @@
1
+ /** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
2
+ export declare const PillIcon: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
3
+ label?: string;
4
+ } & import("react").RefAttributes<HTMLSpanElement>>;
5
+ /** The thin line between the icon and the message. */
6
+ export declare const PillDivider: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
7
+ /** The message, in the italic serif. Accepts any content. */
8
+ export declare const PillMessage: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
9
+ /** A row (or a column, in a vertical pill) of actions. */
10
+ export declare const PillActions: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,2 @@
1
+ let e=require("react"),t=require("react/jsx-runtime");const n=(0,e.forwardRef)(function({label:e,...n},r){return/* @__PURE__ */ (0,t.jsx)(`span`,{...e?{role:`img`,"aria-label":e}:{"aria-hidden":!0},...n,ref:r,"data-mp":`icon`})}),r=(0,e.forwardRef)(function(e,n){return/* @__PURE__ */ (0,t.jsx)(`span`,{"aria-hidden":`true`,...e,ref:n,"data-mp":`divider`})}),i=(0,e.forwardRef)(function(e,n){return/* @__PURE__ */ (0,t.jsx)(`div`,{...e,ref:n,"data-mp":`message`})}),a=(0,e.forwardRef)(function(e,n){return/* @__PURE__ */ (0,t.jsx)(`div`,{...e,ref:n,"data-mp":`actions`})});exports.PillActions=a,exports.PillDivider=r,exports.PillIcon=n,exports.PillMessage=i;
2
+ //# sourceMappingURL=parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.js","names":["forwardRef","react","react_jsx_runtime","PillIcon","label","rest","ref","PillDivider","props","PillMessage","PillActions"],"sources":["../../src/Pill/parts.tsx"],"sourcesContent":["// No \"use client\": these parts hold no state, so Server Components can render\n// them, and they add no client JavaScript there.\nimport { forwardRef, type ComponentPropsWithoutRef } from \"react\";\n\n/** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */\nexport const PillIcon = forwardRef<HTMLSpanElement, ComponentPropsWithoutRef<\"span\"> & { label?: string }>(\n function PillIcon({ label, ...rest }, ref) {\n const a11y = label ? { role: \"img\", \"aria-label\": label } : { \"aria-hidden\": true as const };\n return <span {...a11y} {...rest} ref={ref} data-mp=\"icon\" />;\n },\n);\n\n/** The thin line between the icon and the message. */\nexport const PillDivider = forwardRef<HTMLSpanElement, ComponentPropsWithoutRef<\"span\">>(\n function PillDivider(props, ref) {\n return <span aria-hidden=\"true\" {...props} ref={ref} data-mp=\"divider\" />;\n },\n);\n\n/** The message, in the italic serif. Accepts any content. */\nexport const PillMessage = forwardRef<HTMLDivElement, ComponentPropsWithoutRef<\"div\">>(\n function PillMessage(props, ref) {\n return <div {...props} ref={ref} data-mp=\"message\" />;\n },\n);\n\n/** A row (or a column, in a vertical pill) of actions. */\nexport const PillActions = forwardRef<HTMLDivElement, ComponentPropsWithoutRef<\"div\">>(\n function PillActions(props, ref) {\n return <div {...props} ref={ref} data-mp=\"actions\" />;\n },\n);\n"],"mappings":"A,sDAKA,MAAaG,GAAA,EAAWH,EAAAA,WAAAA,CACtB,SAAkB,CAAEI,QAAO,GAAGC,GAAQC,EAAK,CAEzC,MAAO,iBAAA,EAAAJ,EAAA,IAAA,CAAC,OAAD,CAAM,GADAE,EAAQ,CAAE,KAAM,MAAO,aAAcA,CAAM,EAAI,CAAE,cAAe,EAAc,EACpE,GAAIC,EAAWC,MAAK,UAAQ,MAAQ,CAAA,CAC7D,CACF,EAGaC,GAAA,EAAcP,EAAAA,WAAAA,CACzB,SAAqBQ,EAAOF,EAAK,CAC/B,MAAO,iBAAA,EAAAJ,EAAA,IAAA,CAAC,OAAD,CAAM,cAAY,OAAO,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CAC1E,CACF,EAGaG,GAAA,EAAcT,EAAAA,WAAAA,CACzB,SAAqBQ,EAAOF,EAAK,CAC/B,MAAO,iBAAA,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CACtD,CACF,EAGaI,GAAA,EAAcV,EAAAA,WAAAA,CACzB,SAAqBQ,EAAOF,EAAK,CAC/B,MAAO,iBAAA,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CACtD,CACF,E"}
@@ -0,0 +1,2 @@
1
+ import{forwardRef as e}from"react";import{jsx as t}from"react/jsx-runtime";const n=e(function({label:e,...n},r){return/* @__PURE__ */ t(`span`,{...e?{role:`img`,"aria-label":e}:{"aria-hidden":!0},...n,ref:r,"data-mp":`icon`})}),r=e(function(e,n){return/* @__PURE__ */ t(`span`,{"aria-hidden":`true`,...e,ref:n,"data-mp":`divider`})}),i=e(function(e,n){return/* @__PURE__ */ t(`div`,{...e,ref:n,"data-mp":`message`})}),a=e(function(e,n){return/* @__PURE__ */ t(`div`,{...e,ref:n,"data-mp":`actions`})});export{a as PillActions,r as PillDivider,n as PillIcon,i as PillMessage};
2
+ //# sourceMappingURL=parts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.mjs","names":["forwardRef","jsx","PillIcon","label","rest","ref","PillDivider","props","PillMessage","PillActions"],"sources":["../../src/Pill/parts.tsx"],"sourcesContent":["// No \"use client\": these parts hold no state, so Server Components can render\n// them, and they add no client JavaScript there.\nimport { forwardRef, type ComponentPropsWithoutRef } from \"react\";\n\n/** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */\nexport const PillIcon = forwardRef<HTMLSpanElement, ComponentPropsWithoutRef<\"span\"> & { label?: string }>(\n function PillIcon({ label, ...rest }, ref) {\n const a11y = label ? { role: \"img\", \"aria-label\": label } : { \"aria-hidden\": true as const };\n return <span {...a11y} {...rest} ref={ref} data-mp=\"icon\" />;\n },\n);\n\n/** The thin line between the icon and the message. */\nexport const PillDivider = forwardRef<HTMLSpanElement, ComponentPropsWithoutRef<\"span\">>(\n function PillDivider(props, ref) {\n return <span aria-hidden=\"true\" {...props} ref={ref} data-mp=\"divider\" />;\n },\n);\n\n/** The message, in the italic serif. Accepts any content. */\nexport const PillMessage = forwardRef<HTMLDivElement, ComponentPropsWithoutRef<\"div\">>(\n function PillMessage(props, ref) {\n return <div {...props} ref={ref} data-mp=\"message\" />;\n },\n);\n\n/** A row (or a column, in a vertical pill) of actions. */\nexport const PillActions = forwardRef<HTMLDivElement, ComponentPropsWithoutRef<\"div\">>(\n function PillActions(props, ref) {\n return <div {...props} ref={ref} data-mp=\"actions\" />;\n },\n);\n"],"mappings":"A,2EAKA,MAAaE,EAAWF,EACtB,SAAkB,CAAEG,QAAO,GAAGC,GAAQC,EAAK,CAEzC,MAAOJ,kBAAC,OAAD,CAAM,GADAE,EAAQ,CAAE,KAAM,MAAO,aAAcA,CAAM,EAAI,CAAE,cAAe,EAAc,EACpE,GAAIC,EAAWC,MAAK,UAAQ,MAAQ,CAAA,CAC7D,CACF,EAGaC,EAAcN,EACzB,SAAqBO,EAAOF,EAAK,CAC/B,MAAOJ,kBAAC,OAAD,CAAM,cAAY,OAAO,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CAC1E,CACF,EAGaG,EAAcR,EACzB,SAAqBO,EAAOF,EAAK,CAC/B,MAAOJ,kBAAC,MAAD,CAAK,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CACtD,CACF,EAGaI,EAAcT,EACzB,SAAqBO,EAAOF,EAAK,CAC/B,MAAOJ,kBAAC,MAAD,CAAK,GAAIM,EAAYF,MAAK,UAAQ,SAAW,CAAA,CACtD,CACF,E"}