@tanstack/hotkeys 0.7.1 → 0.9.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 (158) hide show
  1. package/README.md +15 -1
  2. package/dist/{manager.utils.js → _event-target.cjs} +5 -41
  3. package/dist/_event-target.cjs.map +1 -0
  4. package/dist/{manager.utils.cjs → _event-target.js} +3 -47
  5. package/dist/_event-target.js.map +1 -0
  6. package/dist/_keyboard-event.cjs +83 -0
  7. package/dist/_keyboard-event.cjs.map +1 -0
  8. package/dist/_keyboard-event.js +76 -0
  9. package/dist/_keyboard-event.js.map +1 -0
  10. package/dist/_match.cjs +49 -0
  11. package/dist/_match.cjs.map +1 -0
  12. package/dist/_match.js +49 -0
  13. package/dist/_match.js.map +1 -0
  14. package/dist/_named-keys.cjs +68 -0
  15. package/dist/_named-keys.cjs.map +1 -0
  16. package/dist/_named-keys.d.cts +8 -0
  17. package/dist/_named-keys.d.ts +8 -0
  18. package/dist/_named-keys.js +66 -0
  19. package/dist/_named-keys.js.map +1 -0
  20. package/dist/_recorder-chord.cjs +44 -0
  21. package/dist/_recorder-chord.cjs.map +1 -0
  22. package/dist/_recorder-chord.js +43 -0
  23. package/dist/_recorder-chord.js.map +1 -0
  24. package/dist/_recording-guard.cjs +59 -0
  25. package/dist/_recording-guard.cjs.map +1 -0
  26. package/dist/_recording-guard.js +56 -0
  27. package/dist/_recording-guard.js.map +1 -0
  28. package/dist/_registration.cjs +54 -0
  29. package/dist/_registration.cjs.map +1 -0
  30. package/dist/_registration.js +50 -0
  31. package/dist/_registration.js.map +1 -0
  32. package/dist/conflicts.cjs +55 -0
  33. package/dist/conflicts.cjs.map +1 -0
  34. package/dist/conflicts.d.cts +39 -0
  35. package/dist/conflicts.d.ts +39 -0
  36. package/dist/conflicts.js +55 -0
  37. package/dist/conflicts.js.map +1 -0
  38. package/dist/constants.cjs +46 -171
  39. package/dist/constants.cjs.map +1 -1
  40. package/dist/constants.d.cts +4 -129
  41. package/dist/constants.d.ts +4 -129
  42. package/dist/constants.js +48 -164
  43. package/dist/constants.js.map +1 -1
  44. package/dist/display-labels.cjs +119 -0
  45. package/dist/display-labels.cjs.map +1 -0
  46. package/dist/display-labels.d.cts +93 -0
  47. package/dist/display-labels.d.ts +93 -0
  48. package/dist/display-labels.js +113 -0
  49. package/dist/display-labels.js.map +1 -0
  50. package/dist/format.cjs +30 -36
  51. package/dist/format.cjs.map +1 -1
  52. package/dist/format.d.cts +46 -7
  53. package/dist/format.d.ts +46 -7
  54. package/dist/format.js +31 -37
  55. package/dist/format.js.map +1 -1
  56. package/dist/hint.cjs +24 -0
  57. package/dist/hint.cjs.map +1 -0
  58. package/dist/hint.d.cts +23 -0
  59. package/dist/hint.d.ts +23 -0
  60. package/dist/hint.js +24 -0
  61. package/dist/hint.js.map +1 -0
  62. package/dist/hotkey-manager.cjs +53 -22
  63. package/dist/hotkey-manager.cjs.map +1 -1
  64. package/dist/hotkey-manager.d.cts +6 -2
  65. package/dist/hotkey-manager.d.ts +6 -2
  66. package/dist/hotkey-manager.js +49 -18
  67. package/dist/hotkey-manager.js.map +1 -1
  68. package/dist/hotkey-recorder.cjs +67 -11
  69. package/dist/hotkey-recorder.cjs.map +1 -1
  70. package/dist/hotkey-recorder.d.cts +6 -3
  71. package/dist/hotkey-recorder.d.ts +6 -3
  72. package/dist/hotkey-recorder.js +66 -10
  73. package/dist/hotkey-recorder.js.map +1 -1
  74. package/dist/hotkey-sequence-recorder.cjs +85 -22
  75. package/dist/hotkey-sequence-recorder.cjs.map +1 -1
  76. package/dist/hotkey-sequence-recorder.d.cts +9 -2
  77. package/dist/hotkey-sequence-recorder.d.ts +9 -2
  78. package/dist/hotkey-sequence-recorder.js +84 -21
  79. package/dist/hotkey-sequence-recorder.js.map +1 -1
  80. package/dist/{hotkey.d.ts → hotkey.types.d.cts} +55 -120
  81. package/dist/{hotkey.d.cts → hotkey.types.d.ts} +55 -120
  82. package/dist/index.cjs +18 -10
  83. package/dist/index.d.cts +14 -9
  84. package/dist/index.d.ts +14 -9
  85. package/dist/index.js +10 -6
  86. package/dist/key-state-tracker.cjs +24 -24
  87. package/dist/key-state-tracker.cjs.map +1 -1
  88. package/dist/key-state-tracker.js +24 -24
  89. package/dist/key-state-tracker.js.map +1 -1
  90. package/dist/key.types.d.cts +82 -0
  91. package/dist/key.types.d.ts +82 -0
  92. package/dist/match.cjs +21 -30
  93. package/dist/match.cjs.map +1 -1
  94. package/dist/match.d.cts +19 -3
  95. package/dist/match.d.ts +19 -3
  96. package/dist/match.js +19 -29
  97. package/dist/match.js.map +1 -1
  98. package/dist/parse.cjs +43 -26
  99. package/dist/parse.cjs.map +1 -1
  100. package/dist/parse.d.cts +10 -4
  101. package/dist/parse.d.ts +10 -4
  102. package/dist/parse.js +35 -19
  103. package/dist/parse.js.map +1 -1
  104. package/dist/platform.cjs +55 -0
  105. package/dist/platform.cjs.map +1 -0
  106. package/dist/platform.d.cts +44 -0
  107. package/dist/platform.d.ts +44 -0
  108. package/dist/platform.js +53 -0
  109. package/dist/platform.js.map +1 -0
  110. package/dist/recorder-options.d.cts +34 -0
  111. package/dist/recorder-options.d.ts +34 -0
  112. package/dist/sequence-manager.cjs +54 -28
  113. package/dist/sequence-manager.cjs.map +1 -1
  114. package/dist/sequence-manager.d.cts +18 -3
  115. package/dist/sequence-manager.d.ts +18 -3
  116. package/dist/sequence-manager.js +49 -23
  117. package/dist/sequence-manager.js.map +1 -1
  118. package/dist/validate.cjs +6 -10
  119. package/dist/validate.cjs.map +1 -1
  120. package/dist/validate.d.cts +13 -2
  121. package/dist/validate.d.ts +13 -2
  122. package/dist/validate.js +7 -11
  123. package/dist/validate.js.map +1 -1
  124. package/package.json +2 -2
  125. package/src/{manager.utils.ts → _event-target.ts} +0 -74
  126. package/src/_keyboard-event.ts +101 -0
  127. package/src/_match.ts +96 -0
  128. package/src/_named-keys.ts +62 -0
  129. package/src/_recorder-chord.ts +76 -0
  130. package/src/_recording-guard.ts +63 -0
  131. package/src/_registration.ts +79 -0
  132. package/src/conflicts.ts +125 -0
  133. package/src/constants.ts +48 -196
  134. package/src/display-labels.ts +123 -0
  135. package/src/format.ts +111 -52
  136. package/src/hint.ts +42 -0
  137. package/src/hotkey-manager.ts +95 -40
  138. package/src/hotkey-recorder.ts +92 -16
  139. package/src/hotkey-sequence-recorder.ts +110 -28
  140. package/src/{hotkey.ts → hotkey.types.ts} +57 -224
  141. package/src/index.ts +11 -5
  142. package/src/key-state-tracker.ts +36 -24
  143. package/src/key.types.ts +268 -0
  144. package/src/match.ts +41 -90
  145. package/src/parse.ts +67 -26
  146. package/src/platform.ts +66 -0
  147. package/src/recorder-options.ts +34 -0
  148. package/src/sequence-manager.ts +77 -42
  149. package/src/validate.ts +29 -21
  150. package/dist/manager.utils.cjs.map +0 -1
  151. package/dist/manager.utils.d.cts +0 -13
  152. package/dist/manager.utils.d.ts +0 -13
  153. package/dist/manager.utils.js.map +0 -1
  154. package/dist/recorder-chord.cjs +0 -18
  155. package/dist/recorder-chord.cjs.map +0 -1
  156. package/dist/recorder-chord.js +0 -18
  157. package/dist/recorder-chord.js.map +0 -1
  158. package/src/recorder-chord.ts +0 -25
