wulf.js 1.9.3 → 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.
- package/README.md +118 -78
- package/changelog.md +60 -0
- package/dist/focus-trap.esm.js +202 -136
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +203 -137
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +2130 -858
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2124 -852
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +4 -4
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.css +1 -1
- package/dist/mask.css.map +2 -2
- package/dist/mask.esm.js +686 -330
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +687 -331
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +4 -4
- package/dist/mask.global.min.js.map +4 -4
- package/dist/mask.layered.css +1 -0
- package/dist/mask.layered.css.map +7 -0
- package/dist/masonry.css +1 -1
- package/dist/masonry.css.map +2 -2
- package/dist/masonry.esm.js +248 -77
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +249 -78
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/masonry.layered.css +1 -0
- package/dist/masonry.layered.css.map +7 -0
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +462 -129
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +463 -130
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +4 -4
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -0
- package/dist/scroll.layered.css.map +7 -0
- package/dist/shortcut.esm.js +164 -48
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +165 -49
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +2 -2
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +489 -124
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +490 -125
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +3 -3
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -0
- package/dist/toast.layered.css.map +7 -0
- package/dist/types/common/dom.d.ts +38 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +14 -6
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/BaseInputMask.d.ts +20 -0
- package/dist/types/mask/InputAmountMask.d.ts +2 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- package/dist/types/mask/MaskEngine.d.ts +4 -0
- package/dist/types/masonry/Masonry.d.ts +10 -3
- package/dist/types/scroll/ScrollBlock.d.ts +31 -3
- package/dist/types/scroll/types.d.ts +13 -1
- package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +1 -0
- package/dist/types/toast/Toast.d.ts +4 -0
- package/dist/types/toast/ToastInstance.d.ts +22 -10
- package/dist/types/toast/ToastManager.d.ts +37 -4
- package/dist/types/toast/i18n/types.d.ts +2 -0
- package/dist/types/toast/types.d.ts +9 -2
- package/package.json +16 -3
package/dist/toast.esm.js
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
// src/common/dom.ts
|
|
2
|
+
function getSafeWulfNamespace() {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const win = window;
|
|
5
|
+
const existing = win.Wulf;
|
|
6
|
+
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
7
|
+
const fresh = {};
|
|
8
|
+
win.Wulf = fresh;
|
|
9
|
+
return fresh;
|
|
10
|
+
}
|
|
11
|
+
return existing;
|
|
12
|
+
}
|
|
13
|
+
function prefersReducedMotion() {
|
|
14
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
15
|
+
}
|
|
16
|
+
function waitForAnimations(element, fallbackMs, signal) {
|
|
17
|
+
const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
|
|
18
|
+
if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
|
|
22
|
+
if (a.playState !== "running") return false;
|
|
23
|
+
const timing = a.effect?.getComputedTiming?.();
|
|
24
|
+
return timing ? Number.isFinite(timing.endTime) : true;
|
|
25
|
+
}) : [];
|
|
26
|
+
if (animations.length === 0) {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
let settled = false;
|
|
31
|
+
let timerId = null;
|
|
32
|
+
const finish = () => {
|
|
33
|
+
if (settled) return;
|
|
34
|
+
settled = true;
|
|
35
|
+
if (timerId !== null) {
|
|
36
|
+
clearTimeout(timerId);
|
|
37
|
+
timerId = null;
|
|
38
|
+
}
|
|
39
|
+
signal?.removeEventListener("abort", finish);
|
|
40
|
+
resolve();
|
|
41
|
+
};
|
|
42
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
43
|
+
timerId = setTimeout(finish, safeFallback);
|
|
44
|
+
Promise.allSettled(animations.map((a) => a.finished)).then(finish);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
1
48
|
// src/common/i18n.ts
|
|
2
49
|
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
3
50
|
function isSafeKey(key) {
|
|
@@ -15,7 +62,7 @@ function getPrimaryLanguage(normalizedLocale) {
|
|
|
15
62
|
function assignDefined(target, source) {
|
|
16
63
|
if (!source || typeof source !== "object") return target;
|
|
17
64
|
for (const key of Object.keys(source)) {
|
|
18
|
-
if (isSafeKey(String(key)) && Object.
|
|
65
|
+
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
19
66
|
target[key] = source[key];
|
|
20
67
|
}
|
|
21
68
|
}
|
|
@@ -76,7 +123,7 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
76
123
|
if (!isSafeKey(String(key))) {
|
|
77
124
|
return "";
|
|
78
125
|
}
|
|
79
|
-
if (instanceOverride && typeof instanceOverride === "object" && Object.
|
|
126
|
+
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
80
127
|
return String(instanceOverride[key]);
|
|
81
128
|
}
|
|
82
129
|
if (globalOverrides[key] !== void 0) {
|
|
@@ -148,8 +195,11 @@ var AuditableComponent = class {
|
|
|
148
195
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
149
196
|
if (!rawValue) return false;
|
|
150
197
|
const doc = element.ownerDocument || document;
|
|
198
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
151
199
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
152
|
-
const isValid = ids.length > 0 && ids.every(
|
|
200
|
+
const isValid = ids.length > 0 && ids.every(
|
|
201
|
+
(id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
|
|
202
|
+
);
|
|
153
203
|
if (!isValid) {
|
|
154
204
|
warnings.push(
|
|
155
205
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -161,6 +211,7 @@ var AuditableComponent = class {
|
|
|
161
211
|
|
|
162
212
|
// src/common/LocalizedComponent.ts
|
|
163
213
|
var LocalizedComponent = class extends AuditableComponent {
|
|
214
|
+
static _i18n;
|
|
164
215
|
/**
|
|
165
216
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
166
217
|
*/
|
|
@@ -211,6 +262,10 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
211
262
|
static t(key, instanceOverride) {
|
|
212
263
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
213
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Surcharges de localisation spécifiques à cette instance.
|
|
267
|
+
*/
|
|
268
|
+
i18nOverrides;
|
|
214
269
|
constructor(i18nOverrides) {
|
|
215
270
|
super();
|
|
216
271
|
this.i18nOverrides = i18nOverrides;
|
|
@@ -226,12 +281,14 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
226
281
|
|
|
227
282
|
// src/toast/i18n/fr.ts
|
|
228
283
|
var toastFr = {
|
|
229
|
-
closeButton: "Fermer la notification"
|
|
284
|
+
closeButton: "Fermer la notification",
|
|
285
|
+
notificationsRegion: "Notifications"
|
|
230
286
|
};
|
|
231
287
|
|
|
232
288
|
// src/toast/i18n/en.ts
|
|
233
289
|
var toastEn = {
|
|
234
|
-
closeButton: "Close notification"
|
|
290
|
+
closeButton: "Close notification",
|
|
291
|
+
notificationsRegion: "Notifications"
|
|
235
292
|
};
|
|
236
293
|
|
|
237
294
|
// src/toast/i18n/index.ts
|
|
@@ -242,29 +299,54 @@ var toastI18n = createI18nManager("fr", {
|
|
|
242
299
|
|
|
243
300
|
// src/toast/ToastInstance.ts
|
|
244
301
|
var nextToastId = 1;
|
|
302
|
+
var DEFAULT_TOAST_DURATION = 5e3;
|
|
245
303
|
function isSafeCssValue(val) {
|
|
246
304
|
if (!val || typeof val !== "string" || val.length > 128) return false;
|
|
247
|
-
|
|
305
|
+
const trimmed = val.trim();
|
|
306
|
+
if (!trimmed) return false;
|
|
307
|
+
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
|
|
311
|
+
return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
248
314
|
}
|
|
249
315
|
function sanitizeIconClasses(icon) {
|
|
250
|
-
return icon.trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
|
|
316
|
+
return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
|
|
251
317
|
}
|
|
252
318
|
var ToastInstance = class extends AuditableComponent {
|
|
319
|
+
id;
|
|
320
|
+
options;
|
|
321
|
+
element;
|
|
322
|
+
_isClosed = false;
|
|
323
|
+
_isFinalized = false;
|
|
324
|
+
closePromise = null;
|
|
325
|
+
timerId = null;
|
|
326
|
+
remainingTime = 0;
|
|
327
|
+
hasDuration = false;
|
|
328
|
+
timerStartTime = 0;
|
|
329
|
+
isPausedByHover = false;
|
|
330
|
+
isPausedByFocus = false;
|
|
331
|
+
isPausedByVisibility = false;
|
|
332
|
+
isPendingFocusDismiss = false;
|
|
333
|
+
previousActiveElement = null;
|
|
334
|
+
eventsAbortController = new AbortController();
|
|
335
|
+
disposeAbortController = new AbortController();
|
|
336
|
+
onDismissCallback;
|
|
253
337
|
constructor(options, onDismiss) {
|
|
254
338
|
super();
|
|
255
|
-
this._isClosed = false;
|
|
256
|
-
this.timerId = null;
|
|
257
|
-
this.remainingTime = 0;
|
|
258
|
-
this.timerStartTime = 0;
|
|
259
|
-
this.isPaused = false;
|
|
260
339
|
this.id = `wulf-toast-${nextToastId++}`;
|
|
261
340
|
this.options = Object.freeze({ ...options });
|
|
262
341
|
this.onDismissCallback = onDismiss;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
342
|
+
this.previousActiveElement = typeof document !== "undefined" && document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
343
|
+
const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
|
|
344
|
+
if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
|
|
345
|
+
this.remainingTime = Math.min(duration, 2147483647);
|
|
346
|
+
this.hasDuration = true;
|
|
266
347
|
} else {
|
|
267
348
|
this.remainingTime = 0;
|
|
349
|
+
this.hasDuration = false;
|
|
268
350
|
}
|
|
269
351
|
this.element = this.createDOM();
|
|
270
352
|
this.bindEvents();
|
|
@@ -273,6 +355,9 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
273
355
|
get isClosed() {
|
|
274
356
|
return this._isClosed;
|
|
275
357
|
}
|
|
358
|
+
getPreviousActiveElement() {
|
|
359
|
+
return this.previousActiveElement;
|
|
360
|
+
}
|
|
276
361
|
/**
|
|
277
362
|
* Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
|
|
278
363
|
* et retourne la liste des contraintes manquantes.
|
|
@@ -286,7 +371,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
286
371
|
"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)."
|
|
287
372
|
);
|
|
288
373
|
}
|
|
289
|
-
const duration = this.options.duration === void 0 ?
|
|
374
|
+
const duration = this.options.duration === void 0 ? DEFAULT_TOAST_DURATION : this.options.duration;
|
|
290
375
|
if (typeof duration === "number" && duration > 0 && duration < 5e3) {
|
|
291
376
|
warnings.push(
|
|
292
377
|
`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).`
|
|
@@ -294,9 +379,9 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
294
379
|
}
|
|
295
380
|
const closable = this.options.closable ?? true;
|
|
296
381
|
const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
|
|
297
|
-
if (isPersistent && !closable
|
|
382
|
+
if (isPersistent && !closable) {
|
|
298
383
|
warnings.push(
|
|
299
|
-
"Notification persistante impossible \xE0 fermer : activez closable: true
|
|
384
|
+
"Notification persistante impossible \xE0 fermer au clavier : activez closable: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
|
|
300
385
|
);
|
|
301
386
|
}
|
|
302
387
|
return warnings;
|
|
@@ -309,15 +394,13 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
309
394
|
}
|
|
310
395
|
/**
|
|
311
396
|
* Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
|
|
397
|
+
* Les annonces sont gérées sur un canal unique dans `ToastManager` pour éviter tout doublon AT.
|
|
312
398
|
*/
|
|
313
399
|
createDOM() {
|
|
314
400
|
const el = document.createElement("div");
|
|
315
401
|
el.id = this.id;
|
|
316
402
|
el.className = "wulf-toast";
|
|
317
|
-
|
|
318
|
-
el.setAttribute("role", role);
|
|
319
|
-
el.setAttribute("aria-live", role === "alert" ? "assertive" : "polite");
|
|
320
|
-
el.setAttribute("aria-atomic", "true");
|
|
403
|
+
el.setAttribute("data-toast-role", this.options.role === "alert" ? "alert" : "status");
|
|
321
404
|
if (this.options.backgroundColor && isSafeCssValue(this.options.backgroundColor)) {
|
|
322
405
|
el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor.trim());
|
|
323
406
|
}
|
|
@@ -363,7 +446,6 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
363
446
|
closeBtn.type = "button";
|
|
364
447
|
closeBtn.className = "wulf-toast-close";
|
|
365
448
|
closeBtn.setAttribute("aria-label", toastI18n.t("closeButton", this.options.i18n));
|
|
366
|
-
closeBtn.setAttribute("tabindex", "0");
|
|
367
449
|
const closeIcon = document.createElement("span");
|
|
368
450
|
closeIcon.className = "wulf-toast-close-icon";
|
|
369
451
|
closeIcon.setAttribute("aria-hidden", "true");
|
|
@@ -372,7 +454,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
372
454
|
closeBtn.addEventListener("click", (e) => {
|
|
373
455
|
e.stopPropagation();
|
|
374
456
|
this.close("close-button");
|
|
375
|
-
});
|
|
457
|
+
}, { signal: this.eventsAbortController.signal });
|
|
376
458
|
el.appendChild(closeBtn);
|
|
377
459
|
}
|
|
378
460
|
if (this.options.progressBar && this.remainingTime > 0) {
|
|
@@ -386,7 +468,6 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
386
468
|
}
|
|
387
469
|
/**
|
|
388
470
|
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
389
|
-
* Utilise document.createTextNode et des éléments <br> créés proprement (plafonné contre le DoS DOM).
|
|
390
471
|
*/
|
|
391
472
|
appendTextWithLineBreaks(container, text) {
|
|
392
473
|
const safeText = String(text ?? "").slice(0, 4096);
|
|
@@ -399,9 +480,10 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
399
480
|
});
|
|
400
481
|
}
|
|
401
482
|
/**
|
|
402
|
-
* Liaison des événements clavier, souris, et pause au survol
|
|
483
|
+
* Liaison des événements clavier, souris, visibilité d'onglet et pause au survol/focus (WCAG 2.2).
|
|
403
484
|
*/
|
|
404
485
|
bindEvents() {
|
|
486
|
+
const { signal } = this.eventsAbortController;
|
|
405
487
|
this.element.addEventListener("click", (e) => {
|
|
406
488
|
if (this.options.onClick) {
|
|
407
489
|
this.options.onClick(this, e);
|
|
@@ -409,115 +491,162 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
409
491
|
if (this.options.closeOnClick) {
|
|
410
492
|
this.close("toast-click");
|
|
411
493
|
}
|
|
412
|
-
});
|
|
413
|
-
this.element.addEventListener("mouseenter", () => this.pauseTimer());
|
|
414
|
-
this.element.addEventListener("mouseleave", () => this.resumeTimer());
|
|
415
|
-
this.element.addEventListener("focusin", () => this.pauseTimer());
|
|
416
|
-
this.element.addEventListener("focusout", () =>
|
|
494
|
+
}, { signal });
|
|
495
|
+
this.element.addEventListener("mouseenter", () => this.pauseTimer("hover"), { signal });
|
|
496
|
+
this.element.addEventListener("mouseleave", () => this.resumeTimer("hover"), { signal });
|
|
497
|
+
this.element.addEventListener("focusin", () => this.pauseTimer("focus"), { signal });
|
|
498
|
+
this.element.addEventListener("focusout", (e) => {
|
|
499
|
+
const nextFocused = e.relatedTarget;
|
|
500
|
+
if (nextFocused && this.element.contains(nextFocused)) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (this.isPendingFocusDismiss && !this._isClosed) {
|
|
504
|
+
this.isPendingFocusDismiss = false;
|
|
505
|
+
this.close("timeout");
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
this.resumeTimer("focus");
|
|
509
|
+
}, { signal });
|
|
510
|
+
this.element.addEventListener("keydown", (e) => {
|
|
511
|
+
if (e.key === "Escape" && (this.options.closable ?? true)) {
|
|
512
|
+
e.stopPropagation();
|
|
513
|
+
this.close("close-button");
|
|
514
|
+
}
|
|
515
|
+
}, { signal });
|
|
516
|
+
if (typeof document !== "undefined") {
|
|
517
|
+
document.addEventListener("visibilitychange", () => {
|
|
518
|
+
if (document.visibilityState === "hidden") {
|
|
519
|
+
this.pauseTimer("visibility");
|
|
520
|
+
} else {
|
|
521
|
+
this.resumeTimer("visibility");
|
|
522
|
+
}
|
|
523
|
+
}, { signal });
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
get isPaused() {
|
|
527
|
+
return this.isPausedByHover || this.isPausedByFocus || this.isPausedByVisibility;
|
|
417
528
|
}
|
|
418
529
|
/**
|
|
419
|
-
* Démarrage du compte à rebours de disparition automatique
|
|
530
|
+
* Démarrage du compte à rebours de disparition automatique (horloge monotone).
|
|
420
531
|
*/
|
|
421
532
|
startTimer() {
|
|
422
|
-
if (this._isClosed || this.remainingTime <= 0) return;
|
|
423
|
-
|
|
533
|
+
if (this._isClosed || this.remainingTime <= 0 || this.isPaused) return;
|
|
534
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") {
|
|
535
|
+
this.isPausedByVisibility = true;
|
|
536
|
+
this.element.classList.add("is-paused");
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (this.timerId !== null) {
|
|
540
|
+
window.clearTimeout(this.timerId);
|
|
541
|
+
this.timerId = null;
|
|
542
|
+
}
|
|
543
|
+
this.timerStartTime = performance.now();
|
|
424
544
|
this.timerId = window.setTimeout(() => {
|
|
545
|
+
this.timerId = null;
|
|
546
|
+
if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
|
|
547
|
+
this.isPendingFocusDismiss = true;
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
425
550
|
this.close("timeout");
|
|
426
551
|
}, this.remainingTime);
|
|
427
552
|
}
|
|
428
553
|
/**
|
|
429
|
-
* Met en pause le compte à rebours (au survol ou
|
|
554
|
+
* Met en pause le compte à rebours (au survol, au focus ou à la perte de visibilité d'onglet).
|
|
430
555
|
*/
|
|
431
|
-
pauseTimer() {
|
|
432
|
-
if (this._isClosed || this.remainingTime <= 0
|
|
556
|
+
pauseTimer(source = "interaction") {
|
|
557
|
+
if (this._isClosed || !this.hasDuration || this.remainingTime <= 0) return;
|
|
558
|
+
const wasPaused = this.isPaused;
|
|
559
|
+
if (source === "visibility") {
|
|
560
|
+
this.isPausedByVisibility = true;
|
|
561
|
+
} else if (source === "focus") {
|
|
562
|
+
this.isPausedByFocus = true;
|
|
563
|
+
} else {
|
|
564
|
+
this.isPausedByHover = true;
|
|
565
|
+
}
|
|
566
|
+
if (wasPaused) return;
|
|
433
567
|
if (this.timerId !== null) {
|
|
434
568
|
window.clearTimeout(this.timerId);
|
|
435
569
|
this.timerId = null;
|
|
570
|
+
const elapsed = performance.now() - this.timerStartTime;
|
|
571
|
+
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
436
572
|
}
|
|
437
|
-
const elapsed = Date.now() - this.timerStartTime;
|
|
438
|
-
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
439
|
-
this.isPaused = true;
|
|
440
573
|
this.element.classList.add("is-paused");
|
|
441
574
|
}
|
|
442
575
|
/**
|
|
443
|
-
* Reprend le compte à rebours
|
|
576
|
+
* Reprend le compte à rebours si aucune autre cause de pause n'est active.
|
|
444
577
|
*/
|
|
445
|
-
resumeTimer() {
|
|
446
|
-
if (this._isClosed ||
|
|
447
|
-
|
|
578
|
+
resumeTimer(source = "interaction") {
|
|
579
|
+
if (this._isClosed || !this.hasDuration) return;
|
|
580
|
+
if (source === "visibility") {
|
|
581
|
+
this.isPausedByVisibility = false;
|
|
582
|
+
} else if (source === "focus") {
|
|
583
|
+
this.isPausedByFocus = false;
|
|
584
|
+
} else if (source === "hover") {
|
|
585
|
+
this.isPausedByHover = false;
|
|
586
|
+
} else {
|
|
587
|
+
this.isPausedByHover = false;
|
|
588
|
+
this.isPausedByFocus = false;
|
|
589
|
+
}
|
|
590
|
+
if (this.isPaused) return;
|
|
448
591
|
this.element.classList.remove("is-paused");
|
|
592
|
+
if (this.remainingTime <= 0) {
|
|
593
|
+
this.close("timeout");
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
449
596
|
this.startTimer();
|
|
450
597
|
}
|
|
598
|
+
finalizeDismiss(reason) {
|
|
599
|
+
if (this._isFinalized) return;
|
|
600
|
+
this._isFinalized = true;
|
|
601
|
+
this.eventsAbortController.abort();
|
|
602
|
+
if (this.onDismissCallback) {
|
|
603
|
+
this.onDismissCallback(this, reason);
|
|
604
|
+
}
|
|
605
|
+
if (this.element.parentNode) {
|
|
606
|
+
this.element.parentNode.removeChild(this.element);
|
|
607
|
+
}
|
|
608
|
+
if (this.options.onClose) {
|
|
609
|
+
this.options.onClose(this, reason);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
451
612
|
/**
|
|
452
|
-
* Déclenche la destruction immédiate sans animation
|
|
613
|
+
* Déclenche la destruction immédiate sans animation.
|
|
453
614
|
*/
|
|
454
615
|
destroyImmediate(reason = "replace") {
|
|
455
|
-
if (this._isClosed) return;
|
|
456
616
|
this._isClosed = true;
|
|
457
617
|
if (this.timerId !== null) {
|
|
458
618
|
window.clearTimeout(this.timerId);
|
|
459
619
|
this.timerId = null;
|
|
460
620
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
if (this.onDismissCallback) {
|
|
465
|
-
this.onDismissCallback(this, reason);
|
|
466
|
-
}
|
|
467
|
-
if (this.options.onClose) {
|
|
468
|
-
this.options.onClose(this, reason);
|
|
469
|
-
}
|
|
621
|
+
this.disposeAbortController.abort();
|
|
622
|
+
this.finalizeDismiss(reason);
|
|
470
623
|
}
|
|
471
624
|
/**
|
|
472
625
|
* Déclenche la fermeture propre et l'animation de sortie du toast.
|
|
473
|
-
* Si fast = true, utilise une disparition accélérée
|
|
626
|
+
* Si fast = true, utilise une disparition accélérée pour le remplacement séquentiel.
|
|
474
627
|
*/
|
|
475
628
|
close(reason = "programmatic", fast = false) {
|
|
476
|
-
if (this._isClosed)
|
|
629
|
+
if (this._isClosed) {
|
|
630
|
+
return this.closePromise ?? Promise.resolve();
|
|
631
|
+
}
|
|
477
632
|
this._isClosed = true;
|
|
478
633
|
if (this.timerId !== null) {
|
|
479
634
|
window.clearTimeout(this.timerId);
|
|
480
635
|
this.timerId = null;
|
|
481
636
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
this.options.onClose(this, reason);
|
|
493
|
-
}
|
|
494
|
-
resolve();
|
|
495
|
-
};
|
|
496
|
-
const isReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
497
|
-
if (isReducedMotion) {
|
|
498
|
-
handleAnimationEnd();
|
|
499
|
-
} else if (fast) {
|
|
500
|
-
window.setTimeout(handleAnimationEnd, 90);
|
|
501
|
-
} else {
|
|
502
|
-
let transitioned = false;
|
|
503
|
-
let fallbackTimerId = null;
|
|
504
|
-
const onEnd = () => {
|
|
505
|
-
if (!transitioned) {
|
|
506
|
-
transitioned = true;
|
|
507
|
-
if (fallbackTimerId !== null) {
|
|
508
|
-
window.clearTimeout(fallbackTimerId);
|
|
509
|
-
fallbackTimerId = null;
|
|
510
|
-
}
|
|
511
|
-
this.element.removeEventListener("animationend", onEnd);
|
|
512
|
-
this.element.removeEventListener("transitionend", onEnd);
|
|
513
|
-
handleAnimationEnd();
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
this.element.addEventListener("animationend", onEnd, { once: true });
|
|
517
|
-
this.element.addEventListener("transitionend", onEnd, { once: true });
|
|
518
|
-
fallbackTimerId = window.setTimeout(onEnd, 300);
|
|
637
|
+
this.eventsAbortController.abort();
|
|
638
|
+
this.element.classList.add(fast ? "wulf-toast-hiding-fast" : "wulf-toast-hiding");
|
|
639
|
+
if (prefersReducedMotion()) {
|
|
640
|
+
this.finalizeDismiss(reason);
|
|
641
|
+
this.closePromise = Promise.resolve();
|
|
642
|
+
return this.closePromise;
|
|
643
|
+
}
|
|
644
|
+
this.closePromise = waitForAnimations(this.element, fast ? 90 : 300, this.disposeAbortController.signal).then(() => {
|
|
645
|
+
if (!this.disposeAbortController.signal.aborted) {
|
|
646
|
+
this.finalizeDismiss(reason);
|
|
519
647
|
}
|
|
520
648
|
});
|
|
649
|
+
return this.closePromise;
|
|
521
650
|
}
|
|
522
651
|
};
|
|
523
652
|
|
|
@@ -533,12 +662,35 @@ var VALID_POSITIONS = /* @__PURE__ */ new Set([
|
|
|
533
662
|
function normalizePosition(pos) {
|
|
534
663
|
return pos && VALID_POSITIONS.has(pos) ? pos : "top-right";
|
|
535
664
|
}
|
|
536
|
-
var
|
|
665
|
+
var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
|
|
666
|
+
var ToastManager = class _ToastManager {
|
|
667
|
+
static instance = null;
|
|
668
|
+
containers = /* @__PURE__ */ new Map();
|
|
669
|
+
activeToasts = /* @__PURE__ */ new Map();
|
|
670
|
+
announcerEl = null;
|
|
671
|
+
politeRegion = null;
|
|
672
|
+
assertiveRegion = null;
|
|
673
|
+
announceTimers = [];
|
|
674
|
+
politeAnnounceTimerId = null;
|
|
675
|
+
assertiveAnnounceTimerId = null;
|
|
676
|
+
politeClearTimerId = null;
|
|
677
|
+
assertiveClearTimerId = null;
|
|
678
|
+
lastPoliteText = "";
|
|
679
|
+
lastAssertiveText = "";
|
|
680
|
+
announcerToggle = false;
|
|
681
|
+
/**
|
|
682
|
+
* Vérifie si un conteneur Popover est ouvert (compatible natif et polyfill OddBird).
|
|
683
|
+
*/
|
|
684
|
+
isPopoverOpen(container) {
|
|
685
|
+
try {
|
|
686
|
+
if (container.matches(":popover-open")) return true;
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
return container.classList.contains(":popover-open");
|
|
690
|
+
}
|
|
691
|
+
replaceTokens = /* @__PURE__ */ new Map();
|
|
692
|
+
pendingReplacements = /* @__PURE__ */ new Set();
|
|
537
693
|
constructor() {
|
|
538
|
-
this.containers = /* @__PURE__ */ new Map();
|
|
539
|
-
this.activeToasts = /* @__PURE__ */ new Map();
|
|
540
|
-
this.replaceTokens = /* @__PURE__ */ new Map();
|
|
541
|
-
this.pendingReplacements = /* @__PURE__ */ new Set();
|
|
542
694
|
}
|
|
543
695
|
static getInstance() {
|
|
544
696
|
if (!_ToastManager.instance) {
|
|
@@ -556,6 +708,8 @@ var _ToastManager = class _ToastManager {
|
|
|
556
708
|
list = [];
|
|
557
709
|
this.activeToasts.set(position, list);
|
|
558
710
|
}
|
|
711
|
+
const rawMax = toast.options.maxToasts;
|
|
712
|
+
const maxToasts = typeof rawMax === "number" && Number.isFinite(rawMax) && rawMax > 0 ? Math.min(50, Math.max(1, Math.floor(rawMax))) : 5;
|
|
559
713
|
if (toast.options.replace && list.length > 0) {
|
|
560
714
|
const existing = [...list];
|
|
561
715
|
const token = (this.replaceTokens.get(position) || 0) + 1;
|
|
@@ -565,14 +719,17 @@ var _ToastManager = class _ToastManager {
|
|
|
565
719
|
Promise.all(promises).then(() => {
|
|
566
720
|
this.pendingReplacements.delete(position);
|
|
567
721
|
if (this.replaceTokens.get(position) !== token) {
|
|
722
|
+
toast.destroyImmediate("replace");
|
|
568
723
|
return;
|
|
569
724
|
}
|
|
570
|
-
this.mountToast(toast, position,
|
|
725
|
+
this.mountToast(toast, position, maxToasts);
|
|
571
726
|
});
|
|
572
727
|
return;
|
|
573
728
|
}
|
|
574
|
-
|
|
575
|
-
|
|
729
|
+
if (this.pendingReplacements.has(position)) {
|
|
730
|
+
this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
|
|
731
|
+
this.pendingReplacements.delete(position);
|
|
732
|
+
}
|
|
576
733
|
if (list.length >= maxToasts) {
|
|
577
734
|
const countToRemove = list.length - maxToasts + 1;
|
|
578
735
|
const oldestItems = list.splice(0, countToRemove);
|
|
@@ -583,10 +740,12 @@ var _ToastManager = class _ToastManager {
|
|
|
583
740
|
this.mountToast(toast, position, maxToasts);
|
|
584
741
|
}
|
|
585
742
|
/**
|
|
586
|
-
* Insère l'élément toast dans le
|
|
743
|
+
* Insère l'élément toast dans le conteneur Top Layer, annonce le message et démarre le minuteur.
|
|
587
744
|
*/
|
|
588
745
|
mountToast(toast, position, maxToasts = 5) {
|
|
589
|
-
|
|
746
|
+
if (toast.isClosed) return;
|
|
747
|
+
const useTopLayer = toast.options.useTopLayer ?? true;
|
|
748
|
+
const container = this.getOrCreateContainer(position, toast, useTopLayer);
|
|
590
749
|
let list = this.activeToasts.get(position);
|
|
591
750
|
if (!list) {
|
|
592
751
|
list = [];
|
|
@@ -602,8 +761,19 @@ var _ToastManager = class _ToastManager {
|
|
|
602
761
|
}
|
|
603
762
|
}
|
|
604
763
|
}
|
|
764
|
+
if (useTopLayer && typeof container.showPopover === "function" && container.getAttribute("popover") === "manual") {
|
|
765
|
+
try {
|
|
766
|
+
const popoverEl = container;
|
|
767
|
+
if (!this.isPopoverOpen(container)) {
|
|
768
|
+
popoverEl.showPopover();
|
|
769
|
+
}
|
|
770
|
+
} catch {
|
|
771
|
+
container.removeAttribute("popover");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
605
774
|
container.appendChild(toast.element);
|
|
606
775
|
list.push(toast);
|
|
776
|
+
this.announce(toast);
|
|
607
777
|
if (toast.options.onOpen) {
|
|
608
778
|
try {
|
|
609
779
|
toast.options.onOpen(toast);
|
|
@@ -613,6 +783,142 @@ var _ToastManager = class _ToastManager {
|
|
|
613
783
|
}
|
|
614
784
|
toast.startTimer();
|
|
615
785
|
}
|
|
786
|
+
/**
|
|
787
|
+
* Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
|
|
788
|
+
*/
|
|
789
|
+
announce(toast) {
|
|
790
|
+
const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
|
|
791
|
+
if (parts.length === 0) return;
|
|
792
|
+
const rawText = parts.join(". ");
|
|
793
|
+
const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
|
|
794
|
+
const isAlert = toast.options.role === "alert";
|
|
795
|
+
const docWithAriaNotify = document;
|
|
796
|
+
if (typeof docWithAriaNotify.ariaNotify === "function") {
|
|
797
|
+
try {
|
|
798
|
+
docWithAriaNotify.ariaNotify(text, { priority: isAlert ? "high" : "normal" });
|
|
799
|
+
return;
|
|
800
|
+
} catch {
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
const wasCreated = !this.announcerEl || !this.announcerEl.isConnected;
|
|
804
|
+
this.ensureAnnouncer();
|
|
805
|
+
const region = isAlert ? this.assertiveRegion : this.politeRegion;
|
|
806
|
+
if (!region) return;
|
|
807
|
+
if (isAlert) {
|
|
808
|
+
if (this.assertiveAnnounceTimerId !== null) {
|
|
809
|
+
window.clearTimeout(this.assertiveAnnounceTimerId);
|
|
810
|
+
this.assertiveAnnounceTimerId = null;
|
|
811
|
+
}
|
|
812
|
+
if (this.assertiveClearTimerId !== null) {
|
|
813
|
+
window.clearTimeout(this.assertiveClearTimerId);
|
|
814
|
+
this.assertiveClearTimerId = null;
|
|
815
|
+
}
|
|
816
|
+
} else {
|
|
817
|
+
if (this.politeAnnounceTimerId !== null) {
|
|
818
|
+
window.clearTimeout(this.politeAnnounceTimerId);
|
|
819
|
+
this.politeAnnounceTimerId = null;
|
|
820
|
+
}
|
|
821
|
+
if (this.politeClearTimerId !== null) {
|
|
822
|
+
window.clearTimeout(this.politeClearTimerId);
|
|
823
|
+
this.politeClearTimerId = null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
region.textContent = "";
|
|
827
|
+
const lastText = isAlert ? this.lastAssertiveText : this.lastPoliteText;
|
|
828
|
+
let finalMessage = text;
|
|
829
|
+
if (text === lastText) {
|
|
830
|
+
this.announcerToggle = !this.announcerToggle;
|
|
831
|
+
finalMessage = this.announcerToggle ? `${text}\xA0` : text;
|
|
832
|
+
} else {
|
|
833
|
+
this.announcerToggle = false;
|
|
834
|
+
}
|
|
835
|
+
if (isAlert) {
|
|
836
|
+
this.lastAssertiveText = text;
|
|
837
|
+
} else {
|
|
838
|
+
this.lastPoliteText = text;
|
|
839
|
+
}
|
|
840
|
+
const delay = wasCreated ? 120 : 50;
|
|
841
|
+
const timerId = window.setTimeout(() => {
|
|
842
|
+
const idx = this.announceTimers.indexOf(timerId);
|
|
843
|
+
if (idx !== -1) this.announceTimers.splice(idx, 1);
|
|
844
|
+
if (isAlert) {
|
|
845
|
+
this.assertiveAnnounceTimerId = null;
|
|
846
|
+
} else {
|
|
847
|
+
this.politeAnnounceTimerId = null;
|
|
848
|
+
}
|
|
849
|
+
if (region.isConnected) {
|
|
850
|
+
region.textContent = finalMessage;
|
|
851
|
+
const clearId = window.setTimeout(() => {
|
|
852
|
+
const cIdx = this.announceTimers.indexOf(clearId);
|
|
853
|
+
if (cIdx !== -1) this.announceTimers.splice(cIdx, 1);
|
|
854
|
+
if (region.isConnected && region.textContent === finalMessage) {
|
|
855
|
+
region.textContent = "";
|
|
856
|
+
}
|
|
857
|
+
}, 4e3);
|
|
858
|
+
this.announceTimers.push(clearId);
|
|
859
|
+
if (isAlert) {
|
|
860
|
+
this.assertiveClearTimerId = clearId;
|
|
861
|
+
} else {
|
|
862
|
+
this.politeClearTimerId = clearId;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}, delay);
|
|
866
|
+
this.announceTimers.push(timerId);
|
|
867
|
+
if (isAlert) {
|
|
868
|
+
this.assertiveAnnounceTimerId = timerId;
|
|
869
|
+
} else {
|
|
870
|
+
this.politeAnnounceTimerId = timerId;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Crée ou reconnecte le conteneur persistant des annonces ARIA hors du popover.
|
|
875
|
+
*/
|
|
876
|
+
ensureAnnouncer() {
|
|
877
|
+
if (this.announcerEl && document.body.contains(this.announcerEl)) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
const wrapper = document.createElement("div");
|
|
881
|
+
wrapper.className = "wulf-toast-announcer";
|
|
882
|
+
wrapper.setAttribute("data-wulf-toast-announcer", "true");
|
|
883
|
+
const polite = document.createElement("div");
|
|
884
|
+
polite.setAttribute("role", "status");
|
|
885
|
+
polite.setAttribute("aria-live", "polite");
|
|
886
|
+
polite.setAttribute("aria-atomic", "true");
|
|
887
|
+
const assertive = document.createElement("div");
|
|
888
|
+
assertive.setAttribute("role", "alert");
|
|
889
|
+
assertive.setAttribute("aria-live", "assertive");
|
|
890
|
+
assertive.setAttribute("aria-atomic", "true");
|
|
891
|
+
wrapper.appendChild(polite);
|
|
892
|
+
wrapper.appendChild(assertive);
|
|
893
|
+
document.body.appendChild(wrapper);
|
|
894
|
+
this.announcerEl = wrapper;
|
|
895
|
+
this.politeRegion = polite;
|
|
896
|
+
this.assertiveRegion = assertive;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
|
|
900
|
+
*/
|
|
901
|
+
handleFocusHandoff(toast, list) {
|
|
902
|
+
if (!toast.element.contains(document.activeElement)) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
906
|
+
const sibling = list[i];
|
|
907
|
+
if (sibling === toast || sibling.isClosed || !sibling.element.isConnected) continue;
|
|
908
|
+
const target = sibling.element.querySelector(FOCUSABLE_IN_TOAST);
|
|
909
|
+
if (target) {
|
|
910
|
+
target.focus({ preventScroll: true });
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
const prev = toast.getPreviousActiveElement();
|
|
915
|
+
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
|
|
916
|
+
try {
|
|
917
|
+
prev.focus();
|
|
918
|
+
} catch {
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
616
922
|
/**
|
|
617
923
|
* Retire une notification de la pile et nettoie le conteneur s'il est vide.
|
|
618
924
|
*/
|
|
@@ -624,16 +930,32 @@ var _ToastManager = class _ToastManager {
|
|
|
624
930
|
if (index !== -1) {
|
|
625
931
|
list.splice(index, 1);
|
|
626
932
|
}
|
|
933
|
+
this.handleFocusHandoff(toast, list);
|
|
934
|
+
if (toast.element.parentNode) {
|
|
935
|
+
toast.element.parentNode.removeChild(toast.element);
|
|
936
|
+
}
|
|
627
937
|
if (list.length === 0 && !this.pendingReplacements.has(position)) {
|
|
628
938
|
const container = this.containers.get(position);
|
|
629
939
|
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
630
|
-
|
|
631
|
-
container.parentNode.removeChild(container);
|
|
632
|
-
}
|
|
940
|
+
this.disposeContainer(container);
|
|
633
941
|
this.containers.delete(position);
|
|
634
942
|
this.activeToasts.delete(position);
|
|
635
943
|
}
|
|
636
944
|
}
|
|
945
|
+
} else if (toast.element.parentNode) {
|
|
946
|
+
toast.element.parentNode.removeChild(toast.element);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
disposeContainer(container) {
|
|
950
|
+
try {
|
|
951
|
+
const popoverEl = container;
|
|
952
|
+
if (typeof popoverEl.hidePopover === "function" && this.isPopoverOpen(container)) {
|
|
953
|
+
popoverEl.hidePopover();
|
|
954
|
+
}
|
|
955
|
+
} catch {
|
|
956
|
+
}
|
|
957
|
+
if (container.parentNode) {
|
|
958
|
+
container.parentNode.removeChild(container);
|
|
637
959
|
}
|
|
638
960
|
}
|
|
639
961
|
/**
|
|
@@ -642,6 +964,8 @@ var _ToastManager = class _ToastManager {
|
|
|
642
964
|
clearAll(position) {
|
|
643
965
|
const promises = [];
|
|
644
966
|
if (position) {
|
|
967
|
+
this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
|
|
968
|
+
this.pendingReplacements.delete(position);
|
|
645
969
|
const list = this.activeToasts.get(position);
|
|
646
970
|
if (list && list.length > 0) {
|
|
647
971
|
const copy = [...list];
|
|
@@ -651,14 +975,24 @@ var _ToastManager = class _ToastManager {
|
|
|
651
975
|
} else {
|
|
652
976
|
const container = this.containers.get(position);
|
|
653
977
|
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
654
|
-
|
|
655
|
-
container.parentNode.removeChild(container);
|
|
656
|
-
}
|
|
978
|
+
this.disposeContainer(container);
|
|
657
979
|
this.containers.delete(position);
|
|
658
980
|
this.activeToasts.delete(position);
|
|
659
981
|
}
|
|
660
982
|
}
|
|
661
983
|
} else {
|
|
984
|
+
for (const pos of this.replaceTokens.keys()) {
|
|
985
|
+
this.replaceTokens.set(pos, (this.replaceTokens.get(pos) || 0) + 1);
|
|
986
|
+
}
|
|
987
|
+
this.pendingReplacements.clear();
|
|
988
|
+
for (const timerId of this.announceTimers) {
|
|
989
|
+
window.clearTimeout(timerId);
|
|
990
|
+
}
|
|
991
|
+
this.announceTimers = [];
|
|
992
|
+
this.politeAnnounceTimerId = null;
|
|
993
|
+
this.assertiveAnnounceTimerId = null;
|
|
994
|
+
this.politeClearTimerId = null;
|
|
995
|
+
this.assertiveClearTimerId = null;
|
|
662
996
|
const allPositions = /* @__PURE__ */ new Set([
|
|
663
997
|
...Array.from(this.containers.keys()),
|
|
664
998
|
...Array.from(this.activeToasts.keys())
|
|
@@ -671,9 +1005,7 @@ var _ToastManager = class _ToastManager {
|
|
|
671
1005
|
if (!position) {
|
|
672
1006
|
for (const [pos, container] of Array.from(this.containers.entries())) {
|
|
673
1007
|
if (!container.firstChild || container.children.length === 0) {
|
|
674
|
-
|
|
675
|
-
container.parentNode.removeChild(container);
|
|
676
|
-
}
|
|
1008
|
+
this.disposeContainer(container);
|
|
677
1009
|
this.containers.delete(pos);
|
|
678
1010
|
this.activeToasts.delete(pos);
|
|
679
1011
|
}
|
|
@@ -681,27 +1013,58 @@ var _ToastManager = class _ToastManager {
|
|
|
681
1013
|
}
|
|
682
1014
|
});
|
|
683
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Détruit immédiatement tous les toasts, conteneurs, annonceurs ARIA et temporisations en cours.
|
|
1018
|
+
*/
|
|
1019
|
+
destroy() {
|
|
1020
|
+
for (const timerId of this.announceTimers) {
|
|
1021
|
+
window.clearTimeout(timerId);
|
|
1022
|
+
}
|
|
1023
|
+
this.announceTimers = [];
|
|
1024
|
+
for (const list of Array.from(this.activeToasts.values())) {
|
|
1025
|
+
for (const toast of [...list]) {
|
|
1026
|
+
toast.destroyImmediate("programmatic");
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
for (const container of Array.from(this.containers.values())) {
|
|
1030
|
+
this.disposeContainer(container);
|
|
1031
|
+
}
|
|
1032
|
+
this.containers.clear();
|
|
1033
|
+
this.activeToasts.clear();
|
|
1034
|
+
this.replaceTokens.clear();
|
|
1035
|
+
this.pendingReplacements.clear();
|
|
1036
|
+
if (this.announcerEl) {
|
|
1037
|
+
this.announcerEl.remove();
|
|
1038
|
+
this.announcerEl = null;
|
|
1039
|
+
this.politeRegion = null;
|
|
1040
|
+
this.assertiveRegion = null;
|
|
1041
|
+
}
|
|
1042
|
+
_ToastManager.instance = null;
|
|
1043
|
+
}
|
|
684
1044
|
/**
|
|
685
1045
|
* Récupère ou crée le conteneur DOM pour une position d'affichage.
|
|
686
1046
|
*/
|
|
687
|
-
getOrCreateContainer(position) {
|
|
1047
|
+
getOrCreateContainer(position, toast, useTopLayer) {
|
|
688
1048
|
let container = this.containers.get(position);
|
|
689
1049
|
if (!container || !document.body.contains(container)) {
|
|
690
1050
|
container = document.createElement("div");
|
|
691
1051
|
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
692
|
-
container.setAttribute("
|
|
693
|
-
container.setAttribute("aria-
|
|
1052
|
+
container.setAttribute("role", "region");
|
|
1053
|
+
container.setAttribute("aria-label", toastI18n.t("notificationsRegion", toast.options.i18n));
|
|
1054
|
+
if (useTopLayer && typeof container.showPopover === "function") {
|
|
1055
|
+
container.setAttribute("popover", "manual");
|
|
1056
|
+
}
|
|
694
1057
|
document.body.appendChild(container);
|
|
695
1058
|
this.containers.set(position, container);
|
|
696
1059
|
}
|
|
697
1060
|
return container;
|
|
698
1061
|
}
|
|
699
1062
|
};
|
|
700
|
-
_ToastManager.instance = null;
|
|
701
|
-
var ToastManager = _ToastManager;
|
|
702
1063
|
|
|
703
1064
|
// src/toast/Toast.ts
|
|
704
1065
|
var Toast = class extends LocalizedComponent {
|
|
1066
|
+
static _i18n = toastI18n;
|
|
1067
|
+
static i18n = toastI18n;
|
|
705
1068
|
audit() {
|
|
706
1069
|
return [];
|
|
707
1070
|
}
|
|
@@ -728,16 +1091,18 @@ var Toast = class extends LocalizedComponent {
|
|
|
728
1091
|
static clearAll(position) {
|
|
729
1092
|
return ToastManager.getInstance().clearAll(position);
|
|
730
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Détruit le gestionnaire de notifications (conteneurs, annonceurs ARIA et timers).
|
|
1096
|
+
*/
|
|
1097
|
+
static destroy() {
|
|
1098
|
+
ToastManager.getInstance().destroy();
|
|
1099
|
+
}
|
|
731
1100
|
};
|
|
732
|
-
Toast._i18n = toastI18n;
|
|
733
|
-
Toast.i18n = toastI18n;
|
|
734
1101
|
|
|
735
1102
|
// src/toast/index.ts
|
|
736
1103
|
var index_default = Toast;
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
const wulfNamespace = win.Wulf || {};
|
|
740
|
-
win.Wulf = wulfNamespace;
|
|
1104
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
1105
|
+
if (wulfNamespace) {
|
|
741
1106
|
wulfNamespace.Toast = Object.assign(Toast, {
|
|
742
1107
|
Toast,
|
|
743
1108
|
i18n: toastI18n
|