vue-toast-kit 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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1145 -0
  3. package/dist/composables/useToast.d.ts +28 -0
  4. package/dist/composables/useToastContext.d.ts +6 -0
  5. package/dist/composables/useToastState.d.ts +7 -0
  6. package/dist/core/GroupManager.d.ts +16 -0
  7. package/dist/core/ToastBuffer.d.ts +19 -0
  8. package/dist/core/ToastQueue.d.ts +55 -0
  9. package/dist/core/UndoTimer.d.ts +23 -0
  10. package/dist/core/types.d.ts +114 -0
  11. package/dist/index.d.ts +23 -0
  12. package/dist/module.d.ts +1 -0
  13. package/dist/nuxt/module.cjs +2 -0
  14. package/dist/nuxt/module.cjs.map +1 -0
  15. package/dist/nuxt/module.d.ts +1 -0
  16. package/dist/nuxt/module.js +34 -0
  17. package/dist/nuxt/module.js.map +1 -0
  18. package/dist/plugin.d.ts +6 -0
  19. package/dist/style.css +1 -0
  20. package/dist/testing.d.ts +14 -0
  21. package/dist/vue-toast-kit.cjs +2 -0
  22. package/dist/vue-toast-kit.cjs.map +1 -0
  23. package/dist/vue-toast-kit.d.ts +540 -0
  24. package/dist/vue-toast-kit.js +1000 -0
  25. package/dist/vue-toast-kit.js.map +1 -0
  26. package/package.json +89 -0
  27. package/src/components/Toast.vue +222 -0
  28. package/src/components/ToastActions.vue +34 -0
  29. package/src/components/ToastContainer.vue +257 -0
  30. package/src/components/ToastIcon.vue +53 -0
  31. package/src/components/ToastProgressBar.vue +18 -0
  32. package/src/composables/useToast.ts +152 -0
  33. package/src/composables/useToastContext.ts +63 -0
  34. package/src/composables/useToastState.ts +18 -0
  35. package/src/core/GroupManager.ts +105 -0
  36. package/src/core/ToastBuffer.ts +45 -0
  37. package/src/core/ToastQueue.ts +377 -0
  38. package/src/core/UndoTimer.ts +90 -0
  39. package/src/core/types.ts +142 -0
  40. package/src/env.d.ts +7 -0
  41. package/src/index.ts +51 -0
  42. package/src/nuxt/composables.ts +13 -0
  43. package/src/nuxt/module.ts +52 -0
  44. package/src/nuxt/plugin.ts +8 -0
  45. package/src/plugin.ts +18 -0
  46. package/src/styles/animations.css +106 -0
  47. package/src/styles/base.css +201 -0
  48. package/src/styles/themes/dark.css +30 -0
  49. package/src/styles/themes/light.css +30 -0
  50. package/src/styles/themes/system.css +32 -0
  51. package/src/styles/tokens.css +74 -0
  52. package/src/testing.ts +81 -0
