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