wulf.js 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -11
- package/changelog.md +50 -0
- package/dist/anchor.esm.js +9 -0
- package/dist/anchor.esm.js.map +7 -0
- package/dist/anchor.global.js +695 -0
- package/dist/anchor.global.js.map +7 -0
- package/dist/anchor.global.min.js +6 -0
- package/dist/anchor.global.min.js.map +7 -0
- package/dist/autosize.css +1 -0
- package/dist/autosize.css.map +7 -0
- package/dist/autosize.esm.js +10 -0
- package/dist/autosize.esm.js.map +7 -0
- package/dist/autosize.global.js +657 -0
- package/dist/autosize.global.js.map +7 -0
- package/dist/autosize.global.min.js +6 -0
- package/dist/autosize.global.min.js.map +7 -0
- package/dist/autosize.layered.css +1 -0
- package/dist/autosize.layered.css.map +7 -0
- package/dist/chunks/chunk-22AIMRD5.js +119 -0
- package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
- package/dist/chunks/chunk-5N2IRGDM.js +766 -0
- package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
- package/dist/chunks/chunk-72FVCNNZ.js +863 -0
- package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
- package/dist/chunks/chunk-AXZYYW7H.js +865 -0
- package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
- package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
- package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
- package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
- package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
- package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
- package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
- package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
- package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
- package/dist/chunks/chunk-QV46A7FV.js +197 -0
- package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
- package/dist/chunks/chunk-SXLUXN6W.js +612 -0
- package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
- package/dist/chunks/chunk-T2H4EJCW.js +621 -0
- package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
- package/dist/chunks/chunk-TILLYEF2.js +6044 -0
- package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
- package/dist/chunks/chunk-VJO22BAT.js +72 -0
- package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
- package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
- package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
- package/dist/focus-trap.esm.js +6 -594
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +176 -61
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +79 -10448
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +3660 -202
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +6 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +16 -6094
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +44 -55
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +3 -3
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +15 -1158
- package/dist/masonry.esm.js.map +4 -4
- package/dist/masonry.global.js +84 -94
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +14 -1252
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +64 -58
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +3 -3
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +6 -901
- package/dist/shortcut.esm.js.map +4 -4
- package/dist/shortcut.global.js +43 -36
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +6 -3
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/size-report.json +319 -0
- package/dist/sortable.css +1 -0
- package/dist/sortable.css.map +7 -0
- package/dist/sortable.esm.js +22 -0
- package/dist/sortable.esm.js.map +7 -0
- package/dist/sortable.global.js +1477 -0
- package/dist/sortable.global.js.map +7 -0
- package/dist/sortable.global.min.js +6 -0
- package/dist/sortable.global.min.js.map +7 -0
- package/dist/sortable.layered.css +1 -0
- package/dist/sortable.layered.css.map +7 -0
- package/dist/sri-manifest.json +64 -0
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +19 -1208
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +314 -111
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +3 -3
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/anchor/Anchor.d.ts +41 -0
- package/dist/types/anchor/index.d.ts +3 -0
- package/dist/types/anchor/types.d.ts +115 -0
- package/dist/types/autosize/Autosize.d.ts +71 -0
- package/dist/types/autosize/index.d.ts +3 -0
- package/dist/types/autosize/types.d.ts +66 -0
- package/dist/types/common/AuditableComponent.d.ts +1 -1
- package/dist/types/common/registry.d.ts +40 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
- package/dist/types/index.d.ts +13 -1
- package/dist/types/scroll/types.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
- package/dist/types/shortcut/types.d.ts +5 -0
- package/dist/types/sortable/Sortable.d.ts +75 -0
- package/dist/types/sortable/i18n/en.d.ts +2 -0
- package/dist/types/sortable/i18n/fr.d.ts +2 -0
- package/dist/types/sortable/i18n/index.d.ts +9 -0
- package/dist/types/sortable/i18n/types.d.ts +15 -0
- package/dist/types/sortable/index.d.ts +4 -0
- package/dist/types/sortable/types.d.ts +112 -0
- package/dist/types/toast/Toast.d.ts +6 -1
- package/dist/types/toast/ToastInstance.d.ts +7 -0
- package/dist/types/toast/ToastManager.d.ts +2 -2
- package/dist/types/toast/types.d.ts +27 -1
- package/dist/types/undo/UndoManager.d.ts +112 -0
- package/dist/types/undo/i18n/en.d.ts +2 -0
- package/dist/types/undo/i18n/fr.d.ts +2 -0
- package/dist/types/undo/i18n/index.d.ts +9 -0
- package/dist/types/undo/i18n/types.d.ts +6 -0
- package/dist/types/undo/index.d.ts +5 -0
- package/dist/types/undo/types.d.ts +106 -0
- package/dist/undo.esm.js +23 -0
- package/dist/undo.esm.js.map +7 -0
- package/dist/undo.global.js +1029 -0
- package/dist/undo.global.js.map +7 -0
- package/dist/undo.global.min.js +6 -0
- package/dist/undo.global.min.js.map +7 -0
- package/package.json +54 -5
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,597 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
33
|
-
// src/common/AuditableComponent.ts
|
|
34
|
-
var AuditableComponent = class {
|
|
35
|
-
/**
|
|
36
|
-
* Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
|
|
37
|
-
*/
|
|
38
|
-
getAuditDisableHint() {
|
|
39
|
-
return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
|
|
43
|
-
* si l'audit est activé et que des contraintes manquent.
|
|
44
|
-
*/
|
|
45
|
-
runAuditWarning(enabled = true) {
|
|
46
|
-
if (!enabled) return [];
|
|
47
|
-
const warnings = this.audit();
|
|
48
|
-
if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
49
|
-
console.warn(
|
|
50
|
-
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
51
|
-
` + warnings.map((w) => ` - ${w}`).join("\n") + `
|
|
52
|
-
(${this.getAuditDisableHint()})`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return warnings;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
|
|
59
|
-
* pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
|
|
60
|
-
*/
|
|
61
|
-
checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
|
|
62
|
-
const rawValue = element.getAttribute(attrName)?.trim();
|
|
63
|
-
if (!rawValue) return false;
|
|
64
|
-
const doc = element.ownerDocument || document;
|
|
65
|
-
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
66
|
-
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
67
|
-
const targets = ids.map(
|
|
68
|
-
(id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
|
|
69
|
-
);
|
|
70
|
-
const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
|
|
71
|
-
if (!allFound) {
|
|
72
|
-
warnings.push(
|
|
73
|
-
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
74
|
-
);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (requireNonEmptyText) {
|
|
78
|
-
const hasNonEmptyText = targets.some((el) => {
|
|
79
|
-
if (!el) return false;
|
|
80
|
-
const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
|
|
81
|
-
return text.length > 0;
|
|
82
|
-
});
|
|
83
|
-
if (!hasNonEmptyText) {
|
|
84
|
-
warnings.push(
|
|
85
|
-
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
|
|
86
|
-
);
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// src/focus-trap/FocusTrap.ts
|
|
95
|
-
var FOCUSABLE_SELECTOR = [
|
|
96
|
-
"a[href]",
|
|
97
|
-
"area[href]",
|
|
98
|
-
'input:not([disabled]):not([type="hidden"])',
|
|
99
|
-
"select:not([disabled])",
|
|
100
|
-
"textarea:not([disabled])",
|
|
101
|
-
"button:not([disabled])",
|
|
102
|
-
"audio[controls]",
|
|
103
|
-
"video[controls]",
|
|
104
|
-
"details > summary:first-of-type",
|
|
105
|
-
"iframe",
|
|
106
|
-
"object",
|
|
107
|
-
"embed",
|
|
108
|
-
'[contenteditable]:not([contenteditable="false"])',
|
|
109
|
-
'[tabindex]:not([tabindex="-1"])'
|
|
110
|
-
].join(",");
|
|
111
|
-
function safeQuerySelector(root, selector) {
|
|
112
|
-
if (!selector || typeof selector !== "string") return null;
|
|
113
|
-
try {
|
|
114
|
-
return root.querySelector(selector);
|
|
115
|
-
} catch {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
var trapStack = [];
|
|
120
|
-
var FocusTrap = class extends AuditableComponent {
|
|
121
|
-
element;
|
|
122
|
-
options;
|
|
123
|
-
active = false;
|
|
124
|
-
paused = false;
|
|
125
|
-
previousActiveElement = null;
|
|
126
|
-
inertSiblings = [];
|
|
127
|
-
addedContainerTabIndex = false;
|
|
128
|
-
lastOutsidePointerDownTime = 0;
|
|
129
|
-
abortController;
|
|
130
|
-
// Handlers liés
|
|
131
|
-
handleKeyDownBound;
|
|
132
|
-
handleClickOutsideBound;
|
|
133
|
-
handleFocusInBound;
|
|
134
|
-
constructor(target, options = {}) {
|
|
135
|
-
super();
|
|
136
|
-
const el = typeof target === "string" ? safeQuerySelector(document, target) : target;
|
|
137
|
-
if (!el || !(el instanceof HTMLElement)) {
|
|
138
|
-
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
139
|
-
}
|
|
140
|
-
this.element = el;
|
|
141
|
-
const allowOutsideClick = options.allowOutsideClick ?? false;
|
|
142
|
-
this.options = {
|
|
143
|
-
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
144
|
-
returnFocus: options.returnFocus ?? true,
|
|
145
|
-
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
146
|
-
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
147
|
-
allowOutsideClick,
|
|
148
|
-
setInert: options.setInert ?? !allowOutsideClick,
|
|
149
|
-
onActivate: options.onActivate ?? (() => {
|
|
150
|
-
}),
|
|
151
|
-
onDeactivate: options.onDeactivate ?? (() => {
|
|
152
|
-
}),
|
|
153
|
-
audit: options.audit ?? true
|
|
154
|
-
};
|
|
155
|
-
this.handleKeyDownBound = this.handleKeyDown.bind(this);
|
|
156
|
-
this.handleClickOutsideBound = this.handleClickOutside.bind(this);
|
|
157
|
-
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
158
|
-
this.runAuditWarning(this.options.audit);
|
|
159
|
-
}
|
|
160
|
-
isNativeDialogElement() {
|
|
161
|
-
return this.element.tagName.toLowerCase() === "dialog";
|
|
162
|
-
}
|
|
163
|
-
isNativeModalDialog() {
|
|
164
|
-
if (!this.isNativeDialogElement()) return false;
|
|
165
|
-
try {
|
|
166
|
-
return this.element.matches(":modal");
|
|
167
|
-
} catch {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
isElementVisibleAndEnabled(el) {
|
|
172
|
-
if (!el || !el.isConnected) return false;
|
|
173
|
-
if (el.disabled) return false;
|
|
174
|
-
try {
|
|
175
|
-
if (el.matches(":disabled")) return false;
|
|
176
|
-
} catch {
|
|
177
|
-
if (el.closest("fieldset[disabled]")) return false;
|
|
178
|
-
}
|
|
179
|
-
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
180
|
-
if (el.hidden || el.closest("[hidden]")) return false;
|
|
181
|
-
const elWithCheck = el;
|
|
182
|
-
if (typeof elWithCheck.checkVisibility === "function") {
|
|
183
|
-
if (!elWithCheck.checkVisibility({
|
|
184
|
-
checkOpacity: false,
|
|
185
|
-
checkVisibilityCSS: true,
|
|
186
|
-
visibilityProperty: true
|
|
187
|
-
})) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
if (el.style.display === "none" || el.style.visibility === "hidden") return false;
|
|
192
|
-
const style = window.getComputedStyle(el);
|
|
193
|
-
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
194
|
-
if (el.offsetWidth === 0 && el.offsetHeight === 0 && style.position !== "fixed") {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
isElementFocusableBase(el) {
|
|
201
|
-
if (!el || el.tabIndex < 0) return false;
|
|
202
|
-
return this.isElementVisibleAndEnabled(el);
|
|
203
|
-
}
|
|
204
|
-
isProgrammaticallyFocusable(el) {
|
|
205
|
-
if (!el || !this.isElementVisibleAndEnabled(el)) return false;
|
|
206
|
-
return el.tabIndex >= 0 || el.getAttribute("tabindex") !== null;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Vérifie si un élément est réellement focusable, visible et actif dans le DOM.
|
|
210
|
-
*/
|
|
211
|
-
isFocusable(el) {
|
|
212
|
-
if (!this.isElementFocusableBase(el)) return false;
|
|
213
|
-
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
214
|
-
const group = Array.from(
|
|
215
|
-
this.element.querySelectorAll(`input[type="radio"][name="${safeCssEscape(el.name)}"]`)
|
|
216
|
-
).filter((r) => r.form === el.form && this.isElementFocusableBase(r));
|
|
217
|
-
if (group.length === 0) return false;
|
|
218
|
-
const checked = group.find((r) => r.checked);
|
|
219
|
-
if (checked) {
|
|
220
|
-
return el === checked;
|
|
221
|
-
}
|
|
222
|
-
return el === group[0];
|
|
223
|
-
}
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Retourne tous les éléments focusables réels ordonnés dans le conteneur.
|
|
228
|
-
*/
|
|
229
|
-
getFocusableElements() {
|
|
230
|
-
const rawElements = Array.from(this.element.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
231
|
-
return rawElements.filter((el) => this.isFocusable(el));
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Active le trap.
|
|
235
|
-
*/
|
|
236
|
-
activate() {
|
|
237
|
-
if (this.active) return this;
|
|
238
|
-
const currentTop = trapStack[trapStack.length - 1];
|
|
239
|
-
if (currentTop) {
|
|
240
|
-
currentTop.pause();
|
|
241
|
-
}
|
|
242
|
-
this.active = true;
|
|
243
|
-
this.paused = false;
|
|
244
|
-
trapStack.push(this);
|
|
245
|
-
const deepActive = getDeepActiveElement(document);
|
|
246
|
-
this.previousActiveElement = deepActive instanceof HTMLElement ? deepActive : document.activeElement;
|
|
247
|
-
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
248
|
-
this.applyInert();
|
|
249
|
-
}
|
|
250
|
-
this.abortController?.abort();
|
|
251
|
-
this.abortController = new AbortController();
|
|
252
|
-
const { signal } = this.abortController;
|
|
253
|
-
document.addEventListener("keydown", this.handleKeyDownBound, { capture: true, signal });
|
|
254
|
-
document.addEventListener("focusin", this.handleFocusInBound, { capture: true, signal });
|
|
255
|
-
document.addEventListener("pointerdown", this.handleClickOutsideBound, { capture: true, signal });
|
|
256
|
-
if (!this.options.allowOutsideClick) {
|
|
257
|
-
document.addEventListener("mousedown", this.handleClickOutsideBound, { capture: true, signal });
|
|
258
|
-
document.addEventListener("touchstart", this.handleClickOutsideBound, { capture: true, signal });
|
|
259
|
-
document.addEventListener("click", this.handleClickOutsideBound, { capture: true, signal });
|
|
260
|
-
}
|
|
261
|
-
if (this.isNativeDialogElement()) {
|
|
262
|
-
this.element.addEventListener("close", () => this.deactivate(), { signal });
|
|
263
|
-
}
|
|
264
|
-
this.applyInitialFocus();
|
|
265
|
-
this.runAuditWarning(this.options.audit);
|
|
266
|
-
try {
|
|
267
|
-
this.options.onActivate();
|
|
268
|
-
} catch (err) {
|
|
269
|
-
console.error("[Wulf.FocusTrap] Erreur dans onActivate:", err);
|
|
270
|
-
}
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Désactive le trap et libère les écouteurs.
|
|
275
|
-
*/
|
|
276
|
-
deactivate() {
|
|
277
|
-
if (!this.active) return this;
|
|
278
|
-
const wasTop = trapStack[trapStack.length - 1] === this;
|
|
279
|
-
this.active = false;
|
|
280
|
-
this.paused = false;
|
|
281
|
-
const index = trapStack.indexOf(this);
|
|
282
|
-
if (index !== -1) {
|
|
283
|
-
trapStack.splice(index, 1);
|
|
284
|
-
}
|
|
285
|
-
this.abortController?.abort();
|
|
286
|
-
this.abortController = void 0;
|
|
287
|
-
this.removeInert();
|
|
288
|
-
if (this.addedContainerTabIndex) {
|
|
289
|
-
this.element.removeAttribute("tabindex");
|
|
290
|
-
this.addedContainerTabIndex = false;
|
|
291
|
-
}
|
|
292
|
-
if (wasTop) {
|
|
293
|
-
const nextTop = trapStack[trapStack.length - 1];
|
|
294
|
-
if (nextTop) {
|
|
295
|
-
nextTop.unpause();
|
|
296
|
-
}
|
|
297
|
-
if (this.options.returnFocus) {
|
|
298
|
-
this.restoreFocus();
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
this.previousActiveElement = null;
|
|
302
|
-
try {
|
|
303
|
-
this.options.onDeactivate();
|
|
304
|
-
} catch (err) {
|
|
305
|
-
console.error("[Wulf.FocusTrap] Erreur dans onDeactivate:", err);
|
|
306
|
-
}
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Met en pause le trap (utilisé quand un trap fils s'ouvre au-dessus).
|
|
311
|
-
* Retire temporairement `inert` pour ne pas bloquer une modale sœur ou enfant.
|
|
312
|
-
*/
|
|
313
|
-
pause() {
|
|
314
|
-
this.paused = true;
|
|
315
|
-
this.removeInert();
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Sort de pause et réapplique l'isolation `inert` si active et si ce trap est bien au sommet de la pile.
|
|
319
|
-
*/
|
|
320
|
-
unpause() {
|
|
321
|
-
if (!this.active) return;
|
|
322
|
-
if (trapStack[trapStack.length - 1] !== this) return;
|
|
323
|
-
this.paused = false;
|
|
324
|
-
if (this.options.setInert && !this.isNativeModalDialog()) {
|
|
325
|
-
this.applyInert();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Indique si le trap est actuellement actif et non en pause.
|
|
330
|
-
*/
|
|
331
|
-
isActive() {
|
|
332
|
-
return this.active && !this.paused;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Vérifie la conformité d'accessibilité WAI-ARIA du conteneur FocusTrap
|
|
336
|
-
* et retourne la liste des contraintes manquantes.
|
|
337
|
-
*/
|
|
338
|
-
audit() {
|
|
339
|
-
const warnings = [];
|
|
340
|
-
const role = this.element.getAttribute("role");
|
|
341
|
-
const isNativeDialog = this.isNativeDialogElement();
|
|
342
|
-
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
343
|
-
if (isNativeDialog) {
|
|
344
|
-
if (role === "dialog") {
|
|
345
|
-
warnings.push(
|
|
346
|
-
'Attribut redondant : role="dialog" est d\xE9j\xE0 implicite sur une balise native <dialog>.'
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
if (this.element.hasAttribute("aria-modal")) {
|
|
350
|
-
warnings.push(
|
|
351
|
-
'Attribut redondant : <dialog> ouvert via showModal() g\xE8re nativement la modalit\xE9 sans n\xE9cessiter aria-modal="true".'
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
if (this.element.hasAttribute("open") && !this.isNativeModalDialog()) {
|
|
355
|
-
warnings.push(
|
|
356
|
-
"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."
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
} else {
|
|
360
|
-
if (!role || !validRoles.includes(role)) {
|
|
361
|
-
warnings.push(
|
|
362
|
-
'R\xF4le s\xE9mantique manquant ou inadapt\xE9 : d\xE9finissez role="dialog" (ou "alertdialog", "menu", "listbox") sur le conteneur.'
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if ((role === "dialog" || role === "alertdialog") && this.element.getAttribute("aria-modal") !== "true") {
|
|
366
|
-
warnings.push(
|
|
367
|
-
'Isolation modale manquante : d\xE9finissez aria-modal="true" sur le conteneur de dialogue (WCAG 4.1.2).'
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
372
|
-
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings, true);
|
|
373
|
-
if (!ariaLabel && !hasValidLabelledby) {
|
|
374
|
-
warnings.push(
|
|
375
|
-
'Nom accessible manquant : d\xE9finissez aria-labelledby="id-titre" ou aria-label="..." sur le conteneur (WCAG 4.1.2).'
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
if (this.element.hasAttribute("aria-describedby")) {
|
|
379
|
-
this.checkAriaIdReferences(this.element, "aria-describedby", warnings, true);
|
|
380
|
-
}
|
|
381
|
-
const positiveTabIndexEls = Array.from(this.element.querySelectorAll("[tabindex]")).filter(
|
|
382
|
-
(el) => el.tabIndex > 0
|
|
383
|
-
);
|
|
384
|
-
if (positiveTabIndexEls.length > 0) {
|
|
385
|
-
warnings.push(
|
|
386
|
-
`${positiveTabIndexEls.length} \xE9l\xE9ment(s) avec tabindex > 0 d\xE9tect\xE9(s) : utilisez uniquement tabindex="0" ou "-1" pour pr\xE9server l'ordre s\xE9quentiel de tabulation (WCAG 2.4.3).`
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
return warnings;
|
|
390
|
-
}
|
|
391
|
-
getAuditPrefix() {
|
|
392
|
-
return "Wulf.FocusTrap";
|
|
393
|
-
}
|
|
394
|
-
getAuditTargetLabel() {
|
|
395
|
-
return this.element.id ? `#${this.element.id}` : `<${this.element.tagName.toLowerCase()}>`;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Détruit l'instance proprement.
|
|
399
|
-
*/
|
|
400
|
-
destroy() {
|
|
401
|
-
this.deactivate();
|
|
402
|
-
}
|
|
403
|
-
// --- Implémentation interne ---
|
|
404
|
-
isEventInside(e, target) {
|
|
405
|
-
if (target && this.element.contains(target)) {
|
|
406
|
-
return true;
|
|
407
|
-
}
|
|
408
|
-
if (typeof e.composedPath === "function") {
|
|
409
|
-
const path = e.composedPath();
|
|
410
|
-
if (path.includes(this.element)) {
|
|
411
|
-
return true;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
isInsideToastContainer(target) {
|
|
417
|
-
if (!target || !(target instanceof Element)) return false;
|
|
418
|
-
const container = target.closest(".wulf-toast-container");
|
|
419
|
-
return Boolean(container && container.parentElement === document.body && !this.element.contains(container));
|
|
420
|
-
}
|
|
421
|
-
ensureContainerTabIndex() {
|
|
422
|
-
if (this.element.getAttribute("tabindex") === null) {
|
|
423
|
-
this.element.setAttribute("tabindex", "-1");
|
|
424
|
-
this.addedContainerTabIndex = true;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
handleKeyDown(e) {
|
|
428
|
-
if (!this.isActive()) return;
|
|
429
|
-
if (this.element.isConnected === false) {
|
|
430
|
-
this.deactivate();
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
434
|
-
if (e.defaultPrevented || e.ctrlKey || e.altKey || e.metaKey || e.shiftKey || isImeComposing(e)) return;
|
|
435
|
-
const deepActive = getDeepActiveElement(document);
|
|
436
|
-
if (this.isInsideToastContainer(deepActive) || this.isInsideToastContainer(e.target)) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (this.isNativeModalDialog()) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
e.preventDefault();
|
|
443
|
-
e.stopPropagation();
|
|
444
|
-
this.deactivate();
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
if (e.key !== "Tab") return;
|
|
448
|
-
const focusables = this.getFocusableElements();
|
|
449
|
-
if (focusables.length === 0) {
|
|
450
|
-
e.preventDefault();
|
|
451
|
-
this.ensureContainerTabIndex();
|
|
452
|
-
this.element.focus();
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
const first = focusables[0];
|
|
456
|
-
const last = focusables[focusables.length - 1];
|
|
457
|
-
const deepCurrent = getDeepActiveElement(document);
|
|
458
|
-
const current = deepCurrent instanceof HTMLElement ? deepCurrent : document.activeElement;
|
|
459
|
-
const isInside = current ? this.element.contains(current) || this.isEventInside(e, current) : false;
|
|
460
|
-
if (!e.shiftKey && (current === last || !isInside)) {
|
|
461
|
-
e.preventDefault();
|
|
462
|
-
first.focus();
|
|
463
|
-
} else if (e.shiftKey && (current === first || current === this.element || !isInside)) {
|
|
464
|
-
e.preventDefault();
|
|
465
|
-
last.focus();
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
handleFocusIn(e) {
|
|
469
|
-
if (!this.isActive()) return;
|
|
470
|
-
if (this.element.isConnected === false) {
|
|
471
|
-
this.deactivate();
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
const target = e.target;
|
|
475
|
-
if (!target) return;
|
|
476
|
-
if (this.isInsideToastContainer(target)) {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
if (this.options.allowOutsideClick && performance.now() - this.lastOutsidePointerDownTime < 150) {
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
if (!this.isEventInside(e, target)) {
|
|
483
|
-
const focusables = this.getFocusableElements();
|
|
484
|
-
if (focusables.length > 0) {
|
|
485
|
-
focusables[0].focus();
|
|
486
|
-
} else {
|
|
487
|
-
this.ensureContainerTabIndex();
|
|
488
|
-
this.element.focus();
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
handleClickOutside(e) {
|
|
493
|
-
if (!this.isActive()) return;
|
|
494
|
-
if (this.element.isConnected === false) {
|
|
495
|
-
this.deactivate();
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
const target = e.target;
|
|
499
|
-
if (target && !this.isEventInside(e, target)) {
|
|
500
|
-
if (this.isInsideToastContainer(target)) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
if (this.options.allowOutsideClick) {
|
|
504
|
-
this.lastOutsidePointerDownTime = performance.now();
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
e.preventDefault();
|
|
508
|
-
e.stopPropagation();
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Applique `inert` sur les éléments frères à chaque niveau hiérarchique jusqu'à <body>
|
|
513
|
-
* (y compris en remontant à travers les ShadowRoot.host), en préservant les conteneurs
|
|
514
|
-
* de notifications Toast en Top Layer enfants directs de <body>.
|
|
515
|
-
*/
|
|
516
|
-
applyInert() {
|
|
517
|
-
this.removeInert();
|
|
518
|
-
let current = this.element;
|
|
519
|
-
const ignoredTags = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "LINK", "META", "NOSCRIPT"]);
|
|
520
|
-
while (current && current !== document.body) {
|
|
521
|
-
const parent = current.parentElement;
|
|
522
|
-
if (parent) {
|
|
523
|
-
for (const sibling of Array.from(parent.children)) {
|
|
524
|
-
if (sibling instanceof HTMLElement && sibling !== current && !ignoredTags.has(sibling.tagName) && !sibling.hasAttribute("inert") && !(parent === document.body && sibling.matches(".wulf-toast-container, .wulf-toast-announcer"))) {
|
|
525
|
-
sibling.setAttribute("inert", "");
|
|
526
|
-
this.inertSiblings.push(sibling);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
current = parent;
|
|
530
|
-
} else {
|
|
531
|
-
const root = typeof current.getRootNode === "function" ? current.getRootNode() : null;
|
|
532
|
-
if (typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot) {
|
|
533
|
-
for (const sibling of Array.from(root.children)) {
|
|
534
|
-
if (sibling instanceof HTMLElement && sibling !== current && !ignoredTags.has(sibling.tagName) && !sibling.hasAttribute("inert")) {
|
|
535
|
-
sibling.setAttribute("inert", "");
|
|
536
|
-
this.inertSiblings.push(sibling);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
current = root.host instanceof HTMLElement ? root.host : null;
|
|
540
|
-
} else {
|
|
541
|
-
break;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
removeInert() {
|
|
547
|
-
this.inertSiblings.forEach((el) => el.removeAttribute("inert"));
|
|
548
|
-
this.inertSiblings = [];
|
|
549
|
-
}
|
|
550
|
-
applyInitialFocus() {
|
|
551
|
-
if (this.options.initialFocus === false) return;
|
|
552
|
-
let targetEl = null;
|
|
553
|
-
if (typeof this.options.initialFocus === "string") {
|
|
554
|
-
targetEl = safeQuerySelector(this.element, this.options.initialFocus);
|
|
555
|
-
} else if (this.options.initialFocus instanceof HTMLElement) {
|
|
556
|
-
targetEl = this.element.contains(this.options.initialFocus) ? this.options.initialFocus : null;
|
|
557
|
-
}
|
|
558
|
-
if (targetEl) {
|
|
559
|
-
const isRadio = targetEl instanceof HTMLInputElement && targetEl.type === "radio" && Boolean(targetEl.name);
|
|
560
|
-
const canFocus = isRadio && targetEl.tabIndex >= 0 ? this.isFocusable(targetEl) : this.isProgrammaticallyFocusable(targetEl);
|
|
561
|
-
if (canFocus) {
|
|
562
|
-
targetEl.focus();
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
const focusables = this.getFocusableElements();
|
|
567
|
-
if (focusables.length > 0) {
|
|
568
|
-
focusables[0].focus();
|
|
569
|
-
} else {
|
|
570
|
-
this.ensureContainerTabIndex();
|
|
571
|
-
this.element.focus();
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
restoreFocus() {
|
|
575
|
-
if (this.previousActiveElement && this.previousActiveElement.isConnected && this.isProgrammaticallyFocusable(this.previousActiveElement)) {
|
|
576
|
-
this.previousActiveElement.focus();
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
if (this.options.fallbackReturnFocus) {
|
|
580
|
-
const fallback = typeof this.options.fallbackReturnFocus === "string" ? safeQuerySelector(document, this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
581
|
-
if (fallback && fallback.isConnected && this.isProgrammaticallyFocusable(fallback)) {
|
|
582
|
-
fallback.focus();
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
// src/focus-trap/index.ts
|
|
589
|
-
var wulfNamespace = getSafeWulfNamespace();
|
|
590
|
-
if (wulfNamespace) {
|
|
591
|
-
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
592
|
-
FocusTrap
|
|
593
|
-
});
|
|
594
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
FocusTrap
|
|
3
|
+
} from "./chunks/chunk-SXLUXN6W.js";
|
|
4
|
+
import "./chunks/chunk-ZGUU6DMM.js";
|
|
5
|
+
import "./chunks/chunk-22AIMRD5.js";
|
|
6
|
+
import "./chunks/chunk-VJO22BAT.js";
|
|
595
7
|
export {
|
|
596
8
|
FocusTrap,
|
|
597
9
|
FocusTrap as default
|