@editora/toast 1.0.2 → 2.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 (51) hide show
  1. package/README.md +901 -7
  2. package/dist/core/AnimationUtils.d.ts +36 -0
  3. package/dist/core/ToastLifecycle.d.ts +25 -0
  4. package/dist/core/ToastManager.d.ts +36 -0
  5. package/dist/core/ToastQueue.d.ts +19 -0
  6. package/dist/core/ToastRenderer.d.ts +20 -0
  7. package/dist/core/ToastStore.d.ts +31 -0
  8. package/dist/core/types.d.ts +168 -0
  9. package/dist/index.cjs.js +2 -0
  10. package/dist/index.cjs.js.map +1 -0
  11. package/dist/index.d.ts +32 -7
  12. package/dist/index.esm.js +1061 -0
  13. package/dist/index.esm.js.map +1 -0
  14. package/dist/index.umd.js +2 -0
  15. package/dist/index.umd.js.map +1 -0
  16. package/dist/toast.css +783 -18
  17. package/package.json +45 -12
  18. package/LICENSE +0 -21
  19. package/dist/index.js +0 -70
  20. package/dist/packages/core/src/Editor.d.ts +0 -15
  21. package/dist/packages/core/src/Editor.js +0 -37
  22. package/dist/packages/core/src/EditorState.d.ts +0 -13
  23. package/dist/packages/core/src/EditorState.js +0 -14
  24. package/dist/packages/core/src/Selection.d.ts +0 -126
  25. package/dist/packages/core/src/Selection.js +0 -232
  26. package/dist/packages/core/src/commands/CommandManager.d.ts +0 -56
  27. package/dist/packages/core/src/commands/CommandManager.js +0 -166
  28. package/dist/packages/core/src/index.d.ts +0 -7
  29. package/dist/packages/core/src/index.js +0 -4
  30. package/dist/packages/core/src/model/Fragment.d.ts +0 -80
  31. package/dist/packages/core/src/model/Fragment.js +0 -172
  32. package/dist/packages/core/src/model/Mark.d.ts +0 -108
  33. package/dist/packages/core/src/model/Mark.js +0 -138
  34. package/dist/packages/core/src/model/Node.d.ts +0 -172
  35. package/dist/packages/core/src/model/Node.js +0 -458
  36. package/dist/packages/core/src/model/types.d.ts +0 -29
  37. package/dist/packages/core/src/model/types.js +0 -1
  38. package/dist/packages/core/src/plugins/Plugin.d.ts +0 -37
  39. package/dist/packages/core/src/plugins/Plugin.js +0 -31
  40. package/dist/packages/core/src/plugins/PluginManager.d.ts +0 -75
  41. package/dist/packages/core/src/plugins/PluginManager.js +0 -185
  42. package/dist/packages/core/src/schema/Node.d.ts +0 -26
  43. package/dist/packages/core/src/schema/Node.js +0 -12
  44. package/dist/packages/core/src/schema/Schema.d.ts +0 -52
  45. package/dist/packages/core/src/schema/Schema.js +0 -296
  46. package/dist/packages/core/src/security/Sanitizer.d.ts +0 -81
  47. package/dist/packages/core/src/security/Sanitizer.js +0 -200
  48. package/dist/packages/editora-toast/src/index.d.ts +0 -18
  49. package/dist/packages/editora-toast/src/index.js +0 -70
  50. package/src/index.ts +0 -83
  51. package/src/toast.css +0 -42
