hotkey-router 0.0.3 → 0.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/LICENSE +284 -284
- package/README.md +479 -333
- package/data/browser-hotkeys.json +349 -0
- package/dist/auto.js +967 -0
- package/dist/auto.js.map +7 -0
- package/dist/auto.min.js +3 -0
- package/dist/hotkey-router.cjs +141 -37
- package/dist/hotkey-router.cjs.map +2 -2
- package/dist/hotkey-router.js +141 -37
- package/dist/hotkey-router.js.map +2 -2
- package/dist/hotkey-router.min.js +2 -2
- package/dist/reservations.js +528 -0
- package/dist/reservations.js.map +7 -0
- package/package.json +62 -51
package/dist/hotkey-router.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// hotkey-router v0.0
|
|
1
|
+
// hotkey-router v0.2.0 | SEE LICENSE IN LICENSE
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -17,6 +17,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// hotkey-router.js
|
|
20
22
|
var hotkey_router_exports = {};
|
|
21
23
|
__export(hotkey_router_exports, {
|
|
22
24
|
default: () => hotkey_router_default
|
|
@@ -26,9 +28,17 @@ function on(target, type, fn, options) {
|
|
|
26
28
|
target.addEventListener(type, fn, options);
|
|
27
29
|
return () => target.removeEventListener(type, fn, options);
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform);
|
|
32
|
+
var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta"]);
|
|
33
|
+
var MODIFIER_KEY_TOKEN = Object.freeze({
|
|
34
|
+
Alt: "alt",
|
|
35
|
+
AltGraph: "alt",
|
|
36
|
+
Control: "ctrl",
|
|
37
|
+
Shift: "shift",
|
|
38
|
+
Meta: "meta",
|
|
39
|
+
OS: "meta"
|
|
40
|
+
});
|
|
41
|
+
var ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
32
42
|
["^", "ctrl"],
|
|
33
43
|
// Ctrl
|
|
34
44
|
["!", "alt"],
|
|
@@ -38,7 +48,7 @@ const ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
|
38
48
|
["#", "meta"]
|
|
39
49
|
// Win / Command
|
|
40
50
|
]);
|
|
41
|
-
|
|
51
|
+
var keyAliases = Object.freeze({
|
|
42
52
|
// common
|
|
43
53
|
esc: "escape",
|
|
44
54
|
escape: "escape",
|
|
@@ -82,27 +92,32 @@ const keyAliases = Object.freeze({
|
|
|
82
92
|
// plus key ergonomics
|
|
83
93
|
plus: "+"
|
|
84
94
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
var ignoreEditable = true;
|
|
96
|
+
var defaultTarget = typeof window !== "undefined" ? window : null;
|
|
97
|
+
var bindHooks = [];
|
|
98
|
+
var registry = /* @__PURE__ */ new Map();
|
|
99
|
+
var plugins = /* @__PURE__ */ new Map();
|
|
100
|
+
var bindingIndex = /* @__PURE__ */ new Map();
|
|
101
|
+
var paused = false;
|
|
102
|
+
var nextId = 1;
|
|
92
103
|
function normalizeKey(key) {
|
|
93
104
|
const raw = String(key ?? "").trim();
|
|
94
105
|
const k = raw.toLowerCase();
|
|
95
106
|
return keyAliases[k] ?? (raw === " " ? " " : k);
|
|
96
107
|
}
|
|
97
|
-
function comboKeyFromParts({ ctrl, shift, alt, meta, key }) {
|
|
108
|
+
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
109
|
+
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
98
110
|
let s = "";
|
|
99
111
|
if (ctrl) s += "ctrl+";
|
|
100
112
|
if (shift) s += "shift+";
|
|
101
113
|
if (alt) s += "alt+";
|
|
102
114
|
if (meta) s += "meta+";
|
|
115
|
+
if (code) return s + "code:" + code;
|
|
103
116
|
return s ? s + key : key;
|
|
104
117
|
}
|
|
105
118
|
function comboKeyFromEvent(e) {
|
|
119
|
+
const bareMod = MODIFIER_KEY_TOKEN[e.key];
|
|
120
|
+
if (bareMod) return `__bare__:${bareMod}`;
|
|
106
121
|
return comboKeyFromParts({
|
|
107
122
|
ctrl: e.ctrlKey,
|
|
108
123
|
shift: e.shiftKey,
|
|
@@ -111,22 +126,52 @@ function comboKeyFromEvent(e) {
|
|
|
111
126
|
key: normalizeKey(e.key)
|
|
112
127
|
});
|
|
113
128
|
}
|
|
129
|
+
function codeKeyFromEvent(e) {
|
|
130
|
+
if (!e.code) return null;
|
|
131
|
+
let s = "";
|
|
132
|
+
if (e.ctrlKey) s += "ctrl+";
|
|
133
|
+
if (e.shiftKey) s += "shift+";
|
|
134
|
+
if (e.altKey) s += "alt+";
|
|
135
|
+
if (e.metaKey) s += "meta+";
|
|
136
|
+
return s + "code:" + e.code;
|
|
137
|
+
}
|
|
114
138
|
function isModifierToken(token) {
|
|
115
139
|
const t = normalizeKey(token);
|
|
116
140
|
return modifierTokens.has(t);
|
|
117
141
|
}
|
|
142
|
+
var CODE_TOKEN_RE = /(^|\+)code:([A-Za-z][A-Za-z0-9_]*)/;
|
|
118
143
|
function parseHotkey(hotkeyStr) {
|
|
119
144
|
const raw = String(hotkeyStr || "").trim();
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
145
|
+
const isUp = /\s+up$/i.test(raw);
|
|
146
|
+
const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
|
|
147
|
+
const combo = {
|
|
148
|
+
ctrl: false,
|
|
149
|
+
shift: false,
|
|
150
|
+
alt: false,
|
|
151
|
+
meta: false,
|
|
152
|
+
key: null,
|
|
153
|
+
code: null,
|
|
154
|
+
bareModifier: null
|
|
155
|
+
};
|
|
156
|
+
let stripped = baseRaw;
|
|
157
|
+
while (stripped.length) {
|
|
158
|
+
const mod = ahkPrefixMap.get(stripped[0]) ?? null;
|
|
126
159
|
if (!mod) break;
|
|
127
160
|
combo[mod] = true;
|
|
128
|
-
|
|
161
|
+
stripped = stripped.slice(1).trimStart();
|
|
129
162
|
}
|
|
163
|
+
const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
|
|
164
|
+
if (codeMatches && codeMatches.length > 1) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Invalid hotkey "${hotkeyStr}": multiple code: tokens not supported (got ${codeMatches.length}).`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
let codeValue = null;
|
|
170
|
+
const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
|
|
171
|
+
codeValue = val;
|
|
172
|
+
return sep + "__code__";
|
|
173
|
+
});
|
|
174
|
+
let cleanStr = scrubbed.toLowerCase();
|
|
130
175
|
const rawParts = cleanStr.split("+").map((p) => p.trim());
|
|
131
176
|
const parts = rawParts.filter(Boolean);
|
|
132
177
|
const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
|
|
@@ -145,6 +190,10 @@ function parseHotkey(hotkeyStr) {
|
|
|
145
190
|
}
|
|
146
191
|
}
|
|
147
192
|
for (const part of parts) {
|
|
193
|
+
if (part === "__code__") {
|
|
194
|
+
combo.code = codeValue;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
148
197
|
const actual = keyAliases[part] ?? part;
|
|
149
198
|
if (actual === "ctrl") combo.ctrl = true;
|
|
150
199
|
else if (actual === "shift") combo.shift = true;
|
|
@@ -152,8 +201,19 @@ function parseHotkey(hotkeyStr) {
|
|
|
152
201
|
else if (actual === "meta") combo.meta = true;
|
|
153
202
|
else combo.key = normalizeKey(actual);
|
|
154
203
|
}
|
|
155
|
-
if (!combo.key && impliedPlusKey) combo.key = "+";
|
|
156
|
-
if (!combo.key
|
|
204
|
+
if (!combo.key && !combo.code && impliedPlusKey) combo.key = "+";
|
|
205
|
+
if (!combo.key && !combo.code) {
|
|
206
|
+
const modCount = (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) + (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0);
|
|
207
|
+
if (modCount === 1) {
|
|
208
|
+
combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
|
|
209
|
+
} else if (modCount > 1) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Invalid hotkey "${hotkeyStr}": multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").`
|
|
212
|
+
);
|
|
213
|
+
} else {
|
|
214
|
+
throw new Error(`Invalid hotkey "${hotkeyStr}" (missing base key)`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
157
217
|
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr };
|
|
158
218
|
}
|
|
159
219
|
function isFromInputTarget(e) {
|
|
@@ -214,11 +274,29 @@ function bind(hotkeyStr, handler, plugin = null, options = {}) {
|
|
|
214
274
|
};
|
|
215
275
|
ensureSlot(comboStr, type).push(binding);
|
|
216
276
|
bindingIndex.set(binding.id, { comboStr, type });
|
|
277
|
+
if (bindHooks.length) {
|
|
278
|
+
for (const hook of bindHooks) {
|
|
279
|
+
try {
|
|
280
|
+
hook({ combo, raw, options: opts, plugin, id: binding.id });
|
|
281
|
+
} catch (err) {
|
|
282
|
+
console.error("[hotkey-router] onBind hook threw:", err);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
217
286
|
const off = () => removeById(binding.id);
|
|
218
287
|
off.id = binding.id;
|
|
219
288
|
off.hotkey = raw;
|
|
220
289
|
return off;
|
|
221
290
|
}
|
|
291
|
+
function onBind(hook) {
|
|
292
|
+
if (typeof hook !== "function") {
|
|
293
|
+
throw new TypeError("hotkeys.onBind(hook) expects a function");
|
|
294
|
+
}
|
|
295
|
+
bindHooks.push(hook);
|
|
296
|
+
return () => {
|
|
297
|
+
bindHooks = bindHooks.filter((h) => h !== hook);
|
|
298
|
+
};
|
|
299
|
+
}
|
|
222
300
|
function unbind(hotkeyStr, handler) {
|
|
223
301
|
const { combo, type } = parseHotkey(hotkeyStr);
|
|
224
302
|
const comboStr = comboKeyFromParts(combo);
|
|
@@ -283,15 +361,21 @@ function handleEvent(type) {
|
|
|
283
361
|
if (paused) return;
|
|
284
362
|
const fromInput = ignoreEditable && isFromInputTarget(e);
|
|
285
363
|
const comboStr = comboKeyFromEvent(e);
|
|
286
|
-
const
|
|
287
|
-
|
|
364
|
+
const codeStr = codeKeyFromEvent(e);
|
|
365
|
+
const seen = /* @__PURE__ */ new Set();
|
|
288
366
|
const candidates = [];
|
|
289
|
-
for (const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
|
|
367
|
+
for (const lookupKey of [comboStr, codeStr]) {
|
|
368
|
+
if (!lookupKey || seen.has(lookupKey)) continue;
|
|
369
|
+
seen.add(lookupKey);
|
|
370
|
+
const bindings = registry.get(lookupKey)?.get(type);
|
|
371
|
+
if (!bindings?.length) continue;
|
|
372
|
+
for (const b of bindings) {
|
|
373
|
+
const o2 = b.options;
|
|
374
|
+
if (fromInput && !o2.allowIn?.(e)) continue;
|
|
375
|
+
if (type === "keydown" && o2.repeat === false && e.repeat) continue;
|
|
376
|
+
if (o2.when && o2.when(e) === false) continue;
|
|
377
|
+
candidates.push(b);
|
|
378
|
+
}
|
|
295
379
|
}
|
|
296
380
|
if (!candidates.length) return;
|
|
297
381
|
const winner = pickWinner(candidates);
|
|
@@ -303,8 +387,8 @@ function handleEvent(type) {
|
|
|
303
387
|
if (o.once) removeById(winner.id);
|
|
304
388
|
};
|
|
305
389
|
}
|
|
306
|
-
|
|
307
|
-
|
|
390
|
+
var stopDown = null;
|
|
391
|
+
var stopUp = null;
|
|
308
392
|
function init({ target = defaultTarget, capture = false } = {}) {
|
|
309
393
|
if (!target) throw new Error("hotkeys.init() requires a target (e.g. window)");
|
|
310
394
|
if (stopDown || stopUp) destroy();
|
|
@@ -320,19 +404,37 @@ function destroy() {
|
|
|
320
404
|
plugins.clear();
|
|
321
405
|
bindingIndex.clear();
|
|
322
406
|
}
|
|
407
|
+
var BARE_MOD_TO_KEY = {
|
|
408
|
+
ctrl: "Control",
|
|
409
|
+
shift: "Shift",
|
|
410
|
+
alt: "Alt",
|
|
411
|
+
meta: "Meta"
|
|
412
|
+
};
|
|
323
413
|
function trigger(hotkeyStr, { type: forcedType } = {}) {
|
|
324
414
|
const { combo, type } = parseHotkey(hotkeyStr);
|
|
325
415
|
const comboStr = comboKeyFromParts(combo);
|
|
326
416
|
const actualType = forcedType || type;
|
|
327
417
|
const bindings = registry.get(comboStr)?.get(actualType);
|
|
328
418
|
if (!bindings?.length) return false;
|
|
419
|
+
const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key;
|
|
420
|
+
let altKey = !!combo.alt;
|
|
421
|
+
let ctrlKey = !!combo.ctrl;
|
|
422
|
+
let shiftKey = !!combo.shift;
|
|
423
|
+
let metaKey = !!combo.meta;
|
|
424
|
+
if (combo.bareModifier && actualType === "keyup") {
|
|
425
|
+
if (combo.bareModifier === "alt") altKey = false;
|
|
426
|
+
else if (combo.bareModifier === "ctrl") ctrlKey = false;
|
|
427
|
+
else if (combo.bareModifier === "shift") shiftKey = false;
|
|
428
|
+
else if (combo.bareModifier === "meta") metaKey = false;
|
|
429
|
+
}
|
|
329
430
|
const e = {
|
|
330
431
|
type: actualType,
|
|
331
|
-
key:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
432
|
+
key: eventKey,
|
|
433
|
+
code: combo.code || null,
|
|
434
|
+
ctrlKey,
|
|
435
|
+
shiftKey,
|
|
436
|
+
altKey,
|
|
437
|
+
metaKey,
|
|
336
438
|
repeat: false,
|
|
337
439
|
preventDefault() {
|
|
338
440
|
},
|
|
@@ -361,6 +463,8 @@ var hotkey_router_default = {
|
|
|
361
463
|
unbind,
|
|
362
464
|
registerPlugin,
|
|
363
465
|
unregisterPlugin,
|
|
466
|
+
// extension hooks
|
|
467
|
+
onBind,
|
|
364
468
|
// control
|
|
365
469
|
pause,
|
|
366
470
|
resume,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../hotkey-router.js"],
|
|
4
|
-
"sourcesContent": ["// hotkey-router.js\r\n// Hotkey Router \u2014 plugin-first keyboard shortcut router (tiny + predictable)\r\n//\r\n// Goals:\r\n// - O(1) dispatch by combo string lookup\r\n// - Deterministic routing: highest priority wins; ties -> most recently bound wins\r\n// - Safe plugin cleanup (never deletes other plugins\u2019 bindings)\r\n// - Modern browser target (KeyboardEvent.key + addEventListener)\r\n\r\n// --- tiny event helper ---\r\nfunction on(target, type, fn, options) {\r\n target.addEventListener(type, fn, options)\r\n return () => target.removeEventListener(type, fn, options)\r\n}\r\n\r\n// --- key alias map ---\r\nconst isMac =\r\n typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.platform)\r\n\r\n\r\nconst modifierTokens = new Set(['ctrl', 'shift', 'alt', 'meta'])\r\n\r\nconst ahkPrefixMap = new Map([\r\n ['^', 'ctrl'], // Ctrl\r\n ['!', 'alt'], // Alt\r\n ['+', 'shift'], // Shift\r\n ['#', 'meta'], // Win / Command\r\n])\r\n\r\n\r\nconst keyAliases = Object.freeze({\r\n // common\r\n esc: 'escape',\r\n escape: 'escape',\r\n space: ' ',\r\n spacebar: ' ',\r\n enter: 'enter',\r\n return: 'enter',\r\n del: 'delete',\r\n delete: 'delete',\r\n backspace: 'backspace',\r\n tab: 'tab',\r\n\r\n // arrows\r\n up: 'arrowup',\r\n down: 'arrowdown',\r\n left: 'arrowleft',\r\n right: 'arrowright',\r\n\r\n // navigation\r\n home: 'home',\r\n end: 'end',\r\n pageup: 'pageup',\r\n pagedown: 'pagedown',\r\n pgup: 'pageup',\r\n pgdn: 'pagedown',\r\n\r\n // modifiers (words)\r\n cmd: 'meta',\r\n command: 'meta',\r\n win: 'meta',\r\n meta: 'meta',\r\n control: 'ctrl',\r\n ctrl: 'ctrl',\r\n option: 'alt',\r\n alt: 'alt',\r\n shift: 'shift',\r\n\r\n // modifiers (symbols)\r\n '\u2318': 'meta',\r\n '\u2303': 'ctrl',\r\n '\u2325': 'alt',\r\n '\u21E7': 'shift',\r\n\r\n // cross-platform \"mod\"\r\n mod: isMac ? 'meta' : 'ctrl',\r\n\r\n // plus key ergonomics\r\n plus: '+',\r\n})\r\n\r\n// --- config ---\r\nlet ignoreEditable = true\r\nlet defaultTarget = typeof window !== 'undefined' ? window : null\r\n\r\n// --- state ---\r\n// comboStr -> Map<type, Array<Binding>>\r\nconst registry = new Map()\r\n// pluginName -> Array<bindingId>\r\nconst plugins = new Map()\r\n// bindingId -> { comboStr, type }\r\nconst bindingIndex = new Map()\r\n\r\nlet paused = false\r\nlet nextId = 1\r\n\r\n// --- helpers ---\r\nfunction normalizeKey(key) {\r\n const raw = String(key ?? '').trim()\r\n const k = raw.toLowerCase()\r\n return keyAliases[k] ?? (raw === ' ' ? ' ' : k)\r\n}\r\n\r\nfunction comboKeyFromParts({ ctrl, shift, alt, meta, key }) {\r\n let s = ''\r\n if (ctrl) s += 'ctrl+'\r\n if (shift) s += 'shift+'\r\n if (alt) s += 'alt+'\r\n if (meta) s += 'meta+'\r\n return s ? s + key : key\r\n}\r\n\r\nfunction comboKeyFromEvent(e) {\r\n return comboKeyFromParts({\r\n ctrl: e.ctrlKey,\r\n shift: e.shiftKey,\r\n alt: e.altKey,\r\n meta: e.metaKey,\r\n key: normalizeKey(e.key),\r\n })\r\n}\r\n\r\n\r\nfunction isModifierToken(token) {\r\n const t = normalizeKey(token)\r\n return modifierTokens.has(t)\r\n}\r\n\r\n\r\nfunction parseHotkey(hotkeyStr) {\r\n const raw = String(hotkeyStr || '').trim()\r\n const lower = raw.toLowerCase()\r\n\r\n const isUp = lower.endsWith(' up')\r\n let cleanStr = (isUp ? raw.slice(0, -3) : raw).trim().toLowerCase()\r\n\r\n // --- AHK-style prefix modifiers ---\r\n // Examples:\r\n // ^k => ctrl+k\r\n // !k => alt+k\r\n // +k => shift+k\r\n // #k => meta+k\r\n // ^!k => ctrl+alt+k\r\n //\r\n // This runs BEFORE normal \"+\" token parsing so it composes cleanly.\r\n const combo = { ctrl: false, shift: false, alt: false, meta: false, key: null }\r\n\r\n while (cleanStr.length) {\r\n const mod = ahkPrefixMap.get(cleanStr[0]) ?? null\r\n if (!mod) break\r\n combo[mod] = true\r\n cleanStr = cleanStr.slice(1).trimStart()\r\n }\r\n\r\n // Allow plus key:\r\n // - \"ctrl++\" => ctrl + \"+\"\r\n // - \"++\" => shift + \"+\" (AHK '+' prefix sets shift, remaining '+' becomes the base key)\r\n // `split('+')` produces empties; we keep that signal.\r\n const rawParts = cleanStr.split('+').map((p) => p.trim())\r\n const parts = rawParts.filter(Boolean)\r\n const impliedPlusKey = rawParts.some((p) => p === '') && cleanStr.includes('++')\r\n\r\n // Enforce: modifiers must come before the base key.\r\n // Example: \"ctrl+k\" \u2705 | \"k+ctrl\" \u274C\r\n // We ignore the special \"+ key\" case (ctrl++) since it has no explicit base token.\r\n if (!impliedPlusKey) {\r\n let seenBase = false\r\n for (const part of parts) {\r\n if (isModifierToken(part)) {\r\n if (seenBase) {\r\n throw new Error(\r\n `Invalid hotkey \"${hotkeyStr}\": modifiers must come before the base key (e.g. \"ctrl+k\", not \"k+ctrl\")`\r\n )\r\n }\r\n } else {\r\n if (!seenBase) seenBase = true\r\n }\r\n }\r\n }\r\n\r\n // Continue parsing the remaining tokens (words/symbols/aliases)\r\n for (const part of parts) {\r\n const actual = keyAliases[part] ?? part\r\n if (actual === 'ctrl') combo.ctrl = true\r\n else if (actual === 'shift') combo.shift = true\r\n else if (actual === 'alt') combo.alt = true\r\n else if (actual === 'meta') combo.meta = true\r\n else combo.key = normalizeKey(actual)\r\n }\r\n\r\n if (!combo.key && impliedPlusKey) combo.key = '+'\r\n if (!combo.key) throw new Error(`Invalid hotkey \"${hotkeyStr}\" (missing base key)`)\r\n\r\n return { combo, type: isUp ? 'keyup' : 'keydown', raw: hotkeyStr }\r\n}\r\n\r\n\r\nfunction isFromInputTarget(e) {\r\n const t = e?.target\r\n if (!t) return false\r\n const tag = String(t.tagName || '').toUpperCase()\r\n return (\r\n t.isContentEditable ||\r\n tag === 'INPUT' ||\r\n tag === 'TEXTAREA' ||\r\n tag === 'SELECT' ||\r\n t.getAttribute?.('role') === 'textbox'\r\n )\r\n}\r\n\r\n\r\n// --- binding model ---\r\n// options:\r\n// preventDefault, stopPropagation, stopImmediatePropagation\r\n// repeat (default false on keydown), once\r\n// when(e) -> boolean (gate)\r\n// allowIn(e) -> boolean (override ignoreInput)\r\n// priority (higher wins)\r\nfunction normalizeOptions(type, options) {\r\n const o = options ? { ...options } : {}\r\n if (type === 'keydown' && o.repeat == null) o.repeat = false\r\n if (o.priority == null) o.priority = 0\r\n return o\r\n}\r\n\r\n\r\nfunction ensureSlot(comboStr, type) {\r\n let typeMap = registry.get(comboStr)\r\n if (!typeMap) {\r\n typeMap = new Map()\r\n registry.set(comboStr, typeMap)\r\n }\r\n let arr = typeMap.get(type)\r\n if (!arr) {\r\n arr = []\r\n typeMap.set(type, arr)\r\n }\r\n return arr\r\n}\r\n\r\n\r\nfunction removeById(id) {\r\n const idx = bindingIndex.get(id)\r\n if (!idx) return false\r\n\r\n const { comboStr, type } = idx\r\n const typeMap = registry.get(comboStr)\r\n const arr = typeMap?.get(type)\r\n if (!arr?.length) {\r\n bindingIndex.delete(id)\r\n return false\r\n }\r\n\r\n const next = arr.filter((b) => b.id !== id)\r\n if (next.length) typeMap.set(type, next)\r\n else typeMap.delete(type)\r\n\r\n if (!typeMap.size) registry.delete(comboStr)\r\n bindingIndex.delete(id)\r\n return true\r\n}\r\n\r\n\r\n// --- public API: bind / unbind ---\r\n// bind returns an off() function; off.id is exposed for plugin bookkeeping.\r\nfunction bind(hotkeyStr, handler, plugin = null, options = {}) {\r\n const { combo, type, raw } = parseHotkey(hotkeyStr)\r\n const comboStr = comboKeyFromParts(combo)\r\n const opts = normalizeOptions(type, options)\r\n\r\n const binding = {\r\n id: nextId++,\r\n comboStr,\r\n type,\r\n combo,\r\n handler,\r\n plugin,\r\n raw,\r\n options: opts,\r\n }\r\n\r\n ensureSlot(comboStr, type).push(binding)\r\n bindingIndex.set(binding.id, { comboStr, type })\r\n\r\n const off = () => removeById(binding.id)\r\n off.id = binding.id\r\n off.hotkey = raw\r\n return off\r\n}\r\n\r\n\r\n// unbind('ctrl+k') -> remove all for that combo/type\r\n// unbind('ctrl+k', fn) -> remove only that handler\r\nfunction unbind(hotkeyStr, handler) {\r\n const { combo, type } = parseHotkey(hotkeyStr)\r\n const comboStr = comboKeyFromParts(combo)\r\n const typeMap = registry.get(comboStr)\r\n if (!typeMap) return\r\n\r\n const arr = typeMap.get(type)\r\n if (!arr?.length) return\r\n\r\n if (!handler) {\r\n for (const b of arr) bindingIndex.delete(b.id)\r\n typeMap.delete(type)\r\n } else {\r\n const keep = []\r\n for (const b of arr) {\r\n if (b.handler === handler) bindingIndex.delete(b.id)\r\n else keep.push(b)\r\n }\r\n if (keep.length) typeMap.set(type, keep)\r\n else typeMap.delete(type)\r\n }\r\n\r\n if (!typeMap.size) registry.delete(comboStr)\r\n}\r\n\r\n\r\n// --- plugin system ---\r\n// registerPlugin returns unregister function.\r\nfunction registerPlugin(name, hotkeyMap) {\r\n if (plugins.has(name)) throw new Error(`Plugin \"${name}\" already registered`)\r\n const ids = []\r\n\r\n for (const [hotkeyStr, fnOrTuple] of Object.entries(hotkeyMap)) {\r\n const [fn, options] = Array.isArray(fnOrTuple) ? fnOrTuple : [fnOrTuple, {}]\r\n const off = bind(hotkeyStr, fn, name, options)\r\n ids.push(off.id)\r\n }\r\n\r\n plugins.set(name, ids)\r\n return () => unregisterPlugin(name)\r\n}\r\n\r\nfunction unregisterPlugin(name) {\r\n const ids = plugins.get(name)\r\n if (!ids) return\r\n for (const id of ids) removeById(id)\r\n plugins.delete(name)\r\n}\r\n\r\n// --- control ---\r\nfunction pause() {\r\n paused = true\r\n}\r\n\r\nfunction resume() {\r\n paused = false\r\n}\r\n\r\nfunction ignoreInput(value = true) {\r\n ignoreEditable = !!value\r\n}\r\n\r\n// allow changing the default target (iframes/tests).\r\n// we intentionally do not auto-rebind to keep the core tiny.\r\nfunction setTarget(target) {\r\n defaultTarget = target\r\n}\r\n\r\n\r\n// --- dispatch (O(1) lookup) ---\r\nfunction pickWinner(bindings) {\r\n // Highest priority wins; ties -> newest wins (largest id).\r\n let best = null\r\n for (const b of bindings) {\r\n if (!best) best = b\r\n else if (b.options.priority > best.options.priority) best = b\r\n else if (b.options.priority === best.options.priority && b.id > best.id) best = b\r\n }\r\n return best\r\n}\r\n\r\n\r\nfunction handleEvent(type) {\r\n return (e) => {\r\n if (paused) return\r\n\r\n const fromInput = ignoreEditable && isFromInputTarget(e)\r\n const comboStr = comboKeyFromEvent(e)\r\n\r\n const bindings = registry.get(comboStr)?.get(type)\r\n if (!bindings?.length) return\r\n\r\n const candidates = []\r\n for (const b of bindings) {\r\n const o = b.options\r\n if (fromInput && !o.allowIn?.(e)) continue\r\n if (type === 'keydown' && o.repeat === false && e.repeat) continue\r\n if (o.when && o.when(e) === false) continue\r\n candidates.push(b)\r\n }\r\n if (!candidates.length) return\r\n\r\n const winner = pickWinner(candidates)\r\n const o = winner.options\r\n\r\n if (o.preventDefault) e.preventDefault()\r\n if (o.stopImmediatePropagation) e.stopImmediatePropagation()\r\n else if (o.stopPropagation) e.stopPropagation()\r\n\r\n winner.handler(e)\r\n\r\n if (o.once) removeById(winner.id)\r\n }\r\n}\r\n\r\n\r\n// --- listeners ---\r\nlet stopDown = null\r\nlet stopUp = null\r\n\r\nfunction init({ target = defaultTarget, capture = false } = {}) {\r\n if (!target) throw new Error('hotkeys.init() requires a target (e.g. window)')\r\n if (stopDown || stopUp) destroy()\r\n\r\n stopDown = on(target, 'keydown', handleEvent('keydown'), { capture })\r\n stopUp = on(target, 'keyup', handleEvent('keyup'), { capture })\r\n}\r\n\r\n\r\nfunction destroy() {\r\n stopDown?.()\r\n stopUp?.()\r\n stopDown = null\r\n stopUp = null\r\n registry.clear()\r\n plugins.clear()\r\n bindingIndex.clear()\r\n}\r\n\r\n\r\n// --- programmatic trigger (tests / automation) ---\r\nfunction trigger(hotkeyStr, { type: forcedType } = {}) {\r\n const { combo, type } = parseHotkey(hotkeyStr)\r\n const comboStr = comboKeyFromParts(combo)\r\n const actualType = forcedType || type\r\n\r\n const bindings = registry.get(comboStr)?.get(actualType)\r\n if (!bindings?.length) return false\r\n\r\n const e = {\r\n type: actualType,\r\n key: combo.key,\r\n ctrlKey: !!combo.ctrl,\r\n shiftKey: !!combo.shift,\r\n altKey: !!combo.alt,\r\n metaKey: !!combo.meta,\r\n repeat: false,\r\n preventDefault() { },\r\n stopPropagation() { },\r\n stopImmediatePropagation() { },\r\n target: null,\r\n }\r\n\r\n const winner = pickWinner(\r\n bindings.filter((b) => (b.options.when ? b.options.when(e) !== false : true))\r\n )\r\n if (!winner) return false\r\n\r\n winner.handler(e)\r\n if (winner.options.once) removeById(winner.id)\r\n return true\r\n}\r\n\r\n\r\n// Auto-init on window by default (browser only)\r\nif (defaultTarget) init()\r\n\r\nexport default {\r\n // lifecycle\r\n init,\r\n destroy,\r\n setTarget,\r\n\r\n // bindings\r\n bind,\r\n unbind,\r\n registerPlugin,\r\n unregisterPlugin,\r\n\r\n // control\r\n pause,\r\n resume,\r\n ignoreInput,\r\n\r\n // testing / automation\r\n trigger,\r\n}"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// hotkey-router.js\n// Hotkey Router \u2014 plugin-first keyboard shortcut router (tiny + predictable)\n//\n// Goals:\n// - O(1) dispatch by combo string lookup\n// - Deterministic routing: highest priority wins; ties -> most recently bound wins\n// - Safe plugin cleanup (never deletes other plugins\u2019 bindings)\n// - Modern browser target (KeyboardEvent.key + addEventListener)\n//\n// This core ships ZERO reservation data \u2014 opt in via `hotkey-router/auto`\n// or by calling `installReservationWarnings(hotkeys)` from the separate\n// `hotkey-router/reservations` module. Bundlers tree-shake the data file\n// out entirely when neither is imported.\n\n// --- tiny event helper ---\nfunction on(target, type, fn, options) {\n target.addEventListener(type, fn, options)\n return () => target.removeEventListener(type, fn, options)\n}\n\n// --- key alias map ---\nconst isMac =\n typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.platform)\n\n\nconst modifierTokens = new Set(['ctrl', 'shift', 'alt', 'meta'])\n\n// Map from KeyboardEvent.key (which IS the modifier name on bare-modifier events)\n// to the canonical token used in combo strings. Used to detect bare-modifier\n// keydown/keyup events at dispatch time.\nconst MODIFIER_KEY_TOKEN = Object.freeze({\n Alt: 'alt',\n AltGraph: 'alt',\n Control: 'ctrl',\n Shift: 'shift',\n Meta: 'meta',\n OS: 'meta',\n})\n\nconst ahkPrefixMap = new Map([\n ['^', 'ctrl'], // Ctrl\n ['!', 'alt'], // Alt\n ['+', 'shift'], // Shift\n ['#', 'meta'], // Win / Command\n])\n\n\nconst keyAliases = Object.freeze({\n // common\n esc: 'escape',\n escape: 'escape',\n space: ' ',\n spacebar: ' ',\n enter: 'enter',\n return: 'enter',\n del: 'delete',\n delete: 'delete',\n backspace: 'backspace',\n tab: 'tab',\n\n // arrows\n up: 'arrowup',\n down: 'arrowdown',\n left: 'arrowleft',\n right: 'arrowright',\n\n // navigation\n home: 'home',\n end: 'end',\n pageup: 'pageup',\n pagedown: 'pagedown',\n pgup: 'pageup',\n pgdn: 'pagedown',\n\n // modifiers (words)\n cmd: 'meta',\n command: 'meta',\n win: 'meta',\n meta: 'meta',\n control: 'ctrl',\n ctrl: 'ctrl',\n option: 'alt',\n alt: 'alt',\n shift: 'shift',\n\n // modifiers (symbols)\n '\u2318': 'meta',\n '\u2303': 'ctrl',\n '\u2325': 'alt',\n '\u21E7': 'shift',\n\n // cross-platform \"mod\"\n mod: isMac ? 'meta' : 'ctrl',\n\n // plus key ergonomics\n plus: '+',\n})\n\n// --- config ---\nlet ignoreEditable = true\nlet defaultTarget = typeof window !== 'undefined' ? window : null\n\n// Bind hooks: subscribers called after each successful bind. Used by the\n// optional reservations module to emit conflict warnings without coupling\n// the core router to the (~5 KB) reservation table.\nlet bindHooks = []\n\n// --- state ---\n// comboStr -> Map<type, Array<Binding>>\nconst registry = new Map()\n// pluginName -> Array<bindingId>\nconst plugins = new Map()\n// bindingId -> { comboStr, type }\nconst bindingIndex = new Map()\n\nlet paused = false\nlet nextId = 1\n\n// --- helpers ---\nfunction normalizeKey(key) {\n const raw = String(key ?? '').trim()\n const k = raw.toLowerCase()\n return keyAliases[k] ?? (raw === ' ' ? ' ' : k)\n}\n\nfunction comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {\n // Bare-modifier bindings get a sentinel namespace so they can't collide with\n // regular chord combo strings (`'alt+x'` vs `'__bare__:alt'`).\n if (bareModifier) return `__bare__:${bareModifier}`\n\n let s = ''\n if (ctrl) s += 'ctrl+'\n if (shift) s += 'shift+'\n if (alt) s += 'alt+'\n if (meta) s += 'meta+'\n\n // Code-based combos use a `code:KeyX` suffix instead of the key character.\n if (code) return s + 'code:' + code\n return s ? s + key : key\n}\n\nfunction comboKeyFromEvent(e) {\n // If the event's `key` is itself a modifier name, this is a bare-modifier\n // press/release. Match it via the bare-modifier sentinel regardless of which\n // other modifier flags are set (loose match \u2014 Alt fires `alt` even when held\n // alongside Ctrl).\n const bareMod = MODIFIER_KEY_TOKEN[e.key]\n if (bareMod) return `__bare__:${bareMod}`\n\n return comboKeyFromParts({\n ctrl: e.ctrlKey,\n shift: e.shiftKey,\n alt: e.altKey,\n meta: e.metaKey,\n key: normalizeKey(e.key),\n })\n}\n\n// Code-based lookup string for an event. Independent of `comboKeyFromEvent`\n// because consumers can register either key-based OR code-based bindings (or\n// both) for the same physical key combo, and we look up under whichever they\n// chose.\nfunction codeKeyFromEvent(e) {\n if (!e.code) return null\n\n let s = ''\n if (e.ctrlKey) s += 'ctrl+'\n if (e.shiftKey) s += 'shift+'\n if (e.altKey) s += 'alt+'\n if (e.metaKey) s += 'meta+'\n return s + 'code:' + e.code\n}\n\n\nfunction isModifierToken(token) {\n const t = normalizeKey(token)\n return modifierTokens.has(t)\n}\n\n\n// Matches `code:KeyX` (case-sensitive value). Used to extract code tokens BEFORE\n// the rest of the parser lowercases everything, since KeyboardEvent.code values\n// are camelCase (KeyA, Digit1, ArrowLeft) and must be preserved.\nconst CODE_TOKEN_RE = /(^|\\+)code:([A-Za-z][A-Za-z0-9_]*)/\n\nfunction parseHotkey(hotkeyStr) {\n const raw = String(hotkeyStr || '').trim()\n\n // Detect ' up' suffix case-insensitively so 'Alt UP' works the same as 'alt up'.\n const isUp = /\\s+up$/i.test(raw)\n const baseRaw = isUp ? raw.replace(/\\s+up$/i, '').trim() : raw\n\n // --- AHK-style prefix modifiers ---\n // Examples:\n // ^k => ctrl+k\n // !k => alt+k\n // +k => shift+k\n // #k => meta+k\n // ^!k => ctrl+alt+k\n // !code:KeyX => alt+code:KeyX\n //\n // We strip these BEFORE both the code-token extraction AND the lowercase\n // pass, because the AHK prefix chars (^ ! + #) are case-stable, and the\n // remainder may contain a case-sensitive `code:KeyX` token that must survive.\n const combo = {\n ctrl: false, shift: false, alt: false, meta: false,\n key: null, code: null, bareModifier: null,\n }\n\n let stripped = baseRaw\n while (stripped.length) {\n const mod = ahkPrefixMap.get(stripped[0]) ?? null\n if (!mod) break\n combo[mod] = true\n stripped = stripped.slice(1).trimStart()\n }\n\n // Pull out a code:XXX token before lowercasing; preserve the camelCase value.\n // Reject multiple code: tokens to avoid silent loss of intent.\n const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g)\n if (codeMatches && codeMatches.length > 1) {\n throw new Error(\n `Invalid hotkey \"${hotkeyStr}\": multiple code: tokens not supported (got ${codeMatches.length}).`\n )\n }\n let codeValue = null\n const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {\n codeValue = val\n return sep + '__code__'\n })\n\n let cleanStr = scrubbed.toLowerCase()\n\n // Allow plus key:\n // - \"ctrl++\" => ctrl + \"+\"\n // - \"++\" => shift + \"+\" (AHK '+' prefix sets shift, remaining '+' becomes the base key)\n // `split('+')` produces empties; we keep that signal.\n const rawParts = cleanStr.split('+').map((p) => p.trim())\n const parts = rawParts.filter(Boolean)\n const impliedPlusKey = rawParts.some((p) => p === '') && cleanStr.includes('++')\n\n // Enforce: modifiers must come before the base key.\n // Example: \"ctrl+k\" \u2705 | \"k+ctrl\" \u274C\n // We ignore the special \"+ key\" case (ctrl++) since it has no explicit base token.\n if (!impliedPlusKey) {\n let seenBase = false\n for (const part of parts) {\n if (isModifierToken(part)) {\n if (seenBase) {\n throw new Error(\n `Invalid hotkey \"${hotkeyStr}\": modifiers must come before the base key (e.g. \"ctrl+k\", not \"k+ctrl\")`\n )\n }\n } else {\n if (!seenBase) seenBase = true\n }\n }\n }\n\n // Continue parsing the remaining tokens (words/symbols/aliases)\n for (const part of parts) {\n if (part === '__code__') {\n combo.code = codeValue\n continue\n }\n const actual = keyAliases[part] ?? part\n if (actual === 'ctrl') combo.ctrl = true\n else if (actual === 'shift') combo.shift = true\n else if (actual === 'alt') combo.alt = true\n else if (actual === 'meta') combo.meta = true\n else combo.key = normalizeKey(actual)\n }\n\n if (!combo.key && !combo.code && impliedPlusKey) combo.key = '+'\n\n // If no base key/code is set, this might be a bare-modifier binding ('alt' / 'ctrl').\n // Allow exactly ONE modifier with no other tokens. Multi-modifier bare bindings\n // (e.g. 'ctrl+alt') are intentionally rejected \u2014 add a base key for those.\n if (!combo.key && !combo.code) {\n const modCount =\n (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) +\n (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0)\n\n if (modCount === 1) {\n combo.bareModifier =\n combo.ctrl ? 'ctrl' :\n combo.shift ? 'shift' :\n combo.alt ? 'alt' : 'meta'\n } else if (modCount > 1) {\n throw new Error(\n `Invalid hotkey \"${hotkeyStr}\": multi-modifier bare bindings not supported. Add a base key (e.g. \"ctrl+alt+x\").`\n )\n } else {\n throw new Error(`Invalid hotkey \"${hotkeyStr}\" (missing base key)`)\n }\n }\n\n return { combo, type: isUp ? 'keyup' : 'keydown', raw: hotkeyStr }\n}\n\n\nfunction isFromInputTarget(e) {\n const t = e?.target\n if (!t) return false\n const tag = String(t.tagName || '').toUpperCase()\n return (\n t.isContentEditable ||\n tag === 'INPUT' ||\n tag === 'TEXTAREA' ||\n tag === 'SELECT' ||\n t.getAttribute?.('role') === 'textbox'\n )\n}\n\n\n// --- binding model ---\n// options:\n// preventDefault, stopPropagation, stopImmediatePropagation\n// repeat (default false on keydown), once\n// when(e) -> boolean (gate)\n// allowIn(e) -> boolean (override ignoreInput)\n// priority (higher wins)\nfunction normalizeOptions(type, options) {\n const o = options ? { ...options } : {}\n if (type === 'keydown' && o.repeat == null) o.repeat = false\n if (o.priority == null) o.priority = 0\n return o\n}\n\n\nfunction ensureSlot(comboStr, type) {\n let typeMap = registry.get(comboStr)\n if (!typeMap) {\n typeMap = new Map()\n registry.set(comboStr, typeMap)\n }\n let arr = typeMap.get(type)\n if (!arr) {\n arr = []\n typeMap.set(type, arr)\n }\n return arr\n}\n\n\nfunction removeById(id) {\n const idx = bindingIndex.get(id)\n if (!idx) return false\n\n const { comboStr, type } = idx\n const typeMap = registry.get(comboStr)\n const arr = typeMap?.get(type)\n if (!arr?.length) {\n bindingIndex.delete(id)\n return false\n }\n\n const next = arr.filter((b) => b.id !== id)\n if (next.length) typeMap.set(type, next)\n else typeMap.delete(type)\n\n if (!typeMap.size) registry.delete(comboStr)\n bindingIndex.delete(id)\n return true\n}\n\n\n// --- public API: bind / unbind ---\n// bind returns an off() function; off.id is exposed for plugin bookkeeping.\nfunction bind(hotkeyStr, handler, plugin = null, options = {}) {\n const { combo, type, raw } = parseHotkey(hotkeyStr)\n const comboStr = comboKeyFromParts(combo)\n const opts = normalizeOptions(type, options)\n\n const binding = {\n id: nextId++,\n comboStr,\n type,\n combo,\n handler,\n plugin,\n raw,\n options: opts,\n }\n\n ensureSlot(comboStr, type).push(binding)\n bindingIndex.set(binding.id, { comboStr, type })\n\n // Notify bind subscribers. Hook errors must never break the bind itself.\n if (bindHooks.length) {\n for (const hook of bindHooks) {\n try {\n hook({ combo, raw, options: opts, plugin, id: binding.id })\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('[hotkey-router] onBind hook threw:', err)\n }\n }\n }\n\n const off = () => removeById(binding.id)\n off.id = binding.id\n off.hotkey = raw\n return off\n}\n\n// Subscribe to bind events. The hook receives\n// { combo, raw, options, plugin, id }\n// after the binding is registered. Returns an unsubscribe function. Used by\n// extensions like `installReservationWarnings` from `hotkey-router/reservations`.\nfunction onBind(hook) {\n if (typeof hook !== 'function') {\n throw new TypeError('hotkeys.onBind(hook) expects a function')\n }\n bindHooks.push(hook)\n return () => {\n bindHooks = bindHooks.filter((h) => h !== hook)\n }\n}\n\n\n// unbind('ctrl+k') -> remove all for that combo/type\n// unbind('ctrl+k', fn) -> remove only that handler\nfunction unbind(hotkeyStr, handler) {\n const { combo, type } = parseHotkey(hotkeyStr)\n const comboStr = comboKeyFromParts(combo)\n const typeMap = registry.get(comboStr)\n if (!typeMap) return\n\n const arr = typeMap.get(type)\n if (!arr?.length) return\n\n if (!handler) {\n for (const b of arr) bindingIndex.delete(b.id)\n typeMap.delete(type)\n } else {\n const keep = []\n for (const b of arr) {\n if (b.handler === handler) bindingIndex.delete(b.id)\n else keep.push(b)\n }\n if (keep.length) typeMap.set(type, keep)\n else typeMap.delete(type)\n }\n\n if (!typeMap.size) registry.delete(comboStr)\n}\n\n\n// --- plugin system ---\n// registerPlugin returns unregister function.\nfunction registerPlugin(name, hotkeyMap) {\n if (plugins.has(name)) throw new Error(`Plugin \"${name}\" already registered`)\n const ids = []\n\n for (const [hotkeyStr, fnOrTuple] of Object.entries(hotkeyMap)) {\n const [fn, options] = Array.isArray(fnOrTuple) ? fnOrTuple : [fnOrTuple, {}]\n const off = bind(hotkeyStr, fn, name, options)\n ids.push(off.id)\n }\n\n plugins.set(name, ids)\n return () => unregisterPlugin(name)\n}\n\nfunction unregisterPlugin(name) {\n const ids = plugins.get(name)\n if (!ids) return\n for (const id of ids) removeById(id)\n plugins.delete(name)\n}\n\n// --- control ---\nfunction pause() {\n paused = true\n}\n\nfunction resume() {\n paused = false\n}\n\nfunction ignoreInput(value = true) {\n ignoreEditable = !!value\n}\n\n// allow changing the default target (iframes/tests).\n// we intentionally do not auto-rebind to keep the core tiny.\nfunction setTarget(target) {\n defaultTarget = target\n}\n\n\n// --- dispatch (O(1) lookup) ---\nfunction pickWinner(bindings) {\n // Highest priority wins; ties -> newest wins (largest id).\n let best = null\n for (const b of bindings) {\n if (!best) best = b\n else if (b.options.priority > best.options.priority) best = b\n else if (b.options.priority === best.options.priority && b.id > best.id) best = b\n }\n return best\n}\n\n\nfunction handleEvent(type) {\n return (e) => {\n if (paused) return\n\n const fromInput = ignoreEditable && isFromInputTarget(e)\n const comboStr = comboKeyFromEvent(e)\n const codeStr = codeKeyFromEvent(e)\n\n // Look up under both lookup keys: key-based (`alt+x`) and code-based\n // (`alt+code:KeyX`). Same physical keypress, two valid binding shapes.\n // Merge candidates and let the existing priority/recency arbiter pick.\n const seen = new Set()\n const candidates = []\n for (const lookupKey of [comboStr, codeStr]) {\n if (!lookupKey || seen.has(lookupKey)) continue\n seen.add(lookupKey)\n\n const bindings = registry.get(lookupKey)?.get(type)\n if (!bindings?.length) continue\n\n for (const b of bindings) {\n const o = b.options\n if (fromInput && !o.allowIn?.(e)) continue\n if (type === 'keydown' && o.repeat === false && e.repeat) continue\n if (o.when && o.when(e) === false) continue\n candidates.push(b)\n }\n }\n if (!candidates.length) return\n\n const winner = pickWinner(candidates)\n const o = winner.options\n\n if (o.preventDefault) e.preventDefault()\n if (o.stopImmediatePropagation) e.stopImmediatePropagation()\n else if (o.stopPropagation) e.stopPropagation()\n\n winner.handler(e)\n\n if (o.once) removeById(winner.id)\n }\n}\n\n\n// --- listeners ---\nlet stopDown = null\nlet stopUp = null\n\nfunction init({ target = defaultTarget, capture = false } = {}) {\n if (!target) throw new Error('hotkeys.init() requires a target (e.g. window)')\n if (stopDown || stopUp) destroy()\n\n stopDown = on(target, 'keydown', handleEvent('keydown'), { capture })\n stopUp = on(target, 'keyup', handleEvent('keyup'), { capture })\n}\n\n\nfunction destroy() {\n stopDown?.()\n stopUp?.()\n stopDown = null\n stopUp = null\n registry.clear()\n plugins.clear()\n bindingIndex.clear()\n // Note: bindHooks deliberately survive destroy(). Consumer extensions\n // (reservations, future telemetry, etc.) install once at startup and\n // shouldn't have to re-attach when the router restarts. Tests that need\n // a clean slate should use the uninstall fn returned by their installer.\n}\n\n\n// --- programmatic trigger (tests / automation) ---\n//\n// Reverse map: 'alt' -> 'Alt' (the KeyboardEvent.key value for that bare modifier).\n// Used to populate the synthetic event's `.key` field so consumer handlers that\n// inspect `e.key` see the same value they'd get from a real event.\nconst BARE_MOD_TO_KEY = {\n ctrl: 'Control',\n shift: 'Shift',\n alt: 'Alt',\n meta: 'Meta',\n}\n\nfunction trigger(hotkeyStr, { type: forcedType } = {}) {\n const { combo, type } = parseHotkey(hotkeyStr)\n const comboStr = comboKeyFromParts(combo)\n const actualType = forcedType || type\n\n const bindings = registry.get(comboStr)?.get(actualType)\n if (!bindings?.length) return false\n\n // Fill `.key` from bareModifier when the binding is bare-modifier-only;\n // otherwise use combo.key. `.code` is set from combo.code for code-based bindings.\n const eventKey = combo.bareModifier\n ? BARE_MOD_TO_KEY[combo.bareModifier]\n : combo.key\n\n // For bare-modifier keyup, real KeyboardEvents have the corresponding\n // modifier flag FALSE (the modifier just released). Mirror that so\n // automation handlers that inspect e.altKey / e.ctrlKey / etc. see the\n // same value they'd see from a real event.\n let altKey = !!combo.alt\n let ctrlKey = !!combo.ctrl\n let shiftKey = !!combo.shift\n let metaKey = !!combo.meta\n if (combo.bareModifier && actualType === 'keyup') {\n if (combo.bareModifier === 'alt') altKey = false\n else if (combo.bareModifier === 'ctrl') ctrlKey = false\n else if (combo.bareModifier === 'shift') shiftKey = false\n else if (combo.bareModifier === 'meta') metaKey = false\n }\n\n const e = {\n type: actualType,\n key: eventKey,\n code: combo.code || null,\n ctrlKey, shiftKey, altKey, metaKey,\n repeat: false,\n preventDefault() { },\n stopPropagation() { },\n stopImmediatePropagation() { },\n target: null,\n }\n\n const winner = pickWinner(\n bindings.filter((b) => (b.options.when ? b.options.when(e) !== false : true))\n )\n if (!winner) return false\n\n winner.handler(e)\n if (winner.options.once) removeById(winner.id)\n return true\n}\n\n\n// Auto-init on window by default (browser only)\nif (defaultTarget) init()\n\nexport default {\n // lifecycle\n init,\n destroy,\n setTarget,\n\n // bindings\n bind,\n unbind,\n registerPlugin,\n unregisterPlugin,\n\n // extension hooks\n onBind,\n\n // control\n pause,\n resume,\n ignoreInput,\n\n // testing / automation\n trigger,\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,SAAS,GAAG,QAAQ,MAAM,IAAI,SAAS;AACrC,SAAO,iBAAiB,MAAM,IAAI,OAAO;AACzC,SAAO,MAAM,OAAO,oBAAoB,MAAM,IAAI,OAAO;AAC3D;AAGA,IAAM,QACJ,OAAO,cAAc,eAAe,uBAAuB,KAAK,UAAU,QAAQ;AAGpF,IAAM,iBAAiB,oBAAI,IAAI,CAAC,QAAQ,SAAS,OAAO,MAAM,CAAC;AAK/D,IAAM,qBAAqB,OAAO,OAAO;AAAA,EACvC,KAAK;AAAA,EACL,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,IAAI;AACN,CAAC;AAED,IAAM,e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