@@ -1,22 +1,6 @@
1
- import { CanonicalModifier, EditingKey, FunctionKey, LetterKey, NavigationKey, NumberKey, PunctuationKey } from "./hotkey.js";
1
+ import { CanonicalModifier, EditingKey, FunctionKey, LetterKey, NavigationKey, NumberKey, PunctuationKey } from "./key.types.js";
2
2
 
3
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
4
  /**
21
5
  * Canonical order for modifiers in normalized hotkey strings.
22
6
  *
@@ -60,28 +44,6 @@ declare const MODIFIER_KEYS: Set<string>;
60
44
  * ```
61
45
  */
62
46
  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
47
  /**
86
48
  * Set of all valid letter keys (A-Z).
87
49
  *
@@ -98,7 +60,7 @@ declare const LETTER_KEYS: Set<LetterKey>;
98
60
  */
99
61
  declare const NUMBER_KEYS: Set<NumberKey>;
100
62
  /**
101
- * Set of all valid function keys (F1-F12).
63
+ * Set of all valid function keys (F1-F24).
102
64
  *
103
65
  * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
104
66
  * Alt+F4 to close windows) and application-specific commands.
@@ -157,7 +119,7 @@ declare const PUNCTUATION_CODE_MAP: Record<string, string>;
157
119
  * @see {@link EDITING_KEYS}
158
120
  * @see {@link PUNCTUATION_KEYS}
159
121
  */
