@wello-dev/notifications 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +47 -0
- package/README.md +169 -3
- package/dist/index.cjs +1418 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +323 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +1383 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +338 -0
- package/package.json +73 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,1383 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// #style-inject:#style-inject
|
|
4
|
+
function styleInject(css, { insertAt } = {}) {
|
|
5
|
+
if (!css || typeof document === "undefined") return;
|
|
6
|
+
const head = document.head || document.getElementsByTagName("head")[0];
|
|
7
|
+
const style = document.createElement("style");
|
|
8
|
+
style.type = "text/css";
|
|
9
|
+
if (insertAt === "top") {
|
|
10
|
+
if (head.firstChild) {
|
|
11
|
+
head.insertBefore(style, head.firstChild);
|
|
12
|
+
} else {
|
|
13
|
+
head.appendChild(style);
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
head.appendChild(style);
|
|
17
|
+
}
|
|
18
|
+
if (style.styleSheet) {
|
|
19
|
+
style.styleSheet.cssText = css;
|
|
20
|
+
} else {
|
|
21
|
+
style.appendChild(document.createTextNode(css));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/styles.css
|
|
26
|
+
styleInject('@layer theme, base, components, utilities;\n@layer components {\n .wello-notifications-toaster {\n --wello-notifications-bg: rgb(255 255 255 / 0.95);\n --wello-notifications-fg: #0f172a;\n --wello-notifications-muted: #64748b;\n --wello-notifications-border: rgb(226 232 240 / 0.7);\n --wello-notifications-ring: rgb(0 0 0 / 0.05);\n --wello-notifications-hover: rgb(0 0 0 / 0.05);\n --wello-notifications-shadow: 0 8px 24px -12px rgb(0 0 0 / 0.22);\n --wello-notifications-radius: 16px;\n --wello-notifications-font: inherit;\n position: fixed;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n width: var(--wello-notifications-width, 390px);\n max-width: calc(100vw - 2 * var(--wello-notifications-offset, 16px));\n margin: 0;\n padding: 0;\n list-style: none;\n pointer-events: none;\n font-family: var(--wello-notifications-font);\n color-scheme: light;\n }\n .dark .wello-notifications-toaster:not([data-theme=light]),\n [data-theme=dark] .wello-notifications-toaster:not([data-theme=light]),\n .wello-notifications-toaster[data-theme=dark] {\n --wello-notifications-bg: rgb(15 23 42 / 0.92);\n --wello-notifications-fg: #f1f5f9;\n --wello-notifications-muted: #94a3b8;\n --wello-notifications-border: rgb(255 255 255 / 0.1);\n --wello-notifications-ring: rgb(255 255 255 / 0.06);\n --wello-notifications-hover: rgb(255 255 255 / 0.1);\n --wello-notifications-shadow: 0 8px 24px -12px rgb(0 0 0 / 0.45);\n color-scheme: dark;\n }\n .wello-notifications-toaster[data-y=top] {\n top: calc(var(--wello-notifications-offset, 16px) - var(--wello-notifications-gap, 12px) / 2);\n }\n .wello-notifications-toaster[data-y=bottom] {\n bottom: calc(var(--wello-notifications-offset, 16px) - var(--wello-notifications-gap, 12px) / 2);\n flex-direction: column-reverse;\n }\n .wello-notifications-toaster[data-x=start] {\n inset-inline-start: var(--wello-notifications-offset, 16px);\n }\n .wello-notifications-toaster[data-x=end] {\n inset-inline-end: var(--wello-notifications-offset, 16px);\n }\n .wello-notifications-toaster[data-x=center] {\n left: 50%;\n transform: translateX(-50%);\n }\n @media (max-width: 480px) {\n .wello-notifications-toaster {\n width: auto;\n max-width: none;\n inset-inline: var(--wello-notifications-offset, 16px);\n transform: none;\n }\n .wello-notifications-toaster[data-x=center] {\n left: var(--wello-notifications-offset, 16px);\n }\n }\n .wello-notifications-item {\n display: grid;\n grid-template-rows: 1fr;\n transition: grid-template-rows 200ms ease 110ms;\n }\n .wello-notifications-item-inner {\n min-height: 0;\n padding-block: calc(var(--wello-notifications-gap, 12px) / 2);\n }\n .wello-notifications-item[data-state=closing] {\n grid-template-rows: 0fr;\n }\n .wello-notifications-item[data-state=closing] .wello-notifications-item-inner {\n overflow: hidden;\n }\n .wello-notifications-toast,\n .wello-notifications-custom {\n pointer-events: auto;\n touch-action: pan-y;\n transform: translateX(var(--wello-notifications-swipe, 0px));\n transition:\n transform 200ms ease,\n opacity 160ms ease,\n scale 160ms ease;\n animation: wello-notifications-in 260ms cubic-bezier(0.21, 1.02, 0.73, 1);\n }\n .wello-notifications-toaster[data-y=top] .wello-notifications-toast,\n .wello-notifications-toaster[data-y=top] .wello-notifications-custom {\n --wello-notifications-enter: -14px;\n }\n .wello-notifications-toast[data-swiping],\n .wello-notifications-custom[data-swiping] {\n transition: none;\n user-select: none;\n }\n .wello-notifications-item[data-state=closing] .wello-notifications-toast,\n .wello-notifications-item[data-state=closing] .wello-notifications-custom {\n opacity: 0;\n scale: 0.96;\n }\n .wello-notifications-item[data-swiped=end] .wello-notifications-toast,\n .wello-notifications-item[data-swiped=end] .wello-notifications-custom {\n transform: translateX(calc(100% + 32px));\n }\n .wello-notifications-item[data-swiped=start] .wello-notifications-toast,\n .wello-notifications-item[data-swiped=start] .wello-notifications-custom {\n transform: translateX(calc(-100% - 32px));\n }\n .wello-notifications-toast {\n position: relative;\n display: flex;\n align-items: flex-start;\n gap: 12px;\n box-sizing: border-box;\n width: 100%;\n padding-block: 14px;\n padding-inline: 14px 8px;\n overflow: hidden;\n border: 1px solid var(--wello-notifications-border);\n border-radius: var(--wello-notifications-radius);\n background: var(--wello-notifications-bg);\n color: var(--wello-notifications-fg);\n box-shadow: var(--wello-notifications-shadow), 0 0 0 1px var(--wello-notifications-ring);\n backdrop-filter: blur(24px) saturate(1.5);\n -webkit-backdrop-filter: blur(24px) saturate(1.5);\n font-size: 14px;\n line-height: 1.4;\n text-align: start;\n }\n .wello-notifications-toast::before {\n content: "";\n position: absolute;\n inset-block: 0.55rem;\n inset-inline-start: 0;\n width: 3px;\n border-radius: 999px;\n background: var(--wello-notifications-tone);\n }\n .wello-notifications-icon {\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n border-radius: var(--wello-notifications-radius);\n color: var(--wello-notifications-tone);\n background: color-mix(in oklab, var(--wello-notifications-tone) 16%, transparent);\n box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--wello-notifications-tone) 28%, transparent);\n font-size: 1.15rem;\n }\n .wello-notifications-content {\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: 4px;\n min-width: 0;\n padding-block: 2px;\n padding-inline-end: 8px;\n overflow-wrap: anywhere;\n }\n .wello-notifications-toast > .wello-notifications-content:first-child {\n padding-inline-start: 2px;\n }\n .wello-notifications-title {\n margin: 0;\n font-weight: 600;\n line-height: 1.35;\n color: var(--wello-notifications-tone);\n }\n .wello-notifications-toast[data-type=default] .wello-notifications-title,\n .wello-notifications-toast[data-type=loading] .wello-notifications-title {\n color: var(--wello-notifications-fg);\n }\n .wello-notifications-description {\n margin: 0;\n color: var(--wello-notifications-muted);\n line-height: 1.55;\n }\n .wello-notifications-actions {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n margin-top: 6px;\n }\n .wello-notifications-button {\n display: inline-flex;\n align-items: center;\n height: 28px;\n padding-inline: 10px;\n border: 1px solid transparent;\n border-radius: 8px;\n font: inherit;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n transition: background-color 120ms ease, filter 120ms ease;\n }\n .wello-notifications-action {\n background: var(--wello-notifications-tone);\n color: #fff;\n }\n .wello-notifications-toast[data-type=default] .wello-notifications-action,\n .wello-notifications-toast[data-type=loading] .wello-notifications-action {\n background: var(--wello-notifications-fg);\n color: var(--wello-notifications-bg);\n }\n .wello-notifications-action:hover {\n filter: brightness(1.08);\n }\n .wello-notifications-cancel {\n background: transparent;\n border-color: var(--wello-notifications-border);\n color: var(--wello-notifications-fg);\n }\n .wello-notifications-cancel:hover {\n background: var(--wello-notifications-hover);\n }\n .wello-notifications-button:focus-visible,\n .wello-notifications-close:focus-visible {\n outline: 2px solid var(--wello-notifications-tone);\n outline-offset: 2px;\n }\n .wello-notifications-close {\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n margin: -2px 0;\n padding: 0;\n border: 0;\n border-radius: 10px;\n background: transparent;\n color: var(--wello-notifications-muted);\n font-size: 16px;\n cursor: pointer;\n transition: background-color 120ms ease, color 120ms ease;\n }\n .wello-notifications-close:hover {\n background: var(--wello-notifications-hover);\n color: var(--wello-notifications-fg);\n }\n .wello-notifications-progress {\n position: absolute;\n inset-inline: 0;\n bottom: 0;\n height: 3px;\n background: var(--wello-notifications-tone);\n opacity: 0.45;\n transform-origin: left;\n animation-name: wello-notifications-progress;\n animation-timing-function: linear;\n animation-fill-mode: forwards;\n }\n [dir=rtl] .wello-notifications-progress {\n transform-origin: right;\n }\n .wello-notifications-spin {\n animation: wello-notifications-spin 0.9s linear infinite;\n }\n @keyframes wello-notifications-in {\n from {\n opacity: 0;\n translate: 0 var(--wello-notifications-enter, 14px);\n scale: 0.96;\n }\n }\n @keyframes wello-notifications-progress {\n from {\n transform: scaleX(1);\n }\n to {\n transform: scaleX(0);\n }\n }\n @keyframes wello-notifications-spin {\n to {\n transform: rotate(360deg);\n }\n }\n @media (prefers-reduced-motion: reduce) {\n .wello-notifications-toast,\n .wello-notifications-custom,\n .wello-notifications-item {\n animation-duration: 1ms;\n transition-duration: 1ms;\n transition-delay: 0ms;\n }\n .wello-notifications-spin {\n animation-duration: 2.5s;\n }\n }\n}\n');
|
|
27
|
+
|
|
28
|
+
// src/core/store.ts
|
|
29
|
+
var state = { toasts: [], paused: false };
|
|
30
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
31
|
+
var counter = 0;
|
|
32
|
+
function emit(next) {
|
|
33
|
+
state = next;
|
|
34
|
+
listeners.forEach((listener) => listener());
|
|
35
|
+
}
|
|
36
|
+
var toastStore = {
|
|
37
|
+
getState: () => state,
|
|
38
|
+
subscribe(listener) {
|
|
39
|
+
listeners.add(listener);
|
|
40
|
+
return () => {
|
|
41
|
+
listeners.delete(listener);
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
/** `true` when at least one `<Toaster>` is mounted */
|
|
45
|
+
hasToaster: () => listeners.size > 0,
|
|
46
|
+
nextId: () => `wello-notifications-${++counter}`,
|
|
47
|
+
/** Adds a toast, or replaces the open one with the same id. */
|
|
48
|
+
upsert(record) {
|
|
49
|
+
const existing = state.toasts.find((t) => t.id === record.id);
|
|
50
|
+
if (existing?.open) {
|
|
51
|
+
emit({
|
|
52
|
+
...state,
|
|
53
|
+
toasts: state.toasts.map(
|
|
54
|
+
(t) => t.id === record.id ? { ...record, version: t.version + 1, createdAt: t.createdAt, open: true } : t
|
|
55
|
+
)
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
const fresh = { ...record, version: 0, createdAt: Date.now(), open: true };
|
|
59
|
+
emit({ ...state, toasts: [fresh, ...state.toasts.filter((t) => t.id !== record.id)] });
|
|
60
|
+
}
|
|
61
|
+
return record.id;
|
|
62
|
+
},
|
|
63
|
+
/** Merges changes into an open toast. Returns false when there is none with this id. */
|
|
64
|
+
patch(id, changes) {
|
|
65
|
+
const existing = state.toasts.find((t) => t.id === id && t.open);
|
|
66
|
+
if (!existing) return false;
|
|
67
|
+
emit({
|
|
68
|
+
...state,
|
|
69
|
+
toasts: state.toasts.map(
|
|
70
|
+
(t) => t === existing ? { ...t, ...changes, id, version: t.version + 1, open: true } : t
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
/** Starts closing one toast, or all of them. */
|
|
76
|
+
dismiss(id, reason = "close") {
|
|
77
|
+
const closing = state.toasts.filter((t) => t.open && (id === void 0 || t.id === id));
|
|
78
|
+
if (!closing.length) return;
|
|
79
|
+
const keep = toastStore.hasToaster();
|
|
80
|
+
emit({
|
|
81
|
+
...state,
|
|
82
|
+
toasts: keep ? state.toasts.map((t) => closing.includes(t) ? { ...t, open: false } : t) : state.toasts.filter((t) => !closing.includes(t))
|
|
83
|
+
});
|
|
84
|
+
for (const t of closing) {
|
|
85
|
+
if (reason === "auto") t.onAutoClose?.(t);
|
|
86
|
+
t.onClose?.(t);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
/** Removes a toast right away (after its exit animation). */
|
|
90
|
+
remove(id) {
|
|
91
|
+
if (!state.toasts.some((t) => t.id === id)) return;
|
|
92
|
+
emit({ ...state, toasts: state.toasts.filter((t) => t.id !== id) });
|
|
93
|
+
},
|
|
94
|
+
setPaused(paused) {
|
|
95
|
+
if (state.paused !== paused) emit({ ...state, paused });
|
|
96
|
+
},
|
|
97
|
+
/** Test helper: forget every toast. */
|
|
98
|
+
reset() {
|
|
99
|
+
emit({ toasts: [], paused: false });
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/core/toast.ts
|
|
104
|
+
function toRecord(type, message, options = {}) {
|
|
105
|
+
const { id, title, description, autoClose, duration, ...rest } = options;
|
|
106
|
+
const resolvedTitle = title ?? message;
|
|
107
|
+
const resolvedDescription = description ?? (title != null && title !== message ? message : void 0);
|
|
108
|
+
return {
|
|
109
|
+
...rest,
|
|
110
|
+
id: id ?? toastStore.nextId(),
|
|
111
|
+
type,
|
|
112
|
+
title: resolvedTitle,
|
|
113
|
+
description: resolvedDescription,
|
|
114
|
+
duration: duration ?? autoClose
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function show(type, message, options) {
|
|
118
|
+
return toastStore.upsert(toRecord(type, message, options));
|
|
119
|
+
}
|
|
120
|
+
var typed = (type) => (message, options) => show(type, message, options);
|
|
121
|
+
function promise(source, messages, options) {
|
|
122
|
+
const id = show("loading", messages.loading, options);
|
|
123
|
+
const run = typeof source === "function" ? source() : source;
|
|
124
|
+
const settle = (type, content) => toastStore.upsert(toRecord(type, content, { ...options, id }));
|
|
125
|
+
return run.then(
|
|
126
|
+
(data) => {
|
|
127
|
+
settle("success", typeof messages.success === "function" ? messages.success(data) : messages.success);
|
|
128
|
+
messages.finally?.();
|
|
129
|
+
return data;
|
|
130
|
+
},
|
|
131
|
+
(error) => {
|
|
132
|
+
settle("error", typeof messages.error === "function" ? messages.error(error) : messages.error);
|
|
133
|
+
messages.finally?.();
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
function update(id, changes) {
|
|
139
|
+
if (changes !== null && typeof changes === "object" && !isReactElement(changes)) {
|
|
140
|
+
const { id: _ignored, autoClose, duration, ...rest } = changes;
|
|
141
|
+
const patch = { ...rest };
|
|
142
|
+
if (duration !== void 0 || autoClose !== void 0) patch.duration = duration ?? autoClose;
|
|
143
|
+
return toastStore.patch(id, patch);
|
|
144
|
+
}
|
|
145
|
+
return toastStore.patch(id, { title: changes });
|
|
146
|
+
}
|
|
147
|
+
function isReactElement(value) {
|
|
148
|
+
return "$$typeof" in value;
|
|
149
|
+
}
|
|
150
|
+
var dismiss = (id) => toastStore.dismiss(id);
|
|
151
|
+
var toast = Object.assign(typed("default"), {
|
|
152
|
+
success: typed("success"),
|
|
153
|
+
error: typed("error"),
|
|
154
|
+
/** Same as `error` */
|
|
155
|
+
danger: typed("error"),
|
|
156
|
+
warning: typed("warning"),
|
|
157
|
+
info: typed("info"),
|
|
158
|
+
loading: typed("loading"),
|
|
159
|
+
/** Same as `toast()` */
|
|
160
|
+
message: typed("default"),
|
|
161
|
+
/** Fully custom content; `render` gets the toast (use `toast.dismiss(t.id)` to close it). */
|
|
162
|
+
custom: (render, options) => toastStore.upsert({ ...toRecord("default", null, options), title: void 0, render }),
|
|
163
|
+
promise,
|
|
164
|
+
update,
|
|
165
|
+
/** Closes one toast, or all of them without an id */
|
|
166
|
+
dismiss,
|
|
167
|
+
/** Same as `dismiss` */
|
|
168
|
+
close: dismiss,
|
|
169
|
+
/** Closes every toast */
|
|
170
|
+
clear: () => toastStore.dismiss(),
|
|
171
|
+
/** Stops every timer, e.g. while a dialog is open */
|
|
172
|
+
pauseAll: () => toastStore.setPaused(true),
|
|
173
|
+
resumeAll: () => toastStore.setPaused(false),
|
|
174
|
+
/** `true` while the toast is open */
|
|
175
|
+
isActive: (id) => toastStore.getState().toasts.some((t) => t.id === id && t.open)
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// src/core/use-toasts.ts
|
|
179
|
+
import { useSyncExternalStore } from "react";
|
|
180
|
+
var NONE = [];
|
|
181
|
+
function useToasts() {
|
|
182
|
+
return useSyncExternalStore(
|
|
183
|
+
toastStore.subscribe,
|
|
184
|
+
() => toastStore.getState().toasts,
|
|
185
|
+
() => NONE
|
|
186
|
+
).filter((t) => t.open);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/components/toaster.tsx
|
|
190
|
+
import {
|
|
191
|
+
useEffect as useEffect2,
|
|
192
|
+
useMemo,
|
|
193
|
+
useState as useState2,
|
|
194
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
195
|
+
} from "react";
|
|
196
|
+
import { createPortal } from "react-dom";
|
|
197
|
+
|
|
198
|
+
// src/lib/colors.ts
|
|
199
|
+
var PALETTE = {
|
|
200
|
+
slate: [
|
|
201
|
+
"#f8fafc",
|
|
202
|
+
"#f1f5f9",
|
|
203
|
+
"#e2e8f0",
|
|
204
|
+
"#cbd5e1",
|
|
205
|
+
"#94a3b8",
|
|
206
|
+
"#64748b",
|
|
207
|
+
"#475569",
|
|
208
|
+
"#334155",
|
|
209
|
+
"#1e293b",
|
|
210
|
+
"#0f172a",
|
|
211
|
+
"#020617"
|
|
212
|
+
],
|
|
213
|
+
gray: [
|
|
214
|
+
"#f9fafb",
|
|
215
|
+
"#f3f4f6",
|
|
216
|
+
"#e5e7eb",
|
|
217
|
+
"#d1d5db",
|
|
218
|
+
"#9ca3af",
|
|
219
|
+
"#6b7280",
|
|
220
|
+
"#4b5563",
|
|
221
|
+
"#374151",
|
|
222
|
+
"#1f2937",
|
|
223
|
+
"#111827",
|
|
224
|
+
"#030712"
|
|
225
|
+
],
|
|
226
|
+
zinc: [
|
|
227
|
+
"#fafafa",
|
|
228
|
+
"#f4f4f5",
|
|
229
|
+
"#e4e4e7",
|
|
230
|
+
"#d4d4d8",
|
|
231
|
+
"#a1a1aa",
|
|
232
|
+
"#71717a",
|
|
233
|
+
"#52525b",
|
|
234
|
+
"#3f3f46",
|
|
235
|
+
"#27272a",
|
|
236
|
+
"#18181b",
|
|
237
|
+
"#09090b"
|
|
238
|
+
],
|
|
239
|
+
neutral: [
|
|
240
|
+
"#fafafa",
|
|
241
|
+
"#f5f5f5",
|
|
242
|
+
"#e5e5e5",
|
|
243
|
+
"#d4d4d4",
|
|
244
|
+
"#a3a3a3",
|
|
245
|
+
"#737373",
|
|
246
|
+
"#525252",
|
|
247
|
+
"#404040",
|
|
248
|
+
"#262626",
|
|
249
|
+
"#171717",
|
|
250
|
+
"#0a0a0a"
|
|
251
|
+
],
|
|
252
|
+
stone: [
|
|
253
|
+
"#fafaf9",
|
|
254
|
+
"#f5f5f4",
|
|
255
|
+
"#e7e5e4",
|
|
256
|
+
"#d6d3d1",
|
|
257
|
+
"#a8a29e",
|
|
258
|
+
"#78716c",
|
|
259
|
+
"#57534e",
|
|
260
|
+
"#44403c",
|
|
261
|
+
"#292524",
|
|
262
|
+
"#1c1917",
|
|
263
|
+
"#0c0a09"
|
|
264
|
+
],
|
|
265
|
+
red: [
|
|
266
|
+
"#fef2f2",
|
|
267
|
+
"#fee2e2",
|
|
268
|
+
"#fecaca",
|
|
269
|
+
"#fca5a5",
|
|
270
|
+
"#f87171",
|
|
271
|
+
"#ef4444",
|
|
272
|
+
"#dc2626",
|
|
273
|
+
"#b91c1c",
|
|
274
|
+
"#991b1b",
|
|
275
|
+
"#7f1d1d",
|
|
276
|
+
"#450a0a"
|
|
277
|
+
],
|
|
278
|
+
orange: [
|
|
279
|
+
"#fff7ed",
|
|
280
|
+
"#ffedd5",
|
|
281
|
+
"#fed7aa",
|
|
282
|
+
"#fdba74",
|
|
283
|
+
"#fb923c",
|
|
284
|
+
"#f97316",
|
|
285
|
+
"#ea580c",
|
|
286
|
+
"#c2410c",
|
|
287
|
+
"#9a3412",
|
|
288
|
+
"#7c2d12",
|
|
289
|
+
"#431407"
|
|
290
|
+
],
|
|
291
|
+
amber: [
|
|
292
|
+
"#fffbeb",
|
|
293
|
+
"#fef3c7",
|
|
294
|
+
"#fde68a",
|
|
295
|
+
"#fcd34d",
|
|
296
|
+
"#fbbf24",
|
|
297
|
+
"#f59e0b",
|
|
298
|
+
"#d97706",
|
|
299
|
+
"#b45309",
|
|
300
|
+
"#92400e",
|
|
301
|
+
"#78350f",
|
|
302
|
+
"#451a03"
|
|
303
|
+
],
|
|
304
|
+
yellow: [
|
|
305
|
+
"#fefce8",
|
|
306
|
+
"#fef9c3",
|
|
307
|
+
"#fef08a",
|
|
308
|
+
"#fde047",
|
|
309
|
+
"#facc15",
|
|
310
|
+
"#eab308",
|
|
311
|
+
"#ca8a04",
|
|
312
|
+
"#a16207",
|
|
313
|
+
"#854d0e",
|
|
314
|
+
"#713f12",
|
|
315
|
+
"#422006"
|
|
316
|
+
],
|
|
317
|
+
lime: [
|
|
318
|
+
"#f7fee7",
|
|
319
|
+
"#ecfccb",
|
|
320
|
+
"#d9f99d",
|
|
321
|
+
"#bef264",
|
|
322
|
+
"#a3e635",
|
|
323
|
+
"#84cc16",
|
|
324
|
+
"#65a30d",
|
|
325
|
+
"#4d7c0f",
|
|
326
|
+
"#3f6212",
|
|
327
|
+
"#365314",
|
|
328
|
+
"#1a2e05"
|
|
329
|
+
],
|
|
330
|
+
green: [
|
|
331
|
+
"#f0fdf4",
|
|
332
|
+
"#dcfce7",
|
|
333
|
+
"#bbf7d0",
|
|
334
|
+
"#86efac",
|
|
335
|
+
"#4ade80",
|
|
336
|
+
"#22c55e",
|
|
337
|
+
"#16a34a",
|
|
338
|
+
"#15803d",
|
|
339
|
+
"#166534",
|
|
340
|
+
"#14532d",
|
|
341
|
+
"#052e16"
|
|
342
|
+
],
|
|
343
|
+
emerald: [
|
|
344
|
+
"#ecfdf5",
|
|
345
|
+
"#d1fae5",
|
|
346
|
+
"#a7f3d0",
|
|
347
|
+
"#6ee7b7",
|
|
348
|
+
"#34d399",
|
|
349
|
+
"#10b981",
|
|
350
|
+
"#059669",
|
|
351
|
+
"#047857",
|
|
352
|
+
"#065f46",
|
|
353
|
+
"#064e3b",
|
|
354
|
+
"#022c22"
|
|
355
|
+
],
|
|
356
|
+
teal: [
|
|
357
|
+
"#f0fdfa",
|
|
358
|
+
"#ccfbf1",
|
|
359
|
+
"#99f6e4",
|
|
360
|
+
"#5eead4",
|
|
361
|
+
"#2dd4bf",
|
|
362
|
+
"#14b8a6",
|
|
363
|
+
"#0d9488",
|
|
364
|
+
"#0f766e",
|
|
365
|
+
"#115e59",
|
|
366
|
+
"#134e4a",
|
|
367
|
+
"#042f2e"
|
|
368
|
+
],
|
|
369
|
+
cyan: [
|
|
370
|
+
"#ecfeff",
|
|
371
|
+
"#cffafe",
|
|
372
|
+
"#a5f3fc",
|
|
373
|
+
"#67e8f9",
|
|
374
|
+
"#22d3ee",
|
|
375
|
+
"#06b6d4",
|
|
376
|
+
"#0891b2",
|
|
377
|
+
"#0e7490",
|
|
378
|
+
"#155e75",
|
|
379
|
+
"#164e63",
|
|
380
|
+
"#083344"
|
|
381
|
+
],
|
|
382
|
+
sky: [
|
|
383
|
+
"#f0f9ff",
|
|
384
|
+
"#e0f2fe",
|
|
385
|
+
"#bae6fd",
|
|
386
|
+
"#7dd3fc",
|
|
387
|
+
"#38bdf8",
|
|
388
|
+
"#0ea5e9",
|
|
389
|
+
"#0284c7",
|
|
390
|
+
"#0369a1",
|
|
391
|
+
"#075985",
|
|
392
|
+
"#0c4a6e",
|
|
393
|
+
"#082f49"
|
|
394
|
+
],
|
|
395
|
+
blue: [
|
|
396
|
+
"#eff6ff",
|
|
397
|
+
"#dbeafe",
|
|
398
|
+
"#bfdbfe",
|
|
399
|
+
"#93c5fd",
|
|
400
|
+
"#60a5fa",
|
|
401
|
+
"#3b82f6",
|
|
402
|
+
"#2563eb",
|
|
403
|
+
"#1d4ed8",
|
|
404
|
+
"#1e40af",
|
|
405
|
+
"#1e3a8a",
|
|
406
|
+
"#172554"
|
|
407
|
+
],
|
|
408
|
+
indigo: [
|
|
409
|
+
"#eef2ff",
|
|
410
|
+
"#e0e7ff",
|
|
411
|
+
"#c7d2fe",
|
|
412
|
+
"#a5b4fc",
|
|
413
|
+
"#818cf8",
|
|
414
|
+
"#6366f1",
|
|
415
|
+
"#4f46e5",
|
|
416
|
+
"#4338ca",
|
|
417
|
+
"#3730a3",
|
|
418
|
+
"#312e81",
|
|
419
|
+
"#1e1b4b"
|
|
420
|
+
],
|
|
421
|
+
violet: [
|
|
422
|
+
"#f5f3ff",
|
|
423
|
+
"#ede9fe",
|
|
424
|
+
"#ddd6fe",
|
|
425
|
+
"#c4b5fd",
|
|
426
|
+
"#a78bfa",
|
|
427
|
+
"#8b5cf6",
|
|
428
|
+
"#7c3aed",
|
|
429
|
+
"#6d28d9",
|
|
430
|
+
"#5b21b6",
|
|
431
|
+
"#4c1d95",
|
|
432
|
+
"#2e1065"
|
|
433
|
+
],
|
|
434
|
+
purple: [
|
|
435
|
+
"#faf5ff",
|
|
436
|
+
"#f3e8ff",
|
|
437
|
+
"#e9d5ff",
|
|
438
|
+
"#d8b4fe",
|
|
439
|
+
"#c084fc",
|
|
440
|
+
"#a855f7",
|
|
441
|
+
"#9333ea",
|
|
442
|
+
"#7e22ce",
|
|
443
|
+
"#6b21a8",
|
|
444
|
+
"#581c87",
|
|
445
|
+
"#3b0764"
|
|
446
|
+
],
|
|
447
|
+
fuchsia: [
|
|
448
|
+
"#fdf4ff",
|
|
449
|
+
"#fae8ff",
|
|
450
|
+
"#f5d0fe",
|
|
451
|
+
"#f0abfc",
|
|
452
|
+
"#e879f9",
|
|
453
|
+
"#d946ef",
|
|
454
|
+
"#c026d3",
|
|
455
|
+
"#a21caf",
|
|
456
|
+
"#86198f",
|
|
457
|
+
"#701a75",
|
|
458
|
+
"#4a044e"
|
|
459
|
+
],
|
|
460
|
+
pink: [
|
|
461
|
+
"#fdf2f8",
|
|
462
|
+
"#fce7f3",
|
|
463
|
+
"#fbcfe8",
|
|
464
|
+
"#f9a8d4",
|
|
465
|
+
"#f472b6",
|
|
466
|
+
"#ec4899",
|
|
467
|
+
"#db2777",
|
|
468
|
+
"#be185d",
|
|
469
|
+
"#9d174d",
|
|
470
|
+
"#831843",
|
|
471
|
+
"#500724"
|
|
472
|
+
],
|
|
473
|
+
rose: [
|
|
474
|
+
"#fff1f2",
|
|
475
|
+
"#ffe4e6",
|
|
476
|
+
"#fecdd3",
|
|
477
|
+
"#fda4af",
|
|
478
|
+
"#fb7185",
|
|
479
|
+
"#f43f5e",
|
|
480
|
+
"#e11d48",
|
|
481
|
+
"#be123c",
|
|
482
|
+
"#9f1239",
|
|
483
|
+
"#881337",
|
|
484
|
+
"#4c0519"
|
|
485
|
+
]
|
|
486
|
+
};
|
|
487
|
+
var SHADES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
488
|
+
function resolveColor(color) {
|
|
489
|
+
const match = /^([a-z]+)(?:-(\d{2,3}))?$/.exec(color);
|
|
490
|
+
const palette = match && PALETTE[match[1]];
|
|
491
|
+
if (!palette) return color;
|
|
492
|
+
const index = SHADES.indexOf(match[2] === void 0 ? 500 : Number(match[2]));
|
|
493
|
+
return index === -1 ? color : palette[index];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/lib/labels.ts
|
|
497
|
+
var LABELS = {
|
|
498
|
+
en: { region: "Notifications", close: "Close" },
|
|
499
|
+
ar: { region: "\u0627\u0644\u0625\u0634\u0639\u0627\u0631\u0627\u062A", close: "\u0625\u063A\u0644\u0627\u0642" }
|
|
500
|
+
};
|
|
501
|
+
function resolveLabels(locale = "en", overrides) {
|
|
502
|
+
return { ...LABELS[locale] ?? LABELS.en, ...overrides };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/lib/utils.ts
|
|
506
|
+
function cx(...parts) {
|
|
507
|
+
return parts.filter(Boolean).join(" ");
|
|
508
|
+
}
|
|
509
|
+
var toCssSize = (value) => typeof value === "number" ? `${value}px` : value;
|
|
510
|
+
|
|
511
|
+
// src/components/icons.tsx
|
|
512
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
513
|
+
function icon(paths) {
|
|
514
|
+
return function Icon(props) {
|
|
515
|
+
return /* @__PURE__ */ jsx(
|
|
516
|
+
"svg",
|
|
517
|
+
{
|
|
518
|
+
viewBox: "0 0 24 24",
|
|
519
|
+
width: "1em",
|
|
520
|
+
height: "1em",
|
|
521
|
+
fill: "none",
|
|
522
|
+
stroke: "currentColor",
|
|
523
|
+
strokeWidth: 2.25,
|
|
524
|
+
strokeLinecap: "round",
|
|
525
|
+
strokeLinejoin: "round",
|
|
526
|
+
"aria-hidden": "true",
|
|
527
|
+
...props,
|
|
528
|
+
children: paths
|
|
529
|
+
}
|
|
530
|
+
);
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
var SuccessIcon = icon(
|
|
534
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
535
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
536
|
+
/* @__PURE__ */ jsx("path", { d: "m9 12 2 2 4-4" })
|
|
537
|
+
] })
|
|
538
|
+
);
|
|
539
|
+
var ErrorIcon = icon(
|
|
540
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
541
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
542
|
+
/* @__PURE__ */ jsx("path", { d: "m15 9-6 6M9 9l6 6" })
|
|
543
|
+
] })
|
|
544
|
+
);
|
|
545
|
+
var WarningIcon = icon(
|
|
546
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
547
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
548
|
+
/* @__PURE__ */ jsx("path", { d: "M12 8v4M12 16h.01" })
|
|
549
|
+
] })
|
|
550
|
+
);
|
|
551
|
+
var InfoIcon = icon(
|
|
552
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
553
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
554
|
+
/* @__PURE__ */ jsx("path", { d: "M12 16v-4M12 8h.01" })
|
|
555
|
+
] })
|
|
556
|
+
);
|
|
557
|
+
var LoadingIcon = icon(/* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }));
|
|
558
|
+
var CloseIcon = icon(/* @__PURE__ */ jsx("path", { d: "M18 6 6 18M6 6l12 12" }));
|
|
559
|
+
var DEFAULT_ICONS = {
|
|
560
|
+
success: /* @__PURE__ */ jsx(SuccessIcon, {}),
|
|
561
|
+
error: /* @__PURE__ */ jsx(ErrorIcon, {}),
|
|
562
|
+
warning: /* @__PURE__ */ jsx(WarningIcon, {}),
|
|
563
|
+
info: /* @__PURE__ */ jsx(InfoIcon, {}),
|
|
564
|
+
loading: /* @__PURE__ */ jsx(LoadingIcon, { className: "wello-notifications-spin" })
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// src/components/toast-item.tsx
|
|
568
|
+
import {
|
|
569
|
+
useEffect,
|
|
570
|
+
useRef,
|
|
571
|
+
useState
|
|
572
|
+
} from "react";
|
|
573
|
+
|
|
574
|
+
// src/sound/notification-sound.ts
|
|
575
|
+
var TIMBRES = {
|
|
576
|
+
// Warm bell: octave and a slightly inharmonic upper partial for shimmer.
|
|
577
|
+
bell: [
|
|
578
|
+
{ ratio: 1, gain: 1, decay: 1 },
|
|
579
|
+
{ ratio: 2, gain: 0.28, decay: 0.55 },
|
|
580
|
+
{ ratio: 3.01, gain: 0.1, decay: 0.32 },
|
|
581
|
+
{ ratio: 5.43, gain: 0.035, decay: 0.16 }
|
|
582
|
+
],
|
|
583
|
+
// Wooden mallet: strong fundamental, quick bright "knock" on top.
|
|
584
|
+
marimba: [
|
|
585
|
+
{ ratio: 1, gain: 1, decay: 1 },
|
|
586
|
+
{ ratio: 3.98, gain: 0.16, decay: 0.12 },
|
|
587
|
+
{ ratio: 9.8, gain: 0.03, decay: 0.05 }
|
|
588
|
+
],
|
|
589
|
+
// Soft, darker string pluck for errors.
|
|
590
|
+
pluck: [
|
|
591
|
+
{ ratio: 1, gain: 1, decay: 1, type: "triangle" },
|
|
592
|
+
{ ratio: 2, gain: 0.18, decay: 0.4 },
|
|
593
|
+
{ ratio: 0.5, gain: 0.22, decay: 0.7 }
|
|
594
|
+
],
|
|
595
|
+
// Thin and bright, cuts through for urgent alerts.
|
|
596
|
+
glass: [
|
|
597
|
+
{ ratio: 1, gain: 1, decay: 1 },
|
|
598
|
+
{ ratio: 2.76, gain: 0.22, decay: 0.45 },
|
|
599
|
+
{ ratio: 5.4, gain: 0.07, decay: 0.2 }
|
|
600
|
+
]
|
|
601
|
+
};
|
|
602
|
+
var N = {
|
|
603
|
+
G4: 392,
|
|
604
|
+
A4: 440,
|
|
605
|
+
C5: 523.25,
|
|
606
|
+
D5: 587.33,
|
|
607
|
+
E5: 659.25,
|
|
608
|
+
F5: 698.46,
|
|
609
|
+
G5: 783.99,
|
|
610
|
+
A5: 880,
|
|
611
|
+
B5: 987.77,
|
|
612
|
+
C6: 1046.5,
|
|
613
|
+
E6: 1318.51,
|
|
614
|
+
G6: 1567.98
|
|
615
|
+
};
|
|
616
|
+
var SOUNDS = {
|
|
617
|
+
// Rising major arpeggio: bright and "done".
|
|
618
|
+
success: [
|
|
619
|
+
{ f: N.C5, at: 0, dur: 0.5, gain: 0.7, timbre: "marimba" },
|
|
620
|
+
{ f: N.E5, at: 0.075, dur: 0.5, gain: 0.7, timbre: "marimba" },
|
|
621
|
+
{ f: N.G5, at: 0.15, dur: 0.55, gain: 0.75, timbre: "marimba" },
|
|
622
|
+
{ f: N.C6, at: 0.225, dur: 0.9, gain: 0.6, timbre: "bell" }
|
|
623
|
+
],
|
|
624
|
+
// Falling minor step, low and soft: noticeable without being harsh.
|
|
625
|
+
error: [
|
|
626
|
+
{ f: N.E5, at: 0, dur: 0.35, gain: 0.75, timbre: "pluck" },
|
|
627
|
+
{ f: N.C5, at: 0.13, dur: 0.6, gain: 0.85, timbre: "pluck" }
|
|
628
|
+
],
|
|
629
|
+
// Two even knocks: "look here".
|
|
630
|
+
warning: [
|
|
631
|
+
{ f: N.D5, at: 0, dur: 0.32, gain: 0.85, timbre: "marimba" },
|
|
632
|
+
{ f: N.D5, at: 0.17, dur: 0.45, gain: 0.85, timbre: "marimba" }
|
|
633
|
+
],
|
|
634
|
+
// A single soft bell with its octave.
|
|
635
|
+
info: [
|
|
636
|
+
{ f: N.A5, at: 0, dur: 1.1, gain: 0.95, timbre: "bell" },
|
|
637
|
+
{ f: N.E6, at: 0.03, dur: 0.6, gain: 0.25, timbre: "bell" }
|
|
638
|
+
],
|
|
639
|
+
// Chat-style "ding-dong".
|
|
640
|
+
message: [
|
|
641
|
+
{ f: N.E6, at: 0, dur: 0.6, gain: 0.55, timbre: "bell" },
|
|
642
|
+
{ f: N.B5, at: 0.12, dur: 1, gain: 0.65, timbre: "bell" }
|
|
643
|
+
],
|
|
644
|
+
// Three quick rising pairs: urgent, repeats so it isn't missed.
|
|
645
|
+
critical: [0, 0.32, 0.64].flatMap((start) => [
|
|
646
|
+
{ f: N.A5, at: start, dur: 0.22, gain: 0.7, timbre: "glass" },
|
|
647
|
+
{ f: N.E6, at: start + 0.1, dur: 0.3, gain: 0.7, timbre: "glass" }
|
|
648
|
+
]),
|
|
649
|
+
// Tiny bubble pop for plain toasts.
|
|
650
|
+
pop: [{ f: N.G5, at: 0, dur: 0.3, gain: 2.2, timbre: "marimba", glide: 1.6 }]
|
|
651
|
+
};
|
|
652
|
+
var PRIORITY_SOUNDS = {
|
|
653
|
+
critical: "critical",
|
|
654
|
+
high: "message",
|
|
655
|
+
normal: "info",
|
|
656
|
+
low: "pop"
|
|
657
|
+
};
|
|
658
|
+
var isSoundName = (value) => value in SOUNDS;
|
|
659
|
+
var toSoundName = (name) => isSoundName(name) ? name : PRIORITY_SOUNDS[name] ?? "info";
|
|
660
|
+
var ATTACK = 6e-3;
|
|
661
|
+
function scheduleNote(ctx, out, note, start) {
|
|
662
|
+
const t0 = start + note.at;
|
|
663
|
+
for (const partial of TIMBRES[note.timbre]) {
|
|
664
|
+
const frequency = note.f * partial.ratio;
|
|
665
|
+
if (frequency > 16e3) continue;
|
|
666
|
+
const peak = (note.gain ?? 1) * partial.gain;
|
|
667
|
+
const end = t0 + ATTACK + Math.max(0.04, note.dur * partial.decay);
|
|
668
|
+
const oscillator = ctx.createOscillator();
|
|
669
|
+
const envelope = ctx.createGain();
|
|
670
|
+
oscillator.type = partial.type ?? "sine";
|
|
671
|
+
if (note.glide) {
|
|
672
|
+
oscillator.frequency.setValueAtTime(frequency * note.glide, t0);
|
|
673
|
+
oscillator.frequency.exponentialRampToValueAtTime(frequency, t0 + 0.04);
|
|
674
|
+
} else {
|
|
675
|
+
oscillator.frequency.setValueAtTime(frequency, t0);
|
|
676
|
+
}
|
|
677
|
+
envelope.gain.setValueAtTime(1e-4, t0);
|
|
678
|
+
envelope.gain.exponentialRampToValueAtTime(peak, t0 + ATTACK);
|
|
679
|
+
envelope.gain.exponentialRampToValueAtTime(1e-4, end);
|
|
680
|
+
oscillator.connect(envelope);
|
|
681
|
+
envelope.connect(out);
|
|
682
|
+
oscillator.start(t0);
|
|
683
|
+
oscillator.stop(end + 0.02);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function createRoom(ctx) {
|
|
687
|
+
const seconds = 1.2;
|
|
688
|
+
const length = Math.floor(ctx.sampleRate * seconds);
|
|
689
|
+
const buffer = ctx.createBuffer(2, length, ctx.sampleRate);
|
|
690
|
+
for (let channel = 0; channel < 2; channel++) {
|
|
691
|
+
const data = buffer.getChannelData(channel);
|
|
692
|
+
for (let i = 0; i < length; i++) {
|
|
693
|
+
data[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / length, 3.5);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return buffer;
|
|
697
|
+
}
|
|
698
|
+
var buses = /* @__PURE__ */ new WeakMap();
|
|
699
|
+
function bus(ctx) {
|
|
700
|
+
const existing = buses.get(ctx);
|
|
701
|
+
if (existing) return existing;
|
|
702
|
+
const input = ctx.createGain();
|
|
703
|
+
const tone = ctx.createBiquadFilter();
|
|
704
|
+
tone.type = "lowpass";
|
|
705
|
+
tone.frequency.value = 7500;
|
|
706
|
+
const reverb = ctx.createConvolver();
|
|
707
|
+
reverb.buffer = createRoom(ctx);
|
|
708
|
+
const wet = ctx.createGain();
|
|
709
|
+
wet.gain.value = 0.16;
|
|
710
|
+
const compressor = ctx.createDynamicsCompressor();
|
|
711
|
+
compressor.threshold.value = -16;
|
|
712
|
+
compressor.knee.value = 10;
|
|
713
|
+
compressor.ratio.value = 4;
|
|
714
|
+
compressor.attack.value = 2e-3;
|
|
715
|
+
compressor.release.value = 0.2;
|
|
716
|
+
input.connect(tone);
|
|
717
|
+
tone.connect(compressor);
|
|
718
|
+
tone.connect(reverb);
|
|
719
|
+
reverb.connect(wet);
|
|
720
|
+
wet.connect(compressor);
|
|
721
|
+
compressor.connect(ctx.destination);
|
|
722
|
+
const created = { input };
|
|
723
|
+
buses.set(ctx, created);
|
|
724
|
+
return created;
|
|
725
|
+
}
|
|
726
|
+
function scheduleSound(ctx, name, volume = 0.7, when = ctx.currentTime + 0.01) {
|
|
727
|
+
const notes = SOUNDS[toSoundName(name)];
|
|
728
|
+
const level = ctx.createGain();
|
|
729
|
+
level.gain.value = Math.min(1, Math.max(0, volume)) * 0.32;
|
|
730
|
+
level.connect(bus(ctx).input);
|
|
731
|
+
for (const note of notes) scheduleNote(ctx, level, note, when);
|
|
732
|
+
return Math.max(...notes.map((n) => n.at + n.dur)) + 1.2;
|
|
733
|
+
}
|
|
734
|
+
var context = null;
|
|
735
|
+
var buffers = /* @__PURE__ */ new Map();
|
|
736
|
+
function audioContext() {
|
|
737
|
+
if (typeof window === "undefined") return null;
|
|
738
|
+
try {
|
|
739
|
+
const Ctor = window.AudioContext ?? window.webkitAudioContext;
|
|
740
|
+
if (!Ctor) return null;
|
|
741
|
+
context ?? (context = new Ctor());
|
|
742
|
+
if (context.state === "suspended") void context.resume().catch(() => {
|
|
743
|
+
});
|
|
744
|
+
return context;
|
|
745
|
+
} catch {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function playSound(name = "info", options = {}) {
|
|
750
|
+
const ctx = audioContext();
|
|
751
|
+
if (!ctx) return;
|
|
752
|
+
try {
|
|
753
|
+
scheduleSound(ctx, name, options.volume ?? 0.7);
|
|
754
|
+
} catch {
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function playTone(priority = "normal", volume = 0.7) {
|
|
758
|
+
playSound(priority, { volume });
|
|
759
|
+
}
|
|
760
|
+
var NOTIFICATION_SOUNDS = Object.keys(SOUNDS);
|
|
761
|
+
async function playNotificationSound(url, options = {}) {
|
|
762
|
+
const { volume = 0.7, fallback = "info" } = options;
|
|
763
|
+
if (url && isSoundName(url)) return playSound(url, { volume });
|
|
764
|
+
if (url) {
|
|
765
|
+
const ctx = audioContext();
|
|
766
|
+
if (ctx) {
|
|
767
|
+
try {
|
|
768
|
+
let buffer = buffers.get(url);
|
|
769
|
+
if (!buffer) {
|
|
770
|
+
buffer = fetch(url).then((response) => {
|
|
771
|
+
if (!response.ok) throw new Error(`${response.status}`);
|
|
772
|
+
return response.arrayBuffer();
|
|
773
|
+
}).then((data) => ctx.decodeAudioData(data));
|
|
774
|
+
buffers.set(url, buffer);
|
|
775
|
+
buffer.catch(() => buffers.delete(url));
|
|
776
|
+
}
|
|
777
|
+
const source = ctx.createBufferSource();
|
|
778
|
+
const gain = ctx.createGain();
|
|
779
|
+
gain.gain.value = volume;
|
|
780
|
+
source.buffer = await buffer;
|
|
781
|
+
source.connect(gain);
|
|
782
|
+
gain.connect(ctx.destination);
|
|
783
|
+
source.start(0);
|
|
784
|
+
return;
|
|
785
|
+
} catch {
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
try {
|
|
789
|
+
const audio = new Audio(url);
|
|
790
|
+
audio.volume = volume;
|
|
791
|
+
await audio.play();
|
|
792
|
+
return;
|
|
793
|
+
} catch {
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (fallback) playSound(fallback, { volume });
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/components/toast-item.tsx
|
|
800
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
801
|
+
var EXIT_MS = 320;
|
|
802
|
+
var SWIPE_THRESHOLD = 64;
|
|
803
|
+
var TYPE_SOUNDS = {
|
|
804
|
+
success: "success",
|
|
805
|
+
error: "error",
|
|
806
|
+
warning: "warning",
|
|
807
|
+
info: "info",
|
|
808
|
+
default: "pop"
|
|
809
|
+
};
|
|
810
|
+
function ToastItem({ toast: toast2, settings, paused, labels }) {
|
|
811
|
+
const { id, open, version, type } = toast2;
|
|
812
|
+
const { duration, classNames, styles } = settings;
|
|
813
|
+
const cardRef = useRef(null);
|
|
814
|
+
const [swipedOut, setSwipedOut] = useState(null);
|
|
815
|
+
const part = (name, base) => ({
|
|
816
|
+
className: cx(base, classNames[name]),
|
|
817
|
+
style: styles[name]
|
|
818
|
+
});
|
|
819
|
+
const opened = useRef(false);
|
|
820
|
+
useEffect(() => {
|
|
821
|
+
if (opened.current) return;
|
|
822
|
+
opened.current = true;
|
|
823
|
+
toast2.onOpen?.(toast2);
|
|
824
|
+
}, []);
|
|
825
|
+
const soundedType = useRef(null);
|
|
826
|
+
useEffect(() => {
|
|
827
|
+
const sound = settings.sound;
|
|
828
|
+
if (!sound || !open || type === "loading" || soundedType.current === type) return;
|
|
829
|
+
soundedType.current = type;
|
|
830
|
+
const builtIn = TYPE_SOUNDS[type] ?? "info";
|
|
831
|
+
void playNotificationSound(typeof sound === "string" ? sound : builtIn, { fallback: builtIn });
|
|
832
|
+
}, [type, open]);
|
|
833
|
+
const remaining = useRef(duration);
|
|
834
|
+
const lastVersion = useRef(version);
|
|
835
|
+
if (lastVersion.current !== version) {
|
|
836
|
+
lastVersion.current = version;
|
|
837
|
+
remaining.current = duration;
|
|
838
|
+
}
|
|
839
|
+
useEffect(() => {
|
|
840
|
+
const left = remaining.current;
|
|
841
|
+
if (!open || paused || left === false || !Number.isFinite(left)) return;
|
|
842
|
+
const startedAt = Date.now();
|
|
843
|
+
const timer = setTimeout(() => toastStore.dismiss(id, "auto"), Math.max(0, left));
|
|
844
|
+
return () => {
|
|
845
|
+
clearTimeout(timer);
|
|
846
|
+
if (lastVersion.current === version) {
|
|
847
|
+
remaining.current = Math.max(0, left - (Date.now() - startedAt));
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}, [id, open, paused, version, duration]);
|
|
851
|
+
useEffect(() => {
|
|
852
|
+
if (open) return;
|
|
853
|
+
const timer = setTimeout(() => toastStore.remove(id), EXIT_MS);
|
|
854
|
+
return () => clearTimeout(timer);
|
|
855
|
+
}, [id, open]);
|
|
856
|
+
const drag = useRef(null);
|
|
857
|
+
const canSwipe = settings.swipe && settings.dismissible && open;
|
|
858
|
+
function onPointerDown(event) {
|
|
859
|
+
if (!canSwipe || event.button !== 0) return;
|
|
860
|
+
if (event.target.closest("button, a, input, textarea, select")) return;
|
|
861
|
+
drag.current = { x: event.clientX, y: event.clientY, pointer: event.pointerId, dx: 0 };
|
|
862
|
+
}
|
|
863
|
+
function onPointerMove(event) {
|
|
864
|
+
const state2 = drag.current;
|
|
865
|
+
const card = cardRef.current;
|
|
866
|
+
if (!state2 || !card || event.pointerId !== state2.pointer) return;
|
|
867
|
+
const dx = event.clientX - state2.x;
|
|
868
|
+
if (state2.dx === 0 && Math.abs(dx) < 6) return;
|
|
869
|
+
if (state2.dx === 0 && Math.abs(event.clientY - state2.y) > Math.abs(dx)) {
|
|
870
|
+
drag.current = null;
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
if (state2.dx === 0) card.setPointerCapture(event.pointerId);
|
|
874
|
+
state2.dx = dx;
|
|
875
|
+
card.dataset.swiping = "";
|
|
876
|
+
card.style.setProperty("--wello-notifications-swipe", `${dx}px`);
|
|
877
|
+
card.style.opacity = String(Math.max(0.2, 1 - Math.abs(dx) / 220));
|
|
878
|
+
}
|
|
879
|
+
function onPointerUp(event) {
|
|
880
|
+
const state2 = drag.current;
|
|
881
|
+
const card = cardRef.current;
|
|
882
|
+
drag.current = null;
|
|
883
|
+
if (!state2 || !card || event.pointerId !== state2.pointer) return;
|
|
884
|
+
delete card.dataset.swiping;
|
|
885
|
+
if (Math.abs(state2.dx) >= SWIPE_THRESHOLD) {
|
|
886
|
+
setSwipedOut(state2.dx > 0 ? "end" : "start");
|
|
887
|
+
toastStore.dismiss(id);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
card.style.removeProperty("--wello-notifications-swipe");
|
|
891
|
+
card.style.opacity = "";
|
|
892
|
+
}
|
|
893
|
+
function onKeyDown(event) {
|
|
894
|
+
if (event.key === "Escape" && settings.dismissible) {
|
|
895
|
+
event.stopPropagation();
|
|
896
|
+
toastStore.dismiss(id);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
const important = toast2.important ?? type === "error";
|
|
900
|
+
const tone = { "--wello-notifications-tone": settings.color };
|
|
901
|
+
return /* @__PURE__ */ jsx2(
|
|
902
|
+
"li",
|
|
903
|
+
{
|
|
904
|
+
className: "wello-notifications-item",
|
|
905
|
+
"data-state": open ? "open" : "closing",
|
|
906
|
+
"data-swiped": swipedOut ?? void 0,
|
|
907
|
+
onKeyDown,
|
|
908
|
+
children: /* @__PURE__ */ jsx2("div", { className: "wello-notifications-item-inner", children: toast2.render ? /* @__PURE__ */ jsx2(
|
|
909
|
+
"div",
|
|
910
|
+
{
|
|
911
|
+
ref: cardRef,
|
|
912
|
+
className: cx("wello-notifications-custom", settings.className),
|
|
913
|
+
style: { ...tone, ...settings.style },
|
|
914
|
+
role: important ? "alert" : "status",
|
|
915
|
+
"aria-live": important ? "assertive" : "polite",
|
|
916
|
+
"aria-atomic": "true",
|
|
917
|
+
"data-type": type,
|
|
918
|
+
onPointerDown,
|
|
919
|
+
onPointerMove,
|
|
920
|
+
onPointerUp,
|
|
921
|
+
onPointerCancel: onPointerUp,
|
|
922
|
+
children: toast2.render(toast2)
|
|
923
|
+
}
|
|
924
|
+
) : /* @__PURE__ */ jsxs2(
|
|
925
|
+
"div",
|
|
926
|
+
{
|
|
927
|
+
ref: cardRef,
|
|
928
|
+
className: cx("wello-notifications-toast", classNames.toast, settings.className),
|
|
929
|
+
style: { ...tone, ...styles.toast, ...settings.style },
|
|
930
|
+
role: important ? "alert" : "status",
|
|
931
|
+
"aria-live": important ? "assertive" : "polite",
|
|
932
|
+
"aria-atomic": "true",
|
|
933
|
+
"data-type": type,
|
|
934
|
+
"data-dismissible": settings.dismissible || void 0,
|
|
935
|
+
onPointerDown,
|
|
936
|
+
onPointerMove,
|
|
937
|
+
onPointerUp,
|
|
938
|
+
onPointerCancel: onPointerUp,
|
|
939
|
+
children: [
|
|
940
|
+
settings.icon != null && settings.icon !== false && /* @__PURE__ */ jsx2("span", { ...part("icon", "wello-notifications-icon"), children: settings.icon }),
|
|
941
|
+
/* @__PURE__ */ jsxs2("div", { ...part("content", "wello-notifications-content"), children: [
|
|
942
|
+
toast2.title != null && toast2.title !== false && /* @__PURE__ */ jsx2("div", { ...part("title", "wello-notifications-title"), children: toast2.title }),
|
|
943
|
+
toast2.description != null && toast2.description !== false && /* @__PURE__ */ jsx2("div", { ...part("description", "wello-notifications-description"), children: toast2.description }),
|
|
944
|
+
(toast2.action || toast2.cancel) && /* @__PURE__ */ jsxs2("div", { ...part("actions", "wello-notifications-actions"), children: [
|
|
945
|
+
toast2.cancel && /* @__PURE__ */ jsx2(
|
|
946
|
+
ActionButton,
|
|
947
|
+
{
|
|
948
|
+
action: toast2.cancel,
|
|
949
|
+
id,
|
|
950
|
+
...part("cancel", "wello-notifications-button wello-notifications-cancel")
|
|
951
|
+
}
|
|
952
|
+
),
|
|
953
|
+
toast2.action && /* @__PURE__ */ jsx2(
|
|
954
|
+
ActionButton,
|
|
955
|
+
{
|
|
956
|
+
action: toast2.action,
|
|
957
|
+
id,
|
|
958
|
+
...part("action", "wello-notifications-button wello-notifications-action")
|
|
959
|
+
}
|
|
960
|
+
)
|
|
961
|
+
] })
|
|
962
|
+
] }),
|
|
963
|
+
settings.dismissible && settings.closeButton && /* @__PURE__ */ jsx2(
|
|
964
|
+
"button",
|
|
965
|
+
{
|
|
966
|
+
type: "button",
|
|
967
|
+
...part("closeButton", "wello-notifications-close"),
|
|
968
|
+
"aria-label": labels.close,
|
|
969
|
+
title: labels.close,
|
|
970
|
+
onClick: () => toastStore.dismiss(id),
|
|
971
|
+
children: /* @__PURE__ */ jsx2(CloseIcon, {})
|
|
972
|
+
}
|
|
973
|
+
),
|
|
974
|
+
settings.progress && duration !== false && /* @__PURE__ */ jsx2(
|
|
975
|
+
"span",
|
|
976
|
+
{
|
|
977
|
+
...part("progress", "wello-notifications-progress"),
|
|
978
|
+
style: {
|
|
979
|
+
animationDuration: `${duration}ms`,
|
|
980
|
+
animationPlayState: paused || !open ? "paused" : "running",
|
|
981
|
+
...styles.progress
|
|
982
|
+
},
|
|
983
|
+
"aria-hidden": "true"
|
|
984
|
+
},
|
|
985
|
+
version
|
|
986
|
+
)
|
|
987
|
+
]
|
|
988
|
+
}
|
|
989
|
+
) })
|
|
990
|
+
}
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
function ActionButton({
|
|
994
|
+
action,
|
|
995
|
+
id,
|
|
996
|
+
className,
|
|
997
|
+
style
|
|
998
|
+
}) {
|
|
999
|
+
return /* @__PURE__ */ jsx2(
|
|
1000
|
+
"button",
|
|
1001
|
+
{
|
|
1002
|
+
type: "button",
|
|
1003
|
+
className,
|
|
1004
|
+
style,
|
|
1005
|
+
onClick: (event) => {
|
|
1006
|
+
action.onClick?.(event);
|
|
1007
|
+
if (action.closeOnClick !== false && !event.defaultPrevented) toastStore.dismiss(id);
|
|
1008
|
+
},
|
|
1009
|
+
children: action.label
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// src/components/toaster.tsx
|
|
1015
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1016
|
+
var DEFAULT_COLORS = {
|
|
1017
|
+
default: "slate-500",
|
|
1018
|
+
success: "emerald-600",
|
|
1019
|
+
error: "red-600",
|
|
1020
|
+
warning: "amber-600",
|
|
1021
|
+
info: "blue-600",
|
|
1022
|
+
loading: "slate-500"
|
|
1023
|
+
};
|
|
1024
|
+
var DEFAULT_DURATIONS = {
|
|
1025
|
+
error: 5500,
|
|
1026
|
+
warning: 5e3,
|
|
1027
|
+
loading: false
|
|
1028
|
+
};
|
|
1029
|
+
var EMPTY = { toasts: [], paused: false };
|
|
1030
|
+
var getServerState = () => EMPTY;
|
|
1031
|
+
var nextToasterId = 0;
|
|
1032
|
+
var activeToasterId = null;
|
|
1033
|
+
var mountedToasters = /* @__PURE__ */ new Set();
|
|
1034
|
+
var toasterListeners = /* @__PURE__ */ new Set();
|
|
1035
|
+
function subscribeToasters(listener) {
|
|
1036
|
+
toasterListeners.add(listener);
|
|
1037
|
+
return () => {
|
|
1038
|
+
toasterListeners.delete(listener);
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function registerToaster(id) {
|
|
1042
|
+
mountedToasters.add(id);
|
|
1043
|
+
if (activeToasterId === null) {
|
|
1044
|
+
activeToasterId = id;
|
|
1045
|
+
toasterListeners.forEach((listener) => listener());
|
|
1046
|
+
}
|
|
1047
|
+
return () => {
|
|
1048
|
+
mountedToasters.delete(id);
|
|
1049
|
+
if (activeToasterId === id) {
|
|
1050
|
+
activeToasterId = mountedToasters.values().next().value ?? null;
|
|
1051
|
+
toasterListeners.forEach((listener) => listener());
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
function useDocumentDirection(dir) {
|
|
1056
|
+
const [documentDir, setDocumentDir] = useState2("ltr");
|
|
1057
|
+
useEffect2(() => {
|
|
1058
|
+
if (dir !== "auto" || typeof document === "undefined") return;
|
|
1059
|
+
const html = document.documentElement;
|
|
1060
|
+
const read = () => setDocumentDir(
|
|
1061
|
+
(html.getAttribute("dir") || getComputedStyle(html).direction) === "rtl" ? "rtl" : "ltr"
|
|
1062
|
+
);
|
|
1063
|
+
read();
|
|
1064
|
+
const observer = new MutationObserver(read);
|
|
1065
|
+
observer.observe(html, { attributes: true, attributeFilter: ["dir"] });
|
|
1066
|
+
return () => observer.disconnect();
|
|
1067
|
+
}, [dir]);
|
|
1068
|
+
return dir === "ltr" || dir === "rtl" ? dir : documentDir;
|
|
1069
|
+
}
|
|
1070
|
+
function usePageHidden(enabled) {
|
|
1071
|
+
const [hidden, setHidden] = useState2(false);
|
|
1072
|
+
useEffect2(() => {
|
|
1073
|
+
if (!enabled) return;
|
|
1074
|
+
const update2 = () => setHidden(document.visibilityState === "hidden");
|
|
1075
|
+
update2();
|
|
1076
|
+
document.addEventListener("visibilitychange", update2);
|
|
1077
|
+
return () => document.removeEventListener("visibilitychange", update2);
|
|
1078
|
+
}, [enabled]);
|
|
1079
|
+
return enabled && hidden;
|
|
1080
|
+
}
|
|
1081
|
+
function useSystemDark(enabled) {
|
|
1082
|
+
const [dark, setDark] = useState2(false);
|
|
1083
|
+
useEffect2(() => {
|
|
1084
|
+
if (!enabled || typeof matchMedia === "undefined") return;
|
|
1085
|
+
const query = matchMedia("(prefers-color-scheme: dark)");
|
|
1086
|
+
const update2 = () => setDark(query.matches);
|
|
1087
|
+
update2();
|
|
1088
|
+
query.addEventListener("change", update2);
|
|
1089
|
+
return () => query.removeEventListener("change", update2);
|
|
1090
|
+
}, [enabled]);
|
|
1091
|
+
return dark;
|
|
1092
|
+
}
|
|
1093
|
+
function splitPosition(position, dir) {
|
|
1094
|
+
const [y, x] = position.split("-");
|
|
1095
|
+
const physical = {
|
|
1096
|
+
left: dir === "ltr" ? "start" : "end",
|
|
1097
|
+
right: dir === "ltr" ? "end" : "start"
|
|
1098
|
+
};
|
|
1099
|
+
return { y, x: physical[x] ?? x };
|
|
1100
|
+
}
|
|
1101
|
+
function Toaster(props) {
|
|
1102
|
+
const {
|
|
1103
|
+
position = "bottom-start",
|
|
1104
|
+
dir: dirProp = "auto",
|
|
1105
|
+
limit = 4,
|
|
1106
|
+
duration = 4e3,
|
|
1107
|
+
durations,
|
|
1108
|
+
colors,
|
|
1109
|
+
icons,
|
|
1110
|
+
closeButton = true,
|
|
1111
|
+
progress = true,
|
|
1112
|
+
swipe = true,
|
|
1113
|
+
pauseOnHover = true,
|
|
1114
|
+
pauseWhenPageHidden = true,
|
|
1115
|
+
sound = false,
|
|
1116
|
+
theme,
|
|
1117
|
+
width = 390,
|
|
1118
|
+
gap = 12,
|
|
1119
|
+
offset = 16,
|
|
1120
|
+
zIndex = 11e3,
|
|
1121
|
+
locale,
|
|
1122
|
+
labels: labelOverrides,
|
|
1123
|
+
classNames = {},
|
|
1124
|
+
styles = {},
|
|
1125
|
+
className,
|
|
1126
|
+
style,
|
|
1127
|
+
container
|
|
1128
|
+
} = props;
|
|
1129
|
+
const state2 = useSyncExternalStore2(toastStore.subscribe, toastStore.getState, getServerState);
|
|
1130
|
+
const dir = useDocumentDirection(dirProp);
|
|
1131
|
+
const pageHidden = usePageHidden(pauseWhenPageHidden);
|
|
1132
|
+
const systemDark = useSystemDark(theme === "system");
|
|
1133
|
+
const labels = useMemo(() => resolveLabels(locale, labelOverrides), [locale, labelOverrides]);
|
|
1134
|
+
const [hovered, setHovered] = useState2(null);
|
|
1135
|
+
const instanceId = useMemo(() => ++nextToasterId, []);
|
|
1136
|
+
const isActiveToaster = useSyncExternalStore2(
|
|
1137
|
+
subscribeToasters,
|
|
1138
|
+
() => activeToasterId === instanceId,
|
|
1139
|
+
() => false
|
|
1140
|
+
);
|
|
1141
|
+
const [mounted, setMounted] = useState2(false);
|
|
1142
|
+
useEffect2(() => {
|
|
1143
|
+
setMounted(true);
|
|
1144
|
+
return registerToaster(instanceId);
|
|
1145
|
+
}, [instanceId]);
|
|
1146
|
+
const groups = useMemo(() => {
|
|
1147
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1148
|
+
for (const t of state2.toasts) {
|
|
1149
|
+
const { y, x } = splitPosition(t.position ?? position, dir);
|
|
1150
|
+
const key = `${y}-${x}`;
|
|
1151
|
+
if (!byKey.has(key)) byKey.set(key, { y, x, toasts: [] });
|
|
1152
|
+
byKey.get(key).toasts.push(t);
|
|
1153
|
+
}
|
|
1154
|
+
for (const group of byKey.values()) {
|
|
1155
|
+
const shown = new Set(
|
|
1156
|
+
group.toasts.filter((t) => t.open).sort((a, b) => a.createdAt - b.createdAt).slice(0, Math.max(1, limit))
|
|
1157
|
+
);
|
|
1158
|
+
group.toasts = group.toasts.filter((t) => !t.open || shown.has(t));
|
|
1159
|
+
}
|
|
1160
|
+
return [...byKey.entries()];
|
|
1161
|
+
}, [state2.toasts, position, dir, limit]);
|
|
1162
|
+
useEffect2(() => {
|
|
1163
|
+
if (hovered && !groups.some(([key]) => key === hovered)) setHovered(null);
|
|
1164
|
+
}, [groups, hovered]);
|
|
1165
|
+
if (!mounted || !isActiveToaster) return null;
|
|
1166
|
+
const target = container ?? document.body;
|
|
1167
|
+
const resolve = (t) => {
|
|
1168
|
+
const typeDuration = durations?.[t.type] ?? DEFAULT_DURATIONS[t.type];
|
|
1169
|
+
const customIcon = icons && t.type in icons ? icons[t.type] : void 0;
|
|
1170
|
+
return {
|
|
1171
|
+
duration: t.duration ?? (typeDuration === void 0 ? duration : typeDuration),
|
|
1172
|
+
color: resolveColor(t.color ?? colors?.[t.type] ?? DEFAULT_COLORS[t.type]),
|
|
1173
|
+
icon: t.icon === false ? null : t.icon ?? (customIcon !== void 0 ? customIcon : DEFAULT_ICONS[t.type]),
|
|
1174
|
+
dismissible: t.dismissible ?? t.type !== "loading",
|
|
1175
|
+
closeButton,
|
|
1176
|
+
progress: t.progress ?? progress,
|
|
1177
|
+
swipe,
|
|
1178
|
+
sound: t.sound ?? sound,
|
|
1179
|
+
className: t.className,
|
|
1180
|
+
style: t.style,
|
|
1181
|
+
classNames: { ...classNames, ...t.classNames },
|
|
1182
|
+
styles: { ...styles, ...t.styles }
|
|
1183
|
+
};
|
|
1184
|
+
};
|
|
1185
|
+
const resolvedTheme = theme === "system" ? systemDark ? "dark" : "light" : theme;
|
|
1186
|
+
return createPortal(
|
|
1187
|
+
/* @__PURE__ */ jsx3("div", { role: "region", "aria-label": labels.region, className: "wello-notifications-region", dir, children: groups.map(([key, group]) => /* @__PURE__ */ jsx3(
|
|
1188
|
+
"ol",
|
|
1189
|
+
{
|
|
1190
|
+
className: cx("wello-notifications-toaster", classNames.toaster, className),
|
|
1191
|
+
"data-y": group.y,
|
|
1192
|
+
"data-x": group.x,
|
|
1193
|
+
"data-theme": resolvedTheme,
|
|
1194
|
+
dir,
|
|
1195
|
+
style: {
|
|
1196
|
+
"--wello-notifications-width": toCssSize(width),
|
|
1197
|
+
"--wello-notifications-gap": `${gap}px`,
|
|
1198
|
+
"--wello-notifications-offset": toCssSize(offset),
|
|
1199
|
+
zIndex,
|
|
1200
|
+
...styles.toaster,
|
|
1201
|
+
...style
|
|
1202
|
+
},
|
|
1203
|
+
onMouseEnter: pauseOnHover ? () => setHovered(key) : void 0,
|
|
1204
|
+
onMouseLeave: pauseOnHover ? () => setHovered(null) : void 0,
|
|
1205
|
+
onFocus: pauseOnHover ? () => setHovered(key) : void 0,
|
|
1206
|
+
onBlur: pauseOnHover ? (event) => {
|
|
1207
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
1208
|
+
setHovered(null);
|
|
1209
|
+
} : void 0,
|
|
1210
|
+
children: group.toasts.map((t) => /* @__PURE__ */ jsx3(
|
|
1211
|
+
ToastItem,
|
|
1212
|
+
{
|
|
1213
|
+
toast: t,
|
|
1214
|
+
settings: resolve(t),
|
|
1215
|
+
paused: state2.paused || pageHidden || hovered === key,
|
|
1216
|
+
labels
|
|
1217
|
+
},
|
|
1218
|
+
t.id
|
|
1219
|
+
))
|
|
1220
|
+
},
|
|
1221
|
+
key
|
|
1222
|
+
)) }),
|
|
1223
|
+
target
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// src/tab/tab-notifications.ts
|
|
1228
|
+
var defaultFormat = (count, title) => `(${count > 99 ? "99+" : count}) ${title}`;
|
|
1229
|
+
function createTabNotifications(options = {}) {
|
|
1230
|
+
const { formatTitle = defaultFormat, dotColor = "#ef4444", favicon = true } = options;
|
|
1231
|
+
let ready = false;
|
|
1232
|
+
let originalTitle = "";
|
|
1233
|
+
let originalFavicon = null;
|
|
1234
|
+
let unread = 0;
|
|
1235
|
+
let flashTimer = null;
|
|
1236
|
+
let stopListening = null;
|
|
1237
|
+
let dotted = null;
|
|
1238
|
+
let faviconRequest = 0;
|
|
1239
|
+
const hasDocument = () => typeof document !== "undefined";
|
|
1240
|
+
function init() {
|
|
1241
|
+
if (ready || !hasDocument()) return;
|
|
1242
|
+
ready = true;
|
|
1243
|
+
originalTitle = document.title;
|
|
1244
|
+
originalFavicon = document.querySelector('link[rel~="icon"]')?.href ?? null;
|
|
1245
|
+
}
|
|
1246
|
+
const baseTitle = () => unread > 0 ? formatTitle(unread, originalTitle) : originalTitle;
|
|
1247
|
+
function applyFavicon(href) {
|
|
1248
|
+
const links = document.querySelectorAll('link[rel~="icon"]');
|
|
1249
|
+
if (href === null) {
|
|
1250
|
+
links.forEach((link2) => link2.dataset.wnFavicon !== void 0 && link2.remove());
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
let link = links[0];
|
|
1254
|
+
if (!link) {
|
|
1255
|
+
link = document.createElement("link");
|
|
1256
|
+
link.rel = "icon";
|
|
1257
|
+
link.dataset.wnFavicon = "";
|
|
1258
|
+
document.head.appendChild(link);
|
|
1259
|
+
}
|
|
1260
|
+
link.href = href;
|
|
1261
|
+
}
|
|
1262
|
+
function drawDot(base) {
|
|
1263
|
+
const size = 32;
|
|
1264
|
+
const canvas = document.createElement("canvas");
|
|
1265
|
+
canvas.width = size;
|
|
1266
|
+
canvas.height = size;
|
|
1267
|
+
const ctx = canvas.getContext("2d");
|
|
1268
|
+
if (!ctx) return null;
|
|
1269
|
+
if (base) ctx.drawImage(base, 0, 0, size, size);
|
|
1270
|
+
const radius = base ? 7 : 10;
|
|
1271
|
+
const x = size - radius - 1;
|
|
1272
|
+
const y = base ? radius + 1 : size / 2;
|
|
1273
|
+
ctx.beginPath();
|
|
1274
|
+
ctx.arc(x, y, radius + 2, 0, Math.PI * 2);
|
|
1275
|
+
ctx.fillStyle = "#ffffff";
|
|
1276
|
+
ctx.fill();
|
|
1277
|
+
ctx.beginPath();
|
|
1278
|
+
ctx.arc(x, y, radius, 0, Math.PI * 2);
|
|
1279
|
+
ctx.fillStyle = dotColor;
|
|
1280
|
+
ctx.fill();
|
|
1281
|
+
try {
|
|
1282
|
+
return canvas.toDataURL("image/png");
|
|
1283
|
+
} catch {
|
|
1284
|
+
return null;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function showDot() {
|
|
1288
|
+
if (!favicon) return;
|
|
1289
|
+
const source = originalFavicon ?? "";
|
|
1290
|
+
if (dotted?.source === source) return applyFavicon(dotted.url);
|
|
1291
|
+
const request = ++faviconRequest;
|
|
1292
|
+
const done = (base) => {
|
|
1293
|
+
if (request !== faviconRequest || unread === 0) return;
|
|
1294
|
+
const url = drawDot(base);
|
|
1295
|
+
if (!url) return;
|
|
1296
|
+
dotted = { source, url };
|
|
1297
|
+
applyFavicon(url);
|
|
1298
|
+
};
|
|
1299
|
+
if (!source) return done(null);
|
|
1300
|
+
const image = new Image();
|
|
1301
|
+
image.crossOrigin = "anonymous";
|
|
1302
|
+
image.onload = () => done(image);
|
|
1303
|
+
image.onerror = () => done(null);
|
|
1304
|
+
image.src = source;
|
|
1305
|
+
}
|
|
1306
|
+
function hideDot() {
|
|
1307
|
+
faviconRequest++;
|
|
1308
|
+
if (favicon) applyFavicon(originalFavicon);
|
|
1309
|
+
}
|
|
1310
|
+
const api = {
|
|
1311
|
+
setUnreadCount(count) {
|
|
1312
|
+
if (!hasDocument()) return;
|
|
1313
|
+
init();
|
|
1314
|
+
unread = Math.max(0, Math.floor(count) || 0);
|
|
1315
|
+
if (!flashTimer) document.title = baseTitle();
|
|
1316
|
+
if (unread > 0) showDot();
|
|
1317
|
+
else hideDot();
|
|
1318
|
+
},
|
|
1319
|
+
getUnreadCount: () => unread,
|
|
1320
|
+
flashTitle(message, flashOptions) {
|
|
1321
|
+
if (!hasDocument()) return;
|
|
1322
|
+
init();
|
|
1323
|
+
api.stopFlashing();
|
|
1324
|
+
const { interval = 1500, stopOnFocus = true } = typeof flashOptions === "number" ? { interval: flashOptions } : flashOptions ?? {};
|
|
1325
|
+
let showMessage = false;
|
|
1326
|
+
document.title = message;
|
|
1327
|
+
flashTimer = setInterval(() => {
|
|
1328
|
+
document.title = showMessage ? message : baseTitle();
|
|
1329
|
+
showMessage = !showMessage;
|
|
1330
|
+
}, interval);
|
|
1331
|
+
if (stopOnFocus) {
|
|
1332
|
+
const onVisible = () => {
|
|
1333
|
+
if (document.visibilityState === "visible" && document.hasFocus()) api.stopFlashing();
|
|
1334
|
+
};
|
|
1335
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
1336
|
+
window.addEventListener("focus", onVisible);
|
|
1337
|
+
stopListening = () => {
|
|
1338
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
1339
|
+
window.removeEventListener("focus", onVisible);
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
},
|
|
1343
|
+
stopFlashing() {
|
|
1344
|
+
if (flashTimer) clearInterval(flashTimer);
|
|
1345
|
+
flashTimer = null;
|
|
1346
|
+
stopListening?.();
|
|
1347
|
+
stopListening = null;
|
|
1348
|
+
if (ready) document.title = baseTitle();
|
|
1349
|
+
},
|
|
1350
|
+
isFlashing: () => flashTimer !== null,
|
|
1351
|
+
reset() {
|
|
1352
|
+
api.stopFlashing();
|
|
1353
|
+
unread = 0;
|
|
1354
|
+
if (!ready) return;
|
|
1355
|
+
document.title = originalTitle;
|
|
1356
|
+
hideDot();
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
return api;
|
|
1360
|
+
}
|
|
1361
|
+
var tabNotifications = createTabNotifications();
|
|
1362
|
+
export {
|
|
1363
|
+
CloseIcon,
|
|
1364
|
+
ErrorIcon,
|
|
1365
|
+
InfoIcon,
|
|
1366
|
+
LoadingIcon,
|
|
1367
|
+
NOTIFICATION_SOUNDS,
|
|
1368
|
+
SuccessIcon,
|
|
1369
|
+
Toaster,
|
|
1370
|
+
WarningIcon,
|
|
1371
|
+
createTabNotifications,
|
|
1372
|
+
playNotificationSound,
|
|
1373
|
+
playSound,
|
|
1374
|
+
playTone,
|
|
1375
|
+
resolveColor,
|
|
1376
|
+
resolveLabels,
|
|
1377
|
+
scheduleSound,
|
|
1378
|
+
tabNotifications,
|
|
1379
|
+
toast,
|
|
1380
|
+
toastStore,
|
|
1381
|
+
useToasts
|
|
1382
|
+
};
|
|
1383
|
+
//# sourceMappingURL=index.js.map
|