@wcomp/elementum 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +282 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +593 -0
- package/package.json +77 -4
- package/skills/elementum-break-ui/CATALOG.md +11 -0
- package/skills/elementum-break-ui/SKILL.md +16 -0
- package/skills/elementum-mobile/SKILL.md +18 -0
- package/skills/elementum-motion/SKILL.md +18 -0
- package/skills/elementum-motion/STANDARDS.md +15 -0
- package/skills/elementum-penpot/SKILL.md +45 -0
- package/skills/elementum-ui/CATALOG.md +14 -0
- package/skills/elementum-ui/SKILL.md +21 -0
- package/src/ag-ui.js +474 -0
- package/src/behaviors/index.js +760 -0
- package/src/components/el-accordion.js +201 -0
- package/src/components/el-alert-dialog.js +186 -0
- package/src/components/el-alert.js +254 -0
- package/src/components/el-aspect-ratio.js +73 -0
- package/src/components/el-autocomplete.js +775 -0
- package/src/components/el-avatar.js +271 -0
- package/src/components/el-badge.js +131 -0
- package/src/components/el-border-beam.js +135 -0
- package/src/components/el-breadcrumb.js +203 -0
- package/src/components/el-button.js +231 -0
- package/src/components/el-calendar.js +436 -0
- package/src/components/el-callout.js +158 -0
- package/src/components/el-card.js +298 -0
- package/src/components/el-carousel.js +308 -0
- package/src/components/el-chart.js +632 -0
- package/src/components/el-checkbox-card.js +221 -0
- package/src/components/el-checkbox.js +208 -0
- package/src/components/el-chip.js +276 -0
- package/src/components/el-code-block.js +230 -0
- package/src/components/el-collapsible.js +124 -0
- package/src/components/el-command.js +556 -0
- package/src/components/el-context-menu.js +328 -0
- package/src/components/el-data-list.js +210 -0
- package/src/components/el-datepicker.js +192 -0
- package/src/components/el-dialog.js +272 -0
- package/src/components/el-diff-viewer.js +441 -0
- package/src/components/el-drawer.js +782 -0
- package/src/components/el-dropdown.js +182 -0
- package/src/components/el-dropzone.js +242 -0
- package/src/components/el-empty-state.js +130 -0
- package/src/components/el-field.js +394 -0
- package/src/components/el-form.js +185 -0
- package/src/components/el-input.js +229 -0
- package/src/components/el-inset.js +90 -0
- package/src/components/el-insight-card.js +263 -0
- package/src/components/el-kbd.js +151 -0
- package/src/components/el-menubar.js +254 -0
- package/src/components/el-meter.js +183 -0
- package/src/components/el-navbar.js +294 -0
- package/src/components/el-navigation-menu.js +327 -0
- package/src/components/el-number-field.js +510 -0
- package/src/components/el-number-flow.js +164 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +231 -0
- package/src/components/el-popover.js +288 -0
- package/src/components/el-preview-card.js +202 -0
- package/src/components/el-progress.js +179 -0
- package/src/components/el-prompt-input.js +383 -0
- package/src/components/el-radio-card.js +360 -0
- package/src/components/el-radio.js +257 -0
- package/src/components/el-rating.js +165 -0
- package/src/components/el-reasoning-card.js +293 -0
- package/src/components/el-resizable.js +324 -0
- package/src/components/el-router.js +305 -0
- package/src/components/el-scroll-area.js +150 -0
- package/src/components/el-segmented-control.js +282 -0
- package/src/components/el-select.js +220 -0
- package/src/components/el-separator.js +85 -0
- package/src/components/el-sidebar.js +386 -0
- package/src/components/el-skeleton.js +156 -0
- package/src/components/el-slider.js +351 -0
- package/src/components/el-sources.js +288 -0
- package/src/components/el-spinner.js +159 -0
- package/src/components/el-streaming-text.js +199 -0
- package/src/components/el-switch.js +221 -0
- package/src/components/el-table.js +397 -0
- package/src/components/el-tabs.js +235 -0
- package/src/components/el-task-list.js +230 -0
- package/src/components/el-textarea.js +175 -0
- package/src/components/el-theme-switch.js +120 -0
- package/src/components/el-timeline.js +254 -0
- package/src/components/el-toast.js +778 -0
- package/src/components/el-toggle.js +311 -0
- package/src/components/el-tool-call.js +386 -0
- package/src/components/el-toolbar.js +183 -0
- package/src/components/el-tooltip.js +172 -0
- package/src/components/el-tree-view.js +261 -0
- package/src/components/el-visually-hidden.js +32 -0
- package/src/elementum.js +504 -0
- package/src/index.d.ts +1093 -0
- package/src/index.js +112 -0
- package/src/signal.js +215 -0
- package/src/ssr.js +136 -0
- package/src/template.js +321 -0
- package/src/tokens.css +416 -0
- package/tokens/figma-tokens.json +69 -0
- package/tokens/penpot-tokens.json +98 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-toast> and <el-toaster>
|
|
3
|
+
* Next-generation notification toast system inspired by Sonner (Emil Kowalski).
|
|
4
|
+
* Features:
|
|
5
|
+
* - Ultra-smooth 60fps GPU transitions (no DOM remounting / no choppy re-render)
|
|
6
|
+
* - toast.promise(promise, { loading, success, error }) with reactive in-place morphing
|
|
7
|
+
* - 3D stacked card deck with butter-smooth hover expansion
|
|
8
|
+
* - Gesture swipe-to-dismiss with pointer tracking
|
|
9
|
+
* - Rich action and cancel buttons
|
|
10
|
+
* - Zero runtime dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Elementum } from '../elementum.js';
|
|
14
|
+
import { css } from '../template.js';
|
|
15
|
+
import { signal, effect } from '../signal.js';
|
|
16
|
+
|
|
17
|
+
export class ToastManager {
|
|
18
|
+
toasts = signal([]); // [{ id, message, description, variant, duration, action, cancel, dismissible, _timer }]
|
|
19
|
+
#counter = 0;
|
|
20
|
+
|
|
21
|
+
show(msgOrOpts, maybeOpts = {}) {
|
|
22
|
+
const opts = typeof msgOrOpts === 'string' ? { message: msgOrOpts, ...maybeOpts } : (msgOrOpts || {});
|
|
23
|
+
const id = opts.id || ++this.#counter;
|
|
24
|
+
const duration = opts.duration !== undefined ? opts.duration : (opts.variant === 'loading' ? 0 : 3500);
|
|
25
|
+
|
|
26
|
+
const item = {
|
|
27
|
+
id,
|
|
28
|
+
message: opts.message || '',
|
|
29
|
+
description: opts.description || '',
|
|
30
|
+
variant: opts.variant || 'info', // 'info' | 'success' | 'danger' | 'warning' | 'loading'
|
|
31
|
+
duration,
|
|
32
|
+
action: opts.action || null,
|
|
33
|
+
cancel: opts.cancel || null,
|
|
34
|
+
dismissible: opts.dismissible !== false,
|
|
35
|
+
_timer: null
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (duration > 0) {
|
|
39
|
+
item._timer = setTimeout(() => {
|
|
40
|
+
this.dismiss(id);
|
|
41
|
+
}, duration);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.toasts.value = [...this.toasts.value, item];
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
update(id, updates) {
|
|
49
|
+
this.toasts.value = this.toasts.value.map((t) => {
|
|
50
|
+
if (t.id === id) {
|
|
51
|
+
if (t._timer) clearTimeout(t._timer);
|
|
52
|
+
const updated = { ...t, ...updates };
|
|
53
|
+
const dur = updates.duration !== undefined ? updates.duration : 3500;
|
|
54
|
+
if (dur > 0) {
|
|
55
|
+
updated._timer = setTimeout(() => this.dismiss(id), dur);
|
|
56
|
+
}
|
|
57
|
+
return updated;
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
success(message, opts = {}) {
|
|
64
|
+
return this.show(message, { ...opts, variant: 'success' });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
error(message, opts = {}) {
|
|
68
|
+
return this.show(message, { ...opts, variant: 'danger' });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
warning(message, opts = {}) {
|
|
72
|
+
return this.show(message, { ...opts, variant: 'warning' });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
info(message, opts = {}) {
|
|
76
|
+
return this.show(message, { ...opts, variant: 'info' });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
loading(message, opts = {}) {
|
|
80
|
+
return this.show(message, { ...opts, variant: 'loading', duration: 0 });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
promise(prom, { loading = 'Loading...', success = 'Success', error = 'Error' } = {}) {
|
|
84
|
+
const id = this.loading(
|
|
85
|
+
typeof loading === 'string' ? loading : loading.message || 'Loading...',
|
|
86
|
+
typeof loading === 'object' ? loading : {}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return prom
|
|
90
|
+
.then((data) => {
|
|
91
|
+
const successVal = typeof success === 'function' ? success(data) : success;
|
|
92
|
+
const msg = typeof successVal === 'string' ? successVal : successVal.message || 'Success';
|
|
93
|
+
const desc = typeof successVal === 'object' ? successVal.description : '';
|
|
94
|
+
this.update(id, {
|
|
95
|
+
message: msg,
|
|
96
|
+
description: desc,
|
|
97
|
+
variant: 'success',
|
|
98
|
+
duration: 3500
|
|
99
|
+
});
|
|
100
|
+
return data;
|
|
101
|
+
})
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
const errorVal = typeof error === 'function' ? error(err) : error;
|
|
104
|
+
const msg = typeof errorVal === 'string' ? errorVal : errorVal.message || 'Error occurred';
|
|
105
|
+
const desc = typeof errorVal === 'object' ? errorVal.description : '';
|
|
106
|
+
this.update(id, {
|
|
107
|
+
message: msg,
|
|
108
|
+
description: desc,
|
|
109
|
+
variant: 'danger',
|
|
110
|
+
duration: 4000
|
|
111
|
+
});
|
|
112
|
+
throw err;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
dismiss(id) {
|
|
117
|
+
if (id === undefined) {
|
|
118
|
+
this.toasts.value.forEach(t => { if (t._timer) clearTimeout(t._timer); });
|
|
119
|
+
this.toasts.value = [];
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const t = this.toasts.value.find(item => item.id === id);
|
|
123
|
+
if (t && t._timer) clearTimeout(t._timer);
|
|
124
|
+
this.toasts.value = this.toasts.value.filter((item) => item.id !== id);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function createToastCallable() {
|
|
129
|
+
const manager = new ToastManager();
|
|
130
|
+
const fn = function (msgOrOpts, opts) {
|
|
131
|
+
return manager.show(msgOrOpts, opts);
|
|
132
|
+
};
|
|
133
|
+
Object.setPrototypeOf(fn, ToastManager.prototype);
|
|
134
|
+
fn.toasts = manager.toasts;
|
|
135
|
+
fn.show = manager.show.bind(manager);
|
|
136
|
+
fn.update = manager.update.bind(manager);
|
|
137
|
+
fn.success = manager.success.bind(manager);
|
|
138
|
+
fn.error = manager.error.bind(manager);
|
|
139
|
+
fn.warning = manager.warning.bind(manager);
|
|
140
|
+
fn.info = manager.info.bind(manager);
|
|
141
|
+
fn.loading = manager.loading.bind(manager);
|
|
142
|
+
fn.promise = manager.promise.bind(manager);
|
|
143
|
+
fn.dismiss = manager.dismiss.bind(manager);
|
|
144
|
+
return fn;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const toast = createToastCallable();
|
|
148
|
+
if (typeof window !== 'undefined' && !window.toast) {
|
|
149
|
+
window.toast = toast;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class ElToaster extends Elementum {
|
|
153
|
+
static get observedAttributes() {
|
|
154
|
+
return ['position', 'expand'];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
#cards = new Map(); // id -> { el, item, exiting: bool, height: number }
|
|
158
|
+
#isHovered = false;
|
|
159
|
+
#cleanupEffect = null;
|
|
160
|
+
|
|
161
|
+
static styles = css`
|
|
162
|
+
:host {
|
|
163
|
+
position: fixed;
|
|
164
|
+
z-index: 9999;
|
|
165
|
+
pointer-events: none;
|
|
166
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
167
|
+
box-sizing: border-box;
|
|
168
|
+
max-width: 100%;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
:host([position="bottom-right"]),
|
|
172
|
+
:host(:not([position])) {
|
|
173
|
+
bottom: 24px;
|
|
174
|
+
right: 24px;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
:host([position="bottom-left"]) {
|
|
178
|
+
bottom: 24px;
|
|
179
|
+
left: 24px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
:host([position="top-right"]) {
|
|
183
|
+
top: 24px;
|
|
184
|
+
right: 24px;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
:host([position="top-left"]) {
|
|
188
|
+
top: 24px;
|
|
189
|
+
left: 24px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
:host([position="bottom-center"]) {
|
|
193
|
+
bottom: 24px;
|
|
194
|
+
left: 50%;
|
|
195
|
+
transform: translateX(-50%);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
:host([position="top-center"]) {
|
|
199
|
+
top: 24px;
|
|
200
|
+
left: 50%;
|
|
201
|
+
transform: translateX(-50%);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.toaster-viewport {
|
|
205
|
+
position: relative;
|
|
206
|
+
display: flex;
|
|
207
|
+
flex-direction: column;
|
|
208
|
+
min-width: 340px;
|
|
209
|
+
max-width: 420px;
|
|
210
|
+
width: 100%;
|
|
211
|
+
pointer-events: auto;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.toast-list {
|
|
215
|
+
position: relative;
|
|
216
|
+
width: 100%;
|
|
217
|
+
min-height: 64px;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.toast-card {
|
|
221
|
+
pointer-events: auto;
|
|
222
|
+
position: absolute;
|
|
223
|
+
bottom: 0;
|
|
224
|
+
right: 0;
|
|
225
|
+
width: 100%;
|
|
226
|
+
box-sizing: border-box;
|
|
227
|
+
display: flex;
|
|
228
|
+
align-items: flex-start;
|
|
229
|
+
gap: 12px;
|
|
230
|
+
padding: 14px 16px;
|
|
231
|
+
background: var(--el-surface-elevated, #ffffff);
|
|
232
|
+
color: var(--el-text-primary, #0f172a);
|
|
233
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
234
|
+
border-radius: var(--el-radius-lg, 12px);
|
|
235
|
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
|
|
236
|
+
cursor: grab;
|
|
237
|
+
touch-action: pan-y;
|
|
238
|
+
user-select: none;
|
|
239
|
+
transform-origin: bottom center;
|
|
240
|
+
transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
|
|
241
|
+
opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
|
|
242
|
+
box-shadow 0.25s ease;
|
|
243
|
+
will-change: transform, opacity;
|
|
244
|
+
animation: toastSlideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.toast-card:active {
|
|
248
|
+
cursor: grabbing;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
:host([position^="top"]) .toast-card {
|
|
252
|
+
bottom: auto;
|
|
253
|
+
top: 0;
|
|
254
|
+
transform-origin: top center;
|
|
255
|
+
animation-name: toastSlideDown;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
:host([position*="left"]) .toast-card {
|
|
259
|
+
right: auto;
|
|
260
|
+
left: 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
:host([position*="center"]) .toast-card {
|
|
264
|
+
right: auto;
|
|
265
|
+
left: 50%;
|
|
266
|
+
transform: translateX(-50%);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
:root[data-theme="dark"] .toast-card {
|
|
270
|
+
background: #1e293b;
|
|
271
|
+
border-color: #334155;
|
|
272
|
+
color: #f8fafc;
|
|
273
|
+
box-shadow: 0 14px 35px -4px rgba(0, 0, 0, 0.55), 0 4px 10px -2px rgba(0, 0, 0, 0.4);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@keyframes toastSlideUp {
|
|
277
|
+
from {
|
|
278
|
+
opacity: 0;
|
|
279
|
+
transform: translate3d(0, 24px, 0) scale(0.92);
|
|
280
|
+
}
|
|
281
|
+
to {
|
|
282
|
+
opacity: 1;
|
|
283
|
+
transform: translate3d(0, 0, 0) scale(1);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@keyframes toastSlideDown {
|
|
288
|
+
from {
|
|
289
|
+
opacity: 0;
|
|
290
|
+
transform: translate3d(0, -24px, 0) scale(0.92);
|
|
291
|
+
}
|
|
292
|
+
to {
|
|
293
|
+
opacity: 1;
|
|
294
|
+
transform: translate3d(0, 0, 0) scale(1);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.toast-card.is-exiting {
|
|
299
|
+
animation: none !important;
|
|
300
|
+
transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease !important;
|
|
301
|
+
opacity: 0 !important;
|
|
302
|
+
transform: translate3d(0, 16px, 0) scale(0.92) !important;
|
|
303
|
+
pointer-events: none !important;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
:host([position^="top"]) .toast-card.is-exiting {
|
|
307
|
+
transform: translate3d(0, -16px, 0) scale(0.92) !important;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.toast-icon {
|
|
311
|
+
flex-shrink: 0;
|
|
312
|
+
width: 20px;
|
|
313
|
+
height: 20px;
|
|
314
|
+
display: inline-flex;
|
|
315
|
+
align-items: center;
|
|
316
|
+
justify-content: center;
|
|
317
|
+
margin-top: 1px;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.toast-icon.loading {
|
|
321
|
+
color: var(--el-color-primary, #2563eb);
|
|
322
|
+
animation: toastSpin 0.9s linear infinite;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@keyframes toastSpin {
|
|
326
|
+
100% { transform: rotate(360deg); }
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.toast-icon.success {
|
|
330
|
+
color: var(--el-color-success, #16a34a);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.toast-icon.danger {
|
|
334
|
+
color: var(--el-color-danger, #dc2626);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.toast-icon.warning {
|
|
338
|
+
color: #d97706;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.toast-icon.info {
|
|
342
|
+
color: var(--el-color-primary, #2563eb);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.toast-body {
|
|
346
|
+
flex: 1;
|
|
347
|
+
min-width: 0;
|
|
348
|
+
display: flex;
|
|
349
|
+
flex-direction: column;
|
|
350
|
+
gap: 3px;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.toast-title {
|
|
354
|
+
font-size: 0.875rem;
|
|
355
|
+
font-weight: 600;
|
|
356
|
+
line-height: 1.35;
|
|
357
|
+
color: inherit;
|
|
358
|
+
word-break: break-word;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.toast-desc {
|
|
362
|
+
font-size: 0.8125rem;
|
|
363
|
+
color: var(--el-text-muted, #64748b);
|
|
364
|
+
line-height: 1.35;
|
|
365
|
+
word-break: break-word;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
:root[data-theme="dark"] .toast-desc {
|
|
369
|
+
color: #94a3b8;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
.toast-actions {
|
|
373
|
+
display: flex;
|
|
374
|
+
align-items: center;
|
|
375
|
+
gap: 8px;
|
|
376
|
+
margin-top: 8px;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.toast-btn {
|
|
380
|
+
font-family: inherit;
|
|
381
|
+
font-size: 0.75rem;
|
|
382
|
+
font-weight: 600;
|
|
383
|
+
padding: 5px 12px;
|
|
384
|
+
border-radius: var(--el-radius-md, 6px);
|
|
385
|
+
cursor: pointer;
|
|
386
|
+
outline: none;
|
|
387
|
+
transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
|
|
388
|
+
border: 1px solid transparent;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.toast-btn.action {
|
|
392
|
+
background: var(--el-color-primary, #2563eb);
|
|
393
|
+
color: #ffffff;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.toast-btn.action:hover {
|
|
397
|
+
background: var(--el-color-primary-hover, #1d4ed8);
|
|
398
|
+
transform: translateY(-1px);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.toast-btn.cancel {
|
|
402
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
403
|
+
color: var(--el-text-primary, #0f172a);
|
|
404
|
+
border-color: var(--el-surface-border, #e2e8f0);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
:root[data-theme="dark"] .toast-btn.cancel {
|
|
408
|
+
background: #334155;
|
|
409
|
+
color: #f8fafc;
|
|
410
|
+
border-color: #475569;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.toast-close {
|
|
414
|
+
flex-shrink: 0;
|
|
415
|
+
background: none;
|
|
416
|
+
border: none;
|
|
417
|
+
color: var(--el-text-muted, #94a3b8);
|
|
418
|
+
font-size: 1rem;
|
|
419
|
+
cursor: pointer;
|
|
420
|
+
line-height: 1;
|
|
421
|
+
padding: 4px;
|
|
422
|
+
border-radius: 4px;
|
|
423
|
+
margin-left: 2px;
|
|
424
|
+
transition: color 0.15s ease, background 0.15s ease;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.toast-close:hover {
|
|
428
|
+
color: var(--el-text-primary, #0f172a);
|
|
429
|
+
background: var(--el-surface-muted, rgba(0, 0, 0, 0.05));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
:root[data-theme="dark"] .toast-close:hover {
|
|
433
|
+
color: #f8fafc;
|
|
434
|
+
background: rgba(255, 255, 255, 0.1);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
@media (prefers-reduced-motion: reduce) {
|
|
438
|
+
*, *::before, *::after {
|
|
439
|
+
animation: none !important;
|
|
440
|
+
transition: none !important;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
`;
|
|
444
|
+
|
|
445
|
+
connected() {
|
|
446
|
+
this.shadowRoot.innerHTML = `
|
|
447
|
+
<style>${ElToaster.styles.cssText}</style>
|
|
448
|
+
<div class="toaster-viewport" role="region" aria-label="Notifications">
|
|
449
|
+
<div class="toast-list"></div>
|
|
450
|
+
</div>
|
|
451
|
+
`;
|
|
452
|
+
|
|
453
|
+
const viewport = this.shadowRoot.querySelector('.toaster-viewport');
|
|
454
|
+
viewport.addEventListener('mouseenter', this.#onMouseEnter);
|
|
455
|
+
viewport.addEventListener('mouseleave', this.#onMouseLeave);
|
|
456
|
+
|
|
457
|
+
this.#cleanupEffect = effect(() => {
|
|
458
|
+
const items = toast.toasts.value;
|
|
459
|
+
this.#syncToasts(items);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
disconnected() {
|
|
464
|
+
if (this.#cleanupEffect) {
|
|
465
|
+
this.#cleanupEffect();
|
|
466
|
+
this.#cleanupEffect = null;
|
|
467
|
+
}
|
|
468
|
+
const viewport = this.shadowRoot.querySelector('.toaster-viewport');
|
|
469
|
+
if (viewport) {
|
|
470
|
+
viewport.removeEventListener('mouseenter', this.#onMouseEnter);
|
|
471
|
+
viewport.removeEventListener('mouseleave', this.#onMouseLeave);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
#onMouseEnter = () => {
|
|
476
|
+
this.#isHovered = true;
|
|
477
|
+
this.#updateLayout();
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
#onMouseLeave = () => {
|
|
481
|
+
this.#isHovered = false;
|
|
482
|
+
this.#updateLayout();
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
#getIconSvg(variant) {
|
|
486
|
+
if (variant === 'loading') {
|
|
487
|
+
return `
|
|
488
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
489
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
|
|
490
|
+
</svg>
|
|
491
|
+
`;
|
|
492
|
+
}
|
|
493
|
+
if (variant === 'success') {
|
|
494
|
+
return `
|
|
495
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
496
|
+
<path d="M20 6 9 17l-5-5"/>
|
|
497
|
+
</svg>
|
|
498
|
+
`;
|
|
499
|
+
}
|
|
500
|
+
if (variant === 'danger') {
|
|
501
|
+
return `
|
|
502
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
503
|
+
<circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/>
|
|
504
|
+
</svg>
|
|
505
|
+
`;
|
|
506
|
+
}
|
|
507
|
+
if (variant === 'warning') {
|
|
508
|
+
return `
|
|
509
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
510
|
+
<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/>
|
|
511
|
+
</svg>
|
|
512
|
+
`;
|
|
513
|
+
}
|
|
514
|
+
return `
|
|
515
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
516
|
+
<circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/>
|
|
517
|
+
</svg>
|
|
518
|
+
`;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
#createCardElement(item) {
|
|
522
|
+
const card = document.createElement('div');
|
|
523
|
+
card.className = `toast-card ${item.variant}`;
|
|
524
|
+
card.setAttribute('role', 'status');
|
|
525
|
+
card.setAttribute('aria-live', 'polite');
|
|
526
|
+
card.setAttribute('data-toast-id', String(item.id));
|
|
527
|
+
|
|
528
|
+
card.innerHTML = `
|
|
529
|
+
<span class="toast-icon ${item.variant}" aria-hidden="true">
|
|
530
|
+
${this.#getIconSvg(item.variant)}
|
|
531
|
+
</span>
|
|
532
|
+
<div class="toast-body">
|
|
533
|
+
<div class="toast-title"></div>
|
|
534
|
+
<div class="toast-desc" style="display: none;"></div>
|
|
535
|
+
<div class="toast-actions" style="display: none;"></div>
|
|
536
|
+
</div>
|
|
537
|
+
<button type="button" class="toast-close" aria-label="Dismiss notification" style="display: none;">✕</button>
|
|
538
|
+
`;
|
|
539
|
+
|
|
540
|
+
this.#updateCardContent(card, item);
|
|
541
|
+
this.#setupGesture(card, item.id);
|
|
542
|
+
return card;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
#updateCardContent(card, item) {
|
|
546
|
+
// Update classes
|
|
547
|
+
card.className = `toast-card ${item.variant}`;
|
|
548
|
+
|
|
549
|
+
// Update icon
|
|
550
|
+
const iconEl = card.querySelector('.toast-icon');
|
|
551
|
+
if (iconEl) {
|
|
552
|
+
iconEl.className = `toast-icon ${item.variant}`;
|
|
553
|
+
iconEl.innerHTML = this.#getIconSvg(item.variant);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Update title
|
|
557
|
+
const titleEl = card.querySelector('.toast-title');
|
|
558
|
+
if (titleEl) {
|
|
559
|
+
titleEl.textContent = item.message;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// Update description
|
|
563
|
+
const descEl = card.querySelector('.toast-desc');
|
|
564
|
+
if (descEl) {
|
|
565
|
+
if (item.description) {
|
|
566
|
+
descEl.textContent = item.description;
|
|
567
|
+
descEl.style.display = 'block';
|
|
568
|
+
} else {
|
|
569
|
+
descEl.textContent = '';
|
|
570
|
+
descEl.style.display = 'none';
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Update actions
|
|
575
|
+
const actionsEl = card.querySelector('.toast-actions');
|
|
576
|
+
if (actionsEl) {
|
|
577
|
+
actionsEl.innerHTML = '';
|
|
578
|
+
if (item.action || item.cancel) {
|
|
579
|
+
actionsEl.style.display = 'flex';
|
|
580
|
+
if (item.action) {
|
|
581
|
+
const btn = document.createElement('button');
|
|
582
|
+
btn.type = 'button';
|
|
583
|
+
btn.className = 'toast-btn action';
|
|
584
|
+
btn.textContent = item.action.label || 'Action';
|
|
585
|
+
btn.addEventListener('click', (e) => {
|
|
586
|
+
e.stopPropagation();
|
|
587
|
+
if (typeof item.action.onClick === 'function') item.action.onClick(item);
|
|
588
|
+
toast.dismiss(item.id);
|
|
589
|
+
});
|
|
590
|
+
actionsEl.appendChild(btn);
|
|
591
|
+
}
|
|
592
|
+
if (item.cancel) {
|
|
593
|
+
const btn = document.createElement('button');
|
|
594
|
+
btn.type = 'button';
|
|
595
|
+
btn.className = 'toast-btn cancel';
|
|
596
|
+
btn.textContent = item.cancel.label || 'Cancel';
|
|
597
|
+
btn.addEventListener('click', (e) => {
|
|
598
|
+
e.stopPropagation();
|
|
599
|
+
if (typeof item.cancel.onClick === 'function') item.cancel.onClick(item);
|
|
600
|
+
toast.dismiss(item.id);
|
|
601
|
+
});
|
|
602
|
+
actionsEl.appendChild(btn);
|
|
603
|
+
}
|
|
604
|
+
} else {
|
|
605
|
+
actionsEl.style.display = 'none';
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Update close button
|
|
610
|
+
const closeEl = card.querySelector('.toast-close');
|
|
611
|
+
if (closeEl) {
|
|
612
|
+
if (item.dismissible) {
|
|
613
|
+
closeEl.style.display = 'inline-flex';
|
|
614
|
+
closeEl.onclick = (e) => {
|
|
615
|
+
e.stopPropagation();
|
|
616
|
+
toast.dismiss(item.id);
|
|
617
|
+
};
|
|
618
|
+
} else {
|
|
619
|
+
closeEl.style.display = 'none';
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
#setupGesture(cardEl, id) {
|
|
625
|
+
let startX = 0;
|
|
626
|
+
let currentX = 0;
|
|
627
|
+
let isDragging = false;
|
|
628
|
+
|
|
629
|
+
const onPointerDown = (e) => {
|
|
630
|
+
if (e.target.closest('button')) return;
|
|
631
|
+
startX = e.clientX;
|
|
632
|
+
currentX = 0;
|
|
633
|
+
isDragging = true;
|
|
634
|
+
cardEl.style.transition = 'none';
|
|
635
|
+
if (cardEl.setPointerCapture) cardEl.setPointerCapture(e.pointerId);
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
const onPointerMove = (e) => {
|
|
639
|
+
if (!isDragging) return;
|
|
640
|
+
currentX = e.clientX - startX;
|
|
641
|
+
cardEl.style.transform = `translate3d(${currentX}px, 0, 0)`;
|
|
642
|
+
cardEl.style.opacity = `${Math.max(0.2, 1 - Math.abs(currentX) / 180)}`;
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const onPointerUp = (e) => {
|
|
646
|
+
if (!isDragging) return;
|
|
647
|
+
isDragging = false;
|
|
648
|
+
cardEl.style.transition = 'transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease';
|
|
649
|
+
|
|
650
|
+
if (Math.abs(currentX) > 75) {
|
|
651
|
+
const flyDir = currentX > 0 ? 350 : -350;
|
|
652
|
+
cardEl.style.transform = `translate3d(${flyDir}px, 0, 0)`;
|
|
653
|
+
cardEl.style.opacity = '0';
|
|
654
|
+
setTimeout(() => toast.dismiss(id), 180);
|
|
655
|
+
} else {
|
|
656
|
+
this.#updateLayout();
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
cardEl.addEventListener('pointerdown', onPointerDown);
|
|
661
|
+
cardEl.addEventListener('pointermove', onPointerMove);
|
|
662
|
+
cardEl.addEventListener('pointerup', onPointerUp);
|
|
663
|
+
cardEl.addEventListener('pointercancel', onPointerUp);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
#syncToasts(items) {
|
|
667
|
+
const listEl = this.shadowRoot.querySelector('.toast-list');
|
|
668
|
+
if (!listEl) return;
|
|
669
|
+
|
|
670
|
+
const currentIds = new Set(items.map(t => t.id));
|
|
671
|
+
|
|
672
|
+
// 1. Remove or start exit animation for items not in current list
|
|
673
|
+
for (const [id, record] of this.#cards.entries()) {
|
|
674
|
+
if (!currentIds.has(id) && !record.exiting) {
|
|
675
|
+
record.exiting = true;
|
|
676
|
+
record.el.classList.add('is-exiting');
|
|
677
|
+
setTimeout(() => {
|
|
678
|
+
if (record.el.parentNode === listEl) {
|
|
679
|
+
listEl.removeChild(record.el);
|
|
680
|
+
}
|
|
681
|
+
this.#cards.delete(id);
|
|
682
|
+
this.#updateLayout();
|
|
683
|
+
}, 220);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// 2. Add or update items
|
|
688
|
+
for (let i = 0; i < items.length; i++) {
|
|
689
|
+
const item = items[i];
|
|
690
|
+
let record = this.#cards.get(item.id);
|
|
691
|
+
|
|
692
|
+
if (!record) {
|
|
693
|
+
const cardEl = this.#createCardElement(item);
|
|
694
|
+
listEl.appendChild(cardEl);
|
|
695
|
+
record = { el: cardEl, item, exiting: false, height: 60 };
|
|
696
|
+
this.#cards.set(item.id, record);
|
|
697
|
+
|
|
698
|
+
const raf = typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame : (fn) => setTimeout(fn, 16);
|
|
699
|
+
raf(() => {
|
|
700
|
+
if (cardEl.offsetHeight) record.height = cardEl.offsetHeight;
|
|
701
|
+
this.#updateLayout();
|
|
702
|
+
});
|
|
703
|
+
} else {
|
|
704
|
+
this.#updateCardContent(record.el, item);
|
|
705
|
+
record.item = item;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
this.#updateLayout();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
#updateLayout() {
|
|
713
|
+
const activeRecords = [];
|
|
714
|
+
const isTop = (this.getAttribute('position') || '').startsWith('top');
|
|
715
|
+
const isHovered = this.#isHovered;
|
|
716
|
+
|
|
717
|
+
for (const item of toast.toasts.value) {
|
|
718
|
+
const rec = this.#cards.get(item.id);
|
|
719
|
+
if (rec && !rec.exiting) {
|
|
720
|
+
activeRecords.push(rec);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const total = activeRecords.length;
|
|
725
|
+
let accumulatedOffset = 0;
|
|
726
|
+
const gap = 12;
|
|
727
|
+
|
|
728
|
+
for (let i = 0; i < total; i++) {
|
|
729
|
+
const rec = activeRecords[i];
|
|
730
|
+
const stackIndex = total - 1 - i; // 0 is newest / front card
|
|
731
|
+
const cardEl = rec.el;
|
|
732
|
+
|
|
733
|
+
if (isHovered) {
|
|
734
|
+
const yOffset = isTop ? accumulatedOffset : -accumulatedOffset;
|
|
735
|
+
cardEl.style.transform = `translate3d(0, ${yOffset}px, 0) scale(1)`;
|
|
736
|
+
cardEl.style.zIndex = `${30 - stackIndex}`;
|
|
737
|
+
cardEl.style.opacity = '1';
|
|
738
|
+
cardEl.style.pointerEvents = 'auto';
|
|
739
|
+
|
|
740
|
+
const h = rec.height || cardEl.offsetHeight || 60;
|
|
741
|
+
accumulatedOffset += h + gap;
|
|
742
|
+
} else {
|
|
743
|
+
if (stackIndex === 0) {
|
|
744
|
+
cardEl.style.transform = 'translate3d(0, 0, 0) scale(1)';
|
|
745
|
+
cardEl.style.zIndex = '20';
|
|
746
|
+
cardEl.style.opacity = '1';
|
|
747
|
+
cardEl.style.pointerEvents = 'auto';
|
|
748
|
+
} else if (stackIndex === 1) {
|
|
749
|
+
const dir = isTop ? 14 : -14;
|
|
750
|
+
cardEl.style.transform = `translate3d(0, ${dir}px, 0) scale(0.95)`;
|
|
751
|
+
cardEl.style.zIndex = '19';
|
|
752
|
+
cardEl.style.opacity = '0.92';
|
|
753
|
+
cardEl.style.pointerEvents = 'auto';
|
|
754
|
+
} else if (stackIndex === 2) {
|
|
755
|
+
const dir = isTop ? 28 : -28;
|
|
756
|
+
cardEl.style.transform = `translate3d(0, ${dir}px, 0) scale(0.90)`;
|
|
757
|
+
cardEl.style.zIndex = '18';
|
|
758
|
+
cardEl.style.opacity = '0.78';
|
|
759
|
+
cardEl.style.pointerEvents = 'auto';
|
|
760
|
+
} else {
|
|
761
|
+
const dir = isTop ? 42 : -42;
|
|
762
|
+
cardEl.style.transform = `translate3d(0, ${dir}px, 0) scale(0.85)`;
|
|
763
|
+
cardEl.style.zIndex = '15';
|
|
764
|
+
cardEl.style.opacity = '0';
|
|
765
|
+
cardEl.style.pointerEvents = 'none';
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
render() {
|
|
772
|
+
return '';
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-toaster')) {
|
|
777
|
+
customElements.define('el-toaster', ElToaster);
|
|
778
|
+
}
|