hotkey-router 0.5.0 → 0.5.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 +290 -658
- package/data/browser-hotkeys.json +40 -0
- package/data/site-hotkeys.json +1 -1
- package/data/site-hotkeys.runtime.json +1 -1
- package/dist/auto.js +1 -1
- package/dist/auto.min.js +2 -2
- package/dist/core.js +62 -27
- package/dist/core.js.map +3 -3
- package/dist/format.js +43 -18
- package/dist/format.js.map +3 -3
- package/dist/hotkey-router.cjs +62 -27
- package/dist/hotkey-router.cjs.map +3 -3
- package/dist/hotkey-router.js +1 -1
- package/dist/hotkey-router.min.js +2 -2
- package/dist/reservations.js +168 -24
- package/dist/reservations.js.map +3 -3
- package/dist/sites.js +35 -10
- package/dist/sites.js.map +3 -3
- package/dist/types/lookup.d.ts +1 -0
- package/dist/types/reservations.d.ts +14 -1
- package/dist/validate.js +25 -9
- package/dist/validate.js.map +3 -3
- package/package.json +1 -1
package/dist/reservations.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
// hotkey-router v0.5.
|
|
1
|
+
// hotkey-router v0.5.2 | SEE LICENSE IN LICENSE
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
// lookup.js
|
|
5
|
+
function ownValue(table, key) {
|
|
6
|
+
return table != null && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : void 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
// data/browser-hotkeys.json
|
|
5
10
|
var browser_hotkeys_default = {
|
|
6
11
|
$comment: "Machine-readable companion to docs/browser-hotkeys.md. Each combo entry describes who claims the binding and how strongly. Intended for runtime conflict warnings in keyboard-routing libraries (e.g. hotkey-router) and dev-time validation in apps like WebRadar. Update both this file and the markdown together \u2014 the markdown is the human source of truth, this file is the machine projection.",
|
|
@@ -145,6 +150,46 @@ var browser_hotkeys_default = {
|
|
|
145
150
|
"meta+shift+z": { action: "Redo", severity: "hard" },
|
|
146
151
|
"meta+alt+c": { action: "Web Inspector pick", severity: "hard" },
|
|
147
152
|
"meta+alt+i": { action: "Web Inspector", severity: "hard" }
|
|
153
|
+
},
|
|
154
|
+
edge: {
|
|
155
|
+
$comment: "From Microsoft's Edge shortcuts page (Mac table), 2026-11-15. Edit-menu rows (meta+a/c/v/x/z, meta+shift+z) as Chrome. Not checked with real keys.",
|
|
156
|
+
"meta+a": { action: "Select all", severity: "hard" },
|
|
157
|
+
"meta+c": { action: "Copy", severity: "hard" },
|
|
158
|
+
"meta+d": { action: "Save as favorite", severity: "hard" },
|
|
159
|
+
"meta+f": { action: "Find in page", severity: "hard" },
|
|
160
|
+
"meta+g": { action: "Find next", severity: "hard" },
|
|
161
|
+
"meta+l": { action: "Focus address bar", severity: "hard" },
|
|
162
|
+
"meta+n": { action: "New window", severity: "hard" },
|
|
163
|
+
"meta+o": { action: "Open file", severity: "hard" },
|
|
164
|
+
"meta+p": { action: "Print", severity: "hard" },
|
|
165
|
+
"meta+r": { action: "Reload", severity: "hard" },
|
|
166
|
+
"meta+s": { action: "Save page", severity: "hard" },
|
|
167
|
+
"meta+t": { action: "New tab", severity: "hard" },
|
|
168
|
+
"meta+v": { action: "Paste", severity: "hard" },
|
|
169
|
+
"meta+w": { action: "Close tab", severity: "hard" },
|
|
170
|
+
"meta+x": { action: "Cut", severity: "hard" },
|
|
171
|
+
"meta+y": { action: "History", severity: "hard" },
|
|
172
|
+
"meta+z": { action: "Undo", severity: "hard" },
|
|
173
|
+
"ctrl+m": { action: "Mute current tab", severity: "hard" },
|
|
174
|
+
"ctrl+meta+f": { action: "Toggle full screen", severity: "hard" },
|
|
175
|
+
"meta+shift+b": { action: "Favorites bar toggle", severity: "hard" },
|
|
176
|
+
"meta+shift+c": { action: "Developer tools", severity: "hard" },
|
|
177
|
+
"meta+shift+d": { action: "Favorite all tabs", severity: "hard" },
|
|
178
|
+
"meta+shift+e": { action: "Search in sidebar", severity: "hard" },
|
|
179
|
+
"meta+shift+g": { action: "Find previous", severity: "find-bar-only" },
|
|
180
|
+
"meta+shift+h": { action: "Home page", severity: "hard" },
|
|
181
|
+
"meta+shift+m": { action: "Switch user / guest", severity: "hard" },
|
|
182
|
+
"meta+shift+n": { action: "New InPrivate window", severity: "hard" },
|
|
183
|
+
"meta+shift+r": { action: "Hard reload", severity: "hard" },
|
|
184
|
+
"meta+shift+t": { action: "Reopen closed tab", severity: "hard" },
|
|
185
|
+
"meta+shift+u": { action: "Read Aloud toggle", severity: "hard" },
|
|
186
|
+
"meta+shift+v": { action: "Paste as plain text", severity: "hard" },
|
|
187
|
+
"meta+shift+w": { action: "Close window", severity: "hard" },
|
|
188
|
+
"meta+shift+z": { action: "Redo", severity: "hard" },
|
|
189
|
+
"meta+alt+f": { action: "Search the web", severity: "hard" },
|
|
190
|
+
"meta+alt+j": { action: "JavaScript console", severity: "hard" },
|
|
191
|
+
"meta+alt+l": { action: "Downloads", severity: "hard" },
|
|
192
|
+
"meta+alt+m": { action: "Minimize all windows", severity: "hard" }
|
|
148
193
|
}
|
|
149
194
|
},
|
|
150
195
|
system: {
|
|
@@ -386,11 +431,22 @@ function detectBrowser(nav = typeof navigator !== "undefined" ? navigator : null
|
|
|
386
431
|
}
|
|
387
432
|
var PLATFORM_LABELS = { mac: "macOS", windows: "Windows", linux: "Linux", chromeos: "ChromeOS" };
|
|
388
433
|
function platformLabel(platform) {
|
|
389
|
-
return PLATFORM_LABELS
|
|
434
|
+
return ownValue(PLATFORM_LABELS, platform) || platform;
|
|
390
435
|
}
|
|
391
436
|
|
|
392
437
|
// parse.js
|
|
393
438
|
var DEFAULT_PLATFORM = detectPlatform();
|
|
439
|
+
var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
|
|
440
|
+
var ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
441
|
+
["^", "ctrl"],
|
|
442
|
+
// Ctrl
|
|
443
|
+
["!", "alt"],
|
|
444
|
+
// Alt
|
|
445
|
+
["+", "shift"],
|
|
446
|
+
// Shift
|
|
447
|
+
["#", "meta"]
|
|
448
|
+
// Win / Command
|
|
449
|
+
]);
|
|
394
450
|
var keyAliases = Object.freeze({
|
|
395
451
|
// common
|
|
396
452
|
esc: "escape",
|
|
@@ -441,8 +497,105 @@ function normalizeKey(key) {
|
|
|
441
497
|
if (original === " ") return " ";
|
|
442
498
|
const trimmed = original.trim();
|
|
443
499
|
const k = trimmed.toLowerCase();
|
|
444
|
-
return keyAliases
|
|
500
|
+
return ownValue(keyAliases, k) ?? k;
|
|
501
|
+
}
|
|
502
|
+
function isModifierToken(token) {
|
|
503
|
+
return modifierTokens.has(normalizeKey(token));
|
|
504
|
+
}
|
|
505
|
+
var CODE_TOKEN_RE = /(^|\+)\s*code:([A-Za-z][A-Za-z0-9_]*)/;
|
|
506
|
+
function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
|
|
507
|
+
const raw = String(hotkeyStr || "").trim();
|
|
508
|
+
let error = null;
|
|
509
|
+
const fail = (msg) => {
|
|
510
|
+
error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
|
|
511
|
+
};
|
|
512
|
+
const isUp = /\s+up$/i.test(raw);
|
|
513
|
+
const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
|
|
514
|
+
const combo = {
|
|
515
|
+
ctrl: false,
|
|
516
|
+
shift: false,
|
|
517
|
+
alt: false,
|
|
518
|
+
meta: false,
|
|
519
|
+
key: null,
|
|
520
|
+
code: null,
|
|
521
|
+
bareModifier: null
|
|
522
|
+
};
|
|
523
|
+
const setMod = (mod) => {
|
|
524
|
+
if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
|
|
525
|
+
else combo[mod] = true;
|
|
526
|
+
};
|
|
527
|
+
let stripped = baseRaw;
|
|
528
|
+
while (stripped.length > 1) {
|
|
529
|
+
const mod = ahkPrefixMap.get(stripped[0]) ?? null;
|
|
530
|
+
if (!mod) break;
|
|
531
|
+
setMod(mod);
|
|
532
|
+
stripped = stripped.slice(1).trimStart();
|
|
533
|
+
}
|
|
534
|
+
const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
|
|
535
|
+
if (codeMatches && codeMatches.length > 1) {
|
|
536
|
+
fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
|
|
537
|
+
}
|
|
538
|
+
let codeValue = null;
|
|
539
|
+
const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
|
|
540
|
+
codeValue = val;
|
|
541
|
+
return sep + "__code__";
|
|
542
|
+
});
|
|
543
|
+
const cleanStr = scrubbed.toLowerCase();
|
|
544
|
+
const rawParts = cleanStr.split("+").map((p) => p.trim());
|
|
545
|
+
const parts = rawParts.filter(Boolean);
|
|
546
|
+
const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
|
|
547
|
+
if (!impliedPlusKey) {
|
|
548
|
+
let seenBase = false;
|
|
549
|
+
for (const part of parts) {
|
|
550
|
+
if (isModifierToken(part)) {
|
|
551
|
+
if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
|
|
552
|
+
} else {
|
|
553
|
+
seenBase = true;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
let bases = 0;
|
|
558
|
+
for (const part of parts) {
|
|
559
|
+
if (part === "__code__") {
|
|
560
|
+
combo.code = codeValue;
|
|
561
|
+
bases++;
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
const actual = ownValue(keyAliases, part) ?? part;
|
|
565
|
+
if (modifierTokens.has(actual)) setMod(actual);
|
|
566
|
+
else {
|
|
567
|
+
combo.key = normalizeKey(actual);
|
|
568
|
+
bases++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (bases > 1) fail('use one base key (e.g. "ctrl+k"), or one code: token');
|
|
572
|
+
if (!combo.key && !combo.code && (impliedPlusKey || stripped === "+")) combo.key = "+";
|
|
573
|
+
if (!combo.key && !combo.code) {
|
|
574
|
+
const modCount = (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) + (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0);
|
|
575
|
+
if (modCount === 1) {
|
|
576
|
+
combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
|
|
577
|
+
} else if (modCount > 1) {
|
|
578
|
+
fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
|
|
579
|
+
} else {
|
|
580
|
+
error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
|
|
445
584
|
}
|
|
585
|
+
var SHIFTED_PUNCT = {
|
|
586
|
+
",": ["<", "Comma"],
|
|
587
|
+
".": [">", "Period"],
|
|
588
|
+
"/": ["?", "Slash"],
|
|
589
|
+
";": [":", "Semicolon"],
|
|
590
|
+
"'": ['"', "Quote"],
|
|
591
|
+
"[": ["{", "BracketLeft"],
|
|
592
|
+
"]": ["}", "BracketRight"],
|
|
593
|
+
"\\": ["|", "Backslash"],
|
|
594
|
+
"-": ["_", "Minus"],
|
|
595
|
+
"=": ["+", "Equal"],
|
|
596
|
+
"`": ["~", "Backquote"]
|
|
597
|
+
};
|
|
598
|
+
for (let d = 0; d < 10; d++) SHIFTED_PUNCT[d] = [")!@#$%^&*("[d], "Digit" + d];
|
|
446
599
|
var PUNCT_NAMES = {
|
|
447
600
|
".": "period",
|
|
448
601
|
",": "comma",
|
|
@@ -468,9 +621,9 @@ function codeToBase(code) {
|
|
|
468
621
|
}
|
|
469
622
|
function keyToBase(key) {
|
|
470
623
|
if (key == null || key === "") return null;
|
|
471
|
-
if (PUNCT_NAMES
|
|
624
|
+
if (ownValue(PUNCT_NAMES, key)) return ownValue(PUNCT_NAMES, key);
|
|
472
625
|
const k = normalizeKey(key);
|
|
473
|
-
return PUNCT_NAMES
|
|
626
|
+
return ownValue(PUNCT_NAMES, k) || k || null;
|
|
474
627
|
}
|
|
475
628
|
function lookupKey(combo) {
|
|
476
629
|
if (!combo || combo.bareModifier) return null;
|
|
@@ -490,17 +643,7 @@ var SUPPORTED_SCHEMA = "1.0";
|
|
|
490
643
|
var HARD_SEVERITIES = /* @__PURE__ */ new Set(["hard", "os", "menu-activation"]);
|
|
491
644
|
var SOFT_SEVERITIES = /* @__PURE__ */ new Set(["find-bar-only", "compose", "system-text", "devtools-open", "preventable"]);
|
|
492
645
|
function canonicalize(rawKey) {
|
|
493
|
-
|
|
494
|
-
if (!parts.length) return "";
|
|
495
|
-
const base = parts[parts.length - 1];
|
|
496
|
-
const mods = new Set(parts.slice(0, -1));
|
|
497
|
-
const out = [];
|
|
498
|
-
if (mods.has("ctrl")) out.push("ctrl");
|
|
499
|
-
if (mods.has("meta")) out.push("meta");
|
|
500
|
-
if (mods.has("alt")) out.push("alt");
|
|
501
|
-
if (mods.has("shift")) out.push("shift");
|
|
502
|
-
out.push(base);
|
|
503
|
-
return out.join("+");
|
|
646
|
+
return lookupKey(readHotkey(rawKey).combo) || "";
|
|
504
647
|
}
|
|
505
648
|
function resolveRef(value, root) {
|
|
506
649
|
if (typeof value !== "string" || !value.startsWith("$ref:")) return value;
|
|
@@ -519,10 +662,10 @@ function normalizeTable(table) {
|
|
|
519
662
|
return out;
|
|
520
663
|
}
|
|
521
664
|
function buildIndex(data) {
|
|
522
|
-
const idx = { platforms:
|
|
665
|
+
const idx = { platforms: /* @__PURE__ */ Object.create(null) };
|
|
523
666
|
const platforms = data?.platforms || {};
|
|
524
667
|
for (const [platform, pdata] of Object.entries(platforms)) {
|
|
525
|
-
const browsers =
|
|
668
|
+
const browsers = /* @__PURE__ */ Object.create(null);
|
|
526
669
|
for (const [name, btable] of Object.entries(pdata.browsers || {})) {
|
|
527
670
|
browsers[name] = normalizeTable(resolveRef(btable, data));
|
|
528
671
|
}
|
|
@@ -534,16 +677,16 @@ function buildIndex(data) {
|
|
|
534
677
|
return idx;
|
|
535
678
|
}
|
|
536
679
|
var SCHEMA_OK = browser_hotkeys_default?.version?.schema === SUPPORTED_SCHEMA;
|
|
537
|
-
var INDEX = SCHEMA_OK ? buildIndex(browser_hotkeys_default) : { platforms:
|
|
680
|
+
var INDEX = SCHEMA_OK ? buildIndex(browser_hotkeys_default) : { platforms: /* @__PURE__ */ Object.create(null) };
|
|
538
681
|
var lookupKeyFromCombo = lookupKey;
|
|
539
682
|
function lookupReservation(combo, { platform, browser } = {}) {
|
|
540
683
|
if (!SCHEMA_OK) return null;
|
|
541
684
|
const lookupKey2 = lookupKeyFromCombo(combo);
|
|
542
685
|
if (!lookupKey2) return null;
|
|
543
|
-
const pdata = platform && INDEX.platforms
|
|
686
|
+
const pdata = platform && ownValue(INDEX.platforms, platform);
|
|
544
687
|
if (!pdata) return null;
|
|
545
|
-
const btable = browser ? pdata.browsers
|
|
546
|
-
const bclaim = btable
|
|
688
|
+
const btable = browser ? ownValue(pdata.browsers, browser) : null;
|
|
689
|
+
const bclaim = ownValue(btable, lookupKey2);
|
|
547
690
|
if (bclaim) {
|
|
548
691
|
return {
|
|
549
692
|
source: "browser",
|
|
@@ -554,7 +697,7 @@ function lookupReservation(combo, { platform, browser } = {}) {
|
|
|
554
697
|
severity: bclaim.severity
|
|
555
698
|
};
|
|
556
699
|
}
|
|
557
|
-
const sclaim = pdata.system
|
|
700
|
+
const sclaim = ownValue(pdata.system, lookupKey2);
|
|
558
701
|
if (sclaim) {
|
|
559
702
|
return {
|
|
560
703
|
source: "system",
|
|
@@ -603,9 +746,10 @@ function installReservationWarnings(hotkeys, opts = {}) {
|
|
|
603
746
|
}
|
|
604
747
|
var SCHEMA_VERSION = browser_hotkeys_default?.version?.schema;
|
|
605
748
|
var DATA_GENERATED = browser_hotkeys_default?.version?.generated;
|
|
749
|
+
var BUNDLED_DATA = browser_hotkeys_default;
|
|
606
750
|
export {
|
|
607
751
|
DATA_GENERATED,
|
|
608
|
-
|
|
752
|
+
BUNDLED_DATA as HOTKEY_DATA,
|
|
609
753
|
SCHEMA_VERSION,
|
|
610
754
|
detectBrowser,
|
|
611
755
|
detectPlatform,
|