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