@tanstack/hotkeys 0.9.0 → 0.10.1

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 (148) hide show
  1. package/dist/_event-target.js +1 -2
  2. package/dist/_keyboard-event.js +1 -2
  3. package/dist/_match.js +1 -2
  4. package/dist/_named-keys.d.ts +3 -5
  5. package/dist/_named-keys.js +1 -2
  6. package/dist/_recorder-chord.js +1 -2
  7. package/dist/_recording-guard.js +1 -2
  8. package/dist/_registration.js +1 -2
  9. package/dist/conflicts.d.ts +4 -7
  10. package/dist/conflicts.js +1 -2
  11. package/dist/constants.d.ts +14 -17
  12. package/dist/constants.js +8 -9
  13. package/dist/display-labels.d.ts +7 -10
  14. package/dist/display-labels.js +1 -2
  15. package/dist/format.d.ts +12 -14
  16. package/dist/format.js +17 -7
  17. package/dist/hint.d.ts +3 -6
  18. package/dist/hint.js +1 -2
  19. package/dist/hotkey-manager.d.ts +8 -10
  20. package/dist/hotkey-manager.js +21 -3
  21. package/dist/hotkey-recorder.d.ts +4 -7
  22. package/dist/hotkey-recorder.js +9 -6
  23. package/dist/hotkey-sequence-recorder.d.ts +5 -8
  24. package/dist/hotkey-sequence-recorder.js +6 -7
  25. package/dist/hotkey.types.d.ts +15 -18
  26. package/dist/key-state-tracker.d.ts +4 -7
  27. package/dist/key-state-tracker.js +6 -3
  28. package/dist/key.types.d.ts +17 -20
  29. package/dist/match.d.ts +8 -11
  30. package/dist/match.js +1 -2
  31. package/dist/parse.d.ts +11 -14
  32. package/dist/parse.js +5 -4
  33. package/dist/platform.d.ts +3 -6
  34. package/dist/platform.js +1 -2
  35. package/dist/recorder-options.d.ts +6 -9
  36. package/dist/sequence-manager.d.ts +11 -14
  37. package/dist/sequence-manager.js +12 -7
  38. package/dist/validate.d.ts +5 -8
  39. package/dist/validate.js +1 -2
  40. package/package.json +8 -13
  41. package/dist/_event-target.cjs +0 -73
  42. package/dist/_event-target.cjs.map +0 -1
  43. package/dist/_event-target.js.map +0 -1
  44. package/dist/_keyboard-event.cjs +0 -83
  45. package/dist/_keyboard-event.cjs.map +0 -1
  46. package/dist/_keyboard-event.js.map +0 -1
  47. package/dist/_match.cjs +0 -49
  48. package/dist/_match.cjs.map +0 -1
  49. package/dist/_match.js.map +0 -1
  50. package/dist/_named-keys.cjs +0 -68
  51. package/dist/_named-keys.cjs.map +0 -1
  52. package/dist/_named-keys.d.cts +0 -8
  53. package/dist/_named-keys.js.map +0 -1
  54. package/dist/_recorder-chord.cjs +0 -44
  55. package/dist/_recorder-chord.cjs.map +0 -1
  56. package/dist/_recorder-chord.js.map +0 -1
  57. package/dist/_recording-guard.cjs +0 -59
  58. package/dist/_recording-guard.cjs.map +0 -1
  59. package/dist/_recording-guard.js.map +0 -1
  60. package/dist/_registration.cjs +0 -54
  61. package/dist/_registration.cjs.map +0 -1
  62. package/dist/_registration.js.map +0 -1
  63. package/dist/conflicts.cjs +0 -55
  64. package/dist/conflicts.cjs.map +0 -1
  65. package/dist/conflicts.d.cts +0 -39
  66. package/dist/conflicts.js.map +0 -1
  67. package/dist/constants.cjs +0 -410
  68. package/dist/constants.cjs.map +0 -1
  69. package/dist/constants.d.cts +0 -165
  70. package/dist/constants.js.map +0 -1
  71. package/dist/display-labels.cjs +0 -119
  72. package/dist/display-labels.cjs.map +0 -1
  73. package/dist/display-labels.d.cts +0 -93
  74. package/dist/display-labels.js.map +0 -1
  75. package/dist/format.cjs +0 -85
  76. package/dist/format.cjs.map +0 -1
  77. package/dist/format.d.cts +0 -99
  78. package/dist/format.js.map +0 -1
  79. package/dist/hint.cjs +0 -24
  80. package/dist/hint.cjs.map +0 -1
  81. package/dist/hint.d.cts +0 -23
  82. package/dist/hint.js.map +0 -1
  83. package/dist/hotkey-manager.cjs +0 -414
  84. package/dist/hotkey-manager.cjs.map +0 -1
  85. package/dist/hotkey-manager.d.cts +0 -234
  86. package/dist/hotkey-manager.js.map +0 -1
  87. package/dist/hotkey-recorder.cjs +0 -235
  88. package/dist/hotkey-recorder.cjs.map +0 -1
  89. package/dist/hotkey-recorder.d.cts +0 -119
  90. package/dist/hotkey-recorder.js.map +0 -1
  91. package/dist/hotkey-sequence-recorder.cjs +0 -255
  92. package/dist/hotkey-sequence-recorder.cjs.map +0 -1
  93. package/dist/hotkey-sequence-recorder.d.cts +0 -86
  94. package/dist/hotkey-sequence-recorder.js.map +0 -1
  95. package/dist/hotkey.types.d.cts +0 -236
  96. package/dist/index.cjs +0 -71
  97. package/dist/index.d.cts +0 -18
  98. package/dist/key-state-tracker.cjs +0 -197
  99. package/dist/key-state-tracker.cjs.map +0 -1
  100. package/dist/key-state-tracker.d.cts +0 -107
  101. package/dist/key-state-tracker.js.map +0 -1
  102. package/dist/key.types.d.cts +0 -82
  103. package/dist/match.cjs +0 -144
  104. package/dist/match.cjs.map +0 -1
  105. package/dist/match.d.cts +0 -101
  106. package/dist/match.js.map +0 -1
  107. package/dist/parse.cjs +0 -245
  108. package/dist/parse.cjs.map +0 -1
  109. package/dist/parse.d.cts +0 -134
  110. package/dist/parse.js.map +0 -1
  111. package/dist/platform.cjs +0 -55
  112. package/dist/platform.cjs.map +0 -1
  113. package/dist/platform.d.cts +0 -44
  114. package/dist/platform.js.map +0 -1
  115. package/dist/recorder-options.d.cts +0 -34
  116. package/dist/sequence-manager.cjs +0 -441
  117. package/dist/sequence-manager.cjs.map +0 -1
  118. package/dist/sequence-manager.d.cts +0 -172
  119. package/dist/sequence-manager.js.map +0 -1
  120. package/dist/validate.cjs +0 -112
  121. package/dist/validate.cjs.map +0 -1
  122. package/dist/validate.d.cts +0 -67
  123. package/dist/validate.js.map +0 -1
  124. package/src/_event-target.ts +0 -157
  125. package/src/_keyboard-event.ts +0 -101
  126. package/src/_match.ts +0 -96
  127. package/src/_named-keys.ts +0 -62
  128. package/src/_recorder-chord.ts +0 -76
  129. package/src/_recording-guard.ts +0 -63
  130. package/src/_registration.ts +0 -79
  131. package/src/conflicts.ts +0 -125
  132. package/src/constants.ts +0 -455
  133. package/src/display-labels.ts +0 -123
  134. package/src/format.ts +0 -201
  135. package/src/hint.ts +0 -42
  136. package/src/hotkey-manager.ts +0 -814
  137. package/src/hotkey-recorder.ts +0 -348
  138. package/src/hotkey-sequence-recorder.ts +0 -410
  139. package/src/hotkey.types.ts +0 -269
  140. package/src/index.ts +0 -17
  141. package/src/key-state-tracker.ts +0 -261
  142. package/src/key.types.ts +0 -268
  143. package/src/match.ts +0 -210
  144. package/src/parse.ts +0 -369
  145. package/src/platform.ts +0 -66
  146. package/src/recorder-options.ts +0 -34
  147. package/src/sequence-manager.ts +0 -769
  148. package/src/validate.ts +0 -179
