@editora/toast 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1251 @@
1
+ let K = null;
2
+ function Te(o) {
3
+ K = o;
4
+ }
5
+ function Y() {
6
+ return K;
7
+ }
8
+ class J {
9
+ constructor(e) {
10
+ this.toasts = /* @__PURE__ */ new Map(), this.groups = /* @__PURE__ */ new Map(), this.containers = /* @__PURE__ */ new Map(), this.config = { ...e };
11
+ }
12
+ // Toast management
13
+ addToast(e) {
14
+ this.toasts.set(e.id, e), this.updateGroup(e);
15
+ }
16
+ removeToast(e) {
17
+ const t = this.toasts.get(e);
18
+ return t ? (this.toasts.delete(e), this.updateGroup(t), !0) : !1;
19
+ }
20
+ getToast(e) {
21
+ return this.toasts.get(e);
22
+ }
23
+ getAllToasts() {
24
+ return Array.from(this.toasts.values());
25
+ }
26
+ getToastsByPosition(e) {
27
+ return this.getAllToasts().filter((t) => t.options.position === e);
28
+ }
29
+ updateToast(e, t) {
30
+ const s = this.toasts.get(e);
31
+ return s ? (Object.assign(s, t), this.updateGroup(s), !0) : !1;
32
+ }
33
+ // Group management
34
+ updateGroup(e) {
35
+ const t = e.options.group;
36
+ if (!t) return;
37
+ let s = this.groups.get(t);
38
+ s || (s = { id: t, toasts: [] }, this.groups.set(t, s)), s.toasts = s.toasts.filter((i) => i.id !== e.id), e.options.group === t && s.toasts.push(e), s.toasts.length === 0 && this.groups.delete(t);
39
+ }
40
+ getGroup(e) {
41
+ return this.groups.get(e);
42
+ }
43
+ getAllGroups() {
44
+ return Array.from(this.groups.values());
45
+ }
46
+ // Container management
47
+ getContainer(e) {
48
+ return this.containers.get(e);
49
+ }
50
+ setContainer(e, t) {
51
+ this.containers.set(e, t);
52
+ }
53
+ removeContainer(e) {
54
+ return this.containers.delete(e);
55
+ }
56
+ getAllContainers() {
57
+ return new Map(this.containers);
58
+ }
59
+ // Configuration
60
+ getConfig() {
61
+ return { ...this.config };
62
+ }
63
+ updateConfig(e) {
64
+ this.config = { ...this.config, ...e };
65
+ }
66
+ // Cleanup
67
+ clear() {
68
+ this.toasts.clear(), this.groups.clear();
69
+ }
70
+ // Statistics
71
+ getStats() {
72
+ return {
73
+ totalToasts: this.toasts.size,
74
+ totalGroups: this.groups.size,
75
+ toastsByPosition: Object.fromEntries(
76
+ Array.from(this.containers.keys()).map((e) => [
77
+ e,
78
+ this.getToastsByPosition(e).length
79
+ ])
80
+ )
81
+ };
82
+ }
83
+ }
84
+ class Z {
85
+ constructor(e) {
86
+ this.queue = [], this.visible = [], this.config = this.normalizeConfig(e);
87
+ }
88
+ enqueue(e) {
89
+ var r;
90
+ const t = this.findDuplicate(e);
91
+ if (t && ((r = e.options.preventDuplicate) != null ? r : this.config.preventDuplicate))
92
+ return { show: [], hide: [], rejected: t };
93
+ const s = [];
94
+ if (e.options.important && this.visible.length >= this.maxVisible) {
95
+ const n = this.removeLowestPriorityVisible();
96
+ return this.visible.push(e), { show: [e], hide: n ? [...s, n] : s };
97
+ }
98
+ this.config.queueStrategy === "fifo" ? this.queue.push(e) : this.queue.unshift(e), this.sortQueue();
99
+ const i = this.processQueue();
100
+ return { show: i.show, hide: [...s, ...i.hide] };
101
+ }
102
+ dequeue(e) {
103
+ return this.removeFromCollections(e) ? { show: this.processQueue().show, hide: [] } : { show: [], hide: [] };
104
+ }
105
+ updateConfig(e) {
106
+ return this.config = this.normalizeConfig({ ...this.config, ...e }), this.sortQueue(), this.processQueue();
107
+ }
108
+ getQueued() {
109
+ return [...this.queue];
110
+ }
111
+ getVisible() {
112
+ return [...this.visible];
113
+ }
114
+ getAll() {
115
+ return [...this.visible, ...this.queue];
116
+ }
117
+ isVisible(e) {
118
+ return this.visible.some((t) => t.id === e);
119
+ }
120
+ clear() {
121
+ const e = [...this.visible, ...this.queue];
122
+ return this.queue = [], this.visible = [], e;
123
+ }
124
+ processQueue() {
125
+ const e = [], t = [];
126
+ for (; this.visible.length > this.maxVisible; ) {
127
+ const s = this.visible.pop();
128
+ s && t.push(s);
129
+ }
130
+ for (; this.visible.length < this.maxVisible && this.queue.length > 0; ) {
131
+ const s = this.queue.shift();
132
+ if (!s) break;
133
+ this.visible.push(s), e.push(s);
134
+ }
135
+ return { show: e, hide: t };
136
+ }
137
+ removeLowestPriorityVisible() {
138
+ if (this.visible.length === 0) return;
139
+ let e = 0;
140
+ for (let t = 1; t < this.visible.length; t += 1)
141
+ (this.visible[t].options.priority || 0) < (this.visible[e].options.priority || 0) && (e = t);
142
+ return this.visible.splice(e, 1)[0];
143
+ }
144
+ removeFromCollections(e) {
145
+ const t = this.visible.findIndex((i) => i.id === e);
146
+ if (t !== -1)
147
+ return this.visible.splice(t, 1)[0];
148
+ const s = this.queue.findIndex((i) => i.id === e);
149
+ if (s !== -1)
150
+ return this.queue.splice(s, 1)[0];
151
+ }
152
+ findDuplicate(e) {
153
+ const t = e.options.dedupeScope || this.config.dedupeScope, s = t === "visible" ? this.visible : t === "queue" ? this.queue : [...this.visible, ...this.queue], i = this.getDedupeKey(e);
154
+ return s.find((r) => this.getDedupeKey(r) === i);
155
+ }
156
+ getDedupeKey(e) {
157
+ if (e.options.dedupeKey) return e.options.dedupeKey;
158
+ const { level: t, title: s, message: i, description: r } = e.options;
159
+ return typeof Node != "undefined" && [s, i, r].some((a) => a instanceof Node) ? `node:${e.id}` : `${t || "info"}:${s || ""}:${i || ""}:${r || ""}`;
160
+ }
161
+ sortQueue() {
162
+ this.queue.sort((e, t) => {
163
+ const s = (t.options.priority || 0) - (e.options.priority || 0);
164
+ return s !== 0 ? s : e.createdAt - t.createdAt;
165
+ });
166
+ }
167
+ get maxVisible() {
168
+ return Math.max(1, this.config.visibleToasts || this.config.maxVisible || 1);
169
+ }
170
+ normalizeConfig(e) {
171
+ return {
172
+ ...e,
173
+ maxVisible: e.visibleToasts || e.maxVisible
174
+ };
175
+ }
176
+ }
177
+ const ee = /* @__PURE__ */ new Set([
178
+ "a",
179
+ "b",
180
+ "strong",
181
+ "i",
182
+ "em",
183
+ "u",
184
+ "s",
185
+ "del",
186
+ "ins",
187
+ "mark",
188
+ "small",
189
+ "sub",
190
+ "sup",
191
+ "code",
192
+ "kbd",
193
+ "br",
194
+ "span",
195
+ "p",
196
+ "ul",
197
+ "ol",
198
+ "li"
199
+ ]), te = /* @__PURE__ */ new Set([
200
+ "script",
201
+ "style",
202
+ "iframe",
203
+ "frame",
204
+ "frameset",
205
+ "object",
206
+ "embed",
207
+ "applet",
208
+ "noscript",
209
+ "template",
210
+ "svg",
211
+ "math",
212
+ "form",
213
+ "input",
214
+ "button",
215
+ "textarea",
216
+ "select",
217
+ "option",
218
+ "head",
219
+ "title",
220
+ "link",
221
+ "meta",
222
+ "base",
223
+ "audio",
224
+ "video",
225
+ "canvas"
226
+ ]), se = /^(?:https?:|mailto:|tel:)/i;
227
+ function ie(o) {
228
+ const e = o.replace(/[\u0000- \u007f-\u009f]/g, "");
229
+ return e ? se.test(e) ? !0 : !/^[a-z][a-z0-9+.-]*:/i.test(e) : !1;
230
+ }
231
+ function P(o, e, t) {
232
+ for (const s of Array.from(o.childNodes)) {
233
+ if (s.nodeType === Node.TEXT_NODE) {
234
+ e.appendChild(t.createTextNode(s.textContent || ""));
235
+ continue;
236
+ }
237
+ if (s.nodeType !== Node.ELEMENT_NODE) continue;
238
+ const i = s, r = i.localName.toLowerCase();
239
+ if (te.has(r)) continue;
240
+ if (!ee.has(r)) {
241
+ P(i, e, t);
242
+ continue;
243
+ }
244
+ const n = t.createElement(r);
245
+ if (r === "a") {
246
+ const a = i.getAttribute("href");
247
+ a && ie(a) && (n.setAttribute("href", a.trim()), /^(?:https?:)?\/\//i.test(a.trim()) && (n.setAttribute("target", "_blank"), n.setAttribute("rel", "noopener noreferrer")));
248
+ const c = i.getAttribute("title");
249
+ c && n.setAttribute("title", c);
250
+ }
251
+ P(i, n, t), e.appendChild(n);
252
+ }
253
+ }
254
+ function oe(o, e) {
255
+ const t = document.createElement("template");
256
+ t.innerHTML = e;
257
+ const s = document.createDocumentFragment();
258
+ P(t.content, s, document), o.textContent = "", o.appendChild(s);
259
+ }
260
+ const B = "http://www.w3.org/2000/svg", ne = {
261
+ success: [
262
+ ["circle", { cx: "10", cy: "10", r: "8" }],
263
+ ["path", { d: "M6.6 10.3l2.3 2.3 4.5-4.9" }]
264
+ ],
265
+ error: [
266
+ ["circle", { cx: "10", cy: "10", r: "8" }],
267
+ ["path", { d: "M7.6 7.6l4.8 4.8M12.4 7.6l-4.8 4.8" }]
268
+ ],
269
+ warning: [
270
+ ["path", { d: "M10 2.9L18 16.4H2L10 2.9z" }],
271
+ ["path", { d: "M10 8.3v3.4M10 13.9v.1" }]
272
+ ],
273
+ info: [
274
+ ["circle", { cx: "10", cy: "10", r: "8" }],
275
+ ["path", { d: "M10 9.2v4.4M10 6.5v.1" }]
276
+ ],
277
+ loading: [["path", { d: "M10 2a8 8 0 1 0 8 8" }]]
278
+ }, re = {
279
+ success: "success",
280
+ error: "error",
281
+ warning: "warning",
282
+ info: "info",
283
+ loading: "loading",
284
+ promise: "loading"
285
+ };
286
+ function _(o, e) {
287
+ const t = document.createElementNS(B, "svg");
288
+ return t.setAttribute("viewBox", "0 0 20 20"), t.setAttribute("width", String(e)), t.setAttribute("height", String(e)), t.setAttribute("fill", "none"), t.setAttribute("stroke", "currentColor"), t.setAttribute("stroke-width", "1.7"), t.setAttribute("stroke-linecap", "round"), t.setAttribute("stroke-linejoin", "round"), t.setAttribute("focusable", "false"), t.setAttribute("aria-hidden", "true"), o.forEach(([s, i]) => {
289
+ const r = document.createElementNS(B, s);
290
+ Object.keys(i).forEach((n) => r.setAttribute(n, i[n])), t.appendChild(r);
291
+ }), t;
292
+ }
293
+ function ae(o) {
294
+ const e = ne[re[o] || ""];
295
+ return e ? _(e, 18) : null;
296
+ }
297
+ function le() {
298
+ const o = _([["path", { d: "M5.5 5.5l9 9M14.5 5.5l-9 9" }]], 14);
299
+ return o.setAttribute("stroke-width", "1.8"), o;
300
+ }
301
+ const F = 12, ce = 0.05, z = 3, M = /* @__PURE__ */ new WeakMap();
302
+ function de(o) {
303
+ const e = o.style.height;
304
+ o.style.height = "auto";
305
+ const t = o.offsetHeight;
306
+ return o.style.height = e, M.set(o, t), t;
307
+ }
308
+ function I(o) {
309
+ M.delete(o);
310
+ }
311
+ function he(o, e) {
312
+ return !e.stack || e.expand || o.dataset.open === "true";
313
+ }
314
+ function ue(o, e, t = !1) {
315
+ const i = o.dataset.edge === "bottom" ? -1 : 1, r = Array.from(o.querySelectorAll(".editora-toast")), n = r.filter((h) => !h.classList.contains("hiding") && h.dataset.leaving !== "true"), a = n.slice().reverse(), c = he(o, e);
316
+ a.forEach((h) => {
317
+ (t || !M.has(h)) && de(h);
318
+ });
319
+ const l = a.map((h) => M.get(h) || 0), f = l[0] || 0;
320
+ let m = 0;
321
+ a.forEach((h, g) => {
322
+ const k = l[g], u = c ? 1 : Math.max(1 - g * ce, 0.8), b = c ? k : f, p = c ? m : g * F + f * (1 - u);
323
+ h.style.setProperty("--et-y", `${i * p}px`), h.style.setProperty("--et-s", String(u)), h.style.setProperty("--et-index", String(g)), h.style.height = `${b}px`, h.style.zIndex = String(a.length - g), h.dataset.index = String(g), h.dataset.front = String(g === 0), h.dataset.collapsed = String(!c && g > 0), h.dataset.hidden = String(!c && g >= z), m += k + e.gap;
324
+ }), r.forEach((h) => {
325
+ n.includes(h) || (h.dataset.front = "false");
326
+ });
327
+ const w = a.length, A = c ? l.reduce((h, g) => h + g, 0) + Math.max(w - 1, 0) * e.gap : f + (Math.min(w, z) - 1 > 0 ? (Math.min(w, z) - 1) * F : 0);
328
+ o.style.height = w > 0 ? `${A}px` : "0px", o.dataset.count = String(w), o.dataset.expanded = String(c);
329
+ }
330
+ let V = null;
331
+ const O = () => V || (V = import("./AnimationUtils-CaHTcqKD.es.js").then((o) => o.animationManager)), H = (o) => !!o && o.type !== "css" && o.type !== "custom", fe = (o) => new Promise((e) => {
332
+ requestAnimationFrame(() => {
333
+ o.classList.add("show"), window.setTimeout(e, 220);
334
+ });
335
+ }), pe = (o) => new Promise((e) => {
336
+ o.classList.remove("show"), o.classList.add("hiding"), window.setTimeout(e, 220);
337
+ });
338
+ async function W(o, e, t, s) {
339
+ if (H(s)) {
340
+ const i = await O();
341
+ return o === "show" ? i.showToast(e, t, s) : i.hideToast(e, t, s);
342
+ }
343
+ if (s.type === "custom") {
344
+ const i = o === "show" ? s.show : s.hide;
345
+ if (i) return void await Promise.resolve(i(e, t));
346
+ }
347
+ return o === "show" ? fe(e) : pe(e);
348
+ }
349
+ const R = (o) => typeof Node != "undefined" && o instanceof Node;
350
+ function N(o, e, t) {
351
+ R(e) ? o.appendChild(e) : t ? oe(o, e) : o.textContent = e;
352
+ }
353
+ function ge() {
354
+ const o = document.querySelector('meta[property="csp-nonce"]');
355
+ return o && (o.nonce || o.getAttribute("nonce") || o.content) || void 0;
356
+ }
357
+ const me = (o) => R(o) ? o.textContent || "" : o ? String(o) : "";
358
+ class be {
359
+ constructor(e) {
360
+ this.containers = /* @__PURE__ */ new Map(), this.cssInjected = !1, this.toastOf = /* @__PURE__ */ new WeakMap(), this.holds = /* @__PURE__ */ new Map(), this.timing = /* @__PURE__ */ new Map(), this.returnFocusTo = null, this.globalListeners = [], this.resizeObserver = null, this.config = e, H(e.animation) && O();
361
+ }
362
+ observeSize(e) {
363
+ if (typeof ResizeObserver == "undefined") return;
364
+ if (!this.resizeObserver) {
365
+ const s = /* @__PURE__ */ new Set();
366
+ let i = 0;
367
+ this.resizeObserver = new ResizeObserver((r) => {
368
+ for (const n of r) {
369
+ const a = n.target.closest(".editora-toast");
370
+ a && s.add(a);
371
+ }
372
+ i || (i = requestAnimationFrame(() => {
373
+ i = 0;
374
+ const n = /* @__PURE__ */ new Set();
375
+ s.forEach((a) => {
376
+ I(a), a.parentElement && n.add(a.parentElement);
377
+ }), s.clear(), n.forEach((a) => this.layout(a));
378
+ }));
379
+ });
380
+ }
381
+ const t = e.querySelector(".editora-toast-content");
382
+ t && this.resizeObserver.observe(t);
383
+ }
384
+ updateConfig(e) {
385
+ H(e.animation) && O(), this.config = e, this.containers.forEach((t, s) => {
386
+ this.applyContainerStyles(t, s), this.layout(t, !0);
387
+ });
388
+ }
389
+ // Ensure container exists for position
390
+ ensureContainer(e) {
391
+ if (this.containers.has(e))
392
+ return this.containers.get(e);
393
+ const t = document.createElement("div");
394
+ return t.className = `editora-toast-container editora-toast-${e.replace("-", "-")}`, t.setAttribute("role", "region"), t.setAttribute("aria-label", "Toast notifications"), t.setAttribute("aria-live", "polite"), t.dataset.expand = String(this.config.expand), t.dataset.stack = String(this.config.stack), this.applyContainerStyles(t, e), this.attachContainerListeners(t), document.body.appendChild(t), this.containers.set(e, t), this.attachGlobalListeners(), this.injectCSS(), t;
395
+ }
396
+ // Hovering or focusing the stack opens it and holds the timers; leaving closes it and lets them run on.
397
+ attachContainerListeners(e) {
398
+ e.addEventListener("mouseenter", () => {
399
+ e.dataset.hover = "true", this.holdAll(e, "pointer"), this.syncOpen(e);
400
+ }), e.addEventListener("pointerdown", (t) => {
401
+ t.pointerType !== "touch" || e.dataset.hover === "true" || (e.dataset.hover = "true", this.holdAll(e, "pointer"), this.syncOpen(e));
402
+ }), e.addEventListener("mouseleave", () => {
403
+ delete e.dataset.hover, this.releaseAll(e, "pointer"), this.syncOpen(e);
404
+ }), e.addEventListener("focusin", (t) => {
405
+ this.isKeyboardFocus(t.target) && (e.dataset.focus = "true", this.holdAll(e, "focus"), this.syncOpen(e));
406
+ }), e.addEventListener("focusout", (t) => {
407
+ const s = t.relatedTarget;
408
+ s && e.contains(s) || (delete e.dataset.focus, this.releaseAll(e, "focus"), this.syncOpen(e));
409
+ }), e.addEventListener("keydown", (t) => this.onContainerKey(e, t));
410
+ }
411
+ syncOpen(e) {
412
+ const t = e.dataset.hover === "true" || e.dataset.focus === "true";
413
+ e.dataset.open = String(t), this.layout(e);
414
+ }
415
+ isKeyboardFocus(e) {
416
+ if (!(e instanceof Element)) return !1;
417
+ try {
418
+ return e.matches(":focus-visible");
419
+ } catch (t) {
420
+ return !0;
421
+ }
422
+ }
423
+ onContainerKey(e, t) {
424
+ if (t.key !== "Escape") return;
425
+ const s = t.target instanceof Element ? t.target.closest(".editora-toast") : null, i = s ? this.toastOf.get(s) : void 0;
426
+ if (!s || !i) return;
427
+ t.preventDefault();
428
+ const r = Array.from(e.querySelectorAll(".editora-toast:not(.hiding)")), n = r[r.indexOf(s) + 1] || r[r.indexOf(s) - 1];
429
+ i.dismiss(), n && n !== s ? n.focus() : this.restoreFocus();
430
+ }
431
+ restoreFocus() {
432
+ const e = this.returnFocusTo;
433
+ this.returnFocusTo = null, e && e.isConnected && e.focus();
434
+ }
435
+ // Document level behaviour: the hotkey that jumps to the toasts, a tap outside that closes an open stack, and
436
+ // a resize that can change how much the text of a toast wraps.
437
+ attachGlobalListeners() {
438
+ if (this.globalListeners.length > 0 || typeof window == "undefined") return;
439
+ const e = (t, s, i) => {
440
+ t.addEventListener(s, i), this.globalListeners.push([t, s, i]);
441
+ };
442
+ e(document, "keydown", ((t) => {
443
+ if (!this.matchesHotkey(t)) return;
444
+ const s = Array.from(this.containers.values()).find((n) => n.querySelector(".editora-toast:not(.hiding)"));
445
+ if (!s) return;
446
+ const i = s.querySelector('.editora-toast[data-front="true"]');
447
+ if (!i) return;
448
+ t.preventDefault();
449
+ const r = document.activeElement;
450
+ r instanceof HTMLElement && !s.contains(r) && (this.returnFocusTo = r), i.focus();
451
+ })), e(document, "pointerdown", ((t) => {
452
+ this.containers.forEach((s) => {
453
+ s.dataset.hover === "true" && !s.contains(t.target) && (delete s.dataset.hover, this.releaseAll(s, "pointer"), this.syncOpen(s));
454
+ });
455
+ })), e(window, "resize", (() => {
456
+ window.clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => this.containers.forEach((t) => this.layout(t, !0)), 120);
457
+ }));
458
+ }
459
+ matchesHotkey(e) {
460
+ const t = this.config.hotkey;
461
+ if (!t) return !1;
462
+ const s = t.toLowerCase().split("+").map((n) => n.trim()).filter(Boolean), i = s.pop();
463
+ if (!i) return !1;
464
+ const r = (n) => s.includes(n);
465
+ return e.altKey !== r("alt") || e.shiftKey !== r("shift") || e.ctrlKey !== r("ctrl") || e.metaKey !== (r("meta") || r("cmd")) ? !1 : e.code.toLowerCase() === `key${i}` || e.code.toLowerCase() === i || e.key.toLowerCase() === i;
466
+ }
467
+ layout(e, t = !1) {
468
+ ue(e, { stack: this.config.stack, expand: this.config.expand, gap: this.toPx(this.config.gap) }, t);
469
+ }
470
+ toPx(e) {
471
+ if (typeof e == "number") return e;
472
+ const t = parseFloat(e || "");
473
+ return Number.isFinite(t) ? t : 8;
474
+ }
475
+ // Timer holds
476
+ holdAll(e, t) {
477
+ e.querySelectorAll(".editora-toast").forEach((s) => {
478
+ const i = this.toastOf.get(s);
479
+ if (!i) return;
480
+ (t === "focus" ? i.options.pauseOnFocus : i.options.pauseOnHover) !== !1 && this.pauseToast(i, t);
481
+ });
482
+ }
483
+ releaseAll(e, t) {
484
+ e.querySelectorAll(".editora-toast").forEach((s) => {
485
+ const i = this.toastOf.get(s);
486
+ i && this.resumeToast(i, t);
487
+ });
488
+ }
489
+ // Create toast element
490
+ createToastElement(e) {
491
+ const t = e.options, s = document.createElement("div");
492
+ s.className = `editora-toast editora-toast-${t.level || "info"}`, s.dataset.level = t.level || "info", t.customClass && t.customClass.split(/\s+/).filter(Boolean).forEach((a) => s.classList.add(a)), s.setAttribute("role", t.role || (t.level === "error" ? "alert" : "status")), s.setAttribute("aria-atomic", "true"), s.tabIndex = 0, (t.closable || t.closeButton) && (s.dataset.closable = "true"), this.toastOf.set(s, e), t.ariaLive && t.ariaLive !== "off" && s.setAttribute("aria-live", t.ariaLive);
493
+ const i = t.theme || this.config.theme;
494
+ i && i !== "system" && s.setAttribute("data-theme", i), (this.config.richColors || i === "colored") && s.setAttribute("data-rich-colors", "true"), (t.rtl !== void 0 ? t.rtl : this.config.rtl) && (s.setAttribute("data-rtl", "true"), s.setAttribute("dir", "rtl"));
495
+ const n = this.createContent(e);
496
+ if (s.appendChild(n), t.actions && t.actions.length > 0) {
497
+ const a = document.createElement("div");
498
+ a.className = "editora-toast-actions", t.actions.forEach((c) => a.appendChild(this.createActionButton(c, e))), s.appendChild(a);
499
+ }
500
+ return (t.closable || t.closeButton) && s.appendChild(this.createCloseButton(e)), t.swipeDismiss && this.addSwipeDismiss(s, e), t.dragDismiss && this.addDragDismiss(s, e), s;
501
+ }
502
+ // Show toast with animation
503
+ async showToast(e) {
504
+ var r, n;
505
+ const t = this.ensureContainer(e.options.position || this.config.position), s = this.createToastElement(e);
506
+ e.element = s, t.appendChild(s), t.dataset.hover === "true" && e.options.pauseOnHover !== !1 && this.pauseToast(e, "pointer"), t.dataset.focus === "true" && e.options.pauseOnFocus !== !1 && this.pauseToast(e, "focus"), this.layout(t);
507
+ const i = e.options.animation || this.config.animation || { type: "css" };
508
+ H(i) && O(), this.observeSize(s), await W("show", s, e, i), this.config.enableAccessibility && this.announceToast(e), (n = (r = e.options).onShow) == null || n.call(r), this.startTimer(e);
509
+ }
510
+ // Hide toast with animation
511
+ async hideToast(e) {
512
+ var r, n, a;
513
+ if (!e.element) return;
514
+ this.stopTimer(e), this.holds.delete(e.id);
515
+ const t = e.element;
516
+ t.dataset.leaving = "true", t.parentElement && this.layout(t.parentElement);
517
+ const s = e.options.animation || this.config.animation || { type: "css" }, i = t.querySelector(".editora-toast-content");
518
+ if (i && ((r = this.resizeObserver) == null || r.unobserve(i)), await W("hide", t, e, s), e.element && e.element.parentNode) {
519
+ const c = e.element.parentElement;
520
+ e.element.parentNode.removeChild(e.element), e.element = void 0, c && (c.querySelector(".editora-toast") || (delete c.dataset.hover, delete c.dataset.focus, c.dataset.open = "false"), this.layout(c));
521
+ }
522
+ (a = (n = e.options).onHide) == null || a.call(n);
523
+ }
524
+ // Update toast content
525
+ async updateToast(e, t) {
526
+ var r, n, a, c;
527
+ if (!e.element) return;
528
+ const s = e.options.animation || this.config.animation || { type: "css" };
529
+ if (s.type === "custom" && s.update) {
530
+ await Promise.resolve(s.update(e.element, e, t));
531
+ return;
532
+ }
533
+ if (Object.assign(e.options, t), t.level && (e.element.className = e.element.className.replace(/editora-toast-(info|success|error|warning|loading|progress|promise|custom)/g, ""), e.element.classList.add(`editora-toast-${t.level}`), e.element.dataset.level = t.level), t.title !== void 0 || t.description !== void 0 || t.message !== void 0 || t.icon !== void 0 || t.level !== void 0 || t.render) {
534
+ const l = e.element.querySelector(".editora-toast-content"), f = this.createContent(e);
535
+ l && ((r = this.resizeObserver) == null || r.unobserve(l)), l == null || l.replaceWith(f), this.observeSize(e.element);
536
+ }
537
+ const i = (n = t.closeButton) != null ? n : t.closable;
538
+ if (i !== void 0) {
539
+ e.options.closable = i, e.options.closeButton = i, i ? e.element.dataset.closable = "true" : delete e.element.dataset.closable;
540
+ const l = e.element.querySelector(".editora-toast-close");
541
+ i && !l ? e.element.appendChild(this.createCloseButton(e)) : !i && l && l.remove();
542
+ }
543
+ if (t.progress !== void 0) {
544
+ const l = e.element.querySelector(".editora-toast-body"), f = e.element.querySelector(".editora-toast-progress-track");
545
+ if (t.progress && l) {
546
+ const m = this.createProgress(t.progress);
547
+ f ? f.replaceWith(m) : l.appendChild(m);
548
+ } else f && f.remove();
549
+ }
550
+ if (t.actions !== void 0 || t.action !== void 0 || t.cancel !== void 0) {
551
+ let l = e.element.querySelector(".editora-toast-actions");
552
+ const f = e.options.actions || [];
553
+ f.length > 0 ? (l ? l.innerHTML = "" : (l = document.createElement("div"), l.className = "editora-toast-actions", e.element.appendChild(l)), l && f.forEach((m) => l.appendChild(this.createActionButton(m, e)))) : l && l.remove();
554
+ }
555
+ (t.duration !== void 0 || t.persistent !== void 0 || t.level !== void 0) && this.startTimer(e), e.element.style.height = "", I(e.element), e.element.parentElement && this.layout(e.element.parentElement), (c = (a = e.options).onUpdate) == null || c.call(a, t);
556
+ }
557
+ createContent(e) {
558
+ const t = e.options, s = document.createElement("div");
559
+ s.className = "editora-toast-content";
560
+ const i = this.createIcon(e);
561
+ i && s.appendChild(i);
562
+ const r = document.createElement("div");
563
+ if (r.className = "editora-toast-body", t.render)
564
+ r.appendChild(t.render(e));
565
+ else {
566
+ if (t.title) {
567
+ const n = document.createElement("div");
568
+ n.className = "editora-toast-title", N(n, t.title), r.appendChild(n);
569
+ }
570
+ if (t.message) {
571
+ const n = document.createElement("div");
572
+ n.className = "editora-toast-message", N(n, t.message, t.html), r.appendChild(n);
573
+ }
574
+ if (t.description) {
575
+ const n = document.createElement("div");
576
+ n.className = "editora-toast-description", N(n, t.description), r.appendChild(n);
577
+ }
578
+ }
579
+ return t.progress && r.appendChild(this.createProgress(t.progress)), s.appendChild(r), s;
580
+ }
581
+ createProgress(e) {
582
+ const t = Math.min(100, Math.max(0, e.value)), s = document.createElement("div");
583
+ s.className = "editora-toast-progress-track", s.setAttribute("role", "progressbar"), s.setAttribute("aria-valuemin", "0"), s.setAttribute("aria-valuemax", "100"), s.setAttribute("aria-valuenow", String(t));
584
+ const i = document.createElement("div");
585
+ if (i.className = "editora-toast-progress-bar", i.style.width = `${t}%`, e.showPercentage) {
586
+ const r = document.createElement("span");
587
+ r.className = "editora-toast-progress-text", r.textContent = `${Math.round(e.value)}%`, s.appendChild(r);
588
+ }
589
+ return s.appendChild(i), s;
590
+ }
591
+ createCloseButton(e) {
592
+ const t = document.createElement("button");
593
+ return t.className = "editora-toast-close", t.setAttribute("type", "button"), t.setAttribute("aria-label", "Close notification"), t.appendChild(le()), t.onclick = () => e.dismiss(), t;
594
+ }
595
+ // The icon is the caller's own (text, emoji or a node), false for none, or else the built-in one of the level.
596
+ createIcon(e) {
597
+ const t = e.options;
598
+ if (t.icon === !1) return null;
599
+ const s = document.createElement("span");
600
+ if (s.className = "editora-toast-icon", s.setAttribute("aria-hidden", "true"), typeof t.icon == "string" && t.icon)
601
+ return s.textContent = t.icon, s;
602
+ if (t.icon && typeof t.icon == "object")
603
+ return s.appendChild(t.icon), s;
604
+ if (this.config.icons === !1) return null;
605
+ const i = t.level || "info", r = ae(i);
606
+ return r ? ((i === "loading" || i === "promise") && (s.dataset.spin = "true"), s.appendChild(r), s) : null;
607
+ }
608
+ createActionButton(e, t) {
609
+ const s = document.createElement("button");
610
+ return s.className = `editora-toast-action ${e.primary ? "primary" : ""}`, s.textContent = e.label, e.altText && s.setAttribute("aria-label", e.altText), s.onclick = (i) => {
611
+ i.stopPropagation(), e.onClick(), e.dismissOnClick !== !1 && t.dismiss();
612
+ }, s;
613
+ }
614
+ applyContainerStyles(e, t) {
615
+ const s = this.toCssLength(this.config.offset), i = this.toCssLength(this.config.mobileOffset), r = this.toCssLength(this.config.gap);
616
+ e.dataset.position = t, e.dataset.edge = t.startsWith("bottom") ? "bottom" : "top", e.dataset.expand = String(this.config.expand), e.dataset.stack = String(this.config.stack), e.style.setProperty("--editora-toast-offset", s), e.style.setProperty("--editora-toast-mobile-offset", i), e.style.setProperty("--editora-toast-gap", r), e.style.setProperty("--et-edge", t.startsWith("bottom") ? "1" : "-1");
617
+ const n = {
618
+ position: "fixed",
619
+ zIndex: (this.config.zIndex || 2147483647).toString(),
620
+ display: "block",
621
+ width: "var(--et-width, 360px)",
622
+ maxWidth: `calc(100vw - 2 * ${s})`,
623
+ boxSizing: "border-box",
624
+ top: "",
625
+ right: "",
626
+ bottom: "",
627
+ left: "",
628
+ transform: ""
629
+ };
630
+ switch (t) {
631
+ case "top-left":
632
+ n.top = `max(${s}, env(safe-area-inset-top))`, n.left = `max(${s}, env(safe-area-inset-left))`;
633
+ break;
634
+ case "top-center":
635
+ n.top = `max(${s}, env(safe-area-inset-top))`, n.left = "50%", n.transform = "translateX(-50%)";
636
+ break;
637
+ case "top-right":
638
+ n.top = `max(${s}, env(safe-area-inset-top))`, n.right = `max(${s}, env(safe-area-inset-right))`;
639
+ break;
640
+ case "bottom-left":
641
+ n.bottom = `max(${s}, env(safe-area-inset-bottom))`, n.left = `max(${s}, env(safe-area-inset-left))`;
642
+ break;
643
+ case "bottom-center":
644
+ n.bottom = `max(${s}, env(safe-area-inset-bottom))`, n.left = "50%", n.transform = "translateX(-50%)";
645
+ break;
646
+ case "bottom-right":
647
+ n.bottom = `max(${s}, env(safe-area-inset-bottom))`, n.right = `max(${s}, env(safe-area-inset-right))`;
648
+ break;
649
+ case "center":
650
+ n.top = "50%", n.left = "50%", n.transform = "translate(-50%, -50%)";
651
+ break;
652
+ }
653
+ Object.assign(e.style, n), e.style.setProperty("--editora-toast-mobile-left", i);
654
+ }
655
+ toCssLength(e) {
656
+ return typeof e == "number" ? `${e}px` : e || "16px";
657
+ }
658
+ // Auto-dismiss timer. It keeps the time that is left, so pausing a toast and letting go does not give it a
659
+ // fresh full duration.
660
+ startTimer(e) {
661
+ if (this.stopTimer(e), e.options.persistent || e.options.duration === 0) {
662
+ this.timing.delete(e.id);
663
+ return;
664
+ }
665
+ this.arm(e, e.options.duration || this.config.duration);
666
+ }
667
+ arm(e, t) {
668
+ var s;
669
+ this.timing.set(e.id, { remaining: t, startedAt: Date.now() }), !((((s = this.holds.get(e.id)) == null ? void 0 : s.size) || 0) > 0) && (e.timeoutId = window.setTimeout(() => {
670
+ e.timeoutId = void 0, e.dismiss();
671
+ }, t));
672
+ }
673
+ stopTimer(e) {
674
+ e.timeoutId && (clearTimeout(e.timeoutId), e.timeoutId = void 0);
675
+ }
676
+ pauseToast(e, t = "hover") {
677
+ const s = this.holds.get(e.id) || /* @__PURE__ */ new Set();
678
+ if (this.holds.set(e.id, s), s.size === 0 && e.timeoutId) {
679
+ const i = this.timing.get(e.id);
680
+ this.stopTimer(e), i && (i.remaining = Math.max(0, i.remaining - (Date.now() - i.startedAt)));
681
+ }
682
+ s.add(t);
683
+ }
684
+ resumeToast(e, t = "hover") {
685
+ const s = this.holds.get(e.id);
686
+ if (!s || !s.delete(t) || s.size > 0) return;
687
+ this.holds.delete(e.id);
688
+ const i = this.timing.get(e.id);
689
+ i && !e.timeoutId && !e.options.persistent && e.options.duration !== 0 && this.arm(e, i.remaining);
690
+ }
691
+ // Swipe dismiss with directional control
692
+ addSwipeDismiss(e, t) {
693
+ let s = 0, i = 0, r = !1;
694
+ const n = t.options.swipeDirection || this.config.swipeDirection || "any", a = 40;
695
+ let c = "", l = !1;
696
+ const f = 'button, a[href], input, select, textarea, label, summary, [role="button"], [contenteditable="true"]', m = () => {
697
+ e.style.transform = c, e.style.transition = "", e.style.cursor = "", e.style.userSelect = "";
698
+ }, w = (u, b) => {
699
+ if ("changedTouches" in u || "touches" in u) {
700
+ const p = b ? u.changedTouches : u.touches, v = p && p[0];
701
+ return v ? { x: v.clientX, y: v.clientY } : null;
702
+ }
703
+ return { x: u.clientX, y: u.clientY };
704
+ }, A = (u) => {
705
+ const b = u.target;
706
+ if (b instanceof Element && e.contains(b) && b.closest(f) || "button" in u && u.button !== 0) return;
707
+ const p = w(u, !1);
708
+ p && (r = !0, l = !1, s = p.x, i = p.y, c = e.style.transform || "");
709
+ }, h = (u) => {
710
+ var y, q;
711
+ if (!r) return;
712
+ const b = w(u, !1);
713
+ if (!b) return;
714
+ const p = b.x - s, v = b.y - i, T = 5;
715
+ if (!l && (Math.abs(p) > T || Math.abs(v) > T) && (l = !0, e.style.transition = "none", e.style.cursor = "grabbing", e.style.userSelect = "none", (q = (y = window.getSelection) == null ? void 0 : y.call(window)) == null || q.removeAllRanges()), l) {
716
+ const E = Math.abs(v) > Math.abs(p) ? 25 : 20, Q = Math.min(Math.max(p * 0.2, -E), E), X = Math.min(Math.max(v * 0.2, -E), E);
717
+ e.style.transform = `${c} translate(${Q}px, ${X}px)`, u.cancelable && u.preventDefault();
718
+ }
719
+ }, g = (u) => {
720
+ if (!r) return;
721
+ r = !1;
722
+ const b = l;
723
+ if (m(), !b) return;
724
+ const p = w(u, !0);
725
+ if (!p) return;
726
+ const v = p.x - s, T = p.y - i;
727
+ let y = !1;
728
+ const E = n === "vertical" || n === "up" || n === "down" ? 35 : a;
729
+ switch (n) {
730
+ case "any":
731
+ y = Math.abs(v) > a || Math.abs(T) > a;
732
+ break;
733
+ case "horizontal":
734
+ y = Math.abs(v) > a;
735
+ break;
736
+ case "vertical":
737
+ y = Math.abs(T) > E;
738
+ break;
739
+ case "left":
740
+ y = v < -a;
741
+ break;
742
+ case "right":
743
+ y = v > a;
744
+ break;
745
+ case "up":
746
+ y = T < -E;
747
+ break;
748
+ case "down":
749
+ y = T > E;
750
+ break;
751
+ }
752
+ y && t.dismiss();
753
+ }, k = () => {
754
+ r && (r = !1, l = !1, m());
755
+ };
756
+ e.addEventListener("dragstart", (u) => u.preventDefault()), e.addEventListener("touchstart", A, { passive: !0 }), e.addEventListener("touchmove", h, { passive: !1 }), e.addEventListener("touchend", g), e.addEventListener("touchcancel", k), e.addEventListener("mousedown", A), e.addEventListener("mousemove", h), e.addEventListener("mouseup", g), e.addEventListener("mouseleave", g);
757
+ }
758
+ // Drag dismiss (simplified)
759
+ addDragDismiss(e, t) {
760
+ this.addSwipeDismiss(e, t);
761
+ }
762
+ // Accessibility
763
+ announceToast(e) {
764
+ if (e.options.ariaLive === "off") return;
765
+ const t = document.createElement("div");
766
+ t.setAttribute("aria-live", e.options.ariaLive || (e.options.level === "error" ? "assertive" : "polite")), t.setAttribute("aria-atomic", "true"), t.style.position = "absolute", t.style.left = "-10000px", t.style.width = "1px", t.style.height = "1px", t.style.overflow = "hidden";
767
+ const s = [e.options.title, e.options.message, e.options.description].map(me).filter(Boolean).join(". ");
768
+ t.textContent = `${e.options.level || "info"}: ${s}`, document.body.appendChild(t), setTimeout(() => {
769
+ t.remove();
770
+ }, 1e3);
771
+ }
772
+ // The stylesheet, once, with the first toast. In order:
773
+ // - toast.css is already on the page (linked, imported by a bundler, or put there earlier): nothing to do;
774
+ // - the built-in copy (the main entry has one) goes first in <head>, so the app's own CSS still wins;
775
+ // - otherwise (the lite entry, or injectStyles: false) a minimal layout style, and a warning.
776
+ injectCSS() {
777
+ if (this.cssInjected || typeof document == "undefined" || (this.cssInjected = !0, getComputedStyle(document.documentElement).getPropertyValue("--editora-toast-stylesheet").trim() !== "" || Array.from(document.styleSheets).some(
778
+ (n) => {
779
+ var a, c, l, f;
780
+ return ((c = (a = n.ownerNode) == null ? void 0 : a.href) == null ? void 0 : c.includes("toast.css")) || ((f = (l = n.ownerNode) == null ? void 0 : l.textContent) == null ? void 0 : f.includes("editora-toast"));
781
+ }
782
+ ))) return;
783
+ const s = document.createElement("style"), i = this.config.nonce || ge();
784
+ i && (s.nonce = i);
785
+ const r = this.config.injectStyles === !1 ? null : Y();
786
+ if (r) {
787
+ s.setAttribute("data-editora-toast", ""), s.textContent = r, document.head.insertBefore(s, document.head.firstChild);
788
+ return;
789
+ }
790
+ console.warn(
791
+ "[@editora/toast] toast.css is not loaded, so toasts use a minimal fallback style. Import '@editora/toast/toast.css' once in your app (or link @editora/toast/dist/toast.css)."
792
+ ), s.setAttribute("data-editora-toast-fallback", "true"), s.textContent = ".editora-toast-container{position:fixed;width:360px;max-width:100vw;box-sizing:border-box}.editora-toast{position:absolute;left:0;width:100%;box-sizing:border-box;padding:12px 14px;background:#fff;color:#111;border:1px solid #ddd;border-radius:12px;font:13px/1.45 system-ui,sans-serif;overflow:hidden;pointer-events:auto;opacity:0;translate:0 var(--et-y,0px);scale:var(--et-s,1);transition:opacity .2s,translate .3s,scale .3s,height .3s}.editora-toast-container[data-edge=bottom] .editora-toast{bottom:0}.editora-toast-container[data-edge=top] .editora-toast{top:0}.editora-toast.show{opacity:1}.editora-toast.hiding,.editora-toast[data-hidden=true]{opacity:0}", document.head.appendChild(s);
793
+ }
794
+ // Cleanup
795
+ destroy() {
796
+ var e;
797
+ (e = this.resizeObserver) == null || e.disconnect(), this.resizeObserver = null, this.globalListeners.forEach(([t, s, i]) => t.removeEventListener(s, i)), this.globalListeners = [], window.clearTimeout(this.resizeTimer), this.containers.forEach((t) => {
798
+ t.parentNode && t.parentNode.removeChild(t);
799
+ }), this.containers.clear();
800
+ }
801
+ }
802
+ class ve {
803
+ constructor() {
804
+ this.plugins = [], this.hooks = {
805
+ beforeShow: [],
806
+ afterShow: [],
807
+ beforeHide: [],
808
+ afterHide: [],
809
+ beforeUpdate: [],
810
+ afterUpdate: []
811
+ };
812
+ }
813
+ // Plugin management
814
+ use(e) {
815
+ if (this.plugins.find((t) => t.name === e.name)) {
816
+ console.warn(`Plugin "${e.name}" is already installed`);
817
+ return;
818
+ }
819
+ this.plugins.push(e), e.install(this);
820
+ }
821
+ remove(e) {
822
+ const t = this.plugins.findIndex((i) => i.name === e);
823
+ if (t === -1) return !1;
824
+ const s = this.plugins[t];
825
+ return s.uninstall && s.uninstall(this), this.plugins.splice(t, 1), !0;
826
+ }
827
+ getPlugins() {
828
+ return [...this.plugins];
829
+ }
830
+ // Hook registration
831
+ on(e, t) {
832
+ this.hooks[e] && this.hooks[e].push(t);
833
+ }
834
+ off(e, t) {
835
+ if (this.hooks[e]) {
836
+ const s = this.hooks[e].indexOf(t);
837
+ s !== -1 && this.hooks[e].splice(s, 1);
838
+ }
839
+ }
840
+ // Hook execution
841
+ async trigger(e, t, ...s) {
842
+ const i = this.hooks[e];
843
+ if (!(!i || i.length === 0))
844
+ for (const r of i)
845
+ try {
846
+ await r(t, ...s);
847
+ } catch (n) {
848
+ console.error(`Error in ${e} hook:`, n);
849
+ }
850
+ }
851
+ // Convenience methods for common lifecycle events
852
+ async beforeShow(e) {
853
+ await this.trigger("beforeShow", e);
854
+ }
855
+ async afterShow(e) {
856
+ await this.trigger("afterShow", e);
857
+ }
858
+ async beforeHide(e) {
859
+ await this.trigger("beforeHide", e);
860
+ }
861
+ async afterHide(e) {
862
+ await this.trigger("afterHide", e);
863
+ }
864
+ async beforeUpdate(e, t) {
865
+ await this.trigger("beforeUpdate", e, t);
866
+ }
867
+ async afterUpdate(e, t) {
868
+ await this.trigger("afterUpdate", e, t);
869
+ }
870
+ // Editor integration hooks (for RTE)
871
+ onEditorEvent(e, t) {
872
+ const s = `editor:${e}`;
873
+ this.hooks[s] || (this.hooks[s] = []), this.hooks[s].push(t);
874
+ }
875
+ triggerEditorEvent(e, t, ...s) {
876
+ const i = `editor:${e}`;
877
+ this.trigger(i, t, ...s);
878
+ }
879
+ // Promise lifecycle helpers
880
+ async handlePromise(e, t, s, i) {
881
+ t();
882
+ try {
883
+ const r = await e;
884
+ return s(r), r;
885
+ } catch (r) {
886
+ throw i(r), r;
887
+ }
888
+ }
889
+ // Batch operations
890
+ async batchShow(e) {
891
+ const t = e.map((i) => this.beforeShow(i));
892
+ await Promise.all(t);
893
+ const s = e.map((i) => this.afterShow(i));
894
+ await Promise.all(s);
895
+ }
896
+ async batchHide(e) {
897
+ const t = e.map((i) => this.beforeHide(i));
898
+ await Promise.all(t);
899
+ const s = e.map((i) => this.afterHide(i));
900
+ await Promise.all(s);
901
+ }
902
+ // Cleanup
903
+ destroy() {
904
+ this.plugins.forEach((e) => {
905
+ e.uninstall && e.uninstall(this);
906
+ }), this.plugins = [], Object.keys(this.hooks).forEach((e) => {
907
+ this.hooks[e] = [];
908
+ });
909
+ }
910
+ }
911
+ const ye = (o) => typeof Node != "undefined" && o instanceof Node, j = {
912
+ position: "bottom-right",
913
+ duration: 4e3,
914
+ maxVisible: 3,
915
+ queueStrategy: "fifo",
916
+ theme: "system",
917
+ richColors: !1,
918
+ expand: !1,
919
+ stack: !0,
920
+ offset: 16,
921
+ mobileOffset: 16,
922
+ gap: 8,
923
+ pauseOnHover: !0,
924
+ pauseOnFocus: !0,
925
+ pauseOnWindowBlur: !1,
926
+ // Don't pause by default
927
+ swipeDismiss: !0,
928
+ swipeDirection: "any",
929
+ // Allow any direction by default
930
+ dragDismiss: !1,
931
+ rtl: !1,
932
+ // LTR by default
933
+ enableAccessibility: !0,
934
+ closeButton: !1,
935
+ icons: !0,
936
+ hotkey: "alt+t",
937
+ preventDuplicate: !1,
938
+ dedupeScope: "all",
939
+ animation: { type: "css" }
940
+ // Default to CSS animations
941
+ };
942
+ class D {
943
+ constructor(e = {}) {
944
+ this.idCounter = 0, this.pendingShows = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Set(), this.config = this.normalizeConfig({ ...j, ...e }), this.store = new J(this.config), this.queue = new Z(this.config), this.renderer = new be(this.config), this.lifecycle = new ve(), this.setupWindowFocusHandling();
945
+ }
946
+ // Core API
947
+ show(e) {
948
+ const t = e.id || `toast-${++this.idCounter}`, s = {
949
+ id: t,
950
+ options: this.normalizeToastOptions({ ...this.config, ...e }, e),
951
+ createdAt: Date.now(),
952
+ dismiss: () => this.dismiss(t),
953
+ update: (n) => this.update(t, n)
954
+ }, i = this.lifecycle.beforeShow(s).then(async () => {
955
+ const n = this.queue.enqueue(s);
956
+ n.rejected || (this.store.addToast(s), await this.hideToasts(n.hide, !0), await this.showToasts(n.show), this.notify());
957
+ });
958
+ this.pendingShows.set(t, i);
959
+ const r = () => {
960
+ this.pendingShows.get(t) === i && this.pendingShows.delete(t);
961
+ };
962
+ return i.then(r, r), s;
963
+ }
964
+ update(e, t) {
965
+ const s = this.pendingShows.get(e);
966
+ if (s)
967
+ return s.then(() => this.update(e, t), () => {
968
+ }), !0;
969
+ const i = this.store.getToast(e);
970
+ return i ? (this.lifecycle.beforeUpdate(i, t).then(async () => {
971
+ const r = this.normalizeToastOptions({ ...i.options, ...t }, t);
972
+ this.store.updateToast(e, { options: r }), this.queue.isVisible(e) && await this.renderer.updateToast(i, t), this.lifecycle.afterUpdate(i, t), this.notify();
973
+ }), !0) : !1;
974
+ }
975
+ dismiss(e) {
976
+ const t = this.pendingShows.get(e);
977
+ if (t)
978
+ return t.then(() => this.dismiss(e), () => {
979
+ }), !0;
980
+ const s = this.store.getToast(e);
981
+ return s ? (this.lifecycle.beforeHide(s).then(async () => {
982
+ const i = this.queue.isVisible(e), r = this.queue.dequeue(e);
983
+ i && await this.renderer.hideToast(s), this.store.removeToast(e), this.lifecycle.afterHide(s), await this.showToasts(r.show), this.notify();
984
+ }), !0) : !1;
985
+ }
986
+ clear() {
987
+ const e = this.queue.clear();
988
+ Promise.all(e.map((t) => this.hideOne(t, !1))).then(() => {
989
+ this.store.clear(), this.notify();
990
+ });
991
+ }
992
+ // Promise API
993
+ async promise(e, t) {
994
+ var i, r;
995
+ const s = this.show({ duration: 0, ...this.normalizeOptions(t.loading, "loading") });
996
+ try {
997
+ const n = await e, a = this.normalizeResult(
998
+ typeof t.success == "function" ? t.success(n) : t.success,
999
+ "success"
1000
+ );
1001
+ return a.duration === void 0 && !a.persistent && (a.duration = this.config.duration), this.update(s.id, a), (i = t.onSuccess) == null || i.call(t, n), n;
1002
+ } catch (n) {
1003
+ const a = this.normalizeResult(
1004
+ typeof t.error == "function" ? t.error(n) : t.error,
1005
+ "error"
1006
+ );
1007
+ throw a.duration === void 0 && !a.persistent && (a.duration = this.config.duration), this.update(s.id, a), (r = t.onError) == null || r.call(t, n), n;
1008
+ }
1009
+ }
1010
+ // Group API
1011
+ group(e, t) {
1012
+ return this.show({ ...t, group: e });
1013
+ }
1014
+ // Plugin API
1015
+ use(e) {
1016
+ this.lifecycle.use(e);
1017
+ }
1018
+ // Configuration
1019
+ configure(e) {
1020
+ const t = this.config.pauseOnWindowBlur, s = { ...this.config, ...e };
1021
+ e.maxVisible !== void 0 && e.visibleToasts === void 0 && delete s.visibleToasts, this.config = this.normalizeConfig(s), this.store.updateConfig(this.config), this.renderer.updateConfig(this.config);
1022
+ const i = this.queue.updateConfig(this.config);
1023
+ this.hideToasts(i.hide, !0).then(() => this.showToasts(i.show)).then(() => this.notify()), e.pauseOnWindowBlur !== void 0 && e.pauseOnWindowBlur !== t && (this.teardownWindowFocusHandling(), this.setupWindowFocusHandling());
1024
+ }
1025
+ getConfig() {
1026
+ return { ...this.config };
1027
+ }
1028
+ // State queries
1029
+ getToasts() {
1030
+ return this.store.getAllToasts();
1031
+ }
1032
+ getState() {
1033
+ return {
1034
+ toasts: this.store.getAllToasts(),
1035
+ visible: this.queue.getVisible(),
1036
+ queued: this.queue.getQueued(),
1037
+ groups: this.store.getAllGroups(),
1038
+ config: this.getConfig()
1039
+ };
1040
+ }
1041
+ subscribe(e) {
1042
+ return this.subscribers.add(e), e(this.getState()), () => {
1043
+ this.subscribers.delete(e);
1044
+ };
1045
+ }
1046
+ getGroups() {
1047
+ return this.store.getAllGroups();
1048
+ }
1049
+ // Convenience methods for backward compatibility
1050
+ info(e, t) {
1051
+ return this.show({ message: e, level: "info", duration: t });
1052
+ }
1053
+ success(e, t) {
1054
+ return this.show({ message: e, level: "success", duration: t });
1055
+ }
1056
+ error(e, t) {
1057
+ return this.show({ message: e, level: "error", duration: t });
1058
+ }
1059
+ warning(e, t) {
1060
+ return this.show({ message: e, level: "warning", duration: t });
1061
+ }
1062
+ loading(e, t) {
1063
+ return this.show({ message: e, level: "loading", duration: t });
1064
+ }
1065
+ // Utility methods
1066
+ normalizeOptions(e, t) {
1067
+ return typeof e == "string" || ye(e) ? { message: e, level: t } : { ...e, level: e.level || t };
1068
+ }
1069
+ // The result of a promise replaces the loading toast's text. update() merges, so a result given as options
1070
+ // without a message (a title and a description, say) would otherwise keep showing the loading message.
1071
+ normalizeResult(e, t) {
1072
+ const s = this.normalizeOptions(e, t);
1073
+ return "message" in s ? s : { ...s, message: void 0 };
1074
+ }
1075
+ normalizeConfig(e) {
1076
+ const t = e.visibleToasts || e.maxVisible || j.maxVisible;
1077
+ return {
1078
+ ...e,
1079
+ maxVisible: t,
1080
+ visibleToasts: t
1081
+ };
1082
+ }
1083
+ // `options` is the caller's options already merged over the config (or over the toast's current options when
1084
+ // updating); `explicit` is just what the caller passed. The close button has to be decided from what the
1085
+ // caller passed first: the merged object always carries the config's `closeButton: false`, so reading it
1086
+ // first made an explicit `closable: true` lose and the documented option silently did nothing.
1087
+ normalizeToastOptions(e, t = e) {
1088
+ var n, a, c, l, f, m;
1089
+ const s = (l = (c = (a = (n = t.closeButton) != null ? n : t.closable) != null ? a : e.closable) != null ? c : e.closeButton) != null ? l : this.config.closeButton, i = e.action ? { ...e.action, primary: (f = e.action.primary) != null ? f : !0 } : void 0, r = [
1090
+ ...i ? [i] : [],
1091
+ ...e.cancel ? [e.cancel] : [],
1092
+ ...e.actions || []
1093
+ ];
1094
+ return {
1095
+ ...e,
1096
+ closable: s,
1097
+ // Keep the alias in step: the renderer shows the button if either flag is set, and the merged config
1098
+ // value would otherwise re-enable a button the caller explicitly turned off.
1099
+ closeButton: s,
1100
+ actions: r.length > 0 ? r : void 0,
1101
+ ariaLive: e.ariaLive || (e.level === "error" || e.important ? "assertive" : "polite"),
1102
+ role: e.role || (e.level === "error" || e.important ? "alert" : "status"),
1103
+ preventDuplicate: (m = e.preventDuplicate) != null ? m : this.config.preventDuplicate,
1104
+ dedupeScope: e.dedupeScope || this.config.dedupeScope
1105
+ };
1106
+ }
1107
+ async showToasts(e) {
1108
+ for (const t of e)
1109
+ await this.renderer.showToast(t), await this.lifecycle.afterShow(t);
1110
+ }
1111
+ async hideToasts(e, t) {
1112
+ for (const s of e)
1113
+ await this.hideOne(s, t);
1114
+ }
1115
+ async hideOne(e, t) {
1116
+ await this.lifecycle.beforeHide(e), await this.renderer.hideToast(e), t && this.store.removeToast(e.id), await this.lifecycle.afterHide(e);
1117
+ }
1118
+ notify() {
1119
+ if (this.subscribers.size === 0) return;
1120
+ const e = this.getState();
1121
+ this.subscribers.forEach((t) => t(e));
1122
+ }
1123
+ // Editor integration (for RTE)
1124
+ onEditorEvent(e, t) {
1125
+ this.lifecycle.onEditorEvent(e, t);
1126
+ }
1127
+ triggerEditorEvent(e, t, ...s) {
1128
+ this.lifecycle.triggerEditorEvent(e, t, ...s);
1129
+ }
1130
+ // Window focus/blur handling
1131
+ setupWindowFocusHandling() {
1132
+ typeof window == "undefined" || typeof document == "undefined" || !this.config.pauseOnWindowBlur || (this.teardownWindowFocusHandling(), this.windowBlurHandler = () => this.pauseAllToasts(), this.windowFocusHandler = () => this.resumeAllToasts(), this.visibilityChangeHandler = () => {
1133
+ document.hidden ? this.pauseAllToasts() : this.resumeAllToasts();
1134
+ }, window.addEventListener("blur", this.windowBlurHandler), window.addEventListener("focus", this.windowFocusHandler), document.addEventListener("visibilitychange", this.visibilityChangeHandler));
1135
+ }
1136
+ teardownWindowFocusHandling() {
1137
+ typeof window != "undefined" && (this.windowBlurHandler && (window.removeEventListener("blur", this.windowBlurHandler), this.windowBlurHandler = void 0), this.windowFocusHandler && (window.removeEventListener("focus", this.windowFocusHandler), this.windowFocusHandler = void 0), typeof document != "undefined" && this.visibilityChangeHandler && (document.removeEventListener("visibilitychange", this.visibilityChangeHandler), this.visibilityChangeHandler = void 0));
1138
+ }
1139
+ pauseAllToasts() {
1140
+ this.store.getAllToasts().forEach((e) => this.renderer.pauseToast(e, "window"));
1141
+ }
1142
+ resumeAllToasts() {
1143
+ this.store.getAllToasts().forEach((e) => this.renderer.resumeToast(e, "window"));
1144
+ }
1145
+ // Cleanup
1146
+ destroy() {
1147
+ this.teardownWindowFocusHandling(), this.clear(), this.renderer.destroy(), this.lifecycle.destroy();
1148
+ }
1149
+ }
1150
+ let x = null;
1151
+ function d() {
1152
+ return x || (x = new D()), x;
1153
+ }
1154
+ const we = (o) => ({
1155
+ id: o.id || "",
1156
+ options: o,
1157
+ createdAt: 0,
1158
+ dismiss: () => {
1159
+ },
1160
+ update: () => {
1161
+ }
1162
+ });
1163
+ function $(o) {
1164
+ return typeof document == "undefined" ? we(o) : d().show(o);
1165
+ }
1166
+ function U(o, e, t, s) {
1167
+ let i = {};
1168
+ e && typeof e == "object" ? i = { ...e } : typeof e == "number" && (i.duration = e), t && (i.theme = t), s && (i.position = s);
1169
+ const r = {
1170
+ message: o,
1171
+ ...i,
1172
+ level: i.level || void 0
1173
+ };
1174
+ return i.duration !== void 0 && (r.duration = i.duration), i.position && (r.position = i.position), i.theme && (r.theme = i.theme), r;
1175
+ }
1176
+ function C(o) {
1177
+ return (e, t, s, i) => $({
1178
+ ...U(e, t, s, i),
1179
+ level: o
1180
+ });
1181
+ }
1182
+ const S = () => typeof document != "undefined";
1183
+ function Ee(o, e, t, s) {
1184
+ const i = U(o, e, t, s);
1185
+ return $({ ...i, level: i.level || "custom" });
1186
+ }
1187
+ const G = Object.assign(Ee, {
1188
+ info: C("info"),
1189
+ success: C("success"),
1190
+ error: C("error"),
1191
+ warning: C("warning"),
1192
+ loading: C("loading"),
1193
+ // Full options (title, description, actions, progress, ...). Returns the toast.
1194
+ show: (o) => $(o),
1195
+ // One toast that follows a promise from loading to success or error. Resolves with the promise's value.
1196
+ promise: (o, e) => S() ? d().promise(o, e) : o,
1197
+ update: (o, e) => S() ? d().update(o, e) : !1,
1198
+ // With an id: that toast. Without: all of them.
1199
+ dismiss: (o) => S() ? o === void 0 ? (d().clear(), !0) : d().dismiss(o) : !1,
1200
+ clear: () => {
1201
+ S() && d().clear();
1202
+ },
1203
+ configure: (o) => {
1204
+ S() && d().configure(o);
1205
+ }
1206
+ }), L = {
1207
+ // Core methods
1208
+ show: (o) => d().show(o),
1209
+ update: (o, e) => d().update(o, e),
1210
+ dismiss: (o) => d().dismiss(o),
1211
+ clear: () => d().clear(),
1212
+ // Convenience methods
1213
+ info: (o, e) => d().show({ message: o, level: "info", ...e }),
1214
+ success: (o, e) => d().show({ message: o, level: "success", ...e }),
1215
+ error: (o, e) => d().show({ message: o, level: "error", ...e }),
1216
+ warning: (o, e) => d().show({ message: o, level: "warning", ...e }),
1217
+ loading: (o, e) => d().show({ message: o, level: "loading", ...e }),
1218
+ // Advanced features
1219
+ promise: (o, e) => d().promise(o, e),
1220
+ group: (o, e) => d().group(o, e),
1221
+ configure: (o) => d().configure(o),
1222
+ use: (o) => d().use(o),
1223
+ // State queries
1224
+ getToasts: () => d().getToasts(),
1225
+ getGroups: () => d().getGroups(),
1226
+ getConfig: () => d().getConfig(),
1227
+ getState: () => d().getState(),
1228
+ subscribe: (o) => d().subscribe(o),
1229
+ // Editor integration
1230
+ onEditorEvent: (o, e) => d().onEditorEvent(o, e),
1231
+ triggerEditorEvent: (o, e, ...t) => d().triggerEditorEvent(o, e, ...t),
1232
+ // Cleanup
1233
+ destroy: () => {
1234
+ x && (x.destroy(), x = null);
1235
+ }
1236
+ };
1237
+ if (typeof window != "undefined" && typeof document != "undefined") {
1238
+ const o = window;
1239
+ o.toast = G, o.toastAdvanced = L, o.toastPro = L, o.ToastManager = D, o.__editoraToastReady || (o.__editoraToastReady = !0, window.dispatchEvent(
1240
+ new CustomEvent("toastReady", {
1241
+ detail: { toast: G, toastAdvanced: L, toastPro: L, ToastManager: D }
1242
+ })
1243
+ ));
1244
+ }
1245
+ export {
1246
+ D as T,
1247
+ L as a,
1248
+ Te as p,
1249
+ G as t
1250
+ };
1251
+ //# sourceMappingURL=toast-CISbzOBc.es.js.map