@editora/toast 2.0.0 → 2.0.1
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.
- package/README.md +28 -26
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.esm.js +79 -65
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -109,11 +109,11 @@ You can also use Editora Toast directly from a CDN without installing it via npm
|
|
|
109
109
|
<script src="https://cdn.jsdelivr.net/npm/@editora/toast@latest/dist/index.umd.js"></script>
|
|
110
110
|
|
|
111
111
|
<script>
|
|
112
|
-
// Now you can use the toast functions
|
|
113
|
-
toast.success('Hello from CDN!');
|
|
114
|
-
toast.error('Something went wrong!', 1000);
|
|
115
|
-
toast.info('This is an info message');
|
|
116
|
-
toast.warning('This is a warning');
|
|
112
|
+
// Now you can use the toast functions (legacy API supports an optional options object)
|
|
113
|
+
toast.success('Hello from CDN!', { theme: 'light', position: 'top-right' });
|
|
114
|
+
toast.error('Something went wrong!', { duration: 1000 });
|
|
115
|
+
toast.info('This is an info message', { theme: 'light', position: 'top-right' });
|
|
116
|
+
toast.warning('This is a warning', { theme: 'light', position: 'top-right' });
|
|
117
117
|
|
|
118
118
|
// Advanced usage (toastAdvanced, toastPro)
|
|
119
119
|
// global window.toastPro.show()
|
|
@@ -154,19 +154,20 @@ You can also use Editora Toast directly from a CDN without installing it via npm
|
|
|
154
154
|
|
|
155
155
|
```typescript
|
|
156
156
|
import { toast } from '@editora/toast';
|
|
157
|
+
import "@editora/toast/toast.css";
|
|
157
158
|
|
|
158
|
-
// Simple notifications
|
|
159
|
-
toast.success('File saved successfully!');
|
|
160
|
-
toast.error('Failed to save file');
|
|
161
|
-
toast.info('Info message');
|
|
162
|
-
toast.warning('Warning message');
|
|
159
|
+
// Simple notifications (migrated to optional advanced options)
|
|
160
|
+
toast.success('File saved successfully!', { theme: 'light', position: 'top-right' });
|
|
161
|
+
toast.error('Failed to save file', { theme: 'light', position: 'top-right' });
|
|
162
|
+
toast.info('Info message', { theme: 'light', position: 'top-right' });
|
|
163
|
+
toast.warning('Warning message', { theme: 'light', position: 'top-right' });
|
|
163
164
|
```
|
|
164
165
|
|
|
165
166
|
### Advanced Usage (v2.0.0 Features)
|
|
166
167
|
|
|
167
168
|
```typescript
|
|
168
169
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
169
|
-
|
|
170
|
+
import "@editora/toast/toast.css";
|
|
170
171
|
// Rich notifications with actions and progress
|
|
171
172
|
const notification = toast.show({
|
|
172
173
|
message: 'Document uploaded successfully!',
|
|
@@ -218,7 +219,7 @@ toast.group('file-operations', {
|
|
|
218
219
|
|
|
219
220
|
```typescript
|
|
220
221
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
221
|
-
|
|
222
|
+
import "@editora/toast/toast.css";
|
|
222
223
|
// Global configuration with all available options
|
|
223
224
|
toast.configure({
|
|
224
225
|
// Positioning
|
|
@@ -290,7 +291,7 @@ Editora Toast comes with 13 beautiful themes:
|
|
|
290
291
|
|
|
291
292
|
```typescript
|
|
292
293
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
293
|
-
|
|
294
|
+
import "@editora/toast/toast.css";
|
|
294
295
|
// Set global theme
|
|
295
296
|
toast.configure({
|
|
296
297
|
theme: 'glass' // or 'neon', 'retro', 'ocean', etc.
|
|
@@ -374,7 +375,7 @@ Add interactive buttons to your toasts:
|
|
|
374
375
|
|
|
375
376
|
```typescript
|
|
376
377
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
377
|
-
|
|
378
|
+
import "@editora/toast/toast.css";
|
|
378
379
|
const notification = toast.show({
|
|
379
380
|
message: 'Document saved successfully!',
|
|
380
381
|
level: 'success',
|
|
@@ -407,7 +408,7 @@ Built-in progress bars with customizable display:
|
|
|
407
408
|
|
|
408
409
|
```typescript
|
|
409
410
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
410
|
-
|
|
411
|
+
import "@editora/toast/toast.css";
|
|
411
412
|
// Determinate progress
|
|
412
413
|
const progressToast = toast.show({
|
|
413
414
|
message: 'Processing files...',
|
|
@@ -446,7 +447,7 @@ Modify existing toasts dynamically:
|
|
|
446
447
|
|
|
447
448
|
```typescript
|
|
448
449
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
449
|
-
|
|
450
|
+
import "@editora/toast/toast.css";
|
|
450
451
|
// Create a loading toast
|
|
451
452
|
const loadingToast = toast.loading('Connecting to server...');
|
|
452
453
|
|
|
@@ -477,7 +478,7 @@ Group related notifications together:
|
|
|
477
478
|
|
|
478
479
|
```typescript
|
|
479
480
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
480
|
-
|
|
481
|
+
import "@editora/toast/toast.css";
|
|
481
482
|
// Group file operations
|
|
482
483
|
const files = ['document.pdf', 'image.jpg', 'data.json'];
|
|
483
484
|
|
|
@@ -513,7 +514,7 @@ Create interactive forms within toasts:
|
|
|
513
514
|
|
|
514
515
|
```typescript
|
|
515
516
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
516
|
-
|
|
517
|
+
import "@editora/toast/toast.css";
|
|
517
518
|
toast.show({
|
|
518
519
|
message: 'How was your experience?',
|
|
519
520
|
level: 'info',
|
|
@@ -548,7 +549,7 @@ toast.show({
|
|
|
548
549
|
|
|
549
550
|
```typescript
|
|
550
551
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
551
|
-
|
|
552
|
+
import "@editora/toast/toast.css";
|
|
552
553
|
const myPlugin = {
|
|
553
554
|
name: 'my-plugin',
|
|
554
555
|
install(manager) {
|
|
@@ -577,7 +578,7 @@ toast.show({
|
|
|
577
578
|
|
|
578
579
|
```typescript
|
|
579
580
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
580
|
-
|
|
581
|
+
import "@editora/toast/toast.css";
|
|
581
582
|
// Spring animation with custom physics
|
|
582
583
|
toast.show({
|
|
583
584
|
message: 'Spring animated toast!',
|
|
@@ -598,7 +599,7 @@ toast.show({
|
|
|
598
599
|
|
|
599
600
|
```typescript
|
|
600
601
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
601
|
-
|
|
602
|
+
import "@editora/toast/toast.css";
|
|
602
603
|
// Custom animation functions
|
|
603
604
|
toast.show({
|
|
604
605
|
message: 'Custom animated toast!',
|
|
@@ -642,7 +643,7 @@ toast.show({
|
|
|
642
643
|
|
|
643
644
|
```typescript
|
|
644
645
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
645
|
-
|
|
646
|
+
import "@editora/toast/toast.css";
|
|
646
647
|
// Set default animation for all toasts
|
|
647
648
|
toast.configure({
|
|
648
649
|
animation: {
|
|
@@ -683,10 +684,10 @@ toast.show({
|
|
|
683
684
|
|
|
684
685
|
```typescript
|
|
685
686
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
686
|
-
|
|
687
|
+
import "@editora/toast/toast.css";
|
|
687
688
|
// Listen for editor events
|
|
688
689
|
toast.onEditorEvent('spellcheck-error', (error) => {
|
|
689
|
-
toast.error(`Spelling error: ${error.word}
|
|
690
|
+
toast.error(`Spelling error: ${error.word}`, { theme: 'light', position: 'top-right' });
|
|
690
691
|
});
|
|
691
692
|
|
|
692
693
|
// Trigger editor events
|
|
@@ -855,11 +856,12 @@ The v2.0.0 release introduces powerful new features while maintaining **full bac
|
|
|
855
856
|
```typescript
|
|
856
857
|
// v1.x (still works)
|
|
857
858
|
import { toast } from '@editora/toast';
|
|
858
|
-
toast.
|
|
859
|
+
import "@editora/toast/toast.css";
|
|
860
|
+
toast.success('Hello World', { theme: 'light', position: 'top-right' });
|
|
859
861
|
|
|
860
862
|
// v2.0.0 advanced features
|
|
861
863
|
import { toastAdvanced as toast } from '@editora/toast';
|
|
862
|
-
|
|
864
|
+
import "@editora/toast/toast.css";
|
|
863
865
|
// Promise lifecycle toasts
|
|
864
866
|
toast.promise(fetchData(), {
|
|
865
867
|
loading: 'Loading...',
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +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;
|
|
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 M{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 n={...this.config,...r};let o,a=!1;const l=Object.keys(s).reduce((u,p)=>(u[p]=s[p].from,u),{}),d=Object.keys(s).reduce((u,p)=>(u[p]=0,u),{}),m=()=>{if(a)return;let u=!0;Object.keys(s).forEach(g=>{const b=s[g].to,y=l[g],w=d[g],f=-n.stiffness*(y-b),v=-n.damping*w,C=(f+v)/n.mass;d[g]+=C*.016,l[g]+=d[g]*.016,(Math.abs(y-b)>n.precision||Math.abs(w)>n.precision)&&(u=!1)});const p=Object.keys(l).reduce((g,b)=>{const y=s[b].unit||"px";return g[b]=`${l[b]}${y}`,g},{});e(p),u?(a=!0,i==null||i()):o=requestAnimationFrame(m)};return o=requestAnimationFrame(m),()=>{a=!0,o&&cancelAnimationFrame(o)}}}class A{constructor(){this.springAnimation=new M}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 n,o,a;t.classList.add("spring-animation"),t.style.setProperty("transition","none","important"),t.style.setProperty("-webkit-transition","none","important");const r=((n=t.parentElement)==null?void 0:n.classList.contains("editora-toast-bottom-right"))||((o=t.parentElement)==null?void 0:o.classList.contains("editora-toast-bottom-left"))||((a=t.parentElement)==null?void 0:a.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"),n=s.intensity||"normal",o=s.duration||800,a=n==="gentle"?.05:n==="strong"?.15:.1,l=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(${l}px) scale(${1-a})`:`translateY(${l}px) scale(${1-a})`,"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"),n=s.distance||100,o=s.easing||"ease-out",a=s.duration||400,l=r==="up"?`translateY(${n}px)`:r==="down"?`translateY(-${n}px)`:r==="left"?`translateX(${n}px)`:`translateX(-${n}px)`;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",l,"important"),t.offsetHeight,setTimeout(()=>{t.style.setProperty("transition",`opacity ${a}ms ${o}, transform ${a}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()},a)},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,n=s.easing||"ease-in",o=s.duration||300,a=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 ${n}, transform ${o}ms ${n}`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",a,"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",n=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 ${n}, transform ${o}ms ${n}`,"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",n=s.easing||"ease-in",o=s.duration||300;t.style.setProperty("transform-origin",r,"important"),setTimeout(()=>{t.style.setProperty("transition",`opacity ${o}ms ${n}, transform ${o}ms ${n}`,"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,n=s.direction||"forward",o=s.duration||600;t.style.setProperty("transform-style","preserve-3d","important"),t.parentElement.style.setProperty("perspective",`${r}px`,"important");const a=n==="forward"?i==="x"?-90:90:i==="x"?90:-90;t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate${i.toUpperCase()}(${a}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,n=s.direction||"backward",o=s.duration||400;t.style.setProperty("transform-style","preserve-3d","important"),t.parentElement.style.setProperty("perspective",`${r}px`,"important");const a=n==="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()}(${a}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,n=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 ${n}ms ease, transform ${n}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()},n)},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,n=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 ${n}ms ease, transform ${n}ms ease`,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",o,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),e()},n)},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"),n=s.intensity||"normal",o=s.duration||1e3,a=n==="gentle"?.1:n==="strong"?.3:.2,l=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(${l}px) scale(${1+a})`:`translateY(${l}px) scale(${1+a})`,"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",n=s.origin||"center",o=s.duration||500,a=r==="clockwise"?i:-i;t.style.setProperty("transform-origin",n,"important"),t.style.setProperty("opacity","0","important"),t.style.setProperty("transform",`rotate(${a}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",n=s.origin||"center",o=s.duration||300,a=r==="clockwise"?i:-i;t.style.setProperty("transform-origin",n,"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(${a}deg) scale(0.8)`,"important"),setTimeout(()=>{t.style.setProperty("transition","none","important"),t.style.setProperty("transform-origin","","important"),e()},o)},16)})}}const L=new A;class q{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 n=document.createElement("div");if(n.className="editora-toast-content",s.icon){const a=document.createElement("span");a.className="editora-toast-icon",a.textContent=s.icon,n.appendChild(a)}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 a=s.render();o.appendChild(a)}else o.textContent=s.message||"";if(n.appendChild(o),s.progress){const a=document.createElement("div");a.className="editora-toast-progress";const l=document.createElement("div");if(l.className="editora-toast-progress-bar",l.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)}%`,a.appendChild(d)}a.appendChild(l),n.appendChild(a)}if(e.appendChild(n),s.actions&&s.actions.length>0){const a=document.createElement("div");a.className="editora-toast-actions",s.actions.forEach(l=>{const d=document.createElement("button");d.className=`editora-toast-action ${l.primary?"primary":""}`,d.textContent=l.label,d.onclick=m=>{m.stopPropagation(),l.onClick()},a.appendChild(d)}),e.appendChild(a)}if(s.closable!==!1){const a=document.createElement("button");a.className="editora-toast-close",a.setAttribute("aria-label","Close notification"),a.innerHTML="×",a.onclick=()=>t.dismiss(),e.appendChild(a)}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,n;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 L.showToast(e,t,i),this.config.enableAccessibility&&this.announceToast(t),(n=(r=t.options).onShow)==null||n.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 L.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,n;if(!t.element)return;const e=t.options.animation||this.config.animation||{type:"css"};if(e.type==="custom"&&e.update){await L.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 a=t.options.render();o.innerHTML="",o.appendChild(a)}}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 l=t.element.querySelector(".editora-toast-content");l&&l.appendChild(o)}const a=o.querySelector(".editora-toast-progress-bar");if(a&&(a.style.width=`${Math.min(100,Math.max(0,s.progress.value))}%`),s.progress.showPercentage){let l=o.querySelector(".editora-toast-progress-text");l||(l=document.createElement("span"),l.className="editora-toast-progress-text",o.insertBefore(l,o.firstChild)),l.textContent=`${Math.round(s.progress.value)}%`}else{const l=o.querySelector(".editora-toast-progress-text");l&&l.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(a=>{const l=document.createElement("button");l.className=`editora-toast-action ${a.primary?"primary":""}`,l.textContent=a.label,l.onclick=d=>{d.stopPropagation(),a.onClick()},o.appendChild(l)})):o&&o.remove()}(n=(r=t.options).onUpdate)==null||n.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 n=s.options.swipeDirection||this.config.swipeDirection||"any",o=40;let a="",l=!1;const d=p=>{r=!0,l=!1,e="touches"in p?p.touches[0].clientX:p.clientX,i="touches"in p?p.touches[0].clientY:p.clientY,a=t.style.transform||"",t.style.transition="none",t.style.cursor="grabbing",p.preventDefault()},m=p=>{if(!r)return;const g="touches"in p?p.touches[0].clientX:p.clientX,b="touches"in p?p.touches[0].clientY:p.clientY,y=g-e,w=b-i,f=5;if((Math.abs(y)>f||Math.abs(w)>f)&&(l=!0),l){const v=Math.abs(w)>Math.abs(y)?25:20,P=Math.min(Math.max(y*.2,-v),v),C=Math.min(Math.max(w*.2,-v),v);t.style.transform=`${a} translate(${P}px, ${C}px)`}(Math.abs(w)>Math.abs(y)||n==="vertical"||n==="up"||n==="down")&&p.preventDefault()},u=p=>{if(!r)return;if(t.style.transform=a,t.style.transition="",t.style.cursor="",!l){r=!1;return}const g="changedTouches"in p?p.changedTouches[0].clientX:p.clientX,b="changedTouches"in p?p.changedTouches[0].clientY:p.clientY,y=g-e,w=b-i;let f=!1;const v=n==="vertical"||n==="up"||n==="down",P=v?35:o;switch(n){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=${n}, deltaY=${w}, effectiveMinDistance=${P}, shouldDismiss=${f}`),f&&s.dismiss(),r=!1};t.addEventListener("dragstart",p=>p.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,n;return((i=(e=s.ownerNode)==null?void 0:e.href)==null?void 0:i.includes("toast.css"))||((n=(r=s.ownerNode)==null?void 0:r.textContent)==null?void 0:n.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 Y{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(n){console.error(`Error in ${t} hook:`,n)}}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 X={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 x{constructor(t={}){this.idCounter=0,this.pausedToasts=new Set,this.config={...X,...t},this.store=new k(this.config),this.queue=new H(this.config),this.renderer=new q(this.config),this.lifecycle=new Y,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 n=await t,o=this.normalizeOptions(typeof s.success=="function"?s.success(n):s.success,"success");return this.update(e.id,o),(i=s.onSuccess)==null||i.call(s,n),n}catch(n){const o=this.normalizeOptions(typeof s.error=="function"?s.error(n):s.error,"error");throw this.update(e.id,o),(r=s.onError)==null||r.call(s,n),n}}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 x;function E(c){return typeof document=="undefined"?{dismiss:()=>{}}:h.show(c)}function $(c,t,s,e){const i={position:"top-right",theme:"light"};let r={};return t&&typeof t=="object"?r={...t}:typeof t=="number"&&(r.duration=t),s&&(r.theme=s),e&&(r.position=e),{message:c,...r,duration:r.duration,level:r.level||void 0,position:r.position||i.position,theme:r.theme||i.theme}}const S={info:(c,t,s,e)=>E({...$(c,t,s,e),level:"info"}),success:(c,t,s,e)=>E({...$(c,t,s,e),level:"success"}),error:(c,t,s,e)=>E({...$(c,t,s,e),level:"error"}),warning:(c,t,s,e)=>E({...$(c,t,s,e),level:"warning"}),loading:(c,t,s,e)=>E({...$(c,t,s,e),level:"loading"})},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=S,window.toastAdvanced=T,window.toastPro=T,window.ToastManager=x,window.dispatchEvent(new CustomEvent("toastReady",{detail:{toast:S,toastAdvanced:T,toastPro:T,ToastManager:x}})));exports.ToastManager=x;exports.default=S;exports.toast=S;exports.toastAdvanced=T;exports.toastPro=T;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|