wulf.js 1.9.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +124 -78
  2. package/changelog.md +105 -0
  3. package/dist/focus-trap.esm.js +245 -126
  4. package/dist/focus-trap.esm.js.map +3 -3
  5. package/dist/focus-trap.global.js +247 -128
  6. package/dist/focus-trap.global.js.map +3 -3
  7. package/dist/focus-trap.global.min.js +4 -4
  8. package/dist/focus-trap.global.min.js.map +4 -4
  9. package/dist/index.esm.js +2434 -905
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +2436 -907
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +4 -4
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.css +1 -1
  16. package/dist/mask.css.map +2 -2
  17. package/dist/mask.esm.js +746 -346
  18. package/dist/mask.esm.js.map +3 -3
  19. package/dist/mask.global.js +748 -348
  20. package/dist/mask.global.js.map +3 -3
  21. package/dist/mask.global.min.js +4 -4
  22. package/dist/mask.global.min.js.map +4 -4
  23. package/dist/mask.layered.css +1 -0
  24. package/dist/mask.layered.css.map +7 -0
  25. package/dist/masonry.css +1 -1
  26. package/dist/masonry.css.map +2 -2
  27. package/dist/masonry.esm.js +341 -114
  28. package/dist/masonry.esm.js.map +3 -3
  29. package/dist/masonry.global.js +343 -116
  30. package/dist/masonry.global.js.map +3 -3
  31. package/dist/masonry.global.min.js +4 -4
  32. package/dist/masonry.global.min.js.map +4 -4
  33. package/dist/masonry.layered.css +1 -0
  34. package/dist/masonry.layered.css.map +7 -0
  35. package/dist/scroll.css +1 -1
  36. package/dist/scroll.css.map +2 -2
  37. package/dist/scroll.esm.js +524 -153
  38. package/dist/scroll.esm.js.map +3 -3
  39. package/dist/scroll.global.js +526 -155
  40. package/dist/scroll.global.js.map +3 -3
  41. package/dist/scroll.global.min.js +4 -4
  42. package/dist/scroll.global.min.js.map +4 -4
  43. package/dist/scroll.layered.css +1 -0
  44. package/dist/scroll.layered.css.map +7 -0
  45. package/dist/shortcut.esm.js +209 -46
  46. package/dist/shortcut.esm.js.map +3 -3
  47. package/dist/shortcut.global.js +211 -48
  48. package/dist/shortcut.global.js.map +3 -3
  49. package/dist/shortcut.global.min.js +2 -2
  50. package/dist/shortcut.global.min.js.map +4 -4
  51. package/dist/toast.css +1 -1
  52. package/dist/toast.css.map +2 -2
  53. package/dist/toast.esm.js +590 -160
  54. package/dist/toast.esm.js.map +3 -3
  55. package/dist/toast.global.js +592 -162
  56. package/dist/toast.global.js.map +3 -3
  57. package/dist/toast.global.min.js +4 -4
  58. package/dist/toast.global.min.js.map +4 -4
  59. package/dist/toast.layered.css +1 -0
  60. package/dist/toast.layered.css.map +7 -0
  61. package/dist/types/common/dom.d.ts +38 -0
  62. package/dist/types/focus-trap/FocusTrap.d.ts +15 -5
  63. package/dist/types/focus-trap/types.d.ts +2 -2
  64. package/dist/types/index.d.ts +10 -0
  65. package/dist/types/mask/AmountEngine.d.ts +1 -0
  66. package/dist/types/mask/BaseInputMask.d.ts +24 -0
  67. package/dist/types/mask/InputAmountMask.d.ts +3 -0
  68. package/dist/types/mask/InputEmailMask.d.ts +16 -1
  69. package/dist/types/mask/InputMask.d.ts +1 -0
  70. package/dist/types/mask/MaskEngine.d.ts +4 -0
  71. package/dist/types/masonry/Masonry.d.ts +10 -3
  72. package/dist/types/scroll/ScrollBlock.d.ts +31 -3
  73. package/dist/types/scroll/types.d.ts +13 -1
  74. package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
  75. package/dist/types/shortcut/ShortcutManager.d.ts +5 -0
  76. package/dist/types/toast/Toast.d.ts +4 -0
  77. package/dist/types/toast/ToastInstance.d.ts +22 -10
  78. package/dist/types/toast/ToastManager.d.ts +37 -4
  79. package/dist/types/toast/i18n/types.d.ts +2 -0
  80. package/dist/types/toast/types.d.ts +14 -2
  81. package/package.json +20 -5
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var Wulf = (() => {
2
+ var __WulfIIFE = (() => {
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -32,36 +32,97 @@ var Wulf = (() => {
32
32
  toastI18n: () => toastI18n
33
33
  });
34
34
 
35
+ // src/common/dom.ts
36
+ function getSafeWulfNamespace() {
37
+ if (typeof window === "undefined") return null;
38
+ const win = window;
39
+ const existing = win.Wulf;
40
+ if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
41
+ const fresh = {};
42
+ win.Wulf = fresh;
43
+ return fresh;
44
+ }
45
+ return existing;
46
+ }
47
+ function prefersReducedMotion() {
48
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
49
+ }
50
+ function waitForAnimations(element, fallbackMs, signal) {
51
+ const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
52
+ if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
53
+ return Promise.resolve();
54
+ }
55
+ const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
56
+ if (a.playState !== "running") return false;
57
+ const timing = a.effect?.getComputedTiming?.();
58
+ return timing ? Number.isFinite(timing.endTime) : true;
59
+ }) : [];
60
+ if (animations.length === 0) {
61
+ return Promise.resolve();
62
+ }
63
+ return new Promise((resolve) => {
64
+ let settled = false;
65
+ let timerId = null;
66
+ const finish = () => {
67
+ if (settled) return;
68
+ settled = true;
69
+ if (timerId !== null) {
70
+ clearTimeout(timerId);
71
+ timerId = null;
72
+ }
73
+ signal?.removeEventListener("abort", finish);
74
+ resolve();
75
+ };
76
+ signal?.addEventListener("abort", finish, { once: true });
77
+ timerId = setTimeout(finish, safeFallback);
78
+ Promise.allSettled(animations.map((a) => a.finished)).then(finish);
79
+ });
80
+ }
81
+
35
82
  // src/common/i18n.ts
