wulf.js 1.9.0 → 1.9.2
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 +220 -19
- package/changelog.md +42 -0
- package/dist/focus-trap.esm.js +407 -0
- package/dist/focus-trap.esm.js.map +7 -0
- package/dist/focus-trap.global.js +433 -0
- package/dist/focus-trap.global.js.map +7 -0
- package/dist/focus-trap.global.min.js +6 -0
- package/dist/focus-trap.global.min.js.map +7 -0
- package/dist/index.esm.js +1179 -8
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +1180 -9
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +5 -2
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +106 -2
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +107 -3
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +5 -2
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +78 -3
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +79 -4
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +5 -2
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.esm.js +78 -3
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +79 -4
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +5 -2
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/shortcut.esm.js +584 -0
- package/dist/shortcut.esm.js.map +7 -0
- package/dist/shortcut.global.js +610 -0
- package/dist/shortcut.global.js.map +7 -0
- package/dist/shortcut.global.min.js +3 -0
- package/dist/shortcut.global.min.js.map +7 -0
- package/dist/toast.esm.js +91 -2
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +92 -3
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +5 -2
- package/dist/toast.global.min.js.map +4 -4
- package/dist/types/common/AuditableComponent.d.ts +45 -0
- package/dist/types/common/LocalizedComponent.d.ts +3 -2
- package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
- package/dist/types/focus-trap/index.d.ts +3 -0
- package/dist/types/focus-trap/types.d.ts +45 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mask/BaseInputMask.d.ts +14 -1
- package/dist/types/mask/InputMask.d.ts +1 -0
- package/dist/types/mask/types.d.ts +5 -2
- package/dist/types/masonry/Masonry.d.ts +7 -0
- package/dist/types/masonry/types.d.ts +7 -2
- package/dist/types/scroll/ScrollBlock.d.ts +7 -0
- package/dist/types/scroll/types.d.ts +3 -2
- package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +91 -0
- package/dist/types/shortcut/index.d.ts +4 -0
- package/dist/types/shortcut/types.d.ts +101 -0
- package/dist/types/toast/Toast.d.ts +3 -0
- package/dist/types/toast/ToastInstance.d.ts +9 -1
- package/dist/types/toast/types.d.ts +3 -2
- package/package.json +23 -10
- package/dist/index.cjs.js +0 -4783
- package/dist/index.cjs.js.map +0 -7
- package/dist/mask.cjs.js +0 -2982
- package/dist/mask.cjs.js.map +0 -7
- package/dist/masonry.cjs.js +0 -783
- package/dist/masonry.cjs.js.map +0 -7
- package/dist/scroll.cjs.js +0 -748
- package/dist/scroll.cjs.js.map +0 -7
- package/dist/toast.cjs.js +0 -626
- package/dist/toast.cjs.js.map +0 -7
package/dist/index.global.js
CHANGED
|
@@ -22,8 +22,10 @@ var Wulf = (() => {
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
AmountEngine: () => AmountEngine,
|
|
25
|
+
AuditableComponent: () => AuditableComponent,
|
|
25
26
|
BaseInputMask: () => BaseInputMask,
|
|
26
27
|
EmailEngine: () => EmailEngine,
|
|
28
|
+
FocusTrap: () => focus_trap_exports,
|
|
27
29
|
InputAmountMask: () => InputAmountMask,
|
|
28
30
|
InputEmailMask: () => InputEmailMask,
|
|
29
31
|
InputMask: () => InputMask,
|
|
@@ -34,7 +36,10 @@ var Wulf = (() => {
|
|
|
34
36
|
MaskKeyboard: () => MaskKeyboard,
|
|
35
37
|
Masonry: () => masonry_exports,
|
|
36
38
|
Scroll: () => scroll_exports,
|
|
39
|
+
Shortcut: () => shortcut_exports,
|
|
37
40
|
Toast: () => toast_exports,
|
|
41
|
+
WulfFocusTrap: () => FocusTrap,
|
|
42
|
+
WulfShortcut: () => ShortcutManager,
|
|
38
43
|
createI18nManager: () => createI18nManager,
|
|
39
44
|
default: () => mask_default,
|
|
40
45
|
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
|
|
@@ -57,6 +62,49 @@ var Wulf = (() => {
|
|
|
57
62
|
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
|
|
58
63
|
});
|
|
59
64
|
|
|
65
|
+
// src/common/AuditableComponent.ts
|
|
66
|
+
var AuditableComponent = class {
|
|
67
|
+
/**
|
|
68
|
+
* Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
|
|
69
|
+
*/
|
|
70
|
+
getAuditDisableHint() {
|
|
71
|
+
return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
|
|
75
|
+
* si l'audit est activé et que des contraintes manquent.
|
|
76
|
+
*/
|
|
77
|
+
runAuditWarning(enabled = true) {
|
|
78
|
+
if (!enabled) return [];
|
|
79
|
+
const warnings = this.audit();
|
|
80
|
+
if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
81
|
+
console.warn(
|
|
82
|
+
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
83
|
+
` + warnings.map((w) => ` - ${w}`).join("\n") + `
|
|
84
|
+
(${this.getAuditDisableHint()})`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return warnings;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
91
|
+
* pointe vers des éléments réellement présents dans le document.
|
|
92
|
+
*/
|
|
93
|
+
checkAriaIdReferences(element, attrName, warnings) {
|
|
94
|
+
const rawValue = element.getAttribute(attrName)?.trim();
|
|
95
|
+
if (!rawValue) return false;
|
|
96
|
+
const doc = element.ownerDocument || document;
|
|
97
|
+
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
98
|
+
const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
|
|
99
|
+
if (!isValid) {
|
|
100
|
+
warnings.push(
|
|
101
|
+
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return isValid;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
60
108
|
// src/mask/BaseInputMask.ts
|
|
61
109
|
function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
62
110
|
const isSecondArgInput = Boolean(
|
|
@@ -75,8 +123,9 @@ var Wulf = (() => {
|
|
|
75
123
|
options: inputOrOptions && typeof inputOrOptions === "object" && !("tagName" in inputOrOptions) ? inputOrOptions : {}
|
|
76
124
|
};
|
|
77
125
|
}
|
|
78
|
-
var BaseInputMask = class {
|
|
126
|
+
var BaseInputMask = class extends AuditableComponent {
|
|
79
127
|
constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
128
|
+
super();
|
|
80
129
|
this.ghost = null;
|
|
81
130
|
this.isWrapperCreated = false;
|
|
82
131
|
this.isDestroyed = false;
|
|
@@ -164,8 +213,10 @@ var Wulf = (() => {
|
|
|
164
213
|
const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
|
|
165
214
|
const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
|
|
166
215
|
const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
|
|
216
|
+
const dataAudit = this.getAttr("data-mask-audit");
|
|
167
217
|
const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
|
|
168
218
|
const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
|
|
219
|
+
const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
|
|
169
220
|
const isPassword = this.input.type === "password";
|
|
170
221
|
this.options = {
|
|
171
222
|
...otherOptions,
|
|
@@ -175,7 +226,8 @@ var Wulf = (() => {
|
|
|
175
226
|
copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
|
|
176
227
|
disabled: resolvedDisabled,
|
|
177
228
|
align: optAlign ?? (dataAlign || void 0),
|
|
178
|
-
emitNativeInput: options.emitNativeInput ?? true
|
|
229
|
+
emitNativeInput: options.emitNativeInput ?? true,
|
|
230
|
+
audit: resolvedAudit
|
|
179
231
|
};
|
|
180
232
|
if (this.options.showMaskOnFocus) {
|
|
181
233
|
this.wrapper.classList.add("mask-focus-only");
|
|
@@ -520,6 +572,48 @@ var Wulf = (() => {
|
|
|
520
572
|
getRawValue() {
|
|
521
573
|
return this.input.value;
|
|
522
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
|
|
577
|
+
* et retourne la liste des contraintes manquantes.
|
|
578
|
+
*/
|
|
579
|
+
audit() {
|
|
580
|
+
const warnings = [];
|
|
581
|
+
const doc = this.input.ownerDocument || document;
|
|
582
|
+
const ariaLabel = this.input.getAttribute("aria-label")?.trim();
|
|
583
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
|
|
584
|
+
const hasWrappingLabel = Boolean(this.input.closest("label"));
|
|
585
|
+
const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
|
|
586
|
+
let hasExplicitLabelFor = false;
|
|
587
|
+
if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
588
|
+
hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
|
|
589
|
+
} else if (this.input.id) {
|
|
590
|
+
hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
|
|
591
|
+
}
|
|
592
|
+
if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
|
|
593
|
+
warnings.push(
|
|
594
|
+
`\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
|
|
598
|
+
const extraWarnings = this.getSpecificAuditWarnings();
|
|
599
|
+
warnings.push(...extraWarnings);
|
|
600
|
+
return warnings;
|
|
601
|
+
}
|
|
602
|
+
getAuditPrefix() {
|
|
603
|
+
return `Wulf.Mask.${this.constructor.name || "InputMask"}`;
|
|
604
|
+
}
|
|
605
|
+
getAuditTargetLabel() {
|
|
606
|
+
return this.input.id ? `#${this.input.id}` : this.input.name ? `input[name="${this.input.name}"]` : "<input>";
|
|
607
|
+
}
|
|
608
|
+
getAuditDisableHint() {
|
|
609
|
+
return 'Passez { audit: false } ou data-mask-audit="false" pour d\xE9sactiver cet avertissement';
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Crochet permettant aux classes filles d'ajouter des vérifications d'audit spécifiques.
|
|
613
|
+
*/
|
|
614
|
+
getSpecificAuditWarnings() {
|
|
615
|
+
return [];
|
|
616
|
+
}
|
|
523
617
|
/**
|
|
524
618
|
* Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
|
|
525
619
|
*/
|
|
@@ -1314,6 +1408,19 @@ var Wulf = (() => {
|
|
|
1314
1408
|
this.bindEvents();
|
|
1315
1409
|
this.lastValue = this.input.value;
|
|
1316
1410
|
this.syncInitialValue();
|
|
1411
|
+
this.runAuditWarning(this.options.audit);
|
|
1412
|
+
}
|
|
1413
|
+
getSpecificAuditWarnings() {
|
|
1414
|
+
const warnings = [];
|
|
1415
|
+
const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
|
|
1416
|
+
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
1417
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
1418
|
+
if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
|
|
1419
|
+
warnings.push(
|
|
1420
|
+
"Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
return warnings;
|
|
1317
1424
|
}
|
|
1318
1425
|
extractRawSnippet(snippet) {
|
|
1319
1426
|
return this.engine.extractRaw(snippet);
|
|
@@ -2163,6 +2270,7 @@ var Wulf = (() => {
|
|
|
2163
2270
|
isValid: true
|
|
2164
2271
|
});
|
|
2165
2272
|
}
|
|
2273
|
+
this.runAuditWarning(this.options.audit);
|
|
2166
2274
|
}
|
|
2167
2275
|
extractRawSnippet(snippet) {
|
|
2168
2276
|
const p = this.engine.parse(snippet);
|
|
@@ -2745,6 +2853,7 @@ var Wulf = (() => {
|
|
|
2745
2853
|
if (!this.options.disabled) {
|
|
2746
2854
|
this.updateSuggestion();
|
|
2747
2855
|
}
|
|
2856
|
+
this.runAuditWarning(this.options.audit);
|
|
2748
2857
|
}
|
|
2749
2858
|
onNativeValueSet(_strVal) {
|
|
2750
2859
|
if (this.options.disabled) return;
|
|
@@ -3016,7 +3125,7 @@ var Wulf = (() => {
|
|
|
3016
3125
|
});
|
|
3017
3126
|
|
|
3018
3127
|
// src/common/LocalizedComponent.ts
|
|
3019
|
-
var LocalizedComponent = class {
|
|
3128
|
+
var LocalizedComponent = class extends AuditableComponent {
|
|
3020
3129
|
/**
|
|
3021
3130
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
3022
3131
|
*/
|
|
@@ -3068,6 +3177,7 @@ var Wulf = (() => {
|
|
|
3068
3177
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
3069
3178
|
}
|
|
3070
3179
|
constructor(i18nOverrides) {
|
|
3180
|
+
super();
|
|
3071
3181
|
this.i18nOverrides = i18nOverrides;
|
|
3072
3182
|
}
|
|
3073
3183
|
/**
|
|
@@ -3217,7 +3327,7 @@ var Wulf = (() => {
|
|
|
3217
3327
|
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
3218
3328
|
}
|
|
3219
3329
|
this.root = resolvedElement;
|
|
3220
|
-
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel);
|
|
3330
|
+
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
|
|
3221
3331
|
this.options = {
|
|
3222
3332
|
axis: options?.axis || "y",
|
|
3223
3333
|
autoHide: options?.autoHide ?? true,
|
|
@@ -3232,7 +3342,8 @@ var Wulf = (() => {
|
|
|
3232
3342
|
onTotalScroll: options?.onTotalScroll || (() => {
|
|
3233
3343
|
}),
|
|
3234
3344
|
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
3235
|
-
})
|
|
3345
|
+
}),
|
|
3346
|
+
audit: options?.audit ?? true
|
|
3236
3347
|
};
|
|
3237
3348
|
this.boundOnScroll = this.handleScroll.bind(this);
|
|
3238
3349
|
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
@@ -3247,6 +3358,7 @@ var Wulf = (() => {
|
|
|
3247
3358
|
this.setupEventListeners();
|
|
3248
3359
|
this.setupObserver();
|
|
3249
3360
|
this.update();
|
|
3361
|
+
this.runAuditWarning(this.options.audit);
|
|
3250
3362
|
}
|
|
3251
3363
|
/**
|
|
3252
3364
|
* Prépare le viewport défilant sans altérer les éléments enfants.
|
|
@@ -3667,6 +3779,35 @@ var Wulf = (() => {
|
|
|
3667
3779
|
behavior
|
|
3668
3780
|
});
|
|
3669
3781
|
}
|
|
3782
|
+
/**
|
|
3783
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
|
|
3784
|
+
* et retourne la liste des contraintes manquantes.
|
|
3785
|
+
*/
|
|
3786
|
+
audit() {
|
|
3787
|
+
const warnings = [];
|
|
3788
|
+
const hasViewportLabelledby = this.checkAriaIdReferences(this.viewport, "aria-labelledby", warnings);
|
|
3789
|
+
const hasRootLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
|
|
3790
|
+
const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
|
|
3791
|
+
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
3792
|
+
const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
|
|
3793
|
+
if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
3794
|
+
warnings.push(
|
|
3795
|
+
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour d\xE9crire la zone d\xE9filable (WCAG 4.1.2)."
|
|
3796
|
+
);
|
|
3797
|
+
}
|
|
3798
|
+
if (this.options.minThumbSize < 24) {
|
|
3799
|
+
warnings.push(
|
|
3800
|
+
`Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
|
|
3801
|
+
);
|
|
3802
|
+
}
|
|
3803
|
+
return warnings;
|
|
3804
|
+
}
|
|
3805
|
+
getAuditPrefix() {
|
|
3806
|
+
return "Wulf.Scroll";
|
|
3807
|
+
}
|
|
3808
|
+
getAuditTargetLabel() {
|
|
3809
|
+
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-scrollblock>`;
|
|
3810
|
+
}
|
|
3670
3811
|
/**
|
|
3671
3812
|
* Détruit le composant et libère toutes les ressources.
|
|
3672
3813
|
*/
|
|
@@ -3977,7 +4118,7 @@ var Wulf = (() => {
|
|
|
3977
4118
|
height: this.root.style.height,
|
|
3978
4119
|
width: this.root.style.width
|
|
3979
4120
|
};
|
|
3980
|
-
this.hasExplicitAriaLabel = Boolean(options.ariaLabel);
|
|
4121
|
+
this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
|
|
3981
4122
|
this.options = {
|
|
3982
4123
|
itemSelector: options.itemSelector || "> *",
|
|
3983
4124
|
columnWidth: options.columnWidth ?? 0,
|
|
@@ -3996,7 +4137,8 @@ var Wulf = (() => {
|
|
|
3996
4137
|
onLayout: options.onLayout || (() => {
|
|
3997
4138
|
}),
|
|
3998
4139
|
onItemPlaced: options.onItemPlaced || (() => {
|
|
3999
|
-
})
|
|
4140
|
+
}),
|
|
4141
|
+
audit: options.audit ?? true
|
|
4000
4142
|
};
|
|
4001
4143
|
const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
|
|
4002
4144
|
if (this.options.useNativeCSSGrid && supportsNativeCSS) {
|
|
@@ -4011,6 +4153,7 @@ var Wulf = (() => {
|
|
|
4011
4153
|
this.initObservers();
|
|
4012
4154
|
this.initImages();
|
|
4013
4155
|
this.layout();
|
|
4156
|
+
this.runAuditWarning(this.options.audit);
|
|
4014
4157
|
}
|
|
4015
4158
|
get items() {
|
|
4016
4159
|
return [...this._items];
|
|
@@ -4263,6 +4406,35 @@ var Wulf = (() => {
|
|
|
4263
4406
|
}, dur);
|
|
4264
4407
|
this.removeTimers.add(timerId);
|
|
4265
4408
|
}
|
|
4409
|
+
/**
|
|
4410
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
|
|
4411
|
+
* et retourne la liste des contraintes manquantes.
|
|
4412
|
+
*/
|
|
4413
|
+
audit() {
|
|
4414
|
+
const warnings = [];
|
|
4415
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
|
|
4416
|
+
const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
|
|
4417
|
+
if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
|
|
4418
|
+
warnings.push(
|
|
4419
|
+
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour qualifier la grille (WCAG 4.1.2)."
|
|
4420
|
+
);
|
|
4421
|
+
}
|
|
4422
|
+
const imagesWithoutAlt = Array.from(this.root.querySelectorAll("img")).filter(
|
|
4423
|
+
(img) => !img.hasAttribute("alt") && img.getAttribute("aria-hidden") !== "true"
|
|
4424
|
+
);
|
|
4425
|
+
if (imagesWithoutAlt.length > 0) {
|
|
4426
|
+
warnings.push(
|
|
4427
|
+
`${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
|
|
4428
|
+
);
|
|
4429
|
+
}
|
|
4430
|
+
return warnings;
|
|
4431
|
+
}
|
|
4432
|
+
getAuditPrefix() {
|
|
4433
|
+
return "Wulf.Masonry";
|
|
4434
|
+
}
|
|
4435
|
+
getAuditTargetLabel() {
|
|
4436
|
+
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-masonry>`;
|
|
4437
|
+
}
|
|
4266
4438
|
/**
|
|
4267
4439
|
* Libère les ressources, déconnecte les observateurs et nettoie les styles injectés.
|
|
4268
4440
|
*/
|
|
@@ -4366,8 +4538,9 @@ var Wulf = (() => {
|
|
|
4366
4538
|
|
|
4367
4539
|
// src/toast/ToastInstance.ts
|
|
4368
4540
|
var nextToastId = 1;
|
|
4369
|
-
var ToastInstance = class {
|
|
4541
|
+
var ToastInstance = class extends AuditableComponent {
|
|
4370
4542
|
constructor(options, onDismiss) {
|
|
4543
|
+
super();
|
|
4371
4544
|
this._isClosed = false;
|
|
4372
4545
|
this.timerId = null;
|
|
4373
4546
|
this.remainingTime = 0;
|
|
@@ -4384,10 +4557,45 @@ var Wulf = (() => {
|
|
|
4384
4557
|
}
|
|
4385
4558
|
this.element = this.createDOM();
|
|
4386
4559
|
this.bindEvents();
|
|
4560
|
+
this.runAuditWarning(options.audit !== false);
|
|
4387
4561
|
}
|
|
4388
4562
|
get isClosed() {
|
|
4389
4563
|
return this._isClosed;
|
|
4390
4564
|
}
|
|
4565
|
+
/**
|
|
4566
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
|
|
4567
|
+
* et retourne la liste des contraintes manquantes.
|
|
4568
|
+
*/
|
|
4569
|
+
audit() {
|
|
4570
|
+
const warnings = [];
|
|
4571
|
+
const hasTitle = Boolean(this.options.title && this.options.title.trim().length > 0);
|
|
4572
|
+
const hasMessage = Boolean(this.options.message && this.options.message.trim().length > 0);
|
|
4573
|
+
if (!hasTitle && !hasMessage) {
|
|
4574
|
+
warnings.push(
|
|
4575
|
+
"Contenu textuel vide : d\xE9finissez au moins un title ou un message pour que le lecteur d'\xE9cran puisse annoncer la notification (WCAG 4.1.3)."
|
|
4576
|
+
);
|
|
4577
|
+
}
|
|
4578
|
+
const duration = this.options.duration === void 0 ? 4e3 : this.options.duration;
|
|
4579
|
+
if (typeof duration === "number" && duration > 0 && duration < 5e3) {
|
|
4580
|
+
warnings.push(
|
|
4581
|
+
`Dur\xE9e d'affichage trop courte (duration: ${duration}ms) : pr\xE9voyez au moins 5000ms ou duration: false pour laisser le temps de lecture aux utilisateurs (WCAG 2.2.1).`
|
|
4582
|
+
);
|
|
4583
|
+
}
|
|
4584
|
+
const closable = this.options.closable ?? true;
|
|
4585
|
+
const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
|
|
4586
|
+
if (isPersistent && !closable && !this.options.closeOnClick) {
|
|
4587
|
+
warnings.push(
|
|
4588
|
+
"Notification persistante impossible \xE0 fermer : activez closable: true ou closeOnClick: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
|
|
4589
|
+
);
|
|
4590
|
+
}
|
|
4591
|
+
return warnings;
|
|
4592
|
+
}
|
|
4593
|
+
getAuditPrefix() {
|
|
4594
|
+
return "Wulf.Toast";
|
|
4595
|
+
}
|
|
4596
|
+
getAuditTargetLabel() {
|
|
4597
|
+
return `#${this.id}`;
|
|
4598
|
+
}
|
|
4391
4599
|
/**
|
|
4392
4600
|
* Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
|
|
4393
4601
|
*/
|
|
@@ -4748,6 +4956,15 @@ var Wulf = (() => {
|
|
|
4748
4956
|
|
|
4749
4957
|
// src/toast/Toast.ts
|
|
4750
4958
|
var Toast = class extends LocalizedComponent {
|
|
4959
|
+
audit() {
|
|
4960
|
+
return [];
|
|
4961
|
+
}
|
|
4962
|
+
getAuditPrefix() {
|
|
4963
|
+
return "Wulf.Toast";
|
|
4964
|
+
}
|
|
4965
|
+
getAuditTargetLabel() {
|
|
4966
|
+
return "Toast";
|
|
4967
|
+
}
|
|
4751
4968
|
/**
|
|
4752
4969
|
* Affiche une nouvelle notification Toast avec les options spécifiées.
|
|
4753
4970
|
*/
|
|
@@ -4780,7 +4997,961 @@ var Wulf = (() => {
|
|
|
4780
4997
|
i18n: toastI18n
|
|
4781
4998
|
});
|
|
4782
4999
|
}
|
|
5000
|
+
|
|
5001
|
+
// src/focus-trap/index.ts
|
|
5002
|
+
var focus_trap_exports = {};
|
|
5003
|
+
__export(focus_trap_exports, {
|
|
5004
|
+
FocusTrap: () => FocusTrap,
|
|
5005
|
+
default: () => FocusTrap
|
|
5006
|
+
});
|
|
5007
|
+
|
|
5008
|
+
// src/focus-trap/FocusTrap.ts
|
|
5009
|
+
var FOCUSABLE_SELECTOR = [
|
|
5010
|
+
"a[href]",
|
|
5011
|
+
"area[href]",
|
|
5012
|
+
"input:not([disabled])",
|
|
5013
|
+
"select:not([disabled])",
|
|
5014
|
+
"textarea:not([disabled])",
|
|
5015
|
+
"button:not([disabled])",
|
|
5016
|
+
"iframe",
|
|
5017
|
+
"object",
|
|
5018
|
+
"embed",
|
|
5019
|
+
'[contenteditable="true"]',
|
|
5020
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
5021
|
+
].join(",");
|
|
5022
|
+
var trapStack = [];
|
|
5023
|
+
var FocusTrap = class extends AuditableComponent {
|
|
5024
|
+
constructor(target, options = {}) {
|
|
5025
|
+
super();
|
|
5026
|
+
this.active = false;
|
|
5027
|
+
this.paused = false;
|
|
5028
|
+
this.previousActiveElement = null;
|
|
5029
|
+
this.inertSiblings = [];
|
|
5030
|
+
// Sentinelles anti-fuite de focus
|
|
5031
|
+
this.startSentinel = null;
|
|
5032
|
+
this.endSentinel = null;
|
|
5033
|
+
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
5034
|
+
if (!el || !(el instanceof HTMLElement)) {
|
|
5035
|
+
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
5036
|
+
}
|
|
5037
|
+
this.element = el;
|
|
5038
|
+
this.options = {
|
|
5039
|
+
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
5040
|
+
returnFocus: options.returnFocus ?? true,
|
|
5041
|
+
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
5042
|
+
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
5043
|
+
allowOutsideClick: options.allowOutsideClick ?? false,
|
|
5044
|
+
setInert: options.setInert ?? false,
|
|
5045
|
+
onActivate: options.onActivate ?? (() => {
|
|
5046
|
+
}),
|
|
5047
|
+
onDeactivate: options.onDeactivate ?? (() => {
|
|
5048
|
+
}),
|
|
5049
|
+
audit: options.audit ?? true
|
|
5050
|
+
};
|
|
5051
|
+
this.handleKeyDownBound = this.handleKeyDown.bind(this);
|
|
5052
|
+
this.handleClickOutsideBound = this.handleClickOutside.bind(this);
|
|
5053
|
+
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
5054
|
+
this.runAuditWarning(this.options.audit);
|
|
5055
|
+
}
|
|
5056
|
+
/**
|
|
5057
|
+
* Vérifie si un élément est réellement focusable, visible et actif dans le DOM.
|
|
5058
|
+
*/
|
|
5059
|
+
isFocusable(el) {
|
|
5060
|
+
if (!el || !el.isConnected) return false;
|
|
5061
|
+
if (el.disabled) return false;
|
|
5062
|
+
if (el.closest("fieldset[disabled]") && !el.closest("legend")) return false;
|
|
5063
|
+
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
5064
|
+
if (el.hidden || el.closest("[hidden]")) return false;
|
|
5065
|
+
if (el.style.display === "none" || el.style.visibility === "hidden") return false;
|
|
5066
|
+
const style = window.getComputedStyle(el);
|
|
5067
|
+
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
5068
|
+
if (el.offsetWidth === 0 && el.offsetHeight === 0 && style.position !== "fixed") {
|
|
5069
|
+
return false;
|
|
5070
|
+
}
|
|
5071
|
+
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
5072
|
+
const group = Array.from(
|
|
5073
|
+
this.element.querySelectorAll(`input[type="radio"][name="${CSS.escape(el.name)}"]`)
|
|
5074
|
+
);
|
|
5075
|
+
const checked = group.find((r) => r.checked);
|
|
5076
|
+
if (checked) {
|
|
5077
|
+
return el === checked;
|
|
5078
|
+
}
|
|
5079
|
+
return el === group[0];
|
|
5080
|
+
}
|
|
5081
|
+
return true;
|
|
5082
|
+
}
|
|
5083
|
+
/**
|
|
5084
|
+
* Retourne tous les éléments focusables réels ordonnés dans le conteneur.
|
|
5085
|
+
*/
|
|
5086
|
+
getFocusableElements() {
|
|
5087
|
+
const rawElements = Array.from(this.element.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
5088
|
+
return rawElements.filter((el) => this.isFocusable(el));
|
|
5089
|
+
}
|
|
5090
|
+
/**
|
|
5091
|
+
* Active le trap.
|
|
5092
|
+
*/
|
|
5093
|
+
activate() {
|
|
5094
|
+
if (this.active) return this;
|
|
5095
|
+
const currentTop = trapStack[trapStack.length - 1];
|
|
5096
|
+
if (currentTop) {
|
|
5097
|
+
currentTop.pause();
|
|
5098
|
+
}
|
|
5099
|
+
this.active = true;
|
|
5100
|
+
this.paused = false;
|
|
5101
|
+
trapStack.push(this);
|
|
5102
|
+
this.previousActiveElement = document.activeElement;
|
|
5103
|
+
this.setupSentinels();
|
|
5104
|
+
if (this.options.setInert) {
|
|
5105
|
+
this.applyInert();
|
|
5106
|
+
}
|
|
5107
|
+
document.addEventListener("keydown", this.handleKeyDownBound, true);
|
|
5108
|
+
document.addEventListener("focusin", this.handleFocusInBound, true);
|
|
5109
|
+
if (!this.options.allowOutsideClick) {
|
|
5110
|
+
document.addEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
5111
|
+
document.addEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
5112
|
+
}
|
|
5113
|
+
this.applyInitialFocus();
|
|
5114
|
+
this.runAuditWarning(this.options.audit);
|
|
5115
|
+
this.options.onActivate();
|
|
5116
|
+
return this;
|
|
5117
|
+
}
|
|
5118
|
+
/**
|
|
5119
|
+
* Désactive le trap et libère les écouteurs.
|
|
5120
|
+
*/
|
|
5121
|
+
deactivate() {
|
|
5122
|
+
if (!this.active) return this;
|
|
5123
|
+
this.active = false;
|
|
5124
|
+
this.paused = false;
|
|
5125
|
+
const index = trapStack.indexOf(this);
|
|
5126
|
+
if (index !== -1) {
|
|
5127
|
+
trapStack.splice(index, 1);
|
|
5128
|
+
}
|
|
5129
|
+
const nextTop = trapStack[trapStack.length - 1];
|
|
5130
|
+
if (nextTop) {
|
|
5131
|
+
nextTop.unpause();
|
|
5132
|
+
}
|
|
5133
|
+
document.removeEventListener("keydown", this.handleKeyDownBound, true);
|
|
5134
|
+
document.removeEventListener("focusin", this.handleFocusInBound, true);
|
|
5135
|
+
document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
5136
|
+
document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
5137
|
+
this.removeSentinels();
|
|
5138
|
+
this.removeInert();
|
|
5139
|
+
if (this.options.returnFocus) {
|
|
5140
|
+
this.restoreFocus();
|
|
5141
|
+
}
|
|
5142
|
+
this.options.onDeactivate();
|
|
5143
|
+
return this;
|
|
5144
|
+
}
|
|
5145
|
+
/**
|
|
5146
|
+
* Met en pause le trap (utilisé quand un trap fils s'ouvre au-dessus).
|
|
5147
|
+
*/
|
|
5148
|
+
pause() {
|
|
5149
|
+
this.paused = true;
|
|
5150
|
+
}
|
|
5151
|
+
/**
|
|
5152
|
+
* Sort de pause.
|
|
5153
|
+
*/
|
|
5154
|
+
unpause() {
|
|
5155
|
+
this.paused = false;
|
|
5156
|
+
}
|
|
5157
|
+
/**
|
|
5158
|
+
* Indique si le trap est actuellement actif et non en pause.
|
|
5159
|
+
*/
|
|
5160
|
+
isActive() {
|
|
5161
|
+
return this.active && !this.paused;
|
|
5162
|
+
}
|
|
5163
|
+
/**
|
|
5164
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA du conteneur FocusTrap
|
|
5165
|
+
* et retourne la liste des contraintes manquantes.
|
|
5166
|
+
*/
|
|
5167
|
+
audit() {
|
|
5168
|
+
const warnings = [];
|
|
5169
|
+
const role = this.element.getAttribute("role");
|
|
5170
|
+
const isNativeDialog = this.element.tagName.toLowerCase() === "dialog";
|
|
5171
|
+
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
5172
|
+
if (!isNativeDialog && (!role || !validRoles.includes(role))) {
|
|
5173
|
+
warnings.push(
|
|
5174
|
+
'R\xF4le s\xE9mantique manquant ou inadapt\xE9 : d\xE9finissez role="dialog" (ou "alertdialog", "menu", "listbox") sur le conteneur.'
|
|
5175
|
+
);
|
|
5176
|
+
}
|
|
5177
|
+
if ((isNativeDialog || role === "dialog" || role === "alertdialog") && this.element.getAttribute("aria-modal") !== "true") {
|
|
5178
|
+
warnings.push(
|
|
5179
|
+
'Isolation modale manquante : d\xE9finissez aria-modal="true" sur le conteneur de dialogue (WCAG 4.1.2).'
|
|
5180
|
+
);
|
|
5181
|
+
}
|
|
5182
|
+
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
5183
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
|
|
5184
|
+
if (!ariaLabel && !hasValidLabelledby) {
|
|
5185
|
+
warnings.push(
|
|
5186
|
+
'Nom accessible manquant : d\xE9finissez aria-labelledby="id-titre" ou aria-label="..." sur le conteneur (WCAG 4.1.2).'
|
|
5187
|
+
);
|
|
5188
|
+
}
|
|
5189
|
+
return warnings;
|
|
5190
|
+
}
|
|
5191
|
+
getAuditPrefix() {
|
|
5192
|
+
return "Wulf.FocusTrap";
|
|
5193
|
+
}
|
|
5194
|
+
getAuditTargetLabel() {
|
|
5195
|
+
return this.element.id ? `#${this.element.id}` : `<${this.element.tagName.toLowerCase()}>`;
|
|
5196
|
+
}
|
|
5197
|
+
/**
|
|
5198
|
+
* Détruit l'instance proprement.
|
|
5199
|
+
*/
|
|
5200
|
+
destroy() {
|
|
5201
|
+
this.deactivate();
|
|
5202
|
+
}
|
|
5203
|
+
// --- Implémentation interne ---
|
|
5204
|
+
handleKeyDown(e) {
|
|
5205
|
+
if (!this.isActive()) return;
|
|
5206
|
+
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
5207
|
+
e.preventDefault();
|
|
5208
|
+
e.stopPropagation();
|
|
5209
|
+
this.deactivate();
|
|
5210
|
+
return;
|
|
5211
|
+
}
|
|
5212
|
+
if (e.key !== "Tab") return;
|
|
5213
|
+
const focusables = this.getFocusableElements();
|
|
5214
|
+
if (focusables.length === 0) {
|
|
5215
|
+
e.preventDefault();
|
|
5216
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5217
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5218
|
+
}
|
|
5219
|
+
this.element.focus();
|
|
5220
|
+
return;
|
|
5221
|
+
}
|
|
5222
|
+
const first = focusables[0];
|
|
5223
|
+
const last = focusables[focusables.length - 1];
|
|
5224
|
+
const current = document.activeElement;
|
|
5225
|
+
if (!e.shiftKey && (current === last || !this.element.contains(current))) {
|
|
5226
|
+
e.preventDefault();
|
|
5227
|
+
first.focus();
|
|
5228
|
+
} else if (e.shiftKey && (current === first || !this.element.contains(current))) {
|
|
5229
|
+
e.preventDefault();
|
|
5230
|
+
last.focus();
|
|
5231
|
+
}
|
|
5232
|
+
}
|
|
5233
|
+
handleFocusIn(e) {
|
|
5234
|
+
if (!this.isActive()) return;
|
|
5235
|
+
const target = e.target;
|
|
5236
|
+
if (!target) return;
|
|
5237
|
+
if (target === this.startSentinel) {
|
|
5238
|
+
const focusables = this.getFocusableElements();
|
|
5239
|
+
if (focusables.length > 0) {
|
|
5240
|
+
focusables[focusables.length - 1].focus();
|
|
5241
|
+
} else {
|
|
5242
|
+
this.element.focus();
|
|
5243
|
+
}
|
|
5244
|
+
return;
|
|
5245
|
+
}
|
|
5246
|
+
if (target === this.endSentinel) {
|
|
5247
|
+
const focusables = this.getFocusableElements();
|
|
5248
|
+
if (focusables.length > 0) {
|
|
5249
|
+
focusables[0].focus();
|
|
5250
|
+
} else {
|
|
5251
|
+
this.element.focus();
|
|
5252
|
+
}
|
|
5253
|
+
return;
|
|
5254
|
+
}
|
|
5255
|
+
if (!this.element.contains(target)) {
|
|
5256
|
+
const focusables = this.getFocusableElements();
|
|
5257
|
+
if (focusables.length > 0) {
|
|
5258
|
+
focusables[0].focus();
|
|
5259
|
+
} else {
|
|
5260
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5261
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5262
|
+
}
|
|
5263
|
+
this.element.focus();
|
|
5264
|
+
}
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
handleClickOutside(e) {
|
|
5268
|
+
if (!this.isActive()) return;
|
|
5269
|
+
const target = e.target;
|
|
5270
|
+
if (target && !this.element.contains(target)) {
|
|
5271
|
+
e.preventDefault();
|
|
5272
|
+
e.stopPropagation();
|
|
5273
|
+
}
|
|
5274
|
+
}
|
|
5275
|
+
setupSentinels() {
|
|
5276
|
+
if (!this.startSentinel) {
|
|
5277
|
+
this.startSentinel = document.createElement("span");
|
|
5278
|
+
this.startSentinel.setAttribute("tabindex", "0");
|
|
5279
|
+
this.startSentinel.setAttribute("aria-hidden", "true");
|
|
5280
|
+
this.startSentinel.className = "wulf-sentinel-start";
|
|
5281
|
+
this.startSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
5282
|
+
}
|
|
5283
|
+
if (!this.endSentinel) {
|
|
5284
|
+
this.endSentinel = document.createElement("span");
|
|
5285
|
+
this.endSentinel.setAttribute("tabindex", "0");
|
|
5286
|
+
this.endSentinel.setAttribute("aria-hidden", "true");
|
|
5287
|
+
this.endSentinel.className = "wulf-sentinel-end";
|
|
5288
|
+
this.endSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
5289
|
+
}
|
|
5290
|
+
if (this.element.parentNode) {
|
|
5291
|
+
this.element.parentNode.insertBefore(this.startSentinel, this.element);
|
|
5292
|
+
this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
|
|
5293
|
+
}
|
|
5294
|
+
}
|
|
5295
|
+
removeSentinels() {
|
|
5296
|
+
this.startSentinel?.remove();
|
|
5297
|
+
this.endSentinel?.remove();
|
|
5298
|
+
this.startSentinel = null;
|
|
5299
|
+
this.endSentinel = null;
|
|
5300
|
+
}
|
|
5301
|
+
applyInert() {
|
|
5302
|
+
this.inertSiblings = [];
|
|
5303
|
+
let parent = this.element.parentElement;
|
|
5304
|
+
let currentChild = this.element;
|
|
5305
|
+
while (parent && parent !== document.body) {
|
|
5306
|
+
currentChild = parent;
|
|
5307
|
+
parent = parent.parentElement;
|
|
5308
|
+
}
|
|
5309
|
+
if (parent === document.body) {
|
|
5310
|
+
Array.from(document.body.children).forEach((child) => {
|
|
5311
|
+
if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
|
|
5312
|
+
child.setAttribute("inert", "");
|
|
5313
|
+
this.inertSiblings.push(child);
|
|
5314
|
+
}
|
|
5315
|
+
});
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
removeInert() {
|
|
5319
|
+
this.inertSiblings.forEach((el) => el.removeAttribute("inert"));
|
|
5320
|
+
this.inertSiblings = [];
|
|
5321
|
+
}
|
|
5322
|
+
applyInitialFocus() {
|
|
5323
|
+
if (this.options.initialFocus === false) return;
|
|
5324
|
+
let targetEl = null;
|
|
5325
|
+
if (typeof this.options.initialFocus === "string") {
|
|
5326
|
+
targetEl = this.element.querySelector(this.options.initialFocus);
|
|
5327
|
+
} else if (this.options.initialFocus instanceof HTMLElement) {
|
|
5328
|
+
targetEl = this.options.initialFocus;
|
|
5329
|
+
}
|
|
5330
|
+
if (targetEl && this.isFocusable(targetEl)) {
|
|
5331
|
+
targetEl.focus();
|
|
5332
|
+
return;
|
|
5333
|
+
}
|
|
5334
|
+
const focusables = this.getFocusableElements();
|
|
5335
|
+
if (focusables.length > 0) {
|
|
5336
|
+
focusables[0].focus();
|
|
5337
|
+
} else {
|
|
5338
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5339
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5340
|
+
}
|
|
5341
|
+
this.element.focus();
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
restoreFocus() {
|
|
5345
|
+
if (this.previousActiveElement && this.previousActiveElement.isConnected) {
|
|
5346
|
+
this.previousActiveElement.focus();
|
|
5347
|
+
return;
|
|
5348
|
+
}
|
|
5349
|
+
if (this.options.fallbackReturnFocus) {
|
|
5350
|
+
const fallback = typeof this.options.fallbackReturnFocus === "string" ? document.querySelector(this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
5351
|
+
if (fallback && fallback.isConnected) {
|
|
5352
|
+
fallback.focus();
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
};
|
|
5357
|
+
|
|
5358
|
+
// src/focus-trap/index.ts
|
|
5359
|
+
if (typeof window !== "undefined") {
|
|
5360
|
+
const win = window;
|
|
5361
|
+
const wulfNamespace = win.Wulf || {};
|
|
5362
|
+
win.Wulf = wulfNamespace;
|
|
5363
|
+
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
5364
|
+
FocusTrap
|
|
5365
|
+
});
|
|
5366
|
+
}
|
|
5367
|
+
|
|
5368
|
+
// src/shortcut/index.ts
|
|
5369
|
+
var shortcut_exports = {};
|
|
5370
|
+
__export(shortcut_exports, {
|
|
5371
|
+
ShortcutFormatter: () => ShortcutFormatter,
|
|
5372
|
+
ShortcutManager: () => ShortcutManager,
|
|
5373
|
+
default: () => ShortcutManager
|
|
5374
|
+
});
|
|
5375
|
+
|
|
5376
|
+
// src/shortcut/ShortcutFormatter.ts
|
|
5377
|
+
var ShortcutFormatter = class _ShortcutFormatter {
|
|
5378
|
+
/**
|
|
5379
|
+
* Détecte si l'environnement d'exécution actuel est un environnement Apple (macOS / iOS / iPadOS).
|
|
5380
|
+
*/
|
|
5381
|
+
static isApple() {
|
|
5382
|
+
if (typeof navigator === "undefined") {
|
|
5383
|
+
return false;
|
|
5384
|
+
}
|
|
5385
|
+
const uaData = navigator.userAgentData;
|
|
5386
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
5387
|
+
const p = uaData.platform.toLowerCase();
|
|
5388
|
+
if (p.includes("mac") || p.includes("ios")) {
|
|
5389
|
+
return true;
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5392
|
+
const platform = (navigator.platform || "").toLowerCase();
|
|
5393
|
+
if (platform.includes("mac") || platform.includes("iphone") || platform.includes("ipad") || platform.includes("ipod")) {
|
|
5394
|
+
return true;
|
|
5395
|
+
}
|
|
5396
|
+
const ua = (navigator.userAgent || "").toLowerCase();
|
|
5397
|
+
return ua.includes("macintosh") || ua.includes("mac os x") || ua.includes("ipad") || ua.includes("iphone");
|
|
5398
|
+
}
|
|
5399
|
+
/**
|
|
5400
|
+
* Normalise un nom de touche unitaire pour les comparaisons.
|
|
5401
|
+
*/
|
|
5402
|
+
static normalizeKeyName(key) {
|
|
5403
|
+
const k = key.trim().toLowerCase();
|
|
5404
|
+
switch (k) {
|
|
5405
|
+
case "esc":
|
|
5406
|
+
return "escape";
|
|
5407
|
+
case "return":
|
|
5408
|
+
return "enter";
|
|
5409
|
+
case "space":
|
|
5410
|
+
case "spacebar":
|
|
5411
|
+
return " ";
|
|
5412
|
+
case "del":
|
|
5413
|
+
return "delete";
|
|
5414
|
+
case "ins":
|
|
5415
|
+
return "insert";
|
|
5416
|
+
case "up":
|
|
5417
|
+
return "arrowup";
|
|
5418
|
+
case "down":
|
|
5419
|
+
return "arrowdown";
|
|
5420
|
+
case "left":
|
|
5421
|
+
return "arrowleft";
|
|
5422
|
+
case "right":
|
|
5423
|
+
return "arrowright";
|
|
5424
|
+
default:
|
|
5425
|
+
return k;
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
/**
|
|
5429
|
+
* Parse une chaîne de combinaison (ex: "Mod+K", "g i", "Shift+?", "Alt++")
|
|
5430
|
+
* et retourne la liste des étapes normalisées nécessaires au déclenchement.
|
|
5431
|
+
*/
|
|
5432
|
+
static parseCombo(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
5433
|
+
const trimmed = combo.trim();
|
|
5434
|
+
if (!trimmed) {
|
|
5435
|
+
return [];
|
|
5436
|
+
}
|
|
5437
|
+
const stepsRaw = trimmed.split(/\s+/);
|
|
5438
|
+
const steps = [];
|
|
5439
|
+
for (const rawStep of stepsRaw) {
|
|
5440
|
+
const tokens = [];
|
|
5441
|
+
let currentToken = "";
|
|
5442
|
+
for (let i = 0; i < rawStep.length; i++) {
|
|
5443
|
+
const char = rawStep[i];
|
|
5444
|
+
if (char === "+") {
|
|
5445
|
+
if (currentToken === "" && tokens.length > 0) {
|
|
5446
|
+
tokens.push("+");
|
|
5447
|
+
} else if (currentToken !== "") {
|
|
5448
|
+
tokens.push(currentToken);
|
|
5449
|
+
currentToken = "";
|
|
5450
|
+
}
|
|
5451
|
+
} else {
|
|
5452
|
+
currentToken += char;
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
if (currentToken !== "") {
|
|
5456
|
+
tokens.push(currentToken);
|
|
5457
|
+
}
|
|
5458
|
+
let ctrl = false;
|
|
5459
|
+
let alt = false;
|
|
5460
|
+
let shift = false;
|
|
5461
|
+
let meta = false;
|
|
5462
|
+
let mainKey = "";
|
|
5463
|
+
for (const token of tokens) {
|
|
5464
|
+
const lower = token.trim().toLowerCase();
|
|
5465
|
+
if (lower === "ctrl" || lower === "control") {
|
|
5466
|
+
ctrl = true;
|
|
5467
|
+
} else if (lower === "alt" || lower === "option" || lower === "opt") {
|
|
5468
|
+
alt = true;
|
|
5469
|
+
} else if (lower === "shift" || lower === "maj") {
|
|
5470
|
+
shift = true;
|
|
5471
|
+
} else if (lower === "cmd" || lower === "command" || lower === "meta" || lower === "win" || lower === "super") {
|
|
5472
|
+
meta = true;
|
|
5473
|
+
} else if (lower === "mod" || lower === "$mod") {
|
|
5474
|
+
if (isApple) {
|
|
5475
|
+
meta = true;
|
|
5476
|
+
} else {
|
|
5477
|
+
ctrl = true;
|
|
5478
|
+
}
|
|
5479
|
+
} else {
|
|
5480
|
+
mainKey = _ShortcutFormatter.normalizeKeyName(token);
|
|
5481
|
+
}
|
|
5482
|
+
}
|
|
5483
|
+
steps.push({
|
|
5484
|
+
ctrl,
|
|
5485
|
+
alt,
|
|
5486
|
+
shift,
|
|
5487
|
+
meta,
|
|
5488
|
+
key: mainKey
|
|
5489
|
+
});
|
|
5490
|
+
}
|
|
5491
|
+
return steps;
|
|
5492
|
+
}
|
|
5493
|
+
/**
|
|
5494
|
+
* Formate une combinaison brute en libellé soigné et lisible pour l'OS cible.
|
|
5495
|
+
* Ex: "Mod+Shift+P" -> macOS: "⇧⌘P", Windows: "Ctrl+Shift+P"
|
|
5496
|
+
* Ex: "g i" -> "g puis i" ou "g i"
|
|
5497
|
+
*/
|
|
5498
|
+
static format(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
5499
|
+
const steps = _ShortcutFormatter.parseCombo(combo, isApple);
|
|
5500
|
+
if (steps.length === 0) {
|
|
5501
|
+
return combo;
|
|
5502
|
+
}
|
|
5503
|
+
const formattedSteps = steps.map((step) => {
|
|
5504
|
+
const parts = [];
|
|
5505
|
+
if (isApple) {
|
|
5506
|
+
if (step.ctrl) parts.push("\u2303");
|
|
5507
|
+
if (step.alt) parts.push("\u2325");
|
|
5508
|
+
if (step.shift) parts.push("\u21E7");
|
|
5509
|
+
if (step.meta) parts.push("\u2318");
|
|
5510
|
+
const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, true);
|
|
5511
|
+
parts.push(keyDisplay);
|
|
5512
|
+
return parts.join("");
|
|
5513
|
+
} else {
|
|
5514
|
+
if (step.ctrl) parts.push("Ctrl");
|
|
5515
|
+
if (step.alt) parts.push("Alt");
|
|
5516
|
+
if (step.shift) parts.push("Shift");
|
|
5517
|
+
if (step.meta) parts.push("Win");
|
|
5518
|
+
const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, false);
|
|
5519
|
+
parts.push(keyDisplay);
|
|
5520
|
+
return parts.join("+");
|
|
5521
|
+
}
|
|
5522
|
+
});
|
|
5523
|
+
return formattedSteps.join(" ");
|
|
5524
|
+
}
|
|
5525
|
+
/**
|
|
5526
|
+
* Convertit un combo technique vers le format officiel WAI-ARIA `aria-keyshortcuts`.
|
|
5527
|
+
* Standard W3C : les modificateurs sont 'Control', 'Alt', 'Shift', 'Meta' et le séparateur est '+'.
|
|
5528
|
+
*/
|
|
5529
|
+
static toAriaKeyShortcuts(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
5530
|
+
const steps = _ShortcutFormatter.parseCombo(combo, isApple);
|
|
5531
|
+
return steps.map((step) => {
|
|
5532
|
+
const parts = [];
|
|
5533
|
+
if (step.ctrl) parts.push("Control");
|
|
5534
|
+
if (step.alt) parts.push("Alt");
|
|
5535
|
+
if (step.shift) parts.push("Shift");
|
|
5536
|
+
if (step.meta) parts.push("Meta");
|
|
5537
|
+
parts.push(_ShortcutFormatter.formatKeyDisplay(step.key, false));
|
|
5538
|
+
return parts.join("+");
|
|
5539
|
+
}).join(" ");
|
|
5540
|
+
}
|
|
5541
|
+
static formatKeyDisplay(key, isApple) {
|
|
5542
|
+
if (!key) return "";
|
|
5543
|
+
switch (key.toLowerCase()) {
|
|
5544
|
+
case "escape":
|
|
5545
|
+
return isApple ? "\u238B" : "Esc";
|
|
5546
|
+
case "enter":
|
|
5547
|
+
return isApple ? "\u21A9" : "Enter";
|
|
5548
|
+
case " ":
|
|
5549
|
+
return isApple ? "\u2423" : "Space";
|
|
5550
|
+
case "tab":
|
|
5551
|
+
return isApple ? "\u21E5" : "Tab";
|
|
5552
|
+
case "backspace":
|
|
5553
|
+
return isApple ? "\u232B" : "Backspace";
|
|
5554
|
+
case "delete":
|
|
5555
|
+
return isApple ? "\u2326" : "Suppr";
|
|
5556
|
+
case "arrowup":
|
|
5557
|
+
return "\u2191";
|
|
5558
|
+
case "arrowdown":
|
|
5559
|
+
return "\u2193";
|
|
5560
|
+
case "arrowleft":
|
|
5561
|
+
return "\u2190";
|
|
5562
|
+
case "arrowright":
|
|
5563
|
+
return "\u2192";
|
|
5564
|
+
default:
|
|
5565
|
+
return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
};
|
|
5569
|
+
|
|
5570
|
+
// src/shortcut/ShortcutManager.ts
|
|
5571
|
+
var ShortcutManager = class _ShortcutManager {
|
|
5572
|
+
constructor(options) {
|
|
5573
|
+
this.shortcuts = /* @__PURE__ */ new Map();
|
|
5574
|
+
this.scopeStack = [];
|
|
5575
|
+
this.sequenceBuffer = [];
|
|
5576
|
+
this.sequenceTimer = null;
|
|
5577
|
+
this.isListening = true;
|
|
5578
|
+
this.boundListener = null;
|
|
5579
|
+
this.idCounter = 0;
|
|
5580
|
+
this.options = {
|
|
5581
|
+
defaultScope: options?.defaultScope || "global",
|
|
5582
|
+
sequenceTimeout: options?.sequenceTimeout ?? 800,
|
|
5583
|
+
target: options?.target || (typeof window !== "undefined" ? window : {}),
|
|
5584
|
+
onError: options?.onError
|
|
5585
|
+
};
|
|
5586
|
+
this.scopeStack = [this.options.defaultScope];
|
|
5587
|
+
this.initListener();
|
|
5588
|
+
}
|
|
5589
|
+
/**
|
|
5590
|
+
* Vérifie si un élément DOM est une zone d'édition où la saisie de l'utilisateur
|
|
5591
|
+
* ne doit JAMAIS être interrompue ou détournée (Axiome Primordial).
|
|
5592
|
+
*/
|
|
5593
|
+
static isEditable(target) {
|
|
5594
|
+
if (!target || typeof target.tagName !== "string") {
|
|
5595
|
+
return false;
|
|
5596
|
+
}
|
|
5597
|
+
const el = target;
|
|
5598
|
+
const tagName = el.tagName.toUpperCase();
|
|
5599
|
+
if (tagName === "INPUT") {
|
|
5600
|
+
const type = el.type?.toLowerCase() || "text";
|
|
5601
|
+
const nonTextTypes = ["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"];
|
|
5602
|
+
return !nonTextTypes.includes(type);
|
|
5603
|
+
}
|
|
5604
|
+
if (tagName === "TEXTAREA" || tagName === "SELECT") {
|
|
5605
|
+
return true;
|
|
5606
|
+
}
|
|
5607
|
+
if (el.isContentEditable || el.getAttribute("contenteditable") === "true" || el.getAttribute("contenteditable") === "plaintext-only") {
|
|
5608
|
+
return true;
|
|
5609
|
+
}
|
|
5610
|
+
const role = el.getAttribute("role");
|
|
5611
|
+
if (role === "textbox" || role === "searchbox") {
|
|
5612
|
+
return true;
|
|
5613
|
+
}
|
|
5614
|
+
return false;
|
|
5615
|
+
}
|
|
5616
|
+
/**
|
|
5617
|
+
* Enregistre un ou plusieurs raccourcis clavier.
|
|
5618
|
+
* Retourne une fonction de nettoyage pour désenregistrer immédiatement.
|
|
5619
|
+
*/
|
|
5620
|
+
bind(definition) {
|
|
5621
|
+
const list = Array.isArray(definition) ? definition : [definition];
|
|
5622
|
+
const registeredIds = [];
|
|
5623
|
+
for (const def of list) {
|
|
5624
|
+
if (!def.combo || typeof def.handler !== "function") {
|
|
5625
|
+
continue;
|
|
5626
|
+
}
|
|
5627
|
+
const id = `wulf_shortcut_${++this.idCounter}`;
|
|
5628
|
+
const normalizedSteps = ShortcutFormatter.parseCombo(def.combo);
|
|
5629
|
+
const isSequence = normalizedSteps.length > 1;
|
|
5630
|
+
const formattedCombo = ShortcutFormatter.format(def.combo);
|
|
5631
|
+
const registered = {
|
|
5632
|
+
...def,
|
|
5633
|
+
id,
|
|
5634
|
+
scope: def.scope || "global",
|
|
5635
|
+
category: def.category || "G\xE9n\xE9ral",
|
|
5636
|
+
allowInEditable: def.allowInEditable ?? false,
|
|
5637
|
+
preventDefault: def.preventDefault ?? true,
|
|
5638
|
+
stopPropagation: def.stopPropagation ?? true,
|
|
5639
|
+
priority: def.priority ?? 0,
|
|
5640
|
+
formattedCombo,
|
|
5641
|
+
normalizedSteps,
|
|
5642
|
+
isSequence
|
|
5643
|
+
};
|
|
5644
|
+
this.shortcuts.set(id, registered);
|
|
5645
|
+
registeredIds.push(id);
|
|
5646
|
+
}
|
|
5647
|
+
return () => {
|
|
5648
|
+
for (const id of registeredIds) {
|
|
5649
|
+
this.shortcuts.delete(id);
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
/**
|
|
5654
|
+
* Retire tous les raccourcis correspondant à une combinaison et éventuellement un scope.
|
|
5655
|
+
*/
|
|
5656
|
+
unbind(combo, scope) {
|
|
5657
|
+
const formatted = ShortcutFormatter.format(combo);
|
|
5658
|
+
for (const [id, s] of this.shortcuts.entries()) {
|
|
5659
|
+
if (s.formattedCombo === formatted || s.combo.trim().toLowerCase() === combo.trim().toLowerCase()) {
|
|
5660
|
+
if (!scope || s.scope === scope) {
|
|
5661
|
+
this.shortcuts.delete(id);
|
|
5662
|
+
}
|
|
5663
|
+
}
|
|
5664
|
+
}
|
|
5665
|
+
}
|
|
5666
|
+
/**
|
|
5667
|
+
* Empile un nouveau scope actif (mode LIFO).
|
|
5668
|
+
* Seuls les raccourcis de ce scope (et les omniprésents '*') seront actifs.
|
|
5669
|
+
*/
|
|
5670
|
+
pushScope(scope) {
|
|
5671
|
+
if (scope && typeof scope === "string") {
|
|
5672
|
+
this.scopeStack.push(scope);
|
|
5673
|
+
this.clearSequenceBuffer();
|
|
5674
|
+
}
|
|
5675
|
+
}
|
|
5676
|
+
/**
|
|
5677
|
+
* Dépile le scope actuel et rétablit le précédent.
|
|
5678
|
+
* Si un paramètre `scope` est passé, ne retire que si le scope actuel correspond.
|
|
5679
|
+
*/
|
|
5680
|
+
popScope(scope) {
|
|
5681
|
+
if (this.scopeStack.length <= 1) {
|
|
5682
|
+
return this.scopeStack[0];
|
|
5683
|
+
}
|
|
5684
|
+
if (scope) {
|
|
5685
|
+
if (this.getScope() === scope) {
|
|
5686
|
+
const popped2 = this.scopeStack.pop();
|
|
5687
|
+
this.clearSequenceBuffer();
|
|
5688
|
+
return popped2;
|
|
5689
|
+
}
|
|
5690
|
+
return void 0;
|
|
5691
|
+
}
|
|
5692
|
+
const popped = this.scopeStack.pop();
|
|
5693
|
+
this.clearSequenceBuffer();
|
|
5694
|
+
return popped;
|
|
5695
|
+
}
|
|
5696
|
+
/**
|
|
5697
|
+
* Réinitialise brutalement la pile pour activer le scope spécifié.
|
|
5698
|
+
*/
|
|
5699
|
+
setScope(scope) {
|
|
5700
|
+
this.scopeStack = [scope || this.options.defaultScope];
|
|
5701
|
+
this.clearSequenceBuffer();
|
|
5702
|
+
}
|
|
5703
|
+
/**
|
|
5704
|
+
* Retourne le scope actuellement actif au sommet de la pile.
|
|
5705
|
+
*/
|
|
5706
|
+
getScope() {
|
|
5707
|
+
return this.scopeStack[this.scopeStack.length - 1] || this.options.defaultScope;
|
|
5708
|
+
}
|
|
5709
|
+
/**
|
|
5710
|
+
* Retourne une copie de la pile complète des scopes.
|
|
5711
|
+
*/
|
|
5712
|
+
getScopeStack() {
|
|
5713
|
+
return [...this.scopeStack];
|
|
5714
|
+
}
|
|
5715
|
+
/**
|
|
5716
|
+
* Met en pause l'écoute de tous les raccourcis.
|
|
5717
|
+
*/
|
|
5718
|
+
pause() {
|
|
5719
|
+
this.isListening = false;
|
|
5720
|
+
this.clearSequenceBuffer();
|
|
5721
|
+
}
|
|
5722
|
+
/**
|
|
5723
|
+
* Réactive l'écoute des raccourcis.
|
|
5724
|
+
*/
|
|
5725
|
+
resume() {
|
|
5726
|
+
this.isListening = true;
|
|
5727
|
+
}
|
|
5728
|
+
/**
|
|
5729
|
+
* Indique si le gestionnaire est actif et à l'écoute.
|
|
5730
|
+
*/
|
|
5731
|
+
isActive() {
|
|
5732
|
+
return this.isListening;
|
|
5733
|
+
}
|
|
5734
|
+
/**
|
|
5735
|
+
* Retourne le catalogue des raccourcis enregistrés (optionnellement filtré par scope).
|
|
5736
|
+
*/
|
|
5737
|
+
getRegistry(scope) {
|
|
5738
|
+
const list = [];
|
|
5739
|
+
for (const shortcut of this.shortcuts.values()) {
|
|
5740
|
+
if (!scope || shortcut.scope === scope || shortcut.scope === "*") {
|
|
5741
|
+
list.push({ ...shortcut });
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
return list;
|
|
5745
|
+
}
|
|
5746
|
+
/**
|
|
5747
|
+
* Associe l'attribut standard WAI-ARIA `aria-keyshortcuts` sur un élément DOM.
|
|
5748
|
+
*/
|
|
5749
|
+
attachAria(element, combo) {
|
|
5750
|
+
if (element && typeof element.setAttribute === "function") {
|
|
5751
|
+
const ariaValue = ShortcutFormatter.toAriaKeyShortcuts(combo);
|
|
5752
|
+
element.setAttribute("aria-keyshortcuts", ariaValue);
|
|
5753
|
+
}
|
|
5754
|
+
}
|
|
5755
|
+
/**
|
|
5756
|
+
* Formate une combinaison brute selon l'OS courant ("⌘K" ou "Ctrl+K").
|
|
5757
|
+
*/
|
|
5758
|
+
static format(combo, isApple) {
|
|
5759
|
+
return ShortcutFormatter.format(combo, isApple);
|
|
5760
|
+
}
|
|
5761
|
+
/**
|
|
5762
|
+
* Détruit le gestionnaire : supprime les écouteurs du DOM et vide toute la mémoire.
|
|
5763
|
+
*/
|
|
5764
|
+
destroy() {
|
|
5765
|
+
this.pause();
|
|
5766
|
+
this.removeListener();
|
|
5767
|
+
this.shortcuts.clear();
|
|
5768
|
+
this.scopeStack = [];
|
|
5769
|
+
this.clearSequenceBuffer();
|
|
5770
|
+
}
|
|
5771
|
+
// --- Implémentation Interne ---
|
|
5772
|
+
initListener() {
|
|
5773
|
+
if (typeof window === "undefined" || !this.options.target) {
|
|
5774
|
+
return;
|
|
5775
|
+
}
|
|
5776
|
+
this.boundListener = (event) => this.handleKeyDown(event);
|
|
5777
|
+
const target = this.options.target;
|
|
5778
|
+
if (typeof target.addEventListener === "function") {
|
|
5779
|
+
target.addEventListener("keydown", this.boundListener, false);
|
|
5780
|
+
}
|
|
5781
|
+
}
|
|
5782
|
+
removeListener() {
|
|
5783
|
+
if (this.boundListener && this.options.target) {
|
|
5784
|
+
const target = this.options.target;
|
|
5785
|
+
if (typeof target.removeEventListener === "function") {
|
|
5786
|
+
target.removeEventListener("keydown", this.boundListener, false);
|
|
5787
|
+
}
|
|
5788
|
+
this.boundListener = null;
|
|
5789
|
+
}
|
|
5790
|
+
}
|
|
5791
|
+
handleKeyDown(event) {
|
|
5792
|
+
if (!this.isListening) {
|
|
5793
|
+
return;
|
|
5794
|
+
}
|
|
5795
|
+
const k = (event.key || "").toLowerCase();
|
|
5796
|
+
if (["control", "alt", "shift", "meta"].includes(k)) {
|
|
5797
|
+
return;
|
|
5798
|
+
}
|
|
5799
|
+
const currentScope = this.getScope();
|
|
5800
|
+
const isEditable = _ShortcutManager.isEditable(event.target);
|
|
5801
|
+
const currentStep = {
|
|
5802
|
+
ctrl: event.ctrlKey,
|
|
5803
|
+
alt: event.altKey,
|
|
5804
|
+
shift: event.shiftKey,
|
|
5805
|
+
meta: event.metaKey,
|
|
5806
|
+
key: ShortcutFormatter.normalizeKeyName(event.key || "")
|
|
5807
|
+
};
|
|
5808
|
+
const now = Date.now();
|
|
5809
|
+
if (this.sequenceBuffer.length > 0) {
|
|
5810
|
+
const last = this.sequenceBuffer[this.sequenceBuffer.length - 1];
|
|
5811
|
+
if (now - last.timestamp > this.options.sequenceTimeout) {
|
|
5812
|
+
this.clearSequenceBuffer();
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5815
|
+
const activeCandidates = this.getActiveShortcuts(currentScope, isEditable);
|
|
5816
|
+
const proposedSequence = [...this.sequenceBuffer.map((b) => b.step), currentStep];
|
|
5817
|
+
const matchingSequence = this.findMatchingSequence(activeCandidates, proposedSequence);
|
|
5818
|
+
if (matchingSequence) {
|
|
5819
|
+
this.clearSequenceBuffer();
|
|
5820
|
+
this.executeShortcut(matchingSequence, event, currentScope, true);
|
|
5821
|
+
return;
|
|
5822
|
+
}
|
|
5823
|
+
if (this.isPrefixOfAnySequence(activeCandidates, proposedSequence)) {
|
|
5824
|
+
this.sequenceBuffer.push({ step: currentStep, timestamp: now });
|
|
5825
|
+
this.resetSequenceTimer();
|
|
5826
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !isEditable) {
|
|
5827
|
+
event.preventDefault();
|
|
5828
|
+
}
|
|
5829
|
+
return;
|
|
5830
|
+
}
|
|
5831
|
+
this.clearSequenceBuffer();
|
|
5832
|
+
const matchingChord = this.findMatchingChord(activeCandidates, currentStep, event);
|
|
5833
|
+
if (matchingChord) {
|
|
5834
|
+
this.executeShortcut(matchingChord, event, currentScope, false);
|
|
5835
|
+
}
|
|
5836
|
+
}
|
|
5837
|
+
getActiveShortcuts(currentScope, isEditable) {
|
|
5838
|
+
const list = [];
|
|
5839
|
+
for (const shortcut of this.shortcuts.values()) {
|
|
5840
|
+
if (shortcut.scope !== currentScope && shortcut.scope !== "*") {
|
|
5841
|
+
continue;
|
|
5842
|
+
}
|
|
5843
|
+
if (isEditable && !shortcut.allowInEditable) {
|
|
5844
|
+
continue;
|
|
5845
|
+
}
|
|
5846
|
+
list.push(shortcut);
|
|
5847
|
+
}
|
|
5848
|
+
return list.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
5849
|
+
}
|
|
5850
|
+
stepMatches(step, eventStep, rawEvent) {
|
|
5851
|
+
if (step.ctrl !== eventStep.ctrl) return false;
|
|
5852
|
+
if (step.alt !== eventStep.alt) return false;
|
|
5853
|
+
if (step.meta !== eventStep.meta) return false;
|
|
5854
|
+
const keyMatches = step.key === eventStep.key || rawEvent && step.key === rawEvent.key.toLowerCase();
|
|
5855
|
+
if (!keyMatches) return false;
|
|
5856
|
+
if (step.shift === eventStep.shift) {
|
|
5857
|
+
return true;
|
|
5858
|
+
}
|
|
5859
|
+
if (!step.shift && eventStep.shift) {
|
|
5860
|
+
if (rawEvent && rawEvent.key === step.key) {
|
|
5861
|
+
return true;
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
return false;
|
|
5865
|
+
}
|
|
5866
|
+
findMatchingChord(candidates, currentStep, rawEvent) {
|
|
5867
|
+
for (const candidate of candidates) {
|
|
5868
|
+
if (candidate.isSequence || candidate.normalizedSteps.length !== 1) {
|
|
5869
|
+
continue;
|
|
5870
|
+
}
|
|
5871
|
+
const step = candidate.normalizedSteps[0];
|
|
5872
|
+
if (this.stepMatches(step, currentStep, rawEvent)) {
|
|
5873
|
+
return candidate;
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
return null;
|
|
5877
|
+
}
|
|
5878
|
+
findMatchingSequence(candidates, proposed) {
|
|
5879
|
+
for (const candidate of candidates) {
|
|
5880
|
+
if (!candidate.isSequence || candidate.normalizedSteps.length !== proposed.length) {
|
|
5881
|
+
continue;
|
|
5882
|
+
}
|
|
5883
|
+
let allMatch = true;
|
|
5884
|
+
for (let i = 0; i < proposed.length; i++) {
|
|
5885
|
+
if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
|
|
5886
|
+
allMatch = false;
|
|
5887
|
+
break;
|
|
5888
|
+
}
|
|
5889
|
+
}
|
|
5890
|
+
if (allMatch) {
|
|
5891
|
+
return candidate;
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
return null;
|
|
5895
|
+
}
|
|
5896
|
+
isPrefixOfAnySequence(candidates, proposed) {
|
|
5897
|
+
for (const candidate of candidates) {
|
|
5898
|
+
if (!candidate.isSequence || candidate.normalizedSteps.length <= proposed.length) {
|
|
5899
|
+
continue;
|
|
5900
|
+
}
|
|
5901
|
+
let prefixMatches = true;
|
|
5902
|
+
for (let i = 0; i < proposed.length; i++) {
|
|
5903
|
+
if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
|
|
5904
|
+
prefixMatches = false;
|
|
5905
|
+
break;
|
|
5906
|
+
}
|
|
5907
|
+
}
|
|
5908
|
+
if (prefixMatches) {
|
|
5909
|
+
return true;
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
return false;
|
|
5913
|
+
}
|
|
5914
|
+
executeShortcut(shortcut, event, scope, isSequence) {
|
|
5915
|
+
if (shortcut.preventDefault) {
|
|
5916
|
+
event.preventDefault();
|
|
5917
|
+
}
|
|
5918
|
+
if (shortcut.stopPropagation) {
|
|
5919
|
+
event.stopPropagation();
|
|
5920
|
+
}
|
|
5921
|
+
const info = {
|
|
5922
|
+
combo: shortcut.combo,
|
|
5923
|
+
formattedCombo: shortcut.formattedCombo,
|
|
5924
|
+
scope,
|
|
5925
|
+
target: event.target,
|
|
5926
|
+
isSequence
|
|
5927
|
+
};
|
|
5928
|
+
try {
|
|
5929
|
+
shortcut.handler(event, info);
|
|
5930
|
+
} catch (err) {
|
|
5931
|
+
if (this.options.onError) {
|
|
5932
|
+
this.options.onError(err instanceof Error ? err : new Error(String(err)), shortcut.combo);
|
|
5933
|
+
} else {
|
|
5934
|
+
console.error(`[Wulf.Shortcut] Erreur lors de l'ex\xE9cution du raccourci "${shortcut.combo}":`, err);
|
|
5935
|
+
}
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5938
|
+
resetSequenceTimer() {
|
|
5939
|
+
if (this.sequenceTimer) {
|
|
5940
|
+
clearTimeout(this.sequenceTimer);
|
|
5941
|
+
}
|
|
5942
|
+
this.sequenceTimer = setTimeout(() => {
|
|
5943
|
+
this.clearSequenceBuffer();
|
|
5944
|
+
}, this.options.sequenceTimeout);
|
|
5945
|
+
}
|
|
5946
|
+
clearSequenceBuffer() {
|
|
5947
|
+
this.sequenceBuffer = [];
|
|
5948
|
+
if (this.sequenceTimer) {
|
|
5949
|
+
clearTimeout(this.sequenceTimer);
|
|
5950
|
+
this.sequenceTimer = null;
|
|
5951
|
+
}
|
|
5952
|
+
}
|
|
5953
|
+
};
|
|
4783
5954
|
return __toCommonJS(index_exports);
|
|
4784
5955
|
})();
|
|
4785
|
-
if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
|
|
5956
|
+
if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast", "FocusTrap", "Shortcut"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
|
|
4786
5957
|
//# sourceMappingURL=index.global.js.map
|