vetra-toast 1.0.2 → 1.0.6
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/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 -1419
- 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-CqZy4LyN.cjs +0 -893
- package/dist/core-CqZy4LyN.cjs.map +0 -1
- package/dist/core-KMoYj72S.js +0 -804
- package/dist/core-KMoYj72S.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/dist/index.js
CHANGED
|
@@ -1,1043 +1 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { a as createToastStore, c as cx, d as resolveIconAnimationMode, f as tokensToCssVars, h as getDefaultSwipeDirections, i as ToastStore, l as isFiniteDuration, n as toast, o as defaultToastStore, p as SWIPE_DRAG_DAMPENING, r as EMPTY_SNAPSHOT, s as PauseableTimer, t as createToastApi, u as mergeClassNames } from "./core-KMoYj72S.js";
|
|
3
|
-
import { memo, useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
-
import { createPortal } from "react-dom";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
// src/hooks/use-mounted.ts
|
|
7
|
-
var emptySubscribe = () => () => {};
|
|
8
|
-
var getClientSnapshot = () => true;
|
|
9
|
-
var getServerSnapshot = () => false;
|
|
10
|
-
function useMounted() {
|
|
11
|
-
return useSyncExternalStore(emptySubscribe, getClientSnapshot, getServerSnapshot);
|
|
12
|
-
}
|
|
13
|
-
// src/utils/dom.ts
|
|
14
|
-
function isBrowser() {
|
|
15
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
16
|
-
}
|
|
17
|
-
function getSystemColorScheme() {
|
|
18
|
-
if (!isBrowser() || typeof window.matchMedia !== "function") return "dark";
|
|
19
|
-
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
20
|
-
}
|
|
21
|
-
// src/hooks/use-system-theme.ts
|
|
22
|
-
function useResolvedTheme(theme) {
|
|
23
|
-
const [systemTheme, setSystemTheme] = useState(() => theme === "system" ? getSystemColorScheme() : theme);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (theme !== "system" || !isBrowser() || typeof window.matchMedia !== "function") return;
|
|
26
|
-
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
27
|
-
const sync = () => {
|
|
28
|
-
setSystemTheme(mediaQuery.matches ? "dark" : "light");
|
|
29
|
-
};
|
|
30
|
-
sync();
|
|
31
|
-
if (typeof mediaQuery.addEventListener === "function") {
|
|
32
|
-
mediaQuery.addEventListener("change", sync);
|
|
33
|
-
return () => {
|
|
34
|
-
mediaQuery.removeEventListener("change", sync);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
mediaQuery.addListener(sync);
|
|
38
|
-
return () => {
|
|
39
|
-
mediaQuery.removeListener(sync);
|
|
40
|
-
};
|
|
41
|
-
}, [theme]);
|
|
42
|
-
if (theme === "system") return systemTheme;
|
|
43
|
-
return theme;
|
|
44
|
-
}
|
|
45
|
-
// src/hooks/use-toasts.ts
|
|
46
|
-
function useToasts(store = defaultToastStore) {
|
|
47
|
-
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
48
|
-
}
|
|
49
|
-
// src/utils/feedback.ts
|
|
50
|
-
var SOUND_PATTERNS = {
|
|
51
|
-
success: [523.25, 659.25],
|
|
52
|
-
error: [311.13, 246.94],
|
|
53
|
-
warning: [440, 392],
|
|
54
|
-
info: [587.33],
|
|
55
|
-
loading: [493.88],
|
|
56
|
-
default: [523.25],
|
|
57
|
-
custom: [523.25]
|
|
58
|
-
};
|
|
59
|
-
var HAPTIC_PATTERNS = {
|
|
60
|
-
success: 18,
|
|
61
|
-
error: [
|
|
62
|
-
28,
|
|
63
|
-
36,
|
|
64
|
-
28
|
|
65
|
-
],
|
|
66
|
-
warning: [22, 28],
|
|
67
|
-
info: 12,
|
|
68
|
-
loading: 10,
|
|
69
|
-
default: 12,
|
|
70
|
-
custom: 12
|
|
71
|
-
};
|
|
72
|
-
var sharedAudioContext = null;
|
|
73
|
-
function getAudioContext() {
|
|
74
|
-
if (!isBrowser()) return null;
|
|
75
|
-
const AudioCtx = window.AudioContext ?? window.webkitAudioContext;
|
|
76
|
-
if (!AudioCtx) return null;
|
|
77
|
-
try {
|
|
78
|
-
if (!sharedAudioContext || sharedAudioContext.state === "closed") sharedAudioContext = new AudioCtx();
|
|
79
|
-
return sharedAudioContext;
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function playToastSound(variant) {
|
|
85
|
-
const ctx = getAudioContext();
|
|
86
|
-
if (!ctx) return;
|
|
87
|
-
try {
|
|
88
|
-
if (ctx.state === "suspended") ctx.resume().catch(() => {});
|
|
89
|
-
const notes = SOUND_PATTERNS[variant] ?? SOUND_PATTERNS.default;
|
|
90
|
-
const now = ctx.currentTime;
|
|
91
|
-
notes.forEach((freq, idx) => {
|
|
92
|
-
const osc = ctx.createOscillator();
|
|
93
|
-
const gain = ctx.createGain();
|
|
94
|
-
const start = now + idx * .085;
|
|
95
|
-
const end = start + .14;
|
|
96
|
-
osc.type = variant === "error" ? "triangle" : "sine";
|
|
97
|
-
osc.frequency.setValueAtTime(freq, start);
|
|
98
|
-
gain.gain.setValueAtTime(1e-4, start);
|
|
99
|
-
gain.gain.exponentialRampToValueAtTime(.045, start + .015);
|
|
100
|
-
gain.gain.exponentialRampToValueAtTime(1e-4, end);
|
|
101
|
-
osc.connect(gain);
|
|
102
|
-
gain.connect(ctx.destination);
|
|
103
|
-
osc.start(start);
|
|
104
|
-
osc.stop(end + .01);
|
|
105
|
-
});
|
|
106
|
-
} catch {}
|
|
107
|
-
}
|
|
108
|
-
function triggerToastHaptic(variant) {
|
|
109
|
-
if (!isBrowser() || typeof navigator === "undefined" || typeof navigator.vibrate !== "function") return;
|
|
110
|
-
try {
|
|
111
|
-
navigator.vibrate(HAPTIC_PATTERNS[variant] ?? 12);
|
|
112
|
-
} catch {}
|
|
113
|
-
}
|
|
114
|
-
// src/hooks/use-swipe.ts
|
|
115
|
-
var INITIAL_SWIPE_STATE = {
|
|
116
|
-
isSwiping: false,
|
|
117
|
-
offsetX: 0,
|
|
118
|
-
offsetY: 0,
|
|
119
|
-
opacity: 1
|
|
120
|
-
};
|
|
121
|
-
function isInteractiveTarget(target) {
|
|
122
|
-
if (!(target instanceof Element)) return false;
|
|
123
|
-
return target.closest("button, a, input, textarea, select, [data-vt-no-swipe]") !== null;
|
|
124
|
-
}
|
|
125
|
-
function useSwipe({ enabled, position, directions, onSwipeStart, onSwipeCancel, onDismiss }) {
|
|
126
|
-
const [swipeState, setSwipeState] = useState(INITIAL_SWIPE_STATE);
|
|
127
|
-
const dragRef = useRef(null);
|
|
128
|
-
const allowedDirections = directions && directions.length > 0 ? directions : getDefaultSwipeDirections(position);
|
|
129
|
-
const allowLeft = allowedDirections.includes("left");
|
|
130
|
-
const allowRight = allowedDirections.includes("right");
|
|
131
|
-
const allowUp = allowedDirections.includes("up");
|
|
132
|
-
const allowDown = allowedDirections.includes("down");
|
|
133
|
-
const supportsX = allowLeft || allowRight;
|
|
134
|
-
const supportsY = allowUp || allowDown;
|
|
135
|
-
const computeDismissOffset = useCallback((dx, dy, axis) => {
|
|
136
|
-
if (axis === "x") {
|
|
137
|
-
const isAligned = dx > 0 && allowRight || dx < 0 && allowLeft;
|
|
138
|
-
return {
|
|
139
|
-
offsetX: isAligned ? dx : dx * SWIPE_DRAG_DAMPENING,
|
|
140
|
-
offsetY: 0,
|
|
141
|
-
primaryDelta: isAligned ? Math.abs(dx) : 0
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
const isAligned = dy < 0 && allowUp || dy > 0 && allowDown;
|
|
145
|
-
return {
|
|
146
|
-
offsetX: 0,
|
|
147
|
-
offsetY: isAligned ? dy : dy * SWIPE_DRAG_DAMPENING,
|
|
148
|
-
primaryDelta: isAligned ? Math.abs(dy) : 0
|
|
149
|
-
};
|
|
150
|
-
}, [
|
|
151
|
-
allowDown,
|
|
152
|
-
allowLeft,
|
|
153
|
-
allowRight,
|
|
154
|
-
allowUp
|
|
155
|
-
]);
|
|
156
|
-
const resetSwipe = useCallback((notifyCancel) => {
|
|
157
|
-
dragRef.current = null;
|
|
158
|
-
setSwipeState(INITIAL_SWIPE_STATE);
|
|
159
|
-
if (notifyCancel) onSwipeCancel?.();
|
|
160
|
-
}, [onSwipeCancel]);
|
|
161
|
-
return {
|
|
162
|
-
swipeState,
|
|
163
|
-
handlers: {
|
|
164
|
-
onPointerDown: useCallback((event) => {
|
|
165
|
-
if (!enabled || event.button !== 0 || isInteractiveTarget(event.target)) return;
|
|
166
|
-
dragRef.current = {
|
|
167
|
-
pointerId: event.pointerId,
|
|
168
|
-
startX: event.clientX,
|
|
169
|
-
startY: event.clientY,
|
|
170
|
-
startTime: Date.now(),
|
|
171
|
-
active: false,
|
|
172
|
-
lockedAxis: null
|
|
173
|
-
};
|
|
174
|
-
if (typeof event.currentTarget.setPointerCapture === "function") try {
|
|
175
|
-
event.currentTarget.setPointerCapture(event.pointerId);
|
|
176
|
-
} catch {}
|
|
177
|
-
}, [enabled]),
|
|
178
|
-
onPointerMove: useCallback((event) => {
|
|
179
|
-
const drag = dragRef.current;
|
|
180
|
-
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
181
|
-
const dx = event.clientX - drag.startX;
|
|
182
|
-
const dy = event.clientY - drag.startY;
|
|
183
|
-
const absX = Math.abs(dx);
|
|
184
|
-
const absY = Math.abs(dy);
|
|
185
|
-
if (!drag.lockedAxis) {
|
|
186
|
-
if (Math.max(absX, absY) < 6) return;
|
|
187
|
-
if (supportsX && supportsY) drag.lockedAxis = absX >= absY ? "x" : "y";
|
|
188
|
-
else drag.lockedAxis = supportsX ? "x" : "y";
|
|
189
|
-
}
|
|
190
|
-
const movement = drag.lockedAxis === "x" ? absX : absY;
|
|
191
|
-
if (!drag.active && movement < 6) return;
|
|
192
|
-
if (!drag.active) {
|
|
193
|
-
drag.active = true;
|
|
194
|
-
onSwipeStart?.();
|
|
195
|
-
}
|
|
196
|
-
const { offsetX, offsetY, primaryDelta } = computeDismissOffset(dx, dy, drag.lockedAxis);
|
|
197
|
-
const progress = Math.min(1, Math.max(0, primaryDelta / 126));
|
|
198
|
-
setSwipeState({
|
|
199
|
-
isSwiping: true,
|
|
200
|
-
offsetX,
|
|
201
|
-
offsetY,
|
|
202
|
-
opacity: Math.max(.25, 1 - progress * .7)
|
|
203
|
-
});
|
|
204
|
-
}, [
|
|
205
|
-
computeDismissOffset,
|
|
206
|
-
onSwipeStart,
|
|
207
|
-
supportsX,
|
|
208
|
-
supportsY
|
|
209
|
-
]),
|
|
210
|
-
onPointerUp: useCallback((event) => {
|
|
211
|
-
const drag = dragRef.current;
|
|
212
|
-
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
213
|
-
if (typeof event.currentTarget.releasePointerCapture === "function") try {
|
|
214
|
-
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
215
|
-
} catch {}
|
|
216
|
-
if (!drag.active || !drag.lockedAxis) {
|
|
217
|
-
dragRef.current = null;
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const dx = event.clientX - drag.startX;
|
|
221
|
-
const dy = event.clientY - drag.startY;
|
|
222
|
-
const elapsed = Math.max(1, Date.now() - drag.startTime);
|
|
223
|
-
const { primaryDelta } = computeDismissOffset(dx, dy, drag.lockedAxis);
|
|
224
|
-
const velocity = primaryDelta / elapsed;
|
|
225
|
-
if (primaryDelta >= 84 || velocity >= .45) {
|
|
226
|
-
dragRef.current = null;
|
|
227
|
-
setSwipeState(INITIAL_SWIPE_STATE);
|
|
228
|
-
onDismiss();
|
|
229
|
-
} else resetSwipe(true);
|
|
230
|
-
}, [
|
|
231
|
-
computeDismissOffset,
|
|
232
|
-
onDismiss,
|
|
233
|
-
resetSwipe
|
|
234
|
-
]),
|
|
235
|
-
onPointerCancel: useCallback((event) => {
|
|
236
|
-
const drag = dragRef.current;
|
|
237
|
-
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
238
|
-
resetSwipe(drag.active);
|
|
239
|
-
}, [resetSwipe])
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
// src/components/ToastIcon.tsx
|
|
244
|
-
function ToastIcon({ variant, icon, animationMode = "default", className }) {
|
|
245
|
-
const uid = useId();
|
|
246
|
-
if (icon === null) return null;
|
|
247
|
-
if (icon !== void 0) return /* @__PURE__ */ jsx("span", {
|
|
248
|
-
className: cx("vt-icon-badge vt-icon-badge-custom", className),
|
|
249
|
-
"data-vt-icon": "",
|
|
250
|
-
"data-vt-icon-animation": animationMode,
|
|
251
|
-
"aria-hidden": "true",
|
|
252
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
253
|
-
className: "vt-icon-inner",
|
|
254
|
-
children: icon
|
|
255
|
-
})
|
|
256
|
-
});
|
|
257
|
-
if (variant === "default" || variant === "custom") return null;
|
|
258
|
-
const gradId = `vt-grad-${uid}`;
|
|
259
|
-
const glowId = `vt-glow-${uid}`;
|
|
260
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
261
|
-
className: cx("vt-icon-badge", className),
|
|
262
|
-
"data-vt-icon": "",
|
|
263
|
-
"data-vt-variant": variant,
|
|
264
|
-
"data-vt-icon-animation": animationMode,
|
|
265
|
-
"aria-hidden": "true",
|
|
266
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
267
|
-
className: "vt-icon-pulse",
|
|
268
|
-
"aria-hidden": "true"
|
|
269
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
270
|
-
className: "vt-icon-inner",
|
|
271
|
-
children: [
|
|
272
|
-
variant === "success" && /* @__PURE__ */ jsxs("svg", {
|
|
273
|
-
viewBox: "0 0 24 24",
|
|
274
|
-
fill: "none",
|
|
275
|
-
className: "vt-svg vt-svg-success",
|
|
276
|
-
focusable: "false",
|
|
277
|
-
"aria-hidden": "true",
|
|
278
|
-
children: [
|
|
279
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
280
|
-
id: gradId,
|
|
281
|
-
x1: "4",
|
|
282
|
-
y1: "4",
|
|
283
|
-
x2: "20",
|
|
284
|
-
y2: "20",
|
|
285
|
-
gradientUnits: "userSpaceOnUse",
|
|
286
|
-
children: [/* @__PURE__ */ jsx("stop", {
|
|
287
|
-
offset: "0%",
|
|
288
|
-
stopColor: "currentColor",
|
|
289
|
-
stopOpacity: "1"
|
|
290
|
-
}), /* @__PURE__ */ jsx("stop", {
|
|
291
|
-
offset: "100%",
|
|
292
|
-
stopColor: "#a7f3d0",
|
|
293
|
-
stopOpacity: "0.95"
|
|
294
|
-
})]
|
|
295
|
-
}) }),
|
|
296
|
-
/* @__PURE__ */ jsx("circle", {
|
|
297
|
-
cx: "12",
|
|
298
|
-
cy: "12",
|
|
299
|
-
r: "8.75",
|
|
300
|
-
fill: "currentColor",
|
|
301
|
-
className: "vt-success-fill"
|
|
302
|
-
}),
|
|
303
|
-
/* @__PURE__ */ jsx("circle", {
|
|
304
|
-
cx: "12",
|
|
305
|
-
cy: "12",
|
|
306
|
-
r: "8.75",
|
|
307
|
-
stroke: `url(#${gradId})`,
|
|
308
|
-
strokeWidth: "1.75",
|
|
309
|
-
strokeLinecap: "round",
|
|
310
|
-
pathLength: 100,
|
|
311
|
-
className: "vt-success-ring"
|
|
312
|
-
}),
|
|
313
|
-
/* @__PURE__ */ jsx("path", {
|
|
314
|
-
d: "M8.1 12.35L10.75 15L16.1 9.35",
|
|
315
|
-
stroke: `url(#${gradId})`,
|
|
316
|
-
strokeWidth: "2.2",
|
|
317
|
-
strokeLinecap: "round",
|
|
318
|
-
strokeLinejoin: "round",
|
|
319
|
-
pathLength: 100,
|
|
320
|
-
className: "vt-success-check"
|
|
321
|
-
}),
|
|
322
|
-
/* @__PURE__ */ jsx("circle", {
|
|
323
|
-
cx: "4.2",
|
|
324
|
-
cy: "4.8",
|
|
325
|
-
r: "1.05",
|
|
326
|
-
fill: "currentColor",
|
|
327
|
-
className: "vt-spark vt-spark-1"
|
|
328
|
-
}),
|
|
329
|
-
/* @__PURE__ */ jsx("circle", {
|
|
330
|
-
cx: "19.8",
|
|
331
|
-
cy: "4.8",
|
|
332
|
-
r: "0.95",
|
|
333
|
-
fill: "currentColor",
|
|
334
|
-
className: "vt-spark vt-spark-2"
|
|
335
|
-
}),
|
|
336
|
-
/* @__PURE__ */ jsx("circle", {
|
|
337
|
-
cx: "20.2",
|
|
338
|
-
cy: "18.8",
|
|
339
|
-
r: "0.9",
|
|
340
|
-
fill: "currentColor",
|
|
341
|
-
className: "vt-spark vt-spark-3"
|
|
342
|
-
}),
|
|
343
|
-
/* @__PURE__ */ jsx("circle", {
|
|
344
|
-
cx: "4.2",
|
|
345
|
-
cy: "18.8",
|
|
346
|
-
r: "0.85",
|
|
347
|
-
fill: "currentColor",
|
|
348
|
-
className: "vt-spark vt-spark-4"
|
|
349
|
-
})
|
|
350
|
-
]
|
|
351
|
-
}),
|
|
352
|
-
variant === "error" && /* @__PURE__ */ jsxs("svg", {
|
|
353
|
-
viewBox: "0 0 24 24",
|
|
354
|
-
fill: "none",
|
|
355
|
-
className: "vt-svg vt-svg-error",
|
|
356
|
-
focusable: "false",
|
|
357
|
-
"aria-hidden": "true",
|
|
358
|
-
children: [
|
|
359
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
360
|
-
id: gradId,
|
|
361
|
-
x1: "4",
|
|
362
|
-
y1: "4",
|
|
363
|
-
x2: "20",
|
|
364
|
-
y2: "20",
|
|
365
|
-
gradientUnits: "userSpaceOnUse",
|
|
366
|
-
children: [/* @__PURE__ */ jsx("stop", {
|
|
367
|
-
offset: "0%",
|
|
368
|
-
stopColor: "#fda4af",
|
|
369
|
-
stopOpacity: "1"
|
|
370
|
-
}), /* @__PURE__ */ jsx("stop", {
|
|
371
|
-
offset: "100%",
|
|
372
|
-
stopColor: "currentColor",
|
|
373
|
-
stopOpacity: "1"
|
|
374
|
-
})]
|
|
375
|
-
}) }),
|
|
376
|
-
/* @__PURE__ */ jsx("path", {
|
|
377
|
-
d: "M8.4 3.4H15.6L20.6 8.4V15.6L15.6 20.6H8.4L3.4 15.6V8.4L8.4 3.4Z",
|
|
378
|
-
fill: "currentColor",
|
|
379
|
-
className: "vt-error-fill"
|
|
380
|
-
}),
|
|
381
|
-
/* @__PURE__ */ jsx("path", {
|
|
382
|
-
d: "M8.4 3.4H15.6L20.6 8.4V15.6L15.6 20.6H8.4L3.4 15.6V8.4L8.4 3.4Z",
|
|
383
|
-
stroke: `url(#${gradId})`,
|
|
384
|
-
strokeWidth: "1.75",
|
|
385
|
-
strokeLinejoin: "round",
|
|
386
|
-
pathLength: 100,
|
|
387
|
-
className: "vt-error-frame"
|
|
388
|
-
}),
|
|
389
|
-
/* @__PURE__ */ jsx("path", {
|
|
390
|
-
d: "M9.1 9.1L14.9 14.9",
|
|
391
|
-
stroke: `url(#${gradId})`,
|
|
392
|
-
strokeWidth: "2.15",
|
|
393
|
-
strokeLinecap: "round",
|
|
394
|
-
pathLength: 100,
|
|
395
|
-
className: "vt-error-line-1"
|
|
396
|
-
}),
|
|
397
|
-
/* @__PURE__ */ jsx("path", {
|
|
398
|
-
d: "M14.9 9.1L9.1 14.9",
|
|
399
|
-
stroke: `url(#${gradId})`,
|
|
400
|
-
strokeWidth: "2.15",
|
|
401
|
-
strokeLinecap: "round",
|
|
402
|
-
pathLength: 100,
|
|
403
|
-
className: "vt-error-line-2"
|
|
404
|
-
})
|
|
405
|
-
]
|
|
406
|
-
}),
|
|
407
|
-
variant === "warning" && /* @__PURE__ */ jsxs("svg", {
|
|
408
|
-
viewBox: "0 0 24 24",
|
|
409
|
-
fill: "none",
|
|
410
|
-
className: "vt-svg vt-svg-warning",
|
|
411
|
-
focusable: "false",
|
|
412
|
-
"aria-hidden": "true",
|
|
413
|
-
children: [
|
|
414
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
415
|
-
id: gradId,
|
|
416
|
-
x1: "12",
|
|
417
|
-
y1: "3",
|
|
418
|
-
x2: "12",
|
|
419
|
-
y2: "21",
|
|
420
|
-
gradientUnits: "userSpaceOnUse",
|
|
421
|
-
children: [/* @__PURE__ */ jsx("stop", {
|
|
422
|
-
offset: "0%",
|
|
423
|
-
stopColor: "#fde68a",
|
|
424
|
-
stopOpacity: "1"
|
|
425
|
-
}), /* @__PURE__ */ jsx("stop", {
|
|
426
|
-
offset: "100%",
|
|
427
|
-
stopColor: "currentColor",
|
|
428
|
-
stopOpacity: "1"
|
|
429
|
-
})]
|
|
430
|
-
}) }),
|
|
431
|
-
/* @__PURE__ */ jsx("path", {
|
|
432
|
-
d: "M10.42 4.65C11.12 3.43 12.88 3.43 13.58 4.65L20.38 16.45C21.08 17.67 20.2 19.2 18.8 19.2H5.2C3.8 19.2 2.92 17.67 3.62 16.45L10.42 4.65Z",
|
|
433
|
-
fill: "currentColor",
|
|
434
|
-
className: "vt-warning-fill"
|
|
435
|
-
}),
|
|
436
|
-
/* @__PURE__ */ jsx("path", {
|
|
437
|
-
d: "M10.42 4.65C11.12 3.43 12.88 3.43 13.58 4.65L20.38 16.45C21.08 17.67 20.2 19.2 18.8 19.2H5.2C3.8 19.2 2.92 17.67 3.62 16.45L10.42 4.65Z",
|
|
438
|
-
stroke: `url(#${gradId})`,
|
|
439
|
-
strokeWidth: "1.75",
|
|
440
|
-
strokeLinejoin: "round",
|
|
441
|
-
pathLength: 100,
|
|
442
|
-
className: "vt-warning-frame"
|
|
443
|
-
}),
|
|
444
|
-
/* @__PURE__ */ jsx("path", {
|
|
445
|
-
d: "M12 9.1V13.15",
|
|
446
|
-
stroke: `url(#${gradId})`,
|
|
447
|
-
strokeWidth: "2.1",
|
|
448
|
-
strokeLinecap: "round",
|
|
449
|
-
pathLength: 100,
|
|
450
|
-
className: "vt-warning-stem"
|
|
451
|
-
}),
|
|
452
|
-
/* @__PURE__ */ jsx("circle", {
|
|
453
|
-
cx: "12",
|
|
454
|
-
cy: "16.1",
|
|
455
|
-
r: "1.2",
|
|
456
|
-
fill: `url(#${gradId})`,
|
|
457
|
-
className: "vt-warning-dot"
|
|
458
|
-
})
|
|
459
|
-
]
|
|
460
|
-
}),
|
|
461
|
-
variant === "info" && /* @__PURE__ */ jsxs("svg", {
|
|
462
|
-
viewBox: "0 0 24 24",
|
|
463
|
-
fill: "none",
|
|
464
|
-
className: "vt-svg vt-svg-info",
|
|
465
|
-
focusable: "false",
|
|
466
|
-
"aria-hidden": "true",
|
|
467
|
-
children: [
|
|
468
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
469
|
-
id: gradId,
|
|
470
|
-
x1: "4",
|
|
471
|
-
y1: "4",
|
|
472
|
-
x2: "20",
|
|
473
|
-
y2: "20",
|
|
474
|
-
gradientUnits: "userSpaceOnUse",
|
|
475
|
-
children: [/* @__PURE__ */ jsx("stop", {
|
|
476
|
-
offset: "0%",
|
|
477
|
-
stopColor: "#bae6fd",
|
|
478
|
-
stopOpacity: "1"
|
|
479
|
-
}), /* @__PURE__ */ jsx("stop", {
|
|
480
|
-
offset: "100%",
|
|
481
|
-
stopColor: "currentColor",
|
|
482
|
-
stopOpacity: "1"
|
|
483
|
-
})]
|
|
484
|
-
}) }),
|
|
485
|
-
/* @__PURE__ */ jsx("circle", {
|
|
486
|
-
cx: "12",
|
|
487
|
-
cy: "12",
|
|
488
|
-
r: "8.75",
|
|
489
|
-
fill: "currentColor",
|
|
490
|
-
className: "vt-info-fill"
|
|
491
|
-
}),
|
|
492
|
-
/* @__PURE__ */ jsx("circle", {
|
|
493
|
-
cx: "12",
|
|
494
|
-
cy: "12",
|
|
495
|
-
r: "8.75",
|
|
496
|
-
stroke: `url(#${gradId})`,
|
|
497
|
-
strokeWidth: "1.75",
|
|
498
|
-
pathLength: 100,
|
|
499
|
-
className: "vt-info-ring"
|
|
500
|
-
}),
|
|
501
|
-
/* @__PURE__ */ jsx("circle", {
|
|
502
|
-
cx: "12",
|
|
503
|
-
cy: "12",
|
|
504
|
-
r: "8.75",
|
|
505
|
-
stroke: "#ffffff",
|
|
506
|
-
strokeWidth: "1.75",
|
|
507
|
-
strokeLinecap: "round",
|
|
508
|
-
strokeDasharray: "16 84",
|
|
509
|
-
pathLength: 100,
|
|
510
|
-
className: "vt-info-glint"
|
|
511
|
-
}),
|
|
512
|
-
/* @__PURE__ */ jsx("circle", {
|
|
513
|
-
cx: "12",
|
|
514
|
-
cy: "8.25",
|
|
515
|
-
r: "1.25",
|
|
516
|
-
fill: `url(#${gradId})`,
|
|
517
|
-
className: "vt-info-dot"
|
|
518
|
-
}),
|
|
519
|
-
/* @__PURE__ */ jsx("path", {
|
|
520
|
-
d: "M12 11.2V16.1",
|
|
521
|
-
stroke: `url(#${gradId})`,
|
|
522
|
-
strokeWidth: "2.15",
|
|
523
|
-
strokeLinecap: "round",
|
|
524
|
-
pathLength: 100,
|
|
525
|
-
className: "vt-info-stem"
|
|
526
|
-
})
|
|
527
|
-
]
|
|
528
|
-
}),
|
|
529
|
-
variant === "loading" && /* @__PURE__ */ jsxs("svg", {
|
|
530
|
-
viewBox: "0 0 24 24",
|
|
531
|
-
fill: "none",
|
|
532
|
-
className: "vt-svg vt-svg-loading",
|
|
533
|
-
focusable: "false",
|
|
534
|
-
"aria-hidden": "true",
|
|
535
|
-
children: [
|
|
536
|
-
/* @__PURE__ */ jsxs("defs", { children: [/* @__PURE__ */ jsxs("linearGradient", {
|
|
537
|
-
id: gradId,
|
|
538
|
-
x1: "2",
|
|
539
|
-
y1: "2",
|
|
540
|
-
x2: "22",
|
|
541
|
-
y2: "22",
|
|
542
|
-
gradientUnits: "userSpaceOnUse",
|
|
543
|
-
children: [
|
|
544
|
-
/* @__PURE__ */ jsx("stop", {
|
|
545
|
-
offset: "0%",
|
|
546
|
-
stopColor: "currentColor",
|
|
547
|
-
stopOpacity: "1"
|
|
548
|
-
}),
|
|
549
|
-
/* @__PURE__ */ jsx("stop", {
|
|
550
|
-
offset: "65%",
|
|
551
|
-
stopColor: "#c4b5fd",
|
|
552
|
-
stopOpacity: "0.85"
|
|
553
|
-
}),
|
|
554
|
-
/* @__PURE__ */ jsx("stop", {
|
|
555
|
-
offset: "100%",
|
|
556
|
-
stopColor: "currentColor",
|
|
557
|
-
stopOpacity: "0.08"
|
|
558
|
-
})
|
|
559
|
-
]
|
|
560
|
-
}), /* @__PURE__ */ jsxs("linearGradient", {
|
|
561
|
-
id: glowId,
|
|
562
|
-
x1: "20",
|
|
563
|
-
y1: "4",
|
|
564
|
-
x2: "4",
|
|
565
|
-
y2: "20",
|
|
566
|
-
gradientUnits: "userSpaceOnUse",
|
|
567
|
-
children: [/* @__PURE__ */ jsx("stop", {
|
|
568
|
-
offset: "0%",
|
|
569
|
-
stopColor: "#ffffff",
|
|
570
|
-
stopOpacity: "0.85"
|
|
571
|
-
}), /* @__PURE__ */ jsx("stop", {
|
|
572
|
-
offset: "100%",
|
|
573
|
-
stopColor: "currentColor",
|
|
574
|
-
stopOpacity: "0.1"
|
|
575
|
-
})]
|
|
576
|
-
})] }),
|
|
577
|
-
/* @__PURE__ */ jsx("circle", {
|
|
578
|
-
cx: "12",
|
|
579
|
-
cy: "12",
|
|
580
|
-
r: "9",
|
|
581
|
-
stroke: "currentColor",
|
|
582
|
-
strokeOpacity: "0.18",
|
|
583
|
-
strokeWidth: "1.8"
|
|
584
|
-
}),
|
|
585
|
-
/* @__PURE__ */ jsx("circle", {
|
|
586
|
-
cx: "12",
|
|
587
|
-
cy: "12",
|
|
588
|
-
r: "9",
|
|
589
|
-
stroke: `url(#${gradId})`,
|
|
590
|
-
strokeWidth: "2.1",
|
|
591
|
-
strokeLinecap: "round",
|
|
592
|
-
pathLength: 100,
|
|
593
|
-
className: "vt-loader-outer"
|
|
594
|
-
}),
|
|
595
|
-
/* @__PURE__ */ jsx("circle", {
|
|
596
|
-
cx: "12",
|
|
597
|
-
cy: "12",
|
|
598
|
-
r: "5.3",
|
|
599
|
-
stroke: `url(#${glowId})`,
|
|
600
|
-
strokeWidth: "1.65",
|
|
601
|
-
strokeLinecap: "round",
|
|
602
|
-
strokeDasharray: "34 66",
|
|
603
|
-
pathLength: 100,
|
|
604
|
-
className: "vt-loader-inner"
|
|
605
|
-
}),
|
|
606
|
-
/* @__PURE__ */ jsx("circle", {
|
|
607
|
-
cx: "12",
|
|
608
|
-
cy: "12",
|
|
609
|
-
r: "2.1",
|
|
610
|
-
fill: "currentColor",
|
|
611
|
-
className: "vt-loader-core"
|
|
612
|
-
})
|
|
613
|
-
]
|
|
614
|
-
})
|
|
615
|
-
]
|
|
616
|
-
})]
|
|
617
|
-
}, variant);
|
|
618
|
-
}
|
|
619
|
-
// src/components/ToastProgress.tsx
|
|
620
|
-
function ToastProgress({ duration, paused, variant, resetKey, position = "bottom", height = 3, trackClassName, barClassName }) {
|
|
621
|
-
if (!isFiniteDuration(duration)) return null;
|
|
622
|
-
const trackStyle = { height: `${Math.max(1, height)}px` };
|
|
623
|
-
const barStyle = {
|
|
624
|
-
animationDuration: `${duration}ms`,
|
|
625
|
-
animationPlayState: paused ? "paused" : "running"
|
|
626
|
-
};
|
|
627
|
-
return /* @__PURE__ */ jsx("div", {
|
|
628
|
-
className: cx("vt-progress-track", trackClassName),
|
|
629
|
-
style: trackStyle,
|
|
630
|
-
"aria-hidden": "true",
|
|
631
|
-
"data-vt-progress": "",
|
|
632
|
-
"data-vt-progress-position": position,
|
|
633
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
634
|
-
className: cx("vt-progress-bar", barClassName),
|
|
635
|
-
"data-vt-variant": variant,
|
|
636
|
-
style: barStyle
|
|
637
|
-
}, resetKey)
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
// src/components/ToastItem.tsx
|
|
641
|
-
function resolveGlobalVariantIcon(variant, icons) {
|
|
642
|
-
if (!icons) return;
|
|
643
|
-
switch (variant) {
|
|
644
|
-
case "success": return icons.success;
|
|
645
|
-
case "error": return icons.error;
|
|
646
|
-
case "warning": return icons.warning;
|
|
647
|
-
case "info": return icons.info;
|
|
648
|
-
case "loading": return icons.loading;
|
|
649
|
-
default: return;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
var ToastItem = memo(function ToastItem({ toast, index, total, position, expanded, store, glassDefault, radiusDefault, sizeDefault, ambientGlowDefault, animationDefault, iconAnimationDefault, showCloseButton, closeButtonPositionDefault, showCloseOnHoverDefault, showProgressDefault, progressPositionDefault, progressHeightDefault, pauseOnHoverDefault, pauseOnFocusDefault, swipeToDismissDefault, swipeDirectionsDefault, richColors, icons, classNames, toastClassName }) {
|
|
653
|
-
const canHoverPause = pauseOnHoverDefault && toast.pauseOnHover;
|
|
654
|
-
const canFocusPause = pauseOnFocusDefault && toast.pauseOnFocus;
|
|
655
|
-
const canSwipe = swipeToDismissDefault && toast.swipeToDismiss && toast.dismissible;
|
|
656
|
-
const shouldShowProgress = showProgressDefault && toast.showProgress && toast.status !== "exiting";
|
|
657
|
-
const shouldShowClose = (toast.closeButton ?? showCloseButton) && toast.dismissible;
|
|
658
|
-
const effectiveGlass = toast.glass ?? glassDefault;
|
|
659
|
-
const effectiveRadius = toast.radius ?? radiusDefault;
|
|
660
|
-
const effectiveSize = toast.size ?? sizeDefault;
|
|
661
|
-
const effectiveGlow = toast.ambientGlow ?? ambientGlowDefault;
|
|
662
|
-
const effectiveAnimation = toast.animation ?? animationDefault;
|
|
663
|
-
const effectiveIconAnimation = resolveIconAnimationMode(toast.iconAnimation ?? iconAnimationDefault);
|
|
664
|
-
const effectiveProgressPos = toast.progressPosition ?? progressPositionDefault;
|
|
665
|
-
const effectiveProgressHeight = toast.progressHeight ?? progressHeightDefault;
|
|
666
|
-
const effectiveClosePos = toast.closeButtonPosition ?? closeButtonPositionDefault;
|
|
667
|
-
const effectiveCloseOnHover = toast.showCloseOnHover ?? showCloseOnHoverDefault;
|
|
668
|
-
const effectiveSwipeDirections = toast.swipeDirections ?? swipeDirectionsDefault;
|
|
669
|
-
const resolvedClassNames = mergeClassNames(classNames, toast.classNames);
|
|
670
|
-
const effectiveIcon = toast.icon !== void 0 ? toast.icon : resolveGlobalVariantIcon(toast.variant, icons);
|
|
671
|
-
const handleDismiss = useCallback(() => {
|
|
672
|
-
store.dismiss(toast.id, "user");
|
|
673
|
-
}, [store, toast.id]);
|
|
674
|
-
const handlePauseManual = useCallback(() => {
|
|
675
|
-
store.pause(toast.id, "manual");
|
|
676
|
-
}, [store, toast.id]);
|
|
677
|
-
const handleResumeManual = useCallback(() => {
|
|
678
|
-
store.resume(toast.id, "manual");
|
|
679
|
-
}, [store, toast.id]);
|
|
680
|
-
const { swipeState, handlers: swipeHandlers } = useSwipe({
|
|
681
|
-
enabled: canSwipe,
|
|
682
|
-
position,
|
|
683
|
-
directions: effectiveSwipeDirections,
|
|
684
|
-
onSwipeStart: useCallback(() => {
|
|
685
|
-
store.pause(toast.id, "swipe");
|
|
686
|
-
}, [store, toast.id]),
|
|
687
|
-
onSwipeCancel: useCallback(() => {
|
|
688
|
-
store.resume(toast.id, "swipe");
|
|
689
|
-
}, [store, toast.id]),
|
|
690
|
-
onDismiss: handleDismiss
|
|
691
|
-
});
|
|
692
|
-
const handleMouseEnter = useCallback(() => {
|
|
693
|
-
if (canHoverPause) store.pause(toast.id, "hover");
|
|
694
|
-
}, [
|
|
695
|
-
canHoverPause,
|
|
696
|
-
store,
|
|
697
|
-
toast.id
|
|
698
|
-
]);
|
|
699
|
-
const handleMouseLeave = useCallback(() => {
|
|
700
|
-
if (canHoverPause) store.resume(toast.id, "hover");
|
|
701
|
-
}, [
|
|
702
|
-
canHoverPause,
|
|
703
|
-
store,
|
|
704
|
-
toast.id
|
|
705
|
-
]);
|
|
706
|
-
const handleFocus = useCallback(() => {
|
|
707
|
-
if (canFocusPause) store.pause(toast.id, "focus");
|
|
708
|
-
}, [
|
|
709
|
-
canFocusPause,
|
|
710
|
-
store,
|
|
711
|
-
toast.id
|
|
712
|
-
]);
|
|
713
|
-
const handleBlur = useCallback((event) => {
|
|
714
|
-
if (!canFocusPause) return;
|
|
715
|
-
if (event.relatedTarget && event.currentTarget.contains(event.relatedTarget)) return;
|
|
716
|
-
store.resume(toast.id, "focus");
|
|
717
|
-
}, [
|
|
718
|
-
canFocusPause,
|
|
719
|
-
store,
|
|
720
|
-
toast.id
|
|
721
|
-
]);
|
|
722
|
-
const handleKeyDown = useCallback((event) => {
|
|
723
|
-
if (event.key === "Escape" && toast.dismissible) {
|
|
724
|
-
event.stopPropagation();
|
|
725
|
-
handleDismiss();
|
|
726
|
-
}
|
|
727
|
-
}, [handleDismiss, toast.dismissible]);
|
|
728
|
-
const isFront = index === 0;
|
|
729
|
-
const zIndex = Math.max(1, total - index);
|
|
730
|
-
const stackStyle = {
|
|
731
|
-
...toast.style,
|
|
732
|
-
"--vt-index": String(index),
|
|
733
|
-
"--vt-z-index": String(zIndex),
|
|
734
|
-
"--vt-swipe-x": `${swipeState.offsetX}px`,
|
|
735
|
-
"--vt-swipe-y": `${swipeState.offsetY}px`,
|
|
736
|
-
"--vt-swipe-opacity": String(swipeState.opacity)
|
|
737
|
-
};
|
|
738
|
-
const isCustom = toast.variant === "custom" && typeof toast.customRender === "function";
|
|
739
|
-
const closeButtonEl = shouldShowClose ? /* @__PURE__ */ jsx("button", {
|
|
740
|
-
type: "button",
|
|
741
|
-
className: cx("vt-close", effectiveClosePos === "floating" && "vt-close-floating", effectiveClosePos === "top-left" && "vt-close-left", effectiveCloseOnHover && "vt-close-hover-only", resolvedClassNames?.closeButton),
|
|
742
|
-
"aria-label": "Dismiss notification",
|
|
743
|
-
"data-vt-close": "",
|
|
744
|
-
"data-vt-close-position": effectiveClosePos,
|
|
745
|
-
onClick: handleDismiss,
|
|
746
|
-
children: icons?.close !== void 0 ? icons.close : /* @__PURE__ */ jsx("svg", {
|
|
747
|
-
viewBox: "0 0 16 16",
|
|
748
|
-
fill: "none",
|
|
749
|
-
className: "vt-close-svg",
|
|
750
|
-
"aria-hidden": "true",
|
|
751
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
752
|
-
d: "M4.5 4.5L11.5 11.5M11.5 4.5L4.5 11.5",
|
|
753
|
-
stroke: "currentColor",
|
|
754
|
-
strokeWidth: "1.75",
|
|
755
|
-
strokeLinecap: "round"
|
|
756
|
-
})
|
|
757
|
-
})
|
|
758
|
-
}) : null;
|
|
759
|
-
return /* @__PURE__ */ jsx("li", {
|
|
760
|
-
className: cx("vt-toast-slot", expanded && "vt-toast-slot-expanded"),
|
|
761
|
-
"data-vt-slot": "",
|
|
762
|
-
"data-vt-index": index,
|
|
763
|
-
"data-vt-front": isFront ? "true" : "false",
|
|
764
|
-
"data-vt-status": toast.status,
|
|
765
|
-
style: stackStyle,
|
|
766
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
767
|
-
className: cx("vt-toast", richColors && "vt-toast-rich", swipeState.isSwiping && "vt-toast-swiping", effectiveClosePos === "floating" && "vt-toast-floating-close", toastClassName, resolvedClassNames?.toast, toast.className),
|
|
768
|
-
role: toast.role,
|
|
769
|
-
"aria-live": toast.role === "alert" ? "assertive" : "polite",
|
|
770
|
-
"aria-atomic": "true",
|
|
771
|
-
"aria-label": toast.ariaLabel,
|
|
772
|
-
tabIndex: 0,
|
|
773
|
-
"data-vt-toast": "",
|
|
774
|
-
"data-vt-id": toast.id,
|
|
775
|
-
"data-vt-variant": toast.variant,
|
|
776
|
-
"data-vt-status": toast.status,
|
|
777
|
-
"data-vt-paused": toast.paused ? "true" : "false",
|
|
778
|
-
"data-vt-swiping": swipeState.isSwiping ? "true" : "false",
|
|
779
|
-
"data-vt-position": position,
|
|
780
|
-
"data-vt-glass": effectiveGlass,
|
|
781
|
-
"data-vt-radius": effectiveRadius,
|
|
782
|
-
"data-vt-size": effectiveSize,
|
|
783
|
-
"data-vt-glow": effectiveGlow ? "true" : "false",
|
|
784
|
-
"data-vt-animation": effectiveAnimation,
|
|
785
|
-
onMouseEnter: handleMouseEnter,
|
|
786
|
-
onMouseLeave: handleMouseLeave,
|
|
787
|
-
onFocus: handleFocus,
|
|
788
|
-
onBlur: handleBlur,
|
|
789
|
-
onKeyDown: handleKeyDown,
|
|
790
|
-
...swipeHandlers,
|
|
791
|
-
children: [
|
|
792
|
-
effectiveClosePos === "floating" && closeButtonEl,
|
|
793
|
-
isCustom && toast.customRender ? /* @__PURE__ */ jsx("div", {
|
|
794
|
-
className: "vt-custom-content",
|
|
795
|
-
children: toast.customRender({
|
|
796
|
-
id: toast.id,
|
|
797
|
-
toast,
|
|
798
|
-
dismiss: handleDismiss,
|
|
799
|
-
pause: handlePauseManual,
|
|
800
|
-
resume: handleResumeManual
|
|
801
|
-
})
|
|
802
|
-
}) : /* @__PURE__ */ jsxs("div", {
|
|
803
|
-
className: cx("vt-body", resolvedClassNames?.body),
|
|
804
|
-
children: [
|
|
805
|
-
effectiveClosePos === "top-left" && closeButtonEl,
|
|
806
|
-
/* @__PURE__ */ jsx(ToastIcon, {
|
|
807
|
-
variant: toast.variant,
|
|
808
|
-
icon: effectiveIcon,
|
|
809
|
-
animationMode: effectiveIconAnimation,
|
|
810
|
-
className: resolvedClassNames?.icon
|
|
811
|
-
}),
|
|
812
|
-
/* @__PURE__ */ jsxs("div", {
|
|
813
|
-
className: cx("vt-content", resolvedClassNames?.content),
|
|
814
|
-
children: [
|
|
815
|
-
/* @__PURE__ */ jsxs("div", {
|
|
816
|
-
className: "vt-header",
|
|
817
|
-
children: [toast.title !== void 0 && toast.title !== null && /* @__PURE__ */ jsx("div", {
|
|
818
|
-
className: cx("vt-title", resolvedClassNames?.title),
|
|
819
|
-
"data-vt-title": "",
|
|
820
|
-
children: toast.title
|
|
821
|
-
}), toast.count > 1 && /* @__PURE__ */ jsxs("span", {
|
|
822
|
-
className: cx("vt-count-badge", resolvedClassNames?.countBadge),
|
|
823
|
-
title: `${toast.count} occurrences`,
|
|
824
|
-
"data-vt-count": toast.count,
|
|
825
|
-
children: ["×", toast.count]
|
|
826
|
-
})]
|
|
827
|
-
}),
|
|
828
|
-
toast.description !== void 0 && toast.description !== null && /* @__PURE__ */ jsx("div", {
|
|
829
|
-
className: cx("vt-description", resolvedClassNames?.description),
|
|
830
|
-
"data-vt-description": "",
|
|
831
|
-
children: toast.description
|
|
832
|
-
}),
|
|
833
|
-
(toast.action || toast.cancel) && /* @__PURE__ */ jsxs("div", {
|
|
834
|
-
className: cx("vt-actions", resolvedClassNames?.actions),
|
|
835
|
-
"data-vt-actions": "",
|
|
836
|
-
children: [toast.action && /* @__PURE__ */ jsx("button", {
|
|
837
|
-
type: "button",
|
|
838
|
-
className: cx("vt-btn vt-btn-primary", resolvedClassNames?.actionButton),
|
|
839
|
-
"aria-label": toast.action.ariaLabel,
|
|
840
|
-
onClick: (event) => {
|
|
841
|
-
toast.action?.onClick(event);
|
|
842
|
-
},
|
|
843
|
-
children: toast.action.label
|
|
844
|
-
}), toast.cancel && /* @__PURE__ */ jsx("button", {
|
|
845
|
-
type: "button",
|
|
846
|
-
className: cx("vt-btn vt-btn-secondary", resolvedClassNames?.cancelButton),
|
|
847
|
-
"aria-label": toast.cancel.ariaLabel,
|
|
848
|
-
onClick: (event) => {
|
|
849
|
-
toast.cancel?.onClick(event);
|
|
850
|
-
},
|
|
851
|
-
children: toast.cancel.label
|
|
852
|
-
})]
|
|
853
|
-
})
|
|
854
|
-
]
|
|
855
|
-
}),
|
|
856
|
-
effectiveClosePos === "top-right" && closeButtonEl
|
|
857
|
-
]
|
|
858
|
-
}),
|
|
859
|
-
shouldShowProgress && /* @__PURE__ */ jsx(ToastProgress, {
|
|
860
|
-
duration: toast.duration,
|
|
861
|
-
paused: toast.paused,
|
|
862
|
-
variant: toast.variant,
|
|
863
|
-
position: effectiveProgressPos,
|
|
864
|
-
height: effectiveProgressHeight,
|
|
865
|
-
trackClassName: resolvedClassNames?.progress,
|
|
866
|
-
barClassName: resolvedClassNames?.progressBar,
|
|
867
|
-
resetKey: `${toast.id}-${toast.duration}-${toast.count}-${toast.variant}`
|
|
868
|
-
})
|
|
869
|
-
]
|
|
870
|
-
})
|
|
871
|
-
});
|
|
872
|
-
});
|
|
873
|
-
// src/components/Toaster.tsx
|
|
874
|
-
var ALL_POSITIONS = [
|
|
875
|
-
"top-left",
|
|
876
|
-
"top-center",
|
|
877
|
-
"top-right",
|
|
878
|
-
"bottom-left",
|
|
879
|
-
"bottom-center",
|
|
880
|
-
"bottom-right"
|
|
881
|
-
];
|
|
882
|
-
var DEFAULT_HOTKEY = ["altKey", "KeyT"];
|
|
883
|
-
function matchesHotkey(event, hotkey) {
|
|
884
|
-
if (hotkey.length === 0) return false;
|
|
885
|
-
return hotkey.every((key) => {
|
|
886
|
-
if (key === "altKey") return event.altKey;
|
|
887
|
-
if (key === "ctrlKey") return event.ctrlKey;
|
|
888
|
-
if (key === "metaKey") return event.metaKey;
|
|
889
|
-
if (key === "shiftKey") return event.shiftKey;
|
|
890
|
-
return event.code === key || event.key.toLowerCase() === key.toLowerCase();
|
|
891
|
-
});
|
|
892
|
-
}
|
|
893
|
-
function Toaster({ position = "top-right", theme = "dark", duration = 4e3, visibleToasts = 4, gap = 12, offset = 20, expand = false, glass = "frosted", radius = "md", size = "default", ambientGlow = true, themeTokens, animation = "bounce", iconAnimation = "default", progressPosition = "bottom", progressHeight = 3, pauseOnHover = true, pauseOnFocus = true, swipeToDismiss = true, swipeDirections, showProgress = false, closeButton = true, closeButtonPosition = "floating", showCloseOnHover = true, preventDuplicates = false, richColors = false, icons, classNames, hotkey = DEFAULT_HOTKEY, sound = true, haptic = true, onToastShow, toastOptions, dir = "ltr", className, toastClassName, style, containerAriaLabel = "Notifications", portalContainer, exitDuration = 240, store = defaultToastStore }) {
|
|
894
|
-
const mounted = useMounted();
|
|
895
|
-
const resolvedTheme = useResolvedTheme(theme);
|
|
896
|
-
const { toasts } = useToasts(store);
|
|
897
|
-
const [hoveredPosition, setHoveredPosition] = useState(null);
|
|
898
|
-
const [focusedPosition, setFocusedPosition] = useState(null);
|
|
899
|
-
const seenToastIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
900
|
-
const effectiveExitDuration = animation === "none" ? 0 : exitDuration;
|
|
901
|
-
useEffect(() => {
|
|
902
|
-
store.configure({
|
|
903
|
-
defaultDuration: duration,
|
|
904
|
-
visibleToasts,
|
|
905
|
-
exitDuration: effectiveExitDuration,
|
|
906
|
-
preventDuplicates,
|
|
907
|
-
toastOptions
|
|
908
|
-
});
|
|
909
|
-
}, [
|
|
910
|
-
duration,
|
|
911
|
-
effectiveExitDuration,
|
|
912
|
-
preventDuplicates,
|
|
913
|
-
store,
|
|
914
|
-
toastOptions,
|
|
915
|
-
visibleToasts
|
|
916
|
-
]);
|
|
917
|
-
useEffect(() => {
|
|
918
|
-
if (!isBrowser()) return;
|
|
919
|
-
const handleVisibilityChange = () => {
|
|
920
|
-
if (document.hidden) store.pauseAll("document-hidden");
|
|
921
|
-
else store.resumeAll("document-hidden");
|
|
922
|
-
};
|
|
923
|
-
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
924
|
-
return () => {
|
|
925
|
-
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
926
|
-
};
|
|
927
|
-
}, [store]);
|
|
928
|
-
useEffect(() => {
|
|
929
|
-
if (!isBrowser() || hotkey.length === 0) return;
|
|
930
|
-
const handleKeyDown = (event) => {
|
|
931
|
-
if (!matchesHotkey(event, hotkey)) return;
|
|
932
|
-
const firstToast = document.querySelector("[data-vt-toast]");
|
|
933
|
-
if (firstToast) {
|
|
934
|
-
event.preventDefault();
|
|
935
|
-
firstToast.focus();
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
939
|
-
return () => {
|
|
940
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
941
|
-
};
|
|
942
|
-
}, [hotkey]);
|
|
943
|
-
useEffect(() => {
|
|
944
|
-
const activeIds = /* @__PURE__ */ new Set();
|
|
945
|
-
for (const item of toasts) {
|
|
946
|
-
activeIds.add(item.id);
|
|
947
|
-
if (item.status !== "exiting" && !seenToastIdsRef.current.has(item.id)) {
|
|
948
|
-
seenToastIdsRef.current.add(item.id);
|
|
949
|
-
onToastShow?.(item);
|
|
950
|
-
if (item.sound ?? sound) playToastSound(item.variant);
|
|
951
|
-
if (item.haptic ?? haptic) triggerToastHaptic(item.variant);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
for (const seenId of seenToastIdsRef.current) if (!activeIds.has(seenId)) seenToastIdsRef.current.delete(seenId);
|
|
955
|
-
}, [
|
|
956
|
-
haptic,
|
|
957
|
-
onToastShow,
|
|
958
|
-
sound,
|
|
959
|
-
toasts
|
|
960
|
-
]);
|
|
961
|
-
const tokenCssVars = useMemo(() => tokensToCssVars(themeTokens), [themeTokens]);
|
|
962
|
-
const groupedByPosition = useMemo(() => {
|
|
963
|
-
const groups = /* @__PURE__ */ new Map();
|
|
964
|
-
for (const item of toasts) {
|
|
965
|
-
const targetPos = item.position ?? position;
|
|
966
|
-
const list = groups.get(targetPos);
|
|
967
|
-
if (list) list.push(item);
|
|
968
|
-
else groups.set(targetPos, [item]);
|
|
969
|
-
}
|
|
970
|
-
return groups;
|
|
971
|
-
}, [position, toasts]);
|
|
972
|
-
if (!mounted || !isBrowser()) return null;
|
|
973
|
-
const targetContainer = portalContainer ?? document.body;
|
|
974
|
-
if (!targetContainer) return null;
|
|
975
|
-
const resolvedOffset = typeof offset === "number" ? `${offset}px` : offset;
|
|
976
|
-
const activePositions = ALL_POSITIONS.filter((pos) => {
|
|
977
|
-
const group = groupedByPosition.get(pos);
|
|
978
|
-
return group && group.length > 0;
|
|
979
|
-
});
|
|
980
|
-
if (activePositions.length === 0) return null;
|
|
981
|
-
const content = /* @__PURE__ */ jsx(Fragment, { children: activePositions.map((pos) => {
|
|
982
|
-
const ordered = [...groupedByPosition.get(pos) ?? []].reverse();
|
|
983
|
-
const isExpanded = expand || hoveredPosition === pos || focusedPosition === pos;
|
|
984
|
-
const sectionStyle = {
|
|
985
|
-
...tokenCssVars,
|
|
986
|
-
...style,
|
|
987
|
-
"--vt-gap": `${gap}px`,
|
|
988
|
-
"--vt-offset": resolvedOffset
|
|
989
|
-
};
|
|
990
|
-
return /* @__PURE__ */ jsx("section", {
|
|
991
|
-
"aria-label": containerAriaLabel,
|
|
992
|
-
dir,
|
|
993
|
-
className: cx("vt-toaster", classNames?.toaster, className),
|
|
994
|
-
"data-vt-toaster": "",
|
|
995
|
-
"data-vt-theme": resolvedTheme,
|
|
996
|
-
"data-vt-position": pos,
|
|
997
|
-
"data-vt-expanded": isExpanded ? "true" : "false",
|
|
998
|
-
style: sectionStyle,
|
|
999
|
-
onMouseEnter: () => setHoveredPosition(pos),
|
|
1000
|
-
onMouseLeave: () => setHoveredPosition((prev) => prev === pos ? null : prev),
|
|
1001
|
-
onFocus: () => setFocusedPosition(pos),
|
|
1002
|
-
onBlur: (event) => {
|
|
1003
|
-
if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) setFocusedPosition((prev) => prev === pos ? null : prev);
|
|
1004
|
-
},
|
|
1005
|
-
children: /* @__PURE__ */ jsx("ol", {
|
|
1006
|
-
className: cx("vt-list", classNames?.list),
|
|
1007
|
-
"data-vt-list": "",
|
|
1008
|
-
children: ordered.map((item, idx) => /* @__PURE__ */ jsx(ToastItem, {
|
|
1009
|
-
toast: item,
|
|
1010
|
-
index: idx,
|
|
1011
|
-
total: ordered.length,
|
|
1012
|
-
position: pos,
|
|
1013
|
-
expanded: isExpanded,
|
|
1014
|
-
store,
|
|
1015
|
-
glassDefault: glass,
|
|
1016
|
-
radiusDefault: radius,
|
|
1017
|
-
sizeDefault: size,
|
|
1018
|
-
ambientGlowDefault: ambientGlow,
|
|
1019
|
-
animationDefault: animation,
|
|
1020
|
-
iconAnimationDefault: iconAnimation,
|
|
1021
|
-
showCloseButton: closeButton,
|
|
1022
|
-
closeButtonPositionDefault: closeButtonPosition,
|
|
1023
|
-
showCloseOnHoverDefault: showCloseOnHover,
|
|
1024
|
-
showProgressDefault: showProgress,
|
|
1025
|
-
progressPositionDefault: progressPosition,
|
|
1026
|
-
progressHeightDefault: progressHeight,
|
|
1027
|
-
pauseOnHoverDefault: pauseOnHover,
|
|
1028
|
-
pauseOnFocusDefault: pauseOnFocus,
|
|
1029
|
-
swipeToDismissDefault: swipeToDismiss,
|
|
1030
|
-
swipeDirectionsDefault: swipeDirections,
|
|
1031
|
-
richColors,
|
|
1032
|
-
icons,
|
|
1033
|
-
classNames,
|
|
1034
|
-
toastClassName
|
|
1035
|
-
}, item.id))
|
|
1036
|
-
})
|
|
1037
|
-
}, pos);
|
|
1038
|
-
}) });
|
|
1039
|
-
return createPortal(content, targetContainer);
|
|
1040
|
-
}
|
|
1041
|
-
export { EMPTY_SNAPSHOT, PauseableTimer, ToastStore, Toaster, createToastApi, createToastStore, defaultToastStore, playToastSound, toast, tokensToCssVars, triggerToastHaptic, useMounted, useResolvedTheme, useToasts };
|
|
1042
|
-
|
|
1043
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use client";import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,n as s,o as c,p as l,r as u,s as d,t as f,u as p}from"./core-BikVsncn.js";import{memo as m,useCallback as h,useEffect as g,useId as _,useMemo as v,useRef as y,useState as b,useSyncExternalStore as x}from"react";import{createPortal as S}from"react-dom";import{Fragment as C,jsx as w,jsxs as T}from"react/jsx-runtime";var E=()=>()=>{},D=()=>!0,O=()=>!1;function ee(){return x(E,D,O)}function k(){return typeof window<`u`&&typeof document<`u`}function A(){return!k()||typeof window.matchMedia!=`function`||window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function j(e){let[t,n]=b(()=>e===`system`?A():e);return g(()=>{if(e!==`system`||!k()||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(`(prefers-color-scheme: dark)`),r=()=>{n(t.matches?`dark`:`light`)};return r(),typeof t.addEventListener==`function`?(t.addEventListener(`change`,r),()=>{t.removeEventListener(`change`,r)}):(t.addListener(r),()=>{t.removeListener(r)})},[e]),e===`system`?t:e}function te(e=c){return x(e.subscribe,e.getSnapshot,e.getServerSnapshot)}var M={success:[523.25,659.25],error:[311.13,246.94],warning:[440,392],info:[587.33],loading:[493.88],default:[523.25],custom:[523.25]},N={success:18,error:[28,36,28],warning:[22,28],info:12,loading:10,default:12,custom:12},P=null;function F(){if(!k())return null;let e=window.AudioContext??window.webkitAudioContext;if(!e)return null;try{return P&&P.state!==`closed`||(P=new e),P}catch{return null}}function I(e){let t=F();if(t)try{t.state===`suspended`&&t.resume().catch(()=>{});let n=M[e]??M.default,r=t.currentTime;n.forEach((n,i)=>{let a=t.createOscillator(),o=t.createGain(),s=r+i*.085,c=s+.14;a.type=e===`error`?`triangle`:`sine`,a.frequency.setValueAtTime(n,s),o.gain.setValueAtTime(1e-4,s),o.gain.exponentialRampToValueAtTime(.045,s+.015),o.gain.exponentialRampToValueAtTime(1e-4,c),a.connect(o),o.connect(t.destination),a.start(s),a.stop(c+.01)})}catch{}}function L(e){if(k()&&typeof navigator<`u`&&typeof navigator.vibrate==`function`)try{navigator.vibrate(N[e]??12)}catch{}}var R={isSwiping:!1,offsetX:0,offsetY:0,opacity:1};function z(e){return e instanceof Element&&e.closest(`button, a, input, textarea, select, [data-vt-no-swipe]`)!==null}function B({enabled:e,position:t,directions:n,onSwipeStart:r,onSwipeCancel:a,onDismiss:o}){let[s,c]=b(R),u=y(null),d=n&&n.length>0?n:i(t),f=d.includes(`left`),p=d.includes(`right`),m=d.includes(`up`),g=d.includes(`down`),_=f||p,v=m||g,x=h((e,t,n)=>{if(n===`x`){let t=e>0&&p||e<0&&f;return{offsetX:t?e:e*l,offsetY:0,primaryDelta:t?Math.abs(e):0}}let r=t<0&&m||t>0&&g;return{offsetX:0,offsetY:r?t:t*l,primaryDelta:r?Math.abs(t):0}},[g,f,p,m]),S=h(e=>{u.current=null,c(R),e&&a?.()},[a]);return{swipeState:s,handlers:{onPointerDown:h(t=>{if(e&&t.button===0&&!z(t.target)&&(u.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,startTime:Date.now(),active:!1,lockedAxis:null},typeof t.currentTarget.setPointerCapture==`function`))try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}},[e]),onPointerMove:h(e=>{let t=u.current;if(!t||t.pointerId!==e.pointerId)return;let n=e.clientX-t.startX,i=e.clientY-t.startY,a=Math.abs(n),o=Math.abs(i);if(!t.lockedAxis){if(Math.max(a,o)<6)return;t.lockedAxis=_&&v?a>=o?`x`:`y`:_?`x`:`y`}let s=t.lockedAxis===`x`?a:o;if(!t.active&&s<6)return;t.active||(t.active=!0,r?.());let{offsetX:l,offsetY:d,primaryDelta:f}=x(n,i,t.lockedAxis),p=Math.min(1,Math.max(0,f/126));c({isSwiping:!0,offsetX:l,offsetY:d,opacity:Math.max(.25,1-p*.7)})},[x,r,_,v]),onPointerUp:h(e=>{let t=u.current;if(!t||t.pointerId!==e.pointerId)return;if(typeof e.currentTarget.releasePointerCapture==`function`)try{e.currentTarget.hasPointerCapture?.(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)}catch{}if(!t.active||!t.lockedAxis){u.current=null;return}let n=e.clientX-t.startX,r=e.clientY-t.startY,i=Math.max(1,Date.now()-t.startTime),{primaryDelta:a}=x(n,r,t.lockedAxis),s=a/i;a>=84||s>=.45?(u.current=null,c(R),o()):S(!0)},[x,o,S]),onPointerCancel:h(e=>{let t=u.current;t&&t.pointerId===e.pointerId&&S(t.active)},[S])}}}var V=`M8.4 3.4H15.6L20.6 8.4V15.6L15.6 20.6H8.4L3.4 15.6V8.4L8.4 3.4Z`,H=`M10.42 4.65C11.12 3.43 12.88 3.43 13.58 4.65L20.38 16.45C21.08 17.67 20.2 19.2 18.8 19.2H5.2C3.8 19.2 2.92 17.67 3.62 16.45L10.42 4.65Z`,U=[[4.2,4.8,1.05],[19.8,4.8,.95],[20.2,18.8,.9],[4.2,18.8,.85]],W={success:[4,4,20,20,`currentColor`,`#a7f3d0`,1,.95],error:[4,4,20,20,`#fda4af`,`currentColor`],warning:[12,3,12,21,`#fde68a`,`currentColor`],info:[4,4,20,20,`#bae6fd`,`currentColor`],loading:[2,2,22,22,`currentColor`,`currentColor`,1,.08]};function G({variant:e,icon:n,animationMode:r=`default`,className:i}){let a=_();if(n===null)return null;if(n!==void 0)return/* @__PURE__ */ w(`span`,{className:t(`vt-icon-badge vt-icon-badge-custom`,i),"data-vt-icon":``,"data-vt-icon-animation":r,"aria-hidden":`true`,children:/* @__PURE__ */ w(`span`,{className:`vt-icon-inner`,children:n})});if(e==="default"||e===`custom`)return null;let o=`vt-grad-${a}`,s=`vt-glow-${a}`,c=`url(#${o})`,[l,u,d,f,p,m,h=1,g=1]=W[e];return/* @__PURE__ */ T(`span`,{className:t(`vt-icon-badge`,i),"data-vt-icon":``,"data-vt-variant":e,"data-vt-icon-animation":r,"aria-hidden":`true`,children:[/* @__PURE__ */ w(`span`,{className:`vt-icon-pulse`,"aria-hidden":`true`}),/* @__PURE__ */ w(`span`,{className:`vt-icon-inner`,children:/* @__PURE__ */ T(`svg`,{viewBox:`0 0 24 24`,fill:`none`,className:`vt-svg vt-svg-${e}`,focusable:`false`,"aria-hidden":`true`,children:[/* @__PURE__ */ T(`defs`,{children:[/* @__PURE__ */ T(`linearGradient`,{id:o,x1:l,y1:u,x2:d,y2:f,gradientUnits:`userSpaceOnUse`,children:[/* @__PURE__ */ w(`stop`,{offset:`0%`,stopColor:p,stopOpacity:h}),e===`loading`&&/* @__PURE__ */ w(`stop`,{offset:`65%`,stopColor:`#c4b5fd`,stopOpacity:`0.85`}),/* @__PURE__ */ w(`stop`,{offset:`100%`,stopColor:m,stopOpacity:g})]}),e===`loading`&&/* @__PURE__ */ T(`linearGradient`,{id:s,x1:`20`,y1:`4`,x2:`4`,y2:`20`,gradientUnits:`userSpaceOnUse`,children:[/* @__PURE__ */ w(`stop`,{offset:`0%`,stopColor:`#fff`,stopOpacity:`0.85`}),/* @__PURE__ */ w(`stop`,{offset:`100%`,stopColor:`currentColor`,stopOpacity:`0.1`})]})]}),e===`success`&&/* @__PURE__ */ T(C,{children:[/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`8.75`,fill:`currentColor`,className:`vt-success-fill`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`8.75`,stroke:c,strokeWidth:`1.75`,strokeLinecap:`round`,pathLength:100,className:`vt-success-ring`}),/* @__PURE__ */ w(`path`,{d:`M8.1 12.35L10.75 15L16.1 9.35`,stroke:c,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,pathLength:100,className:`vt-success-check`}),U.map(([e,t,n],r)=>/* @__PURE__ */ w(`circle`,{cx:e,cy:t,r:n,fill:`currentColor`,className:`vt-spark vt-spark-${r+1}`},r))]}),e===`error`&&/* @__PURE__ */ T(C,{children:[/* @__PURE__ */ w(`path`,{d:V,fill:`currentColor`,className:`vt-error-fill`}),/* @__PURE__ */ w(`path`,{d:V,stroke:c,strokeWidth:`1.75`,strokeLinejoin:`round`,pathLength:100,className:`vt-error-frame`}),/* @__PURE__ */ w(`path`,{d:`M9.1 9.1L14.9 14.9`,stroke:c,strokeWidth:`2.15`,strokeLinecap:`round`,pathLength:100,className:`vt-error-line-1`}),/* @__PURE__ */ w(`path`,{d:`M14.9 9.1L9.1 14.9`,stroke:c,strokeWidth:`2.15`,strokeLinecap:`round`,pathLength:100,className:`vt-error-line-2`})]}),e===`warning`&&/* @__PURE__ */ T(C,{children:[/* @__PURE__ */ w(`path`,{d:H,fill:`currentColor`,className:`vt-warning-fill`}),/* @__PURE__ */ w(`path`,{d:H,stroke:c,strokeWidth:`1.75`,strokeLinejoin:`round`,pathLength:100,className:`vt-warning-frame`}),/* @__PURE__ */ w(`path`,{d:`M12 9.1V13.15`,stroke:c,strokeWidth:`2.1`,strokeLinecap:`round`,pathLength:100,className:`vt-warning-stem`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`16.1`,r:`1.2`,fill:c,className:`vt-warning-dot`})]}),e===`info`&&/* @__PURE__ */ T(C,{children:[/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`8.75`,fill:`currentColor`,className:`vt-info-fill`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`8.75`,stroke:c,strokeWidth:`1.75`,pathLength:100,className:`vt-info-ring`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`8.75`,stroke:`#fff`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeDasharray:`16 84`,pathLength:100,className:`vt-info-glint`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`8.25`,r:`1.25`,fill:c,className:`vt-info-dot`}),/* @__PURE__ */ w(`path`,{d:`M12 11.2V16.1`,stroke:c,strokeWidth:`2.15`,strokeLinecap:`round`,pathLength:100,className:`vt-info-stem`})]}),e===`loading`&&/* @__PURE__ */ T(C,{children:[/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeOpacity:`0.18`,strokeWidth:`1.8`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:c,strokeWidth:`2.1`,strokeLinecap:`round`,pathLength:100,className:`vt-loader-outer`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`5.3`,stroke:`url(#${s})`,strokeWidth:`1.65`,strokeLinecap:`round`,strokeDasharray:`34 66`,pathLength:100,className:`vt-loader-inner`}),/* @__PURE__ */ w(`circle`,{cx:`12`,cy:`12`,r:`2.1`,fill:`currentColor`,className:`vt-loader-core`})]})]})})]},e)}function K({duration:e,paused:n,variant:r,resetKey:i,position:a=`bottom`,height:s=3,trackClassName:c,barClassName:l}){if(!o(e))return null;let u={height:`${Math.max(1,s)}px`},d={animationDuration:`${e}ms`,animationPlayState:n?`paused`:`running`};return/* @__PURE__ */ w(`div`,{className:t(`vt-progress-track`,c),style:u,"aria-hidden":`true`,"data-vt-progress":``,"data-vt-progress-position":a,children:/* @__PURE__ */ w(`div`,{className:t(`vt-progress-bar`,l),"data-vt-variant":r,style:d},i)})}var ne=m(function({toast:e,index:r,total:i,position:a,expanded:o,store:s,cfg:c}){let l=c.pauseOnHover&&e.pauseOnHover,u=c.pauseOnFocus&&e.pauseOnFocus,d=c.showProgress&&e.showProgress&&e.status!==`exiting`,f=(e.closeButton??c.closeButton)&&e.dismissible,m=e.closeButtonPosition??c.closeButtonPosition,g=p(c.classNames,e.classNames),_=e.icon===void 0?c.icons&&e.variant!=="default"&&e.variant!==`custom`?c.icons[e.variant]:void 0:e.icon,v=h(()=>{s.dismiss(e.id,`user`)},[s,e.id]),{swipeState:y,handlers:b}=B({enabled:c.swipeToDismiss&&e.swipeToDismiss&&e.dismissible,position:a,directions:e.swipeDirections??c.swipeDirections,onSwipeStart:h(()=>s.pause(e.id,`swipe`),[s,e.id]),onSwipeCancel:h(()=>s.resume(e.id,`swipe`),[s,e.id]),onDismiss:v}),x=t=>{!u||t.relatedTarget&&t.currentTarget.contains(t.relatedTarget)||s.resume(e.id,`focus`)},S=t=>{t.key===`Escape`&&e.dismissible&&(t.stopPropagation(),v())},C={...e.style,"--vt-index":String(r),"--vt-z-index":String(Math.max(1,i-r)),"--vt-swipe-x":`${y.offsetX}px`,"--vt-swipe-y":`${y.offsetY}px`,"--vt-swipe-opacity":String(y.opacity)},E=f?/* @__PURE__ */ w(`button`,{type:`button`,className:t(`vt-close`,m===`floating`&&`vt-close-floating`,m===`top-left`&&`vt-close-left`,(e.showCloseOnHover??c.showCloseOnHover)&&`vt-close-hover-only`,g?.closeButton),"aria-label":`Dismiss notification`,"data-vt-close":``,"data-vt-close-position":m,onClick:v,children:c.icons?.close===void 0?/* @__PURE__ */ w(`svg`,{viewBox:`0 0 16 16`,fill:`none`,className:`vt-close-svg`,"aria-hidden":`true`,children:/* @__PURE__ */ w(`path`,{d:`M4.5 4.5L11.5 11.5M11.5 4.5L4.5 11.5`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`})}):c.icons.close}):null;return/* @__PURE__ */ w(`li`,{className:t(`vt-toast-slot`,o&&`vt-toast-slot-expanded`),"data-vt-slot":``,"data-vt-index":r,"data-vt-front":r===0?`true`:`false`,"data-vt-status":e.status,style:C,children:/* @__PURE__ */ T(`div`,{className:t(`vt-toast`,c.richColors&&`vt-toast-rich`,y.isSwiping&&`vt-toast-swiping`,m===`floating`&&`vt-toast-floating-close`,c.toastClassName,g?.toast,e.className),role:e.role,"aria-live":e.role===`alert`?`assertive`:`polite`,"aria-atomic":`true`,"aria-label":e.ariaLabel,tabIndex:0,"data-vt-toast":``,"data-vt-id":e.id,"data-vt-variant":e.variant,"data-vt-status":e.status,"data-vt-paused":e.paused?`true`:`false`,"data-vt-swiping":y.isSwiping?`true`:`false`,"data-vt-position":a,"data-vt-glass":e.glass??c.glass,"data-vt-radius":e.radius??c.radius,"data-vt-size":e.size??c.size,"data-vt-glow":e.ambientGlow??c.ambientGlow?`true`:`false`,"data-vt-animation":e.animation??c.animation,onMouseEnter:()=>l&&s.pause(e.id,`hover`),onMouseLeave:()=>l&&s.resume(e.id,`hover`),onFocus:()=>u&&s.pause(e.id,`focus`),onBlur:x,onKeyDown:S,...b,children:[m===`floating`&&E,e.variant===`custom`&&typeof e.customRender==`function`?/* @__PURE__ */ w(`div`,{className:`vt-custom-content`,children:e.customRender({id:e.id,toast:e,dismiss:v,pause:()=>s.pause(e.id,`manual`),resume:()=>s.resume(e.id,`manual`)})}):/* @__PURE__ */ T(`div`,{className:t(`vt-body`,g?.body),children:[m===`top-left`&&E,/* @__PURE__ */ w(G,{variant:e.variant,icon:_,animationMode:n(e.iconAnimation??c.iconAnimation),className:g?.icon}),/* @__PURE__ */ T(`div`,{className:t(`vt-content`,g?.content),children:[/* @__PURE__ */ T(`div`,{className:`vt-header`,children:[e.title!=null&&/* @__PURE__ */ w(`div`,{className:t(`vt-title`,g?.title),"data-vt-title":``,children:e.title}),e.count>1&&/* @__PURE__ */ T(`span`,{className:t(`vt-count-badge`,g?.countBadge),title:`${e.count} occurrences`,"data-vt-count":e.count,children:[`×`,e.count]})]}),e.description!=null&&/* @__PURE__ */ w(`div`,{className:t(`vt-description`,g?.description),"data-vt-description":``,children:e.description}),(e.action||e.cancel)&&/* @__PURE__ */ T(`div`,{className:t(`vt-actions`,g?.actions),"data-vt-actions":``,children:[e.action&&/* @__PURE__ */ w(`button`,{type:`button`,className:t(`vt-btn vt-btn-primary`,g?.actionButton),"aria-label":e.action.ariaLabel,onClick:t=>e.action?.onClick(t),children:e.action.label}),e.cancel&&/* @__PURE__ */ w(`button`,{type:`button`,className:t(`vt-btn vt-btn-secondary`,g?.cancelButton),"aria-label":e.cancel.ariaLabel,onClick:t=>e.cancel?.onClick(t),children:e.cancel.label})]})]}),m===`top-right`&&E]}),d&&/* @__PURE__ */ w(K,{duration:e.duration,paused:e.paused,variant:e.variant,position:e.progressPosition??c.progressPosition,height:e.progressHeight??c.progressHeight,trackClassName:g?.progress,barClassName:g?.progressBar,resetKey:`${e.id}-${e.duration}-${e.count}-${e.variant}`})]})})}),re=[`top-left`,`top-center`,`top-right`,`bottom-left`,`bottom-center`,`bottom-right`],ie=[`altKey`,`KeyT`];function ae(e,t){return t.length!==0&&t.every(t=>t===`altKey`?e.altKey:t===`ctrlKey`?e.ctrlKey:t===`metaKey`?e.metaKey:t===`shiftKey`?e.shiftKey:e.code===t||e.key.toLowerCase()===t.toLowerCase())}function q({position:e=`top-right`,theme:n=`dark`,duration:i=4e3,visibleToasts:a=4,gap:o=12,offset:s=20,expand:l=!1,glass:u=`frosted`,radius:d=`md`,size:f=`default`,ambientGlow:p=!0,themeTokens:m,animation:h=`bounce`,iconAnimation:_=`default`,progressPosition:x=`bottom`,progressHeight:T=3,pauseOnHover:E=!0,pauseOnFocus:D=!0,swipeToDismiss:O=!0,swipeDirections:A,showProgress:M=!1,closeButton:N=!0,closeButtonPosition:P=`floating`,showCloseOnHover:F=!0,preventDuplicates:R=!1,richColors:z=!1,icons:B,classNames:V,hotkey:H=ie,sound:U=!0,haptic:W=!0,onToastShow:G,toastOptions:K,dir:q=`ltr`,className:oe,toastClassName:J,style:se,containerAriaLabel:ce=`Notifications`,portalContainer:le,exitDuration:ue=240,store:Y=c}){let de=ee(),fe=j(n),{toasts:X}=te(Y),[pe,Z]=b(null),[me,he]=b(null),Q=y(/* @__PURE__ */ new Set),$=h===`none`?0:ue;g(()=>{Y.configure({defaultDuration:i,visibleToasts:a,exitDuration:$,preventDuplicates:R,toastOptions:K})},[i,$,R,Y,K,a]),g(()=>{if(!k())return;let e=()=>{document.hidden?Y.pauseAll(`document-hidden`):Y.resumeAll(`document-hidden`)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[Y]),g(()=>{if(!k()||H.length===0)return;let e=e=>{if(!ae(e,H))return;let t=document.querySelector(`[data-vt-toast]`);t&&(e.preventDefault(),t.focus())};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[H]),g(()=>{let e=/* @__PURE__ */ new Set;for(let t of X)e.add(t.id),t.status!==`exiting`&&!Q.current.has(t.id)&&(Q.current.add(t.id),G?.(t),(t.sound??U)&&I(t.variant),(t.haptic??W)&&L(t.variant));for(let t of Q.current)e.has(t)||Q.current.delete(t)},[W,G,U,X]);let ge=v(()=>r(m),[m]),_e=v(()=>{let t=/* @__PURE__ */ new Map;for(let n of X){let r=n.position??e,i=t.get(r);i?i.push(n):t.set(r,[n])}return t},[e,X]),ve=v(()=>({glass:u,radius:d,size:f,ambientGlow:p,animation:h,iconAnimation:_,closeButton:N,closeButtonPosition:P,showCloseOnHover:F,showProgress:M,progressPosition:x,progressHeight:T,pauseOnHover:E,pauseOnFocus:D,swipeToDismiss:O,swipeDirections:A,richColors:z,icons:B,classNames:V,toastClassName:J}),[u,d,f,p,h,_,N,P,F,M,x,T,E,D,O,A,z,B,V,J]);if(!de||!k())return null;let ye=le??document.body;if(!ye)return null;let be=typeof s==`number`?`${s}px`:s,xe=re.filter(e=>{let t=_e.get(e);return t&&t.length>0});if(xe.length===0)return null;let Se=/* @__PURE__ */ w(C,{children:xe.map(e=>{let n=[..._e.get(e)??[]].reverse(),r=l||pe===e||me===e,i={...ge,...se,"--vt-gap":`${o}px`,"--vt-offset":be};return/* @__PURE__ */ w(`section`,{"aria-label":ce,dir:q,className:t(`vt-toaster`,V?.toaster,oe),"data-vt-toaster":``,"data-vt-theme":fe,"data-vt-position":e,"data-vt-expanded":r?`true`:`false`,style:i,onMouseEnter:()=>Z(e),onMouseLeave:()=>Z(t=>t===e?null:t),onFocus:()=>he(e),onBlur:t=>{t.relatedTarget&&t.currentTarget.contains(t.relatedTarget)||he(t=>t===e?null:t)},children:/* @__PURE__ */ w(`ol`,{className:t(`vt-list`,V?.list),"data-vt-list":``,children:n.map((t,i)=>/* @__PURE__ */ w(ne,{toast:t,index:i,total:n.length,position:e,expanded:r,store:Y,cfg:ve},t.id))})},e)})});return S(Se,ye)}export{u as EMPTY_SNAPSHOT,d as PauseableTimer,a as ToastStore,q as Toaster,f as createToastApi,e as createToastStore,c as defaultToastStore,I as playToastSound,s as toast,r as tokensToCssVars,L as triggerToastHaptic,ee as useMounted,j as useResolvedTheme,te as useToasts};
|