160
- declare const ALL_KEYS: Set<LetterKey | NumberKey | FunctionKey | NavigationKey | EditingKey | PunctuationKey>;
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">;
161
123
  /**
162
124
  * Normalizes a key name to its canonical form.
163
125
  *
@@ -198,93 +160,6 @@ declare function isSingleLetterKey(key: string): boolean;
198
160
  * ```
199
161
  */
200
162
  declare function normalizeKeyName(key: string): string;
201
- /**
202
- * Modifier key symbols for macOS display.
203
- *
204
- * Used by formatting functions to display hotkeys with macOS-style symbols
205
- * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
206
- * a native macOS look and feel in hotkey displays.
207
- *
208
- * @example
209
- * ```ts
210
- * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
211
- * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
212
- * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
213
- * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
214
- * ```
215
- */
216
- declare const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier | 'Mod', string>;
217
- /**
218
- * Modifier key labels for macOS display.
219
- *
220
- * Used by formatting functions to display hotkeys with macOS-style text labels
221
- * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.
222
- * This provides a familiar macOS look and feel in hotkey displays.
223
- *
224
- * @example
225
- * ```ts
226
- * MAC_MODIFIER_LABELS['Control'] // 'control'
227
- * MAC_MODIFIER_LABELS['Alt'] // 'option'
228
- * MAC_MODIFIER_LABELS['Shift'] // 'shift'
229
- * MAC_MODIFIER_LABELS['Meta'] // 'cmd'
230
- * ```
231
- */
232
- declare const MAC_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
233
- /**
234
- * Modifier key labels for Windows/Linux display.
235
- *
236
- * Used by formatting functions to display hotkeys with standard text labels
237
- * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
238
- * This provides a familiar Windows/Linux look and feel in hotkey displays.
239
- *
240
- * @example
241
- * ```ts
242
- * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
243
- * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
244
- * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
245
- * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
246
- * ```
247
- */
248
- declare const WINDOWS_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
249
- declare const LINUX_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
250
- declare const PUNCTUATION_KEY_DISPLAY_LABELS: {
251
- readonly '`': "Backquote";
252
- readonly '\\': "Backslash";
253
- readonly '[': "Left Bracket";
254
- readonly ']': "Right Bracket";
255
- readonly ',': "Comma";
256
- readonly '=': "Equal";
257
- readonly '-': "Minus";
258
- readonly '.': "Period";
259
- readonly ';': "Semicolon";
260
- };
261
- /**
262
- * Special key symbols for display formatting.
263
- *
264
- * Maps certain keys to their visual symbols for better readability in hotkey displays.
265
- * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
266
- * instead of text labels.
267
- *
268
- * @example
269
- * ```ts
270
- * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
271
- * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
272
- * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
273
- * KEY_DISPLAY_SYMBOLS['Space'] // '␣'
274
- * ```
275
- */
276
- declare const KEY_DISPLAY_SYMBOLS: {
277
- readonly ArrowUp: "↑";
278
- readonly ArrowDown: "↓";
279
- readonly ArrowLeft: "←";
280
- readonly ArrowRight: "→";
281
- readonly Enter: "↵";
282
- readonly Escape: "Esc";
283
- readonly Backspace: "⌫";
284
- readonly Delete: "⌦";
285
- readonly Tab: "⇥";
286
- readonly Space: "␣";
287
- };
288
163
  //#endregion
289
- export { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, KEY_DISPLAY_SYMBOLS, LETTER_KEYS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS, detectPlatform, isSingleLetterKey, normalizeKeyName, resolveModifier };
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 };
290
165
  //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -1,28 +1,7 @@
1
+ import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from "./_named-keys.js";
2
+
1
3
  //#region src/constants.ts
