@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,119 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,93 +0,0 @@
1
- import { CanonicalModifier } from "./key.types.cjs";
2
-
3
- //#region src/display-labels.d.ts
4
- /**
5
- * Modifier key symbols for macOS display.
6
- *
7
- * Used by formatting functions to display hotkeys with macOS-style symbols
8
- * (e.g., ⌘ for Command, ⌃ for Control) instead of text labels. This provides
9
- * a native macOS look and feel in hotkey displays.
10
- *
11
- * @example
12
- * ```ts
13
- * MAC_MODIFIER_SYMBOLS['Meta'] // '⌘'
14
- * MAC_MODIFIER_SYMBOLS['Control'] // '⌃'
15
- * MAC_MODIFIER_SYMBOLS['Alt'] // '⌥'
16
- * MAC_MODIFIER_SYMBOLS['Shift'] // '⇧'
17
- * ```
18
- */
19
- declare const MAC_MODIFIER_SYMBOLS: Record<CanonicalModifier | 'Mod', string>;
20
- /**
21
- * Modifier key labels for macOS display.
22
- *
23
- * Used by formatting functions to display hotkeys with macOS-style text labels
24
- * (e.g., 'Control' for Control, 'Option' for Alt, 'Cmd' for Meta) instead of symbols.
25
- * This provides a familiar macOS look and feel in hotkey displays.
26
- *
27
- * @example
28
- * ```ts
29
- * MAC_MODIFIER_LABELS['Control'] // 'control'
30
- * MAC_MODIFIER_LABELS['Alt'] // 'option'
31
- * MAC_MODIFIER_LABELS['Shift'] // 'shift'
32
- * MAC_MODIFIER_LABELS['Meta'] // 'cmd'
33
- * ```
34
- */
35
- declare const MAC_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
36
- /**
37
- * Modifier key labels for Windows/Linux display.
38
- *
39
- * Used by formatting functions to display hotkeys with standard text labels
40
- * (e.g., 'Ctrl' for Control, 'Win' for Meta/Windows key) instead of symbols.
41
- * This provides a familiar Windows/Linux look and feel in hotkey displays.
42
- *
43
- * @example
44
- * ```ts
45
- * STANDARD_MODIFIER_LABELS['Control'] // 'Ctrl'
46
- * STANDARD_MODIFIER_LABELS['Meta'] // 'Win'
47
- * STANDARD_MODIFIER_LABELS['Alt'] // 'Alt'
48
- * STANDARD_MODIFIER_LABELS['Shift'] // 'Shift'
49
- * ```
50
- */
51
- declare const WINDOWS_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
52
- declare const LINUX_MODIFIER_LABELS: Record<CanonicalModifier | 'Mod', string>;
53
- declare const PUNCTUATION_KEY_DISPLAY_LABELS: {
54
- readonly '`': "Backquote";
55
- readonly '\\': "Backslash";
56
- readonly '[': "Left Bracket";
57
- readonly ']': "Right Bracket";
58
- readonly ',': "Comma";
59
- readonly '=': "Equal";
60
- readonly '-': "Minus";
61
- readonly '.': "Period";
62
- readonly ';': "Semicolon";
63
- };
64
- /**
65
- * Special key symbols for display formatting.
66
- *
67
- * Maps certain keys to their visual symbols for better readability in hotkey displays.
68
- * Used by formatting functions to show symbols like ↑ for ArrowUp or ↵ for Enter
69
- * instead of text labels.
70
- *
71
- * @example
72
- * ```ts
73
- * KEY_DISPLAY_SYMBOLS['ArrowUp'] // '↑'
74
- * KEY_DISPLAY_SYMBOLS['Enter'] // '↵'
75
- * KEY_DISPLAY_SYMBOLS['Escape'] // 'Esc'
76
- * KEY_DISPLAY_SYMBOLS['Space'] // '␣'
77
- * ```
78
- */
79
- declare const KEY_DISPLAY_SYMBOLS: {
80
- readonly ArrowUp: "↑";
81
- readonly ArrowDown: "↓";
82
- readonly ArrowLeft: "←";
83
- readonly ArrowRight: "→";
84
- readonly Enter: "↵";
85
- readonly Escape: "Esc";
86
- readonly Backspace: "⌫";
87
- readonly Delete: "⌦";
88
- readonly Tab: "⇥";
89
- readonly Space: "␣";
90
- };
91
- //#endregion
92
- export { KEY_DISPLAY_SYMBOLS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS };
93
- //# sourceMappingURL=display-labels.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"display-labels.js","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"}
package/dist/format.cjs DELETED
@@ -1,85 +0,0 @@
1
- const require_constants = require('./constants.cjs');
2
- const require_display_labels = require('./display-labels.cjs');
3
- const require_platform = require('./platform.cjs');
4
- const require__keyboard_event = require('./_keyboard-event.cjs');
5
- const require_parse = require('./parse.cjs');
6
-
7
- //#region src/format.ts
8
- /**
9
- * Joins stored sequence steps with spaces, preserving physical code tokens.
10
- * For user-facing labels, call formatForDisplay on each step instead.
11
- *
12
- * @param sequence - Array of hotkey strings that form the sequence
13
- * @returns A space-separated string (e.g. ['G','G'] → 'G G')
14
- *
15
- * @example
16
- * ```ts
17
- * formatHotkeySequence(['G', 'G']) // 'G G'
18
- * formatHotkeySequence(['D', 'I', 'W']) // 'D I W'
19
- * ```
20
- */
21
- function formatHotkeySequence(sequence) {
22
- return sequence.join(" ");
23
- }
24
- /**
25
- * Converts a ParsedHotkey back to a hotkey string.
26
- *
27
- * @param parsed - The parsed hotkey object
28
- * @returns A hotkey string in canonical form
29
- *
30
- * @example
31
- * ```ts
32
- * formatHotkey({ key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] })
33
- * // Returns: 'Control+Shift+S'
34
- * ```
35
- */
36
- function formatHotkey(parsed) {
37
- if (parsed.code === void 0) require__keyboard_event.assertLogicalKey(parsed.key);
38
- const parts = [];
39
- for (const modifier of require_constants.MODIFIER_ORDER) if (parsed.modifiers.includes(modifier)) parts.push(modifier);
40
- parts.push(parsed.code !== void 0 ? `[${parsed.code}]` : parsed.key);
41
- return parts.join("+");
42
- }
43
- function formatForDisplay(hotkey, options = {}) {
44
- const platform = options.platform ?? require_platform.detectPlatform();
45
- const symbols = options.useSymbols ?? true;
46
- const modifierSymbols = typeof symbols === "boolean" ? symbols : symbols.modifiers ?? true;
47
- const keySymbols = typeof symbols === "boolean" ? symbols : symbols.keys ?? true;
48
- const separator = options.separatorToken ?? (platform === "mac" && modifierSymbols ? " " : "+");
49
- const parts = require__keyboard_event.splitHotkeyParts(typeof hotkey === "object" && "modifiers" in hotkey ? require_parse.normalizeHotkeyFromParsed(hotkey, platform) : require_parse.normalizeRegisterableHotkey(hotkey, platform)).map((segment) => {
50
- if (require_parse.isModifierKey(segment)) {
51
- const modifier = require_constants.MODIFIER_ALIASES[segment] ?? require_constants.MODIFIER_ALIASES[segment.toLowerCase()];
52
- return platform === "mac" ? modifierSymbols ? require_display_labels.MAC_MODIFIER_SYMBOLS[modifier] : require_display_labels.MAC_MODIFIER_LABELS[modifier] : platform === "windows" ? require_display_labels.WINDOWS_MODIFIER_LABELS[modifier] : require_display_labels.LINUX_MODIFIER_LABELS[modifier];
53
- }
54
- const code = /^\[([A-Za-z][A-Za-z0-9]*)\]$/.exec(segment)?.[1];
55
- const label = options.keyLabels?.[code ?? segment];
56
- if (label !== void 0) return label;
57
- const numpad = code?.startsWith("Numpad") ?? false;
58
- let displayKey = code ?? segment;
59
- const mappedKey = code ? options.layoutMap?.get(code) : void 0;
60
- if (mappedKey) displayKey = require_constants.normalizeKeyName(mappedKey);
61
- else if (code) if (/^Key[A-Z]$/.test(code)) displayKey = code.slice(3);
62
- else if (/^Digit[0-9]$/.test(code)) displayKey = code.slice(5);
63
- else if (numpad) displayKey = code.slice(6);
64
- else displayKey = require_constants.PUNCTUATION_CODE_MAP[code] ?? code;
65
- const display = (keySymbols ? require_display_labels.KEY_DISPLAY_SYMBOLS : require_display_labels.PUNCTUATION_KEY_DISPLAY_LABELS)[displayKey] ?? displayKey;
66
- return numpad ? `Numpad ${display.replace(/([a-z])([A-Z])/g, "$1 $2")}` : display;
67
- });
68
- return options.parts ? parts : parts.join(separator);
69
- }
70
- /**
71
- * @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option.
72
- */
73
- function formatWithLabels(hotkey, options = {}) {
74
- return formatForDisplay(hotkey, {
75
- ...options,
76
- useSymbols: false
77
- });
78
- }
79
-
80
- //#endregion
81
- exports.formatForDisplay = formatForDisplay;
82
- exports.formatHotkey = formatHotkey;
83
- exports.formatHotkeySequence = formatHotkeySequence;
84
- exports.formatWithLabels = formatWithLabels;
85
- //# sourceMappingURL=format.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.cjs","names":["MODIFIER_ORDER","detectPlatform","splitHotkeyParts","normalizeHotkeyFromParsed","normalizeRegisterableHotkey","isModifierKey","MODIFIER_ALIASES","MAC_MODIFIER_SYMBOLS","MAC_MODIFIER_LABELS","WINDOWS_MODIFIER_LABELS","LINUX_MODIFIER_LABELS","normalizeKeyName","PUNCTUATION_CODE_MAP","KEY_DISPLAY_SYMBOLS","PUNCTUATION_KEY_DISPLAY_LABELS"],"sources":["../src/format.ts"],"sourcesContent":["import {\n KEY_DISPLAY_SYMBOLS,\n LINUX_MODIFIER_LABELS,\n MAC_MODIFIER_LABELS,\n MAC_MODIFIER_SYMBOLS,\n PUNCTUATION_KEY_DISPLAY_LABELS,\n WINDOWS_MODIFIER_LABELS,\n} from './display-labels'\nimport {\n MODIFIER_ALIASES,\n MODIFIER_ORDER,\n PUNCTUATION_CODE_MAP,\n normalizeKeyName,\n} from './constants'\nimport { detectPlatform } from './platform'\nimport { assertLogicalKey, splitHotkeyParts } from './_keyboard-event'\nimport {\n isModifierKey,\n normalizeHotkeyFromParsed,\n normalizeRegisterableHotkey,\n} from './parse'\nimport type { CanonicalModifier } from './key.types'\nimport type { Hotkey, ParsedHotkey, RegisterableHotkey } from './hotkey.types'\n\n/**\n * Joins stored sequence steps with spaces, preserving physical code tokens.\n * For user-facing labels, call formatForDisplay on each step instead.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @returns A space-separated string (e.g. ['G','G'] → 'G G')\n *\n * @example\n * ```ts\n * formatHotkeySequence(['G', 'G']) // 'G G'\n * formatHotkeySequence(['D', 'I', 'W']) // 'D I W'\n * ```\n */\nexport function formatHotkeySequence(sequence: Array<Hotkey>): string {\n return sequence.join(' ')\n}\n\n/**\n * Converts a ParsedHotkey back to a hotkey string.\n *\n * @param parsed - The parsed hotkey object\n * @returns A hotkey string in canonical form\n *\n * @example\n * ```ts\n * formatHotkey({ key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] })\n * // Returns: 'Control+Shift+S'\n * ```\n */\nexport function formatHotkey(parsed: ParsedHotkey): string {\n if (parsed.code === undefined) assertLogicalKey(parsed.key)\n const parts: Array<string> = []\n\n // Add modifiers in canonical order\n for (const modifier of MODIFIER_ORDER) {\n if (parsed.modifiers.includes(modifier)) {\n parts.push(modifier)\n }\n }\n\n // Add the key\n parts.push(parsed.code !== undefined ? `[${parsed.code}]` : parsed.key)\n\n return parts.join('+')\n}\n\nexport type DisplayHotkey = RegisterableHotkey | ParsedHotkey | (string & {})\n\n/**\n * Formats a hotkey for display in a user interface.\n *\n * On macOS, uses symbols (⌘⇧S) in the same modifier order as {@link normalizeHotkeyFromParsed}.\n * On Windows/Linux, uses text (Ctrl+Shift+S) with `+` separators.\n * The separator can be customized with `separatorToken`.\n * Physical codes use conventional display labels: `[KeyS]` becomes `S` and\n * `[Digit2]` becomes `2`. These labels do not infer the active keyboard layout\n * or change matching. Supply a resolved `layoutMap` for layout-aware labels;\n * `keyLabels` overrides both layout entries and fallback labels.\n *\n * @param hotkey - A logical or physical string, raw binding, or ParsedHotkey\n * @param options - Formatting options\n * @returns Display text, or individual key labels when parts is true\n *\n * @example\n * ```ts\n * formatForDisplay('Mod+Shift+S', { platform: 'mac' })\n * // Returns: '⌘ ⇧ S' (symbols separated by spaces on macOS)\n *\n * formatForDisplay('Mod+Shift+S', { platform: 'windows' })\n * // Returns: 'Ctrl+Shift+S'\n *\n * formatForDisplay('Escape')\n * // Returns: 'Esc' (on all platforms)\n * ```\n */\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions & { parts: true },\n): Array<string>\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options?: FormatDisplayOptions & { parts?: false },\n): string\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions,\n): string | Array<string>\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions = {},\n): string | Array<string> {\n const platform = options.platform ?? detectPlatform()\n const symbols = options.useSymbols ?? true\n const modifierSymbols =\n typeof symbols === 'boolean' ? symbols : (symbols.modifiers ?? true)\n const keySymbols =\n typeof symbols === 'boolean' ? symbols : (symbols.keys ?? true)\n const separator =\n options.separatorToken ??\n (platform === 'mac' && modifierSymbols ? ' ' : '+')\n const normalized =\n typeof hotkey === 'object' && 'modifiers' in hotkey\n ? normalizeHotkeyFromParsed(hotkey, platform)\n : normalizeRegisterableHotkey(hotkey as RegisterableHotkey, platform)\n const parts = splitHotkeyParts(normalized).map((segment) => {\n if (isModifierKey(segment)) {\n const modifier = (MODIFIER_ALIASES[segment] ??\n MODIFIER_ALIASES[segment.toLowerCase()]) as CanonicalModifier | 'Mod'\n return platform === 'mac'\n ? modifierSymbols\n ? MAC_MODIFIER_SYMBOLS[modifier]\n : MAC_MODIFIER_LABELS[modifier]\n : platform === 'windows'\n ? WINDOWS_MODIFIER_LABELS[modifier]\n : LINUX_MODIFIER_LABELS[modifier]\n }\n const code = /^\\[([A-Za-z][A-Za-z0-9]*)\\]$/.exec(segment)?.[1]\n const label = options.keyLabels?.[code ?? segment]\n if (label !== undefined) return label\n // Shorten conventional position labels for display only; stored identity is unchanged.\n const numpad = code?.startsWith('Numpad') ?? false\n let displayKey = code ?? segment\n const mappedKey = code ? options.layoutMap?.get(code) : undefined\n if (mappedKey) {\n // Layout entries are logical labels; normalize their case and whitespace names.\n displayKey = normalizeKeyName(mappedKey)\n } else if (code) {\n if (/^Key[A-Z]$/.test(code)) displayKey = code.slice(3)\n else if (/^Digit[0-9]$/.test(code)) displayKey = code.slice(5)\n else if (numpad) displayKey = code.slice(6)\n else displayKey = PUNCTUATION_CODE_MAP[code] ?? code\n }\n const labels = keySymbols\n ? KEY_DISPLAY_SYMBOLS\n : PUNCTUATION_KEY_DISPLAY_LABELS\n const display =\n (labels as Partial<Record<string, string>>)[displayKey] ?? displayKey\n // Retain numpad identity while making longer names such as MemoryAdd readable.\n return numpad\n ? `Numpad ${display.replace(/([a-z])([A-Z])/g, '$1 $2')}`\n : display\n })\n return options.parts ? parts : parts.join(separator)\n}\n\n/**\n * @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option.\n */\nexport function formatWithLabels(\n hotkey: RegisterableHotkey,\n options: Omit<FormatDisplayOptions, 'useSymbols' | 'parts'> = {},\n): string {\n return formatForDisplay(hotkey, { ...options, useSymbols: false })\n}\n\n/**\n * Options for formatting hotkeys for display.\n */\nexport interface FormatDisplayOptions {\n /** The target platform. Defaults to auto-detection. */\n platform?: 'mac' | 'windows' | 'linux'\n /** Whether to use symbols for the display. Defaults to true. */\n useSymbols?: boolean | { modifiers?: boolean; keys?: boolean }\n /** Return individual key labels instead of a joined string. Default: false. */\n parts?: boolean\n /**\n * An already-resolved code-to-key map, such as KeyboardLayoutMap or Map.\n * Used only for physical bindings. Mapped keys receive normal display formatting;\n * missing or empty entries use conventional fallback labels. The caller owns\n * loading and refreshing the map; this formatter never calls browser APIs.\n */\n layoutMap?: { get: (code: string) => string | undefined }\n /** Final display overrides for logical keys or physical codes; take precedence over layoutMap. Never changes matching. */\n keyLabels?: Readonly<Record<string, string>>\n /** Override the separator between display tokens. Defaults to platform-specific formatting when null/undefined. */\n separatorToken?: string | null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,qBAAqB,UAAiC;AACpE,QAAO,SAAS,KAAK,IAAI;;;;;;;;;;;;;;AAe3B,SAAgB,aAAa,QAA8B;AACzD,KAAI,OAAO,SAAS,OAAW,0CAAiB,OAAO,IAAI;CAC3D,MAAM,QAAuB,EAAE;AAG/B,MAAK,MAAM,YAAYA,iCACrB,KAAI,OAAO,UAAU,SAAS,SAAS,CACrC,OAAM,KAAK,SAAS;AAKxB,OAAM,KAAK,OAAO,SAAS,SAAY,IAAI,OAAO,KAAK,KAAK,OAAO,IAAI;AAEvE,QAAO,MAAM,KAAK,IAAI;;AA4CxB,SAAgB,iBACd,QACA,UAAgC,EAAE,EACV;CACxB,MAAM,WAAW,QAAQ,YAAYC,iCAAgB;CACrD,MAAM,UAAU,QAAQ,cAAc;CACtC,MAAM,kBACJ,OAAO,YAAY,YAAY,UAAW,QAAQ,aAAa;CACjE,MAAM,aACJ,OAAO,YAAY,YAAY,UAAW,QAAQ,QAAQ;CAC5D,MAAM,YACJ,QAAQ,mBACP,aAAa,SAAS,kBAAkB,MAAM;CAKjD,MAAM,QAAQC,yCAHZ,OAAO,WAAW,YAAY,eAAe,SACzCC,wCAA0B,QAAQ,SAAS,GAC3CC,0CAA4B,QAA8B,SAAS,CAC/B,CAAC,KAAK,YAAY;AAC1D,MAAIC,4BAAc,QAAQ,EAAE;GAC1B,MAAM,WAAYC,mCAAiB,YACjCA,mCAAiB,QAAQ,aAAa;AACxC,UAAO,aAAa,QAChB,kBACEC,4CAAqB,YACrBC,2CAAoB,YACtB,aAAa,YACXC,+CAAwB,YACxBC,6CAAsB;;EAE9B,MAAM,OAAO,+BAA+B,KAAK,QAAQ,GAAG;EAC5D,MAAM,QAAQ,QAAQ,YAAY,QAAQ;AAC1C,MAAI,UAAU,OAAW,QAAO;EAEhC,MAAM,SAAS,MAAM,WAAW,SAAS,IAAI;EAC7C,IAAI,aAAa,QAAQ;EACzB,MAAM,YAAY,OAAO,QAAQ,WAAW,IAAI,KAAK,GAAG;AACxD,MAAI,UAEF,cAAaC,mCAAiB,UAAU;WAC/B,KACT,KAAI,aAAa,KAAK,KAAK,CAAE,cAAa,KAAK,MAAM,EAAE;WAC9C,eAAe,KAAK,KAAK,CAAE,cAAa,KAAK,MAAM,EAAE;WACrD,OAAQ,cAAa,KAAK,MAAM,EAAE;MACtC,cAAaC,uCAAqB,SAAS;EAKlD,MAAM,WAHS,aACXC,6CACAC,uDAE0C,eAAe;AAE7D,SAAO,SACH,UAAU,QAAQ,QAAQ,mBAAmB,QAAQ,KACrD;GACJ;AACF,QAAO,QAAQ,QAAQ,QAAQ,MAAM,KAAK,UAAU;;;;;AAMtD,SAAgB,iBACd,QACA,UAA8D,EAAE,EACxD;AACR,QAAO,iBAAiB,QAAQ;EAAE,GAAG;EAAS,YAAY;EAAO,CAAC"}
package/dist/format.d.cts DELETED
@@ -1,99 +0,0 @@
1
- import { Hotkey, ParsedHotkey, RegisterableHotkey } from "./hotkey.types.cjs";
2
-
3
- //#region src/format.d.ts
4
- /**
5
- * Joins stored sequence steps with spaces, preserving physical code tokens.
6
- * For user-facing labels, call formatForDisplay on each step instead.
7
- *
8
- * @param sequence - Array of hotkey strings that form the sequence
9
- * @returns A space-separated string (e.g. ['G','G'] → 'G G')
10
- *
11
- * @example
12
- * ```ts
13
- * formatHotkeySequence(['G', 'G']) // 'G G'
14
- * formatHotkeySequence(['D', 'I', 'W']) // 'D I W'
15
- * ```
16
- */
17
- declare function formatHotkeySequence(sequence: Array<Hotkey>): string;
18
- /**
19
- * Converts a ParsedHotkey back to a hotkey string.
20
- *
21
- * @param parsed - The parsed hotkey object
22
- * @returns A hotkey string in canonical form
23
- *
24
- * @example
25
- * ```ts
26
- * formatHotkey({ key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] })
27
- * // Returns: 'Control+Shift+S'
28
- * ```
29
- */
30
- declare function formatHotkey(parsed: ParsedHotkey): string;
31
- type DisplayHotkey = RegisterableHotkey | ParsedHotkey | (string & {});
32
- /**
33
- * Formats a hotkey for display in a user interface.
34
- *
35
- * On macOS, uses symbols (⌘⇧S) in the same modifier order as {@link normalizeHotkeyFromParsed}.
36
- * On Windows/Linux, uses text (Ctrl+Shift+S) with `+` separators.
37
- * The separator can be customized with `separatorToken`.
38
- * Physical codes use conventional display labels: `[KeyS]` becomes `S` and
39
- * `[Digit2]` becomes `2`. These labels do not infer the active keyboard layout
40
- * or change matching. Supply a resolved `layoutMap` for layout-aware labels;
41
- * `keyLabels` overrides both layout entries and fallback labels.
42
- *
43
- * @param hotkey - A logical or physical string, raw binding, or ParsedHotkey
44
- * @param options - Formatting options
45
- * @returns Display text, or individual key labels when parts is true
46
- *
47
- * @example
48
- * ```ts
49
- * formatForDisplay('Mod+Shift+S', { platform: 'mac' })
50
- * // Returns: '⌘ ⇧ S' (symbols separated by spaces on macOS)
51
- *
52
- * formatForDisplay('Mod+Shift+S', { platform: 'windows' })
53
- * // Returns: 'Ctrl+Shift+S'
54
- *
55
- * formatForDisplay('Escape')
56
- * // Returns: 'Esc' (on all platforms)
57
- * ```
58
- */
59
- declare function formatForDisplay(hotkey: DisplayHotkey, options: FormatDisplayOptions & {
60
- parts: true;
61
- }): Array<string>;
62
- declare function formatForDisplay(hotkey: DisplayHotkey, options?: FormatDisplayOptions & {
63
- parts?: false;
64
- }): string;
65
- declare function formatForDisplay(hotkey: DisplayHotkey, options: FormatDisplayOptions): string | Array<string>;
66
- /**
67
- * @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option.
68
- */
69
- declare function formatWithLabels(hotkey: RegisterableHotkey, options?: Omit<FormatDisplayOptions, 'useSymbols' | 'parts'>): string;
70
- /**
71
- * Options for formatting hotkeys for display.
72
- */
73
- interface FormatDisplayOptions {
74
- /** The target platform. Defaults to auto-detection. */
75
- platform?: 'mac' | 'windows' | 'linux';
76
- /** Whether to use symbols for the display. Defaults to true. */
77
- useSymbols?: boolean | {
78
- modifiers?: boolean;
79
- keys?: boolean;
80
- };
81
- /** Return individual key labels instead of a joined string. Default: false. */
82
- parts?: boolean;
83
- /**
84
- * An already-resolved code-to-key map, such as KeyboardLayoutMap or Map.
85
- * Used only for physical bindings. Mapped keys receive normal display formatting;
86
- * missing or empty entries use conventional fallback labels. The caller owns
87
- * loading and refreshing the map; this formatter never calls browser APIs.
88
- */
89
- layoutMap?: {
90
- get: (code: string) => string | undefined;
91
- };
92
- /** Final display overrides for logical keys or physical codes; take precedence over layoutMap. Never changes matching. */
93
- keyLabels?: Readonly<Record<string, string>>;
94
- /** Override the separator between display tokens. Defaults to platform-specific formatting when null/undefined. */
95
- separatorToken?: string | null;
96
- }
97
- //#endregion
98
- export { DisplayHotkey, FormatDisplayOptions, formatForDisplay, formatHotkey, formatHotkeySequence, formatWithLabels };
99
- //# sourceMappingURL=format.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import {\n KEY_DISPLAY_SYMBOLS,\n LINUX_MODIFIER_LABELS,\n MAC_MODIFIER_LABELS,\n MAC_MODIFIER_SYMBOLS,\n PUNCTUATION_KEY_DISPLAY_LABELS,\n WINDOWS_MODIFIER_LABELS,\n} from './display-labels'\nimport {\n MODIFIER_ALIASES,\n MODIFIER_ORDER,\n PUNCTUATION_CODE_MAP,\n normalizeKeyName,\n} from './constants'\nimport { detectPlatform } from './platform'\nimport { assertLogicalKey, splitHotkeyParts } from './_keyboard-event'\nimport {\n isModifierKey,\n normalizeHotkeyFromParsed,\n normalizeRegisterableHotkey,\n} from './parse'\nimport type { CanonicalModifier } from './key.types'\nimport type { Hotkey, ParsedHotkey, RegisterableHotkey } from './hotkey.types'\n\n/**\n * Joins stored sequence steps with spaces, preserving physical code tokens.\n * For user-facing labels, call formatForDisplay on each step instead.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @returns A space-separated string (e.g. ['G','G'] → 'G G')\n *\n * @example\n * ```ts\n * formatHotkeySequence(['G', 'G']) // 'G G'\n * formatHotkeySequence(['D', 'I', 'W']) // 'D I W'\n * ```\n */\nexport function formatHotkeySequence(sequence: Array<Hotkey>): string {\n return sequence.join(' ')\n}\n\n/**\n * Converts a ParsedHotkey back to a hotkey string.\n *\n * @param parsed - The parsed hotkey object\n * @returns A hotkey string in canonical form\n *\n * @example\n * ```ts\n * formatHotkey({ key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] })\n * // Returns: 'Control+Shift+S'\n * ```\n */\nexport function formatHotkey(parsed: ParsedHotkey): string {\n if (parsed.code === undefined) assertLogicalKey(parsed.key)\n const parts: Array<string> = []\n\n // Add modifiers in canonical order\n for (const modifier of MODIFIER_ORDER) {\n if (parsed.modifiers.includes(modifier)) {\n parts.push(modifier)\n }\n }\n\n // Add the key\n parts.push(parsed.code !== undefined ? `[${parsed.code}]` : parsed.key)\n\n return parts.join('+')\n}\n\nexport type DisplayHotkey = RegisterableHotkey | ParsedHotkey | (string & {})\n\n/**\n * Formats a hotkey for display in a user interface.\n *\n * On macOS, uses symbols (⌘⇧S) in the same modifier order as {@link normalizeHotkeyFromParsed}.\n * On Windows/Linux, uses text (Ctrl+Shift+S) with `+` separators.\n * The separator can be customized with `separatorToken`.\n * Physical codes use conventional display labels: `[KeyS]` becomes `S` and\n * `[Digit2]` becomes `2`. These labels do not infer the active keyboard layout\n * or change matching. Supply a resolved `layoutMap` for layout-aware labels;\n * `keyLabels` overrides both layout entries and fallback labels.\n *\n * @param hotkey - A logical or physical string, raw binding, or ParsedHotkey\n * @param options - Formatting options\n * @returns Display text, or individual key labels when parts is true\n *\n * @example\n * ```ts\n * formatForDisplay('Mod+Shift+S', { platform: 'mac' })\n * // Returns: '⌘ ⇧ S' (symbols separated by spaces on macOS)\n *\n * formatForDisplay('Mod+Shift+S', { platform: 'windows' })\n * // Returns: 'Ctrl+Shift+S'\n *\n * formatForDisplay('Escape')\n * // Returns: 'Esc' (on all platforms)\n * ```\n */\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions & { parts: true },\n): Array<string>\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options?: FormatDisplayOptions & { parts?: false },\n): string\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions,\n): string | Array<string>\nexport function formatForDisplay(\n hotkey: DisplayHotkey,\n options: FormatDisplayOptions = {},\n): string | Array<string> {\n const platform = options.platform ?? detectPlatform()\n const symbols = options.useSymbols ?? true\n const modifierSymbols =\n typeof symbols === 'boolean' ? symbols : (symbols.modifiers ?? true)\n const keySymbols =\n typeof symbols === 'boolean' ? symbols : (symbols.keys ?? true)\n const separator =\n options.separatorToken ??\n (platform === 'mac' && modifierSymbols ? ' ' : '+')\n const normalized =\n typeof hotkey === 'object' && 'modifiers' in hotkey\n ? normalizeHotkeyFromParsed(hotkey, platform)\n : normalizeRegisterableHotkey(hotkey as RegisterableHotkey, platform)\n const parts = splitHotkeyParts(normalized).map((segment) => {\n if (isModifierKey(segment)) {\n const modifier = (MODIFIER_ALIASES[segment] ??\n MODIFIER_ALIASES[segment.toLowerCase()]) as CanonicalModifier | 'Mod'\n return platform === 'mac'\n ? modifierSymbols\n ? MAC_MODIFIER_SYMBOLS[modifier]\n : MAC_MODIFIER_LABELS[modifier]\n : platform === 'windows'\n ? WINDOWS_MODIFIER_LABELS[modifier]\n : LINUX_MODIFIER_LABELS[modifier]\n }\n const code = /^\\[([A-Za-z][A-Za-z0-9]*)\\]$/.exec(segment)?.[1]\n const label = options.keyLabels?.[code ?? segment]\n if (label !== undefined) return label\n // Shorten conventional position labels for display only; stored identity is unchanged.\n const numpad = code?.startsWith('Numpad') ?? false\n let displayKey = code ?? segment\n const mappedKey = code ? options.layoutMap?.get(code) : undefined\n if (mappedKey) {\n // Layout entries are logical labels; normalize their case and whitespace names.\n displayKey = normalizeKeyName(mappedKey)\n } else if (code) {\n if (/^Key[A-Z]$/.test(code)) displayKey = code.slice(3)\n else if (/^Digit[0-9]$/.test(code)) displayKey = code.slice(5)\n else if (numpad) displayKey = code.slice(6)\n else displayKey = PUNCTUATION_CODE_MAP[code] ?? code\n }\n const labels = keySymbols\n ? KEY_DISPLAY_SYMBOLS\n : PUNCTUATION_KEY_DISPLAY_LABELS\n const display =\n (labels as Partial<Record<string, string>>)[displayKey] ?? displayKey\n // Retain numpad identity while making longer names such as MemoryAdd readable.\n return numpad\n ? `Numpad ${display.replace(/([a-z])([A-Z])/g, '$1 $2')}`\n : display\n })\n return options.parts ? parts : parts.join(separator)\n}\n\n/**\n * @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option.\n */\nexport function formatWithLabels(\n hotkey: RegisterableHotkey,\n options: Omit<FormatDisplayOptions, 'useSymbols' | 'parts'> = {},\n): string {\n return formatForDisplay(hotkey, { ...options, useSymbols: false })\n}\n\n/**\n * Options for formatting hotkeys for display.\n */\nexport interface FormatDisplayOptions {\n /** The target platform. Defaults to auto-detection. */\n platform?: 'mac' | 'windows' | 'linux'\n /** Whether to use symbols for the display. Defaults to true. */\n useSymbols?: boolean | { modifiers?: boolean; keys?: boolean }\n /** Return individual key labels instead of a joined string. Default: false. */\n parts?: boolean\n /**\n * An already-resolved code-to-key map, such as KeyboardLayoutMap or Map.\n * Used only for physical bindings. Mapped keys receive normal display formatting;\n * missing or empty entries use conventional fallback labels. The caller owns\n * loading and refreshing the map; this formatter never calls browser APIs.\n */\n layoutMap?: { get: (code: string) => string | undefined }\n /** Final display overrides for logical keys or physical codes; take precedence over layoutMap. Never changes matching. */\n keyLabels?: Readonly<Record<string, string>>\n /** Override the separator between display tokens. Defaults to platform-specific formatting when null/undefined. */\n separatorToken?: string | null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,qBAAqB,UAAiC;AACpE,QAAO,SAAS,KAAK,IAAI;;;;;;;;;;;;;;AAe3B,SAAgB,aAAa,QAA8B;AACzD,KAAI,OAAO,SAAS,OAAW,kBAAiB,OAAO,IAAI;CAC3D,MAAM,QAAuB,EAAE;AAG/B,MAAK,MAAM,YAAY,eACrB,KAAI,OAAO,UAAU,SAAS,SAAS,CACrC,OAAM,KAAK,SAAS;AAKxB,OAAM,KAAK,OAAO,SAAS,SAAY,IAAI,OAAO,KAAK,KAAK,OAAO,IAAI;AAEvE,QAAO,MAAM,KAAK,IAAI;;AA4CxB,SAAgB,iBACd,QACA,UAAgC,EAAE,EACV;CACxB,MAAM,WAAW,QAAQ,YAAY,gBAAgB;CACrD,MAAM,UAAU,QAAQ,cAAc;CACtC,MAAM,kBACJ,OAAO,YAAY,YAAY,UAAW,QAAQ,aAAa;CACjE,MAAM,aACJ,OAAO,YAAY,YAAY,UAAW,QAAQ,QAAQ;CAC5D,MAAM,YACJ,QAAQ,mBACP,aAAa,SAAS,kBAAkB,MAAM;CAKjD,MAAM,QAAQ,iBAHZ,OAAO,WAAW,YAAY,eAAe,SACzC,0BAA0B,QAAQ,SAAS,GAC3C,4BAA4B,QAA8B,SAAS,CAC/B,CAAC,KAAK,YAAY;AAC1D,MAAI,cAAc,QAAQ,EAAE;GAC1B,MAAM,WAAY,iBAAiB,YACjC,iBAAiB,QAAQ,aAAa;AACxC,UAAO,aAAa,QAChB,kBACE,qBAAqB,YACrB,oBAAoB,YACtB,aAAa,YACX,wBAAwB,YACxB,sBAAsB;;EAE9B,MAAM,OAAO,+BAA+B,KAAK,QAAQ,GAAG;EAC5D,MAAM,QAAQ,QAAQ,YAAY,QAAQ;AAC1C,MAAI,UAAU,OAAW,QAAO;EAEhC,MAAM,SAAS,MAAM,WAAW,SAAS,IAAI;EAC7C,IAAI,aAAa,QAAQ;EACzB,MAAM,YAAY,OAAO,QAAQ,WAAW,IAAI,KAAK,GAAG;AACxD,MAAI,UAEF,cAAa,iBAAiB,UAAU;WAC/B,KACT,KAAI,aAAa,KAAK,KAAK,CAAE,cAAa,KAAK,MAAM,EAAE;WAC9C,eAAe,KAAK,KAAK,CAAE,cAAa,KAAK,MAAM,EAAE;WACrD,OAAQ,cAAa,KAAK,MAAM,EAAE;MACtC,cAAa,qBAAqB,SAAS;EAKlD,MAAM,WAHS,aACX,sBACA,gCAE0C,eAAe;AAE7D,SAAO,SACH,UAAU,QAAQ,QAAQ,mBAAmB,QAAQ,KACrD;GACJ;AACF,QAAO,QAAQ,QAAQ,QAAQ,MAAM,KAAK,UAAU;;;;;AAMtD,SAAgB,iBACd,QACA,UAA8D,EAAE,EACxD;AACR,QAAO,iBAAiB,QAAQ;EAAE,GAAG;EAAS,YAAY;EAAO,CAAC"}
package/dist/hint.cjs DELETED
@@ -1,24 +0,0 @@
1
- const require_constants = require('./constants.cjs');
2
- const require_parse = require('./parse.cjs');
3
-
4
- //#region src/hint.ts
5
- /**
6
- * Returns whether held modifiers should reveal a shortcut hint.
7
- * By default, any nonempty subset of the binding's modifiers qualifies; an
8
- * unrelated modifier hides the hint. `exact` requires every binding modifier.
9
- * Nonmodifier keys are ignored. This does not check registration or focus.
10
- *
11
- * @example
12
- * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt']) // true
13
- * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt', 'Control']) // false
14
- */
15
- function matchesHeldModifiers(hotkey, heldKeys, options = {}) {
16
- if (heldKeys.includes("AltGraph")) return false;
17
- const held = [...new Set(heldKeys.map(require_constants.normalizeKeyName).filter((key) => require_constants.MODIFIER_KEYS.has(key)))];
18
- const { modifiers } = require_parse.parseRegisterableHotkey(hotkey, options.platform);
19
- return held.length > 0 && held.every((key) => modifiers.includes(key)) && (!options.exact || held.length === modifiers.length);
20
- }
21
-
22
- //#endregion
23
- exports.matchesHeldModifiers = matchesHeldModifiers;
24
- //# sourceMappingURL=hint.cjs.map
package/dist/hint.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hint.cjs","names":["normalizeKeyName","MODIFIER_KEYS","parseRegisterableHotkey"],"sources":["../src/hint.ts"],"sourcesContent":["import { MODIFIER_KEYS, normalizeKeyName } from './constants'\nimport { parseRegisterableHotkey } from './parse'\nimport type { CanonicalModifier } from './key.types'\nimport type { RegisterableHotkey } from './hotkey.types'\n\nexport interface HeldModifierOptions {\n /** Resolve Mod for this platform. Defaults to platform detection. */\n platform?: 'mac' | 'windows' | 'linux'\n /** Require every binding modifier to be held. Default: false (nonempty subset). */\n exact?: boolean\n}\n\n/**\n * Returns whether held modifiers should reveal a shortcut hint.\n * By default, any nonempty subset of the binding's modifiers qualifies; an\n * unrelated modifier hides the hint. `exact` requires every binding modifier.\n * Nonmodifier keys are ignored. This does not check registration or focus.\n *\n * @example\n * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt']) // true\n * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt', 'Control']) // false\n */\nexport function matchesHeldModifiers(\n hotkey: RegisterableHotkey,\n heldKeys: ReadonlyArray<string>,\n options: HeldModifierOptions = {},\n): boolean {\n // AltGraph (AltGr) types alternate characters such as @ or € on many layouts.\n // It can synthesize Ctrl+Alt; character entry should not reveal shortcut hints.\n if (heldKeys.includes('AltGraph')) return false\n const held = [\n ...new Set(\n heldKeys.map(normalizeKeyName).filter((key) => MODIFIER_KEYS.has(key)),\n ),\n ]\n const { modifiers } = parseRegisterableHotkey(hotkey, options.platform)\n return (\n held.length > 0 &&\n held.every((key) => modifiers.includes(key as CanonicalModifier)) &&\n (!options.exact || held.length === modifiers.length)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,qBACd,QACA,UACA,UAA+B,EAAE,EACxB;AAGT,KAAI,SAAS,SAAS,WAAW,CAAE,QAAO;CAC1C,MAAM,OAAO,CACX,GAAG,IAAI,IACL,SAAS,IAAIA,mCAAiB,CAAC,QAAQ,QAAQC,gCAAc,IAAI,IAAI,CAAC,CACvE,CACF;CACD,MAAM,EAAE,cAAcC,sCAAwB,QAAQ,QAAQ,SAAS;AACvE,QACE,KAAK,SAAS,KACd,KAAK,OAAO,QAAQ,UAAU,SAAS,IAAyB,CAAC,KAChE,CAAC,QAAQ,SAAS,KAAK,WAAW,UAAU"}
package/dist/hint.d.cts DELETED
@@ -1,23 +0,0 @@
1
- import { RegisterableHotkey } from "./hotkey.types.cjs";
2
-
3
- //#region src/hint.d.ts
4
- interface HeldModifierOptions {
5
- /** Resolve Mod for this platform. Defaults to platform detection. */
6
- platform?: 'mac' | 'windows' | 'linux';
7
- /** Require every binding modifier to be held. Default: false (nonempty subset). */
8
- exact?: boolean;
9
- }
10
- /**
11
- * Returns whether held modifiers should reveal a shortcut hint.
12
- * By default, any nonempty subset of the binding's modifiers qualifies; an
13
- * unrelated modifier hides the hint. `exact` requires every binding modifier.
14
- * Nonmodifier keys are ignored. This does not check registration or focus.
15
- *
16
- * @example
17
- * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt']) // true
18
- * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt', 'Control']) // false
19
- */
20
- declare function matchesHeldModifiers(hotkey: RegisterableHotkey, heldKeys: ReadonlyArray<string>, options?: HeldModifierOptions): boolean;
21
- //#endregion
22
- export { HeldModifierOptions, matchesHeldModifiers };
23
- //# sourceMappingURL=hint.d.cts.map
package/dist/hint.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hint.js","names":[],"sources":["../src/hint.ts"],"sourcesContent":["import { MODIFIER_KEYS, normalizeKeyName } from './constants'\nimport { parseRegisterableHotkey } from './parse'\nimport type { CanonicalModifier } from './key.types'\nimport type { RegisterableHotkey } from './hotkey.types'\n\nexport interface HeldModifierOptions {\n /** Resolve Mod for this platform. Defaults to platform detection. */\n platform?: 'mac' | 'windows' | 'linux'\n /** Require every binding modifier to be held. Default: false (nonempty subset). */\n exact?: boolean\n}\n\n/**\n * Returns whether held modifiers should reveal a shortcut hint.\n * By default, any nonempty subset of the binding's modifiers qualifies; an\n * unrelated modifier hides the hint. `exact` requires every binding modifier.\n * Nonmodifier keys are ignored. This does not check registration or focus.\n *\n * @example\n * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt']) // true\n * matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt', 'Control']) // false\n */\nexport function matchesHeldModifiers(\n hotkey: RegisterableHotkey,\n heldKeys: ReadonlyArray<string>,\n options: HeldModifierOptions = {},\n): boolean {\n // AltGraph (AltGr) types alternate characters such as @ or € on many layouts.\n // It can synthesize Ctrl+Alt; character entry should not reveal shortcut hints.\n if (heldKeys.includes('AltGraph')) return false\n const held = [\n ...new Set(\n heldKeys.map(normalizeKeyName).filter((key) => MODIFIER_KEYS.has(key)),\n ),\n ]\n const { modifiers } = parseRegisterableHotkey(hotkey, options.platform)\n return (\n held.length > 0 &&\n held.every((key) => modifiers.includes(key as CanonicalModifier)) &&\n (!options.exact || held.length === modifiers.length)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,qBACd,QACA,UACA,UAA+B,EAAE,EACxB;AAGT,KAAI,SAAS,SAAS,WAAW,CAAE,QAAO;CAC1C,MAAM,OAAO,CACX,GAAG,IAAI,IACL,SAAS,IAAI,iBAAiB,CAAC,QAAQ,QAAQ,cAAc,IAAI,IAAI,CAAC,CACvE,CACF;CACD,MAAM,EAAE,cAAc,wBAAwB,QAAQ,QAAQ,SAAS;AACvE,QACE,KAAK,SAAS,KACd,KAAK,OAAO,QAAQ,UAAU,SAAS,IAAyB,CAAC,KAChE,CAAC,QAAQ,SAAS,KAAK,WAAW,UAAU"}