snice 1.14.3 → 2.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 (185) hide show
  1. package/bin/templates/base/tsconfig.json +5 -4
  2. package/components/accordion/demo.html +403 -0
  3. package/components/accordion/snice-accordion-item.css +85 -0
  4. package/components/accordion/snice-accordion-item.ts +226 -0
  5. package/components/accordion/snice-accordion.css +31 -0
  6. package/components/accordion/snice-accordion.ts +182 -0
  7. package/components/accordion/snice-accordion.types.ts +32 -0
  8. package/components/alert/demo.html +445 -0
  9. package/components/alert/snice-alert.css +195 -0
  10. package/components/alert/snice-alert.ts +141 -0
  11. package/components/alert/snice-alert.types.ts +12 -0
  12. package/components/avatar/demo.html +598 -0
  13. package/components/avatar/snice-avatar.css +131 -0
  14. package/components/avatar/snice-avatar.ts +136 -0
  15. package/components/avatar/snice-avatar.types.ts +13 -0
  16. package/components/badge/demo.html +523 -0
  17. package/components/badge/snice-badge.css +161 -0
  18. package/components/badge/snice-badge.ts +117 -0
  19. package/components/badge/snice-badge.types.ts +16 -0
  20. package/components/breadcrumbs/demo.html +404 -0
  21. package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
  22. package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
  23. package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
  24. package/components/breadcrumbs/snice-crumb.ts +26 -0
  25. package/components/button/demo.html +42 -0
  26. package/components/button/snice-button.css +230 -0
  27. package/components/button/snice-button.ts +169 -0
  28. package/components/button/snice-button.types.ts +25 -0
  29. package/components/card/demo.html +525 -0
  30. package/components/card/snice-card.css +140 -0
  31. package/components/card/snice-card.ts +102 -0
  32. package/components/card/snice-card.types.ts +10 -0
  33. package/components/checkbox/demo.html +253 -0
  34. package/components/checkbox/snice-checkbox.css +164 -0
  35. package/components/checkbox/snice-checkbox.ts +223 -0
  36. package/components/checkbox/snice-checkbox.types.ts +22 -0
  37. package/components/chip/demo.html +383 -0
  38. package/components/chip/snice-chip.css +195 -0
  39. package/components/chip/snice-chip.ts +139 -0
  40. package/components/chip/snice-chip.types.ts +15 -0
  41. package/components/date-picker/README.md +233 -0
  42. package/components/date-picker/demo.html +191 -0
  43. package/components/date-picker/snice-date-picker.css +330 -0
  44. package/components/date-picker/snice-date-picker.ts +777 -0
  45. package/components/date-picker/snice-date-picker.types.ts +83 -0
  46. package/components/divider/demo.html +233 -0
  47. package/components/divider/snice-divider.css +155 -0
  48. package/components/divider/snice-divider.ts +69 -0
  49. package/components/divider/snice-divider.types.ts +15 -0
  50. package/components/drawer/demo.html +328 -0
  51. package/components/drawer/snice-drawer.css +476 -0
  52. package/components/drawer/snice-drawer.ts +287 -0
  53. package/components/drawer/snice-drawer.types.ts +17 -0
  54. package/components/global.d.ts +14 -0
  55. package/components/input/demo.html +303 -0
  56. package/components/input/snice-input.css +257 -0
  57. package/components/input/snice-input.ts +442 -0
  58. package/components/input/snice-input.types.ts +59 -0
  59. package/components/input/test.html +77 -0
  60. package/components/layout/README.md +260 -0
  61. package/components/layout/demo.html +538 -0
  62. package/components/layout/snice-layout-blog.css +129 -0
  63. package/components/layout/snice-layout-blog.ts +48 -0
  64. package/components/layout/snice-layout-card.css +104 -0
  65. package/components/layout/snice-layout-card.ts +35 -0
  66. package/components/layout/snice-layout-centered.css +51 -0
  67. package/components/layout/snice-layout-centered.ts +22 -0
  68. package/components/layout/snice-layout-dashboard.css +98 -0
  69. package/components/layout/snice-layout-dashboard.ts +45 -0
  70. package/components/layout/snice-layout-fullscreen.css +72 -0
  71. package/components/layout/snice-layout-fullscreen.ts +34 -0
  72. package/components/layout/snice-layout-landing.css +92 -0
  73. package/components/layout/snice-layout-landing.ts +47 -0
  74. package/components/layout/snice-layout-minimal.css +16 -0
  75. package/components/layout/snice-layout-minimal.ts +19 -0
  76. package/components/layout/snice-layout-sidebar.css +117 -0
  77. package/components/layout/snice-layout-sidebar.ts +48 -0
  78. package/components/layout/snice-layout-split.css +103 -0
  79. package/components/layout/snice-layout-split.ts +29 -0
  80. package/components/layout/snice-layout.css +72 -0
  81. package/components/layout/snice-layout.ts +35 -0
  82. package/components/layout/snice-layout.types.ts +5 -0
  83. package/components/login/demo-auth-controller.ts +185 -0
  84. package/components/login/demo.html +470 -0
  85. package/components/login/snice-login.css +204 -0
  86. package/components/login/snice-login.ts +337 -0
  87. package/components/login/snice-login.types.ts +34 -0
  88. package/components/modal/demo.html +291 -0
  89. package/components/modal/snice-modal.css +203 -0
  90. package/components/modal/snice-modal.ts +233 -0
  91. package/components/modal/snice-modal.types.ts +21 -0
  92. package/components/pagination/demo.html +395 -0
  93. package/components/pagination/snice-pagination.ts +333 -0
  94. package/components/pagination/snice-pagination.types.ts +21 -0
  95. package/components/progress/demo.html +510 -0
  96. package/components/progress/snice-progress.css +267 -0
  97. package/components/progress/snice-progress.ts +247 -0
  98. package/components/progress/snice-progress.types.ts +19 -0
  99. package/components/radio/demo.html +287 -0
  100. package/components/radio/snice-radio.css +171 -0
  101. package/components/radio/snice-radio.ts +218 -0
  102. package/components/radio/snice-radio.types.ts +21 -0
  103. package/components/select/demo.html +511 -0
  104. package/components/select/snice-option.ts +52 -0
  105. package/components/select/snice-option.types.ts +14 -0
  106. package/components/select/snice-select.css +392 -0
  107. package/components/select/snice-select.ts +796 -0
  108. package/components/select/snice-select.types.ts +55 -0
  109. package/components/skeleton/demo.html +514 -0
  110. package/components/skeleton/snice-skeleton.css +109 -0
  111. package/components/skeleton/snice-skeleton.ts +126 -0
  112. package/components/skeleton/snice-skeleton.types.ts +11 -0
  113. package/components/switch/demo.html +284 -0
  114. package/components/switch/snice-switch.css +221 -0
  115. package/components/switch/snice-switch.ts +229 -0
  116. package/components/switch/snice-switch.types.ts +23 -0
  117. package/components/symbols.ts +23 -0
  118. package/components/table/demo-table-controller.ts +100 -0
  119. package/components/table/demo.html +480 -0
  120. package/components/table/snice-cell-boolean.ts +112 -0
  121. package/components/table/snice-cell-date.ts +210 -0
  122. package/components/table/snice-cell-duration.ts +91 -0
  123. package/components/table/snice-cell-filesize.ts +90 -0
  124. package/components/table/snice-cell-number.ts +165 -0
  125. package/components/table/snice-cell-progress.ts +83 -0
  126. package/components/table/snice-cell-rating.ts +82 -0
  127. package/components/table/snice-cell-sparkline.ts +253 -0
  128. package/components/table/snice-cell-text.ts +125 -0
  129. package/components/table/snice-cell.css +296 -0
  130. package/components/table/snice-cell.ts +473 -0
  131. package/components/table/snice-column.ts +353 -0
  132. package/components/table/snice-header.css +243 -0
  133. package/components/table/snice-header.ts +261 -0
  134. package/components/table/snice-progress.ts +66 -0
  135. package/components/table/snice-rating.ts +45 -0
  136. package/components/table/snice-row.css +255 -0
  137. package/components/table/snice-row.ts +331 -0
  138. package/components/table/snice-table.css +241 -0
  139. package/components/table/snice-table.ts +737 -0
  140. package/components/table/snice-table.types.ts +158 -0
  141. package/components/tabs/demo.html +487 -0
  142. package/components/tabs/snice-tab-panel.css +264 -0
  143. package/components/tabs/snice-tab-panel.ts +47 -0
  144. package/components/tabs/snice-tab.css +96 -0
  145. package/components/tabs/snice-tab.ts +65 -0
  146. package/components/tabs/snice-tabs.css +189 -0
  147. package/components/tabs/snice-tabs.ts +332 -0
  148. package/components/tabs/snice-tabs.types.ts +28 -0
  149. package/components/theme/theme.css +234 -0
  150. package/components/toast/demo.html +329 -0
  151. package/components/toast/snice-toast-container.ts +256 -0
  152. package/components/toast/snice-toast.css +213 -0
  153. package/components/toast/snice-toast.ts +276 -0
  154. package/components/toast/snice-toast.types.ts +35 -0
  155. package/components/tooltip/demo.html +350 -0
  156. package/components/tooltip/snice-tooltip-portal.css +79 -0
  157. package/components/tooltip/snice-tooltip.css +117 -0
  158. package/components/tooltip/snice-tooltip.ts +612 -0
  159. package/components/tooltip/snice-tooltip.types.ts +32 -0
  160. package/components/transitions.ts +94 -0
  161. package/components/tsconfig.json +18 -0
  162. package/dist/index.cjs +441 -329
  163. package/dist/index.cjs.map +1 -1
  164. package/dist/index.cjs.min.map +1 -1
  165. package/dist/index.esm.js +441 -329
  166. package/dist/index.esm.js.map +1 -1
  167. package/dist/index.esm.min.js +3 -3
  168. package/dist/index.esm.min.js.map +1 -1
  169. package/dist/index.iife.js +441 -329
  170. package/dist/index.iife.js.map +1 -1
  171. package/dist/index.iife.min.js +3 -3
  172. package/dist/index.iife.min.js.map +1 -1
  173. package/dist/symbols.esm.js +1 -1
  174. package/dist/transitions.esm.js +1 -1
  175. package/dist/types/controller.d.ts +1 -1
  176. package/dist/types/element.d.ts +10 -10
  177. package/dist/types/events.d.ts +2 -2
  178. package/dist/types/index.d.ts +1 -1
  179. package/dist/types/observe.d.ts +1 -1
  180. package/dist/types/request-response.d.ts +2 -3
  181. package/dist/types/router.d.ts +1 -1
  182. package/package.json +9 -3
  183. package/dist/index.cjs.min +0 -15
  184. package/dist/symbols.cjs +0 -103
  185. package/dist/transitions.cjs +0 -219
