vetra-toast 1.0.5 → 1.0.7
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 +19 -283
- package/dist/animations/index.d.ts +0 -1
- package/dist/components/ToastIcon.d.ts +0 -1
- package/dist/components/ToastItem.d.ts +24 -22
- package/dist/components/ToastProgress.d.ts +0 -1
- package/dist/components/Toaster.d.ts +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/store.d.ts +2 -23
- package/dist/core/timer.d.ts +0 -1
- package/dist/core/toast-api.d.ts +0 -1
- package/dist/core-BikVsncn.js +1 -0
- package/dist/core-DWP-MMiI.cjs +1 -0
- package/dist/core.cjs +1 -9
- package/dist/core.js +1 -1
- package/dist/hooks/use-mounted.d.ts +0 -1
- package/dist/hooks/use-swipe.d.ts +0 -1
- package/dist/hooks/use-system-theme.d.ts +0 -1
- package/dist/hooks/use-toasts.d.ts +0 -1
- package/dist/index.cjs +1 -1057
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1043
- package/dist/styles.css +1 -1438
- package/dist/types/index.d.ts +0 -1
- package/dist/utils/dom.d.ts +0 -1
- package/dist/utils/feedback.d.ts +0 -1
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/merge.d.ts +0 -1
- package/package.json +1 -1
- package/dist/animations/index.d.ts.map +0 -1
- package/dist/components/ToastIcon.d.ts.map +0 -1
- package/dist/components/ToastItem.d.ts.map +0 -1
- package/dist/components/ToastProgress.d.ts.map +0 -1
- package/dist/components/Toaster.d.ts.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/store.d.ts.map +0 -1
- package/dist/core/timer.d.ts.map +0 -1
- package/dist/core/toast-api.d.ts.map +0 -1
- package/dist/core-Ce3e1p9h.cjs +0 -893
- package/dist/core-Ce3e1p9h.cjs.map +0 -1
- package/dist/core-D9-gmw70.js +0 -804
- package/dist/core-D9-gmw70.js.map +0 -1
- package/dist/hooks/use-mounted.d.ts.map +0 -1
- package/dist/hooks/use-swipe.d.ts.map +0 -1
- package/dist/hooks/use-system-theme.d.ts.map +0 -1
- package/dist/hooks/use-toasts.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/dom.d.ts.map +0 -1
- package/dist/utils/feedback.d.ts.map +0 -1
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/merge.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,56 +1,19 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
1
|
# Vetra Toast
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Premium glassmorphism toast notifications for React & Next.js. Zero runtime dependencies.
|
|
6
4
|
|
|
7
5
|
[](https://www.npmjs.com/package/vetra-toast)
|
|
8
|
-
[](https://www.npmjs.com/package/vetra-toast)
|
|
10
|
-
[](https://www.typescriptlang.org/)
|
|
11
|
-
[](https://www.npmjs.com/package/vetra-toast)
|
|
6
|
+
[](https://vetra-toast.vercel.app/)
|
|
12
7
|
[](https://github.com/immobarok/vetra-toast/blob/main/LICENSE)
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## Why Vetra Toast?
|
|
21
|
-
|
|
22
|
-
- **Signature Frosted Glass UI** — Layered `backdrop-filter` blur, prismatic top specular edge, semantic corner aura, and four glass presets (`subtle`, `frosted`, `crystal`, `solid`).
|
|
23
|
-
- **Bespoke Animated SVG Icons** — Hand-crafted micro-animations per variant (spring-drawn success check with sparkles, dual-stroke error shield with micro-shake, warning prism, orbital info glint, and dual-ring gyroscope loader).
|
|
24
|
-
- **Zero Runtime Dependencies** — No mandatory Tailwind CSS or animation libraries. Tree-shakeable ESM + CJS with standalone `vetra-toast/styles.css`.
|
|
25
|
-
- **Framework-Agnostic Core** — Predictable external store (`useSyncExternalStore`) with FIFO queue promotion, reference-counted multi-reason pause/resume (`hover`, `focus`, `document-hidden`, `swipe`), and duplicate prevention.
|
|
26
|
-
- **Next.js App Router & SSR Safe** — Ships `"use client"` on the React entry, defers portal mounting until client hydration, and keeps browser APIs out of module initialization.
|
|
27
|
-
- **Accessibility First** — Semantic `role="alert"` / `role="status"`, `aria-live`, `Alt+T` focus hotkey, `Escape` dismissal, `prefers-reduced-motion`, and `prefers-reduced-transparency` fallbacks.
|
|
28
|
-
- **Rich Sensory Feedback** — Optional subtle synthesized Web Audio chimes and mobile haptic vibration (`navigator.vibrate`), zero audio asset downloads.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## Installation
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
pnpm add vetra-toast
|
|
36
|
-
```
|
|
9
|
+
## Install
|
|
37
10
|
|
|
38
11
|
```bash
|
|
39
12
|
npm install vetra-toast
|
|
40
13
|
```
|
|
41
14
|
|
|
42
|
-
```bash
|
|
43
|
-
yarn add vetra-toast
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
> **Peer dependencies**: `react >= 18` and `react-dom >= 18` (built and tested with React 19.3+).
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
15
|
## Quick Start
|
|
51
16
|
|
|
52
|
-
Import the stylesheet once in your app entry, mount `<Toaster />` near the root, and call `toast` from anywhere:
|
|
53
|
-
|
|
54
17
|
```tsx
|
|
55
18
|
import { Toaster, toast } from "vetra-toast";
|
|
56
19
|
import "vetra-toast/styles.css";
|
|
@@ -59,264 +22,37 @@ export function App() {
|
|
|
59
22
|
return (
|
|
60
23
|
<>
|
|
61
24
|
<Toaster position="top-right" theme="dark" />
|
|
62
|
-
|
|
63
25
|
<button onClick={() => toast.success("Profile updated!")}>
|
|
64
|
-
|
|
26
|
+
Show Toast
|
|
65
27
|
</button>
|
|
66
28
|
</>
|
|
67
29
|
);
|
|
68
30
|
}
|
|
69
31
|
```
|
|
70
32
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## Next.js App Router
|
|
74
|
-
|
|
75
|
-
Mount `<Toaster />` directly inside your Server Component root layout (`app/layout.tsx`) with zero hydration warnings:
|
|
76
|
-
|
|
77
|
-
```tsx
|
|
78
|
-
// app/layout.tsx
|
|
79
|
-
import type { ReactNode } from "react";
|
|
80
|
-
import { Toaster } from "vetra-toast";
|
|
81
|
-
import "vetra-toast/styles.css";
|
|
82
|
-
|
|
83
|
-
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
84
|
-
return (
|
|
85
|
-
<html lang="en">
|
|
86
|
-
<body>
|
|
87
|
-
{children}
|
|
88
|
-
<Toaster position="top-right" theme="system" />
|
|
89
|
-
</body>
|
|
90
|
-
</html>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Then trigger toasts from any Client Component (`"use client"`):
|
|
96
|
-
|
|
97
|
-
```tsx
|
|
98
|
-
"use client";
|
|
99
|
-
|
|
100
|
-
import { toast } from "vetra-toast";
|
|
101
|
-
|
|
102
|
-
export function SaveButton() {
|
|
103
|
-
return (
|
|
104
|
-
<button onClick={() => toast.success("Saved to cloud!")}>
|
|
105
|
-
Save Changes
|
|
106
|
-
</button>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## API Reference
|
|
114
|
-
|
|
115
|
-
### Variants
|
|
33
|
+
## Usage
|
|
116
34
|
|
|
117
35
|
```ts
|
|
118
36
|
toast("Default notification");
|
|
119
|
-
toast.success("
|
|
120
|
-
toast.error("Something went wrong
|
|
121
|
-
toast.warning("
|
|
122
|
-
toast.info("New update available
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Automatically transitions a single toast from `loading` → `success` or `error`. Rejections are handled internally so fire-and-forget usage never triggers unhandled promise rejections; call `.unwrap()` when you want the original promise result:
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
const req = toast.promise(uploadFile(), {
|
|
132
|
-
loading: "Uploading...",
|
|
133
|
-
success: (file) => `Uploaded ${file.name}!`,
|
|
134
|
-
error: (err) => `Upload failed: ${err.message}`,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Optional: await resolved data or catch rejection
|
|
138
|
-
// const file = await req.unwrap();
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Update, Dismiss & Dismiss All
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
const id = toast.loading("Deploying to production...");
|
|
145
|
-
|
|
146
|
-
toast.update(id, {
|
|
147
|
-
variant: "success",
|
|
148
|
-
title: "Deployment live!",
|
|
149
|
-
description: "All health checks passed.",
|
|
37
|
+
toast.success("Saved!", { description: "Your changes are live." });
|
|
38
|
+
toast.error("Something went wrong");
|
|
39
|
+
toast.warning("Storage almost full");
|
|
40
|
+
toast.info("New update available");
|
|
41
|
+
|
|
42
|
+
toast.promise(saveData(), {
|
|
43
|
+
loading: "Saving...",
|
|
44
|
+
success: "Saved!",
|
|
45
|
+
error: "Failed to save",
|
|
150
46
|
});
|
|
151
47
|
|
|
152
|
-
toast.dismiss(id);
|
|
153
48
|
toast.dismissAll();
|
|
154
49
|
```
|
|
155
50
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
```tsx
|
|
159
|
-
toast.warning("File moved to trash", {
|
|
160
|
-
description: "Restore it within 30 days.",
|
|
161
|
-
action: {
|
|
162
|
-
label: "Undo",
|
|
163
|
-
onClick: () => restoreFile(),
|
|
164
|
-
},
|
|
165
|
-
cancel: {
|
|
166
|
-
label: "Dismiss",
|
|
167
|
-
onClick: () => {},
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
toast.custom(({ dismiss }) => (
|
|
172
|
-
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
|
|
173
|
-
<strong>Custom Glass Widget</strong>
|
|
174
|
-
<button type="button" onClick={dismiss}>Close</button>
|
|
175
|
-
</div>
|
|
176
|
-
));
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Duplicate Prevention
|
|
180
|
-
|
|
181
|
-
```ts
|
|
182
|
-
// Global: <Toaster preventDuplicates />
|
|
183
|
-
// Or per-toast:
|
|
184
|
-
toast.info("Connection restored", {
|
|
185
|
-
dedupe: true,
|
|
186
|
-
dedupeKey: "network-status",
|
|
187
|
-
});
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Repeated triggers increment a sleek `×2`, `×3` counter badge and reset the auto-dismiss timer instead of flooding the screen.
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## `<Toaster />` Props
|
|
195
|
-
|
|
196
|
-
| Prop | Type | Default | Description |
|
|
197
|
-
| :--- | :--- | :--- | :--- |
|
|
198
|
-
| `position` | `"top-left" \| "top-center" \| "top-right" \| "bottom-left" \| "bottom-center" \| "bottom-right"` | `"top-right"` | Viewport anchor (auto-centered on mobile `<= 640px`) |
|
|
199
|
-
| `theme` | `"dark" \| "light" \| "system"` | `"dark"` | Glassmorphism theme mode |
|
|
200
|
-
| `glass` | `"subtle" \| "frosted" \| "crystal" \| "solid"` | `"frosted"` | Glass blur & surface intensity preset |
|
|
201
|
-
| `radius` | `"sm" \| "md" \| "lg" \| "pill"` | `"md"` | Corner radius preset |
|
|
202
|
-
| `size` | `"compact" \| "default" \| "comfortable"` | `"default"` | Spacing & typography density |
|
|
203
|
-
| `animation` | `"spring" \| "slide" \| "fade" \| "zoom" \| "bounce" \| "none"` | `"bounce"` | Entrance & exit animation style |
|
|
204
|
-
| `iconAnimation` | `"default" \| "subtle" \| "none" \| boolean` | `"default"` | Control animated SVG icon motion |
|
|
205
|
-
| `ambientGlow` | `boolean` | `true` | Semantic corner aura glow behind the icon |
|
|
206
|
-
| `richColors` | `boolean` | `false` | Apply subtle semantic tint to glass surface & border |
|
|
207
|
-
| `duration` | `number` | `4000` | Default auto-dismiss duration in ms (`Infinity` disables) |
|
|
208
|
-
| `visibleToasts` | `number` | `4` | Max visible toasts; overflow queues in FIFO order |
|
|
209
|
-
| `expand` | `boolean` | `false` | Stacked depth mode by default (fans open on hover/focus) |
|
|
210
|
-
| `showProgress` | `boolean` | `false` | Synchronized countdown progress bar |
|
|
211
|
-
| `progressPosition` | `"bottom" \| "top"` | `"bottom"` | Progress bar edge placement |
|
|
212
|
-
| `progressHeight` | `number` | `3` | Progress bar height in px |
|
|
213
|
-
| `closeButton` | `boolean` | `true` | Render accessible dismiss button |
|
|
214
|
-
| `closeButtonPosition` | `"top-right" \| "top-left" \| "floating"` | `"floating"` | Close button placement |
|
|
215
|
-
| `showCloseOnHover` | `boolean` | `true` | Reveal close button on hover or keyboard focus |
|
|
216
|
-
| `pauseOnHover` | `boolean` | `true` | Pause auto-dismiss timer while hovered |
|
|
217
|
-
| `pauseOnFocus` | `boolean` | `true` | Pause auto-dismiss timer while focused |
|
|
218
|
-
| `swipeToDismiss` | `boolean` | `true` | Enable pointer/touch swipe dismissal |
|
|
219
|
-
| `swipeDirections` | `Array<"left" \| "right" \| "up" \| "down">` | Position-based | Override allowed swipe directions |
|
|
220
|
-
| `preventDuplicates` | `boolean` | `false` | Deduplicate matching active toasts globally |
|
|
221
|
-
| `hotkey` | `string[]` | `["altKey", "KeyT"]` | Global keyboard shortcut to focus notifications |
|
|
222
|
-
| `sound` | `boolean` | `true` | Subtle synthesized Web Audio chime |
|
|
223
|
-
| `haptic` | `boolean` | `true` | Mobile `navigator.vibrate` haptic pulse |
|
|
224
|
-
| `onToastShow` | `(toast: ToastRecord) => void` | — | Callback fired when a toast becomes visible |
|
|
225
|
-
| `themeTokens` | `VetraThemeTokens` | — | Inline CSS custom property overrides |
|
|
226
|
-
| `icons` | `ToastIcons` | — | Global custom icons (`success`, `error`, `warning`, `info`, `loading`, `close`) |
|
|
227
|
-
| `classNames` | `ToastClassNames` | — | Granular slot class names (`toast`, `title`, `description`, `icon`, `actionButton`, `closeButton`, `progress`, etc.) |
|
|
228
|
-
| `toastOptions` | `ToastDefaultOptions` | — | Global & per-variant default options |
|
|
229
|
-
| `gap` / `offset` | `number` / `number \| string` | `12` / `20` | Stack gap and viewport offset |
|
|
230
|
-
| `portalContainer` | `HTMLElement \| null` | `document.body` | Custom React Portal mount target |
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
## Customization
|
|
235
|
-
|
|
236
|
-
### Inline Theme Tokens & Per-Variant Defaults
|
|
237
|
-
|
|
238
|
-
```tsx
|
|
239
|
-
<Toaster
|
|
240
|
-
theme="dark"
|
|
241
|
-
glass="crystal"
|
|
242
|
-
radius="lg"
|
|
243
|
-
animation="spring"
|
|
244
|
-
showProgress
|
|
245
|
-
progressPosition="top"
|
|
246
|
-
themeTokens={{
|
|
247
|
-
blur: 28,
|
|
248
|
-
width: 400,
|
|
249
|
-
success: "#10b981",
|
|
250
|
-
error: "#f43f5e",
|
|
251
|
-
}}
|
|
252
|
-
toastOptions={{
|
|
253
|
-
success: { duration: 2500 },
|
|
254
|
-
error: { duration: 6000 },
|
|
255
|
-
}}
|
|
256
|
-
/>
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### CSS Custom Properties
|
|
260
|
-
|
|
261
|
-
Override any `--vt-*` variable directly in CSS:
|
|
262
|
-
|
|
263
|
-
```css
|
|
264
|
-
:root {
|
|
265
|
-
--vt-blur: 24px;
|
|
266
|
-
--vt-saturate: 195%;
|
|
267
|
-
--vt-radius: 18px;
|
|
268
|
-
--vt-width: 390px;
|
|
269
|
-
--vt-success: #34d399;
|
|
270
|
-
--vt-error: #fb7185;
|
|
271
|
-
--vt-warning: #fbbf24;
|
|
272
|
-
--vt-info: #38bdf8;
|
|
273
|
-
--vt-loading: #a78bfa;
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Granular Slot Styling (`classNames`)
|
|
278
|
-
|
|
279
|
-
Style any internal element with Tailwind CSS or CSS Modules:
|
|
280
|
-
|
|
281
|
-
```tsx
|
|
282
|
-
<Toaster
|
|
283
|
-
classNames={{
|
|
284
|
-
toast: "shadow-2xl",
|
|
285
|
-
title: "tracking-tight",
|
|
286
|
-
description: "text-xs opacity-80",
|
|
287
|
-
actionButton: "rounded-full",
|
|
288
|
-
closeButton: "hover:scale-110",
|
|
289
|
-
}}
|
|
290
|
-
/>
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
---
|
|
294
|
-
|
|
295
|
-
## Framework-Agnostic Core (`vetra-toast/core`)
|
|
296
|
-
|
|
297
|
-
Import the notification store and timer engine without pulling React into non-UI modules:
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
import { createToastStore, createToastApi, defaultToastStore } from "vetra-toast/core";
|
|
301
|
-
|
|
302
|
-
const store = createToastStore({ visibleToasts: 3, defaultDuration: 3500 });
|
|
303
|
-
const api = createToastApi(store);
|
|
304
|
-
api.success("Triggered outside React");
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
---
|
|
308
|
-
|
|
309
|
-
## Accessibility
|
|
310
|
-
|
|
311
|
-
- **Semantic Live Regions**: `error` and `warning` use `role="alert"` (`aria-live="assertive"`); `success`, `info`, and `loading` use `role="status"` (`aria-live="polite"`).
|
|
312
|
-
- **Keyboard Control**: Press `Alt+T` to focus active notifications, `Tab` through actions/close buttons with high-visibility focus rings, or press `Escape` to dismiss.
|
|
313
|
-
- **Tab Visibility Awareness**: Timers pause automatically when the browser tab goes hidden (`document.visibilitychange`) and resume when returning.
|
|
314
|
-
- **OS Preferences**: Automatic `@media (prefers-reduced-transparency: reduce)` solid surface fallback and `@media (prefers-reduced-motion: reduce)` gentle fade transitions.
|
|
315
|
-
|
|
316
|
-
---
|
|
51
|
+
## Docs & Playground
|
|
317
52
|
|
|
318
|
-
|
|
53
|
+
- **Live Playground**: https://vetra-toast.vercel.app/
|
|
54
|
+
- **Full Documentation & API**: https://github.com/immobarok/vetra-toast
|
|
319
55
|
|
|
320
|
-
|
|
56
|
+
## License
|
|
321
57
|
|
|
322
|
-
|
|
58
|
+
MIT © [Mobarok](https://www.mobarok.me)
|
|
@@ -4,4 +4,3 @@ export declare const SWIPE_DISMISS_THRESHOLD_PX = 84;
|
|
|
4
4
|
export declare const SWIPE_VELOCITY_THRESHOLD = 0.45;
|
|
5
5
|
export declare const SWIPE_DRAG_DAMPENING = 0.35;
|
|
6
6
|
export declare function getDefaultSwipeDirections(position: ToastPosition): readonly SwipeDirection[];
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { ToastStore } from "../core/store.js";
|
|
3
3
|
import type { SwipeDirection, ToastAnimationPreset, ToastClassNames, ToastCloseButtonPosition, ToastGlassPreset, ToastIconAnimation, ToastIcons, ToastPosition, ToastProgressPosition, ToastRadiusPreset, ToastRecord, ToastSize } from "../types/index.js";
|
|
4
|
+
export interface ToastItemDefaults {
|
|
5
|
+
glass: ToastGlassPreset;
|
|
6
|
+
radius: ToastRadiusPreset;
|
|
7
|
+
size: ToastSize;
|
|
8
|
+
ambientGlow: boolean;
|
|
9
|
+
animation: ToastAnimationPreset;
|
|
10
|
+
iconAnimation: ToastIconAnimation;
|
|
11
|
+
closeButton: boolean;
|
|
12
|
+
closeButtonPosition: ToastCloseButtonPosition;
|
|
13
|
+
showCloseOnHover: boolean;
|
|
14
|
+
showProgress: boolean;
|
|
15
|
+
progressPosition: ToastProgressPosition;
|
|
16
|
+
progressHeight: number;
|
|
17
|
+
pauseOnHover: boolean;
|
|
18
|
+
pauseOnFocus: boolean;
|
|
19
|
+
swipeToDismiss: boolean;
|
|
20
|
+
swipeDirections?: readonly SwipeDirection[];
|
|
21
|
+
richColors: boolean;
|
|
22
|
+
icons?: ToastIcons;
|
|
23
|
+
classNames?: ToastClassNames;
|
|
24
|
+
toastClassName?: string;
|
|
25
|
+
}
|
|
4
26
|
export interface ToastItemProps {
|
|
5
27
|
toast: ToastRecord;
|
|
6
28
|
index: number;
|
|
@@ -8,26 +30,6 @@ export interface ToastItemProps {
|
|
|
8
30
|
position: ToastPosition;
|
|
9
31
|
expanded: boolean;
|
|
10
32
|
store: ToastStore;
|
|
11
|
-
|
|
12
|
-
radiusDefault: ToastRadiusPreset;
|
|
13
|
-
sizeDefault: ToastSize;
|
|
14
|
-
ambientGlowDefault: boolean;
|
|
15
|
-
animationDefault: ToastAnimationPreset;
|
|
16
|
-
iconAnimationDefault: ToastIconAnimation;
|
|
17
|
-
showCloseButton: boolean;
|
|
18
|
-
closeButtonPositionDefault: ToastCloseButtonPosition;
|
|
19
|
-
showCloseOnHoverDefault: boolean;
|
|
20
|
-
showProgressDefault: boolean;
|
|
21
|
-
progressPositionDefault: ToastProgressPosition;
|
|
22
|
-
progressHeightDefault: number;
|
|
23
|
-
pauseOnHoverDefault: boolean;
|
|
24
|
-
pauseOnFocusDefault: boolean;
|
|
25
|
-
swipeToDismissDefault: boolean;
|
|
26
|
-
swipeDirectionsDefault?: readonly SwipeDirection[];
|
|
27
|
-
richColors: boolean;
|
|
28
|
-
icons?: ToastIcons;
|
|
29
|
-
classNames?: ToastClassNames;
|
|
30
|
-
toastClassName?: string;
|
|
33
|
+
cfg: ToastItemDefaults;
|
|
31
34
|
}
|
|
32
|
-
export declare const ToastItem: import("react").MemoExoticComponent<({ toast, index, total, position, expanded, store,
|
|
33
|
-
//# sourceMappingURL=ToastItem.d.ts.map
|
|
35
|
+
export declare const ToastItem: import("react").MemoExoticComponent<({ toast, index, total, position, expanded, store, cfg, }: ToastItemProps) => ReactNode>;
|
|
@@ -11,4 +11,3 @@ export interface ToastProgressProps {
|
|
|
11
11
|
barClassName?: string;
|
|
12
12
|
}
|
|
13
13
|
export declare function ToastProgress({ duration, paused, variant, resetKey, position, height, trackClassName, barClassName, }: ToastProgressProps): ReactNode;
|
|
14
|
-
//# sourceMappingURL=ToastProgress.d.ts.map
|
|
@@ -6,4 +6,3 @@ export interface InternalToasterProps extends ToasterProps {
|
|
|
6
6
|
store?: ToastStore;
|
|
7
7
|
}
|
|
8
8
|
export declare function Toaster({ position, theme, duration, visibleToasts, gap, offset, expand, glass, radius, size, ambientGlow, themeTokens, animation, iconAnimation, progressPosition, progressHeight, pauseOnHover, pauseOnFocus, swipeToDismiss, swipeDirections, showProgress, closeButton, closeButtonPosition, showCloseOnHover, preventDuplicates, richColors, icons, classNames, hotkey, sound, haptic, onToastShow, toastOptions, dir, className, toastClassName, style, containerAriaLabel, portalContainer, exitDuration, store, }: InternalToasterProps): ReactNode;
|
|
9
|
-
//# sourceMappingURL=Toaster.d.ts.map
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { createToastStore, defaultToastStore, EMPTY_SNAPSHOT, type StoreListener, ToastStore, } from "./store.js";
|
|
2
2
|
export { type Clock, PauseableTimer } from "./timer.js";
|
|
3
3
|
export { createToastApi, type ToastApi, toast } from "./toast-api.js";
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/store.d.ts
CHANGED
|
@@ -3,14 +3,7 @@ import { type Clock } from "./timer.js";
|
|
|
3
3
|
export type StoreListener = () => void;
|
|
4
4
|
export declare const EMPTY_SNAPSHOT: ToastStoreSnapshot;
|
|
5
5
|
export declare class ToastStore {
|
|
6
|
-
private
|
|
7
|
-
private queue;
|
|
8
|
-
private snapshot;
|
|
9
|
-
private config;
|
|
10
|
-
private readonly listeners;
|
|
11
|
-
private readonly autoCloseTimers;
|
|
12
|
-
private readonly exitTimers;
|
|
13
|
-
private readonly clock;
|
|
6
|
+
#private;
|
|
14
7
|
constructor(initialConfig?: Partial<ToastStoreConfig>, clock?: Clock);
|
|
15
8
|
configure(next: Partial<ToastStoreConfig>): void;
|
|
16
9
|
getConfig(): Readonly<ToastStoreConfig>;
|
|
@@ -29,20 +22,6 @@ export declare class ToastStore {
|
|
|
29
22
|
removeImmediately(id: string): void;
|
|
30
23
|
clear(): void;
|
|
31
24
|
destroy(): void;
|
|
32
|
-
private applyPatch;
|
|
33
|
-
private syncTimerAfterUpdate;
|
|
34
|
-
private bumpDuplicate;
|
|
35
|
-
private startAutoCloseTimer;
|
|
36
|
-
private clearAutoCloseTimer;
|
|
37
|
-
private scheduleExitRemoval;
|
|
38
|
-
private clearExitTimer;
|
|
39
|
-
private promoteFromQueue;
|
|
40
|
-
private promoteFromQueueInternal;
|
|
41
|
-
private countActiveVisible;
|
|
42
|
-
private findActive;
|
|
43
|
-
private findByDedupeKey;
|
|
44
|
-
private commit;
|
|
45
25
|
}
|
|
46
|
-
export declare function createToastStore(
|
|
26
|
+
export declare function createToastStore(initialConfig?: Partial<ToastStoreConfig>, clock?: Clock): ToastStore;
|
|
47
27
|
export declare const defaultToastStore: ToastStore;
|
|
48
|
-
//# sourceMappingURL=store.d.ts.map
|
package/dist/core/timer.d.ts
CHANGED
package/dist/core/toast-api.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=.45,t=.35;function n(e){return e===`top-center`?[`up`]:e===`bottom-center`?[`down`]:e.endsWith(`left`)?[`left`]:[`right`]}var r=0;function i(e=`vt`){r+=1;let t=globalThis.crypto!==void 0&&typeof globalThis.crypto.randomUUID==`function`?globalThis.crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10);return`${e}-${r}-${t}`}function a(...e){return e.filter(Boolean).join(` `)}function o(e){return Number.isFinite(e)&&e>0}function s(...e){let t;for(let n of e)if(n){if(!t)t={...n};else for(let e of Object.keys(n)){let r=n[e];r&&(t[e]=a(t[e],r))}}return t}function c(e){return e===!1||e===`none`?`none`:e===`subtle`?`subtle`:`default`}var l=[[`fontFamily`,`font-family`],[`width`,`width`,1],[`radius`,`radius`,1],[`blur`,`blur`,1],[`saturate`,`saturate`],[`bg`,`bg`],[`bgSolid`,`bg-solid`],[`border`,`border`],[`text`,`text`],[`textMuted`,`text-muted`],[`shadow`,`shadow`],[`success`,`success`],[`error`,`error`],[`warning`,`warning`],[`info`,`info`],[`loading`,`loading`],[`default`,`default`],[`zIndex`,`z-index-root`]];function u(e){if(!e)return{};let t={};for(let[n,r,i]of l){let a=e[n];a!==void 0&&(t[`--vt-${r}`]=i&&typeof a==`number`?`${a}px`:a)}return t}var d={now:()=>Date.now()},f=class{onComplete;clock;timerId=null;duration;remaining;startedAt=null;paused=!1;completed=!1;constructor(e,t,n=d){this.duration=e,this.remaining=e,this.onComplete=t,this.clock=n}start(){this.completed||!Number.isFinite(this.remaining)||this.remaining<=0||(this.clearHandle(),this.paused=!1,this.startedAt=this.clock.now(),this.timerId=setTimeout(()=>{this.timerId=null,this.startedAt=null,this.remaining=0,this.completed=!0,this.onComplete()},this.remaining))}pause(){if(this.paused||this.completed)return this.remaining;if(this.clearHandle(),this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);this.remaining=Math.max(0,this.remaining-e),this.startedAt=null}return this.paused=!0,this.remaining}resume(){this.paused&&!this.completed&&(this.remaining<=0?(this.completed=!0,this.paused=!1,this.onComplete()):this.start())}reset(e,t=!0){this.clearHandle(),this.duration=e,this.remaining=e,this.startedAt=null,this.paused=!1,this.completed=!1,t&&Number.isFinite(e)&&e>0&&this.start()}getRemaining(){if(this.completed)return 0;if(!this.paused&&this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);return Math.max(0,this.remaining-e)}return this.remaining}getDuration(){return this.duration}isPaused(){return this.paused}isRunning(){return this.timerId!==null}clear(){this.clearHandle(),this.startedAt=null,this.completed=!0}clearHandle(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}},p={defaultDuration:4e3,visibleToasts:4,exitDuration:240,preventDuplicates:!1,toastOptions:void 0},m=/* @__PURE__ */ new Set([`default`,`success`,`error`,`warning`,`info`,`loading`,`custom`]),h=Object.freeze({toasts:Object.freeze([]),queue:Object.freeze([])});function g(e,t){return t??(e===`error`||e===`warning`?`alert`:`status`)}function _(e,t,n){let r=t===void 0?e===`loading`?0:n:t;return r<=0?1/0:r}function v(e,t,n,r){if(r)return r;let i=typeof t==`string`||typeof t==`number`?String(t):``,a=typeof n==`string`||typeof n==`number`?String(n):``;return i||a?`${e}::${i}::${a}`:void 0}function y(e,t){if(!e)return{};let n={};for(let[t,r]of Object.entries(e))m.has(t)||(n[t]=r);let r=n,i=e[t];return i?{...r,...i,className:a(r.className,i.className)||void 0,classNames:s(r.classNames,i.classNames),style:r.style||i.style?{...r.style,...i.style}:void 0}:r}function b(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function x(e,t,n){let r=[...e];return r[t]=n,r}var S=class{#e=[];#t=[];#n=h;#r;#i=/* @__PURE__ */ new Set;#a=/* @__PURE__ */ new Map;#o=/* @__PURE__ */ new Map;#s;constructor(e,t={now:()=>Date.now()}){this.#r={...p,...e},this.#s=t}configure(e){let t=this.#r.visibleToasts;this.#r={...this.#r,...e},this.#r.visibleToasts>t&&this.#t.length>0&&this.#m()&&this.#_()}getConfig(){return this.#r}subscribe=e=>(this.#i.add(e),()=>{this.#i.delete(e)});getSnapshot=()=>this.#n;getServerSnapshot=()=>h;add(e){let t=this.#s.now(),n=e.variant??(e.customRender?`custom`:`default`),r=y(this.#r.toastOptions,n),c={...r,...e,variant:n,className:a(r.className,e.className)||void 0,classNames:s(r.classNames,e.classNames),style:r.style||e.style?{...r.style,...e.style}:void 0};if(c.id&&this.#g(c.id))return this.update(c.id,c),c.id;let l=c.dedupe??(c.dedupeKey!==void 0||this.#r.preventDuplicates),u=v(n,c.title,c.description,c.dedupeKey);if(l&&u){let e=this.#e.find(e=>e.dedupeKey===u&&e.status!==`exiting`)??this.#t.find(e=>e.dedupeKey===u);if(e)return this.#l(e.id,t,c),e.id}let d=c.id??i(),f=_(n,c.duration,this.#r.defaultDuration),p=o(f),m={...c,id:d,variant:n,duration:f,remainingTime:f,startedAt:null,paused:!1,pauseReasons:/* @__PURE__ */ new Set,status:`visible`,createdAt:t,updatedAt:t,dismissible:c.dismissible??!0,showProgress:c.showProgress??(p&&n!==`loading`),pauseOnHover:c.pauseOnHover??!0,pauseOnFocus:c.pauseOnFocus??!0,swipeToDismiss:c.swipeToDismiss??!0,role:g(n,c.role),dedupeKey:u,count:1};if(this.#h()<Math.max(1,this.#r.visibleToasts)){let e=p?{...m,startedAt:t}:m;this.#e=[...this.#e,e],p&&this.#u(e.id,f)}else this.#t=[...this.#t,m];return this.#_(),d}update(e,t){let n=this.#s.now(),r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let e=this.#e[r];if(!e||e.status===`exiting`)return!1;let i=this.#c(e,t,n,!0);return this.#e=x(this.#e,r,i),(e.duration!==i.duration||t.duration!==void 0||e.variant===`loading`&&i.variant!==`loading`)&&(this.#d(i.id),o(i.duration)&&this.#u(i.id,i.duration,!i.paused)),this.#_(),!0}let i=this.#t.findIndex(t=>t.id===e);if(i!==-1){let e=this.#t[i];return e?(this.#t=x(this.#t,i,this.#c(e,t,n,!1)),this.#_(),!0):!1}return!1}dismiss(e,t=`user`){let n=this.#t.findIndex(t=>t.id===e);if(n!==-1){let t=this.#t[n];return this.#t=this.#t.filter(t=>t.id!==e),this.#_(),t?.onDismiss?.(t),!0}let r=this.#e.findIndex(t=>t.id===e),i=this.#e[r];if(!i||i.status===`exiting`)return!1;this.#d(e);let a={...i,status:`exiting`,updatedAt:this.#s.now()};return this.#r.exitDuration<=0?(this.#e=this.#e.filter(t=>t.id!==e),this.#m()):(this.#e=x(this.#e,r,a),this.#f(e)),this.#_(),t===`auto`&&a.onAutoClose?.(a),a.onDismiss?.(a),!0}dismissAll(){let e=[...this.#t];this.#t=[];for(let t of e)t.onDismiss?.(t);let t=this.#e.filter(e=>e.status!==`exiting`);if(t.length!==0||e.length!==0){for(let e of t)this.#d(e.id);if(this.#r.exitDuration<=0)this.#e=[];else{let e=this.#s.now();this.#e=this.#e.map(t=>t.status===`exiting`?t:(this.#f(t.id),{...t,status:`exiting`,updatedAt:e}))}this.#_();for(let e of t)e.onDismiss?.(e)}}pause(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||t===`hover`&&!r.pauseOnHover||t===`focus`&&!r.pauseOnFocus||r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons).add(t),a=this.#a.get(e);this.#e=x(this.#e,n,{...r,paused:!0,pauseReasons:i,remainingTime:a?a.pause():r.remainingTime,startedAt:null}),this.#_()}resume(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||!r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons);i.delete(t);let a=i.size>0;this.#e=x(this.#e,n,{...r,paused:a,pauseReasons:i,startedAt:!a&&o(r.duration)?this.#s.now():null}),this.#_(),a||this.#a.get(e)?.resume()}pauseAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.pause(t.id,e)}resumeAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.resume(t.id,e)}getRemainingTime(e){let t=this.#a.get(e);return t?t.getRemaining():this.#g(e)?.remainingTime??0}removeImmediately(e){this.#d(e),this.#p(e);let t=this.#e.length,n=this.#t.length;this.#e=this.#e.filter(t=>t.id!==e),this.#t=this.#t.filter(t=>t.id!==e),this.#e.length!==t&&this.#m(),(this.#e.length!==t||this.#t.length!==n)&&this.#_()}clear(){for(let e of this.#a.values())e.clear();this.#a.clear();for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),(this.#e.length>0||this.#t.length>0)&&(this.#e=[],this.#t=[],this.#_())}destroy(){this.clear(),this.#i.clear()}#c(e,t,n,r){let i=t.variant??e.variant,a=e.variant===`loading`,c=a&&i!==`loading`,l=c?y(this.#r.toastOptions,i):void 0,u=e.duration;if(t.duration!==void 0)u=t.duration<=0?1/0:t.duration;else if(c){let e=l?.duration??this.#r.defaultDuration;u=e<=0?1/0:e}else i===`loading`&&!a&&(u=1/0);let d=o(u),f=u!==e.duration;return{...e,...b(t),variant:i,duration:u,remainingTime:f?u:e.remainingTime,startedAt:r&&f&&d&&!e.paused?n:e.startedAt,updatedAt:n,showProgress:t.showProgress??(f?d&&i!==`loading`:e.showProgress),classNames:t.classNames===void 0?e.classNames:s(e.classNames,t.classNames),role:g(i,t.role??(t.variant?void 0:e.role)),dedupeKey:t.dedupeKey??(t.title!==void 0||t.description!==void 0||t.variant!==void 0?v(i,t.title===void 0?e.title:t.title,t.description===void 0?e.description:t.description,e.dedupeKey):e.dedupeKey)}}#l(e,t,n){let r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let i=this.#e[r];if(!i)return;let a=n.duration===void 0?i.duration:_(i.variant,n.duration,this.#r.defaultDuration),s=o(a);this.#e=x(this.#e,r,{...i,count:i.count+1,duration:a,remainingTime:a,startedAt:s&&!i.paused?t:null,updatedAt:t}),s&&(this.#d(e),this.#u(e,a,!i.paused)),this.#_();return}let i=this.#t.findIndex(t=>t.id===e),a=this.#t[i];a&&(this.#t=x(this.#t,i,{...a,count:a.count+1,updatedAt:t}),this.#_())}#u(e,t,n=!0){this.#d(e);let r=new f(t,()=>{this.#a.delete(e),this.dismiss(e,`auto`)},this.#s);this.#a.set(e,r),n&&r.start()}#d(e){let t=this.#a.get(e);t&&(t.clear(),this.#a.delete(e))}#f(e){this.#p(e);let t=setTimeout(()=>{this.#o.delete(e),this.#e=this.#e.filter(t=>t.id!==e),this.#m(),this.#_()},this.#r.exitDuration);this.#o.set(e,t)}#p(e){let t=this.#o.get(e);t!==void 0&&(clearTimeout(t),this.#o.delete(e))}#m(){let e=Math.max(1,this.#r.visibleToasts),t=!1;for(;this.#h()<e&&this.#t.length>0;){let e=this.#t[0];if(!e)break;this.#t=this.#t.slice(1);let n=this.#s.now(),r=o(e.duration),i={...e,status:`visible`,startedAt:r?n:null,remainingTime:e.duration,updatedAt:n};this.#e=[...this.#e,i],r&&this.#u(i.id,i.duration),t=!0}return t}#h(){let e=0;for(let t of this.#e)t.status!==`exiting`&&(e+=1);return e}#g(e){return this.#e.find(t=>t.id===e&&t.status!==`exiting`)??this.#t.find(t=>t.id===e)}#_(){this.#n=Object.freeze({toasts:Object.freeze([...this.#e]),queue:Object.freeze([...this.#t])});for(let e of this.#i)e()}};function C(e,t){return new S(e,t)}var w=C();function T(e){return typeof e==`object`&&!!e&&`title`in e&&!(`$$typeof`in e)}function E(e){return T(e)?{...e}:{title:e,description:void 0}}function D(e=w){let t=((t,n)=>e.add({...n,title:t}));for(let n of[`success`,`error`,`warning`,`info`,`loading`])t[n]=(t,r)=>e.add({...r,title:t,variant:n});return t.custom=(t,n)=>e.add({...n,variant:`custom`,customRender:t}),t.update=(t,n)=>e.update(t,n),t.dismiss=t=>e.dismiss(t,`user`),t.dismissAll=()=>e.dismissAll(),t.promise=(t,n,r)=>{let i=e.add({...r,...E(n.loading),variant:`loading`,duration:1/0,showProgress:!1}),a;try{a=typeof t==`function`?t():t}catch(e){a=Promise.reject(e)}let o=(t,n)=>{let a=E(n);e.update(i,{...a,variant:t,duration:a.duration??r?.duration,showProgress:a.showProgress??r?.showProgress})};return a.then(e=>o(`success`,typeof n.success==`function`?n.success(e):n.success),e=>o(`error`,typeof n.error==`function`?n.error(e):n.error)).finally(()=>{n.finally?.()}),{id:i,unwrap:()=>a}},t}var O=D(w);export{C as a,a as c,c as d,u as f,n as h,S as i,o as l,e as m,O as n,w as o,t as p,h as r,f as s,D as t,s as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e===`top-center`?[`up`]:e===`bottom-center`?[`down`]:e.endsWith(`left`)?[`left`]:[`right`]}var t=0;function n(e=`vt`){t+=1;let n=globalThis.crypto!==void 0&&typeof globalThis.crypto.randomUUID==`function`?globalThis.crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10);return`${e}-${t}-${n}`}function r(...e){return e.filter(Boolean).join(` `)}function i(e){return Number.isFinite(e)&&e>0}function a(...e){let t;for(let n of e)if(n){if(!t)t={...n};else for(let e of Object.keys(n)){let i=n[e];i&&(t[e]=r(t[e],i))}}return t}function o(e){return e===!1||e===`none`?`none`:e===`subtle`?`subtle`:`default`}var s=[[`fontFamily`,`font-family`],[`width`,`width`,1],[`radius`,`radius`,1],[`blur`,`blur`,1],[`saturate`,`saturate`],[`bg`,`bg`],[`bgSolid`,`bg-solid`],[`border`,`border`],[`text`,`text`],[`textMuted`,`text-muted`],[`shadow`,`shadow`],[`success`,`success`],[`error`,`error`],[`warning`,`warning`],[`info`,`info`],[`loading`,`loading`],[`default`,`default`],[`zIndex`,`z-index-root`]];function c(e){if(!e)return{};let t={};for(let[n,r,i]of s){let a=e[n];a!==void 0&&(t[`--vt-${r}`]=i&&typeof a==`number`?`${a}px`:a)}return t}var l={now:()=>Date.now()},u=class{onComplete;clock;timerId=null;duration;remaining;startedAt=null;paused=!1;completed=!1;constructor(e,t,n=l){this.duration=e,this.remaining=e,this.onComplete=t,this.clock=n}start(){this.completed||!Number.isFinite(this.remaining)||this.remaining<=0||(this.clearHandle(),this.paused=!1,this.startedAt=this.clock.now(),this.timerId=setTimeout(()=>{this.timerId=null,this.startedAt=null,this.remaining=0,this.completed=!0,this.onComplete()},this.remaining))}pause(){if(this.paused||this.completed)return this.remaining;if(this.clearHandle(),this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);this.remaining=Math.max(0,this.remaining-e),this.startedAt=null}return this.paused=!0,this.remaining}resume(){this.paused&&!this.completed&&(this.remaining<=0?(this.completed=!0,this.paused=!1,this.onComplete()):this.start())}reset(e,t=!0){this.clearHandle(),this.duration=e,this.remaining=e,this.startedAt=null,this.paused=!1,this.completed=!1,t&&Number.isFinite(e)&&e>0&&this.start()}getRemaining(){if(this.completed)return 0;if(!this.paused&&this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);return Math.max(0,this.remaining-e)}return this.remaining}getDuration(){return this.duration}isPaused(){return this.paused}isRunning(){return this.timerId!==null}clear(){this.clearHandle(),this.startedAt=null,this.completed=!0}clearHandle(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}},d={defaultDuration:4e3,visibleToasts:4,exitDuration:240,preventDuplicates:!1,toastOptions:void 0},f=new Set([`default`,`success`,`error`,`warning`,`info`,`loading`,`custom`]),p=Object.freeze({toasts:Object.freeze([]),queue:Object.freeze([])});function m(e,t){return t??(e===`error`||e===`warning`?`alert`:`status`)}function h(e,t,n){let r=t===void 0?e===`loading`?0:n:t;return r<=0?1/0:r}function g(e,t,n,r){if(r)return r;let i=typeof t==`string`||typeof t==`number`?String(t):``,a=typeof n==`string`||typeof n==`number`?String(n):``;return i||a?`${e}::${i}::${a}`:void 0}function _(e,t){if(!e)return{};let n={};for(let[t,r]of Object.entries(e))f.has(t)||(n[t]=r);let i=n,o=e[t];return o?{...i,...o,className:r(i.className,o.className)||void 0,classNames:a(i.classNames,o.classNames),style:i.style||o.style?{...i.style,...o.style}:void 0}:i}function v(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function y(e,t,n){let r=[...e];return r[t]=n,r}var b=class{#e=[];#t=[];#n=p;#r;#i=new Set;#a=new Map;#o=new Map;#s;constructor(e,t={now:()=>Date.now()}){this.#r={...d,...e},this.#s=t}configure(e){let t=this.#r.visibleToasts;this.#r={...this.#r,...e},this.#r.visibleToasts>t&&this.#t.length>0&&this.#m()&&this.#_()}getConfig(){return this.#r}subscribe=e=>(this.#i.add(e),()=>{this.#i.delete(e)});getSnapshot=()=>this.#n;getServerSnapshot=()=>p;add(e){let t=this.#s.now(),o=e.variant??(e.customRender?`custom`:`default`),s=_(this.#r.toastOptions,o),c={...s,...e,variant:o,className:r(s.className,e.className)||void 0,classNames:a(s.classNames,e.classNames),style:s.style||e.style?{...s.style,...e.style}:void 0};if(c.id&&this.#g(c.id))return this.update(c.id,c),c.id;let l=c.dedupe??(c.dedupeKey!==void 0||this.#r.preventDuplicates),u=g(o,c.title,c.description,c.dedupeKey);if(l&&u){let e=this.#e.find(e=>e.dedupeKey===u&&e.status!==`exiting`)??this.#t.find(e=>e.dedupeKey===u);if(e)return this.#l(e.id,t,c),e.id}let d=c.id??n(),f=h(o,c.duration,this.#r.defaultDuration),p=i(f),v={...c,id:d,variant:o,duration:f,remainingTime:f,startedAt:null,paused:!1,pauseReasons:new Set,status:`visible`,createdAt:t,updatedAt:t,dismissible:c.dismissible??!0,showProgress:c.showProgress??(p&&o!==`loading`),pauseOnHover:c.pauseOnHover??!0,pauseOnFocus:c.pauseOnFocus??!0,swipeToDismiss:c.swipeToDismiss??!0,role:m(o,c.role),dedupeKey:u,count:1};if(this.#h()<Math.max(1,this.#r.visibleToasts)){let e=p?{...v,startedAt:t}:v;this.#e=[...this.#e,e],p&&this.#u(e.id,f)}else this.#t=[...this.#t,v];return this.#_(),d}update(e,t){let n=this.#s.now(),r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let e=this.#e[r];if(!e||e.status===`exiting`)return!1;let a=this.#c(e,t,n,!0);return this.#e=y(this.#e,r,a),(e.duration!==a.duration||t.duration!==void 0||e.variant===`loading`&&a.variant!==`loading`)&&(this.#d(a.id),i(a.duration)&&this.#u(a.id,a.duration,!a.paused)),this.#_(),!0}let a=this.#t.findIndex(t=>t.id===e);if(a!==-1){let e=this.#t[a];return e?(this.#t=y(this.#t,a,this.#c(e,t,n,!1)),this.#_(),!0):!1}return!1}dismiss(e,t=`user`){let n=this.#t.findIndex(t=>t.id===e);if(n!==-1){let t=this.#t[n];return this.#t=this.#t.filter(t=>t.id!==e),this.#_(),t?.onDismiss?.(t),!0}let r=this.#e.findIndex(t=>t.id===e),i=this.#e[r];if(!i||i.status===`exiting`)return!1;this.#d(e);let a={...i,status:`exiting`,updatedAt:this.#s.now()};return this.#r.exitDuration<=0?(this.#e=this.#e.filter(t=>t.id!==e),this.#m()):(this.#e=y(this.#e,r,a),this.#f(e)),this.#_(),t===`auto`&&a.onAutoClose?.(a),a.onDismiss?.(a),!0}dismissAll(){let e=[...this.#t];this.#t=[];for(let t of e)t.onDismiss?.(t);let t=this.#e.filter(e=>e.status!==`exiting`);if(t.length!==0||e.length!==0){for(let e of t)this.#d(e.id);if(this.#r.exitDuration<=0)this.#e=[];else{let e=this.#s.now();this.#e=this.#e.map(t=>t.status===`exiting`?t:(this.#f(t.id),{...t,status:`exiting`,updatedAt:e}))}this.#_();for(let e of t)e.onDismiss?.(e)}}pause(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||t===`hover`&&!r.pauseOnHover||t===`focus`&&!r.pauseOnFocus||r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons).add(t),a=this.#a.get(e);this.#e=y(this.#e,n,{...r,paused:!0,pauseReasons:i,remainingTime:a?a.pause():r.remainingTime,startedAt:null}),this.#_()}resume(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||!r.pauseReasons.has(t))return;let a=new Set(r.pauseReasons);a.delete(t);let o=a.size>0;this.#e=y(this.#e,n,{...r,paused:o,pauseReasons:a,startedAt:!o&&i(r.duration)?this.#s.now():null}),this.#_(),o||this.#a.get(e)?.resume()}pauseAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.pause(t.id,e)}resumeAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.resume(t.id,e)}getRemainingTime(e){let t=this.#a.get(e);return t?t.getRemaining():this.#g(e)?.remainingTime??0}removeImmediately(e){this.#d(e),this.#p(e);let t=this.#e.length,n=this.#t.length;this.#e=this.#e.filter(t=>t.id!==e),this.#t=this.#t.filter(t=>t.id!==e),this.#e.length!==t&&this.#m(),(this.#e.length!==t||this.#t.length!==n)&&this.#_()}clear(){for(let e of this.#a.values())e.clear();this.#a.clear();for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),(this.#e.length>0||this.#t.length>0)&&(this.#e=[],this.#t=[],this.#_())}destroy(){this.clear(),this.#i.clear()}#c(e,t,n,r){let o=t.variant??e.variant,s=e.variant===`loading`,c=s&&o!==`loading`,l=c?_(this.#r.toastOptions,o):void 0,u=e.duration;if(t.duration!==void 0)u=t.duration<=0?1/0:t.duration;else if(c){let e=l?.duration??this.#r.defaultDuration;u=e<=0?1/0:e}else o===`loading`&&!s&&(u=1/0);let d=i(u),f=u!==e.duration;return{...e,...v(t),variant:o,duration:u,remainingTime:f?u:e.remainingTime,startedAt:r&&f&&d&&!e.paused?n:e.startedAt,updatedAt:n,showProgress:t.showProgress??(f?d&&o!==`loading`:e.showProgress),classNames:t.classNames===void 0?e.classNames:a(e.classNames,t.classNames),role:m(o,t.role??(t.variant?void 0:e.role)),dedupeKey:t.dedupeKey??(t.title!==void 0||t.description!==void 0||t.variant!==void 0?g(o,t.title===void 0?e.title:t.title,t.description===void 0?e.description:t.description,e.dedupeKey):e.dedupeKey)}}#l(e,t,n){let r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let a=this.#e[r];if(!a)return;let o=n.duration===void 0?a.duration:h(a.variant,n.duration,this.#r.defaultDuration),s=i(o);this.#e=y(this.#e,r,{...a,count:a.count+1,duration:o,remainingTime:o,startedAt:s&&!a.paused?t:null,updatedAt:t}),s&&(this.#d(e),this.#u(e,o,!a.paused)),this.#_();return}let a=this.#t.findIndex(t=>t.id===e),o=this.#t[a];o&&(this.#t=y(this.#t,a,{...o,count:o.count+1,updatedAt:t}),this.#_())}#u(e,t,n=!0){this.#d(e);let r=new u(t,()=>{this.#a.delete(e),this.dismiss(e,`auto`)},this.#s);this.#a.set(e,r),n&&r.start()}#d(e){let t=this.#a.get(e);t&&(t.clear(),this.#a.delete(e))}#f(e){this.#p(e);let t=setTimeout(()=>{this.#o.delete(e),this.#e=this.#e.filter(t=>t.id!==e),this.#m(),this.#_()},this.#r.exitDuration);this.#o.set(e,t)}#p(e){let t=this.#o.get(e);t!==void 0&&(clearTimeout(t),this.#o.delete(e))}#m(){let e=Math.max(1,this.#r.visibleToasts),t=!1;for(;this.#h()<e&&this.#t.length>0;){let e=this.#t[0];if(!e)break;this.#t=this.#t.slice(1);let n=this.#s.now(),r=i(e.duration),a={...e,status:`visible`,startedAt:r?n:null,remainingTime:e.duration,updatedAt:n};this.#e=[...this.#e,a],r&&this.#u(a.id,a.duration),t=!0}return t}#h(){let e=0;for(let t of this.#e)t.status!==`exiting`&&(e+=1);return e}#g(e){return this.#e.find(t=>t.id===e&&t.status!==`exiting`)??this.#t.find(t=>t.id===e)}#_(){this.#n=Object.freeze({toasts:Object.freeze([...this.#e]),queue:Object.freeze([...this.#t])});for(let e of this.#i)e()}};function x(e,t){return new b(e,t)}var S=x();function C(e){return typeof e==`object`&&!!e&&`title`in e&&!(`$$typeof`in e)}function w(e){return C(e)?{...e}:{title:e,description:void 0}}function T(e=S){let t=((t,n)=>e.add({...n,title:t}));for(let n of[`success`,`error`,`warning`,`info`,`loading`])t[n]=(t,r)=>e.add({...r,title:t,variant:n});return t.custom=(t,n)=>e.add({...n,variant:`custom`,customRender:t}),t.update=(t,n)=>e.update(t,n),t.dismiss=t=>e.dismiss(t,`user`),t.dismissAll=()=>e.dismissAll(),t.promise=(t,n,r)=>{let i=e.add({...r,...w(n.loading),variant:`loading`,duration:1/0,showProgress:!1}),a;try{a=typeof t==`function`?t():t}catch(e){a=Promise.reject(e)}let o=(t,n)=>{let a=w(n);e.update(i,{...a,variant:t,duration:a.duration??r?.duration,showProgress:a.showProgress??r?.showProgress})};return a.then(e=>o(`success`,typeof n.success==`function`?n.success(e):n.success),e=>o(`error`,typeof n.error==`function`?n.error(e):n.error)).finally(()=>{n.finally?.()}),{id:i,unwrap:()=>a}},t}var E=T(S);Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return .45}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return .35}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return a}});
|
package/dist/core.cjs
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_core = require("./core-Ce3e1p9h.cjs");
|
|
3
|
-
exports.EMPTY_SNAPSHOT = require_core.EMPTY_SNAPSHOT;
|
|
4
|
-
exports.PauseableTimer = require_core.PauseableTimer;
|
|
5
|
-
exports.ToastStore = require_core.ToastStore;
|
|
6
|
-
exports.createToastApi = require_core.createToastApi;
|
|
7
|
-
exports.createToastStore = require_core.createToastStore;
|
|
8
|
-
exports.defaultToastStore = require_core.defaultToastStore;
|
|
9
|
-
exports.toast = require_core.toast;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./core-DWP-MMiI.cjs");exports.EMPTY_SNAPSHOT=e.r,exports.PauseableTimer=e.s,exports.ToastStore=e.i,exports.createToastApi=e.t,exports.createToastStore=e.a,exports.defaultToastStore=e.o,exports.toast=e.n;
|
package/dist/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{r as EMPTY_SNAPSHOT,s as PauseableTimer,i as ToastStore,t as createToastApi,a as createToastStore,o as defaultToastStore,n as toast}from"./core-BikVsncn.js";
|