@zazz-ui/core 0.1.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 (260) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -0
  4. package/dist/sri.json +75 -0
  5. package/dist/zazz.css +1 -0
  6. package/dist/zazz.js +1 -0
  7. package/examples/about.html +590 -0
  8. package/examples/components.html +1040 -0
  9. package/examples/forms.html +511 -0
  10. package/examples/index.html +268 -0
  11. package/examples/layout.html +320 -0
  12. package/examples/products.html +846 -0
  13. package/examples/responsive.html +339 -0
  14. package/package.json +85 -0
  15. package/src/base/_layers.css +12 -0
  16. package/src/base/_layout.css +568 -0
  17. package/src/base/_reset.css +515 -0
  18. package/src/base/_typography.css +495 -0
  19. package/src/base/_utilities.css +6628 -0
  20. package/src/base/_variables.css +682 -0
  21. package/src/base/_view-transitions.css +103 -0
  22. package/src/base/command-score.d.ts +12 -0
  23. package/src/base/command-score.d.ts.map +1 -0
  24. package/src/base/command-score.js +151 -0
  25. package/src/base/command-score.ts +192 -0
  26. package/src/base/dialog-lifecycle.d.ts +11 -0
  27. package/src/base/dialog-lifecycle.d.ts.map +1 -0
  28. package/src/base/dialog-lifecycle.js +65 -0
  29. package/src/base/dialog-lifecycle.ts +80 -0
  30. package/src/base/embla.d.ts +90 -0
  31. package/src/base/embla.d.ts.map +1 -0
  32. package/src/base/embla.js +643 -0
  33. package/src/base/embla.ts +791 -0
  34. package/src/base/hotkeys.d.ts +82 -0
  35. package/src/base/hotkeys.d.ts.map +1 -0
  36. package/src/base/hotkeys.js +141 -0
  37. package/src/base/hotkeys.ts +195 -0
  38. package/src/base/navigation.d.ts +2 -0
  39. package/src/base/navigation.d.ts.map +1 -0
  40. package/src/base/navigation.js +136 -0
  41. package/src/base/navigation.ts +151 -0
  42. package/src/base/reveal.d.ts +80 -0
  43. package/src/base/reveal.d.ts.map +1 -0
  44. package/src/base/reveal.js +305 -0
  45. package/src/base/reveal.ts +379 -0
  46. package/src/base/signals.d.ts +89 -0
  47. package/src/base/signals.d.ts.map +1 -0
  48. package/src/base/signals.js +134 -0
  49. package/src/base/signals.ts +164 -0
  50. package/src/base/typeahead.d.ts +105 -0
  51. package/src/base/typeahead.d.ts.map +1 -0
  52. package/src/base/typeahead.js +411 -0
  53. package/src/base/typeahead.ts +500 -0
  54. package/src/base/utils.d.ts +56 -0
  55. package/src/base/utils.d.ts.map +1 -0
  56. package/src/base/utils.js +88 -0
  57. package/src/base/utils.ts +98 -0
  58. package/src/base/zazz-element.d.ts +44 -0
  59. package/src/base/zazz-element.d.ts.map +1 -0
  60. package/src/base/zazz-element.js +59 -0
  61. package/src/base/zazz-element.ts +73 -0
  62. package/src/globals.d.ts +148 -0
  63. package/src/head.d.ts +95 -0
  64. package/src/head.d.ts.map +1 -0
  65. package/src/head.js +311 -0
  66. package/src/head.ts +433 -0
  67. package/src/index.css +71 -0
  68. package/src/index.d.ts +36 -0
  69. package/src/index.d.ts.map +1 -0
  70. package/src/index.js +35 -0
  71. package/src/index.ts +36 -0
  72. package/src/manifest.d.ts +90 -0
  73. package/src/manifest.d.ts.map +1 -0
  74. package/src/manifest.js +614 -0
  75. package/src/manifest.ts +667 -0
  76. package/src/primitives/accordion/accordion.css +104 -0
  77. package/src/primitives/accordion/accordion.html +69 -0
  78. package/src/primitives/alert-dialog/alert-dialog.css +38 -0
  79. package/src/primitives/alert-dialog/alert-dialog.html +53 -0
  80. package/src/primitives/autocomplete/autocomplete-groups.html +77 -0
  81. package/src/primitives/autocomplete/autocomplete.css +114 -0
  82. package/src/primitives/autocomplete/autocomplete.d.ts +30 -0
  83. package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -0
  84. package/src/primitives/autocomplete/autocomplete.html +66 -0
  85. package/src/primitives/autocomplete/autocomplete.js +41 -0
  86. package/src/primitives/autocomplete/autocomplete.ts +46 -0
  87. package/src/primitives/avatar/avatar.html +44 -0
  88. package/src/primitives/badge/badge-icon.html +36 -0
  89. package/src/primitives/badge/badge.css +251 -0
  90. package/src/primitives/badge/badge.html +7 -0
  91. package/src/primitives/breadcrumbs/breadcrumbs.html +9 -0
  92. package/src/primitives/button/button-icon-only.html +84 -0
  93. package/src/primitives/button/button-icon.html +82 -0
  94. package/src/primitives/button/button.css +319 -0
  95. package/src/primitives/button/button.html +8 -0
  96. package/src/primitives/button-group/button-group-vertical.html +6 -0
  97. package/src/primitives/button-group/button-group.css +94 -0
  98. package/src/primitives/button-group/button-group.html +64 -0
  99. package/src/primitives/card/card-subgrid.html +118 -0
  100. package/src/primitives/card/card.html +53 -0
  101. package/src/primitives/carousel/carousel.css +61 -0
  102. package/src/primitives/carousel/carousel.d.ts +16 -0
  103. package/src/primitives/carousel/carousel.d.ts.map +1 -0
  104. package/src/primitives/carousel/carousel.html +315 -0
  105. package/src/primitives/carousel/carousel.js +73 -0
  106. package/src/primitives/carousel/carousel.ts +84 -0
  107. package/src/primitives/checkbox/checkbox-tasklist.html +71 -0
  108. package/src/primitives/checkbox/checkbox.css +82 -0
  109. package/src/primitives/checkbox/checkbox.d.ts +21 -0
  110. package/src/primitives/checkbox/checkbox.d.ts.map +1 -0
  111. package/src/primitives/checkbox/checkbox.html +17 -0
  112. package/src/primitives/checkbox/checkbox.js +190 -0
  113. package/src/primitives/checkbox/checkbox.ts +219 -0
  114. package/src/primitives/combobox/combobox-multiselect.html +91 -0
  115. package/src/primitives/combobox/combobox.css +307 -0
  116. package/src/primitives/combobox/combobox.d.ts +100 -0
  117. package/src/primitives/combobox/combobox.d.ts.map +1 -0
  118. package/src/primitives/combobox/combobox.html +73 -0
  119. package/src/primitives/combobox/combobox.js +503 -0
  120. package/src/primitives/combobox/combobox.ts +559 -0
  121. package/src/primitives/command/command-actions.d.ts +31 -0
  122. package/src/primitives/command/command-actions.d.ts.map +1 -0
  123. package/src/primitives/command/command-actions.html +89 -0
  124. package/src/primitives/command/command-actions.js +70 -0
  125. package/src/primitives/command/command-actions.ts +77 -0
  126. package/src/primitives/command/command-dialog.html +77 -0
  127. package/src/primitives/command/command.css +151 -0
  128. package/src/primitives/command/command.d.ts +52 -0
  129. package/src/primitives/command/command.d.ts.map +1 -0
  130. package/src/primitives/command/command.html +119 -0
  131. package/src/primitives/command/command.js +146 -0
  132. package/src/primitives/command/command.ts +157 -0
  133. package/src/primitives/dialog/dialog-with-form.html +200 -0
  134. package/src/primitives/dialog/dialog.css +229 -0
  135. package/src/primitives/dialog/dialog.html +90 -0
  136. package/src/primitives/fields/fields.css +278 -0
  137. package/src/primitives/input/input-icon-leading.html +19 -0
  138. package/src/primitives/input/input-icon-trailing.html +18 -0
  139. package/src/primitives/input/input.css +114 -0
  140. package/src/primitives/input/input.html +61 -0
  141. package/src/primitives/input-group/input-group-password-group.html +108 -0
  142. package/src/primitives/input-group/input-group.css +215 -0
  143. package/src/primitives/input-group/input-group.html +132 -0
  144. package/src/primitives/kbd/kbd-group.html +18 -0
  145. package/src/primitives/kbd/kbd.css +87 -0
  146. package/src/primitives/kbd/kbd.html +7 -0
  147. package/src/primitives/lightbox/lightbox.css +459 -0
  148. package/src/primitives/lightbox/lightbox.d.ts +7 -0
  149. package/src/primitives/lightbox/lightbox.d.ts.map +1 -0
  150. package/src/primitives/lightbox/lightbox.html +665 -0
  151. package/src/primitives/lightbox/lightbox.js +96 -0
  152. package/src/primitives/lightbox/lightbox.ts +113 -0
  153. package/src/primitives/menu/menu-interest.html +52 -0
  154. package/src/primitives/menu/menu.css +55 -0
  155. package/src/primitives/menu/menu.d.ts +38 -0
  156. package/src/primitives/menu/menu.d.ts.map +1 -0
  157. package/src/primitives/menu/menu.html +70 -0
  158. package/src/primitives/menu/menu.js +117 -0
  159. package/src/primitives/menu/menu.ts +131 -0
  160. package/src/primitives/menubar/menubar-help-search.html +103 -0
  161. package/src/primitives/menubar/menubar.html +166 -0
  162. package/src/primitives/meter/meter.css +178 -0
  163. package/src/primitives/meter/meter.html +38 -0
  164. package/src/primitives/mobile-menu/mobile-menu.css +145 -0
  165. package/src/primitives/mobile-menu/mobile-menu.html +614 -0
  166. package/src/primitives/navigation-menu/navigation-menu-featured.html +76 -0
  167. package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +158 -0
  168. package/src/primitives/navigation-menu/navigation-menu-interest.html +103 -0
  169. package/src/primitives/navigation-menu/navigation-menu-megamenu.html +141 -0
  170. package/src/primitives/navigation-menu/navigation-menu-simple.html +96 -0
  171. package/src/primitives/navigation-menu/navigation-menu.css +295 -0
  172. package/src/primitives/navigation-menu/navigation-menu.html +576 -0
  173. package/src/primitives/otp/otp.css +126 -0
  174. package/src/primitives/otp/otp.d.ts +89 -0
  175. package/src/primitives/otp/otp.d.ts.map +1 -0
  176. package/src/primitives/otp/otp.html +22 -0
  177. package/src/primitives/otp/otp.js +226 -0
  178. package/src/primitives/otp/otp.ts +279 -0
  179. package/src/primitives/password-group/password-group.css +238 -0
  180. package/src/primitives/password-group/password-group.d.ts +25 -0
  181. package/src/primitives/password-group/password-group.d.ts.map +1 -0
  182. package/src/primitives/password-group/password-group.html +109 -0
  183. package/src/primitives/password-group/password-group.js +76 -0
  184. package/src/primitives/password-group/password-group.ts +95 -0
  185. package/src/primitives/popover/popover.css +233 -0
  186. package/src/primitives/progress/progress-indeterminate.html +1 -0
  187. package/src/primitives/progress/progress.css +105 -0
  188. package/src/primitives/progress/progress.html +7 -0
  189. package/src/primitives/prose/prose.html +65 -0
  190. package/src/primitives/radio/radio.css +84 -0
  191. package/src/primitives/radio/radio.html +17 -0
  192. package/src/primitives/reveal/reveal.css +167 -0
  193. package/src/primitives/select/multiselect.d.ts +43 -0
  194. package/src/primitives/select/multiselect.d.ts.map +1 -0
  195. package/src/primitives/select/multiselect.js +147 -0
  196. package/src/primitives/select/multiselect.ts +188 -0
  197. package/src/primitives/select/select-align.html +49 -0
  198. package/src/primitives/select/select-multiple.html +12 -0
  199. package/src/primitives/select/select-sides.html +65 -0
  200. package/src/primitives/select/select.css +481 -0
  201. package/src/primitives/select/select.html +16 -0
  202. package/src/primitives/separator/separator.css +49 -0
  203. package/src/primitives/separator/separator.html +16 -0
  204. package/src/primitives/slider/slider.css +122 -0
  205. package/src/primitives/slider/slider.html +1 -0
  206. package/src/primitives/switch/switch.css +126 -0
  207. package/src/primitives/switch/switch.html +13 -0
  208. package/src/primitives/table/table-alternating.html +36 -0
  209. package/src/primitives/table/table-grid.html +30 -0
  210. package/src/primitives/table/table-size-sm.html +26 -0
  211. package/src/primitives/table/table.css +158 -0
  212. package/src/primitives/table/table.html +45 -0
  213. package/src/primitives/tabs/tabs.css +328 -0
  214. package/src/primitives/tabs/tabs.d.ts +35 -0
  215. package/src/primitives/tabs/tabs.d.ts.map +1 -0
  216. package/src/primitives/tabs/tabs.html +75 -0
  217. package/src/primitives/tabs/tabs.js +84 -0
  218. package/src/primitives/tabs/tabs.ts +93 -0
  219. package/src/primitives/textarea/textarea.css +78 -0
  220. package/src/primitives/textarea/textarea.html +10 -0
  221. package/src/primitives/toaster/toaster.css +309 -0
  222. package/src/primitives/toaster/toaster.d.ts +138 -0
  223. package/src/primitives/toaster/toaster.d.ts.map +1 -0
  224. package/src/primitives/toaster/toaster.html +77 -0
  225. package/src/primitives/toaster/toaster.js +736 -0
  226. package/src/primitives/toaster/toaster.ts +823 -0
  227. package/src/primitives/toggle/toggle.css +295 -0
  228. package/src/primitives/toggle/toggle.html +68 -0
  229. package/src/primitives/toggle-group/toggle-group-multiple.html +14 -0
  230. package/src/primitives/toggle-group/toggle-group-vertical.html +14 -0
  231. package/src/primitives/toggle-group/toggle-group.css +73 -0
  232. package/src/primitives/toggle-group/toggle-group.html +53 -0
  233. package/src/primitives/toolbar/toolbar.html +45 -0
  234. package/src/primitives/tooltip/tooltip-disabled.html +19 -0
  235. package/src/primitives/tooltip/tooltip-sides.html +57 -0
  236. package/src/primitives/tooltip/tooltip-with-kbd.html +31 -0
  237. package/src/primitives/tooltip/tooltip.css +235 -0
  238. package/src/primitives/tooltip/tooltip.html +12 -0
  239. package/src/primitives/utilities/aspect-ratio.html +17 -0
  240. package/src/primitives/utilities/basis.html +27 -0
  241. package/src/primitives/utilities/col-span.html +23 -0
  242. package/src/primitives/utilities/compose.html +19 -0
  243. package/src/primitives/utilities/flex-align.html +26 -0
  244. package/src/primitives/utilities/flex-direction.html +36 -0
  245. package/src/primitives/utilities/flex-grow.html +17 -0
  246. package/src/primitives/utilities/gap.html +62 -0
  247. package/src/primitives/utilities/grid-cols.html +20 -0
  248. package/src/primitives/utilities/grid-pile.html +5 -0
  249. package/src/primitives/utilities/grid-responsive.html +31 -0
  250. package/src/primitives/utilities/margin-auto.html +13 -0
  251. package/src/primitives/utilities/object-fit.html +41 -0
  252. package/src/primitives/utilities/order.html +17 -0
  253. package/src/primitives/utilities/overflow.html +26 -0
  254. package/src/primitives/utilities/padding-compose.html +23 -0
  255. package/src/primitives/utilities/padding.html +30 -0
  256. package/src/primitives/utilities/position.html +13 -0
  257. package/src/primitives/utilities/responsive-flex.html +22 -0
  258. package/src/primitives/utilities/responsive-grid.html +31 -0
  259. package/src/primitives/utilities/size.html +22 -0
  260. package/src/primitives/utilities/width.html +22 -0
