vetra-toast 1.0.2 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/animations/index.d.ts +0 -1
  2. package/dist/components/ToastIcon.d.ts +0 -1
  3. package/dist/components/ToastItem.d.ts +24 -22
  4. package/dist/components/ToastProgress.d.ts +0 -1
  5. package/dist/components/Toaster.d.ts +0 -1
  6. package/dist/core/index.d.ts +0 -1
  7. package/dist/core/store.d.ts +2 -23
  8. package/dist/core/timer.d.ts +0 -1
  9. package/dist/core/toast-api.d.ts +0 -1
  10. package/dist/core-BikVsncn.js +1 -0
  11. package/dist/core-DWP-MMiI.cjs +1 -0
  12. package/dist/core.cjs +1 -9
  13. package/dist/core.js +1 -1
  14. package/dist/hooks/use-mounted.d.ts +0 -1
  15. package/dist/hooks/use-swipe.d.ts +0 -1
  16. package/dist/hooks/use-system-theme.d.ts +0 -1
  17. package/dist/hooks/use-toasts.d.ts +0 -1
  18. package/dist/index.cjs +1 -1057
  19. package/dist/index.d.ts +0 -1
  20. package/dist/index.js +1 -1043
  21. package/dist/styles.css +1 -1419
  22. package/dist/types/index.d.ts +0 -1
  23. package/dist/utils/dom.d.ts +0 -1
  24. package/dist/utils/feedback.d.ts +0 -1
  25. package/dist/utils/id.d.ts +0 -1
  26. package/dist/utils/merge.d.ts +0 -1
  27. package/package.json +1 -1
  28. package/dist/animations/index.d.ts.map +0 -1
  29. package/dist/components/ToastIcon.d.ts.map +0 -1
  30. package/dist/components/ToastItem.d.ts.map +0 -1
  31. package/dist/components/ToastProgress.d.ts.map +0 -1
  32. package/dist/components/Toaster.d.ts.map +0 -1
  33. package/dist/core/index.d.ts.map +0 -1
  34. package/dist/core/store.d.ts.map +0 -1
  35. package/dist/core/timer.d.ts.map +0 -1
  36. package/dist/core/toast-api.d.ts.map +0 -1
  37. package/dist/core-CqZy4LyN.cjs +0 -893
  38. package/dist/core-CqZy4LyN.cjs.map +0 -1
  39. package/dist/core-KMoYj72S.js +0 -804
  40. package/dist/core-KMoYj72S.js.map +0 -1
  41. package/dist/hooks/use-mounted.d.ts.map +0 -1
  42. package/dist/hooks/use-swipe.d.ts.map +0 -1
  43. package/dist/hooks/use-system-theme.d.ts.map +0 -1
  44. package/dist/hooks/use-toasts.d.ts.map +0 -1
  45. package/dist/index.cjs.map +0 -1
  46. package/dist/index.d.ts.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/types/index.d.ts.map +0 -1
  49. package/dist/utils/dom.d.ts.map +0 -1
  50. package/dist/utils/feedback.d.ts.map +0 -1
  51. package/dist/utils/id.d.ts.map +0 -1
  52. package/dist/utils/merge.d.ts.map +0 -1
