wulf.js 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +160 -21
  2. package/changelog.md +66 -0
  3. package/dist/focus-trap.esm.js +62 -9
  4. package/dist/focus-trap.esm.js.map +2 -2
  5. package/dist/focus-trap.global.js +64 -11
  6. package/dist/focus-trap.global.js.map +2 -2
  7. package/dist/focus-trap.global.min.js +3 -3
  8. package/dist/focus-trap.global.min.js.map +3 -3
  9. package/dist/index.esm.js +947 -101
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +949 -103
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +3 -3
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.esm.js +66 -22
  16. package/dist/mask.esm.js.map +2 -2
  17. package/dist/mask.global.js +68 -24
  18. package/dist/mask.global.js.map +2 -2
  19. package/dist/mask.global.min.js +3 -3
  20. package/dist/mask.global.min.js.map +3 -3
  21. package/dist/masonry.esm.js +96 -40
  22. package/dist/masonry.esm.js.map +2 -2
  23. package/dist/masonry.global.js +98 -42
  24. package/dist/masonry.global.js.map +2 -2
  25. package/dist/masonry.global.min.js +3 -3
  26. package/dist/masonry.global.min.js.map +3 -3
  27. package/dist/scroll.esm.js +66 -28
  28. package/dist/scroll.esm.js.map +2 -2
  29. package/dist/scroll.global.js +68 -30
  30. package/dist/scroll.global.js.map +2 -2
  31. package/dist/scroll.global.min.js +4 -4
  32. package/dist/scroll.global.min.js.map +3 -3
  33. package/dist/shortcut.esm.js +631 -0
  34. package/dist/shortcut.esm.js.map +7 -0
  35. package/dist/shortcut.global.js +657 -0
  36. package/dist/shortcut.global.js.map +7 -0
  37. package/dist/shortcut.global.min.js +3 -0
  38. package/dist/shortcut.global.min.js.map +7 -0
  39. package/dist/toast.css +1 -1
  40. package/dist/toast.css.map +2 -2
  41. package/dist/toast.esm.js +109 -44
  42. package/dist/toast.esm.js.map +2 -2
  43. package/dist/toast.global.js +111 -46
  44. package/dist/toast.global.js.map +2 -2
  45. package/dist/toast.global.min.js +4 -4
  46. package/dist/toast.global.min.js.map +3 -3
  47. package/dist/types/focus-trap/FocusTrap.d.ts +2 -0
  48. package/dist/types/index.d.ts +2 -0
  49. package/dist/types/mask/AmountEngine.d.ts +1 -0
  50. package/dist/types/mask/BaseInputMask.d.ts +4 -0
  51. package/dist/types/mask/InputAmountMask.d.ts +1 -0
  52. package/dist/types/mask/InputMask.d.ts +1 -0
  53. package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
  54. package/dist/types/shortcut/ShortcutManager.d.ts +95 -0
  55. package/dist/types/shortcut/index.d.ts +4 -0
  56. package/dist/types/shortcut/types.d.ts +101 -0
  57. package/dist/types/toast/ToastInstance.d.ts +1 -1
  58. package/dist/types/toast/types.d.ts +5 -0
  59. package/package.json +20 -11
  60. package/dist/focus-trap.cjs.js +0 -430
  61. package/dist/focus-trap.cjs.js.map +0 -7
  62. package/dist/index.cjs.js +0 -5365
  63. package/dist/index.cjs.js.map +0 -7
  64. package/dist/mask.cjs.js +0 -3086
  65. package/dist/mask.cjs.js.map +0 -7
  66. package/dist/masonry.cjs.js +0 -858
  67. package/dist/masonry.cjs.js.map +0 -7
  68. package/dist/scroll.cjs.js +0 -823
  69. package/dist/scroll.cjs.js.map +0 -7
  70. package/dist/toast.cjs.js +0 -715
  71. package/dist/toast.cjs.js.map +0 -7