@@ -0,0 +1,823 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview `<ui-toaster>`: HTML web component for stacked toast notifications.
5
+ * @description Light-DOM custom element that hosts a top-layer toast stack, plus
6
+ * the `window.Toaster` imperative API. The stacking model (newest toast in front,
7
+ * older toasts peeking behind, expand on hover, timer pause on hover/hidden tab)
8
+ * is adapted from Sonner by Emil Kowalski (https://sonner.emilkowal.ski, MIT).
9
+ *
10
+ * The region is a `popover="manual"` element: it enters the top layer via
11
+ * `showPopover()` when the first toast arrives and leaves it after the last
12
+ * toast's exit transition. Toasts are plain `<li>` children, so the collapsed
13
+ * stack offsets in `_toaster.css` work with normal CSS transforms.
14
+ *
15
+ * Fire toasts two ways:
16
+ * - Declaratively, from any button, via a custom Invoker Command:
17
+ * `command="--toast"` (or `--toast-success|info|warning|destructive`) with
18
+ * `commandfor="<region id>"`. Toast content comes from the button's
19
+ * `data-title`, `data-description`, `data-variant`, `data-duration`, and
20
+ * `data-close-button` attributes.
21
+ * - Imperatively: `window.Toaster.toast({ title, description, variant, … })`
22
+ * and the `.success()/.info()/.warning()/.error()` shorthands.
23
+ *
24
+ * Region attributes:
25
+ * - `data-position`: `top-start | top-center | top-end | bottom-start |
26
+ * bottom-center | bottom-end` (logical; default `bottom-end`).
27
+ *
28
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
29
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API
30
+ *
31
+ * @example
32
+ * <ui-toaster class="ui-toaster" id="toaster" popover="manual"></ui-toaster>
33
+ * <button commandfor="toaster" command="--toast" data-title="Saved">Save</button>
34
+ */
35
+
36
+ import { computed, effect, state } from "../../base/signals.ts";
37
+ import { ZazzElement, defineZazzElement } from "../../base/zazz-element.ts";
38
+
39
+ // `using` compiles (target ES2022) to try/finally helpers that read this
40
+ // well-known symbol at runtime; engines without native Explicit Resource
41
+ // Management (Safari) don't define it, so give them a local stand-in.
42
+ (Symbol as { dispose: symbol }).dispose ??= Symbol("Symbol.dispose");
43
+
44
+ // --- Constants ---
45
+
46
+ /** Default toast lifetime in milliseconds. */
47
+ const TOAST_LIFETIME = 4000;
48
+
49
+ /** Maximum number of toasts shown in the collapsed stack. */
50
+ const VISIBLE_TOASTS = 3;
51
+
52
+ /** Safety net for node removal when no exit `transitionend` fires. */
53
+ const EXIT_FALLBACK_MS = 600;
54
+
55
+ const VARIANTS: ReadonlyArray<string> = ["success", "info", "warning", "destructive"];
56
+
57
+ // --- Icons (adapted from Sonner's assets.tsx (MIT, Emil Kowalski)) ---
58
+
59
+ const ICONS: Record<string, string> = {
60
+ success:
61
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd"/></svg>',
62
+ info: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd"/></svg>',
63
+ warning:
64
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z" clip-rule="evenodd"/></svg>',
65
+ destructive:
66
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"/></svg>',
67
+ close:
68
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
69
+ };
70
+
71
+ // --- Typedefs ---
72
+
73
+ interface ToastAction {
74
+ /** Button label. */
75
+ label: string;
76
+ /** Click handler. Call `event.preventDefault()` to keep the toast open. */
77
+ onClick?: (event: MouseEvent) => void;
78
+ }
79
+
80
+ interface ToastOptions {
81
+ /** Toast heading. */
82
+ title?: string;
83
+ /** Supporting copy under the title. */
84
+ description?: string;
85
+ /** Status accent + icon. */
86
+ variant?: "success" | "info" | "warning" | "destructive";
87
+ /** Lifetime in ms; `Infinity` persists until dismissed. Default `4000`. */
88
+ duration?: number;
89
+ /** Optional action button. */
90
+ action?: ToastAction;
91
+ /** Render the explicit close button. Default `true`. */
92
+ closeButton?: boolean;
93
+ /** Target region id or element (default: first `<ui-toaster>`). */
94
+ region?: string | Element;
95
+ }
96
+
97
+ interface ToastTimer {
98
+ /** Milliseconds left when next resumed. */
99
+ remaining: number;
100
+ /** `Date.now()` at the last (re)schedule. */
101
+ startedAt: number;
102
+ /** Active timeout id, or `0` while paused. */
103
+ timeoutId: number;
104
+ }
105
+
106
+ /** One measured toast in the stack (oldest first, matching DOM order). */
107
+ interface ToastStackEntry {
108
+ /** The toast element. */
109
+ node: HTMLElement;
110
+ /** Measured natural height in px. */
111
+ height: number;
112
+ }
113
+
114
+ /** Computed placement for one toast (same index as the heights input). */
115
+ interface ToastStackLayout {
116
+ /** 0 = front (newest); grows toward the back of the stack. */
117
+ stackIndex: number;
118
+ /** Sum of the heights of the toasts stacked in front, in px. */
119
+ offsetPx: number;
120
+ /** Paint order: front toast highest. */
121
+ zIndex: number;
122
+ /** Whether this is the front (newest) toast. */
123
+ front: boolean;
124
+ /** Whether the toast is within the visible collapsed stack. */
125
+ visible: boolean;
126
+ }
127
+
128
+ // --- Measurement ---
129
+
130
+ /**
131
+ * @description Unclamps every toast's block-size for a batch measurement (the
132
+ * inline style beats the collapsed block-size rule) and returns a disposer
133
+ * that restores the clamp. Bind it with `using` so the restore is guaranteed
134
+ * at scope exit, even if a measure in between throws.
135
+ *
136
+ * @param toasts - The live toasts to unclamp.
137
+ * @returns A `Disposable` that removes the inline block-size again.
138
+ * @private
139
+ */
140
+ function unclampForMeasure(toasts: readonly HTMLElement[]): Disposable {
141
+ for (const toast of toasts) toast.style.blockSize = "auto";
142
+ return {
143
+ [Symbol.dispose]() {
144
+ for (const toast of toasts) toast.style.removeProperty("block-size");
145
+ },
146
+ };
147
+ }
148
+
149
+ // --- Stack math (pure) ---
150
+
151
+ /**
152
+ * @description Computes the collapsed-stack placement for every toast from the
153
+ * measured heights alone (oldest first, matching DOM order). Pure: the
154
+ * measure step feeds it and an effect writes the results to the DOM, so this
155
+ * is the unit-testable core of the stacking model.
156
+ *
157
+ * @param heights - Natural toast heights in px, oldest first.
158
+ * @returns Per-toast layout (same order) and the front toast's height.
159
+ */
160
+ function computeStackLayout(heights: number[]): {
161
+ toasts: ToastStackLayout[];
162
+ frontToastHeightPx: number | null;
163
+ } {
164
+ const count = heights.length;
165
+ const toasts: ToastStackLayout[] = Array.from({ length: count });
166
+
167
+ let heightsBefore = 0;
168
+ for (let i = count - 1; i >= 0; i--) {
169
+ const stackIndex = count - 1 - i; // 0 = front (newest, last in DOM)
170
+ toasts[i] = {
171
+ stackIndex,
172
+ offsetPx: heightsBefore,
173
+ zIndex: count - stackIndex,
174
+ front: stackIndex === 0,
175
+ visible: stackIndex < VISIBLE_TOASTS,
176
+ };
177
+ heightsBefore += heights[i];
178
+ }
179
+
180
+ return { toasts, frontToastHeightPx: count > 0 ? heights[count - 1] : null };
181
+ }
182
+
183
+ // --- <ui-toaster> element ---
184
+
185
+ /**
186
+ * @class
187
+ * @description Hosts the toast stack: builds toast markup, maintains the
188
+ * collapsed-stack CSS custom properties, runs auto-dismiss timers, and shows or
189
+ * hides the `popover="manual"` region as toasts come and go.
190
+ */
191
+ class UiToaster extends ZazzElement {
192
+ #timers: Map<string, ToastTimer> = new Map();
193
+
194
+ #counter = 0;
195
+
196
+ #resizeFrame = 0;
197
+
198
+ #handledCommand: { source: Element | null; command: string } | null = null;
199
+
200
+ #collapseTimer = 0;
201
+
202
+ // Signal state: DOM events and observers write in; computed holds the pure
203
+ // derivations; effects (bound in connectedCallback) write back to the DOM.
204
+ /** Whether the stack is expanded (hover/focus). */
205
+ #expanded = state(false);
206
+
207
+ /** Whether the tab is hidden (mirrors `document.hidden`). */
208
+ #hidden = state(typeof document !== "undefined" ? document.hidden : false);
209
+
210
+ /** Timers run only while neither expanded nor hidden. */
211
+ #paused = computed(() => this.#expanded.get() || this.#hidden.get());
212
+
213
+ /** Measured stack (oldest first): written by `#reindex`'s measure pass. */
214
+ #stack = state<ToastStackEntry[]>([]);
215
+
216
+ /** Pure placement derived from the measured heights. */
217
+ #layout = computed(() => computeStackLayout(this.#stack.get().map((entry) => entry.height)));
218
+
219
+ protected setup(signal: AbortSignal): void {
220
+ // Region baseline: manual popover (no light dismiss), reachable landmark.
221
+ if (!this.hasAttribute("popover")) this.setAttribute("popover", "manual");
222
+ if (!this.hasAttribute("role")) this.setAttribute("role", "region");
223
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Notifications");
224
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "-1");
225
+
226
+ // The live region must exist before toasts are inserted so additions announce.
227
+ if (!this.querySelector('[data-slot~="toaster-list"]')) {
228
+ const list = document.createElement("ol");
229
+ list.setAttribute("data-slot", "toaster-list");
230
+ list.setAttribute("aria-live", "polite");
231
+ list.setAttribute("aria-relevant", "additions text");
232
+ list.setAttribute("aria-atomic", "false");
233
+ this.append(list);
234
+ }
235
+
236
+ this.addEventListener("command", (event) => this.#onCommand(event), { signal });
237
+
238
+ // Hover/focus expands the stack; expanded (or hidden tab) pauses timers.
239
+ // Leave events only *request* a collapse: dismissal animations and node
240
+ // removal fire spurious mouseleave/focusout while the pointer never moved,
241
+ // so the collapse is verified against real hover/focus state first.
242
+ this.addEventListener("mouseenter", () => this.#setExpanded(true), { signal });
243
+ this.addEventListener("mouseleave", () => this.#requestCollapse(), { signal });
244
+ this.addEventListener("focusin", () => this.#setExpanded(true), { signal });
245
+ this.addEventListener("focusout", () => this.#requestCollapse(), { signal });
246
+
247
+ document.addEventListener("visibilitychange", () => this.#hidden.set(document.hidden), {
248
+ signal,
249
+ });
250
+
251
+ // Viewport resizes rewrap toast text: remeasure the stack.
252
+ window.addEventListener(
253
+ "resize",
254
+ () => {
255
+ cancelAnimationFrame(this.#resizeFrame);
256
+ this.#resizeFrame = requestAnimationFrame(() => this.#reindex());
257
+ },
258
+ { signal },
259
+ );
260
+
261
+ // Output effects (disposed by the same controller as the listeners):
262
+ // one owns the expanded attribute, one owns pausing/resuming the timers,
263
+ // one writes the computed stack placement to the DOM.
264
+ effect(
265
+ () => {
266
+ this.dataset.expanded = String(this.#expanded.get());
267
+ },
268
+ { signal },
269
+ );
270
+
271
+ effect(
272
+ () => {
273
+ if (this.#paused.get()) {
274
+ this.#pauseTimers();
275
+ } else {
276
+ this.#resumeTimers();
277
+ }
278
+ },
279
+ { signal },
280
+ );
281
+
282
+ effect(
283
+ () => {
284
+ const entries = this.#stack.get();
285
+ const { toasts, frontToastHeightPx } = this.#layout.get();
286
+
287
+ for (let i = 0; i < entries.length; i++) {
288
+ const { node, height } = entries[i];
289
+ const layout = toasts[i];
290
+ node.dataset.front = String(layout.front);
291
+ node.dataset.visible = String(layout.visible);
292
+ node.style.zIndex = String(layout.zIndex);
293
+ node.style.setProperty("--toasts-before", String(layout.stackIndex));
294
+ node.style.setProperty("--initial-height", `${height}px`);
295
+ node.style.setProperty(
296
+ "--offset",
297
+ `calc(${layout.offsetPx}px + var(--ui-toaster-gap) * ${layout.stackIndex})`,
298
+ );
299
+ }
300
+
301
+ if (frontToastHeightPx !== null) {
302
+ this.style.setProperty("--front-toast-height", `${frontToastHeightPx}px`);
303
+ }
304
+ },
305
+ { signal },
306
+ );
307
+ }
308
+
309
+ protected teardown(): void {
310
+ cancelAnimationFrame(this.#resizeFrame);
311
+ window.clearTimeout(this.#collapseTimer);
312
+ for (const timer of this.#timers.values()) clearTimeout(timer.timeoutId);
313
+ this.#timers.clear();
314
+ }
315
+
316
+ // --- Public API ---
317
+
318
+ /**
319
+ * @description Adds a toast to this region and shows the region if needed.
320
+ *
321
+ * @param options - Toast content and behavior.
322
+ * @returns The toast id (usable with `dismiss()`).
323
+ */
324
+ addToast(options: ToastOptions = {}): string {
325
+ const id = `toast-${++this.#counter}`;
326
+ const list = this.#list();
327
+
328
+ // Show the popover before inserting so the insertion is announced and the
329
+ // toast's @starting-style enter transition runs inside an open region.
330
+ this.#showRegion();
331
+
332
+ list.append(this.#buildToast(options, id));
333
+ this.#reindex();
334
+ this.#startTimer(id, options.duration ?? TOAST_LIFETIME);
335
+
336
+ return id;
337
+ }
338
+
339
+ /**
340
+ * @description Dismisses one toast by id, or every toast when omitted.
341
+ *
342
+ * @param id - Toast id returned by `addToast()`.
343
+ */
344
+ dismiss(id?: string): void {
345
+ if (id === undefined) {
346
+ this.dismissAll();
347
+ return;
348
+ }
349
+
350
+ const toast = this.#list().querySelector(`[data-toast-id="${CSS.escape(id)}"]`);
351
+ if (!(toast instanceof HTMLElement) || toast.dataset.removed === "true") return;
352
+
353
+ const timer = this.#timers.get(id);
354
+ if (timer) clearTimeout(timer.timeoutId);
355
+ this.#timers.delete(id);
356
+
357
+ toast.dataset.removed = "true";
358
+
359
+ // Keyboard users keep their place: hand focus to the next toast before this
360
+ // one goes. A mouse click's incidental focus is left to drop to <body>;
361
+ // holding it would pin the stack expanded after the pointer leaves, and
362
+ // #requestCollapse's :hover check already keeps the stack open meanwhile.
363
+ const active = document.activeElement;
364
+ if (
365
+ active instanceof HTMLElement &&
366
+ toast.contains(active) &&
367
+ active.matches(":focus-visible")
368
+ ) {
369
+ this.#toasts()
370
+ .filter((t) => t.dataset.removed !== "true")
371
+ .at(-1)
372
+ ?.focus({ preventScroll: true });
373
+ }
374
+
375
+ this.#reindex();
376
+ this.#finalizeRemoval(toast);
377
+ }
378
+
379
+ /**
380
+ * @description Dismisses every toast in this region.
381
+ */
382
+ dismissAll(): void {
383
+ for (const toast of this.#toasts()) {
384
+ const toastId = toast.dataset.toastId;
385
+ if (toastId) this.dismiss(toastId);
386
+ }
387
+ }
388
+
389
+ // --- Invoker Commands ---
390
+
391
+ /**
392
+ * @description Handles the custom `--toast` Invoker Command fired by buttons
393
+ * with `commandfor` pointing at this region. `--toast-success` (etc.) sets the
394
+ * variant; everything else comes from the invoker's `data-*` attributes.
395
+ *
396
+ * @param event - The command event.
397
+ */
398
+ #onCommand(event: CommandEvent): void {
399
+ const command = event.command;
400
+ if (typeof command !== "string" || !command.startsWith("--toast")) return;
401
+
402
+ // The invokers polyfill re-dispatches commands even in browsers with a
403
+ // native CommandEvent, so one click can deliver the same command twice in
404
+ // the same task. Handle the first and drop the same-task duplicate.
405
+ const handled = this.#handledCommand;
406
+ if (handled && handled.source === event.source && handled.command === command) return;
407
+ this.#handledCommand = { source: event.source, command };
408
+ window.setTimeout(() => {
409
+ this.#handledCommand = null;
410
+ }, 0);
411
+
412
+ const source = event.source;
413
+ const options: ToastOptions = {};
414
+
415
+ const suffix = command.slice("--toast-".length);
416
+ if (VARIANTS.includes(suffix)) {
417
+ options.variant = suffix as ToastOptions["variant"];
418
+ }
419
+
420
+ if (source instanceof HTMLElement) {
421
+ const { title, description, variant, duration, closeButton } = source.dataset;
422
+ if (title) options.title = title;
423
+ if (description) options.description = description;
424
+ if (!options.variant && variant && VARIANTS.includes(variant)) {
425
+ options.variant = variant as ToastOptions["variant"];
426
+ }
427
+ if (duration !== undefined) {
428
+ // A duration is only ever a number: parse it as one rather than running
429
+ // it through the polymorphic attribute parser and narrowing after.
430
+ // NaN-guarded rather than finite-guarded: `Infinity` is a documented
431
+ // value (persist until dismissed). Blank strings coerce to 0, so they
432
+ // are rejected before Number() sees them.
433
+ const parsed = duration.trim() === "" ? Number.NaN : Number(duration);
434
+ if (!Number.isNaN(parsed)) options.duration = parsed;
435
+ }
436
+ if (closeButton !== undefined) options.closeButton = closeButton !== "false";
437
+ }
438
+
439
+ this.addToast(options);
440
+ }
441
+
442
+ // --- Toast construction ---
443
+
444
+ /**
445
+ * @description Builds a toast `<li>`: status icon, title/description, and the
446
+ * optional action and close buttons. Text is set via `textContent`.
447
+ *
448
+ * @param options - Toast content and behavior.
449
+ * @param id - The generated toast id.
450
+ * @returns The toast element (not yet inserted).
451
+ */
452
+ #buildToast(options: ToastOptions, id: string): HTMLLIElement {
453
+ const toast = document.createElement("li");
454
+ toast.setAttribute("data-slot", "toaster-toast");
455
+ toast.dataset.toastId = id;
456
+ toast.tabIndex = 0;
457
+ if (options.variant) toast.dataset.variant = options.variant;
458
+
459
+ if (options.variant) {
460
+ const icon = document.createElement("span");
461
+ icon.setAttribute("data-slot", "toaster-icon");
462
+ icon.setAttribute("aria-hidden", "true");
463
+ icon.innerHTML = ICONS[options.variant];
464
+ toast.append(icon);
465
+ }
466
+
467
+ const content = document.createElement("div");
468
+ content.setAttribute("data-slot", "toaster-content");
469
+ if (options.title) {
470
+ const title = document.createElement("div");
471
+ title.setAttribute("data-slot", "toaster-title");
472
+ title.textContent = options.title;
473
+ content.append(title);
474
+ }
475
+ if (options.description) {
476
+ const description = document.createElement("div");
477
+ description.setAttribute("data-slot", "toaster-description");
478
+ description.textContent = options.description;
479
+ content.append(description);
480
+ }
481
+ toast.append(content);
482
+
483
+ const action = options.action;
484
+ if (action) {
485
+ const button = document.createElement("button");
486
+ button.type = "button";
487
+ button.className = "ui-button";
488
+ button.setAttribute("data-slot", "toaster-action");
489
+ button.dataset.size = "sm";
490
+ button.textContent = action.label;
491
+ button.addEventListener("click", (event) => {
492
+ action.onClick?.(event);
493
+ if (!event.defaultPrevented) this.dismiss(id);
494
+ });
495
+ toast.append(button);
496
+ }
497
+
498
+ if (options.closeButton !== false) {
499
+ const close = document.createElement("button");
500
+ close.type = "button";
501
+ close.className = "ui-button";
502
+ close.setAttribute("data-slot", "toaster-close");
503
+ close.dataset.variant = "ghost";
504
+ close.dataset.size = "icon-sm";
505
+ close.setAttribute("aria-label", "Close notification");
506
+ close.innerHTML = ICONS.close;
507
+ close.addEventListener("click", () => this.dismiss(id));
508
+ toast.append(close);
509
+ }
510
+
511
+ return toast;
512
+ }
513
+
514
+ // --- Stack math ---
515
+
516
+ /**
517
+ * @description Remeasures the stack: the measure half of the stacking
518
+ * model. Batch-reads every live toast's natural height and writes the
519
+ * result into `#stack`; `#layout` derives the placement purely
520
+ * (`computeStackLayout`) and the stack effect writes the CSS custom
521
+ * properties `_toaster.css` reads (`--toasts-before`, `--offset`,
522
+ * `--initial-height`, `--front-toast-height`) plus `data-front`,
523
+ * `data-visible`, and z-index. DOM order is chronological; the last child
524
+ * is the front (newest) toast.
525
+ */
526
+ #reindex(): void {
527
+ const toasts = this.#toasts().filter((toast) => toast.dataset.removed !== "true");
528
+
529
+ // Batch-measure with heights unclamped, restored at scope exit: one
530
+ // layout pass, no visible change (the stack effect is microtask-batched,
531
+ // so its DOM writes land after the restore).
532
+ using _measure = unclampForMeasure(toasts);
533
+ const entries = toasts.map((toast) => ({ node: toast, height: toast.offsetHeight }));
534
+
535
+ this.#stack.set(entries);
536
+ }
537
+
538
+ /**
539
+ * @returns The toast list (created in `connectedCallback`).
540
+ */
541
+ #list(): HTMLOListElement {
542
+ let list = this.querySelector('[data-slot~="toaster-list"]');
543
+ if (!(list instanceof HTMLOListElement)) {
544
+ list = document.createElement("ol");
545
+ list.setAttribute("data-slot", "toaster-list");
546
+ this.append(list);
547
+ }
548
+ return list as HTMLOListElement;
549
+ }
550
+
551
+ /**
552
+ * @returns All toast elements, oldest first (DOM order).
553
+ */
554
+ #toasts(): HTMLElement[] {
555
+ return Array.from(this.#list().children)
556
+ .filter((child): child is HTMLElement => child instanceof HTMLElement)
557
+ .filter((child) => child.matches('[data-slot~="toaster-toast"]'));
558
+ }
559
+
560
+ // --- Expand / collapse ---
561
+
562
+ /**
563
+ * @description Expands or collapses the stack by writing the signal state.
564
+ * The attribute write and the timer pause/resume (matching Sonner) are owned
565
+ * by the effects in `connectedCallback`: no caller has to remember them.
566
+ *
567
+ * @param expanded - Whether the stack is expanded.
568
+ */
569
+ #setExpanded(expanded: boolean): void {
570
+ if (expanded) window.clearTimeout(this.#collapseTimer);
571
+ this.#expanded.set(expanded);
572
+ }
573
+
574
+ /**
575
+ * @description Collapses the stack only if the user has really left it.
576
+ * Waits a beat, then checks actual hover and focus state: dismissals fire
577
+ * spurious mouseleave/focusout (exit transforms, node removal, focus drops)
578
+ * that a raw event handler would mistake for the pointer leaving.
579
+ */
580
+ #requestCollapse(): void {
581
+ window.clearTimeout(this.#collapseTimer);
582
+ this.#collapseTimer = window.setTimeout(() => {
583
+ const activeElement = document.activeElement;
584
+ const focusWithin = activeElement instanceof Node && this.contains(activeElement);
585
+ if (!this.matches(":hover") && !focusWithin) this.#setExpanded(false);
586
+ }, 100);
587
+ }
588
+
589
+ // --- Timers ---
590
+
591
+ /**
592
+ * @description Registers a toast's auto-dismiss timer and schedules it unless
593
+ * the stack is currently paused (expanded or hidden tab).
594
+ *
595
+ * @param id - Toast id.
596
+ * @param duration - Lifetime in ms; `Infinity` skips the timer.
597
+ */
598
+ #startTimer(id: string, duration: number): void {
599
+ if (duration === Infinity || Number.isNaN(duration)) return;
600
+ const timer: ToastTimer = { remaining: duration, startedAt: 0, timeoutId: 0 };
601
+ this.#timers.set(id, timer);
602
+ if (!this.#paused.get()) this.#schedule(id, timer);
603
+ }
604
+
605
+ /**
606
+ * @description Arms a timer's timeout for its remaining lifetime.
607
+ *
608
+ * @param id - Toast id.
609
+ * @param timer - The timer record.
610
+ */
611
+ #schedule(id: string, timer: ToastTimer): void {
612
+ timer.startedAt = Date.now();
613
+ timer.timeoutId = window.setTimeout(() => this.dismiss(id), timer.remaining);
614
+ }
615
+
616
+ /**
617
+ * @description Pauses all running timers, banking each one's remaining time.
618
+ */
619
+ #pauseTimers(): void {
620
+ for (const timer of this.#timers.values()) {
621
+ if (!timer.timeoutId) continue;
622
+ clearTimeout(timer.timeoutId);
623
+ timer.timeoutId = 0;
624
+ timer.remaining = Math.max(0, timer.remaining - (Date.now() - timer.startedAt));
625
+ }
626
+ }
627
+
628
+ /**
629
+ * @description Resumes paused timers (no-op while still expanded or hidden).
630
+ */
631
+ #resumeTimers(): void {
632
+ if (this.#paused.get()) return;
633
+ for (const [id, timer] of this.#timers) {
634
+ if (!timer.timeoutId) this.#schedule(id, timer);
635
+ }
636
+ }
637
+
638
+ // --- Region show/hide ---
639
+
640
+ /**
641
+ * @description Puts the region on the top layer if it isn't already.
642
+ */
643
+ #showRegion(): void {
644
+ try {
645
+ if (!this.matches(":popover-open, .\\:popover-open")) this.showPopover();
646
+ } catch {
647
+ // Older engines without the Popover API: the region stays a fixed-position
648
+ // element, which still renders (just not on the top layer).
649
+ }
650
+ }
651
+
652
+ /**
653
+ * @description Removes the region from the top layer.
654
+ */
655
+ #hideRegion(): void {
656
+ try {
657
+ if (this.matches(":popover-open, .\\:popover-open")) this.hidePopover();
658
+ } catch {
659
+ // See #showRegion.
660
+ }
661
+ }
662
+
663
+ /**
664
+ * @description Removes a dismissed toast after its exit transition (with a
665
+ * timeout safety net), then hides the region once the stack is empty.
666
+ *
667
+ * @param toast - The toast marked `data-removed="true"`.
668
+ */
669
+ #finalizeRemoval(toast: HTMLElement): void {
670
+ let done = false;
671
+ const remove = () => {
672
+ if (done) return;
673
+ done = true;
674
+ toast.remove();
675
+ if (this.#toasts().length === 0) {
676
+ this.#setExpanded(false);
677
+ this.#hideRegion();
678
+ }
679
+ };
680
+
681
+ toast.addEventListener("transitionend", (event) => {
682
+ if (event.target === toast) remove();
683
+ });
684
+
685
+ // Safety net for when no transitionend fires (reduced motion → duration 0).
686
+ // Scaled to the computed duration so retuned --ui-toaster-transition-duration
687
+ // themes aren't yanked out mid-exit.
688
+ const duration = getComputedStyle(toast)
689
+ .transitionDuration.split(",")
690
+ .reduce((max, value) => Math.max(max, Number.parseFloat(value) || 0), 0);
691
+ window.setTimeout(remove, Math.max(EXIT_FALLBACK_MS, duration * 1000 + 100));
692
+ }
693
+ }
694
+
695
+ // --- Imperative API ---
696
+
697
+ /**
698
+ * @description Resolves a target region from an id, element, or the document.
699
+ *
700
+ * @param region - Region id or element.
701
+ * @returns The region, or `null` when none exists.
702
+ * @private
703
+ */
704
+ function resolveRegion(region?: string | Element): UiToaster | null {
705
+ const node =
706
+ region instanceof Element
707
+ ? region
708
+ : typeof region === "string"
709
+ ? document.getElementById(region)
710
+ : document.querySelector("ui-toaster");
711
+
712
+ if (node instanceof UiToaster) return node;
713
+
714
+ console.warn(
715
+ 'Toaster: no <ui-toaster> found. Add `<ui-toaster class="ui-toaster" popover="manual"></ui-toaster>` to the page.',
716
+ );
717
+ return null;
718
+ }
719
+
720
+ /**
721
+ * @description Normalizes the `toast("message")` string shorthand.
722
+ *
723
+ * @param options - Options object or title string.
724
+ * @returns The options object.
725
+ * @private
726
+ */
727
+ function toOptions(options?: ToastOptions | string): ToastOptions {
728
+ if (typeof options === "string") return { title: options };
729
+ return options ?? {};
730
+ }
731
+
732
+ /**
733
+ * @namespace Toaster
734
+ * @description Imperative toast API. Requires a `<ui-toaster>` in the page:
735
+ * the region is never auto-created (HTML-first, like every Zazz component).
736
+ *
737
+ * @property toast - Shows a toast; returns its id.
738
+ * @property success - Success shorthand.
739
+ * @property info - Info shorthand.
740
+ * @property warning - Warning shorthand.
741
+ * @property error - Destructive shorthand.
742
+ * @property dismiss - Dismisses one toast, or all when omitted.
743
+ */
744
+ const Toaster = {
745
+ /**
746
+ * @description Shows a toast in the target (or first) region.
747
+ *
748
+ * @param options - Options object or title string.
749
+ * @returns The toast id, or `null` when no region exists.
750
+ */
751
+ toast(options?: ToastOptions | string): string | null {
752
+ const resolved = toOptions(options);
753
+ const region = resolveRegion(resolved.region);
754
+ return region ? region.addToast(resolved) : null;
755
+ },
756
+
757
+ /**
758
+ * @description Shows a success toast.
759
+ *
760
+ * @param message - Toast title.
761
+ * @param options - Additional options.
762
+ * @returns The toast id, or `null` when no region exists.
763
+ */
764
+ success(message: string, options?: ToastOptions): string | null {
765
+ return Toaster.toast({ ...options, title: message, variant: "success" });
766
+ },
767
+
768
+ /**
769
+ * @description Shows an info toast.
770
+ *
771
+ * @param message - Toast title.
772
+ * @param options - Additional options.
773
+ * @returns The toast id, or `null` when no region exists.
774
+ */
775
+ info(message: string, options?: ToastOptions): string | null {
776
+ return Toaster.toast({ ...options, title: message, variant: "info" });
777
+ },
778
+
779
+ /**
780
+ * @description Shows a warning toast.
781
+ *
782
+ * @param message - Toast title.
783
+ * @param options - Additional options.
784
+ * @returns The toast id, or `null` when no region exists.
785
+ */
786
+ warning(message: string, options?: ToastOptions): string | null {
787
+ return Toaster.toast({ ...options, title: message, variant: "warning" });
788
+ },
789
+
790
+ /**
791
+ * @description Shows a destructive/error toast.
792
+ *
793
+ * @param message - Toast title.
794
+ * @param options - Additional options.
795
+ * @returns The toast id, or `null` when no region exists.
796
+ */
797
+ error(message: string, options?: ToastOptions): string | null {
798
+ return Toaster.toast({ ...options, title: message, variant: "destructive" });
799
+ },
800
+
801
+ /**
802
+ * @description Dismisses a toast by id in any region, or every toast everywhere.
803
+ *
804
+ * @param id - Toast id returned by `toast()`.
805
+ */
806
+ dismiss(id?: string): void {
807
+ for (const region of document.querySelectorAll("ui-toaster")) {
808
+ if (region instanceof UiToaster) region.dismiss(id);
809
+ }
810
+ },
811
+ };
812
+
813
+ defineZazzElement("ui-toaster", UiToaster);
814
+
815
+ // Attach the imperative toast API to window (the documented public surface app
816
+ // authors call), then export for module consumers.
817
+ if (typeof window !== "undefined") {
818
+ window.Toaster = Toaster;
819
+ }
820
+
821
+ // computeStackLayout is exported for unit tests only; not part of the
822
+ // documented public API (window.Toaster is the surface app authors use).
823
+ export { Toaster, UiToaster, computeStackLayout };