robot-toast 2.0.0-beta.2 → 2.0.0-beta.3
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/README.md +30 -4
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +128 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/MIGRATION.md +0 -192
package/README.md
CHANGED
|
@@ -39,7 +39,8 @@ A lightweight, zero-dependency, framework-agnostic toast notification library fe
|
|
|
39
39
|
|
|
40
40
|
- **36% smaller core bundle** (61 KB → 39 KB). Robots moved to a tree-shakeable subpath — only the ones you import end up in your bundle.
|
|
41
41
|
- **Opt-in robots.** Omitting `robotVariant` renders *no robot* now. Pass `'default'` or import from `robot-toast/robots` to bring one back.
|
|
42
|
-
- **
|
|
42
|
+
- **Action buttons.** Pass `action` / `cancel` for Undo, Confirm/Cancel, and similar inline CTAs.
|
|
43
|
+
- **Native-feel mobile layout.** On viewports ≤ 600 px the toast stretches edge-to-edge with a 16 px gutter, matching how iOS/Android system toasts behave. Drag is suppressed there since it would fight the layout.
|
|
43
44
|
- **`toast.promise()`** — attach loading/success/error toasts to any promise.
|
|
44
45
|
- **React subpath.** `useRobotToast()` + `useToastOnMount()` as optional ergonomic bindings.
|
|
45
46
|
- **ARIA roles.** `role="alert"` for `error`/`warning`, `role="status"` elsewhere, plus `aria-atomic` and a labeled close button.
|
|
@@ -117,6 +118,27 @@ Prefer the built-in inline SVG with no extra import?
|
|
|
117
118
|
toast({ message: 'Hello', robotVariant: 'default' });
|
|
118
119
|
```
|
|
119
120
|
|
|
121
|
+
## Action buttons
|
|
122
|
+
|
|
123
|
+
Add an inline button for patterns like "Undo" or "Confirm / Cancel":
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// Undo pattern — single primary action
|
|
127
|
+
toast({
|
|
128
|
+
message: 'File deleted',
|
|
129
|
+
action: { label: 'Undo', onClick: () => restoreFile() },
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Confirm + cancel
|
|
133
|
+
toast({
|
|
134
|
+
message: 'Discard changes?',
|
|
135
|
+
action: { label: 'Discard', onClick: () => discardChanges() },
|
|
136
|
+
cancel: { label: 'Keep', onClick: () => {} },
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Clicking either button fires its `onClick` and then dismisses the toast automatically. `cancel` renders as a muted outline button on the left; `action` is the primary CTA on the right. A callback that throws is logged and the toast still closes, so a bad handler can't strand the toast on screen.
|
|
141
|
+
|
|
120
142
|
## Promise lifecycle
|
|
121
143
|
|
|
122
144
|
```ts
|
|
@@ -251,6 +273,8 @@ toast.success({ message: 'Deployed!', theme: 'colored', position: 'top-center',
|
|
|
251
273
|
| `rtl` | `boolean` | `false` | Right-to-left layout |
|
|
252
274
|
| `limit` | `number` | `0` | Max toasts visible at once. `0` = unlimited. Excess is queued |
|
|
253
275
|
| `newestOnTop` | `boolean` | `false` | Stack newest toasts above older ones |
|
|
276
|
+
| `action` | `{ label: string; onClick: (e: MouseEvent) => void }` | — | Primary inline button (e.g. "Undo"). Fires `onClick` then closes the toast. |
|
|
277
|
+
| `cancel` | `{ label: string; onClick: (e: MouseEvent) => void }` | — | Secondary inline button (e.g. "Cancel"). Fires `onClick` then closes the toast. |
|
|
254
278
|
| `onOpen` | `() => void` | — | Callback fired when the toast finishes its entrance |
|
|
255
279
|
| `onClose` | `() => void` | — | Callback fired after the toast fully exits |
|
|
256
280
|
|
|
@@ -331,13 +355,15 @@ toast({ message: 'Slide!', transition: 'slide' });
|
|
|
331
355
|
|
|
332
356
|
---
|
|
333
357
|
|
|
334
|
-
## Drag
|
|
358
|
+
## Drag & responsive layout
|
|
335
359
|
|
|
336
360
|
When `draggable` is on (default):
|
|
337
361
|
|
|
338
362
|
- **Drag anywhere** on the toast to move it. On release it snaps to the nearest horizontal edge — including when you drag all the way across the screen.
|
|
339
|
-
-
|
|
340
|
-
- Use the **close button** or `toast.closeById()` / `toast.closeAll()` to dismiss programmatically.
|
|
363
|
+
- `touch-action: none` prevents the browser from fighting the drag, and rect dimensions are cached on pointerdown to eliminate layout-thrash jank on low-end devices.
|
|
364
|
+
- Use the **close button**, an **action button**, or `toast.closeById()` / `toast.closeAll()` to dismiss programmatically.
|
|
365
|
+
|
|
366
|
+
**On viewports ≤ 600 px** the toast automatically lays out edge-to-edge with a 16 px gutter (matching native mobile toast UX). All six position presets collapse to "pinned to top" or "pinned to bottom" accordingly. Drag is suppressed below this breakpoint since it would fight the full-width layout.
|
|
341
367
|
|
|
342
368
|
---
|
|
343
369
|
|
package/dist/index.d.mts
CHANGED
|
@@ -18,6 +18,23 @@ type ToastType = typeof TOAST_TYPES[number];
|
|
|
18
18
|
type ToastTheme = typeof TOAST_THEMES[number];
|
|
19
19
|
/** Type derived from TOAST_TRANSITIONS constant */
|
|
20
20
|
type TransitionType = typeof TOAST_TRANSITIONS[number];
|
|
21
|
+
/**
|
|
22
|
+
* A button rendered inside the toast. Typical use is the "Undo" pattern:
|
|
23
|
+
*
|
|
24
|
+
* toast({
|
|
25
|
+
* message: 'File deleted',
|
|
26
|
+
* action: { label: 'Undo', onClick: () => restore() },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* Clicking the button fires `onClick` and then closes the toast. Pass `cancel`
|
|
30
|
+
* alongside `action` to render a secondary dismiss-style button.
|
|
31
|
+
*/
|
|
32
|
+
interface ToastAction {
|
|
33
|
+
/** Visible button text. Keep it short (1–2 words). */
|
|
34
|
+
label: string;
|
|
35
|
+
/** Fired before the toast closes. Receives the click event. */
|
|
36
|
+
onClick: (event: MouseEvent) => void;
|
|
37
|
+
}
|
|
21
38
|
interface RobotToastOptions {
|
|
22
39
|
/** The message text to display in the toast */
|
|
23
40
|
message: string;
|
|
@@ -78,6 +95,16 @@ interface RobotToastOptions {
|
|
|
78
95
|
rtl?: boolean;
|
|
79
96
|
/** Entry / exit transition style. Default: 'bounce' */
|
|
80
97
|
transition?: TransitionType;
|
|
98
|
+
/**
|
|
99
|
+
* Primary action button (e.g. "Undo"). Clicking fires `onClick` then closes
|
|
100
|
+
* the toast. Styled as the bold/CTA variant.
|
|
101
|
+
*/
|
|
102
|
+
action?: ToastAction;
|
|
103
|
+
/**
|
|
104
|
+
* Secondary dismiss-style button (e.g. "Cancel"). Clicking fires `onClick`
|
|
105
|
+
* then closes the toast. Rendered to the left of `action` when both exist.
|
|
106
|
+
*/
|
|
107
|
+
cancel?: ToastAction;
|
|
81
108
|
/** Called when the toast finishes its enter animation and is fully visible. */
|
|
82
109
|
onOpen?: () => void;
|
|
83
110
|
/** Called after the toast has fully exited the screen. */
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,23 @@ type ToastType = typeof TOAST_TYPES[number];
|
|
|
18
18
|
type ToastTheme = typeof TOAST_THEMES[number];
|
|
19
19
|
/** Type derived from TOAST_TRANSITIONS constant */
|
|
20
20
|
type TransitionType = typeof TOAST_TRANSITIONS[number];
|
|
21
|
+
/**
|
|
22
|
+
* A button rendered inside the toast. Typical use is the "Undo" pattern:
|
|
23
|
+
*
|
|
24
|
+
* toast({
|
|
25
|
+
* message: 'File deleted',
|
|
26
|
+
* action: { label: 'Undo', onClick: () => restore() },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* Clicking the button fires `onClick` and then closes the toast. Pass `cancel`
|
|
30
|
+
* alongside `action` to render a secondary dismiss-style button.
|
|
31
|
+
*/
|
|
32
|
+
interface ToastAction {
|
|
33
|
+
/** Visible button text. Keep it short (1–2 words). */
|
|
34
|
+
label: string;
|
|
35
|
+
/** Fired before the toast closes. Receives the click event. */
|
|
36
|
+
onClick: (event: MouseEvent) => void;
|
|
37
|
+
}
|
|
21
38
|
interface RobotToastOptions {
|
|
22
39
|
/** The message text to display in the toast */
|
|
23
40
|
message: string;
|
|
@@ -78,6 +95,16 @@ interface RobotToastOptions {
|
|
|
78
95
|
rtl?: boolean;
|
|
79
96
|
/** Entry / exit transition style. Default: 'bounce' */
|
|
80
97
|
transition?: TransitionType;
|
|
98
|
+
/**
|
|
99
|
+
* Primary action button (e.g. "Undo"). Clicking fires `onClick` then closes
|
|
100
|
+
* the toast. Styled as the bold/CTA variant.
|
|
101
|
+
*/
|
|
102
|
+
action?: ToastAction;
|
|
103
|
+
/**
|
|
104
|
+
* Secondary dismiss-style button (e.g. "Cancel"). Clicking fires `onClick`
|
|
105
|
+
* then closes the toast. Rendered to the left of `action` when both exist.
|
|
106
|
+
*/
|
|
107
|
+
cancel?: ToastAction;
|
|
81
108
|
/** Called when the toast finishes its enter animation and is fully visible. */
|
|
82
109
|
onOpen?: () => void;
|
|
83
110
|
/** Called after the toast has fully exited the screen. */
|
package/dist/index.js
CHANGED
|
@@ -289,6 +289,88 @@
|
|
|
289
289
|
min-height: 1.5em;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
/* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
|
|
293
|
+
/* ACTION BUTTONS \u2014 Undo / Confirm / Cancel */
|
|
294
|
+
/* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
|
|
295
|
+
|
|
296
|
+
.robot-toast-actions {
|
|
297
|
+
display: flex;
|
|
298
|
+
gap: 8px;
|
|
299
|
+
justify-content: flex-end;
|
|
300
|
+
align-items: center;
|
|
301
|
+
margin-top: 10px;
|
|
302
|
+
padding-bottom: 10px;
|
|
303
|
+
flex-wrap: wrap;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.robot-toast-action,
|
|
307
|
+
.robot-toast-cancel {
|
|
308
|
+
appearance: none;
|
|
309
|
+
font: inherit;
|
|
310
|
+
font-size: 13px;
|
|
311
|
+
font-weight: 600;
|
|
312
|
+
line-height: 1;
|
|
313
|
+
padding: 6px 12px;
|
|
314
|
+
border-radius: 6px;
|
|
315
|
+
cursor: pointer;
|
|
316
|
+
transition: background 0.15s ease, color 0.15s ease, transform 0.05s ease;
|
|
317
|
+
white-space: nowrap;
|
|
318
|
+
}
|
|
319
|
+
.robot-toast-action:active,
|
|
320
|
+
.robot-toast-cancel:active { transform: scale(0.97); }
|
|
321
|
+
|
|
322
|
+
/* Primary (action) \u2014 filled CTA */
|
|
323
|
+
.robot-toast-action {
|
|
324
|
+
background: #18181b;
|
|
325
|
+
color: #fafafa;
|
|
326
|
+
border: 1px solid #18181b;
|
|
327
|
+
}
|
|
328
|
+
.robot-toast-action:hover { background: #000; border-color: #000; }
|
|
329
|
+
|
|
330
|
+
/* Secondary (cancel) \u2014 outline */
|
|
331
|
+
.robot-toast-cancel {
|
|
332
|
+
background: transparent;
|
|
333
|
+
color: #52525b;
|
|
334
|
+
border: 1px solid #e4e4e7;
|
|
335
|
+
}
|
|
336
|
+
.robot-toast-cancel:hover { background: #f4f4f5; color: #18181b; }
|
|
337
|
+
|
|
338
|
+
/* Dark theme inversion */
|
|
339
|
+
.robot-toast-message.robot-toast-theme-dark .robot-toast-action {
|
|
340
|
+
background: #fafafa;
|
|
341
|
+
color: #18181b;
|
|
342
|
+
border-color: #fafafa;
|
|
343
|
+
}
|
|
344
|
+
.robot-toast-message.robot-toast-theme-dark .robot-toast-action:hover {
|
|
345
|
+
background: #e4e4e7;
|
|
346
|
+
border-color: #e4e4e7;
|
|
347
|
+
}
|
|
348
|
+
.robot-toast-message.robot-toast-theme-dark .robot-toast-cancel {
|
|
349
|
+
color: #a1a1aa;
|
|
350
|
+
border-color: #3f3f46;
|
|
351
|
+
}
|
|
352
|
+
.robot-toast-message.robot-toast-theme-dark .robot-toast-cancel:hover {
|
|
353
|
+
background: #27272a;
|
|
354
|
+
color: #fafafa;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* Colored theme \u2014 translucent whites keep contrast on any gradient */
|
|
358
|
+
.robot-toast-message.robot-toast-theme-colored .robot-toast-action {
|
|
359
|
+
background: rgba(255, 255, 255, 0.95);
|
|
360
|
+
color: #18181b;
|
|
361
|
+
border-color: transparent;
|
|
362
|
+
}
|
|
363
|
+
.robot-toast-message.robot-toast-theme-colored .robot-toast-action:hover {
|
|
364
|
+
background: #fff;
|
|
365
|
+
}
|
|
366
|
+
.robot-toast-message.robot-toast-theme-colored .robot-toast-cancel {
|
|
367
|
+
color: rgba(255, 255, 255, 0.92);
|
|
368
|
+
border-color: rgba(255, 255, 255, 0.42);
|
|
369
|
+
}
|
|
370
|
+
.robot-toast-message.robot-toast-theme-colored .robot-toast-cancel:hover {
|
|
371
|
+
background: rgba(255, 255, 255, 0.15);
|
|
372
|
+
}
|
|
373
|
+
|
|
292
374
|
/* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
|
|
293
375
|
/* PROGRESS BAR */
|
|
294
376
|
/* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
|
|
@@ -543,47 +625,53 @@
|
|
|
543
625
|
/* RESPONSIVE - Mobile / small-screen tweaks */
|
|
544
626
|
/* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
|
|
545
627
|
|
|
628
|
+
/*
|
|
629
|
+
* On phone-sized viewports the toast stretches edge-to-edge with a 16px
|
|
630
|
+
* gutter \u2014 matches Sonner / native mobile toast UX. All six position presets
|
|
631
|
+
* collapse to either "pinned to top" or "pinned to bottom"; left/right become
|
|
632
|
+
* meaningless when we're full-width. !important overrides inline drag
|
|
633
|
+
* transforms (drag is also disabled below this breakpoint in JS).
|
|
634
|
+
*/
|
|
546
635
|
@media (max-width: 600px) {
|
|
547
636
|
.robot-toast-wrapper {
|
|
548
|
-
gap:
|
|
549
|
-
|
|
637
|
+
gap: 10px;
|
|
638
|
+
left: 16px !important;
|
|
639
|
+
right: 16px !important;
|
|
640
|
+
width: auto !important;
|
|
641
|
+
max-width: none !important;
|
|
642
|
+
transform: none !important;
|
|
550
643
|
}
|
|
551
644
|
|
|
552
645
|
.robot-toast-wrapper.robot-toast-top-right,
|
|
553
|
-
.robot-toast-wrapper.robot-toast-bottom-right {
|
|
554
|
-
right: 12px;
|
|
555
|
-
}
|
|
556
646
|
.robot-toast-wrapper.robot-toast-top-left,
|
|
557
|
-
.robot-toast-wrapper.robot-toast-
|
|
558
|
-
|
|
647
|
+
.robot-toast-wrapper.robot-toast-top-center {
|
|
648
|
+
top: 16px !important;
|
|
649
|
+
bottom: auto !important;
|
|
559
650
|
}
|
|
560
|
-
.robot-toast-wrapper.robot-toast-top-right,
|
|
561
|
-
.robot-toast-wrapper.robot-toast-top-left,
|
|
562
|
-
.robot-toast-wrapper.robot-toast-top-center { top: 12px; }
|
|
563
651
|
.robot-toast-wrapper.robot-toast-bottom-right,
|
|
564
652
|
.robot-toast-wrapper.robot-toast-bottom-left,
|
|
565
|
-
.robot-toast-wrapper.robot-toast-bottom-center { bottom: 12px; }
|
|
566
|
-
|
|
567
|
-
.robot-toast-wrapper.robot-toast-top-center,
|
|
568
653
|
.robot-toast-wrapper.robot-toast-bottom-center {
|
|
569
|
-
|
|
570
|
-
|
|
654
|
+
bottom: 16px !important;
|
|
655
|
+
top: auto !important;
|
|
571
656
|
}
|
|
572
657
|
|
|
573
658
|
.robot-toast-robot {
|
|
574
659
|
width: 48px;
|
|
575
660
|
height: 52px;
|
|
661
|
+
flex-shrink: 0;
|
|
576
662
|
}
|
|
577
663
|
|
|
664
|
+
/* The message box expands to fill the remaining wrapper width */
|
|
578
665
|
.robot-toast-message {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
666
|
+
flex: 1 1 auto;
|
|
667
|
+
min-width: 0;
|
|
668
|
+
max-width: none;
|
|
669
|
+
font-size: 14px;
|
|
670
|
+
padding: 12px 36px 0 14px;
|
|
583
671
|
}
|
|
584
672
|
|
|
585
673
|
.robot-toast-text {
|
|
586
|
-
font-size:
|
|
674
|
+
font-size: 14px;
|
|
587
675
|
padding-bottom: 10px;
|
|
588
676
|
}
|
|
589
677
|
|
|
@@ -592,18 +680,31 @@
|
|
|
592
680
|
height: 24px;
|
|
593
681
|
font-size: 20px;
|
|
594
682
|
}
|
|
683
|
+
|
|
684
|
+
/* Actions get full horizontal space and larger tap targets */
|
|
685
|
+
.robot-toast-actions {
|
|
686
|
+
gap: 10px;
|
|
687
|
+
margin-top: 12px;
|
|
688
|
+
}
|
|
689
|
+
.robot-toast-action,
|
|
690
|
+
.robot-toast-cancel {
|
|
691
|
+
padding: 8px 14px;
|
|
692
|
+
font-size: 14px;
|
|
693
|
+
}
|
|
595
694
|
}
|
|
596
695
|
|
|
597
696
|
@media (max-width: 360px) {
|
|
598
|
-
.robot-toast-
|
|
599
|
-
|
|
600
|
-
|
|
697
|
+
.robot-toast-wrapper {
|
|
698
|
+
left: 12px !important;
|
|
699
|
+
right: 12px !important;
|
|
700
|
+
gap: 8px;
|
|
601
701
|
}
|
|
602
|
-
.robot-toast-
|
|
603
|
-
|
|
702
|
+
.robot-toast-robot {
|
|
703
|
+
width: 42px;
|
|
704
|
+
height: 46px;
|
|
604
705
|
}
|
|
605
706
|
}
|
|
606
|
-
`,e=document.createElement("style");e.id=t,e.textContent=o,document.head.appendChild(e);}};h.injected=false;var g=h,T=g;var R=1;function k(){return R++}var L=16,y=class{constructor(t,o,e){this.progressBar=null;this.timerStart=null;this.closeTimeout=null;this.isDragging=false;this.dragOffsetX=0;this.dragOffsetY=0;this.dragWidth=0;this.dragHeight=0;this.isHovered=false;this.isFocusLost=false;this.isClosed=false;this.cleanupFns=[];this.id=t,this.onRemove=e;let s={message:o.message,autoClose:o.autoClose??5e3,position:o.position??"bottom-right",type:o.type??"default",theme:o.theme??"light",style:o.style,typeSpeed:o.typeSpeed??30,robotVariant:o.robotVariant??"",hideProgressBar:o.hideProgressBar??false,pauseOnFocusLoss:o.pauseOnFocusLoss??true,draggable:o.draggable??true,nearScreen:o.nearScreen??true,pauseOnHover:o.pauseOnHover??true,rtl:o.rtl??false,transition:o.transition??"bounce",onOpen:o.onOpen,onClose:o.onClose};this.options=s;let r=s.position.includes("left"),i;s.nearScreen?i=r?"left":"right":i=r?"right":"left",this.currentRobotSide=i,this.autoCloseDuration=typeof s.autoClose=="number"?s.autoClose:s.autoClose?5e3:0,this.remainingTime=this.autoCloseDuration,this.wrapper=this.buildWrapper(),this.robotEl=this.buildRobot(),this.messageBox=this.buildMessageBox(),this.messageText=this.messageBox.querySelector(".robot-toast-text"),this.progressBar=this.messageBox.querySelector(".robot-toast-progress-bar"),s.message===""&&this.messageBox.classList.add("robot-toast-empty"),this.assembleLayout(),document.body.appendChild(this.wrapper),s.draggable&&this.initDrag(),s.pauseOnFocusLoss&&this.initFocusWatcher(),s.pauseOnHover&&this.initHoverWatcher(),requestAnimationFrame(()=>this.playEntrance());}close(){this.isClosed||(this.isClosed=true,this.cancelTimer(),this.cleanupFns.forEach(t=>t()),this.cleanupFns=[],this.playExit(()=>{this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.options.onClose?.(),this.onRemove(this.id);}));}shiftVertical(t){this.options.position.startsWith("bottom")?this.wrapper.style.bottom=`${t}px`:this.wrapper.style.top=`${t}px`;}getWrapperHeight(){return this.wrapper.getBoundingClientRect().height||90}buildWrapper(){let t=document.createElement("div"),o=["robot-toast-wrapper",`robot-toast-${this.options.position}`];this.options.rtl&&o.push("robot-toast-rtl"),t.className=o.join(" ");let e=this.options.type==="error"||this.options.type==="warning";return t.setAttribute("role",e?"alert":"status"),t.setAttribute("aria-live",e?"assertive":"polite"),t.setAttribute("aria-atomic","true"),t}resolveVariant(){let t=this.options.robotVariant;if(!t||t==="none")return "hidden";if(t==="default")return "default";let o=[".svg",".png",".jpg",".jpeg",".gif",".webp"];return t.startsWith("data:")||o.some(r=>t.toLowerCase().endsWith(r))?"image":"hidden"}buildRobot(){let t=document.createElement("div");t.className="robot-toast-robot";let o=this.resolveVariant();if(o==="hidden")return t.style.display="none",t;if(o==="default")return t.innerHTML=this.getBuiltinSVG(),t;let e=document.createElement("img");return e.src=this.options.robotVariant,e.alt="Robot",e.setAttribute("width","65"),e.setAttribute("height","70"),e.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",e.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(e),t}buildMessageBox(){let t=document.createElement("div"),o=["robot-toast-message",`robot-toast-type-${this.options.type}`,`robot-toast-theme-${this.options.theme}`].filter(Boolean);t.className=o.join(" "),t.style.cursor=this.options.draggable?"grab":"default",this.options.style&&Object.entries(this.options.style).forEach(([p,c])=>{let m=p.replace(/-([a-z])/g,b=>b[1].toUpperCase());t.style[m]=c;});let e=document.createElement("button");e.className="robot-toast-close",e.innerHTML="×",e.title="Dismiss",e.type="button",e.setAttribute("aria-label","Dismiss notification"),e.addEventListener("click",p=>{p.stopPropagation(),this.close();}),t.appendChild(e);let s=document.createElement("div");s.className="robot-toast-text",t.appendChild(s);let r=document.createElement("div");r.className="robot-toast-progress-container",this.options.hideProgressBar&&(r.style.display="none");let i=document.createElement("div");return i.className="robot-toast-progress-bar",r.appendChild(i),t.appendChild(r),t}assembleLayout(){let{rtl:t}=this.options;this.wrapper.innerHTML="",(t?this.currentRobotSide==="right":this.currentRobotSide==="left")?(this.wrapper.appendChild(this.robotEl),this.wrapper.appendChild(this.messageBox)):(this.wrapper.appendChild(this.messageBox),this.wrapper.appendChild(this.robotEl));}playEntrance(){this.wrapper.classList.add("robot-toast-visible");let t=this.resolveVariant()==="hidden",o=this.options.message==="",e=()=>{if(o){this.options.onOpen?.(),this.afterTypingComplete();return}let s=this.options.transition==="bounce"?"message-enter":`message-enter-${this.options.transition}`;this.messageBox.classList.add(s);let r=()=>{this.messageBox.removeEventListener("animationend",r),this.messageBox.classList.remove(s),this.messageBox.style.opacity="1",this.messageBox.style.transform="none",this.options.onOpen?.(),this.startTyping();};this.messageBox.addEventListener("animationend",r,{once:true});};if(t)e();else {let s=this.currentRobotSide==="left"?"left":"right",r=this.options.transition!=="bounce"?`-${this.options.transition}`:"",i=`robot-enter-${s}${r}`;this.robotEl.classList.add(i);let p=()=>{this.robotEl.removeEventListener("animationend",p),this.robotEl.style.opacity="1",this.robotEl.classList.remove(i),this.robotEl.classList.add("robot-idle"),e();};this.robotEl.addEventListener("animationend",p,{once:true});}}playExit(t){let o=this.resolveVariant()==="hidden",e=this.options.message==="",s=()=>{if(this.messageBox.removeEventListener("animationend",s),o)this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);else {this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right");let r=this.currentRobotSide==="left"?"left":"right",i=this.options.transition!=="bounce"?`-${this.options.transition}`:"",p=`robot-exit-${r}${i}`;this.robotEl.classList.add(p);let c=()=>{this.robotEl.removeEventListener("animationend",c),this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);};this.robotEl.addEventListener("animationend",c,{once:true});}};e?s():(this.messageBox.classList.add("message-exit"),this.messageBox.addEventListener("animationend",s,{once:true}));}startTyping(){let{message:t,typeSpeed:o}=this.options,e=this.messageText;if(o===0){e.textContent=t,this.afterTypingComplete();return}let s=0,r=true;this.cleanupFns.push(()=>{r=false;});let i=()=>{r&&(s<t.length?(e.textContent+=t.charAt(s++),setTimeout(i,o)):this.afterTypingComplete());};i();}afterTypingComplete(){this.autoCloseDuration>0&&!this.options.hideProgressBar&&this.progressBar&&(this.progressBar.style.animationDuration=`${this.autoCloseDuration}ms`,this.progressBar.offsetWidth,this.progressBar.classList.add("robot-toast-progress-auto"),(this.isHovered||this.isFocusLost)&&this.progressBar.classList.add("robot-toast-progress-paused")),!this.isHovered&&!this.isFocusLost&&this.startTimer();}startTimer(){this.autoCloseDuration<=0||this.remainingTime<=0||(this.timerStart=Date.now(),this.closeTimeout=setTimeout(()=>this.close(),this.remainingTime));}pauseTimer(){if(this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null,this.timerStart!==null)){let t=Date.now()-this.timerStart;this.remainingTime=Math.max(0,this.remainingTime-t),this.timerStart=null;}this.progressBar?.classList.add("robot-toast-progress-paused");}resumeTimer(){this.isHovered||this.isFocusLost||this.isDragging||(this.progressBar?.classList.remove("robot-toast-progress-paused"),this.startTimer());}cancelTimer(){this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null);}initHoverWatcher(){let t=()=>{this.isHovered=true,this.pauseTimer();},o=()=>{this.isHovered=false,this.resumeTimer();};this.wrapper.addEventListener("mouseenter",t),this.wrapper.addEventListener("mouseleave",o),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("mouseenter",t),this.wrapper.removeEventListener("mouseleave",o);});}initFocusWatcher(){let t=()=>{this.isFocusLost=true,this.pauseTimer();},o=()=>{this.isFocusLost=false,this.resumeTimer();};window.addEventListener("blur",t),window.addEventListener("focus",o),this.cleanupFns.push(()=>{window.removeEventListener("blur",t),window.removeEventListener("focus",o);});}initDrag(){this.messageBox.style.cursor="grab";let t=s=>{if(s.target.closest(".robot-toast-close")||s.button!==void 0&&s.button!==0)return;s.preventDefault(),this.isDragging=true,this.pauseTimer();let r=this.wrapper.getBoundingClientRect();this.wrapper.classList.add("robot-toast-dragging"),this.wrapper.style.top=`${r.top}px`,this.wrapper.style.left=`${r.left}px`,this.wrapper.style.right="auto",this.wrapper.style.bottom="auto",this.wrapper.style.transform="none",this.dragWidth=r.width,this.dragHeight=r.height,this.dragOffsetX=s.clientX-r.left,this.dragOffsetY=s.clientY-r.top,this.messageBox.style.cursor="grabbing",this.wrapper.setPointerCapture(s.pointerId);},o=s=>{if(!this.isDragging)return;s.preventDefault();let r=window.innerWidth-this.dragWidth,i=window.innerHeight-this.dragHeight,p=Math.max(0,Math.min(s.clientX-this.dragOffsetX,r)),c=Math.max(0,Math.min(s.clientY-this.dragOffsetY,i));this.wrapper.style.left=`${p}px`,this.wrapper.style.top=`${c}px`;},e=s=>{if(!this.isDragging)return;this.isDragging=false,this.wrapper.classList.remove("robot-toast-dragging"),this.messageBox.style.cursor="grab";let r=parseFloat(this.wrapper.style.left)||0,i=parseFloat(this.wrapper.style.top)||0,p=r+this.dragWidth/2,c=window.innerWidth/2,m=p<c,b=this.options.nearScreen?m?"left":"right":m?"right":"left",v=m?20:window.innerWidth-this.dragWidth-20,E=Math.max(20,Math.min(i,window.innerHeight-this.dragHeight-20));if(this.wrapper.style.transition="left 0.45s cubic-bezier(0.34,1.56,0.64,1), top 0.4s cubic-bezier(0.34,1.56,0.64,1)",this.wrapper.style.left=`${v}px`,this.wrapper.style.top=`${E}px`,b!==this.currentRobotSide){this.currentRobotSide=b;let x=b==="left";this.robotEl.style.order=x?"0":"1",this.messageBox.style.order=x?"1":"0";let w=b==="left"?"robot-snap-left":"robot-snap-right";this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right"),this.robotEl.classList.add(w),this.robotEl.addEventListener("animationend",()=>{this.robotEl.style.opacity="1",this.robotEl.classList.remove(w),this.robotEl.classList.add("robot-idle");},{once:true});}setTimeout(()=>{this.wrapper.style.transition="";},500),this.resumeTimer();};this.wrapper.addEventListener("pointerdown",t),this.wrapper.addEventListener("pointermove",o),this.wrapper.addEventListener("pointerup",e),this.wrapper.addEventListener("pointercancel",e),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("pointerdown",t),this.wrapper.removeEventListener("pointermove",o),this.wrapper.removeEventListener("pointerup",e),this.wrapper.removeEventListener("pointercancel",e);});}getBuiltinSVG(){return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 120"
|
|
707
|
+
`,e=document.createElement("style");e.id=t,e.textContent=o,document.head.appendChild(e);}};h.injected=false;var u=h,T=u;var k=600,R=1;function L(){return R++}var O=16,y=class{constructor(t,o,e){this.progressBar=null;this.timerStart=null;this.closeTimeout=null;this.isDragging=false;this.dragOffsetX=0;this.dragOffsetY=0;this.dragWidth=0;this.dragHeight=0;this.isHovered=false;this.isFocusLost=false;this.isClosed=false;this.cleanupFns=[];this.id=t,this.onRemove=e;let r={message:o.message,autoClose:o.autoClose??5e3,position:o.position??"bottom-right",type:o.type??"default",theme:o.theme??"light",style:o.style,typeSpeed:o.typeSpeed??30,robotVariant:o.robotVariant??"",hideProgressBar:o.hideProgressBar??false,pauseOnFocusLoss:o.pauseOnFocusLoss??true,draggable:o.draggable??true,nearScreen:o.nearScreen??true,pauseOnHover:o.pauseOnHover??true,rtl:o.rtl??false,transition:o.transition??"bounce",action:o.action,cancel:o.cancel,onOpen:o.onOpen,onClose:o.onClose};this.options=r;let s=r.position.includes("left"),i;r.nearScreen?i=s?"left":"right":i=s?"right":"left",this.currentRobotSide=i,this.autoCloseDuration=typeof r.autoClose=="number"?r.autoClose:r.autoClose?5e3:0,this.remainingTime=this.autoCloseDuration,this.wrapper=this.buildWrapper(),this.robotEl=this.buildRobot(),this.messageBox=this.buildMessageBox(),this.messageText=this.messageBox.querySelector(".robot-toast-text"),this.progressBar=this.messageBox.querySelector(".robot-toast-progress-bar"),r.message===""&&this.messageBox.classList.add("robot-toast-empty"),this.assembleLayout(),document.body.appendChild(this.wrapper),r.draggable&&this.initDrag(),r.pauseOnFocusLoss&&this.initFocusWatcher(),r.pauseOnHover&&this.initHoverWatcher(),requestAnimationFrame(()=>this.playEntrance());}close(){this.isClosed||(this.isClosed=true,this.cancelTimer(),this.cleanupFns.forEach(t=>t()),this.cleanupFns=[],this.playExit(()=>{this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.options.onClose?.(),this.onRemove(this.id);}));}shiftVertical(t){this.options.position.startsWith("bottom")?this.wrapper.style.bottom=`${t}px`:this.wrapper.style.top=`${t}px`;}getWrapperHeight(){return this.wrapper.getBoundingClientRect().height||90}buildWrapper(){let t=document.createElement("div"),o=["robot-toast-wrapper",`robot-toast-${this.options.position}`];this.options.rtl&&o.push("robot-toast-rtl"),t.className=o.join(" ");let e=this.options.type==="error"||this.options.type==="warning";return t.setAttribute("role",e?"alert":"status"),t.setAttribute("aria-live",e?"assertive":"polite"),t.setAttribute("aria-atomic","true"),t}resolveVariant(){let t=this.options.robotVariant;if(!t||t==="none")return "hidden";if(t==="default")return "default";let o=[".svg",".png",".jpg",".jpeg",".gif",".webp"];return t.startsWith("data:")||o.some(s=>t.toLowerCase().endsWith(s))?"image":"hidden"}buildRobot(){let t=document.createElement("div");t.className="robot-toast-robot";let o=this.resolveVariant();if(o==="hidden")return t.style.display="none",t;if(o==="default")return t.innerHTML=this.getBuiltinSVG(),t;let e=document.createElement("img");return e.src=this.options.robotVariant,e.alt="Robot",e.setAttribute("width","65"),e.setAttribute("height","70"),e.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",e.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(e),t}buildMessageBox(){let t=document.createElement("div"),o=["robot-toast-message",`robot-toast-type-${this.options.type}`,`robot-toast-theme-${this.options.theme}`].filter(Boolean);t.className=o.join(" "),t.style.cursor=this.options.draggable?"grab":"default",this.options.style&&Object.entries(this.options.style).forEach(([n,c])=>{let m=n.replace(/-([a-z])/g,b=>b[1].toUpperCase());t.style[m]=c;});let e=document.createElement("button");e.className="robot-toast-close",e.innerHTML="×",e.title="Dismiss",e.type="button",e.setAttribute("aria-label","Dismiss notification"),e.addEventListener("click",n=>{n.stopPropagation(),this.close();}),t.appendChild(e);let r=document.createElement("div");if(r.className="robot-toast-text",t.appendChild(r),this.options.action||this.options.cancel){let n=document.createElement("div");n.className="robot-toast-actions",this.options.cancel&&n.appendChild(this.buildActionButton(this.options.cancel,"cancel")),this.options.action&&n.appendChild(this.buildActionButton(this.options.action,"action")),t.appendChild(n);}let s=document.createElement("div");s.className="robot-toast-progress-container",this.options.hideProgressBar&&(s.style.display="none");let i=document.createElement("div");return i.className="robot-toast-progress-bar",s.appendChild(i),t.appendChild(s),t}buildActionButton(t,o){let e=document.createElement("button");return e.type="button",e.className=`robot-toast-${o}`,e.textContent=t.label,e.addEventListener("click",r=>{r.stopPropagation();try{t.onClick(r);}catch(s){console.error("[robot-toast] action onClick threw:",s);}this.close();}),e}assembleLayout(){let{rtl:t}=this.options;this.wrapper.innerHTML="",(t?this.currentRobotSide==="right":this.currentRobotSide==="left")?(this.wrapper.appendChild(this.robotEl),this.wrapper.appendChild(this.messageBox)):(this.wrapper.appendChild(this.messageBox),this.wrapper.appendChild(this.robotEl));}playEntrance(){this.wrapper.classList.add("robot-toast-visible");let t=this.resolveVariant()==="hidden",o=this.options.message==="",e=()=>{if(o){this.options.onOpen?.(),this.afterTypingComplete();return}let r=this.options.transition==="bounce"?"message-enter":`message-enter-${this.options.transition}`;this.messageBox.classList.add(r);let s=()=>{this.messageBox.removeEventListener("animationend",s),this.messageBox.classList.remove(r),this.messageBox.style.opacity="1",this.messageBox.style.transform="none",this.options.onOpen?.(),this.startTyping();};this.messageBox.addEventListener("animationend",s,{once:true});};if(t)e();else {let r=this.currentRobotSide==="left"?"left":"right",s=this.options.transition!=="bounce"?`-${this.options.transition}`:"",i=`robot-enter-${r}${s}`;this.robotEl.classList.add(i);let n=()=>{this.robotEl.removeEventListener("animationend",n),this.robotEl.style.opacity="1",this.robotEl.classList.remove(i),this.robotEl.classList.add("robot-idle"),e();};this.robotEl.addEventListener("animationend",n,{once:true});}}playExit(t){let o=this.resolveVariant()==="hidden",e=this.options.message==="",r=()=>{if(this.messageBox.removeEventListener("animationend",r),o)this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);else {this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right");let s=this.currentRobotSide==="left"?"left":"right",i=this.options.transition!=="bounce"?`-${this.options.transition}`:"",n=`robot-exit-${s}${i}`;this.robotEl.classList.add(n);let c=()=>{this.robotEl.removeEventListener("animationend",c),this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);};this.robotEl.addEventListener("animationend",c,{once:true});}};e?r():(this.messageBox.classList.add("message-exit"),this.messageBox.addEventListener("animationend",r,{once:true}));}startTyping(){let{message:t,typeSpeed:o}=this.options,e=this.messageText;if(o===0){e.textContent=t,this.afterTypingComplete();return}let r=0,s=true;this.cleanupFns.push(()=>{s=false;});let i=()=>{s&&(r<t.length?(e.textContent+=t.charAt(r++),setTimeout(i,o)):this.afterTypingComplete());};i();}afterTypingComplete(){this.autoCloseDuration>0&&!this.options.hideProgressBar&&this.progressBar&&(this.progressBar.style.animationDuration=`${this.autoCloseDuration}ms`,this.progressBar.offsetWidth,this.progressBar.classList.add("robot-toast-progress-auto"),(this.isHovered||this.isFocusLost)&&this.progressBar.classList.add("robot-toast-progress-paused")),!this.isHovered&&!this.isFocusLost&&this.startTimer();}startTimer(){this.autoCloseDuration<=0||this.remainingTime<=0||(this.timerStart=Date.now(),this.closeTimeout=setTimeout(()=>this.close(),this.remainingTime));}pauseTimer(){if(this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null,this.timerStart!==null)){let t=Date.now()-this.timerStart;this.remainingTime=Math.max(0,this.remainingTime-t),this.timerStart=null;}this.progressBar?.classList.add("robot-toast-progress-paused");}resumeTimer(){this.isHovered||this.isFocusLost||this.isDragging||(this.progressBar?.classList.remove("robot-toast-progress-paused"),this.startTimer());}cancelTimer(){this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null);}initHoverWatcher(){let t=()=>{this.isHovered=true,this.pauseTimer();},o=()=>{this.isHovered=false,this.resumeTimer();};this.wrapper.addEventListener("mouseenter",t),this.wrapper.addEventListener("mouseleave",o),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("mouseenter",t),this.wrapper.removeEventListener("mouseleave",o);});}initFocusWatcher(){let t=()=>{this.isFocusLost=true,this.pauseTimer();},o=()=>{this.isFocusLost=false,this.resumeTimer();};window.addEventListener("blur",t),window.addEventListener("focus",o),this.cleanupFns.push(()=>{window.removeEventListener("blur",t),window.removeEventListener("focus",o);});}initDrag(){this.messageBox.style.cursor="grab";let t=r=>{if(r.target.closest(".robot-toast-close, .robot-toast-action, .robot-toast-cancel")||r.button!==void 0&&r.button!==0||typeof window<"u"&&window.innerWidth<=k)return;r.preventDefault(),this.isDragging=true,this.pauseTimer();let s=this.wrapper.getBoundingClientRect();this.wrapper.classList.add("robot-toast-dragging"),this.wrapper.style.top=`${s.top}px`,this.wrapper.style.left=`${s.left}px`,this.wrapper.style.right="auto",this.wrapper.style.bottom="auto",this.wrapper.style.transform="none",this.dragWidth=s.width,this.dragHeight=s.height,this.dragOffsetX=r.clientX-s.left,this.dragOffsetY=r.clientY-s.top,this.messageBox.style.cursor="grabbing",this.wrapper.setPointerCapture(r.pointerId);},o=r=>{if(!this.isDragging)return;r.preventDefault();let s=window.innerWidth-this.dragWidth,i=window.innerHeight-this.dragHeight,n=Math.max(0,Math.min(r.clientX-this.dragOffsetX,s)),c=Math.max(0,Math.min(r.clientY-this.dragOffsetY,i));this.wrapper.style.left=`${n}px`,this.wrapper.style.top=`${c}px`;},e=r=>{if(!this.isDragging)return;this.isDragging=false,this.wrapper.classList.remove("robot-toast-dragging"),this.messageBox.style.cursor="grab";let s=parseFloat(this.wrapper.style.left)||0,i=parseFloat(this.wrapper.style.top)||0,n=s+this.dragWidth/2,c=window.innerWidth/2,m=n<c,b=this.options.nearScreen?m?"left":"right":m?"right":"left",v=m?20:window.innerWidth-this.dragWidth-20,E=Math.max(20,Math.min(i,window.innerHeight-this.dragHeight-20));if(this.wrapper.style.transition="left 0.45s cubic-bezier(0.34,1.56,0.64,1), top 0.4s cubic-bezier(0.34,1.56,0.64,1)",this.wrapper.style.left=`${v}px`,this.wrapper.style.top=`${E}px`,b!==this.currentRobotSide){this.currentRobotSide=b;let x=b==="left";this.robotEl.style.order=x?"0":"1",this.messageBox.style.order=x?"1":"0";let w=b==="left"?"robot-snap-left":"robot-snap-right";this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right"),this.robotEl.classList.add(w),this.robotEl.addEventListener("animationend",()=>{this.robotEl.style.opacity="1",this.robotEl.classList.remove(w),this.robotEl.classList.add("robot-idle");},{once:true});}setTimeout(()=>{this.wrapper.style.transition="";},500),this.resumeTimer();};this.wrapper.addEventListener("pointerdown",t),this.wrapper.addEventListener("pointermove",o),this.wrapper.addEventListener("pointerup",e),this.wrapper.addEventListener("pointercancel",e),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("pointerdown",t),this.wrapper.removeEventListener("pointermove",o),this.wrapper.removeEventListener("pointerup",e),this.wrapper.removeEventListener("pointercancel",e);});}getBuiltinSVG(){return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 120"
|
|
607
708
|
width="100%" height="100%" role="img" aria-label="Robot">
|
|
608
709
|
<defs>
|
|
609
710
|
<linearGradient id="rtGrad${this.id}" x1="0" y1="0" x2="1" y2="1">
|
|
@@ -651,5 +752,5 @@
|
|
|
651
752
|
fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
|
|
652
753
|
<rect x="54" y="110" width="16" height="10" rx="5"
|
|
653
754
|
fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
|
|
654
|
-
</svg>`}},d=class d{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new T;}static getInstance(){return d._instance||(d._instance=new d),d._instance}show(t){if(typeof document>"u")return -1;let o=
|
|
755
|
+
</svg>`}},d=class d{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new T;}static getInstance(){return d._instance||(d._instance=new d),d._instance}show(t){if(typeof document>"u")return -1;let o=L(),e=t.limit??this.globalLimit;return e>0&&this.activeToasts.length>=e?(this.queue.push({options:t,id:o}),o):(this.spawnToast(t,o),o)}closeAll(){this.queue=[],[...this.activeToasts].forEach(t=>t.close());}closeById(t){let o=this.activeToasts.find(e=>e.id===t);o&&o.close(),this.queue=this.queue.filter(e=>e.id!==t);}spawnToast(t,o){let e=new y(o,t,s=>this.handleRemoved(s));t.newestOnTop??false?this.activeToasts.unshift(e):this.activeToasts.push(e),this.restack();}handleRemoved(t){if(this.activeToasts=this.activeToasts.filter(o=>o.id!==t),this.restack(),this.queue.length>0){let o=this.queue.shift();setTimeout(()=>this.spawnToast(o.options,o.id),120);}}restack(){let t={};this.activeToasts.forEach(o=>{let e=o.options.position;t[e]||(t[e]=[]),t[e].push(o);}),Object.keys(t).forEach(o=>{let e=t[o],r=20;e.forEach(s=>{s.shiftVertical(r),r+=s.getWrapperHeight()+O;});});}};d._instance=null;var p=d;function g(a=5e3){return new Promise((t,o)=>{if(typeof window>"u"){o(new Error("[RobotToast] Cannot run outside of a browser environment."));return}if(window.RobotToast){t(window.RobotToast);return}let e=Date.now(),r=setInterval(()=>{if(window.RobotToast){clearInterval(r),t(window.RobotToast);return}Date.now()-e>=a&&(clearInterval(r),o(new Error(`[RobotToast] Failed to load within ${a}ms.`)));},80);})}async function A(a){try{return (await g()).show(a)}catch(t){return console.error("[RobotToast] showRobotToast failed:",t),-1}}async function B(){try{(await g()).closeAll();}catch(a){console.error("[RobotToast] closeAllRobotToasts failed:",a);}}async function S(){return g()}var I=["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center"],C=["default","info","success","warning","error"],P=["light","dark","colored"],Y=["bounce","slide","zoom","flip"];function f(a){return typeof a=="string"?{message:a}:a}function l(a){return typeof window>"u"?-1:p.getInstance().show(f(a))}l.success=a=>l({...f(a),type:"success"});l.error=a=>l({...f(a),type:"error"});l.info=a=>l({...f(a),type:"info"});l.warning=a=>l({...f(a),type:"warning"});l.closeAll=()=>{typeof window>"u"||p.getInstance().closeAll();};l.closeById=a=>{typeof window>"u"||p.getInstance().closeById(a);};l.promise=(a,t)=>{if(typeof window>"u")return a;let o=typeof t.loading=="string"?{message:t.loading}:{message:"",...t.loading},e=l({autoClose:false,hideProgressBar:true,...o,typeSpeed:o.typeSpeed??0}),r=(s,i)=>{let n=typeof s=="string"?{message:s}:{message:"",...s};return {type:i,...n}};return a.then(s=>{l.closeById(e);let i=typeof t.success=="function"?t.success(s):t.success;return l(r(i,"success")),s},s=>{l.closeById(e);let i=typeof t.error=="function"?t.error(s):t.error;throw l(r(i,"error")),s})};function X(){if(typeof window>"u"||window.__robotToastLoaded)return;window.__robotToastLoaded=true;let a={show:t=>p.getInstance().show(t),closeAll:()=>p.getInstance().closeAll(),closeById:t=>p.getInstance().closeById(t),getInstance:()=>p.getInstance()};window.RobotToast=a;}X();exports.RobotToast=p;exports.RobotToastManager=p;exports.TOAST_POSITIONS=I;exports.TOAST_THEMES=P;exports.TOAST_TRANSITIONS=Y;exports.TOAST_TYPES=C;exports.closeAllRobotToasts=B;exports.ensureRobotToastReady=g;exports.getRobotToastInstance=S;exports.showRobotToast=A;exports.toast=l;//# sourceMappingURL=index.js.map
|
|
655
756
|
//# sourceMappingURL=index.js.map
|