hotkey-router 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -8
- package/dist/auto.js +265 -195
- package/dist/auto.js.map +4 -4
- package/dist/auto.min.js +2 -2
- package/dist/format.js +394 -0
- package/dist/format.js.map +7 -0
- package/dist/hotkey-router.cjs +204 -125
- package/dist/hotkey-router.cjs.map +4 -4
- package/dist/hotkey-router.js +203 -126
- package/dist/hotkey-router.js.map +4 -4
- package/dist/hotkey-router.min.js +2 -2
- package/dist/reservations.js +128 -62
- package/dist/reservations.js.map +4 -4
- package/dist/sites.js +195 -80
- package/dist/sites.js.map +4 -4
- package/dist/types/format.d.ts +128 -0
- package/dist/types/hotkey-router.d.ts +19 -20
- package/dist/types/parse.d.ts +112 -0
- package/dist/types/platform.d.ts +23 -0
- package/dist/types/reservations.d.ts +11 -6
- package/dist/types/sites.d.ts +6 -1
- package/dist/validate.js +10 -8
- package/dist/validate.js.map +2 -2
- package/package.json +5 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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"],
|
|
5
|
+
"mappings": ";;;;AAYA,SAAS,mBAAmB,GAAG;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,mBAAmB,KAAK,CAAC,EAAG,QAAO;AACvC,MAAI,wBAAwB,KAAK,CAAC,EAAG,QAAO;AAC5C,MAAI,OAAO,KAAK,CAAC,EAAG,QAAO;AAC3B,MAAI,aAAa,KAAK,CAAC,EAAG,QAAO;AACjC,SAAO;AACT;AAWO,SAAS,eAAe,MAAO,OAAO,cAAc,cAAc,YAAY,MAAO,EAAE,WAAW,MAAM,IAAI,CAAC,GAAG;AACrH,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,KAAK,IAAI,aAAa;AAC5B,QAAM,SACH,WAAW,KAAK,EAAE,IAAI,aAAa,SACpC,mBAAmB,IAAI,eAAe,QAAQ,KAC9C,mBAAmB,IAAI,QAAQ,MAC9B,YAAY,KAAK,EAAE,IAAI,QAAQ,WAAW,KAAK,EAAE,IAAI,YAAY,aAAa,KAAK,EAAE,IAAI,UAAU;AACtG,MAAI,UAAU,cAAc,CAAC,SAAU,QAAO;AAC9C,SAAO;AACT;AA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AQ,KAAK;AACtE,SAAO,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG;AAC5C;AAUO,SAAS,cAAc,OAAO,EAAE,UAAU,cAAc,KAAK,IAAI,CAAC,GAAG;AAC1E,QAAM,SAAS,MAAM,IAAI,CAAC,MAAM,cAAc,GAAG,EAAE,SAAS,CAAC,CAAC;AAC9D,MAAI,OAAO,UAAU,EAAG,QAAO,OAAO,KAAK,EAAE;AAC7C,SAAO,GAAG,OAAO,MAAM,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC,IAAI,WAAW,IAAI,OAAO,OAAO,SAAS,CAAC,CAAC;AACtF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/hotkey-router.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// hotkey-router v0.3.
|
|
1
|
+
// hotkey-router v0.3.2 | SEE LICENSE IN LICENSE
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,23 +23,31 @@ var hotkey_router_exports = {};
|
|
|
23
23
|
__export(hotkey_router_exports, {
|
|
24
24
|
comboFromEvent: () => comboFromEvent,
|
|
25
25
|
default: () => hotkey_router_default,
|
|
26
|
+
detectPlatform: () => detectPlatform,
|
|
26
27
|
parseHotkey: () => parseHotkey
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(hotkey_router_exports);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
// platform.js
|
|
32
|
+
function fromPlatformString(s) {
|
|
33
|
+
if (!s) return null;
|
|
34
|
+
if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
|
|
35
|
+
if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
|
|
36
|
+
if (/Win/i.test(s)) return "windows";
|
|
37
|
+
if (/Linux|X11/i.test(s)) return "linux";
|
|
38
|
+
return null;
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
|
|
41
|
+
if (!nav) return null;
|
|
42
|
+
const ua = nav.userAgent || "";
|
|
43
|
+
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);
|
|
44
|
+
if (found === "chromeos" && !chromeos) return "linux";
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// parse.js
|
|
49
|
+
var DEFAULT_PLATFORM = detectPlatform();
|
|
50
|
+
var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
|
|
43
51
|
var ahkPrefixMap = /* @__PURE__ */ new Map([
|
|
44
52
|
["^", "ctrl"],
|
|
45
53
|
// Ctrl
|
|
@@ -82,6 +90,7 @@ var keyAliases = Object.freeze({
|
|
|
82
90
|
control: "ctrl",
|
|
83
91
|
ctrl: "ctrl",
|
|
84
92
|
option: "alt",
|
|
93
|
+
opt: "alt",
|
|
85
94
|
alt: "alt",
|
|
86
95
|
shift: "shift",
|
|
87
96
|
// modifiers (symbols)
|
|
@@ -89,19 +98,11 @@ var keyAliases = Object.freeze({
|
|
|
89
98
|
"\u2303": "ctrl",
|
|
90
99
|
"\u2325": "alt",
|
|
91
100
|
"\u21E7": "shift",
|
|
92
|
-
// cross-platform "mod"
|
|
93
|
-
mod:
|
|
101
|
+
// cross-platform "mod", resolved per platform while parsing
|
|
102
|
+
mod: "mod",
|
|
94
103
|
// plus key ergonomics
|
|
95
104
|
plus: "+"
|
|
96
105
|
});
|
|
97
|
-
var ignoreEditable = true;
|
|
98
|
-
var defaultTarget = typeof window !== "undefined" ? window : null;
|
|
99
|
-
var bindHooks = [];
|
|
100
|
-
var registry = /* @__PURE__ */ new Map();
|
|
101
|
-
var plugins = /* @__PURE__ */ new Map();
|
|
102
|
-
var bindingIndex = /* @__PURE__ */ new Map();
|
|
103
|
-
var paused = false;
|
|
104
|
-
var nextId = 1;
|
|
105
106
|
function normalizeKey(key) {
|
|
106
107
|
const original = String(key ?? "");
|
|
107
108
|
if (original === " ") return " ";
|
|
@@ -109,43 +110,16 @@ function normalizeKey(key) {
|
|
|
109
110
|
const k = trimmed.toLowerCase();
|
|
110
111
|
return keyAliases[k] ?? k;
|
|
111
112
|
}
|
|
112
|
-
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
113
|
-
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
114
|
-
let s = "";
|
|
115
|
-
if (ctrl) s += "ctrl+";
|
|
116
|
-
if (shift) s += "shift+";
|
|
117
|
-
if (alt) s += "alt+";
|
|
118
|
-
if (meta) s += "meta+";
|
|
119
|
-
if (code) return s + "code:" + code;
|
|
120
|
-
return s ? s + key : key;
|
|
121
|
-
}
|
|
122
|
-
function comboKeyFromEvent(e) {
|
|
123
|
-
const bareMod = MODIFIER_KEY_TOKEN[e.key];
|
|
124
|
-
if (bareMod) return `__bare__:${bareMod}`;
|
|
125
|
-
return comboKeyFromParts({
|
|
126
|
-
ctrl: e.ctrlKey,
|
|
127
|
-
shift: e.shiftKey,
|
|
128
|
-
alt: e.altKey,
|
|
129
|
-
meta: e.metaKey,
|
|
130
|
-
key: normalizeKey(e.key)
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function codeKeyFromEvent(e) {
|
|
134
|
-
if (!e.code) return null;
|
|
135
|
-
let s = "";
|
|
136
|
-
if (e.ctrlKey) s += "ctrl+";
|
|
137
|
-
if (e.shiftKey) s += "shift+";
|
|
138
|
-
if (e.altKey) s += "alt+";
|
|
139
|
-
if (e.metaKey) s += "meta+";
|
|
140
|
-
return s + "code:" + e.code;
|
|
141
|
-
}
|
|
142
113
|
function isModifierToken(token) {
|
|
143
|
-
|
|
144
|
-
return modifierTokens.has(t);
|
|
114
|
+
return modifierTokens.has(normalizeKey(token));
|
|
145
115
|
}
|
|
146
116
|
var CODE_TOKEN_RE = /(^|\+)code:([A-Za-z][A-Za-z0-9_]*)/;
|
|
147
|
-
function
|
|
117
|
+
function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
|
|
148
118
|
const raw = String(hotkeyStr || "").trim();
|
|
119
|
+
let error = null;
|
|
120
|
+
const fail = (msg) => {
|
|
121
|
+
error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
|
|
122
|
+
};
|
|
149
123
|
const isUp = /\s+up$/i.test(raw);
|
|
150
124
|
const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
|
|
151
125
|
const combo = {
|
|
@@ -157,25 +131,27 @@ function parseHotkey(hotkeyStr) {
|
|
|
157
131
|
code: null,
|
|
158
132
|
bareModifier: null
|
|
159
133
|
};
|
|
134
|
+
const setMod = (mod) => {
|
|
135
|
+
if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
|
|
136
|
+
else combo[mod] = true;
|
|
137
|
+
};
|
|
160
138
|
let stripped = baseRaw;
|
|
161
139
|
while (stripped.length) {
|
|
162
140
|
const mod = ahkPrefixMap.get(stripped[0]) ?? null;
|
|
163
141
|
if (!mod) break;
|
|
164
|
-
|
|
142
|
+
setMod(mod);
|
|
165
143
|
stripped = stripped.slice(1).trimStart();
|
|
166
144
|
}
|
|
167
145
|
const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
|
|
168
146
|
if (codeMatches && codeMatches.length > 1) {
|
|
169
|
-
|
|
170
|
-
`Invalid hotkey "${hotkeyStr}": multiple code: tokens not supported (got ${codeMatches.length}).`
|
|
171
|
-
);
|
|
147
|
+
fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
|
|
172
148
|
}
|
|
173
149
|
let codeValue = null;
|
|
174
150
|
const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
|
|
175
151
|
codeValue = val;
|
|
176
152
|
return sep + "__code__";
|
|
177
153
|
});
|
|
178
|
-
|
|
154
|
+
const cleanStr = scrubbed.toLowerCase();
|
|
179
155
|
const rawParts = cleanStr.split("+").map((p) => p.trim());
|
|
180
156
|
const parts = rawParts.filter(Boolean);
|
|
181
157
|
const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
|
|
@@ -183,13 +159,9 @@ function parseHotkey(hotkeyStr) {
|
|
|
183
159
|
let seenBase = false;
|
|
184
160
|
for (const part of parts) {
|
|
185
161
|
if (isModifierToken(part)) {
|
|
186
|
-
if (seenBase)
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Invalid hotkey "${hotkeyStr}": modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
162
|
+
if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
|
|
191
163
|
} else {
|
|
192
|
-
|
|
164
|
+
seenBase = true;
|
|
193
165
|
}
|
|
194
166
|
}
|
|
195
167
|
}
|
|
@@ -199,10 +171,7 @@ function parseHotkey(hotkeyStr) {
|
|
|
199
171
|
continue;
|
|
200
172
|
}
|
|
201
173
|
const actual = keyAliases[part] ?? part;
|
|
202
|
-
if (actual
|
|
203
|
-
else if (actual === "shift") combo.shift = true;
|
|
204
|
-
else if (actual === "alt") combo.alt = true;
|
|
205
|
-
else if (actual === "meta") combo.meta = true;
|
|
174
|
+
if (modifierTokens.has(actual)) setMod(actual);
|
|
206
175
|
else combo.key = normalizeKey(actual);
|
|
207
176
|
}
|
|
208
177
|
if (!combo.key && !combo.code && impliedPlusKey) combo.key = "+";
|
|
@@ -211,14 +180,70 @@ function parseHotkey(hotkeyStr) {
|
|
|
211
180
|
if (modCount === 1) {
|
|
212
181
|
combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
|
|
213
182
|
} else if (modCount > 1) {
|
|
214
|
-
|
|
215
|
-
`Invalid hotkey "${hotkeyStr}": multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").`
|
|
216
|
-
);
|
|
183
|
+
fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
|
|
217
184
|
} else {
|
|
218
|
-
|
|
185
|
+
error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
|
|
219
186
|
}
|
|
220
187
|
}
|
|
221
|
-
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr };
|
|
188
|
+
return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
|
|
189
|
+
}
|
|
190
|
+
function parseHotkey(hotkeyStr, opts) {
|
|
191
|
+
const { combo, type, raw, error } = readHotkey(hotkeyStr, opts);
|
|
192
|
+
if (error) throw new Error(error);
|
|
193
|
+
return { combo, type, raw };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// hotkey-router.js
|
|
197
|
+
function on(target, type, fn, options) {
|
|
198
|
+
target.addEventListener(type, fn, options);
|
|
199
|
+
return () => target.removeEventListener(type, fn, options);
|
|
200
|
+
}
|
|
201
|
+
var PLATFORM = detectPlatform();
|
|
202
|
+
var MODIFIER_KEY_TOKEN = Object.freeze({
|
|
203
|
+
Alt: "alt",
|
|
204
|
+
AltGraph: "alt",
|
|
205
|
+
Control: "ctrl",
|
|
206
|
+
Shift: "shift",
|
|
207
|
+
Meta: "meta",
|
|
208
|
+
OS: "meta"
|
|
209
|
+
});
|
|
210
|
+
var ignoreEditable = true;
|
|
211
|
+
var defaultTarget = typeof window !== "undefined" ? window : null;
|
|
212
|
+
var bindHooks = [];
|
|
213
|
+
var registry = /* @__PURE__ */ new Map();
|
|
214
|
+
var plugins = /* @__PURE__ */ new Map();
|
|
215
|
+
var bindingIndex = /* @__PURE__ */ new Map();
|
|
216
|
+
var paused = false;
|
|
217
|
+
var nextId = 1;
|
|
218
|
+
function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
|
|
219
|
+
if (bareModifier) return `__bare__:${bareModifier}`;
|
|
220
|
+
let s = "";
|
|
221
|
+
if (ctrl) s += "ctrl+";
|
|
222
|
+
if (shift) s += "shift+";
|
|
223
|
+
if (alt) s += "alt+";
|
|
224
|
+
if (meta) s += "meta+";
|
|
225
|
+
if (code) return s + "code:" + code;
|
|
226
|
+
return s ? s + key : key;
|
|
227
|
+
}
|
|
228
|
+
function comboKeyFromEvent(e) {
|
|
229
|
+
const bareMod = MODIFIER_KEY_TOKEN[e.key];
|
|
230
|
+
if (bareMod) return `__bare__:${bareMod}`;
|
|
231
|
+
return comboKeyFromParts({
|
|
232
|
+
ctrl: e.ctrlKey,
|
|
233
|
+
shift: e.shiftKey,
|
|
234
|
+
alt: e.altKey,
|
|
235
|
+
meta: e.metaKey,
|
|
236
|
+
key: normalizeKey(e.key)
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function codeKeyFromEvent(e) {
|
|
240
|
+
if (!e.code) return null;
|
|
241
|
+
let s = "";
|
|
242
|
+
if (e.ctrlKey) s += "ctrl+";
|
|
243
|
+
if (e.shiftKey) s += "shift+";
|
|
244
|
+
if (e.altKey) s += "alt+";
|
|
245
|
+
if (e.metaKey) s += "meta+";
|
|
246
|
+
return s + "code:" + e.code;
|
|
222
247
|
}
|
|
223
248
|
function isFromInputTarget(e) {
|
|
224
249
|
const t = e?.target;
|
|
@@ -368,41 +393,44 @@ function isAltGraphCharacter(e) {
|
|
|
368
393
|
function isComposingEvent(e) {
|
|
369
394
|
return Boolean(e.isComposing || e.keyCode === 229);
|
|
370
395
|
}
|
|
396
|
+
function eligibleBindings(e, type, phase) {
|
|
397
|
+
const altGraphChar = isAltGraphCharacter(e);
|
|
398
|
+
const composing = isComposingEvent(e);
|
|
399
|
+
const fromInput = ignoreEditable && isFromInputTarget(e);
|
|
400
|
+
const seen = /* @__PURE__ */ new Set();
|
|
401
|
+
const candidates = [];
|
|
402
|
+
for (const lookupKey of [comboKeyFromEvent(e), codeKeyFromEvent(e)]) {
|
|
403
|
+
if (!lookupKey || seen.has(lookupKey)) continue;
|
|
404
|
+
seen.add(lookupKey);
|
|
405
|
+
const bindings = registry.get(lookupKey)?.get(type);
|
|
406
|
+
if (!bindings?.length) continue;
|
|
407
|
+
for (const b of bindings) {
|
|
408
|
+
const o = b.options;
|
|
409
|
+
if (phase === "capture" && !o.capture) continue;
|
|
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
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return candidates;
|
|
420
|
+
}
|
|
421
|
+
function fire(winner, e) {
|
|
422
|
+
const o = winner.options;
|
|
423
|
+
if (o.preventDefault) e.preventDefault();
|
|
424
|
+
if (o.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
425
|
+
else if (o.stopPropagation) e.stopPropagation();
|
|
426
|
+
winner.handler(e);
|
|
427
|
+
if (o.once) removeById(winner.id);
|
|
428
|
+
}
|
|
371
429
|
function handleEvent(type, phase = "all") {
|
|
372
430
|
return (e) => {
|
|
373
431
|
if (paused) return;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
const fromInput = ignoreEditable && isFromInputTarget(e);
|
|
377
|
-
const comboStr = comboKeyFromEvent(e);
|
|
378
|
-
const codeStr = codeKeyFromEvent(e);
|
|
379
|
-
const seen = /* @__PURE__ */ new Set();
|
|
380
|
-
const candidates = [];
|
|
381
|
-
for (const lookupKey of [comboStr, codeStr]) {
|
|
382
|
-
if (!lookupKey || seen.has(lookupKey)) continue;
|
|
383
|
-
seen.add(lookupKey);
|
|
384
|
-
const bindings = registry.get(lookupKey)?.get(type);
|
|
385
|
-
if (!bindings?.length) continue;
|
|
386
|
-
for (const b of bindings) {
|
|
387
|
-
const o2 = b.options;
|
|
388
|
-
if (phase === "capture" && !o2.capture) continue;
|
|
389
|
-
if (phase === "bubble" && o2.capture) continue;
|
|
390
|
-
if (altGraphChar && !o2.altGraph) continue;
|
|
391
|
-
if (composing && !o2.composing) continue;
|
|
392
|
-
if (fromInput && !o2.allowIn?.(e)) continue;
|
|
393
|
-
if (type === "keydown" && o2.repeat === false && e.repeat) continue;
|
|
394
|
-
if (o2.when && o2.when(e) === false) continue;
|
|
395
|
-
candidates.push(b);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (!candidates.length) return;
|
|
399
|
-
const winner = pickWinner(candidates);
|
|
400
|
-
const o = winner.options;
|
|
401
|
-
if (o.preventDefault) e.preventDefault();
|
|
402
|
-
if (o.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
403
|
-
else if (o.stopPropagation) e.stopPropagation();
|
|
404
|
-
winner.handler(e);
|
|
405
|
-
if (o.once) removeById(winner.id);
|
|
432
|
+
const candidates = eligibleBindings(e, type, phase);
|
|
433
|
+
if (candidates.length) fire(pickWinner(candidates), e);
|
|
406
434
|
};
|
|
407
435
|
}
|
|
408
436
|
var stopDown = null;
|
|
@@ -441,13 +469,62 @@ var BARE_MOD_TO_KEY = {
|
|
|
441
469
|
alt: "Alt",
|
|
442
470
|
meta: "Meta"
|
|
443
471
|
};
|
|
444
|
-
|
|
472
|
+
var CODE_TO_KEY = {
|
|
473
|
+
Period: ".",
|
|
474
|
+
Comma: ",",
|
|
475
|
+
Semicolon: ";",
|
|
476
|
+
Quote: "'",
|
|
477
|
+
Slash: "/",
|
|
478
|
+
Backslash: "\\",
|
|
479
|
+
BracketLeft: "[",
|
|
480
|
+
BracketRight: "]",
|
|
481
|
+
Minus: "-",
|
|
482
|
+
Equal: "=",
|
|
483
|
+
Backquote: "`",
|
|
484
|
+
Space: " ",
|
|
485
|
+
Enter: "Enter",
|
|
486
|
+
NumpadEnter: "Enter",
|
|
487
|
+
Tab: "Tab",
|
|
488
|
+
Escape: "Escape",
|
|
489
|
+
Backspace: "Backspace",
|
|
490
|
+
Delete: "Delete",
|
|
491
|
+
Insert: "Insert",
|
|
492
|
+
Home: "Home",
|
|
493
|
+
End: "End",
|
|
494
|
+
PageUp: "PageUp",
|
|
495
|
+
PageDown: "PageDown",
|
|
496
|
+
ArrowUp: "ArrowUp",
|
|
497
|
+
ArrowDown: "ArrowDown",
|
|
498
|
+
ArrowLeft: "ArrowLeft",
|
|
499
|
+
ArrowRight: "ArrowRight"
|
|
500
|
+
};
|
|
501
|
+
var KEY_TO_CODE = {};
|
|
502
|
+
var _a;
|
|
503
|
+
for (const [code, key] of Object.entries(CODE_TO_KEY)) {
|
|
504
|
+
KEY_TO_CODE[_a = normalizeKey(key)] ?? (KEY_TO_CODE[_a] = code);
|
|
505
|
+
}
|
|
506
|
+
function keyForCode(code) {
|
|
507
|
+
if (!code) return null;
|
|
508
|
+
const letter = /^Key([A-Z])$/.exec(code);
|
|
509
|
+
if (letter) return letter[1].toLowerCase();
|
|
510
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
511
|
+
if (digit) return digit[1];
|
|
512
|
+
if (/^F\d{1,2}$/.test(code)) return code;
|
|
513
|
+
return CODE_TO_KEY[code] ?? null;
|
|
514
|
+
}
|
|
515
|
+
function codeForKey(key) {
|
|
516
|
+
if (!key) return null;
|
|
517
|
+
if (/^[a-z]$/.test(key)) return "Key" + key.toUpperCase();
|
|
518
|
+
if (/^\d$/.test(key)) return "Digit" + key;
|
|
519
|
+
if (/^f\d{1,2}$/.test(key)) return key.toUpperCase();
|
|
520
|
+
return KEY_TO_CODE[key] ?? null;
|
|
521
|
+
}
|
|
522
|
+
function trigger(hotkeyStr, { type: forcedType, target = null } = {}) {
|
|
445
523
|
const { combo, type } = parseHotkey(hotkeyStr);
|
|
446
|
-
const comboStr = comboKeyFromParts(combo);
|
|
447
524
|
const actualType = forcedType || type;
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
525
|
+
if (paused) return false;
|
|
526
|
+
const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key ?? keyForCode(combo.code);
|
|
527
|
+
const eventCode = combo.bareModifier ? null : combo.code ?? codeForKey(combo.key);
|
|
451
528
|
let altKey = !!combo.alt;
|
|
452
529
|
let ctrlKey = !!combo.ctrl;
|
|
453
530
|
let shiftKey = !!combo.shift;
|
|
@@ -461,32 +538,33 @@ function trigger(hotkeyStr, { type: forcedType } = {}) {
|
|
|
461
538
|
const e = {
|
|
462
539
|
type: actualType,
|
|
463
540
|
key: eventKey,
|
|
464
|
-
code:
|
|
541
|
+
code: eventCode,
|
|
465
542
|
ctrlKey,
|
|
466
543
|
shiftKey,
|
|
467
544
|
altKey,
|
|
468
545
|
metaKey,
|
|
469
546
|
repeat: false,
|
|
547
|
+
isComposing: false,
|
|
548
|
+
getModifierState() {
|
|
549
|
+
return false;
|
|
550
|
+
},
|
|
470
551
|
preventDefault() {
|
|
471
552
|
},
|
|
472
553
|
stopPropagation() {
|
|
473
554
|
},
|
|
474
555
|
stopImmediatePropagation() {
|
|
475
556
|
},
|
|
476
|
-
target
|
|
557
|
+
target
|
|
477
558
|
};
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
);
|
|
481
|
-
if (!winner) return false;
|
|
482
|
-
winner.handler(e);
|
|
483
|
-
if (winner.options.once) removeById(winner.id);
|
|
559
|
+
const candidates = eligibleBindings(e, actualType, "all");
|
|
560
|
+
if (!candidates.length) return false;
|
|
561
|
+
fire(pickWinner(candidates), e);
|
|
484
562
|
return true;
|
|
485
563
|
}
|
|
486
|
-
function comboFromEvent(e, { physical = true, useMod = false } = {}) {
|
|
564
|
+
function comboFromEvent(e, { physical = true, useMod = false, platform = PLATFORM } = {}) {
|
|
487
565
|
if (!e || MODIFIER_KEY_TOKEN[e.key]) return null;
|
|
488
566
|
const parts = [];
|
|
489
|
-
const primaryIsMeta =
|
|
567
|
+
const primaryIsMeta = platform === "mac";
|
|
490
568
|
if (useMod && (primaryIsMeta ? e.metaKey : e.ctrlKey)) parts.push("mod");
|
|
491
569
|
if (e.ctrlKey && !(useMod && !primaryIsMeta)) parts.push("ctrl");
|
|
492
570
|
if (e.metaKey && !(useMod && primaryIsMeta)) parts.push("meta");
|
|
@@ -521,6 +599,7 @@ var hotkey_router_default = {
|
|
|
521
599
|
trigger,
|
|
522
600
|
// helpers
|
|
523
601
|
parseHotkey,
|
|
524
|
-
comboFromEvent
|
|
602
|
+
comboFromEvent,
|
|
603
|
+
detectPlatform
|
|
525
604
|
};
|
|
526
605
|
//# sourceMappingURL=hotkey-router.cjs.map
|