@@ -1,893 +0,0 @@
1
- // src/animations/index.ts
2
- var SWIPE_VELOCITY_THRESHOLD = .45;
3
- var SWIPE_DRAG_DAMPENING = .35;
4
- function getDefaultSwipeDirections(position) {
5
- if (position === "top-center") return ["up"];
6
- if (position === "bottom-center") return ["down"];
7
- if (position.endsWith("left")) return ["left"];
8
- return ["right"];
9
- }
10
- // src/utils/id.ts
11
- var sequence = 0;
12
- function generateToastId(prefix = "vt") {
13
- sequence += 1;
14
- const randomPart = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.randomUUID === "function" ? globalThis.crypto.randomUUID().slice(0, 8) : Math.random().toString(36).slice(2, 10);
15
- return `${prefix}-${sequence}-${randomPart}`;
16
- }
17
- // src/utils/merge.ts
18
- function cx(...values) {
19
- let result = "";
20
- for (const value of values) if (value) result = result ? `${result} ${value}` : value;
21
- return result;
22
- }
23
- function isFiniteDuration(duration) {
24
- return Number.isFinite(duration) && duration > 0;
25
- }
26
- function mergeClassNames(...maps) {
27
- let merged;
28
- for (const map of maps) {
29
- if (!map) continue;
30
- if (!merged) {
31
- merged = { ...map };
32
- continue;
33
- }
34
- for (const key of Object.keys(map)) {
35
- const value = map[key];
36
- if (value) merged[key] = cx(merged[key], value);
37
- }
38
- }
39
- return merged;
40
- }
41
- function resolveIconAnimationMode(value) {
42
- if (value === false || value === "none") return "none";
43
- if (value === "subtle") return "subtle";
44
- return "default";
45
- }
46
- function toPx(value) {
47
- if (value === void 0) return;
48
- return typeof value === "number" ? `${value}px` : value;
49
- }
50
- function tokensToCssVars(tokens) {
51
- if (!tokens) return {};
52
- const vars = {};
53
- const setVar = (name, val) => {
54
- if (val !== void 0) vars[name] = val;
55
- };
56
- setVar("--vt-font-family", tokens.fontFamily);
57
- setVar("--vt-width", toPx(tokens.width));
58
- setVar("--vt-radius", toPx(tokens.radius));
59
- setVar("--vt-blur", toPx(tokens.blur));
60
- setVar("--vt-saturate", tokens.saturate);
61
- setVar("--vt-bg", tokens.bg);
62
- setVar("--vt-bg-solid", tokens.bgSolid);
63
- setVar("--vt-border", tokens.border);
64
- setVar("--vt-text", tokens.text);
65
- setVar("--vt-text-muted", tokens.textMuted);
66
- setVar("--vt-shadow", tokens.shadow);
67
- setVar("--vt-success", tokens.success);
68
- setVar("--vt-error", tokens.error);
69
- setVar("--vt-warning", tokens.warning);
70
- setVar("--vt-info", tokens.info);
71
- setVar("--vt-loading", tokens.loading);
72
- setVar("--vt-default", tokens.default);
73
- setVar("--vt-z-index-root", tokens.zIndex);
74
- return vars;
75
- }
76
- // src/core/timer.ts
77
- var defaultClock = { now: () => Date.now() };
78
- var PauseableTimer = class {
79
- onComplete;
80
- clock;
81
- timerId = null;
82
- duration;
83
- remaining;
84
- startedAt = null;
85
- paused = false;
86
- completed = false;
87
- constructor(duration, onComplete, clock = defaultClock) {
88
- this.duration = duration;
89
- this.remaining = duration;
90
- this.onComplete = onComplete;
91
- this.clock = clock;
92
- }
93
- start() {
94
- if (this.completed || !Number.isFinite(this.remaining) || this.remaining <= 0) return;
95
- this.clearHandle();
96
- this.paused = false;
97
- this.startedAt = this.clock.now();
98
- this.timerId = setTimeout(() => {
99
- this.timerId = null;
100
- this.startedAt = null;
101
- this.remaining = 0;
102
- this.completed = true;
103
- this.onComplete();
104
- }, this.remaining);
105
- }
106
- pause() {
107
- if (this.paused || this.completed) return this.remaining;
108
- this.clearHandle();
109
- if (this.startedAt !== null) {
110
- const elapsed = Math.max(0, this.clock.now() - this.startedAt);
111
- this.remaining = Math.max(0, this.remaining - elapsed);
112
- this.startedAt = null;
113
- }
114
- this.paused = true;
115
- return this.remaining;
116
- }
117
- resume() {
118
- if (!this.paused || this.completed) return;
119
- if (this.remaining <= 0) {
120
- this.completed = true;
121
- this.paused = false;
122
- this.onComplete();
123
- return;
124
- }
125
- this.start();
126
- }
127
- reset(newDuration, autoStart = true) {
128
- this.clearHandle();
129
- this.duration = newDuration;
130
- this.remaining = newDuration;
131
- this.startedAt = null;
132
- this.paused = false;
133
- this.completed = false;
134
- if (autoStart && Number.isFinite(newDuration) && newDuration > 0) this.start();
135
- }
136
- getRemaining() {
137
- if (this.completed) return 0;
138
- if (!this.paused && this.startedAt !== null) {
139
- const elapsed = Math.max(0, this.clock.now() - this.startedAt);
140
- return Math.max(0, this.remaining - elapsed);
141
- }
142
- return this.remaining;
143
- }
144
- getDuration() {
145
- return this.duration;
146
- }
147
- isPaused() {
148
- return this.paused;
149
- }
150
- isRunning() {
151
- return this.timerId !== null;
152
- }
153
- clear() {
154
- this.clearHandle();
155
- this.startedAt = null;
156
- this.completed = true;
157
- }
158
- clearHandle() {
159
- if (this.timerId !== null) {
160
- clearTimeout(this.timerId);
161
- this.timerId = null;
162
- }
163
- }
164
- };
165
- // src/core/store.ts
166
- var DEFAULT_CONFIG = {
167
- defaultDuration: 4e3,
168
- visibleToasts: 4,
169
- exitDuration: 240,
170
- preventDuplicates: false,
171
- toastOptions: void 0
172
- };
173
- var EMPTY_SNAPSHOT = Object.freeze({
174
- toasts: Object.freeze([]),
175
- queue: Object.freeze([])
176
- });
177
- function resolveRole(variant, explicit) {
178
- if (explicit) return explicit;
179
- return variant === "error" || variant === "warning" ? "alert" : "status";
180
- }
181
- function resolveDuration(variant, explicitDuration, defaultDuration) {
182
- if (explicitDuration !== void 0) return explicitDuration <= 0 ? Number.POSITIVE_INFINITY : explicitDuration;
183
- if (variant === "loading") return Number.POSITIVE_INFINITY;
184
- return defaultDuration <= 0 ? Number.POSITIVE_INFINITY : defaultDuration;
185
- }
186
- function computeDedupeKey(variant, title, description, explicitKey) {
187
- if (explicitKey) return explicitKey;
188
- const titleStr = typeof title === "string" || typeof title === "number" ? String(title) : "";
189
- const descStr = typeof description === "string" || typeof description === "number" ? String(description) : "";
190
- if (!titleStr && !descStr) return;
191
- return `${variant}::${titleStr}::${descStr}`;
192
- }
193
- function resolveVariantDefaults(defaults, variant) {
194
- if (!defaults) return {};
195
- const { default: defaultPreset, success, error, warning, info, loading, custom, ...baseDefaults } = defaults;
196
- const specific = {
197
- default: defaultPreset,
198
- success,
199
- error,
200
- warning,
201
- info,
202
- loading,
203
- custom
204
- }[variant];
205
- if (!specific) return baseDefaults;
206
- return {
207
- ...baseDefaults,
208
- ...specific,
209
- className: cx(baseDefaults.className, specific.className) || void 0,
210
- classNames: mergeClassNames(baseDefaults.classNames, specific.classNames),
211
- style: baseDefaults.style || specific.style ? {
212
- ...baseDefaults.style,
213
- ...specific.style
214
- } : void 0
215
- };
216
- }
217
- var ToastStore = class {
218
- toasts = [];
219
- queue = [];
220
- snapshot = EMPTY_SNAPSHOT;
221
- config;
222
- listeners = /* @__PURE__ */ new Set();
223
- autoCloseTimers = /* @__PURE__ */ new Map();
224
- exitTimers = /* @__PURE__ */ new Map();
225
- clock;
226
- constructor(initialConfig, clock = { now: () => Date.now() }) {
227
- this.config = {
228
- ...DEFAULT_CONFIG,
229
- ...initialConfig
230
- };
231
- this.clock = clock;
232
- }
233
- configure(next) {
234
- const prevVisible = this.config.visibleToasts;
235
- this.config = {
236
- ...this.config,
237
- ...next
238
- };
239
- if (this.config.visibleToasts > prevVisible && this.queue.length > 0) this.promoteFromQueue();
240
- }
241
- getConfig() {
242
- return this.config;
243
- }
244
- subscribe = (listener) => {
245
- this.listeners.add(listener);
246
- return () => {
247
- this.listeners.delete(listener);
248
- };
249
- };
250
- getSnapshot = () => {
251
- return this.snapshot;
252
- };
253
- getServerSnapshot = () => {
254
- return EMPTY_SNAPSHOT;
255
- };
256
- add(rawOptions) {
257
- const now = this.clock.now();
258
- const variant = rawOptions.variant ?? (rawOptions.customRender ? "custom" : "default");
259
- const preset = resolveVariantDefaults(this.config.toastOptions, variant);
260
- const options = {
261
- ...preset,
262
- ...rawOptions,
263
- variant,
264
- className: cx(preset.className, rawOptions.className) || void 0,
265
- classNames: mergeClassNames(preset.classNames, rawOptions.classNames),
266
- style: preset.style || rawOptions.style ? {
267
- ...preset.style,
268
- ...rawOptions.style
269
- } : void 0
270
- };
271
- if (options.id) {
272
- if (this.findActive(options.id)) {
273
- this.update(options.id, options);
274
- return options.id;
275
- }
276
- }
277
- const shouldDedupe = options.dedupe ?? (options.dedupeKey !== void 0 ? true : this.config.preventDuplicates);
278
- const dedupeKey = computeDedupeKey(variant, options.title, options.description, options.dedupeKey);
279
- if (shouldDedupe && dedupeKey) {
280
- const duplicate = this.findByDedupeKey(dedupeKey);
281
- if (duplicate) {
282
- this.bumpDuplicate(duplicate.id, now, options);
283
- return duplicate.id;
284
- }
285
- }
286
- const id = options.id ?? generateToastId();
287
- const duration = resolveDuration(variant, options.duration, this.config.defaultDuration);
288
- const finite = isFiniteDuration(duration);
289
- const showProgress = options.showProgress ?? (finite && variant !== "loading");
290
- const record = {
291
- id,
292
- variant,
293
- title: options.title,
294
- description: options.description,
295
- position: options.position,
296
- duration,
297
- remainingTime: duration,
298
- startedAt: null,
299
- paused: false,
300
- pauseReasons: /* @__PURE__ */ new Set(),
301
- status: "visible",
302
- createdAt: now,
303
- updatedAt: now,
304
- dismissible: options.dismissible ?? true,
305
- showProgress,
306
- progressPosition: options.progressPosition,
307
- progressHeight: options.progressHeight,
308
- pauseOnHover: options.pauseOnHover ?? true,
309
- pauseOnFocus: options.pauseOnFocus ?? true,
310
- swipeToDismiss: options.swipeToDismiss ?? true,
311
- swipeDirections: options.swipeDirections,
312
- icon: options.icon,
313
- iconAnimation: options.iconAnimation,
314
- glass: options.glass,
315
- radius: options.radius,
316
- size: options.size,
317
- animation: options.animation,
318
- ambientGlow: options.ambientGlow,
319
- closeButton: options.closeButton,
320
- closeButtonPosition: options.closeButtonPosition,
321
- showCloseOnHover: options.showCloseOnHover,
322
- sound: options.sound,
323
- haptic: options.haptic,
324
- action: options.action,
325
- cancel: options.cancel,
326
- className: options.className,
327
- classNames: options.classNames,
328
- style: options.style,
329
- ariaLabel: options.ariaLabel,
330
- role: resolveRole(variant, options.role),
331
- dedupeKey,
332
- count: 1,
333
- onDismiss: options.onDismiss,
334
- onAutoClose: options.onAutoClose,
335
- customRender: options.customRender
336
- };
337
- if (this.countActiveVisible() < Math.max(1, this.config.visibleToasts)) {
338
- const startedRecord = finite ? {
339
- ...record,
340
- startedAt: now
341
- } : record;
342
- this.toasts = [...this.toasts, startedRecord];
343
- if (finite) this.startAutoCloseTimer(startedRecord.id, duration);
344
- } else this.queue = [...this.queue, record];
345
- this.commit();
346
- return id;
347
- }
348
- update(id, patch) {
349
- const now = this.clock.now();
350
- const visibleIndex = this.toasts.findIndex((t) => t.id === id);
351
- if (visibleIndex !== -1) {
352
- const current = this.toasts[visibleIndex];
353
- if (!current || current.status === "exiting") return false;
354
- const next = this.applyPatch(current, patch, now, true);
355
- const updatedList = [...this.toasts];
356
- updatedList[visibleIndex] = next;
357
- this.toasts = updatedList;
358
- this.syncTimerAfterUpdate(current, next, patch);
359
- this.commit();
360
- return true;
361
- }
362
- const queueIndex = this.queue.findIndex((t) => t.id === id);
363
- if (queueIndex !== -1) {
364
- const current = this.queue[queueIndex];
365
- if (!current) return false;
366
- const next = this.applyPatch(current, patch, now, false);
367
- const updatedQueue = [...this.queue];
368
- updatedQueue[queueIndex] = next;
369
- this.queue = updatedQueue;
370
- this.commit();
371
- return true;
372
- }
373
- return false;
374
- }
375
- dismiss(id, reason = "user") {
376
- const queueIndex = this.queue.findIndex((t) => t.id === id);
377
- if (queueIndex !== -1) {
378
- const target = this.queue[queueIndex];
379
- this.queue = this.queue.filter((t) => t.id !== id);
380
- this.commit();
381
- if (target) target.onDismiss?.(target);
382
- return true;
383
- }
384
- const visibleIndex = this.toasts.findIndex((t) => t.id === id);
385
- if (visibleIndex === -1) return false;
386
- const target = this.toasts[visibleIndex];
387
- if (!target || target.status === "exiting") return false;
388
- this.clearAutoCloseTimer(id);
389
- const exitingRecord = {
390
- ...target,
391
- status: "exiting",
392
- updatedAt: this.clock.now()
393
- };
394
- if (this.config.exitDuration <= 0) {
395
- this.toasts = this.toasts.filter((t) => t.id !== id);
396
- this.promoteFromQueueInternal();
397
- this.commit();
398
- } else {
399
- const updated = [...this.toasts];
400
- updated[visibleIndex] = exitingRecord;
401
- this.toasts = updated;
402
- this.scheduleExitRemoval(id);
403
- this.commit();
404
- }
405
- if (reason === "auto") exitingRecord.onAutoClose?.(exitingRecord);
406
- exitingRecord.onDismiss?.(exitingRecord);
407
- return true;
408
- }
409
- dismissAll() {
410
- const queued = [...this.queue];
411
- this.queue = [];
412
- for (const q of queued) q.onDismiss?.(q);
413
- const active = this.toasts.filter((t) => t.status !== "exiting");
414
- if (active.length === 0 && queued.length === 0) return;
415
- for (const item of active) this.clearAutoCloseTimer(item.id);
416
- if (this.config.exitDuration <= 0) {
417
- this.toasts = [];
418
- this.commit();
419
- } else {
420
- const now = this.clock.now();
421
- this.toasts = this.toasts.map((t) => {
422
- if (t.status === "exiting") return t;
423
- this.scheduleExitRemoval(t.id);
424
- return {
425
- ...t,
426
- status: "exiting",
427
- updatedAt: now
428
- };
429
- });
430
- this.commit();
431
- }
432
- for (const item of active) item.onDismiss?.(item);
433
- }
434
- pause(id, reason = "manual") {
435
- const index = this.toasts.findIndex((t) => t.id === id);
436
- if (index === -1) return;
437
- const current = this.toasts[index];
438
- if (!current || current.status === "exiting") return;
439
- if (reason === "hover" && !current.pauseOnHover) return;
440
- if (reason === "focus" && !current.pauseOnFocus) return;
441
- if (current.pauseReasons.has(reason)) return;
442
- const nextReasons = new Set(current.pauseReasons);
443
- nextReasons.add(reason);
444
- const timer = this.autoCloseTimers.get(id);
445
- const remainingTime = timer ? timer.pause() : current.remainingTime;
446
- const updated = [...this.toasts];
447
- updated[index] = {
448
- ...current,
449
- paused: true,
450
- pauseReasons: nextReasons,
451
- remainingTime,
452
- startedAt: null
453
- };
454
- this.toasts = updated;
455
- this.commit();
456
- }
457
- resume(id, reason = "manual") {
458
- const index = this.toasts.findIndex((t) => t.id === id);
459
- if (index === -1) return;
460
- const current = this.toasts[index];
461
- if (!current || current.status === "exiting" || !current.pauseReasons.has(reason)) return;
462
- const nextReasons = new Set(current.pauseReasons);
463
- nextReasons.delete(reason);
464
- const stillPaused = nextReasons.size > 0;
465
- const now = this.clock.now();
466
- const updated = [...this.toasts];
467
- updated[index] = {
468
- ...current,
469
- paused: stillPaused,
470
- pauseReasons: nextReasons,
471
- startedAt: !stillPaused && isFiniteDuration(current.duration) ? now : null
472
- };
473
- this.toasts = updated;
474
- this.commit();
475
- if (!stillPaused) this.autoCloseTimers.get(id)?.resume();
476
- }
477
- pauseAll(reason = "manual") {
478
- for (const item of this.toasts) if (item.status !== "exiting") this.pause(item.id, reason);
479
- }
480
- resumeAll(reason = "manual") {
481
- for (const item of this.toasts) if (item.status !== "exiting") this.resume(item.id, reason);
482
- }
483
- getRemainingTime(id) {
484
- const timer = this.autoCloseTimers.get(id);
485
- if (timer) return timer.getRemaining();
486
- const found = this.findActive(id);
487
- return found ? found.remainingTime : 0;
488
- }
489
- removeImmediately(id) {
490
- this.clearAutoCloseTimer(id);
491
- this.clearExitTimer(id);
492
- const prevLen = this.toasts.length;
493
- const prevQueueLen = this.queue.length;
494
- this.toasts = this.toasts.filter((t) => t.id !== id);
495
- this.queue = this.queue.filter((t) => t.id !== id);
496
- if (this.toasts.length !== prevLen) this.promoteFromQueueInternal();
497
- if (this.toasts.length !== prevLen || this.queue.length !== prevQueueLen) this.commit();
498
- }
499
- clear() {
500
- for (const timer of this.autoCloseTimers.values()) timer.clear();
501
- this.autoCloseTimers.clear();
502
- for (const handle of this.exitTimers.values()) clearTimeout(handle);
503
- this.exitTimers.clear();
504
- if (this.toasts.length > 0 || this.queue.length > 0) {
505
- this.toasts = [];
506
- this.queue = [];
507
- this.commit();
508
- }
509
- }
510
- destroy() {
511
- this.clear();
512
- this.listeners.clear();
513
- }
514
- applyPatch(current, patch, now, isVisible) {
515
- const nextVariant = patch.variant ?? current.variant;
516
- const wasLoading = current.variant === "loading";
517
- const leftLoading = wasLoading && nextVariant !== "loading";
518
- const variantPreset = leftLoading ? resolveVariantDefaults(this.config.toastOptions, nextVariant) : void 0;
519
- let nextDuration = current.duration;
520
- if (patch.duration !== void 0) nextDuration = patch.duration <= 0 ? Number.POSITIVE_INFINITY : patch.duration;
521
- else if (leftLoading) {
522
- const targetDefault = variantPreset?.duration ?? this.config.defaultDuration;
523
- nextDuration = targetDefault <= 0 ? Number.POSITIVE_INFINITY : targetDefault;
524
- } else if (nextVariant === "loading" && !wasLoading) nextDuration = Number.POSITIVE_INFINITY;
525
- const finite = isFiniteDuration(nextDuration);
526
- const durationChanged = nextDuration !== current.duration;
527
- const nextShowProgress = patch.showProgress ?? (durationChanged ? finite && nextVariant !== "loading" : current.showProgress);
528
- const nextDedupeKey = patch.dedupeKey ?? (patch.title !== void 0 || patch.description !== void 0 || patch.variant !== void 0 ? computeDedupeKey(nextVariant, patch.title !== void 0 ? patch.title : current.title, patch.description !== void 0 ? patch.description : current.description, current.dedupeKey) : current.dedupeKey);
529
- return {
530
- ...current,
531
- variant: nextVariant,
532
- title: patch.title !== void 0 ? patch.title : current.title,
533
- description: patch.description !== void 0 ? patch.description : current.description,
534
- position: patch.position !== void 0 ? patch.position : current.position,
535
- duration: nextDuration,
536
- remainingTime: durationChanged ? nextDuration : current.remainingTime,
537
- startedAt: isVisible && durationChanged && finite && !current.paused ? now : current.startedAt,
538
- updatedAt: now,
539
- dismissible: patch.dismissible ?? current.dismissible,
540
- showProgress: nextShowProgress,
541
- progressPosition: patch.progressPosition !== void 0 ? patch.progressPosition : current.progressPosition,
542
- progressHeight: patch.progressHeight !== void 0 ? patch.progressHeight : current.progressHeight,
543
- pauseOnHover: patch.pauseOnHover ?? current.pauseOnHover,
544
- pauseOnFocus: patch.pauseOnFocus ?? current.pauseOnFocus,
545
- swipeToDismiss: patch.swipeToDismiss ?? current.swipeToDismiss,
546
- swipeDirections: patch.swipeDirections !== void 0 ? patch.swipeDirections : current.swipeDirections,
547
- icon: patch.icon !== void 0 ? patch.icon : current.icon,
548
- iconAnimation: patch.iconAnimation !== void 0 ? patch.iconAnimation : current.iconAnimation,
549
- glass: patch.glass !== void 0 ? patch.glass : current.glass,
550
- radius: patch.radius !== void 0 ? patch.radius : current.radius,
551
- size: patch.size !== void 0 ? patch.size : current.size,
552
- animation: patch.animation !== void 0 ? patch.animation : current.animation,
553
- ambientGlow: patch.ambientGlow !== void 0 ? patch.ambientGlow : current.ambientGlow,
554
- closeButton: patch.closeButton !== void 0 ? patch.closeButton : current.closeButton,
555
- closeButtonPosition: patch.closeButtonPosition !== void 0 ? patch.closeButtonPosition : current.closeButtonPosition,
556
- showCloseOnHover: patch.showCloseOnHover !== void 0 ? patch.showCloseOnHover : current.showCloseOnHover,
557
- sound: patch.sound !== void 0 ? patch.sound : current.sound,
558
- haptic: patch.haptic !== void 0 ? patch.haptic : current.haptic,
559
- action: patch.action !== void 0 ? patch.action : current.action,
560
- cancel: patch.cancel !== void 0 ? patch.cancel : current.cancel,
561
- className: patch.className !== void 0 ? patch.className : current.className,
562
- classNames: patch.classNames !== void 0 ? mergeClassNames(current.classNames, patch.classNames) : current.classNames,
563
- style: patch.style !== void 0 ? patch.style : current.style,
564
- ariaLabel: patch.ariaLabel !== void 0 ? patch.ariaLabel : current.ariaLabel,
565
- role: resolveRole(nextVariant, patch.role ?? (patch.variant ? void 0 : current.role)),
566
- dedupeKey: nextDedupeKey,
567
- onDismiss: patch.onDismiss !== void 0 ? patch.onDismiss : current.onDismiss,
568
- onAutoClose: patch.onAutoClose !== void 0 ? patch.onAutoClose : current.onAutoClose,
569
- customRender: patch.customRender !== void 0 ? patch.customRender : current.customRender
570
- };
571
- }
572
- syncTimerAfterUpdate(prev, next, patch) {
573
- if (!(prev.duration !== next.duration || patch.duration !== void 0 || prev.variant === "loading" && next.variant !== "loading")) return;
574
- this.clearAutoCloseTimer(next.id);
575
- if (isFiniteDuration(next.duration)) this.startAutoCloseTimer(next.id, next.duration, !next.paused);
576
- }
577
- bumpDuplicate(id, now, options) {
578
- const visibleIndex = this.toasts.findIndex((t) => t.id === id);
579
- if (visibleIndex !== -1) {
580
- const current = this.toasts[visibleIndex];
581
- if (!current) return;
582
- const nextDuration = options.duration !== void 0 ? resolveDuration(current.variant, options.duration, this.config.defaultDuration) : current.duration;
583
- const finite = isFiniteDuration(nextDuration);
584
- const updatedRecord = {
585
- ...current,
586
- count: current.count + 1,
587
- duration: nextDuration,
588
- remainingTime: nextDuration,
589
- startedAt: finite && !current.paused ? now : null,
590
- updatedAt: now
591
- };
592
- const updated = [...this.toasts];
593
- updated[visibleIndex] = updatedRecord;
594
- this.toasts = updated;
595
- if (finite) {
596
- this.clearAutoCloseTimer(id);
597
- this.startAutoCloseTimer(id, nextDuration, !current.paused);
598
- }
599
- this.commit();
600
- return;
601
- }
602
- const queueIndex = this.queue.findIndex((t) => t.id === id);
603
- if (queueIndex !== -1) {
604
- const current = this.queue[queueIndex];
605
- if (!current) return;
606
- const updatedQueue = [...this.queue];
607
- updatedQueue[queueIndex] = {
608
- ...current,
609
- count: current.count + 1,
610
- updatedAt: now
611
- };
612
- this.queue = updatedQueue;
613
- this.commit();
614
- }
615
- }
616
- startAutoCloseTimer(id, duration, autoStart = true) {
617
- this.clearAutoCloseTimer(id);
618
- const timer = new PauseableTimer(duration, () => {
619
- this.autoCloseTimers.delete(id);
620
- this.dismiss(id, "auto");
621
- }, this.clock);
622
- this.autoCloseTimers.set(id, timer);
623
- if (autoStart) timer.start();
624
- }
625
- clearAutoCloseTimer(id) {
626
- const timer = this.autoCloseTimers.get(id);
627
- if (timer) {
628
- timer.clear();
629
- this.autoCloseTimers.delete(id);
630
- }
631
- }
632
- scheduleExitRemoval(id) {
633
- this.clearExitTimer(id);
634
- const handle = setTimeout(() => {
635
- this.exitTimers.delete(id);
636
- this.toasts = this.toasts.filter((t) => t.id !== id);
637
- this.promoteFromQueueInternal();
638
- this.commit();
639
- }, this.config.exitDuration);
640
- this.exitTimers.set(id, handle);
641
- }
642
- clearExitTimer(id) {
643
- const handle = this.exitTimers.get(id);
644
- if (handle !== void 0) {
645
- clearTimeout(handle);
646
- this.exitTimers.delete(id);
647
- }
648
- }
649
- promoteFromQueue() {
650
- if (this.promoteFromQueueInternal()) this.commit();
651
- }
652
- promoteFromQueueInternal() {
653
- const maxVisible = Math.max(1, this.config.visibleToasts);
654
- let promoted = false;
655
- while (this.countActiveVisible() < maxVisible && this.queue.length > 0) {
656
- const next = this.queue[0];
657
- if (!next) break;
658
- this.queue = this.queue.slice(1);
659
- const now = this.clock.now();
660
- const finite = isFiniteDuration(next.duration);
661
- const promotedRecord = {
662
- ...next,
663
- status: "visible",
664
- startedAt: finite ? now : null,
665
- remainingTime: next.duration,
666
- updatedAt: now
667
- };
668
- this.toasts = [...this.toasts, promotedRecord];
669
- if (finite) this.startAutoCloseTimer(promotedRecord.id, promotedRecord.duration);
670
- promoted = true;
671
- }
672
- return promoted;
673
- }
674
- countActiveVisible() {
675
- let count = 0;
676
- for (const item of this.toasts) if (item.status !== "exiting") count += 1;
677
- return count;
678
- }
679
- findActive(id) {
680
- const visible = this.toasts.find((t) => t.id === id && t.status !== "exiting");
681
- if (visible) return visible;
682
- return this.queue.find((t) => t.id === id);
683
- }
684
- findByDedupeKey(dedupeKey) {
685
- const visible = this.toasts.find((t) => t.dedupeKey === dedupeKey && t.status !== "exiting");
686
- if (visible) return visible;
687
- return this.queue.find((t) => t.dedupeKey === dedupeKey);
688
- }
689
- commit() {
690
- this.snapshot = Object.freeze({
691
- toasts: Object.freeze([...this.toasts]),
692
- queue: Object.freeze([...this.queue])
693
- });
694
- for (const listener of this.listeners) listener();
695
- }
696
- };
697
- function createToastStore(config, clock) {
698
- return new ToastStore(config, clock);
699
- }
700
- var defaultToastStore = createToastStore();
701
- // src/core/toast-api.ts
702
- function isPromiseDescriptor(value) {
703
- return typeof value === "object" && value !== null && "title" in value && !("$$typeof" in value);
704
- }
705
- function normalizeDescriptor(input) {
706
- if (isPromiseDescriptor(input)) return {
707
- title: input.title,
708
- description: input.description,
709
- duration: input.duration,
710
- icon: input.icon,
711
- action: input.action,
712
- cancel: input.cancel,
713
- showProgress: input.showProgress
714
- };
715
- return {
716
- title: input,
717
- description: void 0
718
- };
719
- }
720
- function createToastApi(store = defaultToastStore) {
721
- const base = ((title, options) => {
722
- return store.add({
723
- ...options,
724
- title
725
- });
726
- });
727
- base.success = (title, options) => store.add({
728
- ...options,
729
- title,
730
- variant: "success"
731
- });
732
- base.error = (title, options) => store.add({
733
- ...options,
734
- title,
735
- variant: "error"
736
- });
737
- base.warning = (title, options) => store.add({
738
- ...options,
739
- title,
740
- variant: "warning"
741
- });
742
- base.info = (title, options) => store.add({
743
- ...options,
744
- title,
745
- variant: "info"
746
- });
747
- base.loading = (title, options) => store.add({
748
- ...options,
749
- title,
750
- variant: "loading"
751
- });
752
- base.custom = (render, options) => store.add({
753
- ...options,
754
- variant: "custom",
755
- customRender: render
756
- });
757
- base.update = (id, options) => store.update(id, options);
758
- base.dismiss = (id) => store.dismiss(id, "user");
759
- base.dismissAll = () => store.dismissAll();
760
- base.promise = (promiseOrFactory, messages, options) => {
761
- const loadingOpts = normalizeDescriptor(messages.loading);
762
- const id = store.add({
763
- ...options,
764
- ...loadingOpts,
765
- variant: "loading",
766
- duration: Number.POSITIVE_INFINITY,
767
- showProgress: false
768
- });
769
- let targetPromise;
770
- try {
771
- targetPromise = typeof promiseOrFactory === "function" ? promiseOrFactory() : promiseOrFactory;
772
- } catch (syncError) {
773
- targetPromise = Promise.reject(syncError);
774
- }
775
- targetPromise.then((data) => {
776
- const successOpts = normalizeDescriptor(typeof messages.success === "function" ? messages.success(data) : messages.success);
777
- store.update(id, {
778
- ...successOpts,
779
- variant: "success",
780
- duration: successOpts.duration ?? options?.duration,
781
- showProgress: successOpts.showProgress ?? options?.showProgress
782
- });
783
- }, (err) => {
784
- const errorOpts = normalizeDescriptor(typeof messages.error === "function" ? messages.error(err) : messages.error);
785
- store.update(id, {
786
- ...errorOpts,
787
- variant: "error",
788
- duration: errorOpts.duration ?? options?.duration,
789
- showProgress: errorOpts.showProgress ?? options?.showProgress
790
- });
791
- }).finally(() => {
792
- messages.finally?.();
793
- });
794
- return {
795
- id,
796
- unwrap: () => targetPromise
797
- };
798
- };
799
- return base;
800
- }
801
- var toast = createToastApi(defaultToastStore);
802
- Object.defineProperty(exports, "EMPTY_SNAPSHOT", {
803
- enumerable: true,
804
- get: function() {
805
- return EMPTY_SNAPSHOT;
806
- }
807
- });
808
- Object.defineProperty(exports, "PauseableTimer", {
809
- enumerable: true,
810
- get: function() {
811
- return PauseableTimer;
812
- }
813
- });
814
- Object.defineProperty(exports, "SWIPE_DRAG_DAMPENING", {
815
- enumerable: true,
816
- get: function() {
817
- return SWIPE_DRAG_DAMPENING;
818
- }
819
- });
820
- Object.defineProperty(exports, "SWIPE_VELOCITY_THRESHOLD", {
821
- enumerable: true,
822
- get: function() {
823
- return SWIPE_VELOCITY_THRESHOLD;
824
- }
825
- });
826
- Object.defineProperty(exports, "ToastStore", {
827
- enumerable: true,
828
- get: function() {
829
- return ToastStore;
830
- }
831
- });
832
- Object.defineProperty(exports, "createToastApi", {
833
- enumerable: true,
834
- get: function() {
835
- return createToastApi;
836
- }
837
- });
838
- Object.defineProperty(exports, "createToastStore", {
839
- enumerable: true,
840
- get: function() {
841
- return createToastStore;
842
- }
843
- });
844
- Object.defineProperty(exports, "cx", {
845
- enumerable: true,
846
- get: function() {
847
- return cx;
848
- }
849
- });
850
- Object.defineProperty(exports, "defaultToastStore", {
851
- enumerable: true,
852
- get: function() {
853
- return defaultToastStore;
854
- }
855
- });
856
- Object.defineProperty(exports, "getDefaultSwipeDirections", {
857
- enumerable: true,
858
- get: function() {
859
- return getDefaultSwipeDirections;
860
- }
861
- });
862
- Object.defineProperty(exports, "isFiniteDuration", {
863
- enumerable: true,
864
- get: function() {
865
- return isFiniteDuration;
866
- }
867
- });
868
- Object.defineProperty(exports, "mergeClassNames", {
869
- enumerable: true,
870
- get: function() {
871
- return mergeClassNames;
872
- }
873
- });
874
- Object.defineProperty(exports, "resolveIconAnimationMode", {
875
- enumerable: true,
876
- get: function() {
877
- return resolveIconAnimationMode;
878
- }
879
- });
880
- Object.defineProperty(exports, "toast", {
881
- enumerable: true,
882
- get: function() {
883
- return toast;
884
- }
885
- });
886
- Object.defineProperty(exports, "tokensToCssVars", {
887
- enumerable: true,
888
- get: function() {
889
- return tokensToCssVars;
890
- }
891
- });
892
-
893
- //# sourceMappingURL=core-CqZy4LyN.cjs.map