@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.
- package/dist/_event-target.js +1 -2
- package/dist/_keyboard-event.js +1 -2
- package/dist/_match.js +1 -2
- package/dist/_named-keys.d.ts +3 -5
- package/dist/_named-keys.js +1 -2
- package/dist/_recorder-chord.js +1 -2
- package/dist/_recording-guard.js +1 -2
- package/dist/_registration.js +1 -2
- package/dist/conflicts.d.ts +4 -7
- package/dist/conflicts.js +1 -2
- package/dist/constants.d.ts +14 -17
- package/dist/constants.js +8 -9
- package/dist/display-labels.d.ts +7 -10
- package/dist/display-labels.js +1 -2
- package/dist/format.d.ts +12 -14
- package/dist/format.js +17 -7
- package/dist/hint.d.ts +3 -6
- package/dist/hint.js +1 -2
- package/dist/hotkey-manager.d.ts +8 -10
- package/dist/hotkey-manager.js +21 -3
- package/dist/hotkey-recorder.d.ts +4 -7
- package/dist/hotkey-recorder.js +9 -6
- package/dist/hotkey-sequence-recorder.d.ts +5 -8
- package/dist/hotkey-sequence-recorder.js +6 -7
- package/dist/hotkey.types.d.ts +15 -18
- package/dist/key-state-tracker.d.ts +4 -7
- package/dist/key-state-tracker.js +6 -3
- package/dist/key.types.d.ts +17 -20
- package/dist/match.d.ts +8 -11
- package/dist/match.js +1 -2
- package/dist/parse.d.ts +11 -14
- package/dist/parse.js +5 -4
- package/dist/platform.d.ts +3 -6
- package/dist/platform.js +1 -2
- package/dist/recorder-options.d.ts +6 -9
- package/dist/sequence-manager.d.ts +11 -14
- package/dist/sequence-manager.js +12 -7
- package/dist/validate.d.ts +5 -8
- package/dist/validate.js +1 -2
- package/package.json +8 -13
- package/dist/_event-target.cjs +0 -73
- package/dist/_event-target.cjs.map +0 -1
- package/dist/_event-target.js.map +0 -1
- package/dist/_keyboard-event.cjs +0 -83
- package/dist/_keyboard-event.cjs.map +0 -1
- package/dist/_keyboard-event.js.map +0 -1
- package/dist/_match.cjs +0 -49
- package/dist/_match.cjs.map +0 -1
- package/dist/_match.js.map +0 -1
- package/dist/_named-keys.cjs +0 -68
- package/dist/_named-keys.cjs.map +0 -1
- package/dist/_named-keys.d.cts +0 -8
- package/dist/_named-keys.js.map +0 -1
- package/dist/_recorder-chord.cjs +0 -44
- package/dist/_recorder-chord.cjs.map +0 -1
- package/dist/_recorder-chord.js.map +0 -1
- package/dist/_recording-guard.cjs +0 -59
- package/dist/_recording-guard.cjs.map +0 -1
- package/dist/_recording-guard.js.map +0 -1
- package/dist/_registration.cjs +0 -54
- package/dist/_registration.cjs.map +0 -1
- package/dist/_registration.js.map +0 -1
- package/dist/conflicts.cjs +0 -55
- package/dist/conflicts.cjs.map +0 -1
- package/dist/conflicts.d.cts +0 -39
- package/dist/conflicts.js.map +0 -1
- package/dist/constants.cjs +0 -410
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -165
- package/dist/constants.js.map +0 -1
- package/dist/display-labels.cjs +0 -119
- package/dist/display-labels.cjs.map +0 -1
- package/dist/display-labels.d.cts +0 -93
- package/dist/display-labels.js.map +0 -1
- package/dist/format.cjs +0 -85
- package/dist/format.cjs.map +0 -1
- package/dist/format.d.cts +0 -99
- package/dist/format.js.map +0 -1
- package/dist/hint.cjs +0 -24
- package/dist/hint.cjs.map +0 -1
- package/dist/hint.d.cts +0 -23
- package/dist/hint.js.map +0 -1
- package/dist/hotkey-manager.cjs +0 -414
- package/dist/hotkey-manager.cjs.map +0 -1
- package/dist/hotkey-manager.d.cts +0 -234
- package/dist/hotkey-manager.js.map +0 -1
- package/dist/hotkey-recorder.cjs +0 -235
- package/dist/hotkey-recorder.cjs.map +0 -1
- package/dist/hotkey-recorder.d.cts +0 -119
- package/dist/hotkey-recorder.js.map +0 -1
- package/dist/hotkey-sequence-recorder.cjs +0 -255
- package/dist/hotkey-sequence-recorder.cjs.map +0 -1
- package/dist/hotkey-sequence-recorder.d.cts +0 -86
- package/dist/hotkey-sequence-recorder.js.map +0 -1
- package/dist/hotkey.types.d.cts +0 -236
- package/dist/index.cjs +0 -71
- package/dist/index.d.cts +0 -18
- package/dist/key-state-tracker.cjs +0 -197
- package/dist/key-state-tracker.cjs.map +0 -1
- package/dist/key-state-tracker.d.cts +0 -107
- package/dist/key-state-tracker.js.map +0 -1
- package/dist/key.types.d.cts +0 -82
- package/dist/match.cjs +0 -144
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -101
- package/dist/match.js.map +0 -1
- package/dist/parse.cjs +0 -245
- package/dist/parse.cjs.map +0 -1
- package/dist/parse.d.cts +0 -134
- package/dist/parse.js.map +0 -1
- package/dist/platform.cjs +0 -55
- package/dist/platform.cjs.map +0 -1
- package/dist/platform.d.cts +0 -44
- package/dist/platform.js.map +0 -1
- package/dist/recorder-options.d.cts +0 -34
- package/dist/sequence-manager.cjs +0 -441
- package/dist/sequence-manager.cjs.map +0 -1
- package/dist/sequence-manager.d.cts +0 -172
- package/dist/sequence-manager.js.map +0 -1
- package/dist/validate.cjs +0 -112
- package/dist/validate.cjs.map +0 -1
- package/dist/validate.d.cts +0 -67
- package/dist/validate.js.map +0 -1
- package/src/_event-target.ts +0 -157
- package/src/_keyboard-event.ts +0 -101
- package/src/_match.ts +0 -96
- package/src/_named-keys.ts +0 -62
- package/src/_recorder-chord.ts +0 -76
- package/src/_recording-guard.ts +0 -63
- package/src/_registration.ts +0 -79
- package/src/conflicts.ts +0 -125
- package/src/constants.ts +0 -455
- package/src/display-labels.ts +0 -123
- package/src/format.ts +0 -201
- package/src/hint.ts +0 -42
- package/src/hotkey-manager.ts +0 -814
- package/src/hotkey-recorder.ts +0 -348
- package/src/hotkey-sequence-recorder.ts +0 -410
- package/src/hotkey.types.ts +0 -269
- package/src/index.ts +0 -17
- package/src/key-state-tracker.ts +0 -261
- package/src/key.types.ts +0 -268
- package/src/match.ts +0 -210
- package/src/parse.ts +0 -369
- package/src/platform.ts +0 -66
- package/src/recorder-options.ts +0 -34
- package/src/sequence-manager.ts +0 -769
- package/src/validate.ts +0 -179
package/dist/hotkey-recorder.js
CHANGED
|
@@ -49,14 +49,18 @@ import { Store } from "@tanstack/store";
|
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
var HotkeyRecorder = class {
|
|
52
|
+
/**
|
|
53
|
+
* The TanStack Store instance containing the recorder state.
|
|
54
|
+
* Use this to subscribe to state changes or access current state.
|
|
55
|
+
*/
|
|
56
|
+
store = new Store({
|
|
57
|
+
isRecording: false,
|
|
58
|
+
recordedHotkey: null
|
|
59
|
+
});
|
|
52
60
|
#keydownHandler = null;
|
|
53
61
|
#options;
|
|
54
62
|
#platform;
|
|
55
63
|
constructor(options) {
|
|
56
|
-
this.store = new Store({
|
|
57
|
-
isRecording: false,
|
|
58
|
-
recordedHotkey: null
|
|
59
|
-
});
|
|
60
64
|
this.#options = options;
|
|
61
65
|
this.#platform = detectPlatform();
|
|
62
66
|
}
|
|
@@ -231,5 +235,4 @@ var HotkeyRecorder = class {
|
|
|
231
235
|
};
|
|
232
236
|
|
|
233
237
|
//#endregion
|
|
234
|
-
export { HotkeyRecorder };
|
|
235
|
-
//# sourceMappingURL=hotkey-recorder.js.map
|
|
238
|
+
export { HotkeyRecorder };
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { HotkeySequence } from "./sequence-manager.js";
|
|
2
2
|
import { HotkeySequenceRecorderValidationContext, RecorderOptions } from "./recorder-options.js";
|
|
3
3
|
import { Store } from "@tanstack/store";
|
|
4
|
-
|
|
5
4
|
//#region src/hotkey-sequence-recorder.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* How the user can commit a recorded sequence from the keyboard.
|
|
8
7
|
* - `'enter'`: plain Enter (no modifiers) commits when at least one step exists.
|
|
9
8
|
* - `'none'`: only {@link HotkeySequenceRecorder.commit} finishes recording (or idle timeout if set).
|
|
10
9
|
*/
|
|
11
|
-
type HotkeySequenceRecorderCommitKeys = 'enter' | 'none';
|
|
10
|
+
export type HotkeySequenceRecorderCommitKeys = 'enter' | 'none';
|
|
12
11
|
/**
|
|
13
12
|
* State interface for the HotkeySequenceRecorder.
|
|
14
13
|
*/
|
|
15
|
-
interface HotkeySequenceRecorderState {
|
|
14
|
+
export interface HotkeySequenceRecorderState {
|
|
16
15
|
/** Whether recording is currently active */
|
|
17
16
|
isRecording: boolean;
|
|
18
17
|
/** Chords captured so far in the current recording session */
|
|
@@ -23,7 +22,7 @@ interface HotkeySequenceRecorderState {
|
|
|
23
22
|
/**
|
|
24
23
|
* Options for configuring a HotkeySequenceRecorder instance.
|
|
25
24
|
*/
|
|
26
|
-
interface HotkeySequenceRecorderOptions extends RecorderOptions {
|
|
25
|
+
export interface HotkeySequenceRecorderOptions extends RecorderOptions {
|
|
27
26
|
/** Validate the completed sequence. Rejection preserves the steps for editing. */
|
|
28
27
|
validate?: (sequence: HotkeySequence, context: HotkeySequenceRecorderValidationContext) => boolean | string;
|
|
29
28
|
/** Callback when a sequence is successfully recorded */
|
|
@@ -63,7 +62,7 @@ interface HotkeySequenceRecorderOptions extends RecorderOptions {
|
|
|
63
62
|
* when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,
|
|
64
63
|
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
65
64
|
*/
|
|
66
|
-
declare class HotkeySequenceRecorder {
|
|
65
|
+
export declare class HotkeySequenceRecorder {
|
|
67
66
|
#private;
|
|
68
67
|
readonly store: Store<HotkeySequenceRecorderState>;
|
|
69
68
|
constructor(options: HotkeySequenceRecorderOptions);
|
|
@@ -81,6 +80,4 @@ declare class HotkeySequenceRecorder {
|
|
|
81
80
|
cancel(): void;
|
|
82
81
|
destroy(): void;
|
|
83
82
|
}
|
|
84
|
-
//#endregion
|
|
85
|
-
export { HotkeySequenceRecorder, HotkeySequenceRecorderCommitKeys, HotkeySequenceRecorderOptions, HotkeySequenceRecorderState };
|
|
86
|
-
//# sourceMappingURL=hotkey-sequence-recorder.d.ts.map
|
|
83
|
+
//#endregion
|
|
@@ -26,17 +26,17 @@ function resolvedCommitOnEnter(options) {
|
|
|
26
26
|
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
27
27
|
*/
|
|
28
28
|
var HotkeySequenceRecorder = class {
|
|
29
|
+
store = new Store({
|
|
30
|
+
isRecording: false,
|
|
31
|
+
steps: [],
|
|
32
|
+
recordedSequence: null
|
|
33
|
+
});
|
|
29
34
|
#keydownHandler = null;
|
|
30
35
|
#options;
|
|
31
36
|
#platform;
|
|
32
37
|
#events = [];
|
|
33
38
|
#idleTimer = null;
|
|
34
39
|
constructor(options) {
|
|
35
|
-
this.store = new Store({
|
|
36
|
-
isRecording: false,
|
|
37
|
-
steps: [],
|
|
38
|
-
recordedSequence: null
|
|
39
|
-
});
|
|
40
40
|
this.#options = {
|
|
41
41
|
...defaultHotkeySequenceRecorderOptions,
|
|
42
42
|
...options
|
|
@@ -251,5 +251,4 @@ var HotkeySequenceRecorder = class {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
//#endregion
|
|
254
|
-
export { HotkeySequenceRecorder };
|
|
255
|
-
//# sourceMappingURL=hotkey-sequence-recorder.js.map
|
|
254
|
+
export { HotkeySequenceRecorder };
|
package/dist/hotkey.types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CanonicalModifier, Key, LogicalKey } from "./key.types.js";
|
|
2
|
-
|
|
3
2
|
//#region src/hotkey.types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Single modifier + key combinations.
|
|
@@ -12,7 +11,7 @@ import { CanonicalModifier, Key, LogicalKey } from "./key.types.js";
|
|
|
12
11
|
* This enables cross-platform hotkey definitions that automatically adapt to the platform.
|
|
13
12
|
* For example, `Mod+S` becomes `Command+S` on Mac and `Ctrl+S` on Windows/Linux.
|
|
14
13
|
*/
|
|
15
|
-
type SingleModifierHotkey = `Control+${Key}` | `Alt+${Key}` | `Shift+${Key}` | `Meta+${Key}` | `Mod+${Key}`;
|
|
14
|
+
export type SingleModifierHotkey = `Control+${Key}` | `Alt+${Key}` | `Shift+${Key}` | `Meta+${Key}` | `Mod+${Key}`;
|
|
16
15
|
/**
|
|
17
16
|
* Two modifier + key combinations.
|
|
18
17
|
*
|
|
@@ -22,7 +21,7 @@ type SingleModifierHotkey = `Control+${Key}` | `Alt+${Key}` | `Shift+${Key}` | `
|
|
|
22
21
|
* - `Mod+Control` duplicates `Control` on Windows/Linux (Mod = Control)
|
|
23
22
|
* - `Mod+Meta` duplicates `Meta` on macOS (Mod = Meta)
|
|
24
23
|
*/
|
|
25
|
-
type TwoModifierHotkey = `Control+Alt+${Key}` | `Control+Shift+${Key}` | `Control+Meta+${Key}` | `Alt+Shift+${Key}` | `Alt+Meta+${Key}` | `Shift+Meta+${Key}` | `Mod+Alt+${Key}` | `Mod+Shift+${Key}`;
|
|
24
|
+
export type TwoModifierHotkey = `Control+Alt+${Key}` | `Control+Shift+${Key}` | `Control+Meta+${Key}` | `Alt+Shift+${Key}` | `Alt+Meta+${Key}` | `Shift+Meta+${Key}` | `Mod+Alt+${Key}` | `Mod+Shift+${Key}`;
|
|
26
25
|
/**
|
|
27
26
|
* Three modifier + key combinations.
|
|
28
27
|
*
|
|
@@ -32,7 +31,7 @@ type TwoModifierHotkey = `Control+Alt+${Key}` | `Control+Shift+${Key}` | `Contro
|
|
|
32
31
|
* - `Mod+Control+Shift` duplicates `Control` on Windows/Linux (Mod = Control)
|
|
33
32
|
* - `Mod+Shift+Meta` duplicates `Meta` on macOS (Mod = Meta)
|
|
34
33
|
*/
|
|
35
|
-
type ThreeModifierHotkey = `Control+Alt+Shift+${Key}` | `Control+Alt+Meta+${Key}` | `Control+Shift+Meta+${Key}` | `Alt+Shift+Meta+${Key}` | `Mod+Alt+Shift+${Key}`;
|
|
34
|
+
export type ThreeModifierHotkey = `Control+Alt+Shift+${Key}` | `Control+Alt+Meta+${Key}` | `Control+Shift+Meta+${Key}` | `Alt+Shift+Meta+${Key}` | `Mod+Alt+Shift+${Key}`;
|
|
36
35
|
/**
|
|
37
36
|
* Four modifier + key combinations.
|
|
38
37
|
*
|
|
@@ -45,7 +44,7 @@ type ThreeModifierHotkey = `Control+Alt+Shift+${Key}` | `Control+Alt+Meta+${Key}
|
|
|
45
44
|
* - `Mod+Control+Alt+Shift` → duplicates `Control` on Windows/Linux
|
|
46
45
|
* - `Mod+Alt+Shift+Meta` → duplicates `Meta` on macOS
|
|
47
46
|
*/
|
|
48
|
-
type FourModifierHotkey = `Control+Alt+Shift+Meta+${Key}`;
|
|
47
|
+
export type FourModifierHotkey = `Control+Alt+Shift+Meta+${Key}`;
|
|
49
48
|
/**
|
|
50
49
|
* A type-safe hotkey string.
|
|
51
50
|
*
|
|
@@ -98,9 +97,9 @@ type FourModifierHotkey = `Control+Alt+Shift+Meta+${Key}`;
|
|
|
98
97
|
* const windowsOnly: Hotkey = 'Control+S' // Ctrl+S on Windows/Linux only
|
|
99
98
|
* ```
|
|
100
99
|
*/
|
|
101
|
-
type Hotkey = Key | SingleModifierHotkey | TwoModifierHotkey | ThreeModifierHotkey | FourModifierHotkey;
|
|
100
|
+
export type Hotkey = Key | SingleModifierHotkey | TwoModifierHotkey | ThreeModifierHotkey | FourModifierHotkey;
|
|
102
101
|
/** Resolved modifier flags shared by both parsed binding variants. */
|
|
103
|
-
interface ParsedModifiers {
|
|
102
|
+
export interface ParsedModifiers {
|
|
104
103
|
/** Whether Control is required. */
|
|
105
104
|
ctrl: boolean;
|
|
106
105
|
/** Whether Shift is required. */
|
|
@@ -121,7 +120,7 @@ interface ParsedModifiers {
|
|
|
121
120
|
* parseHotkey('Alt+S') // { key: 'S', alt: true, ... }
|
|
122
121
|
* parseHotkey('Alt+[KeyS]') // { code: 'KeyS', alt: true, ... } — no key property
|
|
123
122
|
*/
|
|
124
|
-
type ParsedHotkey = ParsedModifiers & ({
|
|
123
|
+
export type ParsedHotkey = ParsedModifiers & ({
|
|
125
124
|
key: LogicalKey | (string & {});
|
|
126
125
|
code?: never;
|
|
127
126
|
} | {
|
|
@@ -151,7 +150,7 @@ type ParsedHotkey = ParsedModifiers & ({
|
|
|
151
150
|
* ```
|
|
152
151
|
*/
|
|
153
152
|
/** Modifier flags shared by logical-key and physical-code registrations. */
|
|
154
|
-
interface RawModifiers {
|
|
153
|
+
export interface RawModifiers {
|
|
155
154
|
/** The non-modifier key (e.g., 'S', 'Escape', 'F1'). */
|
|
156
155
|
/** Platform-adaptive modifier: Command on macOS, Control on Windows/Linux. Defaults to false. */
|
|
157
156
|
mod?: boolean;
|
|
@@ -164,7 +163,7 @@ interface RawModifiers {
|
|
|
164
163
|
/** Whether the Meta (Command) key is required. Defaults to false. */
|
|
165
164
|
meta?: boolean;
|
|
166
165
|
}
|
|
167
|
-
type RawHotkey = ({
|
|
166
|
+
export type RawHotkey = ({
|
|
168
167
|
key: LogicalKey | (string & {});
|
|
169
168
|
code?: never;
|
|
170
169
|
} & RawModifiers) | ({
|
|
@@ -175,11 +174,11 @@ type RawHotkey = ({
|
|
|
175
174
|
* A hotkey that can be passed to `HotkeyManager.register()` and `useHotkey()`.
|
|
176
175
|
* Either a type-safe string (`Hotkey`) or a raw object (`RawHotkey`).
|
|
177
176
|
*/
|
|
178
|
-
type RegisterableHotkey = Hotkey | RawHotkey;
|
|
177
|
+
export type RegisterableHotkey = Hotkey | RawHotkey;
|
|
179
178
|
/**
|
|
180
179
|
* Context passed to hotkey callbacks along with the keyboard event.
|
|
181
180
|
*/
|
|
182
|
-
interface HotkeyCallbackContext {
|
|
181
|
+
export interface HotkeyCallbackContext {
|
|
183
182
|
/** The original hotkey string that was registered */
|
|
184
183
|
hotkey: Hotkey;
|
|
185
184
|
/** The parsed representation of the hotkey */
|
|
@@ -199,7 +198,7 @@ interface HotkeyCallbackContext {
|
|
|
199
198
|
* }
|
|
200
199
|
* ```
|
|
201
200
|
*/
|
|
202
|
-
type HotkeyCallback = (event: KeyboardEvent, context: HotkeyCallbackContext) => void;
|
|
201
|
+
export type HotkeyCallback = (event: KeyboardEvent, context: HotkeyCallbackContext) => void;
|
|
203
202
|
/**
|
|
204
203
|
* Metadata for hotkey and sequence registrations.
|
|
205
204
|
* Includes `name`, `description`, and `group` by default. Extend via declaration merging:
|
|
@@ -214,7 +213,7 @@ type HotkeyCallback = (event: KeyboardEvent, context: HotkeyCallbackContext) =>
|
|
|
214
213
|
* }
|
|
215
214
|
* ```
|
|
216
215
|
*/
|
|
217
|
-
interface HotkeyMeta {
|
|
216
|
+
export interface HotkeyMeta {
|
|
218
217
|
/** Human-readable name for this hotkey (e.g., "Save Document") */
|
|
219
218
|
name?: string;
|
|
220
219
|
/** Description of what this hotkey does */
|
|
@@ -230,7 +229,5 @@ interface HotkeyMeta {
|
|
|
230
229
|
* - `'replace'` - Unregister the existing registration and register the new one
|
|
231
230
|
* - `'allow'` - Allow multiple registrations without warning
|
|
232
231
|
*/
|
|
233
|
-
type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
|
|
234
|
-
//#endregion
|
|
235
|
-
export { ConflictBehavior, FourModifierHotkey, Hotkey, HotkeyCallback, HotkeyCallbackContext, HotkeyMeta, ParsedHotkey, ParsedModifiers, RawHotkey, RawModifiers, RegisterableHotkey, SingleModifierHotkey, ThreeModifierHotkey, TwoModifierHotkey };
|
|
236
|
-
//# sourceMappingURL=hotkey.types.d.ts.map
|
|
232
|
+
export type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
|
|
233
|
+
//#endregion
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Store } from "@tanstack/store";
|
|
2
|
-
|
|
3
2
|
//#region src/key-state-tracker.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* State interface for the KeyStateTracker.
|
|
6
5
|
*/
|
|
7
|
-
interface KeyStateTrackerState {
|
|
6
|
+
export interface KeyStateTrackerState {
|
|
8
7
|
/**
|
|
9
8
|
* Array of currently held key names (normalized, e.g. "Control", "A").
|
|
10
9
|
*/
|
|
@@ -49,7 +48,7 @@ interface KeyStateTrackerState {
|
|
|
49
48
|
* unsubscribe()
|
|
50
49
|
* ```
|
|
51
50
|
*/
|
|
52
|
-
declare class KeyStateTracker {
|
|
51
|
+
export declare class KeyStateTracker {
|
|
53
52
|
#private;
|
|
54
53
|
/**
|
|
55
54
|
* The TanStack Store instance containing the tracker state.
|
|
@@ -101,7 +100,5 @@ declare class KeyStateTracker {
|
|
|
101
100
|
* Gets the singleton KeyStateTracker instance.
|
|
102
101
|
* Convenience function for accessing the tracker.
|
|
103
102
|
*/
|
|
104
|
-
declare function getKeyStateTracker(): KeyStateTracker;
|
|
105
|
-
//#endregion
|
|
106
|
-
export { KeyStateTracker, KeyStateTrackerState, getKeyStateTracker };
|
|
107
|
-
//# sourceMappingURL=key-state-tracker.d.ts.map
|
|
103
|
+
export declare function getKeyStateTracker(): KeyStateTracker;
|
|
104
|
+
//#endregion
|
|
@@ -47,12 +47,16 @@ function getDefaultKeyStateTrackerState() {
|
|
|
47
47
|
*/
|
|
48
48
|
var KeyStateTracker = class KeyStateTracker {
|
|
49
49
|
static #instance = null;
|
|
50
|
+
/**
|
|
51
|
+
* The TanStack Store instance containing the tracker state.
|
|
52
|
+
* Use this to subscribe to state changes or access current state.
|
|
53
|
+
*/
|
|
54
|
+
store = new Store(getDefaultKeyStateTrackerState());
|
|
50
55
|
#heldEntries = /* @__PURE__ */ new Map();
|
|
51
56
|
#keydownListener = null;
|
|
52
57
|
#keyupListener = null;
|
|
53
58
|
#blurListener = null;
|
|
54
59
|
constructor() {
|
|
55
|
-
this.store = new Store(getDefaultKeyStateTrackerState());
|
|
56
60
|
this.#setupListeners();
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
@@ -192,5 +196,4 @@ function getKeyStateTracker() {
|
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
//#endregion
|
|
195
|
-
export { KeyStateTracker, getKeyStateTracker };
|
|
196
|
-
//# sourceMappingURL=key-state-tracker.js.map
|
|
199
|
+
export { KeyStateTracker, getKeyStateTracker };
|
package/dist/key.types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from "./_named-keys.js";
|
|
2
|
-
|
|
3
2
|
//#region src/key.types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* All supported modifier key names, including aliases.
|
|
@@ -9,40 +8,40 @@ import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from "./_named-keys.js";
|
|
|
9
8
|
* - Command/Cmd: The Command key (macOS only)
|
|
10
9
|
* - CommandOrControl/Mod: Command on macOS, Control on other platforms
|
|
11
10
|
*/
|
|
12
|
-
type Modifier = 'Control' | 'Ctrl' | 'Shift' | 'Alt' | 'Option' | 'Command' | 'Cmd' | 'CommandOrControl' | 'Mod';
|
|
11
|
+
export type Modifier = 'Control' | 'Ctrl' | 'Shift' | 'Alt' | 'Option' | 'Command' | 'Cmd' | 'CommandOrControl' | 'Mod';
|
|
13
12
|
/**
|
|
14
13
|
* Canonical modifier names that map to KeyboardEvent properties.
|
|
15
14
|
*/
|
|
16
|
-
type CanonicalModifier = 'Control' | 'Shift' | 'Alt' | 'Meta';
|
|
15
|
+
export type CanonicalModifier = 'Control' | 'Shift' | 'Alt' | 'Meta';
|
|
17
16
|
/**
|
|
18
17
|
* Letter keys A-Z (case-insensitive in matching).
|
|
19
18
|
*/
|
|
20
|
-
type LetterKey = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
19
|
+
export type LetterKey = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
21
20
|
/**
|
|
22
21
|
* Number keys 0-9.
|
|
23
22
|
*/
|
|
24
|
-
type NumberKey = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
23
|
+
export type NumberKey = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
25
24
|
/**
|
|
26
25
|
* Function keys F1-F24, supported as both logical keys and physical codes.
|
|
27
26
|
*/
|
|
28
|
-
type FunctionKey = 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12' | 'F13' | 'F14' | 'F15' | 'F16' | 'F17' | 'F18' | 'F19' | 'F20' | 'F21' | 'F22' | 'F23' | 'F24';
|
|
27
|
+
export type FunctionKey = 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12' | 'F13' | 'F14' | 'F15' | 'F16' | 'F17' | 'F18' | 'F19' | 'F20' | 'F21' | 'F22' | 'F23' | 'F24';
|
|
29
28
|
/**
|
|
30
29
|
* Navigation keys for cursor movement.
|
|
31
30
|
*/
|
|
32
|
-
type NavigationKey = 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
31
|
+
export type NavigationKey = 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
33
32
|
/**
|
|
34
33
|
* Editing and special keys.
|
|
35
34
|
*/
|
|
36
|
-
type EditingKey = 'Enter' | 'Escape' | 'Space' | 'Tab' | 'Backspace' | 'Delete';
|
|
35
|
+
export type EditingKey = 'Enter' | 'Escape' | 'Space' | 'Tab' | 'Backspace' | 'Delete';
|
|
37
36
|
/**
|
|
38
37
|
* Printable punctuation glyphs used in keyboard shortcuts. Matching uses the
|
|
39
38
|
* final KeyboardEvent.key glyph, independent of which layout produced it.
|
|
40
39
|
*/
|
|
41
|
-
type PunctuationKey = '/' | '[' | ']' | '\\' | '=' | '-' | ',' | '.' | ';' | '`' | "'" | '+' | '?' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '_' | '{' | '}' | '|' | ':' | '"' | '<' | '>' | '~';
|
|
40
|
+
export type PunctuationKey = '/' | '[' | ']' | '\\' | '=' | '-' | ',' | '.' | ';' | '`' | "'" | '+' | '?' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '_' | '{' | '}' | '|' | ':' | '"' | '<' | '>' | '~';
|
|
42
41
|
/** Additional named logical keys, including media, browser, lock, and input-mode keys. */
|
|
43
|
-
type NamedKey = (typeof SHARED_NAMED_KEYS)[number] | (typeof LOGICAL_ONLY_NAMED_KEYS)[number];
|
|
42
|
+
export type NamedKey = (typeof SHARED_NAMED_KEYS)[number] | (typeof LOGICAL_ONLY_NAMED_KEYS)[number];
|
|
44
43
|
/** Supported logical key names other than printable punctuation. */
|
|
45
|
-
type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | FunctionKey | NamedKey;
|
|
44
|
+
export type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | FunctionKey | NamedKey;
|
|
46
45
|
/**
|
|
47
46
|
* Supported physical KeyboardEvent.code names, independent of keyboard layout.
|
|
48
47
|
* Letter, digit, numpad, and sided modifier names use finite template unions.
|
|
@@ -50,23 +49,23 @@ type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | Fu
|
|
|
50
49
|
*
|
|
51
50
|
* @see https://www.w3.org/TR/uievents-code/
|
|
52
51
|
*/
|
|
53
|
-
type PhysicalKeyCode = `Key${LetterKey}` | `Digit${NumberKey}` | `Numpad${NumberKey}` | `${'Alt' | 'Control' | 'Meta' | 'Shift'}${'Left' | 'Right'}` | EditingKey | NavigationKey | FunctionKey | (typeof SHARED_NAMED_KEYS)[number] | 'Backquote' | 'Backslash' | 'BracketLeft' | 'BracketRight' | 'Comma' | 'Equal' | 'IntlBackslash' | 'IntlRo' | 'IntlYen' | 'Minus' | 'Period' | 'Quote' | 'Semicolon' | 'Slash' | `Lang${1 | 2 | 3 | 4 | 5}` | `Numpad${'Add' | 'Backspace' | 'Clear' | 'ClearEntry' | 'Comma' | 'Decimal' | 'Divide' | 'Enter' | 'Equal' | 'Hash' | 'MemoryAdd' | 'MemoryClear' | 'MemoryRecall' | 'MemoryStore' | 'MemorySubtract' | 'Multiply' | 'ParenLeft' | 'ParenRight' | 'Star' | 'Subtract'}` | 'LaunchApp1' | 'LaunchApp2' | 'MediaSelect' | 'Sleep' | 'Turbo' | 'Abort' | 'Resume' | 'Suspend';
|
|
52
|
+
export type PhysicalKeyCode = `Key${LetterKey}` | `Digit${NumberKey}` | `Numpad${NumberKey}` | `${'Alt' | 'Control' | 'Meta' | 'Shift'}${'Left' | 'Right'}` | EditingKey | NavigationKey | FunctionKey | (typeof SHARED_NAMED_KEYS)[number] | 'Backquote' | 'Backslash' | 'BracketLeft' | 'BracketRight' | 'Comma' | 'Equal' | 'IntlBackslash' | 'IntlRo' | 'IntlYen' | 'Minus' | 'Period' | 'Quote' | 'Semicolon' | 'Slash' | `Lang${1 | 2 | 3 | 4 | 5}` | `Numpad${'Add' | 'Backspace' | 'Clear' | 'ClearEntry' | 'Comma' | 'Decimal' | 'Divide' | 'Enter' | 'Equal' | 'Hash' | 'MemoryAdd' | 'MemoryClear' | 'MemoryRecall' | 'MemoryStore' | 'MemorySubtract' | 'Multiply' | 'ParenLeft' | 'ParenRight' | 'Star' | 'Subtract'}` | 'LaunchApp1' | 'LaunchApp2' | 'MediaSelect' | 'Sleep' | 'Turbo' | 'Abort' | 'Resume' | 'Suspend';
|
|
54
53
|
/**
|
|
55
54
|
* An explicit physical key token. All codes use brackets, including names such
|
|
56
55
|
* as `[Enter]` that also exist as logical keys. Invalid code names are rejected
|
|
57
56
|
* by TypeScript, and supported names are available in autocomplete.
|
|
58
57
|
*/
|
|
59
|
-
type PhysicalKey = `[${PhysicalKeyCode}]`;
|
|
58
|
+
export type PhysicalKey = `[${PhysicalKeyCode}]`;
|
|
60
59
|
/** Supported logical key names, excluding bracketed physical-code syntax. */
|
|
61
|
-
type LogicalKey = NonPunctuationKey | PunctuationKey;
|
|
60
|
+
export type LogicalKey = NonPunctuationKey | PunctuationKey;
|
|
62
61
|
/** All supported logical keys and bracketed physical key tokens. */
|
|
63
|
-
type Key = LogicalKey | PhysicalKey;
|
|
62
|
+
export type Key = LogicalKey | PhysicalKey;
|
|
64
63
|
/**
|
|
65
64
|
* Includes both modifier keys and regular keys.
|
|
66
65
|
*/
|
|
67
|
-
type IndividualKey = CanonicalModifier | Key;
|
|
66
|
+
export type IndividualKey = CanonicalModifier | Key;
|
|
68
67
|
/** Keyboard event properties normalized for internal matching and recording. */
|
|
69
|
-
interface NormalizedKeyboardEvent {
|
|
68
|
+
export interface NormalizedKeyboardEvent {
|
|
70
69
|
key: string;
|
|
71
70
|
code: string;
|
|
72
71
|
ctrl: boolean;
|
|
@@ -77,6 +76,4 @@ interface NormalizedKeyboardEvent {
|
|
|
77
76
|
location: number;
|
|
78
77
|
isComposing: boolean;
|
|
79
78
|
}
|
|
80
|
-
//#endregion
|
|
81
|
-
export { CanonicalModifier, EditingKey, FunctionKey, IndividualKey, Key, LetterKey, LogicalKey, Modifier, NamedKey, NavigationKey, NonPunctuationKey, NormalizedKeyboardEvent, NumberKey, PhysicalKey, PhysicalKeyCode, PunctuationKey };
|
|
82
|
-
//# sourceMappingURL=key.types.d.ts.map
|
|
79
|
+
//#endregion
|
package/dist/match.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hotkey, HotkeyCallback, ParsedHotkey, RegisterableHotkey } from "./hotkey.types.js";
|
|
2
|
-
|
|
3
2
|
//#region src/match.d.ts
|
|
4
|
-
interface KeyboardEventMatch {
|
|
3
|
+
export interface KeyboardEventMatch {
|
|
5
4
|
matched: boolean;
|
|
6
5
|
score: 0 | 1 | 2 | 3;
|
|
7
6
|
source?: 'key' | 'code' | 'fallback';
|
|
@@ -39,11 +38,11 @@ interface KeyboardEventMatch {
|
|
|
39
38
|
* })
|
|
40
39
|
* ```
|
|
41
40
|
*/
|
|
42
|
-
declare function matchesKeyboardEvent(event: KeyboardEvent, hotkey: Hotkey | ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): boolean;
|
|
41
|
+
export declare function matchesKeyboardEvent(event: KeyboardEvent, hotkey: Hotkey | ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): boolean;
|
|
43
42
|
/**
|
|
44
43
|
* Options for creating a hotkey handler.
|
|
45
44
|
*/
|
|
46
|
-
interface CreateHotkeyHandlerOptions {
|
|
45
|
+
export interface CreateHotkeyHandlerOptions {
|
|
47
46
|
/** Prevent the default browser action when the hotkey matches. Defaults to true */
|
|
48
47
|
preventDefault?: boolean;
|
|
49
48
|
/** Stop event propagation when the hotkey matches. Defaults to true */
|
|
@@ -69,8 +68,8 @@ interface CreateHotkeyHandlerOptions {
|
|
|
69
68
|
* document.addEventListener('keydown', handler)
|
|
70
69
|
* ```
|
|
71
70
|
*/
|
|
72
|
-
declare function createHotkeyHandler(hotkey: Hotkey | ParsedHotkey, callback: HotkeyCallback, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
73
|
-
type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback };
|
|
71
|
+
export declare function createHotkeyHandler(hotkey: Hotkey | ParsedHotkey, callback: HotkeyCallback, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
72
|
+
export type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback; };
|
|
74
73
|
/**
|
|
75
74
|
* Creates a handler that matches multiple hotkeys.
|
|
76
75
|
*
|
|
@@ -89,13 +88,11 @@ type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback };
|
|
|
89
88
|
* document.addEventListener('keydown', handler)
|
|
90
89
|
* ```
|
|
91
90
|
*/
|
|
92
|
-
declare function createMultiHotkeyHandler(handlers: MultiHotkeyHandler, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
91
|
+
export declare function createMultiHotkeyHandler(handlers: MultiHotkeyHandler, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
93
92
|
/**
|
|
94
93
|
* Compares normalized binding identity, including all four modifiers.
|
|
95
94
|
* Aliases resolve on the supplied platform. A physical code and a logical key
|
|
96
95
|
* remain distinct even when one keyboard event could match both.
|
|
97
96
|
*/
|
|
98
|
-
declare function areHotkeysEqual(left: RegisterableHotkey, right: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): boolean;
|
|
99
|
-
//#endregion
|
|
100
|
-
export { CreateHotkeyHandlerOptions, KeyboardEventMatch, MultiHotkeyHandler, areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
101
|
-
//# sourceMappingURL=match.d.ts.map
|
|
97
|
+
export declare function areHotkeysEqual(left: RegisterableHotkey, right: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): boolean;
|
|
98
|
+
//#endregion
|
package/dist/match.js
CHANGED
|
@@ -137,5 +137,4 @@ function areHotkeysEqual(left, right, platform = detectPlatform()) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
//#endregion
|
|
140
|
-
export { areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
141
|
-
//# sourceMappingURL=match.js.map
|
|
140
|
+
export { areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Key } from "./key.types.js";
|
|
2
2
|
import { MODIFIER_ALIASES } from "./constants.js";
|
|
3
3
|
import { Hotkey, ParsedHotkey, RawHotkey, RegisterableHotkey } from "./hotkey.types.js";
|
|
4
|
-
|
|
5
4
|
//#region src/parse.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Parses a hotkey string into its component parts.
|
|
@@ -17,7 +16,7 @@ import { Hotkey, ParsedHotkey, RawHotkey, RegisterableHotkey } from "./hotkey.ty
|
|
|
17
16
|
* parseHotkey('Control+Shift+A') // { key: 'A', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] }
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
20
|
-
declare function parseHotkey(hotkey: Hotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
19
|
+
export declare function parseHotkey(hotkey: Hotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
21
20
|
/**
|
|
22
21
|
* Converts a RawHotkey object to a ParsedHotkey.
|
|
23
22
|
* Optional modifier booleans default to false; modifiers array is derived from them.
|
|
@@ -39,7 +38,7 @@ declare function parseHotkey(hotkey: Hotkey | (string & {}), platform?: 'mac' |
|
|
|
39
38
|
* // { key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] }
|
|
40
39
|
* ```
|
|
41
40
|
*/
|
|
42
|
-
declare function rawHotkeyToParsedHotkey(raw: RawHotkey, platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
41
|
+
export declare function rawHotkeyToParsedHotkey(raw: RawHotkey, platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
43
42
|
/**
|
|
44
43
|
* Normalizes a hotkey string to its canonical form.
|
|
45
44
|
*
|
|
@@ -60,16 +59,16 @@ declare function rawHotkeyToParsedHotkey(raw: RawHotkey, platform?: 'mac' | 'win
|
|
|
60
59
|
* normalizeHotkey('esc') // 'Escape'
|
|
61
60
|
* ```
|
|
62
61
|
*/
|
|
63
|
-
declare function normalizeHotkey(hotkey: Key | (string & {}), platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
62
|
+
export declare function normalizeHotkey(hotkey: Key | (string & {}), platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
64
63
|
/**
|
|
65
64
|
* Same canonical string as {@link normalizeHotkey}, but from an already-parsed hotkey.
|
|
66
65
|
*/
|
|
67
|
-
declare function normalizeHotkeyFromParsed(parsed: ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
66
|
+
export declare function normalizeHotkeyFromParsed(parsed: ParsedHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
68
67
|
/**
|
|
69
68
|
* Normalizes a string or {@link RawHotkey} object to the same canonical hotkey string.
|
|
70
69
|
* Use this in framework adapters instead of branching on `formatHotkey(rawHotkeyToParsedHotkey(...))`.
|
|
71
70
|
*/
|
|
72
|
-
declare function normalizeRegisterableHotkey(hotkey: RegisterableHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
71
|
+
export declare function normalizeRegisterableHotkey(hotkey: RegisterableHotkey, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
73
72
|
/**
|
|
74
73
|
* Checks if a string is a recognized modifier token (including aliases).
|
|
75
74
|
*
|
|
@@ -79,7 +78,7 @@ declare function normalizeRegisterableHotkey(hotkey: RegisterableHotkey, platfor
|
|
|
79
78
|
* @param key - Key name or alias (e.g. from a hotkey string or `event.key`)
|
|
80
79
|
* @returns True if the string is a recognized modifier
|
|
81
80
|
*/
|
|
82
|
-
declare function isModifierKey(key: Key | (string & {})): key is keyof typeof MODIFIER_ALIASES;
|
|
81
|
+
export declare function isModifierKey(key: Key | (string & {})): key is keyof typeof MODIFIER_ALIASES;
|
|
83
82
|
/**
|
|
84
83
|
* Parses a KeyboardEvent into a ParsedHotkey object.
|
|
85
84
|
*
|
|
@@ -98,14 +97,14 @@ declare function isModifierKey(key: Key | (string & {})): key is keyof typeof MO
|
|
|
98
97
|
* })
|
|
99
98
|
* ```
|
|
100
99
|
*/
|
|
101
|
-
declare function parseKeyboardEvent(event: KeyboardEvent, platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
100
|
+
export declare function parseKeyboardEvent(event: KeyboardEvent, platform?: 'mac' | 'windows' | 'linux'): ParsedHotkey;
|
|
102
101
|
/**
|
|
103
102
|
* Normalizes a keyboard event to the same canonical hotkey string as {@link normalizeHotkey}.
|
|
104
103
|
*
|
|
105
104
|
* @param event - The keyboard event (typically `keydown`)
|
|
106
105
|
* @param platform - Target platform for `Mod` eligibility
|
|
107
106
|
*/
|
|
108
|
-
declare function normalizeHotkeyFromEvent(event: KeyboardEvent, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
107
|
+
export declare function normalizeHotkeyFromEvent(event: KeyboardEvent, platform?: 'mac' | 'windows' | 'linux'): Hotkey;
|
|
109
108
|
/**
|
|
110
109
|
* Checks if a hotkey or ParsedHotkey contains at least one non-modifier key.
|
|
111
110
|
*
|
|
@@ -123,12 +122,10 @@ declare function normalizeHotkeyFromEvent(event: KeyboardEvent, platform?: 'mac'
|
|
|
123
122
|
* hasNonModifierKey(parseHotkey('Mod+A')) // true
|
|
124
123
|
* ```
|
|
125
124
|
*/
|
|
126
|
-
declare function hasNonModifierKey(hotkey: Hotkey | ParsedHotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): boolean;
|
|
125
|
+
export declare function hasNonModifierKey(hotkey: Hotkey | ParsedHotkey | (string & {}), platform?: 'mac' | 'windows' | 'linux'): boolean;
|
|
127
126
|
/**
|
|
128
127
|
* Parses a string or raw binding, resolving Mod for the supplied platform.
|
|
129
128
|
* Physical tokens such as `[KeyQ]` retain `code`; they never become logical Q.
|
|
130
129
|
*/
|
|
131
|
-
declare function parseRegisterableHotkey(hotkey: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): ParsedHotkey;
|
|
132
|
-
//#endregion
|
|
133
|
-
export { hasNonModifierKey, isModifierKey, normalizeHotkey, normalizeHotkeyFromEvent, normalizeHotkeyFromParsed, normalizeRegisterableHotkey, parseHotkey, parseKeyboardEvent, parseRegisterableHotkey, rawHotkeyToParsedHotkey };
|
|
134
|
-
//# sourceMappingURL=parse.d.ts.map
|
|
130
|
+
export declare function parseRegisterableHotkey(hotkey: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): ParsedHotkey;
|
|
131
|
+
//#endregion
|
package/dist/parse.js
CHANGED
|
@@ -70,8 +70,10 @@ function rawHotkeyToParsedHotkey(raw, platform = detectPlatform()) {
|
|
|
70
70
|
const shift = raw.shift ?? false;
|
|
71
71
|
const alt = raw.alt ?? false;
|
|
72
72
|
let meta = raw.meta ?? false;
|
|
73
|
-
if (raw.mod)
|
|
74
|
-
|
|
73
|
+
if (raw.mod) {
|
|
74
|
+
if (resolveModifier("Mod", platform) === "Control") ctrl = true;
|
|
75
|
+
else meta = true;
|
|
76
|
+
}
|
|
75
77
|
const modifiers = MODIFIER_ORDER.filter((m) => {
|
|
76
78
|
switch (m) {
|
|
77
79
|
case "Control": return ctrl;
|
|
@@ -232,5 +234,4 @@ function parseRegisterableHotkey(hotkey, platform = detectPlatform()) {
|
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
//#endregion
|
|
235
|
-
export { hasNonModifierKey, isModifierKey, normalizeHotkey, normalizeHotkeyFromEvent, normalizeHotkeyFromParsed, normalizeRegisterableHotkey, parseHotkey, parseKeyboardEvent, parseRegisterableHotkey, rawHotkeyToParsedHotkey };
|
|
236
|
-
//# sourceMappingURL=parse.js.map
|
|
237
|
+
export { hasNonModifierKey, isModifierKey, normalizeHotkey, normalizeHotkeyFromEvent, normalizeHotkeyFromParsed, normalizeRegisterableHotkey, parseHotkey, parseKeyboardEvent, parseRegisterableHotkey, rawHotkeyToParsedHotkey };
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CanonicalModifier } from "./key.types.js";
|
|
2
|
-
|
|
3
2
|
//#region src/platform.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Detects the current platform based on browser navigator properties.
|
|
@@ -16,7 +15,7 @@ import { CanonicalModifier } from "./key.types.js";
|
|
|
16
15
|
* const modifier = resolveModifier('Mod', platform) // 'Meta' on Mac, 'Control' elsewhere
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
|
-
declare function detectPlatform(): 'mac' | 'windows' | 'linux';
|
|
18
|
+
export declare function detectPlatform(): 'mac' | 'windows' | 'linux';
|
|
20
19
|
/**
|
|
21
20
|
* Resolves the platform-adaptive 'Mod' modifier to the appropriate canonical modifier.
|
|
22
21
|
*
|
|
@@ -38,7 +37,5 @@ declare function detectPlatform(): 'mac' | 'windows' | 'linux';
|
|
|
38
37
|
* resolveModifier('Control', 'mac') // 'Control' (unchanged)
|
|
39
38
|
* ```
|
|
40
39
|
*/
|
|
41
|
-
declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
|
42
|
-
//#endregion
|
|
43
|
-
export { detectPlatform, resolveModifier };
|
|
44
|
-
//# sourceMappingURL=platform.d.ts.map
|
|
40
|
+
export declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
|
41
|
+
//#endregion
|
package/dist/platform.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { Hotkey, ParsedHotkey } from "./hotkey.types.js";
|
|
2
2
|
import { HotkeyConflict, HotkeyConflictOptions } from "./conflicts.js";
|
|
3
|
-
|
|
4
3
|
//#region src/recorder-options.d.ts
|
|
5
4
|
/** Event property used to record a binding. Physical codes are the default. */
|
|
6
|
-
type RecorderKeyMode = 'code' | 'key';
|
|
7
|
-
interface RecorderRejection {
|
|
5
|
+
export type RecorderKeyMode = 'code' | 'key';
|
|
6
|
+
export interface RecorderRejection {
|
|
8
7
|
reason: 'missing-code' | 'alt-graph' | 'invalid' | 'conflict' | 'validation';
|
|
9
8
|
message: string;
|
|
10
9
|
hotkey?: Hotkey;
|
|
11
10
|
sequence?: Array<Hotkey>;
|
|
12
11
|
conflicts?: Array<HotkeyConflict>;
|
|
13
12
|
}
|
|
14
|
-
interface RecorderOptions {
|
|
13
|
+
export interface RecorderOptions {
|
|
15
14
|
/** Physical code recording is the default. Choose key to record logical characters. */
|
|
16
15
|
recordBy?: RecorderKeyMode;
|
|
17
16
|
/** Platform used for Mod and AltGraph handling. Defaults to platform detection. */
|
|
@@ -21,14 +20,12 @@ interface RecorderOptions {
|
|
|
21
20
|
/** Rejected candidates leave recording active. */
|
|
22
21
|
onReject?: (rejection: RecorderRejection) => void;
|
|
23
22
|
}
|
|
24
|
-
interface HotkeyRecorderValidationContext {
|
|
23
|
+
export interface HotkeyRecorderValidationContext {
|
|
25
24
|
event: KeyboardEvent;
|
|
26
25
|
parsedHotkey: ParsedHotkey;
|
|
27
26
|
}
|
|
28
|
-
interface HotkeySequenceRecorderValidationContext {
|
|
27
|
+
export interface HotkeySequenceRecorderValidationContext {
|
|
29
28
|
events: ReadonlyArray<KeyboardEvent>;
|
|
30
29
|
parsedSequence: ReadonlyArray<ParsedHotkey>;
|
|
31
30
|
}
|
|
32
|
-
//#endregion
|
|
33
|
-
export { HotkeyRecorderValidationContext, HotkeySequenceRecorderValidationContext, RecorderKeyMode, RecorderOptions, RecorderRejection };
|
|
34
|
-
//# sourceMappingURL=recorder-options.d.ts.map
|
|
31
|
+
//#endregion
|