wulf.js 1.9.1 → 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 +154 -21
- package/changelog.md +21 -0
- package/dist/focus-trap.global.js +1 -1
- package/dist/focus-trap.global.min.js +1 -1
- package/dist/index.esm.js +589 -0
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +590 -1
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +3 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.global.js +1 -1
- package/dist/mask.global.min.js +1 -1
- package/dist/masonry.global.js +1 -1
- package/dist/masonry.global.min.js +1 -1
- package/dist/scroll.global.js +1 -1
- package/dist/scroll.global.min.js +1 -1
- 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.global.js +1 -1
- package/dist/toast.global.min.js +1 -1
- package/dist/types/index.d.ts +2 -0
- 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/package.json +17 -10
- package/dist/focus-trap.cjs.js +0 -430
- package/dist/focus-trap.cjs.js.map +0 -7
- package/dist/index.cjs.js +0 -5365
- package/dist/index.cjs.js.map +0 -7
- package/dist/mask.cjs.js +0 -3086
- package/dist/mask.cjs.js.map +0 -7
- package/dist/masonry.cjs.js +0 -858
- package/dist/masonry.cjs.js.map +0 -7
- package/dist/scroll.cjs.js +0 -823
- package/dist/scroll.cjs.js.map +0 -7
- package/dist/toast.cjs.js +0 -715
- package/dist/toast.cjs.js.map +0 -7
package/dist/index.global.js
CHANGED
|
@@ -36,8 +36,10 @@ var Wulf = (() => {
|
|
|
36
36
|
MaskKeyboard: () => MaskKeyboard,
|
|
37
37
|
Masonry: () => masonry_exports,
|
|
38
38
|
Scroll: () => scroll_exports,
|
|
39
|
+
Shortcut: () => shortcut_exports,
|
|
39
40
|
Toast: () => toast_exports,
|
|
40
41
|
WulfFocusTrap: () => FocusTrap,
|
|
42
|
+
WulfShortcut: () => ShortcutManager,
|
|
41
43
|
createI18nManager: () => createI18nManager,
|
|
42
44
|
default: () => mask_default,
|
|
43
45
|
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
|
|
@@ -5362,7 +5364,594 @@ var Wulf = (() => {
|
|
|
5362
5364
|
FocusTrap
|
|
5363
5365
|
});
|
|
5364
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
|
+
};
|
|
5365
5954
|
return __toCommonJS(index_exports);
|
|
5366
5955
|
})();
|
|
5367
|
-
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 (__) {} } } } } }
|
|
5368
5957
|
//# sourceMappingURL=index.global.js.map
|