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 @@
1
+ {"version":3,"file":"store.js","names":["devWarn","require_react","EMPTY_STATE","lastId","isServer","createStore","name","items","state","hosts","listeners","commit","next","listener","replace","id","input","item","patch","queued","reason","dismissed","stores","getStore","store","controllers","controller"],"sources":["../../src/store/store.ts"],"sourcesContent":["// No \"use client\" and no React: the store and pill() can be imported from any\n// module and called from anywhere on the client, including outside React.\nimport type { ReactNode } from \"react\";\n\nimport type { PillVariant } from \"../Pill/types\";\nimport type { PillNotificationProps } from \"../PillNotification/PillNotification\";\nimport { devWarn } from \"../utils/react\";\n\nexport type DismissReason = \"timeout\" | \"action\" | \"dismissed\" | \"cleared\";\n\ninterface NotifyCommon {\n /**\n * Reusing the id of a queued or visible notification updates it in place\n * (e.g. \"Saving…\" → \"Saved\") instead of queueing a new one.\n */\n id?: string;\n variant?: PillVariant;\n /**\n * Milliseconds the notification stays once fully shown. Default: the host's\n * `duration` (5000). `Infinity` keeps it until dismissed. The countdown\n * pauses on hover, focus, an open panel and a hidden browser tab, and\n * starts again from the full duration afterwards.\n */\n duration?: number;\n /**\n * What screen readers announce. Default: the text of the message (or of the\n * whole pill for a `render` notification). `false` announces nothing.\n */\n announce?: string | false;\n onDismiss?: (id: string, reason: DismissReason) => void;\n}\n\n/** The built-in notification template, as data. */\nexport interface NotifyOptions extends NotifyCommon, Omit<PillNotificationProps, \"linkComponent\" | \"classNames\"> {\n render?: undefined;\n}\n\n/** Your own template, with the queue, timing and animation of the host. */\nexport interface NotifyRenderOptions extends NotifyCommon {\n render: (notification: { id: string; dismiss: () => void }) => ReactNode;\n}\n\nexport type NotifyInput = NotifyOptions | NotifyRenderOptions;\n\nexport interface QueuedNotification {\n readonly id: string;\n readonly input: NotifyInput;\n}\n\nexport interface PillQueueState {\n /** The notification the pill shows (or is about to show). */\n readonly current: QueuedNotification | null;\n /** The ones waiting behind it, first in, first out. */\n readonly queued: readonly QueuedNotification[];\n}\n\nexport interface PillController {\n readonly name: string;\n /**\n * Queue a notification (first in, first out). Returns its id.\n * Calls made before the host mounts are kept and shown once it mounts.\n */\n notify: (input: NotifyInput) => string;\n update: (id: string, patch: Partial<NotifyOptions>) => void;\n /** Dismiss one notification, or the visible one when called without an id. */\n dismiss: (id?: string) => void;\n /** Empty the queue and dismiss the visible notification. */\n clear: () => void;\n}\n\n/** One named pill's queue. Internal: the host uses more than the controller exposes. */\nexport interface PillStore {\n getState: () => PillQueueState;\n subscribe: (listener: () => void) => () => void;\n notify: (input: NotifyInput) => string;\n update: (id: string, patch: Partial<NotifyOptions>) => void;\n dismiss: (id: string | undefined, reason: DismissReason) => void;\n clear: () => void;\n /** Counts mounted hosts, to warn about two hosts with the same name. Returns the cleanup. */\n registerHost: () => () => void;\n}\n\nexport const EMPTY_STATE: PillQueueState = Object.freeze({ current: null, queued: Object.freeze([]) });\n\nlet lastId = 0;\n\n// On the server, a module-level queue would be shared by every request\nconst isServer = () => typeof document === \"undefined\";\n\nfunction createStore(name: string): PillStore {\n let items: readonly QueuedNotification[] = [];\n let state: PillQueueState = EMPTY_STATE;\n let hosts = 0;\n const listeners = new Set<() => void>();\n\n const commit = (next: readonly QueuedNotification[]) => {\n items = next;\n state = next.length === 0 ? EMPTY_STATE : { current: next[0], queued: next.slice(1) };\n listeners.forEach((listener) => listener());\n };\n\n const replace = (id: string, input: NotifyInput) =>\n commit(items.map((item) => (item.id === id ? { id, input } : item)));\n\n return {\n getState: () => state,\n\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n\n notify(input) {\n const id = input.id ?? `mp-${++lastId}`;\n if (isServer()) {\n devWarn(`pill(\"${name}\").notify() was called on the server and does nothing: call it from client code.`);\n return id;\n }\n if (items.some((item) => item.id === id)) {\n replace(id, input);\n } else {\n commit([...items, { id, input }]);\n }\n return id;\n },\n\n update(id, patch) {\n const item = items.find((queued) => queued.id === id);\n if (item) {\n replace(id, { ...item.input, ...patch } as NotifyInput);\n }\n },\n\n dismiss(id, reason) {\n const item = id === undefined ? items[0] : items.find((queued) => queued.id === id);\n if (!item) return;\n commit(items.filter((queued) => queued !== item));\n item.input.onDismiss?.(item.id, reason);\n },\n\n clear() {\n const dismissed = items;\n if (dismissed.length === 0) return;\n commit([]);\n dismissed.forEach((item) => item.input.onDismiss?.(item.id, \"cleared\"));\n },\n\n registerHost() {\n hosts += 1;\n if (hosts > 1) {\n devWarn(`Several <MagicPill name=\"${name}\"> are mounted. Give each one its own name.`);\n }\n return () => {\n hosts -= 1;\n };\n },\n };\n}\n\nconst stores = new Map<string, PillStore>();\n\n/** The store of the pill with this name, created on first use. */\nexport function getStore(name: string): PillStore {\n let store = stores.get(name);\n if (!store) {\n store = createStore(name);\n stores.set(name, store);\n }\n return store;\n}\n\nconst controllers = new Map<string, PillController>();\n\n/** Control the <MagicPill> with this name (default \"main\") from anywhere. */\nexport function pill(name = \"main\"): PillController {\n let controller = controllers.get(name);\n if (!controller) {\n const store = getStore(name);\n controller = Object.freeze({\n name,\n notify: (input: NotifyInput) => store.notify(input),\n update: (id: string, patch: Partial<NotifyOptions>) => store.update(id, patch),\n dismiss: (id?: string) => store.dismiss(id, \"dismissed\"),\n clear: () => store.clear(),\n });\n controllers.set(name, controller);\n }\n return controller;\n}\n\n/** Tests only: forget every store. */\nexport function resetStores(): void {\n stores.clear();\n controllers.clear();\n}\n"],"mappings":"A,qCAkFaE,EAA8B,OAAO,OAAO,CAAE,QAAS,KAAM,OAAQ,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC,EAErG,IAAIC,EAAS,EAGb,MAAMC,MAAiB,OAAO,SAAa,IAE3C,SAASC,EAAYC,EAAyB,CAC5C,IAAIC,EAAuC,CAAC,EACxCC,EAAwBN,EACxBO,EAAQ,EACNC,kBAAY,IAAI,IAEhBC,EAAUC,GAAwC,CACtDL,EAAQK,EACRJ,EAAQI,EAAK,SAAW,EAAIV,EAAc,CAAE,QAASU,EAAK,GAAI,OAAQA,EAAK,MAAM,CAAC,CAAE,EACpFF,EAAU,QAASG,GAAaA,EAAS,CAAC,CAC5C,EAEMC,GAAWC,EAAYC,IAC3BL,EAAOJ,EAAM,IAAKU,GAAUA,EAAK,KAAOF,EAAK,CAAEA,KAAIC,OAAM,EAAIC,CAAK,CAAC,EAErE,MAAO,CACL,aAAgBT,EAEhB,UAAUK,EAAU,CAElB,OADAH,EAAU,IAAIG,CAAQ,MACTH,EAAU,OAAOG,CAAQ,CACxC,EAEA,OAAOG,EAAO,CACZ,IAAMD,EAAKC,EAAM,IAAM,MAAM,EAAEb,IAU/B,OATIC,EAAS,GACXJ,EAAAA,QAAQ,SAASM,EAAK,iFAAiF,EAChGS,IAELR,EAAM,KAAMU,GAASA,EAAK,KAAOF,CAAE,EACrCD,EAAQC,EAAIC,CAAK,EAEjBL,EAAO,CAAC,GAAGJ,EAAO,CAAEQ,KAAIC,OAAM,CAAC,CAAC,EAE3BD,EACT,EAEA,OAAOA,EAAIG,EAAO,CAChB,IAAMD,EAAOV,EAAM,KAAMY,GAAWA,EAAO,KAAOJ,CAAE,EAChDE,GACFH,EAAQC,EAAI,CAAE,GAAGE,EAAK,MAAO,GAAGC,CAAM,CAAgB,CAE1D,EAEA,QAAQH,EAAIK,EAAQ,CAClB,IAAMH,EAAOF,IAAO,IAAA,GAAYR,EAAM,GAAKA,EAAM,KAAMY,GAAWA,EAAO,KAAOJ,CAAE,EAC7EE,IACLN,EAAOJ,EAAM,OAAQY,GAAWA,IAAWF,CAAI,CAAC,EAChDA,EAAK,MAAM,YAAYA,EAAK,GAAIG,CAAM,EACxC,EAEA,OAAQ,CACN,IAAMC,EAAYd,EACdc,EAAU,SAAW,IACzBV,EAAO,CAAC,CAAC,EACTU,EAAU,QAASJ,GAASA,EAAK,MAAM,YAAYA,EAAK,GAAI,SAAS,CAAC,EACxE,EAEA,cAAe,CAKb,MAJAR,IAAS,EACLA,EAAQ,GACVT,EAAAA,QAAQ,4BAA4BM,EAAK,4CAA4C,MAE1E,CACXG,GACF,CACF,CACF,CACF,CAEA,MAAMa,kBAAS,IAAI,IAGnB,SAAgBC,EAASjB,EAAyB,CAChD,IAAIkB,EAAQF,EAAO,IAAIhB,CAAI,EAK3B,OAJKkB,IACHA,EAAQnB,EAAYC,CAAI,EACxBgB,EAAO,IAAIhB,EAAMkB,CAAK,GAEjBA,CACT,CAEA,MAAMC,kBAAc,IAAI,I,sDAGxB,SAAqBnB,EAAO,OAAwB,CAClD,IAAIoB,EAAaD,EAAY,IAAInB,CAAI,EACrC,GAAI,CAACoB,EAAY,CACf,IAAMF,EAAQD,EAASjB,CAAI,EAC3BoB,EAAa,OAAO,OAAO,CACzBpB,OACA,OAASU,GAAuBQ,EAAM,OAAOR,CAAK,EAClD,QAASD,EAAYG,IAAkCM,EAAM,OAAOT,EAAIG,CAAK,EAC7E,QAAUH,GAAgBS,EAAM,QAAQT,EAAI,WAAW,EACvD,UAAaS,EAAM,MAAM,CAC3B,CAAC,EACDC,EAAY,IAAInB,EAAMoB,CAAU,CAClC,CACA,OAAOA,CACT"}
@@ -0,0 +1,2 @@
1
+ import{devWarn as e}from"../utils/react.mjs";const t=Object.freeze({current:null,queued:Object.freeze([])});let n=0;const r=()=>typeof document>`u`;function i(i){let a=[],o=t,s=0,c=/* @__PURE__ */ new Set,l=e=>{a=e,o=e.length===0?t:{current:e[0],queued:e.slice(1)},c.forEach(e=>e())},u=(e,t)=>l(a.map(n=>n.id===e?{id:e,input:t}:n));return{getState:()=>o,subscribe(e){return c.add(e),()=>c.delete(e)},notify(t){let o=t.id??`mp-${++n}`;return r()?(e(`pill("${i}").notify() was called on the server and does nothing: call it from client code.`),o):(a.some(e=>e.id===o)?u(o,t):l([...a,{id:o,input:t}]),o)},update(e,t){let n=a.find(t=>t.id===e);n&&u(e,{...n.input,...t})},dismiss(e,t){let n=e===void 0?a[0]:a.find(t=>t.id===e);n&&(l(a.filter(e=>e!==n)),n.input.onDismiss?.(n.id,t))},clear(){let e=a;e.length!==0&&(l([]),e.forEach(e=>e.input.onDismiss?.(e.id,`cleared`)))},registerHost(){return s+=1,s>1&&e(`Several <MagicPill name="${i}"> are mounted. Give each one its own name.`),()=>{--s}}}}const a=/* @__PURE__ */ new Map;function o(e){let t=a.get(e);return t||(t=i(e),a.set(e,t)),t}const s=/* @__PURE__ */ new Map;function c(e=`main`){let t=s.get(e);if(!t){let n=o(e);t=Object.freeze({name:e,notify:e=>n.notify(e),update:(e,t)=>n.update(e,t),dismiss:e=>n.dismiss(e,`dismissed`),clear:()=>n.clear()}),s.set(e,t)}return t}export{t as EMPTY_STATE,o as getStore,c as pill};
2
+ //# sourceMappingURL=store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.mjs","names":["devWarn","EMPTY_STATE","lastId","isServer","createStore","name","items","state","hosts","listeners","commit","next","listener","replace","id","input","item","patch","queued","reason","dismissed","stores","getStore","store","controllers","pill","controller"],"sources":["../../src/store/store.ts"],"sourcesContent":["// No \"use client\" and no React: the store and pill() can be imported from any\n// module and called from anywhere on the client, including outside React.\nimport type { ReactNode } from \"react\";\n\nimport type { PillVariant } from \"../Pill/types\";\nimport type { PillNotificationProps } from \"../PillNotification/PillNotification\";\nimport { devWarn } from \"../utils/react\";\n\nexport type DismissReason = \"timeout\" | \"action\" | \"dismissed\" | \"cleared\";\n\ninterface NotifyCommon {\n /**\n * Reusing the id of a queued or visible notification updates it in place\n * (e.g. \"Saving…\" → \"Saved\") instead of queueing a new one.\n */\n id?: string;\n variant?: PillVariant;\n /**\n * Milliseconds the notification stays once fully shown. Default: the host's\n * `duration` (5000). `Infinity` keeps it until dismissed. The countdown\n * pauses on hover, focus, an open panel and a hidden browser tab, and\n * starts again from the full duration afterwards.\n */\n duration?: number;\n /**\n * What screen readers announce. Default: the text of the message (or of the\n * whole pill for a `render` notification). `false` announces nothing.\n */\n announce?: string | false;\n onDismiss?: (id: string, reason: DismissReason) => void;\n}\n\n/** The built-in notification template, as data. */\nexport interface NotifyOptions extends NotifyCommon, Omit<PillNotificationProps, \"linkComponent\" | \"classNames\"> {\n render?: undefined;\n}\n\n/** Your own template, with the queue, timing and animation of the host. */\nexport interface NotifyRenderOptions extends NotifyCommon {\n render: (notification: { id: string; dismiss: () => void }) => ReactNode;\n}\n\nexport type NotifyInput = NotifyOptions | NotifyRenderOptions;\n\nexport interface QueuedNotification {\n readonly id: string;\n readonly input: NotifyInput;\n}\n\nexport interface PillQueueState {\n /** The notification the pill shows (or is about to show). */\n readonly current: QueuedNotification | null;\n /** The ones waiting behind it, first in, first out. */\n readonly queued: readonly QueuedNotification[];\n}\n\nexport interface PillController {\n readonly name: string;\n /**\n * Queue a notification (first in, first out). Returns its id.\n * Calls made before the host mounts are kept and shown once it mounts.\n */\n notify: (input: NotifyInput) => string;\n update: (id: string, patch: Partial<NotifyOptions>) => void;\n /** Dismiss one notification, or the visible one when called without an id. */\n dismiss: (id?: string) => void;\n /** Empty the queue and dismiss the visible notification. */\n clear: () => void;\n}\n\n/** One named pill's queue. Internal: the host uses more than the controller exposes. */\nexport interface PillStore {\n getState: () => PillQueueState;\n subscribe: (listener: () => void) => () => void;\n notify: (input: NotifyInput) => string;\n update: (id: string, patch: Partial<NotifyOptions>) => void;\n dismiss: (id: string | undefined, reason: DismissReason) => void;\n clear: () => void;\n /** Counts mounted hosts, to warn about two hosts with the same name. Returns the cleanup. */\n registerHost: () => () => void;\n}\n\nexport const EMPTY_STATE: PillQueueState = Object.freeze({ current: null, queued: Object.freeze([]) });\n\nlet lastId = 0;\n\n// On the server, a module-level queue would be shared by every request\nconst isServer = () => typeof document === \"undefined\";\n\nfunction createStore(name: string): PillStore {\n let items: readonly QueuedNotification[] = [];\n let state: PillQueueState = EMPTY_STATE;\n let hosts = 0;\n const listeners = new Set<() => void>();\n\n const commit = (next: readonly QueuedNotification[]) => {\n items = next;\n state = next.length === 0 ? EMPTY_STATE : { current: next[0], queued: next.slice(1) };\n listeners.forEach((listener) => listener());\n };\n\n const replace = (id: string, input: NotifyInput) =>\n commit(items.map((item) => (item.id === id ? { id, input } : item)));\n\n return {\n getState: () => state,\n\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n\n notify(input) {\n const id = input.id ?? `mp-${++lastId}`;\n if (isServer()) {\n devWarn(`pill(\"${name}\").notify() was called on the server and does nothing: call it from client code.`);\n return id;\n }\n if (items.some((item) => item.id === id)) {\n replace(id, input);\n } else {\n commit([...items, { id, input }]);\n }\n return id;\n },\n\n update(id, patch) {\n const item = items.find((queued) => queued.id === id);\n if (item) {\n replace(id, { ...item.input, ...patch } as NotifyInput);\n }\n },\n\n dismiss(id, reason) {\n const item = id === undefined ? items[0] : items.find((queued) => queued.id === id);\n if (!item) return;\n commit(items.filter((queued) => queued !== item));\n item.input.onDismiss?.(item.id, reason);\n },\n\n clear() {\n const dismissed = items;\n if (dismissed.length === 0) return;\n commit([]);\n dismissed.forEach((item) => item.input.onDismiss?.(item.id, \"cleared\"));\n },\n\n registerHost() {\n hosts += 1;\n if (hosts > 1) {\n devWarn(`Several <MagicPill name=\"${name}\"> are mounted. Give each one its own name.`);\n }\n return () => {\n hosts -= 1;\n };\n },\n };\n}\n\nconst stores = new Map<string, PillStore>();\n\n/** The store of the pill with this name, created on first use. */\nexport function getStore(name: string): PillStore {\n let store = stores.get(name);\n if (!store) {\n store = createStore(name);\n stores.set(name, store);\n }\n return store;\n}\n\nconst controllers = new Map<string, PillController>();\n\n/** Control the <MagicPill> with this name (default \"main\") from anywhere. */\nexport function pill(name = \"main\"): PillController {\n let controller = controllers.get(name);\n if (!controller) {\n const store = getStore(name);\n controller = Object.freeze({\n name,\n notify: (input: NotifyInput) => store.notify(input),\n update: (id: string, patch: Partial<NotifyOptions>) => store.update(id, patch),\n dismiss: (id?: string) => store.dismiss(id, \"dismissed\"),\n clear: () => store.clear(),\n });\n controllers.set(name, controller);\n }\n return controller;\n}\n\n/** Tests only: forget every store. */\nexport function resetStores(): void {\n stores.clear();\n controllers.clear();\n}\n"],"mappings":"A,6CAkFA,MAAaC,EAA8B,OAAO,OAAO,CAAE,QAAS,KAAM,OAAQ,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC,EAErG,IAAIC,EAAS,EAGb,MAAMC,MAAiB,OAAO,SAAa,IAE3C,SAASC,EAAYC,EAAyB,CAC5C,IAAIC,EAAuC,CAAC,EACxCC,EAAwBN,EACxBO,EAAQ,EACNC,kBAAY,IAAI,IAEhBC,EAAUC,GAAwC,CACtDL,EAAQK,EACRJ,EAAQI,EAAK,SAAW,EAAIV,EAAc,CAAE,QAASU,EAAK,GAAI,OAAQA,EAAK,MAAM,CAAC,CAAE,EACpFF,EAAU,QAASG,GAAaA,EAAS,CAAC,CAC5C,EAEMC,GAAWC,EAAYC,IAC3BL,EAAOJ,EAAM,IAAKU,GAAUA,EAAK,KAAOF,EAAK,CAAEA,KAAIC,OAAM,EAAIC,CAAK,CAAC,EAErE,MAAO,CACL,aAAgBT,EAEhB,UAAUK,EAAU,CAElB,OADAH,EAAU,IAAIG,CAAQ,MACTH,EAAU,OAAOG,CAAQ,CACxC,EAEA,OAAOG,EAAO,CACZ,IAAMD,EAAKC,EAAM,IAAM,MAAM,EAAEb,IAU/B,OATIC,EAAS,GACXH,EAAQ,SAASK,EAAK,iFAAiF,EAChGS,IAELR,EAAM,KAAMU,GAASA,EAAK,KAAOF,CAAE,EACrCD,EAAQC,EAAIC,CAAK,EAEjBL,EAAO,CAAC,GAAGJ,EAAO,CAAEQ,KAAIC,OAAM,CAAC,CAAC,EAE3BD,EACT,EAEA,OAAOA,EAAIG,EAAO,CAChB,IAAMD,EAAOV,EAAM,KAAMY,GAAWA,EAAO,KAAOJ,CAAE,EAChDE,GACFH,EAAQC,EAAI,CAAE,GAAGE,EAAK,MAAO,GAAGC,CAAM,CAAgB,CAE1D,EAEA,QAAQH,EAAIK,EAAQ,CAClB,IAAMH,EAAOF,IAAO,IAAA,GAAYR,EAAM,GAAKA,EAAM,KAAMY,GAAWA,EAAO,KAAOJ,CAAE,EAC7EE,IACLN,EAAOJ,EAAM,OAAQY,GAAWA,IAAWF,CAAI,CAAC,EAChDA,EAAK,MAAM,YAAYA,EAAK,GAAIG,CAAM,EACxC,EAEA,OAAQ,CACN,IAAMC,EAAYd,EACdc,EAAU,SAAW,IACzBV,EAAO,CAAC,CAAC,EACTU,EAAU,QAASJ,GAASA,EAAK,MAAM,YAAYA,EAAK,GAAI,SAAS,CAAC,EACxE,EAEA,cAAe,CAKb,MAJAR,IAAS,EACLA,EAAQ,GACVR,EAAQ,4BAA4BK,EAAK,4CAA4C,MAE1E,CACXG,GACF,CACF,CACF,CACF,CAEA,MAAMa,kBAAS,IAAI,IAGnB,SAAgBC,EAASjB,EAAyB,CAChD,IAAIkB,EAAQF,EAAO,IAAIhB,CAAI,EAK3B,OAJKkB,IACHA,EAAQnB,EAAYC,CAAI,EACxBgB,EAAO,IAAIhB,EAAMkB,CAAK,GAEjBA,CACT,CAEA,MAAMC,kBAAc,IAAI,IAGxB,SAAgBC,EAAKpB,EAAO,OAAwB,CAClD,IAAIqB,EAAaF,EAAY,IAAInB,CAAI,EACrC,GAAI,CAACqB,EAAY,CACf,IAAMH,EAAQD,EAASjB,CAAI,EAC3BqB,EAAa,OAAO,OAAO,CACzBrB,OACA,OAASU,GAAuBQ,EAAM,OAAOR,CAAK,EAClD,QAASD,EAAYG,IAAkCM,EAAM,OAAOT,EAAIG,CAAK,EAC7E,QAAUH,GAAgBS,EAAM,QAAQT,EAAI,WAAW,EACvD,UAAaS,EAAM,MAAM,CAC3B,CAAC,EACDC,EAAY,IAAInB,EAAMqB,CAAU,CAClC,CACA,OAAOA,CACT,C"}
@@ -0,0 +1,6 @@
1
+ import { PillQueueState } from "./store.mjs";
2
+ /**
3
+ * Headless access to a pill's queue, to build your own host or display
4
+ * (like react-hot-toast's useToaster). <MagicPill> is built on it.
5
+ */
6
+ export declare function usePillQueue(name?: string): PillQueueState;
@@ -0,0 +1,6 @@
1
+ import { PillQueueState } from "./store.js";
2
+ /**
3
+ * Headless access to a pill's queue, to build your own host or display
4
+ * (like react-hot-toast's useToaster). <MagicPill> is built on it.
5
+ */
6
+ export declare function usePillQueue(name?: string): PillQueueState;
@@ -0,0 +1,2 @@
1
+ "use client";let e=require("react");const t=require("./store.js"),n=()=>t.EMPTY_STATE;exports.usePillQueue=function(r=`main`){let i=t.getStore(r);return(0,e.useSyncExternalStore)(i.subscribe,i.getState,n)};
2
+ //# sourceMappingURL=usePillQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePillQueue.js","names":["EMPTY_STATE","getStore","useSyncExternalStore","react","require_store","getServerSnapshot","name","store"],"sources":["../../src/store/usePillQueue.ts"],"sourcesContent":["\"use client\"\nimport { useSyncExternalStore } from \"react\";\n\nimport { EMPTY_STATE, getStore, type PillQueueState } from \"./store\";\n\n// The server never holds notifications (see store.ts), and hydration must match it\nconst getServerSnapshot = () => EMPTY_STATE;\n\n/**\n * Headless access to a pill's queue, to build your own host or display\n * (like react-hot-toast's useToaster). <MagicPill> is built on it.\n */\nexport function usePillQueue(name = \"main\"): PillQueueState {\n const store = getStore(name);\n return useSyncExternalStore(store.subscribe, store.getState, getServerSnapshot);\n}\n"],"mappings":"A,kEAMMK,MAA0BL,EAAAA,Y,qBAMhC,SAA6BM,EAAO,OAAwB,CAC1D,IAAMC,EAAQN,EAAAA,SAASK,CAAI,EAC3B,OAAA,EAAOJ,EAAAA,qBAAAA,CAAqBK,EAAM,UAAWA,EAAM,SAAUF,CAAiB,CAChF"}
@@ -0,0 +1,2 @@
1
+ "use client";import{useSyncExternalStore as e}from"react";import{EMPTY_STATE as t,getStore as n}from"./store.mjs";const r=()=>t;function i(t=`main`){let i=n(t);return e(i.subscribe,i.getState,r)}export{i as usePillQueue};
2
+ //# sourceMappingURL=usePillQueue.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePillQueue.mjs","names":["useSyncExternalStore","EMPTY_STATE","getStore","getServerSnapshot","usePillQueue","name","store"],"sources":["../../src/store/usePillQueue.ts"],"sourcesContent":["\"use client\"\nimport { useSyncExternalStore } from \"react\";\n\nimport { EMPTY_STATE, getStore, type PillQueueState } from \"./store\";\n\n// The server never holds notifications (see store.ts), and hydration must match it\nconst getServerSnapshot = () => EMPTY_STATE;\n\n/**\n * Headless access to a pill's queue, to build your own host or display\n * (like react-hot-toast's useToaster). <MagicPill> is built on it.\n */\nexport function usePillQueue(name = \"main\"): PillQueueState {\n const store = getStore(name);\n return useSyncExternalStore(store.subscribe, store.getState, getServerSnapshot);\n}\n"],"mappings":"A,kHAMA,MAAMG,MAA0BF,EAMhC,SAAgBG,EAAaC,EAAO,OAAwB,CAC1D,IAAMC,EAAQJ,EAASG,CAAI,EAC3B,OAAOL,EAAqBM,EAAM,UAAWA,EAAM,SAAUH,CAAiB,CAChF,C"}
@@ -0,0 +1,427 @@
1
+ /*
2
+ * Magic Pill v9 styles.
3
+ *
4
+ * - Every rule sits in the `magic-pill` cascade layer: any CSS of yours that
5
+ * isn't in a layer wins, whatever its specificity, without !important.
6
+ * With Tailwind v4, declare the order once, before your imports:
7
+ * @layer theme, base, magic-pill, components, utilities;
8
+ * - Parts are selected by [data-mp="…"] and states by data attributes.
9
+ * There are no class names of ours to collide with yours.
10
+ * - No fonts are loaded. The pill uses your page's fonts; set --mp-font-text
11
+ * and --mp-font-accent for the Magic Pill look (Overlock + Lexend).
12
+ * - Public tokens (--mp-*) are only read, with fallbacks, never declared
13
+ * here: set them on :root, on one pill, or anywhere in between.
14
+ * Private values start with --_mp-.
15
+ */
16
+
17
+ @layer magic-pill {
18
+ /* Behaviour comes last, so it beats the look whatever the specificity:
19
+ a closed panel or a hidden pill stays hidden even if a visual rule
20
+ sets a display. Your own unlayered CSS still beats both. */
21
+ @layer look, behaviour;
22
+
23
+ @layer behaviour {
24
+ /* ─── Behaviour: kept by `unstyled` pills ──────────────────────────────── */
25
+
26
+ /* Hidden: invisible once the exit transition is over. React also makes it inert. */
27
+ [data-mp="pill"][data-presence="hidden"] {
28
+ visibility: hidden;
29
+ }
30
+
31
+ /* A closed <dialog> stays closed, whatever display the pill uses */
32
+ dialog[data-mp="pill"]:not([open]) {
33
+ display: none;
34
+ }
35
+
36
+ /* Resting circle: only the leading icon remains, for everyone */
37
+ [data-mp="pill"][data-presence="rest"] > :not([data-mp="icon"]) {
38
+ visibility: hidden;
39
+ }
40
+
41
+ /* The panel replaces the pill's content while it's open */
42
+ [data-mp="panel"]:not([data-open]),
43
+ [data-mp="pill"][data-presence="panel"] > :not([data-mp="panel"]) {
44
+ display: none;
45
+ }
46
+ }
47
+
48
+ @layer look {
49
+ /* ─── Look ─────────────────────────────────────────────────────────────── */
50
+
51
+ [data-mp="pill"]:not([data-unstyled]) {
52
+ --_mp-surface: var(--mp-surface, #141414);
53
+ --_mp-on-surface: var(--mp-on-surface, #f9f9f9);
54
+ --_mp-action: var(--mp-action, #f9f9f9);
55
+ --_mp-on-action: var(--mp-on-action, #141414);
56
+ --_mp-offset: var(--mp-offset, 1.5rem);
57
+ --_mp-padding: var(--mp-padding, 0.875rem);
58
+ --_mp-gap: var(--mp-gap, 1rem);
59
+ --_mp-action-size: var(--mp-action-size, 2.75rem);
60
+ --_mp-rest-size: calc(var(--_mp-action-size) + 2 * var(--_mp-padding));
61
+ --_mp-max-size: min(var(--mp-max-width, 48rem), 100%);
62
+ --_mp-enter: var(--mp-duration-enter, 500ms);
63
+ --_mp-exit: var(--mp-duration-exit, 300ms);
64
+ --_mp-change: var(--mp-duration-change, 250ms);
65
+ /* The entry overshoot from the mockups' "pop" */
66
+ --_mp-ease-enter: cubic-bezier(0.34, 1.56, 0.64, 1);
67
+
68
+ box-sizing: border-box;
69
+ display: flex;
70
+ align-items: center;
71
+ gap: var(--_mp-gap);
72
+ inline-size: fit-content;
73
+ min-block-size: var(--_mp-rest-size);
74
+ max-inline-size: var(--_mp-max-size);
75
+ margin: 0;
76
+ padding: var(--_mp-padding);
77
+ overflow: hidden;
78
+ border: 0;
79
+ border-radius: 9999px;
80
+ background: var(--_mp-surface);
81
+ color: var(--_mp-on-surface);
82
+ box-shadow: var(--mp-shadow, 0 0.5rem 0.5rem rgb(20 20 20 / 0.45));
83
+ font-family: var(--mp-font-text, inherit);
84
+ font-size: var(--mp-text-size, clamp(0.9375rem, 0.875rem + 0.25vw, 1.0625rem));
85
+ line-height: 1.3;
86
+ scale: 1;
87
+ /* Lets the width animate from its real size (fit-content) to the
88
+ circle's, where supported; elsewhere max-inline-size does the work */
89
+ interpolate-size: allow-keywords;
90
+ transition:
91
+ scale var(--_mp-enter) var(--_mp-ease-enter),
92
+ inline-size var(--_mp-change) ease-in-out,
93
+ block-size var(--_mp-change) ease-in-out,
94
+ max-inline-size var(--_mp-change) ease-in-out,
95
+ max-block-size var(--_mp-change) ease-in-out,
96
+ border-radius var(--_mp-change) ease-in-out,
97
+ padding var(--_mp-change) ease-in-out,
98
+ background-color var(--_mp-change) ease-in-out,
99
+ visibility 0s;
100
+
101
+ & *,
102
+ & *::before,
103
+ & *::after {
104
+ box-sizing: border-box;
105
+ }
106
+
107
+ /* Variants */
108
+ &[data-variant="success"] {
109
+ --_mp-surface: var(--mp-success, #3f7253);
110
+ }
111
+
112
+ /* Darker than 8.x's #fc5d6a, which had a 2.9:1 contrast with the light text */
113
+ &[data-variant="danger"] {
114
+ --_mp-surface: var(--mp-danger, #c2303e);
115
+ }
116
+
117
+ /* Presence levels */
118
+ &[data-presence="hidden"] {
119
+ scale: 0;
120
+ inline-size: var(--_mp-rest-size);
121
+ max-inline-size: var(--_mp-rest-size);
122
+ max-block-size: var(--_mp-rest-size);
123
+ /* Shrink to a circle, then scale out, then stop being visible */
124
+ transition:
125
+ scale var(--_mp-exit) ease-in var(--_mp-change),
126
+ inline-size var(--_mp-change) ease-in-out,
127
+ block-size var(--_mp-change) ease-in-out,
128
+ max-inline-size var(--_mp-change) ease-in-out,
129
+ max-block-size var(--_mp-change) ease-in-out,
130
+ border-radius var(--_mp-change) ease-in-out,
131
+ padding var(--_mp-change) ease-in-out,
132
+ background-color var(--_mp-change) ease-in-out,
133
+ visibility 0s linear calc(var(--_mp-change) + var(--_mp-exit));
134
+ }
135
+
136
+ /* A circle: both axes clamped, whatever the hidden content would need */
137
+ &[data-presence="rest"] {
138
+ inline-size: var(--_mp-rest-size);
139
+ max-inline-size: var(--_mp-rest-size);
140
+ max-block-size: var(--_mp-rest-size);
141
+ }
142
+
143
+ /* The content stays while the pill closes over it, then hides */
144
+ & > :not([data-mp="icon"], [data-mp="panel"]) {
145
+ transition: visibility 0s;
146
+ }
147
+
148
+ &[data-presence="rest"] > :not([data-mp="icon"], [data-mp="panel"]) {
149
+ transition: visibility 0s linear var(--_mp-change);
150
+ }
151
+
152
+ &[data-presence="panel"] {
153
+ --_mp-max-size: min(var(--mp-panel-width, 32rem), 100%);
154
+ display: block;
155
+ max-block-size: calc(100dvh - 2 * var(--_mp-offset));
156
+ padding: calc(var(--_mp-padding) * 2.5);
157
+ overflow-y: auto;
158
+ border-radius: var(--mp-radius-panel, 2.5rem);
159
+ }
160
+
161
+ /* Placements: fixed ones stay inside the viewport and its safe areas */
162
+ &:not([data-placement="inline"]) {
163
+ --_mp-max-size: min(var(--mp-max-width, 48rem), 100vw - 2 * var(--_mp-offset));
164
+ position: fixed;
165
+ z-index: var(--mp-z-index, 50);
166
+ }
167
+
168
+ &[data-presence="panel"]:not([data-placement="inline"]) {
169
+ --_mp-max-size: min(var(--mp-panel-width, 32rem), 100vw - 2 * var(--_mp-offset));
170
+ }
171
+
172
+ &[data-placement^="top"] {
173
+ inset-block-start: calc(var(--_mp-offset) + env(safe-area-inset-top, 0px));
174
+ transform-origin: top;
175
+ }
176
+
177
+ &[data-placement^="bottom"] {
178
+ inset-block-end: calc(var(--_mp-offset) + env(safe-area-inset-bottom, 0px));
179
+ transform-origin: bottom;
180
+ }
181
+
182
+ /* Centred with auto margins, not left: 50% + translate, which would
183
+ leave the pill only half the viewport to size itself in */
184
+ &[data-placement="top"],
185
+ &[data-placement="bottom"] {
186
+ inset-inline: 0;
187
+ margin-inline: auto;
188
+ }
189
+
190
+ &[data-placement$="-start"] {
191
+ inset-inline-start: var(--_mp-offset);
192
+ }
193
+
194
+ &[data-placement$="-end"] {
195
+ inset-inline-end: var(--_mp-offset);
196
+ }
197
+
198
+ &[data-placement="left"],
199
+ &[data-placement="right"] {
200
+ inset-block: 0;
201
+ margin-block: auto;
202
+ block-size: fit-content;
203
+ }
204
+
205
+ &[data-placement="left"] {
206
+ left: calc(var(--_mp-offset) + env(safe-area-inset-left, 0px));
207
+ transform-origin: left;
208
+ }
209
+
210
+ &[data-placement="right"] {
211
+ right: calc(var(--_mp-offset) + env(safe-area-inset-right, 0px));
212
+ transform-origin: right;
213
+ }
214
+
215
+ &[data-placement="overlay"] {
216
+ inset: 0;
217
+ margin: auto;
218
+ block-size: fit-content;
219
+ max-block-size: calc(100dvh - 2 * var(--_mp-offset));
220
+
221
+ &::backdrop {
222
+ background: var(--mp-backdrop, rgb(20 20 20 / 0.4));
223
+ }
224
+ }
225
+
226
+ /* Vertical pills (sidebars) */
227
+ &[data-orientation="vertical"] {
228
+ flex-direction: column;
229
+ inline-size: auto;
230
+ block-size: fit-content;
231
+ max-inline-size: none;
232
+ }
233
+
234
+ &[data-orientation="vertical"]:not([data-presence="rest"], [data-presence="hidden"]) {
235
+ max-block-size: calc(100dvh - 2 * var(--_mp-offset));
236
+ }
237
+
238
+ &[data-orientation="vertical"]:is([data-presence="rest"], [data-presence="hidden"]) {
239
+ block-size: var(--_mp-rest-size);
240
+ }
241
+
242
+ /* Parts */
243
+ & [data-mp="icon"] {
244
+ flex: none;
245
+ display: grid;
246
+ place-items: center;
247
+ inline-size: var(--_mp-action-size);
248
+ block-size: var(--_mp-action-size);
249
+ font-size: calc(var(--_mp-action-size) * 0.6);
250
+ }
251
+
252
+ & [data-mp="divider"] {
253
+ flex: none;
254
+ align-self: center;
255
+ inline-size: 1px;
256
+ block-size: var(--_mp-action-size);
257
+ background: currentColor;
258
+ }
259
+
260
+ &[data-orientation="vertical"] [data-mp="divider"] {
261
+ inline-size: var(--_mp-action-size);
262
+ block-size: 1px;
263
+ }
264
+
265
+ /* Its own width, up to a cap: it doesn't reflow word by word while the
266
+ pill grows (the pill reveals it instead), and still wraps on phones */
267
+ & [data-mp="message"] {
268
+ flex: 0 0 auto;
269
+ inline-size: max-content;
270
+ max-inline-size: min(var(--mp-message-width, 24rem), 100vw - 14rem);
271
+ font-style: italic;
272
+ text-wrap: balance;
273
+ }
274
+
275
+ & [data-mp="actions"] {
276
+ flex: none;
277
+ display: flex;
278
+ align-items: center;
279
+ gap: calc(var(--_mp-gap) * 0.75);
280
+ }
281
+
282
+ &[data-orientation="vertical"] [data-mp="actions"] {
283
+ flex-direction: column;
284
+ }
285
+
286
+ & [data-mp="action"] {
287
+ appearance: none;
288
+ flex: none;
289
+ display: inline-flex;
290
+ align-items: center;
291
+ block-size: var(--_mp-action-size);
292
+ min-inline-size: var(--_mp-action-size);
293
+ margin: 0;
294
+ padding-inline: calc((var(--_mp-action-size) - 1.25rem) / 2);
295
+ overflow: hidden;
296
+ border: 0;
297
+ border-radius: 9999px;
298
+ background: var(--_mp-action);
299
+ color: var(--_mp-on-action);
300
+ font: inherit;
301
+ font-family: var(--mp-font-accent, inherit);
302
+ font-style: normal;
303
+ font-weight: 700;
304
+ white-space: nowrap;
305
+ text-decoration: none;
306
+ cursor: pointer;
307
+ transition: padding var(--_mp-change) ease-in-out;
308
+ }
309
+
310
+ & [data-mp="action"]:focus-visible {
311
+ outline: 2px solid var(--_mp-on-surface);
312
+ outline-offset: 2px;
313
+ }
314
+
315
+ & [data-mp="action"][aria-disabled="true"] {
316
+ cursor: not-allowed;
317
+ opacity: 0.6;
318
+ }
319
+
320
+ & [data-mp="action-icon"] {
321
+ flex: none;
322
+ display: grid;
323
+ place-items: center;
324
+ inline-size: 1.25rem;
325
+ block-size: 1.25rem;
326
+ font-size: 1.25rem;
327
+ }
328
+
329
+ & [data-mp="icon"] > svg,
330
+ & [data-mp="action-icon"] > svg {
331
+ inline-size: 1em;
332
+ block-size: 1em;
333
+ }
334
+
335
+ /* Labels: folded away (but still the accessible name) until expanded */
336
+ & [data-mp="label"] {
337
+ max-inline-size: 0;
338
+ opacity: 0;
339
+ transition:
340
+ max-inline-size var(--_mp-change) ease-in-out,
341
+ opacity var(--_mp-change) ease-in-out,
342
+ margin var(--_mp-change) ease-in-out;
343
+ }
344
+
345
+ & [data-mp="action"]:is(:hover, :focus-visible, [data-expanded], [aria-current="page"], [aria-current="true"]),
346
+ &:is([data-presence="expanded"], [data-presence="panel"]) [data-mp="action"] {
347
+ padding-inline-end: calc(var(--_mp-action-size) / 2.5);
348
+
349
+ & [data-mp="label"] {
350
+ max-inline-size: 20rem;
351
+ opacity: 1;
352
+ }
353
+
354
+ & [data-mp="action-icon"] + [data-mp="label"] {
355
+ margin-inline-start: 0.5rem;
356
+ }
357
+ }
358
+
359
+ /* Panel */
360
+ & [data-mp="panel"] {
361
+ display: grid;
362
+ gap: var(--_mp-gap);
363
+ outline: none;
364
+ opacity: 1;
365
+ transition: opacity var(--_mp-change) ease-out var(--_mp-change);
366
+
367
+ @starting-style {
368
+ opacity: 0;
369
+ }
370
+ }
371
+
372
+ & [data-mp="panel-title"] {
373
+ font-size: var(--mp-title-size, clamp(1.5rem, 1.25rem + 1vw, 2rem));
374
+ font-style: italic;
375
+ font-weight: 900;
376
+ line-height: 1.15;
377
+ }
378
+
379
+ & [data-mp="panel-body"] {
380
+ font-style: italic;
381
+ }
382
+
383
+ /* Stays in reach when a long panel scrolls */
384
+ & [data-mp="panel-footer"] {
385
+ position: sticky;
386
+ inset-block-end: 0;
387
+ display: flex;
388
+ justify-content: center;
389
+ padding-block-start: var(--_mp-gap);
390
+ background: linear-gradient(transparent, var(--_mp-surface) 50%);
391
+ }
392
+ }
393
+
394
+ /* ─── Preferences ──────────────────────────────────────────────────────── */
395
+
396
+ /* Reduced motion: short fades instead of scaling and resizing */
397
+ @media (prefers-reduced-motion: reduce) {
398
+ [data-mp="pill"]:not([data-unstyled]) {
399
+ transition:
400
+ opacity 150ms linear,
401
+ visibility 0s;
402
+
403
+ &[data-presence="hidden"] {
404
+ scale: 1;
405
+ opacity: 0;
406
+ transition:
407
+ opacity 150ms linear,
408
+ visibility 0s linear 150ms;
409
+ }
410
+
411
+ & [data-mp="label"],
412
+ & [data-mp="action"],
413
+ & [data-mp="panel"] {
414
+ transition: none;
415
+ }
416
+ }
417
+ }
418
+
419
+ /* Forced colours (e.g. Windows High Contrast): keep the shapes visible */
420
+ @media (forced-colors: active) {
421
+ [data-mp="pill"]:not([data-unstyled]),
422
+ [data-mp="pill"]:not([data-unstyled]) [data-mp="action"] {
423
+ border: 1px solid CanvasText;
424
+ }
425
+ }
426
+ }
427
+ }
@@ -0,0 +1,2 @@
1
+ let e=require("react");const t=Number.parseInt(e.version,10)>=19||``;exports.devWarn=function(e){typeof process<`u`&&process.env.NODE_ENV!==`production`&&console.warn(`[magic-pill] ${e}`)},exports.inertProps=function(e){return e?{inert:t}:{}},exports.mergeRefs=function(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n&&(n.current=t)}};
2
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":["version","react","INERT_VALUE","message","inert","refs","node","ref"],"sources":["../../src/utils/react.ts"],"sourcesContent":["import { version, type Ref, type RefCallback } from \"react\";\n\n// Bundlers replace `process.env.NODE_ENV`; the typeof guard covers the rest.\ndeclare const process: { env: { NODE_ENV?: string } } | undefined;\n\n/** Warn in development builds only. */\nexport function devWarn(message: string): void {\n if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n console.warn(`[magic-pill] ${message}`);\n }\n}\n\n// React 19 knows `inert` as a boolean attribute. React 18 doesn't: it drops\n// `true` with a warning, so it needs an empty string, which React 19 treats as false.\nconst INERT_VALUE = Number.parseInt(version, 10) >= 19 ? true : \"\";\n\n/** Spread on an element to make it inert (unfocusable, hidden from assistive technology). */\nexport function inertProps(inert: boolean): { inert?: boolean } {\n return inert ? ({ inert: INERT_VALUE } as { inert: boolean }) : {};\n}\n\n/** Combine refs (React 18 compatible: no ref cleanup functions). */\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n };\n}\n"],"mappings":"A,uBAcA,MAAME,EAAc,OAAO,SAASF,EAAAA,QAAS,EAAE,GAAK,IAAY,G,gBARhE,SAAwBG,EAAuB,CACzC,OAAO,QAAY,KAAe,QAAQ,IAAI,WAAa,cAC7D,QAAQ,KAAK,gBAAgBA,GAAS,CAE1C,E,mBAOA,SAA2BC,EAAqC,CAC9D,OAAOA,EAAS,CAAE,MAAOF,CAAY,EAA2B,CAAC,CACnE,E,kBAGA,SAA6B,GAAGG,EAA8C,CAC5E,MAAQC,IAAS,CACf,IAAK,IAAMC,KAAOF,EACZ,OAAOE,GAAQ,WACjBA,EAAID,CAAI,EACCC,IACTA,EAAI,QAAUD,EAGpB,CACF"}
@@ -0,0 +1,2 @@
1
+ import{version as e}from"react";function t(e){typeof process<`u`&&process.env.NODE_ENV!==`production`&&console.warn(`[magic-pill] ${e}`)}const n=Number.parseInt(e,10)>=19||``;function r(e){return e?{inert:n}:{}}function i(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n&&(n.current=t)}}export{t as devWarn,r as inertProps,i as mergeRefs};
2
+ //# sourceMappingURL=react.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.mjs","names":["version","devWarn","message","INERT_VALUE","inertProps","inert","mergeRefs","refs","node","ref"],"sources":["../../src/utils/react.ts"],"sourcesContent":["import { version, type Ref, type RefCallback } from \"react\";\n\n// Bundlers replace `process.env.NODE_ENV`; the typeof guard covers the rest.\ndeclare const process: { env: { NODE_ENV?: string } } | undefined;\n\n/** Warn in development builds only. */\nexport function devWarn(message: string): void {\n if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n console.warn(`[magic-pill] ${message}`);\n }\n}\n\n// React 19 knows `inert` as a boolean attribute. React 18 doesn't: it drops\n// `true` with a warning, so it needs an empty string, which React 19 treats as false.\nconst INERT_VALUE = Number.parseInt(version, 10) >= 19 ? true : \"\";\n\n/** Spread on an element to make it inert (unfocusable, hidden from assistive technology). */\nexport function inertProps(inert: boolean): { inert?: boolean } {\n return inert ? ({ inert: INERT_VALUE } as { inert: boolean }) : {};\n}\n\n/** Combine refs (React 18 compatible: no ref cleanup functions). */\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n };\n}\n"],"mappings":"A,gCAMA,SAAgBC,EAAQC,EAAuB,CACzC,OAAO,QAAY,KAAe,QAAQ,IAAI,WAAa,cAC7D,QAAQ,KAAK,gBAAgBA,GAAS,CAE1C,CAIA,MAAMC,EAAc,OAAO,SAASH,EAAS,EAAE,GAAK,IAAY,GAGhE,SAAgBI,EAAWC,EAAqC,CAC9D,OAAOA,EAAS,CAAE,MAAOF,CAAY,EAA2B,CAAC,CACnE,CAGA,SAAgBG,EAAa,GAAGC,EAA8C,CAC5E,MAAQC,IAAS,CACf,IAAK,IAAMC,KAAOF,EACZ,OAAOE,GAAQ,WACjBA,EAAID,CAAI,EACCC,IACTA,EAAI,QAAUD,EAGpB,CACF,C"}
@@ -0,0 +1,2 @@
1
+ const e=/* @__PURE__ */ new Set([`http`,`https`,`mailto`,`tel`]);exports.isSafeHref=function(t){let n=t.replace(/^[\x00-\x20]+/,``).replace(/[\t\n\r]/g,``),r=/^([a-z][a-z\d+.-]*):/i.exec(n);return r===null||e.has(r[1].toLowerCase())};
2
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","names":["ALLOWED_SCHEMES","href","normalised","scheme"],"sources":["../../src/utils/url.ts"],"sourcesContent":["// Link safety (L16): React 18 renders `javascript:` URLs as-is, so every href\n// the library renders goes through this check first.\n\nconst ALLOWED_SCHEMES = new Set([\"http\", \"https\", \"mailto\", \"tel\"]);\n\n/**\n * Whether an href is safe to render: relative URLs (including `#…`, `?…`\n * and `//host`), or absolute URLs with an `http(s):`, `mailto:` or `tel:` scheme.\n *\n * It normalises the URL the way browsers do before reading the scheme\n * (leading spaces and control characters dropped, tabs and newlines removed),\n * so `\" java\\tscript:…\"` is caught too.\n */\nexport function isSafeHref(href: string): boolean {\n const normalised = href\n .replace(/^[\\x00-\\x20]+/, \"\")\n .replace(/[\\t\\n\\r]/g, \"\");\n const scheme = /^([a-z][a-z\\d+.-]*):/i.exec(normalised);\n return scheme === null || ALLOWED_SCHEMES.has(scheme[1].toLowerCase());\n}\n"],"mappings":"AAGA,MAAMA,kBAAkB,IAAI,IAAI,CAAC,OAAQ,QAAS,SAAU,KAAK,CAAC,E,mBAUlE,SAA2BC,EAAuB,CAChD,IAAMC,EAAaD,EAChB,QAAQ,gBAAiB,EAAE,CAAC,CAC5B,QAAQ,YAAa,EAAE,EACpBE,EAAS,wBAAwB,KAAKD,CAAU,EACtD,OAAOC,IAAW,MAAQH,EAAgB,IAAIG,EAAO,EAAE,CAAC,YAAY,CAAC,CACvE"}
@@ -0,0 +1,2 @@
1
+ const e=/* @__PURE__ */ new Set([`http`,`https`,`mailto`,`tel`]);function t(t){let n=t.replace(/^[\x00-\x20]+/,``).replace(/[\t\n\r]/g,``),r=/^([a-z][a-z\d+.-]*):/i.exec(n);return r===null||e.has(r[1].toLowerCase())}export{t as isSafeHref};
2
+ //# sourceMappingURL=url.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.mjs","names":["ALLOWED_SCHEMES","isSafeHref","href","normalised","scheme"],"sources":["../../src/utils/url.ts"],"sourcesContent":["// Link safety (L16): React 18 renders `javascript:` URLs as-is, so every href\n// the library renders goes through this check first.\n\nconst ALLOWED_SCHEMES = new Set([\"http\", \"https\", \"mailto\", \"tel\"]);\n\n/**\n * Whether an href is safe to render: relative URLs (including `#…`, `?…`\n * and `//host`), or absolute URLs with an `http(s):`, `mailto:` or `tel:` scheme.\n *\n * It normalises the URL the way browsers do before reading the scheme\n * (leading spaces and control characters dropped, tabs and newlines removed),\n * so `\" java\\tscript:…\"` is caught too.\n */\nexport function isSafeHref(href: string): boolean {\n const normalised = href\n .replace(/^[\\x00-\\x20]+/, \"\")\n .replace(/[\\t\\n\\r]/g, \"\");\n const scheme = /^([a-z][a-z\\d+.-]*):/i.exec(normalised);\n return scheme === null || ALLOWED_SCHEMES.has(scheme[1].toLowerCase());\n}\n"],"mappings":"AAGA,MAAMA,kBAAkB,IAAI,IAAI,CAAC,OAAQ,QAAS,SAAU,KAAK,CAAC,EAUlE,SAAgBC,EAAWC,EAAuB,CAChD,IAAMC,EAAaD,EAChB,QAAQ,gBAAiB,EAAE,CAAC,CAC5B,QAAQ,YAAa,EAAE,EACpBE,EAAS,wBAAwB,KAAKD,CAAU,EACtD,OAAOC,IAAW,MAAQJ,EAAgB,IAAII,EAAO,EAAE,CAAC,YAAY,CAAC,CACvE,C"}
package/package.json CHANGED
@@ -1,24 +1,43 @@
1
1
  {
2
2
  "name": "magic-pill",
3
- "version": "8.0.3",
3
+ "version": "9.0.0-next.0",
4
+ "type": "commonjs",
4
5
  "main": "dist/index.js",
5
- "module": "dist/index.esm.js",
6
+ "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "./styles.css": "./dist/styles.css",
20
+ "./magicpill.css": "./dist/styles.css",
21
+ "./dist/magicpill.css": "./dist/styles.css",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "sideEffects": [
25
+ "*.css"
26
+ ],
7
27
  "description": "A new way to guide your audience and bring them contextual information through your app",
8
28
  "repository": {
9
29
  "type": "git",
10
30
  "url": "git+https://github.com/CedricTheveneau/Magic-Pill.git"
11
31
  },
12
32
  "scripts": {
13
- "build": "rollup -c && cp src/magicpill.css dist/magicpill.css",
33
+ "build": "tsdown",
14
34
  "prepare": "npm run build",
15
- "typecheck": "tsc --noEmit"
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest run"
16
37
  },
17
38
  "peerDependencies": {
18
- "next": ">=14.0.0",
19
39
  "react": ">=18.0.0",
20
- "react-dom": ">=18.0.0",
21
- "typescript": ">=5.0.0"
40
+ "react-dom": ">=18.0.0"
22
41
  },
23
42
  "keywords": [
24
43
  "notifications",
@@ -40,28 +59,22 @@
40
59
  "bugs": {
41
60
  "url": "https://github.com/CedricTheveneau/Magic-Pill/issues"
42
61
  },
43
- "cdn": {
44
- "url": "https://cdn.jsdelivr.net/npm/magic-pill@latest/dist/index.js",
45
- "style": "https://cdn.jsdelivr.net/npm/magic-pill@latest/dist/magicpill.css"
46
- },
47
62
  "devDependencies": {
48
- "@babel/core": "^7.26.0",
49
- "@babel/preset-env": "^7.26.0",
50
- "@babel/preset-react": "^7.25.9",
51
- "@babel/preset-typescript": "^7.26.0",
52
- "@rollup/plugin-babel": "^6.0.4",
53
- "@rollup/plugin-typescript": "^11.1.6",
54
- "@types/react": "^18.2.64",
55
- "@types/react-dom": "^18.2.21",
56
- "rollup": "^2.79.2",
57
- "rollup-plugin-postcss": "^4.0.2",
58
- "rollup-plugin-terser": "^7.0.2",
59
- "tslib": "^2.6.2",
60
- "typescript": "^5.4.2"
63
+ "@testing-library/dom": "^10.4.2",
64
+ "@testing-library/react": "^16.3.3",
65
+ "@types/react": "^19.3.0",
66
+ "@types/react-dom": "^19.3.0",
67
+ "jsdom": "^31.0.0",
68
+ "react": "^19.3.1",
69
+ "react-dom": "^19.3.1",
70
+ "tsdown": "0.23.7",
71
+ "typescript": "^6.0.3",
72
+ "vitest": "^5.1.0"
61
73
  },
62
74
  "files": [
63
75
  "dist",
64
76
  "CHANGELOG.md",
77
+ "MIGRATING.md",
65
78
  "LICENSE.md",
66
79
  "NOTICE.md"
67
80
  ]
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- import "./magicpill.css";
3
- import { MagicPillType } from "./types";
4
- interface MagicPillProps {
5
- pillData: MagicPillType;
6
- }
7
- declare const MagicPill: ({ pillData }: MagicPillProps) => React.JSX.Element;
8
- export default MagicPill;