hotkey-router 0.3.2 → 0.3.3
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 +55 -4
- package/dist/auto.js +5 -1101
- package/dist/auto.js.map +4 -4
- package/dist/auto.min.js +2 -2
- package/dist/format.js +1 -1
- package/dist/format.js.map +1 -1
- package/dist/hotkey-router.cjs +86 -22
- package/dist/hotkey-router.cjs.map +2 -2
- package/dist/hotkey-router.js +86 -22
- package/dist/hotkey-router.js.map +2 -2
- package/dist/hotkey-router.min.js +2 -2
- package/dist/reservations.js +1 -1
- package/dist/reservations.js.map +2 -2
- package/dist/sites.js +1 -1
- package/dist/sites.js.map +2 -2
- package/dist/types/parse.d.ts +13 -0
- package/dist/types/validate.d.ts +2 -2
- package/dist/validate.js +193 -1
- package/dist/validate.js.map +3 -3
- package/package.json +8 -2
package/dist/format.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../platform.js", "../parse.js", "../format.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\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 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 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 { 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 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 = /(^|\\+)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 let stripped = baseRaw\r\n while (stripped.length) {\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 for (const part of parts) {\r\n if (part === '__code__') {\r\n combo.code = codeValue\r\n continue\r\n }\r\n const actual = keyAliases[part] ?? part\r\n if (modifierTokens.has(actual)) setMod(actual)\r\n else combo.key = normalizeKey(actual)\r\n }\r\n\r\n if (!combo.key && !combo.code && impliedPlusKey) 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// --- 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 (PUNCT_NAMES[key]) return PUNCT_NAMES[key]\r\n const k = normalizeKey(key)\r\n return 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", "// format.js\r\n// Show a hotkey to people: `mod+shift+code:Period` -> \"Ctrl+Shift+.\" on\r\n// Windows and Linux, \"\u21E7\u2318.\" (glyphs) or \"Shift+Cmd+.\" (text) on macOS, plus\r\n// keycap tokens with names a screen reader can say.\r\n//\r\n// import { formatCombo, comboTokens, modifierLabel } from 'hotkey-router/format'\r\n//\r\n// formatCombo('mod+shift+code:Period') // 'Ctrl+Shift+.'\r\n// formatCombo('mod+shift+code:Period', { platform: 'mac', style: 'glyphs' }) // '\u21E7\u2318.'\r\n// comboTokens('mod+code:KeyK', { platform: 'mac' })\r\n// // [{ label: '\u2318', name: 'Command', modifier: 'meta' }, { label: 'K', name: 'K', key: 'KeyK' }]\r\n// modifierLabel('alt', { platform: 'mac', style: 'both' }) // '\u2325 Option'\r\n//\r\n// Modifier order. By default modifiers come in the platform's own order,\r\n// whatever order the string was written in: on macOS Apple's \u2303\u2325\u21E7\u2318\r\n// (Control, Option, Shift, Command), the order every Mac menu shows; on\r\n// Windows, Linux and ChromeOS Win/Super/Search, Ctrl, Alt, Shift. Pass\r\n// `{ order: 'combo' }` to keep the order the string was written in.\r\n//\r\n// Styles. 'text' (default for formatCombo): words joined by '+'. 'glyphs'\r\n// (default for comboTokens): macOS modifier and key symbols (\u2318 \u21E7 \u2325 \u2303 \u21A9 \u232B \u2190),\r\n// joined with no separator; Windows, Linux and ChromeOS have no such\r\n// symbols, so 'glyphs' there gives the same words as 'text'. 'both'\r\n// (modifierLabel only): glyph and word, '\u2325 Option'.\r\n//\r\n// Imports only the shared parser and detector, never the core router.\r\n\r\nimport { readHotkey, normalizeKey } from './parse.js'\r\nimport { detectPlatform, platformLabel, browserLabel } from './platform.js'\r\n\r\nexport { platformLabel, browserLabel }\r\n\r\n/** @typedef {'mac' | 'windows' | 'linux' | 'chromeos'} FormatPlatform */\r\n/** @typedef {'text' | 'glyphs'} FormatStyle */\r\n/** @typedef {'ctrl' | 'alt' | 'shift' | 'meta'} Modifier */\r\n\r\n// label: on-screen word; glyph: macOS symbol; name: what a screen reader says.\r\nconst MAC_MODIFIERS = {\r\n ctrl: { label: 'Control', glyph: '\u2303', name: 'Control' },\r\n alt: { label: 'Option', glyph: '\u2325', name: 'Option' },\r\n shift: { label: 'Shift', glyph: '\u21E7', name: 'Shift' },\r\n meta: { label: 'Cmd', glyph: '\u2318', name: 'Command' },\r\n}\r\nconst PC_MODIFIERS = {\r\n ctrl: { label: 'Ctrl', name: 'Control' },\r\n alt: { label: 'Alt', name: 'Alt' },\r\n shift: { label: 'Shift', name: 'Shift' },\r\n meta: { label: 'Win', name: 'Windows' },\r\n}\r\nconst META_BY_PLATFORM = {\r\n linux: { label: 'Super', name: 'Super' },\r\n chromeos: { label: 'Search', name: 'Search' },\r\n}\r\n\r\nconst ORDER = {\r\n mac: ['ctrl', 'alt', 'shift', 'meta'],\r\n pc: ['meta', 'ctrl', 'alt', 'shift'],\r\n}\r\n\r\n/**\r\n * Display names for `KeyboardEvent.code` values (the `code:` part of a\r\n * hotkey). `label` is the on-screen text, `name` what a screen reader says;\r\n * `mac`/`macName` replace them on macOS, `glyph` is the macOS symbol.\r\n * Letters (`KeyA`), digits (`Digit1`, `Numpad1`) and `F1`-`F24` are derived,\r\n * not listed.\r\n *\r\n * @type {Readonly<Record<string, Readonly<{ label: string, name: string, mac?: string, macName?: string, glyph?: string }>>>}\r\n */\r\nexport const KEY_LABELS = Object.freeze({\r\n Period: { label: '.', name: 'Period' },\r\n Comma: { label: ',', name: 'Comma' },\r\n Semicolon: { label: ';', name: 'Semicolon' },\r\n Quote: { label: \"'\", name: 'Quote' },\r\n Slash: { label: '/', name: 'Slash' },\r\n Backslash: { label: '\\\\', name: 'Backslash' },\r\n IntlBackslash: { label: '\\\\', name: 'Backslash' },\r\n BracketLeft: { label: '[', name: 'Left Bracket' },\r\n BracketRight: { label: ']', name: 'Right Bracket' },\r\n Minus: { label: '-', name: 'Minus' },\r\n Equal: { label: '=', name: 'Equals' },\r\n Backquote: { label: '`', name: 'Backquote' },\r\n Space: { label: 'Space', name: 'Space' },\r\n Enter: { label: 'Enter', name: 'Enter', mac: 'Return', glyph: '\u21A9' },\r\n NumpadEnter: { label: 'Enter', name: 'Enter', mac: 'Enter', glyph: '\u2324' },\r\n Tab: { label: 'Tab', name: 'Tab', glyph: '\u21E5' },\r\n Backspace: { label: 'Backspace', name: 'Backspace', mac: 'Delete', glyph: '\u232B' },\r\n Delete: { label: 'Delete', name: 'Delete', mac: 'Forward Delete', glyph: '\u2326' },\r\n Escape: { label: 'Esc', name: 'Escape', glyph: '\u238B' },\r\n Insert: { label: 'Insert', name: 'Insert' },\r\n Home: { label: 'Home', name: 'Home', glyph: '\u2196' },\r\n End: { label: 'End', name: 'End', glyph: '\u2198' },\r\n PageUp: { label: 'Page Up', name: 'Page Up', glyph: '\u21DE' },\r\n PageDown: { label: 'Page Down', name: 'Page Down', glyph: '\u21DF' },\r\n ArrowUp: { label: 'Up', name: 'Up Arrow', glyph: '\u2191' },\r\n ArrowDown: { label: 'Down', name: 'Down Arrow', glyph: '\u2193' },\r\n ArrowLeft: { label: 'Left', name: 'Left Arrow', glyph: '\u2190' },\r\n ArrowRight: { label: 'Right', name: 'Right Arrow', glyph: '\u2192' },\r\n CapsLock: { label: 'Caps Lock', name: 'Caps Lock', glyph: '\u21EA' },\r\n ContextMenu: { label: 'Menu', name: 'Menu' },\r\n NumpadAdd: { label: 'Num +', name: 'Numpad Plus' },\r\n NumpadSubtract: { label: 'Num -', name: 'Numpad Minus' },\r\n NumpadMultiply: { label: 'Num *', name: 'Numpad Multiply' },\r\n NumpadDivide: { label: 'Num /', name: 'Numpad Divide' },\r\n NumpadDecimal: { label: 'Num .', name: 'Numpad Decimal' },\r\n})\r\n\r\n// `event.key` values (as the parser normalizes them) that name a code above.\r\nconst KEY_TO_CODE = {\r\n '.': 'Period', ',': 'Comma', ';': 'Semicolon', \"'\": 'Quote', '/': 'Slash',\r\n '\\\\': 'Backslash', '[': 'BracketLeft', ']': 'BracketRight', '-': 'Minus',\r\n '=': 'Equal', '`': 'Backquote', ' ': 'Space', enter: 'Enter', tab: 'Tab',\r\n backspace: 'Backspace', delete: 'Delete', escape: 'Escape', insert: 'Insert',\r\n home: 'Home', end: 'End', pageup: 'PageUp', pagedown: 'PageDown',\r\n arrowup: 'ArrowUp', arrowdown: 'ArrowDown', arrowleft: 'ArrowLeft',\r\n arrowright: 'ArrowRight', capslock: 'CapsLock', contextmenu: 'ContextMenu',\r\n}\r\n\r\nconst KEY_NAMES = { '+': 'Plus', '*': 'Asterisk', '?': 'Question Mark', '!': 'Exclamation Mark' }\r\n\r\nfunction resolvePlatform(platform) {\r\n return platform || detectPlatform(undefined, { chromeos: true }) || 'windows'\r\n}\r\n\r\nfunction modifierInfo(mod, platform) {\r\n if (platform === 'mac') return MAC_MODIFIERS[mod]\r\n if (mod === 'meta' && META_BY_PLATFORM[platform]) return META_BY_PLATFORM[platform]\r\n return PC_MODIFIERS[mod]\r\n}\r\n\r\n// A key or code as { label, name, glyph? } for the platform.\r\nfunction keyInfo({ key, code }, platform) {\r\n const mac = platform === 'mac'\r\n let c = code\r\n if (!c && key != null) {\r\n c = KEY_TO_CODE[key]\r\n if (!c && /^[a-z]$/.test(key)) c = 'Key' + key.toUpperCase()\r\n if (!c && /^\\d$/.test(key)) c = 'Digit' + key\r\n if (!c && /^f\\d{1,2}$/.test(key)) c = key.toUpperCase()\r\n }\r\n if (c) {\r\n const known = KEY_LABELS[c]\r\n if (known) {\r\n const label = mac && known.mac ? known.mac : known.label\r\n return { label, name: mac && known.mac ? known.mac : known.name, glyph: mac ? known.glyph : undefined }\r\n }\r\n const letter = /^Key([A-Z])$/.exec(c)\r\n if (letter) return { label: letter[1], name: letter[1] }\r\n const digit = /^Digit(\\d)$/.exec(c)\r\n if (digit) return { label: digit[1], name: digit[1] }\r\n const numpad = /^Numpad(\\d)$/.exec(c)\r\n if (numpad) return { label: `Num ${numpad[1]}`, name: `Numpad ${numpad[1]}` }\r\n if (/^F\\d{1,2}$/.test(c)) return { label: c, name: c }\r\n if (code) return { label: code, name: code }\r\n }\r\n // Any other `event.key` value: a character as typed, a word capitalized.\r\n const k = String(key ?? '')\r\n if (k.length === 1) return { label: k.toUpperCase(), name: KEY_NAMES[k] || k.toUpperCase() }\r\n const word = k.charAt(0).toUpperCase() + k.slice(1)\r\n return { label: word, name: word }\r\n}\r\n\r\n// Parse a string (or take a parsed combo) into ordered parts.\r\nfunction partsOf(combo, platform, order) {\r\n let c = combo\r\n let written = null\r\n if (typeof combo === 'string') {\r\n c = readHotkey(combo, { platform }).combo\r\n if (order === 'combo') written = writtenModifiers(combo, platform)\r\n }\r\n if (!c) return null\r\n const mods = /** @type {Modifier[]} */ (['ctrl', 'alt', 'shift', 'meta'].filter((m) => c[m] || c.bareModifier === m))\r\n const sequence = written\r\n ? [...written.filter((m) => mods.includes(m)), ...mods.filter((m) => !written.includes(m))]\r\n : (platform === 'mac' ? ORDER.mac : ORDER.pc).filter((m) => mods.includes(m))\r\n const hasKey = !c.bareModifier && (c.key != null || c.code != null)\r\n return { mods: sequence, key: hasKey ? { key: c.key ?? null, code: c.code ?? null } : null }\r\n}\r\n\r\n// Modifiers in the order the string names them (`shift+mod+k` -> shift, meta).\r\nfunction writtenModifiers(str, platform) {\r\n const out = []\r\n const raw = String(str).replace(/\\s+up$/i, '')\r\n // AHK prefixes first, then '+'-separated tokens.\r\n let i = 0\r\n const ahk = { '^': 'ctrl', '!': 'alt', '+': 'shift', '#': 'meta' }\r\n while (i < raw.length && ahk[raw[i]] && raw[i + 1] !== undefined) {\r\n out.push(ahk[raw[i]])\r\n i++\r\n }\r\n for (const token of raw.slice(i).split('+')) {\r\n const t = normalizeKey(token)\r\n const m = t === 'mod' ? (platform === 'mac' ? 'meta' : 'ctrl') : t\r\n if (['ctrl', 'alt', 'shift', 'meta'].includes(m) && !out.includes(m)) out.push(m)\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * A modifier as this platform names it. Accepts `ctrl`, `alt`, `shift`,\r\n * `meta`, `mod` (Cmd on macOS, Ctrl elsewhere) and their aliases (`cmd`,\r\n * `option`, `opt`, `win`, `control`, `\u2318`).\r\n *\r\n * @param {string} name\r\n * @param {{ platform?: FormatPlatform, style?: 'text' | 'glyphs' | 'both' }} [opts]\r\n * @returns {string}\r\n */\r\nexport function modifierLabel(name, { platform, style = 'text' } = {}) {\r\n const plat = resolvePlatform(platform)\r\n let mod = normalizeKey(name)\r\n if (mod === 'mod') mod = plat === 'mac' ? 'meta' : 'ctrl'\r\n const info = modifierInfo(mod, plat)\r\n if (!info) return String(name)\r\n if (style === 'glyphs' && info.glyph) return info.glyph\r\n if (style === 'both' && info.glyph) return `${info.glyph} ${info.label}`\r\n return info.label\r\n}\r\n\r\n/**\r\n * What a screen reader should say for a modifier: 'Command', 'Option',\r\n * 'Control', 'Shift', 'Alt', 'Windows', 'Super', 'Search'.\r\n *\r\n * @param {string} name\r\n * @param {{ platform?: FormatPlatform }} [opts]\r\n * @returns {string}\r\n */\r\nexport function modifierName(name, { platform } = {}) {\r\n const plat = resolvePlatform(platform)\r\n let mod = normalizeKey(name)\r\n if (mod === 'mod') mod = plat === 'mac' ? 'meta' : 'ctrl'\r\n return modifierInfo(mod, plat)?.name ?? String(name)\r\n}\r\n\r\n/**\r\n * The label for one key: a `code:` value (`code:Period`, `KeyK`) or an\r\n * `event.key` value (`.`, `k`, `Enter`, `ArrowUp`).\r\n *\r\n * @param {string} key\r\n * @param {{ platform?: FormatPlatform, style?: FormatStyle }} [opts]\r\n * @returns {string}\r\n */\r\nexport function keyLabel(key, { platform, style = 'text' } = {}) {\r\n const plat = resolvePlatform(platform)\r\n const info = keyInfo(toKeyRef(key), plat)\r\n return style === 'glyphs' && info.glyph ? info.glyph : info.label\r\n}\r\n\r\nfunction toKeyRef(key) {\r\n const s = String(key ?? '')\r\n const code = /^code:(.+)$/.exec(s)?.[1] ?? (/^[A-Z][A-Za-z0-9]+$/.test(s) && (KEY_LABELS[s] || /^(Key[A-Z]|Digit\\d|Numpad\\d|F\\d{1,2})$/.test(s)) ? s : null)\r\n return code ? { code } : { key: normalizeKey(s) }\r\n}\r\n\r\n/**\r\n * @typedef {{\r\n * label: string,\r\n * name: string,\r\n * modifier?: Modifier,\r\n * key?: string\r\n * }} ComboToken\r\n *\r\n * `label` is what the keycap shows; `name` what a screen reader should say\r\n * (put it in visually hidden text or `aria-label` when `label` is a glyph).\r\n * `modifier` is set on modifier tokens; `key` on the base key token (the\r\n * `code` value, or the `event.key` value for key-based combos).\r\n */\r\n\r\n/**\r\n * One keycap per key, modifiers first. Default style 'glyphs': \u2318 \u21E7 \u2325 \u2303 on\r\n * macOS, words elsewhere.\r\n *\r\n * @param {string | object | null} combo hotkey string or parsed combo\r\n * @param {{ platform?: FormatPlatform, style?: FormatStyle, order?: 'platform' | 'combo' }} [opts]\r\n * @returns {ComboToken[]}\r\n */\r\nexport function comboTokens(combo, { platform, style = 'glyphs', order = 'platform' } = {}) {\r\n if (combo == null || combo === '') return []\r\n const plat = resolvePlatform(platform)\r\n const parts = partsOf(combo, plat, order)\r\n if (!parts) return []\r\n const glyphs = style === 'glyphs' && plat === 'mac'\r\n const tokens = parts.mods.map((m) => {\r\n const info = modifierInfo(m, plat)\r\n return { label: glyphs ? info.glyph : info.label, name: info.name, modifier: m }\r\n })\r\n if (parts.key) {\r\n const info = keyInfo(parts.key, plat)\r\n tokens.push({ label: glyphs && info.glyph ? info.glyph : info.label, name: info.name, key: parts.key.code ?? parts.key.key })\r\n }\r\n return tokens\r\n}\r\n\r\n/**\r\n * A hotkey as one string: 'Ctrl+Shift+.' (text) or '\u21E7\u2318.' (glyphs, macOS).\r\n * Empty string for an empty combo.\r\n *\r\n * @param {string | object | null} combo hotkey string or parsed combo\r\n * @param {{\r\n * platform?: FormatPlatform,\r\n * style?: FormatStyle,\r\n * order?: 'platform' | 'combo',\r\n * separator?: string // default '+' ('' for macOS glyphs)\r\n * }} [opts]\r\n * @returns {string}\r\n */\r\nexport function formatCombo(combo, { platform, style = 'text', order = 'platform', separator } = {}) {\r\n const plat = resolvePlatform(platform)\r\n const tokens = comboTokens(combo, { platform: plat, style, order })\r\n const sep = separator ?? (style === 'glyphs' && plat === 'mac' ? '' : '+')\r\n return tokens.map((t) => t.label).join(sep)\r\n}\r\n\r\n/**\r\n * The words for a list of modifiers, for sentences: ['ctrl', 'alt', 'shift']\r\n * -> 'Ctrl, Alt or Shift'.\r\n *\r\n * @param {string[]} names\r\n * @param {{ platform?: FormatPlatform, conjunction?: string }} [opts]\r\n * @returns {string}\r\n */\r\nexport function listModifiers(names, { platform, conjunction = 'or' } = {}) {\r\n const labels = names.map((n) => modifierLabel(n, { platform }))\r\n if (labels.length <= 1) return labels.join('')\r\n return `${labels.slice(0, -1).join(', ')} ${conjunction} ${labels[labels.length - 1]}`\r\n}\r\n"],
|
|
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\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 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 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 { 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 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 = /(^|\\+)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 let stripped = baseRaw\r\n while (stripped.length) {\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 for (const part of parts) {\r\n if (part === '__code__') {\r\n combo.code = codeValue\r\n continue\r\n }\r\n const actual = keyAliases[part] ?? part\r\n if (modifierTokens.has(actual)) setMod(actual)\r\n else combo.key = normalizeKey(actual)\r\n }\r\n\r\n if (!combo.key && !combo.code && impliedPlusKey) 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\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 = 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 (PUNCT_NAMES[key]) return PUNCT_NAMES[key]\r\n const k = normalizeKey(key)\r\n return 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", "// format.js\r\n// Show a hotkey to people: `mod+shift+code:Period` -> \"Ctrl+Shift+.\" on\r\n// Windows and Linux, \"\u21E7\u2318.\" (glyphs) or \"Shift+Cmd+.\" (text) on macOS, plus\r\n// keycap tokens with names a screen reader can say.\r\n//\r\n// import { formatCombo, comboTokens, modifierLabel } from 'hotkey-router/format'\r\n//\r\n// formatCombo('mod+shift+code:Period') // 'Ctrl+Shift+.'\r\n// formatCombo('mod+shift+code:Period', { platform: 'mac', style: 'glyphs' }) // '\u21E7\u2318.'\r\n// comboTokens('mod+code:KeyK', { platform: 'mac' })\r\n// // [{ label: '\u2318', name: 'Command', modifier: 'meta' }, { label: 'K', name: 'K', key: 'KeyK' }]\r\n// modifierLabel('alt', { platform: 'mac', style: 'both' }) // '\u2325 Option'\r\n//\r\n// Modifier order. By default modifiers come in the platform's own order,\r\n// whatever order the string was written in: on macOS Apple's \u2303\u2325\u21E7\u2318\r\n// (Control, Option, Shift, Command), the order every Mac menu shows; on\r\n// Windows, Linux and ChromeOS Win/Super/Search, Ctrl, Alt, Shift. Pass\r\n// `{ order: 'combo' }` to keep the order the string was written in.\r\n//\r\n// Styles. 'text' (default for formatCombo): words joined by '+'. 'glyphs'\r\n// (default for comboTokens): macOS modifier and key symbols (\u2318 \u21E7 \u2325 \u2303 \u21A9 \u232B \u2190),\r\n// joined with no separator; Windows, Linux and ChromeOS have no such\r\n// symbols, so 'glyphs' there gives the same words as 'text'. 'both'\r\n// (modifierLabel only): glyph and word, '\u2325 Option'.\r\n//\r\n// Imports only the shared parser and detector, never the core router.\r\n\r\nimport { readHotkey, normalizeKey } from './parse.js'\r\nimport { detectPlatform, platformLabel, browserLabel } from './platform.js'\r\n\r\nexport { platformLabel, browserLabel }\r\n\r\n/** @typedef {'mac' | 'windows' | 'linux' | 'chromeos'} FormatPlatform */\r\n/** @typedef {'text' | 'glyphs'} FormatStyle */\r\n/** @typedef {'ctrl' | 'alt' | 'shift' | 'meta'} Modifier */\r\n\r\n// label: on-screen word; glyph: macOS symbol; name: what a screen reader says.\r\nconst MAC_MODIFIERS = {\r\n ctrl: { label: 'Control', glyph: '\u2303', name: 'Control' },\r\n alt: { label: 'Option', glyph: '\u2325', name: 'Option' },\r\n shift: { label: 'Shift', glyph: '\u21E7', name: 'Shift' },\r\n meta: { label: 'Cmd', glyph: '\u2318', name: 'Command' },\r\n}\r\nconst PC_MODIFIERS = {\r\n ctrl: { label: 'Ctrl', name: 'Control' },\r\n alt: { label: 'Alt', name: 'Alt' },\r\n shift: { label: 'Shift', name: 'Shift' },\r\n meta: { label: 'Win', name: 'Windows' },\r\n}\r\nconst META_BY_PLATFORM = {\r\n linux: { label: 'Super', name: 'Super' },\r\n chromeos: { label: 'Search', name: 'Search' },\r\n}\r\n\r\nconst ORDER = {\r\n mac: ['ctrl', 'alt', 'shift', 'meta'],\r\n pc: ['meta', 'ctrl', 'alt', 'shift'],\r\n}\r\n\r\n/**\r\n * Display names for `KeyboardEvent.code` values (the `code:` part of a\r\n * hotkey). `label` is the on-screen text, `name` what a screen reader says;\r\n * `mac`/`macName` replace them on macOS, `glyph` is the macOS symbol.\r\n * Letters (`KeyA`), digits (`Digit1`, `Numpad1`) and `F1`-`F24` are derived,\r\n * not listed.\r\n *\r\n * @type {Readonly<Record<string, Readonly<{ label: string, name: string, mac?: string, macName?: string, glyph?: string }>>>}\r\n */\r\nexport const KEY_LABELS = Object.freeze({\r\n Period: { label: '.', name: 'Period' },\r\n Comma: { label: ',', name: 'Comma' },\r\n Semicolon: { label: ';', name: 'Semicolon' },\r\n Quote: { label: \"'\", name: 'Quote' },\r\n Slash: { label: '/', name: 'Slash' },\r\n Backslash: { label: '\\\\', name: 'Backslash' },\r\n IntlBackslash: { label: '\\\\', name: 'Backslash' },\r\n BracketLeft: { label: '[', name: 'Left Bracket' },\r\n BracketRight: { label: ']', name: 'Right Bracket' },\r\n Minus: { label: '-', name: 'Minus' },\r\n Equal: { label: '=', name: 'Equals' },\r\n Backquote: { label: '`', name: 'Backquote' },\r\n Space: { label: 'Space', name: 'Space' },\r\n Enter: { label: 'Enter', name: 'Enter', mac: 'Return', glyph: '\u21A9' },\r\n NumpadEnter: { label: 'Enter', name: 'Enter', mac: 'Enter', glyph: '\u2324' },\r\n Tab: { label: 'Tab', name: 'Tab', glyph: '\u21E5' },\r\n Backspace: { label: 'Backspace', name: 'Backspace', mac: 'Delete', glyph: '\u232B' },\r\n Delete: { label: 'Delete', name: 'Delete', mac: 'Forward Delete', glyph: '\u2326' },\r\n Escape: { label: 'Esc', name: 'Escape', glyph: '\u238B' },\r\n Insert: { label: 'Insert', name: 'Insert' },\r\n Home: { label: 'Home', name: 'Home', glyph: '\u2196' },\r\n End: { label: 'End', name: 'End', glyph: '\u2198' },\r\n PageUp: { label: 'Page Up', name: 'Page Up', glyph: '\u21DE' },\r\n PageDown: { label: 'Page Down', name: 'Page Down', glyph: '\u21DF' },\r\n ArrowUp: { label: 'Up', name: 'Up Arrow', glyph: '\u2191' },\r\n ArrowDown: { label: 'Down', name: 'Down Arrow', glyph: '\u2193' },\r\n ArrowLeft: { label: 'Left', name: 'Left Arrow', glyph: '\u2190' },\r\n ArrowRight: { label: 'Right', name: 'Right Arrow', glyph: '\u2192' },\r\n CapsLock: { label: 'Caps Lock', name: 'Caps Lock', glyph: '\u21EA' },\r\n ContextMenu: { label: 'Menu', name: 'Menu' },\r\n NumpadAdd: { label: 'Num +', name: 'Numpad Plus' },\r\n NumpadSubtract: { label: 'Num -', name: 'Numpad Minus' },\r\n NumpadMultiply: { label: 'Num *', name: 'Numpad Multiply' },\r\n NumpadDivide: { label: 'Num /', name: 'Numpad Divide' },\r\n NumpadDecimal: { label: 'Num .', name: 'Numpad Decimal' },\r\n})\r\n\r\n// `event.key` values (as the parser normalizes them) that name a code above.\r\nconst KEY_TO_CODE = {\r\n '.': 'Period', ',': 'Comma', ';': 'Semicolon', \"'\": 'Quote', '/': 'Slash',\r\n '\\\\': 'Backslash', '[': 'BracketLeft', ']': 'BracketRight', '-': 'Minus',\r\n '=': 'Equal', '`': 'Backquote', ' ': 'Space', enter: 'Enter', tab: 'Tab',\r\n backspace: 'Backspace', delete: 'Delete', escape: 'Escape', insert: 'Insert',\r\n home: 'Home', end: 'End', pageup: 'PageUp', pagedown: 'PageDown',\r\n arrowup: 'ArrowUp', arrowdown: 'ArrowDown', arrowleft: 'ArrowLeft',\r\n arrowright: 'ArrowRight', capslock: 'CapsLock', contextmenu: 'ContextMenu',\r\n}\r\n\r\nconst KEY_NAMES = { '+': 'Plus', '*': 'Asterisk', '?': 'Question Mark', '!': 'Exclamation Mark' }\r\n\r\nfunction resolvePlatform(platform) {\r\n return platform || detectPlatform(undefined, { chromeos: true }) || 'windows'\r\n}\r\n\r\nfunction modifierInfo(mod, platform) {\r\n if (platform === 'mac') return MAC_MODIFIERS[mod]\r\n if (mod === 'meta' && META_BY_PLATFORM[platform]) return META_BY_PLATFORM[platform]\r\n return PC_MODIFIERS[mod]\r\n}\r\n\r\n// A key or code as { label, name, glyph? } for the platform.\r\nfunction keyInfo({ key, code }, platform) {\r\n const mac = platform === 'mac'\r\n let c = code\r\n if (!c && key != null) {\r\n c = KEY_TO_CODE[key]\r\n if (!c && /^[a-z]$/.test(key)) c = 'Key' + key.toUpperCase()\r\n if (!c && /^\\d$/.test(key)) c = 'Digit' + key\r\n if (!c && /^f\\d{1,2}$/.test(key)) c = key.toUpperCase()\r\n }\r\n if (c) {\r\n const known = KEY_LABELS[c]\r\n if (known) {\r\n const label = mac && known.mac ? known.mac : known.label\r\n return { label, name: mac && known.mac ? known.mac : known.name, glyph: mac ? known.glyph : undefined }\r\n }\r\n const letter = /^Key([A-Z])$/.exec(c)\r\n if (letter) return { label: letter[1], name: letter[1] }\r\n const digit = /^Digit(\\d)$/.exec(c)\r\n if (digit) return { label: digit[1], name: digit[1] }\r\n const numpad = /^Numpad(\\d)$/.exec(c)\r\n if (numpad) return { label: `Num ${numpad[1]}`, name: `Numpad ${numpad[1]}` }\r\n if (/^F\\d{1,2}$/.test(c)) return { label: c, name: c }\r\n if (code) return { label: code, name: code }\r\n }\r\n // Any other `event.key` value: a character as typed, a word capitalized.\r\n const k = String(key ?? '')\r\n if (k.length === 1) return { label: k.toUpperCase(), name: KEY_NAMES[k] || k.toUpperCase() }\r\n const word = k.charAt(0).toUpperCase() + k.slice(1)\r\n return { label: word, name: word }\r\n}\r\n\r\n// Parse a string (or take a parsed combo) into ordered parts.\r\nfunction partsOf(combo, platform, order) {\r\n let c = combo\r\n let written = null\r\n if (typeof combo === 'string') {\r\n c = readHotkey(combo, { platform }).combo\r\n if (order === 'combo') written = writtenModifiers(combo, platform)\r\n }\r\n if (!c) return null\r\n const mods = /** @type {Modifier[]} */ (['ctrl', 'alt', 'shift', 'meta'].filter((m) => c[m] || c.bareModifier === m))\r\n const sequence = written\r\n ? [...written.filter((m) => mods.includes(m)), ...mods.filter((m) => !written.includes(m))]\r\n : (platform === 'mac' ? ORDER.mac : ORDER.pc).filter((m) => mods.includes(m))\r\n const hasKey = !c.bareModifier && (c.key != null || c.code != null)\r\n return { mods: sequence, key: hasKey ? { key: c.key ?? null, code: c.code ?? null } : null }\r\n}\r\n\r\n// Modifiers in the order the string names them (`shift+mod+k` -> shift, meta).\r\nfunction writtenModifiers(str, platform) {\r\n const out = []\r\n const raw = String(str).replace(/\\s+up$/i, '')\r\n // AHK prefixes first, then '+'-separated tokens.\r\n let i = 0\r\n const ahk = { '^': 'ctrl', '!': 'alt', '+': 'shift', '#': 'meta' }\r\n while (i < raw.length && ahk[raw[i]] && raw[i + 1] !== undefined) {\r\n out.push(ahk[raw[i]])\r\n i++\r\n }\r\n for (const token of raw.slice(i).split('+')) {\r\n const t = normalizeKey(token)\r\n const m = t === 'mod' ? (platform === 'mac' ? 'meta' : 'ctrl') : t\r\n if (['ctrl', 'alt', 'shift', 'meta'].includes(m) && !out.includes(m)) out.push(m)\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * A modifier as this platform names it. Accepts `ctrl`, `alt`, `shift`,\r\n * `meta`, `mod` (Cmd on macOS, Ctrl elsewhere) and their aliases (`cmd`,\r\n * `option`, `opt`, `win`, `control`, `\u2318`).\r\n *\r\n * @param {string} name\r\n * @param {{ platform?: FormatPlatform, style?: 'text' | 'glyphs' | 'both' }} [opts]\r\n * @returns {string}\r\n */\r\nexport function modifierLabel(name, { platform, style = 'text' } = {}) {\r\n const plat = resolvePlatform(platform)\r\n let mod = normalizeKey(name)\r\n if (mod === 'mod') mod = plat === 'mac' ? 'meta' : 'ctrl'\r\n const info = modifierInfo(mod, plat)\r\n if (!info) return String(name)\r\n if (style === 'glyphs' && info.glyph) return info.glyph\r\n if (style === 'both' && info.glyph) return `${info.glyph} ${info.label}`\r\n return info.label\r\n}\r\n\r\n/**\r\n * What a screen reader should say for a modifier: 'Command', 'Option',\r\n * 'Control', 'Shift', 'Alt', 'Windows', 'Super', 'Search'.\r\n *\r\n * @param {string} name\r\n * @param {{ platform?: FormatPlatform }} [opts]\r\n * @returns {string}\r\n */\r\nexport function modifierName(name, { platform } = {}) {\r\n const plat = resolvePlatform(platform)\r\n let mod = normalizeKey(name)\r\n if (mod === 'mod') mod = plat === 'mac' ? 'meta' : 'ctrl'\r\n return modifierInfo(mod, plat)?.name ?? String(name)\r\n}\r\n\r\n/**\r\n * The label for one key: a `code:` value (`code:Period`, `KeyK`) or an\r\n * `event.key` value (`.`, `k`, `Enter`, `ArrowUp`).\r\n *\r\n * @param {string} key\r\n * @param {{ platform?: FormatPlatform, style?: FormatStyle }} [opts]\r\n * @returns {string}\r\n */\r\nexport function keyLabel(key, { platform, style = 'text' } = {}) {\r\n const plat = resolvePlatform(platform)\r\n const info = keyInfo(toKeyRef(key), plat)\r\n return style === 'glyphs' && info.glyph ? info.glyph : info.label\r\n}\r\n\r\nfunction toKeyRef(key) {\r\n const s = String(key ?? '')\r\n const code = /^code:(.+)$/.exec(s)?.[1] ?? (/^[A-Z][A-Za-z0-9]+$/.test(s) && (KEY_LABELS[s] || /^(Key[A-Z]|Digit\\d|Numpad\\d|F\\d{1,2})$/.test(s)) ? s : null)\r\n return code ? { code } : { key: normalizeKey(s) }\r\n}\r\n\r\n/**\r\n * @typedef {{\r\n * label: string,\r\n * name: string,\r\n * modifier?: Modifier,\r\n * key?: string\r\n * }} ComboToken\r\n *\r\n * `label` is what the keycap shows; `name` what a screen reader should say\r\n * (put it in visually hidden text or `aria-label` when `label` is a glyph).\r\n * `modifier` is set on modifier tokens; `key` on the base key token (the\r\n * `code` value, or the `event.key` value for key-based combos).\r\n */\r\n\r\n/**\r\n * One keycap per key, modifiers first. Default style 'glyphs': \u2318 \u21E7 \u2325 \u2303 on\r\n * macOS, words elsewhere.\r\n *\r\n * @param {string | object | null} combo hotkey string or parsed combo\r\n * @param {{ platform?: FormatPlatform, style?: FormatStyle, order?: 'platform' | 'combo' }} [opts]\r\n * @returns {ComboToken[]}\r\n */\r\nexport function comboTokens(combo, { platform, style = 'glyphs', order = 'platform' } = {}) {\r\n if (combo == null || combo === '') return []\r\n const plat = resolvePlatform(platform)\r\n const parts = partsOf(combo, plat, order)\r\n if (!parts) return []\r\n const glyphs = style === 'glyphs' && plat === 'mac'\r\n const tokens = parts.mods.map((m) => {\r\n const info = modifierInfo(m, plat)\r\n return { label: glyphs ? info.glyph : info.label, name: info.name, modifier: m }\r\n })\r\n if (parts.key) {\r\n const info = keyInfo(parts.key, plat)\r\n tokens.push({ label: glyphs && info.glyph ? info.glyph : info.label, name: info.name, key: parts.key.code ?? parts.key.key })\r\n }\r\n return tokens\r\n}\r\n\r\n/**\r\n * A hotkey as one string: 'Ctrl+Shift+.' (text) or '\u21E7\u2318.' (glyphs, macOS).\r\n * Empty string for an empty combo.\r\n *\r\n * @param {string | object | null} combo hotkey string or parsed combo\r\n * @param {{\r\n * platform?: FormatPlatform,\r\n * style?: FormatStyle,\r\n * order?: 'platform' | 'combo',\r\n * separator?: string // default '+' ('' for macOS glyphs)\r\n * }} [opts]\r\n * @returns {string}\r\n */\r\nexport function formatCombo(combo, { platform, style = 'text', order = 'platform', separator } = {}) {\r\n const plat = resolvePlatform(platform)\r\n const tokens = comboTokens(combo, { platform: plat, style, order })\r\n const sep = separator ?? (style === 'glyphs' && plat === 'mac' ? '' : '+')\r\n return tokens.map((t) => t.label).join(sep)\r\n}\r\n\r\n/**\r\n * The words for a list of modifiers, for sentences: ['ctrl', 'alt', 'shift']\r\n * -> 'Ctrl, Alt or Shift'.\r\n *\r\n * @param {string[]} names\r\n * @param {{ platform?: FormatPlatform, conjunction?: string }} [opts]\r\n * @returns {string}\r\n */\r\nexport function listModifiers(names, { platform, conjunction = 'or' } = {}) {\r\n const labels = names.map((n) => modifierLabel(n, { platform }))\r\n if (labels.length <= 1) return labels.join('')\r\n return `${labels.slice(0, -1).join(', ')} ${conjunction} ${labels[labels.length - 1]}`\r\n}\r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
+
// hotkey-router v0.3.3 | SEE LICENSE IN LICENSE
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -192,6 +192,32 @@ function parseHotkey(hotkeyStr, opts) {
|
|
|
192
192
|
if (error) throw new Error(error);
|
|
193
193
|
return { combo, type, raw };
|
|
194
194
|
}
|
|
195
|
+
var SHIFTED_PUNCT = {
|
|
196
|
+
",": ["<", "Comma"],
|
|
197
|
+
".": [">", "Period"],
|
|
198
|
+
"/": ["?", "Slash"],
|
|
199
|
+
";": [":", "Semicolon"],
|
|
200
|
+
"'": ['"', "Quote"],
|
|
201
|
+
"[": ["{", "BracketLeft"],
|
|
202
|
+
"]": ["}", "BracketRight"],
|
|
203
|
+
"\\": ["|", "Backslash"],
|
|
204
|
+
"-": ["_", "Minus"],
|
|
205
|
+
"=": ["+", "Equal"],
|
|
206
|
+
"`": ["~", "Backquote"]
|
|
207
|
+
};
|
|
208
|
+
function shiftedPunctuationHint(hotkeyStr) {
|
|
209
|
+
const { combo, type, error } = readHotkey(hotkeyStr);
|
|
210
|
+
if (error || !combo.shift || combo.code) return null;
|
|
211
|
+
const shifted = SHIFTED_PUNCT[combo.key];
|
|
212
|
+
if (!shifted) return null;
|
|
213
|
+
const [typed, code] = shifted;
|
|
214
|
+
const base = String(hotkeyStr).trim().replace(/\s+up$/i, "");
|
|
215
|
+
const suggestion = base.slice(0, -1) + "code:" + code + (type === "keyup" ? " up" : "");
|
|
216
|
+
return {
|
|
217
|
+
message: `"${hotkeyStr}" never fires on US layouts: Shift turns "${combo.key}" into "${typed}". Bind "${suggestion}" instead.`,
|
|
218
|
+
suggestion
|
|
219
|
+
};
|
|
220
|
+
}
|
|
195
221
|
|
|
196
222
|
// hotkey-router.js
|
|
197
223
|
function on(target, type, fn, options) {
|
|
@@ -215,6 +241,7 @@ var plugins = /* @__PURE__ */ new Map();
|
|
|
215
241
|
var bindingIndex = /* @__PURE__ */ new Map();
|
|
216
242
|
var paused = false;
|
|
217
243
|
var nextId = 1;
|
|
244
|
+
var warnedShifted = /* @__PURE__ */ new Set();
|
|
218
245
|
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
219
246
|
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
220
247
|
let s = "";
|
|
@@ -246,7 +273,7 @@ function codeKeyFromEvent(e) {
|
|
|
246
273
|
return s + "code:" + e.code;
|
|
247
274
|
}
|
|
248
275
|
function isFromInputTarget(e) {
|
|
249
|
-
const t = e?.target;
|
|
276
|
+
const t = e?.composedPath?.()[0] ?? e?.target;
|
|
250
277
|
if (!t) return false;
|
|
251
278
|
const tag = String(t.tagName || "").toUpperCase();
|
|
252
279
|
return t.isContentEditable || tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || t.getAttribute?.("role") === "textbox";
|
|
@@ -303,6 +330,14 @@ function bind(hotkeyStr, handler, plugin = null, options = {}) {
|
|
|
303
330
|
};
|
|
304
331
|
ensureSlot(comboStr, type).push(binding);
|
|
305
332
|
bindingIndex.set(binding.id, { comboStr, type });
|
|
333
|
+
const warnKey = `${comboStr} ${type}`;
|
|
334
|
+
if (!warnedShifted.has(warnKey)) {
|
|
335
|
+
const hint = shiftedPunctuationHint(hotkeyStr);
|
|
336
|
+
if (hint) {
|
|
337
|
+
warnedShifted.add(warnKey);
|
|
338
|
+
console.warn(`[hotkey-router] ${hint.message}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
306
341
|
if (bindHooks.length) {
|
|
307
342
|
for (const hook of bindHooks) {
|
|
308
343
|
try {
|
|
@@ -349,8 +384,10 @@ function unbind(hotkeyStr, handler) {
|
|
|
349
384
|
}
|
|
350
385
|
function registerPlugin(name, hotkeyMap) {
|
|
351
386
|
if (plugins.has(name)) throw new Error(`Plugin "${name}" already registered`);
|
|
387
|
+
const entries = Object.entries(hotkeyMap);
|
|
388
|
+
for (const [hotkeyStr] of entries) parseHotkey(hotkeyStr);
|
|
352
389
|
const ids = [];
|
|
353
|
-
for (const [hotkeyStr, fnOrTuple] of
|
|
390
|
+
for (const [hotkeyStr, fnOrTuple] of entries) {
|
|
354
391
|
const [fn, options] = Array.isArray(fnOrTuple) ? fnOrTuple : [fnOrTuple, {}];
|
|
355
392
|
const off = bind(hotkeyStr, fn, name, options);
|
|
356
393
|
ids.push(off.id);
|
|
@@ -393,38 +430,65 @@ function isAltGraphCharacter(e) {
|
|
|
393
430
|
function isComposingEvent(e) {
|
|
394
431
|
return Boolean(e.isComposing || e.keyCode === 229);
|
|
395
432
|
}
|
|
433
|
+
var NON_LATIN_LETTER = /^(?!\p{Script=Latin})\p{L}$/u;
|
|
434
|
+
function latinKeyFromEvent(e) {
|
|
435
|
+
if (!(e.ctrlKey || e.metaKey) || e.altKey) return null;
|
|
436
|
+
if (isComposingEvent(e)) return null;
|
|
437
|
+
if (typeof e.getModifierState === "function" && e.getModifierState("AltGraph")) return null;
|
|
438
|
+
const letter = /^Key([A-Z])$/.exec(e.code || "");
|
|
439
|
+
if (!letter || typeof e.key !== "string" || !NON_LATIN_LETTER.test(e.key)) return null;
|
|
440
|
+
return comboKeyFromParts({
|
|
441
|
+
ctrl: e.ctrlKey,
|
|
442
|
+
shift: e.shiftKey,
|
|
443
|
+
alt: false,
|
|
444
|
+
meta: e.metaKey,
|
|
445
|
+
key: letter[1].toLowerCase()
|
|
446
|
+
});
|
|
447
|
+
}
|
|
396
448
|
function eligibleBindings(e, type, phase) {
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
449
|
+
const guards = {
|
|
450
|
+
altGraphChar: isAltGraphCharacter(e),
|
|
451
|
+
composing: isComposingEvent(e),
|
|
452
|
+
fromInput: ignoreEditable && isFromInputTarget(e)
|
|
453
|
+
};
|
|
401
454
|
const candidates = [];
|
|
455
|
+
const seen = /* @__PURE__ */ new Set();
|
|
402
456
|
for (const lookupKey of [comboKeyFromEvent(e), codeKeyFromEvent(e)]) {
|
|
403
457
|
if (!lookupKey || seen.has(lookupKey)) continue;
|
|
404
458
|
seen.add(lookupKey);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (phase === "bubble" && o.capture) continue;
|
|
411
|
-
if (altGraphChar && !o.altGraph) continue;
|
|
412
|
-
if (composing && !o.composing) continue;
|
|
413
|
-
if (fromInput && !o.allowIn?.(e)) continue;
|
|
414
|
-
if (type === "keydown" && o.repeat === false && e.repeat) continue;
|
|
415
|
-
if (o.when && o.when(e) === false) continue;
|
|
416
|
-
candidates.push(b);
|
|
417
|
-
}
|
|
459
|
+
collectEligible(candidates, lookupKey, e, type, phase, guards);
|
|
460
|
+
}
|
|
461
|
+
if (!candidates.length) {
|
|
462
|
+
const latinKey = latinKeyFromEvent(e);
|
|
463
|
+
if (latinKey && !seen.has(latinKey)) collectEligible(candidates, latinKey, e, type, phase, guards);
|
|
418
464
|
}
|
|
419
465
|
return candidates;
|
|
420
466
|
}
|
|
467
|
+
function collectEligible(candidates, lookupKey, e, type, phase, { altGraphChar, composing, fromInput }) {
|
|
468
|
+
const bindings = registry.get(lookupKey)?.get(type);
|
|
469
|
+
if (!bindings?.length) return;
|
|
470
|
+
for (const b of bindings) {
|
|
471
|
+
const o = b.options;
|
|
472
|
+
if (phase === "capture" && !o.capture) continue;
|
|
473
|
+
if (phase === "bubble" && o.capture) continue;
|
|
474
|
+
if (altGraphChar && !o.altGraph) continue;
|
|
475
|
+
if (composing && !o.composing) continue;
|
|
476
|
+
if (fromInput && !o.allowIn?.(e)) continue;
|
|
477
|
+
if (type === "keydown" && o.repeat === false && e.repeat) continue;
|
|
478
|
+
if (o.when && o.when(e) === false) continue;
|
|
479
|
+
candidates.push(b);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
421
482
|
function fire(winner, e) {
|
|
422
483
|
const o = winner.options;
|
|
423
484
|
if (o.preventDefault) e.preventDefault();
|
|
424
485
|
if (o.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
425
486
|
else if (o.stopPropagation) e.stopPropagation();
|
|
426
|
-
|
|
427
|
-
|
|
487
|
+
try {
|
|
488
|
+
winner.handler(e);
|
|
489
|
+
} finally {
|
|
490
|
+
if (o.once) removeById(winner.id);
|
|
491
|
+
}
|
|
428
492
|
}
|
|
429
493
|
function handleEvent(type, phase = "all") {
|
|
430
494
|
return (e) => {
|