wulf.js 1.9.1 → 1.9.2
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 +154 -21
- package/changelog.md +21 -0
- package/dist/focus-trap.global.js +1 -1
- package/dist/focus-trap.global.min.js +1 -1
- package/dist/index.esm.js +589 -0
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +590 -1
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +3 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.global.js +1 -1
- package/dist/mask.global.min.js +1 -1
- package/dist/masonry.global.js +1 -1
- package/dist/masonry.global.min.js +1 -1
- package/dist/scroll.global.js +1 -1
- package/dist/scroll.global.min.js +1 -1
- package/dist/shortcut.esm.js +584 -0
- package/dist/shortcut.esm.js.map +7 -0
- package/dist/shortcut.global.js +610 -0
- package/dist/shortcut.global.js.map +7 -0
- package/dist/shortcut.global.min.js +3 -0
- package/dist/shortcut.global.min.js.map +7 -0
- package/dist/toast.global.js +1 -1
- package/dist/toast.global.min.js +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +91 -0
- package/dist/types/shortcut/index.d.ts +4 -0
- package/dist/types/shortcut/types.d.ts +101 -0
- package/package.json +17 -10
- package/dist/focus-trap.cjs.js +0 -430
- package/dist/focus-trap.cjs.js.map +0 -7
- package/dist/index.cjs.js +0 -5365
- package/dist/index.cjs.js.map +0 -7
- package/dist/mask.cjs.js +0 -3086
- package/dist/mask.cjs.js.map +0 -7
- package/dist/masonry.cjs.js +0 -858
- package/dist/masonry.cjs.js.map +0 -7
- package/dist/scroll.cjs.js +0 -823
- package/dist/scroll.cjs.js.map +0 -7
- package/dist/toast.cjs.js +0 -715
- package/dist/toast.cjs.js.map +0 -7
package/dist/toast.cjs.js
DELETED
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/toast/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
LocalizedComponent: () => LocalizedComponent,
|
|
24
|
-
Toast: () => Toast,
|
|
25
|
-
ToastInstance: () => ToastInstance,
|
|
26
|
-
ToastManager: () => ToastManager,
|
|
27
|
-
createI18nManager: () => createI18nManager,
|
|
28
|
-
default: () => index_default,
|
|
29
|
-
toastEn: () => toastEn,
|
|
30
|
-
toastFr: () => toastFr,
|
|
31
|
-
toastI18n: () => toastI18n
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(index_exports);
|
|
34
|
-
|
|
35
|
-
// src/common/i18n.ts
|
|
36
|
-
function normalizeLocaleCode(locale) {
|
|
37
|
-
return locale.trim().toLowerCase().replace(/_/g, "-");
|
|
38
|
-
}
|
|
39
|
-
function getPrimaryLanguage(normalizedLocale) {
|
|
40
|
-
const dashIndex = normalizedLocale.indexOf("-");
|
|
41
|
-
return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
42
|
-
}
|
|
43
|
-
function assignDefined(target, source) {
|
|
44
|
-
if (!source) return target;
|
|
45
|
-
for (const key of Object.keys(source)) {
|
|
46
|
-
if (source[key] !== void 0) {
|
|
47
|
-
target[key] = source[key];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return target;
|
|
51
|
-
}
|
|
52
|
-
function createI18nManager(defaultLocale, locales) {
|
|
53
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
54
|
-
const initialLocales = {};
|
|
55
|
-
for (const [loc, dict] of Object.entries(locales)) {
|
|
56
|
-
initialLocales[normalizeLocaleCode(loc)] = { ...dict };
|
|
57
|
-
}
|
|
58
|
-
let currentLocale = fallbackLocale;
|
|
59
|
-
let activeLocales = { ...initialLocales };
|
|
60
|
-
let globalOverrides = {};
|
|
61
|
-
function resolveActiveDictionaries() {
|
|
62
|
-
const dicts = [];
|
|
63
|
-
const exact = activeLocales[currentLocale];
|
|
64
|
-
if (exact) dicts.push(exact);
|
|
65
|
-
const primary = getPrimaryLanguage(currentLocale);
|
|
66
|
-
if (primary && activeLocales[primary]) {
|
|
67
|
-
dicts.push(activeLocales[primary]);
|
|
68
|
-
}
|
|
69
|
-
return dicts;
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
setLocale(locale) {
|
|
73
|
-
if (locale && locale.trim()) {
|
|
74
|
-
currentLocale = normalizeLocaleCode(locale);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
getLocale() {
|
|
78
|
-
return currentLocale;
|
|
79
|
-
},
|
|
80
|
-
registerLocale(locale, translations) {
|
|
81
|
-
if (!locale || !locale.trim() || !translations) return;
|
|
82
|
-
const norm = normalizeLocaleCode(locale);
|
|
83
|
-
activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
|
|
84
|
-
},
|
|
85
|
-
setI18n(overrides) {
|
|
86
|
-
if (!overrides) return;
|
|
87
|
-
globalOverrides = assignDefined({ ...globalOverrides }, overrides);
|
|
88
|
-
},
|
|
89
|
-
t(key, instanceOverride) {
|
|
90
|
-
if (instanceOverride && instanceOverride[key] !== void 0) {
|
|
91
|
-
return String(instanceOverride[key]);
|
|
92
|
-
}
|
|
93
|
-
if (globalOverrides[key] !== void 0) {
|
|
94
|
-
return String(globalOverrides[key]);
|
|
95
|
-
}
|
|
96
|
-
for (const dict of resolveActiveDictionaries()) {
|
|
97
|
-
if (dict[key] !== void 0) {
|
|
98
|
-
return String(dict[key]);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
102
|
-
if (fallbackDict && fallbackDict[key] !== void 0) {
|
|
103
|
-
return String(fallbackDict[key]);
|
|
104
|
-
}
|
|
105
|
-
return String(key);
|
|
106
|
-
},
|
|
107
|
-
getAll(instanceOverride) {
|
|
108
|
-
const result = {};
|
|
109
|
-
const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
110
|
-
assignDefined(result, fallback);
|
|
111
|
-
const activeDicts = resolveActiveDictionaries().reverse();
|
|
112
|
-
for (const dict of activeDicts) {
|
|
113
|
-
assignDefined(result, dict);
|
|
114
|
-
}
|
|
115
|
-
assignDefined(result, globalOverrides);
|
|
116
|
-
assignDefined(result, instanceOverride);
|
|
117
|
-
return result;
|
|
118
|
-
},
|
|
119
|
-
reset() {
|
|
120
|
-
currentLocale = fallbackLocale;
|
|
121
|
-
globalOverrides = {};
|
|
122
|
-
activeLocales = {};
|
|
123
|
-
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
124
|
-
activeLocales[loc] = { ...dict };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/common/AuditableComponent.ts
|
|
131
|
-
var AuditableComponent = class {
|
|
132
|
-
/**
|
|
133
|
-
* Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
|
|
134
|
-
*/
|
|
135
|
-
getAuditDisableHint() {
|
|
136
|
-
return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
|
|
140
|
-
* si l'audit est activé et que des contraintes manquent.
|
|
141
|
-
*/
|
|
142
|
-
runAuditWarning(enabled = true) {
|
|
143
|
-
if (!enabled) return [];
|
|
144
|
-
const warnings = this.audit();
|
|
145
|
-
if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
146
|
-
console.warn(
|
|
147
|
-
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
148
|
-
` + warnings.map((w) => ` - ${w}`).join("\n") + `
|
|
149
|
-
(${this.getAuditDisableHint()})`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
return warnings;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
156
|
-
* pointe vers des éléments réellement présents dans le document.
|
|
157
|
-
*/
|
|
158
|
-
checkAriaIdReferences(element, attrName, warnings) {
|
|
159
|
-
const rawValue = element.getAttribute(attrName)?.trim();
|
|
160
|
-
if (!rawValue) return false;
|
|
161
|
-
const doc = element.ownerDocument || document;
|
|
162
|
-
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
163
|
-
const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
|
|
164
|
-
if (!isValid) {
|
|
165
|
-
warnings.push(
|
|
166
|
-
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
return isValid;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// src/common/LocalizedComponent.ts
|
|
174
|
-
var LocalizedComponent = class extends AuditableComponent {
|
|
175
|
-
/**
|
|
176
|
-
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
177
|
-
*/
|
|
178
|
-
static setLocale(locale) {
|
|
179
|
-
if (this._i18n) {
|
|
180
|
-
this._i18n.setLocale(locale);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Retourne la langue globale active du composant.
|
|
185
|
-
*/
|
|
186
|
-
static getLocale() {
|
|
187
|
-
return this._i18n ? this._i18n.getLocale() : "";
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Enregistre un dictionnaire de traduction pour une langue donnée.
|
|
191
|
-
*/
|
|
192
|
-
static registerLocale(locale, translations) {
|
|
193
|
-
if (this._i18n) {
|
|
194
|
-
this._i18n.registerLocale(locale, translations);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Surcharge les libellés globalement pour ce composant.
|
|
199
|
-
*/
|
|
200
|
-
static setI18n(overrides) {
|
|
201
|
-
if (this._i18n) {
|
|
202
|
-
this._i18n.setI18n(overrides);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Retourne l'ensemble des libellés actifs résolus du composant.
|
|
207
|
-
*/
|
|
208
|
-
static getI18n() {
|
|
209
|
-
return this._i18n ? this._i18n.getAll() : {};
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Réinitialise les réglages de langue et surcharges globales.
|
|
213
|
-
*/
|
|
214
|
-
static resetI18n() {
|
|
215
|
-
if (this._i18n) {
|
|
216
|
-
this._i18n.reset();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Résout une clé au niveau statique de la classe.
|
|
221
|
-
*/
|
|
222
|
-
static t(key, instanceOverride) {
|
|
223
|
-
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
224
|
-
}
|
|
225
|
-
constructor(i18nOverrides) {
|
|
226
|
-
super();
|
|
227
|
-
this.i18nOverrides = i18nOverrides;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
|
|
231
|
-
*/
|
|
232
|
-
t(key) {
|
|
233
|
-
const ctor = this.constructor;
|
|
234
|
-
return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// src/toast/i18n/fr.ts
|
|
239
|
-
var toastFr = {
|
|
240
|
-
closeButton: "Fermer la notification"
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// src/toast/i18n/en.ts
|
|
244
|
-
var toastEn = {
|
|
245
|
-
closeButton: "Close notification"
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// src/toast/i18n/index.ts
|
|
249
|
-
var toastI18n = createI18nManager("fr", {
|
|
250
|
-
fr: toastFr,
|
|
251
|
-
en: toastEn
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// src/toast/ToastInstance.ts
|
|
255
|
-
var nextToastId = 1;
|
|
256
|
-
var ToastInstance = class extends AuditableComponent {
|
|
257
|
-
constructor(options, onDismiss) {
|
|
258
|
-
super();
|
|
259
|
-
this._isClosed = false;
|
|
260
|
-
this.timerId = null;
|
|
261
|
-
this.remainingTime = 0;
|
|
262
|
-
this.timerStartTime = 0;
|
|
263
|
-
this.isPaused = false;
|
|
264
|
-
this.id = `wulf-toast-${nextToastId++}`;
|
|
265
|
-
this.options = Object.freeze({ ...options });
|
|
266
|
-
this.onDismissCallback = onDismiss;
|
|
267
|
-
const duration = options.duration === void 0 ? 4e3 : options.duration;
|
|
268
|
-
if (typeof duration === "number" && duration > 0) {
|
|
269
|
-
this.remainingTime = duration;
|
|
270
|
-
} else {
|
|
271
|
-
this.remainingTime = 0;
|
|
272
|
-
}
|
|
273
|
-
this.element = this.createDOM();
|
|
274
|
-
this.bindEvents();
|
|
275
|
-
this.runAuditWarning(options.audit !== false);
|
|
276
|
-
}
|
|
277
|
-
get isClosed() {
|
|
278
|
-
return this._isClosed;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
|
|
282
|
-
* et retourne la liste des contraintes manquantes.
|
|
283
|
-
*/
|
|
284
|
-
audit() {
|
|
285
|
-
const warnings = [];
|
|
286
|
-
const hasTitle = Boolean(this.options.title && this.options.title.trim().length > 0);
|
|
287
|
-
const hasMessage = Boolean(this.options.message && this.options.message.trim().length > 0);
|
|
288
|
-
if (!hasTitle && !hasMessage) {
|
|
289
|
-
warnings.push(
|
|
290
|
-
"Contenu textuel vide : d\xE9finissez au moins un title ou un message pour que le lecteur d'\xE9cran puisse annoncer la notification (WCAG 4.1.3)."
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
const duration = this.options.duration === void 0 ? 4e3 : this.options.duration;
|
|
294
|
-
if (typeof duration === "number" && duration > 0 && duration < 5e3) {
|
|
295
|
-
warnings.push(
|
|
296
|
-
`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).`
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
const closable = this.options.closable ?? true;
|
|
300
|
-
const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
|
|
301
|
-
if (isPersistent && !closable && !this.options.closeOnClick) {
|
|
302
|
-
warnings.push(
|
|
303
|
-
"Notification persistante impossible \xE0 fermer : activez closable: true ou closeOnClick: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
return warnings;
|
|
307
|
-
}
|
|
308
|
-
getAuditPrefix() {
|
|
309
|
-
return "Wulf.Toast";
|
|
310
|
-
}
|
|
311
|
-
getAuditTargetLabel() {
|
|
312
|
-
return `#${this.id}`;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
|
|
316
|
-
*/
|
|
317
|
-
createDOM() {
|
|
318
|
-
const el = document.createElement("div");
|
|
319
|
-
el.id = this.id;
|
|
320
|
-
el.className = "wulf-toast";
|
|
321
|
-
const role = this.options.role === "alert" ? "alert" : "status";
|
|
322
|
-
el.setAttribute("role", role);
|
|
323
|
-
el.setAttribute("aria-live", role === "alert" ? "assertive" : "polite");
|
|
324
|
-
el.setAttribute("aria-atomic", "true");
|
|
325
|
-
if (this.options.backgroundColor) {
|
|
326
|
-
el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor);
|
|
327
|
-
}
|
|
328
|
-
if (this.options.titleColor) {
|
|
329
|
-
el.style.setProperty("--wulf-toast-title-color", this.options.titleColor);
|
|
330
|
-
}
|
|
331
|
-
if (this.options.textColor) {
|
|
332
|
-
el.style.setProperty("--wulf-toast-text-color", this.options.textColor);
|
|
333
|
-
}
|
|
334
|
-
if (this.options.iconColor) {
|
|
335
|
-
el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor);
|
|
336
|
-
}
|
|
337
|
-
if (this.options.closeButtonColor) {
|
|
338
|
-
el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor);
|
|
339
|
-
}
|
|
340
|
-
if (this.options.icon && this.options.icon.trim() !== "") {
|
|
341
|
-
const iconContainer = document.createElement("span");
|
|
342
|
-
iconContainer.className = `wulf-toast-icon ${this.options.icon.trim()}`;
|
|
343
|
-
iconContainer.setAttribute("aria-hidden", "true");
|
|
344
|
-
el.appendChild(iconContainer);
|
|
345
|
-
}
|
|
346
|
-
const content = document.createElement("div");
|
|
347
|
-
content.className = "wulf-toast-content";
|
|
348
|
-
if (this.options.title && this.options.title.trim() !== "") {
|
|
349
|
-
const titleEl = document.createElement("div");
|
|
350
|
-
titleEl.className = "wulf-toast-title";
|
|
351
|
-
this.appendTextWithLineBreaks(titleEl, this.options.title);
|
|
352
|
-
content.appendChild(titleEl);
|
|
353
|
-
}
|
|
354
|
-
if (this.options.message && this.options.message.trim() !== "") {
|
|
355
|
-
const messageEl = document.createElement("div");
|
|
356
|
-
messageEl.className = "wulf-toast-message";
|
|
357
|
-
this.appendTextWithLineBreaks(messageEl, this.options.message);
|
|
358
|
-
content.appendChild(messageEl);
|
|
359
|
-
}
|
|
360
|
-
el.appendChild(content);
|
|
361
|
-
const closable = this.options.closable ?? true;
|
|
362
|
-
if (closable) {
|
|
363
|
-
const closeBtn = document.createElement("button");
|
|
364
|
-
closeBtn.type = "button";
|
|
365
|
-
closeBtn.className = "wulf-toast-close";
|
|
366
|
-
closeBtn.setAttribute("aria-label", toastI18n.t("closeButton", this.options.i18n));
|
|
367
|
-
closeBtn.setAttribute("tabindex", "0");
|
|
368
|
-
const closeIcon = document.createElement("span");
|
|
369
|
-
closeIcon.className = "wulf-toast-close-icon";
|
|
370
|
-
closeIcon.setAttribute("aria-hidden", "true");
|
|
371
|
-
closeIcon.textContent = "\xD7";
|
|
372
|
-
closeBtn.appendChild(closeIcon);
|
|
373
|
-
closeBtn.addEventListener("click", (e) => {
|
|
374
|
-
e.stopPropagation();
|
|
375
|
-
this.close("close-button");
|
|
376
|
-
});
|
|
377
|
-
el.appendChild(closeBtn);
|
|
378
|
-
}
|
|
379
|
-
return el;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
383
|
-
* Utilise document.createTextNode et des éléments <br> créés proprement.
|
|
384
|
-
*/
|
|
385
|
-
appendTextWithLineBreaks(container, text) {
|
|
386
|
-
const lines = text.split(/\r\n|\r|\n/);
|
|
387
|
-
lines.forEach((line, index) => {
|
|
388
|
-
if (index > 0) {
|
|
389
|
-
container.appendChild(document.createElement("br"));
|
|
390
|
-
}
|
|
391
|
-
container.appendChild(document.createTextNode(line));
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Liaison des événements clavier, souris, et pause au survol / focus (WCAG 2.2)
|
|
396
|
-
*/
|
|
397
|
-
bindEvents() {
|
|
398
|
-
this.element.addEventListener("click", (e) => {
|
|
399
|
-
if (this.options.onClick) {
|
|
400
|
-
this.options.onClick(this, e);
|
|
401
|
-
}
|
|
402
|
-
if (this.options.closeOnClick) {
|
|
403
|
-
this.close("toast-click");
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
this.element.addEventListener("mouseenter", () => this.pauseTimer());
|
|
407
|
-
this.element.addEventListener("mouseleave", () => this.resumeTimer());
|
|
408
|
-
this.element.addEventListener("focusin", () => this.pauseTimer());
|
|
409
|
-
this.element.addEventListener("focusout", () => this.resumeTimer());
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Démarrage du compte à rebours de disparition automatique
|
|
413
|
-
*/
|
|
414
|
-
startTimer() {
|
|
415
|
-
if (this._isClosed || this.remainingTime <= 0) return;
|
|
416
|
-
this.timerStartTime = Date.now();
|
|
417
|
-
this.timerId = window.setTimeout(() => {
|
|
418
|
-
this.close("timeout");
|
|
419
|
-
}, this.remainingTime);
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Met en pause le compte à rebours (au survol ou prise de focus)
|
|
423
|
-
*/
|
|
424
|
-
pauseTimer() {
|
|
425
|
-
if (this._isClosed || this.remainingTime <= 0 || this.isPaused) return;
|
|
426
|
-
if (this.timerId !== null) {
|
|
427
|
-
window.clearTimeout(this.timerId);
|
|
428
|
-
this.timerId = null;
|
|
429
|
-
}
|
|
430
|
-
const elapsed = Date.now() - this.timerStartTime;
|
|
431
|
-
this.remainingTime = Math.max(0, this.remainingTime - elapsed);
|
|
432
|
-
this.isPaused = true;
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Reprend le compte à rebours
|
|
436
|
-
*/
|
|
437
|
-
resumeTimer() {
|
|
438
|
-
if (this._isClosed || this.remainingTime <= 0 || !this.isPaused) return;
|
|
439
|
-
this.isPaused = false;
|
|
440
|
-
this.startTimer();
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Déclenche la destruction immédiate sans animation (utile pour purger lors d'une rafale)
|
|
444
|
-
*/
|
|
445
|
-
destroyImmediate(reason = "replace") {
|
|
446
|
-
if (this._isClosed) return;
|
|
447
|
-
this._isClosed = true;
|
|
448
|
-
if (this.timerId !== null) {
|
|
449
|
-
window.clearTimeout(this.timerId);
|
|
450
|
-
this.timerId = null;
|
|
451
|
-
}
|
|
452
|
-
if (this.element.parentNode) {
|
|
453
|
-
this.element.parentNode.removeChild(this.element);
|
|
454
|
-
}
|
|
455
|
-
if (this.onDismissCallback) {
|
|
456
|
-
this.onDismissCallback(this, reason);
|
|
457
|
-
}
|
|
458
|
-
if (this.options.onClose) {
|
|
459
|
-
this.options.onClose(this, reason);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Déclenche la fermeture propre et l'animation de sortie du toast.
|
|
464
|
-
* Si fast = true, utilise une disparition accélérée (90ms) pour le remplacement séquentiel.
|
|
465
|
-
*/
|
|
466
|
-
close(reason = "programmatic", fast = false) {
|
|
467
|
-
if (this._isClosed) return Promise.resolve();
|
|
468
|
-
this._isClosed = true;
|
|
469
|
-
if (this.timerId !== null) {
|
|
470
|
-
window.clearTimeout(this.timerId);
|
|
471
|
-
this.timerId = null;
|
|
472
|
-
}
|
|
473
|
-
return new Promise((resolve) => {
|
|
474
|
-
this.element.classList.add(fast ? "wulf-toast-hiding-fast" : "wulf-toast-hiding");
|
|
475
|
-
const handleAnimationEnd = () => {
|
|
476
|
-
if (this.element.parentNode) {
|
|
477
|
-
this.element.parentNode.removeChild(this.element);
|
|
478
|
-
}
|
|
479
|
-
if (this.onDismissCallback) {
|
|
480
|
-
this.onDismissCallback(this, reason);
|
|
481
|
-
}
|
|
482
|
-
if (this.options.onClose) {
|
|
483
|
-
this.options.onClose(this, reason);
|
|
484
|
-
}
|
|
485
|
-
resolve();
|
|
486
|
-
};
|
|
487
|
-
const isReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
488
|
-
if (isReducedMotion) {
|
|
489
|
-
handleAnimationEnd();
|
|
490
|
-
} else if (fast) {
|
|
491
|
-
window.setTimeout(handleAnimationEnd, 90);
|
|
492
|
-
} else {
|
|
493
|
-
let transitioned = false;
|
|
494
|
-
let fallbackTimerId = null;
|
|
495
|
-
const onEnd = () => {
|
|
496
|
-
if (!transitioned) {
|
|
497
|
-
transitioned = true;
|
|
498
|
-
if (fallbackTimerId !== null) {
|
|
499
|
-
window.clearTimeout(fallbackTimerId);
|
|
500
|
-
fallbackTimerId = null;
|
|
501
|
-
}
|
|
502
|
-
this.element.removeEventListener("animationend", onEnd);
|
|
503
|
-
this.element.removeEventListener("transitionend", onEnd);
|
|
504
|
-
handleAnimationEnd();
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
this.element.addEventListener("animationend", onEnd, { once: true });
|
|
508
|
-
this.element.addEventListener("transitionend", onEnd, { once: true });
|
|
509
|
-
fallbackTimerId = window.setTimeout(onEnd, 300);
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
// src/toast/ToastManager.ts
|
|
516
|
-
var _ToastManager = class _ToastManager {
|
|
517
|
-
constructor() {
|
|
518
|
-
this.containers = /* @__PURE__ */ new Map();
|
|
519
|
-
this.activeToasts = /* @__PURE__ */ new Map();
|
|
520
|
-
this.replaceTokens = /* @__PURE__ */ new Map();
|
|
521
|
-
this.pendingReplacements = /* @__PURE__ */ new Set();
|
|
522
|
-
}
|
|
523
|
-
static getInstance() {
|
|
524
|
-
if (!_ToastManager.instance) {
|
|
525
|
-
_ToastManager.instance = new _ToastManager();
|
|
526
|
-
}
|
|
527
|
-
return _ToastManager.instance;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Ajoute et affiche une notification Toast.
|
|
531
|
-
*/
|
|
532
|
-
add(toast) {
|
|
533
|
-
const position = toast.options.position || "top-right";
|
|
534
|
-
let list = this.activeToasts.get(position);
|
|
535
|
-
if (!list) {
|
|
536
|
-
list = [];
|
|
537
|
-
this.activeToasts.set(position, list);
|
|
538
|
-
}
|
|
539
|
-
if (toast.options.replace && list.length > 0) {
|
|
540
|
-
const existing = [...list];
|
|
541
|
-
const token = (this.replaceTokens.get(position) || 0) + 1;
|
|
542
|
-
this.replaceTokens.set(position, token);
|
|
543
|
-
this.pendingReplacements.add(position);
|
|
544
|
-
const promises = existing.map((t) => t.close("replace", true));
|
|
545
|
-
Promise.all(promises).then(() => {
|
|
546
|
-
this.pendingReplacements.delete(position);
|
|
547
|
-
if (this.replaceTokens.get(position) !== token) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
this.mountToast(toast, position);
|
|
551
|
-
});
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
const maxToasts = typeof toast.options.maxToasts === "number" && toast.options.maxToasts > 0 ? toast.options.maxToasts : 5;
|
|
555
|
-
if (list.length >= maxToasts) {
|
|
556
|
-
const countToRemove = list.length - maxToasts + 1;
|
|
557
|
-
const oldestItems = list.splice(0, countToRemove);
|
|
558
|
-
for (const item of oldestItems) {
|
|
559
|
-
item.close("max-limit", true);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
this.mountToast(toast, position);
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Insère l'élément toast dans le DOM et déclenche les callbacks et compteurs.
|
|
566
|
-
*/
|
|
567
|
-
mountToast(toast, position) {
|
|
568
|
-
const container = this.getOrCreateContainer(position);
|
|
569
|
-
let list = this.activeToasts.get(position);
|
|
570
|
-
if (!list) {
|
|
571
|
-
list = [];
|
|
572
|
-
this.activeToasts.set(position, list);
|
|
573
|
-
}
|
|
574
|
-
container.appendChild(toast.element);
|
|
575
|
-
list.push(toast);
|
|
576
|
-
if (toast.options.onOpen) {
|
|
577
|
-
try {
|
|
578
|
-
toast.options.onOpen(toast);
|
|
579
|
-
} catch (err) {
|
|
580
|
-
console.error("[Wulf.Toast] Erreur dans le callback onOpen:", err);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
toast.startTimer();
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Retire une notification de la pile et nettoie le conteneur s'il est vide.
|
|
587
|
-
*/
|
|
588
|
-
remove(toast, _reason) {
|
|
589
|
-
const position = toast.options.position || "top-right";
|
|
590
|
-
const list = this.activeToasts.get(position);
|
|
591
|
-
if (list) {
|
|
592
|
-
const index = list.indexOf(toast);
|
|
593
|
-
if (index !== -1) {
|
|
594
|
-
list.splice(index, 1);
|
|
595
|
-
}
|
|
596
|
-
if (list.length === 0 && !this.pendingReplacements.has(position)) {
|
|
597
|
-
const container = this.containers.get(position);
|
|
598
|
-
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
599
|
-
if (container.parentNode) {
|
|
600
|
-
container.parentNode.removeChild(container);
|
|
601
|
-
}
|
|
602
|
-
this.containers.delete(position);
|
|
603
|
-
this.activeToasts.delete(position);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Ferme l'ensemble des toasts actifs (sur une position ou partout) et attend leur retrait complet.
|
|
610
|
-
*/
|
|
611
|
-
clearAll(position) {
|
|
612
|
-
const promises = [];
|
|
613
|
-
if (position) {
|
|
614
|
-
const list = this.activeToasts.get(position);
|
|
615
|
-
if (list && list.length > 0) {
|
|
616
|
-
const copy = [...list];
|
|
617
|
-
for (const t of copy) {
|
|
618
|
-
promises.push(t.close("programmatic"));
|
|
619
|
-
}
|
|
620
|
-
} else {
|
|
621
|
-
const container = this.containers.get(position);
|
|
622
|
-
if (container && (!container.firstChild || container.children.length === 0)) {
|
|
623
|
-
if (container.parentNode) {
|
|
624
|
-
container.parentNode.removeChild(container);
|
|
625
|
-
}
|
|
626
|
-
this.containers.delete(position);
|
|
627
|
-
this.activeToasts.delete(position);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
} else {
|
|
631
|
-
const allPositions = /* @__PURE__ */ new Set([
|
|
632
|
-
...Array.from(this.containers.keys()),
|
|
633
|
-
...Array.from(this.activeToasts.keys())
|
|
634
|
-
]);
|
|
635
|
-
for (const pos of allPositions) {
|
|
636
|
-
promises.push(this.clearAll(pos));
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
return Promise.all(promises).then(() => {
|
|
640
|
-
if (!position) {
|
|
641
|
-
for (const [pos, container] of Array.from(this.containers.entries())) {
|
|
642
|
-
if (!container.firstChild || container.children.length === 0) {
|
|
643
|
-
if (container.parentNode) {
|
|
644
|
-
container.parentNode.removeChild(container);
|
|
645
|
-
}
|
|
646
|
-
this.containers.delete(pos);
|
|
647
|
-
this.activeToasts.delete(pos);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Récupère ou crée le conteneur DOM pour une position d'affichage.
|
|
655
|
-
*/
|
|
656
|
-
getOrCreateContainer(position) {
|
|
657
|
-
let container = this.containers.get(position);
|
|
658
|
-
if (!container || !document.body.contains(container)) {
|
|
659
|
-
container = document.createElement("div");
|
|
660
|
-
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
661
|
-
container.setAttribute("aria-live", "polite");
|
|
662
|
-
container.setAttribute("aria-relevant", "additions removals");
|
|
663
|
-
document.body.appendChild(container);
|
|
664
|
-
this.containers.set(position, container);
|
|
665
|
-
}
|
|
666
|
-
return container;
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
_ToastManager.instance = null;
|
|
670
|
-
var ToastManager = _ToastManager;
|
|
671
|
-
|
|
672
|
-
// src/toast/Toast.ts
|
|
673
|
-
var Toast = class extends LocalizedComponent {
|
|
674
|
-
audit() {
|
|
675
|
-
return [];
|
|
676
|
-
}
|
|
677
|
-
getAuditPrefix() {
|
|
678
|
-
return "Wulf.Toast";
|
|
679
|
-
}
|
|
680
|
-
getAuditTargetLabel() {
|
|
681
|
-
return "Toast";
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Affiche une nouvelle notification Toast avec les options spécifiées.
|
|
685
|
-
*/
|
|
686
|
-
static show(options = {}) {
|
|
687
|
-
const manager = ToastManager.getInstance();
|
|
688
|
-
const instance = new ToastInstance(options, (t, reason) => {
|
|
689
|
-
manager.remove(t, reason);
|
|
690
|
-
});
|
|
691
|
-
manager.add(instance);
|
|
692
|
-
return instance;
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Ferme immédiatement l'ensemble des toasts actifs (globalement ou par position) et attend leur retrait complet.
|
|
696
|
-
*/
|
|
697
|
-
static clearAll(position) {
|
|
698
|
-
return ToastManager.getInstance().clearAll(position);
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
Toast._i18n = toastI18n;
|
|
702
|
-
Toast.i18n = toastI18n;
|
|
703
|
-
|
|
704
|
-
// src/toast/index.ts
|
|
705
|
-
var index_default = Toast;
|
|
706
|
-
if (typeof window !== "undefined") {
|
|
707
|
-
const win = window;
|
|
708
|
-
const wulfNamespace = win.Wulf || {};
|
|
709
|
-
win.Wulf = wulfNamespace;
|
|
710
|
-
wulfNamespace.Toast = Object.assign(Toast, {
|
|
711
|
-
Toast,
|
|
712
|
-
i18n: toastI18n
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
//# sourceMappingURL=toast.cjs.js.map
|