hotkey-router 0.5.2 → 0.6.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/README.md +32 -27
- package/dist/auto.js +3 -3
- package/dist/auto.js.map +2 -2
- package/dist/auto.min.js +2 -2
- package/dist/core.js +17 -321
- package/dist/core.js.map +3 -3
- package/dist/dev.js +56 -0
- package/dist/dev.js.map +7 -0
- package/dist/format.js +4 -194
- package/dist/format.js.map +3 -3
- package/dist/hotkey-router.cjs +14 -145
- package/dist/hotkey-router.cjs.map +2 -2
- package/dist/hotkey-router.js +1 -1
- package/dist/hotkey-router.js.map +2 -2
- package/dist/hotkey-router.min.js +2 -2
- package/dist/lookup.js +9 -0
- package/dist/lookup.js.map +7 -0
- package/dist/parse.js +207 -0
- package/dist/parse.js.map +7 -0
- package/dist/platform.js +42 -0
- package/dist/platform.js.map +7 -0
- package/dist/reservations.js +6 -666
- package/dist/reservations.js.map +3 -3
- package/dist/shifted-punctuation.js +34 -0
- package/dist/shifted-punctuation.js.map +7 -0
- package/dist/sites.js +3 -227
- package/dist/sites.js.map +3 -3
- package/dist/testing.js +104 -0
- package/dist/testing.js.map +7 -0
- package/dist/types/core.d.ts +3 -9
- package/dist/types/dev.d.ts +48 -0
- package/dist/types/parse.d.ts +0 -13
- package/dist/types/reservations.d.ts +4 -44
- package/dist/types/shifted-punctuation.d.ts +17 -0
- package/dist/types/testing.d.ts +17 -0
- package/dist/validate.js +7 -203
- package/dist/validate.js.map +3 -3
- package/package.json +9 -1
package/dist/parse.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// hotkey-router v0.6.0 | SEE LICENSE IN LICENSE
|
|
2
|
+
|
|
3
|
+
import { ownValue } from "./lookup.js";
|
|
4
|
+
import { detectPlatform } from "./platform.js";
|
|
5
|
+
const DEFAULT_PLATFORM = detectPlatform();
|
|
6
|
+
const modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
|
|
7
|
+
const ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
8
|
+
["^", "ctrl"],
|
|
9
|
+
// Ctrl
|
|
10
|
+
["!", "alt"],
|
|
11
|
+
// Alt
|
|
12
|
+
["+", "shift"],
|
|
13
|
+
// Shift
|
|
14
|
+
["#", "meta"]
|
|
15
|
+
// Win / Command
|
|
16
|
+
]);
|
|
17
|
+
const keyAliases = Object.freeze({
|
|
18
|
+
// common
|
|
19
|
+
esc: "escape",
|
|
20
|
+
escape: "escape",
|
|
21
|
+
space: " ",
|
|
22
|
+
spacebar: " ",
|
|
23
|
+
enter: "enter",
|
|
24
|
+
return: "enter",
|
|
25
|
+
del: "delete",
|
|
26
|
+
delete: "delete",
|
|
27
|
+
backspace: "backspace",
|
|
28
|
+
tab: "tab",
|
|
29
|
+
// arrows
|
|
30
|
+
up: "arrowup",
|
|
31
|
+
down: "arrowdown",
|
|
32
|
+
left: "arrowleft",
|
|
33
|
+
right: "arrowright",
|
|
34
|
+
// navigation
|
|
35
|
+
home: "home",
|
|
36
|
+
end: "end",
|
|
37
|
+
pageup: "pageup",
|
|
38
|
+
pagedown: "pagedown",
|
|
39
|
+
pgup: "pageup",
|
|
40
|
+
pgdn: "pagedown",
|
|
41
|
+
// modifiers (words)
|
|
42
|
+
cmd: "meta",
|
|
43
|
+
command: "meta",
|
|
44
|
+
win: "meta",
|
|
45
|
+
meta: "meta",
|
|
46
|
+
control: "ctrl",
|
|
47
|
+
ctrl: "ctrl",
|
|
48
|
+
option: "alt",
|
|
49
|
+
opt: "alt",
|
|
50
|
+
alt: "alt",
|
|
51
|
+
shift: "shift",
|
|
52
|
+
// modifiers (symbols)
|
|
53
|
+
"\u2318": "meta",
|
|
54
|
+
"\u2303": "ctrl",
|
|
55
|
+
"\u2325": "alt",
|
|
56
|
+
"\u21E7": "shift",
|
|
57
|
+
// cross-platform "mod", resolved per platform while parsing
|
|
58
|
+
mod: "mod",
|
|
59
|
+
// plus key ergonomics
|
|
60
|
+
plus: "+"
|
|
61
|
+
});
|
|
62
|
+
function normalizeKey(key) {
|
|
63
|
+
const original = String(key ?? "");
|
|
64
|
+
if (original === " ") return " ";
|
|
65
|
+
const trimmed = original.trim();
|
|
66
|
+
const k = trimmed.toLowerCase();
|
|
67
|
+
return ownValue(keyAliases, k) ?? k;
|
|
68
|
+
}
|
|
69
|
+
function isModifierToken(token) {
|
|
70
|
+
return modifierTokens.has(normalizeKey(token));
|
|
71
|
+
}
|
|
72
|
+
const CODE_TOKEN_RE = /(^|\+)\s*code:([A-Za-z][A-Za-z0-9_]*)/;
|
|
73
|
+
function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
|
|
74
|
+
const raw = String(hotkeyStr || "").trim();
|
|
75
|
+
let error = null;
|
|
76
|
+
const fail = (msg) => {
|
|
77
|
+
error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
|
|
78
|
+
};
|
|
79
|
+
const isUp = /\s+up$/i.test(raw);
|
|
80
|
+
const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
|
|
81
|
+
const combo = {
|
|
82
|
+
ctrl: false,
|
|
83
|
+
shift: false,
|
|
84
|
+
alt: false,
|
|
85
|
+
meta: false,
|
|
86
|
+
key: null,
|
|
87
|
+
code: null,
|
|
88
|
+
bareModifier: null
|
|
89
|
+
};
|
|
90
|
+
const setMod = (mod) => {
|
|
91
|
+
if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
|
|
92
|
+
else combo[mod] = true;
|
|
93
|
+
};
|
|
94
|
+
let stripped = baseRaw;
|
|
95
|
+
while (stripped.length > 1) {
|
|
96
|
+
const mod = ahkPrefixMap.get(stripped[0]) ?? null;
|
|
97
|
+
if (!mod) break;
|
|
98
|
+
setMod(mod);
|
|
99
|
+
stripped = stripped.slice(1).trimStart();
|
|
100
|
+
}
|
|
101
|
+
const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
|
|
102
|
+
if (codeMatches && codeMatches.length > 1) {
|
|
103
|
+
fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
|
|
104
|
+
}
|
|
105
|
+
let codeValue = null;
|
|
106
|
+
const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
|
|
107
|
+
codeValue = val;
|
|
108
|
+
return sep + "__code__";
|
|
109
|
+
});
|
|
110
|
+
const cleanStr = scrubbed.toLowerCase();
|
|
111
|
+
const rawParts = cleanStr.split("+").map((p) => p.trim());
|
|
112
|
+
const parts = rawParts.filter(Boolean);
|
|
113
|
+
const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
|
|
114
|
+
if (!impliedPlusKey) {
|
|
115
|
+
let seenBase = false;
|
|
116
|
+
for (const part of parts) {
|
|
117
|
+
if (isModifierToken(part)) {
|
|
118
|
+
if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
|
|
119
|
+
} else {
|
|
120
|
+
seenBase = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let bases = 0;
|
|
125
|
+
for (const part of parts) {
|
|
126
|
+
if (part === "__code__") {
|
|
127
|
+
combo.code = codeValue;
|
|
128
|
+
bases++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const actual = ownValue(keyAliases, part) ?? part;
|
|
132
|
+
if (modifierTokens.has(actual)) setMod(actual);
|
|
133
|
+
else {
|
|
134
|
+
combo.key = normalizeKey(actual);
|
|
135
|
+
bases++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (bases > 1) fail('use one base key (e.g. "ctrl+k"), or one code: token');
|
|
139
|
+
if (!combo.key && !combo.code && (impliedPlusKey || stripped === "+")) combo.key = "+";
|
|
140
|
+
if (!combo.key && !combo.code) {
|
|
141
|
+
const modCount = (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) + (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0);
|
|
142
|
+
if (modCount === 1) {
|
|
143
|
+
combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
|
|
144
|
+
} else if (modCount > 1) {
|
|
145
|
+
fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
|
|
146
|
+
} else {
|
|
147
|
+
error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
|
|
151
|
+
}
|
|
152
|
+
function parseHotkey(hotkeyStr, opts) {
|
|
153
|
+
const { combo, type, raw, error } = readHotkey(hotkeyStr, opts);
|
|
154
|
+
if (error) throw new Error(error);
|
|
155
|
+
return { combo, type, raw };
|
|
156
|
+
}
|
|
157
|
+
const PUNCT_NAMES = {
|
|
158
|
+
".": "period",
|
|
159
|
+
",": "comma",
|
|
160
|
+
";": "semicolon",
|
|
161
|
+
"'": "quote",
|
|
162
|
+
"/": "slash",
|
|
163
|
+
"\\": "backslash",
|
|
164
|
+
"[": "bracketleft",
|
|
165
|
+
"]": "bracketright",
|
|
166
|
+
"-": "minus",
|
|
167
|
+
"=": "equal",
|
|
168
|
+
"`": "backquote",
|
|
169
|
+
" ": "space",
|
|
170
|
+
"+": "equal"
|
|
171
|
+
};
|
|
172
|
+
function codeToBase(code) {
|
|
173
|
+
if (!code) return null;
|
|
174
|
+
const letter = /^Key([A-Za-z])$/.exec(code);
|
|
175
|
+
if (letter) return letter[1].toLowerCase();
|
|
176
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
177
|
+
if (digit) return digit[1];
|
|
178
|
+
return code.toLowerCase();
|
|
179
|
+
}
|
|
180
|
+
function keyToBase(key) {
|
|
181
|
+
if (key == null || key === "") return null;
|
|
182
|
+
if (ownValue(PUNCT_NAMES, key)) return ownValue(PUNCT_NAMES, key);
|
|
183
|
+
const k = normalizeKey(key);
|
|
184
|
+
return ownValue(PUNCT_NAMES, k) || k || null;
|
|
185
|
+
}
|
|
186
|
+
function lookupKey(combo) {
|
|
187
|
+
if (!combo || combo.bareModifier) return null;
|
|
188
|
+
const base = combo.code ? codeToBase(combo.code) : keyToBase(combo.key);
|
|
189
|
+
if (!base) return null;
|
|
190
|
+
const parts = [];
|
|
191
|
+
if (combo.ctrl) parts.push("ctrl");
|
|
192
|
+
if (combo.meta) parts.push("meta");
|
|
193
|
+
if (combo.alt) parts.push("alt");
|
|
194
|
+
if (combo.shift) parts.push("shift");
|
|
195
|
+
parts.push(base);
|
|
196
|
+
return parts.join("+");
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
codeToBase,
|
|
200
|
+
keyAliases,
|
|
201
|
+
keyToBase,
|
|
202
|
+
lookupKey,
|
|
203
|
+
normalizeKey,
|
|
204
|
+
parseHotkey,
|
|
205
|
+
readHotkey
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../parse.js"],
|
|
4
|
+
"sourcesContent": ["// parse.js\n// The one hotkey-string parser. The core router binds with it; sites,\n// validate and format read combos with it, so `opt`, `ctrl++`, `^k` and\n// `mod` mean the same thing everywhere. No state, no side effects.\n\nimport { ownValue } from './lookup.js'\nimport { detectPlatform } from './platform.js'\n\n// `mod` is the platform's primary modifier: meta on macOS, ctrl elsewhere.\nconst DEFAULT_PLATFORM = detectPlatform()\n\nconst modifierTokens = new Set(['ctrl', 'shift', 'alt', 'meta', 'mod'])\n\nconst ahkPrefixMap = new Map([\n ['^', 'ctrl'], // Ctrl\n ['!', 'alt'], // Alt\n ['+', 'shift'], // Shift\n ['#', 'meta'], // Win / Command\n])\n\nexport const 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 opt: '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\", resolved per platform while parsing\n mod: 'mod',\n\n // plus key ergonomics\n plus: '+',\n})\n\nexport function normalizeKey(key) {\n const original = String(key ?? '')\n // A lone space IS the spacebar key \u2014 `.trim()` would erase it to '', so guard\n // on the ORIGINAL before trimming. (The `space`/`spacebar` aliases resolve to\n // ' ' and land here; without this, `space` bindings collapse to no base key.)\n if (original === ' ') return ' '\n const trimmed = original.trim()\n const k = trimmed.toLowerCase()\n return ownValue(keyAliases, k) ?? k\n}\n\nfunction isModifierToken(token) {\n return modifierTokens.has(normalizeKey(token))\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 = /(^|\\+)\\s*code:([A-Za-z][A-Za-z0-9_]*)/\n\n/**\n * Lenient parse: never throws. `error` holds the message `parseHotkey` would\n * throw; the combo is filled in as far as the string allows.\n *\n * @param {string} hotkeyStr\n * @param {{ platform?: string | null }} [opts]\n */\nexport function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {\n const raw = String(hotkeyStr || '').trim()\n let error = null\n const fail = (msg) => { error = error || `Invalid hotkey \"${hotkeyStr}\": ${msg}` }\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 const combo = {\n ctrl: false, shift: false, alt: false, meta: false,\n key: null, code: null, bareModifier: null,\n }\n const setMod = (mod) => {\n if (mod === 'mod') combo[platform === 'mac' ? 'meta' : 'ctrl'] = true\n else combo[mod] = true\n }\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 // A lone prefix character is the key itself: '+', '#', '!' and '^' bind\n // that character, and '^+' is Ctrl with '+'.\n let stripped = baseRaw\n while (stripped.length > 1) {\n const mod = ahkPrefixMap.get(stripped[0]) ?? null\n if (!mod) break\n setMod(mod)\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 fail(`multiple code: tokens not supported (got ${codeMatches.length}).`)\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 const 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) fail('modifiers must come before the base key (e.g. \"ctrl+k\", not \"k+ctrl\")')\n } else {\n seenBase = true\n }\n }\n }\n\n // Continue parsing the remaining tokens (words/symbols/aliases)\n // One base key: 'ctrl+a+b' or 'ctrl+k+code:KeyA' would otherwise keep\n // only one of them without saying so.\n let bases = 0\n for (const part of parts) {\n if (part === '__code__') {\n combo.code = codeValue\n bases++\n continue\n }\n const actual = ownValue(keyAliases, part) ?? part\n if (modifierTokens.has(actual)) setMod(actual)\n else {\n combo.key = normalizeKey(actual)\n bases++\n }\n }\n if (bases > 1) fail('use one base key (e.g. \"ctrl+k\"), or one code: token')\n\n if (!combo.key && !combo.code && (impliedPlusKey || stripped === '+')) 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 fail('multi-modifier bare bindings not supported. Add a base key (e.g. \"ctrl+alt+x\").')\n } else {\n error = error || `Invalid hotkey \"${hotkeyStr}\" (missing base key)`\n }\n }\n\n return { combo, type: isUp ? 'keyup' : 'keydown', raw: hotkeyStr, error }\n}\n\n/**\n * Parse a hotkey string into modifier flags plus a `key` (normalized\n * `KeyboardEvent.key`), a `code` (`KeyboardEvent.code`) or a bare modifier.\n * `mod` resolves for `opts.platform` (default: this machine). Throws on\n * strings the router can't bind.\n *\n * @param {string} hotkeyStr\n * @param {{ platform?: 'mac' | 'windows' | 'linux' | 'chromeos' | null }} [opts]\n * @returns {{\n * combo: { ctrl: boolean, shift: boolean, alt: boolean, meta: boolean, key: string | null, code: string | null, bareModifier: 'ctrl' | 'shift' | 'alt' | 'meta' | null },\n * type: 'keydown' | 'keyup',\n * raw: string\n * }}\n */\nexport function parseHotkey(hotkeyStr, opts) {\n const { combo, type, raw, error } = readHotkey(hotkeyStr, opts)\n if (error) throw new Error(error)\n return { combo, type, raw }\n}\n\n// --- canonical lookup names (reservation + site tables) ----------------------\n\n// Punctuation typed as `event.key` maps to the names the data tables use for\n// `code:` values, so `meta+shift+/` and `meta+shift+code:Slash` find the same\n// row. `+` is Shift+= on most layouts, and browsers treat Ctrl++ as Ctrl+=\n// (zoom in), so it looks up as `equal`.\nconst PUNCT_NAMES = {\n '.': 'period', ',': 'comma', ';': 'semicolon', \"'\": 'quote', '/': 'slash',\n '\\\\': 'backslash', '[': 'bracketleft', ']': 'bracketright', '-': 'minus',\n '=': 'equal', '`': 'backquote', ' ': 'space', '+': 'equal',\n}\n\n/** `KeyA` -> `a`, `Digit1`/`Numpad1` -> `1`, `ArrowLeft` -> `arrowleft`. */\nexport function codeToBase(code) {\n if (!code) return null\n const letter = /^Key([A-Za-z])$/.exec(code)\n if (letter) return letter[1].toLowerCase()\n const digit = /^(?:Digit|Numpad)(\\d)$/.exec(code)\n if (digit) return digit[1]\n return code.toLowerCase()\n}\n\n/** `'.'` -> `period`, `'Esc'` -> `escape`, `'K'` -> `k`. */\nexport function keyToBase(key) {\n if (key == null || key === '') return null\n if (ownValue(PUNCT_NAMES, key)) return ownValue(PUNCT_NAMES, key)\n const k = normalizeKey(key)\n return ownValue(PUNCT_NAMES, k) || k || null\n}\n\n/**\n * The canonical lookup key for a parsed combo: modifiers in the order ctrl,\n * meta, alt, shift, then the base name (`ctrl+shift+period`). Null for a bare\n * modifier or no key.\n *\n * @param {{ ctrl?: boolean, meta?: boolean, alt?: boolean, shift?: boolean, key?: string | null, code?: string | null, bareModifier?: string | null } | null} combo\n * @returns {string | null}\n */\nexport function lookupKey(combo) {\n if (!combo || combo.bareModifier) return null\n const base = combo.code ? codeToBase(combo.code) : keyToBase(combo.key)\n if (!base) return null\n const parts = []\n if (combo.ctrl) parts.push('ctrl')\n if (combo.meta) parts.push('meta')\n if (combo.alt) parts.push('alt')\n if (combo.shift) parts.push('shift')\n parts.push(base)\n return parts.join('+')\n}\n"],
|
|
5
|
+
"mappings": ";;AAKA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAG/B,MAAM,mBAAmB,eAAe;AAExC,MAAM,iBAAiB,oBAAI,IAAI,CAAC,QAAQ,SAAS,OAAO,QAAQ,KAAK,CAAC;AAEtE,MAAM,eAAe,oBAAI,IAAI;AAAA,EAC3B,CAAC,KAAK,MAAM;AAAA;AAAA,EACZ,CAAC,KAAK,KAAK;AAAA;AAAA,EACX,CAAC,KAAK,OAAO;AAAA;AAAA,EACb,CAAC,KAAK,MAAM;AAAA;AACd,CAAC;AAEM,MAAM,aAAa,OAAO,OAAO;AAAA;AAAA,EAEtC,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,KAAK;AAAA;AAAA,EAGL,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA;AAAA,EAGP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAGN,KAAK;AAAA,EACL,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,KAAK;AAAA,EACL,OAAO;AAAA;AAAA,EAGP,UAAK;AAAA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MAAM,aAAc,QAAO;AACzC,QAAM,OAAO,MAAM,OAAO,WAAW,MAAM,IAAI,IAAI,UAAU,MAAM,GAAG;AACtE,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,QAAQ,CAAC;AACf,MAAI,MAAM,KAAM,OAAM,KAAK,MAAM;AACjC,MAAI,MAAM,KAAM,OAAM,KAAK,MAAM;AACjC,MAAI,MAAM,IAAK,OAAM,KAAK,KAAK;AAC/B,MAAI,MAAM,MAAO,OAAM,KAAK,OAAO;AACnC,QAAM,KAAK,IAAI;AACf,SAAO,MAAM,KAAK,GAAG;AACvB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// hotkey-router v0.6.0 | SEE LICENSE IN LICENSE
|
|
2
|
+
|
|
3
|
+
import { ownValue } from "./lookup.js";
|
|
4
|
+
function fromPlatformString(s) {
|
|
5
|
+
if (!s) return null;
|
|
6
|
+
if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
|
|
7
|
+
if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
|
|
8
|
+
if (/Win/i.test(s)) return "windows";
|
|
9
|
+
if (/Linux|X11/i.test(s)) return "linux";
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
|
|
13
|
+
if (!nav) return null;
|
|
14
|
+
const ua = nav.userAgent || "";
|
|
15
|
+
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);
|
|
16
|
+
if (found === "chromeos" && !chromeos) return "linux";
|
|
17
|
+
return found;
|
|
18
|
+
}
|
|
19
|
+
function detectBrowser(nav = typeof navigator !== "undefined" ? navigator : null) {
|
|
20
|
+
if (!nav) return null;
|
|
21
|
+
const ua = nav.userAgent || "";
|
|
22
|
+
if (/Edg\//.test(ua)) return "edge";
|
|
23
|
+
if (/Firefox/.test(ua)) return "firefox";
|
|
24
|
+
if (/Chrome/.test(ua)) return "chrome";
|
|
25
|
+
if (/Safari/.test(ua)) return "safari";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const PLATFORM_LABELS = { mac: "macOS", windows: "Windows", linux: "Linux", chromeos: "ChromeOS" };
|
|
29
|
+
const BROWSER_LABELS = { chrome: "Chrome", firefox: "Firefox", edge: "Edge", safari: "Safari" };
|
|
30
|
+
function platformLabel(platform) {
|
|
31
|
+
return ownValue(PLATFORM_LABELS, platform) || platform;
|
|
32
|
+
}
|
|
33
|
+
function browserLabel(browser) {
|
|
34
|
+
return ownValue(BROWSER_LABELS, browser) || browser;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
browserLabel,
|
|
38
|
+
detectBrowser,
|
|
39
|
+
detectPlatform,
|
|
40
|
+
platformLabel
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../platform.js"],
|
|
4
|
+
"sourcesContent": ["// platform.js\r\n// The one platform/browser detector for hotkey-router. The core router (for\r\n// `mod`), reservations, sites, validate and format all use it, so they never\r\n// disagree about what machine they are on.\r\n//\r\n// Sources, most to least reliable: a ChromeOS user agent (Chromebooks report\r\n// navigator.platform as Linux), navigator.userAgentData.platform (Chromium),\r\n// navigator.platform, then the user agent string.\r\n\r\nimport { ownValue } from './lookup.js'\r\n\r\n/** @typedef {'mac' | 'windows' | 'linux' | 'chromeos'} Platform */\r\n/** @typedef {'chrome' | 'firefox' | 'safari' | 'edge'} Browser */\r\n\r\nfunction fromPlatformString(s) {\r\n if (!s) return null\r\n if (/Chrome ?OS|CrOS/i.test(s)) return 'chromeos'\r\n if (/Mac|iPhone|iPad|iPod/i.test(s)) return 'mac'\r\n if (/Win/i.test(s)) return 'windows'\r\n if (/Linux|X11/i.test(s)) return 'linux'\r\n return null\r\n}\r\n\r\n/**\r\n * The platform a navigator reports: 'mac', 'windows' or 'linux' (ChromeOS\r\n * counts as 'linux' unless `{ chromeos: true }`). Null when it can't tell,\r\n * or outside a browser.\r\n *\r\n * @param {Navigator | null} [nav]\r\n * @param {{ chromeos?: boolean }} [opts]\r\n * @returns {Platform | null}\r\n */\r\nexport function detectPlatform(nav = (typeof navigator !== 'undefined' ? navigator : null), { chromeos = false } = {}) {\r\n if (!nav) return null\r\n const ua = nav.userAgent || ''\r\n const found =\r\n (/\\bCrOS\\b/.test(ua) ? 'chromeos' : null) ||\r\n fromPlatformString(nav.userAgentData?.platform) ||\r\n fromPlatformString(nav.platform) ||\r\n (/Mac OS X/i.test(ua) ? 'mac' : /Windows/i.test(ua) ? 'windows' : /Linux|X11/i.test(ua) ? 'linux' : null)\r\n if (found === 'chromeos' && !chromeos) return 'linux'\r\n return found\r\n}\r\n\r\n/**\r\n * @param {Navigator | null} [nav]\r\n * @returns {Browser | null}\r\n */\r\nexport function detectBrowser(nav = (typeof navigator !== 'undefined' ? navigator : null)) {\r\n if (!nav) return null\r\n const ua = nav.userAgent || ''\r\n // Order matters: Edge UA contains 'Chrome', Chrome UA contains 'Safari'.\r\n if (/Edg\\//.test(ua)) return 'edge'\r\n if (/Firefox/.test(ua)) return 'firefox'\r\n if (/Chrome/.test(ua)) return 'chrome'\r\n if (/Safari/.test(ua)) return 'safari'\r\n return null\r\n}\r\n\r\nconst PLATFORM_LABELS = { mac: 'macOS', windows: 'Windows', linux: 'Linux', chromeos: 'ChromeOS' }\r\nconst BROWSER_LABELS = { chrome: 'Chrome', firefox: 'Firefox', edge: 'Edge', safari: 'Safari' }\r\n\r\n/** 'mac' -> 'macOS'. Unknown names come back as given. @param {string} platform @returns {string} */\r\nexport function platformLabel(platform) {\r\n return ownValue(PLATFORM_LABELS, platform) || platform\r\n}\r\n\r\n/** 'chrome' -> 'Chrome'. Unknown names come back as given. @param {string} browser @returns {string} */\r\nexport function browserLabel(browser) {\r\n return ownValue(BROWSER_LABELS, browser) || browser\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;AASA,SAAS,gBAAgB;AAKzB,SAAS,mBAAmB,GAAG;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,mBAAmB,KAAK,CAAC,EAAG,QAAO;AACvC,MAAI,wBAAwB,KAAK,CAAC,EAAG,QAAO;AAC5C,MAAI,OAAO,KAAK,CAAC,EAAG,QAAO;AAC3B,MAAI,aAAa,KAAK,CAAC,EAAG,QAAO;AACjC,SAAO;AACT;AAWO,SAAS,eAAe,MAAO,OAAO,cAAc,cAAc,YAAY,MAAO,EAAE,WAAW,MAAM,IAAI,CAAC,GAAG;AACrH,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,KAAK,IAAI,aAAa;AAC5B,QAAM,SACH,WAAW,KAAK,EAAE,IAAI,aAAa,SACpC,mBAAmB,IAAI,eAAe,QAAQ,KAC9C,mBAAmB,IAAI,QAAQ,MAC9B,YAAY,KAAK,EAAE,IAAI,QAAQ,WAAW,KAAK,EAAE,IAAI,YAAY,aAAa,KAAK,EAAE,IAAI,UAAU;AACtG,MAAI,UAAU,cAAc,CAAC,SAAU,QAAO;AAC9C,SAAO;AACT;AAMO,SAAS,cAAc,MAAO,OAAO,cAAc,cAAc,YAAY,MAAO;AACzF,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,KAAK,IAAI,aAAa;AAE5B,MAAI,QAAQ,KAAK,EAAE,EAAG,QAAO;AAC7B,MAAI,UAAU,KAAK,EAAE,EAAG,QAAO;AAC/B,MAAI,SAAS,KAAK,EAAE,EAAG,QAAO;AAC9B,MAAI,SAAS,KAAK,EAAE,EAAG,QAAO;AAC9B,SAAO;AACT;AAEA,MAAM,kBAAkB,EAAE,KAAK,SAAS,SAAS,WAAW,OAAO,SAAS,UAAU,WAA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