@@ -1,410 +0,0 @@
1
- const require__named_keys = require('./_named-keys.cjs');
2
-
3
- //#region src/constants.ts
4
- /**
5
- * Canonical order for modifiers in normalized hotkey strings.
6
- *
7
- * Defines the standard order in which modifiers should appear when formatting
8
- * hotkeys. This ensures consistent, predictable output across the library.
9
- *
10
- * Order: Control → Alt → Shift → Meta
11
- *
12
- * @example
13
- * ```ts
14
- * // Input: 'Shift+Control+Meta+S'
15
- * // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)
16
- * ```
17
- */
18
- const MODIFIER_ORDER = [
19
- "Control",
20
- "Alt",
21
- "Shift",
22
- "Meta"
23
- ];
24
- /**
25
- * Set of canonical modifier key names for fast lookup.
26
- *
27
- * Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when
28
- * a modifier is released so we can clear non-modifier keys whose keyup events
29
- * may have been swallowed by the OS (e.g. macOS Cmd+key combos).
30
- */
31
- const MODIFIER_KEYS = new Set(MODIFIER_ORDER);
32
- /**
33
- * Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.
34
- *
35
- * This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')
36
- * which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the
37
- * platform-adaptive 'Mod' token.
38
- *
39
- * The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`
40
- * based on the detected platform (Command on Mac, Control elsewhere).
41
- *
42
- * @remarks Case-insensitive lookups are supported via lowercase variants
43
- *
44
- * @example
45
- * ```ts
46
- * MODIFIER_ALIASES['Ctrl'] // 'Control'
47
- * MODIFIER_ALIASES['Cmd'] // 'Meta'
48
- * MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)
49
- * ```
50
- */
51
- const MODIFIER_ALIASES = {
52
- Control: "Control",
53
- Ctrl: "Control",
54
- control: "Control",
55
- ctrl: "Control",
56
- Shift: "Shift",
57
- shift: "Shift",
58
- Alt: "Alt",
59
- Option: "Alt",
60
- alt: "Alt",
61
- option: "Alt",
62
- Command: "Meta",
63
- Cmd: "Meta",
64
- Meta: "Meta",
65
- command: "Meta",
66
- cmd: "Meta",
67
- meta: "Meta",
68
- OS: "Meta",
69
- os: "Meta",
70
- Win: "Meta",
71
- win: "Meta",
72
- CommandOrControl: "Mod",
73
- Mod: "Mod",
74
- commandorcontrol: "Mod",
75
- mod: "Mod"
76
- };
77
- /**
78
- * Set of all valid letter keys (A-Z).
79
- *
80
- * Used for validation and type checking. Letter keys are matched case-insensitively
81
- * in hotkey matching, but normalized to uppercase in canonical form.
82
- */
83
- const LETTER_KEYS = new Set([
84
- "A",
85
- "B",
86
- "C",
87
- "D",
88
- "E",
89
- "F",
90
- "G",
91
- "H",
92
- "I",
93
- "J",
94
- "K",
95
- "L",
96
- "M",
97
- "N",
98
- "O",
99
- "P",
100
- "Q",
101
- "R",
102
- "S",
103
- "T",
104
- "U",
105
- "V",
106
- "W",
107
- "X",
108
- "Y",
109
- "Z"
110
- ]);
111
- /**
112
- * Set of all valid number keys (0-9).
113
- *
114
- * Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),
115
- * so they're excluded from Shift-based hotkey combinations to avoid
116
- * layout-dependent behavior.
117
- */
118
- const NUMBER_KEYS = new Set([
119
- "0",
120
- "1",
121
- "2",
122
- "3",
123
- "4",
124
- "5",
125
- "6",
126
- "7",
127
- "8",
128
- "9"
129
- ]);
130
- /**
131
- * Set of all valid function keys (F1-F24).
132
- *
133
- * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
134
- * Alt+F4 to close windows) and application-specific commands.
135
- */
136
- const FUNCTION_KEYS = new Set([
137
- "F1",
138
- "F2",
139
- "F3",
140
- "F4",
141
- "F5",
142
- "F6",
143
- "F7",
144
- "F8",
145
- "F9",
146
- "F10",
147
- "F11",
148
- "F12",
149
- "F13",
150
- "F14",
151
- "F15",
152
- "F16",
153
- "F17",
154
- "F18",
155
- "F19",
156
- "F20",
157
- "F21",
158
- "F22",
159
- "F23",
160
- "F24"
161
- ]);
162
- /**
163
- * Set of all valid navigation keys for cursor movement and document navigation.
164
- *
165
- * Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).
166
- * These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or
167
- * navigation shortcuts (Alt+ArrowLeft for back).
168
- */
169
- const NAVIGATION_KEYS = new Set([
170
- "ArrowUp",
171
- "ArrowDown",
172
- "ArrowLeft",
173
- "ArrowRight",
174
- "Home",
175
- "End",
176
- "PageUp",
177
- "PageDown"
178
- ]);
179
- /**
180
- * Set of all valid editing and special keys.
181
- *
182
- * Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and
183
- * special actions (Escape, Space). These keys are frequently combined with modifiers
184
- * for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).
185
- */
186
- const EDITING_KEYS = new Set([
187
- "Enter",
188
- "Escape",
189
- "Space",
190
- "Tab",
191
- "Backspace",
192
- "Delete"
193
- ]);
194
- /**
195
- * Set of all valid punctuation keys commonly used in keyboard shortcuts.
196
- *
197
- * These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,
198
- * typically US keyboard layout). Common shortcuts include:
199
- * - `Mod+/` - Toggle comment
200
- * - `Mod+[` / `Mod+]` - Indent/outdent
201
- * - `Mod+=` / `Mod+-` - Zoom in/out
202
- *
203
- * Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),
204
- * so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.
205
- */
206
- const PUNCTUATION_KEYS = new Set([
207
- "/",
208
- "[",
209
- "]",
210
- "\\",
211
- "=",
212
- "-",
213
- ",",
214
- ".",
215
- ";",
216
- "`",
217
- "'",
218
- "+",
219
- "?",
220
- "!",
221
- "@",
222
- "#",
223
- "$",
224
- "%",
225
- "^",
226
- "&",
227
- "*",
228
- "(",
229
- ")",
230
- "_",
231
- "{",
232
- "}",
233
- "|",
234
- ":",
235
- "\"",
236
- "<",
237
- ">",
238
- "~"
239
- ]);
240
- /**
241
- * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.
242
- *
243
- * On macOS, holding the Option (Alt) key transforms punctuation keys into special characters
244
- * (e.g., Option+Minus → en-dash '–'), causing `event.key` to differ from the expected character.
245
- * However, `event.code` still reports the physical key (e.g., 'Minus'). This map enables
246
- * falling back to `event.code` for punctuation keys, similar to the existing `Key*`/`Digit*`
247
- * fallbacks for letters and digits.
248
- */
249
- const PUNCTUATION_CODE_MAP = {
250
- Backquote: "`",
251
- Backslash: "\\",
252
- BracketLeft: "[",
253
- BracketRight: "]",
254
- Comma: ",",
255
- Equal: "=",
256
- Minus: "-",
257
- Period: ".",
258
- Quote: "'",
259
- Semicolon: ";",
260
- Slash: "/"
261
- };
262
- /**
263
- * Set of all valid non-modifier keys.
264
- *
265
- * This is the union of all key type sets (letters, numbers, function keys, navigation,
266
- * editing, and punctuation). Used primarily for validation to check if a key string
267
- * is recognized and will have type-safe autocomplete support.
268
- *
269
- * @see {@link LETTER_KEYS}
270
- * @see {@link NUMBER_KEYS}
271
- * @see {@link FUNCTION_KEYS}
272
- * @see {@link NAVIGATION_KEYS}
273
- * @see {@link EDITING_KEYS}
274
- * @see {@link PUNCTUATION_KEYS}
275
- */
276
- const ALL_KEYS = new Set([
277
- ...LETTER_KEYS,
278
- ...NUMBER_KEYS,
279
- ...FUNCTION_KEYS,
280
- ...NAVIGATION_KEYS,
281
- ...EDITING_KEYS,
282
- ...PUNCTUATION_KEYS,
283
- ...require__named_keys.SHARED_NAMED_KEYS,
284
- ...require__named_keys.LOGICAL_ONLY_NAMED_KEYS
285
- ]);
286
- const CANONICAL_KEY_NAMES = new Map(Array.from(ALL_KEYS, (key) => [key.toLowerCase(), key]));
287
- /**
288
- * Maps key name aliases to their canonical form.
289
- *
290
- * Handles common variations and alternative names for keys to provide a more
291
- * forgiving API. For example, users can write 'Esc', 'esc', or 'escape' and
292
- * they'll all normalize to 'Escape'.
293
- *
294
- * This map is used internally by `normalizeKeyName()` to convert user input
295
- * into the canonical key names used throughout the library.
296
- *
297
- * @remarks Case-insensitive lookups are supported via lowercase variants
298
- *
299
- * @example
300
- * ```ts
301
- * KEY_ALIASES['Esc'] // 'Escape'
302
- * KEY_ALIASES['Del'] // 'Delete'
303
- * KEY_ALIASES['Up'] // 'ArrowUp'
304
- * ```
305
- */
306
- const KEY_ALIASES = {
307
- Plus: "+",
308
- plus: "+",
309
- Esc: "Escape",
310
- esc: "Escape",
311
- escape: "Escape",
312
- Return: "Enter",
313
- return: "Enter",
314
- enter: "Enter",
315
- " ": "Space",
316
- space: "Space",
317
- Spacebar: "Space",
318
- spacebar: "Space",
319
- tab: "Tab",
320
- backspace: "Backspace",
321
- Del: "Delete",
322
- del: "Delete",
323
- delete: "Delete",
324
- Up: "ArrowUp",
325
- up: "ArrowUp",
326
- arrowup: "ArrowUp",
327
- Down: "ArrowDown",
328
- down: "ArrowDown",
329
- arrowdown: "ArrowDown",
330
- Left: "ArrowLeft",
331
- left: "ArrowLeft",
332
- arrowleft: "ArrowLeft",
333
- Right: "ArrowRight",
334
- right: "ArrowRight",
335
- arrowright: "ArrowRight",
336
- home: "Home",
337
- end: "End",
338
- pageup: "PageUp",
339
- pagedown: "PageDown",
340
- PgUp: "PageUp",
341
- PgDn: "PageDown",
342
- pgup: "PageUp",
343
- pgdn: "PageDown"
344
- };
345
- /**
346
- * Normalizes a key name to its canonical form.
347
- *
348
- * Converts various key name formats (aliases, case variations) into the standard
349
- * canonical names used throughout the library. This enables a more forgiving API
350
- * where users can write keys in different ways and still get correct behavior.
351
- *
352
- * Normalization rules:
353
- * 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')
354
- * 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')
355
- * 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')
356
- * 4. Other keys → returned as-is (already canonical or unknown)
357
- *
358
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
359
- * @returns The canonical key name
360
- *
361
- * @example
362
- * ```ts
363
- * normalizeKeyName('esc') // 'Escape'
364
- * normalizeKeyName('a') // 'A'
365
- * normalizeKeyName('f1') // 'F1'
366
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
367
- * ```
368
- */
369
- function isSingleLetterKey(key) {
370
- return /^\p{Letter}$/u.test(key);
371
- }
372
- /**
373
- * Normalizes a key name to its canonical form.
374
- *
375
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
376
- * @returns The canonical key name
377
- *
378
- * @example
379
- * ```ts
380
- * normalizeKeyName('esc') // 'Escape'
381
- * normalizeKeyName('a') // 'A'
382
- * normalizeKeyName('f1') // 'F1'
383
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
384
- * ```
385
- */
386
- function normalizeKeyName(key) {
387
- if (!key) return "";
388
- if (key in KEY_ALIASES) return KEY_ALIASES[key];
389
- if (isSingleLetterKey(key)) {
390
- const upper = key.toUpperCase();
391
- return upper.length === 1 ? upper : key;
392
- }
393
- return CANONICAL_KEY_NAMES.get(key.toLowerCase()) ?? key;
394
- }
395
-
396
- //#endregion
397
- exports.ALL_KEYS = ALL_KEYS;
398
- exports.EDITING_KEYS = EDITING_KEYS;
399
- exports.FUNCTION_KEYS = FUNCTION_KEYS;
400
- exports.LETTER_KEYS = LETTER_KEYS;
401
- exports.MODIFIER_ALIASES = MODIFIER_ALIASES;
402
- exports.MODIFIER_KEYS = MODIFIER_KEYS;
403
- exports.MODIFIER_ORDER = MODIFIER_ORDER;
404
- exports.NAVIGATION_KEYS = NAVIGATION_KEYS;
405
- exports.NUMBER_KEYS = NUMBER_KEYS;
406
- exports.PUNCTUATION_CODE_MAP = PUNCTUATION_CODE_MAP;
407
- exports.PUNCTUATION_KEYS = PUNCTUATION_KEYS;
408
- exports.isSingleLetterKey = isSingleLetterKey;
409
- exports.normalizeKeyName = normalizeKeyName;
410
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","names":["SHARED_NAMED_KEYS","LOGICAL_ONLY_NAMED_KEYS"],"sources":["../src/constants.ts"],"sourcesContent":["import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from './_named-keys'\nimport type {\n CanonicalModifier,\n EditingKey,\n FunctionKey,\n LetterKey,\n NavigationKey,\n NumberKey,\n PunctuationKey,\n} from './key.types'\n\n/**\n * Canonical order for modifiers in normalized hotkey strings.\n *\n * Defines the standard order in which modifiers should appear when formatting\n * hotkeys. This ensures consistent, predictable output across the library.\n *\n * Order: Control → Alt → Shift → Meta\n *\n * @example\n * ```ts\n * // Input: 'Shift+Control+Meta+S'\n * // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)\n * ```\n */\nexport const MODIFIER_ORDER: Array<CanonicalModifier> = [\n 'Control',\n 'Alt',\n 'Shift',\n 'Meta',\n]\n\n/**\n * Set of canonical modifier key names for fast lookup.\n *\n * Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when\n * a modifier is released so we can clear non-modifier keys whose keyup events\n * may have been swallowed by the OS (e.g. macOS Cmd+key combos).\n */\nexport const MODIFIER_KEYS = new Set<string>(MODIFIER_ORDER)\n\n/**\n * Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.\n *\n * This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')\n * which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the\n * platform-adaptive 'Mod' token.\n *\n * The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`\n * based on the detected platform (Command on Mac, Control elsewhere).\n *\n * @remarks Case-insensitive lookups are supported via lowercase variants\n *\n * @example\n * ```ts\n * MODIFIER_ALIASES['Ctrl'] // 'Control'\n * MODIFIER_ALIASES['Cmd'] // 'Meta'\n * MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)\n * ```\n */\nexport const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'> = {\n // Control variants\n Control: 'Control',\n Ctrl: 'Control',\n control: 'Control',\n ctrl: 'Control',\n\n // Shift variants\n Shift: 'Shift',\n shift: 'Shift',\n\n // Alt variants\n Alt: 'Alt',\n Option: 'Alt',\n alt: 'Alt',\n option: 'Alt',\n\n // Meta/Command variants\n Command: 'Meta',\n Cmd: 'Meta',\n Meta: 'Meta',\n command: 'Meta',\n cmd: 'Meta',\n meta: 'Meta',\n\n // DOM `KeyboardEvent.key` spellings for the meta / Windows key\n OS: 'Meta',\n os: 'Meta',\n Win: 'Meta',\n win: 'Meta',\n\n // Platform-adaptive (resolved at runtime)\n CommandOrControl: 'Mod',\n Mod: 'Mod',\n commandorcontrol: 'Mod',\n mod: 'Mod',\n}\n\n/**\n * Set of all valid letter keys (A-Z).\n *\n * Used for validation and type checking. Letter keys are matched case-insensitively\n * in hotkey matching, but normalized to uppercase in canonical form.\n */\nexport const LETTER_KEYS = new Set<LetterKey>([\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n 'H',\n 'I',\n 'J',\n 'K',\n 'L',\n 'M',\n 'N',\n 'O',\n 'P',\n 'Q',\n 'R',\n 'S',\n 'T',\n 'U',\n 'V',\n 'W',\n 'X',\n 'Y',\n 'Z',\n])\n\n/**\n * Set of all valid number keys (0-9).\n *\n * Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),\n * so they're excluded from Shift-based hotkey combinations to avoid\n * layout-dependent behavior.\n */\nexport const NUMBER_KEYS = new Set<NumberKey>([\n '0',\n '1',\n '2',\n '3',\n '4',\n '5',\n '6',\n '7',\n '8',\n '9',\n])\n\n/**\n * Set of all valid function keys (F1-F24).\n *\n * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,\n * Alt+F4 to close windows) and application-specific commands.\n */\nexport const FUNCTION_KEYS = new Set<FunctionKey>([\n 'F1',\n 'F2',\n 'F3',\n 'F4',\n 'F5',\n 'F6',\n 'F7',\n 'F8',\n 'F9',\n 'F10',\n 'F11',\n 'F12',\n 'F13',\n 'F14',\n 'F15',\n 'F16',\n 'F17',\n 'F18',\n 'F19',\n 'F20',\n 'F21',\n 'F22',\n 'F23',\n 'F24',\n])\n\n/**\n * Set of all valid navigation keys for cursor movement and document navigation.\n *\n * Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).\n * These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or\n * navigation shortcuts (Alt+ArrowLeft for back).\n */\nexport const NAVIGATION_KEYS = new Set<NavigationKey>([\n 'ArrowUp',\n 'ArrowDown',\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n])\n\n/**\n * Set of all valid editing and special keys.\n *\n * Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and\n * special actions (Escape, Space). These keys are frequently combined with modifiers\n * for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).\n */\nexport const EDITING_KEYS = new Set<EditingKey>([\n 'Enter',\n 'Escape',\n 'Space',\n 'Tab',\n 'Backspace',\n 'Delete',\n])\n\n/**\n * Set of all valid punctuation keys commonly used in keyboard shortcuts.\n *\n * These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,\n * typically US keyboard layout). Common shortcuts include:\n * - `Mod+/` - Toggle comment\n * - `Mod+[` / `Mod+]` - Indent/outdent\n * - `Mod+=` / `Mod+-` - Zoom in/out\n *\n * Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),\n * so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.\n */\nexport const PUNCTUATION_KEYS = new Set<PunctuationKey>([\n '/',\n '[',\n ']',\n '\\\\',\n '=',\n '-',\n ',',\n '.',\n ';',\n '`',\n \"'\",\n '+',\n '?',\n '!',\n '@',\n '#',\n '$',\n '%',\n '^',\n '&',\n '*',\n '(',\n ')',\n '_',\n '{',\n '}',\n '|',\n ':',\n '\"',\n '<',\n '>',\n '~',\n])\n\n/**\n * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.\n *\n * On macOS, holding the Option (Alt) key transforms punctuation keys into special characters\n * (e.g., Option+Minus → en-dash '–'), causing `event.key` to differ from the expected character.\n * However, `event.code` still reports the physical key (e.g., 'Minus'). This map enables\n * falling back to `event.code` for punctuation keys, similar to the existing `Key*`/`Digit*`\n * fallbacks for letters and digits.\n */\nexport const PUNCTUATION_CODE_MAP: Record<string, string> = {\n Backquote: '`',\n Backslash: '\\\\',\n BracketLeft: '[',\n BracketRight: ']',\n Comma: ',',\n Equal: '=',\n Minus: '-',\n Period: '.',\n Quote: \"'\",\n Semicolon: ';',\n Slash: '/',\n}\n\n/**\n * Set of all valid non-modifier keys.\n *\n * This is the union of all key type sets (letters, numbers, function keys, navigation,\n * editing, and punctuation). Used primarily for validation to check if a key string\n * is recognized and will have type-safe autocomplete support.\n *\n * @see {@link LETTER_KEYS}\n * @see {@link NUMBER_KEYS}\n * @see {@link FUNCTION_KEYS}\n * @see {@link NAVIGATION_KEYS}\n * @see {@link EDITING_KEYS}\n * @see {@link PUNCTUATION_KEYS}\n */\nexport const ALL_KEYS = new Set([\n ...LETTER_KEYS,\n ...NUMBER_KEYS,\n ...FUNCTION_KEYS,\n ...NAVIGATION_KEYS,\n ...EDITING_KEYS,\n ...PUNCTUATION_KEYS,\n ...SHARED_NAMED_KEYS,\n ...LOGICAL_ONLY_NAMED_KEYS,\n])\n\n// Share canonical spellings with validation, including newly supported named keys.\nconst CANONICAL_KEY_NAMES = new Map<string, string>(\n Array.from(ALL_KEYS, (key) => [key.toLowerCase(), key]),\n)\n\n/**\n * Maps key name aliases to their canonical form.\n *\n * Handles common variations and alternative names for keys to provide a more\n * forgiving API. For example, users can write 'Esc', 'esc', or 'escape' and\n * they'll all normalize to 'Escape'.\n *\n * This map is used internally by `normalizeKeyName()` to convert user input\n * into the canonical key names used throughout the library.\n *\n * @remarks Case-insensitive lookups are supported via lowercase variants\n *\n * @example\n * ```ts\n * KEY_ALIASES['Esc'] // 'Escape'\n * KEY_ALIASES['Del'] // 'Delete'\n * KEY_ALIASES['Up'] // 'ArrowUp'\n * ```\n */\nconst KEY_ALIASES: Record<string, string> = {\n Plus: '+',\n plus: '+',\n // Escape variants\n Esc: 'Escape',\n esc: 'Escape',\n escape: 'Escape',\n\n // Enter variants\n Return: 'Enter',\n return: 'Enter',\n enter: 'Enter',\n\n // Space variants\n ' ': 'Space',\n space: 'Space',\n Spacebar: 'Space',\n spacebar: 'Space',\n\n // Tab variants\n tab: 'Tab',\n\n // Backspace variants\n backspace: 'Backspace',\n\n // Delete variants\n Del: 'Delete',\n del: 'Delete',\n delete: 'Delete',\n\n // Arrow key variants\n Up: 'ArrowUp',\n up: 'ArrowUp',\n arrowup: 'ArrowUp',\n Down: 'ArrowDown',\n down: 'ArrowDown',\n arrowdown: 'ArrowDown',\n Left: 'ArrowLeft',\n left: 'ArrowLeft',\n arrowleft: 'ArrowLeft',\n Right: 'ArrowRight',\n right: 'ArrowRight',\n arrowright: 'ArrowRight',\n\n // Navigation variants\n home: 'Home',\n end: 'End',\n pageup: 'PageUp',\n pagedown: 'PageDown',\n PgUp: 'PageUp',\n PgDn: 'PageDown',\n pgup: 'PageUp',\n pgdn: 'PageDown',\n}\n\n/**\n * Normalizes a key name to its canonical form.\n *\n * Converts various key name formats (aliases, case variations) into the standard\n * canonical names used throughout the library. This enables a more forgiving API\n * where users can write keys in different ways and still get correct behavior.\n *\n * Normalization rules:\n * 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')\n * 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')\n * 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')\n * 4. Other keys → returned as-is (already canonical or unknown)\n *\n * @param key - The key name to normalize (can be an alias, lowercase, etc.)\n * @returns The canonical key name\n *\n * @example\n * ```ts\n * normalizeKeyName('esc') // 'Escape'\n * normalizeKeyName('a') // 'A'\n * normalizeKeyName('f1') // 'F1'\n * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)\n * ```\n */\nexport function isSingleLetterKey(key: string): boolean {\n return /^\\p{Letter}$/u.test(key)\n}\n\n/**\n * Normalizes a key name to its canonical form.\n *\n * @param key - The key name to normalize (can be an alias, lowercase, etc.)\n * @returns The canonical key name\n *\n * @example\n * ```ts\n * normalizeKeyName('esc') // 'Escape'\n * normalizeKeyName('a') // 'A'\n * normalizeKeyName('f1') // 'F1'\n * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)\n * ```\n */\nexport function normalizeKeyName(key: string): string {\n // key can be undefined in rare cases\n // (browser extensions synthesizing key events, accessibility tools, certain OS/browser combinations).\n if (!key) return ''\n // Check aliases first\n if (key in KEY_ALIASES) {\n return KEY_ALIASES[key]!\n }\n\n if (isSingleLetterKey(key)) {\n const upper = key.toUpperCase()\n // Some Unicode letters (e.g., 'ß') uppercase to multi-character sequences\n // ('SS'). Avoid changing the string length so the rest of the matching\n // logic can rely on a stable single-character key value.\n return upper.length === 1 ? upper : key\n }\n\n return CANONICAL_KEY_NAMES.get(key.toLowerCase()) ?? key\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAa,iBAA2C;CACtD;CACA;CACA;CACA;CACD;;;;;;;;AASD,MAAa,gBAAgB,IAAI,IAAY,eAAe;;;;;;;;;;;;;;;;;;;;AAqB5D,MAAa,mBAA8D;CAEzE,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CAGN,OAAO;CACP,OAAO;CAGP,KAAK;CACL,QAAQ;CACR,KAAK;CACL,QAAQ;CAGR,SAAS;CACT,KAAK;CACL,MAAM;CACN,SAAS;CACT,KAAK;CACL,MAAM;CAGN,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,KAAK;CAGL,kBAAkB;CAClB,KAAK;CACL,kBAAkB;CAClB,KAAK;CACN;;;;;;;AAQD,MAAa,cAAc,IAAI,IAAe;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,cAAc,IAAI,IAAe;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;AAQF,MAAa,gBAAgB,IAAI,IAAiB;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,kBAAkB,IAAI,IAAmB;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,eAAe,IAAI,IAAgB;CAC9C;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;AAcF,MAAa,mBAAmB,IAAI,IAAoB;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;;;AAWF,MAAa,uBAA+C;CAC1D,WAAW;CACX,WAAW;CACX,aAAa;CACb,cAAc;CACd,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,WAAW;CACX,OAAO;CACR;;;;;;;;;;;;;;;AAgBD,MAAa,WAAW,IAAI,IAAI;CAC9B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAGA;CACH,GAAGC;CACJ,CAAC;AAGF,MAAM,sBAAsB,IAAI,IAC9B,MAAM,KAAK,WAAW,QAAQ,CAAC,IAAI,aAAa,EAAE,IAAI,CAAC,CACxD;;;;;;;;;;;;;;;;;;;;AAqBD,MAAM,cAAsC;CAC1C,MAAM;CACN,MAAM;CAEN,KAAK;CACL,KAAK;CACL,QAAQ;CAGR,QAAQ;CACR,QAAQ;CACR,OAAO;CAGP,KAAK;CACL,OAAO;CACP,UAAU;CACV,UAAU;CAGV,KAAK;CAGL,WAAW;CAGX,KAAK;CACL,KAAK;CACL,QAAQ;CAGR,IAAI;CACJ,IAAI;CACJ,SAAS;CACT,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN,WAAW;CACX,OAAO;CACP,OAAO;CACP,YAAY;CAGZ,MAAM;CACN,KAAK;CACL,QAAQ;CACR,UAAU;CACV,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACP;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,SAAgB,kBAAkB,KAAsB;AACtD,QAAO,gBAAgB,KAAK,IAAI;;;;;;;;;;;;;;;;AAiBlC,SAAgB,iBAAiB,KAAqB;AAGpD,KAAI,CAAC,IAAK,QAAO;AAEjB,KAAI,OAAO,YACT,QAAO,YAAY;AAGrB,KAAI,kBAAkB,IAAI,EAAE;EAC1B,MAAM,QAAQ,IAAI,aAAa;AAI/B,SAAO,MAAM,WAAW,IAAI,QAAQ;;AAGtC,QAAO,oBAAoB,IAAI,IAAI,aAAa,CAAC,IAAI"}
@@ -1,165 +0,0 @@
1
- import { CanonicalModifier, EditingKey, FunctionKey, LetterKey, NavigationKey, NumberKey, PunctuationKey } from "./key.types.cjs";
2
-
3
- //#region src/constants.d.ts
4
- /**
5
- * Canonical order for modifiers in normalized hotkey strings.
6
- *
7
- * Defines the standard order in which modifiers should appear when formatting
8
- * hotkeys. This ensures consistent, predictable output across the library.
9
- *
10
- * Order: Control → Alt → Shift → Meta
11
- *
12
- * @example
13
- * ```ts
14
- * // Input: 'Shift+Control+Meta+S'
15
- * // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)
16
- * ```
17
- */
18
- declare const MODIFIER_ORDER: Array<CanonicalModifier>;
19
- /**
20
- * Set of canonical modifier key names for fast lookup.
21
- *
22
- * Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when
23
- * a modifier is released so we can clear non-modifier keys whose keyup events
24
- * may have been swallowed by the OS (e.g. macOS Cmd+key combos).
25
- */
26
- declare const MODIFIER_KEYS: Set<string>;
27
- /**
28
- * Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.
29
- *
30
- * This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')
31
- * which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the
32
- * platform-adaptive 'Mod' token.
33
- *
34
- * The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`
35
- * based on the detected platform (Command on Mac, Control elsewhere).
36
- *
37
- * @remarks Case-insensitive lookups are supported via lowercase variants
38
- *
39
- * @example
40
- * ```ts
41
- * MODIFIER_ALIASES['Ctrl'] // 'Control'
42
- * MODIFIER_ALIASES['Cmd'] // 'Meta'
43
- * MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)
44
- * ```
45
- */
46
- declare const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'>;
47
- /**
48
- * Set of all valid letter keys (A-Z).
49
- *
50
- * Used for validation and type checking. Letter keys are matched case-insensitively
51
- * in hotkey matching, but normalized to uppercase in canonical form.
52
- */
53
- declare const LETTER_KEYS: Set<LetterKey>;
54
- /**
55
- * Set of all valid number keys (0-9).
56
- *
57
- * Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),
58
- * so they're excluded from Shift-based hotkey combinations to avoid
59
- * layout-dependent behavior.
60
- */
61
- declare const NUMBER_KEYS: Set<NumberKey>;
62
- /**
63
- * Set of all valid function keys (F1-F24).
64
- *
65
- * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
66
- * Alt+F4 to close windows) and application-specific commands.
67
- */
68
- declare const FUNCTION_KEYS: Set<FunctionKey>;
69
- /**
70
- * Set of all valid navigation keys for cursor movement and document navigation.
71
- *
72
- * Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).
73
- * These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or
74
- * navigation shortcuts (Alt+ArrowLeft for back).
75
- */
76
- declare const NAVIGATION_KEYS: Set<NavigationKey>;
77
- /**
78
- * Set of all valid editing and special keys.
79
- *
80
- * Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and
81
- * special actions (Escape, Space). These keys are frequently combined with modifiers
82
- * for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).
83
- */
84
- declare const EDITING_KEYS: Set<EditingKey>;
85
- /**
86
- * Set of all valid punctuation keys commonly used in keyboard shortcuts.
87
- *
88
- * These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,
89
- * typically US keyboard layout). Common shortcuts include:
90
- * - `Mod+/` - Toggle comment
91
- * - `Mod+[` / `Mod+]` - Indent/outdent
92
- * - `Mod+=` / `Mod+-` - Zoom in/out
93
- *
94
- * Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),
95
- * so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.
96
- */
97
- declare const PUNCTUATION_KEYS: Set<PunctuationKey>;
98
- /**
99
- * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.
100
- *
101
- * On macOS, holding the Option (Alt) key transforms punctuation keys into special characters
102
- * (e.g., Option+Minus → en-dash '–'), causing `event.key` to differ from the expected character.
103
- * However, `event.code` still reports the physical key (e.g., 'Minus'). This map enables
104
- * falling back to `event.code` for punctuation keys, similar to the existing `Key*`/`Digit*`
105
- * fallbacks for letters and digits.
106
- */
107
- declare const PUNCTUATION_CODE_MAP: Record<string, string>;
108
- /**
109
- * Set of all valid non-modifier keys.
110
- *
111
- * This is the union of all key type sets (letters, numbers, function keys, navigation,
112
- * editing, and punctuation). Used primarily for validation to check if a key string
113
- * is recognized and will have type-safe autocomplete support.
114
- *
115
- * @see {@link LETTER_KEYS}
116
- * @see {@link NUMBER_KEYS}
117
- * @see {@link FUNCTION_KEYS}
118
- * @see {@link NAVIGATION_KEYS}
119
- * @see {@link EDITING_KEYS}
120
- * @see {@link PUNCTUATION_KEYS}
121
- */
122
- declare const ALL_KEYS: Set<LetterKey | NumberKey | FunctionKey | NavigationKey | EditingKey | PunctuationKey | "CapsLock" | "ContextMenu" | "Convert" | "KanaMode" | "NonConvert" | "Help" | "Insert" | "NumLock" | "Fn" | "FnLock" | "PrintScreen" | "ScrollLock" | "Pause" | "BrowserBack" | "BrowserFavorites" | "BrowserForward" | "BrowserHome" | "BrowserRefresh" | "BrowserSearch" | "BrowserStop" | "Eject" | "LaunchMail" | "MediaPlayPause" | "MediaStop" | "MediaTrackNext" | "MediaTrackPrevious" | "Power" | "AudioVolumeDown" | "AudioVolumeMute" | "AudioVolumeUp" | "WakeUp" | "Hyper" | "Super" | "Again" | "Copy" | "Cut" | "Find" | "Open" | "Paste" | "Props" | "Select" | "Undo" | "Hiragana" | "Katakana" | "Clear" | "Cancel" | "Standby" | "LaunchApplication1" | "LaunchApplication2" | "LaunchMediaPlayer" | "HangulMode" | "HanjaMode" | "Zenkaku" | "Hankaku" | "ZenkakuHankaku">;
123
- /**
124
- * Normalizes a key name to its canonical form.
125
- *
126
- * Converts various key name formats (aliases, case variations) into the standard
127
- * canonical names used throughout the library. This enables a more forgiving API
128
- * where users can write keys in different ways and still get correct behavior.
129
- *
130
- * Normalization rules:
131
- * 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')
132
- * 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')
133
- * 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')
134
- * 4. Other keys → returned as-is (already canonical or unknown)
135
- *
136
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
137
- * @returns The canonical key name
138
- *
139
- * @example
140
- * ```ts
141
- * normalizeKeyName('esc') // 'Escape'
142
- * normalizeKeyName('a') // 'A'
143
- * normalizeKeyName('f1') // 'F1'
144
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
145
- * ```
146
- */
147
- declare function isSingleLetterKey(key: string): boolean;
148
- /**
149
- * Normalizes a key name to its canonical form.
150
- *
151
- * @param key - The key name to normalize (can be an alias, lowercase, etc.)
152
- * @returns The canonical key name
153
- *
154
- * @example
155
- * ```ts
156
- * normalizeKeyName('esc') // 'Escape'
157
- * normalizeKeyName('a') // 'A'
158
- * normalizeKeyName('f1') // 'F1'
159
- * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)
160
- * ```
161
- */
162
- declare function normalizeKeyName(key: string): string;
163
- //#endregion
164
- export { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, LETTER_KEYS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, isSingleLetterKey, normalizeKeyName };
165
- //# sourceMappingURL=constants.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from './_named-keys'\nimport type {\n CanonicalModifier,\n EditingKey,\n FunctionKey,\n LetterKey,\n NavigationKey,\n NumberKey,\n PunctuationKey,\n} from './key.types'\n\n/**\n * Canonical order for modifiers in normalized hotkey strings.\n *\n * Defines the standard order in which modifiers should appear when formatting\n * hotkeys. This ensures consistent, predictable output across the library.\n *\n * Order: Control → Alt → Shift → Meta\n *\n * @example\n * ```ts\n * // Input: 'Shift+Control+Meta+S'\n * // Normalized: 'Control+Alt+Shift+Meta+S' (following MODIFIER_ORDER)\n * ```\n */\nexport const MODIFIER_ORDER: Array<CanonicalModifier> = [\n 'Control',\n 'Alt',\n 'Shift',\n 'Meta',\n]\n\n/**\n * Set of canonical modifier key names for fast lookup.\n *\n * Derived from `MODIFIER_ORDER` to ensure consistency. Used to detect when\n * a modifier is released so we can clear non-modifier keys whose keyup events\n * may have been swallowed by the OS (e.g. macOS Cmd+key combos).\n */\nexport const MODIFIER_KEYS = new Set<string>(MODIFIER_ORDER)\n\n/**\n * Maps modifier key aliases to their canonical form or platform-adaptive 'Mod'.\n *\n * This map allows users to write hotkeys using various aliases (e.g., 'Ctrl', 'Cmd', 'Option')\n * which are then normalized to canonical names ('Control', 'Meta', 'Alt') or the\n * platform-adaptive 'Mod' token.\n *\n * The 'Mod' and 'CommandOrControl' aliases are resolved at runtime via `resolveModifier()`\n * based on the detected platform (Command on Mac, Control elsewhere).\n *\n * @remarks Case-insensitive lookups are supported via lowercase variants\n *\n * @example\n * ```ts\n * MODIFIER_ALIASES['Ctrl'] // 'Control'\n * MODIFIER_ALIASES['Cmd'] // 'Meta'\n * MODIFIER_ALIASES['Mod'] // 'Mod' (resolved at runtime)\n * ```\n */\nexport const MODIFIER_ALIASES: Record<string, CanonicalModifier | 'Mod'> = {\n // Control variants\n Control: 'Control',\n Ctrl: 'Control',\n control: 'Control',\n ctrl: 'Control',\n\n // Shift variants\n Shift: 'Shift',\n shift: 'Shift',\n\n // Alt variants\n Alt: 'Alt',\n Option: 'Alt',\n alt: 'Alt',\n option: 'Alt',\n\n // Meta/Command variants\n Command: 'Meta',\n Cmd: 'Meta',\n Meta: 'Meta',\n command: 'Meta',\n cmd: 'Meta',\n meta: 'Meta',\n\n // DOM `KeyboardEvent.key` spellings for the meta / Windows key\n OS: 'Meta',\n os: 'Meta',\n Win: 'Meta',\n win: 'Meta',\n\n // Platform-adaptive (resolved at runtime)\n CommandOrControl: 'Mod',\n Mod: 'Mod',\n commandorcontrol: 'Mod',\n mod: 'Mod',\n}\n\n/**\n * Set of all valid letter keys (A-Z).\n *\n * Used for validation and type checking. Letter keys are matched case-insensitively\n * in hotkey matching, but normalized to uppercase in canonical form.\n */\nexport const LETTER_KEYS = new Set<LetterKey>([\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n 'H',\n 'I',\n 'J',\n 'K',\n 'L',\n 'M',\n 'N',\n 'O',\n 'P',\n 'Q',\n 'R',\n 'S',\n 'T',\n 'U',\n 'V',\n 'W',\n 'X',\n 'Y',\n 'Z',\n])\n\n/**\n * Set of all valid number keys (0-9).\n *\n * Note: Number keys are affected by Shift (Shift+1 → '!' on US layout),\n * so they're excluded from Shift-based hotkey combinations to avoid\n * layout-dependent behavior.\n */\nexport const NUMBER_KEYS = new Set<NumberKey>([\n '0',\n '1',\n '2',\n '3',\n '4',\n '5',\n '6',\n '7',\n '8',\n '9',\n])\n\n/**\n * Set of all valid function keys (F1-F24).\n *\n * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,\n * Alt+F4 to close windows) and application-specific commands.\n */\nexport const FUNCTION_KEYS = new Set<FunctionKey>([\n 'F1',\n 'F2',\n 'F3',\n 'F4',\n 'F5',\n 'F6',\n 'F7',\n 'F8',\n 'F9',\n 'F10',\n 'F11',\n 'F12',\n 'F13',\n 'F14',\n 'F15',\n 'F16',\n 'F17',\n 'F18',\n 'F19',\n 'F20',\n 'F21',\n 'F22',\n 'F23',\n 'F24',\n])\n\n/**\n * Set of all valid navigation keys for cursor movement and document navigation.\n *\n * Includes arrow keys, Home/End (line navigation), and PageUp/PageDown (page navigation).\n * These keys are commonly combined with modifiers for selection (Shift+ArrowUp) or\n * navigation shortcuts (Alt+ArrowLeft for back).\n */\nexport const NAVIGATION_KEYS = new Set<NavigationKey>([\n 'ArrowUp',\n 'ArrowDown',\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n])\n\n/**\n * Set of all valid editing and special keys.\n *\n * Includes keys commonly used for text editing (Enter, Backspace, Delete, Tab) and\n * special actions (Escape, Space). These keys are frequently combined with modifiers\n * for editor shortcuts (Mod+Enter to submit, Shift+Tab to go back).\n */\nexport const EDITING_KEYS = new Set<EditingKey>([\n 'Enter',\n 'Escape',\n 'Space',\n 'Tab',\n 'Backspace',\n 'Delete',\n])\n\n/**\n * Set of all valid punctuation keys commonly used in keyboard shortcuts.\n *\n * These are the literal characters as they appear in `KeyboardEvent.key` (layout-dependent,\n * typically US keyboard layout). Common shortcuts include:\n * - `Mod+/` - Toggle comment\n * - `Mod+[` / `Mod+]` - Indent/outdent\n * - `Mod+=` / `Mod+-` - Zoom in/out\n *\n * Note: Punctuation keys are affected by Shift (Shift+',' → '<' on US layout),\n * so they're excluded from Shift-based hotkey combinations to avoid layout-dependent behavior.\n */\nexport const PUNCTUATION_KEYS = new Set<PunctuationKey>([\n '/',\n '[',\n ']',\n '\\\\',\n '=',\n '-',\n ',',\n '.',\n ';',\n '`',\n \"'\",\n '+',\n '?',\n '!',\n '@',\n '#',\n '$',\n '%',\n '^',\n '&',\n '*',\n '(',\n ')',\n '_',\n '{',\n '}',\n '|',\n ':',\n '\"',\n '<',\n '>',\n '~',\n])\n\n/**\n * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.\n *\n * On macOS, holding the Option (Alt) key transforms punctuation keys into special characters\n * (e.g., Option+Minus → en-dash '–'), causing `event.key` to differ from the expected character.\n * However, `event.code` still reports the physical key (e.g., 'Minus'). This map enables\n * falling back to `event.code` for punctuation keys, similar to the existing `Key*`/`Digit*`\n * fallbacks for letters and digits.\n */\nexport const PUNCTUATION_CODE_MAP: Record<string, string> = {\n Backquote: '`',\n Backslash: '\\\\',\n BracketLeft: '[',\n BracketRight: ']',\n Comma: ',',\n Equal: '=',\n Minus: '-',\n Period: '.',\n Quote: \"'\",\n Semicolon: ';',\n Slash: '/',\n}\n\n/**\n * Set of all valid non-modifier keys.\n *\n * This is the union of all key type sets (letters, numbers, function keys, navigation,\n * editing, and punctuation). Used primarily for validation to check if a key string\n * is recognized and will have type-safe autocomplete support.\n *\n * @see {@link LETTER_KEYS}\n * @see {@link NUMBER_KEYS}\n * @see {@link FUNCTION_KEYS}\n * @see {@link NAVIGATION_KEYS}\n * @see {@link EDITING_KEYS}\n * @see {@link PUNCTUATION_KEYS}\n */\nexport const ALL_KEYS = new Set([\n ...LETTER_KEYS,\n ...NUMBER_KEYS,\n ...FUNCTION_KEYS,\n ...NAVIGATION_KEYS,\n ...EDITING_KEYS,\n ...PUNCTUATION_KEYS,\n ...SHARED_NAMED_KEYS,\n ...LOGICAL_ONLY_NAMED_KEYS,\n])\n\n// Share canonical spellings with validation, including newly supported named keys.\nconst CANONICAL_KEY_NAMES = new Map<string, string>(\n Array.from(ALL_KEYS, (key) => [key.toLowerCase(), key]),\n)\n\n/**\n * Maps key name aliases to their canonical form.\n *\n * Handles common variations and alternative names for keys to provide a more\n * forgiving API. For example, users can write 'Esc', 'esc', or 'escape' and\n * they'll all normalize to 'Escape'.\n *\n * This map is used internally by `normalizeKeyName()` to convert user input\n * into the canonical key names used throughout the library.\n *\n * @remarks Case-insensitive lookups are supported via lowercase variants\n *\n * @example\n * ```ts\n * KEY_ALIASES['Esc'] // 'Escape'\n * KEY_ALIASES['Del'] // 'Delete'\n * KEY_ALIASES['Up'] // 'ArrowUp'\n * ```\n */\nconst KEY_ALIASES: Record<string, string> = {\n Plus: '+',\n plus: '+',\n // Escape variants\n Esc: 'Escape',\n esc: 'Escape',\n escape: 'Escape',\n\n // Enter variants\n Return: 'Enter',\n return: 'Enter',\n enter: 'Enter',\n\n // Space variants\n ' ': 'Space',\n space: 'Space',\n Spacebar: 'Space',\n spacebar: 'Space',\n\n // Tab variants\n tab: 'Tab',\n\n // Backspace variants\n backspace: 'Backspace',\n\n // Delete variants\n Del: 'Delete',\n del: 'Delete',\n delete: 'Delete',\n\n // Arrow key variants\n Up: 'ArrowUp',\n up: 'ArrowUp',\n arrowup: 'ArrowUp',\n Down: 'ArrowDown',\n down: 'ArrowDown',\n arrowdown: 'ArrowDown',\n Left: 'ArrowLeft',\n left: 'ArrowLeft',\n arrowleft: 'ArrowLeft',\n Right: 'ArrowRight',\n right: 'ArrowRight',\n arrowright: 'ArrowRight',\n\n // Navigation variants\n home: 'Home',\n end: 'End',\n pageup: 'PageUp',\n pagedown: 'PageDown',\n PgUp: 'PageUp',\n PgDn: 'PageDown',\n pgup: 'PageUp',\n pgdn: 'PageDown',\n}\n\n/**\n * Normalizes a key name to its canonical form.\n *\n * Converts various key name formats (aliases, case variations) into the standard\n * canonical names used throughout the library. This enables a more forgiving API\n * where users can write keys in different ways and still get correct behavior.\n *\n * Normalization rules:\n * 1. Check aliases first (e.g., 'Esc' → 'Escape', 'Del' → 'Delete')\n * 2. Single letters → uppercase (e.g., 'a' → 'A', 's' → 'S')\n * 3. Function keys → uppercase (e.g., 'f1' → 'F1', 'F12' → 'F12')\n * 4. Other keys → returned as-is (already canonical or unknown)\n *\n * @param key - The key name to normalize (can be an alias, lowercase, etc.)\n * @returns The canonical key name\n *\n * @example\n * ```ts\n * normalizeKeyName('esc') // 'Escape'\n * normalizeKeyName('a') // 'A'\n * normalizeKeyName('f1') // 'F1'\n * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)\n * ```\n */\nexport function isSingleLetterKey(key: string): boolean {\n return /^\\p{Letter}$/u.test(key)\n}\n\n/**\n * Normalizes a key name to its canonical form.\n *\n * @param key - The key name to normalize (can be an alias, lowercase, etc.)\n * @returns The canonical key name\n *\n * @example\n * ```ts\n * normalizeKeyName('esc') // 'Escape'\n * normalizeKeyName('a') // 'A'\n * normalizeKeyName('f1') // 'F1'\n * normalizeKeyName('ArrowUp') // 'ArrowUp' (already canonical)\n * ```\n */\nexport function normalizeKeyName(key: string): string {\n // key can be undefined in rare cases\n // (browser extensions synthesizing key events, accessibility tools, certain OS/browser combinations).\n if (!key) return ''\n // Check aliases first\n if (key in KEY_ALIASES) {\n return KEY_ALIASES[key]!\n }\n\n if (isSingleLetterKey(key)) {\n const upper = key.toUpperCase()\n // Some Unicode letters (e.g., 'ß') uppercase to multi-character sequences\n // ('SS'). Avoid changing the string length so the rest of the matching\n // logic can rely on a stable single-character key value.\n return upper.length === 1 ? upper : key\n }\n\n return CANONICAL_KEY_NAMES.get(key.toLowerCase()) ?? key\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAa,iBAA2C;CACtD;CACA;CACA;CACA;CACD;;;;;;;;AASD,MAAa,gBAAgB,IAAI,IAAY,eAAe;;;;;;;;;;;;;;;;;;;;AAqB5D,MAAa,mBAA8D;CAEzE,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CAGN,OAAO;CACP,OAAO;CAGP,KAAK;CACL,QAAQ;CACR,KAAK;CACL,QAAQ;CAGR,SAAS;CACT,KAAK;CACL,MAAM;CACN,SAAS;CACT,KAAK;CACL,MAAM;CAGN,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,KAAK;CAGL,kBAAkB;CAClB,KAAK;CACL,kBAAkB;CAClB,KAAK;CACN;;;;;;;AAQD,MAAa,cAAc,IAAI,IAAe;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,cAAc,IAAI,IAAe;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;AAQF,MAAa,gBAAgB,IAAI,IAAiB;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,kBAAkB,IAAI,IAAmB;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,MAAa,eAAe,IAAI,IAAgB;CAC9C;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;AAcF,MAAa,mBAAmB,IAAI,IAAoB;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;;;AAWF,MAAa,uBAA+C;CAC1D,WAAW;CACX,WAAW;CACX,aAAa;CACb,cAAc;CACd,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,WAAW;CACX,OAAO;CACR;;;;;;;;;;;;;;;AAgBD,MAAa,WAAW,IAAI,IAAI;CAC9B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACJ,CAAC;AAGF,MAAM,sBAAsB,IAAI,IAC9B,MAAM,KAAK,WAAW,QAAQ,CAAC,IAAI,aAAa,EAAE,IAAI,CAAC,CACxD;;;;;;;;;;;;;;;;;;;;AAqBD,MAAM,cAAsC;CAC1C,MAAM;CACN,MAAM;CAEN,KAAK;CACL,KAAK;CACL,QAAQ;CAGR,QAAQ;CACR,QAAQ;CACR,OAAO;CAGP,KAAK;CACL,OAAO;CACP,UAAU;CACV,UAAU;CAGV,KAAK;CAGL,WAAW;CAGX,KAAK;CACL,KAAK;CACL,QAAQ;CAGR,IAAI;CACJ,IAAI;CACJ,SAAS;CACT,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN,WAAW;CACX,OAAO;CACP,OAAO;CACP,YAAY;CAGZ,MAAM;CACN,KAAK;CACL,QAAQ;CACR,UAAU;CACV,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACP;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,SAAgB,kBAAkB,KAAsB;AACtD,QAAO,gBAAgB,KAAK,IAAI;;;;;;;;;;;;;;;;AAiBlC,SAAgB,iBAAiB,KAAqB;AAGpD,KAAI,CAAC,IAAK,QAAO;AAEjB,KAAI,OAAO,YACT,QAAO,YAAY;AAGrB,KAAI,kBAAkB,IAAI,EAAE;EAC1B,MAAM,QAAQ,IAAI,aAAa;AAI/B,SAAO,MAAM,WAAW,IAAI,QAAQ;;AAGtC,QAAO,oBAAoB,IAAI,IAAI,aAAa,CAAC,IAAI"}