@tanstack/hotkeys 0.8.0 → 0.10.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.
Files changed (109) hide show
  1. package/README.md +15 -1
  2. package/dist/{manager.utils.js → _event-target.js} +2 -41
  3. package/dist/_keyboard-event.js +75 -0
  4. package/dist/_match.js +48 -0
  5. package/dist/_named-keys.d.ts +6 -0
  6. package/dist/_named-keys.js +65 -0
  7. package/dist/_recorder-chord.js +42 -0
  8. package/dist/_recording-guard.js +55 -0
  9. package/dist/_registration.js +49 -0
  10. package/dist/conflicts.d.ts +36 -0
  11. package/dist/conflicts.js +54 -0
  12. package/dist/constants.d.ts +16 -144
  13. package/dist/constants.js +55 -172
  14. package/dist/display-labels.d.ts +90 -0
  15. package/dist/display-labels.js +112 -0
  16. package/dist/format.d.ts +48 -12
  17. package/dist/format.js +35 -39
  18. package/dist/hint.d.ts +20 -0
  19. package/dist/hint.js +23 -0
  20. package/dist/hotkey-manager.d.ts +14 -12
  21. package/dist/hotkey-manager.js +70 -21
  22. package/dist/hotkey-recorder.d.ts +8 -8
  23. package/dist/hotkey-recorder.js +74 -15
  24. package/dist/hotkey-sequence-recorder.d.ts +13 -9
  25. package/dist/hotkey-sequence-recorder.js +90 -28
  26. package/dist/{hotkey.d.ts → hotkey.types.d.ts} +58 -126
  27. package/dist/index.d.ts +14 -9
  28. package/dist/index.js +10 -6
  29. package/dist/key-state-tracker.d.ts +4 -7
  30. package/dist/key-state-tracker.js +30 -27
  31. package/dist/key.types.d.ts +79 -0
  32. package/dist/match.d.ts +24 -11
  33. package/dist/match.js +19 -30
  34. package/dist/parse.d.ts +18 -15
  35. package/dist/parse.js +39 -22
  36. package/dist/platform.d.ts +41 -0
  37. package/dist/platform.js +52 -0
  38. package/dist/recorder-options.d.ts +31 -0
  39. package/dist/sequence-manager.d.ts +27 -15
  40. package/dist/sequence-manager.js +61 -30
  41. package/dist/validate.d.ts +16 -8
  42. package/dist/validate.js +8 -13
  43. package/package.json +8 -13
  44. package/dist/constants.cjs +0 -535
  45. package/dist/constants.cjs.map +0 -1
  46. package/dist/constants.d.cts +0 -290
  47. package/dist/constants.js.map +0 -1
  48. package/dist/format.cjs +0 -91
  49. package/dist/format.cjs.map +0 -1
  50. package/dist/format.d.cts +0 -60
  51. package/dist/format.js.map +0 -1
  52. package/dist/hotkey-manager.cjs +0 -383
  53. package/dist/hotkey-manager.cjs.map +0 -1
  54. package/dist/hotkey-manager.d.cts +0 -230
  55. package/dist/hotkey-manager.js.map +0 -1
  56. package/dist/hotkey-recorder.cjs +0 -179
  57. package/dist/hotkey-recorder.cjs.map +0 -1
  58. package/dist/hotkey-recorder.d.cts +0 -116
  59. package/dist/hotkey-recorder.js.map +0 -1
  60. package/dist/hotkey-sequence-recorder.cjs +0 -192
  61. package/dist/hotkey-sequence-recorder.cjs.map +0 -1
  62. package/dist/hotkey-sequence-recorder.d.cts +0 -79
  63. package/dist/hotkey-sequence-recorder.js.map +0 -1
  64. package/dist/hotkey.d.cts +0 -301
  65. package/dist/index.cjs +0 -63
  66. package/dist/index.d.cts +0 -13
  67. package/dist/key-state-tracker.cjs +0 -197
  68. package/dist/key-state-tracker.cjs.map +0 -1
  69. package/dist/key-state-tracker.d.cts +0 -107
  70. package/dist/key-state-tracker.js.map +0 -1
  71. package/dist/manager.utils.cjs +0 -115
  72. package/dist/manager.utils.cjs.map +0 -1
  73. package/dist/manager.utils.d.cts +0 -13
  74. package/dist/manager.utils.d.ts +0 -13
  75. package/dist/manager.utils.js.map +0 -1
  76. package/dist/match.cjs +0 -153
  77. package/dist/match.cjs.map +0 -1
  78. package/dist/match.d.cts +0 -85
  79. package/dist/match.js.map +0 -1
  80. package/dist/parse.cjs +0 -228
  81. package/dist/parse.cjs.map +0 -1
  82. package/dist/parse.d.cts +0 -128
  83. package/dist/parse.js.map +0 -1
  84. package/dist/recorder-chord.cjs +0 -18
  85. package/dist/recorder-chord.cjs.map +0 -1
  86. package/dist/recorder-chord.js +0 -18
  87. package/dist/recorder-chord.js.map +0 -1
  88. package/dist/sequence-manager.cjs +0 -415
  89. package/dist/sequence-manager.cjs.map +0 -1
  90. package/dist/sequence-manager.d.cts +0 -157
  91. package/dist/sequence-manager.js.map +0 -1
  92. package/dist/validate.cjs +0 -116
  93. package/dist/validate.cjs.map +0 -1
  94. package/dist/validate.d.cts +0 -56
  95. package/dist/validate.js.map +0 -1
  96. package/src/constants.ts +0 -603
  97. package/src/format.ts +0 -142
  98. package/src/hotkey-manager.ts +0 -759
  99. package/src/hotkey-recorder.ts +0 -272
  100. package/src/hotkey-sequence-recorder.ts +0 -328
  101. package/src/hotkey.ts +0 -436
  102. package/src/index.ts +0 -11
  103. package/src/key-state-tracker.ts +0 -249
  104. package/src/manager.utils.ts +0 -231
  105. package/src/match.ts +0 -259
  106. package/src/parse.ts +0 -328
  107. package/src/recorder-chord.ts +0 -25
  108. package/src/sequence-manager.ts +0 -734
  109. package/src/validate.ts +0 -171
