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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Render a console-friendly warning string for a reservation.
3
+ *
4
+ * @param {Reservation} reservation
5
+ * @param {string} rawHotkey
6
+ * @param {{ preventDefault?: boolean }} [bindOptions] the binding's options
7
+ * @returns {string}
8
+ */
9
+ export function formatReservationWarning(reservation: Reservation, rawHotkey: string, bindOptions?: {
10
+ preventDefault?: boolean;
11
+ }): string;
12
+ /**
13
+ * Emit a reservation warning via the given console (or the global `console`
14
+ * by default). Hard reservations log via `warn`; soft ones via `info`, except
15
+ * a preventable key bound without `preventDefault`, where the browser's
16
+ * action runs too: that logs via `warn`.
17
+ *
18
+ * @param {Reservation} reservation
19
+ * @param {string} rawHotkey
20
+ * @param {WarningConsole} [console_]
21
+ * @param {{ preventDefault?: boolean }} [bindOptions] the binding's options
22
+ * @returns {void}
23
+ */
24
+ export function emitReservationWarning(reservation: Reservation, rawHotkey: string, console_?: WarningConsole, bindOptions?: {
25
+ preventDefault?: boolean;
26
+ }): void;
27
+ /**
28
+ * Subscribe to reservation warnings and shifted-punctuation hints for future binds.
29
+ * @param {BindSource} router
30
+ * @param {WarningOptions} [opts]
31
+ * @returns {() => void} uninstall function
32
+ */
33
+ export function installDevWarnings(router: BindSource, opts?: WarningOptions): () => void;
34
+ /**
35
+ * Subscribe to reservation warnings for future binds.
36
+ * @param {BindSource} router
37
+ * @param {WarningOptions} [opts]
38
+ * @returns {() => void} uninstall function
39
+ */
40
+ export function installReservationWarnings(router: BindSource, opts?: WarningOptions): () => void;
41
+ export type Reservation = import("./reservations.js").Reservation;
42
+ export type BindSource = Pick<import("./core.js").Router, "onBind">;
43
+ export type WarningConsole = Pick<Console, "warn" | "info">;
44
+ export type WarningOptions = {
45
+ platform?: import("./reservations.js").Platform | null;
46
+ browser?: import("./reservations.js").Browser | null;
47
+ console?: WarningConsole;
48
+ };
@@ -51,19 +51,6 @@ export function parseHotkey(hotkeyStr: string, opts?: {
51
51
  type: "keydown" | "keyup";
52
52
  raw: string;
53
53
  };
54
- /**
55
- * For a key-based combo with Shift and one of `, . / ; ' [ ] \ - = \``, the
56
- * message explaining it never fires on US layouts and the `code:` spelling
57
- * to bind instead (written the way the input was). Null for anything else,
58
- * including strings that do not parse.
59
- *
60
- * @param {string} hotkeyStr
61
- * @returns {{ message: string, suggestion: string } | null}
62
- */
63
- export function shiftedPunctuationHint(hotkeyStr: string): {
64
- message: string;
65
- suggestion: string;
66
- } | null;
67
54
  /** `KeyA` -> `a`, `Digit1`/`Numpad1` -> `1`, `ArrowLeft` -> `arrowleft`. */
68
55
  export function codeToBase(code: any): any;
69
56
  /** `'.'` -> `period`, `'Esc'` -> `escape`, `'K'` -> `k`. */
@@ -30,46 +30,6 @@ export function lookupReservation(combo: object | null, { platform, browser }?:
30
30
  export function severityIsHard(severity: Severity | string): boolean;
31
31
  /** @param {Severity | string} severity @returns {boolean} */
32
32
  export function severityIsSoft(severity: Severity | string): boolean;
33
- /**
34
- * Render a console-friendly warning string for a reservation.
35
- *
36
- * @param {Reservation} reservation
37
- * @param {string} rawHotkey
38
- * @param {{ preventDefault?: boolean }} [bindOptions] the binding's options
39
- * @returns {string}
40
- */
41
- export function formatReservationWarning(reservation: Reservation, rawHotkey: string, bindOptions?: {
42
- preventDefault?: boolean;
43
- }): string;
44
- /**
45
- * Emit a reservation warning via the given console (or the global `console`
46
- * by default). Hard reservations log via `warn`; soft ones via `info`, except
47
- * a preventable key bound without `preventDefault`, where the browser's
48
- * action runs too: that logs via `warn`.
49
- *
50
- * @param {Reservation} reservation
51
- * @param {string} rawHotkey
52
- * @param {Console} [console_]
53
- * @param {{ preventDefault?: boolean }} [bindOptions] the binding's options
54
- * @returns {void}
55
- */
56
- export function emitReservationWarning(reservation: Reservation, rawHotkey: string, console_?: Console, bindOptions?: {
57
- preventDefault?: boolean;
58
- }): void;
59
- /**
60
- * @param {object} hotkeys a hotkey-router default-export instance
61
- * @param {{
62
- * platform?: Platform,
63
- * browser?: Browser,
64
- * console?: Console
65
- * }} [opts]
66
- * @returns {() => void} uninstall function
67
- */
68
- export function installReservationWarnings(hotkeys: object, opts?: {
69
- platform?: Platform;
70
- browser?: Browser;
71
- console?: Console;
72
- }): () => void;
73
33
  export const lookupKeyFromCombo: typeof lookupKey;
74
34
  export const SCHEMA_VERSION: any;
75
35
  export const DATA_GENERATED: any;
@@ -91,16 +51,16 @@ import { detectPlatform } from './platform.js';
91
51
  import { detectBrowser } from './platform.js';
92
52
  import { lookupKey } from './parse.js';
93
53
  /**
94
- * The bundled table as loaded from data/browser-hotkeys.json.
54
+ * Runtime reservation data. The production build bundles the schema, date,
55
+ * shortcut rows and table references from data/browser-hotkeys.json.
95
56
  *
96
- * @type {{ version: { schema: string, generated: string, sources: string[] }, platforms: Record<string, object> } & Record<string, any>}
57
+ * @type {{ version: { schema: string, generated: string }, platforms: Record<string, object> }}
97
58
  */
98
59
  declare const BUNDLED_DATA: {
99
60
  version: {
100
61
  schema: string;
101
62
  generated: string;
102
- sources: string[];
103
63
  };
104
64
  platforms: Record<string, object>;
105
- } & Record<string, any>;
65
+ };
106
66
  export { detectPlatform, detectBrowser, BUNDLED_DATA as HOTKEY_DATA };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * For a key-based combo with Shift and one of `, . / ; ' [ ] \ - = \``, the
3
+ * message explaining it never fires on US layouts and the `code:` spelling
4
+ * to bind instead (written the way the input was). Null for anything else,
5
+ * including strings that do not parse.
6
+ *
7
+ * @param {string} hotkeyStr
8
+ * @param {Pick<ReturnType<typeof readHotkey>, 'combo' | 'type'> & { error?: string | null }} [parsed]
9
+ * @returns {{ message: string, suggestion: string } | null}
10
+ */
11
+ export function shiftedPunctuationHint(hotkeyStr: string, { combo, type, error }?: Pick<ReturnType<typeof readHotkey>, "combo" | "type"> & {
12
+ error?: string | null;
13
+ }): {
14
+ message: string;
15
+ suggestion: string;
16
+ } | null;
17
+ import { readHotkey } from './parse.js';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Programmatically fire the binding a real keypress of `hotkeyStr` would
3
+ * fire. Used by tests and automation; not a typical app-runtime path. The
4
+ * synthetic event carries both `key` and `code` (US layout), so key-based
5
+ * and `code:` bindings both match, and the same guards apply as for a real
6
+ * event: `when`, `ignoreInput`/`allowIn` (pass `target` to fire "from" an
7
+ * element), priority, `once`, and `pause()`. Returns `true` if a handler ran.
8
+ *
9
+ * @param {Pick<import('./core.js').Router, 'dispatch'>} router
10
+ * @param {string} hotkeyStr
11
+ * @param {{ type?: 'keydown' | 'keyup', target?: EventTarget | null }} [opts]
12
+ * @returns {boolean}
13
+ */
14
+ export function trigger(router: Pick<import("./core.js").Router, "dispatch">, hotkeyStr: string, { type: forcedType, target }?: {
15
+ type?: "keydown" | "keyup";
16
+ target?: EventTarget | null;
17
+ }): boolean;
package/dist/validate.js CHANGED
@@ -1,210 +1,13 @@
1
- // hotkey-router v0.5.2 | SEE LICENSE IN LICENSE
1
+ // hotkey-router v0.6.0 | SEE LICENSE IN LICENSE
2
2
 
3
3
 
4
- // lookup.js
5
- function ownValue(table, key) {
6
- return table != null && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : void 0;
7
- }
8
-
9
4
  // validate.js
5
+ import { ownValue } from "./lookup.js";
10
6
  import { lookupReservation, severityIsHard } from "./reservations.js";
11
7
  import { parseComboString, listSites } from "./sites.js";
12
8
  import { modifierLabel, listModifiers, platformLabel, browserLabel } from "./format.js";
13
-
14
- // platform.js
15
- function fromPlatformString(s) {
16
- if (!s) return null;
17
- if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
18
- if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
19
- if (/Win/i.test(s)) return "windows";
20
- if (/Linux|X11/i.test(s)) return "linux";
21
- return null;
22
- }
23
- function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
24
- if (!nav) return null;
25
- const ua = nav.userAgent || "";
26
- 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);
27
- if (found === "chromeos" && !chromeos) return "linux";
28
- return found;
29
- }
30
-
31
- // parse.js
32
- var DEFAULT_PLATFORM = detectPlatform();
33
- var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
34
- var ahkPrefixMap = /* @__PURE__ */ new Map([
35
- ["^", "ctrl"],
36
- // Ctrl
37
- ["!", "alt"],
38
- // Alt
39
- ["+", "shift"],
40
- // Shift
41
- ["#", "meta"]
42
- // Win / Command
43
- ]);
44
- var keyAliases = Object.freeze({
45
- // common
46
- esc: "escape",
47
- escape: "escape",
48
- space: " ",
49
- spacebar: " ",
50
- enter: "enter",
51
- return: "enter",
52
- del: "delete",
53
- delete: "delete",
54
- backspace: "backspace",
55
- tab: "tab",
56
- // arrows
57
- up: "arrowup",
58
- down: "arrowdown",
59
- left: "arrowleft",
60
- right: "arrowright",
61
- // navigation
62
- home: "home",
63
- end: "end",
64
- pageup: "pageup",
65
- pagedown: "pagedown",
66
- pgup: "pageup",
67
- pgdn: "pagedown",
68
- // modifiers (words)
69
- cmd: "meta",
70
- command: "meta",
71
- win: "meta",
72
- meta: "meta",
73
- control: "ctrl",
74
- ctrl: "ctrl",
75
- option: "alt",
76
- opt: "alt",
77
- alt: "alt",
78
- shift: "shift",
79
- // modifiers (symbols)
80
- "\u2318": "meta",
81
- "\u2303": "ctrl",
82
- "\u2325": "alt",
83
- "\u21E7": "shift",
84
- // cross-platform "mod", resolved per platform while parsing
85
- mod: "mod",
86
- // plus key ergonomics
87
- plus: "+"
88
- });
89
- function normalizeKey(key) {
90
- const original = String(key ?? "");
91
- if (original === " ") return " ";
92
- const trimmed = original.trim();
93
- const k = trimmed.toLowerCase();
94
- return ownValue(keyAliases, k) ?? k;
95
- }
96
- function isModifierToken(token) {
97
- return modifierTokens.has(normalizeKey(token));
98
- }
99
- var CODE_TOKEN_RE = /(^|\+)\s*code:([A-Za-z][A-Za-z0-9_]*)/;
100
- function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
101
- const raw = String(hotkeyStr || "").trim();
102
- let error = null;
103
- const fail = (msg) => {
104
- error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
105
- };
106
- const isUp = /\s+up$/i.test(raw);
107
- const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
108
- const combo = {
109
- ctrl: false,
110
- shift: false,
111
- alt: false,
112
- meta: false,
113
- key: null,
114
- code: null,
115
- bareModifier: null
116
- };
117
- const setMod = (mod) => {
118
- if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
119
- else combo[mod] = true;
120
- };
121
- let stripped = baseRaw;
122
- while (stripped.length > 1) {
123
- const mod = ahkPrefixMap.get(stripped[0]) ?? null;
124
- if (!mod) break;
125
- setMod(mod);
126
- stripped = stripped.slice(1).trimStart();
127
- }
128
- const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
129
- if (codeMatches && codeMatches.length > 1) {
130
- fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
131
- }
132
- let codeValue = null;
133
- const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
134
- codeValue = val;
135
- return sep + "__code__";
136
- });
137
- const cleanStr = scrubbed.toLowerCase();
138
- const rawParts = cleanStr.split("+").map((p) => p.trim());
139
- const parts = rawParts.filter(Boolean);
140
- const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
141
- if (!impliedPlusKey) {
142
- let seenBase = false;
143
- for (const part of parts) {
144
- if (isModifierToken(part)) {
145
- if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
146
- } else {
147
- seenBase = true;
148
- }
149
- }
150
- }
151
- let bases = 0;
152
- for (const part of parts) {
153
- if (part === "__code__") {
154
- combo.code = codeValue;
155
- bases++;
156
- continue;
157
- }
158
- const actual = ownValue(keyAliases, part) ?? part;
159
- if (modifierTokens.has(actual)) setMod(actual);
160
- else {
161
- combo.key = normalizeKey(actual);
162
- bases++;
163
- }
164
- }
165
- if (bases > 1) fail('use one base key (e.g. "ctrl+k"), or one code: token');
166
- if (!combo.key && !combo.code && (impliedPlusKey || stripped === "+")) combo.key = "+";
167
- if (!combo.key && !combo.code) {
168
- const modCount = (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) + (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0);
169
- if (modCount === 1) {
170
- combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
171
- } else if (modCount > 1) {
172
- fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
173
- } else {
174
- error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
175
- }
176
- }
177
- return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
178
- }
179
- var SHIFTED_PUNCT = {
180
- ",": ["<", "Comma"],
181
- ".": [">", "Period"],
182
- "/": ["?", "Slash"],
183
- ";": [":", "Semicolon"],
184
- "'": ['"', "Quote"],
185
- "[": ["{", "BracketLeft"],
186
- "]": ["}", "BracketRight"],
187
- "\\": ["|", "Backslash"],
188
- "-": ["_", "Minus"],
189
- "=": ["+", "Equal"],
190
- "`": ["~", "Backquote"]
191
- };
192
- for (let d = 0; d < 10; d++) SHIFTED_PUNCT[d] = [")!@#$%^&*("[d], "Digit" + d];
193
- function shiftedPunctuationHint(hotkeyStr) {
194
- const { combo, type, error } = readHotkey(hotkeyStr);
195
- if (error || !combo.shift || combo.code) return null;
196
- const shifted = ownValue(SHIFTED_PUNCT, combo.key);
197
- if (!shifted) return null;
198
- const [typed, code] = shifted;
199
- const base = String(hotkeyStr).trim().replace(/\s+up$/i, "");
200
- const suggestion = base.slice(0, -1) + "code:" + code + (type === "keyup" ? " up" : "");
201
- return {
202
- message: `"${hotkeyStr}" never fires on US layouts: Shift turns "${combo.key}" into "${typed}". Bind "${suggestion}" instead.`,
203
- suggestion
204
- };
205
- }
206
-
207
- // validate.js
9
+ import { readHotkey } from "./parse.js";
10
+ import { shiftedPunctuationHint } from "./shifted-punctuation.js";
208
11
  var ALL_PLATFORMS = ["mac", "windows", "linux"];
