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.
- package/README.md +217 -11
- package/changelog.md +60 -0
- package/dist/anchor.esm.js +9 -0
- package/dist/anchor.esm.js.map +7 -0
- package/dist/anchor.global.js +695 -0
- package/dist/anchor.global.js.map +7 -0
- package/dist/anchor.global.min.js +6 -0
- package/dist/anchor.global.min.js.map +7 -0
- package/dist/autosize.css +1 -0
- package/dist/autosize.css.map +7 -0
- package/dist/autosize.esm.js +10 -0
- package/dist/autosize.esm.js.map +7 -0
- package/dist/autosize.global.js +657 -0
- package/dist/autosize.global.js.map +7 -0
- package/dist/autosize.global.min.js +6 -0
- package/dist/autosize.global.min.js.map +7 -0
- package/dist/autosize.layered.css +1 -0
- package/dist/autosize.layered.css.map +7 -0
- package/dist/chunks/chunk-22AIMRD5.js +119 -0
- package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
- package/dist/chunks/chunk-5N2IRGDM.js +766 -0
- package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
- package/dist/chunks/chunk-72FVCNNZ.js +863 -0
- package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
- package/dist/chunks/chunk-AXZYYW7H.js +865 -0
- package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
- package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
- package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
- package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
- package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
- package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
- package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
- package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
- package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
- package/dist/chunks/chunk-QV46A7FV.js +197 -0
- package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
- package/dist/chunks/chunk-SXLUXN6W.js +612 -0
- package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
- package/dist/chunks/chunk-T2H4EJCW.js +621 -0
- package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
- package/dist/chunks/chunk-TILLYEF2.js +6044 -0
- package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
- package/dist/chunks/chunk-VJO22BAT.js +72 -0
- package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
- package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
- package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
- package/dist/focus-trap.esm.js +6 -536
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +260 -87
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +79 -10069
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +4192 -355
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +6 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +16 -6094
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +44 -55
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +3 -3
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +15 -1067
- package/dist/masonry.esm.js.map +4 -4
- package/dist/masonry.global.js +229 -148
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +14 -1175
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +171 -88
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +3 -3
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +6 -741
- package/dist/shortcut.esm.js.map +4 -4
- package/dist/shortcut.global.js +225 -58
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +8 -2
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/size-report.json +319 -0
- package/dist/sortable.css +1 -0
- package/dist/sortable.css.map +7 -0
- package/dist/sortable.esm.js +22 -0
- package/dist/sortable.esm.js.map +7 -0
- package/dist/sortable.global.js +1477 -0
- package/dist/sortable.global.js.map +7 -0
- package/dist/sortable.global.min.js +6 -0
- package/dist/sortable.global.min.js.map +7 -0
- package/dist/sortable.layered.css +1 -0
- package/dist/sortable.layered.css.map +7 -0
- package/dist/sri-manifest.json +64 -0
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +19 -1129
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +386 -104
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -4
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/anchor/Anchor.d.ts +41 -0
- package/dist/types/anchor/index.d.ts +3 -0
- package/dist/types/anchor/types.d.ts +115 -0
- package/dist/types/autosize/Autosize.d.ts +71 -0
- package/dist/types/autosize/index.d.ts +3 -0
- package/dist/types/autosize/types.d.ts +66 -0
- package/dist/types/common/AuditableComponent.d.ts +1 -1
- package/dist/types/common/dom.d.ts +5 -0
- package/dist/types/common/registry.d.ts +40 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +8 -3
- package/dist/types/index.d.ts +13 -1
- package/dist/types/mask/paste.d.ts +2 -5
- package/dist/types/masonry/Masonry.d.ts +2 -0
- package/dist/types/scroll/ScrollBlock.d.ts +2 -0
- package/dist/types/scroll/types.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +16 -3
- package/dist/types/shortcut/types.d.ts +5 -0
- package/dist/types/sortable/Sortable.d.ts +75 -0
- package/dist/types/sortable/i18n/en.d.ts +2 -0
- package/dist/types/sortable/i18n/fr.d.ts +2 -0
- package/dist/types/sortable/i18n/index.d.ts +9 -0
- package/dist/types/sortable/i18n/types.d.ts +15 -0
- package/dist/types/sortable/index.d.ts +4 -0
- package/dist/types/sortable/types.d.ts +112 -0
- package/dist/types/toast/Toast.d.ts +6 -1
- package/dist/types/toast/ToastInstance.d.ts +7 -0
- package/dist/types/toast/ToastManager.d.ts +4 -2
- package/dist/types/toast/types.d.ts +27 -1
- package/dist/types/undo/UndoManager.d.ts +112 -0
- package/dist/types/undo/i18n/en.d.ts +2 -0
- package/dist/types/undo/i18n/fr.d.ts +2 -0
- package/dist/types/undo/i18n/index.d.ts +9 -0
- package/dist/types/undo/i18n/types.d.ts +6 -0
- package/dist/types/undo/index.d.ts +5 -0
- package/dist/types/undo/types.d.ts +106 -0
- package/dist/undo.esm.js +23 -0
- package/dist/undo.esm.js.map +7 -0
- package/dist/undo.global.js +1029 -0
- package/dist/undo.global.js.map +7 -0
- package/dist/undo.global.min.js +6 -0
- package/dist/undo.global.min.js.map +7 -0
- package/package.json +54 -5
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isImeComposing
|
|
3
|
+
} from "./chunk-22AIMRD5.js";
|
|
4
|
+
import {
|
|
5
|
+
AuditableComponent,
|
|
6
|
+
__export
|
|
7
|
+
} from "./chunk-VJO22BAT.js";
|
|
8
|
+
|
|
9
|
+
// src/shortcut/index.ts
|
|
10
|
+
var shortcut_exports = {};
|
|
11
|
+
__export(shortcut_exports, {
|
|
12
|
+
ShortcutFormatter: () => ShortcutFormatter,
|
|
13
|
+
ShortcutManager: () => ShortcutManager,
|
|
14
|
+
default: () => ShortcutManager
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// src/shortcut/ShortcutFormatter.ts
|
|
18
|
+
var ShortcutFormatter = class _ShortcutFormatter {
|
|
19
|
+
/**
|
|
20
|
+
* Détecte si l'environnement d'exécution actuel est un environnement Apple (macOS / iOS / iPadOS).
|
|
21
|
+
*/
|
|
22
|
+
static isApple() {
|
|
23
|
+
if (typeof navigator === "undefined") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const uaData = navigator.userAgentData;
|
|
27
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
28
|
+
const p = uaData.platform.toLowerCase();
|
|
29
|
+
if (p.includes("mac") || p.includes("ios")) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const platform = (navigator.platform || "").toLowerCase();
|
|
34
|
+
if (platform.includes("mac") || platform.includes("iphone") || platform.includes("ipad") || platform.includes("ipod")) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const ua = (navigator.userAgent || "").toLowerCase();
|
|
38
|
+
return ua.includes("macintosh") || ua.includes("mac os x") || ua.includes("ipad") || ua.includes("iphone");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Normalise un nom de touche unitaire pour les comparaisons.
|
|
42
|
+
*/
|
|
43
|
+
static normalizeKeyName(key) {
|
|
44
|
+
if (key === " ") {
|
|
45
|
+
return " ";
|
|
46
|
+
}
|
|
47
|
+
const k = key.trim().toLowerCase();
|
|
48
|
+
switch (k) {
|
|
49
|
+
case "esc":
|
|
50
|
+
return "escape";
|
|
51
|
+
case "return":
|
|
52
|
+
return "enter";
|
|
53
|
+
case "space":
|
|
54
|
+
case "spacebar":
|
|
55
|
+
return " ";
|
|
56
|
+
case "plus":
|
|
57
|
+
return "+";
|
|
58
|
+
case "del":
|
|
59
|
+
return "delete";
|
|
60
|
+
case "ins":
|
|
61
|
+
return "insert";
|
|
62
|
+
case "up":
|
|
63
|
+
return "arrowup";
|
|
64
|
+
case "down":
|
|
65
|
+
return "arrowdown";
|
|
66
|
+
case "left":
|
|
67
|
+
return "arrowleft";
|
|
68
|
+
case "right":
|
|
69
|
+
return "arrowright";
|
|
70
|
+
default:
|
|
71
|
+
return k;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse une chaîne de combinaison (ex: "Mod+K", "g i", "Shift+?", "Alt++")
|
|
76
|
+
* et retourne la liste des étapes normalisées nécessaires au déclenchement.
|
|
77
|
+
*/
|
|
78
|
+
static parseCombo(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
79
|
+
if (typeof combo !== "string") {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
if (combo === " ") {
|
|
83
|
+
return [{ ctrl: false, alt: false, shift: false, meta: false, key: " " }];
|
|
84
|
+
}
|
|
85
|
+
const trimmed = combo.slice(0, 512).trim();
|
|
86
|
+
if (!trimmed) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const normalizedChordSpacing = trimmed.replace(
|
|
90
|
+
/\b(ctrl|control|alt|option|opt|shift|maj|cmd|command|meta|win|super|mod|\$mod)\s*\+\s*/gi,
|
|
91
|
+
"$1+"
|
|
92
|
+
);
|
|
93
|
+
const stepsRaw = normalizedChordSpacing.split(/\s+/).slice(0, 10);
|
|
94
|
+
const steps = [];
|
|
95
|
+
for (const rawStep of stepsRaw) {
|
|
96
|
+
const tokens = [];
|
|
97
|
+
if (rawStep === "+") {
|
|
98
|
+
tokens.push("+");
|
|
99
|
+
} else {
|
|
100
|
+
let currentToken = "";
|
|
101
|
+
for (let i = 0; i < rawStep.length; i++) {
|
|
102
|
+
const char = rawStep[i];
|
|
103
|
+
if (char === "+") {
|
|
104
|
+
if (currentToken === "" && tokens.length > 0) {
|
|
105
|
+
tokens.push("+");
|
|
106
|
+
} else if (currentToken !== "") {
|
|
107
|
+
tokens.push(currentToken);
|
|
108
|
+
currentToken = "";
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
currentToken += char;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (currentToken !== "") {
|
|
115
|
+
tokens.push(currentToken);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let ctrl = false;
|
|
119
|
+
let alt = false;
|
|
120
|
+
let shift = false;
|
|
121
|
+
let meta = false;
|
|
122
|
+
let mainKey = "";
|
|
123
|
+
for (const token of tokens) {
|
|
124
|
+
const lower = token.trim().toLowerCase();
|
|
125
|
+
if (lower === "ctrl" || lower === "control") {
|
|
126
|
+
ctrl = true;
|
|
127
|
+
} else if (lower === "alt" || lower === "option" || lower === "opt") {
|
|
128
|
+
alt = true;
|
|
129
|
+
} else if (lower === "shift" || lower === "maj") {
|
|
130
|
+
shift = true;
|
|
131
|
+
} else if (lower === "cmd" || lower === "command" || lower === "meta" || lower === "win" || lower === "super") {
|
|
132
|
+
meta = true;
|
|
133
|
+
} else if (lower === "mod" || lower === "$mod") {
|
|
134
|
+
if (isApple) {
|
|
135
|
+
meta = true;
|
|
136
|
+
} else {
|
|
137
|
+
ctrl = true;
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
mainKey = _ShortcutFormatter.normalizeKeyName(token);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
steps.push({
|
|
144
|
+
ctrl,
|
|
145
|
+
alt,
|
|
146
|
+
shift,
|
|
147
|
+
meta,
|
|
148
|
+
key: mainKey
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return steps;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Formate une combinaison brute en libellé soigné et lisible pour l'OS cible.
|
|
155
|
+
* Ex: "Mod+Shift+P" -> macOS: "⇧⌘P", Windows: "Ctrl+Shift+P"
|
|
156
|
+
* Ex: "g i" -> "g puis i" ou "g i"
|
|
157
|
+
*/
|
|
158
|
+
static format(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
159
|
+
const steps = _ShortcutFormatter.parseCombo(combo, isApple);
|
|
160
|
+
if (steps.length === 0) {
|
|
161
|
+
return combo;
|
|
162
|
+
}
|
|
163
|
+
const formattedSteps = steps.map((step) => {
|
|
164
|
+
const parts = [];
|
|
165
|
+
if (isApple) {
|
|
166
|
+
if (step.ctrl) parts.push("\u2303");
|
|
167
|
+
if (step.alt) parts.push("\u2325");
|
|
168
|
+
if (step.shift) parts.push("\u21E7");
|
|
169
|
+
if (step.meta) parts.push("\u2318");
|
|
170
|
+
const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, true);
|
|
171
|
+
parts.push(keyDisplay);
|
|
172
|
+
return parts.join("");
|
|
173
|
+
} else {
|
|
174
|
+
if (step.ctrl) parts.push("Ctrl");
|
|
175
|
+
if (step.alt) parts.push("Alt");
|
|
176
|
+
if (step.shift) parts.push("Shift");
|
|
177
|
+
if (step.meta) parts.push("Win");
|
|
178
|
+
const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, false);
|
|
179
|
+
parts.push(keyDisplay);
|
|
180
|
+
return parts.join("+");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return formattedSteps.join(" ");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Convertit un combo technique vers le format officiel WAI-ARIA `aria-keyshortcuts`.
|
|
187
|
+
* Standard W3C : les modificateurs sont 'Control', 'Alt', 'Shift', 'Meta' et le séparateur est '+'.
|
|
188
|
+
* Attention : dans WAI-ARIA 1.2, l'espace délimite des raccourcis alternatifs et non une séquence temporelle.
|
|
189
|
+
* Pour une séquence multi-étapes (ex: "g i"), retourne une chaîne vide afin de ne pas induire le lecteur d'écran en erreur.
|
|
190
|
+
*/
|
|
191
|
+
static toAriaKeyShortcuts(combo, isApple = _ShortcutFormatter.isApple()) {
|
|
192
|
+
const steps = _ShortcutFormatter.parseCombo(combo, isApple);
|
|
193
|
+
if (steps.length !== 1) {
|
|
194
|
+
return "";
|
|
195
|
+
}
|
|
196
|
+
const step = steps[0];
|
|
197
|
+
const ariaKey = _ShortcutFormatter.formatAriaKey(step.key);
|
|
198
|
+
if (!ariaKey) {
|
|
199
|
+
return "";
|
|
200
|
+
}
|
|
201
|
+
const parts = [];
|
|
202
|
+
if (step.ctrl) parts.push("Control");
|
|
203
|
+
if (step.alt) parts.push("Alt");
|
|
204
|
+
if (step.shift) parts.push("Shift");
|
|
205
|
+
if (step.meta) parts.push("Meta");
|
|
206
|
+
parts.push(ariaKey);
|
|
207
|
+
return parts.join("+");
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Formate un nom de touche strictement conforme aux valeurs standard W3C UI Events / aria-keyshortcuts.
|
|
211
|
+
*/
|
|
212
|
+
static formatAriaKey(key) {
|
|
213
|
+
if (!key) return "";
|
|
214
|
+
switch (key.toLowerCase()) {
|
|
215
|
+
case "escape":
|
|
216
|
+
return "Escape";
|
|
217
|
+
case "enter":
|
|
218
|
+
return "Enter";
|
|
219
|
+
case " ":
|
|
220
|
+
return "Space";
|
|
221
|
+
case "tab":
|
|
222
|
+
return "Tab";
|
|
223
|
+
case "backspace":
|
|
224
|
+
return "Backspace";
|
|
225
|
+
case "delete":
|
|
226
|
+
return "Delete";
|
|
227
|
+
case "insert":
|
|
228
|
+
return "Insert";
|
|
229
|
+
case "home":
|
|
230
|
+
return "Home";
|
|
231
|
+
case "end":
|
|
232
|
+
return "End";
|
|
233
|
+
case "pageup":
|
|
234
|
+
return "PageUp";
|
|
235
|
+
case "pagedown":
|
|
236
|
+
return "PageDown";
|
|
237
|
+
case "arrowup":
|
|
238
|
+
return "ArrowUp";
|
|
239
|
+
case "arrowdown":
|
|
240
|
+
return "ArrowDown";
|
|
241
|
+
case "arrowleft":
|
|
242
|
+
return "ArrowLeft";
|
|
243
|
+
case "arrowright":
|
|
244
|
+
return "ArrowRight";
|
|
245
|
+
case "printscreen":
|
|
246
|
+
return "PrintScreen";
|
|
247
|
+
case "scrolllock":
|
|
248
|
+
return "ScrollLock";
|
|
249
|
+
case "numlock":
|
|
250
|
+
return "NumLock";
|
|
251
|
+
case "capslock":
|
|
252
|
+
return "CapsLock";
|
|
253
|
+
case "contextmenu":
|
|
254
|
+
return "ContextMenu";
|
|
255
|
+
case "+":
|
|
256
|
+
return "Plus";
|
|
257
|
+
default:
|
|
258
|
+
return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
static formatKeyDisplay(key, isApple) {
|
|
262
|
+
if (!key) return "";
|
|
263
|
+
switch (key.toLowerCase()) {
|
|
264
|
+
case "escape":
|
|
265
|
+
return isApple ? "\u238B" : "Esc";
|
|
266
|
+
case "enter":
|
|
267
|
+
return isApple ? "\u21A9" : "Enter";
|
|
268
|
+
case " ":
|
|
269
|
+
return isApple ? "\u2423" : "Space";
|
|
270
|
+
case "tab":
|
|
271
|
+
return isApple ? "\u21E5" : "Tab";
|
|
272
|
+
case "backspace":
|
|
273
|
+
return isApple ? "\u232B" : "Backspace";
|
|
274
|
+
case "delete":
|
|
275
|
+
return isApple ? "\u2326" : "Delete";
|
|
276
|
+
case "arrowup":
|
|
277
|
+
return "\u2191";
|
|
278
|
+
case "arrowdown":
|
|
279
|
+
return "\u2193";
|
|
280
|
+
case "arrowleft":
|
|
281
|
+
return "\u2190";
|
|
282
|
+
case "arrowright":
|
|
283
|
+
return "\u2192";
|
|
284
|
+
default:
|
|
285
|
+
return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/shortcut/ShortcutManager.ts
|
|
291
|
+
var SENSITIVE_AUTOCOMPLETE_TOKENS = /* @__PURE__ */ new Set([
|
|
292
|
+
"current-password",
|
|
293
|
+
"new-password",
|
|
294
|
+
"one-time-code",
|
|
295
|
+
"cc-number",
|
|
296
|
+
"cc-csc"
|
|
297
|
+
]);
|
|
298
|
+
var ShortcutManager = class _ShortcutManager extends AuditableComponent {
|
|
299
|
+
options;
|
|
300
|
+
shortcuts = /* @__PURE__ */ new Map();
|
|
301
|
+
scopeStack = [];
|
|
302
|
+
sequenceBuffer = [];
|
|
303
|
+
sequenceTimer = null;
|
|
304
|
+
isListening = true;
|
|
305
|
+
isDestroyed = false;
|
|
306
|
+
emittedAuditWarnings = /* @__PURE__ */ new Set();
|
|
307
|
+
boundListener = null;
|
|
308
|
+
abortController = null;
|
|
309
|
+
idCounter = 0;
|
|
310
|
+
constructor(options) {
|
|
311
|
+
super();
|
|
312
|
+
const rawTimeout = options?.sequenceTimeout;
|
|
313
|
+
const sequenceTimeout = typeof rawTimeout === "number" && Number.isFinite(rawTimeout) && rawTimeout > 0 ? Math.min(rawTimeout, 1e4) : 800;
|
|
314
|
+
this.options = {
|
|
315
|
+
defaultScope: options?.defaultScope || "global",
|
|
316
|
+
sequenceTimeout,
|
|
317
|
+
target: options?.target || (typeof window !== "undefined" ? window : {}),
|
|
318
|
+
onError: options?.onError,
|
|
319
|
+
audit: options?.audit ?? true
|
|
320
|
+
};
|
|
321
|
+
this.scopeStack = [this.options.defaultScope];
|
|
322
|
+
this.initListener();
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Vérifie si un élément DOM est une zone d'édition où la saisie de l'utilisateur
|
|
326
|
+
* ne doit JAMAIS être interrompue ou détournée (Axiome Primordial).
|
|
327
|
+
*/
|
|
328
|
+
static isEditable(target) {
|
|
329
|
+
if (!target || typeof target.tagName !== "string") {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
const el = target;
|
|
333
|
+
const tagName = el.tagName.toUpperCase();
|
|
334
|
+
if (tagName === "INPUT") {
|
|
335
|
+
const type = el.type?.toLowerCase() || "text";
|
|
336
|
+
const nonTextTypes = ["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"];
|
|
337
|
+
return !nonTextTypes.includes(type);
|
|
338
|
+
}
|
|
339
|
+
if (tagName === "TEXTAREA" || tagName === "SELECT") {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
const contentEditable = el.getAttribute?.("contenteditable")?.toLowerCase();
|
|
343
|
+
if (el.isContentEditable || contentEditable === "true" || contentEditable === "plaintext-only" || contentEditable === "") {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
const role = el.getAttribute?.("role");
|
|
347
|
+
if (role === "textbox" || role === "searchbox" || role === "combobox" || role === "spinbutton") {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
if (typeof el.closest === "function") {
|
|
351
|
+
const editableAncestor = el.closest(
|
|
352
|
+
'[contenteditable="true"], [contenteditable="plaintext-only"], [contenteditable=""], [role="textbox"], [role="searchbox"], [role="combobox"], [role="spinbutton"]'
|
|
353
|
+
);
|
|
354
|
+
if (editableAncestor) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Vérifie si la cible appartient à un widget composite à typeahead clavier (listbox, menu, tree, grid).
|
|
362
|
+
*/
|
|
363
|
+
static isTypeaheadWidget(target) {
|
|
364
|
+
if (!target || typeof target.tagName !== "string") {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
const el = target;
|
|
368
|
+
const role = el.getAttribute?.("role");
|
|
369
|
+
if (role === "listbox" || role === "menu" || role === "menubar" || role === "tree" || role === "grid") {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
if (typeof el.closest === "function") {
|
|
373
|
+
return Boolean(el.closest('[role="listbox"], [role="menu"], [role="menubar"], [role="tree"], [role="grid"]'));
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Vérifie si la cible est un champ sensible (password, data-mask-sensitive, autocomplete sensible).
|
|
379
|
+
*/
|
|
380
|
+
static isSensitiveField(target) {
|
|
381
|
+
if (!target || typeof target.tagName !== "string") {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
const el = target;
|
|
385
|
+
if (el.tagName.toUpperCase() === "INPUT" && (el.type || "").toLowerCase() === "password") {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
const sensitiveAttr = el.getAttribute?.("data-mask-sensitive");
|
|
389
|
+
if (sensitiveAttr !== null && sensitiveAttr !== void 0 && sensitiveAttr !== "false") {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
const ac = el.getAttribute?.("autocomplete");
|
|
393
|
+
if (ac) {
|
|
394
|
+
const tokens = ac.trim().toLowerCase().split(/\s+/);
|
|
395
|
+
if (tokens.some((tok) => SENSITIVE_AUTOCOMPLETE_TOKENS.has(tok))) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Enregistre un ou plusieurs raccourcis clavier.
|
|
403
|
+
* Retourne une fonction de nettoyage pour désenregistrer immédiatement.
|
|
404
|
+
*/
|
|
405
|
+
bind(definition) {
|
|
406
|
+
if (this.isDestroyed) {
|
|
407
|
+
return () => {
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const list = Array.isArray(definition) ? definition : [definition];
|
|
411
|
+
const registeredIds = [];
|
|
412
|
+
for (const def of list) {
|
|
413
|
+
if (!def.combo || typeof def.handler !== "function") {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const normalizedSteps = ShortcutFormatter.parseCombo(def.combo);
|
|
417
|
+
if (normalizedSteps.length === 0 || normalizedSteps.some((step) => !step.key)) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const id = `wulf_shortcut_${++this.idCounter}`;
|
|
421
|
+
const isSequence = normalizedSteps.length > 1;
|
|
422
|
+
const formattedCombo = ShortcutFormatter.format(def.combo);
|
|
423
|
+
const registered = {
|
|
424
|
+
...def,
|
|
425
|
+
id,
|
|
426
|
+
scope: def.scope || "global",
|
|
427
|
+
category: def.category || "G\xE9n\xE9ral",
|
|
428
|
+
allowInEditable: def.allowInEditable ?? false,
|
|
429
|
+
preventDefault: def.preventDefault ?? true,
|
|
430
|
+
stopPropagation: def.stopPropagation ?? true,
|
|
431
|
+
priority: def.priority ?? 0,
|
|
432
|
+
formattedCombo,
|
|
433
|
+
normalizedSteps,
|
|
434
|
+
isSequence
|
|
435
|
+
};
|
|
436
|
+
this.shortcuts.set(id, registered);
|
|
437
|
+
registeredIds.push(id);
|
|
438
|
+
}
|
|
439
|
+
if (registeredIds.length > 0 && this.options.audit) {
|
|
440
|
+
const warnings = this.audit();
|
|
441
|
+
const newWarnings = warnings.filter((w) => !this.emittedAuditWarnings.has(w));
|
|
442
|
+
if (newWarnings.length > 0) {
|
|
443
|
+
newWarnings.forEach((w) => this.emittedAuditWarnings.add(w));
|
|
444
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
445
|
+
console.warn(
|
|
446
|
+
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${newWarnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
447
|
+
` + newWarnings.map((w) => ` - ${w}`).join("\n") + `
|
|
448
|
+
(${this.getAuditDisableHint()})`
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return () => {
|
|
454
|
+
for (const id of registeredIds) {
|
|
455
|
+
this.shortcuts.delete(id);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Retire tous les raccourcis correspondant à une combinaison et éventuellement un scope.
|
|
461
|
+
*/
|
|
462
|
+
unbind(combo, scope) {
|
|
463
|
+
if (typeof combo !== "string" || !combo.trim()) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const formatted = ShortcutFormatter.format(combo);
|
|
467
|
+
for (const [id, s] of this.shortcuts.entries()) {
|
|
468
|
+
if (s.formattedCombo === formatted || s.combo.trim().toLowerCase() === combo.trim().toLowerCase()) {
|
|
469
|
+
if (!scope || s.scope === scope) {
|
|
470
|
+
this.shortcuts.delete(id);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Empile un nouveau scope actif (mode LIFO).
|
|
477
|
+
* Seuls les raccourcis de ce scope (et les omniprésents '*') seront actifs.
|
|
478
|
+
*/
|
|
479
|
+
pushScope(scope) {
|
|
480
|
+
if (scope && typeof scope === "string") {
|
|
481
|
+
if (this.scopeStack.length >= 64) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
this.scopeStack.push(scope);
|
|
485
|
+
this.clearSequenceBuffer();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Dépile le scope actuel et rétablit le précédent.
|
|
490
|
+
* Si un paramètre `scope` est passé, ne retire que si le scope actuel correspond.
|
|
491
|
+
*/
|
|
492
|
+
popScope(scope) {
|
|
493
|
+
if (this.scopeStack.length <= 1) {
|
|
494
|
+
return this.scopeStack[0];
|
|
495
|
+
}
|
|
496
|
+
if (scope) {
|
|
497
|
+
if (this.getScope() === scope) {
|
|
498
|
+
const popped2 = this.scopeStack.pop();
|
|
499
|
+
this.clearSequenceBuffer();
|
|
500
|
+
return popped2;
|
|
501
|
+
}
|
|
502
|
+
return void 0;
|
|
503
|
+
}
|
|
504
|
+
const popped = this.scopeStack.pop();
|
|
505
|
+
this.clearSequenceBuffer();
|
|
506
|
+
return popped;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Réinitialise brutalement la pile pour activer le scope spécifié.
|
|
510
|
+
*/
|
|
511
|
+
setScope(scope) {
|
|
512
|
+
this.scopeStack = [scope || this.options.defaultScope];
|
|
513
|
+
this.clearSequenceBuffer();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Retourne le scope actuellement actif au sommet de la pile.
|
|
517
|
+
*/
|
|
518
|
+
getScope() {
|
|
519
|
+
return this.scopeStack[this.scopeStack.length - 1] || this.options.defaultScope;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Retourne une copie de la pile complète des scopes.
|
|
523
|
+
*/
|
|
524
|
+
getScopeStack() {
|
|
525
|
+
return [...this.scopeStack];
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Met en pause l'écoute de tous les raccourcis.
|
|
529
|
+
*/
|
|
530
|
+
pause() {
|
|
531
|
+
this.isListening = false;
|
|
532
|
+
this.clearSequenceBuffer();
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Réactive l'écoute des raccourcis.
|
|
536
|
+
*/
|
|
537
|
+
resume() {
|
|
538
|
+
if (this.isDestroyed) return;
|
|
539
|
+
this.isListening = true;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Indique si le gestionnaire est actif et à l'écoute.
|
|
543
|
+
*/
|
|
544
|
+
isActive() {
|
|
545
|
+
return this.isListening;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Retourne le catalogue des raccourcis enregistrés (optionnellement filtré par scope).
|
|
549
|
+
*/
|
|
550
|
+
getRegistry(scope) {
|
|
551
|
+
const list = [];
|
|
552
|
+
for (const shortcut of this.shortcuts.values()) {
|
|
553
|
+
if (!scope || shortcut.scope === scope || shortcut.scope === "*") {
|
|
554
|
+
list.push({
|
|
555
|
+
...shortcut,
|
|
556
|
+
normalizedSteps: shortcut.normalizedSteps.map((step) => ({ ...step }))
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return list;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Audite le registre des raccourcis vis-à-vis de WCAG 2.1.4 et de l'Axiome Primordial.
|
|
564
|
+
*/
|
|
565
|
+
audit() {
|
|
566
|
+
const warnings = [];
|
|
567
|
+
const criticalEditKeys = /* @__PURE__ */ new Set(["c", "v", "x", "a", "z"]);
|
|
568
|
+
for (const shortcut of this.shortcuts.values()) {
|
|
569
|
+
const isSingleCharWithoutMod = shortcut.normalizedSteps.length > 0 && shortcut.normalizedSteps.every(
|
|
570
|
+
(step) => !step.ctrl && !step.alt && !step.meta && step.key.length === 1
|
|
571
|
+
);
|
|
572
|
+
if (isSingleCharWithoutMod) {
|
|
573
|
+
warnings.push(
|
|
574
|
+
`Raccourci mono-caract\xE8re sans modificateur "${shortcut.combo}" : pr\xE9voyez une option pour le d\xE9sactiver ou le reconfigurer (WCAG 2.1.4).`
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
if (shortcut.allowInEditable && !shortcut.isSequence && shortcut.normalizedSteps.length === 1) {
|
|
578
|
+
const s = shortcut.normalizedSteps[0];
|
|
579
|
+
const isPrimaryModOnly = !s.alt && !s.shift && (s.ctrl && !s.meta || s.meta && !s.ctrl);
|
|
580
|
+
if (isPrimaryModOnly && criticalEditKeys.has(s.key)) {
|
|
581
|
+
warnings.push(
|
|
582
|
+
`Raccourci "${shortcut.combo}" avec allowInEditable: true risque d'\xE9craser une commande d'\xE9dition native (Ctrl/Cmd+${s.key.toUpperCase()}).`
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return warnings;
|
|
588
|
+
}
|
|
589
|
+
getAuditPrefix() {
|
|
590
|
+
return "Wulf.Shortcut";
|
|
591
|
+
}
|
|
592
|
+
getAuditTargetLabel() {
|
|
593
|
+
return `${this.shortcuts.size} raccourci(s)`;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Associe l'attribut standard WAI-ARIA `aria-keyshortcuts` sur un élément DOM.
|
|
597
|
+
*/
|
|
598
|
+
attachAria(element, combo) {
|
|
599
|
+
if (element && typeof element.setAttribute === "function") {
|
|
600
|
+
const ariaValue = ShortcutFormatter.toAriaKeyShortcuts(combo);
|
|
601
|
+
if (ariaValue) {
|
|
602
|
+
element.setAttribute("aria-keyshortcuts", ariaValue);
|
|
603
|
+
} else if (typeof element.removeAttribute === "function") {
|
|
604
|
+
element.removeAttribute("aria-keyshortcuts");
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Formate une combinaison brute selon l'OS courant ("⌘K" ou "Ctrl+K").
|
|
610
|
+
*/
|
|
611
|
+
static format(combo, isApple) {
|
|
612
|
+
return ShortcutFormatter.format(combo, isApple);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Détruit le gestionnaire : supprime les écouteurs du DOM et vide toute la mémoire.
|
|
616
|
+
*/
|
|
617
|
+
destroy() {
|
|
618
|
+
if (this.isDestroyed) return;
|
|
619
|
+
this.isDestroyed = true;
|
|
620
|
+
this.pause();
|
|
621
|
+
this.removeListener();
|
|
622
|
+
this.shortcuts.clear();
|
|
623
|
+
this.emittedAuditWarnings.clear();
|
|
624
|
+
this.scopeStack = [];
|
|
625
|
+
this.clearSequenceBuffer();
|
|
626
|
+
}
|
|
627
|
+
// --- Implémentation Interne ---
|
|
628
|
+
initListener() {
|
|
629
|
+
if (typeof window === "undefined" || !this.options.target) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
this.abortController = new AbortController();
|
|
633
|
+
this.boundListener = (event) => this.handleKeyDown(event);
|
|
634
|
+
const target = this.options.target;
|
|
635
|
+
if (typeof target.addEventListener === "function") {
|
|
636
|
+
target.addEventListener("keydown", this.boundListener, {
|
|
637
|
+
capture: false,
|
|
638
|
+
signal: this.abortController.signal
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
removeListener() {
|
|
643
|
+
if (this.abortController) {
|
|
644
|
+
this.abortController.abort();
|
|
645
|
+
this.abortController = null;
|
|
646
|
+
} else if (this.boundListener && this.options.target) {
|
|
647
|
+
const target = this.options.target;
|
|
648
|
+
if (typeof target.removeEventListener === "function") {
|
|
649
|
+
target.removeEventListener("keydown", this.boundListener, false);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
this.boundListener = null;
|
|
653
|
+
}
|
|
654
|
+
handleKeyDown(event) {
|
|
655
|
+
if (this.isDestroyed || !this.isListening || isImeComposing(event)) {
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const k = (event.key || "").toLowerCase();
|
|
659
|
+
if (["control", "alt", "shift", "meta"].includes(k)) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const currentScope = this.getScope();
|
|
663
|
+
const composed = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
664
|
+
const pathTargets = composed.length > 0 ? composed : event.target ? [event.target] : [];
|
|
665
|
+
let isEditable = _ShortcutManager.isEditable(event.target);
|
|
666
|
+
let isSensitiveInput = _ShortcutManager.isSensitiveField(event.target);
|
|
667
|
+
let isTypeahead = _ShortcutManager.isTypeaheadWidget(event.target);
|
|
668
|
+
for (const node of pathTargets) {
|
|
669
|
+
if (!isEditable && _ShortcutManager.isEditable(node)) isEditable = true;
|
|
670
|
+
if (!isSensitiveInput && _ShortcutManager.isSensitiveField(node)) isSensitiveInput = true;
|
|
671
|
+
if (!isTypeahead && _ShortcutManager.isTypeaheadWidget(node)) isTypeahead = true;
|
|
672
|
+
}
|
|
673
|
+
const currentStep = {
|
|
674
|
+
ctrl: event.ctrlKey,
|
|
675
|
+
alt: event.altKey,
|
|
676
|
+
shift: event.shiftKey,
|
|
677
|
+
meta: event.metaKey,
|
|
678
|
+
key: ShortcutFormatter.normalizeKeyName(event.key || "")
|
|
679
|
+
};
|
|
680
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
681
|
+
if (this.sequenceBuffer.length > 0) {
|
|
682
|
+
const last = this.sequenceBuffer[this.sequenceBuffer.length - 1];
|
|
683
|
+
if (now - last.timestamp > this.options.sequenceTimeout) {
|
|
684
|
+
this.clearSequenceBuffer();
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const activeCandidates = this.getActiveShortcuts(currentScope, isEditable, isSensitiveInput, isTypeahead);
|
|
688
|
+
const proposedSequence = [...this.sequenceBuffer.map((b) => b.step), currentStep];
|
|
689
|
+
const matchingSequence = this.findMatchingSequence(activeCandidates, proposedSequence, event);
|
|
690
|
+
if (matchingSequence) {
|
|
691
|
+
this.clearSequenceBuffer();
|
|
692
|
+
this.executeShortcut(matchingSequence, event, currentScope, true);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (this.isPrefixOfAnySequence(activeCandidates, proposedSequence, event)) {
|
|
696
|
+
this.sequenceBuffer.push({ step: currentStep, timestamp: now });
|
|
697
|
+
this.resetSequenceTimer();
|
|
698
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !isEditable && !isTypeahead) {
|
|
699
|
+
event.preventDefault();
|
|
700
|
+
}
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
this.clearSequenceBuffer();
|
|
704
|
+
const matchingChord = this.findMatchingChord(activeCandidates, currentStep, event);
|
|
705
|
+
if (matchingChord) {
|
|
706
|
+
this.executeShortcut(matchingChord, event, currentScope, false);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
getActiveShortcuts(currentScope, isEditable, isSensitiveInput = false, isTypeahead = false) {
|
|
710
|
+
const list = [];
|
|
711
|
+
for (const shortcut of this.shortcuts.values()) {
|
|
712
|
+
if (shortcut.scope !== currentScope && shortcut.scope !== "*") {
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (isEditable && !shortcut.allowInEditable) {
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
if (isTypeahead) {
|
|
719
|
+
const firstStep = shortcut.normalizedSteps[0];
|
|
720
|
+
if (firstStep && !firstStep.ctrl && !firstStep.alt && !firstStep.meta && firstStep.key.length === 1) {
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (isSensitiveInput) {
|
|
725
|
+
if (shortcut.isSequence) {
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
const firstStep = shortcut.normalizedSteps[0];
|
|
729
|
+
if (firstStep) {
|
|
730
|
+
if (firstStep.key.length === 1) {
|
|
731
|
+
const isUntouchedChar = !firstStep.ctrl && !firstStep.alt && !firstStep.meta;
|
|
732
|
+
const isAltGrOrOptionChar = firstStep.ctrl && firstStep.alt && !firstStep.meta || firstStep.alt && !firstStep.ctrl && !firstStep.meta;
|
|
733
|
+
if (isUntouchedChar || isAltGrOrOptionChar) {
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
} else if (!firstStep.ctrl && !firstStep.alt && !firstStep.meta && (firstStep.key === "backspace" || firstStep.key === "delete" || firstStep.key === "dead")) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
list.push(shortcut);
|
|
742
|
+
}
|
|
743
|
+
return list.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
744
|
+
}
|
|
745
|
+
stepMatches(step, eventStep, rawEvent) {
|
|
746
|
+
if (step.ctrl !== eventStep.ctrl) return false;
|
|
747
|
+
if (step.alt !== eventStep.alt) return false;
|
|
748
|
+
if (step.meta !== eventStep.meta) return false;
|
|
749
|
+
const rawKey = typeof rawEvent?.key === "string" ? rawEvent.key : "";
|
|
750
|
+
const keyMatches = step.key === eventStep.key || rawKey !== "" && step.key === rawKey.toLowerCase();
|
|
751
|
+
if (!keyMatches) return false;
|
|
752
|
+
if (step.shift === eventStep.shift) {
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
if (!step.shift && eventStep.shift) {
|
|
756
|
+
const isNonAlphaSymbol = step.key.length === 1 && !/^[a-z]$/i.test(step.key);
|
|
757
|
+
if (rawKey !== "" && rawKey === step.key || isNonAlphaSymbol && eventStep.key === step.key) {
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
findMatchingChord(candidates, currentStep, rawEvent) {
|
|
764
|
+
for (const candidate of candidates) {
|
|
765
|
+
if (candidate.isSequence || candidate.normalizedSteps.length !== 1) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const step = candidate.normalizedSteps[0];
|
|
769
|
+
if (this.stepMatches(step, currentStep, rawEvent)) {
|
|
770
|
+
return candidate;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
findMatchingSequence(candidates, proposed, rawEvent) {
|
|
776
|
+
for (const candidate of candidates) {
|
|
777
|
+
if (!candidate.isSequence || candidate.normalizedSteps.length !== proposed.length) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
let allMatch = true;
|
|
781
|
+
for (let i = 0; i < proposed.length; i++) {
|
|
782
|
+
const stepEvent = i === proposed.length - 1 ? rawEvent : void 0;
|
|
783
|
+
if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i], stepEvent)) {
|
|
784
|
+
allMatch = false;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (allMatch) {
|
|
789
|
+
return candidate;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
isPrefixOfAnySequence(candidates, proposed, rawEvent) {
|
|
795
|
+
for (const candidate of candidates) {
|
|
796
|
+
if (!candidate.isSequence || candidate.normalizedSteps.length <= proposed.length) {
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
let prefixMatches = true;
|
|
800
|
+
for (let i = 0; i < proposed.length; i++) {
|
|
801
|
+
const stepEvent = i === proposed.length - 1 ? rawEvent : void 0;
|
|
802
|
+
if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i], stepEvent)) {
|
|
803
|
+
prefixMatches = false;
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (prefixMatches) {
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
executeShortcut(shortcut, event, scope, isSequence) {
|
|
814
|
+
if (shortcut.preventDefault) {
|
|
815
|
+
event.preventDefault();
|
|
816
|
+
}
|
|
817
|
+
if (shortcut.stopPropagation) {
|
|
818
|
+
event.stopPropagation();
|
|
819
|
+
}
|
|
820
|
+
const info = {
|
|
821
|
+
combo: shortcut.combo,
|
|
822
|
+
formattedCombo: shortcut.formattedCombo,
|
|
823
|
+
scope,
|
|
824
|
+
target: event.target,
|
|
825
|
+
isSequence
|
|
826
|
+
};
|
|
827
|
+
try {
|
|
828
|
+
shortcut.handler(event, info);
|
|
829
|
+
} catch (err) {
|
|
830
|
+
if (this.options.onError) {
|
|
831
|
+
try {
|
|
832
|
+
this.options.onError(err instanceof Error ? err : new Error(String(err)), shortcut.combo);
|
|
833
|
+
} catch (onErrException) {
|
|
834
|
+
console.error("[Wulf.Shortcut] Erreur dans le callback onError:", onErrException);
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
console.error(`[Wulf.Shortcut] Erreur lors de l'ex\xE9cution du raccourci "${shortcut.combo}":`, err);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
resetSequenceTimer() {
|
|
842
|
+
if (this.sequenceTimer) {
|
|
843
|
+
clearTimeout(this.sequenceTimer);
|
|
844
|
+
}
|
|
845
|
+
this.sequenceTimer = setTimeout(() => {
|
|
846
|
+
this.clearSequenceBuffer();
|
|
847
|
+
}, this.options.sequenceTimeout);
|
|
848
|
+
}
|
|
849
|
+
clearSequenceBuffer() {
|
|
850
|
+
this.sequenceBuffer = [];
|
|
851
|
+
if (this.sequenceTimer) {
|
|
852
|
+
clearTimeout(this.sequenceTimer);
|
|
853
|
+
this.sequenceTimer = null;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
export {
|
|
859
|
+
ShortcutFormatter,
|
|
860
|
+
ShortcutManager,
|
|
861
|
+
shortcut_exports
|
|
862
|
+
};
|
|
863
|
+
//# sourceMappingURL=chunk-72FVCNNZ.js.map
|