import { Hotkey, HotkeyCallback, ParsedHotkey } from "./hotkey.js"; //#region src/match.d.ts /** * Checks if a KeyboardEvent matches a hotkey. * * Uses the `key` property from KeyboardEvent for matching, with a fallback to `code` * for letter keys, digit keys (0-9), and punctuation keys when `key` produces special * characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation). * Letter keys are matched case-insensitively. * * Also handles "dead key" events where `event.key` is `'Dead'` instead of the expected * character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E, * Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts. * In these cases, `event.code` is used to determine the physical key. * * @param event - The KeyboardEvent to check * @param hotkey - The hotkey string or ParsedHotkey to match against * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection) * @returns True if the event matches the hotkey * * @example * ```ts * document.addEventListener('keydown', (event) => { * if (matchesKeyboardEvent(event, 'Mod+S')) { * event.preventDefault() * handleSave() * } * }) * ``` */ declare function matchesKeyboardEvent(event: KeyboardEvent, hotkey: Hotkey | ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): boolean; /** * Options for creating a hotkey handler. */ interface CreateHotkeyHandlerOptions { /** Prevent the default browser action when the hotkey matches. Defaults to true */ preventDefault?: boolean; /** Stop event propagation when the hotkey matches. Defaults to true */ stopPropagation?: boolean; /** The target platform for resolving 'Mod' */ platform?: 'mac' | 'windows' | 'linux'; } /** * Creates a keyboard event handler that calls the callback when the hotkey matches. * * @param hotkey - The hotkey string or ParsedHotkey to match * @param callback - The function to call when the hotkey matches * @param options - Options for matching and handling * @returns A function that can be used as an event handler * * @example * ```ts * const handler = createHotkeyHandler('Mod+S', (event, { hotkey, parsedHotkey }) => { * console.log(`${hotkey} was pressed`) * handleSave() * }) * * document.addEventListener('keydown', handler) * ``` */ declare function createHotkeyHandler(hotkey: Hotkey | ParsedHotkey, callback: HotkeyCallback, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void; type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback }; /** * Creates a handler that matches multiple hotkeys. * * @param handlers - A map of hotkey strings to their handlers * @param options - Options for matching and handling * @returns A function that can be used as an event handler * * @example * ```ts * const handler = createMultiHotkeyHandler({ * 'Mod+S': (event, { hotkey }) => handleSave(), * 'Mod+Z': (event, { hotkey }) => handleUndo(), * 'Mod+Shift+Z': (event, { hotkey }) => handleRedo(), * }) * * document.addEventListener('keydown', handler) * ``` */ declare function createMultiHotkeyHandler(handlers: MultiHotkeyHandler, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void; //#endregion export { CreateHotkeyHandlerOptions, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent }; //# sourceMappingURL=match.d.ts.map