209
12
  var ALL_BROWSERS = ["chrome", "firefox", "edge", "safari"];
210
13
  var SITE_COL = { windows: 0, mac: 1, linux: 0 };
@@ -232,11 +35,12 @@ function validateCombo(combo, {
232
35
  if (typeof combo !== "string" || !combo.trim()) {
233
36
  return { ok: false, reasons: [{ code: "invalid", severity: "error", message: "No keys were recorded." }], lookupKeys };
234
37
  }
235
- const { error, combo: read } = readHotkey(combo);
38
+ const parsedCombo = readHotkey(combo);
39
+ const { error, combo: read } = parsedCombo;
236
40
  if (error && (read.key || read.code)) {
237
41
  return { ok: false, reasons: [{ code: "invalid", severity: "error", message: "These keys could not be read.", details: { error } }], lookupKeys };
238
42
  }
239
- const shifted = shiftedPunctuationHint(combo);
43
+ const shifted = shiftedPunctuationHint(combo, parsedCombo);
240
44
  if (shifted) {
241
45
  add({ code: "shifted-punctuation", severity: "error", message: shifted.message, details: { suggestion: shifted.suggestion } });
242
46
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lookup.js", "../validate.js", "../platform.js", "../parse.js"],
4
- "sourcesContent": ["// Read user-keyed tables without treating prototype properties as entries.\r\nexport function ownValue(table, key) {\r\n return table != null && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : undefined\r\n}\r\n", "// validate.js\r\n// Check a hotkey before an app saves it, e.g. from a \"press your keys\"\r\n// recorder. Returns plain-language reasons the app can show as they are.\r\n//\r\n// import { comboFromEvent } from 'hotkey-router'\r\n// import { validateCombo } from 'hotkey-router/validate'\r\n//\r\n// const combo = comboFromEvent(e, { useMod: true }) // 'mod+shift+code:Period'\r\n// const { ok, reasons } = validateCombo(combo, { requirePrimary: true, minModifiers: 2 })\r\n//\r\n// Errors make `ok` false (the combo would not work, or breaks a rule the\r\n// app asked for). Warnings leave `ok` true (it works, with a caveat worth\r\n// telling the user: AltGr on some layouts, sites that use the same keys).\r\n//\r\n// Data: data/browser-hotkeys.json (keys the browser or OS take before the\r\n// page sees them) and data/site-hotkeys.runtime.json (keys popular sites use).\r\n\r\nimport { ownValue } from './lookup.js'\r\nimport { lookupReservation, severityIsHard } from './reservations.js'\r\nimport { parseComboString, listSites } from './sites.js'\r\nimport { modifierLabel, listModifiers, platformLabel, browserLabel } from './format.js'\r\nimport { shiftedPunctuationHint, readHotkey } from './parse.js'\r\n\r\nconst ALL_PLATFORMS = ['mac', 'windows', 'linux']\r\nconst ALL_BROWSERS = ['chrome', 'firefox', 'edge', 'safari']\r\n// Runtime site rows: [windows, mac, chromeos, action, verified]\r\nconst SITE_COL = { windows: 0, mac: 1, linux: 0 }\r\n\r\n/**\r\n * @typedef {{\r\n * code: 'invalid' | 'no-key' | 'no-modifier' | 'alt-only' | 'needs-primary' |\r\n * 'too-few-modifiers' | 'taken' | 'reserved' | 'reserved-soft' |\r\n * 'altgr' | 'site-conflict' | 'shifted-punctuation',\r\n * severity: 'error' | 'warning',\r\n * message: string,\r\n * platforms?: string[],\r\n * details?: object\r\n * }} ComboReason\r\n */\r\n\r\n/**\r\n * @param {string} combo hotkey string, e.g. `mod+shift+code:Period`\r\n * @param {{\r\n * platforms?: Array<'mac' | 'windows' | 'linux'>,\r\n * browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>,\r\n * requirePrimary?: boolean, // must include Ctrl (Cmd on macOS)\r\n * minModifiers?: number, // default 1\r\n * taken?: string[], // combos the app already uses\r\n * sites?: boolean, // warn about sites that use the keys (default true)\r\n * }} [opts]\r\n * @returns {{ ok: boolean, reasons: ComboReason[], lookupKeys: Record<string, string> }}\r\n */\r\nexport function validateCombo(combo, {\r\n platforms = ALL_PLATFORMS,\r\n browsers = ALL_BROWSERS,\r\n requirePrimary = false,\r\n minModifiers = 1,\r\n taken = [],\r\n sites = true,\r\n} = {}) {\r\n /** @type {ComboReason[]} */\r\n const reasons = []\r\n const lookupKeys = {}\r\n const add = (reason) => {\r\n const same = reasons.find((r) => r.code === reason.code && r.message === reason.message)\r\n if (same) {\r\n for (const p of reason.platforms || []) if (!same.platforms?.includes(p)) same.platforms = [...(same.platforms || []), p]\r\n return\r\n }\r\n reasons.push(reason)\r\n }\r\n\r\n // Messages that cover several platforms name the modifiers once: in the\r\n // platform's own words when every platform agrees (all macOS, or none),\r\n // otherwise PC words plus Cmd.\r\n const allMac = platforms.every((p) => p === 'mac')\r\n const noMac = !platforms.includes('mac')\r\n const anyModifier = allMac\r\n ? listModifiers(['meta', 'alt', 'ctrl', 'shift'], { platform: 'mac' })\r\n : noMac\r\n ? listModifiers(['ctrl', 'alt', 'shift'], { platform: 'windows' })\r\n : `${['ctrl', 'alt', 'shift'].map((m) => modifierLabel(m, { platform: 'windows' })).join(', ')} or ${modifierLabel('meta', { platform: 'mac' })}`\r\n\r\n if (typeof combo !== 'string' || !combo.trim()) {\r\n return { ok: false, reasons: [{ code: 'invalid', severity: 'error', message: 'No keys were recorded.' }], lookupKeys }\r\n }\r\n\r\n // A string the router would refuse (`k+ctrl`, two base keys) can't be\r\n // bound, whatever else is true of it. The parser's message says why.\r\n // Modifiers with no key fall through to the friendlier 'no-key'.\r\n const { error, combo: read } = readHotkey(combo)\r\n if (error && (read.key || read.code)) {\r\n return { ok: false, reasons: [{ code: 'invalid', severity: 'error', message: 'These keys could not be read.', details: { error } }], lookupKeys }\r\n }\r\n\r\n // Same on every platform: Shift changes `event.key`, so the combo never matches.\r\n const shifted = shiftedPunctuationHint(combo)\r\n if (shifted) {\r\n add({ code: 'shifted-punctuation', severity: 'error', message: shifted.message, details: { suggestion: shifted.suggestion } })\r\n }\r\n\r\n for (const platform of platforms) {\r\n let parsed\r\n try {\r\n parsed = parseComboString(combo, platform)\r\n } catch {\r\n parsed = null\r\n }\r\n if (!parsed) {\r\n add({ code: 'invalid', severity: 'error', message: 'These keys could not be read.', platforms: [platform] })\r\n continue\r\n }\r\n if (!parsed.base) {\r\n add({ code: 'no-key', severity: 'error', message: 'Add a key to the modifiers, for example a letter or punctuation key.', platforms: [platform] })\r\n continue\r\n }\r\n const mods = ['ctrl', 'meta', 'alt', 'shift'].filter((m) => parsed[m])\r\n const key = [...mods, parsed.base].join('+')\r\n lookupKeys[platform] = key\r\n\r\n if (mods.length === 0) {\r\n add({ code: 'no-modifier', severity: 'error', message: `Use at least one modifier (${anyModifier}), or the key would fire while typing.`, platforms: [platform] })\r\n }\r\n if (platform !== 'mac' && mods.length === 1 && parsed.alt) {\r\n add({ code: 'alt-only', severity: 'error', message: `${modifierLabel('alt', { platform })} on its own moves focus to the browser menu when released. Add ${listModifiers(['ctrl', 'shift'], { platform })}.`, platforms: [platform] })\r\n }\r\n const primary = platform === 'mac' ? parsed.meta : parsed.ctrl\r\n if (requirePrimary && !primary) {\r\n add({ code: 'needs-primary', severity: 'error', message: `Include ${modifierLabel('mod', { platform })}.`, platforms: [platform] })\r\n }\r\n if (mods.length > 0 && mods.length < minModifiers) {\r\n add({ code: 'too-few-modifiers', severity: 'error', message: `Use at least ${minModifiers} modifiers together.`, platforms: [platform] })\r\n }\r\n\r\n for (const other of taken) {\r\n let otherKey = null\r\n try {\r\n const o = parseComboString(other, platform)\r\n if (o?.base) otherKey = [...['ctrl', 'meta', 'alt', 'shift'].filter((m) => o[m]), o.base].join('+')\r\n } catch { /* ignore unreadable entries */ }\r\n if (otherKey === key) {\r\n add({ code: 'taken', severity: 'error', message: 'These keys are already used for something else here.', platforms: [platform], details: { combo: other } })\r\n }\r\n }\r\n\r\n const shape = { ctrl: parsed.ctrl, meta: parsed.meta, alt: parsed.alt, shift: parsed.shift, key: parsed.base, code: null, bareModifier: null }\r\n for (const browser of browsers) {\r\n if (platform !== 'mac' && browser === 'safari') continue\r\n const hit = lookupReservation(shape, { platform, browser })\r\n if (!hit) continue\r\n const where = hit.source === 'system' ? platformLabel(platform) : `${browserLabel(browser)} on ${platformLabel(platform)}`\r\n if (severityIsHard(hit.severity)) {\r\n add({ code: 'reserved', severity: 'error', message: `${where} uses these keys (${hit.action}), so a page never sees them.`, platforms: [platform], details: { browser, action: hit.action } })\r\n } else {\r\n add({ code: 'reserved-soft', severity: 'warning', message: hit.severity === 'preventable' ? `${where} uses these keys (${hit.action}) unless the page calls preventDefault, which a binding does with preventDefault: true.` : `${where} uses these keys in some situations (${hit.action}).`, platforms: [platform], details: { browser, action: hit.action, severity: hit.severity } })\r\n }\r\n }\r\n\r\n if (platform === 'windows' && parsed.ctrl && parsed.alt && !parsed.meta) {\r\n add({ code: 'altgr', severity: 'warning', message: `On some keyboard layouts ${modifierLabel('ctrl', { platform })}+${modifierLabel('alt', { platform })} acts as AltGr and types characters; those keystrokes are skipped.`, platforms: [platform] })\r\n }\r\n\r\n if (sites) {\r\n const col = ownValue(SITE_COL, platform)\r\n const names = []\r\n for (const site of listSites()) {\r\n if (site.shortcuts.some((row) => row[col] === key)) names.push(site.name)\r\n }\r\n if (names.length) {\r\n add({ code: 'site-conflict', severity: 'warning', message: `Also used by ${names.join(', ')}.`, platforms: [platform], details: { sites: names } })\r\n }\r\n }\r\n }\r\n\r\n return { ok: !reasons.some((r) => r.severity === 'error'), reasons, lookupKeys }\r\n}\r\n", "// 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", "// parse.js\r\n// The one hotkey-string parser. The core router binds with it; sites,\r\n// validate and format read combos with it, so `opt`, `ctrl++`, `^k` and\r\n// `mod` mean the same thing everywhere. No state, no side effects.\r\n\r\nimport { ownValue } from './lookup.js'\r\nimport { detectPlatform } from './platform.js'\r\n\r\n// `mod` is the platform's primary modifier: meta on macOS, ctrl elsewhere.\r\nconst DEFAULT_PLATFORM = detectPlatform()\r\n\r\nconst modifierTokens = new Set(['ctrl', 'shift', 'alt', 'meta', 'mod'])\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\nexport const 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 opt: '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\", resolved per platform while parsing\r\n mod: 'mod',\r\n\r\n // plus key ergonomics\r\n plus: '+',\r\n})\r\n\r\nexport function normalizeKey(key) {\r\n const original = String(key ?? '')\r\n // A lone space IS the spacebar key \u2014 `.trim()` would erase it to '', so guard\r\n // on the ORIGINAL before trimming. (The `space`/`spacebar` aliases resolve to\r\n // ' ' and land here; without this, `space` bindings collapse to no base key.)\r\n if (original === ' ') return ' '\r\n const trimmed = original.trim()\r\n const k = trimmed.toLowerCase()\r\n return ownValue(keyAliases, k) ?? k\r\n}\r\n\r\nfunction isModifierToken(token) {\r\n return modifierTokens.has(normalizeKey(token))\r\n}\r\n\r\n// Matches `code:KeyX` (case-sensitive value). Used to extract code tokens BEFORE\r\n// the rest of the parser lowercases everything, since KeyboardEvent.code values\r\n// are camelCase (KeyA, Digit1, ArrowLeft) and must be preserved.\r\nconst CODE_TOKEN_RE = /(^|\\+)\\s*code:([A-Za-z][A-Za-z0-9_]*)/\r\n\r\n/**\r\n * Lenient parse: never throws. `error` holds the message `parseHotkey` would\r\n * throw; the combo is filled in as far as the string allows.\r\n *\r\n * @param {string} hotkeyStr\r\n * @param {{ platform?: string | null }} [opts]\r\n */\r\nexport function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {\r\n const raw = String(hotkeyStr || '').trim()\r\n let error = null\r\n const fail = (msg) => { error = error || `Invalid hotkey \"${hotkeyStr}\": ${msg}` }\r\n\r\n // Detect ' up' suffix case-insensitively so 'Alt UP' works the same as 'alt up'.\r\n const isUp = /\\s+up$/i.test(raw)\r\n const baseRaw = isUp ? raw.replace(/\\s+up$/i, '').trim() : raw\r\n\r\n const combo = {\r\n ctrl: false, shift: false, alt: false, meta: false,\r\n key: null, code: null, bareModifier: null,\r\n }\r\n const setMod = (mod) => {\r\n if (mod === 'mod') combo[platform === 'mac' ? 'meta' : 'ctrl'] = true\r\n else combo[mod] = true\r\n }\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 // !code:KeyX => alt+code:KeyX\r\n //\r\n // We strip these BEFORE both the code-token extraction AND the lowercase\r\n // pass, because the AHK prefix chars (^ ! + #) are case-stable, and the\r\n // remainder may contain a case-sensitive `code:KeyX` token that must survive.\r\n // A lone prefix character is the key itself: '+', '#', '!' and '^' bind\r\n // that character, and '^+' is Ctrl with '+'.\r\n let stripped = baseRaw\r\n while (stripped.length > 1) {\r\n const mod = ahkPrefixMap.get(stripped[0]) ?? null\r\n if (!mod) break\r\n setMod(mod)\r\n stripped = stripped.slice(1).trimStart()\r\n }\r\n\r\n // Pull out a code:XXX token before lowercasing; preserve the camelCase value.\r\n // Reject multiple code: tokens to avoid silent loss of intent.\r\n const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g)\r\n if (codeMatches && codeMatches.length > 1) {\r\n fail(`multiple code: tokens not supported (got ${codeMatches.length}).`)\r\n }\r\n let codeValue = null\r\n const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {\r\n codeValue = val\r\n return sep + '__code__'\r\n })\r\n\r\n const cleanStr = scrubbed.toLowerCase()\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) fail('modifiers must come before the base key (e.g. \"ctrl+k\", not \"k+ctrl\")')\r\n } else {\r\n seenBase = true\r\n }\r\n }\r\n }\r\n\r\n // Continue parsing the remaining tokens (words/symbols/aliases)\r\n // One base key: 'ctrl+a+b' or 'ctrl+k+code:KeyA' would otherwise keep\r\n // only one of them without saying so.\r\n let bases = 0\r\n for (const part of parts) {\r\n if (part === '__code__') {\r\n combo.code = codeValue\r\n bases++\r\n continue\r\n }\r\n const actual = ownValue(keyAliases, part) ?? part\r\n if (modifierTokens.has(actual)) setMod(actual)\r\n else {\r\n combo.key = normalizeKey(actual)\r\n bases++\r\n }\r\n }\r\n if (bases > 1) fail('use one base key (e.g. \"ctrl+k\"), or one code: token')\r\n\r\n if (!combo.key && !combo.code && (impliedPlusKey || stripped === '+')) combo.key = '+'\r\n\r\n // If no base key/code is set, this might be a bare-modifier binding ('alt' / 'ctrl').\r\n // Allow exactly ONE modifier with no other tokens. Multi-modifier bare bindings\r\n // (e.g. 'ctrl+alt') are intentionally rejected \u2014 add a base key for those.\r\n if (!combo.key && !combo.code) {\r\n const modCount =\r\n (combo.ctrl ? 1 : 0) + (combo.shift ? 1 : 0) +\r\n (combo.alt ? 1 : 0) + (combo.meta ? 1 : 0)\r\n\r\n if (modCount === 1) {\r\n combo.bareModifier =\r\n combo.ctrl ? 'ctrl' :\r\n combo.shift ? 'shift' :\r\n combo.alt ? 'alt' : 'meta'\r\n } else if (modCount > 1) {\r\n fail('multi-modifier bare bindings not supported. Add a base key (e.g. \"ctrl+alt+x\").')\r\n } else {\r\n error = error || `Invalid hotkey \"${hotkeyStr}\" (missing base key)`\r\n }\r\n }\r\n\r\n return { combo, type: isUp ? 'keyup' : 'keydown', raw: hotkeyStr, error }\r\n}\r\n\r\n/**\r\n * Parse a hotkey string into modifier flags plus a `key` (normalized\r\n * `KeyboardEvent.key`), a `code` (`KeyboardEvent.code`) or a bare modifier.\r\n * `mod` resolves for `opts.platform` (default: this machine). Throws on\r\n * strings the router can't bind.\r\n *\r\n * @param {string} hotkeyStr\r\n * @param {{ platform?: 'mac' | 'windows' | 'linux' | 'chromeos' | null }} [opts]\r\n * @returns {{\r\n * combo: { ctrl: boolean, shift: boolean, alt: boolean, meta: boolean, key: string | null, code: string | null, bareModifier: 'ctrl' | 'shift' | 'alt' | 'meta' | null },\r\n * type: 'keydown' | 'keyup',\r\n * raw: string\r\n * }}\r\n */\r\nexport function parseHotkey(hotkeyStr, opts) {\r\n const { combo, type, raw, error } = readHotkey(hotkeyStr, opts)\r\n if (error) throw new Error(error)\r\n return { combo, type, raw }\r\n}\r\n\r\n// --- shifted punctuation -----------------------------------------------------\r\n\r\n// Punctuation whose Shift character differs on a US layout. With Shift held,\r\n// `event.key` is the shifted character, so a key-based `ctrl+shift+,` waits\r\n// for a ',' that never arrives (the event says '<').\r\nconst SHIFTED_PUNCT = {\r\n ',': ['<', 'Comma'], '.': ['>', 'Period'], '/': ['?', 'Slash'],\r\n ';': [':', 'Semicolon'], \"'\": ['\"', 'Quote'], '[': ['{', 'BracketLeft'],\r\n ']': ['}', 'BracketRight'], '\\\\': ['|', 'Backslash'], '-': ['_', 'Minus'],\r\n '=': ['+', 'Equal'], '`': ['~', 'Backquote'],\r\n}\r\n// Digits too: Shift+1 types '!' on US layouts.\r\nfor (let d = 0; d < 10; d++) SHIFTED_PUNCT[d] = [')!@#$%^&*('[d], 'Digit' + d]\r\n\r\n/**\r\n * For a key-based combo with Shift and one of `, . / ; ' [ ] \\ - = \\``, the\r\n * message explaining it never fires on US layouts and the `code:` spelling\r\n * to bind instead (written the way the input was). Null for anything else,\r\n * including strings that do not parse.\r\n *\r\n * @param {string} hotkeyStr\r\n * @returns {{ message: string, suggestion: string } | null}\r\n */\r\nexport function shiftedPunctuationHint(hotkeyStr) {\r\n const { combo, type, error } = readHotkey(hotkeyStr)\r\n if (error || !combo.shift || combo.code) return null\r\n const shifted = ownValue(SHIFTED_PUNCT, combo.key)\r\n if (!shifted) return null\r\n const [typed, code] = shifted\r\n\r\n // The base key is the last character before any ' up'; swap just that.\r\n const base = String(hotkeyStr).trim().replace(/\\s+up$/i, '')\r\n const suggestion = base.slice(0, -1) + 'code:' + code + (type === 'keyup' ? ' up' : '')\r\n return {\r\n message: `\"${hotkeyStr}\" never fires on US layouts: Shift turns \"${combo.key}\" into \"${typed}\". Bind \"${suggestion}\" instead.`,\r\n suggestion,\r\n }\r\n}\r\n\r\n// --- canonical lookup names (reservation + site tables) ----------------------\r\n\r\n// Punctuation typed as `event.key` maps to the names the data tables use for\r\n// `code:` values, so `meta+shift+/` and `meta+shift+code:Slash` find the same\r\n// row. `+` is Shift+= on most layouts, and browsers treat Ctrl++ as Ctrl+=\r\n// (zoom in), so it looks up as `equal`.\r\nconst PUNCT_NAMES = {\r\n '.': 'period', ',': 'comma', ';': 'semicolon', \"'\": 'quote', '/': 'slash',\r\n '\\\\': 'backslash', '[': 'bracketleft', ']': 'bracketright', '-': 'minus',\r\n '=': 'equal', '`': 'backquote', ' ': 'space', '+': 'equal',\r\n}\r\n\r\n/** `KeyA` -> `a`, `Digit1`/`Numpad1` -> `1`, `ArrowLeft` -> `arrowleft`. */\r\nexport function codeToBase(code) {\r\n if (!code) return null\r\n const letter = /^Key([A-Za-z])$/.exec(code)\r\n if (letter) return letter[1].toLowerCase()\r\n const digit = /^(?:Digit|Numpad)(\\d)$/.exec(code)\r\n if (digit) return digit[1]\r\n return code.toLowerCase()\r\n}\r\n\r\n/** `'.'` -> `period`, `'Esc'` -> `escape`, `'K'` -> `k`. */\r\nexport function keyToBase(key) {\r\n if (key == null || key === '') return null\r\n if (ownValue(PUNCT_NAMES, key)) return ownValue(PUNCT_NAMES, key)\r\n const k = normalizeKey(key)\r\n return ownValue(PUNCT_NAMES, k) || k || null\r\n}\r\n\r\n/**\r\n * The canonical lookup key for a parsed combo: modifiers in the order ctrl,\r\n * meta, alt, shift, then the base name (`ctrl+shift+period`). Null for a bare\r\n * modifier or no key.\r\n *\r\n * @param {{ ctrl?: boolean, meta?: boolean, alt?: boolean, shift?: boolean, key?: string | null, code?: string | null, bareModifier?: string | null } | null} combo\r\n * @returns {string | null}\r\n */\r\nexport function lookupKey(combo) {\r\n if (!combo || combo.bareModifier) return null\r\n const base = combo.code ? codeToBase(combo.code) : keyToBase(combo.key)\r\n if (!base) return null\r\n const parts = []\r\n if (combo.ctrl) parts.push('ctrl')\r\n if (combo.meta) parts.push('meta')\r\n if (combo.alt) parts.push('alt')\r\n if (combo.shift) parts.push('shift')\r\n parts.push(base)\r\n return parts.join('+')\r\n}\r\n"],
5
- "mappings": ";;;;AACO,SAAS,SAAS,OAAO,KAAK;AACnC,SAAO,SAAS,QAAQ,OAAO,UAAU,eAAe,KAAK,OAAO,GAAG,IAAI,MAAM,GAAG,IAAI;AAC1F;;;ACeA,SAAS,mBAAmB,sBAAsB;AAClD,SAAS,kBAAkB,iBAAiB;AAC5C,SAAS,eAAe,eAAe,eAAe,oBAAoB;;;ACN1E,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,I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E,IAAI,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE,aAAa,OAAO,GAAG,SAAS,WAAW;AACjF;",
3
+ "sources": ["../validate.js"],
4
+ "sourcesContent": ["// validate.js\r\n// Check a hotkey before an app saves it, e.g. from a \"press your keys\"\r\n// recorder. Returns plain-language reasons the app can show as they are.\r\n//\r\n// import { comboFromEvent } from 'hotkey-router'\r\n// import { validateCombo } from 'hotkey-router/validate'\r\n//\r\n// const combo = comboFromEvent(e, { useMod: true }) // 'mod+shift+code:Period'\r\n// const { ok, reasons } = validateCombo(combo, { requirePrimary: true, minModifiers: 2 })\r\n//\r\n// Errors make `ok` false (the combo would not work, or breaks a rule the\r\n// app asked for). Warnings leave `ok` true (it works, with a caveat worth\r\n// telling the user: AltGr on some layouts, sites that use the same keys).\r\n//\r\n// Data: data/browser-hotkeys.json (keys the browser or OS take before the\r\n// page sees them) and data/site-hotkeys.runtime.json (keys popular sites use).\r\n\r\nimport { ownValue } from './lookup.js'\r\nimport { lookupReservation, severityIsHard } from './reservations.js'\r\nimport { parseComboString, listSites } from './sites.js'\r\nimport { modifierLabel, listModifiers, platformLabel, browserLabel } from './format.js'\r\nimport { readHotkey } from './parse.js'\r\nimport { shiftedPunctuationHint } from './shifted-punctuation.js'\r\n\r\nconst ALL_PLATFORMS = ['mac', 'windows', 'linux']\r\nconst ALL_BROWSERS = ['chrome', 'firefox', 'edge', 'safari']\r\n// Runtime site rows: [windows, mac, chromeos, action, verified]\r\nconst SITE_COL = { windows: 0, mac: 1, linux: 0 }\r\n\r\n/**\r\n * @typedef {{\r\n * code: 'invalid' | 'no-key' | 'no-modifier' | 'alt-only' | 'needs-primary' |\r\n * 'too-few-modifiers' | 'taken' | 'reserved' | 'reserved-soft' |\r\n * 'altgr' | 'site-conflict' | 'shifted-punctuation',\r\n * severity: 'error' | 'warning',\r\n * message: string,\r\n * platforms?: string[],\r\n * details?: object\r\n * }} ComboReason\r\n */\r\n\r\n/**\r\n * @param {string} combo hotkey string, e.g. `mod+shift+code:Period`\r\n * @param {{\r\n * platforms?: Array<'mac' | 'windows' | 'linux'>,\r\n * browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>,\r\n * requirePrimary?: boolean, // must include Ctrl (Cmd on macOS)\r\n * minModifiers?: number, // default 1\r\n * taken?: string[], // combos the app already uses\r\n * sites?: boolean, // warn about sites that use the keys (default true)\r\n * }} [opts]\r\n * @returns {{ ok: boolean, reasons: ComboReason[], lookupKeys: Record<string, string> }}\r\n */\r\nexport function validateCombo(combo, {\r\n platforms = ALL_PLATFORMS,\r\n browsers = ALL_BROWSERS,\r\n requirePrimary = false,\r\n minModifiers = 1,\r\n taken = [],\r\n sites = true,\r\n} = {}) {\r\n /** @type {ComboReason[]} */\r\n const reasons = []\r\n const lookupKeys = {}\r\n const add = (reason) => {\r\n const same = reasons.find((r) => r.code === reason.code && r.message === reason.message)\r\n if (same) {\r\n for (const p of reason.platforms || []) if (!same.platforms?.includes(p)) same.platforms = [...(same.platforms || []), p]\r\n return\r\n }\r\n reasons.push(reason)\r\n }\r\n\r\n // Messages that cover several platforms name the modifiers once: in the\r\n // platform's own words when every platform agrees (all macOS, or none),\r\n // otherwise PC words plus Cmd.\r\n const allMac = platforms.every((p) => p === 'mac')\r\n const noMac = !platforms.includes('mac')\r\n const anyModifier = allMac\r\n ? listModifiers(['meta', 'alt', 'ctrl', 'shift'], { platform: 'mac' })\r\n : noMac\r\n ? listModifiers(['ctrl', 'alt', 'shift'], { platform: 'windows' })\r\n : `${['ctrl', 'alt', 'shift'].map((m) => modifierLabel(m, { platform: 'windows' })).join(', ')} or ${modifierLabel('meta', { platform: 'mac' })}`\r\n\r\n if (typeof combo !== 'string' || !combo.trim()) {\r\n return { ok: false, reasons: [{ code: 'invalid', severity: 'error', message: 'No keys were recorded.' }], lookupKeys }\r\n }\r\n\r\n // A string the router would refuse (`k+ctrl`, two base keys) can't be\r\n // bound, whatever else is true of it. The parser's message says why.\r\n // Modifiers with no key fall through to the friendlier 'no-key'.\r\n const parsedCombo = readHotkey(combo)\r\n const { error, combo: read } = parsedCombo\r\n if (error && (read.key || read.code)) {\r\n return { ok: false, reasons: [{ code: 'invalid', severity: 'error', message: 'These keys could not be read.', details: { error } }], lookupKeys }\r\n }\r\n\r\n // Same on every platform: Shift changes `event.key`, so the combo never matches.\r\n const shifted = shiftedPunctuationHint(combo, parsedCombo)\r\n if (shifted) {\r\n add({ code: 'shifted-punctuation', severity: 'error', message: shifted.message, details: { suggestion: shifted.suggestion } })\r\n }\r\n\r\n for (const platform of platforms) {\r\n let parsed\r\n try {\r\n parsed = parseComboString(combo, platform)\r\n } catch {\r\n parsed = null\r\n }\r\n if (!parsed) {\r\n add({ code: 'invalid', severity: 'error', message: 'These keys could not be read.', platforms: [platform] })\r\n continue\r\n }\r\n if (!parsed.base) {\r\n add({ code: 'no-key', severity: 'error', message: 'Add a key to the modifiers, for example a letter or punctuation key.', platforms: [platform] })\r\n continue\r\n }\r\n const mods = ['ctrl', 'meta', 'alt', 'shift'].filter((m) => parsed[m])\r\n const key = [...mods, parsed.base].join('+')\r\n lookupKeys[platform] = key\r\n\r\n if (mods.length === 0) {\r\n add({ code: 'no-modifier', severity: 'error', message: `Use at least one modifier (${anyModifier}), or the key would fire while typing.`, platforms: [platform] })\r\n }\r\n if (platform !== 'mac' && mods.length === 1 && parsed.alt) {\r\n add({ code: 'alt-only', severity: 'error', message: `${modifierLabel('alt', { platform })} on its own moves focus to the browser menu when released. Add ${listModifiers(['ctrl', 'shift'], { platform })}.`, platforms: [platform] })\r\n }\r\n const primary = platform === 'mac' ? parsed.meta : parsed.ctrl\r\n if (requirePrimary && !primary) {\r\n add({ code: 'needs-primary', severity: 'error', message: `Include ${modifierLabel('mod', { platform })}.`, platforms: [platform] })\r\n }\r\n if (mods.length > 0 && mods.length < minModifiers) {\r\n add({ code: 'too-few-modifiers', severity: 'error', message: `Use at least ${minModifiers} modifiers together.`, platforms: [platform] })\r\n }\r\n\r\n for (const other of taken) {\r\n let otherKey = null\r\n try {\r\n const o = parseComboString(other, platform)\r\n if (o?.base) otherKey = [...['ctrl', 'meta', 'alt', 'shift'].filter((m) => o[m]), o.base].join('+')\r\n } catch { /* ignore unreadable entries */ }\r\n if (otherKey === key) {\r\n add({ code: 'taken', severity: 'error', message: 'These keys are already used for something else here.', platforms: [platform], details: { combo: other } })\r\n }\r\n }\r\n\r\n const shape = { ctrl: parsed.ctrl, meta: parsed.meta, alt: parsed.alt, shift: parsed.shift, key: parsed.base, code: null, bareModifier: null }\r\n for (const browser of browsers) {\r\n if (platform !== 'mac' && browser === 'safari') continue\r\n const hit = lookupReservation(shape, { platform, browser })\r\n if (!hit) continue\r\n const where = hit.source === 'system' ? platformLabel(platform) : `${browserLabel(browser)} on ${platformLabel(platform)}`\r\n if (severityIsHard(hit.severity)) {\r\n add({ code: 'reserved', severity: 'error', message: `${where} uses these keys (${hit.action}), so a page never sees them.`, platforms: [platform], details: { browser, action: hit.action } })\r\n } else {\r\n add({ code: 'reserved-soft', severity: 'warning', message: hit.severity === 'preventable' ? `${where} uses these keys (${hit.action}) unless the page calls preventDefault, which a binding does with preventDefault: true.` : `${where} uses these keys in some situations (${hit.action}).`, platforms: [platform], details: { browser, action: hit.action, severity: hit.severity } })\r\n }\r\n }\r\n\r\n if (platform === 'windows' && parsed.ctrl && parsed.alt && !parsed.meta) {\r\n add({ code: 'altgr', severity: 'warning', message: `On some keyboard layouts ${modifierLabel('ctrl', { platform })}+${modifierLabel('alt', { platform })} acts as AltGr and types characters; those keystrokes are skipped.`, platforms: [platform] })\r\n }\r\n\r\n if (sites) {\r\n const col = ownValue(SITE_COL, platform)\r\n const names = []\r\n for (const site of listSites()) {\r\n if (site.shortcuts.some((row) => row[col] === key)) names.push(site.name)\r\n }\r\n if (names.length) {\r\n add({ code: 'site-conflict', severity: 'warning', message: `Also used by ${names.join(', ')}.`, platforms: [platform], details: { sites: names } })\r\n }\r\n }\r\n }\r\n\r\n return { ok: !reasons.some((r) => r.severity === 'error'), reasons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SAAS,UAAU,QAAQ;AACvC,YAAM,QAAQ,CAAC;AACf,iBAAW,QAAQ,UAAU,GAAG;AAC9B,YAAI,KAAK,UAAU,KAAK,CAAC,QAAQ,IAAI,GAAG,MAAM,GAAG,EAAG,OAAM,KAAK,KAAK,IAAI;AAAA,MAC1E;AACA,UAAI,MAAM,QAAQ;AAChB,YAAI,EAAE,MAAM,iBAAiB,UAAU,WAAW,SAAS,gBAAgB,MAAM,KAAK,IAAI,CAAC,KAAK,WAAW,CAAC,QAAQ,GAAG,SAAS,EAAE,OAAO,MAAM,EAAE,CAAC;AAAA,MACpJ;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,IAAI,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE,aAAa,OAAO,GAAG,SAAS,WAAW;AACjF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hotkey-router",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "A tiny, deterministic keyboard routing engine for modern web apps.",
5
5
  "type": "module",
6
6
  "author": "WATT3D <WATT3D@protonmail.com>",
@@ -45,6 +45,14 @@
45
45
  "types": "./dist/types/format.d.ts",
46
46
  "import": "./dist/format.js"
47
47
  },
48
+ "./testing": {
49
+ "types": "./dist/types/testing.d.ts",
50
+ "import": "./dist/testing.js"
51
+ },
52
+ "./dev": {
53
+ "types": "./dist/types/dev.d.ts",
54
+ "import": "./dist/dev.js"
55
+ },
48
56
  "./data/browser-hotkeys.json": "./data/browser-hotkeys.json",
49
57
  "./data/site-hotkeys.json": "./data/site-hotkeys.json",
50
58
  "./data/site-hotkeys.runtime.json": "./data/site-hotkeys.runtime.json"