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
@@ -4,4 +4,3 @@ export declare const SWIPE_DISMISS_THRESHOLD_PX = 84;
4
4
  export declare const SWIPE_VELOCITY_THRESHOLD = 0.45;
5
5
  export declare const SWIPE_DRAG_DAMPENING = 0.35;
6
6
  export declare function getDefaultSwipeDirections(position: ToastPosition): readonly SwipeDirection[];
7
- //# sourceMappingURL=index.d.ts.map
@@ -7,4 +7,3 @@ export interface ToastIconProps {
7
7
  className?: string;
8
8
  }
9
9
  export declare function ToastIcon({ variant, icon, animationMode, className, }: ToastIconProps): ReactNode;
10
- //# sourceMappingURL=ToastIcon.d.ts.map
@@ -1,6 +1,28 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { ToastStore } from "../core/store.js";
3
3
  import type { SwipeDirection, ToastAnimationPreset, ToastClassNames, ToastCloseButtonPosition, ToastGlassPreset, ToastIconAnimation, ToastIcons, ToastPosition, ToastProgressPosition, ToastRadiusPreset, ToastRecord, ToastSize } from "../types/index.js";
4
+ export interface ToastItemDefaults {
5
+ glass: ToastGlassPreset;
6
+ radius: ToastRadiusPreset;
7
+ size: ToastSize;
8
+ ambientGlow: boolean;
9
+ animation: ToastAnimationPreset;
10
+ iconAnimation: ToastIconAnimation;
11
+ closeButton: boolean;
12
+ closeButtonPosition: ToastCloseButtonPosition;
13
+ showCloseOnHover: boolean;
14
+ showProgress: boolean;
15
+ progressPosition: ToastProgressPosition;
16
+ progressHeight: number;
17
+ pauseOnHover: boolean;
18
+ pauseOnFocus: boolean;
19
+ swipeToDismiss: boolean;
20
+ swipeDirections?: readonly SwipeDirection[];
21
+ richColors: boolean;
22
+ icons?: ToastIcons;
23
+ classNames?: ToastClassNames;
24
+ toastClassName?: string;
25
+ }
4
26
  export interface ToastItemProps {
5
27
  toast: ToastRecord;
6
28
  index: number;
@@ -8,26 +30,6 @@ export interface ToastItemProps {
8
30
  position: ToastPosition;
9
31
  expanded: boolean;
10
32
  store: ToastStore;
11
- glassDefault: ToastGlassPreset;
12
- radiusDefault: ToastRadiusPreset;
13
- sizeDefault: ToastSize;
14
- ambientGlowDefault: boolean;
15
- animationDefault: ToastAnimationPreset;
16
- iconAnimationDefault: ToastIconAnimation;
17
- showCloseButton: boolean;
18
- closeButtonPositionDefault: ToastCloseButtonPosition;
19
- showCloseOnHoverDefault: boolean;
20
- showProgressDefault: boolean;
21
- progressPositionDefault: ToastProgressPosition;
22
- progressHeightDefault: number;
23
- pauseOnHoverDefault: boolean;
24
- pauseOnFocusDefault: boolean;
25
- swipeToDismissDefault: boolean;
26
- swipeDirectionsDefault?: readonly SwipeDirection[];
27
- richColors: boolean;
28
- icons?: ToastIcons;
29
- classNames?: ToastClassNames;
30
- toastClassName?: string;
33
+ cfg: ToastItemDefaults;
31
34
  }
32
- export declare const ToastItem: import("react").MemoExoticComponent<({ toast, index, total, position, expanded, store, glassDefault, radiusDefault, sizeDefault, ambientGlowDefault, animationDefault, iconAnimationDefault, showCloseButton, closeButtonPositionDefault, showCloseOnHoverDefault, showProgressDefault, progressPositionDefault, progressHeightDefault, pauseOnHoverDefault, pauseOnFocusDefault, swipeToDismissDefault, swipeDirectionsDefault, richColors, icons, classNames, toastClassName, }: ToastItemProps) => ReactNode>;
33
- //# sourceMappingURL=ToastItem.d.ts.map
35
+ export declare const ToastItem: import("react").MemoExoticComponent<({ toast, index, total, position, expanded, store, cfg, }: ToastItemProps) => ReactNode>;
@@ -11,4 +11,3 @@ export interface ToastProgressProps {
11
11
  barClassName?: string;
12
12
  }
13
13
  export declare function ToastProgress({ duration, paused, variant, resetKey, position, height, trackClassName, barClassName, }: ToastProgressProps): ReactNode;
14
- //# sourceMappingURL=ToastProgress.d.ts.map
@@ -6,4 +6,3 @@ export interface InternalToasterProps extends ToasterProps {
6
6
  store?: ToastStore;
7
7
  }
8
8
  export declare function Toaster({ position, theme, duration, visibleToasts, gap, offset, expand, glass, radius, size, ambientGlow, themeTokens, animation, iconAnimation, progressPosition, progressHeight, pauseOnHover, pauseOnFocus, swipeToDismiss, swipeDirections, showProgress, closeButton, closeButtonPosition, showCloseOnHover, preventDuplicates, richColors, icons, classNames, hotkey, sound, haptic, onToastShow, toastOptions, dir, className, toastClassName, style, containerAriaLabel, portalContainer, exitDuration, store, }: InternalToasterProps): ReactNode;
9
- //# sourceMappingURL=Toaster.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export { createToastStore, defaultToastStore, EMPTY_SNAPSHOT, type StoreListener, ToastStore, } from "./store.js";
2
2
  export { type Clock, PauseableTimer } from "./timer.js";
3
3
  export { createToastApi, type ToastApi, toast } from "./toast-api.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -3,14 +3,7 @@ import { type Clock } from "./timer.js";
3
3
  export type StoreListener = () => void;
4
4
  export declare const EMPTY_SNAPSHOT: ToastStoreSnapshot;
5
5
  export declare class ToastStore {
6
- private toasts;
7
- private queue;
8
- private snapshot;
9
- private config;
10
- private readonly listeners;
11
- private readonly autoCloseTimers;
12
- private readonly exitTimers;
13
- private readonly clock;
6
+ #private;
14
7
  constructor(initialConfig?: Partial<ToastStoreConfig>, clock?: Clock);
15
8
  configure(next: Partial<ToastStoreConfig>): void;
16
9
  getConfig(): Readonly<ToastStoreConfig>;
@@ -29,20 +22,6 @@ export declare class ToastStore {
29
22
  removeImmediately(id: string): void;
30
23
  clear(): void;
31
24
  destroy(): void;
32
- private applyPatch;
33
- private syncTimerAfterUpdate;
34
- private bumpDuplicate;
35
- private startAutoCloseTimer;
36
- private clearAutoCloseTimer;
37
- private scheduleExitRemoval;
38
- private clearExitTimer;
39
- private promoteFromQueue;
40
- private promoteFromQueueInternal;
41
- private countActiveVisible;
42
- private findActive;
43
- private findByDedupeKey;
44
- private commit;
45
25
  }
46
- export declare function createToastStore(config?: Partial<ToastStoreConfig>, clock?: Clock): ToastStore;
26
+ export declare function createToastStore(initialConfig?: Partial<ToastStoreConfig>, clock?: Clock): ToastStore;
47
27
  export declare const defaultToastStore: ToastStore;
48
- //# sourceMappingURL=store.d.ts.map
@@ -22,4 +22,3 @@ export declare class PauseableTimer {
22
22
  clear(): void;
23
23
  private clearHandle;
24
24
  }
25
- //# sourceMappingURL=timer.d.ts.map
@@ -16,4 +16,3 @@ export interface ToastApi {
16
16
  }
17
17
  export declare function createToastApi(store?: ToastStore): ToastApi;
18
18
  export declare const toast: ToastApi;
19
- //# sourceMappingURL=toast-api.d.ts.map
@@ -0,0 +1 @@
1
+ var e=.45,t=.35;function n(e){return e===`top-center`?[`up`]:e===`bottom-center`?[`down`]:e.endsWith(`left`)?[`left`]:[`right`]}var r=0;function i(e=`vt`){r+=1;let t=globalThis.crypto!==void 0&&typeof globalThis.crypto.randomUUID==`function`?globalThis.crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10);return`${e}-${r}-${t}`}function a(...e){return e.filter(Boolean).join(` `)}function o(e){return Number.isFinite(e)&&e>0}function s(...e){let t;for(let n of e)if(n){if(!t)t={...n};else for(let e of Object.keys(n)){let r=n[e];r&&(t[e]=a(t[e],r))}}return t}function c(e){return e===!1||e===`none`?`none`:e===`subtle`?`subtle`:`default`}var l=[[`fontFamily`,`font-family`],[`width`,`width`,1],[`radius`,`radius`,1],[`blur`,`blur`,1],[`saturate`,`saturate`],[`bg`,`bg`],[`bgSolid`,`bg-solid`],[`border`,`border`],[`text`,`text`],[`textMuted`,`text-muted`],[`shadow`,`shadow`],[`success`,`success`],[`error`,`error`],[`warning`,`warning`],[`info`,`info`],[`loading`,`loading`],[`default`,`default`],[`zIndex`,`z-index-root`]];function u(e){if(!e)return{};let t={};for(let[n,r,i]of l){let a=e[n];a!==void 0&&(t[`--vt-${r}`]=i&&typeof a==`number`?`${a}px`:a)}return t}var d={now:()=>Date.now()},f=class{onComplete;clock;timerId=null;duration;remaining;startedAt=null;paused=!1;completed=!1;constructor(e,t,n=d){this.duration=e,this.remaining=e,this.onComplete=t,this.clock=n}start(){this.completed||!Number.isFinite(this.remaining)||this.remaining<=0||(this.clearHandle(),this.paused=!1,this.startedAt=this.clock.now(),this.timerId=setTimeout(()=>{this.timerId=null,this.startedAt=null,this.remaining=0,this.completed=!0,this.onComplete()},this.remaining))}pause(){if(this.paused||this.completed)return this.remaining;if(this.clearHandle(),this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);this.remaining=Math.max(0,this.remaining-e),this.startedAt=null}return this.paused=!0,this.remaining}resume(){this.paused&&!this.completed&&(this.remaining<=0?(this.completed=!0,this.paused=!1,this.onComplete()):this.start())}reset(e,t=!0){this.clearHandle(),this.duration=e,this.remaining=e,this.startedAt=null,this.paused=!1,this.completed=!1,t&&Number.isFinite(e)&&e>0&&this.start()}getRemaining(){if(this.completed)return 0;if(!this.paused&&this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);return Math.max(0,this.remaining-e)}return this.remaining}getDuration(){return this.duration}isPaused(){return this.paused}isRunning(){return this.timerId!==null}clear(){this.clearHandle(),this.startedAt=null,this.completed=!0}clearHandle(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}},p={defaultDuration:4e3,visibleToasts:4,exitDuration:240,preventDuplicates:!1,toastOptions:void 0},m=/* @__PURE__ */ new Set([`default`,`success`,`error`,`warning`,`info`,`loading`,`custom`]),h=Object.freeze({toasts:Object.freeze([]),queue:Object.freeze([])});function g(e,t){return t??(e===`error`||e===`warning`?`alert`:`status`)}function _(e,t,n){let r=t===void 0?e===`loading`?0:n:t;return r<=0?1/0:r}function v(e,t,n,r){if(r)return r;let i=typeof t==`string`||typeof t==`number`?String(t):``,a=typeof n==`string`||typeof n==`number`?String(n):``;return i||a?`${e}::${i}::${a}`:void 0}function y(e,t){if(!e)return{};let n={};for(let[t,r]of Object.entries(e))m.has(t)||(n[t]=r);let r=n,i=e[t];return i?{...r,...i,className:a(r.className,i.className)||void 0,classNames:s(r.classNames,i.classNames),style:r.style||i.style?{...r.style,...i.style}:void 0}:r}function b(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function x(e,t,n){let r=[...e];return r[t]=n,r}var S=class{#e=[];#t=[];#n=h;#r;#i=/* @__PURE__ */ new Set;#a=/* @__PURE__ */ new Map;#o=/* @__PURE__ */ new Map;#s;constructor(e,t={now:()=>Date.now()}){this.#r={...p,...e},this.#s=t}configure(e){let t=this.#r.visibleToasts;this.#r={...this.#r,...e},this.#r.visibleToasts>t&&this.#t.length>0&&this.#m()&&this.#_()}getConfig(){return this.#r}subscribe=e=>(this.#i.add(e),()=>{this.#i.delete(e)});getSnapshot=()=>this.#n;getServerSnapshot=()=>h;add(e){let t=this.#s.now(),n=e.variant??(e.customRender?`custom`:`default`),r=y(this.#r.toastOptions,n),c={...r,...e,variant:n,className:a(r.className,e.className)||void 0,classNames:s(r.classNames,e.classNames),style:r.style||e.style?{...r.style,...e.style}:void 0};if(c.id&&this.#g(c.id))return this.update(c.id,c),c.id;let l=c.dedupe??(c.dedupeKey!==void 0||this.#r.preventDuplicates),u=v(n,c.title,c.description,c.dedupeKey);if(l&&u){let e=this.#e.find(e=>e.dedupeKey===u&&e.status!==`exiting`)??this.#t.find(e=>e.dedupeKey===u);if(e)return this.#l(e.id,t,c),e.id}let d=c.id??i(),f=_(n,c.duration,this.#r.defaultDuration),p=o(f),m={...c,id:d,variant:n,duration:f,remainingTime:f,startedAt:null,paused:!1,pauseReasons:/* @__PURE__ */ new Set,status:`visible`,createdAt:t,updatedAt:t,dismissible:c.dismissible??!0,showProgress:c.showProgress??(p&&n!==`loading`),pauseOnHover:c.pauseOnHover??!0,pauseOnFocus:c.pauseOnFocus??!0,swipeToDismiss:c.swipeToDismiss??!0,role:g(n,c.role),dedupeKey:u,count:1};if(this.#h()<Math.max(1,this.#r.visibleToasts)){let e=p?{...m,startedAt:t}:m;this.#e=[...this.#e,e],p&&this.#u(e.id,f)}else this.#t=[...this.#t,m];return this.#_(),d}update(e,t){let n=this.#s.now(),r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let e=this.#e[r];if(!e||e.status===`exiting`)return!1;let i=this.#c(e,t,n,!0);return this.#e=x(this.#e,r,i),(e.duration!==i.duration||t.duration!==void 0||e.variant===`loading`&&i.variant!==`loading`)&&(this.#d(i.id),o(i.duration)&&this.#u(i.id,i.duration,!i.paused)),this.#_(),!0}let i=this.#t.findIndex(t=>t.id===e);if(i!==-1){let e=this.#t[i];return e?(this.#t=x(this.#t,i,this.#c(e,t,n,!1)),this.#_(),!0):!1}return!1}dismiss(e,t=`user`){let n=this.#t.findIndex(t=>t.id===e);if(n!==-1){let t=this.#t[n];return this.#t=this.#t.filter(t=>t.id!==e),this.#_(),t?.onDismiss?.(t),!0}let r=this.#e.findIndex(t=>t.id===e),i=this.#e[r];if(!i||i.status===`exiting`)return!1;this.#d(e);let a={...i,status:`exiting`,updatedAt:this.#s.now()};return this.#r.exitDuration<=0?(this.#e=this.#e.filter(t=>t.id!==e),this.#m()):(this.#e=x(this.#e,r,a),this.#f(e)),this.#_(),t===`auto`&&a.onAutoClose?.(a),a.onDismiss?.(a),!0}dismissAll(){let e=[...this.#t];this.#t=[];for(let t of e)t.onDismiss?.(t);let t=this.#e.filter(e=>e.status!==`exiting`);if(t.length!==0||e.length!==0){for(let e of t)this.#d(e.id);if(this.#r.exitDuration<=0)this.#e=[];else{let e=this.#s.now();this.#e=this.#e.map(t=>t.status===`exiting`?t:(this.#f(t.id),{...t,status:`exiting`,updatedAt:e}))}this.#_();for(let e of t)e.onDismiss?.(e)}}pause(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||t===`hover`&&!r.pauseOnHover||t===`focus`&&!r.pauseOnFocus||r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons).add(t),a=this.#a.get(e);this.#e=x(this.#e,n,{...r,paused:!0,pauseReasons:i,remainingTime:a?a.pause():r.remainingTime,startedAt:null}),this.#_()}resume(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||!r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons);i.delete(t);let a=i.size>0;this.#e=x(this.#e,n,{...r,paused:a,pauseReasons:i,startedAt:!a&&o(r.duration)?this.#s.now():null}),this.#_(),a||this.#a.get(e)?.resume()}pauseAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.pause(t.id,e)}resumeAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.resume(t.id,e)}getRemainingTime(e){let t=this.#a.get(e);return t?t.getRemaining():this.#g(e)?.remainingTime??0}removeImmediately(e){this.#d(e),this.#p(e);let t=this.#e.length,n=this.#t.length;this.#e=this.#e.filter(t=>t.id!==e),this.#t=this.#t.filter(t=>t.id!==e),this.#e.length!==t&&this.#m(),(this.#e.length!==t||this.#t.length!==n)&&this.#_()}clear(){for(let e of this.#a.values())e.clear();this.#a.clear();for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),(this.#e.length>0||this.#t.length>0)&&(this.#e=[],this.#t=[],this.#_())}destroy(){this.clear(),this.#i.clear()}#c(e,t,n,r){let i=t.variant??e.variant,a=e.variant===`loading`,c=a&&i!==`loading`,l=c?y(this.#r.toastOptions,i):void 0,u=e.duration;if(t.duration!==void 0)u=t.duration<=0?1/0:t.duration;else if(c){let e=l?.duration??this.#r.defaultDuration;u=e<=0?1/0:e}else i===`loading`&&!a&&(u=1/0);let d=o(u),f=u!==e.duration;return{...e,...b(t),variant:i,duration:u,remainingTime:f?u:e.remainingTime,startedAt:r&&f&&d&&!e.paused?n:e.startedAt,updatedAt:n,showProgress:t.showProgress??(f?d&&i!==`loading`:e.showProgress),classNames:t.classNames===void 0?e.classNames:s(e.classNames,t.classNames),role:g(i,t.role??(t.variant?void 0:e.role)),dedupeKey:t.dedupeKey??(t.title!==void 0||t.description!==void 0||t.variant!==void 0?v(i,t.title===void 0?e.title:t.title,t.description===void 0?e.description:t.description,e.dedupeKey):e.dedupeKey)}}#l(e,t,n){let r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let i=this.#e[r];if(!i)return;let a=n.duration===void 0?i.duration:_(i.variant,n.duration,this.#r.defaultDuration),s=o(a);this.#e=x(this.#e,r,{...i,count:i.count+1,duration:a,remainingTime:a,startedAt:s&&!i.paused?t:null,updatedAt:t}),s&&(this.#d(e),this.#u(e,a,!i.paused)),this.#_();return}let i=this.#t.findIndex(t=>t.id===e),a=this.#t[i];a&&(this.#t=x(this.#t,i,{...a,count:a.count+1,updatedAt:t}),this.#_())}#u(e,t,n=!0){this.#d(e);let r=new f(t,()=>{this.#a.delete(e),this.dismiss(e,`auto`)},this.#s);this.#a.set(e,r),n&&r.start()}#d(e){let t=this.#a.get(e);t&&(t.clear(),this.#a.delete(e))}#f(e){this.#p(e);let t=setTimeout(()=>{this.#o.delete(e),this.#e=this.#e.filter(t=>t.id!==e),this.#m(),this.#_()},this.#r.exitDuration);this.#o.set(e,t)}#p(e){let t=this.#o.get(e);t!==void 0&&(clearTimeout(t),this.#o.delete(e))}#m(){let e=Math.max(1,this.#r.visibleToasts),t=!1;for(;this.#h()<e&&this.#t.length>0;){let e=this.#t[0];if(!e)break;this.#t=this.#t.slice(1);let n=this.#s.now(),r=o(e.duration),i={...e,status:`visible`,startedAt:r?n:null,remainingTime:e.duration,updatedAt:n};this.#e=[...this.#e,i],r&&this.#u(i.id,i.duration),t=!0}return t}#h(){let e=0;for(let t of this.#e)t.status!==`exiting`&&(e+=1);return e}#g(e){return this.#e.find(t=>t.id===e&&t.status!==`exiting`)??this.#t.find(t=>t.id===e)}#_(){this.#n=Object.freeze({toasts:Object.freeze([...this.#e]),queue:Object.freeze([...this.#t])});for(let e of this.#i)e()}};function C(e,t){return new S(e,t)}var w=C();function T(e){return typeof e==`object`&&!!e&&`title`in e&&!(`$$typeof`in e)}function E(e){return T(e)?{...e}:{title:e,description:void 0}}function D(e=w){let t=((t,n)=>e.add({...n,title:t}));for(let n of[`success`,`error`,`warning`,`info`,`loading`])t[n]=(t,r)=>e.add({...r,title:t,variant:n});return t.custom=(t,n)=>e.add({...n,variant:`custom`,customRender:t}),t.update=(t,n)=>e.update(t,n),t.dismiss=t=>e.dismiss(t,`user`),t.dismissAll=()=>e.dismissAll(),t.promise=(t,n,r)=>{let i=e.add({...r,...E(n.loading),variant:`loading`,duration:1/0,showProgress:!1}),a;try{a=typeof t==`function`?t():t}catch(e){a=Promise.reject(e)}let o=(t,n)=>{let a=E(n);e.update(i,{...a,variant:t,duration:a.duration??r?.duration,showProgress:a.showProgress??r?.showProgress})};return a.then(e=>o(`success`,typeof n.success==`function`?n.success(e):n.success),e=>o(`error`,typeof n.error==`function`?n.error(e):n.error)).finally(()=>{n.finally?.()}),{id:i,unwrap:()=>a}},t}var O=D(w);export{C as a,a as c,c as d,u as f,n as h,S as i,o as l,e as m,O as n,w as o,t as p,h as r,f as s,D as t,s as u};
@@ -0,0 +1 @@
1
+ function e(e){return e===`top-center`?[`up`]:e===`bottom-center`?[`down`]:e.endsWith(`left`)?[`left`]:[`right`]}var t=0;function n(e=`vt`){t+=1;let n=globalThis.crypto!==void 0&&typeof globalThis.crypto.randomUUID==`function`?globalThis.crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10);return`${e}-${t}-${n}`}function r(...e){return e.filter(Boolean).join(` `)}function i(e){return Number.isFinite(e)&&e>0}function a(...e){let t;for(let n of e)if(n){if(!t)t={...n};else for(let e of Object.keys(n)){let i=n[e];i&&(t[e]=r(t[e],i))}}return t}function o(e){return e===!1||e===`none`?`none`:e===`subtle`?`subtle`:`default`}var s=[[`fontFamily`,`font-family`],[`width`,`width`,1],[`radius`,`radius`,1],[`blur`,`blur`,1],[`saturate`,`saturate`],[`bg`,`bg`],[`bgSolid`,`bg-solid`],[`border`,`border`],[`text`,`text`],[`textMuted`,`text-muted`],[`shadow`,`shadow`],[`success`,`success`],[`error`,`error`],[`warning`,`warning`],[`info`,`info`],[`loading`,`loading`],[`default`,`default`],[`zIndex`,`z-index-root`]];function c(e){if(!e)return{};let t={};for(let[n,r,i]of s){let a=e[n];a!==void 0&&(t[`--vt-${r}`]=i&&typeof a==`number`?`${a}px`:a)}return t}var l={now:()=>Date.now()},u=class{onComplete;clock;timerId=null;duration;remaining;startedAt=null;paused=!1;completed=!1;constructor(e,t,n=l){this.duration=e,this.remaining=e,this.onComplete=t,this.clock=n}start(){this.completed||!Number.isFinite(this.remaining)||this.remaining<=0||(this.clearHandle(),this.paused=!1,this.startedAt=this.clock.now(),this.timerId=setTimeout(()=>{this.timerId=null,this.startedAt=null,this.remaining=0,this.completed=!0,this.onComplete()},this.remaining))}pause(){if(this.paused||this.completed)return this.remaining;if(this.clearHandle(),this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);this.remaining=Math.max(0,this.remaining-e),this.startedAt=null}return this.paused=!0,this.remaining}resume(){this.paused&&!this.completed&&(this.remaining<=0?(this.completed=!0,this.paused=!1,this.onComplete()):this.start())}reset(e,t=!0){this.clearHandle(),this.duration=e,this.remaining=e,this.startedAt=null,this.paused=!1,this.completed=!1,t&&Number.isFinite(e)&&e>0&&this.start()}getRemaining(){if(this.completed)return 0;if(!this.paused&&this.startedAt!==null){let e=Math.max(0,this.clock.now()-this.startedAt);return Math.max(0,this.remaining-e)}return this.remaining}getDuration(){return this.duration}isPaused(){return this.paused}isRunning(){return this.timerId!==null}clear(){this.clearHandle(),this.startedAt=null,this.completed=!0}clearHandle(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}},d={defaultDuration:4e3,visibleToasts:4,exitDuration:240,preventDuplicates:!1,toastOptions:void 0},f=new Set([`default`,`success`,`error`,`warning`,`info`,`loading`,`custom`]),p=Object.freeze({toasts:Object.freeze([]),queue:Object.freeze([])});function m(e,t){return t??(e===`error`||e===`warning`?`alert`:`status`)}function h(e,t,n){let r=t===void 0?e===`loading`?0:n:t;return r<=0?1/0:r}function g(e,t,n,r){if(r)return r;let i=typeof t==`string`||typeof t==`number`?String(t):``,a=typeof n==`string`||typeof n==`number`?String(n):``;return i||a?`${e}::${i}::${a}`:void 0}function _(e,t){if(!e)return{};let n={};for(let[t,r]of Object.entries(e))f.has(t)||(n[t]=r);let i=n,o=e[t];return o?{...i,...o,className:r(i.className,o.className)||void 0,classNames:a(i.classNames,o.classNames),style:i.style||o.style?{...i.style,...o.style}:void 0}:i}function v(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function y(e,t,n){let r=[...e];return r[t]=n,r}var b=class{#e=[];#t=[];#n=p;#r;#i=new Set;#a=new Map;#o=new Map;#s;constructor(e,t={now:()=>Date.now()}){this.#r={...d,...e},this.#s=t}configure(e){let t=this.#r.visibleToasts;this.#r={...this.#r,...e},this.#r.visibleToasts>t&&this.#t.length>0&&this.#m()&&this.#_()}getConfig(){return this.#r}subscribe=e=>(this.#i.add(e),()=>{this.#i.delete(e)});getSnapshot=()=>this.#n;getServerSnapshot=()=>p;add(e){let t=this.#s.now(),o=e.variant??(e.customRender?`custom`:`default`),s=_(this.#r.toastOptions,o),c={...s,...e,variant:o,className:r(s.className,e.className)||void 0,classNames:a(s.classNames,e.classNames),style:s.style||e.style?{...s.style,...e.style}:void 0};if(c.id&&this.#g(c.id))return this.update(c.id,c),c.id;let l=c.dedupe??(c.dedupeKey!==void 0||this.#r.preventDuplicates),u=g(o,c.title,c.description,c.dedupeKey);if(l&&u){let e=this.#e.find(e=>e.dedupeKey===u&&e.status!==`exiting`)??this.#t.find(e=>e.dedupeKey===u);if(e)return this.#l(e.id,t,c),e.id}let d=c.id??n(),f=h(o,c.duration,this.#r.defaultDuration),p=i(f),v={...c,id:d,variant:o,duration:f,remainingTime:f,startedAt:null,paused:!1,pauseReasons:new Set,status:`visible`,createdAt:t,updatedAt:t,dismissible:c.dismissible??!0,showProgress:c.showProgress??(p&&o!==`loading`),pauseOnHover:c.pauseOnHover??!0,pauseOnFocus:c.pauseOnFocus??!0,swipeToDismiss:c.swipeToDismiss??!0,role:m(o,c.role),dedupeKey:u,count:1};if(this.#h()<Math.max(1,this.#r.visibleToasts)){let e=p?{...v,startedAt:t}:v;this.#e=[...this.#e,e],p&&this.#u(e.id,f)}else this.#t=[...this.#t,v];return this.#_(),d}update(e,t){let n=this.#s.now(),r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let e=this.#e[r];if(!e||e.status===`exiting`)return!1;let a=this.#c(e,t,n,!0);return this.#e=y(this.#e,r,a),(e.duration!==a.duration||t.duration!==void 0||e.variant===`loading`&&a.variant!==`loading`)&&(this.#d(a.id),i(a.duration)&&this.#u(a.id,a.duration,!a.paused)),this.#_(),!0}let a=this.#t.findIndex(t=>t.id===e);if(a!==-1){let e=this.#t[a];return e?(this.#t=y(this.#t,a,this.#c(e,t,n,!1)),this.#_(),!0):!1}return!1}dismiss(e,t=`user`){let n=this.#t.findIndex(t=>t.id===e);if(n!==-1){let t=this.#t[n];return this.#t=this.#t.filter(t=>t.id!==e),this.#_(),t?.onDismiss?.(t),!0}let r=this.#e.findIndex(t=>t.id===e),i=this.#e[r];if(!i||i.status===`exiting`)return!1;this.#d(e);let a={...i,status:`exiting`,updatedAt:this.#s.now()};return this.#r.exitDuration<=0?(this.#e=this.#e.filter(t=>t.id!==e),this.#m()):(this.#e=y(this.#e,r,a),this.#f(e)),this.#_(),t===`auto`&&a.onAutoClose?.(a),a.onDismiss?.(a),!0}dismissAll(){let e=[...this.#t];this.#t=[];for(let t of e)t.onDismiss?.(t);let t=this.#e.filter(e=>e.status!==`exiting`);if(t.length!==0||e.length!==0){for(let e of t)this.#d(e.id);if(this.#r.exitDuration<=0)this.#e=[];else{let e=this.#s.now();this.#e=this.#e.map(t=>t.status===`exiting`?t:(this.#f(t.id),{...t,status:`exiting`,updatedAt:e}))}this.#_();for(let e of t)e.onDismiss?.(e)}}pause(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||t===`hover`&&!r.pauseOnHover||t===`focus`&&!r.pauseOnFocus||r.pauseReasons.has(t))return;let i=new Set(r.pauseReasons).add(t),a=this.#a.get(e);this.#e=y(this.#e,n,{...r,paused:!0,pauseReasons:i,remainingTime:a?a.pause():r.remainingTime,startedAt:null}),this.#_()}resume(e,t=`manual`){let n=this.#e.findIndex(t=>t.id===e),r=this.#e[n];if(!r||r.status===`exiting`||!r.pauseReasons.has(t))return;let a=new Set(r.pauseReasons);a.delete(t);let o=a.size>0;this.#e=y(this.#e,n,{...r,paused:o,pauseReasons:a,startedAt:!o&&i(r.duration)?this.#s.now():null}),this.#_(),o||this.#a.get(e)?.resume()}pauseAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.pause(t.id,e)}resumeAll(e=`manual`){for(let t of this.#e)t.status!==`exiting`&&this.resume(t.id,e)}getRemainingTime(e){let t=this.#a.get(e);return t?t.getRemaining():this.#g(e)?.remainingTime??0}removeImmediately(e){this.#d(e),this.#p(e);let t=this.#e.length,n=this.#t.length;this.#e=this.#e.filter(t=>t.id!==e),this.#t=this.#t.filter(t=>t.id!==e),this.#e.length!==t&&this.#m(),(this.#e.length!==t||this.#t.length!==n)&&this.#_()}clear(){for(let e of this.#a.values())e.clear();this.#a.clear();for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),(this.#e.length>0||this.#t.length>0)&&(this.#e=[],this.#t=[],this.#_())}destroy(){this.clear(),this.#i.clear()}#c(e,t,n,r){let o=t.variant??e.variant,s=e.variant===`loading`,c=s&&o!==`loading`,l=c?_(this.#r.toastOptions,o):void 0,u=e.duration;if(t.duration!==void 0)u=t.duration<=0?1/0:t.duration;else if(c){let e=l?.duration??this.#r.defaultDuration;u=e<=0?1/0:e}else o===`loading`&&!s&&(u=1/0);let d=i(u),f=u!==e.duration;return{...e,...v(t),variant:o,duration:u,remainingTime:f?u:e.remainingTime,startedAt:r&&f&&d&&!e.paused?n:e.startedAt,updatedAt:n,showProgress:t.showProgress??(f?d&&o!==`loading`:e.showProgress),classNames:t.classNames===void 0?e.classNames:a(e.classNames,t.classNames),role:m(o,t.role??(t.variant?void 0:e.role)),dedupeKey:t.dedupeKey??(t.title!==void 0||t.description!==void 0||t.variant!==void 0?g(o,t.title===void 0?e.title:t.title,t.description===void 0?e.description:t.description,e.dedupeKey):e.dedupeKey)}}#l(e,t,n){let r=this.#e.findIndex(t=>t.id===e);if(r!==-1){let a=this.#e[r];if(!a)return;let o=n.duration===void 0?a.duration:h(a.variant,n.duration,this.#r.defaultDuration),s=i(o);this.#e=y(this.#e,r,{...a,count:a.count+1,duration:o,remainingTime:o,startedAt:s&&!a.paused?t:null,updatedAt:t}),s&&(this.#d(e),this.#u(e,o,!a.paused)),this.#_();return}let a=this.#t.findIndex(t=>t.id===e),o=this.#t[a];o&&(this.#t=y(this.#t,a,{...o,count:o.count+1,updatedAt:t}),this.#_())}#u(e,t,n=!0){this.#d(e);let r=new u(t,()=>{this.#a.delete(e),this.dismiss(e,`auto`)},this.#s);this.#a.set(e,r),n&&r.start()}#d(e){let t=this.#a.get(e);t&&(t.clear(),this.#a.delete(e))}#f(e){this.#p(e);let t=setTimeout(()=>{this.#o.delete(e),this.#e=this.#e.filter(t=>t.id!==e),this.#m(),this.#_()},this.#r.exitDuration);this.#o.set(e,t)}#p(e){let t=this.#o.get(e);t!==void 0&&(clearTimeout(t),this.#o.delete(e))}#m(){let e=Math.max(1,this.#r.visibleToasts),t=!1;for(;this.#h()<e&&this.#t.length>0;){let e=this.#t[0];if(!e)break;this.#t=this.#t.slice(1);let n=this.#s.now(),r=i(e.duration),a={...e,status:`visible`,startedAt:r?n:null,remainingTime:e.duration,updatedAt:n};this.#e=[...this.#e,a],r&&this.#u(a.id,a.duration),t=!0}return t}#h(){let e=0;for(let t of this.#e)t.status!==`exiting`&&(e+=1);return e}#g(e){return this.#e.find(t=>t.id===e&&t.status!==`exiting`)??this.#t.find(t=>t.id===e)}#_(){this.#n=Object.freeze({toasts:Object.freeze([...this.#e]),queue:Object.freeze([...this.#t])});for(let e of this.#i)e()}};function x(e,t){return new b(e,t)}var S=x();function C(e){return typeof e==`object`&&!!e&&`title`in e&&!(`$$typeof`in e)}function w(e){return C(e)?{...e}:{title:e,description:void 0}}function T(e=S){let t=((t,n)=>e.add({...n,title:t}));for(let n of[`success`,`error`,`warning`,`info`,`loading`])t[n]=(t,r)=>e.add({...r,title:t,variant:n});return t.custom=(t,n)=>e.add({...n,variant:`custom`,customRender:t}),t.update=(t,n)=>e.update(t,n),t.dismiss=t=>e.dismiss(t,`user`),t.dismissAll=()=>e.dismissAll(),t.promise=(t,n,r)=>{let i=e.add({...r,...w(n.loading),variant:`loading`,duration:1/0,showProgress:!1}),a;try{a=typeof t==`function`?t():t}catch(e){a=Promise.reject(e)}let o=(t,n)=>{let a=w(n);e.update(i,{...a,variant:t,duration:a.duration??r?.duration,showProgress:a.showProgress??r?.showProgress})};return a.then(e=>o(`success`,typeof n.success==`function`?n.success(e):n.success),e=>o(`error`,typeof n.error==`function`?n.error(e):n.error)).finally(()=>{n.finally?.()}),{id:i,unwrap:()=>a}},t}var E=T(S);Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return .45}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return .35}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return a}});
package/dist/core.cjs CHANGED
@@ -1,9 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_core = require("./core-CqZy4LyN.cjs");
3
- exports.EMPTY_SNAPSHOT = require_core.EMPTY_SNAPSHOT;
4
- exports.PauseableTimer = require_core.PauseableTimer;
5
- exports.ToastStore = require_core.ToastStore;
6
- exports.createToastApi = require_core.createToastApi;
7
- exports.createToastStore = require_core.createToastStore;
8
- exports.defaultToastStore = require_core.defaultToastStore;
9
- exports.toast = require_core.toast;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./core-DWP-MMiI.cjs");exports.EMPTY_SNAPSHOT=e.r,exports.PauseableTimer=e.s,exports.ToastStore=e.i,exports.createToastApi=e.t,exports.createToastStore=e.a,exports.defaultToastStore=e.o,exports.toast=e.n;
package/dist/core.js CHANGED
@@ -1 +1 @@
1
- export { r as EMPTY_SNAPSHOT, s as PauseableTimer, i as ToastStore, t as createToastApi, a as createToastStore, o as defaultToastStore, n as toast } from "./core-KMoYj72S.js";
1
+ export{r as EMPTY_SNAPSHOT,s as PauseableTimer,i as ToastStore,t as createToastApi,a as createToastStore,o as defaultToastStore,n as toast}from"./core-BikVsncn.js";
@@ -1,2 +1 @@
1
1
  export declare function useMounted(): boolean;
2
- //# sourceMappingURL=use-mounted.d.ts.map
@@ -24,4 +24,3 @@ export interface UseSwipeResult {
24
24
  };
25
25
  }
26
26
  export declare function useSwipe({ enabled, position, directions, onSwipeStart, onSwipeCancel, onDismiss, }: UseSwipeOptions): UseSwipeResult;
27
- //# sourceMappingURL=use-swipe.d.ts.map
@@ -1,3 +1,2 @@
1
1
  import type { ResolvedTheme, ToastTheme } from "../types/index.js";
2
2
  export declare function useResolvedTheme(theme: ToastTheme): ResolvedTheme;
3
- //# sourceMappingURL=use-system-theme.d.ts.map
@@ -1,4 +1,3 @@
1
1
  import { type ToastStore } from "../core/store.js";
2
2
  import type { ToastStoreSnapshot } from "../types/index.js";
3
3
  export declare function useToasts(store?: ToastStore): ToastStoreSnapshot;
4
- //# sourceMappingURL=use-toasts.d.ts.map