@tanstack/hotkeys 0.0.1 → 0.1.0
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/LICENSE +21 -0
- package/README.md +121 -45
- package/dist/constants.cjs +444 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +226 -0
- package/dist/constants.d.ts +226 -0
- package/dist/constants.js +428 -0
- package/dist/constants.js.map +1 -0
- package/dist/format.cjs +178 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +110 -0
- package/dist/format.d.ts +110 -0
- package/dist/format.js +175 -0
- package/dist/format.js.map +1 -0
- package/dist/hotkey-manager.cjs +420 -0
- package/dist/hotkey-manager.cjs.map +1 -0
- package/dist/hotkey-manager.d.cts +207 -0
- package/dist/hotkey-manager.d.ts +207 -0
- package/dist/hotkey-manager.js +419 -0
- package/dist/hotkey-manager.js.map +1 -0
- package/dist/hotkey.d.cts +278 -0
- package/dist/hotkey.d.ts +278 -0
- package/dist/index.cjs +54 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/key-state-tracker.cjs +197 -0
- package/dist/key-state-tracker.cjs.map +1 -0
- package/dist/key-state-tracker.d.cts +107 -0
- package/dist/key-state-tracker.d.ts +107 -0
- package/dist/key-state-tracker.js +196 -0
- package/dist/key-state-tracker.js.map +1 -0
- package/dist/match.cjs +143 -0
- package/dist/match.cjs.map +1 -0
- package/dist/match.d.cts +79 -0
- package/dist/match.d.ts +79 -0
- package/dist/match.js +141 -0
- package/dist/match.js.map +1 -0
- package/dist/parse.cjs +266 -0
- package/dist/parse.cjs.map +1 -0
- package/dist/parse.d.cts +169 -0
- package/dist/parse.d.ts +169 -0
- package/dist/parse.js +258 -0
- package/dist/parse.js.map +1 -0
- package/dist/recorder.cjs +177 -0
- package/dist/recorder.cjs.map +1 -0
- package/dist/recorder.d.cts +108 -0
- package/dist/recorder.d.ts +108 -0
- package/dist/recorder.js +177 -0
- package/dist/recorder.js.map +1 -0
- package/dist/sequence.cjs +242 -0
- package/dist/sequence.cjs.map +1 -0
- package/dist/sequence.d.cts +109 -0
- package/dist/sequence.d.ts +109 -0
- package/dist/sequence.js +240 -0
- package/dist/sequence.js.map +1 -0
- package/dist/validate.cjs +116 -0
- package/dist/validate.cjs.map +1 -0
- package/dist/validate.d.cts +56 -0
- package/dist/validate.d.ts +56 -0
- package/dist/validate.js +114 -0
- package/dist/validate.js.map +1 -0
- package/package.json +55 -7
- package/src/constants.ts +514 -0
- package/src/format.ts +261 -0
- package/src/hotkey-manager.ts +822 -0
- package/src/hotkey.ts +411 -0
- package/src/index.ts +10 -0
- package/src/key-state-tracker.ts +249 -0
- package/src/match.ts +222 -0
- package/src/parse.ts +368 -0
- package/src/recorder.ts +266 -0
- package/src/sequence.ts +391 -0
- package/src/validate.ts +171 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { CanonicalModifier, EditingKey, FunctionKey, LetterKey, NavigationKey, NumberKey, PunctuationKey } from "./hotkey.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/constants.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current platform based on browser navigator properties.
|
|
6
|
+
*
|
|
7
|
+
* Used internally to resolve platform-adaptive modifiers like 'Mod' (Command on Mac,
|
|
8
|
+
* Control elsewhere) and for platform-specific hotkey formatting.
|
|
9
|
+
*
|
|
10
|
+
* @returns The detected platform: 'mac', 'windows', or 'linux'
|
|
11
|
+
* @remarks Defaults to 'linux' in SSR environments where navigator is undefined
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const platform = detectPlatform() // 'mac' | 'windows' | 'linux'
|
|
16
|
+
* const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function detectPlatform(): 'mac' | 'windows' | 'linux';
|
|
20
|
+
/**
|
|
21
|
+
* Canonical order for modifiers in normalized hotkey strings.
|
|
22
|
+
*
|
|
23
|
+
* Defines the standard order in which modifiers should appear when formatting
|
|
24
|
+
* hotkeys. This ensures consistent, predictable output across the library.
|
|
25
|
+
*
|
|
26
|
+
* Order: Control → Alt → Shift → Meta
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Input: 'Shift+Control+Meta+S'
|
|
31
|
+
* // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const MODIFIER_ORDER: Array<CanonicalModifier>;
|
|
35
|
+
/**
|
|
36
|
+
* Set of canonical modifier key names for fast lookup.
|
|
37
|
+
*
|
|
38
|
+
* Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when
|
|
39
|
+
* a modifier is released so we can clear non-modifier keys whose keyup events
|
|
40
|
+
* may have been swallowed by the OS (e.g. macOS Cmd+key combos).
|
|
41
|
+
*/
|
|
42
|
+
declare const MODIFIER_KEYS: Set<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.
|
|
45
|
+
*
|
|
46
|
+
* This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')
|
|
47
|
+
* which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the
|
|
48
|
+
* platform-adaptive 'Mod' token.
|
|
49
|
+
*
|
|
50
|
+
* The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`
|
|
51
|
+
* based on the detected platform (Command on Mac, Control elsewhere).
|
|
52
|
+
*
|
|
53
|
+
* @remarks Case-insensitive lookups are supported via lowercase variants
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* MODIFIER_ALIASES['Ctrl'] // 'Control'
|
|
58
|
+
* MODIFIER_ALIASES['Cmd'] // 'Meta'
|
|
59
|
+
* MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'>;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.
|
|
65
|
+
*
|
|
66
|
+
* The 'Mod' token represents the "primary modifier" on each platform:
|
|
67
|
+
* - macOS: 'Meta' (Command key ⌘)
|
|
68
|
+
* - Windows/Linux: 'Control' (Ctrl key)
|
|
69
|
+
*
|
|
70
|
+
* This enables cross-platform hotkey definitions like 'Mod+S' that automatically
|
|
71
|
+
* map to Command+S on Mac and Ctrl+S on Windows/Linux.
|
|
72
|
+
*
|
|
73
|
+
* @param modifier - The modifier to resolve. If 'Mod', resolves based on platform.
|
|
74
|
+
* @param platform - The target platform. Defaults to auto-detection.
|
|
75
|
+
* @returns The canonical modifier name ('Control', 'Shift', 'Alt', or 'Meta')
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* resolveModifier('Mod', 'mac') // 'Meta'
|
|
80
|
+
* resolveModifier('Mod', 'windows') // 'Control'
|
|
81
|
+
* resolveModifier('Control', 'mac') // 'Control' (unchanged)
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
|
85
|
+
/**
|
|
86
|
+
* Set of all valid letter keys (A-Z).
|
|
87
|
+
*
|
|
88
|
+
* Used for validation and type checking. Letter keys are matched case-insensitively
|
|
89
|
+
* in hotkey matching, but normalized to uppercase in canonical form.
|
|
90
|
+
*/
|
|
91
|
+
declare const LETTER_KEYS: Set<LetterKey>;
|
|
92
|
+
/**
|
|
93
|
+
* Set of all valid number keys (0-9).
|
|
94
|
+
*
|
|
95
|
+
* Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),
|
|
96
|
+
* so they're excluded from Shift-based hotkey combinations to avoid
|
|
97
|
+
* layout-dependent behavior.
|
|
98
|
+
*/
|
|
99
|
+
declare const NUMBER_KEYS: Set<NumberKey>;
|
|
100
|
+
/**
|
|
101
|
+
* Set of all valid function keys (F1-F12).
|
|
102
|
+
*
|
|
103
|
+
* Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
|
|
104
|
+
* Alt+F4 to close windows) and application-specific commands.
|
|
105
|
+
*/
|
|
106
|
+
declare const FUNCTION_KEYS: Set<FunctionKey>;
|
|
107
|
+
/**
|
|
108
|
+
* Set of all valid navigation keys for cursor movement and document navigation.
|
|
109
|
+
*
|
|
110
|
+
* Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).
|
|
111
|
+
* These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or
|
|
112
|
+
* navigation shortcuts (Alt+ArrowLeft for back).
|
|
113
|
+
*/
|
|
114
|
+
declare const NAVIGATION_KEYS: Set<NavigationKey>;
|
|
115
|
+
/**
|
|
116
|
+
* Set of all valid editing and special keys.
|
|
117
|
+
*
|
|
118
|
+
* Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and
|
|
119
|
+
* special actions (Escape, Space). These keys are frequently combined with modifiers
|
|
120
|
+
* for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).
|
|
121
|
+
*/
|
|
122
|
+
declare const EDITING_KEYS: Set<EditingKey>;
|
|
123
|
+
/**
|
|
124
|
+
* Set of all valid punctuation keys commonly used in keyboard shortcuts.
|
|
125
|
+
*
|
|
126
|
+
* These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,
|
|
127
|
+
* typically US keyboard layout). Common shortcuts include:
|
|
128
|
+
* - `Mod+/` - Toggle comment
|
|
129
|
+
* - `Mod+[` / `Mod+]` - Indent/outdent
|
|
130
|
+
* - `Mod+=` / `Mod+-` - Zoom in/out
|
|
131
|
+
*
|
|
132
|
+
* Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),
|
|
133
|
+
* so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.
|
|
134
|
+
*/
|
|
135
|
+
declare const PUNCTUATION_KEYS: Set<PunctuationKey>;
|
|
136
|
+
/**
|
|
137
|
+
* Set of all valid non-modifier keys.
|
|
138
|
+
*
|
|
139
|
+
* This is the union of all key type sets (letters, numbers, function keys, navigation,
|
|
140
|
+
* editing, and punctuation). Used primarily for validation to check if a key string
|
|
141
|
+
* is recognized and will have type-safe autocomplete support.
|
|
142
|
+
*
|
|
143
|
+
* @see {@link LETTER_KEYS}
|
|
144
|
+
* @see {@link NUMBER_KEYS}
|
|
145
|
+
* @see {@link FUNCTION_KEYS}
|
|
146
|
+
* @see {@link NAVIGATION_KEYS}
|
|
147
|
+
* @see {@link EDITING_KEYS}
|
|
148
|
+
* @see {@link PUNCTUATION_KEYS}
|
|
149
|
+
*/
|
|
150
|
+
declare const ALL_KEYS: Set<LetterKey | NumberKey | FunctionKey | NavigationKey | EditingKey | PunctuationKey>;
|
|
151
|
+
/**
|
|
152
|
+
* Normalizes a key name to its canonical form.
|
|
153
|
+
*
|
|
154
|
+
* Converts various key name formats (aliases, case variations) into the standard
|
|
155
|
+
* canonical names used throughout the library. This enables a more forgiving API
|
|
156
|
+
* where users can write keys in different ways and still get correct behavior.
|
|
157
|
+
*
|
|
158
|
+
* Normalization rules:
|
|
159
|
+
* 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')
|
|
160
|
+
* 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')
|
|
161
|
+
* 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')
|
|
162
|
+
* 4. Other keys → returned as-is (already canonical or unknown)
|
|
163
|
+
*
|
|
164
|
+
* @param key - The key name to normalize (can be an alias, lowercase, etc.)
|
|
165
|
+
* @returns The canonical key name
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* normalizeKeyName('esc') // 'Escape'
|
|
170
|
+
* normalizeKeyName('a') // 'A'
|
|
171
|
+
* normalizeKeyName('f1') // 'F1'
|
|
172
|
+
* normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function normalizeKeyName(key: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Modifier key symbols for macOS display.
|
|
178
|
+
*
|
|
179
|
+
* Used by formatting functions to display hotkeys with macOS-style symbols
|
|
180
|
+
* (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
|
|
181
|
+
* a native macOS look and feel in hotkey displays.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
|
|
186
|
+
* MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
|
|
187
|
+
* MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
|
|
188
|
+
* MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier, string>;
|
|
192
|
+
/**
|
|
193
|
+
* Modifier key labels for Windows/Linux display.
|
|
194
|
+
*
|
|
195
|
+
* Used by formatting functions to display hotkeys with standard text labels
|
|
196
|
+
* (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
|
|
197
|
+
* This provides a familiar Windows/Linux look and feel in hotkey displays.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
|
|
202
|
+
* STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
|
|
203
|
+
* STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
|
|
204
|
+
* STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare const STANDARD_MODIFIER_LABELS: Record<CanonicalModifier, string>;
|
|
208
|
+
/**
|
|
209
|
+
* Special key symbols for display formatting.
|
|
210
|
+
*
|
|
211
|
+
* Maps certain keys to their visual symbols for better readability in hotkey displays.
|
|
212
|
+
* Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
|
|
213
|
+
* instead of text labels.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
|
|
218
|
+
* KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
|
|
219
|
+
* KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
|
|
220
|
+
* KEY_DISPLAY_SYMBOLS['Space'] // '␣'
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare const KEY_DISPLAY_SYMBOLS: Record<string, string>;
|
|
224
|
+
//#endregion
|
|
225
|
+
export { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, KEY_DISPLAY_SYMBOLS, LETTER_KEYS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_KEYS, STANDARD_MODIFIER_LABELS, detectPlatform, normalizeKeyName, resolveModifier };
|
|
226
|
+
//# sourceMappingURL=constants.d.cts.map
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { CanonicalModifier, EditingKey, FunctionKey, LetterKey, NavigationKey, NumberKey, PunctuationKey } from "./hotkey.js";
|
|
2
|
+
|
|
3
|
+
//#region src/constants.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current platform based on browser navigator properties.
|
|
6
|
+
*
|
|
7
|
+
* Used internally to resolve platform-adaptive modifiers like 'Mod' (Command on Mac,
|
|
8
|
+
* Control elsewhere) and for platform-specific hotkey formatting.
|
|
9
|
+
*
|
|
10
|
+
* @returns The detected platform: 'mac', 'windows', or 'linux'
|
|
11
|
+
* @remarks Defaults to 'linux' in SSR environments where navigator is undefined
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const platform = detectPlatform() // 'mac' | 'windows' | 'linux'
|
|
16
|
+
* const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function detectPlatform(): 'mac' | 'windows' | 'linux';
|
|
20
|
+
/**
|
|
21
|
+
* Canonical order for modifiers in normalized hotkey strings.
|
|
22
|
+
*
|
|
23
|
+
* Defines the standard order in which modifiers should appear when formatting
|
|
24
|
+
* hotkeys. This ensures consistent, predictable output across the library.
|
|
25
|
+
*
|
|
26
|
+
* Order: Control → Alt → Shift → Meta
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Input: 'Shift+Control+Meta+S'
|
|
31
|
+
* // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const MODIFIER_ORDER: Array<CanonicalModifier>;
|
|
35
|
+
/**
|
|
36
|
+
* Set of canonical modifier key names for fast lookup.
|
|
37
|
+
*
|
|
38
|
+
* Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when
|
|
39
|
+
* a modifier is released so we can clear non-modifier keys whose keyup events
|
|
40
|
+
* may have been swallowed by the OS (e.g. macOS Cmd+key combos).
|
|
41
|
+
*/
|
|
42
|
+
declare const MODIFIER_KEYS: Set<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.
|
|
45
|
+
*
|
|
46
|
+
* This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')
|
|
47
|
+
* which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the
|
|
48
|
+
* platform-adaptive 'Mod' token.
|
|
49
|
+
*
|
|
50
|
+
* The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`
|
|
51
|
+
* based on the detected platform (Command on Mac, Control elsewhere).
|
|
52
|
+
*
|
|
53
|
+
* @remarks Case-insensitive lookups are supported via lowercase variants
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* MODIFIER_ALIASES['Ctrl'] // 'Control'
|
|
58
|
+
* MODIFIER_ALIASES['Cmd'] // 'Meta'
|
|
59
|
+
* MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'>;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.
|
|
65
|
+
*
|
|
66
|
+
* The 'Mod' token represents the "primary modifier" on each platform:
|
|
67
|
+
* - macOS: 'Meta' (Command key ⌘)
|
|
68
|
+
* - Windows/Linux: 'Control' (Ctrl key)
|
|
69
|
+
*
|
|
70
|
+
* This enables cross-platform hotkey definitions like 'Mod+S' that automatically
|
|
71
|
+
* map to Command+S on Mac and Ctrl+S on Windows/Linux.
|
|
72
|
+
*
|
|
73
|
+
* @param modifier - The modifier to resolve. If 'Mod', resolves based on platform.
|
|
74
|
+
* @param platform - The target platform. Defaults to auto-detection.
|
|
75
|
+
* @returns The canonical modifier name ('Control', 'Shift', 'Alt', or 'Meta')
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* resolveModifier('Mod', 'mac') // 'Meta'
|
|
80
|
+
* resolveModifier('Mod', 'windows') // 'Control'
|
|
81
|
+
* resolveModifier('Control', 'mac') // 'Control' (unchanged)
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
|
85
|
+
/**
|
|
86
|
+
* Set of all valid letter keys (A-Z).
|
|
87
|
+
*
|
|
88
|
+
* Used for validation and type checking. Letter keys are matched case-insensitively
|
|
89
|
+
* in hotkey matching, but normalized to uppercase in canonical form.
|
|
90
|
+
*/
|
|
91
|
+
declare const LETTER_KEYS: Set<LetterKey>;
|
|
92
|
+
/**
|
|
93
|
+
* Set of all valid number keys (0-9).
|
|
94
|
+
*
|
|
95
|
+
* Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),
|
|
96
|
+
* so they're excluded from Shift-based hotkey combinations to avoid
|
|
97
|
+
* layout-dependent behavior.
|
|
98
|
+
*/
|
|
99
|
+
declare const NUMBER_KEYS: Set<NumberKey>;
|
|
100
|
+
/**
|
|
101
|
+
* Set of all valid function keys (F1-F12).
|
|
102
|
+
*
|
|
103
|
+
* Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
|
|
104
|
+
* Alt+F4 to close windows) and application-specific commands.
|
|
105
|
+
*/
|
|
106
|
+
declare const FUNCTION_KEYS: Set<FunctionKey>;
|
|
107
|
+
/**
|
|
108
|
+
* Set of all valid navigation keys for cursor movement and document navigation.
|
|
109
|
+
*
|
|
110
|
+
* Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).
|
|
111
|
+
* These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or
|
|
112
|
+
* navigation shortcuts (Alt+ArrowLeft for back).
|
|
113
|
+
*/
|
|
114
|
+
declare const NAVIGATION_KEYS: Set<NavigationKey>;
|
|
115
|
+
/**
|
|
116
|
+
* Set of all valid editing and special keys.
|
|
117
|
+
*
|
|
118
|
+
* Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and
|
|
119
|
+
* special actions (Escape, Space). These keys are frequently combined with modifiers
|
|
120
|
+
* for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).
|
|
121
|
+
*/
|
|
122
|
+
declare const EDITING_KEYS: Set<EditingKey>;
|
|
123
|
+
/**
|
|
124
|
+
* Set of all valid punctuation keys commonly used in keyboard shortcuts.
|
|
125
|
+
*
|
|
126
|
+
* These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,
|
|
127
|
+
* typically US keyboard layout). Common shortcuts include:
|
|
128
|
+
* - `Mod+/` - Toggle comment
|
|
129
|
+
* - `Mod+[` / `Mod+]` - Indent/outdent
|
|
130
|
+
* - `Mod+=` / `Mod+-` - Zoom in/out
|
|
131
|
+
*
|
|
132
|
+
* Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),
|
|
133
|
+
* so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.
|
|
134
|
+
*/
|
|
135
|
+
declare const PUNCTUATION_KEYS: Set<PunctuationKey>;
|
|
136
|
+
/**
|
|
137
|
+
* Set of all valid non-modifier keys.
|
|
138
|
+
*
|
|
139
|
+
* This is the union of all key type sets (letters, numbers, function keys, navigation,
|
|
140
|
+
* editing, and punctuation). Used primarily for validation to check if a key string
|
|
141
|
+
* is recognized and will have type-safe autocomplete support.
|
|
142
|
+
*
|
|
143
|
+
* @see {@link LETTER_KEYS}
|
|
144
|
+
* @see {@link NUMBER_KEYS}
|
|
145
|
+
* @see {@link FUNCTION_KEYS}
|
|
146
|
+
* @see {@link NAVIGATION_KEYS}
|
|
147
|
+
* @see {@link EDITING_KEYS}
|
|
148
|
+
* @see {@link PUNCTUATION_KEYS}
|
|
149
|
+
*/
|
|
150
|
+
declare const ALL_KEYS: Set<LetterKey | NumberKey | FunctionKey | NavigationKey | EditingKey | PunctuationKey>;
|
|
151
|
+
/**
|
|
152
|
+
* Normalizes a key name to its canonical form.
|
|
153
|
+
*
|
|
154
|
+
* Converts various key name formats (aliases, case variations) into the standard
|
|
155
|
+
* canonical names used throughout the library. This enables a more forgiving API
|
|
156
|
+
* where users can write keys in different ways and still get correct behavior.
|
|
157
|
+
*
|
|
158
|
+
* Normalization rules:
|
|
159
|
+
* 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')
|
|
160
|
+
* 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')
|
|
161
|
+
* 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')
|
|
162
|
+
* 4. Other keys → returned as-is (already canonical or unknown)
|
|
163
|
+
*
|
|
164
|
+
* @param key - The key name to normalize (can be an alias, lowercase, etc.)
|
|
165
|
+
* @returns The canonical key name
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* normalizeKeyName('esc') // 'Escape'
|
|
170
|
+
* normalizeKeyName('a') // 'A'
|
|
171
|
+
* normalizeKeyName('f1') // 'F1'
|
|
172
|
+
* normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function normalizeKeyName(key: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Modifier key symbols for macOS display.
|
|
178
|
+
*
|
|
179
|
+
* Used by formatting functions to display hotkeys with macOS-style symbols
|
|
180
|
+
* (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
|
|
181
|
+
* a native macOS look and feel in hotkey displays.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
|
|
186
|
+
* MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
|
|
187
|
+
* MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
|
|
188
|
+
* MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier, string>;
|
|
192
|
+
/**
|
|
193
|
+
* Modifier key labels for Windows/Linux display.
|
|
194
|
+
*
|
|
195
|
+
* Used by formatting functions to display hotkeys with standard text labels
|
|
196
|
+
* (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
|
|
197
|
+
* This provides a familiar Windows/Linux look and feel in hotkey displays.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
|
|
202
|
+
* STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
|
|
203
|
+
* STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
|
|
204
|
+
* STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare const STANDARD_MODIFIER_LABELS: Record<CanonicalModifier, string>;
|
|
208
|
+
/**
|
|
209
|
+
* Special key symbols for display formatting.
|
|
210
|
+
*
|
|
211
|
+
* Maps certain keys to their visual symbols for better readability in hotkey displays.
|
|
212
|
+
* Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
|
|
213
|
+
* instead of text labels.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
|
|
218
|
+
* KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
|
|
219
|
+
* KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
|
|
220
|
+
* KEY_DISPLAY_SYMBOLS['Space'] // '␣'
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare const KEY_DISPLAY_SYMBOLS: Record<string, string>;
|
|
224
|
+
//#endregion
|
|
225
|
+
export { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, KEY_DISPLAY_SYMBOLS, LETTER_KEYS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_KEYS, STANDARD_MODIFIER_LABELS, detectPlatform, normalizeKeyName, resolveModifier };
|
|
226
|
+
//# sourceMappingURL=constants.d.ts.map
|