import { Hotkey, Key, ParsedHotkey, RawHotkey, RegisterableHotkey } from "./hotkey.cjs"; import { MODIFIER_ALIASES } from "./constants.cjs"; //#region src/parse.d.ts /** * Parses a hotkey string into its component parts. * * @param hotkey - The hotkey string to parse (e.g., 'Mod+Shift+S') * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection) * @returns A ParsedHotkey object with the key and modifier flags * * @example * ```ts * parseHotkey('Mod+S') // On Mac: { key: 'S', ctrl: false, shift: false, alt: false, meta: true, modifiers: ['Meta'] } * parseHotkey('Mod+S') // On Windows: { key: 'S', ctrl: true, shift: false, alt: false, meta: false, modifiers: ['Control'] } * parseHotkey('Control+Shift+A') // { key: 'A', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] } * ``` */ declare function parseHotkey(hotkey: Hotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey; /** * Converts a RawHotkey object to a ParsedHotkey. * Optional modifier booleans default to false; modifiers array is derived from them. * When `mod` is true, it is resolved to Control or Meta based on platform. * * @param raw - The raw hotkey object * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection) * @returns A ParsedHotkey suitable for matching and formatting * * @example * ```ts * rawHotkeyToParsedHotkey({ key: 'Escape' }) * // { key: 'Escape', ctrl: false, shift: false, alt: false, meta: false, modifiers: [] } * * rawHotkeyToParsedHotkey({ key: 'S', mod: true }, 'mac') * // { key: 'S', ctrl: false, shift: false, alt: false, meta: true, modifiers: ['Meta'] } * * rawHotkeyToParsedHotkey({ key: 'S', mod: true, shift: true }, 'windows') * // { key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] } * ``` */ declare function rawHotkeyToParsedHotkey(raw: RawHotkey, platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey; /** * Normalizes a hotkey string to its canonical form. * * - When `Mod` is allowed for the platform (Command on Mac without Control; * Control on Windows/Linux without Meta): emits `Mod`, then `Alt`, then `Shift`, * then the key (e.g. `Mod+Shift+E`, `Mod+S`). * - Otherwise: literal modifiers in `Control+Alt+Shift+Meta` order, then the key. * - Resolves aliases and normalizes key casing (e.g. `esc` → `Escape`, `a` → `A`). * * @param hotkey - The hotkey string to normalize * @param platform - The target platform for resolving `Mod` (defaults to auto-detection) * @returns The normalized hotkey string * * @example * ```ts * normalizeHotkey('shift+meta+e', 'mac') // 'Mod+Shift+E' * normalizeHotkey('ctrl+a', 'windows') // 'Mod+A' * normalizeHotkey('esc') // 'Escape' * ``` */ declare function normalizeHotkey(hotkey: Key | (string & {}), platform?: 'mac' | 'windows' | 'linux'): Hotkey; /** * Same canonical string as {@link normalizeHotkey}, but from an already-parsed hotkey. */ declare function normalizeHotkeyFromParsed(parsed: ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey; /** * Normalizes a string or {@link RawHotkey} object to the same canonical hotkey string. * Use this in framework adapters instead of branching on `formatHotkey(rawHotkeyToParsedHotkey(...))`. */ declare function normalizeRegisterableHotkey(hotkey: RegisterableHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey; /** * Checks if a string is a recognized modifier token (including aliases). * * For a `KeyboardEvent`, use `isModifier(normalizeKeyName(event.key))` so DOM * spellings like `OS` / `Win` match the same alias table. * * @param key - Key name or alias (e.g. from a hotkey string or `event.key`) * @returns True if the string is a recognized modifier */ declare function isModifierKey(key: Key | (string & {})): key is keyof typeof MODIFIER_ALIASES; /** * Parses a KeyboardEvent into a ParsedHotkey object. * * This function extracts the key and modifier state from a keyboard event * and converts it into the same format used by `parseHotkey()`. * * @param event - The KeyboardEvent to parse * @param platform - The target platform for resolving modifiers (defaults to auto-detection) * @returns A ParsedHotkey object representing the keyboard event * * @example * ```ts * document.addEventListener('keydown', (event) => { * const parsed = parseKeyboardEvent(event) * console.log(parsed) // { key: 'S', ctrl: true, shift: false, ... } * }) * ``` */ declare function parseKeyboardEvent(event: KeyboardEvent): ParsedHotkey; /** * Normalizes a keyboard event to the same canonical hotkey string as {@link normalizeHotkey}. * * @param event - The keyboard event (typically `keydown`) * @param platform - Target platform for `Mod` eligibility */ declare function normalizeHotkeyFromEvent(event: KeyboardEvent, platform?: 'mac' | 'windows' | 'linux'): Hotkey; /** * Checks if a hotkey or ParsedHotkey contains at least one non-modifier key. * * This is useful for validating that a recorded hotkey is complete and not * just a combination of modifiers without an action key. * * @param hotkey - The hotkey string or ParsedHotkey to check * @param platform - The target platform for parsing (defaults to auto-detection) * @returns True if the hotkey contains at least one non-modifier key * * @example * ```ts * hasNonModifierKey('Control+Shift+S') // true * hasNonModifierKey('Control+Shift') // false (no action key) * hasNonModifierKey(parseHotkey('Mod+A')) // true * ``` */ declare function hasNonModifierKey(hotkey: Hotkey | ParsedHotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): boolean; //#endregion export { hasNonModifierKey, isModifierKey, normalizeHotkey, normalizeHotkeyFromEvent, normalizeHotkeyFromParsed, normalizeRegisterableHotkey, parseHotkey, parseKeyboardEvent, rawHotkeyToParsedHotkey }; //# sourceMappingURL=parse.d.cts.map