hotkey-router 0.3.1 → 0.3.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 +75 -8
- package/dist/auto.js +265 -195
- package/dist/auto.js.map +4 -4
- package/dist/auto.min.js +2 -2
- package/dist/format.js +394 -0
- package/dist/format.js.map +7 -0
- package/dist/hotkey-router.cjs +204 -125
- package/dist/hotkey-router.cjs.map +4 -4
- package/dist/hotkey-router.js +203 -126
- package/dist/hotkey-router.js.map +4 -4
- package/dist/hotkey-router.min.js +2 -2
- package/dist/reservations.js +128 -62
- package/dist/reservations.js.map +4 -4
- package/dist/sites.js +195 -80
- package/dist/sites.js.map +4 -4
- package/dist/types/format.d.ts +128 -0
- package/dist/types/hotkey-router.d.ts +19 -20
- package/dist/types/parse.d.ts +112 -0
- package/dist/types/platform.d.ts +23 -0
- package/dist/types/reservations.d.ts +11 -6
- package/dist/types/sites.d.ts +6 -1
- package/dist/validate.js +10 -8
- package/dist/validate.js.map +2 -2
- package/package.json +5 -1
package/dist/auto.js
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
|
-
// hotkey-router v0.3.
|
|
1
|
+
// hotkey-router v0.3.2 | SEE LICENSE IN LICENSE
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
// platform.js
|
|
5
|
+
function fromPlatformString(s) {
|
|
6
|
+
if (!s) return null;
|
|
7
|
+
if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
|
|
8
|
+
if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
|
|
9
|
+
if (/Win/i.test(s)) return "windows";
|
|
10
|
+
if (/Linux|X11/i.test(s)) return "linux";
|
|
11
|
+
return null;
|
|
8
12
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
|
|
14
|
+
if (!nav) return null;
|
|
15
|
+
const ua = nav.userAgent || "";
|
|
16
|
+
const found = (/\bCrOS\b/.test(ua) ? "chromeos" : null) || fromPlatformString(nav.userAgentData?.platform) || fromPlatformString(nav.platform) || (/Mac OS X/i.test(ua) ? "mac" : /Windows/i.test(ua) ? "windows" : /Linux|X11/i.test(ua) ? "linux" : null);
|
|
17
|
+
if (found === "chromeos" && !chromeos) return "linux";
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
function detectBrowser(nav = typeof navigator !== "undefined" ? navigator : null) {
|
|
21
|
+
if (!nav) return null;
|
|
22
|
+
const ua = nav.userAgent || "";
|
|
23
|
+
if (/Edg\//.test(ua)) return "edge";
|
|
24
|
+
if (/Firefox/.test(ua)) return "firefox";
|
|
25
|
+
if (/Chrome/.test(ua)) return "chrome";
|
|
26
|
+
if (/Safari/.test(ua)) return "safari";
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
var PLATFORM_LABELS = { mac: "macOS", windows: "Windows", linux: "Linux", chromeos: "ChromeOS" };
|
|
30
|
+
function platformLabel(platform) {
|
|
31
|
+
return PLATFORM_LABELS[platform] || platform;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// parse.js
|
|
35
|
+
var DEFAULT_PLATFORM = detectPlatform();
|
|
36
|
+
var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
|
|
19
37
|
var ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
20
38
|
["^", "ctrl"],
|
|
21
39
|
// Ctrl
|
|
@@ -58,6 +76,7 @@ var keyAliases = Object.freeze({
|
|
|
58
76
|
control: "ctrl",
|
|
59
77
|
ctrl: "ctrl",
|
|
60
78
|
option: "alt",
|
|
79
|
+
opt: "alt",
|
|
61
80
|
alt: "alt",
|
|
62
81
|
shift: "shift",
|
|
63
82
|
// modifiers (symbols)
|
|
@@ -65,19 +84,11 @@ var keyAliases = Object.freeze({
|
|
|
65
84
|
"\u2303": "ctrl",
|
|
66
85
|
"\u2325": "alt",
|
|
67
86
|
"\u21E7": "shift",
|
|
68
|
-
// cross-platform "mod"
|
|
69
|
-
mod:
|
|
87
|
+
// cross-platform "mod", resolved per platform while parsing
|
|
88
|
+
mod: "mod",
|
|
70
89
|
// plus key ergonomics
|
|
71
90
|
plus: "+"
|
|
72
91
|
});
|
|
73
|
-
var ignoreEditable = true;
|
|
74
|
-
var defaultTarget = typeof window !== "undefined" ? window : null;
|
|
75
|
-
var bindHooks = [];
|
|
76
|
-
var registry = /* @__PURE__ */ new Map();
|
|
77
|
-
var plugins = /* @__PURE__ */ new Map();
|
|
78
|
-
var bindingIndex = /* @__PURE__ */ new Map();
|
|
79
|
-
var paused = false;
|
|
80
|
-
var nextId = 1;
|
|
81
92
|
function normalizeKey(key) {
|
|
82
93
|
const original = String(key ?? "");
|
|
83
94
|
if (original === " ") return " ";
|
|
@@ -85,43 +96,16 @@ function normalizeKey(key) {
|
|
|
85
96
|
const k = trimmed.toLowerCase();
|
|
86
97
|
return keyAliases[k] ?? k;
|
|
87
98
|
}
|
|
88
|
-
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
89
|
-
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
90
|
-
let s = "";
|
|
91
|
-
if (ctrl) s += "ctrl+";
|
|
92
|
-
if (shift) s += "shift+";
|
|
93
|
-
if (alt) s += "alt+";
|
|
94
|
-
if (meta) s += "meta+";
|
|
95
|
-
if (code) return s + "code:" + code;
|
|
96
|
-
return s ? s + key : key;
|
|
97
|
-
}
|
|
98
|
-
function comboKeyFromEvent(e) {
|
|
99
|
-
const bareMod = MODIFIER_KEY_TOKEN[e.key];
|
|
100
|
-
if (bareMod) return `__bare__:${bareMod}`;
|
|
101
|
-
return comboKeyFromParts({
|
|
102
|
-
ctrl: e.ctrlKey,
|
|
103
|
-
shift: e.shiftKey,
|
|
104
|
-
alt: e.altKey,
|
|
105
|
-
meta: e.metaKey,
|
|
106
|
-
key: normalizeKey(e.key)
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function codeKeyFromEvent(e) {
|
|
110
|
-
if (!e.code) return null;
|
|
111
|
-
let s = "";
|
|
112
|
-
if (e.ctrlKey) s += "ctrl+";
|
|
113
|
-
if (e.shiftKey) s += "shift+";
|
|
114
|
-
if (e.altKey) s += "alt+";
|
|
115
|
-
if (e.metaKey) s += "meta+";
|
|
116
|
-
return s + "code:" + e.code;
|
|
117
|
-
}
|
|
118
99
|
function isModifierToken(token) {
|
|
119
|
-
|
|
120
|
-
return modifierTokens.has(t);
|
|
100
|
+
return modifierTokens.has(normalizeKey(token));
|
|
121
101
|
}
|
|
122
102
|
var CODE_TOKEN_RE = /(^|\+)code:([A-Za-z][A-Za-z0-9_]*)/;
|
|
123
|
-
function
|
|
103
|
+
function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
|
|
124
104
|
const raw = String(hotkeyStr || "").trim();
|
|
105
|
+
let error = null;
|
|
106
|
+
const fail = (msg) => {
|
|
107
|
+
error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
|
|
108
|
+
};
|
|
125
109
|
const isUp = /\s+up$/i.test(raw);
|
|
126
110
|
const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
|
|
127
111
|
const combo = {
|
|
@@ -133,25 +117,27 @@ function parseHotkey(hotkeyStr) {
|
|
|
133
117
|
code: null,
|
|
134
118
|
bareModifier: null
|
|
135
119
|
};
|
|
120
|
+
const setMod = (mod) => {
|
|
121
|
+
if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
|
|
122
|
+
else combo[mod] = true;
|
|
123
|
+
};
|
|
136
124
|
let stripped = baseRaw;
|
|
137
125
|
while (stripped.length) {
|
|
138
126
|
const mod = ahkPrefixMap.get(stripped[0]) ?? null;
|
|
139
127
|
if (!mod) break;
|
|
140
|
-
|
|
128
|
+
setMod(mod);
|
|
141
129
|
stripped = stripped.slice(1).trimStart();
|
|
142
130
|
}
|
|
143
131
|
const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
|
|
144
132
|
if (codeMatches && codeMatches.length > 1) {
|
|
145
|
-
|
|
146
|
-
`Invalid hotkey "${hotkeyStr}": multiple code: tokens not supported (got ${codeMatches.length}).`
|
|
147
|
-
);
|
|
133
|
+
fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
|
|
148
134
|
}
|
|
149
135
|
let codeValue = null;
|
|
150
136
|
const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
|
|
151
137
|
codeValue = val;
|
|
152
138
|
return sep + "__code__";
|
|
153
139
|
});
|
|
154
|
-
|
|
140
|
+
const cleanStr = scrubbed.toLowerCase();
|
|
155
141
|
const rawParts = cleanStr.split("+").map((p) => p.trim());
|
|
156
142
|
const parts = rawParts.filter(Boolean);
|
|
157
143
|
const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
|
|
@@ -159,13 +145,9 @@ function parseHotkey(hotkeyStr) {
|
|
|
159
145
|
let seenBase = false;
|
|
160
146
|
for (const part of parts) {
|
|
161
147
|
if (isModifierToken(part)) {
|
|
162
|
-
if (seenBase)
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Invalid hotkey "${hotkeyStr}": modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")`
|
|
165
|
-
);
|
|
166
|
-
}
|
|
148
|
+
if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
|
|
167
149
|
} else {
|
|
168
|
-
|
|
150
|
+
seenBase = true;
|
|
169
151
|
}
|
|
170
152
|
}
|
|
171
153
|
}
|
|
@@ -175,10 +157,7 @@ function parseHotkey(hotkeyStr) {
|
|
|
175
157
|
continue;
|
|
176
158
|
}
|
|
177
159
|
const actual = keyAliases[part] ?? part;
|
|
178
|
-
if (actual
|
|
179
|
-
else if (actual === "shift") combo.shift = true;
|
|
180
|
-
else if (actual === "alt") combo.alt = true;
|
|
181
|
-
else if (actual === "meta") combo.meta = true;
|
|
160
|
+
if (modifierTokens.has(actual)) setMod(actual);
|
|
182
161
|
else combo.key = normalizeKey(actual);
|
|
183
162
|
}
|
|
184
163
|
if (!combo.key && !combo.code && impliedPlusKey) combo.key = "+";
|
|
@@ -187,14 +166,111 @@ function parseHotkey(hotkeyStr) {
|
|
|
187
166
|
if (modCount === 1) {
|
|
188
167
|
combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
|
|
189
168
|
} else if (modCount > 1) {
|
|
190
|
-
|
|
191
|
-
`Invalid hotkey "${hotkeyStr}": multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").`
|
|
192
|
-
);
|
|
169
|
+
fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
|
|
193
170
|
} else {
|
|
194
|
-
|
|
171
|
+
error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
|
|
195
172
|
}
|
|
196
173
|
}
|
|
197
|
-
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr };
|
|
174
|
+
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
|
|
175
|
+
}
|
|
176
|
+
function parseHotkey(hotkeyStr, opts) {
|
|
177
|
+
const { combo, type, raw, error } = readHotkey(hotkeyStr, opts);
|
|
178
|
+
if (error) throw new Error(error);
|
|
179
|
+
return { combo, type, raw };
|
|
180
|
+
}
|
|
181
|
+
var PUNCT_NAMES = {
|
|
182
|
+
".": "period",
|
|
183
|
+
",": "comma",
|
|
184
|
+
";": "semicolon",
|
|
185
|
+
"'": "quote",
|
|
186
|
+
"/": "slash",
|
|
187
|
+
"\\": "backslash",
|
|
188
|
+
"[": "bracketleft",
|
|
189
|
+
"]": "bracketright",
|
|
190
|
+
"-": "minus",
|
|
191
|
+
"=": "equal",
|
|
192
|
+
"`": "backquote",
|
|
193
|
+
" ": "space",
|
|
194
|
+
"+": "equal"
|
|
195
|
+
};
|
|
196
|
+
function codeToBase(code) {
|
|
197
|
+
if (!code) return null;
|
|
198
|
+
const letter = /^Key([A-Za-z])$/.exec(code);
|
|
199
|
+
if (letter) return letter[1].toLowerCase();
|
|
200
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
201
|
+
if (digit) return digit[1];
|
|
202
|
+
return code.toLowerCase();
|
|
203
|
+
}
|
|
204
|
+
function keyToBase(key) {
|
|
205
|
+
if (key == null || key === "") return null;
|
|
206
|
+
if (PUNCT_NAMES[key]) return PUNCT_NAMES[key];
|
|
207
|
+
const k = normalizeKey(key);
|
|
208
|
+
return PUNCT_NAMES[k] || k || null;
|
|
209
|
+
}
|
|
210
|
+
function lookupKey(combo) {
|
|
211
|
+
if (!combo || combo.bareModifier) return null;
|
|
212
|
+
const base = combo.code ? codeToBase(combo.code) : keyToBase(combo.key);
|
|
213
|
+
if (!base) return null;
|
|
214
|
+
const parts = [];
|
|
215
|
+
if (combo.ctrl) parts.push("ctrl");
|
|
216
|
+
if (combo.meta) parts.push("meta");
|
|
217
|
+
if (combo.alt) parts.push("alt");
|
|
218
|
+
if (combo.shift) parts.push("shift");
|
|
219
|
+
parts.push(base);
|
|
220
|
+
return parts.join("+");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// hotkey-router.js
|
|
224
|
+
function on(target, type, fn, options) {
|
|
225
|
+
target.addEventListener(type, fn, options);
|
|
226
|
+
return () => target.removeEventListener(type, fn, options);
|
|
227
|
+
}
|
|
228
|
+
var PLATFORM = detectPlatform();
|
|
229
|
+
var MODIFIER_KEY_TOKEN = Object.freeze({
|
|
230
|
+
Alt: "alt",
|
|
231
|
+
AltGraph: "alt",
|
|
232
|
+
Control: "ctrl",
|
|
233
|
+
Shift: "shift",
|
|
234
|
+
Meta: "meta",
|
|
235
|
+
OS: "meta"
|
|
236
|
+
});
|
|
237
|
+
var ignoreEditable = true;
|
|
238
|
+
var defaultTarget = typeof window !== "undefined" ? window : null;
|
|
239
|
+
var bindHooks = [];
|
|
240
|
+
var registry = /* @__PURE__ */ new Map();
|
|
241
|
+
var plugins = /* @__PURE__ */ new Map();
|
|
242
|
+
var bindingIndex = /* @__PURE__ */ new Map();
|
|
243
|
+
var paused = false;
|
|
244
|
+
var nextId = 1;
|
|
245
|
+
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
246
|
+
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
247
|
+
let s = "";
|
|
248
|
+
if (ctrl) s += "ctrl+";
|
|
249
|
+
if (shift) s += "shift+";
|
|
250
|
+
if (alt) s += "alt+";
|
|
251
|
+
if (meta) s += "meta+";
|
|
252
|
+
if (code) return s + "code:" + code;
|
|
253
|
+
return s ? s + key : key;
|
|
254
|
+
}
|
|
255
|
+
function comboKeyFromEvent(e) {
|
|
256
|
+
const bareMod = MODIFIER_KEY_TOKEN[e.key];
|
|
257
|
+
if (bareMod) return `__bare__:${bareMod}`;
|
|
258
|
+
return comboKeyFromParts({
|
|
259
|
+
ctrl: e.ctrlKey,
|
|
260
|
+
shift: e.shiftKey,
|
|
261
|
+
alt: e.altKey,
|
|
262
|
+
meta: e.metaKey,
|
|
263
|
+
key: normalizeKey(e.key)
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function codeKeyFromEvent(e) {
|
|
267
|
+
if (!e.code) return null;
|
|
268
|
+
let s = "";
|
|
269
|
+
if (e.ctrlKey) s += "ctrl+";
|
|
270
|
+
if (e.shiftKey) s += "shift+";
|
|
271
|
+
if (e.altKey) s += "alt+";
|
|
272
|
+
if (e.metaKey) s += "meta+";
|
|
273
|
+
return s + "code:" + e.code;
|
|
198
274
|
}
|
|
199
275
|
function isFromInputTarget(e) {
|
|
200
276
|
const t = e?.target;
|
|
@@ -344,41 +420,44 @@ function isAltGraphCharacter(e) {
|
|
|
344
420
|
function isComposingEvent(e) {
|
|
345
421
|
return Boolean(e.isComposing || e.keyCode === 229);
|
|
346
422
|
}
|
|
423
|
+
function eligibleBindings(e, type, phase) {
|
|
424
|
+
const altGraphChar = isAltGraphCharacter(e);
|
|
425
|
+
const composing = isComposingEvent(e);
|
|
426
|
+
const fromInput = ignoreEditable && isFromInputTarget(e);
|
|
427
|
+
const seen = /* @__PURE__ */ new Set();
|
|
428
|
+
const candidates = [];
|
|
429
|
+
for (const lookupKey2 of [comboKeyFromEvent(e), codeKeyFromEvent(e)]) {
|
|
430
|
+
if (!lookupKey2 || seen.has(lookupKey2)) continue;
|
|
431
|
+
seen.add(lookupKey2);
|
|
432
|
+
const bindings = registry.get(lookupKey2)?.get(type);
|
|
433
|
+
if (!bindings?.length) continue;
|
|
434
|
+
for (const b of bindings) {
|
|
435
|
+
const o = b.options;
|
|
436
|
+
if (phase === "capture" && !o.capture) continue;
|
|
437
|
+
if (phase === "bubble" && o.capture) continue;
|
|
438
|
+
if (altGraphChar && !o.altGraph) continue;
|
|
439
|
+
if (composing && !o.composing) continue;
|
|
440
|
+
if (fromInput && !o.allowIn?.(e)) continue;
|
|
441
|
+
if (type === "keydown" && o.repeat === false && e.repeat) continue;
|
|
442
|
+
if (o.when && o.when(e) === false) continue;
|
|
443
|
+
candidates.push(b);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return candidates;
|
|
447
|
+
}
|
|
448
|
+
function fire(winner, e) {
|
|
449
|
+
const o = winner.options;
|
|
450
|
+
if (o.preventDefault) e.preventDefault();
|
|
451
|
+
if (o.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
452
|
+
else if (o.stopPropagation) e.stopPropagation();
|
|
453
|
+
winner.handler(e);
|
|
454
|
+
if (o.once) removeById(winner.id);
|
|
455
|
+
}
|
|
347
456
|
function handleEvent(type, phase = "all") {
|
|
348
457
|
return (e) => {
|
|
349
458
|
if (paused) return;
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
const fromInput = ignoreEditable && isFromInputTarget(e);
|
|
353
|
-
const comboStr = comboKeyFromEvent(e);
|
|
354
|
-
const codeStr = codeKeyFromEvent(e);
|
|
355
|
-
const seen = /* @__PURE__ */ new Set();
|
|
356
|
-
const candidates = [];
|
|
357
|
-
for (const lookupKey of [comboStr, codeStr]) {
|
|
358
|
-
if (!lookupKey || seen.has(lookupKey)) continue;
|
|
359
|
-
seen.add(lookupKey);
|
|
360
|
-
const bindings = registry.get(lookupKey)?.get(type);
|
|
361
|
-
if (!bindings?.length) continue;
|
|
362
|
-
for (const b of bindings) {
|
|
363
|
-
const o2 = b.options;
|
|
364
|
-
if (phase === "capture" && !o2.capture) continue;
|
|
365
|
-
if (phase === "bubble" && o2.capture) continue;
|
|
366
|
-
if (altGraphChar && !o2.altGraph) continue;
|
|
367
|
-
if (composing && !o2.composing) continue;
|
|
368
|
-
if (fromInput && !o2.allowIn?.(e)) continue;
|
|
369
|
-
if (type === "keydown" && o2.repeat === false && e.repeat) continue;
|
|
370
|
-
if (o2.when && o2.when(e) === false) continue;
|
|
371
|
-
candidates.push(b);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
if (!candidates.length) return;
|
|
375
|
-
const winner = pickWinner(candidates);
|
|
376
|
-
const o = winner.options;
|
|
377
|
-
if (o.preventDefault) e.preventDefault();
|
|
378
|
-
if (o.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
379
|
-
else if (o.stopPropagation) e.stopPropagation();
|
|
380
|
-
winner.handler(e);
|
|
381
|
-
if (o.once) removeById(winner.id);
|
|
459
|
+
const candidates = eligibleBindings(e, type, phase);
|
|
460
|
+
if (candidates.length) fire(pickWinner(candidates), e);
|
|
382
461
|
};
|
|
383
462
|
}
|
|
384
463
|
var stopDown = null;
|
|
@@ -417,13 +496,62 @@ var BARE_MOD_TO_KEY = {
|
|
|
417
496
|
alt: "Alt",
|
|
418
497
|
meta: "Meta"
|
|
419
498
|
};
|
|
420
|
-
|
|
499
|
+
var CODE_TO_KEY = {
|
|
500
|
+
Period: ".",
|
|
501
|
+
Comma: ",",
|
|
502
|
+
Semicolon: ";",
|
|
503
|
+
Quote: "'",
|
|
504
|
+
Slash: "/",
|
|
505
|
+
Backslash: "\\",
|
|
506
|
+
BracketLeft: "[",
|
|
507
|
+
BracketRight: "]",
|
|
508
|
+
Minus: "-",
|
|
509
|
+
Equal: "=",
|
|
510
|
+
Backquote: "`",
|
|
511
|
+
Space: " ",
|
|
512
|
+
Enter: "Enter",
|
|
513
|
+
NumpadEnter: "Enter",
|
|
514
|
+
Tab: "Tab",
|
|
515
|
+
Escape: "Escape",
|
|
516
|
+
Backspace: "Backspace",
|
|
517
|
+
Delete: "Delete",
|
|
518
|
+
Insert: "Insert",
|
|
519
|
+
Home: "Home",
|
|
520
|
+
End: "End",
|
|
521
|
+
PageUp: "PageUp",
|
|
522
|
+
PageDown: "PageDown",
|
|
523
|
+
ArrowUp: "ArrowUp",
|
|
524
|
+
ArrowDown: "ArrowDown",
|
|
525
|
+
ArrowLeft: "ArrowLeft",
|
|
526
|
+
ArrowRight: "ArrowRight"
|
|
527
|
+
};
|
|
528
|
+
var KEY_TO_CODE = {};
|
|
529
|
+
var _a;
|
|
530
|
+
for (const [code, key] of Object.entries(CODE_TO_KEY)) {
|
|
531
|
+
KEY_TO_CODE[_a = normalizeKey(key)] ?? (KEY_TO_CODE[_a] = code);
|
|
532
|
+
}
|
|
533
|
+
function keyForCode(code) {
|
|
534
|
+
if (!code) return null;
|
|
535
|
+
const letter = /^Key([A-Z])$/.exec(code);
|
|
536
|
+
if (letter) return letter[1].toLowerCase();
|
|
537
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
538
|
+
if (digit) return digit[1];
|
|
539
|
+
if (/^F\d{1,2}$/.test(code)) return code;
|
|
540
|
+
return CODE_TO_KEY[code] ?? null;
|
|
541
|
+
}
|
|
542
|
+
function codeForKey(key) {
|
|
543
|
+
if (!key) return null;
|
|
544
|
+
if (/^[a-z]$/.test(key)) return "Key" + key.toUpperCase();
|
|
545
|
+
if (/^\d$/.test(key)) return "Digit" + key;
|
|
546
|
+
if (/^f\d{1,2}$/.test(key)) return key.toUpperCase();
|
|
547
|
+
return KEY_TO_CODE[key] ?? null;
|
|
548
|
+
}
|
|
549
|
+
function trigger(hotkeyStr, { type: forcedType, target = null } = {}) {
|
|
421
550
|
const { combo, type } = parseHotkey(hotkeyStr);
|
|
422
|
-
const comboStr = comboKeyFromParts(combo);
|
|
423
551
|
const actualType = forcedType || type;
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const
|
|
552
|
+
if (paused) return false;
|
|
553
|
+
const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key ?? keyForCode(combo.code);
|
|
554
|
+
const eventCode = combo.bareModifier ? null : combo.code ?? codeForKey(combo.key);
|
|
427
555
|
let altKey = !!combo.alt;
|
|
428
556
|
let ctrlKey = !!combo.ctrl;
|
|
429
557
|
let shiftKey = !!combo.shift;
|
|
@@ -437,32 +565,33 @@ function trigger(hotkeyStr, { type: forcedType } = {}) {
|
|
|
437
565
|
const e = {
|
|
438
566
|
type: actualType,
|
|
439
567
|
key: eventKey,
|
|
440
|
-
code:
|
|
568
|
+
code: eventCode,
|
|
441
569
|
ctrlKey,
|
|
442
570
|
shiftKey,
|
|
443
571
|
altKey,
|
|
444
572
|
metaKey,
|
|
445
573
|
repeat: false,
|
|
574
|
+
isComposing: false,
|
|
575
|
+
getModifierState() {
|
|
576
|
+
return false;
|
|
577
|
+
},
|
|
446
578
|
preventDefault() {
|
|
447
579
|
},
|
|
448
580
|
stopPropagation() {
|
|
449
581
|
},
|
|
450
582
|
stopImmediatePropagation() {
|
|
451
583
|
},
|
|
452
|
-
target
|
|
584
|
+
target
|
|
453
585
|
};
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
);
|
|
457
|
-
if (!winner) return false;
|
|
458
|
-
winner.handler(e);
|
|
459
|
-
if (winner.options.once) removeById(winner.id);
|
|
586
|
+
const candidates = eligibleBindings(e, actualType, "all");
|
|
587
|
+
if (!candidates.length) return false;
|
|
588
|
+
fire(pickWinner(candidates), e);
|
|
460
589
|
return true;
|
|
461
590
|
}
|
|
462
|
-
function comboFromEvent(e, { physical = true, useMod = false } = {}) {
|
|
591
|
+
function comboFromEvent(e, { physical = true, useMod = false, platform = PLATFORM } = {}) {
|
|
463
592
|
if (!e || MODIFIER_KEY_TOKEN[e.key]) return null;
|
|
464
593
|
const parts = [];
|
|
465
|
-
const primaryIsMeta =
|
|
594
|
+
const primaryIsMeta = platform === "mac";
|
|
466
595
|
if (useMod && (primaryIsMeta ? e.metaKey : e.ctrlKey)) parts.push("mod");
|
|
467
596
|
if (e.ctrlKey && !(useMod && !primaryIsMeta)) parts.push("ctrl");
|
|
468
597
|
if (e.metaKey && !(useMod && primaryIsMeta)) parts.push("meta");
|
|
@@ -497,7 +626,8 @@ var hotkey_router_default = {
|
|
|
497
626
|
trigger,
|
|
498
627
|
// helpers
|
|
499
628
|
parseHotkey,
|
|
500
|
-
comboFromEvent
|
|
629
|
+
comboFromEvent,
|
|
630
|
+
detectPlatform
|
|
501
631
|
};
|
|
502
632
|
|
|
503
633
|
// data/browser-hotkeys.json
|
|
@@ -858,27 +988,6 @@ var browser_hotkeys_default = {
|
|
|
858
988
|
// reservations.js
|
|
859
989
|
var SUPPORTED_SCHEMA = "1.0";
|
|
860
990
|
var HARD_SEVERITIES = /* @__PURE__ */ new Set(["hard", "os", "menu-activation"]);
|
|
861
|
-
function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null) {
|
|
862
|
-
if (!nav) return null;
|
|
863
|
-
const platform = nav.platform || "";
|
|
864
|
-
if (/Mac|iPhone|iPad|iPod/.test(platform)) return "mac";
|
|
865
|
-
if (/Win/i.test(platform)) return "windows";
|
|
866
|
-
if (/Linux|X11/i.test(platform)) return "linux";
|
|
867
|
-
const ua = nav.userAgent || "";
|
|
868
|
-
if (/Mac OS X/i.test(ua)) return "mac";
|
|
869
|
-
if (/Windows/i.test(ua)) return "windows";
|
|
870
|
-
if (/Linux|X11/i.test(ua)) return "linux";
|
|
871
|
-
return null;
|
|
872
|
-
}
|
|
873
|
-
function detectBrowser(nav = typeof navigator !== "undefined" ? navigator : null) {
|
|
874
|
-
if (!nav) return null;
|
|
875
|
-
const ua = nav.userAgent || "";
|
|
876
|
-
if (/Edg\//.test(ua)) return "edge";
|
|
877
|
-
if (/Firefox/.test(ua)) return "firefox";
|
|
878
|
-
if (/Chrome/.test(ua)) return "chrome";
|
|
879
|
-
if (/Safari/.test(ua)) return "safari";
|
|
880
|
-
return null;
|
|
881
|
-
}
|
|
882
991
|
function canonicalize(rawKey) {
|
|
883
992
|
const parts = String(rawKey).toLowerCase().split("+").map((p) => p.trim()).filter(Boolean);
|
|
884
993
|
if (!parts.length) return "";
|
|
@@ -925,83 +1034,44 @@ function buildIndex(data) {
|
|
|
925
1034
|
}
|
|
926
1035
|
var SCHEMA_OK = browser_hotkeys_default?.version?.schema === SUPPORTED_SCHEMA;
|
|
927
1036
|
var INDEX = SCHEMA_OK ? buildIndex(browser_hotkeys_default) : { platforms: {} };
|
|
928
|
-
|
|
929
|
-
if (!code) return null;
|
|
930
|
-
const letter = /^Key([A-Za-z])$/.exec(code);
|
|
931
|
-
if (letter) return letter[1].toLowerCase();
|
|
932
|
-
const digit = /^Digit(\d)$/.exec(code);
|
|
933
|
-
if (digit) return digit[1];
|
|
934
|
-
return code.toLowerCase();
|
|
935
|
-
}
|
|
936
|
-
var PUNCT_KEYS = {
|
|
937
|
-
".": "period",
|
|
938
|
-
",": "comma",
|
|
939
|
-
";": "semicolon",
|
|
940
|
-
"'": "quote",
|
|
941
|
-
"/": "slash",
|
|
942
|
-
"\\": "backslash",
|
|
943
|
-
"[": "bracketleft",
|
|
944
|
-
"]": "bracketright",
|
|
945
|
-
"-": "minus",
|
|
946
|
-
"=": "equal",
|
|
947
|
-
"`": "backquote",
|
|
948
|
-
" ": "space"
|
|
949
|
-
};
|
|
950
|
-
function keyToBase(key) {
|
|
951
|
-
if (key == null) return null;
|
|
952
|
-
return PUNCT_KEYS[key] || key;
|
|
953
|
-
}
|
|
954
|
-
function lookupKeyFromCombo(combo) {
|
|
955
|
-
if (!combo) return null;
|
|
956
|
-
if (combo.bareModifier) return null;
|
|
957
|
-
const base = combo.code ? codeToKey(combo.code) : keyToBase(combo.key);
|
|
958
|
-
if (!base) return null;
|
|
959
|
-
const parts = [];
|
|
960
|
-
if (combo.ctrl) parts.push("ctrl");
|
|
961
|
-
if (combo.meta) parts.push("meta");
|
|
962
|
-
if (combo.alt) parts.push("alt");
|
|
963
|
-
if (combo.shift) parts.push("shift");
|
|
964
|
-
parts.push(base);
|
|
965
|
-
return parts.join("+");
|
|
966
|
-
}
|
|
1037
|
+
var lookupKeyFromCombo = lookupKey;
|
|
967
1038
|
function lookupReservation(combo, { platform, browser } = {}) {
|
|
968
1039
|
if (!SCHEMA_OK) return null;
|
|
969
|
-
const
|
|
970
|
-
if (!
|
|
1040
|
+
const lookupKey2 = lookupKeyFromCombo(combo);
|
|
1041
|
+
if (!lookupKey2) return null;
|
|
971
1042
|
const pdata = platform && INDEX.platforms[platform];
|
|
972
1043
|
if (!pdata) return null;
|
|
973
1044
|
const btable = browser ? pdata.browsers?.[browser] : null;
|
|
974
|
-
const bclaim = btable?.[
|
|
1045
|
+
const bclaim = btable?.[lookupKey2];
|
|
975
1046
|
if (bclaim) {
|
|
976
1047
|
return {
|
|
977
1048
|
source: "browser",
|
|
978
1049
|
platform,
|
|
979
1050
|
browser,
|
|
980
|
-
lookupKey,
|
|
1051
|
+
lookupKey: lookupKey2,
|
|
981
1052
|
action: bclaim.action,
|
|
982
1053
|
severity: bclaim.severity
|
|
983
1054
|
};
|
|
984
1055
|
}
|
|
985
|
-
const sclaim = pdata.system?.[
|
|
1056
|
+
const sclaim = pdata.system?.[lookupKey2];
|
|
986
1057
|
if (sclaim) {
|
|
987
1058
|
return {
|
|
988
1059
|
source: "system",
|
|
989
1060
|
platform,
|
|
990
1061
|
browser,
|
|
991
|
-
lookupKey,
|
|
1062
|
+
lookupKey: lookupKey2,
|
|
992
1063
|
action: sclaim.action,
|
|
993
1064
|
severity: sclaim.severity
|
|
994
1065
|
};
|
|
995
1066
|
}
|
|
996
1067
|
return null;
|
|
997
1068
|
}
|
|
998
|
-
var PLATFORM_LABEL = { mac: "macOS", windows: "Windows", linux: "Linux" };
|
|
999
1069
|
function severityIsHard(severity) {
|
|
1000
1070
|
return HARD_SEVERITIES.has(severity);
|
|
1001
1071
|
}
|
|
1002
1072
|
function formatReservationWarning(reservation, rawHotkey) {
|
|
1003
|
-
const
|
|
1004
|
-
const sourceLabel = reservation.source === "browser" ? `${reservation.browser} on ${
|
|
1073
|
+
const where = platformLabel(reservation.platform);
|
|
1074
|
+
const sourceLabel = reservation.source === "browser" ? `${reservation.browser} on ${where}` : where;
|
|
1005
1075
|
const tag = severityIsHard(reservation.severity) ? "will not fire" : "fires in normal browsing";
|
|
1006
1076
|
return `[hotkey-router] "${rawHotkey}" (${reservation.lookupKey}) reserved by ${sourceLabel}: "${reservation.action}" [${reservation.severity}] \u2014 ${tag}.`;
|
|
1007
1077
|
}
|