@@ -0,0 +1,657 @@
1
+ "use strict";
2
+ var __WulfIIFE = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/shortcut/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ ShortcutFormatter: () => ShortcutFormatter,
25
+ ShortcutManager: () => ShortcutManager,
26
+ default: () => ShortcutManager
27
+ });
28
+
29
+ // src/shortcut/ShortcutFormatter.ts
30
+ var ShortcutFormatter = class _ShortcutFormatter {
31
+ /**
32
+ * Détecte si l'environnement d'exécution actuel est un environnement Apple (macOS / iOS / iPadOS).
33
+ */
34
+ static isApple() {
35
+ if (typeof navigator === "undefined") {
36
+ return false;
37
+ }
38
+ const uaData = navigator.userAgentData;
39
+ if (uaData && typeof uaData.platform === "string") {
40
+ const p = uaData.platform.toLowerCase();
41
+ if (p.includes("mac") || p.includes("ios")) {
42
+ return true;
43
+ }
44
+ }
45
+ const platform = (navigator.platform || "").toLowerCase();
46
+ if (platform.includes("mac") || platform.includes("iphone") || platform.includes("ipad") || platform.includes("ipod")) {
47
+ return true;
48
+ }
49
+ const ua = (navigator.userAgent || "").toLowerCase();
50
+ return ua.includes("macintosh") || ua.includes("mac os x") || ua.includes("ipad") || ua.includes("iphone");
51
+ }
52
+ /**
53
+ * Normalise un nom de touche unitaire pour les comparaisons.
54
+ */
55
+ static normalizeKeyName(key) {
56
+ const k = key.trim().toLowerCase();
57
+ switch (k) {
58
+ case "esc":
59
+ return "escape";
60
+ case "return":
61
+ return "enter";
62
+ case "space":
63
+ case "spacebar":
64
+ return " ";
65
+ case "del":
66
+ return "delete";
67
+ case "ins":
68
+ return "insert";
69
+ case "up":
70
+ return "arrowup";
71
+ case "down":
72
+ return "arrowdown";
73
+ case "left":
74
+ return "arrowleft";
75
+ case "right":
76
+ return "arrowright";
77
+ default:
78
+ return k;
79
+ }
80
+ }
81
+ /**
82
+ * Parse une chaîne de combinaison (ex: "Mod+K", "g i", "Shift+?", "Alt++")
83
+ * et retourne la liste des étapes normalisées nécessaires au déclenchement.
84
+ */
85
+ static parseCombo(combo, isApple = _ShortcutFormatter.isApple()) {
86
+ if (typeof combo !== "string") {
87
+ return [];
88
+ }
89
+ const trimmed = combo.slice(0, 512).trim();
90
+ if (!trimmed) {
91
+ return [];
92
+ }
93
+ const stepsRaw = trimmed.split(/\s+/).slice(0, 10);
94
+ const steps = [];
95
+ for (const rawStep of stepsRaw) {
96
+ const tokens = [];
97
+ let currentToken = "";
98
+ for (let i = 0; i < rawStep.length; i++) {
99
+ const char = rawStep[i];
100
+ if (char === "+") {
101
+ if (currentToken === "" && tokens.length > 0) {
102
+ tokens.push("+");
103
+ } else if (currentToken !== "") {
104
+ tokens.push(currentToken);
105
+ currentToken = "";
106
+ }
107
+ } else {
108
+ currentToken += char;
109
+ }
110
+ }
111
+ if (currentToken !== "") {
112
+ tokens.push(currentToken);
113
+ }
114
+ let ctrl = false;
115
+ let alt = false;
116
+ let shift = false;
117
+ let meta = false;
118
+ let mainKey = "";
119
+ for (const token of tokens) {
120
+ const lower = token.trim().toLowerCase();
121
+ if (lower === "ctrl" || lower === "control") {
122
+ ctrl = true;
123
+ } else if (lower === "alt" || lower === "option" || lower === "opt") {
124
+ alt = true;
125
+ } else if (lower === "shift" || lower === "maj") {
126
+ shift = true;
127
+ } else if (lower === "cmd" || lower === "command" || lower === "meta" || lower === "win" || lower === "super") {
128
+ meta = true;
129
+ } else if (lower === "mod" || lower === "$mod") {
130
+ if (isApple) {
131
+ meta = true;
132
+ } else {
133
+ ctrl = true;
134
+ }
135
+ } else {
136
+ mainKey = _ShortcutFormatter.normalizeKeyName(token);
137
+ }
138
+ }
139
+ steps.push({
140
+ ctrl,
141
+ alt,
142
+ shift,
143
+ meta,
144
+ key: mainKey
145
+ });
146
+ }
147
+ return steps;
148
+ }
149
+ /**
150
+ * Formate une combinaison brute en libellé soigné et lisible pour l'OS cible.
151
+ * Ex: "Mod+Shift+P" -> macOS: "⇧⌘P", Windows: "Ctrl+Shift+P"
152
+ * Ex: "g i" -> "g puis i" ou "g i"
153
+ */
154
+ static format(combo, isApple = _ShortcutFormatter.isApple()) {
155
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
156
+ if (steps.length === 0) {
157
+ return combo;
158
+ }
159
+ const formattedSteps = steps.map((step) => {
160
+ const parts = [];
161
+ if (isApple) {
162
+ if (step.ctrl) parts.push("\u2303");
163
+ if (step.alt) parts.push("\u2325");
164
+ if (step.shift) parts.push("\u21E7");
165
+ if (step.meta) parts.push("\u2318");
166
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, true);
167
+ parts.push(keyDisplay);
168
+ return parts.join("");
169
+ } else {
170
+ if (step.ctrl) parts.push("Ctrl");
171
+ if (step.alt) parts.push("Alt");
172
+ if (step.shift) parts.push("Shift");
173
+ if (step.meta) parts.push("Win");
174
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, false);
175
+ parts.push(keyDisplay);
176
+ return parts.join("+");
177
+ }
178
+ });
179
+ return formattedSteps.join(" ");
180
+ }
181
+ /**
182
+ * Convertit un combo technique vers le format officiel WAI-ARIA `aria-keyshortcuts`.
183
+ * Standard W3C : les modificateurs sont 'Control', 'Alt', 'Shift', 'Meta' et le séparateur est '+'.
184
+ */
185
+ static toAriaKeyShortcuts(combo, isApple = _ShortcutFormatter.isApple()) {
186
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
187
+ return steps.map((step) => {
188
+ const parts = [];
189
+ if (step.ctrl) parts.push("Control");
190
+ if (step.alt) parts.push("Alt");
191
+ if (step.shift) parts.push("Shift");
192
+ if (step.meta) parts.push("Meta");
193
+ parts.push(_ShortcutFormatter.formatKeyDisplay(step.key, false));
194
+ return parts.join("+");
195
+ }).join(" ");
196
+ }
197
+ static formatKeyDisplay(key, isApple) {
198
+ if (!key) return "";
199
+ switch (key.toLowerCase()) {
200
+ case "escape":
201
+ return isApple ? "\u238B" : "Esc";
202
+ case "enter":
203
+ return isApple ? "\u21A9" : "Enter";
204
+ case " ":
205
+ return isApple ? "\u2423" : "Space";
206
+ case "tab":
207
+ return isApple ? "\u21E5" : "Tab";
208
+ case "backspace":
209
+ return isApple ? "\u232B" : "Backspace";
210
+ case "delete":
211
+ return isApple ? "\u2326" : "Suppr";
212
+ case "arrowup":
213
+ return "\u2191";
214
+ case "arrowdown":
215
+ return "\u2193";
216
+ case "arrowleft":
217
+ return "\u2190";
218
+ case "arrowright":
219
+ return "\u2192";
220
+ default:
221
+ return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
222
+ }
223
+ }
224
+ };
225
+
226
+ // src/shortcut/ShortcutManager.ts
227
+ var ShortcutManager = class _ShortcutManager {
228
+ constructor(options) {
229
+ this.shortcuts = /* @__PURE__ */ new Map();
230
+ this.scopeStack = [];
231
+ this.sequenceBuffer = [];
232
+ this.sequenceTimer = null;
233
+ this.isListening = true;
234
+ this.boundListener = null;
235
+ this.idCounter = 0;
236
+ this.options = {
237
+ defaultScope: options?.defaultScope || "global",
238
+ sequenceTimeout: options?.sequenceTimeout ?? 800,
239
+ target: options?.target || (typeof window !== "undefined" ? window : {}),
240
+ onError: options?.onError
241
+ };
242
+ this.scopeStack = [this.options.defaultScope];
243
+ this.initListener();
244
+ }
245
+ /**
246
+ * Vérifie si un élément DOM est une zone d'édition où la saisie de l'utilisateur
247
+ * ne doit JAMAIS être interrompue ou détournée (Axiome Primordial).
248
+ */
249
+ static isEditable(target) {
250
+ if (!target || typeof target.tagName !== "string") {
251
+ return false;
252
+ }
253
+ const el = target;
254
+ const tagName = el.tagName.toUpperCase();
255
+ if (tagName === "INPUT") {
256
+ const type = el.type?.toLowerCase() || "text";
257
+ const nonTextTypes = ["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"];
258
+ return !nonTextTypes.includes(type);
259
+ }
260
+ if (tagName === "TEXTAREA" || tagName === "SELECT") {
261
+ return true;
262
+ }
263
+ if (el.isContentEditable || el.getAttribute("contenteditable") === "true" || el.getAttribute("contenteditable") === "plaintext-only" || el.getAttribute("contenteditable") === "") {
264
+ return true;
265
+ }
266
+ const role = el.getAttribute("role");
267
+ if (role === "textbox" || role === "searchbox") {
268
+ return true;
269
+ }
270
+ if (typeof el.closest === "function") {
271
+ const editableAncestor = el.closest(
272
+ '[contenteditable="true"], [contenteditable="plaintext-only"], [contenteditable=""], [role="textbox"], [role="searchbox"]'
273
+ );
274
+ if (editableAncestor) {
275
+ return true;
276
+ }
277
+ }
278
+ return false;
279
+ }
280
+ /**
281
+ * Vérifie si la cible est un champ de mot de passe (sanctuaire anti-keylogging).
282
+ */
283
+ static isPasswordField(target) {
284
+ if (!target || typeof target.tagName !== "string") {
285
+ return false;
286
+ }
287
+ const el = target;
288
+ return el.tagName.toUpperCase() === "INPUT" && (el.type || "").toLowerCase() === "password";
289
+ }
290
+ /**
291
+ * Enregistre un ou plusieurs raccourcis clavier.
292
+ * Retourne une fonction de nettoyage pour désenregistrer immédiatement.
293
+ */
294
+ bind(definition) {
295
+ const list = Array.isArray(definition) ? definition : [definition];
296
+ const registeredIds = [];
297
+ for (const def of list) {
298
+ if (!def.combo || typeof def.handler !== "function") {
299
+ continue;
300
+ }
301
+ const id = `wulf_shortcut_${++this.idCounter}`;
302
+ const normalizedSteps = ShortcutFormatter.parseCombo(def.combo);
303
+ const isSequence = normalizedSteps.length > 1;
304
+ const formattedCombo = ShortcutFormatter.format(def.combo);
305
+ const registered = {
306
+ ...def,
307
+ id,
308
+ scope: def.scope || "global",
309
+ category: def.category || "G\xE9n\xE9ral",
310
+ allowInEditable: def.allowInEditable ?? false,
311
+ preventDefault: def.preventDefault ?? true,
312
+ stopPropagation: def.stopPropagation ?? true,
313
+ priority: def.priority ?? 0,
314
+ formattedCombo,
315
+ normalizedSteps,
316
+ isSequence
317
+ };
318
+ this.shortcuts.set(id, registered);
319
+ registeredIds.push(id);
320
+ }
321
+ return () => {
322
+ for (const id of registeredIds) {
323
+ this.shortcuts.delete(id);
324
+ }
325
+ };
326
+ }
327
+ /**
328
+ * Retire tous les raccourcis correspondant à une combinaison et éventuellement un scope.
329
+ */
330
+ unbind(combo, scope) {
331
+ const formatted = ShortcutFormatter.format(combo);
332
+ for (const [id, s] of this.shortcuts.entries()) {
333
+ if (s.formattedCombo === formatted || s.combo.trim().toLowerCase() === combo.trim().toLowerCase()) {
334
+ if (!scope || s.scope === scope) {
335
+ this.shortcuts.delete(id);
336
+ }
337
+ }
338
+ }
339
+ }
340
+ /**
341
+ * Empile un nouveau scope actif (mode LIFO).
342
+ * Seuls les raccourcis de ce scope (et les omniprésents '*') seront actifs.
343
+ */
344
+ pushScope(scope) {
345
+ if (scope && typeof scope === "string") {
346
+ if (this.scopeStack.length >= 64) {
347
+ return;
348
+ }
349
+ this.scopeStack.push(scope);
350
+ this.clearSequenceBuffer();
351
+ }
352
+ }
353
+ /**
354
+ * Dépile le scope actuel et rétablit le précédent.
355
+ * Si un paramètre `scope` est passé, ne retire que si le scope actuel correspond.
356
+ */
357
+ popScope(scope) {
358
+ if (this.scopeStack.length <= 1) {
359
+ return this.scopeStack[0];
360
+ }
361
+ if (scope) {
362
+ if (this.getScope() === scope) {
363
+ const popped2 = this.scopeStack.pop();
364
+ this.clearSequenceBuffer();
365
+ return popped2;
366
+ }
367
+ return void 0;
368
+ }
369
+ const popped = this.scopeStack.pop();
370
+ this.clearSequenceBuffer();
371
+ return popped;
372
+ }
373
+ /**
374
+ * Réinitialise brutalement la pile pour activer le scope spécifié.
375
+ */
376
+ setScope(scope) {
377
+ this.scopeStack = [scope || this.options.defaultScope];
378
+ this.clearSequenceBuffer();
379
+ }
380
+ /**
381
+ * Retourne le scope actuellement actif au sommet de la pile.
382
+ */
383
+ getScope() {
384
+ return this.scopeStack[this.scopeStack.length - 1] || this.options.defaultScope;
385
+ }
386
+ /**
387
+ * Retourne une copie de la pile complète des scopes.
388
+ */
389
+ getScopeStack() {
390
+ return [...this.scopeStack];
391
+ }
392
+ /**
393
+ * Met en pause l'écoute de tous les raccourcis.
394
+ */
395
+ pause() {
396
+ this.isListening = false;
397
+ this.clearSequenceBuffer();
398
+ }
399
+ /**
400
+ * Réactive l'écoute des raccourcis.
401
+ */
402
+ resume() {
403
+ this.isListening = true;
404
+ }
405
+ /**
406
+ * Indique si le gestionnaire est actif et à l'écoute.
407
+ */
408
+ isActive() {
409
+ return this.isListening;
410
+ }
411
+ /**
412
+ * Retourne le catalogue des raccourcis enregistrés (optionnellement filtré par scope).
413
+ */
414
+ getRegistry(scope) {
415
+ const list = [];
416
+ for (const shortcut of this.shortcuts.values()) {
417
+ if (!scope || shortcut.scope === scope || shortcut.scope === "*") {
418
+ list.push({ ...shortcut });
419
+ }
420
+ }
421
+ return list;
422
+ }
423
+ /**
424
+ * Associe l'attribut standard WAI-ARIA `aria-keyshortcuts` sur un élément DOM.
425
+ */
426
+ attachAria(element, combo) {
427
+ if (element && typeof element.setAttribute === "function") {
428
+ const ariaValue = ShortcutFormatter.toAriaKeyShortcuts(combo);
429
+ element.setAttribute("aria-keyshortcuts", ariaValue);
430
+ }
431
+ }
432
+ /**
433
+ * Formate une combinaison brute selon l'OS courant ("⌘K" ou "Ctrl+K").
434
+ */
435
+ static format(combo, isApple) {
436
+ return ShortcutFormatter.format(combo, isApple);
437
+ }
438
+ /**
439
+ * Détruit le gestionnaire : supprime les écouteurs du DOM et vide toute la mémoire.
440
+ */
441
+ destroy() {
442
+ this.pause();
443
+ this.removeListener();
444
+ this.shortcuts.clear();
445
+ this.scopeStack = [];
446
+ this.clearSequenceBuffer();
447
+ }
448
+ // --- Implémentation Interne ---
449
+ initListener() {
450
+ if (typeof window === "undefined" || !this.options.target) {
451
+ return;
452
+ }
453
+ this.boundListener = (event) => this.handleKeyDown(event);
454
+ const target = this.options.target;
455
+ if (typeof target.addEventListener === "function") {
456
+ target.addEventListener("keydown", this.boundListener, false);
457
+ }
458
+ }
459
+ removeListener() {
460
+ if (this.boundListener && this.options.target) {
461
+ const target = this.options.target;
462
+ if (typeof target.removeEventListener === "function") {
463
+ target.removeEventListener("keydown", this.boundListener, false);
464
+ }
465
+ this.boundListener = null;
466
+ }
467
+ }
468
+ handleKeyDown(event) {
469
+ if (!this.isListening) {
470
+ return;
471
+ }
472
+ const k = (event.key || "").toLowerCase();
473
+ if (["control", "alt", "shift", "meta"].includes(k)) {
474
+ return;
475
+ }
476
+ const currentScope = this.getScope();
477
+ const composed = typeof event.composedPath === "function" ? event.composedPath() : [];
478
+ const actualTarget = composed.length > 0 ? composed[0] : event.target;
479
+ const isEditable = _ShortcutManager.isEditable(actualTarget) || _ShortcutManager.isEditable(event.target);
480
+ const isPasswordInput = _ShortcutManager.isPasswordField(actualTarget) || _ShortcutManager.isPasswordField(event.target);
481
+ const currentStep = {
482
+ ctrl: event.ctrlKey,
483
+ alt: event.altKey,
484
+ shift: event.shiftKey,
485
+ meta: event.metaKey,
486
+ key: ShortcutFormatter.normalizeKeyName(event.key || "")
487
+ };
488
+ const now = Date.now();
489
+ if (this.sequenceBuffer.length > 0) {
490
+ const last = this.sequenceBuffer[this.sequenceBuffer.length - 1];
491
+ if (now - last.timestamp > this.options.sequenceTimeout) {
492
+ this.clearSequenceBuffer();
493
+ }
494
+ }
495
+ const activeCandidates = this.getActiveShortcuts(currentScope, isEditable, isPasswordInput);
496
+ const proposedSequence = [...this.sequenceBuffer.map((b) => b.step), currentStep];
497
+ const matchingSequence = this.findMatchingSequence(activeCandidates, proposedSequence);
498
+ if (matchingSequence) {
499
+ this.clearSequenceBuffer();
500
+ this.executeShortcut(matchingSequence, event, currentScope, true);
501
+ return;
502
+ }
503
+ if (this.isPrefixOfAnySequence(activeCandidates, proposedSequence)) {
504
+ this.sequenceBuffer.push({ step: currentStep, timestamp: now });
505
+ this.resetSequenceTimer();
506
+ if (event.key.length === 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !isEditable) {
507
+ event.preventDefault();
508
+ }
509
+ return;
510
+ }
511
+ this.clearSequenceBuffer();
512
+ const matchingChord = this.findMatchingChord(activeCandidates, currentStep, event);
513
+ if (matchingChord) {
514
+ this.executeShortcut(matchingChord, event, currentScope, false);
515
+ }
516
+ }
517
+ getActiveShortcuts(currentScope, isEditable, isPasswordInput = false) {
518
+ const list = [];
519
+ for (const shortcut of this.shortcuts.values()) {
520
+ if (shortcut.scope !== currentScope && shortcut.scope !== "*") {
521
+ continue;
522
+ }
523
+ if (isEditable && !shortcut.allowInEditable) {
524
+ continue;
525
+ }
526
+ if (isPasswordInput) {
527
+ if (shortcut.isSequence) {
528
+ continue;
529
+ }
530
+ const firstStep = shortcut.normalizedSteps[0];
531
+ if (firstStep && firstStep.key.length === 1 && !firstStep.ctrl && !firstStep.alt && !firstStep.meta) {
532
+ continue;
533
+ }
534
+ }
535
+ list.push(shortcut);
536
+ }
537
+ return list.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
538
+ }
539
+ stepMatches(step, eventStep, rawEvent) {
540
+ if (step.ctrl !== eventStep.ctrl) return false;
541
+ if (step.alt !== eventStep.alt) return false;
542
+ if (step.meta !== eventStep.meta) return false;
543
+ const keyMatches = step.key === eventStep.key || rawEvent && step.key === rawEvent.key.toLowerCase();
544
+ if (!keyMatches) return false;
545
+ if (step.shift === eventStep.shift) {
546
+ return true;
547
+ }
548
+ if (!step.shift && eventStep.shift) {
549
+ if (rawEvent && rawEvent.key === step.key) {
550
+ return true;
551
+ }
552
+ }
553
+ return false;
554
+ }
555
+ findMatchingChord(candidates, currentStep, rawEvent) {
556
+ for (const candidate of candidates) {
557
+ if (candidate.isSequence || candidate.normalizedSteps.length !== 1) {
558
+ continue;
559
+ }
560
+ const step = candidate.normalizedSteps[0];
561
+ if (this.stepMatches(step, currentStep, rawEvent)) {
562
+ return candidate;
563
+ }
564
+ }
565
+ return null;
566
+ }
567
+ findMatchingSequence(candidates, proposed) {
568
+ for (const candidate of candidates) {
569
+ if (!candidate.isSequence || candidate.normalizedSteps.length !== proposed.length) {
570
+ continue;
571
+ }
572
+ let allMatch = true;
573
+ for (let i = 0; i < proposed.length; i++) {
574
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
575
+ allMatch = false;
576
+ break;
577
+ }
578
+ }
579
+ if (allMatch) {
580
+ return candidate;
581
+ }
582
+ }
583
+ return null;
584
+ }
585
+ isPrefixOfAnySequence(candidates, proposed) {
586
+ for (const candidate of candidates) {
587
+ if (!candidate.isSequence || candidate.normalizedSteps.length <= proposed.length) {
588
+ continue;
589
+ }
590
+ let prefixMatches = true;
591
+ for (let i = 0; i < proposed.length; i++) {
592
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
593
+ prefixMatches = false;
594
+ break;
595
+ }
596
+ }
597
+ if (prefixMatches) {
598
+ return true;
599
+ }
600
+ }
601
+ return false;
602
+ }
603
+ executeShortcut(shortcut, event, scope, isSequence) {
604
+ if (shortcut.preventDefault) {
605
+ event.preventDefault();
606
+ }
607
+ if (shortcut.stopPropagation) {
608
+ event.stopPropagation();
609
+ }
610
+ const info = {
611
+ combo: shortcut.combo,
612
+ formattedCombo: shortcut.formattedCombo,
613
+ scope,
614
+ target: event.target,
615
+ isSequence
616
+ };
617
+ try {
618
+ shortcut.handler(event, info);
619
+ } catch (err) {
620
+ if (this.options.onError) {
621
+ this.options.onError(err instanceof Error ? err : new Error(String(err)), shortcut.combo);
622
+ } else {
623
+ console.error(`[Wulf.Shortcut] Erreur lors de l'ex\xE9cution du raccourci "${shortcut.combo}":`, err);
624
+ }
625
+ }
626
+ }
627
+ resetSequenceTimer() {
628
+ if (this.sequenceTimer) {
629
+ clearTimeout(this.sequenceTimer);
630
+ }
631
+ this.sequenceTimer = setTimeout(() => {
632
+ this.clearSequenceBuffer();
633
+ }, this.options.sequenceTimeout);
634
+ }
635
+ clearSequenceBuffer() {
636
+ this.sequenceBuffer = [];
637
+ if (this.sequenceTimer) {
638
+ clearTimeout(this.sequenceTimer);
639
+ this.sequenceTimer = null;
640
+ }
641
+ }
642
+ };
643
+
644
+ // src/shortcut/index.ts
645
+ if (typeof window !== "undefined") {
646
+ const win = window;
647
+ const wulfNamespace = win.Wulf || {};
648
+ win.Wulf = wulfNamespace;
649
+ wulfNamespace.Shortcut = Object.assign(ShortcutManager, {
650
+ ShortcutManager,
651
+ ShortcutFormatter
652
+ });
653
+ }
654
+ return __toCommonJS(index_exports);
655
+ })();
656
+ if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.prototype.hasOwnProperty.call(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
657
+ //# sourceMappingURL=shortcut.global.js.map