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.
- package/README.md +124 -78
- package/changelog.md +105 -0
- package/dist/focus-trap.esm.js +245 -126
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +247 -128
- 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 +2434 -905
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2436 -907
- 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 +746 -346
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +748 -348
- 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 +341 -114
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +343 -116
- 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 +524 -153
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +526 -155
- 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 +209 -46
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +211 -48
- 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 +590 -160
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +592 -162
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -4
- 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 +15 -5
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/AmountEngine.d.ts +1 -0
- package/dist/types/mask/BaseInputMask.d.ts +24 -0
- package/dist/types/mask/InputAmountMask.d.ts +3 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- package/dist/types/mask/InputMask.d.ts +1 -0
- 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 +5 -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 +14 -2
- package/package.json +20 -5
package/dist/toast.esm.js
CHANGED
|
@@ -1,33 +1,94 @@
|
|
|
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
|
|
49
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
50
|
+
function isSafeKey(key) {
|
|
51
|
+
return Boolean(key) && !FORBIDDEN_KEYS.has(key);
|
|
52
|
+
}
|
|
2
53
|
function normalizeLocaleCode(locale) {
|
|
3
|
-
|
|
54
|
+
const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
55
|
+
return isSafeKey(norm) ? norm : "";
|
|
4
56
|
}
|
|
5
57
|
function getPrimaryLanguage(normalizedLocale) {
|
|
6
58
|
const dashIndex = normalizedLocale.indexOf("-");
|
|
7
|
-
|
|
59
|
+
const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
60
|
+
return primary && isSafeKey(primary) ? primary : null;
|
|
8
61
|
}
|
|
9
62
|
function assignDefined(target, source) {
|
|
10
|
-
if (!source) return target;
|
|
63
|
+
if (!source || typeof source !== "object") return target;
|
|
11
64
|
for (const key of Object.keys(source)) {
|
|
12
|
-
if (source[key] !== void 0) {
|
|
65
|
+
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
13
66
|
target[key] = source[key];
|
|
14
67
|
}
|
|
15
68
|
}
|
|
16
69
|
return target;
|
|
17
70
|
}
|
|
18
71
|
function createI18nManager(defaultLocale, locales) {
|
|
19
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
20
|
-
const initialLocales =
|
|
72
|
+
const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
|
|
73
|
+
const initialLocales = /* @__PURE__ */ Object.create(null);
|
|
21
74
|
for (const [loc, dict] of Object.entries(locales)) {
|
|
22
|
-
|
|
75
|
+
const norm = normalizeLocaleCode(loc);
|
|
76
|
+
if (norm) {
|
|
77
|
+
initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
78
|
+
}
|
|
23
79
|
}
|
|
24
80
|
let currentLocale = fallbackLocale;
|
|
25
|
-
let activeLocales =
|
|
26
|
-
|
|
81
|
+
let activeLocales = /* @__PURE__ */ Object.create(null);
|
|
82
|
+
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
83
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
84
|
+
}
|
|
85
|
+
let globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
27
86
|
function resolveActiveDictionaries() {
|
|
28
87
|
const dicts = [];
|
|
29
|
-
|
|
30
|
-
|
|
88
|
+
if (isSafeKey(currentLocale)) {
|
|
89
|
+
const exact = activeLocales[currentLocale];
|
|
90
|
+
if (exact) dicts.push(exact);
|
|
91
|
+
}
|
|
31
92
|
const primary = getPrimaryLanguage(currentLocale);
|
|
32
93
|
if (primary && activeLocales[primary]) {
|
|
33
94
|
dicts.push(activeLocales[primary]);
|
|
@@ -36,24 +97,33 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
36
97
|
}
|
|
37
98
|
return {
|
|
38
99
|
setLocale(locale) {
|
|
39
|
-
if (locale && locale.trim()) {
|
|
40
|
-
|
|
100
|
+
if (locale && typeof locale === "string" && locale.trim()) {
|
|
101
|
+
const norm = normalizeLocaleCode(locale);
|
|
102
|
+
if (norm) {
|
|
103
|
+
currentLocale = norm;
|
|
104
|
+
}
|
|
41
105
|
}
|
|
42
106
|
},
|
|
43
107
|
getLocale() {
|
|
44
108
|
return currentLocale;
|
|
45
109
|
},
|
|
46
110
|
registerLocale(locale, translations) {
|
|
47
|
-
if (!locale || !locale.trim() || !translations) return;
|
|
111
|
+
if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
|
|
48
112
|
const norm = normalizeLocaleCode(locale);
|
|
49
|
-
|
|
113
|
+
if (!norm) return;
|
|
114
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
|
|
115
|
+
activeLocales[norm] = assignDefined(base, translations);
|
|
50
116
|
},
|
|
51
117
|
setI18n(overrides) {
|
|
52
|
-
if (!overrides) return;
|
|
53
|
-
|
|
118
|
+
if (!overrides || typeof overrides !== "object") return;
|
|
119
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
|
|
120
|
+
globalOverrides = assignDefined(base, overrides);
|
|
54
121
|
},
|
|
55
122
|
t(key, instanceOverride) {
|
|
56
|
-
if (
|
|
123
|
+
if (!isSafeKey(String(key))) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
57
127
|
return String(instanceOverride[key]);
|
|
58
128
|
}
|
|
59
129
|
if (globalOverrides[key] !== void 0) {
|
|
@@ -84,10 +154,10 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
84
154
|
},
|
|
85
155
|
reset() {
|
|
86
156
|
currentLocale = fallbackLocale;
|
|
87
|
-
globalOverrides =
|
|
88
|
-
activeLocales =
|
|
157
|
+
globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
158
|
+
activeLocales = /* @__PURE__ */ Object.create(null);
|
|
89
159
|
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
90
|
-
activeLocales[loc] =
|
|
160
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
91
161
|
}
|
|
92
162
|
}
|
|
93
163
|
};
|
|
@@ -125,8 +195,11 @@ var AuditableComponent = class {
|
|
|
125
195
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
126
196
|
if (!rawValue) return false;
|
|
127
197
|
const doc = element.ownerDocument || document;
|
|
198
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
128
199
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
129
|
-
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
|
+
);
|
|
130
203
|
if (!isValid) {
|
|
131
204
|
warnings.push(
|
|
132
205
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -138,6 +211,7 @@ var AuditableComponent = class {
|
|
|
138
211
|
|
|
139
212
|
// src/common/LocalizedComponent.ts
|
|
140
213
|
var LocalizedComponent = class extends AuditableComponent {
|
|
214
|
+
static _i18n;
|
|
141
215
|
/**
|
|
142
216
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
143
217
|
*/
|
|
@@ -188,6 +262,10 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
188
262
|
static t(key, instanceOverride) {
|
|
189
263
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
190
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Surcharges de localisation spécifiques à cette instance.
|
|
267
|
+
*/
|
|
268
|
+
i18nOverrides;
|
|
191
269
|
constructor(i18nOverrides) {
|
|
192
270
|
super();
|
|
193
271
|
this.i18nOverrides = i18nOverrides;
|
|
@@ -203,12 +281,14 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
203
281
|
|
|
204
282
|
// src/toast/i18n/fr.ts
|
|
205
283
|
var toastFr = {
|
|
206
|
-
closeButton: "Fermer la notification"
|
|
284
|
+
closeButton: "Fermer la notification",
|
|
285
|
+
notificationsRegion: "Notifications"
|
|
207
286
|
};
|
|
208
287
|
|
|
209
288
|
// src/toast/i18n/en.ts
|
|
210
289
|
var toastEn = {
|
|
211
|
-
closeButton: "Close notification"
|
|
290
|
+
closeButton: "Close notification",
|
|
291
|
+
notificationsRegion: "Notifications"
|
|
212
292
|
};
|
|
213
293
|
|
|
214
294
|
// src/toast/i18n/index.ts
|
|
@@ -219,22 +299,54 @@ var toastI18n = createI18nManager("fr", {
|
|
|
219
299
|
|
|
220
300
|
// src/toast/ToastInstance.ts
|
|
221
301
|
var nextToastId = 1;
|
|
302
|
+
var DEFAULT_TOAST_DURATION = 5e3;
|
|
303
|
+
function isSafeCssValue(val) {
|
|
304
|
+
if (!val || typeof val !== "string" || val.length > 128) return false;
|
|
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;
|
|
314
|
+
}
|
|
315
|
+
function sanitizeIconClasses(icon) {
|
|
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(" ");
|
|
317
|
+
}
|
|
222
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;
|
|
223
337
|
constructor(options, onDismiss) {
|
|
224
338
|
super();
|
|
225
|
-
this._isClosed = false;
|
|
226
|
-
this.timerId = null;
|
|
227
|
-
this.remainingTime = 0;
|
|
228
|
-
this.timerStartTime = 0;
|
|
229
|
-
this.isPaused = false;
|
|
230
339
|
this.id = `wulf-toast-${nextToastId++}`;
|
|
231
340
|
this.options = Object.freeze({ ...options });
|
|
232
341
|
this.onDismissCallback = onDismiss;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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;
|
|
236
347
|
} else {
|
|
237
348
|
this.remainingTime = 0;
|
|
349
|
+
this.hasDuration = false;
|
|
238
350
|
}
|
|
239
351
|
this.element = this.createDOM();
|
|
240
352
|
this.bindEvents();
|
|
@@ -243,6 +355,9 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
243
355
|
get isClosed() {
|
|
244
356
|
return this._isClosed;
|
|
245
357
|
}
|
|
358
|
+
getPreviousActiveElement() {
|
|
359
|
+
return this.previousActiveElement;
|
|
360
|
+
}
|
|
246
361
|
/**
|
|
247
362
|
* Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
|
|
248
363
|
* et retourne la liste des contraintes manquantes.
|
|
@@ -256,7 +371,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
256
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)."
|
|
257
372
|
);
|
|
258
373
|
}
|
|
259
|
-
const duration = this.options.duration === void 0 ?
|
|
374
|
+
const duration = this.options.duration === void 0 ? DEFAULT_TOAST_DURATION : this.options.duration;
|
|
260
375
|
if (typeof duration === "number" && duration > 0 && duration < 5e3) {
|
|
261
376
|
warnings.push(
|
|
262
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).`
|
|
@@ -264,9 +379,9 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
264
379
|
}
|
|
265
380
|
const closable = this.options.closable ?? true;
|
|
266
381
|
const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
|
|
267
|
-
if (isPersistent && !closable
|
|
382
|
+
if (isPersistent && !closable) {
|
|
268
383
|
warnings.push(
|
|
269
|
-
"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)."
|
|
270
385
|
);
|
|
271
386
|
}
|
|
272
387
|
return warnings;
|
|
@@ -279,35 +394,36 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
279
394
|
}
|
|
280
395
|
/**
|
|
281
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.
|
|
282
398
|
*/
|
|
283
399
|
createDOM() {
|
|
284
400
|
const el = document.createElement("div");
|
|
285
401
|
el.id = this.id;
|
|
286
402
|
el.className = "wulf-toast";
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
el.setAttribute("aria-atomic", "true");
|
|
291
|
-
if (this.options.backgroundColor) {
|
|
292
|
-
el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor);
|
|
403
|
+
el.setAttribute("data-toast-role", this.options.role === "alert" ? "alert" : "status");
|
|
404
|
+
if (this.options.backgroundColor && isSafeCssValue(this.options.backgroundColor)) {
|
|
405
|
+
el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor.trim());
|
|
293
406
|
}
|
|
294
|
-
if (this.options.titleColor) {
|
|
295
|
-
el.style.setProperty("--wulf-toast-title-color", this.options.titleColor);
|
|
407
|
+
if (this.options.titleColor && isSafeCssValue(this.options.titleColor)) {
|
|
408
|
+
el.style.setProperty("--wulf-toast-title-color", this.options.titleColor.trim());
|
|
296
409
|
}
|
|
297
|
-
if (this.options.textColor) {
|
|
298
|
-
el.style.setProperty("--wulf-toast-text-color", this.options.textColor);
|
|
410
|
+
if (this.options.textColor && isSafeCssValue(this.options.textColor)) {
|
|
411
|
+
el.style.setProperty("--wulf-toast-text-color", this.options.textColor.trim());
|
|
299
412
|
}
|
|
300
|
-
if (this.options.iconColor) {
|
|
301
|
-
el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor);
|
|
413
|
+
if (this.options.iconColor && isSafeCssValue(this.options.iconColor)) {
|
|
414
|
+
el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor.trim());
|
|
302
415
|
}
|
|
303
|
-
if (this.options.closeButtonColor) {
|
|
304
|
-
el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor);
|
|
416
|
+
if (this.options.closeButtonColor && isSafeCssValue(this.options.closeButtonColor)) {
|
|
417
|
+
el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor.trim());
|
|
305
418
|
}
|
|
306
|
-
if (this.options.icon && this.options.icon.trim() !== "") {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
419
|
+
if (this.options.icon && typeof this.options.icon === "string" && this.options.icon.trim() !== "") {
|
|
420
|
+
const safeIcon = sanitizeIconClasses(this.options.icon);
|
|
421
|
+
if (safeIcon) {
|
|
422
|
+
const iconContainer = document.createElement("span");
|
|
423
|
+
iconContainer.className = `wulf-toast-icon ${safeIcon}`;
|
|
424
|
+
iconContainer.setAttribute("aria-hidden", "true");
|
|
425
|
+
el.appendChild(iconContainer);
|
|
426
|
+
}
|
|
311
427
|
}
|
|
312
428
|
const content = document.createElement("div");
|
|
313
429
|
content.className = "wulf-toast-content";
|
|
@@ -330,7 +446,6 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
330
446
|
closeBtn.type = "button";
|
|
331
447
|
closeBtn.className = "wulf-toast-close";
|
|
332
448
|
closeBtn.setAttribute("aria-label", toastI18n.t("closeButton", this.options.i18n));
|
|
333
|
-
closeBtn.setAttribute("tabindex", "0");
|
|
334
449
|
const closeIcon = document.createElement("span");
|
|
335
450
|
closeIcon.className = "wulf-toast-close-icon";
|
|
336
451
|
closeIcon.setAttribute("aria-hidden", "true");
|
|
@@ -339,17 +454,24 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
339
454
|
closeBtn.addEventListener("click", (e) => {
|
|
340
455
|
e.stopPropagation();
|
|
341
456
|
this.close("close-button");
|
|
342
|
-
});
|
|
457
|
+
}, { signal: this.eventsAbortController.signal });
|
|
343
458
|
el.appendChild(closeBtn);
|
|
344
459
|
}
|
|
460
|
+
if (this.options.progressBar && this.remainingTime > 0) {
|
|
461
|
+
el.style.setProperty("--wulf-toast-duration", `${this.remainingTime}ms`);
|
|
462
|
+
const progressBar = document.createElement("div");
|
|
463
|
+
progressBar.className = "wulf-toast-progress";
|
|
464
|
+
progressBar.setAttribute("aria-hidden", "true");
|
|
465
|
+
el.appendChild(progressBar);
|
|
466
|
+
}
|
|
345
467
|
return el;
|
|
346
468
|
}
|
|
347
469
|
/**
|
|
348
470
|
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
349
|
-
* Utilise document.createTextNode et des éléments <br> créés proprement.
|
|
350
471
|
*/
|
|
351
472
|
appendTextWithLineBreaks(container, text) {
|
|
352
|
-
const
|
|
473
|
+
const safeText = String(text ?? "").slice(0, 4096);
|
|
474
|
+
const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
|
|
353
475
|
lines.forEach((line, index) => {
|
|
354
476
|
if (index > 0) {
|
|
355
477
|
container.appendChild(document.createElement("br"));
|
|
@@ -358,9 +480,10 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
358
480
|
});
|
|
359
481
|
}
|
|
360
482
|
/**
|
|
361
|
-
* 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).
|
|
362
484
|
*/
|
|
363
485
|
bindEvents() {
|
|
486
|
+
const { signal } = this.eventsAbortController;
|
|
364
487
|
this.element.addEventListener("click", (e) => {
|
|
365
488
|
if (this.options.onClick) {
|
|
366
489
|
this.options.onClick(this, e);
|
|
@@ -368,123 +491,206 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
368
491
|
if (this.options.closeOnClick) {
|
|
369
492
|
this.close("toast-click");
|
|
370
493
|
}
|
|
371
|
-
});
|
|
372
|
-
this.element.addEventListener("mouseenter", () => this.pauseTimer());
|
|
373
|
-
this.element.addEventListener("mouseleave", () => this.resumeTimer());
|
|
374
|
-
this.element.addEventListener("focusin", () => this.pauseTimer());
|
|
375
|
-
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;
|
|
376
528
|
}
|
|
377
529
|
/**
|
|
378
|
-
* Démarrage du compte à rebours de disparition automatique
|
|
530
|
+
* Démarrage du compte à rebours de disparition automatique (horloge monotone).
|
|
379
531
|
*/
|
|
380
532
|
startTimer() {
|
|
381
|
-
if (this._isClosed || this.remainingTime <= 0) return;
|
|
382
|
-
|
|
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();
|
|
383
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
|
+
}
|
|
384
550
|
this.close("timeout");
|
|
385
551
|
}, this.remainingTime);
|
|
386
552
|
}
|
|
387
553
|
/**
|
|
388
|
-
* 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).
|
|
389
555
|
*/
|
|
390
|
-
pauseTimer() {
|
|
391
|
-
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;
|
|
392
567
|
if (this.timerId !== null) {
|
|
393
568
|
window.clearTimeout(this.timerId);
|
|
394
569
|
this.timerId = null;
|
|
570
|
+
const elapsed = performance.now() - this.timerStartTime;
|
|
571
|
+
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
395
572
|
}
|
|
396
|
-
|
|
397
|
-
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
398
|
-
this.isPaused = true;
|
|
573
|
+
this.element.classList.add("is-paused");
|
|
399
574
|
}
|
|
400
575
|
/**
|
|
401
|
-
* Reprend le compte à rebours
|
|
576
|
+
* Reprend le compte à rebours si aucune autre cause de pause n'est active.
|
|
402
577
|
*/
|
|
403
|
-
resumeTimer() {
|
|
404
|
-
if (this._isClosed ||
|
|
405
|
-
|
|
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;
|
|
591
|
+
this.element.classList.remove("is-paused");
|
|
592
|
+
if (this.remainingTime <= 0) {
|
|
593
|
+
this.close("timeout");
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
406
596
|
this.startTimer();
|
|
407
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
|
+
}
|
|
408
612
|
/**
|
|
409
|
-
* Déclenche la destruction immédiate sans animation
|
|
613
|
+
* Déclenche la destruction immédiate sans animation.
|
|
410
614
|
*/
|
|
411
615
|
destroyImmediate(reason = "replace") {
|
|
412
|
-
if (this._isClosed) return;
|
|
413
616
|
this._isClosed = true;
|
|
414
617
|
if (this.timerId !== null) {
|
|
415
618
|
window.clearTimeout(this.timerId);
|
|
416
619
|
this.timerId = null;
|
|
417
620
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
if (this.onDismissCallback) {
|
|
422
|
-
this.onDismissCallback(this, reason);
|
|
423
|
-
}
|
|
424
|
-
if (this.options.onClose) {
|
|
425
|
-
this.options.onClose(this, reason);
|
|
426
|
-
}
|
|
621
|
+
this.disposeAbortController.abort();
|
|
622
|
+
this.finalizeDismiss(reason);
|
|
427
623
|
}
|
|
428
624
|
/**
|
|
429
625
|
* Déclenche la fermeture propre et l'animation de sortie du toast.
|
|
430
|
-
* 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.
|
|
431
627
|
*/
|
|
432
628
|
close(reason = "programmatic", fast = false) {
|
|
433
|
-
if (this._isClosed)
|
|
629
|
+
if (this._isClosed) {
|
|
630
|
+
return this.closePromise ?? Promise.resolve();
|
|
631
|
+
}
|
|
434
632
|
this._isClosed = true;
|
|
435
633
|
if (this.timerId !== null) {
|
|
436
634
|
window.clearTimeout(this.timerId);
|
|
437
635
|
this.timerId = null;
|
|
438
636
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.options.onClose(this, reason);
|
|
450
|
-
}
|
|
451
|
-
resolve();
|
|
452
|
-
};
|
|
453
|
-
const isReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
454
|
-
if (isReducedMotion) {
|
|
455
|
-
handleAnimationEnd();
|
|
456
|
-
} else if (fast) {
|
|
457
|
-
window.setTimeout(handleAnimationEnd, 90);
|
|
458
|
-
} else {
|
|
459
|
-
let transitioned = false;
|
|
460
|
-
let fallbackTimerId = null;
|
|
461
|
-
const onEnd = () => {
|
|
462
|
-
if (!transitioned) {
|
|
463
|
-
transitioned = true;
|
|
464
|
-
if (fallbackTimerId !== null) {
|
|
465
|
-
window.clearTimeout(fallbackTimerId);
|
|
466
|
-
fallbackTimerId = null;
|
|
467
|
-
}
|
|
468
|
-
this.element.removeEventListener("animationend", onEnd);
|
|
469
|
-
this.element.removeEventListener("transitionend", onEnd);
|
|
470
|
-
handleAnimationEnd();
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
this.element.addEventListener("animationend", onEnd, { once: true });
|
|
474
|
-
this.element.addEventListener("transitionend", onEnd, { once: true });
|
|
475
|
-
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);
|
|
476
647
|
}
|
|
477
648
|
});
|
|
649
|
+
return this.closePromise;
|
|
478
650
|
}
|
|
479
651
|
};
|
|
480
652
|
|
|
481
653
|
// src/toast/ToastManager.ts
|
|
482
|
-
var
|
|
654
|
+
var VALID_POSITIONS = /* @__PURE__ */ new Set([
|
|
655
|
+
"top-left",
|
|
656
|
+
"top-center",
|
|
657
|
+
"top-right",
|
|
658
|
+
"bottom-left",
|
|
659
|
+
"bottom-center",
|
|
660
|
+
"bottom-right"
|
|
661
|
+
]);
|
|
662
|
+
function normalizePosition(pos) {
|
|
663
|
+
return pos && VALID_POSITIONS.has(pos) ? pos : "top-right";
|
|
664
|
+
}
|
|
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();
|
|
483
693
|
constructor() {
|
|
484
|
-
this.containers = /* @__PURE__ */ new Map();
|
|
485
|
-
this.activeToasts = /* @__PURE__ */ new Map();
|
|
486
|
-
this.replaceTokens = /* @__PURE__ */ new Map();
|
|
487
|
-
this.pendingReplacements = /* @__PURE__ */ new Set();
|
|
488
694
|
}
|
|
489
695
|
static getInstance() {
|
|
490
696
|
if (!_ToastManager.instance) {
|
|
@@ -496,12 +702,14 @@ var _ToastManager = class _ToastManager {
|
|
|
496
702
|
* Ajoute et affiche une notification Toast.
|
|
497
703
|
*/
|
|
498
704
|
add(toast) {
|
|
499
|
-
const position = toast.options.position
|
|
705
|
+
const position = normalizePosition(toast.options.position);
|
|
500
706
|
let list = this.activeToasts.get(position);
|
|
501
707
|
if (!list) {
|
|
502
708
|
list = [];
|
|
503
709
|
this.activeToasts.set(position, list);
|
|
504
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;
|
|
505
713
|
if (toast.options.replace && list.length > 0) {
|
|
506
714
|
const existing = [...list];
|
|
507
715
|
const token = (this.replaceTokens.get(position) || 0) + 1;
|
|
@@ -511,13 +719,17 @@ var _ToastManager = class _ToastManager {
|
|
|
511
719
|
Promise.all(promises).then(() => {
|
|
512
720
|
this.pendingReplacements.delete(position);
|
|
513
721
|
if (this.replaceTokens.get(position) !== token) {
|
|
722
|
+
toast.destroyImmediate("replace");
|
|
514
723
|
return;
|
|
515
724
|
}
|
|
516
|
-
this.mountToast(toast, position);
|
|
725
|
+
this.mountToast(toast, position, maxToasts);
|
|
517
726
|
});
|
|
518
727
|
return;
|
|
519
728
|
}
|
|
520
|
-
|
|
729
|
+
if (this.pendingReplacements.has(position)) {
|
|
730
|
+
this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
|
|
731
|
+
this.pendingReplacements.delete(position);
|
|
732
|
+
}
|
|
521
733
|
if (list.length >= maxToasts) {
|
|
522
734
|
const countToRemove = list.length - maxToasts + 1;
|
|
523
735
|
const oldestItems = list.splice(0, countToRemove);
|
|
@@ -525,20 +737,43 @@ var _ToastManager = class _ToastManager {
|
|
|
525
737
|
item.close("max-limit", true);
|
|
526
738
|
}
|
|
527
739
|
}
|
|
528
|
-
this.mountToast(toast, position);
|
|
740
|
+
this.mountToast(toast, position, maxToasts);
|
|
529
741
|
}
|
|
530
742
|
/**
|
|
531
|
-
* 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.
|
|
532
744
|
*/
|
|
533
|
-
mountToast(toast, position) {
|
|
534
|
-
|
|
745
|
+
mountToast(toast, position, maxToasts = 5) {
|
|
746
|
+
if (toast.isClosed) return;
|
|
747
|
+
const useTopLayer = toast.options.useTopLayer ?? true;
|
|
748
|
+
const container = this.getOrCreateContainer(position, toast, useTopLayer);
|
|
535
749
|
let list = this.activeToasts.get(position);
|
|
536
750
|
if (!list) {
|
|
537
751
|
list = [];
|
|
538
752
|
this.activeToasts.set(position, list);
|
|
539
753
|
}
|
|
754
|
+
const maxDomNodes = maxToasts + 10;
|
|
755
|
+
if (container.children.length >= maxDomNodes) {
|
|
756
|
+
const children = Array.from(container.children);
|
|
757
|
+
for (const child of children) {
|
|
758
|
+
if (container.children.length < maxDomNodes) break;
|
|
759
|
+
if (child.classList.contains("wulf-toast-hiding") || child.classList.contains("wulf-toast-hiding-fast")) {
|
|
760
|
+
child.remove();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
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
|
+
}
|
|
540
774
|
container.appendChild(toast.element);
|
|
541
775
|
list.push(toast);
|
|
776
|
+
this.announce(toast);
|
|
542
777
|
if (toast.options.onOpen) {
|
|
543
778
|
try {
|
|
544
779
|
toast.options.onOpen(toast);
|
|
@@ -548,27 +783,179 @@ var _ToastManager = class _ToastManager {
|
|
|
548
783
|
}
|
|
549
784
|
toast.startTimer();
|
|
550
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
|
+
}
|
|
551
922
|
/**
|
|
552
923
|
* Retire une notification de la pile et nettoie le conteneur s'il est vide.
|
|
553
924
|
*/
|
|
554
925
|
remove(toast, _reason) {
|
|
555
|
-
const position = toast.options.position
|
|
926
|
+
const position = normalizePosition(toast.options.position);
|
|
556
927
|
const list = this.activeToasts.get(position);
|
|
557
928
|
if (list) {
|
|
558
929
|
const index = list.indexOf(toast);
|
|
559
930
|
if (index !== -1) {
|
|
560
931
|
list.splice(index, 1);
|
|
561
932
|
}
|
|
933
|
+
this.handleFocusHandoff(toast, list);
|
|
934
|
+
if (toast.element.parentNode) {
|
|
935
|
+
toast.element.parentNode.removeChild(toast.element);
|
|
936
|
+
}
|
|
562
937
|
if (list.length === 0 && !this.pendingReplacements.has(position)) {
|
|
563
938
|
const container = this.containers.get(position);
|
|
564
939
|
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
565
|
-
|
|
566
|
-
container.parentNode.removeChild(container);
|
|
567
|
-
}
|
|
940
|
+
this.disposeContainer(container);
|
|
568
941
|
this.containers.delete(position);
|
|
569
942
|
this.activeToasts.delete(position);
|
|
570
943
|
}
|
|
571
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);
|
|
572
959
|
}
|
|
573
960
|
}
|
|
574
961
|
/**
|
|
@@ -577,6 +964,8 @@ var _ToastManager = class _ToastManager {
|
|
|
577
964
|
clearAll(position) {
|
|
578
965
|
const promises = [];
|
|
579
966
|
if (position) {
|
|
967
|
+
this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
|
|
968
|
+
this.pendingReplacements.delete(position);
|
|
580
969
|
const list = this.activeToasts.get(position);
|
|
581
970
|
if (list && list.length > 0) {
|
|
582
971
|
const copy = [...list];
|
|
@@ -586,14 +975,24 @@ var _ToastManager = class _ToastManager {
|
|
|
586
975
|
} else {
|
|
587
976
|
const container = this.containers.get(position);
|
|
588
977
|
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
589
|
-
|
|
590
|
-
container.parentNode.removeChild(container);
|
|
591
|
-
}
|
|
978
|
+
this.disposeContainer(container);
|
|
592
979
|
this.containers.delete(position);
|
|
593
980
|
this.activeToasts.delete(position);
|
|
594
981
|
}
|
|
595
982
|
}
|
|
596
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;
|
|
597
996
|
const allPositions = /* @__PURE__ */ new Set([
|
|
598
997
|
...Array.from(this.containers.keys()),
|
|
599
998
|
...Array.from(this.activeToasts.keys())
|
|
@@ -606,9 +1005,7 @@ var _ToastManager = class _ToastManager {
|
|
|
606
1005
|
if (!position) {
|
|
607
1006
|
for (const [pos, container] of Array.from(this.containers.entries())) {
|
|
608
1007
|
if (!container.firstChild || container.children.length === 0) {
|
|
609
|
-
|
|
610
|
-
container.parentNode.removeChild(container);
|
|
611
|
-
}
|
|
1008
|
+
this.disposeContainer(container);
|
|
612
1009
|
this.containers.delete(pos);
|
|
613
1010
|
this.activeToasts.delete(pos);
|
|
614
1011
|
}
|
|
@@ -616,27 +1013,58 @@ var _ToastManager = class _ToastManager {
|
|
|
616
1013
|
}
|
|
617
1014
|
});
|
|
618
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
|
+
}
|
|
619
1044
|
/**
|
|
620
1045
|
* Récupère ou crée le conteneur DOM pour une position d'affichage.
|
|
621
1046
|
*/
|
|
622
|
-
getOrCreateContainer(position) {
|
|
1047
|
+
getOrCreateContainer(position, toast, useTopLayer) {
|
|
623
1048
|
let container = this.containers.get(position);
|
|
624
1049
|
if (!container || !document.body.contains(container)) {
|
|
625
1050
|
container = document.createElement("div");
|
|
626
1051
|
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
627
|
-
container.setAttribute("
|
|
628
|
-
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
|
+
}
|
|
629
1057
|
document.body.appendChild(container);
|
|
630
1058
|
this.containers.set(position, container);
|
|
631
1059
|
}
|
|
632
1060
|
return container;
|
|
633
1061
|
}
|
|
634
1062
|
};
|
|
635
|
-
_ToastManager.instance = null;
|
|
636
|
-
var ToastManager = _ToastManager;
|
|
637
1063
|
|
|
638
1064
|
// src/toast/Toast.ts
|
|
639
1065
|
var Toast = class extends LocalizedComponent {
|
|
1066
|
+
static _i18n = toastI18n;
|
|
1067
|
+
static i18n = toastI18n;
|
|
640
1068
|
audit() {
|
|
641
1069
|
return [];
|
|
642
1070
|
}
|
|
@@ -663,16 +1091,18 @@ var Toast = class extends LocalizedComponent {
|
|
|
663
1091
|
static clearAll(position) {
|
|
664
1092
|
return ToastManager.getInstance().clearAll(position);
|
|
665
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Détruit le gestionnaire de notifications (conteneurs, annonceurs ARIA et timers).
|
|
1096
|
+
*/
|
|
1097
|
+
static destroy() {
|
|
1098
|
+
ToastManager.getInstance().destroy();
|
|
1099
|
+
}
|
|
666
1100
|
};
|
|
667
|
-
Toast._i18n = toastI18n;
|
|
668
|
-
Toast.i18n = toastI18n;
|
|
669
1101
|
|
|
670
1102
|
// src/toast/index.ts
|
|
671
1103
|
var index_default = Toast;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const wulfNamespace = win.Wulf || {};
|
|
675
|
-
win.Wulf = wulfNamespace;
|
|
1104
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
1105
|
+
if (wulfNamespace) {
|
|
676
1106
|
wulfNamespace.Toast = Object.assign(Toast, {
|
|
677
1107
|
Toast,
|
|
678
1108
|
i18n: toastI18n
|