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
|
@@ -25,6 +25,38 @@ var __WulfIIFE = (() => {
|
|
|
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 __WulfIIFE = (() => {
|
|
|
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,7 +107,7 @@ var __WulfIIFE = (() => {
|
|
|
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])",
|
|
@@ -85,12 +120,6 @@ var __WulfIIFE = (() => {
|
|
|
85
120
|
'[contenteditable]:not([contenteditable="false"])',
|
|
86
121
|
'[tabindex]:not([tabindex="-1"])'
|
|
87
122
|
].join(",");
|
|
88
|
-
function safeCssEscape(value) {
|
|
89
|
-
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
90
|
-
return CSS.escape(value);
|
|
91
|
-
}
|
|
92
|
-
return String(value).replace(/["\\]/g, "\\$&");
|
|
93
|
-
}
|
|
94
123
|
function safeQuerySelector(root, selector) {
|
|
95
124
|
if (!selector || typeof selector !== "string") return null;
|
|
96
125
|
try {
|
|
@@ -101,27 +130,34 @@ var __WulfIIFE = (() => {
|
|
|
101
130
|
}
|
|
102
131
|
var trapStack = [];
|
|
103
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;
|
|
104
146
|
constructor(target, options = {}) {
|
|
105
147
|
super();
|
|
106
|
-
this.active = false;
|
|
107
|
-
this.paused = false;
|
|
108
|
-
this.previousActiveElement = null;
|
|
109
|
-
this.inertSiblings = [];
|
|
110
|
-
// Sentinelles anti-fuite de focus
|
|
111
|
-
this.startSentinel = null;
|
|
112
|
-
this.endSentinel = null;
|
|
113
148
|
const el = typeof target === "string" ? safeQuerySelector(document, target) : target;
|
|
114
149
|
if (!el || !(el instanceof HTMLElement)) {
|
|
115
150
|
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
116
151
|
}
|
|
117
152
|
this.element = el;
|
|
153
|
+
const allowOutsideClick = options.allowOutsideClick ?? false;
|
|
118
154
|
this.options = {
|
|
119
155
|
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
120
156
|
returnFocus: options.returnFocus ?? true,
|
|
121
157
|
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
122
158
|
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
123
|
-
allowOutsideClick
|
|
124
|
-
setInert: options.setInert ??
|
|
159
|
+
allowOutsideClick,
|
|
160
|
+
setInert: options.setInert ?? !allowOutsideClick,
|
|
125
161
|
onActivate: options.onActivate ?? (() => {
|
|
126
162
|
}),
|
|
127
163
|
onDeactivate: options.onDeactivate ?? (() => {
|
|
@@ -133,25 +169,57 @@ var __WulfIIFE = (() => {
|
|
|
133
169
|
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
134
170
|
this.runAuditWarning(this.options.audit);
|
|
135
171
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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) {
|
|
140
184
|
if (!el || !el.isConnected) return false;
|
|
185
|
+
if (el.tabIndex < 0) return false;
|
|
141
186
|
if (el.disabled) return false;
|
|
142
|
-
|
|
187
|
+
try {
|
|
188
|
+
if (el.matches(":disabled")) return false;
|
|
189
|
+
} catch {
|
|
190
|
+
if (el.closest("fieldset[disabled]")) return false;
|
|
191
|
+
}
|
|
143
192
|
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
144
193
|
if (el.hidden || el.closest("[hidden]")) return false;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
}
|
|
150
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;
|
|
151
218
|
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
152
219
|
const group = Array.from(
|
|
153
220
|
this.element.querySelectorAll(`input[type="radio"][name="${safeCssEscape(el.name)}"]`)
|
|
154
|
-
);
|
|
221
|
+
).filter((r) => r.form === el.form && this.isElementFocusableBase(r));
|
|
222
|
+
if (group.length === 0) return false;
|
|
155
223
|
const checked = group.find((r) => r.checked);
|
|
156
224
|
if (checked) {
|
|
157
225
|
return el === checked;
|
|
@@ -179,17 +247,21 @@ var __WulfIIFE = (() => {
|
|
|
179
247
|
this.active = true;
|
|
180
248
|
this.paused = false;
|
|
181
249
|
trapStack.push(this);
|
|
182
|
-
|
|
183
|
-
this.
|
|
184
|
-
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()) {
|
|
185
253
|
this.applyInert();
|
|
186
254
|
}
|
|
187
|
-
|
|
188
|
-
|
|
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 });
|
|
189
261
|
if (!this.options.allowOutsideClick) {
|
|
190
|
-
document.addEventListener("
|
|
191
|
-
document.addEventListener("
|
|
192
|
-
document.addEventListener("
|
|
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 });
|
|
193
265
|
}
|
|
194
266
|
this.applyInitialFocus();
|
|
195
267
|
this.runAuditWarning(this.options.audit);
|
|
@@ -207,34 +279,42 @@ var __WulfIIFE = (() => {
|
|
|
207
279
|
if (index !== -1) {
|
|
208
280
|
trapStack.splice(index, 1);
|
|
209
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
|
+
}
|
|
210
289
|
const nextTop = trapStack[trapStack.length - 1];
|
|
211
290
|
if (nextTop) {
|
|
212
291
|
nextTop.unpause();
|
|
213
292
|
}
|
|
214
|
-
document.removeEventListener("keydown", this.handleKeyDownBound, true);
|
|
215
|
-
document.removeEventListener("focusin", this.handleFocusInBound, true);
|
|
216
|
-
document.removeEventListener("pointerdown", this.handleClickOutsideBound, true);
|
|
217
|
-
document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
218
|
-
document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
219
|
-
this.removeSentinels();
|
|
220
|
-
this.removeInert();
|
|
221
293
|
if (this.options.returnFocus) {
|
|
222
294
|
this.restoreFocus();
|
|
223
295
|
}
|
|
296
|
+
this.previousActiveElement = null;
|
|
224
297
|
this.options.onDeactivate();
|
|
225
298
|
return this;
|
|
226
299
|
}
|
|
227
300
|
/**
|
|
228
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.
|
|
229
303
|
*/
|
|
230
304
|
pause() {
|
|
231
305
|
this.paused = true;
|
|
306
|
+
this.removeInert();
|
|
232
307
|
}
|
|
233
308
|
/**
|
|
234
|
-
* 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.
|
|
235
310
|
*/
|
|
236
311
|
unpause() {
|
|
312
|
+
if (!this.active) return;
|
|
313
|
+
if (trapStack[trapStack.length - 1] !== this) return;
|
|
237
314
|
this.paused = false;
|
|
315
|
+
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
316
|
+
this.applyInert();
|
|
317
|
+
}
|
|
238
318
|
}
|
|
239
319
|
/**
|
|
240
320
|
* Indique si le trap est actuellement actif et non en pause.
|
|
@@ -249,17 +329,35 @@ var __WulfIIFE = (() => {
|
|
|
249
329
|
audit() {
|
|
250
330
|
const warnings = [];
|
|
251
331
|
const role = this.element.getAttribute("role");
|
|
252
|
-
const isNativeDialog = this.
|
|
332
|
+
const isNativeDialog = this.isNativeDialogElement();
|
|
253
333
|
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
}
|
|
263
361
|
}
|
|
264
362
|
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
265
363
|
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
|
|
@@ -295,15 +393,15 @@ var __WulfIIFE = (() => {
|
|
|
295
393
|
}
|
|
296
394
|
return false;
|
|
297
395
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
+
}
|
|
307
405
|
}
|
|
308
406
|
handleKeyDown(e) {
|
|
309
407
|
if (!this.isActive()) return;
|
|
@@ -312,8 +410,11 @@ var __WulfIIFE = (() => {
|
|
|
312
410
|
return;
|
|
313
411
|
}
|
|
314
412
|
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
315
|
-
e
|
|
316
|
-
|
|
413
|
+
if (isImeComposing(e)) return;
|
|
414
|
+
if (!this.isNativeModalDialog()) {
|
|
415
|
+
e.preventDefault();
|
|
416
|
+
e.stopPropagation();
|
|
417
|
+
}
|
|
317
418
|
this.deactivate();
|
|
318
419
|
return;
|
|
319
420
|
}
|
|
@@ -321,19 +422,19 @@ var __WulfIIFE = (() => {
|
|
|
321
422
|
const focusables = this.getFocusableElements();
|
|
322
423
|
if (focusables.length === 0) {
|
|
323
424
|
e.preventDefault();
|
|
324
|
-
|
|
325
|
-
this.element.setAttribute("tabindex", "-1");
|
|
326
|
-
}
|
|
425
|
+
this.ensureContainerTabIndex();
|
|
327
426
|
this.element.focus();
|
|
328
427
|
return;
|
|
329
428
|
}
|
|
330
429
|
const first = focusables[0];
|
|
331
430
|
const last = focusables[focusables.length - 1];
|
|
332
|
-
const
|
|
333
|
-
|
|
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)) {
|
|
334
435
|
e.preventDefault();
|
|
335
436
|
first.focus();
|
|
336
|
-
} else if (e.shiftKey && (current === first ||
|
|
437
|
+
} else if (e.shiftKey && (current === first || current === this.element || !isInside)) {
|
|
337
438
|
e.preventDefault();
|
|
338
439
|
last.focus();
|
|
339
440
|
}
|
|
@@ -346,22 +447,10 @@ var __WulfIIFE = (() => {
|
|
|
346
447
|
}
|
|
347
448
|
const target = e.target;
|
|
348
449
|
if (!target) return;
|
|
349
|
-
if (
|
|
350
|
-
const focusables = this.getFocusableElements();
|
|
351
|
-
if (focusables.length > 0) {
|
|
352
|
-
focusables[focusables.length - 1].focus();
|
|
353
|
-
} else {
|
|
354
|
-
this.element.focus();
|
|
355
|
-
}
|
|
450
|
+
if (this.isInsideToastContainer(target)) {
|
|
356
451
|
return;
|
|
357
452
|
}
|
|
358
|
-
if (
|
|
359
|
-
const focusables = this.getFocusableElements();
|
|
360
|
-
if (focusables.length > 0) {
|
|
361
|
-
focusables[0].focus();
|
|
362
|
-
} else {
|
|
363
|
-
this.element.focus();
|
|
364
|
-
}
|
|
453
|
+
if (this.options.allowOutsideClick && performance.now() - this.lastOutsidePointerDownTime < 150) {
|
|
365
454
|
return;
|
|
366
455
|
}
|
|
367
456
|
if (!this.isEventInside(e, target)) {
|
|
@@ -369,9 +458,7 @@ var __WulfIIFE = (() => {
|
|
|
369
458
|
if (focusables.length > 0) {
|
|
370
459
|
focusables[0].focus();
|
|
371
460
|
} else {
|
|
372
|
-
|
|
373
|
-
this.element.setAttribute("tabindex", "-1");
|
|
374
|
-
}
|
|
461
|
+
this.ensureContainerTabIndex();
|
|
375
462
|
this.element.focus();
|
|
376
463
|
}
|
|
377
464
|
}
|
|
@@ -384,51 +471,34 @@ var __WulfIIFE = (() => {
|
|
|
384
471
|
}
|
|
385
472
|
const target = e.target;
|
|
386
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
|
+
}
|
|
387
481
|
e.preventDefault();
|
|
388
482
|
e.stopPropagation();
|
|
389
483
|
}
|
|
390
484
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
this.startSentinel.setAttribute("aria-hidden", "true");
|
|
396
|
-
this.startSentinel.className = "wulf-sentinel-start";
|
|
397
|
-
this.applySentinelStyles(this.startSentinel);
|
|
398
|
-
}
|
|
399
|
-
if (!this.endSentinel) {
|
|
400
|
-
this.endSentinel = document.createElement("span");
|
|
401
|
-
this.endSentinel.setAttribute("tabindex", "0");
|
|
402
|
-
this.endSentinel.setAttribute("aria-hidden", "true");
|
|
403
|
-
this.endSentinel.className = "wulf-sentinel-end";
|
|
404
|
-
this.applySentinelStyles(this.endSentinel);
|
|
405
|
-
}
|
|
406
|
-
if (this.element.parentNode) {
|
|
407
|
-
this.element.parentNode.insertBefore(this.startSentinel, this.element);
|
|
408
|
-
this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
removeSentinels() {
|
|
412
|
-
this.startSentinel?.remove();
|
|
413
|
-
this.endSentinel?.remove();
|
|
414
|
-
this.startSentinel = null;
|
|
415
|
-
this.endSentinel = null;
|
|
416
|
-
}
|
|
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
|
+
*/
|
|
417
489
|
applyInert() {
|
|
418
|
-
this.
|
|
419
|
-
let
|
|
420
|
-
|
|
421
|
-
while (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
|
|
428
|
-
child.setAttribute("inert", "");
|
|
429
|
-
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);
|
|
430
499
|
}
|
|
431
|
-
}
|
|
500
|
+
}
|
|
501
|
+
current = parent;
|
|
432
502
|
}
|
|
433
503
|
}
|
|
434
504
|
removeInert() {
|
|
@@ -451,20 +521,18 @@ var __WulfIIFE = (() => {
|
|
|
451
521
|
if (focusables.length > 0) {
|
|
452
522
|
focusables[0].focus();
|
|
453
523
|
} else {
|
|
454
|
-
|
|
455
|
-
this.element.setAttribute("tabindex", "-1");
|
|
456
|
-
}
|
|
524
|
+
this.ensureContainerTabIndex();
|
|
457
525
|
this.element.focus();
|
|
458
526
|
}
|
|
459
527
|
}
|
|
460
528
|
restoreFocus() {
|
|
461
|
-
if (this.previousActiveElement && this.previousActiveElement.isConnected) {
|
|
529
|
+
if (this.previousActiveElement && this.previousActiveElement.isConnected && this.isElementFocusableBase(this.previousActiveElement)) {
|
|
462
530
|
this.previousActiveElement.focus();
|
|
463
531
|
return;
|
|
464
532
|
}
|
|
465
533
|
if (this.options.fallbackReturnFocus) {
|
|
466
534
|
const fallback = typeof this.options.fallbackReturnFocus === "string" ? safeQuerySelector(document, this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
467
|
-
if (fallback && fallback.isConnected) {
|
|
535
|
+
if (fallback && fallback.isConnected && this.isElementFocusableBase(fallback)) {
|
|
468
536
|
fallback.focus();
|
|
469
537
|
}
|
|
470
538
|
}
|
|
@@ -472,15 +540,13 @@ var __WulfIIFE = (() => {
|
|
|
472
540
|
};
|
|
473
541
|
|
|
474
542
|
// src/focus-trap/index.ts
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const wulfNamespace = win.Wulf || {};
|
|
478
|
-
win.Wulf = wulfNamespace;
|
|
543
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
544
|
+
if (wulfNamespace) {
|
|
479
545
|
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
480
546
|
FocusTrap
|
|
481
547
|
});
|
|
482
548
|
}
|
|
483
549
|
return __toCommonJS(index_exports);
|
|
484
550
|
})();
|
|
485
|
-
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 (__) {} } } } } }
|
|
486
552
|
//# sourceMappingURL=focus-trap.global.js.map
|