package/src/constants.ts DELETED
@@ -1,603 +0,0 @@
1
- import type {
2
- CanonicalModifier,
3
- EditingKey,
4
- FunctionKey,
5
- LetterKey,
6
- NavigationKey,
7
- NumberKey,
8
- PunctuationKey,
9
- } from './hotkey'
10
-
11
- /**
12
- * Detects the current platform based on browser navigator properties.
13
- *
14
- * Used internally to resolve platform-adaptive modifiers like 'Mod' (Command on Mac,
15
- * Control elsewhere) and for platform-specific hotkey formatting.
16
- *
17
- * @returns The detected platform: 'mac', 'windows', or 'linux'
18
- * @remarks Defaults to 'linux' in SSR environments where navigator is undefined
19
- *
20
- * @example
21
- * ```ts
22
- * const platform = detectPlatform() // 'mac' | 'windows' | 'linux'
23
- * const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere
24
- * ```
25
- */
26
- export function detectPlatform(): 'mac' | 'windows' | 'linux' {
27
- if (typeof navigator === 'undefined') {
28
- return 'linux' // Default for SSR
29
- }
30
-
31
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
32
- const platform = navigator.platform?.toLowerCase() ?? ''
33
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
34
- const userAgent = navigator.userAgent?.toLowerCase() ?? ''
35
-
36
- if (platform.includes('mac') || userAgent.includes('mac')) {
37
- return 'mac'
38
- }
39
- if (platform.includes('win') || userAgent.includes('win')) {
40
- return 'windows'
41
- }
42
- return 'linux'
43
- }
44
-
45
- /**
46
- * Canonical order for modifiers in normalized hotkey strings.
47
- *
48
- * Defines the standard order in which modifiers should appear when formatting
49
- * hotkeys. This ensures consistent, predictable output across the library.
50
- *
51
- * Order: Control → Alt → Shift → Meta
52
- *
53
- * @example
54
- * ```ts
55
- * // Input: 'Shift+Control+Meta+S'
56
- * // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)
57
- * ```
58
- */
59
- export const MODIFIER_ORDER: Array<CanonicalModifier> = [
60
- 'Control',
61
- 'Alt',
62
- 'Shift',
63
- 'Meta',
64
- ]
65
-
66
- /**
67
- * Set of canonical modifier key names for fast lookup.
68
- *
69
- * Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when
70
- * a modifier is released so we can clear non-modifier keys whose keyup events
71
- * may have been swallowed by the OS (e.g. macOS Cmd+key combos).
72
- */
73
- export const MODIFIER_KEYS = new Set<string>(MODIFIER_ORDER)
74
-
75
- /**
76
- * Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.
77
- *
78
- * This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')
79
- * which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the
80
- * platform-adaptive 'Mod' token.
81
- *
82
- * The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`
83
- * based on the detected platform (Command on Mac, Control elsewhere).
84
- *
85
- * @remarks Case-insensitive lookups are supported via lowercase variants
86
- *
87
- * @example
88
- * ```ts
89
- * MODIFIER_ALIASES['Ctrl'] // 'Control'
90
- * MODIFIER_ALIASES['Cmd'] // 'Meta'
91
- * MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)
92
- * ```
93
- */
94
- export const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'> = {
95
- // Control variants
96
- Control: 'Control',
97
- Ctrl: 'Control',
98
- control: 'Control',
99
- ctrl: 'Control',
100
-
101
- // Shift variants
102
- Shift: 'Shift',
103
- shift: 'Shift',
104
-
105
- // Alt variants
106
- Alt: 'Alt',
107
- Option: 'Alt',
108
- alt: 'Alt',
109
- option: 'Alt',
110
-
111
- // Meta/Command variants
112
- Command: 'Meta',
113
- Cmd: 'Meta',
114
- Meta: 'Meta',
115
- command: 'Meta',
116
- cmd: 'Meta',
117
- meta: 'Meta',
118
-
119
- // DOM `KeyboardEvent.key` spellings for the meta / Windows key
120
- OS: 'Meta',
121
- os: 'Meta',
122
- Win: 'Meta',
123
- win: 'Meta',
124
-
125
- // Platform-adaptive (resolved at runtime)
126
- CommandOrControl: 'Mod',
127
- Mod: 'Mod',
128
- commandorcontrol: 'Mod',
129
- mod: 'Mod',
130
- }
131
-
132
- /**
133
- * Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.
134
- *
135
- * The 'Mod' token represents the "primary modifier" on each platform:
136
- * - macOS: 'Meta' (Command key ⌘)
137
- * - Windows/Linux: 'Control' (Ctrl key)
138
- *
139
- * This enables cross-platform hotkey definitions like 'Mod+S' that automatically
140
- * map to Command+S on Mac and Ctrl+S on Windows/Linux.
141
- *
142
- * @param modifier - The modifier to resolve. If 'Mod', resolves based on platform.
143
- * @param platform - The target platform. Defaults to auto-detection.
144
- * @returns The canonical modifier name ('Control', 'Shift', 'Alt', or 'Meta')
145
- *
146
- * @example
147
- * ```ts
148
- * resolveModifier('Mod', 'mac') // 'Meta'
149
- * resolveModifier('Mod', 'windows') // 'Control'
150
- * resolveModifier('Control', 'mac') // 'Control' (unchanged)
151
- * ```
152
- */
153
- export function resolveModifier(
154
- modifier: CanonicalModifier | 'Mod',
155
- platform: 'mac' | 'windows' | 'linux' = detectPlatform(),
156
- ): CanonicalModifier {
157
- if (modifier === 'Mod') {
158
- return platform === 'mac' ? 'Meta' : 'Control'
159
- }
160
- return modifier
161
- }
162
-
163
- /**
164
- * Set of all valid letter keys (A-Z).
165
- *
166
- * Used for validation and type checking. Letter keys are matched case-insensitively
167
- * in hotkey matching, but normalized to uppercase in canonical form.
168
- */
169
- export const LETTER_KEYS = new Set<LetterKey>([
170
- 'A',
171
- 'B',
172
- 'C',
173
- 'D',
174
- 'E',
175
- 'F',
176
- 'G',
177
- 'H',
178
- 'I',
179
- 'J',
180
- 'K',
181
- 'L',
182
- 'M',
183
- 'N',
184
- 'O',
185
- 'P',
186
- 'Q',
187
- 'R',
188
- 'S',
189
- 'T',
190
- 'U',
191
- 'V',
192
- 'W',
193
- 'X',
194
- 'Y',
195
- 'Z',
196
- ])
197
-
198
- /**
199
- * Set of all valid number keys (0-9).
200
- *
201
- * Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),
202
- * so they're excluded from Shift-based hotkey combinations to avoid
203
- * layout-dependent behavior.
204
- */
205
- export const NUMBER_KEYS = new Set<NumberKey>([
206
- '0',
207
- '1',
208
- '2',
209
- '3',
210
- '4',
211
- '5',
212
- '6',
213
- '7',
214
- '8',
215
- '9',
216
- ])
217
-
218
- /**
219
- * Set of all valid function keys (F1-F12).
220
- *
221
- * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
222
- * Alt+F4 to close windows) and application-specific commands.
223
- */
224
- export const FUNCTION_KEYS = new Set<FunctionKey>([
225
- 'F1',
226
- 'F2',
227
- 'F3',
228
- 'F4',
229
- 'F5',
230
- 'F6',
231
- 'F7',
232
- 'F8',
233
- 'F9',
234
- 'F10',
235
- 'F11',
236
- 'F12',
237
- ])
238
-
239
- /**
240
- * Set of all valid navigation keys for cursor movement and document navigation.
241
- *
242
- * Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).
243
- * These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or
244
- * navigation shortcuts (Alt+ArrowLeft for back).
245
- */
246
- export const NAVIGATION_KEYS = new Set<NavigationKey>([
247
- 'ArrowUp',
248
- 'ArrowDown',
249
- 'ArrowLeft',
250
- 'ArrowRight',
251
- 'Home',
252
- 'End',
253
- 'PageUp',
254
- 'PageDown',
255
- ])
256
-
257
- /**
258
- * Set of all valid editing and special keys.
259
- *
260
- * Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and
261
- * special actions (Escape, Space). These keys are frequently combined with modifiers
262
- * for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).
263
- */
264
- export const EDITING_KEYS = new Set<EditingKey>([
265
- 'Enter',
266
- 'Escape',
267
- 'Space',
268
- 'Tab',
269
- 'Backspace',
270
- 'Delete',
271
- ])
272
-
273
- /**
274
- * Set of all valid punctuation keys commonly used in keyboard shortcuts.
275
- *
276
- * These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,
277
- * typically US keyboard layout). Common shortcuts include:
278
- * - `Mod+/` - Toggle comment
279
- * - `Mod+[` / `Mod+]` - Indent/outdent
280
- * - `Mod+=` / `Mod+-` - Zoom in/out
281
- *
282
- * Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),
283
- * so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.
284
- */
285
- export const PUNCTUATION_KEYS = new Set<PunctuationKey>([
286
- '/',
287
- '[',
288
- ']',
289
- '\\',
290
- '=',
291
- '-',
292
- ',',
293
- '.',
294
- ';',
295
- '`',
296
- ])
297
-
298
- /**
299
- * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.
300
- *
301
- * On macOS, holding the Option (Alt) key transforms punctuation keys into special characters
302
- * (e.g., Option+Minus → en-dash '–'), causing `event.key` to differ from the expected character.
303
- * However, `event.code` still reports the physical key (e.g., 'Minus'). This map enables
304
- * falling back to `event.code` for punctuation keys, similar to the existing `Key*`/`Digit*`
305
- * fallbacks for letters and digits.
306
- */
307
- export const PUNCTUATION_CODE_MAP: Record<string, string> = {
308
- Backquote: '`',
309
- Backslash: '\\',
310
- BracketLeft: '[',
311
- BracketRight: ']',
312
- Comma: ',',
313
- Equal: '=',
314
- Minus: '-',
315
- Period: '.',
316
- Semicolon: ';',
317
- Slash: '/',
318
- }
319
-
320
- /**
321
- * Set of all valid non-modifier keys.
322
- *
323
- * This is the union of all key type sets (letters, numbers, function keys, navigation,
324
- * editing, and punctuation). Used primarily for validation to check if a key string
325
- * is recognized and will have type-safe autocomplete support.
326
- *
327
- * @see {@link LETTER_KEYS}
328
- * @see {@link NUMBER_KEYS}
329
- * @see {@link FUNCTION_KEYS}
330
- * @see {@link NAVIGATION_KEYS}
331
- * @see {@link EDITING_KEYS}
332
- * @see {@link PUNCTUATION_KEYS}
333
- */
334
- export const ALL_KEYS = new Set([
335
- ...LETTER_KEYS,
336
- ...NUMBER_KEYS,
337
- ...FUNCTION_KEYS,
338
- ...NAVIGATION_KEYS,
339
- ...EDITING_KEYS,
340
- ...PUNCTUATION_KEYS,
341
- ])
342
-
343
- /**
344
- * Maps key name aliases to their canonical form.
345
- *
346
- * Handles common variations and alternative names for keys to provide a more
347
- * forgiving API. For example, users can write 'Esc', 'esc', or 'escape' and
348
- * they'll all normalize to 'Escape'.
349
- *
350
- * This map is used internally by `normalizeKeyName()` to convert user input
351
- * into the canonical key names used throughout the library.
352
- *
353
- * @remarks Case-insensitive lookups are supported via lowercase variants
354
- *
355
- * @example
356
- * ```ts
357
- * KEY_ALIASES['Esc'] // 'Escape'
358
- * KEY_ALIASES['Del'] // 'Delete'
359
- * KEY_ALIASES['Up'] // 'ArrowUp'
360
- * ```
361
- */
362
- const KEY_ALIASES: Record<string, string> = {
363
- // Escape variants
364
- Esc: 'Escape',
365
- esc: 'Escape',
366
- escape: 'Escape',
367
-
368
- // Enter variants
369
- Return: 'Enter',
370
- return: 'Enter',
371
- enter: 'Enter',
372
-
373
- // Space variants
374
- ' ': 'Space',
375
- space: 'Space',
376
- Spacebar: 'Space',
377
- spacebar: 'Space',
378
-
379
- // Tab variants
380
- tab: 'Tab',
381
-
382
- // Backspace variants
383
- backspace: 'Backspace',
384
-
385
- // Delete variants
386
- Del: 'Delete',
387
- del: 'Delete',
388
- delete: 'Delete',
389
-
390
- // Arrow key variants
391
- Up: 'ArrowUp',
392
- up: 'ArrowUp',
393
- arrowup: 'ArrowUp',
394
- Down: 'ArrowDown',
395
- down: 'ArrowDown',
396
- arrowdown: 'ArrowDown',
397
- Left: 'ArrowLeft',
398
- left: 'ArrowLeft',
399
- arrowleft: 'ArrowLeft',
400
- Right: 'ArrowRight',
401
- right: 'ArrowRight',
402
- arrowright: 'ArrowRight',
403
-
404
- // Navigation variants
405
- home: 'Home',
406
- end: 'End',
407
- pageup: 'PageUp',
408
- pagedown: 'PageDown',
409
- PgUp: 'PageUp',
410
- PgDn: 'PageDown',
411
- pgup: 'PageUp',
412
- pgdn: 'PageDown',
413
- }
414
-
415
- /**
416
- * Normalizes a key name to its canonical form.
417
- *
418
- * Converts various key name formats (aliases, case variations) into the standard
419
- * canonical names used throughout the library. This enables a more forgiving API
420
- * where users can write keys in different ways and still get correct behavior.
421
- *
422
- * Normalization rules:
423
- * 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')
424
- * 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')
425
- * 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')
426
- * 4. Other keys → returned as-is (already canonical or unknown)
427
- *
428
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
429
- * @returns The canonical key name
430
- *
431
- * @example
432
- * ```ts
433
- * normalizeKeyName('esc') // 'Escape'
434
- * normalizeKeyName('a') // 'A'
435
- * normalizeKeyName('f1') // 'F1'
436
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
437
- * ```
438
- */
439
- export function isSingleLetterKey(key: string): boolean {
440
- return /^\p{Letter}$/u.test(key)
441
- }
442
-
443
- /**
444
- * Normalizes a key name to its canonical form.
445
- *
446
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
447
- * @returns The canonical key name
448
- *
449
- * @example
450
- * ```ts
451
- * normalizeKeyName('esc') // 'Escape'
452
- * normalizeKeyName('a') // 'A'
453
- * normalizeKeyName('f1') // 'F1'
454
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
455
- * ```
456
- */
457
- export function normalizeKeyName(key: string): string {
458
- // key can be undefined in rare cases
459
- // (browser extensions synthesizing key events, accessibility tools, certain OS/browser combinations).
460
- if (!key) return ''
461
- // Check aliases first
462
- if (key in KEY_ALIASES) {
463
- return KEY_ALIASES[key]!
464
- }
465
-
466
- if (isSingleLetterKey(key)) {
467
- const upper = key.toUpperCase()
468
- // Some Unicode letters (e.g., 'ß') uppercase to multi-character sequences
469
- // ('SS'). Avoid changing the string length so the rest of the matching
470
- // logic can rely on a stable single-character key value.
471
- return upper.length === 1 ? upper : key
472
- }
473
-
474
- // Check if it's a function key (normalize case)
475
- const upperKey = key.toUpperCase()
476
- if (/^F([1-9]|1[0-2])$/.test(upperKey)) {
477
- return upperKey
478
- }
479
-
480
- return key
481
- }
482
-
483
- // =============================================================================
484
- // Display Symbols
485
- // =============================================================================
486
-
487
- /**
488
- * Modifier key symbols for macOS display.
489
- *
490
- * Used by formatting functions to display hotkeys with macOS-style symbols
491
- * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
492
- * a native macOS look and feel in hotkey displays.
493
- *
494
- * @example
495
- * ```ts
496
- * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
497
- * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
498
- * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
499
- * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
500
- * ```
501
- */
502
- export const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier | 'Mod', string> = {
503
- Control: '⌃',
504
- Alt: '⌥',
505
- Shift: '⇧',
506
- Meta: '⌘',
507
- Mod: '⌘',
508
- }
509
-
510
- /**
511
- * Modifier key labels for macOS display.
512
- *
513
- * Used by formatting functions to display hotkeys with macOS-style text labels
514
- * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.
515
- * This provides a familiar macOS look and feel in hotkey displays.
516
- *
517
- * @example
518
- * ```ts
519
- * MAC_MODIFIER_LABELS['Control'] // 'control'
520
- * MAC_MODIFIER_LABELS['Alt'] // 'option'
521
- * MAC_MODIFIER_LABELS['Shift'] // 'shift'
522
- * MAC_MODIFIER_LABELS['Meta'] // 'cmd'
523
- * ```
524
- */
525
- export const MAC_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> = {
526
- Control: 'Control',
527
- Alt: 'Option',
528
- Shift: 'Shift',
529
- Meta: 'Cmd',
530
- Mod: 'Cmd',
531
- }
532
-
533
- /**
534
- * Modifier key labels for Windows/Linux display.
535
- *
536
- * Used by formatting functions to display hotkeys with standard text labels
537
- * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
538
- * This provides a familiar Windows/Linux look and feel in hotkey displays.
539
- *
540
- * @example
541
- * ```ts
542
- * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
543
- * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
544
- * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
545
- * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
546
- * ```
547
- */
548
- export const WINDOWS_MODIFIER_LABELS: Record<
549
- CanonicalModifier | 'Mod',
550
- string
551
- > = {
552
- Control: 'Ctrl',
553
- Alt: 'Alt',
554
- Shift: 'Shift',
555
- Meta: 'Win',
556
- Mod: 'Ctrl',
557
- }
558
-
559
- export const LINUX_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> =
560
- {
561
- ...WINDOWS_MODIFIER_LABELS,
562
- Meta: 'Super',
563
- }
564
-
565
- export const PUNCTUATION_KEY_DISPLAY_LABELS = {
566
- '`': 'Backquote',
567
- '\\': 'Backslash',
568
- '[': 'Left Bracket',
569
- ']': 'Right Bracket',
570
- ',': 'Comma',
571
- '=': 'Equal',
572
- '-': 'Minus',
573
- '.': 'Period',
574
- ';': 'Semicolon',
575
- } as const satisfies Record<string, string>
576
-
577
- /**
578
- * Special key symbols for display formatting.
579
- *
580
- * Maps certain keys to their visual symbols for better readability in hotkey displays.
581
- * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
582
- * instead of text labels.
583
- *
584
- * @example
585
- * ```ts
586
- * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
587
- * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
588
- * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
589
- * KEY_DISPLAY_SYMBOLS['Space'] // '␣'
590
- * ```
591
- */
592
- export const KEY_DISPLAY_SYMBOLS = {
593
- ArrowUp: '↑',
594
- ArrowDown: '↓',
595
- ArrowLeft: '←',
596
- ArrowRight: '→',
597
- Enter: '↵',
598
- Escape: 'Esc',
599
- Backspace: '⌫',
600
- Delete: '⌦',
601
- Tab: '⇥',
602
- Space: '␣',
603
- } as const satisfies Record<string, string>