@editora/toast 1.0.2 → 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.
Files changed (51) hide show
  1. package/README.md +904 -8
  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 +39 -10
  12. package/dist/index.esm.js +1075 -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 +50 -13
  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,1075 @@
1
+ class k {
2
+ constructor(t) {
3
+ this.toasts = /* @__PURE__ */ new Map(), this.groups = /* @__PURE__ */ new Map(), this.containers = /* @__PURE__ */ new Map(), this.config = { ...t };
4
+ }
5
+ // Toast management
6
+ addToast(t) {
7
+ this.toasts.set(t.id, t), this.updateGroup(t);
8
+ }
9
+ removeToast(t) {
10
+ const s = this.toasts.get(t);
11
+ return s ? (this.toasts.delete(t), this.updateGroup(s), !0) : !1;
12
+ }
13
+ getToast(t) {
14
+ return this.toasts.get(t);
15
+ }
16
+ getAllToasts() {
17
+ return Array.from(this.toasts.values());
18
+ }
19
+ getToastsByPosition(t) {
20
+ return this.getAllToasts().filter((s) => s.options.position === t);
21
+ }
22
+ updateToast(t, s) {
23
+ const e = this.toasts.get(t);
24
+ return e ? (Object.assign(e, s), this.updateGroup(e), !0) : !1;
25
+ }
26
+ // Group management
27
+ updateGroup(t) {
28
+ const s = t.options.group;
29
+ if (!s)
30
+ return;
31
+ let e = this.groups.get(s);
32
+ 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);
33
+ }
34
+ getGroup(t) {
35
+ return this.groups.get(t);
36
+ }
37
+ getAllGroups() {
38
+ return Array.from(this.groups.values());
39
+ }
40
+ // Container management
41
+ getContainer(t) {
42
+ return this.containers.get(t);
43
+ }
44
+ setContainer(t, s) {
45
+ this.containers.set(t, s);
46
+ }
47
+ removeContainer(t) {
48
+ return this.containers.delete(t);
49
+ }
50
+ getAllContainers() {
51
+ return new Map(this.containers);
52
+ }
53
+ // Configuration
54
+ getConfig() {
55
+ return { ...this.config };
56
+ }
57
+ updateConfig(t) {
58
+ this.config = { ...this.config, ...t };
59
+ }
60
+ // Cleanup
61
+ clear() {
62
+ this.toasts.clear(), this.groups.clear();
63
+ }
64
+ // Statistics
65
+ getStats() {
66
+ return {
67
+ totalToasts: this.toasts.size,
68
+ totalGroups: this.groups.size,
69
+ toastsByPosition: Object.fromEntries(
70
+ Array.from(this.containers.keys()).map((t) => [
71
+ t,
72
+ this.getToastsByPosition(t).length
73
+ ])
74
+ )
75
+ };
76
+ }
77
+ }
78
+ class H {
79
+ constructor(t) {
80
+ this.queue = [], this.visible = [], this.config = t;
81
+ }
82
+ // Add toast to queue
83
+ enqueue(t) {
84
+ 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();
85
+ }
86
+ // Remove toast from queue/visible
87
+ dequeue(t) {
88
+ let s = !1;
89
+ const e = this.queue.findIndex((r) => r.id === t);
90
+ e !== -1 && (this.queue.splice(e, 1), s = !0);
91
+ const i = this.visible.findIndex((r) => r.id === t);
92
+ return i !== -1 && (this.visible.splice(i, 1), s = !0), s && this.processQueue(), s;
93
+ }
94
+ // Process queue to show toasts within limits
95
+ processQueue() {
96
+ const t = this.config.maxVisible;
97
+ for (; this.visible.length > t; ) {
98
+ const s = this.visible.pop();
99
+ this.hideToast(s);
100
+ }
101
+ for (; this.visible.length < t && this.queue.length > 0; ) {
102
+ const s = this.queue.shift();
103
+ this.showToast(s);
104
+ }
105
+ }
106
+ showToast(t) {
107
+ this.visible.push(t);
108
+ }
109
+ hideToast(t) {
110
+ }
111
+ // Deduplicate toasts with same message and level
112
+ deduplicate(t) {
113
+ this.queue.filter(
114
+ (e) => e.options.message === t.options.message && e.options.level === t.options.level
115
+ ).forEach((e) => {
116
+ const i = this.queue.indexOf(e);
117
+ i !== -1 && this.queue.splice(i, 1);
118
+ });
119
+ }
120
+ // Update configuration
121
+ updateConfig(t) {
122
+ this.config = { ...this.config, ...t }, this.processQueue();
123
+ }
124
+ // Get current state
125
+ getQueued() {
126
+ return [...this.queue];
127
+ }
128
+ getVisible() {
129
+ return [...this.visible];
130
+ }
131
+ getAll() {
132
+ return [...this.visible, ...this.queue];
133
+ }
134
+ // Clear all
135
+ clear() {
136
+ const t = [...this.visible, ...this.queue];
137
+ this.queue = [], this.visible = [], t.forEach((s) => {
138
+ s.element && this.hideToast(s);
139
+ });
140
+ }
141
+ // Force show a high-priority toast (bypass queue)
142
+ forceShow(t) {
143
+ if (this.visible.length >= this.config.maxVisible) {
144
+ const s = this.visible.reduce(
145
+ (e, i) => (i.options.priority || 0) < (e.options.priority || 0) ? i : e
146
+ );
147
+ this.dequeue(s.id);
148
+ }
149
+ this.showToast(t);
150
+ }
151
+ }
152
+ class A {
153
+ constructor(t = {}) {
154
+ var s, e, i, r;
155
+ this.config = {
156
+ stiffness: (s = t.stiffness) != null ? s : 100,
157
+ damping: (e = t.damping) != null ? e : 10,
158
+ mass: (i = t.mass) != null ? i : 1,
159
+ precision: (r = t.precision) != null ? r : 0.01
160
+ };
161
+ }
162
+ // Spring animation function
163
+ animate(t, s, e, i, r) {
164
+ const n = {
165
+ ...this.config,
166
+ ...r
167
+ };
168
+ let o, a = !1;
169
+ 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 = () => {
170
+ if (a)
171
+ return;
172
+ let u = !0;
173
+ Object.keys(s).forEach((g) => {
174
+ const b = s[g].to, y = l[g], w = d[g], f = -n.stiffness * (y - b), v = -n.damping * w, x = (f + v) / n.mass;
175
+ d[g] += x * 0.016, l[g] += d[g] * 0.016, (Math.abs(y - b) > n.precision || Math.abs(w) > n.precision) && (u = !1);
176
+ });
177
+ const p = Object.keys(l).reduce((g, b) => {
178
+ const y = s[b].unit || "px";
179
+ return g[b] = `${l[b]}${y}`, g;
180
+ }, {});
181
+ e(p), u ? (a = !0, i == null || i()) : o = requestAnimationFrame(m);
182
+ };
183
+ return o = requestAnimationFrame(m), () => {
184
+ a = !0, o && cancelAnimationFrame(o);
185
+ };
186
+ }
187
+ }
188
+ class M {
189
+ constructor() {
190
+ this.springAnimation = new A();
191
+ }
192
+ // Show toast with specified animation
193
+ async showToast(t, s, e) {
194
+ switch (e.type) {
195
+ case "spring":
196
+ await this.animateSpringShow(t, e);
197
+ break;
198
+ case "bounce":
199
+ await this.animateBounceShow(t, e);
200
+ break;
201
+ case "slide":
202
+ await this.animateSlideShow(t, e);
203
+ break;
204
+ case "zoom":
205
+ await this.animateZoomShow(t, e);
206
+ break;
207
+ case "flip":
208
+ await this.animateFlipShow(t, e);
209
+ break;
210
+ case "fade":
211
+ await this.animateFadeShow(t, e);
212
+ break;
213
+ case "elastic":
214
+ await this.animateElasticShow(t, e);
215
+ break;
216
+ case "rotate":
217
+ await this.animateRotateShow(t, e);
218
+ break;
219
+ case "custom":
220
+ e.show ? await Promise.resolve(e.show(t, s)) : this.animateCssShow(t);
221
+ break;
222
+ case "css":
223
+ default:
224
+ this.animateCssShow(t);
225
+ break;
226
+ }
227
+ }
228
+ // Hide toast with specified animation
229
+ async hideToast(t, s, e) {
230
+ switch (e.type) {
231
+ case "spring":
232
+ await this.animateSpringHide(t, e);
233
+ break;
234
+ case "bounce":
235
+ await this.animateBounceHide(t, e);
236
+ break;
237
+ case "slide":
238
+ await this.animateSlideHide(t, e);
239
+ break;
240
+ case "zoom":
241
+ await this.animateZoomHide(t, e);
242
+ break;
243
+ case "flip":
244
+ await this.animateFlipHide(t, e);
245
+ break;
246
+ case "fade":
247
+ await this.animateFadeHide(t, e);
248
+ break;
249
+ case "elastic":
250
+ await this.animateElasticHide(t, e);
251
+ break;
252
+ case "rotate":
253
+ await this.animateRotateHide(t, e);
254
+ break;
255
+ case "custom":
256
+ e.hide ? await Promise.resolve(e.hide(t, s)) : this.animateCssHide(t);
257
+ break;
258
+ case "css":
259
+ default:
260
+ this.animateCssHide(t);
261
+ break;
262
+ }
263
+ }
264
+ // Update toast with specified animation
265
+ async updateToast(t, s, e, i) {
266
+ i.type === "custom" && i.update && await Promise.resolve(i.update(t, s, e));
267
+ }
268
+ // CSS-based show animation (existing behavior)
269
+ animateCssShow(t) {
270
+ requestAnimationFrame(() => {
271
+ t.classList.add("show");
272
+ });
273
+ }
274
+ // CSS-based hide animation (existing behavior)
275
+ animateCssHide(t) {
276
+ t.classList.remove("show"), t.classList.add("hiding");
277
+ }
278
+ // Spring-based show animation
279
+ async animateSpringShow(t, s) {
280
+ return new Promise((e) => {
281
+ var n, o, a;
282
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important"), t.style.setProperty("-webkit-transition", "none", "important");
283
+ 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;
284
+ t.style.setProperty("opacity", "0", "important"), t.style.setProperty("transform", `translateY(${r}px) scale(0.95)`, "important"), t.offsetHeight, setTimeout(() => {
285
+ 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(() => {
286
+ t.style.setProperty("transition", "none", "important"), e();
287
+ }, 800);
288
+ }, 16);
289
+ });
290
+ }
291
+ // Spring-based hide animation
292
+ async animateSpringHide(t, s) {
293
+ return new Promise((e) => {
294
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important"), t.style.setProperty("-webkit-transition", "none", "important"), setTimeout(() => {
295
+ 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(() => {
296
+ t.style.setProperty("transition", "none", "important"), e();
297
+ }, 400);
298
+ }, 16);
299
+ });
300
+ }
301
+ // Bounce-based show animation
302
+ async animateBounceShow(t, s) {
303
+ return new Promise((e) => {
304
+ var d, m, u;
305
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
306
+ 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" ? 0.05 : n === "strong" ? 0.15 : 0.1, l = r === "up" ? 30 : r === "down" ? -30 : r === "left" ? 30 : -30;
307
+ t.style.setProperty("opacity", "0", "important"), t.style.setProperty(
308
+ "transform",
309
+ r === "left" || r === "right" ? `translateX(${l}px) scale(${1 - a})` : `translateY(${l}px) scale(${1 - a})`,
310
+ "important"
311
+ ), t.offsetHeight, setTimeout(() => {
312
+ t.style.setProperty(
313
+ "transition",
314
+ `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)`,
315
+ "important"
316
+ ), t.style.setProperty("opacity", "1", "important"), t.style.setProperty("transform", "translateY(0) scale(1)", "important"), setTimeout(() => {
317
+ t.style.setProperty("transition", "none", "important"), e();
318
+ }, o);
319
+ }, 16);
320
+ });
321
+ }
322
+ // Bounce-based hide animation
323
+ async animateBounceHide(t, s) {
324
+ return new Promise((e) => {
325
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
326
+ const i = s.intensity || "normal", r = i === "gentle" ? 0.05 : i === "strong" ? 0.15 : 0.1;
327
+ setTimeout(() => {
328
+ 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(() => {
329
+ t.style.setProperty("transition", "none", "important"), e();
330
+ }, 400);
331
+ }, 16);
332
+ });
333
+ }
334
+ // Slide-based show animation
335
+ async animateSlideShow(t, s) {
336
+ return new Promise((e) => {
337
+ var d, m, u;
338
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
339
+ 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)`;
340
+ t.style.setProperty("opacity", "0", "important"), t.style.setProperty("transform", l, "important"), t.offsetHeight, setTimeout(() => {
341
+ 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(() => {
342
+ t.style.setProperty("transition", "none", "important"), e();
343
+ }, a);
344
+ }, 16);
345
+ });
346
+ }
347
+ // Slide-based hide animation
348
+ async animateSlideHide(t, s) {
349
+ return new Promise((e) => {
350
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
351
+ 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)`;
352
+ setTimeout(() => {
353
+ 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(() => {
354
+ t.style.setProperty("transition", "none", "important"), e();
355
+ }, o);
356
+ }, 16);
357
+ });
358
+ }
359
+ // Zoom-based show animation
360
+ async animateZoomShow(t, s) {
361
+ return new Promise((e) => {
362
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
363
+ const i = s.scale || 0.3, r = s.origin || "center", n = s.easing || "ease-out", o = s.duration || 500;
364
+ t.style.setProperty("transform-origin", r, "important"), t.style.setProperty("opacity", "0", "important"), t.style.setProperty("transform", `scale(${i})`, "important"), t.offsetHeight, setTimeout(() => {
365
+ 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(() => {
366
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-origin", "", "important"), e();
367
+ }, o);
368
+ }, 16);
369
+ });
370
+ }
371
+ // Zoom-based hide animation
372
+ async animateZoomHide(t, s) {
373
+ return new Promise((e) => {
374
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
375
+ const i = s.scale || 0.3, r = s.origin || "center", n = s.easing || "ease-in", o = s.duration || 300;
376
+ t.style.setProperty("transform-origin", r, "important"), setTimeout(() => {
377
+ 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(() => {
378
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-origin", "", "important"), e();
379
+ }, o);
380
+ }, 16);
381
+ });
382
+ }
383
+ // Flip-based show animation
384
+ async animateFlipShow(t, s) {
385
+ return new Promise((e) => {
386
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
387
+ const i = s.axis || "y", r = s.perspective || 1e3, n = s.direction || "forward", o = s.duration || 600;
388
+ t.style.setProperty("transform-style", "preserve-3d", "important"), t.parentElement.style.setProperty("perspective", `${r}px`, "important");
389
+ const a = n === "forward" ? i === "x" ? -90 : 90 : i === "x" ? 90 : -90;
390
+ t.style.setProperty("opacity", "0", "important"), t.style.setProperty("transform", `rotate${i.toUpperCase()}(${a}deg)`, "important"), t.offsetHeight, setTimeout(() => {
391
+ 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(() => {
392
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-style", "", "important"), t.parentElement.style.setProperty("perspective", "", "important"), e();
393
+ }, o);
394
+ }, 16);
395
+ });
396
+ }
397
+ // Flip-based hide animation
398
+ async animateFlipHide(t, s) {
399
+ return new Promise((e) => {
400
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
401
+ const i = s.axis || "y", r = s.perspective || 1e3, n = s.direction || "backward", o = s.duration || 400;
402
+ t.style.setProperty("transform-style", "preserve-3d", "important"), t.parentElement.style.setProperty("perspective", `${r}px`, "important");
403
+ const a = n === "backward" ? i === "x" ? -90 : 90 : i === "x" ? 90 : -90;
404
+ setTimeout(() => {
405
+ 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(() => {
406
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-style", "", "important"), t.parentElement.style.setProperty("perspective", "", "important"), e();
407
+ }, o);
408
+ }, 16);
409
+ });
410
+ }
411
+ // Fade-based show animation
412
+ async animateFadeShow(t, s) {
413
+ return new Promise((e) => {
414
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
415
+ const i = s.direction || "none", r = s.distance || 20, n = s.duration || 300;
416
+ let o = "translateY(0) translateX(0)";
417
+ 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(() => {
418
+ 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(() => {
419
+ t.style.setProperty("transition", "none", "important"), e();
420
+ }, n);
421
+ }, 16);
422
+ });
423
+ }
424
+ // Fade-based hide animation
425
+ async animateFadeHide(t, s) {
426
+ return new Promise((e) => {
427
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
428
+ const i = s.direction || "none", r = s.distance || 20, n = s.duration || 200;
429
+ let o = "translateY(0) translateX(0)";
430
+ i !== "none" && (o = i === "up" ? `translateY(-${r}px)` : i === "down" ? `translateY(${r}px)` : i === "left" ? `translateX(-${r}px)` : `translateX(${r}px)`), setTimeout(() => {
431
+ 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(() => {
432
+ t.style.setProperty("transition", "none", "important"), e();
433
+ }, n);
434
+ }, 16);
435
+ });
436
+ }
437
+ // Elastic-based show animation
438
+ async animateElasticShow(t, s) {
439
+ return new Promise((e) => {
440
+ var d, m, u;
441
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
442
+ 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" ? 0.1 : n === "strong" ? 0.3 : 0.2, l = r === "up" ? 40 : r === "down" ? -40 : r === "left" ? 40 : -40;
443
+ t.style.setProperty("opacity", "0", "important"), t.style.setProperty(
444
+ "transform",
445
+ r === "left" || r === "right" ? `translateX(${l}px) scale(${1 + a})` : `translateY(${l}px) scale(${1 + a})`,
446
+ "important"
447
+ ), t.offsetHeight, setTimeout(() => {
448
+ t.style.setProperty(
449
+ "transition",
450
+ `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)`,
451
+ "important"
452
+ ), t.style.setProperty("opacity", "1", "important"), t.style.setProperty("transform", "translateY(0) scale(1)", "important"), setTimeout(() => {
453
+ t.style.setProperty("transition", "none", "important"), e();
454
+ }, o);
455
+ }, 16);
456
+ });
457
+ }
458
+ // Elastic-based hide animation
459
+ async animateElasticHide(t, s) {
460
+ return new Promise((e) => {
461
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
462
+ const i = s.intensity || "normal", r = i === "gentle" ? 0.1 : i === "strong" ? 0.3 : 0.2;
463
+ s.duration, setTimeout(() => {
464
+ 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(() => {
465
+ t.style.setProperty("transition", "none", "important"), e();
466
+ }, 400);
467
+ }, 16);
468
+ });
469
+ }
470
+ // Rotate-based show animation
471
+ async animateRotateShow(t, s) {
472
+ return new Promise((e) => {
473
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
474
+ const i = s.degrees || 360, r = s.direction || "clockwise", n = s.origin || "center", o = s.duration || 500, a = r === "clockwise" ? i : -i;
475
+ 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(() => {
476
+ 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(() => {
477
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-origin", "", "important"), e();
478
+ }, o);
479
+ }, 16);
480
+ });
481
+ }
482
+ // Rotate-based hide animation
483
+ async animateRotateHide(t, s) {
484
+ return new Promise((e) => {
485
+ t.classList.add("spring-animation"), t.style.setProperty("transition", "none", "important");
486
+ const i = s.degrees || 180, r = s.direction || "counterclockwise", n = s.origin || "center", o = s.duration || 300, a = r === "clockwise" ? i : -i;
487
+ t.style.setProperty("transform-origin", n, "important"), setTimeout(() => {
488
+ 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(() => {
489
+ t.style.setProperty("transition", "none", "important"), t.style.setProperty("transform-origin", "", "important"), e();
490
+ }, o);
491
+ }, 16);
492
+ });
493
+ }
494
+ }
495
+ const S = new M();
496
+ class q {
497
+ constructor(t) {
498
+ this.containers = /* @__PURE__ */ new Map(), this.cssInjected = !1, this.config = t;
499
+ }
500
+ // Ensure container exists for position
501
+ ensureContainer(t) {
502
+ if (this.containers.has(t))
503
+ return this.containers.get(t);
504
+ const s = document.createElement("div");
505
+ s.className = `editora-toast-container editora-toast-${t.replace("-", "-")}`, s.setAttribute("role", "region"), s.setAttribute("aria-label", "Toast notifications"), s.setAttribute("aria-live", "polite");
506
+ const e = {
507
+ position: "fixed",
508
+ zIndex: (this.config.zIndex || 2147483647).toString(),
509
+ display: "flex",
510
+ flexDirection: "column",
511
+ gap: "8px",
512
+ pointerEvents: "none",
513
+ maxWidth: "100%",
514
+ boxSizing: "border-box"
515
+ };
516
+ switch (t) {
517
+ case "top-left":
518
+ e.top = "16px", e.left = "16px";
519
+ break;
520
+ case "top-right":
521
+ e.top = "16px", e.right = "16px";
522
+ break;
523
+ case "bottom-left":
524
+ e.bottom = "16px", e.left = "16px";
525
+ break;
526
+ case "bottom-right":
527
+ e.bottom = "16px", e.right = "16px";
528
+ break;
529
+ case "center":
530
+ e.top = "50%", e.left = "50%", e.transform = "translate(-50%, -50%)", e.alignItems = "center";
531
+ break;
532
+ }
533
+ return Object.assign(s.style, e), document.body.appendChild(s), this.containers.set(t, s), this.injectCSS(), s;
534
+ }
535
+ // Create toast element
536
+ createToastElement(t) {
537
+ const s = t.options, e = document.createElement("div");
538
+ 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");
539
+ const i = s.theme || this.config.theme;
540
+ 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"));
541
+ const n = document.createElement("div");
542
+ if (n.className = "editora-toast-content", s.icon) {
543
+ const a = document.createElement("span");
544
+ a.className = "editora-toast-icon", a.textContent = s.icon, n.appendChild(a);
545
+ }
546
+ const o = document.createElement("span");
547
+ if (o.className = "editora-toast-message", s.html && s.message)
548
+ o.innerHTML = this.sanitizeHTML(s.message);
549
+ else if (s.render) {
550
+ const a = s.render();
551
+ o.appendChild(a);
552
+ } else
553
+ o.textContent = s.message || "";
554
+ if (n.appendChild(o), s.progress) {
555
+ const a = document.createElement("div");
556
+ a.className = "editora-toast-progress";
557
+ const l = document.createElement("div");
558
+ if (l.className = "editora-toast-progress-bar", l.style.width = `${Math.min(100, Math.max(0, s.progress.value))}%`, s.progress.showPercentage) {
559
+ const d = document.createElement("span");
560
+ d.className = "editora-toast-progress-text", d.textContent = `${Math.round(s.progress.value)}%`, a.appendChild(d);
561
+ }
562
+ a.appendChild(l), n.appendChild(a);
563
+ }
564
+ if (e.appendChild(n), s.actions && s.actions.length > 0) {
565
+ const a = document.createElement("div");
566
+ a.className = "editora-toast-actions", s.actions.forEach((l) => {
567
+ const d = document.createElement("button");
568
+ d.className = `editora-toast-action ${l.primary ? "primary" : ""}`, d.textContent = l.label, d.onclick = (m) => {
569
+ m.stopPropagation(), l.onClick();
570
+ }, a.appendChild(d);
571
+ }), e.appendChild(a);
572
+ }
573
+ if (s.closable !== !1) {
574
+ const a = document.createElement("button");
575
+ a.className = "editora-toast-close", a.setAttribute("aria-label", "Close notification"), a.innerHTML = "×", a.onclick = () => t.dismiss(), e.appendChild(a);
576
+ }
577
+ 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;
578
+ }
579
+ // Show toast with animation
580
+ async showToast(t) {
581
+ var r, n;
582
+ const s = this.ensureContainer(t.options.position || this.config.position), e = this.createToastElement(t);
583
+ t.element = e, s.appendChild(e);
584
+ const i = t.options.animation || this.config.animation || { type: "css" };
585
+ if (await S.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) {
586
+ const o = t.options.duration || this.config.duration;
587
+ t.timeoutId = window.setTimeout(() => {
588
+ this.hideToast(t);
589
+ }, o);
590
+ }
591
+ }
592
+ // Hide toast with animation
593
+ async hideToast(t) {
594
+ var e, i;
595
+ if (!t.element)
596
+ return;
597
+ t.timeoutId && (clearTimeout(t.timeoutId), t.timeoutId = void 0);
598
+ const s = t.options.animation || this.config.animation || { type: "css" };
599
+ 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);
600
+ }
601
+ // Update toast content
602
+ async updateToast(t, s) {
603
+ var r, n;
604
+ if (!t.element)
605
+ return;
606
+ const e = t.options.animation || this.config.animation || { type: "css" };
607
+ if (e.type === "custom" && e.update) {
608
+ await S.updateToast(t.element, t, s, e);
609
+ return;
610
+ }
611
+ 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}`));
612
+ const i = t.element.querySelector(".editora-toast-message");
613
+ if (i && s.message !== void 0)
614
+ if (t.options.html && s.message)
615
+ i.innerHTML = this.sanitizeHTML(s.message);
616
+ else if (t.options.render) {
617
+ const o = t.element.querySelector(".editora-toast-content");
618
+ if (o) {
619
+ const a = t.options.render();
620
+ o.innerHTML = "", o.appendChild(a);
621
+ }
622
+ } else
623
+ i.textContent = s.message || "";
624
+ if (s.progress !== void 0) {
625
+ let o = t.element.querySelector(".editora-toast-progress");
626
+ if (s.progress) {
627
+ if (!o) {
628
+ o = document.createElement("div"), o.className = "editora-toast-progress";
629
+ const l = t.element.querySelector(".editora-toast-content");
630
+ l && l.appendChild(o);
631
+ }
632
+ const a = o.querySelector(".editora-toast-progress-bar");
633
+ if (a && (a.style.width = `${Math.min(100, Math.max(0, s.progress.value))}%`), s.progress.showPercentage) {
634
+ let l = o.querySelector(".editora-toast-progress-text");
635
+ l || (l = document.createElement("span"), l.className = "editora-toast-progress-text", o.insertBefore(l, o.firstChild)), l.textContent = `${Math.round(s.progress.value)}%`;
636
+ } else {
637
+ const l = o.querySelector(".editora-toast-progress-text");
638
+ l && l.remove();
639
+ }
640
+ } else
641
+ o && o.remove();
642
+ }
643
+ if (s.actions !== void 0) {
644
+ let o = t.element.querySelector(".editora-toast-actions");
645
+ 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) => {
646
+ const l = document.createElement("button");
647
+ l.className = `editora-toast-action ${a.primary ? "primary" : ""}`, l.textContent = a.label, l.onclick = (d) => {
648
+ d.stopPropagation(), a.onClick();
649
+ }, o.appendChild(l);
650
+ })) : o && o.remove();
651
+ }
652
+ (n = (r = t.options).onUpdate) == null || n.call(r, s);
653
+ }
654
+ // Pause/resume auto-dismiss
655
+ pauseToast(t) {
656
+ t.timeoutId && (clearTimeout(t.timeoutId), t.timeoutId = void 0);
657
+ }
658
+ resumeToast(t) {
659
+ if (!t.options.persistent && t.options.duration !== 0) {
660
+ const s = t.options.duration || this.config.duration;
661
+ t.timeoutId = window.setTimeout(() => {
662
+ this.hideToast(t);
663
+ }, s);
664
+ }
665
+ }
666
+ // Swipe dismiss with directional control
667
+ addSwipeDismiss(t, s) {
668
+ let e = 0, i = 0, r = !1;
669
+ const n = s.options.swipeDirection || this.config.swipeDirection || "any", o = 40;
670
+ let a = "", l = !1;
671
+ const d = (p) => {
672
+ 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();
673
+ }, m = (p) => {
674
+ if (!r)
675
+ return;
676
+ 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;
677
+ if ((Math.abs(y) > f || Math.abs(w) > f) && (l = !0), l) {
678
+ const v = Math.abs(w) > Math.abs(y) ? 25 : 20, P = Math.min(Math.max(y * 0.2, -v), v), x = Math.min(Math.max(w * 0.2, -v), v);
679
+ t.style.transform = `${a} translate(${P}px, ${x}px)`;
680
+ }
681
+ (Math.abs(w) > Math.abs(y) || n === "vertical" || n === "up" || n === "down") && p.preventDefault();
682
+ }, u = (p) => {
683
+ if (!r)
684
+ return;
685
+ if (t.style.transform = a, t.style.transition = "", t.style.cursor = "", !l) {
686
+ r = !1;
687
+ return;
688
+ }
689
+ 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;
690
+ let f = !1;
691
+ const v = n === "vertical" || n === "up" || n === "down", P = v ? 35 : o;
692
+ switch (n) {
693
+ case "any":
694
+ f = Math.abs(y) > o || Math.abs(w) > o;
695
+ break;
696
+ case "horizontal":
697
+ f = Math.abs(y) > o;
698
+ break;
699
+ case "vertical":
700
+ f = Math.abs(w) > P;
701
+ break;
702
+ case "left":
703
+ f = y < -o;
704
+ break;
705
+ case "right":
706
+ f = y > o;
707
+ break;
708
+ case "up":
709
+ f = w < -P;
710
+ break;
711
+ case "down":
712
+ f = w > P;
713
+ break;
714
+ }
715
+ v && console.log(`Vertical swipe attempt: direction=${n}, deltaY=${w}, effectiveMinDistance=${P}, shouldDismiss=${f}`), f && s.dismiss(), r = !1;
716
+ };
717
+ 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);
718
+ }
719
+ // Drag dismiss (simplified)
720
+ addDragDismiss(t, s) {
721
+ this.addSwipeDismiss(t, s);
722
+ }
723
+ // Accessibility
724
+ announceToast(t) {
725
+ const s = document.createElement("div");
726
+ 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(() => {
727
+ document.body.removeChild(s);
728
+ }, 1e3);
729
+ }
730
+ // Security: Basic HTML sanitization
731
+ sanitizeHTML(t) {
732
+ const s = document.createElement("div");
733
+ return s.textContent = t, s.innerHTML;
734
+ }
735
+ // Inject CSS
736
+ injectCSS() {
737
+ if (this.cssInjected || typeof document == "undefined")
738
+ return;
739
+ if (!Array.from(document.styleSheets).find(
740
+ (s) => {
741
+ var e, i, r, n;
742
+ 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"));
743
+ }
744
+ )) {
745
+ const s = document.createElement("link");
746
+ s.rel = "stylesheet", s.href = "/packages/editora-toast/dist/toast.css", document.head.appendChild(s);
747
+ }
748
+ this.cssInjected = !0;
749
+ }
750
+ // Cleanup
751
+ destroy() {
752
+ this.containers.forEach((t) => {
753
+ t.parentNode && t.parentNode.removeChild(t);
754
+ }), this.containers.clear();
755
+ }
756
+ }
757
+ class Y {
758
+ constructor() {
759
+ this.plugins = [], this.hooks = {
760
+ beforeShow: [],
761
+ afterShow: [],
762
+ beforeHide: [],
763
+ afterHide: [],
764
+ beforeUpdate: [],
765
+ afterUpdate: []
766
+ };
767
+ }
768
+ // Plugin management
769
+ use(t) {
770
+ if (this.plugins.find((s) => s.name === t.name)) {
771
+ console.warn(`Plugin "${t.name}" is already installed`);
772
+ return;
773
+ }
774
+ this.plugins.push(t), t.install(this);
775
+ }
776
+ remove(t) {
777
+ const s = this.plugins.findIndex((i) => i.name === t);
778
+ if (s === -1)
779
+ return !1;
780
+ const e = this.plugins[s];
781
+ return e.uninstall && e.uninstall(this), this.plugins.splice(s, 1), !0;
782
+ }
783
+ getPlugins() {
784
+ return [...this.plugins];
785
+ }
786
+ // Hook registration
787
+ on(t, s) {
788
+ this.hooks[t] && this.hooks[t].push(s);
789
+ }
790
+ off(t, s) {
791
+ if (this.hooks[t]) {
792
+ const e = this.hooks[t].indexOf(s);
793
+ e !== -1 && this.hooks[t].splice(e, 1);
794
+ }
795
+ }
796
+ // Hook execution
797
+ async trigger(t, s, ...e) {
798
+ const i = this.hooks[t];
799
+ if (!(!i || i.length === 0))
800
+ for (const r of i)
801
+ try {
802
+ await r(s, ...e);
803
+ } catch (n) {
804
+ console.error(`Error in ${t} hook:`, n);
805
+ }
806
+ }
807
+ // Convenience methods for common lifecycle events
808
+ async beforeShow(t) {
809
+ await this.trigger("beforeShow", t);
810
+ }
811
+ async afterShow(t) {
812
+ await this.trigger("afterShow", t);
813
+ }
814
+ async beforeHide(t) {
815
+ await this.trigger("beforeHide", t);
816
+ }
817
+ async afterHide(t) {
818
+ await this.trigger("afterHide", t);
819
+ }
820
+ async beforeUpdate(t, s) {
821
+ await this.trigger("beforeUpdate", t, s);
822
+ }
823
+ async afterUpdate(t, s) {
824
+ await this.trigger("afterUpdate", t, s);
825
+ }
826
+ // Editor integration hooks (for RTE)
827
+ onEditorEvent(t, s) {
828
+ const e = `editor:${t}`;
829
+ this.hooks[e] || (this.hooks[e] = []), this.hooks[e].push(s);
830
+ }
831
+ triggerEditorEvent(t, s, ...e) {
832
+ const i = `editor:${t}`;
833
+ this.trigger(i, s, ...e);
834
+ }
835
+ // Promise lifecycle helpers
836
+ async handlePromise(t, s, e, i) {
837
+ s();
838
+ try {
839
+ const r = await t;
840
+ return e(r), r;
841
+ } catch (r) {
842
+ throw i(r), r;
843
+ }
844
+ }
845
+ // Batch operations
846
+ async batchShow(t) {
847
+ const s = t.map((i) => this.beforeShow(i));
848
+ await Promise.all(s);
849
+ const e = t.map((i) => this.afterShow(i));
850
+ await Promise.all(e);
851
+ }
852
+ async batchHide(t) {
853
+ const s = t.map((i) => this.beforeHide(i));
854
+ await Promise.all(s);
855
+ const e = t.map((i) => this.afterHide(i));
856
+ await Promise.all(e);
857
+ }
858
+ // Cleanup
859
+ destroy() {
860
+ this.plugins.forEach((t) => {
861
+ t.uninstall && t.uninstall(this);
862
+ }), this.plugins = [], Object.keys(this.hooks).forEach((t) => {
863
+ this.hooks[t] = [];
864
+ });
865
+ }
866
+ }
867
+ const X = {
868
+ position: "bottom-right",
869
+ duration: 4e3,
870
+ maxVisible: 5,
871
+ queueStrategy: "fifo",
872
+ theme: "system",
873
+ pauseOnHover: !0,
874
+ pauseOnFocus: !1,
875
+ pauseOnWindowBlur: !1,
876
+ // Don't pause by default
877
+ swipeDismiss: !1,
878
+ swipeDirection: "any",
879
+ // Allow any direction by default
880
+ dragDismiss: !1,
881
+ rtl: !1,
882
+ // LTR by default
883
+ enableAccessibility: !0,
884
+ animation: { type: "css" }
885
+ // Default to CSS animations
886
+ };
887
+ class C {
888
+ constructor(t = {}) {
889
+ this.idCounter = 0, this.pausedToasts = /* @__PURE__ */ 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();
890
+ }
891
+ // Core API
892
+ show(t) {
893
+ const s = t.id || `toast-${++this.idCounter}`, e = {
894
+ id: s,
895
+ options: { ...this.config, ...t },
896
+ createdAt: Date.now(),
897
+ dismiss: () => this.dismiss(s),
898
+ update: (i) => this.update(s, i)
899
+ };
900
+ return this.lifecycle.beforeShow(e).then(async () => {
901
+ this.store.addToast(e), this.queue.enqueue(e), await this.renderer.showToast(e), this.lifecycle.afterShow(e);
902
+ }), e;
903
+ }
904
+ update(t, s) {
905
+ const e = this.store.getToast(t);
906
+ return e ? (this.lifecycle.beforeUpdate(e, s).then(async () => {
907
+ this.store.updateToast(t, { options: { ...e.options, ...s } }), await this.renderer.updateToast(e, s), this.lifecycle.afterUpdate(e, s);
908
+ }), !0) : !1;
909
+ }
910
+ dismiss(t) {
911
+ const s = this.store.getToast(t);
912
+ return s ? (this.lifecycle.beforeHide(s).then(async () => {
913
+ this.queue.dequeue(t), await this.renderer.hideToast(s), this.store.removeToast(t), this.lifecycle.afterHide(s);
914
+ }), !0) : !1;
915
+ }
916
+ clear() {
917
+ const t = this.store.getAllToasts();
918
+ this.lifecycle.batchHide(t).then(() => {
919
+ this.queue.clear(), this.store.clear();
920
+ });
921
+ }
922
+ // Promise API
923
+ async promise(t, s) {
924
+ var i, r;
925
+ const e = this.show(this.normalizeOptions(s.loading, "loading"));
926
+ try {
927
+ const n = await t, o = this.normalizeOptions(
928
+ typeof s.success == "function" ? s.success(n) : s.success,
929
+ "success"
930
+ );
931
+ return this.update(e.id, o), (i = s.onSuccess) == null || i.call(s, n), n;
932
+ } catch (n) {
933
+ const o = this.normalizeOptions(
934
+ typeof s.error == "function" ? s.error(n) : s.error,
935
+ "error"
936
+ );
937
+ throw this.update(e.id, o), (r = s.onError) == null || r.call(s, n), n;
938
+ }
939
+ }
940
+ // Group API
941
+ group(t, s) {
942
+ return this.show({ ...s, group: t });
943
+ }
944
+ // Plugin API
945
+ use(t) {
946
+ this.lifecycle.use(t);
947
+ }
948
+ // Configuration
949
+ configure(t) {
950
+ this.config = { ...this.config, ...t }, this.store.updateConfig(t), this.queue.updateConfig(t);
951
+ }
952
+ getConfig() {
953
+ return { ...this.config };
954
+ }
955
+ // State queries
956
+ getToasts() {
957
+ return this.store.getAllToasts();
958
+ }
959
+ getGroups() {
960
+ return this.store.getAllGroups();
961
+ }
962
+ // Convenience methods for backward compatibility
963
+ info(t, s) {
964
+ return this.show({ message: t, level: "info", duration: s });
965
+ }
966
+ success(t, s) {
967
+ return this.show({ message: t, level: "success", duration: s });
968
+ }
969
+ error(t, s) {
970
+ return this.show({ message: t, level: "error", duration: s });
971
+ }
972
+ warning(t, s) {
973
+ return this.show({ message: t, level: "warning", duration: s });
974
+ }
975
+ loading(t, s) {
976
+ return this.show({ message: t, level: "loading", duration: s });
977
+ }
978
+ // Utility methods
979
+ normalizeOptions(t, s) {
980
+ return typeof t == "string" ? { message: t, level: s } : { ...t, level: t.level || s };
981
+ }
982
+ // Editor integration (for RTE)
983
+ onEditorEvent(t, s) {
984
+ this.lifecycle.onEditorEvent(t, s);
985
+ }
986
+ triggerEditorEvent(t, s, ...e) {
987
+ this.lifecycle.triggerEditorEvent(t, s, ...e);
988
+ }
989
+ // Window focus/blur handling
990
+ setupWindowFocusHandling() {
991
+ 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", () => {
992
+ document.hidden ? this.pauseAllToasts() : this.resumeAllToasts();
993
+ }));
994
+ }
995
+ pauseAllToasts() {
996
+ this.store.getAllToasts().forEach((s) => {
997
+ s.timeoutId && !this.pausedToasts.has(s.id) && (clearTimeout(s.timeoutId), s.timeoutId = void 0, this.pausedToasts.add(s.id));
998
+ });
999
+ }
1000
+ resumeAllToasts() {
1001
+ this.store.getAllToasts().forEach((s) => {
1002
+ if (this.pausedToasts.has(s.id) && !s.options.persistent && s.options.duration !== 0) {
1003
+ const e = s.options.duration || this.config.duration;
1004
+ s.timeoutId = window.setTimeout(() => {
1005
+ this.dismiss(s.id);
1006
+ }, e), this.pausedToasts.delete(s.id);
1007
+ }
1008
+ });
1009
+ }
1010
+ // Cleanup
1011
+ destroy() {
1012
+ 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();
1013
+ }
1014
+ }
1015
+ const h = new C();
1016
+ function T(c) {
1017
+ return typeof document == "undefined" ? { dismiss: () => {
1018
+ } } : h.show(c);
1019
+ }
1020
+ function E(c, t, s, e) {
1021
+ const i = { position: "top-right", theme: "light" };
1022
+ let r = {};
1023
+ return t && typeof t == "object" ? r = { ...t } : typeof t == "number" && (r.duration = t), s && (r.theme = s), e && (r.position = e), {
1024
+ message: c,
1025
+ ...r,
1026
+ duration: r.duration,
1027
+ level: r.level || void 0,
1028
+ position: r.position || i.position,
1029
+ theme: r.theme || i.theme
1030
+ };
1031
+ }
1032
+ const L = {
1033
+ info: (c, t, s, e) => T({ ...E(c, t, s, e), level: "info" }),
1034
+ success: (c, t, s, e) => T({ ...E(c, t, s, e), level: "success" }),
1035
+ error: (c, t, s, e) => T({ ...E(c, t, s, e), level: "error" }),
1036
+ warning: (c, t, s, e) => T({ ...E(c, t, s, e), level: "warning" }),
1037
+ loading: (c, t, s, e) => T({ ...E(c, t, s, e), level: "loading" })
1038
+ }, $ = {
1039
+ // Core methods
1040
+ show: (c) => h.show(c),
1041
+ update: (c, t) => h.update(c, t),
1042
+ dismiss: (c) => h.dismiss(c),
1043
+ clear: () => h.clear(),
1044
+ // Convenience methods
1045
+ info: (c, t) => h.show({ message: c, level: "info", ...t }),
1046
+ success: (c, t) => h.show({ message: c, level: "success", ...t }),
1047
+ error: (c, t) => h.show({ message: c, level: "error", ...t }),
1048
+ warning: (c, t) => h.show({ message: c, level: "warning", ...t }),
1049
+ loading: (c, t) => h.show({ message: c, level: "loading", ...t }),
1050
+ // Advanced features
1051
+ promise: (c, t) => h.promise(c, t),
1052
+ group: (c, t) => h.group(c, t),
1053
+ configure: (c) => h.configure(c),
1054
+ use: (c) => h.use(c),
1055
+ // State queries
1056
+ getToasts: () => h.getToasts(),
1057
+ getGroups: () => h.getGroups(),
1058
+ getConfig: () => h.getConfig(),
1059
+ // Editor integration
1060
+ onEditorEvent: (c, t) => h.onEditorEvent(c, t),
1061
+ triggerEditorEvent: (c, t, ...s) => h.triggerEditorEvent(c, t, ...s),
1062
+ // Cleanup
1063
+ destroy: () => h.destroy()
1064
+ };
1065
+ typeof window != "undefined" && typeof document != "undefined" && (window.toast = L, window.toastAdvanced = $, window.toastPro = $, window.ToastManager = C, window.dispatchEvent(new CustomEvent("toastReady", {
1066
+ detail: { toast: L, toastAdvanced: $, toastPro: $, ToastManager: C }
1067
+ })));
1068
+ export {
1069
+ C as ToastManager,
1070
+ L as default,
1071
+ L as toast,
1072
+ $ as toastAdvanced,
1073
+ $ as toastPro
1074
+ };
1075
+ //# sourceMappingURL=index.esm.js.map