/** * Keyboard utilities for shortcut handling and platform detection * * This module provides cross-platform keyboard shortcut handling with proper * platform detection (Mac vs. Windows/Linux) and key combination parsing. * * @module utils/keyboardUtils * * @example * ```typescript * import { detectPlatform, getKeyCombination, formatKeyDisplay } from './keyboardUtils'; * * // Detect user's platform * const platform = detectPlatform(); // 'mac' | 'windows' | 'linux' | 'unknown' * * // Handle keyboard event * document.addEventListener('keydown', (e) => { * const combo = getKeyCombination(e); * console.log('Pressed:', combo); // e.g., 'ctrl+shift+k' * }); * ``` */ import { Platform } from '../types/keyboard'; /** * Reset the cached platform (used for testing) * @internal */ export declare function resetPlatformCache(): void; /** * Detect the current platform * * Uses modern navigator.userAgentData when available, with fallback to * the older navigator.platform property for browsers that don't support it. * Result is cached for performance. * * @returns The detected platform * * @example * ```typescript * // Simple platform detection * const platform = detectPlatform(); * * if (platform === 'mac') { * console.log('User is on macOS - show Cmd shortcuts'); * } else if (platform === 'windows') { * console.log('User is on Windows - show Ctrl shortcuts'); * } * * // Use in keyboard shortcut display * const modifier = platform === 'mac' ? '⌘' : 'Ctrl'; * const shortcutText = `${modifier}+K to search`; * ``` */ export declare function detectPlatform(): Platform; /** * Get platform modifier key (Cmd on Mac, Ctrl elsewhere) * * @returns The platform-specific modifier key name * * @example * ```typescript * // Get the right modifier for current platform * const modifier = getPlatformModifier(); * * // Use in shortcut configuration * const shortcuts = { * search: `${modifier}+k`, // 'cmd+k' on Mac, 'ctrl+k' elsewhere * save: `${modifier}+s`, // 'cmd+s' on Mac, 'ctrl+s' elsewhere * }; * * // Display in UI * const displayText = modifier === 'cmd' ? '⌘+K' : 'Ctrl+K'; * ``` */ export declare function getPlatformModifier(): 'cmd' | 'ctrl'; /** * Get key combination string from keyboard event * * Converts KeyboardEvent to a normalized key combination string. * Handles platform differences (Cmd vs. Ctrl) and special keys. * * @param event - The keyboard event * @returns Key combination string (e.g., 'ctrl+shift+k') * * @example * ```typescript * // In event handler * document.addEventListener('keydown', (event) => { * const combo = getKeyCombination(event); * * // Match against shortcuts * if (combo === 'ctrl+shift+k' || combo === 'cmd+shift+k') { * event.preventDefault(); * openCommandPalette(); * } * * // Log for debugging * console.log('Key combo:', combo); * // Examples: 'ctrl+s', 'cmd+k', 'shift+enter', 'escape' * }); * * // Handle special keys * // Space key: 'ctrl+space' * // Escape key: 'escape' * // Enter key: 'shift+enter' * ``` */ export declare function getKeyCombination(event: KeyboardEvent): string; /** * Normalize shortcut string for comparison * * Maintains the canonical modifier key order (ctrl, cmd, meta, shift, alt) * to ensure consistent matching with getKeyCombination output. * * @param shortcut - The shortcut string (e.g., 'Ctrl+K', 'cmd+k') * @returns Normalized shortcut string */ export declare function normalizeShortcut(shortcut: string): string; /** * Check if two shortcuts match * * @param shortcut1 - First shortcut string * @param shortcut2 - Second shortcut string * @returns True if shortcuts match */ export declare function shortcutsMatch(shortcut1: string, shortcut2: string): boolean; /** * Format shortcut for display based on platform * * @param keys - Key combination string (e.g., 'ctrl+k') * @param platform - Target platform (defaults to current) * @returns Formatted shortcut string */ export declare function formatShortcut(keys: string, platform?: Platform): string; /** * Split formatted shortcut into individual keys for badge display * * @param keys - Key combination string * @param platform - Target platform * @returns Array of individual key display strings */ export declare function splitShortcutKeys(keys: string, platform?: Platform): string[]; /** * Check if element is an input that should prevent shortcuts * * @param element - DOM element to check * @returns True if element is an input */ export declare function isInputElement(element: Element | null): boolean; /** * Check if keyboard event should be ignored for shortcuts * * @param event - Keyboard event * @returns True if event should be ignored */ export declare function shouldIgnoreKeyboardEvent(event: KeyboardEvent): boolean; /** * Get keyboard shortcut for current platform * * @param defaultKeys - Default key combination * @param platformKeys - Platform-specific overrides * @returns Key combination for current platform */ export declare function getPlatformShortcut(defaultKeys: string, platformKeys?: Partial>): string; /** * Create accessible label for keyboard shortcut * * @param keys - Key combination string * @returns Accessible label string */ export declare function getShortcutAriaLabel(keys: string): string; /** * Check if keyboard shortcuts are supported in the current environment * * @returns True if keyboard shortcuts are supported */ export declare function areKeyboardShortcutsSupported(): boolean; //# sourceMappingURL=keyboardUtils.d.ts.map