@tomny-dev/uzi 0.2.5 → 0.2.6-pr.22.67.1.9e9e57c
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/components/auth-card/AuthCard.d.ts +24 -0
- package/dist/components/auth-card/AuthCard.d.ts.map +1 -0
- package/dist/components/auth-card/AuthCard.test.d.ts +2 -0
- package/dist/components/auth-card/AuthCard.test.d.ts.map +1 -0
- package/dist/index.cjs +67 -1925
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -1858
- package/dist/index10.cjs +26 -0
- package/dist/index10.cjs.map +1 -0
- package/dist/index10.js +19 -0
- package/dist/index10.js.map +1 -0
- package/dist/index11.cjs +22 -0
- package/dist/index11.cjs.map +1 -0
- package/dist/index11.js +22 -0
- package/dist/index11.js.map +1 -0
- package/dist/index12.cjs +22 -0
- package/dist/index12.cjs.map +1 -0
- package/dist/index12.js +41 -0
- package/dist/index12.js.map +1 -0
- package/dist/index13.cjs +56 -0
- package/dist/index13.cjs.map +1 -0
- package/dist/index13.js +84 -0
- package/dist/index13.js.map +1 -0
- package/dist/index14.cjs +87 -0
- package/dist/index14.cjs.map +1 -0
- package/dist/index14.js +17 -0
- package/dist/index14.js.map +1 -0
- package/dist/index15.cjs +22 -0
- package/dist/index15.cjs.map +1 -0
- package/dist/index15.js +16 -0
- package/dist/index15.js.map +1 -0
- package/dist/index16.cjs +16 -0
- package/dist/index16.cjs.map +1 -0
- package/dist/index16.js +45 -0
- package/dist/index16.js.map +1 -0
- package/dist/index17.cjs +64 -0
- package/dist/index17.cjs.map +1 -0
- package/dist/index17.js +435 -0
- package/dist/index17.js.map +1 -0
- package/dist/index18.cjs +438 -0
- package/dist/index18.cjs.map +1 -0
- package/dist/index18.js +7 -0
- package/dist/index18.js.map +1 -0
- package/dist/index19.cjs +8 -0
- package/dist/index19.cjs.map +1 -0
- package/dist/index19.js +18 -0
- package/dist/index19.js.map +1 -0
- package/dist/index2.cjs +23 -0
- package/dist/index20.cjs +20 -0
- package/dist/index20.cjs.map +1 -0
- package/dist/index20.js +7 -0
- package/dist/index20.js.map +1 -0
- package/dist/index21.cjs +8 -0
- package/dist/index21.cjs.map +1 -0
- package/dist/index21.js +15 -0
- package/dist/index21.js.map +1 -0
- package/dist/index22.cjs +17 -0
- package/dist/index22.cjs.map +1 -0
- package/dist/index22.js +7 -0
- package/dist/index22.js.map +1 -0
- package/dist/index23.cjs +8 -0
- package/dist/index23.cjs.map +1 -0
- package/dist/index23.js +18 -0
- package/dist/index23.js.map +1 -0
- package/dist/index24.cjs +20 -0
- package/dist/index24.cjs.map +1 -0
- package/dist/index24.js +41 -0
- package/dist/index24.js.map +1 -0
- package/dist/index25.cjs +58 -0
- package/dist/index25.cjs.map +1 -0
- package/dist/index25.js +123 -0
- package/dist/index25.js.map +1 -0
- package/dist/index26.cjs +126 -0
- package/dist/index26.cjs.map +1 -0
- package/dist/index26.js +29 -0
- package/dist/index26.js.map +1 -0
- package/dist/index27.cjs +40 -0
- package/dist/index27.cjs.map +1 -0
- package/dist/index27.js +110 -0
- package/dist/index27.js.map +1 -0
- package/dist/index28.cjs +113 -0
- package/dist/index28.cjs.map +1 -0
- package/dist/index28.js +26 -0
- package/dist/index28.js.map +1 -0
- package/dist/index29.cjs +28 -0
- package/dist/index29.cjs.map +1 -0
- package/dist/index29.js +29 -0
- package/dist/index29.js.map +1 -0
- package/dist/index3.js +8 -0
- package/dist/index3.js.map +1 -0
- package/dist/index30.cjs +40 -0
- package/dist/index30.cjs.map +1 -0
- package/dist/index30.js +118 -0
- package/dist/index30.js.map +1 -0
- package/dist/index31.cjs +134 -0
- package/dist/index31.cjs.map +1 -0
- package/dist/index31.js +20 -0
- package/dist/index31.js.map +1 -0
- package/dist/index32.cjs +23 -0
- package/dist/index32.cjs.map +1 -0
- package/dist/index32.js +114 -0
- package/dist/index32.js.map +1 -0
- package/dist/index33.cjs +115 -0
- package/dist/index33.cjs.map +1 -0
- package/dist/index33.js +7 -0
- package/dist/index33.js.map +1 -0
- package/dist/index34.cjs +8 -0
- package/dist/index34.cjs.map +1 -0
- package/dist/index34.js +66 -0
- package/dist/index34.js.map +1 -0
- package/dist/index35.cjs +66 -0
- package/dist/index35.cjs.map +1 -0
- package/dist/index35.js +25 -0
- package/dist/index35.js.map +1 -0
- package/dist/index36.cjs +34 -0
- package/dist/index36.cjs.map +1 -0
- package/dist/index36.js +55 -0
- package/dist/index36.js.map +1 -0
- package/dist/index37.cjs +55 -0
- package/dist/index37.cjs.map +1 -0
- package/dist/index37.js +35 -0
- package/dist/index37.js.map +1 -0
- package/dist/index38.cjs +49 -0
- package/dist/index38.cjs.map +1 -0
- package/dist/index38.js +150 -0
- package/dist/index38.js.map +1 -0
- package/dist/index39.cjs +150 -0
- package/dist/index39.cjs.map +1 -0
- package/dist/index39.js +43 -0
- package/dist/index39.js.map +1 -0
- package/dist/index4.cjs +8 -0
- package/dist/index4.cjs.map +1 -0
- package/dist/index4.js +29 -0
- package/dist/index4.js.map +1 -0
- package/dist/index40.cjs +61 -0
- package/dist/index40.cjs.map +1 -0
- package/dist/index40.js +173 -0
- package/dist/index40.js.map +1 -0
- package/dist/index41.cjs +173 -0
- package/dist/index41.cjs.map +1 -0
- package/dist/index41.js +14 -0
- package/dist/index41.js.map +1 -0
- package/dist/index42.cjs +15 -0
- package/dist/index42.cjs.map +1 -0
- package/dist/index42.js +21 -0
- package/dist/index42.js.map +1 -0
- package/dist/index43.cjs +21 -0
- package/dist/index43.cjs.map +1 -0
- package/dist/index43.js +15 -0
- package/dist/index43.js.map +1 -0
- package/dist/index44.cjs +17 -0
- package/dist/index44.cjs.map +1 -0
- package/dist/index44.js +24 -0
- package/dist/index44.js.map +1 -0
- package/dist/index45.cjs +24 -0
- package/dist/index45.cjs.map +1 -0
- package/dist/index45.js +13 -0
- package/dist/index45.js.map +1 -0
- package/dist/index46.cjs +16 -0
- package/dist/index46.cjs.map +1 -0
- package/dist/index46.js +96 -0
- package/dist/index46.js.map +1 -0
- package/dist/index47.cjs +98 -0
- package/dist/index47.cjs.map +1 -0
- package/dist/index47.js +25 -0
- package/dist/index47.js.map +1 -0
- package/dist/index48.cjs +34 -0
- package/dist/index48.cjs.map +1 -0
- package/dist/index48.js +50 -0
- package/dist/index48.js.map +1 -0
- package/dist/index49.cjs +52 -0
- package/dist/index49.cjs.map +1 -0
- package/dist/index5.cjs +40 -0
- package/dist/index5.cjs.map +1 -0
- package/dist/index5.js +45 -0
- package/dist/index5.js.map +1 -0
- package/dist/index6.cjs +47 -0
- package/dist/index6.cjs.map +1 -0
- package/dist/index6.js +17 -0
- package/dist/index6.js.map +1 -0
- package/dist/index7.cjs +20 -0
- package/dist/index7.cjs.map +1 -0
- package/dist/index7.js +30 -0
- package/dist/index7.js.map +1 -0
- package/dist/index8.cjs +35 -0
- package/dist/index8.cjs.map +1 -0
- package/dist/index8.js +18 -0
- package/dist/index8.js.map +1 -0
- package/dist/index9.cjs +20 -0
- package/dist/index9.cjs.map +1 -0
- package/dist/index9.js +26 -0
- package/dist/index9.js.map +1 -0
- package/dist/style.css +84 -0
- package/package.json +1 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index17.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/components/toast/toast.module.css
|
|
2
|
+
var stack = "uzi-toast-module__stack__SRrda";
|
|
3
|
+
var topRight = "uzi-toast-module__topRight__WiZzM";
|
|
4
|
+
var topLeft = "uzi-toast-module__topLeft__SzFS9";
|
|
5
|
+
var topCenter = "uzi-toast-module__topCenter__X5W-x";
|
|
6
|
+
var bottomRight = "uzi-toast-module__bottomRight__DMtoS";
|
|
7
|
+
var bottomLeft = "uzi-toast-module__bottomLeft__ZZ7VF";
|
|
8
|
+
var bottomCenter = "uzi-toast-module__bottomCenter__QNJrM";
|
|
9
|
+
var toast = "uzi-toast-module__toast__HNUcj";
|
|
10
|
+
var toastSlideIn = "uzi-toast-module__toastSlideIn__BTXfm";
|
|
11
|
+
var toastSlideOut = "uzi-toast-module__toastSlideOut__mBX-G";
|
|
12
|
+
var toastSwipeOut = "uzi-toast-module__toastSwipeOut__R-jk2";
|
|
13
|
+
var icon = "uzi-toast-module__icon__LIAqr";
|
|
14
|
+
var body = "uzi-toast-module__body__9vzs7";
|
|
15
|
+
var message = "uzi-toast-module__message__TBY65";
|
|
16
|
+
var actions = "uzi-toast-module__actions__Iykd9";
|
|
17
|
+
var actionButton = "uzi-toast-module__actionButton__cvUr0";
|
|
18
|
+
var controls = "uzi-toast-module__controls__LqA4Q";
|
|
19
|
+
var iconButton = "uzi-toast-module__iconButton__FOsOp";
|
|
20
|
+
var iconButtonError = "uzi-toast-module__iconButtonError__NJsLX";
|
|
21
|
+
var toast_module_default = {
|
|
22
|
+
stack,
|
|
23
|
+
topRight,
|
|
24
|
+
topLeft,
|
|
25
|
+
topCenter,
|
|
26
|
+
bottomRight,
|
|
27
|
+
bottomLeft,
|
|
28
|
+
bottomCenter,
|
|
29
|
+
toast,
|
|
30
|
+
toastSlideIn,
|
|
31
|
+
toastSlideOut,
|
|
32
|
+
toastSwipeOut,
|
|
33
|
+
icon,
|
|
34
|
+
body,
|
|
35
|
+
message,
|
|
36
|
+
actions,
|
|
37
|
+
actionButton,
|
|
38
|
+
controls,
|
|
39
|
+
iconButton,
|
|
40
|
+
iconButtonError
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.actionButton = actionButton;
|
|
44
|
+
exports.actions = actions;
|
|
45
|
+
exports.body = body;
|
|
46
|
+
exports.bottomCenter = bottomCenter;
|
|
47
|
+
exports.bottomLeft = bottomLeft;
|
|
48
|
+
exports.bottomRight = bottomRight;
|
|
49
|
+
exports.controls = controls;
|
|
50
|
+
exports.default = toast_module_default;
|
|
51
|
+
exports.icon = icon;
|
|
52
|
+
exports.iconButton = iconButton;
|
|
53
|
+
exports.iconButtonError = iconButtonError;
|
|
54
|
+
exports.message = message;
|
|
55
|
+
exports.stack = stack;
|
|
56
|
+
exports.toast = toast;
|
|
57
|
+
exports.toastSlideIn = toastSlideIn;
|
|
58
|
+
exports.toastSlideOut = toastSlideOut;
|
|
59
|
+
exports.toastSwipeOut = toastSwipeOut;
|
|
60
|
+
exports.topCenter = topCenter;
|
|
61
|
+
exports.topLeft = topLeft;
|
|
62
|
+
exports.topRight = topRight;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=index17.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index17.cjs","names":[],"sources":["../src/components/toast/toast.module.css"],"sourcesContent":[".stack {\n position: fixed;\n z-index: 2147483000;\n display: flex;\n flex-direction: column;\n gap: 10px;\n pointer-events: none;\n}\n\n.topRight {\n top: 16px;\n right: 16px;\n align-items: flex-end;\n}\n\n.topLeft {\n top: 16px;\n left: 16px;\n align-items: flex-start;\n}\n\n.topCenter {\n top: 16px;\n left: 50%;\n transform: translateX(-50%);\n align-items: center;\n}\n\n.bottomRight {\n bottom: 16px;\n right: 16px;\n align-items: flex-end;\n}\n\n.bottomLeft {\n bottom: 16px;\n left: 16px;\n align-items: flex-start;\n}\n\n.bottomCenter {\n bottom: 16px;\n left: 50%;\n transform: translateX(-50%);\n align-items: center;\n}\n\n.toast {\n pointer-events: auto;\n position: relative;\n display: flex;\n align-items: flex-start;\n gap: 10px;\n min-width: 280px;\n max-width: min(420px, calc(100vw - 32px));\n padding: 12px 12px 12px 14px;\n border-radius: 10px;\n border: 1px solid var(--toast-border, var(--border));\n background: var(--toast-bg, var(--popover));\n color: var(--toast-text, var(--popover-foreground));\n box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);\n overflow: hidden;\n animation: toastSlideIn 180ms ease-out;\n}\n\n/* Left accent strip */\n.toast::before {\n content: \"\";\n position: absolute;\n left: 0;\n top: 0;\n bottom: 0;\n width: 3px;\n background: var(--toast-accent, transparent);\n border-radius: 10px 0 0 10px;\n}\n\n.toast[data-state=\"closed\"] {\n animation: toastSlideOut 160ms ease-in forwards;\n}\n\n.toast[data-swipe=\"move\"] {\n transform: translateX(var(--radix-toast-swipe-move-x));\n}\n\n.toast[data-swipe=\"cancel\"] {\n transform: translateX(0);\n transition: transform 180ms ease-out;\n}\n\n.toast[data-swipe=\"end\"] {\n animation: toastSwipeOut 160ms ease-out forwards;\n}\n\n.icon {\n width: 18px;\n height: 18px;\n flex-shrink: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--toast-accent, var(--foreground));\n margin-top: 1px;\n}\n\n.body {\n flex: 1;\n min-width: 0;\n display: grid;\n gap: 6px;\n}\n\n.message {\n word-break: break-word;\n font-size: 14px;\n line-height: 1.4;\n}\n\n.actions {\n display: flex;\n gap: 6px;\n flex-wrap: wrap;\n}\n\n.actionButton {\n padding: 5px 10px;\n font-size: 12px;\n font-weight: 600;\n border-radius: 6px;\n border: 1px solid var(--toast-action-border, var(--border));\n background: var(--toast-action-bg, color-mix(in srgb, var(--foreground) 8%, transparent));\n color: var(--toast-text, var(--popover-foreground));\n cursor: pointer;\n transition: background 120ms ease;\n}\n\n.actionButton:hover {\n background: color-mix(in srgb, var(--toast-action-bg, var(--foreground)), var(--foreground) 10%);\n}\n\n.controls {\n flex-shrink: 0;\n display: flex;\n align-items: center;\n gap: 2px;\n margin: -2px -2px -2px 0;\n}\n\n.iconButton {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 22px;\n height: 22px;\n padding: 0;\n border: none;\n border-radius: 5px;\n background: transparent;\n color: var(--toast-text, var(--popover-foreground));\n opacity: 0.5;\n cursor: pointer;\n transition: opacity 120ms ease, background 120ms ease;\n}\n\n.iconButton:hover {\n opacity: 1;\n background: color-mix(in srgb, var(--foreground) 8%, transparent);\n}\n\n.iconButtonError {\n opacity: 1;\n color: var(--destructive);\n}\n\n.iconButton:focus-visible,\n.actionButton:focus-visible {\n outline: var(--focus-ring);\n outline-offset: var(--focus-ring-offset);\n}\n\n@keyframes toastSlideIn {\n from {\n opacity: 0;\n transform: translateY(-8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes toastSlideOut {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(-6px);\n }\n}\n\n@keyframes toastSwipeOut {\n from {\n opacity: 1;\n transform: translateX(var(--radix-toast-swipe-end-x));\n }\n\n to {\n opacity: 0;\n transform: translateX(calc(var(--radix-toast-swipe-end-x) * 1.05));\n }\n}\n"],"mappings":""}
|
package/dist/index17.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "./index3.js";
|
|
3
|
+
import toast_module_default from "./index16.js";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import * as ToastPrimitive from "@radix-ui/react-toast";
|
|
7
|
+
//#region src/components/toast/ToastContext.tsx
|
|
8
|
+
/** Default provider configuration. */
|
|
9
|
+
var DEFAULT_CONFIG = {
|
|
10
|
+
position: "top-right",
|
|
11
|
+
maxToasts: 5,
|
|
12
|
+
defaultDuration: 4e3,
|
|
13
|
+
pauseOnHover: true,
|
|
14
|
+
pauseOnFocusLoss: true
|
|
15
|
+
};
|
|
16
|
+
var ToastContext = createContext(void 0);
|
|
17
|
+
var toastIdCounter = 0;
|
|
18
|
+
var generateToastId = () => `toast-${++toastIdCounter}-${Date.now()}`;
|
|
19
|
+
/**
|
|
20
|
+
* Toast notification context provider.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Wrap your app (or a section) to enable `useToast` calls. Supports configurable placement,
|
|
24
|
+
* maximum visible toasts, and pause behavior on hover or window blur.
|
|
25
|
+
*
|
|
26
|
+
* @param props.children - React subtree that can consume the toast context.
|
|
27
|
+
* @param props.config - Optional provider configuration overrides.
|
|
28
|
+
*/
|
|
29
|
+
function ToastProvider({ children, config }) {
|
|
30
|
+
const [toasts, setToasts] = useState([]);
|
|
31
|
+
const [isPaused, setIsPaused] = useState(false);
|
|
32
|
+
const merged = useMemo(() => ({
|
|
33
|
+
...DEFAULT_CONFIG,
|
|
34
|
+
...config
|
|
35
|
+
}), [config]);
|
|
36
|
+
const push = useCallback((message, options = {}) => {
|
|
37
|
+
const id = generateToastId();
|
|
38
|
+
setToasts((prev) => {
|
|
39
|
+
const next = [...prev, {
|
|
40
|
+
id,
|
|
41
|
+
message,
|
|
42
|
+
type: options.type ?? "info",
|
|
43
|
+
duration: options.duration ?? (options.type === "error" ? 6e3 : merged.defaultDuration),
|
|
44
|
+
dismissible: options.dismissible ?? true,
|
|
45
|
+
copyable: options.copyable ?? false,
|
|
46
|
+
action: options.action
|
|
47
|
+
}];
|
|
48
|
+
if (next.length > merged.maxToasts) next.shift();
|
|
49
|
+
return next;
|
|
50
|
+
});
|
|
51
|
+
return id;
|
|
52
|
+
}, [merged.defaultDuration, merged.maxToasts]);
|
|
53
|
+
const success = useCallback((message, options) => push(message, {
|
|
54
|
+
...options,
|
|
55
|
+
type: "success"
|
|
56
|
+
}), [push]);
|
|
57
|
+
const error = useCallback((message, options) => push(message, {
|
|
58
|
+
copyable: true,
|
|
59
|
+
...options,
|
|
60
|
+
type: "error"
|
|
61
|
+
}), [push]);
|
|
62
|
+
const warning = useCallback((message, options) => push(message, {
|
|
63
|
+
...options,
|
|
64
|
+
type: "warning"
|
|
65
|
+
}), [push]);
|
|
66
|
+
const info = useCallback((message, options) => push(message, {
|
|
67
|
+
...options,
|
|
68
|
+
type: "info"
|
|
69
|
+
}), [push]);
|
|
70
|
+
const dismiss = useCallback((id) => {
|
|
71
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
72
|
+
}, []);
|
|
73
|
+
const dismissAll = useCallback(() => setToasts([]), []);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!merged.pauseOnFocusLoss) return;
|
|
76
|
+
const handleVisibility = () => setIsPaused(document.visibilityState !== "visible");
|
|
77
|
+
document.addEventListener("visibilitychange", handleVisibility);
|
|
78
|
+
return () => document.removeEventListener("visibilitychange", handleVisibility);
|
|
79
|
+
}, [merged.pauseOnFocusLoss]);
|
|
80
|
+
const value = useMemo(() => ({
|
|
81
|
+
toasts,
|
|
82
|
+
push,
|
|
83
|
+
success,
|
|
84
|
+
error,
|
|
85
|
+
warning,
|
|
86
|
+
info,
|
|
87
|
+
dismiss,
|
|
88
|
+
dismissAll
|
|
89
|
+
}), [
|
|
90
|
+
toasts,
|
|
91
|
+
push,
|
|
92
|
+
success,
|
|
93
|
+
error,
|
|
94
|
+
warning,
|
|
95
|
+
info,
|
|
96
|
+
dismiss,
|
|
97
|
+
dismissAll
|
|
98
|
+
]);
|
|
99
|
+
return /* @__PURE__ */ jsx(ToastContext.Provider, {
|
|
100
|
+
value,
|
|
101
|
+
children: /* @__PURE__ */ jsxs(ToastPrimitive.Provider, {
|
|
102
|
+
swipeDirection: "right",
|
|
103
|
+
children: [children, /* @__PURE__ */ jsx(ToastContainer, {
|
|
104
|
+
toasts,
|
|
105
|
+
position: merged.position,
|
|
106
|
+
pauseOnHover: merged.pauseOnHover,
|
|
107
|
+
isPaused,
|
|
108
|
+
onDismiss: dismiss,
|
|
109
|
+
onPauseChange: setIsPaused
|
|
110
|
+
})]
|
|
111
|
+
})
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Hook to access the toast API.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* Exposes `push`, intent helpers (`success`, `error`, `warning`, `info`), and dismissal helpers.
|
|
119
|
+
* Must be called within a `ToastProvider`.
|
|
120
|
+
*
|
|
121
|
+
* @throws Error if used outside of a `ToastProvider`.
|
|
122
|
+
*/
|
|
123
|
+
function useToast() {
|
|
124
|
+
const ctx = useContext(ToastContext);
|
|
125
|
+
if (!ctx) throw new Error("useToast must be used within a ToastProvider");
|
|
126
|
+
return ctx;
|
|
127
|
+
}
|
|
128
|
+
/** Renders the positioned toast stack. */
|
|
129
|
+
function ToastContainer({ toasts, position, pauseOnHover, isPaused, onDismiss, onPauseChange }) {
|
|
130
|
+
const posClass = (() => {
|
|
131
|
+
switch (position) {
|
|
132
|
+
case "top-left": return "topLeft";
|
|
133
|
+
case "top-center": return "topCenter";
|
|
134
|
+
case "bottom-right": return "bottomRight";
|
|
135
|
+
case "bottom-left": return "bottomLeft";
|
|
136
|
+
case "bottom-center": return "bottomCenter";
|
|
137
|
+
default: return "topRight";
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [toasts.map((toast) => /* @__PURE__ */ jsx(ToastItem, {
|
|
141
|
+
toast,
|
|
142
|
+
isPaused,
|
|
143
|
+
onDismiss
|
|
144
|
+
}, toast.id)), /* @__PURE__ */ jsx(ToastPrimitive.Viewport, {
|
|
145
|
+
className: cx(toast_module_default.stack, toast_module_default[posClass]),
|
|
146
|
+
label: "Notifications",
|
|
147
|
+
onMouseEnter: () => pauseOnHover && onPauseChange(true),
|
|
148
|
+
onMouseLeave: () => pauseOnHover && onPauseChange(false)
|
|
149
|
+
})] });
|
|
150
|
+
}
|
|
151
|
+
/** Individual toast item with timers and actions. */
|
|
152
|
+
function ToastItem({ toast, isPaused, onDismiss }) {
|
|
153
|
+
const [open, setOpen] = useState(true);
|
|
154
|
+
const [copyState, setCopyState] = useState("idle");
|
|
155
|
+
const copyTimerRef = useRef(null);
|
|
156
|
+
const timerRef = useRef(null);
|
|
157
|
+
const startRef = useRef(0);
|
|
158
|
+
const remainingRef = useRef(toast.duration ?? 0);
|
|
159
|
+
const closingRef = useRef(false);
|
|
160
|
+
const palette = getPalette(toast.type);
|
|
161
|
+
const styleVars = {
|
|
162
|
+
["--toast-bg"]: palette.background,
|
|
163
|
+
["--toast-border"]: palette.border,
|
|
164
|
+
["--toast-accent"]: palette.accent,
|
|
165
|
+
["--toast-text"]: palette.text,
|
|
166
|
+
["--toast-action-bg"]: palette.actionBg,
|
|
167
|
+
["--toast-action-border"]: palette.actionBorder
|
|
168
|
+
};
|
|
169
|
+
const stopTimer = () => {
|
|
170
|
+
if (timerRef.current) {
|
|
171
|
+
window.clearTimeout(timerRef.current);
|
|
172
|
+
timerRef.current = null;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const triggerDismiss = useCallback(() => {
|
|
176
|
+
if (closingRef.current) return;
|
|
177
|
+
closingRef.current = true;
|
|
178
|
+
setOpen(false);
|
|
179
|
+
stopTimer();
|
|
180
|
+
window.setTimeout(() => onDismiss(toast.id), 160);
|
|
181
|
+
}, [onDismiss, toast.id]);
|
|
182
|
+
const schedule = useCallback((delay) => {
|
|
183
|
+
if (!delay || delay <= 0) {
|
|
184
|
+
triggerDismiss();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
startRef.current = performance.now();
|
|
188
|
+
stopTimer();
|
|
189
|
+
timerRef.current = window.setTimeout(() => triggerDismiss(), delay);
|
|
190
|
+
}, [triggerDismiss]);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (!toast.duration || toast.duration <= 0) return void 0;
|
|
193
|
+
schedule(toast.duration);
|
|
194
|
+
return stopTimer;
|
|
195
|
+
}, [schedule, toast.duration]);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (!toast.duration || toast.duration <= 0) return;
|
|
198
|
+
if (isPaused) {
|
|
199
|
+
const elapsed = performance.now() - startRef.current;
|
|
200
|
+
remainingRef.current = Math.max(0, remainingRef.current - elapsed);
|
|
201
|
+
stopTimer();
|
|
202
|
+
} else schedule(remainingRef.current);
|
|
203
|
+
}, [
|
|
204
|
+
isPaused,
|
|
205
|
+
schedule,
|
|
206
|
+
toast.duration
|
|
207
|
+
]);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
return () => {
|
|
210
|
+
if (copyTimerRef.current) window.clearTimeout(copyTimerRef.current);
|
|
211
|
+
};
|
|
212
|
+
}, []);
|
|
213
|
+
const handleCopy = useCallback(async () => {
|
|
214
|
+
if (copyTimerRef.current) window.clearTimeout(copyTimerRef.current);
|
|
215
|
+
try {
|
|
216
|
+
if (!navigator.clipboard) throw new Error("Clipboard API unavailable");
|
|
217
|
+
await navigator.clipboard.writeText(toast.message);
|
|
218
|
+
setCopyState("copied");
|
|
219
|
+
} catch {
|
|
220
|
+
setCopyState("failed");
|
|
221
|
+
}
|
|
222
|
+
copyTimerRef.current = window.setTimeout(() => setCopyState("idle"), 1800);
|
|
223
|
+
}, [toast.message]);
|
|
224
|
+
const icon = getIcon(toast.type);
|
|
225
|
+
return /* @__PURE__ */ jsxs(ToastPrimitive.Root, {
|
|
226
|
+
open,
|
|
227
|
+
onOpenChange: (nextOpen) => {
|
|
228
|
+
if (!nextOpen) triggerDismiss();
|
|
229
|
+
},
|
|
230
|
+
duration: 2147483647,
|
|
231
|
+
className: toast_module_default.toast,
|
|
232
|
+
style: styleVars,
|
|
233
|
+
children: [
|
|
234
|
+
/* @__PURE__ */ jsx("span", {
|
|
235
|
+
className: toast_module_default.icon,
|
|
236
|
+
"aria-hidden": true,
|
|
237
|
+
children: icon
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ jsxs("div", {
|
|
240
|
+
className: toast_module_default.body,
|
|
241
|
+
children: [/* @__PURE__ */ jsx(ToastPrimitive.Description, {
|
|
242
|
+
className: toast_module_default.message,
|
|
243
|
+
children: toast.message
|
|
244
|
+
}), toast.action && /* @__PURE__ */ jsx("div", {
|
|
245
|
+
className: toast_module_default.actions,
|
|
246
|
+
children: /* @__PURE__ */ jsx(ToastPrimitive.Action, {
|
|
247
|
+
asChild: true,
|
|
248
|
+
altText: toast.action.label,
|
|
249
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
250
|
+
type: "button",
|
|
251
|
+
className: toast_module_default.actionButton,
|
|
252
|
+
onClick: () => {
|
|
253
|
+
toast.action?.onClick();
|
|
254
|
+
triggerDismiss();
|
|
255
|
+
},
|
|
256
|
+
children: toast.action.label
|
|
257
|
+
})
|
|
258
|
+
})
|
|
259
|
+
})]
|
|
260
|
+
}),
|
|
261
|
+
/* @__PURE__ */ jsxs("div", {
|
|
262
|
+
className: toast_module_default.controls,
|
|
263
|
+
children: [toast.copyable && /* @__PURE__ */ jsx("button", {
|
|
264
|
+
type: "button",
|
|
265
|
+
className: cx(toast_module_default.iconButton, copyState === "failed" && toast_module_default.iconButtonError),
|
|
266
|
+
"aria-label": "Copy message",
|
|
267
|
+
onClick: handleCopy,
|
|
268
|
+
children: copyState === "copied" ? /* @__PURE__ */ jsx("svg", {
|
|
269
|
+
width: "13",
|
|
270
|
+
height: "13",
|
|
271
|
+
viewBox: "0 0 13 13",
|
|
272
|
+
fill: "none",
|
|
273
|
+
"aria-hidden": true,
|
|
274
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
275
|
+
d: "M2 6.5l3 3 6-6",
|
|
276
|
+
stroke: "currentColor",
|
|
277
|
+
strokeWidth: "1.5",
|
|
278
|
+
strokeLinecap: "round",
|
|
279
|
+
strokeLinejoin: "round"
|
|
280
|
+
})
|
|
281
|
+
}) : copyState === "failed" ? /* @__PURE__ */ jsx("svg", {
|
|
282
|
+
width: "13",
|
|
283
|
+
height: "13",
|
|
284
|
+
viewBox: "0 0 13 13",
|
|
285
|
+
fill: "none",
|
|
286
|
+
"aria-hidden": true,
|
|
287
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
288
|
+
d: "M10 3L3 10M3 3l7 7",
|
|
289
|
+
stroke: "currentColor",
|
|
290
|
+
strokeWidth: "1.5",
|
|
291
|
+
strokeLinecap: "round"
|
|
292
|
+
})
|
|
293
|
+
}) : /* @__PURE__ */ jsxs("svg", {
|
|
294
|
+
width: "13",
|
|
295
|
+
height: "13",
|
|
296
|
+
viewBox: "0 0 13 13",
|
|
297
|
+
fill: "none",
|
|
298
|
+
"aria-hidden": true,
|
|
299
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
300
|
+
x: "4.5",
|
|
301
|
+
y: "1.5",
|
|
302
|
+
width: "7",
|
|
303
|
+
height: "7",
|
|
304
|
+
rx: "1.5",
|
|
305
|
+
stroke: "currentColor",
|
|
306
|
+
strokeWidth: "1.25"
|
|
307
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
308
|
+
d: "M1.5 5.5v5a1.5 1.5 0 001.5 1.5h5",
|
|
309
|
+
stroke: "currentColor",
|
|
310
|
+
strokeWidth: "1.25",
|
|
311
|
+
strokeLinecap: "round"
|
|
312
|
+
})]
|
|
313
|
+
})
|
|
314
|
+
}), toast.dismissible !== false && /* @__PURE__ */ jsx(ToastPrimitive.Close, {
|
|
315
|
+
asChild: true,
|
|
316
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
317
|
+
type: "button",
|
|
318
|
+
className: toast_module_default.iconButton,
|
|
319
|
+
"aria-label": "Dismiss notification",
|
|
320
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
321
|
+
width: "13",
|
|
322
|
+
height: "13",
|
|
323
|
+
viewBox: "0 0 13 13",
|
|
324
|
+
fill: "none",
|
|
325
|
+
"aria-hidden": true,
|
|
326
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
327
|
+
d: "M10 3L3 10M3 3l7 7",
|
|
328
|
+
stroke: "currentColor",
|
|
329
|
+
strokeWidth: "1.5",
|
|
330
|
+
strokeLinecap: "round"
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
})]
|
|
335
|
+
})
|
|
336
|
+
]
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
function getPalette(type) {
|
|
340
|
+
switch (type) {
|
|
341
|
+
case "success": return {
|
|
342
|
+
background: "color-mix(in srgb, var(--success) 12%, var(--popover))",
|
|
343
|
+
border: "color-mix(in srgb, var(--success) 30%, transparent)",
|
|
344
|
+
accent: "var(--success)",
|
|
345
|
+
text: "var(--popover-foreground)",
|
|
346
|
+
actionBg: "color-mix(in srgb, var(--success) 14%, transparent)",
|
|
347
|
+
actionBorder: "color-mix(in srgb, var(--success) 35%, transparent)"
|
|
348
|
+
};
|
|
349
|
+
case "error": return {
|
|
350
|
+
background: "color-mix(in srgb, var(--destructive) 12%, var(--popover))",
|
|
351
|
+
border: "color-mix(in srgb, var(--destructive) 30%, transparent)",
|
|
352
|
+
accent: "var(--destructive)",
|
|
353
|
+
text: "var(--popover-foreground)",
|
|
354
|
+
actionBg: "color-mix(in srgb, var(--destructive) 14%, transparent)",
|
|
355
|
+
actionBorder: "color-mix(in srgb, var(--destructive) 35%, transparent)"
|
|
356
|
+
};
|
|
357
|
+
case "warning": return {
|
|
358
|
+
background: "color-mix(in srgb, var(--warning) 12%, var(--popover))",
|
|
359
|
+
border: "color-mix(in srgb, var(--warning) 30%, transparent)",
|
|
360
|
+
accent: "var(--warning)",
|
|
361
|
+
text: "var(--popover-foreground)",
|
|
362
|
+
actionBg: "color-mix(in srgb, var(--warning) 14%, transparent)",
|
|
363
|
+
actionBorder: "color-mix(in srgb, var(--warning) 35%, transparent)"
|
|
364
|
+
};
|
|
365
|
+
default: return {
|
|
366
|
+
background: "color-mix(in srgb, var(--primary) 12%, var(--popover))",
|
|
367
|
+
border: "color-mix(in srgb, var(--primary) 30%, transparent)",
|
|
368
|
+
accent: "var(--primary)",
|
|
369
|
+
text: "var(--popover-foreground)",
|
|
370
|
+
actionBg: "color-mix(in srgb, var(--primary) 14%, transparent)",
|
|
371
|
+
actionBorder: "color-mix(in srgb, var(--primary) 35%, transparent)"
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function getIcon(type) {
|
|
376
|
+
switch (type) {
|
|
377
|
+
case "success": return /* @__PURE__ */ jsx("svg", {
|
|
378
|
+
width: "16",
|
|
379
|
+
height: "16",
|
|
380
|
+
viewBox: "0 0 16 16",
|
|
381
|
+
fill: "none",
|
|
382
|
+
"aria-hidden": true,
|
|
383
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
384
|
+
d: "M3 8l3.5 3.5L13 4.5",
|
|
385
|
+
stroke: "currentColor",
|
|
386
|
+
strokeWidth: "1.75",
|
|
387
|
+
strokeLinecap: "round",
|
|
388
|
+
strokeLinejoin: "round"
|
|
389
|
+
})
|
|
390
|
+
});
|
|
391
|
+
case "error": return /* @__PURE__ */ jsx("svg", {
|
|
392
|
+
width: "16",
|
|
393
|
+
height: "16",
|
|
394
|
+
viewBox: "0 0 16 16",
|
|
395
|
+
fill: "none",
|
|
396
|
+
"aria-hidden": true,
|
|
397
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
398
|
+
d: "M4 4l8 8M12 4l-8 8",
|
|
399
|
+
stroke: "currentColor",
|
|
400
|
+
strokeWidth: "1.75",
|
|
401
|
+
strokeLinecap: "round"
|
|
402
|
+
})
|
|
403
|
+
});
|
|
404
|
+
case "warning": return /* @__PURE__ */ jsx("svg", {
|
|
405
|
+
width: "16",
|
|
406
|
+
height: "16",
|
|
407
|
+
viewBox: "0 0 16 16",
|
|
408
|
+
fill: "none",
|
|
409
|
+
"aria-hidden": true,
|
|
410
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
411
|
+
d: "M8 3v6M8 11.5v1",
|
|
412
|
+
stroke: "currentColor",
|
|
413
|
+
strokeWidth: "1.75",
|
|
414
|
+
strokeLinecap: "round"
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
default: return /* @__PURE__ */ jsx("svg", {
|
|
418
|
+
width: "16",
|
|
419
|
+
height: "16",
|
|
420
|
+
viewBox: "0 0 16 16",
|
|
421
|
+
fill: "none",
|
|
422
|
+
"aria-hidden": true,
|
|
423
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
424
|
+
d: "M8 7v5M8 4.5v.5",
|
|
425
|
+
stroke: "currentColor",
|
|
426
|
+
strokeWidth: "1.75",
|
|
427
|
+
strokeLinecap: "round"
|
|
428
|
+
})
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
export { ToastProvider, useToast };
|
|
434
|
+
|
|
435
|
+
//# sourceMappingURL=index17.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index17.js","names":[],"sources":["../src/components/toast/ToastContext.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\nimport * as ToastPrimitive from \"@radix-ui/react-toast\";\nimport { cx } from \"../../utils/cx\";\nimport type {\n Toast,\n ToastConfig,\n ToastContextValue,\n ToastOptions,\n ToastPosition,\n ToastType,\n} from \"./types\";\nimport styles from \"./toast.module.css\";\n\n/** Default provider configuration. */\nconst DEFAULT_CONFIG: Required<ToastConfig> = {\n position: \"top-right\",\n maxToasts: 5,\n defaultDuration: 4000,\n pauseOnHover: true,\n pauseOnFocusLoss: true,\n};\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nlet toastIdCounter = 0;\nconst generateToastId = () => `toast-${++toastIdCounter}-${Date.now()}`;\n\n/**\n * Toast notification context provider.\n *\n * @remarks\n * Wrap your app (or a section) to enable `useToast` calls. Supports configurable placement,\n * maximum visible toasts, and pause behavior on hover or window blur.\n *\n * @param props.children - React subtree that can consume the toast context.\n * @param props.config - Optional provider configuration overrides.\n */\nexport function ToastProvider({\n children,\n config,\n}: {\n children: ReactNode;\n config?: ToastConfig;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const [isPaused, setIsPaused] = useState(false);\n const merged = useMemo(() => ({ ...DEFAULT_CONFIG, ...config }), [config]);\n\n const push = useCallback(\n (message: string, options: ToastOptions = {}) => {\n const id = generateToastId();\n setToasts((prev) => {\n const next: Toast[] = [\n ...prev,\n {\n id,\n message,\n type: options.type ?? \"info\",\n duration: options.duration ?? (options.type === \"error\" ? 6000 : merged.defaultDuration),\n dismissible: options.dismissible ?? true,\n copyable: options.copyable ?? false,\n action: options.action,\n },\n ];\n if (next.length > merged.maxToasts) next.shift();\n return next;\n });\n return id;\n },\n [merged.defaultDuration, merged.maxToasts],\n );\n\n const success = useCallback(\n (message: string, options?: Omit<ToastOptions, \"type\">) => push(message, { ...options, type: \"success\" }),\n [push],\n );\n const error = useCallback(\n (message: string, options?: Omit<ToastOptions, \"type\">) =>\n push(message, { copyable: true, ...options, type: \"error\" }),\n [push],\n );\n const warning = useCallback(\n (message: string, options?: Omit<ToastOptions, \"type\">) => push(message, { ...options, type: \"warning\" }),\n [push],\n );\n const info = useCallback(\n (message: string, options?: Omit<ToastOptions, \"type\">) => push(message, { ...options, type: \"info\" }),\n [push],\n );\n\n const dismiss = useCallback((id: string) => {\n setToasts((prev) => prev.filter((t) => t.id !== id));\n }, []);\n\n const dismissAll = useCallback(() => setToasts([]), []);\n\n useEffect(() => {\n if (!merged.pauseOnFocusLoss) return;\n const handleVisibility = () => setIsPaused(document.visibilityState !== \"visible\");\n document.addEventListener(\"visibilitychange\", handleVisibility);\n return () => document.removeEventListener(\"visibilitychange\", handleVisibility);\n }, [merged.pauseOnFocusLoss]);\n\n const value = useMemo<ToastContextValue>(\n () => ({ toasts, push, success, error, warning, info, dismiss, dismissAll }),\n [toasts, push, success, error, warning, info, dismiss, dismissAll],\n );\n\n return (\n <ToastContext.Provider value={value}>\n <ToastPrimitive.Provider swipeDirection=\"right\">\n {children}\n <ToastContainer\n toasts={toasts}\n position={merged.position}\n pauseOnHover={merged.pauseOnHover}\n isPaused={isPaused}\n onDismiss={dismiss}\n onPauseChange={setIsPaused}\n />\n </ToastPrimitive.Provider>\n </ToastContext.Provider>\n );\n}\n\n/**\n * Hook to access the toast API.\n *\n * @remarks\n * Exposes `push`, intent helpers (`success`, `error`, `warning`, `info`), and dismissal helpers.\n * Must be called within a `ToastProvider`.\n *\n * @throws Error if used outside of a `ToastProvider`.\n */\nexport function useToast(): ToastContextValue {\n const ctx = useContext(ToastContext);\n if (!ctx) throw new Error(\"useToast must be used within a ToastProvider\");\n return ctx;\n}\n\n/** Renders the positioned toast stack. */\nfunction ToastContainer({\n toasts,\n position,\n pauseOnHover,\n isPaused,\n onDismiss,\n onPauseChange,\n}: {\n toasts: Toast[];\n position: ToastPosition;\n pauseOnHover: boolean;\n isPaused: boolean;\n onDismiss: (id: string) => void;\n onPauseChange: (paused: boolean) => void;\n}) {\n const posClass = (() => {\n switch (position) {\n case \"top-left\":\n return \"topLeft\";\n case \"top-center\":\n return \"topCenter\";\n case \"bottom-right\":\n return \"bottomRight\";\n case \"bottom-left\":\n return \"bottomLeft\";\n case \"bottom-center\":\n return \"bottomCenter\";\n case \"top-right\":\n default:\n return \"topRight\";\n }\n })();\n\n return (\n <>\n {toasts.map((toast) => (\n <ToastItem key={toast.id} toast={toast} isPaused={isPaused} onDismiss={onDismiss} />\n ))}\n <ToastPrimitive.Viewport\n className={cx(styles.stack, styles[posClass])}\n label=\"Notifications\"\n onMouseEnter={() => pauseOnHover && onPauseChange(true)}\n onMouseLeave={() => pauseOnHover && onPauseChange(false)}\n />\n </>\n );\n}\n\n/** Individual toast item with timers and actions. */\nfunction ToastItem({\n toast,\n isPaused,\n onDismiss,\n}: {\n toast: Toast;\n isPaused: boolean;\n onDismiss: (id: string) => void;\n}) {\n const [open, setOpen] = useState(true);\n const [copyState, setCopyState] = useState<\"idle\" | \"copied\" | \"failed\">(\"idle\");\n const copyTimerRef = useRef<number | null>(null);\n const timerRef = useRef<number | null>(null);\n const startRef = useRef<number>(0);\n const remainingRef = useRef<number>(toast.duration ?? 0);\n const closingRef = useRef(false);\n\n const palette = getPalette(toast.type);\n const styleVars: CSSProperties = {\n [\"--toast-bg\" as any]: palette.background,\n [\"--toast-border\" as any]: palette.border,\n [\"--toast-accent\" as any]: palette.accent,\n [\"--toast-text\" as any]: palette.text,\n [\"--toast-action-bg\" as any]: palette.actionBg,\n [\"--toast-action-border\" as any]: palette.actionBorder,\n };\n\n const stopTimer = () => {\n if (timerRef.current) {\n window.clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const triggerDismiss = useCallback(() => {\n if (closingRef.current) return;\n closingRef.current = true;\n setOpen(false);\n stopTimer();\n window.setTimeout(() => onDismiss(toast.id), 160);\n }, [onDismiss, toast.id]);\n\n const schedule = useCallback(\n (delay: number) => {\n if (!delay || delay <= 0) {\n triggerDismiss();\n return;\n }\n startRef.current = performance.now();\n stopTimer();\n timerRef.current = window.setTimeout(() => triggerDismiss(), delay);\n },\n [triggerDismiss],\n );\n\n useEffect(() => {\n if (!toast.duration || toast.duration <= 0) return undefined;\n schedule(toast.duration);\n return stopTimer;\n }, [schedule, toast.duration]);\n\n useEffect(() => {\n if (!toast.duration || toast.duration <= 0) return;\n if (isPaused) {\n const elapsed = performance.now() - startRef.current;\n remainingRef.current = Math.max(0, remainingRef.current - elapsed);\n stopTimer();\n } else {\n schedule(remainingRef.current);\n }\n }, [isPaused, schedule, toast.duration]);\n\n useEffect(() => {\n return () => {\n if (copyTimerRef.current) window.clearTimeout(copyTimerRef.current);\n };\n }, []);\n\n const handleCopy = useCallback(async () => {\n if (copyTimerRef.current) window.clearTimeout(copyTimerRef.current);\n try {\n if (!navigator.clipboard) throw new Error(\"Clipboard API unavailable\");\n await navigator.clipboard.writeText(toast.message);\n setCopyState(\"copied\");\n } catch {\n setCopyState(\"failed\");\n }\n copyTimerRef.current = window.setTimeout(() => setCopyState(\"idle\"), 1800);\n }, [toast.message]);\n\n const icon = getIcon(toast.type);\n\n return (\n <ToastPrimitive.Root\n open={open}\n onOpenChange={(nextOpen: boolean) => {\n if (!nextOpen) triggerDismiss();\n }}\n duration={2147483647}\n className={styles.toast}\n style={styleVars}\n >\n <span className={styles.icon} aria-hidden>\n {icon}\n </span>\n <div className={styles.body}>\n <ToastPrimitive.Description className={styles.message}>\n {toast.message}\n </ToastPrimitive.Description>\n {toast.action && (\n <div className={styles.actions}>\n <ToastPrimitive.Action asChild altText={toast.action.label}>\n <button\n type=\"button\"\n className={styles.actionButton}\n onClick={() => {\n toast.action?.onClick();\n triggerDismiss();\n }}\n >\n {toast.action.label}\n </button>\n </ToastPrimitive.Action>\n </div>\n )}\n </div>\n <div className={styles.controls}>\n {toast.copyable && (\n <button\n type=\"button\"\n className={cx(styles.iconButton, copyState === \"failed\" && styles.iconButtonError)}\n aria-label=\"Copy message\"\n onClick={handleCopy}\n >\n {copyState === \"copied\" ? (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 13 13\" fill=\"none\" aria-hidden>\n <path d=\"M2 6.5l3 3 6-6\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n ) : copyState === \"failed\" ? (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 13 13\" fill=\"none\" aria-hidden>\n <path d=\"M10 3L3 10M3 3l7 7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n ) : (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 13 13\" fill=\"none\" aria-hidden>\n <rect x=\"4.5\" y=\"1.5\" width=\"7\" height=\"7\" rx=\"1.5\" stroke=\"currentColor\" strokeWidth=\"1.25\" />\n <path d=\"M1.5 5.5v5a1.5 1.5 0 001.5 1.5h5\" stroke=\"currentColor\" strokeWidth=\"1.25\" strokeLinecap=\"round\" />\n </svg>\n )}\n </button>\n )}\n {toast.dismissible !== false && (\n <ToastPrimitive.Close asChild>\n <button\n type=\"button\"\n className={styles.iconButton}\n aria-label=\"Dismiss notification\"\n >\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 13 13\" fill=\"none\" aria-hidden>\n <path d=\"M10 3L3 10M3 3l7 7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n </button>\n </ToastPrimitive.Close>\n )}\n </div>\n </ToastPrimitive.Root>\n );\n}\n\nfunction getPalette(type: ToastType) {\n switch (type) {\n case \"success\":\n return {\n background: \"color-mix(in srgb, var(--success) 12%, var(--popover))\",\n border: \"color-mix(in srgb, var(--success) 30%, transparent)\",\n accent: \"var(--success)\",\n text: \"var(--popover-foreground)\",\n actionBg: \"color-mix(in srgb, var(--success) 14%, transparent)\",\n actionBorder: \"color-mix(in srgb, var(--success) 35%, transparent)\",\n };\n case \"error\":\n return {\n background: \"color-mix(in srgb, var(--destructive) 12%, var(--popover))\",\n border: \"color-mix(in srgb, var(--destructive) 30%, transparent)\",\n accent: \"var(--destructive)\",\n text: \"var(--popover-foreground)\",\n actionBg: \"color-mix(in srgb, var(--destructive) 14%, transparent)\",\n actionBorder: \"color-mix(in srgb, var(--destructive) 35%, transparent)\",\n };\n case \"warning\":\n return {\n background: \"color-mix(in srgb, var(--warning) 12%, var(--popover))\",\n border: \"color-mix(in srgb, var(--warning) 30%, transparent)\",\n accent: \"var(--warning)\",\n text: \"var(--popover-foreground)\",\n actionBg: \"color-mix(in srgb, var(--warning) 14%, transparent)\",\n actionBorder: \"color-mix(in srgb, var(--warning) 35%, transparent)\",\n };\n case \"info\":\n default:\n return {\n background: \"color-mix(in srgb, var(--primary) 12%, var(--popover))\",\n border: \"color-mix(in srgb, var(--primary) 30%, transparent)\",\n accent: \"var(--primary)\",\n text: \"var(--popover-foreground)\",\n actionBg: \"color-mix(in srgb, var(--primary) 14%, transparent)\",\n actionBorder: \"color-mix(in srgb, var(--primary) 35%, transparent)\",\n };\n }\n}\n\nfunction getIcon(type: ToastType) {\n switch (type) {\n case \"success\":\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n <path d=\"M3 8l3.5 3.5L13 4.5\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n );\n case \"error\":\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n <path d=\"M4 4l8 8M12 4l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n </svg>\n );\n case \"warning\":\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n <path d=\"M8 3v6M8 11.5v1\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n </svg>\n );\n case \"info\":\n default:\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n <path d=\"M8 7v5M8 4.5v.5\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n </svg>\n );\n }\n}\n"],"mappings":";;;;;;;;AA0BA,IAAM,iBAAwC;CAC5C,UAAU;CACV,WAAW;CACX,iBAAiB;CACjB,cAAc;CACd,kBAAkB;AACpB;AAEA,IAAM,eAAe,cAA6C,KAAA,CAAS;AAE3E,IAAI,iBAAiB;AACrB,IAAM,wBAAwB,SAAS,EAAE,eAAe,GAAG,KAAK,IAAI;;;;;;;;;;;AAYpE,SAAgB,cAAc,EAC5B,UACA,UAIC;CACD,MAAM,CAAC,QAAQ,aAAa,SAAkB,CAAC,CAAC;CAChD,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,SAAS,eAAe;EAAE,GAAG;EAAgB,GAAG;CAAO,IAAI,CAAC,MAAM,CAAC;CAEzE,MAAM,OAAO,aACV,SAAiB,UAAwB,CAAC,MAAM;EAC/C,MAAM,KAAK,gBAAgB;EAC3B,WAAW,SAAS;GAClB,MAAM,OAAgB,CACpB,GAAG,MACH;IACE;IACA;IACA,MAAM,QAAQ,QAAQ;IACtB,UAAU,QAAQ,aAAa,QAAQ,SAAS,UAAU,MAAO,OAAO;IACxE,aAAa,QAAQ,eAAe;IACpC,UAAU,QAAQ,YAAY;IAC9B,QAAQ,QAAQ;GAClB,CACF;GACA,IAAI,KAAK,SAAS,OAAO,WAAW,KAAK,MAAM;GAC/C,OAAO;EACT,CAAC;EACD,OAAO;CACT,GACA,CAAC,OAAO,iBAAiB,OAAO,SAAS,CAC3C;CAEA,MAAM,UAAU,aACb,SAAiB,YAAyC,KAAK,SAAS;EAAE,GAAG;EA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