2
4
  /**
3
- * Detects the current platform based on browser navigator properties.
4
- *
5
- * Used internally to resolve platform-adaptive modifiers like 'Mod' (Command on Mac,
6
- * Control elsewhere) and for platform-specific hotkey formatting.
7
- *
8
- * @returns The detected platform: 'mac', 'windows', or 'linux'
9
- * @remarks Defaults to 'linux' in SSR environments where navigator is undefined
10
- *
11
- * @example
12
- * ```ts
13
- * const platform = detectPlatform() // 'mac' | 'windows' | 'linux'
14
- * const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere
15
- * ```
16
- */
17
- function detectPlatform() {
18
- if (typeof navigator === "undefined") return "linux";
19
- const platform = navigator.platform?.toLowerCase() ?? "";
20
- const userAgent = navigator.userAgent?.toLowerCase() ?? "";
21
- if (platform.includes("mac") || userAgent.includes("mac")) return "mac";
22
- if (platform.includes("win") || userAgent.includes("win")) return "windows";
23
- return "linux";
24
- }
25
- /**
26
5
  * Canonical order for modifiers in normalized hotkey strings.
27
6
  *
28
7
  * Defines the standard order in which modifiers should appear when formatting
@@ -96,31 +75,6 @@ const MODIFIER_ALIASES = {
96
75
  mod: "Mod"
97
76
  };
98
77
  /**
99
- * Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.
100
- *
101
- * The 'Mod' token represents the "primary modifier" on each platform:
102
- * - macOS: 'Meta' (Command key ⌘)
103
- * - Windows/Linux: 'Control' (Ctrl key)
104
- *
105
- * This enables cross-platform hotkey definitions like 'Mod+S' that automatically
106
- * map to Command+S on Mac and Ctrl+S on Windows/Linux.
107
- *
108
- * @param modifier - The modifier to resolve. If 'Mod', resolves based on platform.
109
- * @param platform - The target platform. Defaults to auto-detection.
110
- * @returns The canonical modifier name ('Control', 'Shift', 'Alt', or 'Meta')
111
- *
112
- * @example
113
- * ```ts
114
- * resolveModifier('Mod', 'mac') // 'Meta'
115
- * resolveModifier('Mod', 'windows') // 'Control'
116
- * resolveModifier('Control', 'mac') // 'Control' (unchanged)
117
- * ```
118
- */
119
- function resolveModifier(modifier, platform = detectPlatform()) {
120
- if (modifier === "Mod") return platform === "mac" ? "Meta" : "Control";
121
- return modifier;
122
- }
123
- /**
124
78
  * Set of all valid letter keys (A-Z).
125
79
  *
126
80
  * Used for validation and type checking. Letter keys are matched case-insensitively
@@ -174,7 +128,7 @@ const NUMBER_KEYS = new Set([
174
128
  "9"
175
129
  ]);
176
130
  /**
177
- * Set of all valid function keys (F1-F12).
131
+ * Set of all valid function keys (F1-F24).
178
132
  *
179
133
  * Function keys are commonly used for system shortcuts (e.g., F12 for DevTools,
180
134
  * Alt+F4 to close windows) and application-specific commands.
@@ -191,7 +145,19 @@ const FUNCTION_KEYS = new Set([
191
145
  "F9",
192
146
  "F10",
193
147
  "F11",
194
- "F12"
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"
195
161
  ]);
196
162
  /**
197
163
  * Set of all valid navigation keys for cursor movement and document navigation.
@@ -247,7 +213,29 @@ const PUNCTUATION_KEYS = new Set([
247
213
  ",",
248
214
  ".",
249
215
  ";",
250
- "`"
216
+ "`",
217
+ "'",
218
+ "+",
219
+ "?",
220
+ "!",
221
+ "@",
222
+ "#",
223
+ "$",
224
+ "%",
225
+ "^",
226
+ "&",
227
+ "*",
228
+ "(",
229
+ ")",
230
+ "_",
231
+ "{",
232
+ "}",
233
+ "|",
234
+ ":",
235
+ "\"",
236
+ "<",
237
+ ">",
238
+ "~"
251
239
  ]);
252
240
  /**
253
241
  * Maps `KeyboardEvent.code` values for punctuation keys to their canonical characters.
@@ -267,6 +255,7 @@ const PUNCTUATION_CODE_MAP = {
267
255
  Equal: "=",
268
256
  Minus: "-",
269
257
  Period: ".",
258
+ Quote: "'",
270
259
  Semicolon: ";",
271
260
  Slash: "/"
272
261
  };
@@ -290,8 +279,11 @@ const ALL_KEYS = new Set([
290
279
  ...FUNCTION_KEYS,
291
280
  ...NAVIGATION_KEYS,
292
281
  ...EDITING_KEYS,
293
- ...PUNCTUATION_KEYS
282
+ ...PUNCTUATION_KEYS,
283
+ ...SHARED_NAMED_KEYS,
284
+ ...LOGICAL_ONLY_NAMED_KEYS
294
285
  ]);
286
+ const CANONICAL_KEY_NAMES = new Map(Array.from(ALL_KEYS, (key) => [key.toLowerCase(), key]));
295
287
  /**
296
288
  * Maps key name aliases to their canonical form.
297
289
  *
@@ -312,6 +304,8 @@ const ALL_KEYS = new Set([
312
304
  * ```
313
305
  */
314
306
  const KEY_ALIASES = {
307
+ Plus: "+",
308
+ plus: "+",
315
309
  Esc: "Escape",
316
310
  esc: "Escape",
317
311
  escape: "Escape",
@@ -396,119 +390,9 @@ function normalizeKeyName(key) {
396
390
  const upper = key.toUpperCase();
397
391
  return upper.length === 1 ? upper : key;
398
392
  }
399
- const upperKey = key.toUpperCase();
400
- if (/^F([1-9]|1[0-2])$/.test(upperKey)) return upperKey;
401
- return key;
393
+ return CANONICAL_KEY_NAMES.get(key.toLowerCase()) ?? key;
402
394
  }