@@ -0,0 +1,1000 @@
1
+ var nt = Object.defineProperty;
2
+ var at = (i, t, e) => t in i ? nt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var u = (i, t, e) => at(i, typeof t != "symbol" ? t + "" : t, e);
4
+ import { shallowReactive as _, reactive as rt, ref as C, inject as lt, computed as g, defineComponent as D, openBlock as d, createElementBlock as f, normalizeClass as Q, createBlock as S, resolveDynamicComponent as V, toDisplayString as O, Fragment as P, createElementVNode as w, createCommentVNode as L, normalizeStyle as W, onMounted as U, onUnmounted as ut, mergeProps as E, renderSlot as b, withCtx as A, createTextVNode as dt, watch as ct, Teleport as ht, renderList as tt, createVNode as ft, TransitionGroup as mt, createSlots as gt } from "vue";
5
+ const x = {
6
+ critical: 3,
7
+ high: 2,
8
+ normal: 1,
9
+ low: 0
10
+ }, pt = {
11
+ type: "info",
12
+ priority: "normal",
13
+ duration: 4e3,
14
+ closable: !0,
15
+ pauseOnHover: !0,
16
+ pauseOnFocusLoss: !0,
17
+ swipeToDismiss: !0,
18
+ persist: !1
19
+ }, st = Symbol("vue-toast-kit-context");
20
+ class vt {
21
+ constructor(t, e, s) {
22
+ u(this, "groups", /* @__PURE__ */ new Map());
23
+ u(this, "expandedGroups", /* @__PURE__ */ new Set());
24
+ u(this, "getItems");
25
+ u(this, "hideItem");
26
+ u(this, "showItem");
27
+ this.getItems = t, this.hideItem = e, this.showItem = s;
28
+ }
29
+ add(t, e) {
30
+ if (!this.groups.has(e)) {
31
+ this.groups.set(e, [t]);
32
+ return;
33
+ }
34
+ const s = this.groups.get(e);
35
+ s.push(t);
36
+ const [o] = s, n = this.getItems([o])[0];
37
+ n && (n.groupCount.value = s.length), this.expandedGroups.has(e) || this.hideItem(t);
38
+ }
39
+ remove(t, e) {
40
+ const s = this.groups.get(e);
41
+ if (!s) return;
42
+ const o = s.indexOf(t);
43
+ if (o === -1) return;
44
+ if (s.splice(o, 1), s.length === 0) {
45
+ this.groups.delete(e), this.expandedGroups.delete(e);
46
+ return;
47
+ }
48
+ const [n] = s, a = this.getItems([n])[0];
49
+ if (a && (a.groupCount.value = s.length), o === 0 && s.length > 0 && (this.showItem(s[0]), !this.expandedGroups.has(e)))
50
+ for (let r = 1; r < s.length; r++)
51
+ this.hideItem(s[r]);
52
+ }
53
+ toggleExpand(t) {
54
+ const e = this.groups.get(t);
55
+ if (e)
56
+ if (this.expandedGroups.has(t)) {
57
+ this.expandedGroups.delete(t);
58
+ for (let s = 1; s < e.length; s++)
59
+ this.hideItem(e[s]);
60
+ } else {
61
+ this.expandedGroups.add(t);
62
+ for (const s of e)
63
+ this.showItem(s);
64
+ }
65
+ }
66
+ isExpanded(t) {
67
+ return this.expandedGroups.has(t);
68
+ }
69
+ getGroupIds(t) {
70
+ return this.groups.get(t) ?? [];
71
+ }
72
+ hasGroup(t) {
73
+ return this.groups.has(t);
74
+ }
75
+ clear() {
76
+ this.groups.clear(), this.expandedGroups.clear();
77
+ }
78
+ }
79
+ const H = class H {
80
+ constructor(t, e, s) {
81
+ u(this, "timerId", null);
82
+ u(this, "tickId", null);
83
+ u(this, "elapsed", 0);
84
+ u(this, "startTime", 0);
85
+ u(this, "_remaining", 1);
86
+ u(this, "_isPaused", !1);
87
+ u(this, "duration");
88
+ u(this, "onExpire");
89
+ u(this, "onTick");
90
+ this.duration = t, this.onExpire = e, this.onTick = s;
91
+ }
92
+ get remaining() {
93
+ return this._remaining;
94
+ }
95
+ get isPaused() {
96
+ return this._isPaused;
97
+ }
98
+ start() {
99
+ this.elapsed = 0, this._remaining = 1, this.startTime = Date.now(), this.scheduleExpiry(this.duration), this.onTick && this.startTick();
100
+ }
101
+ pause() {
102
+ this._isPaused || (this._isPaused = !0, this.elapsed += Date.now() - this.startTime, this.clearExpiry(), this.clearTick());
103
+ }
104
+ resume() {
105
+ if (!this._isPaused) return;
106
+ this._isPaused = !1;
107
+ const t = this.duration - this.elapsed;
108
+ this.startTime = Date.now(), this.scheduleExpiry(t), this.onTick && this.startTick();
109
+ }
110
+ destroy() {
111
+ this.clearExpiry(), this.clearTick();
112
+ }
113
+ scheduleExpiry(t) {
114
+ this.timerId = setTimeout(() => {
115
+ var e;
116
+ this.clearTick(), this._remaining = 0, (e = this.onTick) == null || e.call(this, 0), this.timerId = null, this.onExpire();
117
+ }, t);
118
+ }
119
+ clearExpiry() {
120
+ this.timerId !== null && (clearTimeout(this.timerId), this.timerId = null);
121
+ }
122
+ startTick() {
123
+ this.tickId = setInterval(() => {
124
+ var e;
125
+ const t = this.elapsed + (Date.now() - this.startTime);
126
+ this._remaining = Math.max(0, 1 - t / this.duration), (e = this.onTick) == null || e.call(this, this._remaining);
127
+ }, H.TICK_INTERVAL);
128
+ }
129
+ clearTick() {
130
+ this.tickId !== null && (clearInterval(this.tickId), this.tickId = null);
131
+ }
132
+ };
133
+ u(H, "TICK_INTERVAL", 50);
134
+ let N = H, yt = 0;
135
+ function kt() {
136
+ return `vtk-${Date.now()}-${++yt}`;
137
+ }
138
+ const $ = "vtk-persist";
139
+ class it {
140
+ constructor(t = 5, e = {}) {
141
+ u(this, "active", _([]));
142
+ u(this, "pending", _([]));
143
+ u(this, "maxVisible");
144
+ u(this, "hiddenItems", rt(/* @__PURE__ */ new Set()));
145
+ u(this, "timers", /* @__PURE__ */ new Map());
146
+ u(this, "groupManager");
147
+ u(this, "rateLimit");
148
+ u(this, "rateLimitWindowMs");
149
+ u(this, "recentAddTimes", []);
150
+ u(this, "persistStorage");
151
+ u(this, "addListeners", /* @__PURE__ */ new Set());
152
+ u(this, "dismissListeners", /* @__PURE__ */ new Set());
153
+ u(this, "updateListeners", /* @__PURE__ */ new Set());
154
+ this.maxVisible = t, this.rateLimit = e.rateLimit ?? 0, this.rateLimitWindowMs = e.rateLimitWindowMs ?? 1e3, this.persistStorage = e.persistStorage ?? !1, this.groupManager = new vt(
155
+ (s) => [...this.active, ...this.pending].filter((o) => s.includes(o.id)),
156
+ (s) => this.hiddenItems.add(s),
157
+ (s) => this.hiddenItems.delete(s)
158
+ ), this.persistStorage && this.restoreFromStorage();
159
+ }
160
+ /** Subscribe to toast add events. Returns an unsubscribe function. */
161
+ onAdd(t) {
162
+ return this.addListeners.add(t), () => this.addListeners.delete(t);
163
+ }
164
+ /** Subscribe to toast dismiss events. Returns an unsubscribe function. */
165
+ onDismiss(t) {
166
+ return this.dismissListeners.add(t), () => this.dismissListeners.delete(t);
167
+ }
168
+ /** Subscribe to toast update events. Returns an unsubscribe function. */
169
+ onUpdate(t) {
170
+ return this.updateListeners.add(t), () => this.updateListeners.delete(t);
171
+ }
172
+ emit(t, ...e) {
173
+ t.forEach((s) => s(...e));
174
+ }
175
+ isRateLimited() {
176
+ if (!this.rateLimit) return !1;
177
+ const t = Date.now();
178
+ return this.recentAddTimes = this.recentAddTimes.filter((e) => t - e < this.rateLimitWindowMs), this.recentAddTimes.length >= this.rateLimit ? !0 : (this.recentAddTimes.push(t), !1);
179
+ }
180
+ restoreFromStorage() {
181
+ if (!(typeof localStorage > "u"))
182
+ try {
183
+ const t = localStorage.getItem($);
184
+ if (!t) return;
185
+ const e = JSON.parse(t);
186
+ for (const s of e)
187
+ this.add(s.message, { ...s.options, id: s.id });
188
+ } catch {
189
+ localStorage.removeItem($);
190
+ }
191
+ }
192
+ saveToStorage(t) {
193
+ if (!(typeof localStorage > "u"))
194
+ try {
195
+ const e = localStorage.getItem($), s = e ? JSON.parse(e) : [];
196
+ s.find((o) => o.id === t.id) || (s.push({ id: t.id, message: t.message, options: t.options }), localStorage.setItem($, JSON.stringify(s)));
197
+ } catch {
198
+ }
199
+ }
200
+ removeFromStorage(t) {
201
+ if (!(typeof localStorage > "u"))
202
+ try {
203
+ const e = localStorage.getItem($);
204
+ if (!e) return;
205
+ const o = JSON.parse(e).filter((n) => n.id !== t);
206
+ o.length ? localStorage.setItem($, JSON.stringify(o)) : localStorage.removeItem($);
207
+ } catch {
208
+ }
209
+ }
210
+ get visibleActive() {
211
+ return this.active.filter((t) => !this.hiddenItems.has(t.id));
212
+ }
213
+ isHidden(t) {
214
+ return this.hiddenItems.has(t);
215
+ }
216
+ add(t, e = {}) {
217
+ if (this.isRateLimited()) return "";
218
+ const s = e.id ?? kt(), o = this.active.find((r) => r.id === s);
219
+ if (o)
220
+ return this.mergeOptions(o, e), s;
221
+ const n = this.createItem(s, t, e);
222
+ if (this.visibleActive.length < this.maxVisible)
223
+ return this.active.push(n), this.startTimer(n), e.groupKey && this.groupManager.add(s, e.groupKey), this.persistStorage && n.options.persist && this.saveToStorage(n), this.emit(this.addListeners, n), s;
224
+ const a = e.priority ?? "normal";
225
+ if (x[a] > x.normal) {
226
+ const r = this.findLowestPriorityIndex();
227
+ if (r !== -1) {
228
+ const p = this.active[r];
229
+ if (x[a] > x[p.options.priority])
230
+ return this.stopTimer(p.id), this.active.splice(r, 1), this.pending.unshift(p), this.active.push(n), this.startTimer(n), e.groupKey && this.groupManager.add(s, e.groupKey), this.persistStorage && n.options.persist && this.saveToStorage(n), this.emit(this.addListeners, n), s;
231
+ }
232
+ }
233
+ return this.pending.push(n), this.sortPending(), e.groupKey && this.groupManager.add(s, e.groupKey), this.persistStorage && n.options.persist && this.saveToStorage(n), this.emit(this.addListeners, n), s;
234
+ }
235
+ remove(t) {
236
+ this.stopTimer(t);
237
+ const e = this.active.findIndex((o) => o.id === t);
238
+ if (e !== -1) {
239
+ const o = this.active[e];
240
+ if (this.active.splice(e, 1), this.hiddenItems.delete(t), o.options.groupKey && this.groupManager.remove(t, o.options.groupKey), this.persistStorage && this.removeFromStorage(t), this.pending.length > 0) {
241
+ const n = this.pending.shift();
242
+ this.active.push(n), this.startTimer(n);
243
+ }
244
+ return;
245
+ }
246
+ const s = this.pending.findIndex((o) => o.id === t);
247
+ if (s !== -1) {
248
+ const o = this.pending[s];
249
+ this.pending.splice(s, 1), this.hiddenItems.delete(t), o.options.groupKey && this.groupManager.remove(t, o.options.groupKey), this.persistStorage && this.removeFromStorage(t);
250
+ }
251
+ }
252
+ update(t, e) {
253
+ const s = [...this.active, ...this.pending].find((o) => o.id === t);
254
+ s && (this.mergeOptions(s, e), this.emit(this.updateListeners, t, e));
255
+ }
256
+ dismiss(t) {
257
+ var s, o;
258
+ if (t === void 0) {
259
+ [...this.active, ...this.pending].map((a) => a.id).forEach((a) => this.remove(a));
260
+ return;
261
+ }
262
+ const e = [...this.active, ...this.pending].find((n) => n.id === t);
263
+ e && ((o = (s = e.options).onClose) == null || o.call(s), this.remove(t), this.emit(this.dismissListeners, t));
264
+ }
265
+ dismissAll(t) {
266
+ [...this.active, ...this.pending].filter(
267
+ (s) => !t || s.options.position === t
268
+ ).forEach((s) => {
269
+ var o, n;
270
+ (n = (o = s.options).onClose) == null || n.call(o), this.remove(s.id), this.emit(this.dismissListeners, s.id);
271
+ });
272
+ }
273
+ isActive(t) {
274
+ return this.active.some((e) => e.id === t);
275
+ }
276
+ pauseAll() {
277
+ this.active.forEach((t) => t.pause());
278
+ }
279
+ resumeAll() {
280
+ this.active.forEach((t) => t.resume());
281
+ }
282
+ setMaxVisible(t) {
283
+ for (this.maxVisible = t; this.visibleActive.length < t && this.pending.length > 0; ) {
284
+ const e = this.pending.shift();
285
+ this.active.push(e), this.startTimer(e);
286
+ }
287
+ }
288
+ toggleGroupExpand(t) {
289
+ this.groupManager.toggleExpand(t);
290
+ }
291
+ isGroupExpanded(t) {
292
+ return this.groupManager.isExpanded(t);
293
+ }
294
+ destroy() {
295
+ this.timers.forEach((t) => t.destroy()), this.timers.clear(), this.groupManager.clear(), this.active.splice(0), this.pending.splice(0), this.hiddenItems.clear(), this.addListeners.clear(), this.dismissListeners.clear(), this.updateListeners.clear();
296
+ }
297
+ createItem(t, e, s) {
298
+ const o = C(1), n = C(!1), a = C(1), r = C(!1), p = {
299
+ ...pt,
300
+ ...s,
301
+ type: s.type ?? "info",
302
+ priority: s.priority ?? "normal",
303
+ duration: s.duration ?? 4e3,
304
+ closable: s.closable ?? !0,
305
+ pauseOnHover: s.pauseOnHover ?? !0,
306
+ pauseOnFocusLoss: s.pauseOnFocusLoss ?? !0,
307
+ swipeToDismiss: s.swipeToDismiss ?? !0,
308
+ persist: s.persist ?? !1
309
+ };
310
+ return {
311
+ id: t,
312
+ message: e,
313
+ options: p,
314
+ createdAt: Date.now(),
315
+ remaining: o,
316
+ isPaused: n,
317
+ groupCount: a,
318
+ isGrouped: r,
319
+ pause: () => {
320
+ var k;
321
+ n.value = !0, (k = this.timers.get(t)) == null || k.pause();
322
+ },
323
+ resume: () => {
324
+ var k;
325
+ n.value = !1, (k = this.timers.get(t)) == null || k.resume();
326
+ },
327
+ dismiss: () => this.dismiss(t),
328
+ update: (k) => this.update(t, k)
329
+ };
330
+ }
331
+ startTimer(t) {
332
+ var o;
333
+ const e = ((o = t.options.undo) == null ? void 0 : o.duration) ?? t.options.duration;
334
+ if (!e) return;
335
+ const s = new N(
336
+ e,
337
+ () => {
338
+ var n, a;
339
+ (a = (n = t.options).onAutoClose) == null || a.call(n), this.remove(t.id);
340
+ },
341
+ (n) => {
342
+ t.remaining.value = n;
343
+ }
344
+ );
345
+ this.timers.set(t.id, s), s.start();
346
+ }
347
+ stopTimer(t) {
348
+ var e;
349
+ (e = this.timers.get(t)) == null || e.destroy(), this.timers.delete(t);
350
+ }
351
+ mergeOptions(t, e) {
352
+ Object.assign(t.options, e), "message" in e && (t.message = e.message);
353
+ }
354
+ findLowestPriorityIndex() {
355
+ let t = -1, e = 999;
356
+ return this.active.forEach((s, o) => {
357
+ const n = x[s.options.priority];
358
+ n < e && (e = n, t = o);
359
+ }), t;
360
+ }
361
+ sortPending() {
362
+ this.pending.sort((t, e) => {
363
+ const s = x[t.options.priority], o = x[e.options.priority];
364
+ return o !== s ? o - s : t.createdAt - e.createdAt;
365
+ });
366
+ }
367
+ }
368
+ const Tt = typeof window > "u";
369
+ class bt {
370
+ constructor() {
371
+ u(this, "buffer", []);
372
+ u(this, "flushed", !1);
373
+ u(this, "flushCallbacks", []);
374
+ }
375
+ push(t, e) {
376
+ this.flushed || this.buffer.push({ message: t, options: e });
377
+ }
378
+ onFlush(t) {
379
+ this.flushCallbacks.push(t);
380
+ }
381
+ flush() {
382
+ if (this.flushed) return;
383
+ this.flushed = !0;
384
+ const t = [...this.buffer];
385
+ this.buffer = [];
386
+ for (const e of this.flushCallbacks)
387
+ e(t);
388
+ this.flushCallbacks = [];
389
+ }
390
+ isFlushed() {
391
+ return this.flushed;
392
+ }
393
+ get size() {
394
+ return this.buffer.length;
395
+ }
396
+ }
397
+ const q = new bt();
398
+ function ot(i) {
399
+ return {
400
+ queue: i,
401
+ addToast(t, e = {}) {
402
+ if (Tt) {
403
+ const s = e.id ?? `vtk-ssr-${Date.now()}`;
404
+ return q.push(t, { ...e, id: s }), s;
405
+ }
406
+ return i.add(t, e);
407
+ },
408
+ dismiss(t) {
409
+ i.dismiss(t);
410
+ },
411
+ update(t, e) {
412
+ i.update(t, e);
413
+ },
414
+ isActive(t) {
415
+ return i.isActive(t);
416
+ }
417
+ };
418
+ }
419
+ let J = null;
420
+ function R(i) {
421
+ if (!J) {
422
+ const t = new it((i == null ? void 0 : i.maxVisible) ?? 5, {
423
+ rateLimit: i == null ? void 0 : i.rateLimit,
424
+ rateLimitWindowMs: i == null ? void 0 : i.rateLimitWindowMs,
425
+ persistStorage: i == null ? void 0 : i.persistStorage
426
+ });
427
+ J = ot(t);
428
+ }
429
+ return J;
430
+ }
431
+ function Yt(i) {
432
+ const t = new it((i == null ? void 0 : i.maxVisible) ?? 5, {
433
+ rateLimit: i == null ? void 0 : i.rateLimit,
434
+ rateLimitWindowMs: i == null ? void 0 : i.rateLimitWindowMs,
435
+ persistStorage: i == null ? void 0 : i.persistStorage
436
+ });
437
+ return ot(t);
438
+ }
439
+ function Z() {
440
+ const i = lt(st, null);
441
+ return i || R();
442
+ }
443
+ function wt(i, t) {
444
+ const e = R(t);
445
+ return i.provide(st, e), e;
446
+ }
447
+ function et(i, t, e) {
448
+ var a;
449
+ const s = i;
450
+ (a = s.timers.get(t)) == null || a.destroy(), s.timers.delete(t);
451
+ const o = i.active.find((r) => r.id === t);
452
+ if (!o || !e) return;
453
+ const n = new N(
454
+ e,
455
+ () => {
456
+ var r, p;
457
+ (p = (r = o.options).onAutoClose) == null || p.call(r), i.remove(t);
458
+ },
459
+ (r) => {
460
+ o.remaining.value = r;
461
+ }
462
+ );
463
+ s.timers.set(t, n), n.start();
464
+ }
465
+ function B(i) {
466
+ const t = i.queue;
467
+ function e(s, o) {
468
+ return i.addToast(s, { type: "info", ...o });
469
+ }
470
+ return e.success = (s, o) => i.addToast(s, { type: "success", ...o }), e.error = (s, o) => i.addToast(s, { type: "error", priority: "high", ...o }), e.warning = (s, o) => i.addToast(s, { type: "warning", ...o }), e.info = (s, o) => i.addToast(s, { type: "info", ...o }), e.loading = (s, o) => i.addToast(s, { type: "loading", duration: 0, closable: !1, ...o }), e.custom = (s, o) => i.addToast("", { type: "custom", component: s, duration: 0, ...o }), e.dismiss = (s) => i.dismiss(s), e.update = (s, o) => {
471
+ const n = t.active.find((a) => a.id === s);
472
+ n && o.message !== void 0 && (n.message = o.message), i.update(s, o);
473
+ }, e.updateMessage = (s, o) => {
474
+ const n = t.active.find((a) => a.id === s);
475
+ n && (n.message = o);
476
+ }, e.isActive = (s) => i.isActive(s), e.promise = async (s, o, n) => {
477
+ const a = e.loading(o.loading, n);
478
+ try {
479
+ const r = await s, p = typeof o.success == "function" ? o.success(r) : o.success, v = t.active.find((k) => k.id === a);
480
+ return v && (v.message = p, v.options.type = "success", v.options.closable = !0, v.options.duration = 3e3, et(t, a, 3e3)), r;
481
+ } catch (r) {
482
+ const p = typeof o.error == "function" ? o.error(r) : o.error, v = t.active.find((k) => k.id === a);
483
+ throw v && (v.message = p, v.options.type = "error", v.options.closable = !0, v.options.duration = 5e3, et(t, a, 5e3)), r;
484
+ }
485
+ }, e.undo = (s, o) => i.addToast(s, {
486
+ type: "info",
487
+ duration: o.undo.duration ?? 5e3,
488
+ closable: !1,
489
+ ...o
490
+ }), e.dismissAll = (s) => t.dismissAll(s), e.pauseAll = () => t.pauseAll(), e.resumeAll = () => t.resumeAll(), e;
491
+ }
492
+ function jt(i) {
493
+ if (i) return B(i);
494
+ try {
495
+ const t = Z();
496
+ return B(t);
497
+ } catch {
498
+ return B(R());
499
+ }
500
+ }
501
+ const Jt = B(R());
502
+ function Ut(i) {
503
+ const t = i ?? Z(), e = t.queue, s = g(() => e.active.filter((r) => !e.isHidden(r.id))), o = g(() => [...e.pending]), n = g(() => s.value.length);
504
+ function a(r) {
505
+ return t.isActive(r);
506
+ }
507
+ return { active: s, pending: o, count: n, has: a };
508
+ }
509
+ const It = { key: 1 }, xt = {
510
+ key: 2,
511
+ class: "vtk-spinner"
512
+ }, St = {
513
+ key: 0,
514
+ viewBox: "0 0 20 20",
515
+ fill: "currentColor"
516
+ }, Lt = {
517
+ key: 1,
518
+ viewBox: "0 0 20 20",
519
+ fill: "currentColor"
520
+ }, Ct = {
521
+ key: 2,
522
+ viewBox: "0 0 20 20",
523
+ fill: "currentColor"
524
+ }, Mt = {
525
+ key: 3,
526
+ viewBox: "0 0 20 20",
527
+ fill: "currentColor"
528
+ }, $t = /* @__PURE__ */ D({
529
+ __name: "ToastIcon",
530
+ props: {
531
+ type: {},
532
+ icon: { type: [String, Boolean] }
533
+ },
534
+ setup(i) {
535
+ const t = i, e = g(
536
+ () => t.icon && typeof t.icon == "object"
537
+ ), s = g(
538
+ () => t.icon && typeof t.icon == "string"
539
+ ), o = g(() => t.icon !== !1 && !t.icon);
540
+ return (n, a) => (d(), f("span", {
541
+ class: Q(["vtk-icon", `vtk-icon--${i.type}`]),
542
+ "aria-hidden": "true"
543
+ }, [
544
+ e.value ? (d(), S(V(i.icon), { key: 0 })) : s.value ? (d(), f("span", It, O(i.icon), 1)) : i.type === "loading" ? (d(), f("span", xt)) : o.value ? (d(), f(P, { key: 3 }, [
545
+ i.type === "success" ? (d(), f("svg", St, [...a[0] || (a[0] = [
546
+ w("path", {
547
+ "fill-rule": "evenodd",
548
+ 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",
549
+ "clip-rule": "evenodd"
550
+ }, null, -1)
551
+ ])])) : i.type === "error" ? (d(), f("svg", Lt, [...a[1] || (a[1] = [
552
+ w("path", {
553
+ "fill-rule": "evenodd",
554
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z",
555
+ "clip-rule": "evenodd"
556
+ }, null, -1)
557
+ ])])) : i.type === "warning" ? (d(), f("svg", Ct, [...a[2] || (a[2] = [
558
+ w("path", {
559
+ "fill-rule": "evenodd",
560
+ d: "M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 5a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 5zm0 9a1 1 0 100-2 1 1 0 000 2z",
561
+ "clip-rule": "evenodd"
562
+ }, null, -1)
563
+ ])])) : i.type === "info" ? (d(), f("svg", Mt, [...a[3] || (a[3] = [
564
+ w("path", {
565
+ "fill-rule": "evenodd",
566
+ 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",
567
+ "clip-rule": "evenodd"
568
+ }, null, -1)
569
+ ])])) : L("", !0)
570
+ ], 64)) : L("", !0)
571
+ ], 2));
572
+ }
573
+ }), At = {
574
+ class: "vtk-progress",
575
+ "aria-hidden": "true"
576
+ }, Et = /* @__PURE__ */ D({
577
+ __name: "ToastProgressBar",
578
+ props: {
579
+ remaining: {}
580
+ },
581
+ setup(i) {
582
+ const t = i, e = g(() => t.remaining);
583
+ return (s, o) => (d(), f("div", At, [
584
+ w("div", {
585
+ class: "vtk-progress__bar",
586
+ style: W({ transform: `scaleX(${e.value})` })
587
+ }, null, 4)
588
+ ]));
589
+ }
590
+ }), Ot = { class: "vtk-actions" }, Pt = /* @__PURE__ */ D({
591
+ __name: "ToastActions",
592
+ props: {
593
+ toast: {},
594
+ onDismiss: { type: Function }
595
+ },
596
+ setup(i) {
597
+ const t = i;
598
+ function e() {
599
+ var s;
600
+ (s = t.toast.options.undo) == null || s.onUndo(), t.onDismiss(t.toast.id);
601
+ }
602
+ return (s, o) => (d(), f("div", Ot, [
603
+ i.toast.options.action ? (d(), f("button", {
604
+ key: 0,
605
+ class: "vtk-btn vtk-btn--action",
606
+ type: "button",
607
+ onClick: o[0] || (o[0] = (n) => i.toast.options.action.onClick())
608
+ }, O(i.toast.options.action.label), 1)) : L("", !0),
609
+ i.toast.options.undo ? (d(), f("button", {
610
+ key: 1,
611
+ class: "vtk-btn vtk-btn--undo",
612
+ type: "button",
613
+ onClick: e
614
+ }, O(i.toast.options.undo.label ?? "Undo"), 1)) : L("", !0)
615
+ ]));
616
+ }
617
+ }), Dt = ["role", "aria-live", "tabindex"], zt = { class: "vtk-content" }, Gt = { class: "vtk-message" }, Ft = ["aria-label"], Vt = /* @__PURE__ */ D({
618
+ __name: "Toast",
619
+ props: {
620
+ toast: {},
621
+ onDismiss: { type: Function },
622
+ onGroupToggle: { type: Function }
623
+ },
624
+ setup(i) {
625
+ const t = i, e = C(null);
626
+ let s = null;
627
+ U(() => {
628
+ s = document.activeElement;
629
+ });
630
+ function o(c) {
631
+ t.onDismiss(c), s && typeof s.focus == "function" && s.focus();
632
+ }
633
+ const n = C(0), a = C(!1);
634
+ let r = 0;
635
+ function p(c) {
636
+ t.toast.options.swipeToDismiss && (r = c.touches[0].clientX, a.value = !0);
637
+ }
638
+ function v(c) {
639
+ a.value && (n.value = c.touches[0].clientX - r);
640
+ }
641
+ function k() {
642
+ var M;
643
+ if (!a.value) return;
644
+ a.value = !1;
645
+ const c = (((M = e.value) == null ? void 0 : M.offsetWidth) ?? 280) * 0.4;
646
+ Math.abs(n.value) > c ? t.onDismiss(t.toast.id) : n.value = 0;
647
+ }
648
+ function X() {
649
+ t.toast.options.pauseOnHover && t.toast.pause();
650
+ }
651
+ function z() {
652
+ t.toast.options.pauseOnHover && t.toast.resume();
653
+ }
654
+ function G() {
655
+ t.toast.options.pauseOnFocusLoss && (document.hidden ? t.toast.pause() : t.toast.resume());
656
+ }
657
+ U(() => {
658
+ document.addEventListener("visibilitychange", G);
659
+ }), ut(() => {
660
+ document.removeEventListener("visibilitychange", G);
661
+ });
662
+ const K = g(() => {
663
+ const c = t.toast.options.type;
664
+ return c === "error" || c === "warning" || t.toast.options.priority === "critical" ? "alert" : "status";
665
+ }), Y = g(() => t.toast.options.ariaLive ? t.toast.options.ariaLive : t.toast.options.priority === "critical" ? "assertive" : "polite"), l = g(() => {
666
+ if (!n.value) return {};
667
+ const c = Math.max(0, 1 - Math.abs(n.value) / 200);
668
+ return {
669
+ transform: `translateX(${n.value}px)`,
670
+ opacity: c,
671
+ transition: a.value ? "none" : void 0
672
+ };
673
+ }), m = g(() => !!t.toast.options.undo), h = g(() => !!t.toast.options.action), y = g(() => t.toast.options.closable), I = g(
674
+ () => t.toast.options.duration > 0 && !t.toast.isPaused.value
675
+ ), T = g(() => t.toast.groupCount.value > 1);
676
+ function F() {
677
+ var c;
678
+ t.toast.options.groupKey && ((c = t.onGroupToggle) == null || c.call(t, t.toast.options.groupKey));
679
+ }
680
+ function j(c) {
681
+ c.key === "Escape" && y.value && (c.stopPropagation(), o(t.toast.id));
682
+ }
683
+ return (c, M) => (d(), f("div", {
684
+ ref_key: "el",
685
+ ref: e,
686
+ class: Q([
687
+ "vtk-toast",
688
+ `vtk-toast--${i.toast.options.type}`,
689
+ i.toast.options.theme && typeof i.toast.options.theme == "string" ? `vtk-theme-${i.toast.options.theme}` : ""
690
+ ]),
691
+ role: K.value,
692
+ "aria-live": Y.value,
693
+ "aria-atomic": !0,
694
+ tabindex: y.value || h.value || m.value ? 0 : void 0,
695
+ style: W(l.value),
696
+ onMouseenter: X,
697
+ onMouseleave: z,
698
+ onTouchstartPassive: p,
699
+ onTouchmovePassive: v,
700
+ onTouchend: k,
701
+ onKeydown: j
702
+ }, [
703
+ i.toast.options.component ? (d(), S(V(i.toast.options.component), E({ key: 0 }, i.toast.options.componentProps, {
704
+ toast: i.toast,
705
+ dismiss: () => i.onDismiss(i.toast.id)
706
+ }), null, 16, ["toast", "dismiss"])) : (d(), f(P, { key: 1 }, [
707
+ b(c.$slots, "toast-icon", { toast: i.toast }, () => [
708
+ i.toast.options.icon !== !1 ? (d(), S($t, {
709
+ key: 0,
710
+ type: i.toast.options.type,
711
+ icon: i.toast.options.icon
712
+ }, null, 8, ["type", "icon"])) : L("", !0)
713
+ ]),
714
+ b(c.$slots, "toast-content", { toast: i.toast }, () => [
715
+ w("div", zt, [
716
+ w("div", Gt, [
717
+ typeof i.toast.message != "string" ? (d(), S(V("span"), { key: 0 }, {
718
+ default: A(() => [
719
+ (d(), S(V(i.toast.message)))
720
+ ]),
721
+ _: 1
722
+ })) : (d(), f(P, { key: 1 }, [
723
+ dt(O(i.toast.message), 1)
724
+ ], 64))
725
+ ]),
726
+ b(c.$slots, "toast-action", { toast: i.toast }, () => [
727
+ h.value || m.value ? (d(), S(Pt, {
728
+ key: 0,
729
+ toast: i.toast,
730
+ "on-dismiss": i.onDismiss
731
+ }, null, 8, ["toast", "on-dismiss"])) : L("", !0)
732
+ ])
733
+ ])
734
+ ]),
735
+ T.value ? (d(), f("span", {
736
+ key: 0,
737
+ class: "vtk-group-count",
738
+ role: "button",
739
+ "aria-label": `Show all (${i.toast.groupCount.value})`,
740
+ onClick: F
741
+ }, " +" + O(i.toast.groupCount.value - 1), 9, Ft)) : L("", !0),
742
+ b(c.$slots, "toast-close", {
743
+ toast: i.toast,
744
+ dismiss: o
745
+ }, () => [
746
+ y.value ? (d(), f("button", {
747
+ key: 0,
748
+ class: "vtk-btn vtk-btn--close",
749
+ type: "button",
750
+ "aria-label": "Close",
751
+ onClick: M[0] || (M[0] = (Rt) => o(i.toast.id))
752
+ }, [...M[1] || (M[1] = [
753
+ w("svg", {
754
+ width: "14",
755
+ height: "14",
756
+ viewBox: "0 0 14 14",
757
+ fill: "currentColor"
758
+ }, [
759
+ w("path", { d: "M1.4 1.4a1 1 0 011.42 0L7 5.59l4.18-4.19a1 1 0 111.42 1.42L8.41 7l4.19 4.18a1 1 0 01-1.42 1.42L7 8.41l-4.18 4.19A1 1 0 011.4 12.6L5.59 7 1.4 2.82a1 1 0 010-1.42z" })
760
+ ], -1)
761
+ ])])) : L("", !0)
762
+ ])
763
+ ], 64)),
764
+ b(c.$slots, "toast-undo", {
765
+ toast: i.toast,
766
+ remaining: i.toast.remaining.value
767
+ }, () => [
768
+ I.value || m.value ? (d(), S(Et, {
769
+ key: 0,
770
+ remaining: i.toast.remaining.value
771
+ }, null, 8, ["remaining"])) : L("", !0)
772
+ ])
773
+ ], 46, Dt));
774
+ }
775
+ }), Bt = ["role", "aria-label"], Wt = /* @__PURE__ */ D({
776
+ __name: "ToastContainer",
777
+ props: {
778
+ position: { default: "bottom-right" },
779
+ maxVisible: { default: 5 },
780
+ gap: { default: 8 },
781
+ offsetX: { default: 16 },
782
+ offsetY: { default: 16 },
783
+ zIndex: { default: 9999 },
784
+ expand: { type: Boolean, default: !1 },
785
+ teleportTo: { default: "body" },
786
+ context: {},
787
+ theme: {},
788
+ stackMode: { type: Boolean, default: !1 }
789
+ },
790
+ setup(i) {
791
+ const t = [
792
+ "top-left",
793
+ "top-center",
794
+ "top-right",
795
+ "bottom-left",
796
+ "bottom-center",
797
+ "bottom-right"
798
+ ], e = i, s = e.context ?? Z(), o = s.queue;
799
+ ct(() => e.maxVisible, (l) => o.setMaxVisible(l), { immediate: !0 });
800
+ const n = C(!1), a = g(() => o.active.filter((l) => !o.isHidden(l.id)));
801
+ function r(l) {
802
+ return a.value.filter((m) => (m.options.position ?? e.position) === l).sort((m, h) => x[h.options.priority] - x[m.options.priority]);
803
+ }
804
+ function p(l, m, h) {
805
+ return h.startsWith("bottom") ? m - 1 - l : l;
806
+ }
807
+ function v(l, m, h) {
808
+ if (!e.stackMode || n.value) return {};
809
+ const y = p(l, m, h);
810
+ if (y === 0) return { "z-index": "10" };
811
+ if (y > 2) return { display: "none" };
812
+ const I = h.startsWith("bottom"), T = Math.max(0.88, 1 - y * 0.06), F = y * 8, j = Math.max(0.5, 1 - y * 0.2);
813
+ return {
814
+ position: "absolute",
815
+ width: "100%",
816
+ [I ? "bottom" : "top"]: "0",
817
+ transform: `translateY(${I ? F : -F}px) scale(${T})`,
818
+ opacity: String(j),
819
+ "pointer-events": "none",
820
+ "z-index": String(10 - y),
821
+ transition: "transform 300ms ease, opacity 300ms ease"
822
+ };
823
+ }
824
+ function k(l) {
825
+ const m = r(l);
826
+ return [
827
+ "vtk-container",
828
+ `vtk-container--${l}`,
829
+ e.theme && typeof e.theme == "string" ? `vtk-theme-${e.theme}` : "",
830
+ e.stackMode && m.length > 1 ? "vtk-container--stack" : "",
831
+ e.stackMode && n.value ? "vtk-container--stack-expanded" : ""
832
+ ];
833
+ }
834
+ const X = g(() => {
835
+ const l = {
836
+ "--vtk-z-index": String(e.zIndex),
837
+ "--vtk-gap": `${e.gap}px`,
838
+ "--vtk-container-offset-x": `${e.offsetX}px`,
839
+ "--vtk-container-offset-y": `${e.offsetY}px`
840
+ };
841
+ if (e.theme && typeof e.theme == "object") {
842
+ const m = {
843
+ colorBg: "--vtk-color-bg",
844
+ colorText: "--vtk-color-text",
845
+ colorBorder: "--vtk-color-border",
846
+ colorSuccess: "--vtk-color-success",
847
+ colorError: "--vtk-color-error",
848
+ colorWarning: "--vtk-color-warning",
849
+ colorInfo: "--vtk-color-info",
850
+ colorLoading: "--vtk-color-loading",
851
+ fontFamily: "--vtk-font-family",
852
+ fontSize: "--vtk-font-size",
853
+ fontWeight: "--vtk-font-weight",
854
+ lineHeight: "--vtk-line-height",
855
+ borderRadius: "--vtk-border-radius",
856
+ borderWidth: "--vtk-border-width",
857
+ shadow: "--vtk-shadow",
858
+ paddingX: "--vtk-padding-x",
859
+ paddingY: "--vtk-padding-y",
860
+ iconSize: "--vtk-icon-size",
861
+ progressHeight: "--vtk-progress-height",
862
+ maxWidth: "--vtk-max-width",
863
+ minWidth: "--vtk-min-width",
864
+ transitionDuration: "--vtk-transition-duration",
865
+ transitionEasing: "--vtk-transition-easing",
866
+ zIndex: "--vtk-z-index"
867
+ };
868
+ for (const [h, y] of Object.entries(m)) {
869
+ const I = e.theme[h];
870
+ I && (l[y] = I);
871
+ }
872
+ }
873
+ return l;
874
+ });
875
+ function z(l) {
876
+ s.dismiss(l);
877
+ }
878
+ function G(l) {
879
+ o.toggleGroupExpand(l);
880
+ }
881
+ function K() {
882
+ n.value = !0, o.pauseAll();
883
+ }
884
+ function Y() {
885
+ n.value = !1, o.resumeAll();
886
+ }
887
+ return U(() => {
888
+ setTimeout(() => {
889
+ q.onFlush((l) => {
890
+ for (const m of l)
891
+ s.addToast(m.message, m.options);
892
+ }), q.flush();
893
+ }, 100);
894
+ }), (l, m) => (d(), S(ht, { to: i.teleportTo }, [
895
+ (d(), f(P, null, tt(t, (h) => w("div", {
896
+ key: h,
897
+ class: Q(k(h)),
898
+ style: W(X.value),
899
+ role: r(h).length ? "region" : void 0,
900
+ "aria-label": r(h).length ? "Notifications" : void 0,
901
+ onMouseenter: K,
902
+ onMouseleave: Y
903
+ }, [
904
+ ft(mt, {
905
+ name: `vtk-slide-${h}`,
906
+ tag: "div",
907
+ class: "vtk-container__list"
908
+ }, {
909
+ default: A(() => [
910
+ (d(!0), f(P, null, tt(r(h), (y, I) => (d(), f("div", {
911
+ key: y.id,
912
+ class: "vtk-toast-wrap",
913
+ style: W(v(I, r(h).length, h))
914
+ }, [
915
+ l.$slots.toast ? b(l.$slots, "toast", {
916
+ key: 0,
917
+ toast: y,
918
+ dismiss: z
919
+ }, void 0, !0) : (d(), S(Vt, {
920
+ key: 1,
921
+ toast: y,
922
+ "on-dismiss": z,
923
+ "on-group-toggle": G
924
+ }, gt({ _: 2 }, [
925
+ l.$slots["toast-icon"] ? {
926
+ name: "toast-icon",
927
+ fn: A((T) => [
928
+ b(l.$slots, "toast-icon", E({ ref_for: !0 }, T), void 0, !0)
929
+ ]),
930
+ key: "0"
931
+ } : void 0,
932
+ l.$slots["toast-content"] ? {
933
+ name: "toast-content",
934
+ fn: A((T) => [
935
+ b(l.$slots, "toast-content", E({ ref_for: !0 }, T), void 0, !0)
936
+ ]),
937
+ key: "1"
938
+ } : void 0,
939
+ l.$slots["toast-action"] ? {
940
+ name: "toast-action",
941
+ fn: A((T) => [
942
+ b(l.$slots, "toast-action", E({ ref_for: !0 }, T), void 0, !0)
943
+ ]),
944
+ key: "2"
945
+ } : void 0,
946
+ l.$slots["toast-close"] ? {
947
+ name: "toast-close",
948
+ fn: A((T) => [
949
+ b(l.$slots, "toast-close", E({ ref_for: !0 }, T), void 0, !0)
950
+ ]),
951
+ key: "3"
952
+ } : void 0,
953
+ l.$slots["toast-undo"] ? {
954
+ name: "toast-undo",
955
+ fn: A((T) => [
956
+ b(l.$slots, "toast-undo", E({ ref_for: !0 }, T), void 0, !0)
957
+ ]),
958
+ key: "4"
959
+ } : void 0
960
+ ]), 1032, ["toast"]))
961
+ ], 4))), 128))
962
+ ]),
963
+ _: 2
964
+ }, 1032, ["name"])
965
+ ], 46, Bt)), 64))
966
+ ], 8, ["to"]));
967
+ }
968
+ }), Nt = (i, t) => {
969
+ const e = i.__vccOpts || i;
970
+ for (const [s, o] of t)
971
+ e[s] = o;
972
+ return e;
973
+ }, Ht = /* @__PURE__ */ Nt(Wt, [["__scopeId", "data-v-4affbb62"]]), qt = {
974
+ install(i, t) {
975
+ wt(i, t ?? {}), (t == null ? void 0 : t.registerComponent) !== !1 && i.component("ToastContainer", Ht);
976
+ }
977
+ };
978
+ export {
979
+ pt as DEFAULT_OPTIONS,
980
+ vt as GroupManager,
981
+ x as PRIORITY_ORDER,
982
+ st as TOAST_CONTEXT_KEY,
983
+ Vt as Toast,
984
+ Pt as ToastActions,
985
+ Ht as ToastContainer,
986
+ $t as ToastIcon,
987
+ Et as ToastProgressBar,
988
+ it as ToastQueue,
989
+ N as UndoTimer,
990
+ qt as VueToastPlugin,
991
+ Yt as createToastContext,
992
+ R as getOrCreateGlobalContext,
993
+ q as globalBuffer,
994
+ Tt as isServer,
995
+ Jt as toast,
996
+ jt as useToast,
997
+ Z as useToastContext,
998
+ Ut as useToastState
999
+ };
1000
+ //# sourceMappingURL=vue-toast-kit.js.map