@@ -0,0 +1,36 @@
1
+ import { SpringConfig, AnimationConfig, ToastInstance, ToastOptions } from './types';
2
+ export declare class SpringAnimation {
3
+ private config;
4
+ constructor(config?: SpringConfig);
5
+ animate(element: HTMLElement, properties: Record<string, {
6
+ from: number;
7
+ to: number;
8
+ unit?: string;
9
+ }>, onUpdate: (values: Record<string, string>) => void, onComplete?: () => void, config?: Partial<SpringConfig>): () => void;
10
+ }
11
+ export declare class AnimationManager {
12
+ private springAnimation;
13
+ constructor();
14
+ showToast(element: HTMLElement, toast: ToastInstance, animation: AnimationConfig): Promise<void>;
15
+ hideToast(element: HTMLElement, toast: ToastInstance, animation: AnimationConfig): Promise<void>;
16
+ updateToast(element: HTMLElement, toast: ToastInstance, updates: Partial<ToastOptions>, animation: AnimationConfig): Promise<void>;
17
+ private animateCssShow;
18
+ private animateCssHide;
19
+ private animateSpringShow;
20
+ private animateSpringHide;
21
+ private animateBounceShow;
22
+ private animateBounceHide;
23
+ private animateSlideShow;
24
+ private animateSlideHide;
25
+ private animateZoomShow;
26
+ private animateZoomHide;
27
+ private animateFlipShow;
28
+ private animateFlipHide;
29
+ private animateFadeShow;
30
+ private animateFadeHide;
31
+ private animateElasticShow;
32
+ private animateElasticHide;
33
+ private animateRotateShow;
34
+ private animateRotateHide;
35
+ }
36
+ export declare const animationManager: AnimationManager;
@@ -0,0 +1,25 @@
1
+ import { ToastInstance, ToastPlugin } from './types';
2
+ type HookCallback = (toast: ToastInstance, ...args: any[]) => void | Promise<void>;
3
+ export declare class ToastLifecycle {
4
+ private plugins;
5
+ private hooks;
6
+ use(plugin: ToastPlugin): void;
7
+ remove(pluginName: string): boolean;
8
+ getPlugins(): ToastPlugin[];
9
+ on(event: keyof typeof this.hooks, callback: HookCallback): void;
10
+ off(event: keyof typeof this.hooks, callback: HookCallback): void;
11
+ trigger(event: keyof typeof this.hooks, toast: ToastInstance, ...args: any[]): Promise<void>;
12
+ beforeShow(toast: ToastInstance): Promise<void>;
13
+ afterShow(toast: ToastInstance): Promise<void>;
14
+ beforeHide(toast: ToastInstance): Promise<void>;
15
+ afterHide(toast: ToastInstance): Promise<void>;
16
+ beforeUpdate(toast: ToastInstance, updates: any): Promise<void>;
17
+ afterUpdate(toast: ToastInstance, updates: any): Promise<void>;
18
+ onEditorEvent(event: string, callback: HookCallback): void;
19
+ triggerEditorEvent(event: string, toast: ToastInstance, ...args: any[]): void;
20
+ handlePromise<T>(promise: Promise<T>, onLoading: () => void, onSuccess: (data: T) => void, onError: (error: any) => void): Promise<T>;
21
+ batchShow(toasts: ToastInstance[]): Promise<void>;
22
+ batchHide(toasts: ToastInstance[]): Promise<void>;
23
+ destroy(): void;
24
+ }
25
+ export {};
@@ -0,0 +1,36 @@
1
+ import { ToastInstance, ToastOptions, ToastConfig, ToastManager as IToastManager, ToastPromiseOptions, ToastPlugin } from './types';
2
+ export declare class ToastManager implements IToastManager {
3
+ private store;
4
+ private queue;
5
+ private renderer;
6
+ private lifecycle;
7
+ private config;
8
+ private idCounter;
9
+ private pausedToasts;
10
+ private windowFocusHandler?;
11
+ private windowBlurHandler?;
12
+ constructor(config?: Partial<ToastConfig>);
13
+ show(options: ToastOptions): ToastInstance;
14
+ update(id: string, options: Partial<ToastOptions>): boolean;
15
+ dismiss(id: string): boolean;
16
+ clear(): void;
17
+ promise<T>(promise: Promise<T>, options: ToastPromiseOptions<T>): Promise<T>;
18
+ group(groupId: string, options: ToastOptions): ToastInstance;
19
+ use(plugin: ToastPlugin): void;
20
+ configure(config: Partial<ToastConfig>): void;
21
+ getConfig(): ToastConfig;
22
+ getToasts(): ToastInstance[];
23
+ getGroups(): import("./types").ToastGroup[];
24
+ info(message: string, duration?: number): ToastInstance;
25
+ success(message: string, duration?: number): ToastInstance;
26
+ error(message: string, duration?: number): ToastInstance;
27
+ warning(message: string, duration?: number): ToastInstance;
28
+ loading(message: string, duration?: number): ToastInstance;
29
+ private normalizeOptions;
30
+ onEditorEvent(event: string, callback: (toast: ToastInstance, ...args: any[]) => void): void;
31
+ triggerEditorEvent(event: string, toast: ToastInstance, ...args: any[]): void;
32
+ private setupWindowFocusHandling;
33
+ private pauseAllToasts;
34
+ private resumeAllToasts;
35
+ destroy(): void;
36
+ }
@@ -0,0 +1,19 @@
1
+ import { ToastInstance, ToastConfig } from './types';
2
+ export declare class ToastQueue {
3
+ private queue;
4
+ private visible;
5
+ private config;
6
+ constructor(config: ToastConfig);
7
+ enqueue(toast: ToastInstance): void;
8
+ dequeue(id: string): boolean;
9
+ private processQueue;
10
+ private showToast;
11
+ private hideToast;
12
+ private deduplicate;
13
+ updateConfig(config: Partial<ToastConfig>): void;
14
+ getQueued(): ToastInstance[];
15
+ getVisible(): ToastInstance[];
16
+ getAll(): ToastInstance[];
17
+ clear(): void;
18
+ forceShow(toast: ToastInstance): void;
19
+ }
@@ -0,0 +1,20 @@
1
+ import { ToastInstance, ToastPosition, ToastConfig } from './types';
2
+ export declare class ToastRenderer {
3
+ private containers;
4
+ private config;
5
+ private cssInjected;
6
+ constructor(config: ToastConfig);
7
+ ensureContainer(position: ToastPosition): HTMLElement;
8
+ createToastElement(toast: ToastInstance): HTMLElement;
9
+ showToast(toast: ToastInstance): Promise<void>;
10
+ hideToast(toast: ToastInstance): Promise<void>;
11
+ updateToast(toast: ToastInstance, updates: Partial<ToastInstance['options']>): Promise<void>;
12
+ private pauseToast;
13
+ private resumeToast;
14
+ private addSwipeDismiss;
15
+ private addDragDismiss;
16
+ private announceToast;
17
+ private sanitizeHTML;
18
+ private injectCSS;
19
+ destroy(): void;
20
+ }
@@ -0,0 +1,31 @@
1
+ import { ToastInstance, ToastGroup, ToastConfig, ToastPosition } from './types';
2
+ export declare class ToastStore {
3
+ private toasts;
4
+ private groups;
5
+ private containers;
6
+ private config;
7
+ constructor(config: ToastConfig);
8
+ addToast(toast: ToastInstance): void;
9
+ removeToast(id: string): boolean;
10
+ getToast(id: string): ToastInstance | undefined;
11
+ getAllToasts(): ToastInstance[];
12
+ getToastsByPosition(position: ToastPosition): ToastInstance[];
13
+ updateToast(id: string, updates: Partial<ToastInstance>): boolean;
14
+ private updateGroup;
15
+ getGroup(id: string): ToastGroup | undefined;
16
+ getAllGroups(): ToastGroup[];
17
+ getContainer(position: ToastPosition): HTMLElement | undefined;
18
+ setContainer(position: ToastPosition, container: HTMLElement): void;
19
+ removeContainer(position: ToastPosition): boolean;
20
+ getAllContainers(): Map<ToastPosition, HTMLElement>;
21
+ getConfig(): ToastConfig;
22
+ updateConfig(config: Partial<ToastConfig>): void;
23
+ clear(): void;
24
+ getStats(): {
25
+ totalToasts: number;
26
+ totalGroups: number;
27
+ toastsByPosition: {
28
+ [k: string]: number;
29
+ };
30
+ };
31
+ }
@@ -0,0 +1,168 @@
1
+ export type ToastLevel = 'info' | 'success' | 'error' | 'warning' | 'loading' | 'progress' | 'promise' | 'custom';
2
+ export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center';
3
+ export type ToastTheme = 'light' | 'dark' | 'system' | 'custom' | 'colored' | 'minimal' | 'glass' | 'neon' | 'retro' | 'ocean' | 'forest' | 'sunset' | 'midnight';
4
+ export type QueueStrategy = 'fifo' | 'lifo';
5
+ export interface SpringConfig {
6
+ stiffness?: number;
7
+ damping?: number;
8
+ mass?: number;
9
+ precision?: number;
10
+ }
11
+ export type AnimationType = 'css' | 'spring' | 'bounce' | 'slide' | 'zoom' | 'flip' | 'fade' | 'elastic' | 'rotate' | 'custom';
12
+ export interface SpringAnimation {
13
+ type: 'spring';
14
+ config?: SpringConfig;
15
+ duration?: number;
16
+ }
17
+ export interface BounceAnimation {
18
+ type: 'bounce';
19
+ direction?: 'up' | 'down' | 'left' | 'right';
20
+ intensity?: 'gentle' | 'normal' | 'strong';
21
+ duration?: number;
22
+ }
23
+ export interface SlideAnimation {
24
+ type: 'slide';
25
+ direction?: 'up' | 'down' | 'left' | 'right';
26
+ distance?: number;
27
+ easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
28
+ duration?: number;
29
+ }
30
+ export interface ZoomAnimation {
31
+ type: 'zoom';
32
+ scale?: number;
33
+ origin?: 'center' | 'top' | 'bottom' | 'left' | 'right';
34
+ easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'bounce';
35
+ duration?: number;
36
+ }
37
+ export interface FlipAnimation {
38
+ type: 'flip';
39
+ axis?: 'x' | 'y';
40
+ perspective?: number;
41
+ direction?: 'forward' | 'backward';
42
+ duration?: number;
43
+ }
44
+ export interface FadeAnimation {
45
+ type: 'fade';
46
+ direction?: 'up' | 'down' | 'left' | 'right' | 'none';
47
+ distance?: number;
48
+ duration?: number;
49
+ }
50
+ export interface ElasticAnimation {
51
+ type: 'elastic';
52
+ direction?: 'up' | 'down' | 'left' | 'right';
53
+ intensity?: 'gentle' | 'normal' | 'strong';
54
+ duration?: number;
55
+ }
56
+ export interface RotateAnimation {
57
+ type: 'rotate';
58
+ degrees?: number;
59
+ direction?: 'clockwise' | 'counterclockwise';
60
+ origin?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
61
+ duration?: number;
62
+ }
63
+ export interface CustomAnimation {
64
+ type: 'custom';
65
+ show?: (element: HTMLElement, toast: ToastInstance) => Promise<void> | void;
66
+ hide?: (element: HTMLElement, toast: ToastInstance) => Promise<void> | void;
67
+ update?: (element: HTMLElement, toast: ToastInstance, updates: Partial<ToastOptions>) => Promise<void> | void;
68
+ }
69
+ export type AnimationConfig = SpringAnimation | BounceAnimation | SlideAnimation | ZoomAnimation | FlipAnimation | FadeAnimation | ElasticAnimation | RotateAnimation | CustomAnimation | {
70
+ type: 'css';
71
+ };
72
+ export interface ToastAction {
73
+ label: string;
74
+ onClick: () => void;
75
+ primary?: boolean;
76
+ }
77
+ export interface ToastProgress {
78
+ value: number;
79
+ showPercentage?: boolean;
80
+ }
81
+ export interface ToastContent {
82
+ message: string;
83
+ icon?: string;
84
+ actions?: ToastAction[];
85
+ progress?: ToastProgress;
86
+ html?: boolean;
87
+ render?: () => HTMLElement;
88
+ }
89
+ export interface ToastOptions extends Partial<ToastContent> {
90
+ id?: string;
91
+ level?: ToastLevel;
92
+ duration?: number;
93
+ position?: ToastPosition;
94
+ priority?: number;
95
+ group?: string;
96
+ persistent?: boolean;
97
+ closable?: boolean;
98
+ pauseOnHover?: boolean;
99
+ pauseOnFocus?: boolean;
100
+ swipeDismiss?: boolean;
101
+ swipeDirection?: 'any' | 'horizontal' | 'vertical' | 'left' | 'right' | 'up' | 'down';
102
+ dragDismiss?: boolean;
103
+ rtl?: boolean;
104
+ theme?: ToastTheme;
105
+ customClass?: string;
106
+ animation?: AnimationConfig;
107
+ onShow?: () => void;
108
+ onHide?: () => void;
109
+ onUpdate?: (options: Partial<ToastOptions>) => void;
110
+ }
111
+ export interface ToastInstance {
112
+ id: string;
113
+ options: ToastOptions;
114
+ element?: HTMLElement;
115
+ timeoutId?: number;
116
+ createdAt: number;
117
+ dismiss: () => void;
118
+ update: (options: Partial<ToastOptions>) => void;
119
+ }
120
+ export interface ToastPromiseOptions<T = any> {
121
+ loading: string | ToastOptions;
122
+ success: string | ((data: T) => string) | ToastOptions;
123
+ error: string | ((error: any) => string) | ToastOptions;
124
+ onSuccess?: (data: T) => void;
125
+ onError?: (error: any) => void;
126
+ }
127
+ export interface ToastGroup {
128
+ id: string;
129
+ toasts: ToastInstance[];
130
+ collapsed?: boolean;
131
+ progress?: number;
132
+ }
133
+ export interface ToastConfig {
134
+ position: ToastPosition;
135
+ duration: number;
136
+ maxVisible: number;
137
+ queueStrategy: QueueStrategy;
138
+ theme: ToastTheme;
139
+ pauseOnHover: boolean;
140
+ pauseOnFocus: boolean;
141
+ pauseOnWindowBlur: boolean;
142
+ swipeDismiss: boolean;
143
+ swipeDirection?: 'any' | 'horizontal' | 'vertical' | 'left' | 'right' | 'up' | 'down';
144
+ dragDismiss: boolean;
145
+ rtl: boolean;
146
+ enableAccessibility: boolean;
147
+ container?: HTMLElement;
148
+ zIndex?: number;
149
+ animation?: AnimationConfig;
150
+ }
151
+ export interface ToastPlugin {
152
+ name: string;
153
+ install: (manager: ToastManager) => void;
154
+ uninstall?: (manager: ToastManager) => void;
155
+ }
156
+ export interface ToastManager {
157
+ show(options: ToastOptions): ToastInstance;
158
+ update(id: string, options: Partial<ToastOptions>): boolean;
159
+ dismiss(id: string): boolean;
160
+ clear(): void;
161
+ configure(config: Partial<ToastConfig>): void;
162
+ promise<T>(promise: Promise<T>, options: ToastPromiseOptions<T>): Promise<T>;
163
+ group(id: string, options: ToastOptions): ToastInstance;
164
+ use(plugin: ToastPlugin): void;
165
+ getConfig(): ToastConfig;
166
+ getToasts(): ToastInstance[];
167
+ getGroups(): ToastGroup[];
168
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class k{constructor(t){this.toasts=new Map,this.groups=new Map,this.containers=new Map,this.config={...t}}addToast(t){this.toasts.set(t.id,t),this.updateGroup(t)}removeToast(t){const s=this.toasts.get(t);return s?(this.toasts.delete(t),this.updateGroup(s),!0):!1}getToast(t){return this.toasts.get(t)}getAllToasts(){return Array.from(this.toasts.values())}getToastsByPosition(t){return this.getAllToasts().filter(s=>s.options.position===t)}updateToast(t,s){const e=this.toasts.get(t);return e?(Object.assign(e,s),this.updateGroup(e),!0):!1}updateGroup(t){const s=t.options.group;if(!s)return;let e=this.groups.get(s);e||(e={id:s,toasts:[]},this.groups.set(s,e)),e.toasts=e.toasts.filter(i=>i.id!==t.id),t.options.group===s&&e.toasts.push(t),e.toasts.length===0&&this.groups.delete(s)}getGroup(t){return this.groups.get(t)}getAllGroups(){return Array.from(this.groups.values())}getContainer(t){return this.containers.get(t)}setContainer(t,s){this.containers.set(t,s)}removeContainer(t){return this.containers.delete(t)}getAllContainers(){return new Map(this.containers)}getConfig(){return{...this.config}}updateConfig(t){this.config={...this.config,...t}}clear(){this.toasts.clear(),this.groups.clear()}getStats(){return{totalToasts:this.toasts.size,totalGroups:this.groups.size,toastsByPosition:Object.fromEntries(Array.from(this.containers.keys()).map(t=>[t,this.getToastsByPosition(t).length]))}}}class H{constructor(t){this.queue=[],this.visible=[],this.config=t}enqueue(t){this.deduplicate(t),this.config.queueStrategy==="fifo"?this.queue.push(t):this.queue.unshift(t),this.queue.sort((s,e)=>(e.options.priority||0)-(s.options.priority||0)),this.processQueue()}dequeue(t){let s=!1;const e=this.queue.findIndex(r=>r.id===t);e!==-1&&(this.queue.splice(e,1),s=!0);const i=this.visible.findIndex(r=>r.id===t);return i!==-1&&(this.visible.splice(i,1),s=!0),s&&this.processQueue(),s}processQueue(){const t=this.config.maxVisible;for(;this.visible.length>t;){const s=this.visible.pop();this.hideToast(s)}for(;this.visible.length<t&&this.queue.length>0;){const s=this.queue.shift();this.showToast(s)}}showToast(t){this.visible.push(t)}hideToast(t){}deduplicate(t){this.queue.filter(e=>e.options.message===t.options.message&&e.options.level===t.options.level).forEach(e=>{const i=this.queue.indexOf(e);i!==-1&&this.queue.splice(i,1)})}updateConfig(t){this.config={...this.config,...t},this.processQueue()}getQueued(){return[...this.queue]}getVisible(){return[...this.visible]}getAll(){return[...this.visible,...this.queue]}clear(){const t=[...this.visible,...this.queue];this.queue=[],this.visible=[],t.forEach(s=>{s.element&&this.hideToast(s)})}forceShow(t){if(this.visible.length>=this.config.maxVisible){const s=this.visible.reduce((e,i)=>(i.options.priority||0)<(e.options.priority||0)?i:e);this.dequeue(s.id)}this.showToast(t)}}class L{constructor(t={}){var s,e,i,r;this.config={stiffness:(s=t.stiffness)!=null?s:100,damping:(e=t.damping)!=null?e:10,mass:(i=t.mass)!=null?i:1,precision:(r=t.precision)!=null?r:.01}}animate(t,s,e,i,r){const a={...this.config,...r};let o,n=!1;const p=Object.keys(s).reduce((u,l)=>(u[l]=s[l].from,u),{}),d=Object.keys(s).reduce((u,l)=>(u[l]=0,u),{}),m=()=>{if(n)return;let u=!0;Object.keys(s).forEach(g=>{const b=s[g].to,y=p[g],w=d[g],f=-a.stiffness*(y-b),v=-a.damping*w,x=(f+v)/a.mass;d[g]+=x*.016,p[g]+=d[g]*.016,(Math.abs(y-b)>a.precision||Math.abs(w)>a.precision)&&(u=!1)});const l=Object.keys(p).reduce((g,b)=>{const y=s[b].unit||"px";return g[b]=`${p[b]}${y}`,g},{});e(l),u?(n=!0,i==null||i()):o=requestAnimationFrame(m)};return o=requestAnimationFrame(m),()=>{n=!0,o&&cancelAnimationFrame(o)}}}class M{constructor(){this.springAnimation=new L}async showToast(t,s,e){switch(e.type){case"spring":await this.animateSpringShow(t,e);break;case"bounce":await this.animateBounceShow(t,e);break;case"slide":await this.animateSlideShow(t,e);break;case"zoom":await this.animateZoomShow(t,e);break;case"flip":await this.animateFlipShow(t,e);break;case"fade":await this.animateFadeShow(t,e);break;case"elastic":await this.animateElasticShow(t,e);break;case"rotate":await this.animateRotateShow(t,e);break;case"custom":e.show?await Promise.resolve(e.show(t,s)):this.animateCssShow(t);break;case"css":default:this.animateCssShow(t);break}}async hideToast(t,s,e){switch(e.type){case"spring":await this.animateSpringHide(t,e);break;case"bounce":await this.animateBounceHide(t,e);break;case"slide":await this.animateSlideHide(t,e);break;case"zoom":await this.animateZoomHide(t,e);break;case"flip":await this.animateFlipHide(t,e);break;case"fade":await this.animateFadeHide(t,e);break;case"elastic":await this.animateElasticHide(t,e);break;case"rotate":await this.animateRotateHide(t,e);break;case"custom":e.hide?await Promise.resolve(e.hide(t,s)):this.animateCssHide(t);break;case"css":default:this.animateCssHide(t);break}}async updateToast(t,s,e,i){i.type==="custom"&&i.update&&await Promise.resolve(i.update(t,s,e))}animateCssShow(t){requestAnimationFrame(()=>{t.classList.add("show")})}animateCssHide(t){t.classList.remove("show"),t.classList.add("hiding")}async animateSpringShow(t,s){return new Promise(e=>{var a,o,n;t.classList.add("spring-animation"),t.style.setProperty("transition","none","important"),t.style.setProperty("-webkit-transition","none","important");const r=((a=t.parentElement)==null?void 0:a.classList.contains("editora-toast-bottom-right"))||((o=t.parentElement)==null?void 0:o.classList.contains("editora-toast-bottom-left"))||((n=t.parentElement)==null?void 0:n.classList.contains("editora-toast-bottom-center"))?20:-20;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`translateY(${r}px) scale(0.95)`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition","opacity 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1)","important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","translateY(0) scale(1)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},800)},16)})}async animateSpringHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important"),t.style.setProperty("-webkit-transition","none","important"),setTimeout(()=>{t.style.setProperty("transition","opacity 0.4s ease, transform 0.4s ease","important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform","translateY(-10px) scale(0.95)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},400)},16)})}async animateBounceShow(t,s){return new Promise(e=>{var d,m,u;t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=((d=t.parentElement)==null?void 0:d.classList.contains("editora-toast-bottom-right"))||((m=t.parentElement)==null?void 0:m.classList.contains("editora-toast-bottom-left"))||((u=t.parentElement)==null?void 0:u.classList.contains("editora-toast-bottom-center")),r=s.direction||(i?"up":"down"),a=s.intensity||"normal",o=s.duration||800,n=a==="gentle"?.05:a==="strong"?.15:.1,p=r==="up"?30:r==="down"?-30:r==="left"?30:-30;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",r==="left"||r==="right"?`translateX(${p}px) scale(${1-n})`:`translateY(${p}px) scale(${1-n})`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms cubic-bezier(0.68, -0.55, 0.265, 1.55), transform ${o}ms cubic-bezier(0.68, -0.55, 0.265, 1.55)`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","translateY(0) scale(1)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},o)},16)})}async animateBounceHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.intensity||"normal",r=i==="gentle"?.05:i==="strong"?.15:.1;setTimeout(()=>{t.style.setProperty("transition","opacity 0.4s ease, transform 0.4s ease","important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`scale(${1-r})`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},400)},16)})}async animateSlideShow(t,s){return new Promise(e=>{var d,m,u;t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=((d=t.parentElement)==null?void 0:d.classList.contains("editora-toast-bottom-right"))||((m=t.parentElement)==null?void 0:m.classList.contains("editora-toast-bottom-left"))||((u=t.parentElement)==null?void 0:u.classList.contains("editora-toast-bottom-center")),r=s.direction||(i?"up":"down"),a=s.distance||100,o=s.easing||"ease-out",n=s.duration||400,p=r==="up"?`translateY(${a}px)`:r==="down"?`translateY(-${a}px)`:r==="left"?`translateX(${a}px)`:`translateX(-${a}px)`;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",p,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${n}ms ${o}, transform ${n}ms ${o}`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","translateY(0) translateX(0)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},n)},16)})}async animateSlideHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.direction||"down",r=s.distance||100,a=s.easing||"ease-in",o=s.duration||300,n=i==="up"?`translateY(-${r}px)`:i==="down"?`translateY(${r}px)`:i==="left"?`translateX(-${r}px)`:`translateX(${r}px)`;setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ${a}, transform ${o}ms ${a}`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",n,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},o)},16)})}async animateZoomShow(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.scale||.3,r=s.origin||"center",a=s.easing||"ease-out",o=s.duration||500;t.style.setProperty("transform-origin",r,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`scale(${i})`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ${a}, transform ${o}ms ${a}`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","scale(1)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-origin","","important"),e()},o)},16)})}async animateZoomHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.scale||.3,r=s.origin||"center",a=s.easing||"ease-in",o=s.duration||300;t.style.setProperty("transform-origin",r,"important"),setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ${a}, transform ${o}ms ${a}`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`scale(${i})`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-origin","","important"),e()},o)},16)})}async animateFlipShow(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.axis||"y",r=s.perspective||1e3,a=s.direction||"forward",o=s.duration||600;t.style.setProperty("transform-style","preserve-3d","important"),t.parentElement.style.setProperty("perspective",`${r}px`,"important");const n=a==="forward"?i==="x"?-90:90:i==="x"?90:-90;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate${i.toUpperCase()}(${n}deg)`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ease, transform ${o}ms cubic-bezier(0.175, 0.885, 0.32, 1.275)`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","rotateX(0deg) rotateY(0deg)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-style","","important"),t.parentElement.style.setProperty("perspective","","important"),e()},o)},16)})}async animateFlipHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.axis||"y",r=s.perspective||1e3,a=s.direction||"backward",o=s.duration||400;t.style.setProperty("transform-style","preserve-3d","important"),t.parentElement.style.setProperty("perspective",`${r}px`,"important");const n=a==="backward"?i==="x"?-90:90:i==="x"?90:-90;setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ease, transform ${o}ms ease-in`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate${i.toUpperCase()}(${n}deg)`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-style","","important"),t.parentElement.style.setProperty("perspective","","important"),e()},o)},16)})}async animateFadeShow(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.direction||"none",r=s.distance||20,a=s.duration||300;let o="translateY(0) translateX(0)";i!=="none"&&(o=i==="up"?`translateY(${r}px)`:i==="down"?`translateY(-${r}px)`:i==="left"?`translateX(${r}px)`:`translateX(-${r}px)`),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",o,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${a}ms ease, transform ${a}ms ease`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","translateY(0) translateX(0)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},a)},16)})}async animateFadeHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.direction||"none",r=s.distance||20,a=s.duration||200;let o="translateY(0) translateX(0)";i!=="none"&&(o=i==="up"?`translateY(-${r}px)`:i==="down"?`translateY(${r}px)`:i==="left"?`translateX(-${r}px)`:`translateX(${r}px)`),setTimeout(()=>{t.style.setProperty("transition",`opacity ${a}ms ease, transform ${a}ms ease`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",o,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},a)},16)})}async animateElasticShow(t,s){return new Promise(e=>{var d,m,u;t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=((d=t.parentElement)==null?void 0:d.classList.contains("editora-toast-bottom-right"))||((m=t.parentElement)==null?void 0:m.classList.contains("editora-toast-bottom-left"))||((u=t.parentElement)==null?void 0:u.classList.contains("editora-toast-bottom-center")),r=s.direction||(i?"up":"down"),a=s.intensity||"normal",o=s.duration||1e3,n=a==="gentle"?.1:a==="strong"?.3:.2,p=r==="up"?40:r==="down"?-40:r==="left"?40:-40;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",r==="left"||r==="right"?`translateX(${p}px) scale(${1+n})`:`translateY(${p}px) scale(${1+n})`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms cubic-bezier(0.68, -0.55, 0.265, 1.55), transform ${o}ms cubic-bezier(0.68, -0.55, 0.265, 1.55)`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","translateY(0) scale(1)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},o)},16)})}async animateElasticHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.intensity||"normal",r=i==="gentle"?.1:i==="strong"?.3:.2;s.duration,setTimeout(()=>{t.style.setProperty("transition","opacity 0.4s ease, transform 0.4s ease","important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`scale(${1+r})`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},400)},16)})}async animateRotateShow(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.degrees||360,r=s.direction||"clockwise",a=s.origin||"center",o=s.duration||500,n=r==="clockwise"?i:-i;t.style.setProperty("transform-origin",a,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate(${n}deg) scale(0.8)`,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ease, transform ${o}ms cubic-bezier(0.175, 0.885, 0.32, 1.275)`,"important"),t.style.setProperty("opacity","1","important"),t.style.setProperty("transform","rotate(0deg) scale(1)","important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-origin","","important"),e()},o)},16)})}async animateRotateHide(t,s){return new Promise(e=>{t.classList.add("spring-animation"),t.style.setProperty("transition","none","important");const i=s.degrees||180,r=s.direction||"counterclockwise",a=s.origin||"center",o=s.duration||300,n=r==="clockwise"?i:-i;t.style.setProperty("transform-origin",a,"important"),setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ease, transform ${o}ms ease-in`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate(${n}deg) scale(0.8)`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-origin","","important"),e()},o)},16)})}}const S=new M;class A{constructor(t){this.containers=new Map,this.cssInjected=!1,this.config=t}ensureContainer(t){if(this.containers.has(t))return this.containers.get(t);const s=document.createElement("div");s.className=`editora-toast-container editora-toast-${t.replace("-","-")}`,s.setAttribute("role","region"),s.setAttribute("aria-label","Toast notifications"),s.setAttribute("aria-live","polite");const e={position:"fixed",zIndex:(this.config.zIndex||2147483647).toString(),display:"flex",flexDirection:"column",gap:"8px",pointerEvents:"none",maxWidth:"100%",boxSizing:"border-box"};switch(t){case"top-left":e.top="16px",e.left="16px";break;case"top-right":e.top="16px",e.right="16px";break;case"bottom-left":e.bottom="16px",e.left="16px";break;case"bottom-right":e.bottom="16px",e.right="16px";break;case"center":e.top="50%",e.left="50%",e.transform="translate(-50%, -50%)",e.alignItems="center";break}return Object.assign(s.style,e),document.body.appendChild(s),this.containers.set(t,s),this.injectCSS(),s}createToastElement(t){const s=t.options,e=document.createElement("div");e.className=`editora-toast editora-toast-${s.level||"info"}`,s.customClass&&e.classList.add(s.customClass),e.setAttribute("role","alert"),e.setAttribute("aria-atomic","true");const i=s.theme||this.config.theme;i&&i!=="system"&&e.setAttribute("data-theme",i),(s.rtl!==void 0?s.rtl:this.config.rtl)&&(e.setAttribute("data-rtl","true"),e.setAttribute("dir","rtl"));const a=document.createElement("div");if(a.className="editora-toast-content",s.icon){const n=document.createElement("span");n.className="editora-toast-icon",n.textContent=s.icon,a.appendChild(n)}const o=document.createElement("span");if(o.className="editora-toast-message",s.html&&s.message)o.innerHTML=this.sanitizeHTML(s.message);else if(s.render){const n=s.render();o.appendChild(n)}else o.textContent=s.message||"";if(a.appendChild(o),s.progress){const n=document.createElement("div");n.className="editora-toast-progress";const p=document.createElement("div");if(p.className="editora-toast-progress-bar",p.style.width=`${Math.min(100,Math.max(0,s.progress.value))}%`,s.progress.showPercentage){const d=document.createElement("span");d.className="editora-toast-progress-text",d.textContent=`${Math.round(s.progress.value)}%`,n.appendChild(d)}n.appendChild(p),a.appendChild(n)}if(e.appendChild(a),s.actions&&s.actions.length>0){const n=document.createElement("div");n.className="editora-toast-actions",s.actions.forEach(p=>{const d=document.createElement("button");d.className=`editora-toast-action ${p.primary?"primary":""}`,d.textContent=p.label,d.onclick=m=>{m.stopPropagation(),p.onClick()},n.appendChild(d)}),e.appendChild(n)}if(s.closable!==!1){const n=document.createElement("button");n.className="editora-toast-close",n.setAttribute("aria-label","Close notification"),n.innerHTML="×",n.onclick=()=>t.dismiss(),e.appendChild(n)}return s.pauseOnHover&&(e.addEventListener("mouseenter",()=>this.pauseToast(t)),e.addEventListener("mouseleave",()=>this.resumeToast(t))),s.pauseOnFocus&&(e.addEventListener("focusin",()=>this.pauseToast(t)),e.addEventListener("focusout",()=>this.resumeToast(t))),s.swipeDismiss&&this.addSwipeDismiss(e,t),s.dragDismiss&&this.addDragDismiss(e,t),e}async showToast(t){var r,a;const s=this.ensureContainer(t.options.position||this.config.position),e=this.createToastElement(t);t.element=e,s.appendChild(e);const i=t.options.animation||this.config.animation||{type:"css"};if(await S.showToast(e,t,i),this.config.enableAccessibility&&this.announceToast(t),(a=(r=t.options).onShow)==null||a.call(r),!t.options.persistent&&t.options.duration!==0){const o=t.options.duration||this.config.duration;t.timeoutId=window.setTimeout(()=>{this.hideToast(t)},o)}}async hideToast(t){var e,i;if(!t.element)return;t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0);const s=t.options.animation||this.config.animation||{type:"css"};await S.hideToast(t.element,t,s),t.element&&t.element.parentNode&&(t.element.parentNode.removeChild(t.element),t.element=void 0),(i=(e=t.options).onHide)==null||i.call(e)}async updateToast(t,s){var r,a;if(!t.element)return;const e=t.options.animation||this.config.animation||{type:"css"};if(e.type==="custom"&&e.update){await S.updateToast(t.element,t,s,e);return}Object.assign(t.options,s),s.level&&(t.element.className=t.element.className.replace(/editora-toast--(info|success|error|warning|loading|custom)/g,""),t.element.classList.add(`editora-toast--${s.level}`));const i=t.element.querySelector(".editora-toast-message");if(i&&s.message!==void 0)if(t.options.html&&s.message)i.innerHTML=this.sanitizeHTML(s.message);else if(t.options.render){const o=t.element.querySelector(".editora-toast-content");if(o){const n=t.options.render();o.innerHTML="",o.appendChild(n)}}else i.textContent=s.message||"";if(s.progress!==void 0){let o=t.element.querySelector(".editora-toast-progress");if(s.progress){if(!o){o=document.createElement("div"),o.className="editora-toast-progress";const p=t.element.querySelector(".editora-toast-content");p&&p.appendChild(o)}const n=o.querySelector(".editora-toast-progress-bar");if(n&&(n.style.width=`${Math.min(100,Math.max(0,s.progress.value))}%`),s.progress.showPercentage){let p=o.querySelector(".editora-toast-progress-text");p||(p=document.createElement("span"),p.className="editora-toast-progress-text",o.insertBefore(p,o.firstChild)),p.textContent=`${Math.round(s.progress.value)}%`}else{const p=o.querySelector(".editora-toast-progress-text");p&&p.remove()}}else o&&o.remove()}if(s.actions!==void 0){let o=t.element.querySelector(".editora-toast-actions");s.actions&&s.actions.length>0?(o?o.innerHTML="":(o=document.createElement("div"),o.className="editora-toast-actions",t.element.appendChild(o)),o&&s.actions.forEach(n=>{const p=document.createElement("button");p.className=`editora-toast-action ${n.primary?"primary":""}`,p.textContent=n.label,p.onclick=d=>{d.stopPropagation(),n.onClick()},o.appendChild(p)})):o&&o.remove()}(a=(r=t.options).onUpdate)==null||a.call(r,s)}pauseToast(t){t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0)}resumeToast(t){if(!t.options.persistent&&t.options.duration!==0){const s=t.options.duration||this.config.duration;t.timeoutId=window.setTimeout(()=>{this.hideToast(t)},s)}}addSwipeDismiss(t,s){let e=0,i=0,r=!1;const a=s.options.swipeDirection||this.config.swipeDirection||"any",o=40;let n="",p=!1;const d=l=>{r=!0,p=!1,e="touches"in l?l.touches[0].clientX:l.clientX,i="touches"in l?l.touches[0].clientY:l.clientY,n=t.style.transform||"",t.style.transition="none",t.style.cursor="grabbing",l.preventDefault()},m=l=>{if(!r)return;const g="touches"in l?l.touches[0].clientX:l.clientX,b="touches"in l?l.touches[0].clientY:l.clientY,y=g-e,w=b-i,f=5;if((Math.abs(y)>f||Math.abs(w)>f)&&(p=!0),p){const v=Math.abs(w)>Math.abs(y)?25:20,P=Math.min(Math.max(y*.2,-v),v),x=Math.min(Math.max(w*.2,-v),v);t.style.transform=`${n} translate(${P}px, ${x}px)`}(Math.abs(w)>Math.abs(y)||a==="vertical"||a==="up"||a==="down")&&l.preventDefault()},u=l=>{if(!r)return;if(t.style.transform=n,t.style.transition="",t.style.cursor="",!p){r=!1;return}const g="changedTouches"in l?l.changedTouches[0].clientX:l.clientX,b="changedTouches"in l?l.changedTouches[0].clientY:l.clientY,y=g-e,w=b-i;let f=!1;const v=a==="vertical"||a==="up"||a==="down",P=v?35:o;switch(a){case"any":f=Math.abs(y)>o||Math.abs(w)>o;break;case"horizontal":f=Math.abs(y)>o;break;case"vertical":f=Math.abs(w)>P;break;case"left":f=y<-o;break;case"right":f=y>o;break;case"up":f=w<-P;break;case"down":f=w>P;break}v&&console.log(`Vertical swipe attempt: direction=${a}, deltaY=${w}, effectiveMinDistance=${P}, shouldDismiss=${f}`),f&&s.dismiss(),r=!1};t.addEventListener("dragstart",l=>l.preventDefault()),t.addEventListener("touchstart",d,{passive:!1}),t.addEventListener("touchmove",m,{passive:!1}),t.addEventListener("touchend",u,{passive:!1}),t.addEventListener("mousedown",d),t.addEventListener("mousemove",m),t.addEventListener("mouseup",u),t.addEventListener("mouseleave",u)}addDragDismiss(t,s){this.addSwipeDismiss(t,s)}announceToast(t){const s=document.createElement("div");s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true"),s.style.position="absolute",s.style.left="-10000px",s.style.width="1px",s.style.height="1px",s.style.overflow="hidden",s.textContent=`${t.options.level||"info"}: ${t.options.message}`,document.body.appendChild(s),setTimeout(()=>{document.body.removeChild(s)},1e3)}sanitizeHTML(t){const s=document.createElement("div");return s.textContent=t,s.innerHTML}injectCSS(){if(this.cssInjected||typeof document=="undefined")return;if(!Array.from(document.styleSheets).find(s=>{var e,i,r,a;return((i=(e=s.ownerNode)==null?void 0:e.href)==null?void 0:i.includes("toast.css"))||((a=(r=s.ownerNode)==null?void 0:r.textContent)==null?void 0:a.includes("editora-toast"))})){const s=document.createElement("link");s.rel="stylesheet",s.href="/packages/editora-toast/dist/toast.css",document.head.appendChild(s)}this.cssInjected=!0}destroy(){this.containers.forEach(t=>{t.parentNode&&t.parentNode.removeChild(t)}),this.containers.clear()}}class q{constructor(){this.plugins=[],this.hooks={beforeShow:[],afterShow:[],beforeHide:[],afterHide:[],beforeUpdate:[],afterUpdate:[]}}use(t){if(this.plugins.find(s=>s.name===t.name)){console.warn(`Plugin "${t.name}" is already installed`);return}this.plugins.push(t),t.install(this)}remove(t){const s=this.plugins.findIndex(i=>i.name===t);if(s===-1)return!1;const e=this.plugins[s];return e.uninstall&&e.uninstall(this),this.plugins.splice(s,1),!0}getPlugins(){return[...this.plugins]}on(t,s){this.hooks[t]&&this.hooks[t].push(s)}off(t,s){if(this.hooks[t]){const e=this.hooks[t].indexOf(s);e!==-1&&this.hooks[t].splice(e,1)}}async trigger(t,s,...e){const i=this.hooks[t];if(!(!i||i.length===0))for(const r of i)try{await r(s,...e)}catch(a){console.error(`Error in ${t} hook:`,a)}}async beforeShow(t){await this.trigger("beforeShow",t)}async afterShow(t){await this.trigger("afterShow",t)}async beforeHide(t){await this.trigger("beforeHide",t)}async afterHide(t){await this.trigger("afterHide",t)}async beforeUpdate(t,s){await this.trigger("beforeUpdate",t,s)}async afterUpdate(t,s){await this.trigger("afterUpdate",t,s)}onEditorEvent(t,s){const e=`editor:${t}`;this.hooks[e]||(this.hooks[e]=[]),this.hooks[e].push(s)}triggerEditorEvent(t,s,...e){const i=`editor:${t}`;this.trigger(i,s,...e)}async handlePromise(t,s,e,i){s();try{const r=await t;return e(r),r}catch(r){throw i(r),r}}async batchShow(t){const s=t.map(i=>this.beforeShow(i));await Promise.all(s);const e=t.map(i=>this.afterShow(i));await Promise.all(e)}async batchHide(t){const s=t.map(i=>this.beforeHide(i));await Promise.all(s);const e=t.map(i=>this.afterHide(i));await Promise.all(e)}destroy(){this.plugins.forEach(t=>{t.uninstall&&t.uninstall(this)}),this.plugins=[],Object.keys(this.hooks).forEach(t=>{this.hooks[t]=[]})}}const Y={position:"bottom-right",duration:4e3,maxVisible:5,queueStrategy:"fifo",theme:"system",pauseOnHover:!0,pauseOnFocus:!1,pauseOnWindowBlur:!1,swipeDismiss:!1,swipeDirection:"any",dragDismiss:!1,rtl:!1,enableAccessibility:!0,animation:{type:"css"}};class E{constructor(t={}){this.idCounter=0,this.pausedToasts=new Set,this.config={...Y,...t},this.store=new k(this.config),this.queue=new H(this.config),this.renderer=new A(this.config),this.lifecycle=new q,this.setupWindowFocusHandling()}show(t){const s=t.id||`toast-${++this.idCounter}`,e={id:s,options:{...this.config,...t},createdAt:Date.now(),dismiss:()=>this.dismiss(s),update:i=>this.update(s,i)};return this.lifecycle.beforeShow(e).then(async()=>{this.store.addToast(e),this.queue.enqueue(e),await this.renderer.showToast(e),this.lifecycle.afterShow(e)}),e}update(t,s){const e=this.store.getToast(t);return e?(this.lifecycle.beforeUpdate(e,s).then(async()=>{this.store.updateToast(t,{options:{...e.options,...s}}),await this.renderer.updateToast(e,s),this.lifecycle.afterUpdate(e,s)}),!0):!1}dismiss(t){const s=this.store.getToast(t);return s?(this.lifecycle.beforeHide(s).then(async()=>{this.queue.dequeue(t),await this.renderer.hideToast(s),this.store.removeToast(t),this.lifecycle.afterHide(s)}),!0):!1}clear(){const t=this.store.getAllToasts();this.lifecycle.batchHide(t).then(()=>{this.queue.clear(),this.store.clear()})}async promise(t,s){var i,r;const e=this.show(this.normalizeOptions(s.loading,"loading"));try{const a=await t,o=this.normalizeOptions(typeof s.success=="function"?s.success(a):s.success,"success");return this.update(e.id,o),(i=s.onSuccess)==null||i.call(s,a),a}catch(a){const o=this.normalizeOptions(typeof s.error=="function"?s.error(a):s.error,"error");throw this.update(e.id,o),(r=s.onError)==null||r.call(s,a),a}}group(t,s){return this.show({...s,group:t})}use(t){this.lifecycle.use(t)}configure(t){this.config={...this.config,...t},this.store.updateConfig(t),this.queue.updateConfig(t)}getConfig(){return{...this.config}}getToasts(){return this.store.getAllToasts()}getGroups(){return this.store.getAllGroups()}info(t,s){return this.show({message:t,level:"info",duration:s})}success(t,s){return this.show({message:t,level:"success",duration:s})}error(t,s){return this.show({message:t,level:"error",duration:s})}warning(t,s){return this.show({message:t,level:"warning",duration:s})}loading(t,s){return this.show({message:t,level:"loading",duration:s})}normalizeOptions(t,s){return typeof t=="string"?{message:t,level:s}:{...t,level:t.level||s}}onEditorEvent(t,s){this.lifecycle.onEditorEvent(t,s)}triggerEditorEvent(t,s,...e){this.lifecycle.triggerEditorEvent(t,s,...e)}setupWindowFocusHandling(){typeof window=="undefined"||!this.config.pauseOnWindowBlur||(this.windowBlurHandler=()=>this.pauseAllToasts(),this.windowFocusHandler=()=>this.resumeAllToasts(),window.addEventListener("blur",this.windowBlurHandler),window.addEventListener("focus",this.windowFocusHandler),document.addEventListener("visibilitychange",()=>{document.hidden?this.pauseAllToasts():this.resumeAllToasts()}))}pauseAllToasts(){this.store.getAllToasts().forEach(s=>{s.timeoutId&&!this.pausedToasts.has(s.id)&&(clearTimeout(s.timeoutId),s.timeoutId=void 0,this.pausedToasts.add(s.id))})}resumeAllToasts(){this.store.getAllToasts().forEach(s=>{if(this.pausedToasts.has(s.id)&&!s.options.persistent&&s.options.duration!==0){const e=s.options.duration||this.config.duration;s.timeoutId=window.setTimeout(()=>{this.dismiss(s.id)},e),this.pausedToasts.delete(s.id)}})}destroy(){this.windowBlurHandler&&typeof window!="undefined"&&window.removeEventListener("blur",this.windowBlurHandler),this.windowFocusHandler&&typeof window!="undefined"&&window.removeEventListener("focus",this.windowFocusHandler),this.clear(),this.renderer.destroy(),this.lifecycle.destroy()}}const h=new E;function C(c){return typeof document=="undefined"?{dismiss:()=>{}}:h.show(c)}const $={info:(c,t)=>C({message:c,level:"info",duration:t}),success:(c,t)=>C({message:c,level:"success",duration:t}),error:(c,t)=>C({message:c,level:"error",duration:t})},T={show:c=>h.show(c),update:(c,t)=>h.update(c,t),dismiss:c=>h.dismiss(c),clear:()=>h.clear(),info:(c,t)=>h.show({message:c,level:"info",...t}),success:(c,t)=>h.show({message:c,level:"success",...t}),error:(c,t)=>h.show({message:c,level:"error",...t}),warning:(c,t)=>h.show({message:c,level:"warning",...t}),loading:(c,t)=>h.show({message:c,level:"loading",...t}),promise:(c,t)=>h.promise(c,t),group:(c,t)=>h.group(c,t),configure:c=>h.configure(c),use:c=>h.use(c),getToasts:()=>h.getToasts(),getGroups:()=>h.getGroups(),getConfig:()=>h.getConfig(),onEditorEvent:(c,t)=>h.onEditorEvent(c,t),triggerEditorEvent:(c,t,...s)=>h.triggerEditorEvent(c,t,...s),destroy:()=>h.destroy()};typeof window!="undefined"&&typeof document!="undefined"&&(window.toast=$,window.toastAdvanced=T,window.toastPro=T,window.ToastManager=E,window.dispatchEvent(new CustomEvent("toastReady",{detail:{toast:$,toastAdvanced:T,toastPro:T,ToastManager:E}})));exports.ToastManager=E;exports.default=$;exports.toast=$;exports.toastAdvanced=T;exports.toastPro=T;
2
+ //# sourceMappingURL=index.cjs.js.map