403
- /**
404
- * Modifier key symbols for macOS display.
405
- *
406
- * Used by formatting functions to display hotkeys with macOS-style symbols
407
- * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
408
- * a native macOS look and feel in hotkey displays.
409
- *
410
- * @example
411
- * ```ts
412
- * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
413
- * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
414
- * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
415
- * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
416
- * ```
417
- */
418
- const MAC_MODIFIER_SYMBOLS = {
419
- Control: "⌃",
420
- Alt: "⌥",
421
- Shift: "⇧",
422
- Meta: "⌘",
423
- Mod: "⌘"
424
- };
425
- /**
426
- * Modifier key labels for macOS display.
427
- *
428
- * Used by formatting functions to display hotkeys with macOS-style text labels
429
- * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.
430
- * This provides a familiar macOS look and feel in hotkey displays.
431
- *
432
- * @example
433
- * ```ts
434
- * MAC_MODIFIER_LABELS['Control'] // 'control'
435
- * MAC_MODIFIER_LABELS['Alt'] // 'option'
436
- * MAC_MODIFIER_LABELS['Shift'] // 'shift'
437
- * MAC_MODIFIER_LABELS['Meta'] // 'cmd'
438
- * ```
439
- */
440
- const MAC_MODIFIER_LABELS = {
441
- Control: "Control",
442
- Alt: "Option",
443
- Shift: "Shift",
444
- Meta: "Cmd",
445
- Mod: "Cmd"
446
- };
447
- /**
448
- * Modifier key labels for Windows/Linux display.
449
- *
450
- * Used by formatting functions to display hotkeys with standard text labels
451
- * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
452
- * This provides a familiar Windows/Linux look and feel in hotkey displays.
453
- *
454
- * @example
455
- * ```ts
456
- * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
457
- * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
458
- * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
459
- * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
460
- * ```
461
- */
462
- const WINDOWS_MODIFIER_LABELS = {
463
- Control: "Ctrl",
464
- Alt: "Alt",
465
- Shift: "Shift",
466
- Meta: "Win",
467
- Mod: "Ctrl"
468
- };
469
- const LINUX_MODIFIER_LABELS = {
470
- ...WINDOWS_MODIFIER_LABELS,
471
- Meta: "Super"
472
- };
473
- const PUNCTUATION_KEY_DISPLAY_LABELS = {
474
- "`": "Backquote",
475
- "\\": "Backslash",
476
- "[": "Left Bracket",
477
- "]": "Right Bracket",
478
- ",": "Comma",
479
- "=": "Equal",
480
- "-": "Minus",
481
- ".": "Period",
482
- ";": "Semicolon"
483
- };
484
- /**
485
- * Special key symbols for display formatting.
486
- *
487
- * Maps certain keys to their visual symbols for better readability in hotkey displays.
488
- * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
489
- * instead of text labels.
490
- *
491
- * @example
492
- * ```ts
493
- * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
494
- * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
495
- * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
496
- * KEY_DISPLAY_SYMBOLS['Space'] // '␣'
497
- * ```
498
- */
499
- const KEY_DISPLAY_SYMBOLS = {
500
- ArrowUp: "↑",
501
- ArrowDown: "↓",
502
- ArrowLeft: "←",
503
- ArrowRight: "→",
504
- Enter: "↵",
505
- Escape: "Esc",
506
- Backspace: "⌫",
507
- Delete: "⌦",
508
- Tab: "⇥",
509
- Space: "␣"
510
- };
511
395
 
512
396
  //#endregion
