wulf.js 1.9.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -78
- package/changelog.md +105 -0
- package/dist/focus-trap.esm.js +245 -126
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +247 -128
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +2434 -905
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2436 -907
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +4 -4
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.css +1 -1
- package/dist/mask.css.map +2 -2
- package/dist/mask.esm.js +746 -346
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +748 -348
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +4 -4
- package/dist/mask.global.min.js.map +4 -4
- package/dist/mask.layered.css +1 -0
- package/dist/mask.layered.css.map +7 -0
- package/dist/masonry.css +1 -1
- package/dist/masonry.css.map +2 -2
- package/dist/masonry.esm.js +341 -114
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +343 -116
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/masonry.layered.css +1 -0
- package/dist/masonry.layered.css.map +7 -0
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +524 -153
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +526 -155
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +4 -4
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -0
- package/dist/scroll.layered.css.map +7 -0
- package/dist/shortcut.esm.js +209 -46
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +211 -48
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +2 -2
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +590 -160
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +592 -162
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -4
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -0
- package/dist/toast.layered.css.map +7 -0
- package/dist/types/common/dom.d.ts +38 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +15 -5
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/AmountEngine.d.ts +1 -0
- package/dist/types/mask/BaseInputMask.d.ts +24 -0
- package/dist/types/mask/InputAmountMask.d.ts +3 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- package/dist/types/mask/InputMask.d.ts +1 -0
- package/dist/types/mask/MaskEngine.d.ts +4 -0
- package/dist/types/masonry/Masonry.d.ts +10 -3
- package/dist/types/scroll/ScrollBlock.d.ts +31 -3
- package/dist/types/scroll/types.d.ts +13 -1
- package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +5 -0
- package/dist/types/toast/Toast.d.ts +4 -0
- package/dist/types/toast/ToastInstance.d.ts +22 -10
- package/dist/types/toast/ToastManager.d.ts +37 -4
- package/dist/types/toast/i18n/types.d.ts +2 -0
- package/dist/types/toast/types.d.ts +14 -2
- package/package.json +20 -5
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
// src/common/dom.ts
|
|
2
|
+
function getSafeWulfNamespace() {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const win = window;
|
|
5
|
+
const existing = win.Wulf;
|
|
6
|
+
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
7
|
+
const fresh = {};
|
|
8
|
+
win.Wulf = fresh;
|
|
9
|
+
return fresh;
|
|
10
|
+
}
|
|
11
|
+
return existing;
|
|
12
|
+
}
|
|
13
|
+
function safeCssEscape(value) {
|
|
14
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
15
|
+
return CSS.escape(value);
|
|
16
|
+
}
|
|
17
|
+
return String(value).replace(/["\\\u0000-\u001F\u007F]/g, "\\$&");
|
|
18
|
+
}
|
|
19
|
+
function getDeepActiveElement(root) {
|
|
20
|
+
if (typeof document === "undefined") return null;
|
|
21
|
+
let active = (root ?? document).activeElement;
|
|
22
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
23
|
+
active = active.shadowRoot.activeElement;
|
|
24
|
+
}
|
|
25
|
+
return active && typeof active.focus === "function" ? active : null;
|
|
26
|
+
}
|
|
27
|
+
function isImeComposing(event) {
|
|
28
|
+
return Boolean(
|
|
29
|
+
event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
1
33
|
// src/common/AuditableComponent.ts
|
|
2
34
|
var AuditableComponent = class {
|
|
3
35
|
/**
|
|
@@ -30,8 +62,11 @@ var AuditableComponent = class {
|
|
|
30
62
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
31
63
|
if (!rawValue) return false;
|
|
32
64
|
const doc = element.ownerDocument || document;
|
|
65
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
33
66
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
34
|
-
const isValid = ids.length > 0 && ids.every(
|
|
67
|
+
const isValid = ids.length > 0 && ids.every(
|
|
68
|
+
(id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
|
|
69
|
+
);
|
|
35
70
|
if (!isValid) {
|
|
36
71
|
warnings.push(
|
|
37
72
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -45,39 +80,57 @@ var AuditableComponent = class {
|
|
|
45
80
|
var FOCUSABLE_SELECTOR = [
|
|
46
81
|
"a[href]",
|
|
47
82
|
"area[href]",
|
|
48
|
-
|
|
83
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
49
84
|
"select:not([disabled])",
|
|
50
85
|
"textarea:not([disabled])",
|
|
51
86
|
"button:not([disabled])",
|
|
87
|
+
"audio[controls]",
|
|
88
|
+
"video[controls]",
|
|
89
|
+
"details > summary:first-of-type",
|
|
52
90
|
"iframe",
|
|
53
91
|
"object",
|
|
54
92
|
"embed",
|
|
55
|
-
'[contenteditable="
|
|
93
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
56
94
|
'[tabindex]:not([tabindex="-1"])'
|
|
57
95
|
].join(",");
|
|
96
|
+
function safeQuerySelector(root, selector) {
|
|
97
|
+
if (!selector || typeof selector !== "string") return null;
|
|
98
|
+
try {
|
|
99
|
+
return root.querySelector(selector);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
58
104
|
var trapStack = [];
|
|
59
105
|
var FocusTrap = class extends AuditableComponent {
|
|
106
|
+
element;
|
|
107
|
+
options;
|
|
108
|
+
active = false;
|
|
109
|
+
paused = false;
|
|
110
|
+
previousActiveElement = null;
|
|
111
|
+
inertSiblings = [];
|
|
112
|
+
addedContainerTabIndex = false;
|
|
113
|
+
lastOutsidePointerDownTime = 0;
|
|
114
|
+
abortController;
|
|
115
|
+
// Handlers liés
|
|
116
|
+
handleKeyDownBound;
|
|
117
|
+
handleClickOutsideBound;
|
|
118
|
+
handleFocusInBound;
|
|
60
119
|
constructor(target, options = {}) {
|
|
61
120
|
super();
|
|
62
|
-
|
|
63
|
-
this.paused = false;
|
|
64
|
-
this.previousActiveElement = null;
|
|
65
|
-
this.inertSiblings = [];
|
|
66
|
-
// Sentinelles anti-fuite de focus
|
|
67
|
-
this.startSentinel = null;
|
|
68
|
-
this.endSentinel = null;
|
|
69
|
-
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
121
|
+
const el = typeof target === "string" ? safeQuerySelector(document, target) : target;
|
|
70
122
|
if (!el || !(el instanceof HTMLElement)) {
|
|
71
123
|
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
72
124
|
}
|
|
73
125
|
this.element = el;
|
|
126
|
+
const allowOutsideClick = options.allowOutsideClick ?? false;
|
|
74
127
|
this.options = {
|
|
75
128
|
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
76
129
|
returnFocus: options.returnFocus ?? true,
|
|
77
130
|
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
78
131
|
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
79
|
-
allowOutsideClick
|
|
80
|
-
setInert: options.setInert ??
|
|
132
|
+
allowOutsideClick,
|
|
133
|
+
setInert: options.setInert ?? !allowOutsideClick,
|
|
81
134
|
onActivate: options.onActivate ?? (() => {
|
|
82
135
|
}),
|
|
83
136
|
onDeactivate: options.onDeactivate ?? (() => {
|
|
@@ -89,25 +142,57 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
89
142
|
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
90
143
|
this.runAuditWarning(this.options.audit);
|
|
91
144
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
isNativeDialogElement() {
|
|
146
|
+
return this.element.tagName.toLowerCase() === "dialog";
|
|
147
|
+
}
|
|
148
|
+
isNativeModalDialog() {
|
|
149
|
+
if (!this.isNativeDialogElement()) return false;
|
|
150
|
+
try {
|
|
151
|
+
return this.element.matches(":modal");
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
isElementFocusableBase(el) {
|
|
96
157
|
if (!el || !el.isConnected) return false;
|
|
158
|
+
if (el.tabIndex < 0) return false;
|
|
97
159
|
if (el.disabled) return false;
|
|
98
|
-
|
|
160
|
+
try {
|
|
161
|
+
if (el.matches(":disabled")) return false;
|
|
162
|
+
} catch {
|
|
163
|
+
if (el.closest("fieldset[disabled]")) return false;
|
|
164
|
+
}
|
|
99
165
|
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
100
166
|
if (el.hidden || el.closest("[hidden]")) return false;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
167
|
+
const elWithCheck = el;
|
|
168
|
+
if (typeof elWithCheck.checkVisibility === "function") {
|
|
169
|
+
if (!elWithCheck.checkVisibility({
|
|
170
|
+
checkOpacity: false,
|
|
171
|
+
checkVisibilityCSS: true,
|
|
172
|
+
visibilityProperty: true
|
|
173
|
+
})) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
if (el.style.display === "none" || el.style.visibility === "hidden") return false;
|
|
178
|
+
const style = window.getComputedStyle(el);
|
|
179
|
+
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
180
|
+
if (el.offsetWidth === 0 && el.offsetHeight === 0 && style.position !== "fixed") {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
106
183
|
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Vérifie si un élément est réellement focusable, visible et actif dans le DOM.
|
|
188
|
+
*/
|
|
189
|
+
isFocusable(el) {
|
|
190
|
+
if (!this.isElementFocusableBase(el)) return false;
|
|
107
191
|
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
108
192
|
const group = Array.from(
|
|
109
|
-
this.element.querySelectorAll(`input[type="radio"][name="${
|
|
110
|
-
);
|
|
193
|
+
this.element.querySelectorAll(`input[type="radio"][name="${safeCssEscape(el.name)}"]`)
|
|
194
|
+
).filter((r) => r.form === el.form && this.isElementFocusableBase(r));
|
|
195
|
+
if (group.length === 0) return false;
|
|
111
196
|
const checked = group.find((r) => r.checked);
|
|
112
197
|
if (checked) {
|
|
113
198
|
return el === checked;
|
|
@@ -135,16 +220,21 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
135
220
|
this.active = true;
|
|
136
221
|
this.paused = false;
|
|
137
222
|
trapStack.push(this);
|
|
138
|
-
|
|
139
|
-
this.
|
|
140
|
-
if (this.options.setInert) {
|
|
223
|
+
const deepActive = getDeepActiveElement(document);
|
|
224
|
+
this.previousActiveElement = deepActive instanceof HTMLElement ? deepActive : document.activeElement;
|
|
225
|
+
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
141
226
|
this.applyInert();
|
|
142
227
|
}
|
|
143
|
-
|
|
144
|
-
|
|
228
|
+
this.abortController?.abort();
|
|
229
|
+
this.abortController = new AbortController();
|
|
230
|
+
const { signal } = this.abortController;
|
|
231
|
+
document.addEventListener("keydown", this.handleKeyDownBound, { capture: true, signal });
|
|
232
|
+
document.addEventListener("focusin", this.handleFocusInBound, { capture: true, signal });
|
|
233
|
+
document.addEventListener("pointerdown", this.handleClickOutsideBound, { capture: true, signal });
|
|
145
234
|
if (!this.options.allowOutsideClick) {
|
|
146
|
-
document.addEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
147
|
-
document.addEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
235
|
+
document.addEventListener("mousedown", this.handleClickOutsideBound, { capture: true, signal });
|
|
236
|
+
document.addEventListener("touchstart", this.handleClickOutsideBound, { capture: true, signal });
|
|
237
|
+
document.addEventListener("click", this.handleClickOutsideBound, { capture: true, signal });
|
|
148
238
|
}
|
|
149
239
|
this.applyInitialFocus();
|
|
150
240
|
this.runAuditWarning(this.options.audit);
|
|
@@ -162,33 +252,42 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
162
252
|
if (index !== -1) {
|
|
163
253
|
trapStack.splice(index, 1);
|
|
164
254
|
}
|
|
255
|
+
this.abortController?.abort();
|
|
256
|
+
this.abortController = void 0;
|
|
257
|
+
this.removeInert();
|
|
258
|
+
if (this.addedContainerTabIndex) {
|
|
259
|
+
this.element.removeAttribute("tabindex");
|
|
260
|
+
this.addedContainerTabIndex = false;
|
|
261
|
+
}
|
|
165
262
|
const nextTop = trapStack[trapStack.length - 1];
|
|
166
263
|
if (nextTop) {
|
|
167
264
|
nextTop.unpause();
|
|
168
265
|
}
|
|
169
|
-
document.removeEventListener("keydown", this.handleKeyDownBound, true);
|
|
170
|
-
document.removeEventListener("focusin", this.handleFocusInBound, true);
|
|
171
|
-
document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
172
|
-
document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
173
|
-
this.removeSentinels();
|
|
174
|
-
this.removeInert();
|
|
175
266
|
if (this.options.returnFocus) {
|
|
176
267
|
this.restoreFocus();
|
|
177
268
|
}
|
|
269
|
+
this.previousActiveElement = null;
|
|
178
270
|
this.options.onDeactivate();
|
|
179
271
|
return this;
|
|
180
272
|
}
|
|
181
273
|
/**
|
|
182
274
|
* Met en pause le trap (utilisé quand un trap fils s'ouvre au-dessus).
|
|
275
|
+
* Retire temporairement `inert` pour ne pas bloquer une modale sœur ou enfant.
|
|
183
276
|
*/
|
|
184
277
|
pause() {
|
|
185
278
|
this.paused = true;
|
|
279
|
+
this.removeInert();
|
|
186
280
|
}
|
|
187
281
|
/**
|
|
188
|
-
* Sort de pause.
|
|
282
|
+
* Sort de pause et réapplique l'isolation `inert` si active et si ce trap est bien au sommet de la pile.
|
|
189
283
|
*/
|
|
190
284
|
unpause() {
|
|
285
|
+
if (!this.active) return;
|
|
286
|
+
if (trapStack[trapStack.length - 1] !== this) return;
|
|
191
287
|
this.paused = false;
|
|
288
|
+
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
289
|
+
this.applyInert();
|
|
290
|
+
}
|
|
192
291
|
}
|
|
193
292
|
/**
|
|
194
293
|
* Indique si le trap est actuellement actif et non en pause.
|
|
@@ -203,17 +302,35 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
203
302
|
audit() {
|
|
204
303
|
const warnings = [];
|
|
205
304
|
const role = this.element.getAttribute("role");
|
|
206
|
-
const isNativeDialog = this.
|
|
305
|
+
const isNativeDialog = this.isNativeDialogElement();
|
|
207
306
|
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
307
|
+
if (isNativeDialog) {
|
|
308
|
+
if (role === "dialog") {
|
|
309
|
+
warnings.push(
|
|
310
|
+
'Attribut redondant : role="dialog" est d\xE9j\xE0 implicite sur une balise native <dialog>.'
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
if (this.element.hasAttribute("aria-modal")) {
|
|
314
|
+
warnings.push(
|
|
315
|
+
'Attribut redondant : <dialog> ouvert via showModal() g\xE8re nativement la modalit\xE9 sans n\xE9cessiter aria-modal="true".'
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (this.element.hasAttribute("open") && !this.isNativeModalDialog()) {
|
|
319
|
+
warnings.push(
|
|
320
|
+
"Dialogue non modal d\xE9tect\xE9 : pr\xE9f\xE9rez dialog.showModal() plut\xF4t que l'attribut open pour obtenir la Top Layer et l'inertie natives."
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if (!role || !validRoles.includes(role)) {
|
|
325
|
+
warnings.push(
|
|
326
|
+
'R\xF4le s\xE9mantique manquant ou inadapt\xE9 : d\xE9finissez role="dialog" (ou "alertdialog", "menu", "listbox") sur le conteneur.'
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
if ((role === "dialog" || role === "alertdialog") && this.element.getAttribute("aria-modal") !== "true") {
|
|
330
|
+
warnings.push(
|
|
331
|
+
'Isolation modale manquante : d\xE9finissez aria-modal="true" sur le conteneur de dialogue (WCAG 4.1.2).'
|
|
332
|
+
);
|
|
333
|
+
}
|
|
217
334
|
}
|
|
218
335
|
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
219
336
|
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
|
|
@@ -237,11 +354,40 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
237
354
|
this.deactivate();
|
|
238
355
|
}
|
|
239
356
|
// --- Implémentation interne ---
|
|
357
|
+
isEventInside(e, target) {
|
|
358
|
+
if (target && this.element.contains(target)) {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
if (typeof e.composedPath === "function") {
|
|
362
|
+
const path = e.composedPath();
|
|
363
|
+
if (path.includes(this.element)) {
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
isInsideToastContainer(target) {
|
|
370
|
+
if (!target || !(target instanceof Element)) return false;
|
|
371
|
+
return Boolean(target.closest(".wulf-toast-container"));
|
|
372
|
+
}
|
|
373
|
+
ensureContainerTabIndex() {
|
|
374
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
375
|
+
this.element.setAttribute("tabindex", "-1");
|
|
376
|
+
this.addedContainerTabIndex = true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
240
379
|
handleKeyDown(e) {
|
|
241
380
|
if (!this.isActive()) return;
|
|
381
|
+
if (this.element.isConnected === false) {
|
|
382
|
+
this.deactivate();
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
242
385
|
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
243
|
-
e
|
|
244
|
-
|
|
386
|
+
if (isImeComposing(e)) return;
|
|
387
|
+
if (!this.isNativeModalDialog()) {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
e.stopPropagation();
|
|
390
|
+
}
|
|
245
391
|
this.deactivate();
|
|
246
392
|
return;
|
|
247
393
|
}
|
|
@@ -249,106 +395,83 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
249
395
|
const focusables = this.getFocusableElements();
|
|
250
396
|
if (focusables.length === 0) {
|
|
251
397
|
e.preventDefault();
|
|
252
|
-
|
|
253
|
-
this.element.setAttribute("tabindex", "-1");
|
|
254
|
-
}
|
|
398
|
+
this.ensureContainerTabIndex();
|
|
255
399
|
this.element.focus();
|
|
256
400
|
return;
|
|
257
401
|
}
|
|
258
402
|
const first = focusables[0];
|
|
259
403
|
const last = focusables[focusables.length - 1];
|
|
260
|
-
const
|
|
261
|
-
|
|
404
|
+
const deepCurrent = getDeepActiveElement(document);
|
|
405
|
+
const current = deepCurrent instanceof HTMLElement ? deepCurrent : document.activeElement;
|
|
406
|
+
const isInside = current ? this.element.contains(current) || this.isEventInside(e, current) : false;
|
|
407
|
+
if (!e.shiftKey && (current === last || !isInside)) {
|
|
262
408
|
e.preventDefault();
|
|
263
409
|
first.focus();
|
|
264
|
-
} else if (e.shiftKey && (current === first ||
|
|
410
|
+
} else if (e.shiftKey && (current === first || current === this.element || !isInside)) {
|
|
265
411
|
e.preventDefault();
|
|
266
412
|
last.focus();
|
|
267
413
|
}
|
|
268
414
|
}
|
|
269
415
|
handleFocusIn(e) {
|
|
270
416
|
if (!this.isActive()) return;
|
|
417
|
+
if (this.element.isConnected === false) {
|
|
418
|
+
this.deactivate();
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
271
421
|
const target = e.target;
|
|
272
422
|
if (!target) return;
|
|
273
|
-
if (
|
|
274
|
-
const focusables = this.getFocusableElements();
|
|
275
|
-
if (focusables.length > 0) {
|
|
276
|
-
focusables[focusables.length - 1].focus();
|
|
277
|
-
} else {
|
|
278
|
-
this.element.focus();
|
|
279
|
-
}
|
|
423
|
+
if (this.isInsideToastContainer(target)) {
|
|
280
424
|
return;
|
|
281
425
|
}
|
|
282
|
-
if (
|
|
283
|
-
const focusables = this.getFocusableElements();
|
|
284
|
-
if (focusables.length > 0) {
|
|
285
|
-
focusables[0].focus();
|
|
286
|
-
} else {
|
|
287
|
-
this.element.focus();
|
|
288
|
-
}
|
|
426
|
+
if (this.options.allowOutsideClick && performance.now() - this.lastOutsidePointerDownTime < 150) {
|
|
289
427
|
return;
|
|
290
428
|
}
|
|
291
|
-
if (!this.
|
|
429
|
+
if (!this.isEventInside(e, target)) {
|
|
292
430
|
const focusables = this.getFocusableElements();
|
|
293
431
|
if (focusables.length > 0) {
|
|
294
432
|
focusables[0].focus();
|
|
295
433
|
} else {
|
|
296
|
-
|
|
297
|
-
this.element.setAttribute("tabindex", "-1");
|
|
298
|
-
}
|
|
434
|
+
this.ensureContainerTabIndex();
|
|
299
435
|
this.element.focus();
|
|
300
436
|
}
|
|
301
437
|
}
|
|
302
438
|
}
|
|
303
439
|
handleClickOutside(e) {
|
|
304
440
|
if (!this.isActive()) return;
|
|
441
|
+
if (this.element.isConnected === false) {
|
|
442
|
+
this.deactivate();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
305
445
|
const target = e.target;
|
|
306
|
-
if (target && !this.
|
|
446
|
+
if (target && !this.isEventInside(e, target)) {
|
|
447
|
+
if (this.isInsideToastContainer(target)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (this.options.allowOutsideClick) {
|
|
451
|
+
this.lastOutsidePointerDownTime = performance.now();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
307
454
|
e.preventDefault();
|
|
308
455
|
e.stopPropagation();
|
|
309
456
|
}
|
|
310
457
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.startSentinel.setAttribute("aria-hidden", "true");
|
|
316
|
-
this.startSentinel.className = "wulf-sentinel-start";
|
|
317
|
-
this.startSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
318
|
-
}
|
|
319
|
-
if (!this.endSentinel) {
|
|
320
|
-
this.endSentinel = document.createElement("span");
|
|
321
|
-
this.endSentinel.setAttribute("tabindex", "0");
|
|
322
|
-
this.endSentinel.setAttribute("aria-hidden", "true");
|
|
323
|
-
this.endSentinel.className = "wulf-sentinel-end";
|
|
324
|
-
this.endSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
325
|
-
}
|
|
326
|
-
if (this.element.parentNode) {
|
|
327
|
-
this.element.parentNode.insertBefore(this.startSentinel, this.element);
|
|
328
|
-
this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
removeSentinels() {
|
|
332
|
-
this.startSentinel?.remove();
|
|
333
|
-
this.endSentinel?.remove();
|
|
334
|
-
this.startSentinel = null;
|
|
335
|
-
this.endSentinel = null;
|
|
336
|
-
}
|
|
458
|
+
/**
|
|
459
|
+
* Applique `inert` sur les éléments frères à chaque niveau hiérarchique jusqu'à <body>,
|
|
460
|
+
* en préservant les conteneurs de notifications Toast en Top Layer.
|
|
461
|
+
*/
|
|
337
462
|
applyInert() {
|
|
338
|
-
this.
|
|
339
|
-
let
|
|
340
|
-
|
|
341
|
-
while (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
|
|
348
|
-
child.setAttribute("inert", "");
|
|
349
|
-
this.inertSiblings.push(child);
|
|
463
|
+
this.removeInert();
|
|
464
|
+
let current = this.element;
|
|
465
|
+
const ignoredTags = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "LINK", "META", "NOSCRIPT"]);
|
|
466
|
+
while (current && current !== document.body && current.parentElement) {
|
|
467
|
+
const parent = current.parentElement;
|
|
468
|
+
for (const sibling of Array.from(parent.children)) {
|
|
469
|
+
if (sibling instanceof HTMLElement && sibling !== current && !ignoredTags.has(sibling.tagName) && !sibling.hasAttribute("inert") && !sibling.matches(".wulf-toast-container, .wulf-toast-announcer")) {
|
|
470
|
+
sibling.setAttribute("inert", "");
|
|
471
|
+
this.inertSiblings.push(sibling);
|
|
350
472
|
}
|
|
351
|
-
}
|
|
473
|
+
}
|
|
474
|
+
current = parent;
|
|
352
475
|
}
|
|
353
476
|
}
|
|
354
477
|
removeInert() {
|
|
@@ -359,7 +482,7 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
359
482
|
if (this.options.initialFocus === false) return;
|
|
360
483
|
let targetEl = null;
|
|
361
484
|
if (typeof this.options.initialFocus === "string") {
|
|
362
|
-
targetEl = this.element
|
|
485
|
+
targetEl = safeQuerySelector(this.element, this.options.initialFocus);
|
|
363
486
|
} else if (this.options.initialFocus instanceof HTMLElement) {
|
|
364
487
|
targetEl = this.options.initialFocus;
|
|
365
488
|
}
|
|
@@ -371,20 +494,18 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
371
494
|
if (focusables.length > 0) {
|
|
372
495
|
focusables[0].focus();
|
|
373
496
|
} else {
|
|
374
|
-
|
|
375
|
-
this.element.setAttribute("tabindex", "-1");
|
|
376
|
-
}
|
|
497
|
+
this.ensureContainerTabIndex();
|
|
377
498
|
this.element.focus();
|
|
378
499
|
}
|
|
379
500
|
}
|
|
380
501
|
restoreFocus() {
|
|
381
|
-
if (this.previousActiveElement && this.previousActiveElement.isConnected) {
|
|
502
|
+
if (this.previousActiveElement && this.previousActiveElement.isConnected && this.isElementFocusableBase(this.previousActiveElement)) {
|
|
382
503
|
this.previousActiveElement.focus();
|
|
383
504
|
return;
|
|
384
505
|
}
|
|
385
506
|
if (this.options.fallbackReturnFocus) {
|
|
386
|
-
const fallback = typeof this.options.fallbackReturnFocus === "string" ? document
|
|
387
|
-
if (fallback && fallback.isConnected) {
|
|
507
|
+
const fallback = typeof this.options.fallbackReturnFocus === "string" ? safeQuerySelector(document, this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
508
|
+
if (fallback && fallback.isConnected && this.isElementFocusableBase(fallback)) {
|
|
388
509
|
fallback.focus();
|
|
389
510
|
}
|
|
390
511
|
}
|
|
@@ -392,10 +513,8 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
392
513
|
};
|
|
393
514
|
|
|
394
515
|
// src/focus-trap/index.ts
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const wulfNamespace = win.Wulf || {};
|
|
398
|
-
win.Wulf = wulfNamespace;
|
|
516
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
517
|
+
if (wulfNamespace) {
|
|
399
518
|
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
400
519
|
FocusTrap
|
|
401
520
|
});
|