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