513
- export { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, KEY_DISPLAY_SYMBOLS, LETTER_KEYS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS, detectPlatform, isSingleLetterKey, normalizeKeyName, resolveModifier };
397
+ 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 };
514
398
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type {\n CanonicalModifier,\n EditingKey,\n FunctionKey,\n LetterKey,\n NavigationKey,\n NumberKey,\n PunctuationKey,\n} from './hotkey'\n\n/**\n * Detects the current platform based on browser navigator properties.\n *\n * Used internally to resolve platform-adaptive modifiers like 'Mod' (Command on Mac,\n * Control elsewhere) and for platform-specific hotkey formatting.\n *\n * @returns The detected platform: 'mac', 'windows', or 'linux'\n * @remarks Defaults to 'linux' in SSR environments where navigator is undefined\n *\n * @example\n * ```ts\n * const platform = detectPlatform() // 'mac' | 'windows' | 'linux'\n * const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere\n * ```\n */\nexport function detectPlatform(): 'mac' | 'windows' | 'linux' {\n if (typeof navigator === 'undefined') {\n return 'linux' // Default for SSR\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const platform = navigator.platform?.toLowerCase() ?? ''\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const userAgent = navigator.userAgent?.toLowerCase() ?? ''\n\n if (platform.includes('mac') || userAgent.includes('mac')) {\n return 'mac'\n }\n if (platform.includes('win') || userAgent.includes('win')) {\n return 'windows'\n }\n return 'linux'\n}\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 * Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.\n *\n * The 'Mod' token represents the \"primary modifier\" on each platform:\n * - macOS: 'Meta' (Command key ⌘)\n * - Windows/Linux: 'Control' (Ctrl key)\n *\n * This enables cross-platform hotkey definitions like 'Mod+S' that automatically\n * map to Command+S on Mac and Ctrl+S on Windows/Linux.\n *\n * @param modifier - The modifier to resolve. If 'Mod', resolves based on platform.\n * @param platform - The target platform. Defaults to auto-detection.\n * @returns The canonical modifier name ('Control', 'Shift', 'Alt', or 'Meta')\n *\n * @example\n * ```ts\n * resolveModifier('Mod', 'mac') // 'Meta'\n * resolveModifier('Mod', 'windows') // 'Control'\n * resolveModifier('Control', 'mac') // 'Control' (unchanged)\n * ```\n */\nexport function resolveModifier(\n modifier: CanonicalModifier | 'Mod',\n platform: 'mac' | 'windows' | 'linux' = detectPlatform(),\n): CanonicalModifier {\n if (modifier === 'Mod') {\n return platform === 'mac' ? 'Meta' : 'Control'\n }\n return modifier\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-F12).\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])\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 * 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 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])\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 // 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 // Check if it's a function key (normalize case)\n const upperKey = key.toUpperCase()\n if (/^F([1-9]|1[0-2])$/.test(upperKey)) {\n return upperKey\n }\n\n return key\n}\n\n// =============================================================================\n// Display Symbols\n// =============================================================================\n\n/**\n * Modifier key symbols for macOS display.\n *\n * Used by formatting functions to display hotkeys with macOS-style symbols\n * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides\n * a native macOS look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'\n * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'\n * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'\n * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'\n * ```\n */\nexport const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier | 'Mod', string> = {\n Control: '⌃',\n Alt: '⌥',\n Shift: '⇧',\n Meta: '⌘',\n Mod: '⌘',\n}\n\n/**\n * Modifier key labels for macOS display.\n *\n * Used by formatting functions to display hotkeys with macOS-style text labels\n * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.\n * This provides a familiar macOS look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * MAC_MODIFIER_LABELS['Control'] // 'control'\n * MAC_MODIFIER_LABELS['Alt'] // 'option'\n * MAC_MODIFIER_LABELS['Shift'] // 'shift'\n * MAC_MODIFIER_LABELS['Meta'] // 'cmd'\n * ```\n */\nexport const MAC_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> = {\n Control: 'Control',\n Alt: 'Option',\n Shift: 'Shift',\n Meta: 'Cmd',\n Mod: 'Cmd',\n}\n\n/**\n * Modifier key labels for Windows/Linux display.\n *\n * Used by formatting functions to display hotkeys with standard text labels\n * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.\n * This provides a familiar Windows/Linux look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'\n * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'\n * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'\n * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'\n * ```\n */\nexport const WINDOWS_MODIFIER_LABELS: Record<\n CanonicalModifier | 'Mod',\n string\n> = {\n Control: 'Ctrl',\n Alt: 'Alt',\n Shift: 'Shift',\n Meta: 'Win',\n Mod: 'Ctrl',\n}\n\nexport const LINUX_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> =\n {\n ...WINDOWS_MODIFIER_LABELS,\n Meta: 'Super',\n }\n\nexport const PUNCTUATION_KEY_DISPLAY_LABELS = {\n '`': 'Backquote',\n '\\\\': 'Backslash',\n '[': 'Left Bracket',\n ']': 'Right Bracket',\n ',': 'Comma',\n '=': 'Equal',\n '-': 'Minus',\n '.': 'Period',\n ';': 'Semicolon',\n} as const satisfies Record<string, string>\n\n/**\n * Special key symbols for display formatting.\n *\n * Maps certain keys to their visual symbols for better readability in hotkey displays.\n * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter\n * instead of text labels.\n *\n * @example\n * ```ts\n * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'\n * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'\n * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'\n * KEY_DISPLAY_SYMBOLS['Space'] // '␣'\n * ```\n */\nexport const KEY_DISPLAY_SYMBOLS = {\n ArrowUp: '↑',\n ArrowDown: '↓',\n ArrowLeft: '←',\n ArrowRight: '→',\n Enter: '↵',\n Escape: 'Esc',\n Backspace: '⌫',\n Delete: '⌦',\n Tab: '⇥',\n Space: '␣',\n} as const satisfies Record<string, string>\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,iBAA8C;AAC5D,KAAI,OAAO,cAAc,YACvB,QAAO;CAIT,MAAM,WAAW,UAAU,UAAU,aAAa,IAAI;CAEtD,MAAM,YAAY,UAAU,WAAW,aAAa,IAAI;AAExD,KAAI,SAAS,SAAS,MAAM,IAAI,UAAU,SAAS,MAAM,CACvD,QAAO;AAET,KAAI,SAAS,SAAS,MAAM,IAAI,UAAU,SAAS,MAAM,CACvD,QAAO;AAET,QAAO;;;;;;;;;;;;;;;;AAiBT,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;;;;;;;;;;;;;;;;;;;;;;AAuBD,SAAgB,gBACd,UACA,WAAwC,gBAAgB,EACrC;AACnB,KAAI,aAAa,MACf,QAAO,aAAa,QAAQ,SAAS;AAEvC,QAAO;;;;;;;;AAST,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;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;CACD,CAAC;;;;;;;;;;AAWF,MAAa,uBAA+C;CAC1D,WAAW;CACX,WAAW;CACX,aAAa;CACb,cAAc;CACd,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,WAAW;CACX,OAAO;CACR;;;;;;;;;;;;;;;AAgBD,MAAa,WAAW,IAAI,IAAI;CAC9B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACJ,CAAC;;;;;;;;;;;;;;;;;;;;AAqBF,MAAM,cAAsC;CAE1C,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;;CAItC,MAAM,WAAW,IAAI,aAAa;AAClC,KAAI,oBAAoB,KAAK,SAAS,CACpC,QAAO;AAGT,QAAO;;;;;;;;;;;;;;;;;AAsBT,MAAa,uBAAkE;CAC7E,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,sBAAiE;CAC5E,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,0BAGT;CACF,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;AAED,MAAa,wBACX;CACE,GAAG;CACH,MAAM;CACP;AAEH,MAAa,iCAAiC;CAC5C,KAAK;CACL,MAAM;CACN,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,sBAAsB;CACjC,SAAS;CACT,WAAW;CACX,WAAW;CACX,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,WAAW;CACX,QAAQ;CACR,KAAK;CACL,OAAO;CACR"}
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"}
@@ -0,0 +1,119 @@
1
+
2
+ //#region src/display-labels.ts
3
+ /**
4
+ * Modifier key symbols for macOS display.
5
+ *
6
+ * Used by formatting functions to display hotkeys with macOS-style symbols
7
+ * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
8
+ * a native macOS look and feel in hotkey displays.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
13
+ * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
14
+ * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
15
+ * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
16
+ * ```
17
+ */
18
+ const MAC_MODIFIER_SYMBOLS = {
19
+ Control: "⌃",
20
+ Alt: "⌥",
21
+ Shift: "⇧",
22
+ Meta: "⌘",
23
+ Mod: "⌘"
24
+ };
25
+ /**
26
+ * Modifier key labels for macOS display.
27
+ *
28
+ * Used by formatting functions to display hotkeys with macOS-style text labels
29
+ * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.
30
+ * This provides a familiar macOS look and feel in hotkey displays.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * MAC_MODIFIER_LABELS['Control'] // 'control'
35
+ * MAC_MODIFIER_LABELS['Alt'] // 'option'
36
+ * MAC_MODIFIER_LABELS['Shift'] // 'shift'
37
+ * MAC_MODIFIER_LABELS['Meta'] // 'cmd'
38
+ * ```
39
+ */
40
+ const MAC_MODIFIER_LABELS = {
41
+ Control: "Control",
42
+ Alt: "Option",
43
+ Shift: "Shift",
44
+ Meta: "Cmd",
45
+ Mod: "Cmd"
46
+ };
47
+ /**
48
+ * Modifier key labels for Windows/Linux display.
49
+ *
50
+ * Used by formatting functions to display hotkeys with standard text labels
51
+ * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
52
+ * This provides a familiar Windows/Linux look and feel in hotkey displays.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
57
+ * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
58
+ * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
59
+ * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
60
+ * ```
61
+ */
62
+ const WINDOWS_MODIFIER_LABELS = {
63
+ Control: "Ctrl",
64
+ Alt: "Alt",
65
+ Shift: "Shift",
66
+ Meta: "Win",
67
+ Mod: "Ctrl"
68
+ };
69
+ const LINUX_MODIFIER_LABELS = {
70
+ ...WINDOWS_MODIFIER_LABELS,
71
+ Meta: "Super"
72
+ };
73
+ const PUNCTUATION_KEY_DISPLAY_LABELS = {
74
+ "`": "Backquote",
75
+ "\\": "Backslash",
76
+ "[": "Left Bracket",
77
+ "]": "Right Bracket",
78
+ ",": "Comma",
79
+ "=": "Equal",
80
+ "-": "Minus",
81
+ ".": "Period",
82
+ ";": "Semicolon"
83
+ };
84
+ /**
85
+ * Special key symbols for display formatting.
86
+ *
87
+ * Maps certain keys to their visual symbols for better readability in hotkey displays.
88
+ * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
89
+ * instead of text labels.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
94
+ * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
95
+ * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
96
+ * KEY_DISPLAY_SYMBOLS['Space'] // '␣'
97
+ * ```
98
+ */
99
+ const KEY_DISPLAY_SYMBOLS = {
100
+ ArrowUp: "↑",
101
+ ArrowDown: "↓",
102
+ ArrowLeft: "←",
103
+ ArrowRight: "→",
104
+ Enter: "↵",
105
+ Escape: "Esc",
106
+ Backspace: "⌫",
107
+ Delete: "⌦",
108
+ Tab: "⇥",
109
+ Space: "␣"
110
+ };
111
+
112
+ //#endregion
113
+ exports.KEY_DISPLAY_SYMBOLS = KEY_DISPLAY_SYMBOLS;
114
+ exports.LINUX_MODIFIER_LABELS = LINUX_MODIFIER_LABELS;
115
+ exports.MAC_MODIFIER_LABELS = MAC_MODIFIER_LABELS;
116
+ exports.MAC_MODIFIER_SYMBOLS = MAC_MODIFIER_SYMBOLS;
117
+ exports.PUNCTUATION_KEY_DISPLAY_LABELS = PUNCTUATION_KEY_DISPLAY_LABELS;
118
+ exports.WINDOWS_MODIFIER_LABELS = WINDOWS_MODIFIER_LABELS;
119
+ //# sourceMappingURL=display-labels.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"display-labels.cjs","names":[],"sources":["../src/display-labels.ts"],"sourcesContent":["import type { CanonicalModifier } from './key.types'\n\n// =============================================================================\n// Display Symbols\n// =============================================================================\n\n/**\n * Modifier key symbols for macOS display.\n *\n * Used by formatting functions to display hotkeys with macOS-style symbols\n * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides\n * a native macOS look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'\n * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'\n * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'\n * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'\n * ```\n */\nexport const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier | 'Mod', string> = {\n Control: '⌃',\n Alt: '⌥',\n Shift: '⇧',\n Meta: '⌘',\n Mod: '⌘',\n}\n\n/**\n * Modifier key labels for macOS display.\n *\n * Used by formatting functions to display hotkeys with macOS-style text labels\n * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.\n * This provides a familiar macOS look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * MAC_MODIFIER_LABELS['Control'] // 'control'\n * MAC_MODIFIER_LABELS['Alt'] // 'option'\n * MAC_MODIFIER_LABELS['Shift'] // 'shift'\n * MAC_MODIFIER_LABELS['Meta'] // 'cmd'\n * ```\n */\nexport const MAC_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> = {\n Control: 'Control',\n Alt: 'Option',\n Shift: 'Shift',\n Meta: 'Cmd',\n Mod: 'Cmd',\n}\n\n/**\n * Modifier key labels for Windows/Linux display.\n *\n * Used by formatting functions to display hotkeys with standard text labels\n * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.\n * This provides a familiar Windows/Linux look and feel in hotkey displays.\n *\n * @example\n * ```ts\n * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'\n * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'\n * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'\n * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'\n * ```\n */\nexport const WINDOWS_MODIFIER_LABELS: Record<\n CanonicalModifier | 'Mod',\n string\n> = {\n Control: 'Ctrl',\n Alt: 'Alt',\n Shift: 'Shift',\n Meta: 'Win',\n Mod: 'Ctrl',\n}\n\nexport const LINUX_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string> =\n {\n ...WINDOWS_MODIFIER_LABELS,\n Meta: 'Super',\n }\n\nexport const PUNCTUATION_KEY_DISPLAY_LABELS = {\n '`': 'Backquote',\n '\\\\': 'Backslash',\n '[': 'Left Bracket',\n ']': 'Right Bracket',\n ',': 'Comma',\n '=': 'Equal',\n '-': 'Minus',\n '.': 'Period',\n ';': 'Semicolon',\n} as const satisfies Record<string, string>\n\n/**\n * Special key symbols for display formatting.\n *\n * Maps certain keys to their visual symbols for better readability in hotkey displays.\n * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter\n * instead of text labels.\n *\n * @example\n * ```ts\n * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'\n * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'\n * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'\n * KEY_DISPLAY_SYMBOLS['Space'] // '␣'\n * ```\n */\nexport const KEY_DISPLAY_SYMBOLS = {\n ArrowUp: '↑',\n ArrowDown: '↓',\n ArrowLeft: '←',\n ArrowRight: '→',\n Enter: '↵',\n Escape: 'Esc',\n Backspace: '⌫',\n Delete: '⌦',\n Tab: '⇥',\n Space: '␣',\n} as const satisfies Record<string, string>\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAa,uBAAkE;CAC7E,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,sBAAiE;CAC5E,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,0BAGT;CACF,SAAS;CACT,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACN;AAED,MAAa,wBACX;CACE,GAAG;CACH,MAAM;CACP;AAEH,MAAa,iCAAiC;CAC5C,KAAK;CACL,MAAM;CACN,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACN;;;;;;;;;;;;;;;;AAiBD,MAAa,sBAAsB;CACjC,SAAS;CACT,WAAW;CACX,WAAW;CACX,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,WAAW;CACX,QAAQ;CACR,KAAK;CACL,OAAO;CACR"}