@corti/dictation-web
Version:
Web component for Corti Dictation
37 lines (36 loc) • 1.43 kB
TypeScript
/**
* Normalizes a keybinding string.
*
* @param keybinding - Keybinding string to normalize
* @returns Normalized keybinding string or null if empty
*
* @example
* normalizeKeybinding("k") // "k"
* normalizeKeybinding("meta") // "Cmd" on Mac
* normalizeKeybinding(" space ") // "Space"
*/
export declare function normalizeKeybinding(keybinding: string | null | undefined): string | null;
/**
* Checks if a pressed key matches the keybinding.
* Checks both event.key and event.code for better reliability.
*
* @param event - KeyboardEvent to check
* @param keybinding - Keybinding string to match against
* @returns true if either the key or code matches the keybinding
*
* @example
* matchesKeybinding(event, "k") // true if event.key is "k" or event.code is "KeyK"
* matchesKeybinding(event, "`") // true if event.key is "`" or event.code is "Backquote"
*/
export declare function matchesKeybinding(event: KeyboardEvent, keybinding: string | null | undefined): boolean;
/**
* Checks if keybindings should be ignored for the current active element.
* Returns true if the user is typing in an input field.
*
* @param element - Element to check
* @returns true if keybindings should be ignored for this element
*
* @example
* shouldIgnoreKeybinding(document.activeElement) // true if input/textarea/contenteditable
*/
export declare function shouldIgnoreKeybinding(element: Element | null): boolean;