@@ -0,0 +1,329 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Snice Toast Demo</title>
7
+ <link rel="stylesheet" href="../theme/theme.css">
8
+ <style>
9
+ body {
10
+ font-family: var(--snice-font-family);
11
+ background: var(--snice-color-background);
12
+ color: var(--snice-color-text);
13
+ padding: var(--snice-spacing-lg);
14
+ margin: 0;
15
+ }
16
+
17
+ .container {
18
+ max-width: 800px;
19
+ margin: 0 auto;
20
+ }
21
+
22
+ h1 {
23
+ font-size: var(--snice-font-size-3xl);
24
+ margin-bottom: var(--snice-spacing-xl);
25
+ }
26
+
27
+ .section {
28
+ margin-bottom: var(--snice-spacing-2xl);
29
+ }
30
+
31
+ .section h2 {
32
+ font-size: var(--snice-font-size-xl);
33
+ margin-bottom: var(--snice-spacing-md);
34
+ color: var(--snice-color-text-secondary);
35
+ }
36
+
37
+ .controls {
38
+ display: flex;
39
+ flex-wrap: wrap;
40
+ gap: var(--snice-spacing-sm);
41
+ margin-bottom: var(--snice-spacing-lg);
42
+ }
43
+
44
+ .button-group {
45
+ display: flex;
46
+ flex-wrap: wrap;
47
+ gap: var(--snice-spacing-xs);
48
+ }
49
+
50
+ button {
51
+ padding: var(--snice-spacing-xs) var(--snice-spacing-md);
52
+ border-radius: var(--snice-border-radius-md);
53
+ border: 1px solid var(--snice-color-border);
54
+ background: var(--snice-color-background);
55
+ color: var(--snice-color-text);
56
+ font-size: var(--snice-font-size-sm);
57
+ font-family: var(--snice-font-family);
58
+ cursor: pointer;
59
+ transition: all var(--snice-transition-fast);
60
+ }
61
+
62
+ button:hover {
63
+ background: var(--snice-color-background-secondary);
64
+ border-color: var(--snice-color-border-hover);
65
+ }
66
+
67
+ button.success {
68
+ background: var(--snice-color-success);
69
+ color: var(--snice-color-text-inverse);
70
+ border-color: var(--snice-color-success);
71
+ }
72
+
73
+ button.success:hover {
74
+ background: var(--snice-color-success-hover);
75
+ border-color: var(--snice-color-success-hover);
76
+ }
77
+
78
+ button.error {
79
+ background: var(--snice-color-danger);
80
+ color: var(--snice-color-text-inverse);
81
+ border-color: var(--snice-color-danger);
82
+ }
83
+
84
+ button.error:hover {
85
+ background: var(--snice-color-danger-hover);
86
+ border-color: var(--snice-color-danger-hover);
87
+ }
88
+
89
+ button.warning {
90
+ background: var(--snice-color-warning);
91
+ color: var(--snice-color-text-inverse);
92
+ border-color: var(--snice-color-warning);
93
+ }
94
+
95
+ button.warning:hover {
96
+ background: var(--snice-color-warning-hover);
97
+ border-color: var(--snice-color-warning-hover);
98
+ }
99
+
100
+ button.info {
101
+ background: var(--snice-color-primary);
102
+ color: var(--snice-color-text-inverse);
103
+ border-color: var(--snice-color-primary);
104
+ }
105
+
106
+ button.info:hover {
107
+ background: var(--snice-color-primary-hover);
108
+ border-color: var(--snice-color-primary-hover);
109
+ }
110
+
111
+ .position-controls {
112
+ display: grid;
113
+ grid-template-columns: repeat(3, 1fr);
114
+ gap: var(--snice-spacing-xs);
115
+ max-width: 300px;
116
+ }
117
+
118
+ .position-controls button {
119
+ padding: var(--snice-spacing-xs);
120
+ font-size: var(--snice-font-size-xs);
121
+ }
122
+
123
+ .position-controls button.active {
124
+ background: var(--snice-color-primary);
125
+ color: var(--snice-color-text-inverse);
126
+ border-color: var(--snice-color-primary);
127
+ }
128
+
129
+ .custom-message {
130
+ display: flex;
131
+ gap: var(--snice-spacing-sm);
132
+ margin-bottom: var(--snice-spacing-md);
133
+ }
134
+
135
+ .custom-message input {
136
+ flex: 1;
137
+ padding: var(--snice-spacing-xs) var(--snice-spacing-sm);
138
+ border: 1px solid var(--snice-color-border);
139
+ border-radius: var(--snice-border-radius-md);
140
+ background: var(--snice-color-background);
141
+ color: var(--snice-color-text);
142
+ font-size: var(--snice-font-size-sm);
143
+ font-family: var(--snice-font-family);
144
+ }
145
+
146
+ .custom-message input:focus {
147
+ outline: none;
148
+ border-color: var(--snice-color-border-focus);
149
+ box-shadow: 0 0 0 3px var(--snice-focus-ring-color);
150
+ }
151
+
152
+ .options {
153
+ display: flex;
154
+ gap: var(--snice-spacing-md);
155
+ margin-bottom: var(--snice-spacing-md);
156
+ }
157
+
158
+ .options label {
159
+ display: flex;
160
+ align-items: center;
161
+ gap: var(--snice-spacing-xs);
162
+ font-size: var(--snice-font-size-sm);
163
+ }
164
+
165
+ .code {
166
+ background: var(--snice-color-background-tertiary);
167
+ padding: var(--snice-spacing-md);
168
+ border-radius: var(--snice-border-radius-md);
169
+ font-family: var(--snice-font-family-mono);
170
+ font-size: var(--snice-font-size-sm);
171
+ line-height: var(--snice-line-height-loose);
172
+ }
173
+ </style>
174
+ <script type="module">
175
+ import Toast from './snice-toast-container.ts';
176
+ import { element, controller, on } from '../../src/index.ts';
177
+
178
+ let currentPosition = 'bottom-right';
179
+
180
+ function showToast(type) {
181
+ const messages = {
182
+ success: 'Operation completed successfully!',
183
+ error: 'An error occurred. Please try again.',
184
+ warning: 'This action cannot be undone.',
185
+ info: 'New updates are available.'
186
+ };
187
+
188
+ Toast[type](messages[type], { position: currentPosition });
189
+ }
190
+
191
+ function showEventToast(type) {
192
+ const messages = {
193
+ success: 'Event triggered: Success!',
194
+ error: 'Event triggered: Error occurred!',
195
+ warning: 'Event triggered: Warning!',
196
+ info: 'Event triggered: Info message'
197
+ };
198
+
199
+ const event = new CustomEvent('@snice/show-toast', {
200
+ detail: {
201
+ message: messages[type],
202
+ options: { type, position: currentPosition }
203
+ },
204
+ bubbles: true,
205
+ composed: true
206
+ });
207
+ document.body.dispatchEvent(event);
208
+ }
209
+
210
+ function setPosition(position) {
211
+ currentPosition = position;
212
+ document.querySelectorAll('.position-controls button').forEach(btn => {
213
+ btn.classList.toggle('active', btn.textContent.includes(position));
214
+ });
215
+ }
216
+
217
+ function showCustom() {
218
+ const input = document.getElementById('custom-input');
219
+ const message = input.value || 'Custom toast message';
220
+ const closable = document.getElementById('closable').checked;
221
+ const hasIcon = document.getElementById('has-icon').checked;
222
+ const duration = parseInt(document.getElementById('duration').value) * 1000;
223
+
224
+ Toast.info(message, {
225
+ position: currentPosition,
226
+ closable,
227
+ icon: hasIcon,
228
+ duration
229
+ });
230
+ }
231
+
232
+ function showMultiple() {
233
+ Toast.success('First toast message', { position: currentPosition });
234
+ setTimeout(() => {
235
+ Toast.info('Second toast message', { position: currentPosition });
236
+ }, 500);
237
+ setTimeout(() => {
238
+ Toast.warning('Third toast message', { position: currentPosition });
239
+ }, 1000);
240
+ setTimeout(() => {
241
+ Toast.error('Fourth toast message', { position: currentPosition });
242
+ }, 1500);
243
+ }
244
+
245
+ function clearAll() {
246
+ Toast.clear();
247
+ }
248
+
249
+ // Expose functions to window for onclick handlers
250
+ window.showToast = showToast;
251
+ window.showEventToast = showEventToast;
252
+ window.setPosition = setPosition;
253
+ window.showCustom = showCustom;
254
+ window.showMultiple = showMultiple;
255
+ window.clearAll = clearAll;
256
+ </script>
257
+ </head>
258
+ <body>
259
+ <div class="container">
260
+ <h1>Snice Toast Component</h1>
261
+
262
+ <div class="section">
263
+ <h2>Basic Toasts</h2>
264
+ <div class="button-group">
265
+ <button class="success" onclick="showToast('success')">Success Toast</button>
266
+ <button class="error" onclick="showToast('error')">Error Toast</button>
267
+ <button class="warning" onclick="showToast('warning')">Warning Toast</button>
268
+ <button class="info" onclick="showToast('info')">Info Toast</button>
269
+ </div>
270
+ </div>
271
+
272
+ <div class="section">
273
+ <h2>Position</h2>
274
+ <div class="position-controls">
275
+ <button onclick="setPosition('top-left')">↖ Top Left</button>
276
+ <button onclick="setPosition('top-center')">↑ Top Center</button>
277
+ <button onclick="setPosition('top-right')">↗ Top Right</button>
278
+ <button onclick="setPosition('bottom-left')">↙ Bottom Left</button>
279
+ <button onclick="setPosition('bottom-center')">↓ Bottom Center</button>
280
+ <button class="active" onclick="setPosition('bottom-right')">↘ Bottom Right</button>
281
+ </div>
282
+ </div>
283
+
284
+ <div class="section">
285
+ <h2>Custom Toast</h2>
286
+ <div class="custom-message">
287
+ <input type="text" id="custom-input" placeholder="Enter custom message...">
288
+ <button onclick="showCustom()">Show Custom</button>
289
+ </div>
290
+ <div class="options">
291
+ <label>
292
+ <input type="checkbox" id="closable" checked>
293
+ Closable
294
+ </label>
295
+ <label>
296
+ <input type="checkbox" id="has-icon" checked>
297
+ Show Icon
298
+ </label>
299
+ <label>
300
+ Duration (sec):
301
+ <input type="number" id="duration" value="4" min="0" max="30" style="width: 60px;">
302
+ </label>
303
+ </div>
304
+ </div>
305
+
306
+ <div class="section">
307
+ <h2>Event-Based Triggering</h2>
308
+ <p style="font-size: var(--snice-font-size-sm); color: var(--snice-color-text-secondary); margin-bottom: var(--snice-spacing-md);">
309
+ Toasts can be triggered via events that bubble up to the document
310
+ </p>
311
+ <div class="button-group">
312
+ <button class="success" onclick="showEventToast('success')">Event Success</button>
313
+ <button class="error" onclick="showEventToast('error')">Event Error</button>
314
+ <button class="warning" onclick="showEventToast('warning')">Event Warning</button>
315
+ <button class="info" onclick="showEventToast('info')">Event Info</button>
316
+ </div>
317
+ </div>
318
+
319
+ <div class="section">
320
+ <h2>Actions</h2>
321
+ <div class="button-group">
322
+ <button onclick="showMultiple()">Show Multiple</button>
323
+ <button onclick="clearAll()">Clear All</button>
324
+ </div>
325
+ </div>
326
+
327
+ </div>
328
+ </body>
329
+ </html>
@@ -0,0 +1,256 @@
1
+ import { element, property, ready, dispose } from 'snice';
2
+ import { getSymbol } from '../symbols';
3
+ import type { ToastPosition, ToastOptions, ToastEventDetail, ToastResponseEventDetail, SniceToastContainerElement } from './snice-toast.types';
4
+ import './snice-toast';
5
+
6
+ // Symbols for global state management
7
+ const TOAST_CONTAINER = getSymbol('@snice/toast', 'container');
8
+ const TOAST_LISTENER_INITIALIZED = getSymbol('@snice/toast', 'listener-initialized');
9
+
10
+ // Namespaced events
11
+ const TOAST_EVENT_SHOW = '@snice/show-toast';
12
+ const TOAST_EVENT_RESPONSE = '@snice/toast-response';
13
+
14
+ @element('snice-toast-container')
15
+ export class SniceToastContainer extends HTMLElement implements SniceToastContainerElement {
16
+ @property({ reflect: true })
17
+ position: ToastPosition = 'bottom-center';
18
+
19
+ private toastIdCounter = 1;
20
+ private toasts: Map<string, HTMLElement> = new Map();
21
+
22
+ html() {
23
+ return /*html*/`
24
+ <div class="toast-wrapper"></div>
25
+ `;
26
+ }
27
+
28
+ css() {
29
+ return /*css*/`
30
+ :host {
31
+ position: fixed;
32
+ z-index: 10000;
33
+ pointer-events: none;
34
+ display: flex;
35
+ flex-direction: column;
36
+ gap: 12px;
37
+ padding: 16px;
38
+ }
39
+
40
+ /* Position variants */
41
+ :host([position="top-left"]) {
42
+ top: 0;
43
+ left: 0;
44
+ align-items: flex-start;
45
+ }
46
+
47
+ :host([position="top-center"]) {
48
+ top: 0;
49
+ left: 50%;
50
+ transform: translateX(-50%);
51
+ align-items: center;
52
+ }
53
+
54
+ :host([position="top-right"]) {
55
+ top: 0;
56
+ right: 0;
57
+ align-items: flex-end;
58
+ }
59
+
60
+ :host([position="bottom-left"]) {
61
+ bottom: 0;
62
+ left: 0;
63
+ align-items: flex-start;
64
+ }
65
+
66
+ :host([position="bottom-center"]) {
67
+ bottom: 0;
68
+ left: 50%;
69
+ transform: translateX(-50%);
70
+ align-items: center;
71
+ }
72
+
73
+ :host([position="bottom-right"]) {
74
+ bottom: 0;
75
+ right: 0;
76
+ align-items: flex-end;
77
+ }
78
+
79
+ .toast-wrapper {
80
+ display: flex;
81
+ flex-direction: column;
82
+ gap: 8px;
83
+ }
84
+ `;
85
+ }
86
+
87
+ @ready()
88
+ init() {
89
+ // Register as global container if none exists
90
+ if (!(globalThis as any)[TOAST_CONTAINER]) {
91
+ (globalThis as any)[TOAST_CONTAINER] = this;
92
+ }
93
+ // Initialize event listener if not already done
94
+ initializeGlobalEventListener();
95
+ }
96
+
97
+ @dispose()
98
+ cleanup() {
99
+ // Unregister as global container
100
+ if ((globalThis as any)[TOAST_CONTAINER] === this) {
101
+ (globalThis as any)[TOAST_CONTAINER] = null;
102
+ }
103
+
104
+ // Clean up all toasts
105
+ this.toasts.clear();
106
+ }
107
+
108
+ show(message: string, options: ToastOptions = {}): string {
109
+ const id = options.id || `toast-${this.toastIdCounter++}`;
110
+ const type = options.type || 'info';
111
+ const duration = options.duration !== undefined ? options.duration : 4000;
112
+ const closable = options.closable !== undefined ? options.closable : true;
113
+ const icon = options.icon !== undefined ? options.icon : true;
114
+
115
+ // Create toast element
116
+ const toast = document.createElement('snice-toast') as any;
117
+ toast.setAttribute('toast-id', id);
118
+ toast.type = type;
119
+ toast.message = message;
120
+ toast.closable = closable;
121
+ toast.icon = icon;
122
+
123
+ // Add to container
124
+ const wrapper = this.shadowRoot?.querySelector('.toast-wrapper');
125
+ if (wrapper) {
126
+ // Add based on position (top positions prepend, bottom positions append)
127
+ if (this.position.startsWith('bottom')) {
128
+ wrapper.appendChild(toast);
129
+ } else {
130
+ wrapper.insertBefore(toast, wrapper.firstChild);
131
+ }
132
+ }
133
+
134
+ // Store reference
135
+ this.toasts.set(id, toast);
136
+
137
+ // Set auto-dismiss timer if duration > 0
138
+ if (duration > 0) {
139
+ setTimeout(() => {
140
+ this.hide(id);
141
+ }, duration);
142
+ }
143
+
144
+ // Listen for close event from toast
145
+ toast.addEventListener('close-toast', () => {
146
+ this.hide(id);
147
+ });
148
+
149
+ return id;
150
+ }
151
+
152
+ hide(id: string): void {
153
+ const toast = this.toasts.get(id);
154
+ if (!toast) return;
155
+
156
+ // Trigger hide animation on toast
157
+ (toast as any).hide();
158
+
159
+ // Remove after animation completes
160
+ toast.addEventListener('animationend', () => {
161
+ toast.remove();
162
+ this.toasts.delete(id);
163
+ }, { once: true });
164
+ }
165
+
166
+ clear(): void {
167
+ this.toasts.forEach((_, id) => this.hide(id));
168
+ }
169
+ }
170
+
171
+ // Static Toast API
172
+ export class Toast {
173
+ private static ensureContainer(position: ToastPosition = 'bottom-center'): SniceToastContainer {
174
+ // Use existing global container if available
175
+ const globalContainer = (globalThis as any)[TOAST_CONTAINER] as SniceToastContainer;
176
+ if (globalContainer) {
177
+ // Update position if different
178
+ if (globalContainer.position !== position) {
179
+ globalContainer.position = position;
180
+ }
181
+ return globalContainer;
182
+ }
183
+
184
+ // Create new container
185
+ const container = document.createElement('snice-toast-container') as SniceToastContainer;
186
+ container.position = position;
187
+ document.body.appendChild(container);
188
+ return container;
189
+ }
190
+
191
+ static show(message: string, options: ToastOptions = {}): string {
192
+ const container = Toast.ensureContainer(options.position);
193
+ return container.show(message, options);
194
+ }
195
+
196
+ static success(message: string, options: ToastOptions = {}): string {
197
+ return Toast.show(message, { ...options, type: 'success' });
198
+ }
199
+
200
+ static error(message: string, options: ToastOptions = {}): string {
201
+ return Toast.show(message, { ...options, type: 'error' });
202
+ }
203
+
204
+ static warning(message: string, options: ToastOptions = {}): string {
205
+ return Toast.show(message, { ...options, type: 'warning' });
206
+ }
207
+
208
+ static info(message: string, options: ToastOptions = {}): string {
209
+ return Toast.show(message, { ...options, type: 'info' });
210
+ }
211
+
212
+ static hide(id: string): void {
213
+ const globalContainer = (globalThis as any)[TOAST_CONTAINER] as SniceToastContainer;
214
+ if (globalContainer) {
215
+ globalContainer.hide(id);
216
+ }
217
+ }
218
+
219
+ static clear(): void {
220
+ const globalContainer = (globalThis as any)[TOAST_CONTAINER] as SniceToastContainer;
221
+ if (globalContainer) {
222
+ globalContainer.clear();
223
+ }
224
+ }
225
+ }
226
+
227
+ // Global event listener for toast events
228
+ function initializeGlobalEventListener() {
229
+ if ((globalThis as any)[TOAST_LISTENER_INITIALIZED]) return;
230
+
231
+ document.documentElement.addEventListener(TOAST_EVENT_SHOW, (event: Event) => {
232
+ const customEvent = event as CustomEvent<ToastEventDetail>;
233
+ const { message, options = {} } = customEvent.detail;
234
+
235
+ // Show the toast
236
+ const toastId = Toast.show(message, options);
237
+
238
+ // Dispatch response event with toast ID if the original event requested it
239
+ if (customEvent.detail.options?.id) {
240
+ const responseEvent = new CustomEvent<ToastResponseEventDetail>(TOAST_EVENT_RESPONSE, {
241
+ detail: { toastId },
242
+ bubbles: true,
243
+ composed: true
244
+ });
245
+ (customEvent.target as HTMLElement)?.dispatchEvent(responseEvent);
246
+ }
247
+ });
248
+
249
+ (globalThis as any)[TOAST_LISTENER_INITIALIZED] = true;
250
+ }
251
+
252
+ // Initialize listener on module load
253
+ initializeGlobalEventListener();
254
+
255
+ // Export for convenience
256
+ export default Toast;