wulf.js 1.9.3 → 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 +118 -78
- package/changelog.md +60 -0
- package/dist/focus-trap.esm.js +202 -136
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +203 -137
- 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 +2130 -858
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2124 -852
- 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 +686 -330
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +687 -331
- 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 +248 -77
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +249 -78
- 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 +462 -129
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +463 -130
- 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 +164 -48
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +165 -49
- 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 +489 -124
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +490 -125
- 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 -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 +14 -6
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/BaseInputMask.d.ts +20 -0
- package/dist/types/mask/InputAmountMask.d.ts +2 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- 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 +1 -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 +9 -2
- package/package.json +16 -3
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,7 +80,7 @@ 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])",
|
|
@@ -58,12 +93,6 @@ var FOCUSABLE_SELECTOR = [
|
|
|
58
93
|
'[contenteditable]:not([contenteditable="false"])',
|
|
59
94
|
'[tabindex]:not([tabindex="-1"])'
|
|
60
95
|
].join(",");
|
|
61
|
-
function safeCssEscape(value) {
|
|
62
|
-
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
63
|
-
return CSS.escape(value);
|
|
64
|
-
}
|
|
65
|
-
return String(value).replace(/["\\]/g, "\\$&");
|
|
66
|
-
}
|
|
67
96
|
function safeQuerySelector(root, selector) {
|
|
68
97
|
if (!selector || typeof selector !== "string") return null;
|
|
69
98
|
try {
|
|
@@ -74,27 +103,34 @@ function safeQuerySelector(root, selector) {
|
|
|
74
103
|
}
|
|
75
104
|
var trapStack = [];
|
|
76
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;
|
|
77
119
|
constructor(target, options = {}) {
|
|
78
120
|
super();
|
|
79
|
-
this.active = false;
|
|
80
|
-
this.paused = false;
|
|
81
|
-
this.previousActiveElement = null;
|
|
82
|
-
this.inertSiblings = [];
|
|
83
|
-
// Sentinelles anti-fuite de focus
|
|
84
|
-
this.startSentinel = null;
|
|
85
|
-
this.endSentinel = null;
|
|
86
121
|
const el = typeof target === "string" ? safeQuerySelector(document, target) : target;
|
|
87
122
|
if (!el || !(el instanceof HTMLElement)) {
|
|
88
123
|
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
89
124
|
}
|
|
90
125
|
this.element = el;
|
|
126
|
+
const allowOutsideClick = options.allowOutsideClick ?? false;
|
|
91
127
|
this.options = {
|
|
92
128
|
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
93
129
|
returnFocus: options.returnFocus ?? true,
|
|
94
130
|
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
95
131
|
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
96
|
-
allowOutsideClick
|
|
97
|
-
setInert: options.setInert ??
|
|
132
|
+
allowOutsideClick,
|
|
133
|
+
setInert: options.setInert ?? !allowOutsideClick,
|
|
98
134
|
onActivate: options.onActivate ?? (() => {
|
|
99
135
|
}),
|
|
100
136
|
onDeactivate: options.onDeactivate ?? (() => {
|
|
@@ -106,25 +142,57 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
106
142
|
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
107
143
|
this.runAuditWarning(this.options.audit);
|
|
108
144
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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) {
|
|
113
157
|
if (!el || !el.isConnected) return false;
|
|
158
|
+
if (el.tabIndex < 0) return false;
|
|
114
159
|
if (el.disabled) return false;
|
|
115
|
-
|
|
160
|
+
try {
|
|
161
|
+
if (el.matches(":disabled")) return false;
|
|
162
|
+
} catch {
|
|
163
|
+
if (el.closest("fieldset[disabled]")) return false;
|
|
164
|
+
}
|
|
116
165
|
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
117
166
|
if (el.hidden || el.closest("[hidden]")) return false;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|
|
123
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;
|
|
124
191
|
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
125
192
|
const group = Array.from(
|
|
126
193
|
this.element.querySelectorAll(`input[type="radio"][name="${safeCssEscape(el.name)}"]`)
|
|
127
|
-
);
|
|
194
|
+
).filter((r) => r.form === el.form && this.isElementFocusableBase(r));
|
|
195
|
+
if (group.length === 0) return false;
|
|
128
196
|
const checked = group.find((r) => r.checked);
|
|
129
197
|
if (checked) {
|
|
130
198
|
return el === checked;
|
|
@@ -152,17 +220,21 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
152
220
|
this.active = true;
|
|
153
221
|
this.paused = false;
|
|
154
222
|
trapStack.push(this);
|
|
155
|
-
|
|
156
|
-
this.
|
|
157
|
-
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()) {
|
|
158
226
|
this.applyInert();
|
|
159
227
|
}
|
|
160
|
-
|
|
161
|
-
|
|
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 });
|
|
162
234
|
if (!this.options.allowOutsideClick) {
|
|
163
|
-
document.addEventListener("
|
|
164
|
-
document.addEventListener("
|
|
165
|
-
document.addEventListener("
|
|
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 });
|
|
166
238
|
}
|
|
167
239
|
this.applyInitialFocus();
|
|
168
240
|
this.runAuditWarning(this.options.audit);
|
|
@@ -180,34 +252,42 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
180
252
|
if (index !== -1) {
|
|
181
253
|
trapStack.splice(index, 1);
|
|
182
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
|
+
}
|
|
183
262
|
const nextTop = trapStack[trapStack.length - 1];
|
|
184
263
|
if (nextTop) {
|
|
185
264
|
nextTop.unpause();
|
|
186
265
|
}
|
|
187
|
-
document.removeEventListener("keydown", this.handleKeyDownBound, true);
|
|
188
|
-
document.removeEventListener("focusin", this.handleFocusInBound, true);
|
|
189
|
-
document.removeEventListener("pointerdown", this.handleClickOutsideBound, true);
|
|
190
|
-
document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
191
|
-
document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
192
|
-
this.removeSentinels();
|
|
193
|
-
this.removeInert();
|
|
194
266
|
if (this.options.returnFocus) {
|
|
195
267
|
this.restoreFocus();
|
|
196
268
|
}
|
|
269
|
+
this.previousActiveElement = null;
|
|
197
270
|
this.options.onDeactivate();
|
|
198
271
|
return this;
|
|
199
272
|
}
|
|
200
273
|
/**
|
|
201
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.
|
|
202
276
|
*/
|
|
203
277
|
pause() {
|
|
204
278
|
this.paused = true;
|
|
279
|
+
this.removeInert();
|
|
205
280
|
}
|
|
206
281
|
/**
|
|
207
|
-
* 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.
|
|
208
283
|
*/
|
|
209
284
|
unpause() {
|
|
285
|
+
if (!this.active) return;
|
|
286
|
+
if (trapStack[trapStack.length - 1] !== this) return;
|
|
210
287
|
this.paused = false;
|
|
288
|
+
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
289
|
+
this.applyInert();
|
|
290
|
+
}
|
|
211
291
|
}
|
|
212
292
|
/**
|
|
213
293
|
* Indique si le trap est actuellement actif et non en pause.
|
|
@@ -222,17 +302,35 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
222
302
|
audit() {
|
|
223
303
|
const warnings = [];
|
|
224
304
|
const role = this.element.getAttribute("role");
|
|
225
|
-
const isNativeDialog = this.
|
|
305
|
+
const isNativeDialog = this.isNativeDialogElement();
|
|
226
306
|
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
}
|
|
236
334
|
}
|
|
237
335
|
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
238
336
|
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
|
|
@@ -268,15 +366,15 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
268
366
|
}
|
|
269
367
|
return false;
|
|
270
368
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
}
|
|
280
378
|
}
|
|
281
379
|
handleKeyDown(e) {
|
|
282
380
|
if (!this.isActive()) return;
|
|
@@ -285,8 +383,11 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
285
383
|
return;
|
|
286
384
|
}
|
|
287
385
|
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
288
|
-
e
|
|
289
|
-
|
|
386
|
+
if (isImeComposing(e)) return;
|
|
387
|
+
if (!this.isNativeModalDialog()) {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
e.stopPropagation();
|
|
390
|
+
}
|
|
290
391
|
this.deactivate();
|
|
291
392
|
return;
|
|
292
393
|
}
|
|
@@ -294,19 +395,19 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
294
395
|
const focusables = this.getFocusableElements();
|
|
295
396
|
if (focusables.length === 0) {
|
|
296
397
|
e.preventDefault();
|
|
297
|
-
|
|
298
|
-
this.element.setAttribute("tabindex", "-1");
|
|
299
|
-
}
|
|
398
|
+
this.ensureContainerTabIndex();
|
|
300
399
|
this.element.focus();
|
|
301
400
|
return;
|
|
302
401
|
}
|
|
303
402
|
const first = focusables[0];
|
|
304
403
|
const last = focusables[focusables.length - 1];
|
|
305
|
-
const
|
|
306
|
-
|
|
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)) {
|
|
307
408
|
e.preventDefault();
|
|
308
409
|
first.focus();
|
|
309
|
-
} else if (e.shiftKey && (current === first ||
|
|
410
|
+
} else if (e.shiftKey && (current === first || current === this.element || !isInside)) {
|
|
310
411
|
e.preventDefault();
|
|
311
412
|
last.focus();
|
|
312
413
|
}
|
|
@@ -319,22 +420,10 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
319
420
|
}
|
|
320
421
|
const target = e.target;
|
|
321
422
|
if (!target) return;
|
|
322
|
-
if (
|
|
323
|
-
const focusables = this.getFocusableElements();
|
|
324
|
-
if (focusables.length > 0) {
|
|
325
|
-
focusables[focusables.length - 1].focus();
|
|
326
|
-
} else {
|
|
327
|
-
this.element.focus();
|
|
328
|
-
}
|
|
423
|
+
if (this.isInsideToastContainer(target)) {
|
|
329
424
|
return;
|
|
330
425
|
}
|
|
331
|
-
if (
|
|
332
|
-
const focusables = this.getFocusableElements();
|
|
333
|
-
if (focusables.length > 0) {
|
|
334
|
-
focusables[0].focus();
|
|
335
|
-
} else {
|
|
336
|
-
this.element.focus();
|
|
337
|
-
}
|
|
426
|
+
if (this.options.allowOutsideClick && performance.now() - this.lastOutsidePointerDownTime < 150) {
|
|
338
427
|
return;
|
|
339
428
|
}
|
|
340
429
|
if (!this.isEventInside(e, target)) {
|
|
@@ -342,9 +431,7 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
342
431
|
if (focusables.length > 0) {
|
|
343
432
|
focusables[0].focus();
|
|
344
433
|
} else {
|
|
345
|
-
|
|
346
|
-
this.element.setAttribute("tabindex", "-1");
|
|
347
|
-
}
|
|
434
|
+
this.ensureContainerTabIndex();
|
|
348
435
|
this.element.focus();
|
|
349
436
|
}
|
|
350
437
|
}
|
|
@@ -357,51 +444,34 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
357
444
|
}
|
|
358
445
|
const target = e.target;
|
|
359
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
|
+
}
|
|
360
454
|
e.preventDefault();
|
|
361
455
|
e.stopPropagation();
|
|
362
456
|
}
|
|
363
457
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
this.startSentinel.setAttribute("aria-hidden", "true");
|
|
369
|
-
this.startSentinel.className = "wulf-sentinel-start";
|
|
370
|
-
this.applySentinelStyles(this.startSentinel);
|
|
371
|
-
}
|
|
372
|
-
if (!this.endSentinel) {
|
|
373
|
-
this.endSentinel = document.createElement("span");
|
|
374
|
-
this.endSentinel.setAttribute("tabindex", "0");
|
|
375
|
-
this.endSentinel.setAttribute("aria-hidden", "true");
|
|
376
|
-
this.endSentinel.className = "wulf-sentinel-end";
|
|
377
|
-
this.applySentinelStyles(this.endSentinel);
|
|
378
|
-
}
|
|
379
|
-
if (this.element.parentNode) {
|
|
380
|
-
this.element.parentNode.insertBefore(this.startSentinel, this.element);
|
|
381
|
-
this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
removeSentinels() {
|
|
385
|
-
this.startSentinel?.remove();
|
|
386
|
-
this.endSentinel?.remove();
|
|
387
|
-
this.startSentinel = null;
|
|
388
|
-
this.endSentinel = null;
|
|
389
|
-
}
|
|
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
|
+
*/
|
|
390
462
|
applyInert() {
|
|
391
|
-
this.
|
|
392
|
-
let
|
|
393
|
-
|
|
394
|
-
while (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
|
|
401
|
-
child.setAttribute("inert", "");
|
|
402
|
-
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);
|
|
403
472
|
}
|
|
404
|
-
}
|
|
473
|
+
}
|
|
474
|
+
current = parent;
|
|
405
475
|
}
|
|
406
476
|
}
|
|
407
477
|
removeInert() {
|
|
@@ -424,20 +494,18 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
424
494
|
if (focusables.length > 0) {
|
|
425
495
|
focusables[0].focus();
|
|
426
496
|
} else {
|
|
427
|
-
|
|
428
|
-
this.element.setAttribute("tabindex", "-1");
|
|
429
|
-
}
|
|
497
|
+
this.ensureContainerTabIndex();
|
|
430
498
|
this.element.focus();
|
|
431
499
|
}
|
|
432
500
|
}
|
|
433
501
|
restoreFocus() {
|
|
434
|
-
if (this.previousActiveElement && this.previousActiveElement.isConnected) {
|
|
502
|
+
if (this.previousActiveElement && this.previousActiveElement.isConnected && this.isElementFocusableBase(this.previousActiveElement)) {
|
|
435
503
|
this.previousActiveElement.focus();
|
|
436
504
|
return;
|
|
437
505
|
}
|
|
438
506
|
if (this.options.fallbackReturnFocus) {
|
|
439
507
|
const fallback = typeof this.options.fallbackReturnFocus === "string" ? safeQuerySelector(document, this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
440
|
-
if (fallback && fallback.isConnected) {
|
|
508
|
+
if (fallback && fallback.isConnected && this.isElementFocusableBase(fallback)) {
|
|
441
509
|
fallback.focus();
|
|
442
510
|
}
|
|
443
511
|
}
|
|
@@ -445,10 +513,8 @@ var FocusTrap = class extends AuditableComponent {
|
|
|
445
513
|
};
|
|
446
514
|
|
|
447
515
|
// src/focus-trap/index.ts
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const wulfNamespace = win.Wulf || {};
|
|
451
|
-
win.Wulf = wulfNamespace;
|
|
516
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
517
|
+
if (wulfNamespace) {
|
|
452
518
|
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
453
519
|
FocusTrap
|
|
454
520
|
});
|