@lssm/lib.ui-kit-web 1.41.0 → 1.42.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.
@@ -1,910 +0,0 @@
1
- 'use client';
2
-
3
- import React from "react";
4
- import ReactDOM from "react-dom";
5
-
6
- //#region ../../../node_modules/sonner/dist/index.mjs
7
- function __insertCSS(code) {
8
- if (!code || typeof document == "undefined") return;
9
- let head = document.head || document.getElementsByTagName("head")[0];
10
- let style = document.createElement("style");
11
- style.type = "text/css";
12
- head.appendChild(style);
13
- style.styleSheet ? style.styleSheet.cssText = code : style.appendChild(document.createTextNode(code));
14
- }
15
- const getAsset = (type) => {
16
- switch (type) {
17
- case "success": return SuccessIcon;
18
- case "info": return InfoIcon;
19
- case "warning": return WarningIcon;
20
- case "error": return ErrorIcon;
21
- default: return null;
22
- }
23
- };
24
- const bars = Array(12).fill(0);
25
- const Loader = ({ visible, className }) => {
26
- return /* @__PURE__ */ React.createElement("div", {
27
- className: ["sonner-loading-wrapper", className].filter(Boolean).join(" "),
28
- "data-visible": visible
29
- }, /* @__PURE__ */ React.createElement("div", { className: "sonner-spinner" }, bars.map((_, i) => /* @__PURE__ */ React.createElement("div", {
30
- className: "sonner-loading-bar",
31
- key: `spinner-bar-${i}`
32
- }))));
33
- };
34
- const SuccessIcon = /* @__PURE__ */ React.createElement("svg", {
35
- xmlns: "http://www.w3.org/2000/svg",
36
- viewBox: "0 0 20 20",
37
- fill: "currentColor",
38
- height: "20",
39
- width: "20"
40
- }, /* @__PURE__ */ React.createElement("path", {
41
- fillRule: "evenodd",
42
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",
43
- clipRule: "evenodd"
44
- }));
45
- const WarningIcon = /* @__PURE__ */ React.createElement("svg", {
46
- xmlns: "http://www.w3.org/2000/svg",
47
- viewBox: "0 0 24 24",
48
- fill: "currentColor",
49
- height: "20",
50
- width: "20"
51
- }, /* @__PURE__ */ React.createElement("path", {
52
- fillRule: "evenodd",
53
- d: "M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",
54
- clipRule: "evenodd"
55
- }));
56
- const InfoIcon = /* @__PURE__ */ React.createElement("svg", {
57
- xmlns: "http://www.w3.org/2000/svg",
58
- viewBox: "0 0 20 20",
59
- fill: "currentColor",
60
- height: "20",
61
- width: "20"
62
- }, /* @__PURE__ */ React.createElement("path", {
63
- fillRule: "evenodd",
64
- d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",
65
- clipRule: "evenodd"
66
- }));
67
- const ErrorIcon = /* @__PURE__ */ React.createElement("svg", {
68
- xmlns: "http://www.w3.org/2000/svg",
69
- viewBox: "0 0 20 20",
70
- fill: "currentColor",
71
- height: "20",
72
- width: "20"
73
- }, /* @__PURE__ */ React.createElement("path", {
74
- fillRule: "evenodd",
75
- d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",
76
- clipRule: "evenodd"
77
- }));
78
- const CloseIcon = /* @__PURE__ */ React.createElement("svg", {
79
- xmlns: "http://www.w3.org/2000/svg",
80
- width: "12",
81
- height: "12",
82
- viewBox: "0 0 24 24",
83
- fill: "none",
84
- stroke: "currentColor",
85
- strokeWidth: "1.5",
86
- strokeLinecap: "round",
87
- strokeLinejoin: "round"
88
- }, /* @__PURE__ */ React.createElement("line", {
89
- x1: "18",
90
- y1: "6",
91
- x2: "6",
92
- y2: "18"
93
- }), /* @__PURE__ */ React.createElement("line", {
94
- x1: "6",
95
- y1: "6",
96
- x2: "18",
97
- y2: "18"
98
- }));
99
- const useIsDocumentHidden = () => {
100
- const [isDocumentHidden, setIsDocumentHidden] = React.useState(document.hidden);
101
- React.useEffect(() => {
102
- const callback = () => {
103
- setIsDocumentHidden(document.hidden);
104
- };
105
- document.addEventListener("visibilitychange", callback);
106
- return () => window.removeEventListener("visibilitychange", callback);
107
- }, []);
108
- return isDocumentHidden;
109
- };
110
- let toastsCounter = 1;
111
- var Observer = class {
112
- constructor() {
113
- this.subscribe = (subscriber) => {
114
- this.subscribers.push(subscriber);
115
- return () => {
116
- const index = this.subscribers.indexOf(subscriber);
117
- this.subscribers.splice(index, 1);
118
- };
119
- };
120
- this.publish = (data) => {
121
- this.subscribers.forEach((subscriber) => subscriber(data));
122
- };
123
- this.addToast = (data) => {
124
- this.publish(data);
125
- this.toasts = [...this.toasts, data];
126
- };
127
- this.create = (data) => {
128
- var _data_id;
129
- const { message, ...rest } = data;
130
- const id = typeof (data == null ? void 0 : data.id) === "number" || ((_data_id = data.id) == null ? void 0 : _data_id.length) > 0 ? data.id : toastsCounter++;
131
- const alreadyExists = this.toasts.find((toast$1) => {
132
- return toast$1.id === id;
133
- });
134
- const dismissible = data.dismissible === void 0 ? true : data.dismissible;
135
- if (this.dismissedToasts.has(id)) this.dismissedToasts.delete(id);
136
- if (alreadyExists) this.toasts = this.toasts.map((toast$1) => {
137
- if (toast$1.id === id) {
138
- this.publish({
139
- ...toast$1,
140
- ...data,
141
- id,
142
- title: message
143
- });
144
- return {
145
- ...toast$1,
146
- ...data,
147
- id,
148
- dismissible,
149
- title: message
150
- };
151
- }
152
- return toast$1;
153
- });
154
- else this.addToast({
155
- title: message,
156
- ...rest,
157
- dismissible,
158
- id
159
- });
160
- return id;
161
- };
162
- this.dismiss = (id) => {
163
- if (id) {
164
- this.dismissedToasts.add(id);
165
- requestAnimationFrame(() => this.subscribers.forEach((subscriber) => subscriber({
166
- id,
167
- dismiss: true
168
- })));
169
- } else this.toasts.forEach((toast$1) => {
170
- this.subscribers.forEach((subscriber) => subscriber({
171
- id: toast$1.id,
172
- dismiss: true
173
- }));
174
- });
175
- return id;
176
- };
177
- this.message = (message, data) => {
178
- return this.create({
179
- ...data,
180
- message
181
- });
182
- };
183
- this.error = (message, data) => {
184
- return this.create({
185
- ...data,
186
- message,
187
- type: "error"
188
- });
189
- };
190
- this.success = (message, data) => {
191
- return this.create({
192
- ...data,
193
- type: "success",
194
- message
195
- });
196
- };
197
- this.info = (message, data) => {
198
- return this.create({
199
- ...data,
200
- type: "info",
201
- message
202
- });
203
- };
204
- this.warning = (message, data) => {
205
- return this.create({
206
- ...data,
207
- type: "warning",
208
- message
209
- });
210
- };
211
- this.loading = (message, data) => {
212
- return this.create({
213
- ...data,
214
- type: "loading",
215
- message
216
- });
217
- };
218
- this.promise = (promise, data) => {
219
- if (!data) return;
220
- let id = void 0;
221
- if (data.loading !== void 0) id = this.create({
222
- ...data,
223
- promise,
224
- type: "loading",
225
- message: data.loading,
226
- description: typeof data.description !== "function" ? data.description : void 0
227
- });
228
- const p = Promise.resolve(promise instanceof Function ? promise() : promise);
229
- let shouldDismiss = id !== void 0;
230
- let result;
231
- const originalPromise = p.then(async (response) => {
232
- result = ["resolve", response];
233
- if (React.isValidElement(response)) {
234
- shouldDismiss = false;
235
- this.create({
236
- id,
237
- type: "default",
238
- message: response
239
- });
240
- } else if (isHttpResponse(response) && !response.ok) {
241
- shouldDismiss = false;
242
- const promiseData = typeof data.error === "function" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
243
- const description = typeof data.description === "function" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
244
- const toastSettings = typeof promiseData === "object" && !React.isValidElement(promiseData) ? promiseData : { message: promiseData };
245
- this.create({
246
- id,
247
- type: "error",
248
- description,
249
- ...toastSettings
250
- });
251
- } else if (response instanceof Error) {
252
- shouldDismiss = false;
253
- const promiseData = typeof data.error === "function" ? await data.error(response) : data.error;
254
- const description = typeof data.description === "function" ? await data.description(response) : data.description;
255
- const toastSettings = typeof promiseData === "object" && !React.isValidElement(promiseData) ? promiseData : { message: promiseData };
256
- this.create({
257
- id,
258
- type: "error",
259
- description,
260
- ...toastSettings
261
- });
262
- } else if (data.success !== void 0) {
263
- shouldDismiss = false;
264
- const promiseData = typeof data.success === "function" ? await data.success(response) : data.success;
265
- const description = typeof data.description === "function" ? await data.description(response) : data.description;
266
- const toastSettings = typeof promiseData === "object" && !React.isValidElement(promiseData) ? promiseData : { message: promiseData };
267
- this.create({
268
- id,
269
- type: "success",
270
- description,
271
- ...toastSettings
272
- });
273
- }
274
- }).catch(async (error) => {
275
- result = ["reject", error];
276
- if (data.error !== void 0) {
277
- shouldDismiss = false;
278
- const promiseData = typeof data.error === "function" ? await data.error(error) : data.error;
279
- const description = typeof data.description === "function" ? await data.description(error) : data.description;
280
- const toastSettings = typeof promiseData === "object" && !React.isValidElement(promiseData) ? promiseData : { message: promiseData };
281
- this.create({
282
- id,
283
- type: "error",
284
- description,
285
- ...toastSettings
286
- });
287
- }
288
- }).finally(() => {
289
- if (shouldDismiss) {
290
- this.dismiss(id);
291
- id = void 0;
292
- }
293
- data.finally == null || data.finally.call(data);
294
- });
295
- const unwrap = () => new Promise((resolve, reject) => originalPromise.then(() => result[0] === "reject" ? reject(result[1]) : resolve(result[1])).catch(reject));
296
- if (typeof id !== "string" && typeof id !== "number") return { unwrap };
297
- else return Object.assign(id, { unwrap });
298
- };
299
- this.custom = (jsx, data) => {
300
- const id = (data == null ? void 0 : data.id) || toastsCounter++;
301
- this.create({
302
- jsx: jsx(id),
303
- id,
304
- ...data
305
- });
306
- return id;
307
- };
308
- this.getActiveToasts = () => {
309
- return this.toasts.filter((toast$1) => !this.dismissedToasts.has(toast$1.id));
310
- };
311
- this.subscribers = [];
312
- this.toasts = [];
313
- this.dismissedToasts = /* @__PURE__ */ new Set();
314
- }
315
- };
316
- const ToastState = new Observer();
317
- const toastFunction = (message, data) => {
318
- const id = (data == null ? void 0 : data.id) || toastsCounter++;
319
- ToastState.addToast({
320
- title: message,
321
- ...data,
322
- id
323
- });
324
- return id;
325
- };
326
- const isHttpResponse = (data) => {
327
- return data && typeof data === "object" && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
328
- };
329
- const basicToast = toastFunction;
330
- const getHistory = () => ToastState.toasts;
331
- const getToasts = () => ToastState.getActiveToasts();
332
- const toast = Object.assign(basicToast, {
333
- success: ToastState.success,
334
- info: ToastState.info,
335
- warning: ToastState.warning,
336
- error: ToastState.error,
337
- custom: ToastState.custom,
338
- message: ToastState.message,
339
- promise: ToastState.promise,
340
- dismiss: ToastState.dismiss,
341
- loading: ToastState.loading
342
- }, {
343
- getHistory,
344
- getToasts
345
- });
346
- __insertCSS("[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}");
347
- function isAction(action) {
348
- return action.label !== void 0;
349
- }
350
- const VISIBLE_TOASTS_AMOUNT = 3;
351
- const VIEWPORT_OFFSET = "24px";
352
- const MOBILE_VIEWPORT_OFFSET = "16px";
353
- const TOAST_LIFETIME = 4e3;
354
- const TOAST_WIDTH = 356;
355
- const GAP = 14;
356
- const SWIPE_THRESHOLD = 45;
357
- const TIME_BEFORE_UNMOUNT = 200;
358
- function cn(...classes) {
359
- return classes.filter(Boolean).join(" ");
360
- }
361
- function getDefaultSwipeDirections(position) {
362
- const [y, x] = position.split("-");
363
- const directions = [];
364
- if (y) directions.push(y);
365
- if (x) directions.push(x);
366
- return directions;
367
- }
368
- const Toast = (props) => {
369
- var _toast_classNames, _toast_classNames1, _toast_classNames2, _toast_classNames3, _toast_classNames4, _toast_classNames5, _toast_classNames6, _toast_classNames7, _toast_classNames8;
370
- const { invert: ToasterInvert, toast: toast$1, unstyled, interacting, setHeights, visibleToasts, heights, index, toasts, expanded, removeToast, defaultRichColors, closeButton: closeButtonFromToaster, style, cancelButtonStyle, actionButtonStyle, className = "", descriptionClassName = "", duration: durationFromToaster, position, gap, expandByDefault, classNames, icons, closeButtonAriaLabel = "Close toast" } = props;
371
- const [swipeDirection, setSwipeDirection] = React.useState(null);
372
- const [swipeOutDirection, setSwipeOutDirection] = React.useState(null);
373
- const [mounted, setMounted] = React.useState(false);
374
- const [removed, setRemoved] = React.useState(false);
375
- const [swiping, setSwiping] = React.useState(false);
376
- const [swipeOut, setSwipeOut] = React.useState(false);
377
- const [isSwiped, setIsSwiped] = React.useState(false);
378
- const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);
379
- const [initialHeight, setInitialHeight] = React.useState(0);
380
- const remainingTime = React.useRef(toast$1.duration || durationFromToaster || TOAST_LIFETIME);
381
- const dragStartTime = React.useRef(null);
382
- const toastRef = React.useRef(null);
383
- const isFront = index === 0;
384
- const isVisible = index + 1 <= visibleToasts;
385
- const toastType = toast$1.type;
386
- const dismissible = toast$1.dismissible !== false;
387
- const toastClassname = toast$1.className || "";
388
- const toastDescriptionClassname = toast$1.descriptionClassName || "";
389
- const heightIndex = React.useMemo(() => heights.findIndex((height) => height.toastId === toast$1.id) || 0, [heights, toast$1.id]);
390
- const closeButton = React.useMemo(() => {
391
- var _toast_closeButton;
392
- return (_toast_closeButton = toast$1.closeButton) != null ? _toast_closeButton : closeButtonFromToaster;
393
- }, [toast$1.closeButton, closeButtonFromToaster]);
394
- const duration = React.useMemo(() => toast$1.duration || durationFromToaster || TOAST_LIFETIME, [toast$1.duration, durationFromToaster]);
395
- const closeTimerStartTimeRef = React.useRef(0);
396
- const offset = React.useRef(0);
397
- const lastCloseTimerStartTimeRef = React.useRef(0);
398
- const pointerStartRef = React.useRef(null);
399
- const [y, x] = position.split("-");
400
- const toastsHeightBefore = React.useMemo(() => {
401
- return heights.reduce((prev, curr, reducerIndex) => {
402
- if (reducerIndex >= heightIndex) return prev;
403
- return prev + curr.height;
404
- }, 0);
405
- }, [heights, heightIndex]);
406
- const isDocumentHidden = useIsDocumentHidden();
407
- const invert = toast$1.invert || ToasterInvert;
408
- const disabled = toastType === "loading";
409
- offset.current = React.useMemo(() => heightIndex * gap + toastsHeightBefore, [heightIndex, toastsHeightBefore]);
410
- React.useEffect(() => {
411
- remainingTime.current = duration;
412
- }, [duration]);
413
- React.useEffect(() => {
414
- setMounted(true);
415
- }, []);
416
- React.useEffect(() => {
417
- const toastNode = toastRef.current;
418
- if (toastNode) {
419
- const height = toastNode.getBoundingClientRect().height;
420
- setInitialHeight(height);
421
- setHeights((h) => [{
422
- toastId: toast$1.id,
423
- height,
424
- position: toast$1.position
425
- }, ...h]);
426
- return () => setHeights((h) => h.filter((height$1) => height$1.toastId !== toast$1.id));
427
- }
428
- }, [setHeights, toast$1.id]);
429
- React.useLayoutEffect(() => {
430
- if (!mounted) return;
431
- const toastNode = toastRef.current;
432
- const originalHeight = toastNode.style.height;
433
- toastNode.style.height = "auto";
434
- const newHeight = toastNode.getBoundingClientRect().height;
435
- toastNode.style.height = originalHeight;
436
- setInitialHeight(newHeight);
437
- setHeights((heights$1) => {
438
- if (!heights$1.find((height) => height.toastId === toast$1.id)) return [{
439
- toastId: toast$1.id,
440
- height: newHeight,
441
- position: toast$1.position
442
- }, ...heights$1];
443
- else return heights$1.map((height) => height.toastId === toast$1.id ? {
444
- ...height,
445
- height: newHeight
446
- } : height);
447
- });
448
- }, [
449
- mounted,
450
- toast$1.title,
451
- toast$1.description,
452
- setHeights,
453
- toast$1.id,
454
- toast$1.jsx,
455
- toast$1.action,
456
- toast$1.cancel
457
- ]);
458
- const deleteToast = React.useCallback(() => {
459
- setRemoved(true);
460
- setOffsetBeforeRemove(offset.current);
461
- setHeights((h) => h.filter((height) => height.toastId !== toast$1.id));
462
- setTimeout(() => {
463
- removeToast(toast$1);
464
- }, TIME_BEFORE_UNMOUNT);
465
- }, [
466
- toast$1,
467
- removeToast,
468
- setHeights,
469
- offset
470
- ]);
471
- React.useEffect(() => {
472
- if (toast$1.promise && toastType === "loading" || toast$1.duration === Infinity || toast$1.type === "loading") return;
473
- let timeoutId;
474
- const pauseTimer = () => {
475
- if (lastCloseTimerStartTimeRef.current < closeTimerStartTimeRef.current) {
476
- const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
477
- remainingTime.current = remainingTime.current - elapsedTime;
478
- }
479
- lastCloseTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
480
- };
481
- const startTimer = () => {
482
- if (remainingTime.current === Infinity) return;
483
- closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
484
- timeoutId = setTimeout(() => {
485
- toast$1.onAutoClose == null || toast$1.onAutoClose.call(toast$1, toast$1);
486
- deleteToast();
487
- }, remainingTime.current);
488
- };
489
- if (expanded || interacting || isDocumentHidden) pauseTimer();
490
- else startTimer();
491
- return () => clearTimeout(timeoutId);
492
- }, [
493
- expanded,
494
- interacting,
495
- toast$1,
496
- toastType,
497
- isDocumentHidden,
498
- deleteToast
499
- ]);
500
- React.useEffect(() => {
501
- if (toast$1.delete) {
502
- deleteToast();
503
- toast$1.onDismiss == null || toast$1.onDismiss.call(toast$1, toast$1);
504
- }
505
- }, [deleteToast, toast$1.delete]);
506
- function getLoadingIcon() {
507
- var _toast_classNames$1;
508
- if (icons == null ? void 0 : icons.loading) {
509
- var _toast_classNames1$1;
510
- return /* @__PURE__ */ React.createElement("div", {
511
- className: cn(classNames == null ? void 0 : classNames.loader, toast$1 == null ? void 0 : (_toast_classNames1$1 = toast$1.classNames) == null ? void 0 : _toast_classNames1$1.loader, "sonner-loader"),
512
- "data-visible": toastType === "loading"
513
- }, icons.loading);
514
- }
515
- return /* @__PURE__ */ React.createElement(Loader, {
516
- className: cn(classNames == null ? void 0 : classNames.loader, toast$1 == null ? void 0 : (_toast_classNames$1 = toast$1.classNames) == null ? void 0 : _toast_classNames$1.loader),
517
- visible: toastType === "loading"
518
- });
519
- }
520
- const icon = toast$1.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType);
521
- var _toast_richColors, _icons_close;
522
- return /* @__PURE__ */ React.createElement("li", {
523
- tabIndex: 0,
524
- ref: toastRef,
525
- className: cn(className, toastClassname, classNames == null ? void 0 : classNames.toast, toast$1 == null ? void 0 : (_toast_classNames = toast$1.classNames) == null ? void 0 : _toast_classNames.toast, classNames == null ? void 0 : classNames.default, classNames == null ? void 0 : classNames[toastType], toast$1 == null ? void 0 : (_toast_classNames1 = toast$1.classNames) == null ? void 0 : _toast_classNames1[toastType]),
526
- "data-sonner-toast": "",
527
- "data-rich-colors": (_toast_richColors = toast$1.richColors) != null ? _toast_richColors : defaultRichColors,
528
- "data-styled": !Boolean(toast$1.jsx || toast$1.unstyled || unstyled),
529
- "data-mounted": mounted,
530
- "data-promise": Boolean(toast$1.promise),
531
- "data-swiped": isSwiped,
532
- "data-removed": removed,
533
- "data-visible": isVisible,
534
- "data-y-position": y,
535
- "data-x-position": x,
536
- "data-index": index,
537
- "data-front": isFront,
538
- "data-swiping": swiping,
539
- "data-dismissible": dismissible,
540
- "data-type": toastType,
541
- "data-invert": invert,
542
- "data-swipe-out": swipeOut,
543
- "data-swipe-direction": swipeOutDirection,
544
- "data-expanded": Boolean(expanded || expandByDefault && mounted),
545
- "data-testid": toast$1.testId,
546
- style: {
547
- "--index": index,
548
- "--toasts-before": index,
549
- "--z-index": toasts.length - index,
550
- "--offset": `${removed ? offsetBeforeRemove : offset.current}px`,
551
- "--initial-height": expandByDefault ? "auto" : `${initialHeight}px`,
552
- ...style,
553
- ...toast$1.style
554
- },
555
- onDragEnd: () => {
556
- setSwiping(false);
557
- setSwipeDirection(null);
558
- pointerStartRef.current = null;
559
- },
560
- onPointerDown: (event) => {
561
- if (event.button === 2) return;
562
- if (disabled || !dismissible) return;
563
- dragStartTime.current = /* @__PURE__ */ new Date();
564
- setOffsetBeforeRemove(offset.current);
565
- event.target.setPointerCapture(event.pointerId);
566
- if (event.target.tagName === "BUTTON") return;
567
- setSwiping(true);
568
- pointerStartRef.current = {
569
- x: event.clientX,
570
- y: event.clientY
571
- };
572
- },
573
- onPointerUp: () => {
574
- var _toastRef_current, _toastRef_current1, _dragStartTime_current;
575
- if (swipeOut || !dismissible) return;
576
- pointerStartRef.current = null;
577
- const swipeAmountX = Number(((_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.getPropertyValue("--swipe-amount-x").replace("px", "")) || 0);
578
- const swipeAmountY = Number(((_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.getPropertyValue("--swipe-amount-y").replace("px", "")) || 0);
579
- const timeTaken = (/* @__PURE__ */ new Date()).getTime() - ((_dragStartTime_current = dragStartTime.current) == null ? void 0 : _dragStartTime_current.getTime());
580
- const swipeAmount = swipeDirection === "x" ? swipeAmountX : swipeAmountY;
581
- const velocity = Math.abs(swipeAmount) / timeTaken;
582
- if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > .11) {
583
- setOffsetBeforeRemove(offset.current);
584
- toast$1.onDismiss == null || toast$1.onDismiss.call(toast$1, toast$1);
585
- if (swipeDirection === "x") setSwipeOutDirection(swipeAmountX > 0 ? "right" : "left");
586
- else setSwipeOutDirection(swipeAmountY > 0 ? "down" : "up");
587
- deleteToast();
588
- setSwipeOut(true);
589
- return;
590
- } else {
591
- var _toastRef_current2, _toastRef_current3;
592
- (_toastRef_current2 = toastRef.current) == null || _toastRef_current2.style.setProperty("--swipe-amount-x", `0px`);
593
- (_toastRef_current3 = toastRef.current) == null || _toastRef_current3.style.setProperty("--swipe-amount-y", `0px`);
594
- }
595
- setIsSwiped(false);
596
- setSwiping(false);
597
- setSwipeDirection(null);
598
- },
599
- onPointerMove: (event) => {
600
- var _window_getSelection, _toastRef_current, _toastRef_current1;
601
- if (!pointerStartRef.current || !dismissible) return;
602
- if (((_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString().length) > 0) return;
603
- const yDelta = event.clientY - pointerStartRef.current.y;
604
- const xDelta = event.clientX - pointerStartRef.current.x;
605
- var _props_swipeDirections;
606
- const swipeDirections = (_props_swipeDirections = props.swipeDirections) != null ? _props_swipeDirections : getDefaultSwipeDirections(position);
607
- if (!swipeDirection && (Math.abs(xDelta) > 1 || Math.abs(yDelta) > 1)) setSwipeDirection(Math.abs(xDelta) > Math.abs(yDelta) ? "x" : "y");
608
- let swipeAmount = {
609
- x: 0,
610
- y: 0
611
- };
612
- const getDampening = (delta) => {
613
- return 1 / (1.5 + Math.abs(delta) / 20);
614
- };
615
- if (swipeDirection === "y") {
616
- if (swipeDirections.includes("top") || swipeDirections.includes("bottom")) if (swipeDirections.includes("top") && yDelta < 0 || swipeDirections.includes("bottom") && yDelta > 0) swipeAmount.y = yDelta;
617
- else {
618
- const dampenedDelta = yDelta * getDampening(yDelta);
619
- swipeAmount.y = Math.abs(dampenedDelta) < Math.abs(yDelta) ? dampenedDelta : yDelta;
620
- }
621
- } else if (swipeDirection === "x") {
622
- if (swipeDirections.includes("left") || swipeDirections.includes("right")) if (swipeDirections.includes("left") && xDelta < 0 || swipeDirections.includes("right") && xDelta > 0) swipeAmount.x = xDelta;
623
- else {
624
- const dampenedDelta = xDelta * getDampening(xDelta);
625
- swipeAmount.x = Math.abs(dampenedDelta) < Math.abs(xDelta) ? dampenedDelta : xDelta;
626
- }
627
- }
628
- if (Math.abs(swipeAmount.x) > 0 || Math.abs(swipeAmount.y) > 0) setIsSwiped(true);
629
- (_toastRef_current = toastRef.current) == null || _toastRef_current.style.setProperty("--swipe-amount-x", `${swipeAmount.x}px`);
630
- (_toastRef_current1 = toastRef.current) == null || _toastRef_current1.style.setProperty("--swipe-amount-y", `${swipeAmount.y}px`);
631
- }
632
- }, closeButton && !toast$1.jsx && toastType !== "loading" ? /* @__PURE__ */ React.createElement("button", {
633
- "aria-label": closeButtonAriaLabel,
634
- "data-disabled": disabled,
635
- "data-close-button": true,
636
- onClick: disabled || !dismissible ? () => {} : () => {
637
- deleteToast();
638
- toast$1.onDismiss == null || toast$1.onDismiss.call(toast$1, toast$1);
639
- },
640
- className: cn(classNames == null ? void 0 : classNames.closeButton, toast$1 == null ? void 0 : (_toast_classNames2 = toast$1.classNames) == null ? void 0 : _toast_classNames2.closeButton)
641
- }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, (toastType || toast$1.icon || toast$1.promise) && toast$1.icon !== null && ((icons == null ? void 0 : icons[toastType]) !== null || toast$1.icon) ? /* @__PURE__ */ React.createElement("div", {
642
- "data-icon": "",
643
- className: cn(classNames == null ? void 0 : classNames.icon, toast$1 == null ? void 0 : (_toast_classNames3 = toast$1.classNames) == null ? void 0 : _toast_classNames3.icon)
644
- }, toast$1.promise || toast$1.type === "loading" && !toast$1.icon ? toast$1.icon || getLoadingIcon() : null, toast$1.type !== "loading" ? icon : null) : null, /* @__PURE__ */ React.createElement("div", {
645
- "data-content": "",
646
- className: cn(classNames == null ? void 0 : classNames.content, toast$1 == null ? void 0 : (_toast_classNames4 = toast$1.classNames) == null ? void 0 : _toast_classNames4.content)
647
- }, /* @__PURE__ */ React.createElement("div", {
648
- "data-title": "",
649
- className: cn(classNames == null ? void 0 : classNames.title, toast$1 == null ? void 0 : (_toast_classNames5 = toast$1.classNames) == null ? void 0 : _toast_classNames5.title)
650
- }, toast$1.jsx ? toast$1.jsx : typeof toast$1.title === "function" ? toast$1.title() : toast$1.title), toast$1.description ? /* @__PURE__ */ React.createElement("div", {
651
- "data-description": "",
652
- className: cn(descriptionClassName, toastDescriptionClassname, classNames == null ? void 0 : classNames.description, toast$1 == null ? void 0 : (_toast_classNames6 = toast$1.classNames) == null ? void 0 : _toast_classNames6.description)
653
- }, typeof toast$1.description === "function" ? toast$1.description() : toast$1.description) : null), /* @__PURE__ */ React.isValidElement(toast$1.cancel) ? toast$1.cancel : toast$1.cancel && isAction(toast$1.cancel) ? /* @__PURE__ */ React.createElement("button", {
654
- "data-button": true,
655
- "data-cancel": true,
656
- style: toast$1.cancelButtonStyle || cancelButtonStyle,
657
- onClick: (event) => {
658
- if (!isAction(toast$1.cancel)) return;
659
- if (!dismissible) return;
660
- toast$1.cancel.onClick == null || toast$1.cancel.onClick.call(toast$1.cancel, event);
661
- deleteToast();
662
- },
663
- className: cn(classNames == null ? void 0 : classNames.cancelButton, toast$1 == null ? void 0 : (_toast_classNames7 = toast$1.classNames) == null ? void 0 : _toast_classNames7.cancelButton)
664
- }, toast$1.cancel.label) : null, /* @__PURE__ */ React.isValidElement(toast$1.action) ? toast$1.action : toast$1.action && isAction(toast$1.action) ? /* @__PURE__ */ React.createElement("button", {
665
- "data-button": true,
666
- "data-action": true,
667
- style: toast$1.actionButtonStyle || actionButtonStyle,
668
- onClick: (event) => {
669
- if (!isAction(toast$1.action)) return;
670
- toast$1.action.onClick == null || toast$1.action.onClick.call(toast$1.action, event);
671
- if (event.defaultPrevented) return;
672
- deleteToast();
673
- },
674
- className: cn(classNames == null ? void 0 : classNames.actionButton, toast$1 == null ? void 0 : (_toast_classNames8 = toast$1.classNames) == null ? void 0 : _toast_classNames8.actionButton)
675
- }, toast$1.action.label) : null);
676
- };
677
- function getDocumentDirection() {
678
- if (typeof window === "undefined") return "ltr";
679
- if (typeof document === "undefined") return "ltr";
680
- const dirAttribute = document.documentElement.getAttribute("dir");
681
- if (dirAttribute === "auto" || !dirAttribute) return window.getComputedStyle(document.documentElement).direction;
682
- return dirAttribute;
683
- }
684
- function assignOffset(defaultOffset, mobileOffset) {
685
- const styles = {};
686
- [defaultOffset, mobileOffset].forEach((offset, index) => {
687
- const isMobile = index === 1;
688
- const prefix = isMobile ? "--mobile-offset" : "--offset";
689
- const defaultValue = isMobile ? MOBILE_VIEWPORT_OFFSET : VIEWPORT_OFFSET;
690
- function assignAll(offset$1) {
691
- [
692
- "top",
693
- "right",
694
- "bottom",
695
- "left"
696
- ].forEach((key) => {
697
- styles[`${prefix}-${key}`] = typeof offset$1 === "number" ? `${offset$1}px` : offset$1;
698
- });
699
- }
700
- if (typeof offset === "number" || typeof offset === "string") assignAll(offset);
701
- else if (typeof offset === "object") [
702
- "top",
703
- "right",
704
- "bottom",
705
- "left"
706
- ].forEach((key) => {
707
- if (offset[key] === void 0) styles[`${prefix}-${key}`] = defaultValue;
708
- else styles[`${prefix}-${key}`] = typeof offset[key] === "number" ? `${offset[key]}px` : offset[key];
709
- });
710
- else assignAll(defaultValue);
711
- });
712
- return styles;
713
- }
714
- const Toaster = /* @__PURE__ */ React.forwardRef(function Toaster$1(props, ref) {
715
- const { id, invert, position = "bottom-right", hotkey = ["altKey", "KeyT"], expand, closeButton, className, offset, mobileOffset, theme = "light", richColors, duration, style, visibleToasts = VISIBLE_TOASTS_AMOUNT, toastOptions, dir = getDocumentDirection(), gap = GAP, icons, containerAriaLabel = "Notifications" } = props;
716
- const [toasts, setToasts] = React.useState([]);
717
- const filteredToasts = React.useMemo(() => {
718
- if (id) return toasts.filter((toast$1) => toast$1.toasterId === id);
719
- return toasts.filter((toast$1) => !toast$1.toasterId);
720
- }, [toasts, id]);
721
- const possiblePositions = React.useMemo(() => {
722
- return Array.from(new Set([position].concat(filteredToasts.filter((toast$1) => toast$1.position).map((toast$1) => toast$1.position))));
723
- }, [filteredToasts, position]);
724
- const [heights, setHeights] = React.useState([]);
725
- const [expanded, setExpanded] = React.useState(false);
726
- const [interacting, setInteracting] = React.useState(false);
727
- const [actualTheme, setActualTheme] = React.useState(theme !== "system" ? theme : typeof window !== "undefined" ? window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : "light");
728
- const listRef = React.useRef(null);
729
- const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
730
- const lastFocusedElementRef = React.useRef(null);
731
- const isFocusWithinRef = React.useRef(false);
732
- const removeToast = React.useCallback((toastToRemove) => {
733
- setToasts((toasts$1) => {
734
- var _toasts_find;
735
- if (!((_toasts_find = toasts$1.find((toast$1) => toast$1.id === toastToRemove.id)) == null ? void 0 : _toasts_find.delete)) ToastState.dismiss(toastToRemove.id);
736
- return toasts$1.filter(({ id: id$1 }) => id$1 !== toastToRemove.id);
737
- });
738
- }, []);
739
- React.useEffect(() => {
740
- return ToastState.subscribe((toast$1) => {
741
- if (toast$1.dismiss) {
742
- requestAnimationFrame(() => {
743
- setToasts((toasts$1) => toasts$1.map((t) => t.id === toast$1.id ? {
744
- ...t,
745
- delete: true
746
- } : t));
747
- });
748
- return;
749
- }
750
- setTimeout(() => {
751
- ReactDOM.flushSync(() => {
752
- setToasts((toasts$1) => {
753
- const indexOfExistingToast = toasts$1.findIndex((t) => t.id === toast$1.id);
754
- if (indexOfExistingToast !== -1) return [
755
- ...toasts$1.slice(0, indexOfExistingToast),
756
- {
757
- ...toasts$1[indexOfExistingToast],
758
- ...toast$1
759
- },
760
- ...toasts$1.slice(indexOfExistingToast + 1)
761
- ];
762
- return [toast$1, ...toasts$1];
763
- });
764
- });
765
- });
766
- });
767
- }, [toasts]);
768
- React.useEffect(() => {
769
- if (theme !== "system") {
770
- setActualTheme(theme);
771
- return;
772
- }
773
- if (theme === "system") if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) setActualTheme("dark");
774
- else setActualTheme("light");
775
- if (typeof window === "undefined") return;
776
- const darkMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
777
- try {
778
- darkMediaQuery.addEventListener("change", ({ matches }) => {
779
- if (matches) setActualTheme("dark");
780
- else setActualTheme("light");
781
- });
782
- } catch (error) {
783
- darkMediaQuery.addListener(({ matches }) => {
784
- try {
785
- if (matches) setActualTheme("dark");
786
- else setActualTheme("light");
787
- } catch (e) {
788
- console.error(e);
789
- }
790
- });
791
- }
792
- }, [theme]);
793
- React.useEffect(() => {
794
- if (toasts.length <= 1) setExpanded(false);
795
- }, [toasts]);
796
- React.useEffect(() => {
797
- const handleKeyDown = (event) => {
798
- var _listRef_current;
799
- if (hotkey.every((key) => event[key] || event.code === key)) {
800
- var _listRef_current1;
801
- setExpanded(true);
802
- (_listRef_current1 = listRef.current) == null || _listRef_current1.focus();
803
- }
804
- if (event.code === "Escape" && (document.activeElement === listRef.current || ((_listRef_current = listRef.current) == null ? void 0 : _listRef_current.contains(document.activeElement)))) setExpanded(false);
805
- };
806
- document.addEventListener("keydown", handleKeyDown);
807
- return () => document.removeEventListener("keydown", handleKeyDown);
808
- }, [hotkey]);
809
- React.useEffect(() => {
810
- if (listRef.current) return () => {
811
- if (lastFocusedElementRef.current) {
812
- lastFocusedElementRef.current.focus({ preventScroll: true });
813
- lastFocusedElementRef.current = null;
814
- isFocusWithinRef.current = false;
815
- }
816
- };
817
- }, [listRef.current]);
818
- return /* @__PURE__ */ React.createElement("section", {
819
- ref,
820
- "aria-label": `${containerAriaLabel} ${hotkeyLabel}`,
821
- tabIndex: -1,
822
- "aria-live": "polite",
823
- "aria-relevant": "additions text",
824
- "aria-atomic": "false",
825
- suppressHydrationWarning: true
826
- }, possiblePositions.map((position$1, index) => {
827
- var _heights_;
828
- const [y, x] = position$1.split("-");
829
- if (!filteredToasts.length) return null;
830
- return /* @__PURE__ */ React.createElement("ol", {
831
- key: position$1,
832
- dir: dir === "auto" ? getDocumentDirection() : dir,
833
- tabIndex: -1,
834
- ref: listRef,
835
- className,
836
- "data-sonner-toaster": true,
837
- "data-sonner-theme": actualTheme,
838
- "data-y-position": y,
839
- "data-x-position": x,
840
- style: {
841
- "--front-toast-height": `${((_heights_ = heights[0]) == null ? void 0 : _heights_.height) || 0}px`,
842
- "--width": `${TOAST_WIDTH}px`,
843
- "--gap": `${gap}px`,
844
- ...style,
845
- ...assignOffset(offset, mobileOffset)
846
- },
847
- onBlur: (event) => {
848
- if (isFocusWithinRef.current && !event.currentTarget.contains(event.relatedTarget)) {
849
- isFocusWithinRef.current = false;
850
- if (lastFocusedElementRef.current) {
851
- lastFocusedElementRef.current.focus({ preventScroll: true });
852
- lastFocusedElementRef.current = null;
853
- }
854
- }
855
- },
856
- onFocus: (event) => {
857
- if (event.target instanceof HTMLElement && event.target.dataset.dismissible === "false") return;
858
- if (!isFocusWithinRef.current) {
859
- isFocusWithinRef.current = true;
860
- lastFocusedElementRef.current = event.relatedTarget;
861
- }
862
- },
863
- onMouseEnter: () => setExpanded(true),
864
- onMouseMove: () => setExpanded(true),
865
- onMouseLeave: () => {
866
- if (!interacting) setExpanded(false);
867
- },
868
- onDragEnd: () => setExpanded(false),
869
- onPointerDown: (event) => {
870
- if (event.target instanceof HTMLElement && event.target.dataset.dismissible === "false") return;
871
- setInteracting(true);
872
- },
873
- onPointerUp: () => setInteracting(false)
874
- }, filteredToasts.filter((toast$1) => !toast$1.position && index === 0 || toast$1.position === position$1).map((toast$1, index$1) => {
875
- var _toastOptions_duration, _toastOptions_closeButton;
876
- return /* @__PURE__ */ React.createElement(Toast, {
877
- key: toast$1.id,
878
- icons,
879
- index: index$1,
880
- toast: toast$1,
881
- defaultRichColors: richColors,
882
- duration: (_toastOptions_duration = toastOptions == null ? void 0 : toastOptions.duration) != null ? _toastOptions_duration : duration,
883
- className: toastOptions == null ? void 0 : toastOptions.className,
884
- descriptionClassName: toastOptions == null ? void 0 : toastOptions.descriptionClassName,
885
- invert,
886
- visibleToasts,
887
- closeButton: (_toastOptions_closeButton = toastOptions == null ? void 0 : toastOptions.closeButton) != null ? _toastOptions_closeButton : closeButton,
888
- interacting,
889
- position: position$1,
890
- style: toastOptions == null ? void 0 : toastOptions.style,
891
- unstyled: toastOptions == null ? void 0 : toastOptions.unstyled,
892
- classNames: toastOptions == null ? void 0 : toastOptions.classNames,
893
- cancelButtonStyle: toastOptions == null ? void 0 : toastOptions.cancelButtonStyle,
894
- actionButtonStyle: toastOptions == null ? void 0 : toastOptions.actionButtonStyle,
895
- closeButtonAriaLabel: toastOptions == null ? void 0 : toastOptions.closeButtonAriaLabel,
896
- removeToast,
897
- toasts: filteredToasts.filter((t) => t.position == toast$1.position),
898
- heights: heights.filter((h) => h.position == toast$1.position),
899
- setHeights,
900
- expandByDefault: expand,
901
- gap,
902
- expanded,
903
- swipeDirections: props.swipeDirections
904
- });
905
- }));
906
- }));
907
- });
908
-
909
- //#endregion
910
- export { Toaster };