83
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
84
+ function isSafeKey(key) {
85
+ return Boolean(key) && !FORBIDDEN_KEYS.has(key);
86
+ }
36
87
  function normalizeLocaleCode(locale) {
37
- return locale.trim().toLowerCase().replace(/_/g, "-");
88
+ const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
89
+ return isSafeKey(norm) ? norm : "";
38
90
  }
39
91
  function getPrimaryLanguage(normalizedLocale) {
40
92
  const dashIndex = normalizedLocale.indexOf("-");
41
- return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
93
+ const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
94
+ return primary && isSafeKey(primary) ? primary : null;
42
95
  }
43
96
  function assignDefined(target, source) {
44
- if (!source) return target;
97
+ if (!source || typeof source !== "object") return target;
45
98
  for (const key of Object.keys(source)) {
46
- if (source[key] !== void 0) {
99
+ if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
47
100
  target[key] = source[key];
48
101
  }
49
102
  }
50
103
  return target;
51
104
  }
52
105
  function createI18nManager(defaultLocale, locales) {
53
- const fallbackLocale = normalizeLocaleCode(defaultLocale);
54
- const initialLocales = {};
106
+ const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
107
+ const initialLocales = /* @__PURE__ */ Object.create(null);
55
108
  for (const [loc, dict] of Object.entries(locales)) {
56
- initialLocales[normalizeLocaleCode(loc)] = { ...dict };
109
+ const norm = normalizeLocaleCode(loc);
110
+ if (norm) {
111
+ initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
112
+ }
57
113
  }
58
114
  let currentLocale = fallbackLocale;
59
- let activeLocales = { ...initialLocales };
60
- let globalOverrides = {};
115
+ let activeLocales = /* @__PURE__ */ Object.create(null);
116
+ for (const [loc, dict] of Object.entries(initialLocales)) {
117
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
118
+ }
119
+ let globalOverrides = /* @__PURE__ */ Object.create(null);
61
120
  function resolveActiveDictionaries() {
62
121
  const dicts = [];
63
- const exact = activeLocales[currentLocale];
64
- if (exact) dicts.push(exact);
122
+ if (isSafeKey(currentLocale)) {
123
+ const exact = activeLocales[currentLocale];
124
+ if (exact) dicts.push(exact);
125
+ }
65
126
  const primary = getPrimaryLanguage(currentLocale);
66
127
  if (primary && activeLocales[primary]) {
67
128
  dicts.push(activeLocales[primary]);
@@ -70,24 +131,33 @@ var Wulf = (() => {
70
131
  }
71
132
  return {
72
133
  setLocale(locale) {
73
- if (locale && locale.trim()) {
74
- currentLocale = normalizeLocaleCode(locale);
134
+ if (locale && typeof locale === "string" && locale.trim()) {
135
+ const norm = normalizeLocaleCode(locale);
136
+ if (norm) {
137
+ currentLocale = norm;
138
+ }
75
139
  }
76
140
  },
77
141
  getLocale() {
78
142
  return currentLocale;
79
143
  },
80
144
  registerLocale(locale, translations) {
81
- if (!locale || !locale.trim() || !translations) return;
145
+ if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
82
146
  const norm = normalizeLocaleCode(locale);
83
- activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
147
+ if (!norm) return;
148
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
149
+ activeLocales[norm] = assignDefined(base, translations);
84
150
  },
85
151
  setI18n(overrides) {
86
- if (!overrides) return;
87
- globalOverrides = assignDefined({ ...globalOverrides }, overrides);
152
+ if (!overrides || typeof overrides !== "object") return;
153
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
154
+ globalOverrides = assignDefined(base, overrides);
88
155
  },
89
156
  t(key, instanceOverride) {
90
- if (instanceOverride && instanceOverride[key] !== void 0) {
157
+ if (!isSafeKey(String(key))) {
158
+ return "";
159
+ }
160
+ if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
91
161
  return String(instanceOverride[key]);
92
162
  }
93
163
  if (globalOverrides[key] !== void 0) {
@@ -118,10 +188,10 @@ var Wulf = (() => {
118
188
  },
119
189
  reset() {
120
190
  currentLocale = fallbackLocale;
121
- globalOverrides = {};
122
- activeLocales = {};
191
+ globalOverrides = /* @__PURE__ */ Object.create(null);
192
+ activeLocales = /* @__PURE__ */ Object.create(null);
123
193
  for (const [loc, dict] of Object.entries(initialLocales)) {
124
- activeLocales[loc] = { ...dict };
194
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
125
195
  }
126
196
  }
127
197
  };
@@ -159,8 +229,11 @@ var Wulf = (() => {
159
229
  const rawValue = element.getAttribute(attrName)?.trim();
160
230
  if (!rawValue) return false;
161
231
  const doc = element.ownerDocument || document;
232
+ const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
162
233
  const ids = rawValue.split(/\s+/).filter(Boolean);
163
- const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
234
+ const isValid = ids.length > 0 && ids.every(
235
+ (id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
236
+ );
164
237
  if (!isValid) {
165
238
  warnings.push(
166
239
  `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
@@ -172,6 +245,7 @@ var Wulf = (() => {
172
245
 
173
246
  // src/common/LocalizedComponent.ts
174
247
  var LocalizedComponent = class extends AuditableComponent {
248
+ static _i18n;
175
249
  /**
176
250
  * Définit la langue globale du composant (ex: 'fr', 'en', 'es').
177
251
  */
@@ -222,6 +296,10 @@ var Wulf = (() => {
222
296
  static t(key, instanceOverride) {
223
297
  return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
224
298
  }
299
+ /**
300
+ * Surcharges de localisation spécifiques à cette instance.
301
+ */
302
+ i18nOverrides;
225
303
  constructor(i18nOverrides) {
226
304
  super();
227
305
  this.i18nOverrides = i18nOverrides;
@@ -237,12 +315,14 @@ var Wulf = (() => {
237
315
 
238
316
  // src/toast/i18n/fr.ts
239
317
  var toastFr = {
240
- closeButton: "Fermer la notification"
318
+ closeButton: "Fermer la notification",
319
+ notificationsRegion: "Notifications"
241
320
  };
242
321
 
243
322
  // src/toast/i18n/en.ts
244
323
  var toastEn = {
245
- closeButton: "Close notification"
324
+ closeButton: "Close notification",
325
+ notificationsRegion: "Notifications"
246
326
  };
247
327
 
248
328
  // src/toast/i18n/index.ts
@@ -253,22 +333,54 @@ var Wulf = (() => {
253
333
 
254
334
  // src/toast/ToastInstance.ts
255
335
  var nextToastId = 1;
336
+ var DEFAULT_TOAST_DURATION = 5e3;
337
+ function isSafeCssValue(val) {
338
+ if (!val || typeof val !== "string" || val.length > 128) return false;
339
+ const trimmed = val.trim();
340
+ if (!trimmed) return false;
341
+ if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
342
+ return false;
343
+ }
344
+ if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
345
+ return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
346
+ }
347
+ return true;
348
+ }
349
+ function sanitizeIconClasses(icon) {
350
+ return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
351
+ }
256
352
  var ToastInstance = class extends AuditableComponent {
353
+ id;
354
+ options;
355
+ element;
356
+ _isClosed = false;
357
+ _isFinalized = false;
358
+ closePromise = null;
359
+ timerId = null;
360
+ remainingTime = 0;
361
+ hasDuration = false;
362
+ timerStartTime = 0;
363
+ isPausedByHover = false;
364
+ isPausedByFocus = false;
365
+ isPausedByVisibility = false;
366
+ isPendingFocusDismiss = false;
367
+ previousActiveElement = null;
368
+ eventsAbortController = new AbortController();
369
+ disposeAbortController = new AbortController();
370
+ onDismissCallback;
257
371
  constructor(options, onDismiss) {
258
372
  super();
259
- this._isClosed = false;
260
- this.timerId = null;
261
- this.remainingTime = 0;
262
- this.timerStartTime = 0;
263
- this.isPaused = false;
264
373
  this.id = `wulf-toast-${nextToastId++}`;
265
374
  this.options = Object.freeze({ ...options });
266
375
  this.onDismissCallback = onDismiss;
267
- const duration = options.duration === void 0 ? 4e3 : options.duration;
268
- if (typeof duration === "number" && duration > 0) {
269
- this.remainingTime = duration;
376
+ this.previousActiveElement = typeof document !== "undefined" && document.activeElement instanceof HTMLElement ? document.activeElement : null;
377
+ const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
378
+ if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
379
+ this.remainingTime = Math.min(duration, 2147483647);
380
+ this.hasDuration = true;
270
381
  } else {
271
382
  this.remainingTime = 0;
383
+ this.hasDuration = false;
272
384
  }
273
385
  this.element = this.createDOM();
274
386
  this.bindEvents();
@@ -277,6 +389,9 @@ var Wulf = (() => {
277
389
  get isClosed() {
278
390
  return this._isClosed;
279
391
  }
392
+ getPreviousActiveElement() {
393
+ return this.previousActiveElement;
394
+ }
280
395
  /**
281
396
  * Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
282
397
  * et retourne la liste des contraintes manquantes.
@@ -290,7 +405,7 @@ var Wulf = (() => {
290
405
  "Contenu textuel vide : d\xE9finissez au moins un title ou un message pour que le lecteur d'\xE9cran puisse annoncer la notification (WCAG 4.1.3)."
291
406
  );
292
407
  }
293
- const duration = this.options.duration === void 0 ? 4e3 : this.options.duration;
408
+ const duration = this.options.duration === void 0 ? DEFAULT_TOAST_DURATION : this.options.duration;
294
409
  if (typeof duration === "number" && duration > 0 && duration < 5e3) {
295
410
  warnings.push(
296
411
  `Dur\xE9e d'affichage trop courte (duration: ${duration}ms) : pr\xE9voyez au moins 5000ms ou duration: false pour laisser le temps de lecture aux utilisateurs (WCAG 2.2.1).`
@@ -298,9 +413,9 @@ var Wulf = (() => {
298
413
  }
299
414
  const closable = this.options.closable ?? true;
300
415
  const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
301
- if (isPersistent && !closable && !this.options.closeOnClick) {
416
+ if (isPersistent && !closable) {
302
417
  warnings.push(
303
- "Notification persistante impossible \xE0 fermer : activez closable: true ou closeOnClick: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
418
+ "Notification persistante impossible \xE0 fermer au clavier : activez closable: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
304
419
  );
305
420
  }
306
421
  return warnings;
@@ -313,35 +428,36 @@ var Wulf = (() => {
313
428
  }
314
429
  /**
315
430
  * Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
431
+ * Les annonces sont gérées sur un canal unique dans `ToastManager` pour éviter tout doublon AT.
316
432
  */
317
433
  createDOM() {
318
434
  const el = document.createElement("div");
319
435
  el.id = this.id;
320
436
  el.className = "wulf-toast";
321
- const role = this.options.role === "alert" ? "alert" : "status";
322
- el.setAttribute("role", role);
323
- el.setAttribute("aria-live", role === "alert" ? "assertive" : "polite");
324
- el.setAttribute("aria-atomic", "true");
325
- if (this.options.backgroundColor) {
326
- el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor);
437
+ el.setAttribute("data-toast-role", this.options.role === "alert" ? "alert" : "status");
438
+ if (this.options.backgroundColor && isSafeCssValue(this.options.backgroundColor)) {
439
+ el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor.trim());
327
440
  }
328
- if (this.options.titleColor) {
329
- el.style.setProperty("--wulf-toast-title-color", this.options.titleColor);
441
+ if (this.options.titleColor && isSafeCssValue(this.options.titleColor)) {
442
+ el.style.setProperty("--wulf-toast-title-color", this.options.titleColor.trim());
330
443
  }
331
- if (this.options.textColor) {
332
- el.style.setProperty("--wulf-toast-text-color", this.options.textColor);
444
+ if (this.options.textColor && isSafeCssValue(this.options.textColor)) {
445
+ el.style.setProperty("--wulf-toast-text-color", this.options.textColor.trim());
333
446
  }
334
- if (this.options.iconColor) {
335
- el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor);
447
+ if (this.options.iconColor && isSafeCssValue(this.options.iconColor)) {
448
+ el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor.trim());
336
449
  }
337
- if (this.options.closeButtonColor) {
338
- el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor);
450
+ if (this.options.closeButtonColor && isSafeCssValue(this.options.closeButtonColor)) {
451
+ el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor.trim());
339
452
  }
340
- if (this.options.icon && this.options.icon.trim() !== "") {
341
- const iconContainer = document.createElement("span");
342
- iconContainer.className = `wulf-toast-icon ${this.options.icon.trim()}`;
343
- iconContainer.setAttribute("aria-hidden", "true");
344
- el.appendChild(iconContainer);
453
+ if (this.options.icon && typeof this.options.icon === "string" && this.options.icon.trim() !== "") {
454
+ const safeIcon = sanitizeIconClasses(this.options.icon);
455
+ if (safeIcon) {
456
+ const iconContainer = document.createElement("span");
457
+ iconContainer.className = `wulf-toast-icon ${safeIcon}`;
458
+ iconContainer.setAttribute("aria-hidden", "true");
459
+ el.appendChild(iconContainer);
460
+ }
345
461
  }
346
462
  const content = document.createElement("div");
347
463
  content.className = "wulf-toast-content";
@@ -364,7 +480,6 @@ var Wulf = (() => {
364
480
  closeBtn.type = "button";
365
481
  closeBtn.className = "wulf-toast-close";
366
482
  closeBtn.setAttribute("aria-label", toastI18n.t("closeButton", this.options.i18n));
367
- closeBtn.setAttribute("tabindex", "0");
368
483
  const closeIcon = document.createElement("span");
369
484
  closeIcon.className = "wulf-toast-close-icon";
370
485
  closeIcon.setAttribute("aria-hidden", "true");
@@ -373,17 +488,24 @@ var Wulf = (() => {
373
488
  closeBtn.addEventListener("click", (e) => {
374
489
  e.stopPropagation();
375
490
  this.close("close-button");
376
- });
491
+ }, { signal: this.eventsAbortController.signal });
377
492
  el.appendChild(closeBtn);
378
493
  }
494
+ if (this.options.progressBar && this.remainingTime > 0) {
495
+ el.style.setProperty("--wulf-toast-duration", `${this.remainingTime}ms`);
496
+ const progressBar = document.createElement("div");
497
+ progressBar.className = "wulf-toast-progress";
498
+ progressBar.setAttribute("aria-hidden", "true");
499
+ el.appendChild(progressBar);
500
+ }
379
501
  return el;
380
502
  }
381
503
  /**
382
504
  * Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
383
- * Utilise document.createTextNode et des éléments <br> créés proprement.
384
505
  */
385
506
  appendTextWithLineBreaks(container, text) {
386
- const lines = text.split(/\r\n|\r|\n/);
507
+ const safeText = String(text ?? "").slice(0, 4096);
508
+ const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
387
509
  lines.forEach((line, index) => {
388
510
  if (index > 0) {
389
511
  container.appendChild(document.createElement("br"));
@@ -392,9 +514,10 @@ var Wulf = (() => {
392
514
  });
393
515
  }
394
516
  /**
395
- * Liaison des événements clavier, souris, et pause au survol / focus (WCAG 2.2)
517
+ * Liaison des événements clavier, souris, visibilité d'onglet et pause au survol/focus (WCAG 2.2).
396
518
  */
397
519
  bindEvents() {
520
+ const { signal } = this.eventsAbortController;
398
521
  this.element.addEventListener("click", (e) => {
399
522
  if (this.options.onClick) {
400
523
  this.options.onClick(this, e);
@@ -402,123 +525,206 @@ var Wulf = (() => {
402
525
  if (this.options.closeOnClick) {
403
526
  this.close("toast-click");
404
527
  }
405
- });
406
- this.element.addEventListener("mouseenter", () => this.pauseTimer());
407
- this.element.addEventListener("mouseleave", () => this.resumeTimer());
408
- this.element.addEventListener("focusin", () => this.pauseTimer());
409
- this.element.addEventListener("focusout", () => this.resumeTimer());
528
+ }, { signal });
529
+ this.element.addEventListener("mouseenter", () => this.pauseTimer("hover"), { signal });
530
+ this.element.addEventListener("mouseleave", () => this.resumeTimer("hover"), { signal });
531
+ this.element.addEventListener("focusin", () => this.pauseTimer("focus"), { signal });
532
+ this.element.addEventListener("focusout", (e) => {
533
+ const nextFocused = e.relatedTarget;
534
+ if (nextFocused && this.element.contains(nextFocused)) {
535
+ return;
536
+ }
537
+ if (this.isPendingFocusDismiss && !this._isClosed) {
538
+ this.isPendingFocusDismiss = false;
539
+ this.close("timeout");
540
+ return;
541
+ }
542
+ this.resumeTimer("focus");
543
+ }, { signal });
544
+ this.element.addEventListener("keydown", (e) => {
545
+ if (e.key === "Escape" && (this.options.closable ?? true)) {
546
+ e.stopPropagation();
547
+ this.close("close-button");
548
+ }
549
+ }, { signal });
550
+ if (typeof document !== "undefined") {
551
+ document.addEventListener("visibilitychange", () => {
552
+ if (document.visibilityState === "hidden") {
553
+ this.pauseTimer("visibility");
554
+ } else {
555
+ this.resumeTimer("visibility");
556
+ }
557
+ }, { signal });
558
+ }
559
+ }
560
+ get isPaused() {
561
+ return this.isPausedByHover || this.isPausedByFocus || this.isPausedByVisibility;
410
562
  }
411
563
  /**
412
- * Démarrage du compte à rebours de disparition automatique
564
+ * Démarrage du compte à rebours de disparition automatique (horloge monotone).
413
565
  */
414
566
  startTimer() {
415
- if (this._isClosed || this.remainingTime <= 0) return;
416
- this.timerStartTime = Date.now();
567
+ if (this._isClosed || this.remainingTime <= 0 || this.isPaused) return;
568
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
569
+ this.isPausedByVisibility = true;
570
+ this.element.classList.add("is-paused");
571
+ return;
572
+ }
573
+ if (this.timerId !== null) {
574
+ window.clearTimeout(this.timerId);
575
+ this.timerId = null;
576
+ }
577
+ this.timerStartTime = performance.now();
417
578
  this.timerId = window.setTimeout(() => {
579
+ this.timerId = null;
580
+ if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
581
+ this.isPendingFocusDismiss = true;
582
+ return;
583
+ }
418
584
  this.close("timeout");
419
585
  }, this.remainingTime);
420
586
  }
421
587
  /**
422
- * Met en pause le compte à rebours (au survol ou prise de focus)
588
+ * Met en pause le compte à rebours (au survol, au focus ou à la perte de visibilité d'onglet).
423
589
  */
424
- pauseTimer() {
425
- if (this._isClosed || this.remainingTime <= 0 || this.isPaused) return;
590
+ pauseTimer(source = "interaction") {
591
+ if (this._isClosed || !this.hasDuration || this.remainingTime <= 0) return;
592
+ const wasPaused = this.isPaused;
593
+ if (source === "visibility") {
594
+ this.isPausedByVisibility = true;
595
+ } else if (source === "focus") {
596
+ this.isPausedByFocus = true;
597
+ } else {
598
+ this.isPausedByHover = true;
599
+ }
600
+ if (wasPaused) return;
426
601
  if (this.timerId !== null) {
427
602
  window.clearTimeout(this.timerId);
428
603
  this.timerId = null;
604
+ const elapsed = performance.now() - this.timerStartTime;
605
+ this.remainingTime = Math.max(0, this.remainingTime - elapsed);
429
606
  }
430
- const elapsed = Date.now() - this.timerStartTime;
431
- this.remainingTime = Math.max(0, this.remainingTime - elapsed);
432
- this.isPaused = true;
607
+ this.element.classList.add("is-paused");
433
608
  }
434
609
  /**
435
- * Reprend le compte à rebours
610
+ * Reprend le compte à rebours si aucune autre cause de pause n'est active.
436
611
  */
437
- resumeTimer() {
438
- if (this._isClosed || this.remainingTime <= 0 || !this.isPaused) return;
439
- this.isPaused = false;
612
+ resumeTimer(source = "interaction") {
613
+ if (this._isClosed || !this.hasDuration) return;
614
+ if (source === "visibility") {
615
+ this.isPausedByVisibility = false;
616
+ } else if (source === "focus") {
617
+ this.isPausedByFocus = false;
618
+ } else if (source === "hover") {
619
+ this.isPausedByHover = false;
620
+ } else {
621
+ this.isPausedByHover = false;
622
+ this.isPausedByFocus = false;
623
+ }
624
+ if (this.isPaused) return;
625
+ this.element.classList.remove("is-paused");
626
+ if (this.remainingTime <= 0) {
627
+ this.close("timeout");
628
+ return;
629
+ }
440
630
  this.startTimer();
441
631
  }
632
+ finalizeDismiss(reason) {
633
+ if (this._isFinalized) return;
634
+ this._isFinalized = true;
635
+ this.eventsAbortController.abort();
636
+ if (this.onDismissCallback) {
637
+ this.onDismissCallback(this, reason);
638
+ }
639
+ if (this.element.parentNode) {
640
+ this.element.parentNode.removeChild(this.element);
641
+ }
642
+ if (this.options.onClose) {
643
+ this.options.onClose(this, reason);
644
+ }
645
+ }
442
646
  /**
443
- * Déclenche la destruction immédiate sans animation (utile pour purger lors d'une rafale)
647
+ * Déclenche la destruction immédiate sans animation.
444
648
  */
445
649
  destroyImmediate(reason = "replace") {
446
- if (this._isClosed) return;
447
650
  this._isClosed = true;
448
651
  if (this.timerId !== null) {
449
652
  window.clearTimeout(this.timerId);
450
653
  this.timerId = null;
451
654
  }
452
- if (this.element.parentNode) {
453
- this.element.parentNode.removeChild(this.element);
454
- }
455
- if (this.onDismissCallback) {
456
- this.onDismissCallback(this, reason);
457
- }
458
- if (this.options.onClose) {
459
- this.options.onClose(this, reason);
460
- }
655
+ this.disposeAbortController.abort();
656
+ this.finalizeDismiss(reason);
461
657
  }
462
658
  /**
463
659
  * Déclenche la fermeture propre et l'animation de sortie du toast.
464
- * Si fast = true, utilise une disparition accélérée (90ms) pour le remplacement séquentiel.
660
+ * Si fast = true, utilise une disparition accélérée pour le remplacement séquentiel.
465
661
  */
466
662
  close(reason = "programmatic", fast = false) {
467
- if (this._isClosed) return Promise.resolve();
663
+ if (this._isClosed) {
664
+ return this.closePromise ?? Promise.resolve();
665
+ }
468
666
  this._isClosed = true;
469
667
  if (this.timerId !== null) {
470
668
  window.clearTimeout(this.timerId);
471
669
  this.timerId = null;
472
670
  }
473
- return new Promise((resolve) => {
474
- this.element.classList.add(fast ? "wulf-toast-hiding-fast" : "wulf-toast-hiding");
475
- const handleAnimationEnd = () => {
476
- if (this.element.parentNode) {
477
- this.element.parentNode.removeChild(this.element);
478
- }
479
- if (this.onDismissCallback) {
480
- this.onDismissCallback(this, reason);
481
- }
482
- if (this.options.onClose) {
483
- this.options.onClose(this, reason);
484
- }
485
- resolve();
486
- };
487
- const isReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
488
- if (isReducedMotion) {
489
- handleAnimationEnd();
490
- } else if (fast) {
491
- window.setTimeout(handleAnimationEnd, 90);
492
- } else {
493
- let transitioned = false;
494
- let fallbackTimerId = null;
495
- const onEnd = () => {
496
- if (!transitioned) {
497
- transitioned = true;
498
- if (fallbackTimerId !== null) {
499
- window.clearTimeout(fallbackTimerId);
500
- fallbackTimerId = null;
501
- }
502
- this.element.removeEventListener("animationend", onEnd);
503
- this.element.removeEventListener("transitionend", onEnd);
504
- handleAnimationEnd();
505
- }
506
- };
507
- this.element.addEventListener("animationend", onEnd, { once: true });
508
- this.element.addEventListener("transitionend", onEnd, { once: true });
509
- fallbackTimerId = window.setTimeout(onEnd, 300);
671
+ this.eventsAbortController.abort();
672
+ this.element.classList.add(fast ? "wulf-toast-hiding-fast" : "wulf-toast-hiding");
673
+ if (prefersReducedMotion()) {
674
+ this.finalizeDismiss(reason);
675
+ this.closePromise = Promise.resolve();
676
+ return this.closePromise;
677
+ }
678
+ this.closePromise = waitForAnimations(this.element, fast ? 90 : 300, this.disposeAbortController.signal).then(() => {
679
+ if (!this.disposeAbortController.signal.aborted) {
680
+ this.finalizeDismiss(reason);
510
681
  }
511
682
  });
683
+ return this.closePromise;
512
684
  }
513
685
  };
514
686
 
515
687
  // src/toast/ToastManager.ts
516
- var _ToastManager = class _ToastManager {
688
+ var VALID_POSITIONS = /* @__PURE__ */ new Set([
689
+ "top-left",
690
+ "top-center",
691
+ "top-right",
692
+ "bottom-left",
693
+ "bottom-center",
694
+ "bottom-right"
695
+ ]);
696
+ function normalizePosition(pos) {
697
+ return pos && VALID_POSITIONS.has(pos) ? pos : "top-right";
698
+ }
699
+ var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
700
+ var ToastManager = class _ToastManager {
701
+ static instance = null;
702
+ containers = /* @__PURE__ */ new Map();
703
+ activeToasts = /* @__PURE__ */ new Map();
704
+ announcerEl = null;
705
+ politeRegion = null;
706
+ assertiveRegion = null;
707
+ announceTimers = [];
708
+ politeAnnounceTimerId = null;
709
+ assertiveAnnounceTimerId = null;
710
+ politeClearTimerId = null;
711
+ assertiveClearTimerId = null;
712
+ lastPoliteText = "";
713
+ lastAssertiveText = "";
714
+ announcerToggle = false;
715
+ /**
716
+ * Vérifie si un conteneur Popover est ouvert (compatible natif et polyfill OddBird).
717
+ */
718
+ isPopoverOpen(container) {
719
+ try {
720
+ if (container.matches(":popover-open")) return true;
721
+ } catch {
722
+ }
723
+ return container.classList.contains(":popover-open");
724
+ }
725
+ replaceTokens = /* @__PURE__ */ new Map();
726
+ pendingReplacements = /* @__PURE__ */ new Set();
517
727
  constructor() {
518
- this.containers = /* @__PURE__ */ new Map();
519
- this.activeToasts = /* @__PURE__ */ new Map();
520
- this.replaceTokens = /* @__PURE__ */ new Map();
521
- this.pendingReplacements = /* @__PURE__ */ new Set();
522
728
  }
523
729
  static getInstance() {
524
730
  if (!_ToastManager.instance) {
@@ -530,12 +736,14 @@ var Wulf = (() => {
530
736
  * Ajoute et affiche une notification Toast.
531
737
  */
532
738
  add(toast) {
533
- const position = toast.options.position || "top-right";
739
+ const position = normalizePosition(toast.options.position);
534
740
  let list = this.activeToasts.get(position);
535
741
  if (!list) {
536
742
  list = [];
537
743
  this.activeToasts.set(position, list);
538
744
  }
745
+ const rawMax = toast.options.maxToasts;
746
+ const maxToasts = typeof rawMax === "number" && Number.isFinite(rawMax) && rawMax > 0 ? Math.min(50, Math.max(1, Math.floor(rawMax))) : 5;
539
747
  if (toast.options.replace && list.length > 0) {
540
748
  const existing = [...list];
541
749
  const token = (this.replaceTokens.get(position) || 0) + 1;
@@ -545,13 +753,17 @@ var Wulf = (() => {
545
753
  Promise.all(promises).then(() => {
546
754
  this.pendingReplacements.delete(position);
547
755
  if (this.replaceTokens.get(position) !== token) {
756
+ toast.destroyImmediate("replace");
548
757
  return;
549
758
  }
550
- this.mountToast(toast, position);
759
+ this.mountToast(toast, position, maxToasts);
551
760
  });
552
761
  return;
553
762
  }
554
- const maxToasts = typeof toast.options.maxToasts === "number" && toast.options.maxToasts > 0 ? toast.options.maxToasts : 5;
763
+ if (this.pendingReplacements.has(position)) {
764
+ this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
765
+ this.pendingReplacements.delete(position);
766
+ }
555
767
  if (list.length >= maxToasts) {
556
768
  const countToRemove = list.length - maxToasts + 1;
557
769
  const oldestItems = list.splice(0, countToRemove);
@@ -559,20 +771,43 @@ var Wulf = (() => {
559
771
  item.close("max-limit", true);
560
772
  }
561
773
  }
562
- this.mountToast(toast, position);
774
+ this.mountToast(toast, position, maxToasts);
563
775
  }
564
776
  /**
565
- * Insère l'élément toast dans le DOM et déclenche les callbacks et compteurs.
777
+ * Insère l'élément toast dans le conteneur Top Layer, annonce le message et démarre le minuteur.
566
778
  */
567
- mountToast(toast, position) {
568
- const container = this.getOrCreateContainer(position);
779
+ mountToast(toast, position, maxToasts = 5) {
780
+ if (toast.isClosed) return;
781
+ const useTopLayer = toast.options.useTopLayer ?? true;
782
+ const container = this.getOrCreateContainer(position, toast, useTopLayer);
569
783
  let list = this.activeToasts.get(position);
570
784
  if (!list) {
571
785
  list = [];
572
786
  this.activeToasts.set(position, list);
573
787
  }
788
+ const maxDomNodes = maxToasts + 10;
789
+ if (container.children.length >= maxDomNodes) {
790
+ const children = Array.from(container.children);
791
+ for (const child of children) {
792
+ if (container.children.length < maxDomNodes) break;
793
+ if (child.classList.contains("wulf-toast-hiding") || child.classList.contains("wulf-toast-hiding-fast")) {
794
+ child.remove();
795
+ }
796
+ }
797
+ }
798
+ if (useTopLayer && typeof container.showPopover === "function" && container.getAttribute("popover") === "manual") {
799
+ try {
800
+ const popoverEl = container;
801
+ if (!this.isPopoverOpen(container)) {
802
+ popoverEl.showPopover();
803
+ }
804
+ } catch {
805
+ container.removeAttribute("popover");
806
+ }
807
+ }
574
808
  container.appendChild(toast.element);
575
809
  list.push(toast);
810
+ this.announce(toast);
576
811
  if (toast.options.onOpen) {
577
812
  try {
578
813
  toast.options.onOpen(toast);
@@ -582,27 +817,179 @@ var Wulf = (() => {
582
817
  }
583
818
  toast.startTimer();
584
819
  }
820
+ /**
821
+ * Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
822
+ */
823
+ announce(toast) {
824
+ const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
825
+ if (parts.length === 0) return;
826
+ const rawText = parts.join(". ");
827
+ const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
828
+ const isAlert = toast.options.role === "alert";
829
+ const docWithAriaNotify = document;
830
+ if (typeof docWithAriaNotify.ariaNotify === "function") {
831
+ try {
832
+ docWithAriaNotify.ariaNotify(text, { priority: isAlert ? "high" : "normal" });
833
+ return;
834
+ } catch {
835
+ }
836
+ }
837
+ const wasCreated = !this.announcerEl || !this.announcerEl.isConnected;
838
+ this.ensureAnnouncer();
839
+ const region = isAlert ? this.assertiveRegion : this.politeRegion;
840
+ if (!region) return;
841
+ if (isAlert) {
842
+ if (this.assertiveAnnounceTimerId !== null) {
843
+ window.clearTimeout(this.assertiveAnnounceTimerId);
844
+ this.assertiveAnnounceTimerId = null;
845
+ }
846
+ if (this.assertiveClearTimerId !== null) {
847
+ window.clearTimeout(this.assertiveClearTimerId);
848
+ this.assertiveClearTimerId = null;
849
+ }
850
+ } else {
851
+ if (this.politeAnnounceTimerId !== null) {
852
+ window.clearTimeout(this.politeAnnounceTimerId);
853
+ this.politeAnnounceTimerId = null;
854
+ }
855
+ if (this.politeClearTimerId !== null) {
856
+ window.clearTimeout(this.politeClearTimerId);
857
+ this.politeClearTimerId = null;
858
+ }
859
+ }
860
+ region.textContent = "";
861
+ const lastText = isAlert ? this.lastAssertiveText : this.lastPoliteText;
862
+ let finalMessage = text;
863
+ if (text === lastText) {
864
+ this.announcerToggle = !this.announcerToggle;
865
+ finalMessage = this.announcerToggle ? `${text}\xA0` : text;
866
+ } else {
867
+ this.announcerToggle = false;
868
+ }
869
+ if (isAlert) {
870
+ this.lastAssertiveText = text;
871
+ } else {
872
+ this.lastPoliteText = text;
873
+ }
874
+ const delay = wasCreated ? 120 : 50;
875
+ const timerId = window.setTimeout(() => {
876
+ const idx = this.announceTimers.indexOf(timerId);
877
+ if (idx !== -1) this.announceTimers.splice(idx, 1);
878
+ if (isAlert) {
879
+ this.assertiveAnnounceTimerId = null;
880
+ } else {
881
+ this.politeAnnounceTimerId = null;
882
+ }
883
+ if (region.isConnected) {
884
+ region.textContent = finalMessage;
885
+ const clearId = window.setTimeout(() => {
886
+ const cIdx = this.announceTimers.indexOf(clearId);
887
+ if (cIdx !== -1) this.announceTimers.splice(cIdx, 1);
888
+ if (region.isConnected && region.textContent === finalMessage) {
889
+ region.textContent = "";
890
+ }
891
+ }, 4e3);
892
+ this.announceTimers.push(clearId);
893
+ if (isAlert) {
894
+ this.assertiveClearTimerId = clearId;
895
+ } else {
896
+ this.politeClearTimerId = clearId;
897
+ }
898
+ }
899
+ }, delay);
900
+ this.announceTimers.push(timerId);
901
+ if (isAlert) {
902
+ this.assertiveAnnounceTimerId = timerId;
903
+ } else {
904
+ this.politeAnnounceTimerId = timerId;
905
+ }
906
+ }
907
+ /**
908
+ * Crée ou reconnecte le conteneur persistant des annonces ARIA hors du popover.
909
+ */
910
+ ensureAnnouncer() {
911
+ if (this.announcerEl && document.body.contains(this.announcerEl)) {
912
+ return;
913
+ }
914
+ const wrapper = document.createElement("div");
915
+ wrapper.className = "wulf-toast-announcer";
916
+ wrapper.setAttribute("data-wulf-toast-announcer", "true");
917
+ const polite = document.createElement("div");
918
+ polite.setAttribute("role", "status");
919
+ polite.setAttribute("aria-live", "polite");
920
+ polite.setAttribute("aria-atomic", "true");
921
+ const assertive = document.createElement("div");
922
+ assertive.setAttribute("role", "alert");
923
+ assertive.setAttribute("aria-live", "assertive");
924
+ assertive.setAttribute("aria-atomic", "true");
925
+ wrapper.appendChild(polite);
926
+ wrapper.appendChild(assertive);
927
+ document.body.appendChild(wrapper);
928
+ this.announcerEl = wrapper;
929
+ this.politeRegion = polite;
930
+ this.assertiveRegion = assertive;
931
+ }
932
+ /**
933
+ * Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
934
+ */
935
+ handleFocusHandoff(toast, list) {
936
+ if (!toast.element.contains(document.activeElement)) {
937
+ return;
938
+ }
939
+ for (let i = list.length - 1; i >= 0; i--) {
940
+ const sibling = list[i];
941
+ if (sibling === toast || sibling.isClosed || !sibling.element.isConnected) continue;
942
+ const target = sibling.element.querySelector(FOCUSABLE_IN_TOAST);
943
+ if (target) {
944
+ target.focus({ preventScroll: true });
945
+ return;
946
+ }
947
+ }
948
+ const prev = toast.getPreviousActiveElement();
949
+ if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
950
+ try {
951
+ prev.focus();
952
+ } catch {
953
+ }
954
+ }
955
+ }
585
956
  /**
586
957
  * Retire une notification de la pile et nettoie le conteneur s'il est vide.
587
958
  */
588
959
  remove(toast, _reason) {
589
- const position = toast.options.position || "top-right";
960
+ const position = normalizePosition(toast.options.position);
590
961
  const list = this.activeToasts.get(position);
591
962
  if (list) {
592
963
  const index = list.indexOf(toast);
593
964
  if (index !== -1) {
594
965
  list.splice(index, 1);
595
966
  }
967
+ this.handleFocusHandoff(toast, list);
968
+ if (toast.element.parentNode) {
969
+ toast.element.parentNode.removeChild(toast.element);
970
+ }
596
971
  if (list.length === 0 && !this.pendingReplacements.has(position)) {
597
972
  const container = this.containers.get(position);
598
973
  if (container && (!container.firstChild || container.children.length === 0)) {
599
- if (container.parentNode) {
600
- container.parentNode.removeChild(container);
601
- }
974
+ this.disposeContainer(container);
602
975
  this.containers.delete(position);
603
976
  this.activeToasts.delete(position);
604
977
  }
605
978
  }
979
+ } else if (toast.element.parentNode) {
980
+ toast.element.parentNode.removeChild(toast.element);
981
+ }
982
+ }
983
+ disposeContainer(container) {
984
+ try {
985
+ const popoverEl = container;
986
+ if (typeof popoverEl.hidePopover === "function" && this.isPopoverOpen(container)) {
987
+ popoverEl.hidePopover();
988
+ }
989
+ } catch {
990
+ }
991
+ if (container.parentNode) {
992
+ container.parentNode.removeChild(container);
606
993
  }
607
994
  }
608
995
  /**
@@ -611,6 +998,8 @@ var Wulf = (() => {
611
998
  clearAll(position) {
612
999
  const promises = [];
613
1000
  if (position) {
1001
+ this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
1002
+ this.pendingReplacements.delete(position);
614
1003
  const list = this.activeToasts.get(position);
615
1004
  if (list && list.length > 0) {
616
1005
  const copy = [...list];
@@ -620,14 +1009,24 @@ var Wulf = (() => {
620
1009
  } else {
621
1010
  const container = this.containers.get(position);
622
1011
  if (container && (!container.firstChild || container.children.length === 0)) {
623
- if (container.parentNode) {
624
- container.parentNode.removeChild(container);
625
- }
1012
+ this.disposeContainer(container);
626
1013
  this.containers.delete(position);
627
1014
  this.activeToasts.delete(position);
628
1015
  }
629
1016
  }
630
1017
  } else {
1018
+ for (const pos of this.replaceTokens.keys()) {
1019
+ this.replaceTokens.set(pos, (this.replaceTokens.get(pos) || 0) + 1);
1020
+ }
1021
+ this.pendingReplacements.clear();
1022
+ for (const timerId of this.announceTimers) {
1023
+ window.clearTimeout(timerId);
1024
+ }
1025
+ this.announceTimers = [];
1026
+ this.politeAnnounceTimerId = null;
1027
+ this.assertiveAnnounceTimerId = null;
1028
+ this.politeClearTimerId = null;
1029
+ this.assertiveClearTimerId = null;
631
1030
  const allPositions = /* @__PURE__ */ new Set([
632
1031
  ...Array.from(this.containers.keys()),
633
1032
  ...Array.from(this.activeToasts.keys())
@@ -640,9 +1039,7 @@ var Wulf = (() => {
640
1039
  if (!position) {
641
1040
  for (const [pos, container] of Array.from(this.containers.entries())) {
642
1041
  if (!container.firstChild || container.children.length === 0) {
643
- if (container.parentNode) {
644
- container.parentNode.removeChild(container);
645
- }
1042
+ this.disposeContainer(container);
646
1043
  this.containers.delete(pos);
647
1044
  this.activeToasts.delete(pos);
648
1045
  }
@@ -650,27 +1047,58 @@ var Wulf = (() => {
650
1047
  }
651
1048
  });
652
1049
  }
1050
+ /**
1051
+ * Détruit immédiatement tous les toasts, conteneurs, annonceurs ARIA et temporisations en cours.
1052
+ */
1053
+ destroy() {
1054
+ for (const timerId of this.announceTimers) {
1055
+ window.clearTimeout(timerId);
1056
+ }
1057
+ this.announceTimers = [];
1058
+ for (const list of Array.from(this.activeToasts.values())) {
1059
+ for (const toast of [...list]) {
1060
+ toast.destroyImmediate("programmatic");
1061
+ }
1062
+ }
1063
+ for (const container of Array.from(this.containers.values())) {
1064
+ this.disposeContainer(container);
1065
+ }
1066
+ this.containers.clear();
1067
+ this.activeToasts.clear();
1068
+ this.replaceTokens.clear();
1069
+ this.pendingReplacements.clear();
1070
+ if (this.announcerEl) {
1071
+ this.announcerEl.remove();
1072
+ this.announcerEl = null;
1073
+ this.politeRegion = null;
1074
+ this.assertiveRegion = null;
1075
+ }
1076
+ _ToastManager.instance = null;
1077
+ }
653
1078
  /**
654
1079
  * Récupère ou crée le conteneur DOM pour une position d'affichage.
655
1080
  */
656
- getOrCreateContainer(position) {
1081
+ getOrCreateContainer(position, toast, useTopLayer) {
657
1082
  let container = this.containers.get(position);
658
1083
  if (!container || !document.body.contains(container)) {
659
1084
  container = document.createElement("div");
660
1085
  container.className = `wulf-toast-container wulf-toast-${position}`;
661
- container.setAttribute("aria-live", "polite");
662
- container.setAttribute("aria-relevant", "additions removals");
1086
+ container.setAttribute("role", "region");
1087
+ container.setAttribute("aria-label", toastI18n.t("notificationsRegion", toast.options.i18n));
1088
+ if (useTopLayer && typeof container.showPopover === "function") {
1089
+ container.setAttribute("popover", "manual");
1090
+ }
663
1091
  document.body.appendChild(container);
664
1092
  this.containers.set(position, container);
665
1093
  }
666
1094
  return container;
667
1095
  }
668
1096
  };
669
- _ToastManager.instance = null;
670
- var ToastManager = _ToastManager;
671
1097
 
672
1098
  // src/toast/Toast.ts
673
1099
  var Toast = class extends LocalizedComponent {
1100
+ static _i18n = toastI18n;
1101
+ static i18n = toastI18n;
674
1102
  audit() {
675
1103
  return [];
676
1104
  }
@@ -697,16 +1125,18 @@ var Wulf = (() => {
697
1125
  static clearAll(position) {
698
1126
  return ToastManager.getInstance().clearAll(position);
699
1127
  }
1128
+ /**
1129
+ * Détruit le gestionnaire de notifications (conteneurs, annonceurs ARIA et timers).
1130
+ */
1131
+ static destroy() {
1132
+ ToastManager.getInstance().destroy();
1133
+ }
700
1134
  };
701
- Toast._i18n = toastI18n;
702
- Toast.i18n = toastI18n;
703
1135
 
704
1136
  // src/toast/index.ts
705
1137
  var index_default = Toast;
706
- if (typeof window !== "undefined") {
707
- const win = window;
708
- const wulfNamespace = win.Wulf || {};
709
- win.Wulf = wulfNamespace;
1138
+ var wulfNamespace = getSafeWulfNamespace();
1139
+ if (wulfNamespace) {
710
1140
  wulfNamespace.Toast = Object.assign(Toast, {
711
1141
  Toast,
712
1142
  i18n: toastI18n
@@ -714,5 +1144,5 @@ var Wulf = (() => {
714
1144
  }
715
1145
  return __toCommonJS(index_exports);
716
1146
  })();
717
- if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast", "FocusTrap", "Shortcut"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
1147
+ if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.hasOwn(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && __w[k] === undefined) { try { Object.defineProperty(__w, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { __w[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
718
1148
  //# sourceMappingURL=toast.global.js.map