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