@tanstack/hotkeys 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/{manager.utils.js → _event-target.cjs} +5 -41
- package/dist/_event-target.cjs.map +1 -0
- package/dist/{manager.utils.cjs → _event-target.js} +3 -47
- package/dist/_event-target.js.map +1 -0
- package/dist/_keyboard-event.cjs +83 -0
- package/dist/_keyboard-event.cjs.map +1 -0
- package/dist/_keyboard-event.js +76 -0
- package/dist/_keyboard-event.js.map +1 -0
- package/dist/_match.cjs +49 -0
- package/dist/_match.cjs.map +1 -0
- package/dist/_match.js +49 -0
- package/dist/_match.js.map +1 -0
- package/dist/_named-keys.cjs +68 -0
- package/dist/_named-keys.cjs.map +1 -0
- package/dist/_named-keys.d.cts +8 -0
- package/dist/_named-keys.d.ts +8 -0
- package/dist/_named-keys.js +66 -0
- package/dist/_named-keys.js.map +1 -0
- package/dist/_recorder-chord.cjs +44 -0
- package/dist/_recorder-chord.cjs.map +1 -0
- package/dist/_recorder-chord.js +43 -0
- package/dist/_recorder-chord.js.map +1 -0
- package/dist/_recording-guard.cjs +59 -0
- package/dist/_recording-guard.cjs.map +1 -0
- package/dist/_recording-guard.js +56 -0
- package/dist/_recording-guard.js.map +1 -0
- package/dist/_registration.cjs +54 -0
- package/dist/_registration.cjs.map +1 -0
- package/dist/_registration.js +50 -0
- package/dist/_registration.js.map +1 -0
- package/dist/conflicts.cjs +55 -0
- package/dist/conflicts.cjs.map +1 -0
- package/dist/conflicts.d.cts +39 -0
- package/dist/conflicts.d.ts +39 -0
- package/dist/conflicts.js +55 -0
- package/dist/conflicts.js.map +1 -0
- package/dist/constants.cjs +46 -171
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +4 -129
- package/dist/constants.d.ts +4 -129
- package/dist/constants.js +48 -164
- package/dist/constants.js.map +1 -1
- package/dist/display-labels.cjs +119 -0
- package/dist/display-labels.cjs.map +1 -0
- package/dist/display-labels.d.cts +93 -0
- package/dist/display-labels.d.ts +93 -0
- package/dist/display-labels.js +113 -0
- package/dist/display-labels.js.map +1 -0
- package/dist/format.cjs +30 -36
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +46 -7
- package/dist/format.d.ts +46 -7
- package/dist/format.js +31 -37
- package/dist/format.js.map +1 -1
- package/dist/hint.cjs +24 -0
- package/dist/hint.cjs.map +1 -0
- package/dist/hint.d.cts +23 -0
- package/dist/hint.d.ts +23 -0
- package/dist/hint.js +24 -0
- package/dist/hint.js.map +1 -0
- package/dist/hotkey-manager.cjs +53 -22
- package/dist/hotkey-manager.cjs.map +1 -1
- package/dist/hotkey-manager.d.cts +6 -2
- package/dist/hotkey-manager.d.ts +6 -2
- package/dist/hotkey-manager.js +49 -18
- package/dist/hotkey-manager.js.map +1 -1
- package/dist/hotkey-recorder.cjs +67 -11
- package/dist/hotkey-recorder.cjs.map +1 -1
- package/dist/hotkey-recorder.d.cts +6 -3
- package/dist/hotkey-recorder.d.ts +6 -3
- package/dist/hotkey-recorder.js +66 -10
- package/dist/hotkey-recorder.js.map +1 -1
- package/dist/hotkey-sequence-recorder.cjs +85 -22
- package/dist/hotkey-sequence-recorder.cjs.map +1 -1
- package/dist/hotkey-sequence-recorder.d.cts +9 -2
- package/dist/hotkey-sequence-recorder.d.ts +9 -2
- package/dist/hotkey-sequence-recorder.js +84 -21
- package/dist/hotkey-sequence-recorder.js.map +1 -1
- package/dist/{hotkey.d.ts → hotkey.types.d.cts} +55 -120
- package/dist/{hotkey.d.cts → hotkey.types.d.ts} +55 -120
- package/dist/index.cjs +18 -10
- package/dist/index.d.cts +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.js +10 -6
- package/dist/key-state-tracker.cjs +24 -24
- package/dist/key-state-tracker.cjs.map +1 -1
- package/dist/key-state-tracker.js +24 -24
- package/dist/key-state-tracker.js.map +1 -1
- package/dist/key.types.d.cts +82 -0
- package/dist/key.types.d.ts +82 -0
- package/dist/match.cjs +21 -30
- package/dist/match.cjs.map +1 -1
- package/dist/match.d.cts +19 -3
- package/dist/match.d.ts +19 -3
- package/dist/match.js +19 -29
- package/dist/match.js.map +1 -1
- package/dist/parse.cjs +43 -26
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +10 -4
- package/dist/parse.d.ts +10 -4
- package/dist/parse.js +35 -19
- package/dist/parse.js.map +1 -1
- package/dist/platform.cjs +55 -0
- package/dist/platform.cjs.map +1 -0
- package/dist/platform.d.cts +44 -0
- package/dist/platform.d.ts +44 -0
- package/dist/platform.js +53 -0
- package/dist/platform.js.map +1 -0
- package/dist/recorder-options.d.cts +34 -0
- package/dist/recorder-options.d.ts +34 -0
- package/dist/sequence-manager.cjs +54 -28
- package/dist/sequence-manager.cjs.map +1 -1
- package/dist/sequence-manager.d.cts +18 -3
- package/dist/sequence-manager.d.ts +18 -3
- package/dist/sequence-manager.js +49 -23
- package/dist/sequence-manager.js.map +1 -1
- package/dist/validate.cjs +6 -10
- package/dist/validate.cjs.map +1 -1
- package/dist/validate.d.cts +13 -2
- package/dist/validate.d.ts +13 -2
- package/dist/validate.js +7 -11
- package/dist/validate.js.map +1 -1
- package/package.json +2 -2
- package/src/{manager.utils.ts → _event-target.ts} +0 -74
- package/src/_keyboard-event.ts +101 -0
- package/src/_match.ts +96 -0
- package/src/_named-keys.ts +62 -0
- package/src/_recorder-chord.ts +76 -0
- package/src/_recording-guard.ts +63 -0
- package/src/_registration.ts +79 -0
- package/src/conflicts.ts +125 -0
- package/src/constants.ts +48 -196
- package/src/display-labels.ts +123 -0
- package/src/format.ts +111 -52
- package/src/hint.ts +42 -0
- package/src/hotkey-manager.ts +95 -40
- package/src/hotkey-recorder.ts +92 -16
- package/src/hotkey-sequence-recorder.ts +110 -28
- package/src/{hotkey.ts → hotkey.types.ts} +57 -224
- package/src/index.ts +11 -5
- package/src/key-state-tracker.ts +36 -24
- package/src/key.types.ts +268 -0
- package/src/match.ts +41 -90
- package/src/parse.ts +67 -26
- package/src/platform.ts +66 -0
- package/src/recorder-options.ts +34 -0
- package/src/sequence-manager.ts +77 -42
- package/src/validate.ts +29 -21
- package/dist/manager.utils.cjs.map +0 -1
- package/dist/manager.utils.d.cts +0 -13
- package/dist/manager.utils.d.ts +0 -13
- package/dist/manager.utils.js.map +0 -1
- package/dist/recorder-chord.cjs +0 -18
- package/dist/recorder-chord.cjs.map +0 -1
- package/dist/recorder-chord.js +0 -18
- package/dist/recorder-chord.js.map +0 -1
- package/src/recorder-chord.ts +0 -25
|
@@ -47,8 +47,7 @@ function getDefaultKeyStateTrackerState() {
|
|
|
47
47
|
*/
|
|
48
48
|
var KeyStateTracker = class KeyStateTracker {
|
|
49
49
|
static #instance = null;
|
|
50
|
-
#
|
|
51
|
-
#heldCodesMap = /* @__PURE__ */ new Map();
|
|
50
|
+
#heldEntries = /* @__PURE__ */ new Map();
|
|
52
51
|
#keydownListener = null;
|
|
53
52
|
#keyupListener = null;
|
|
54
53
|
#blurListener = null;
|
|
@@ -79,44 +78,46 @@ var KeyStateTracker = class KeyStateTracker {
|
|
|
79
78
|
if (typeof document === "undefined") return;
|
|
80
79
|
this.#keydownListener = (event) => {
|
|
81
80
|
const key = normalizeKeyName(event.key);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.#
|
|
81
|
+
const identity = event.code || `key:${key}`;
|
|
82
|
+
if (!this.#heldEntries.has(identity)) {
|
|
83
|
+
this.#heldEntries.set(identity, {
|
|
84
|
+
key,
|
|
85
|
+
code: event.code
|
|
86
|
+
});
|
|
85
87
|
this.#syncState();
|
|
86
88
|
}
|
|
87
89
|
};
|
|
88
90
|
this.#keyupListener = (event) => {
|
|
89
91
|
const key = normalizeKeyName(event.key);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const identity = event.code || `key:${key}`;
|
|
93
|
+
this.#heldEntries.delete(identity);
|
|
94
|
+
if (!event.code) {
|
|
95
|
+
for (const [entryIdentity, entry] of this.#heldEntries) if (entry.key === key) this.#heldEntries.delete(entryIdentity);
|
|
93
96
|
}
|
|
94
97
|
if (MODIFIER_KEYS.has(key)) {
|
|
95
|
-
for (const
|
|
96
|
-
this.#heldKeysSet.delete(heldKey);
|
|
97
|
-
this.#heldCodesMap.delete(heldKey);
|
|
98
|
-
}
|
|
98
|
+
for (const [entryIdentity, entry] of this.#heldEntries) if (!MODIFIER_KEYS.has(entry.key)) this.#heldEntries.delete(entryIdentity);
|
|
99
99
|
}
|
|
100
100
|
this.#syncState();
|
|
101
101
|
};
|
|
102
102
|
this.#blurListener = () => {
|
|
103
|
-
if (this.#
|
|
104
|
-
this.#
|
|
105
|
-
this.#heldCodesMap.clear();
|
|
103
|
+
if (this.#heldEntries.size > 0) {
|
|
104
|
+
this.#heldEntries.clear();
|
|
106
105
|
this.#syncState();
|
|
107
106
|
}
|
|
108
107
|
};
|
|
109
|
-
document.addEventListener("keydown", this.#keydownListener);
|
|
110
|
-
document.addEventListener("keyup", this.#keyupListener);
|
|
108
|
+
document.addEventListener("keydown", this.#keydownListener, true);
|
|
109
|
+
document.addEventListener("keyup", this.#keyupListener, true);
|
|
111
110
|
window.addEventListener("blur", this.#blurListener);
|
|
112
111
|
}
|
|
113
112
|
/**
|
|
114
113
|
* Syncs the internal Set to the Store state.
|
|
115
114
|
*/
|
|
116
115
|
#syncState() {
|
|
116
|
+
const heldKeys = Array.from(new Set(Array.from(this.#heldEntries.values(), (entry) => entry.key)));
|
|
117
|
+
const heldCodes = Object.fromEntries(Array.from(this.#heldEntries.values(), (entry) => [entry.key, entry.code]));
|
|
117
118
|
this.store.setState(() => ({
|
|
118
|
-
heldKeys
|
|
119
|
-
heldCodes
|
|
119
|
+
heldKeys,
|
|
120
|
+
heldCodes
|
|
120
121
|
}));
|
|
121
122
|
}
|
|
122
123
|
/**
|
|
@@ -125,11 +126,11 @@ var KeyStateTracker = class KeyStateTracker {
|
|
|
125
126
|
#removeListeners() {
|
|
126
127
|
if (typeof document === "undefined") return;
|
|
127
128
|
if (this.#keydownListener) {
|
|
128
|
-
document.removeEventListener("keydown", this.#keydownListener);
|
|
129
|
+
document.removeEventListener("keydown", this.#keydownListener, true);
|
|
129
130
|
this.#keydownListener = null;
|
|
130
131
|
}
|
|
131
132
|
if (this.#keyupListener) {
|
|
132
|
-
document.removeEventListener("keyup", this.#keyupListener);
|
|
133
|
+
document.removeEventListener("keyup", this.#keyupListener, true);
|
|
133
134
|
this.#keyupListener = null;
|
|
134
135
|
}
|
|
135
136
|
if (this.#blurListener) {
|
|
@@ -153,7 +154,7 @@ var KeyStateTracker = class KeyStateTracker {
|
|
|
153
154
|
*/
|
|
154
155
|
isKeyHeld(key) {
|
|
155
156
|
const normalizedKey = normalizeKeyName(key);
|
|
156
|
-
return this.#
|
|
157
|
+
return Array.from(this.#heldEntries.values()).some((entry) => entry.key === normalizedKey);
|
|
157
158
|
}
|
|
158
159
|
/**
|
|
159
160
|
* Checks if any of the given keys are currently held.
|
|
@@ -178,8 +179,7 @@ var KeyStateTracker = class KeyStateTracker {
|
|
|
178
179
|
*/
|
|
179
180
|
destroy() {
|
|
180
181
|
this.#removeListeners();
|
|
181
|
-
this.#
|
|
182
|
-
this.#heldCodesMap.clear();
|
|
182
|
+
this.#heldEntries.clear();
|
|
183
183
|
this.store.setState(() => getDefaultKeyStateTrackerState());
|
|
184
184
|
}
|
|
185
185
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-state-tracker.js","names":["#instance","#setupListeners","#keydownListener","#heldKeysSet","#heldCodesMap","#syncState","#keyupListener","#blurListener","#removeListeners"],"sources":["../src/key-state-tracker.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { MODIFIER_KEYS, normalizeKeyName } from './constants'\n\n/**\n * State interface for the KeyStateTracker.\n */\nexport interface KeyStateTrackerState {\n /**\n * Array of currently held key names (normalized, e.g. \"Control\", \"A\").\n */\n heldKeys: Array<string>\n /**\n * Map from normalized key name to the physical `event.code` (e.g. \"KeyA\", \"ShiftLeft\").\n * Useful for debugging which physical key was pressed.\n */\n heldCodes: Record<string, string>\n}\n\n/**\n * Returns the default state for KeyStateTracker.\n */\nfunction getDefaultKeyStateTrackerState(): KeyStateTrackerState {\n return {\n heldKeys: [],\n heldCodes: {},\n }\n}\n\n/**\n * Singleton tracker for currently held keyboard keys.\n *\n * This class maintains a list of all keys currently being pressed,\n * which is useful for:\n * - Displaying currently held keys to users\n * - Custom shortcut recording for rebinding\n * - Complex chord detection\n *\n * State Management:\n * - Uses TanStack Store for reactive state management\n * - State can be accessed via `tracker.store.state` when using the class directly\n * - When using framework adapters (React), use `useHeldKeys` and `useHeldKeyCodes` hooks for reactive state\n *\n * @example\n * ```ts\n * const tracker = KeyStateTracker.getInstance()\n *\n * // Access state directly\n * console.log(tracker.store.state.heldKeys) // ['Control', 'Shift']\n *\n * // Subscribe to changes with TanStack Store\n * const unsubscribe = tracker.store.subscribe(() => {\n * console.log('Currently held:', tracker.store.state.heldKeys)\n * })\n *\n * // Check current state\n * console.log(tracker.getHeldKeys()) // ['Control', 'Shift']\n * console.log(tracker.isKeyHeld('Control')) // true\n *\n * // Cleanup\n * unsubscribe()\n * ```\n */\nexport class KeyStateTracker {\n static #instance: KeyStateTracker | null = null\n\n /**\n * The TanStack Store instance containing the tracker state.\n * Use this to subscribe to state changes or access current state.\n */\n readonly store: Store<KeyStateTrackerState> = new Store(\n getDefaultKeyStateTrackerState(),\n )\n\n #heldKeysSet: Set<string> = new Set()\n #heldCodesMap: Map<string, string> = new Map()\n #keydownListener: ((event: KeyboardEvent) => void) | null = null\n #keyupListener: ((event: KeyboardEvent) => void) | null = null\n #blurListener: (() => void) | null = null\n\n private constructor() {\n this.#setupListeners()\n }\n\n /**\n * Gets the singleton instance of KeyStateTracker.\n */\n static getInstance(): KeyStateTracker {\n if (!KeyStateTracker.#instance) {\n KeyStateTracker.#instance = new KeyStateTracker()\n }\n return KeyStateTracker.#instance\n }\n\n /**\n * Resets the singleton instance. Useful for testing.\n */\n static resetInstance(): void {\n if (KeyStateTracker.#instance) {\n KeyStateTracker.#instance.destroy()\n KeyStateTracker.#instance = null\n }\n }\n\n /**\n * Sets up the keyboard event listeners.\n */\n #setupListeners(): void {\n if (typeof document === 'undefined') {\n return // SSR safety\n }\n\n this.#keydownListener = (event: KeyboardEvent) => {\n const key = normalizeKeyName(event.key)\n if (!this.#heldKeysSet.has(key)) {\n this.#heldKeysSet.add(key)\n this.#heldCodesMap.set(key, event.code)\n this.#syncState()\n }\n }\n\n this.#keyupListener = (event: KeyboardEvent) => {\n const key = normalizeKeyName(event.key)\n if (this.#heldKeysSet.has(key)) {\n this.#heldKeysSet.delete(key)\n this.#heldCodesMap.delete(key)\n }\n\n // When a modifier key is released, clear any non-modifier keys still\n // marked as held. On macOS, the OS intercepts modifier+key combos\n // (e.g. Cmd+S) and swallows the keyup event for the non-modifier key,\n // leaving it permanently stuck in the held set.\n if (MODIFIER_KEYS.has(key)) {\n for (const heldKey of this.#heldKeysSet) {\n if (!MODIFIER_KEYS.has(heldKey)) {\n this.#heldKeysSet.delete(heldKey)\n this.#heldCodesMap.delete(heldKey)\n }\n }\n }\n\n this.#syncState()\n }\n\n // Clear all keys when window loses focus (keys might be released while not focused)\n this.#blurListener = () => {\n if (this.#heldKeysSet.size > 0) {\n this.#heldKeysSet.clear()\n this.#heldCodesMap.clear()\n this.#syncState()\n }\n }\n\n document.addEventListener('keydown', this.#keydownListener)\n document.addEventListener('keyup', this.#keyupListener)\n window.addEventListener('blur', this.#blurListener)\n }\n\n /**\n * Syncs the internal Set to the Store state.\n */\n #syncState(): void {\n this.store.setState(() => ({\n heldKeys: Array.from(this.#heldKeysSet),\n heldCodes: Object.fromEntries(this.#heldCodesMap),\n }))\n }\n\n /**\n * Removes the keyboard event listeners.\n */\n #removeListeners(): void {\n if (typeof document === 'undefined') {\n return\n }\n\n if (this.#keydownListener) {\n document.removeEventListener('keydown', this.#keydownListener)\n this.#keydownListener = null\n }\n\n if (this.#keyupListener) {\n document.removeEventListener('keyup', this.#keyupListener)\n this.#keyupListener = null\n }\n\n if (this.#blurListener) {\n window.removeEventListener('blur', this.#blurListener)\n this.#blurListener = null\n }\n }\n\n /**\n * Gets an array of currently held key names.\n *\n * @returns Array of key names currently being pressed\n */\n getHeldKeys(): Array<string> {\n return this.store.state.heldKeys\n }\n\n /**\n * Checks if a specific key is currently being held.\n *\n * @param key - The key name to check (case-insensitive)\n * @returns True if the key is currently held\n */\n isKeyHeld(key: string): boolean {\n const normalizedKey = normalizeKeyName(key)\n return this.#heldKeysSet.has(normalizedKey)\n }\n\n /**\n * Checks if any of the given keys are currently held.\n *\n * @param keys - Array of key names to check\n * @returns True if any of the keys are currently held\n */\n isAnyKeyHeld(keys: Array<string>): boolean {\n return keys.some((key) => this.isKeyHeld(key))\n }\n\n /**\n * Checks if all of the given keys are currently held.\n *\n * @param keys - Array of key names to check\n * @returns True if all of the keys are currently held\n */\n areAllKeysHeld(keys: Array<string>): boolean {\n return keys.every((key) => this.isKeyHeld(key))\n }\n\n /**\n * Destroys the tracker and removes all listeners.\n */\n destroy(): void {\n this.#removeListeners()\n this.#heldKeysSet.clear()\n this.#heldCodesMap.clear()\n this.store.setState(() => getDefaultKeyStateTrackerState())\n }\n}\n\n/**\n * Gets the singleton KeyStateTracker instance.\n * Convenience function for accessing the tracker.\n */\nexport function getKeyStateTracker(): KeyStateTracker {\n return KeyStateTracker.getInstance()\n}\n"],"mappings":";;;;;;;AAqBA,SAAS,iCAAuD;AAC9D,QAAO;EACL,UAAU,EAAE;EACZ,WAAW,EAAE;EACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,IAAa,kBAAb,MAAa,gBAAgB;CAC3B,QAAOA,WAAoC;CAU3C,+BAA4B,IAAI,KAAK;CACrC,gCAAqC,IAAI,KAAK;CAC9C,mBAA4D;CAC5D,iBAA0D;CAC1D,gBAAqC;CAErC,AAAQ,cAAc;eAVwB,IAAI,MAChD,gCAAgC,CACjC;AASC,QAAKC,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AAY,MAAKC,aAAc;GAClD,EAAE;;;;;CAML,mBAAyB;AACvB,MAAI,OAAO,aAAa,YACtB;AAGF,MAAI,MAAKF,iBAAkB;AACzB,YAAS,oBAAoB,WAAW,MAAKA,gBAAiB;AAC9D,SAAKA,kBAAmB;;AAG1B,MAAI,MAAKI,eAAgB;AACvB,YAAS,oBAAoB,SAAS,MAAKA,cAAe;AAC1D,SAAKA,gBAAiB;;AAGxB,MAAI,MAAKC,cAAe;AACtB,UAAO,oBAAoB,QAAQ,MAAKA,aAAc;AACtD,SAAKA,eAAgB;;;;;;;;CASzB,cAA6B;AAC3B,SAAO,KAAK,MAAM,MAAM;;;;;;;;CAS1B,UAAU,KAAsB;EAC9B,MAAM,gBAAgB,iBAAiB,IAAI;AAC3C,SAAO,MAAKJ,YAAa,IAAI,cAAc;;;;;;;;CAS7C,aAAa,MAA8B;AACzC,SAAO,KAAK,MAAM,QAAQ,KAAK,UAAU,IAAI,CAAC;;;;;;;;CAShD,eAAe,MAA8B;AAC3C,SAAO,KAAK,OAAO,QAAQ,KAAK,UAAU,IAAI,CAAC;;;;;CAMjD,UAAgB;AACd,QAAKK,iBAAkB;AACvB,QAAKL,YAAa,OAAO;AACzB,QAAKC,aAAc,OAAO;AAC1B,OAAK,MAAM,eAAe,gCAAgC,CAAC;;;;;;;AAQ/D,SAAgB,qBAAsC;AACpD,QAAO,gBAAgB,aAAa"}
|
|
1
|
+
{"version":3,"file":"key-state-tracker.js","names":["#instance","#setupListeners","#keydownListener","#heldEntries","#syncState","#keyupListener","#blurListener","#removeListeners"],"sources":["../src/key-state-tracker.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { MODIFIER_KEYS, normalizeKeyName } from './constants'\n\n/**\n * State interface for the KeyStateTracker.\n */\nexport interface KeyStateTrackerState {\n /**\n * Array of currently held key names (normalized, e.g. \"Control\", \"A\").\n */\n heldKeys: Array<string>\n /**\n * Map from normalized key name to the physical `event.code` (e.g. \"KeyA\", \"ShiftLeft\").\n * Useful for debugging which physical key was pressed.\n */\n heldCodes: Record<string, string>\n}\n\n/**\n * Returns the default state for KeyStateTracker.\n */\nfunction getDefaultKeyStateTrackerState(): KeyStateTrackerState {\n return {\n heldKeys: [],\n heldCodes: {},\n }\n}\n\n/**\n * Singleton tracker for currently held keyboard keys.\n *\n * This class maintains a list of all keys currently being pressed,\n * which is useful for:\n * - Displaying currently held keys to users\n * - Custom shortcut recording for rebinding\n * - Complex chord detection\n *\n * State Management:\n * - Uses TanStack Store for reactive state management\n * - State can be accessed via `tracker.store.state` when using the class directly\n * - When using framework adapters (React), use `useHeldKeys` and `useHeldKeyCodes` hooks for reactive state\n *\n * @example\n * ```ts\n * const tracker = KeyStateTracker.getInstance()\n *\n * // Access state directly\n * console.log(tracker.store.state.heldKeys) // ['Control', 'Shift']\n *\n * // Subscribe to changes with TanStack Store\n * const unsubscribe = tracker.store.subscribe(() => {\n * console.log('Currently held:', tracker.store.state.heldKeys)\n * })\n *\n * // Check current state\n * console.log(tracker.getHeldKeys()) // ['Control', 'Shift']\n * console.log(tracker.isKeyHeld('Control')) // true\n *\n * // Cleanup\n * unsubscribe()\n * ```\n */\nexport class KeyStateTracker {\n static #instance: KeyStateTracker | null = null\n\n /**\n * The TanStack Store instance containing the tracker state.\n * Use this to subscribe to state changes or access current state.\n */\n readonly store: Store<KeyStateTrackerState> = new Store(\n getDefaultKeyStateTrackerState(),\n )\n\n #heldEntries: Map<string, { key: string; code: string }> = new Map()\n #keydownListener: ((event: KeyboardEvent) => void) | null = null\n #keyupListener: ((event: KeyboardEvent) => void) | null = null\n #blurListener: (() => void) | null = null\n\n private constructor() {\n this.#setupListeners()\n }\n\n /**\n * Gets the singleton instance of KeyStateTracker.\n */\n static getInstance(): KeyStateTracker {\n if (!KeyStateTracker.#instance) {\n KeyStateTracker.#instance = new KeyStateTracker()\n }\n return KeyStateTracker.#instance\n }\n\n /**\n * Resets the singleton instance. Useful for testing.\n */\n static resetInstance(): void {\n if (KeyStateTracker.#instance) {\n KeyStateTracker.#instance.destroy()\n KeyStateTracker.#instance = null\n }\n }\n\n /**\n * Sets up the keyboard event listeners.\n */\n #setupListeners(): void {\n if (typeof document === 'undefined') {\n return // SSR safety\n }\n\n this.#keydownListener = (event: KeyboardEvent) => {\n const key = normalizeKeyName(event.key)\n const identity = event.code || `key:${key}`\n if (!this.#heldEntries.has(identity)) {\n this.#heldEntries.set(identity, { key, code: event.code })\n this.#syncState()\n }\n }\n\n this.#keyupListener = (event: KeyboardEvent) => {\n const key = normalizeKeyName(event.key)\n const identity = event.code || `key:${key}`\n this.#heldEntries.delete(identity)\n\n // Code-less keyup events can only be paired by their logical key.\n if (!event.code) {\n for (const [entryIdentity, entry] of this.#heldEntries) {\n if (entry.key === key) this.#heldEntries.delete(entryIdentity)\n }\n }\n\n // When a modifier key is released, clear any non-modifier keys still\n // marked as held. On macOS, the OS intercepts modifier+key combos\n // (e.g. Cmd+S) and swallows the keyup event for the non-modifier key,\n // leaving it permanently stuck in the held set.\n if (MODIFIER_KEYS.has(key)) {\n for (const [entryIdentity, entry] of this.#heldEntries) {\n if (!MODIFIER_KEYS.has(entry.key)) {\n this.#heldEntries.delete(entryIdentity)\n }\n }\n }\n\n this.#syncState()\n }\n\n // Clear all keys when window loses focus (keys might be released while not focused)\n this.#blurListener = () => {\n if (this.#heldEntries.size > 0) {\n this.#heldEntries.clear()\n this.#syncState()\n }\n }\n\n document.addEventListener('keydown', this.#keydownListener, true)\n document.addEventListener('keyup', this.#keyupListener, true)\n window.addEventListener('blur', this.#blurListener)\n }\n\n /**\n * Syncs the internal Set to the Store state.\n */\n #syncState(): void {\n const heldKeys = Array.from(\n new Set(Array.from(this.#heldEntries.values(), (entry) => entry.key)),\n )\n const heldCodes = Object.fromEntries(\n Array.from(this.#heldEntries.values(), (entry) => [\n entry.key,\n entry.code,\n ]),\n )\n this.store.setState(() => ({\n heldKeys,\n heldCodes,\n }))\n }\n\n /**\n * Removes the keyboard event listeners.\n */\n #removeListeners(): void {\n if (typeof document === 'undefined') {\n return\n }\n\n if (this.#keydownListener) {\n document.removeEventListener('keydown', this.#keydownListener, true)\n this.#keydownListener = null\n }\n\n if (this.#keyupListener) {\n document.removeEventListener('keyup', this.#keyupListener, true)\n this.#keyupListener = null\n }\n\n if (this.#blurListener) {\n window.removeEventListener('blur', this.#blurListener)\n this.#blurListener = null\n }\n }\n\n /**\n * Gets an array of currently held key names.\n *\n * @returns Array of key names currently being pressed\n */\n getHeldKeys(): Array<string> {\n return this.store.state.heldKeys\n }\n\n /**\n * Checks if a specific key is currently being held.\n *\n * @param key - The key name to check (case-insensitive)\n * @returns True if the key is currently held\n */\n isKeyHeld(key: string): boolean {\n const normalizedKey = normalizeKeyName(key)\n return Array.from(this.#heldEntries.values()).some(\n (entry) => entry.key === normalizedKey,\n )\n }\n\n /**\n * Checks if any of the given keys are currently held.\n *\n * @param keys - Array of key names to check\n * @returns True if any of the keys are currently held\n */\n isAnyKeyHeld(keys: Array<string>): boolean {\n return keys.some((key) => this.isKeyHeld(key))\n }\n\n /**\n * Checks if all of the given keys are currently held.\n *\n * @param keys - Array of key names to check\n * @returns True if all of the keys are currently held\n */\n areAllKeysHeld(keys: Array<string>): boolean {\n return keys.every((key) => this.isKeyHeld(key))\n }\n\n /**\n * Destroys the tracker and removes all listeners.\n */\n destroy(): void {\n this.#removeListeners()\n this.#heldEntries.clear()\n this.store.setState(() => getDefaultKeyStateTrackerState())\n }\n}\n\n/**\n * Gets the singleton KeyStateTracker instance.\n * Convenience function for accessing the tracker.\n */\nexport function getKeyStateTracker(): KeyStateTracker {\n return KeyStateTracker.getInstance()\n}\n"],"mappings":";;;;;;;AAqBA,SAAS,iCAAuD;AAC9D,QAAO;EACL,UAAU,EAAE;EACZ,WAAW,EAAE;EACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,IAAa,kBAAb,MAAa,gBAAgB;CAC3B,QAAOA,WAAoC;CAU3C,+BAA2D,IAAI,KAAK;CACpE,mBAA4D;CAC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 -0,0 +1,82 @@
|
|
|
1
|
+
import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from "./_named-keys.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/key.types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* All supported modifier key names, including aliases.
|
|
6
|
+
* - Control/Ctrl: The Control key
|
|
7
|
+
* - Shift: The Shift key
|
|
8
|
+
* - Alt/Option: The Alt key (Option on macOS)
|
|
9
|
+
* - Command/Cmd: The Command key (macOS only)
|
|
10
|
+
* - CommandOrControl/Mod: Command on macOS, Control on other platforms
|
|
11
|
+
*/
|
|
12
|
+
type Modifier = 'Control' | 'Ctrl' | 'Shift' | 'Alt' | 'Option' | 'Command' | 'Cmd' | 'CommandOrControl' | 'Mod';
|
|
13
|
+
/**
|
|
14
|
+
* Canonical modifier names that map to KeyboardEvent properties.
|
|
15
|
+
*/
|
|
16
|
+
type CanonicalModifier = 'Control' | 'Shift' | 'Alt' | 'Meta';
|
|
17
|
+
/**
|
|
18
|
+
* Letter keys A-Z (case-insensitive in matching).
|
|
19
|
+
*/
|
|
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';
|
|
21
|
+
/**
|
|
22
|
+
* Number keys 0-9.
|
|
23
|
+
*/
|
|
24
|
+
type NumberKey = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
25
|
+
/**
|
|
26
|
+
* Function keys F1-F24, supported as both logical keys and physical codes.
|
|
27
|
+
*/
|
|
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';
|
|
29
|
+
/**
|
|
30
|
+
* Navigation keys for cursor movement.
|
|
31
|
+
*/
|
|
32
|
+
type NavigationKey = 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
33
|
+
/**
|
|
34
|
+
* Editing and special keys.
|
|
35
|
+
*/
|
|
36
|
+
type EditingKey = 'Enter' | 'Escape' | 'Space' | 'Tab' | 'Backspace' | 'Delete';
|
|
37
|
+
/**
|
|
38
|
+
* Printable punctuation glyphs used in keyboard shortcuts. Matching uses the
|
|
39
|
+
* final KeyboardEvent.key glyph, independent of which layout produced it.
|
|
40
|
+
*/
|
|
41
|
+
type PunctuationKey = '/' | '[' | ']' | '\\' | '=' | '-' | ',' | '.' | ';' | '`' | "'" | '+' | '?' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '_' | '{' | '}' | '|' | ':' | '"' | '<' | '>' | '~';
|
|
42
|
+
/** 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];
|
|
44
|
+
/** Supported logical key names other than printable punctuation. */
|
|
45
|
+
type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | FunctionKey | NamedKey;
|
|
46
|
+
/**
|
|
47
|
+
* Supported physical KeyboardEvent.code names, independent of keyboard layout.
|
|
48
|
+
* Letter, digit, numpad, and sided modifier names use finite template unions.
|
|
49
|
+
* `Unidentified` is excluded because it cannot identify a physical key.
|
|
50
|
+
*
|
|
51
|
+
* @see https://www.w3.org/TR/uievents-code/
|
|
52
|
+
*/
|
|
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';
|
|
54
|
+
/**
|
|
55
|
+
* An explicit physical key token. All codes use brackets, including names such
|
|
56
|
+
* as `[Enter]` that also exist as logical keys. Invalid code names are rejected
|
|
57
|
+
* by TypeScript, and supported names are available in autocomplete.
|
|
58
|
+
*/
|
|
59
|
+
type PhysicalKey = `[${PhysicalKeyCode}]`;
|
|
60
|
+
/** Supported logical key names, excluding bracketed physical-code syntax. */
|
|
61
|
+
type LogicalKey = NonPunctuationKey | PunctuationKey;
|
|
62
|
+
/** All supported logical keys and bracketed physical key tokens. */
|
|
63
|
+
type Key = LogicalKey | PhysicalKey;
|
|
64
|
+
/**
|
|
65
|
+
* Includes both modifier keys and regular keys.
|
|
66
|
+
*/
|
|
67
|
+
type IndividualKey = CanonicalModifier | Key;
|
|
68
|
+
/** Keyboard event properties normalized for internal matching and recording. */
|
|
69
|
+
interface NormalizedKeyboardEvent {
|
|
70
|
+
key: string;
|
|
71
|
+
code: string;
|
|
72
|
+
ctrl: boolean;
|
|
73
|
+
shift: boolean;
|
|
74
|
+
alt: boolean;
|
|
75
|
+
meta: boolean;
|
|
76
|
+
altGraph: boolean;
|
|
77
|
+
location: number;
|
|
78
|
+
isComposing: boolean;
|
|
79
|
+
}
|
|
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.cts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from "./_named-keys.js";
|
|
2
|
+
|
|
3
|
+
//#region src/key.types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* All supported modifier key names, including aliases.
|
|
6
|
+
* - Control/Ctrl: The Control key
|
|
7
|
+
* - Shift: The Shift key
|
|
8
|
+
* - Alt/Option: The Alt key (Option on macOS)
|
|
9
|
+
* - Command/Cmd: The Command key (macOS only)
|
|
10
|
+
* - CommandOrControl/Mod: Command on macOS, Control on other platforms
|
|
11
|
+
*/
|
|
12
|
+
type Modifier = 'Control' | 'Ctrl' | 'Shift' | 'Alt' | 'Option' | 'Command' | 'Cmd' | 'CommandOrControl' | 'Mod';
|
|
13
|
+
/**
|
|
14
|
+
* Canonical modifier names that map to KeyboardEvent properties.
|
|
15
|
+
*/
|
|
16
|
+
type CanonicalModifier = 'Control' | 'Shift' | 'Alt' | 'Meta';
|
|
17
|
+
/**
|
|
18
|
+
* Letter keys A-Z (case-insensitive in matching).
|
|
19
|
+
*/
|
|
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';
|
|
21
|
+
/**
|
|
22
|
+
* Number keys 0-9.
|
|
23
|
+
*/
|
|
24
|
+
type NumberKey = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
25
|
+
/**
|
|
26
|
+
* Function keys F1-F24, supported as both logical keys and physical codes.
|
|
27
|
+
*/
|
|
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';
|
|
29
|
+
/**
|
|
30
|
+
* Navigation keys for cursor movement.
|
|
31
|
+
*/
|
|
32
|
+
type NavigationKey = 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
33
|
+
/**
|
|
34
|
+
* Editing and special keys.
|
|
35
|
+
*/
|
|
36
|
+
type EditingKey = 'Enter' | 'Escape' | 'Space' | 'Tab' | 'Backspace' | 'Delete';
|
|
37
|
+
/**
|
|
38
|
+
* Printable punctuation glyphs used in keyboard shortcuts. Matching uses the
|
|
39
|
+
* final KeyboardEvent.key glyph, independent of which layout produced it.
|
|
40
|
+
*/
|
|
41
|
+
type PunctuationKey = '/' | '[' | ']' | '\\' | '=' | '-' | ',' | '.' | ';' | '`' | "'" | '+' | '?' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '_' | '{' | '}' | '|' | ':' | '"' | '<' | '>' | '~';
|
|
42
|
+
/** 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];
|
|
44
|
+
/** Supported logical key names other than printable punctuation. */
|
|
45
|
+
type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | FunctionKey | NamedKey;
|
|
46
|
+
/**
|
|
47
|
+
* Supported physical KeyboardEvent.code names, independent of keyboard layout.
|
|
48
|
+
* Letter, digit, numpad, and sided modifier names use finite template unions.
|
|
49
|
+
* `Unidentified` is excluded because it cannot identify a physical key.
|
|
50
|
+
*
|
|
51
|
+
* @see https://www.w3.org/TR/uievents-code/
|
|
52
|
+
*/
|
|
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';
|
|
54
|
+
/**
|
|
55
|
+
* An explicit physical key token. All codes use brackets, including names such
|
|
56
|
+
* as `[Enter]` that also exist as logical keys. Invalid code names are rejected
|
|
57
|
+
* by TypeScript, and supported names are available in autocomplete.
|
|
58
|
+
*/
|
|
59
|
+
type PhysicalKey = `[${PhysicalKeyCode}]`;
|
|
60
|
+
/** Supported logical key names, excluding bracketed physical-code syntax. */
|
|
61
|
+
type LogicalKey = NonPunctuationKey | PunctuationKey;
|
|
62
|
+
/** All supported logical keys and bracketed physical key tokens. */
|
|
63
|
+
type Key = LogicalKey | PhysicalKey;
|
|
64
|
+
/**
|
|
65
|
+
* Includes both modifier keys and regular keys.
|
|
66
|
+
*/
|
|
67
|
+
type IndividualKey = CanonicalModifier | Key;
|
|
68
|
+
/** Keyboard event properties normalized for internal matching and recording. */
|
|
69
|
+
interface NormalizedKeyboardEvent {
|
|
70
|
+
key: string;
|
|
71
|
+
code: string;
|
|
72
|
+
ctrl: boolean;
|
|
73
|
+
shift: boolean;
|
|
74
|
+
alt: boolean;
|
|
75
|
+
meta: boolean;
|
|
76
|
+
altGraph: boolean;
|
|
77
|
+
location: number;
|
|
78
|
+
isComposing: boolean;
|
|
79
|
+
}
|
|
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
|
package/dist/match.cjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_platform = require('./platform.cjs');
|
|
2
|
+
const require__keyboard_event = require('./_keyboard-event.cjs');
|
|
2
3
|
const require_parse = require('./parse.cjs');
|
|
4
|
+
const require__match = require('./_match.cjs');
|
|
3
5
|
|
|
4
6
|
//#region src/match.ts
|
|
5
7
|
/**
|
|
6
8
|
* Checks if a KeyboardEvent matches a hotkey.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* Physical bindings such as `Mod+[KeyS]` match `event.code` exactly.
|
|
11
|
+
* Logical bindings use `event.key`, with a fallback to `code`
|
|
9
12
|
* for letter keys, digit keys (0-9), and punctuation keys when `key` produces special
|
|
10
13
|
* characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).
|
|
11
14
|
* Letter keys are matched case-insensitively.
|
|
@@ -30,31 +33,8 @@ const require_parse = require('./parse.cjs');
|
|
|
30
33
|
* })
|
|
31
34
|
* ```
|
|
32
35
|
*/
|
|
33
|
-
function matchesKeyboardEvent(event, hotkey, platform =
|
|
34
|
-
|
|
35
|
-
if (event.ctrlKey !== parsed.ctrl) return false;
|
|
36
|
-
if (event.shiftKey !== parsed.shift) return false;
|
|
37
|
-
if (event.altKey !== parsed.alt) return false;
|
|
38
|
-
if (event.metaKey !== parsed.meta) return false;
|
|
39
|
-
const eventKey = require_constants.normalizeKeyName(event.key);
|
|
40
|
-
const hotkeyKey = parsed.key;
|
|
41
|
-
if (eventKey !== "Dead" && eventKey.length === 1 && hotkeyKey.length === 1) {
|
|
42
|
-
if (eventKey.toUpperCase() === hotkeyKey.toUpperCase()) return true;
|
|
43
|
-
if (require_constants.isSingleLetterKey(eventKey) && (/^[A-Za-z]$/.test(eventKey) || !event.altKey)) return false;
|
|
44
|
-
}
|
|
45
|
-
if (event.code && (eventKey === "Dead" || eventKey.length === 1 && hotkeyKey.length === 1)) {
|
|
46
|
-
if (event.code.startsWith("Key")) {
|
|
47
|
-
const codeLetter = event.code.slice(3);
|
|
48
|
-
if (codeLetter.length === 1 && /^[A-Za-z]$/.test(codeLetter)) return codeLetter.toUpperCase() === hotkeyKey.toUpperCase();
|
|
49
|
-
}
|
|
50
|
-
if (event.code.startsWith("Digit")) {
|
|
51
|
-
const codeDigit = event.code.slice(5);
|
|
52
|
-
if (codeDigit.length === 1 && /^[0-9]$/.test(codeDigit)) return codeDigit === hotkeyKey;
|
|
53
|
-
}
|
|
54
|
-
if (event.code in require_constants.PUNCTUATION_CODE_MAP) return require_constants.PUNCTUATION_CODE_MAP[event.code] === hotkeyKey;
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return eventKey === hotkeyKey;
|
|
36
|
+
function matchesKeyboardEvent(event, hotkey, platform = require_platform.detectPlatform()) {
|
|
37
|
+
return require__match.matchKeyboardEvent(event, hotkey, platform).matched;
|
|
58
38
|
}
|
|
59
39
|
/**
|
|
60
40
|
* Creates a keyboard event handler that calls the callback when the hotkey matches.
|
|
@@ -76,7 +56,7 @@ function matchesKeyboardEvent(event, hotkey, platform = require_constants.detect
|
|
|
76
56
|
*/
|
|
77
57
|
function createHotkeyHandler(hotkey, callback, options = {}) {
|
|
78
58
|
const { preventDefault = true, stopPropagation = true, platform } = options;
|
|
79
|
-
const resolvedPlatform = platform ??
|
|
59
|
+
const resolvedPlatform = platform ?? require_platform.detectPlatform();
|
|
80
60
|
const hotkeyString = typeof hotkey === "string" ? hotkey : formatParsedHotkey(hotkey);
|
|
81
61
|
const parsed = typeof hotkey === "string" ? require_parse.parseHotkey(hotkey, resolvedPlatform) : hotkey;
|
|
82
62
|
const context = {
|
|
@@ -111,7 +91,7 @@ function createHotkeyHandler(hotkey, callback, options = {}) {
|
|
|
111
91
|
*/
|
|
112
92
|
function createMultiHotkeyHandler(handlers, options = {}) {
|
|
113
93
|
const { preventDefault = true, stopPropagation = true, platform } = options;
|
|
114
|
-
const resolvedPlatform = platform ??
|
|
94
|
+
const resolvedPlatform = platform ?? require_platform.detectPlatform();
|
|
115
95
|
const parsedHandlers = Object.entries(handlers).filter((entry) => Boolean(entry[1])).map(([hotkey, handler]) => {
|
|
116
96
|
const parsed = require_parse.parseHotkey(hotkey, resolvedPlatform);
|
|
117
97
|
return {
|
|
@@ -142,11 +122,22 @@ function formatParsedHotkey(parsed) {
|
|
|
142
122
|
if (parsed.alt) parts.push("Alt");
|
|
143
123
|
if (parsed.shift) parts.push("Shift");
|
|
144
124
|
if (parsed.meta) parts.push("Meta");
|
|
145
|
-
parts.push(parsed.key);
|
|
125
|
+
parts.push(parsed.code !== void 0 ? `[${parsed.code}]` : parsed.key);
|
|
146
126
|
return parts.join("+");
|
|
147
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Compares normalized binding identity, including all four modifiers.
|
|
130
|
+
* Aliases resolve on the supplied platform. A physical code and a logical key
|
|
131
|
+
* remain distinct even when one keyboard event could match both.
|
|
132
|
+
*/
|
|
133
|
+
function areHotkeysEqual(left, right, platform = require_platform.detectPlatform()) {
|
|
134
|
+
const a = require_parse.parseRegisterableHotkey(left, platform);
|
|
135
|
+
const b = require_parse.parseRegisterableHotkey(right, platform);
|
|
136
|
+
return a.ctrl === b.ctrl && a.alt === b.alt && a.shift === b.shift && a.meta === b.meta && (a.code !== void 0 || b.code !== void 0 ? a.code === b.code : require__keyboard_event.keysEqual(a.key, b.key));
|
|
137
|
+
}
|
|
148
138
|
|
|
149
139
|
//#endregion
|
|
140
|
+
exports.areHotkeysEqual = areHotkeysEqual;
|
|
150
141
|
exports.createHotkeyHandler = createHotkeyHandler;
|
|
151
142
|
exports.createMultiHotkeyHandler = createMultiHotkeyHandler;
|
|
152
143
|
exports.matchesKeyboardEvent = matchesKeyboardEvent;
|
package/dist/match.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.cjs","names":["detectPlatform","parseHotkey","normalizeKeyName","isSingleLetterKey","PUNCTUATION_CODE_MAP"],"sources":["../src/match.ts"],"sourcesContent":["import {\n PUNCTUATION_CODE_MAP,\n detectPlatform,\n isSingleLetterKey,\n normalizeKeyName,\n} from './constants'\nimport { parseHotkey } from './parse'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyCallbackContext,\n ParsedHotkey,\n} from './hotkey'\n\n/**\n * Checks if a KeyboardEvent matches a hotkey.\n *\n * Uses the `key` property from KeyboardEvent for matching, with a fallback to `code`\n * for letter keys, digit keys (0-9), and punctuation keys when `key` produces special\n * characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).\n * Letter keys are matched case-insensitively.\n *\n * Also handles \"dead key\" events where `event.key` is `'Dead'` instead of the expected\n * character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E,\n * Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts.\n * In these cases, `event.code` is used to determine the physical key.\n *\n * @param event - The KeyboardEvent to check\n * @param hotkey - The hotkey string or ParsedHotkey to match against\n * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection)\n * @returns True if the event matches the hotkey\n *\n * @example\n * ```ts\n * document.addEventListener('keydown', (event) => {\n * if (matchesKeyboardEvent(event, 'Mod+S')) {\n * event.preventDefault()\n * handleSave()\n * }\n * })\n * ```\n */\nexport function matchesKeyboardEvent(\n event: KeyboardEvent,\n hotkey: Hotkey | ParsedHotkey,\n platform: 'mac' | 'windows' | 'linux' = detectPlatform(),\n): boolean {\n const parsed =\n typeof hotkey === 'string' ? parseHotkey(hotkey, platform) : hotkey\n\n // Check modifiers\n if (event.ctrlKey !== parsed.ctrl) {\n return false\n }\n if (event.shiftKey !== parsed.shift) {\n return false\n }\n if (event.altKey !== parsed.alt) {\n return false\n }\n if (event.metaKey !== parsed.meta) {\n return false\n }\n\n // Check key (case-insensitive for letters)\n const eventKey = normalizeKeyName(event.key)\n const hotkeyKey = parsed.key\n\n // For single-character keys (not dead keys), try direct event.key match first\n if (eventKey !== 'Dead' && eventKey.length === 1 && hotkeyKey.length === 1) {\n if (eventKey.toUpperCase() === hotkeyKey.toUpperCase()) {\n return true\n }\n\n // If event.key is a letter, we usually trust the keyboard layout.\n // For ASCII letters: always trust layout (Dvorak, Colemak, AZERTY support).\n // For non-ASCII letters without Alt: trust layout (e.g., Cyrillic keyboards).\n //\n // For non-ASCII letters WITH Alt held down: fall through to the event.code\n // fallback. macOS Option+letter combinations produce non-ASCII letters as\n // event.key (e.g., Option+A → 'å', Option+' → 'æ', Option+P → 'π'), but\n // event.code still reflects the physical key. We want Alt+A to match even\n // when Option+A fires event.key='å'.\n if (\n isSingleLetterKey(eventKey) &&\n (/^[A-Za-z]$/.test(eventKey) || !event.altKey)\n ) {\n return false\n }\n }\n\n // Fallback to event.code for dead keys or single-char mismatches where\n // event.key is a non-letter special character.\n // Dead keys: Option+letter on macOS, international layouts produce event.key === 'Dead'\n // Single-char mismatches: Cmd+Option+T gives '†' instead of 'T', Shift+4 gives '$'\n if (\n event.code &&\n (eventKey === 'Dead' || (eventKey.length === 1 && hotkeyKey.length === 1))\n ) {\n // fallback for letter keys (common with mac option + letter)\n if (event.code.startsWith('Key')) {\n const codeLetter = event.code.slice(3)\n if (codeLetter.length === 1 && /^[A-Za-z]$/.test(codeLetter)) {\n return codeLetter.toUpperCase() === hotkeyKey.toUpperCase()\n }\n }\n\n // fallback for number keys (common with mac option + num)\n if (event.code.startsWith('Digit')) {\n const codeDigit = event.code.slice(5)\n if (codeDigit.length === 1 && /^[0-9]$/.test(codeDigit)) {\n return codeDigit === hotkeyKey\n }\n }\n // Fallback for punctuation keys (e.g., Minus, Slash, BracketLeft).\n // On macOS, Option+punctuation produces composed characters (e.g., Option+- → '–'),\n // but event.code still reports the physical key.\n if (event.code in PUNCTUATION_CODE_MAP) {\n return PUNCTUATION_CODE_MAP[event.code] === hotkeyKey\n }\n\n return false\n }\n\n // For special keys, compare exactly (after normalization)\n return eventKey === hotkeyKey\n}\n\n/**\n * Options for creating a hotkey handler.\n */\nexport interface CreateHotkeyHandlerOptions {\n /** Prevent the default browser action when the hotkey matches. Defaults to true */\n preventDefault?: boolean\n /** Stop event propagation when the hotkey matches. Defaults to true */\n stopPropagation?: boolean\n /** The target platform for resolving 'Mod' */\n platform?: 'mac' | 'windows' | 'linux'\n}\n\n/**\n * Creates a keyboard event handler that calls the callback when the hotkey matches.\n *\n * @param hotkey - The hotkey string or ParsedHotkey to match\n * @param callback - The function to call when the hotkey matches\n * @param options - Options for matching and handling\n * @returns A function that can be used as an event handler\n *\n * @example\n * ```ts\n * const handler = createHotkeyHandler('Mod+S', (event, { hotkey, parsedHotkey }) => {\n * console.log(`${hotkey} was pressed`)\n * handleSave()\n * })\n *\n * document.addEventListener('keydown', handler)\n * ```\n */\nexport function createHotkeyHandler(\n hotkey: Hotkey | ParsedHotkey,\n callback: HotkeyCallback,\n options: CreateHotkeyHandlerOptions = {},\n): (event: KeyboardEvent) => void {\n const { preventDefault = true, stopPropagation = true, platform } = options\n const resolvedPlatform = platform ?? detectPlatform()\n\n const hotkeyString: Hotkey =\n typeof hotkey === 'string' ? hotkey : formatParsedHotkey(hotkey)\n const parsed =\n typeof hotkey === 'string' ? parseHotkey(hotkey, resolvedPlatform) : hotkey\n\n const context: HotkeyCallbackContext = {\n hotkey: hotkeyString,\n parsedHotkey: parsed,\n }\n\n return (event: KeyboardEvent) => {\n if (matchesKeyboardEvent(event, parsed, resolvedPlatform)) {\n if (preventDefault) {\n event.preventDefault()\n }\n if (stopPropagation) {\n event.stopPropagation()\n }\n callback(event, context)\n }\n }\n}\n\ntype MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback }\n\n/**\n * Creates a handler that matches multiple hotkeys.\n *\n * @param handlers - A map of hotkey strings to their handlers\n * @param options - Options for matching and handling\n * @returns A function that can be used as an event handler\n *\n * @example\n * ```ts\n * const handler = createMultiHotkeyHandler({\n * 'Mod+S': (event, { hotkey }) => handleSave(),\n * 'Mod+Z': (event, { hotkey }) => handleUndo(),\n * 'Mod+Shift+Z': (event, { hotkey }) => handleRedo(),\n * })\n *\n * document.addEventListener('keydown', handler)\n * ```\n */\nexport function createMultiHotkeyHandler(\n handlers: MultiHotkeyHandler,\n options: CreateHotkeyHandlerOptions = {},\n): (event: KeyboardEvent) => void {\n const { preventDefault = true, stopPropagation = true, platform } = options\n const resolvedPlatform = platform ?? detectPlatform()\n\n // Pre-parse all hotkeys for efficiency\n const parsedHandlers = Object.entries(handlers)\n .filter((entry): entry is [string, HotkeyCallback] => Boolean(entry[1]))\n .map(([hotkey, handler]) => {\n const parsed = parseHotkey(hotkey as Hotkey, resolvedPlatform)\n const context: HotkeyCallbackContext = {\n hotkey: hotkey as Hotkey,\n parsedHotkey: parsed,\n }\n return { parsed, handler, context }\n })\n\n return (event: KeyboardEvent) => {\n for (const { parsed, handler, context } of parsedHandlers) {\n if (matchesKeyboardEvent(event, parsed, resolvedPlatform)) {\n if (preventDefault) {\n event.preventDefault()\n }\n if (stopPropagation) {\n event.stopPropagation()\n }\n handler(event, context)\n return // Only handle the first match\n }\n }\n }\n}\n\n/**\n * Formats a ParsedHotkey back to a hotkey string.\n * Used internally to provide the hotkey string in callback context.\n */\nfunction formatParsedHotkey(parsed: ParsedHotkey): Hotkey {\n const parts: Array<string> = []\n\n if (parsed.ctrl) parts.push('Control')\n if (parsed.alt) parts.push('Alt')\n if (parsed.shift) parts.push('Shift')\n if (pars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AM,OAAM,KAAK,OAAO;AACnC,OAAM,KAAK,OAAO,IAAI;AAEtB,QAAO,MAAM,KAAK,IAAI"}
|
|
1
|
+
{"version":3,"file":"match.cjs","names":["detectPlatform","matchKeyboardEvent","parseHotkey","parseRegisterableHotkey","keysEqual"],"sources":["../src/match.ts"],"sourcesContent":["import { matchKeyboardEvent } from './_match'\nimport { parseHotkey, parseRegisterableHotkey } from './parse'\nimport { detectPlatform } from './platform'\nimport { keysEqual } from './_keyboard-event'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyCallbackContext,\n ParsedHotkey,\n RegisterableHotkey,\n} from './hotkey.types'\n\nexport interface KeyboardEventMatch {\n matched: boolean\n score: 0 | 1 | 2 | 3\n source?: 'key' | 'code' | 'fallback'\n identity?: { key: string; code: string }\n}\n\n/**\n * Checks if a KeyboardEvent matches a hotkey.\n *\n * Physical bindings such as `Mod+[KeyS]` match `event.code` exactly.\n * Logical bindings use `event.key`, with a fallback to `code`\n * for letter keys, digit keys (0-9), and punctuation keys when `key` produces special\n * characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).\n * Letter keys are matched case-insensitively.\n *\n * Also handles \"dead key\" events where `event.key` is `'Dead'` instead of the expected\n * character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E,\n * Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts.\n * In these cases, `event.code` is used to determine the physical key.\n *\n * @param event - The KeyboardEvent to check\n * @param hotkey - The hotkey string or ParsedHotkey to match against\n * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection)\n * @returns True if the event matches the hotkey\n *\n * @example\n * ```ts\n * document.addEventListener('keydown', (event) => {\n * if (matchesKeyboardEvent(event, 'Mod+S')) {\n * event.preventDefault()\n * handleSave()\n * }\n * })\n * ```\n */\nexport function matchesKeyboardEvent(\n event: KeyboardEvent,\n hotkey: Hotkey | ParsedHotkey,\n platform: 'mac' | 'windows' | 'linux' = detectPlatform(),\n): boolean {\n return matchKeyboardEvent(event, hotkey, platform).matched\n}\n\n/**\n * Options for creating a hotkey handler.\n */\nexport interface CreateHotkeyHandlerOptions {\n /** Prevent the default browser action when the hotkey matches. Defaults to true */\n preventDefault?: boolean\n /** Stop event propagation when the hotkey matches. Defaults to true */\n stopPropagation?: boolean\n /** The target platform for resolving 'Mod' */\n platform?: 'mac' | 'windows' | 'linux'\n}\n\n/**\n * Creates a keyboard event handler that calls the callback when the hotkey matches.\n *\n * @param hotkey - The hotkey string or ParsedHotkey to match\n * @param callback - The function to call when the hotkey matches\n * @param options - Options for matching and handling\n * @returns A function that can be used as an event handler\n *\n * @example\n * ```ts\n * const handler = createHotkeyHandler('Mod+S', (event, { hotkey, parsedHotkey }) => {\n * console.log(`${hotkey} was pressed`)\n * handleSave()\n * })\n *\n * document.addEventListener('keydown', handler)\n * ```\n */\nexport function createHotkeyHandler(\n hotkey: Hotkey | ParsedHotkey,\n callback: HotkeyCallback,\n options: CreateHotkeyHandlerOptions = {},\n): (event: KeyboardEvent) => void {\n const { preventDefault = true, stopPropagation = true, platform } = options\n const resolvedPlatform = platform ?? detectPlatform()\n\n const hotkeyString: Hotkey =\n typeof hotkey === 'string' ? hotkey : formatParsedHotkey(hotkey)\n const parsed =\n typeof hotkey === 'string' ? parseHotkey(hotkey, resolvedPlatform) : hotkey\n\n const context: HotkeyCallbackContext = {\n hotkey: hotkeyString,\n parsedHotkey: parsed,\n }\n\n return (event: KeyboardEvent) => {\n if (matchesKeyboardEvent(event, parsed, resolvedPlatform)) {\n if (preventDefault) {\n event.preventDefault()\n }\n if (stopPropagation) {\n event.stopPropagation()\n }\n callback(event, context)\n }\n }\n}\n\nexport type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback }\n\n/**\n * Creates a handler that matches multiple hotkeys.\n *\n * @param handlers - A map of hotkey strings to their handlers\n * @param options - Options for matching and handling\n * @returns A function that can be used as an event handler\n *\n * @example\n * ```ts\n * const handler = createMultiHotkeyHandler({\n * 'Mod+S': (event, { hotkey }) => handleSave(),\n * 'Mod+Z': (event, { hotkey }) => handleUndo(),\n * 'Mod+Shift+Z': (event, { hotkey }) => handleRedo(),\n * })\n *\n * document.addEventListener('keydown', handler)\n * ```\n */\nexport function createMultiHotkeyHandler(\n handlers: MultiHotkeyHandler,\n options: CreateHotkeyHandlerOptions = {},\n): (event: KeyboardEvent) => void {\n const { preventDefault = true, stopPropagation = true, platform } = options\n const resolvedPlatform = platform ?? detectPlatform()\n\n // Pre-parse all hotkeys for efficiency\n const parsedHandlers = Object.entries(handlers)\n .filter((entry): entry is [string, HotkeyCallback] => Boolean(entry[1]))\n .map(([hotkey, handler]) => {\n const parsed = parseHotkey(hotkey as Hotkey, resolvedPlatform)\n const context: HotkeyCallbackContext = {\n hotkey: hotkey as Hotkey,\n parsedHotkey: parsed,\n }\n return { parsed, handler, context }\n })\n\n return (event: KeyboardEvent) => {\n for (const { parsed, handler, context } of parsedHandlers) {\n if (matchesKeyboardEvent(event, parsed, resolvedPlatform)) {\n if (preventDefault) {\n event.preventDefault()\n }\n if (stopPropagation) {\n event.stopPropagation()\n }\n handler(event, context)\n return // Only handle the first match\n }\n }\n }\n}\n\n/**\n * Formats a ParsedHotkey back to a hotkey string.\n * Used internally to provide the hotkey string in callback context.\n */\nfunction formatParsedHotkey(parsed: ParsedHotkey): Hotkey {\n const parts: Array<string> = []\n\n if (parsed.ctrl) parts.push('Control')\n if (parsed.alt) parts.push('Alt')\n if (parsed.shift) parts.push('Shift')\n if (parsed.meta) parts.push('Meta')\n parts.push(parsed.code !== undefined ? `[${parsed.code}]` : parsed.key)\n\n return parts.join('+') as Hotkey\n}\n\n/**\n * Compares normalized binding identity, including all four modifiers.\n * Aliases resolve on the supplied platform. A physical code and a logical key\n * remain distinct even when one keyboard event could match both.\n */\nexport function areHotkeysEqual(\n left: RegisterableHotkey,\n right: RegisterableHotkey,\n platform = detectPlatform(),\n): boolean {\n const a = parseRegisterableHotkey(left, platform)\n const b = parseRegisterableHotkey(right, platform)\n return (\n a.ctrl === b.ctrl &&\n a.alt === b.alt &&\n a.shift === b.shift &&\n a.meta === b.meta &&\n (a.code !== undefined || b.code !== undefined\n ? a.code === b.code\n : keysEqual(a.key, b.key))\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,qBACd,OACA,QACA,WAAwCA,iCAAgB,EAC/C;AACT,QAAOC,kCAAmB,OAAO,QAAQ,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;AAiCrD,SAAgB,oBACd,QACA,UACA,UAAsC,EAAE,EACR;CAChC,MAAM,EAAE,iBAAiB,MAAM,kBAAkB,MAAM,aAAa;CACpE,MAAM,mBAAmB,YAAYD,iCAAgB;CAErD,MAAM,eACJ,OAAO,WAAW,WAAW,SAAS,mBAAmB,OAAO;CAClE,MAAM,SACJ,OAAO,WAAW,WAAWE,0BAAY,QAAQ,iBAAiB,GAAG;CAEvE,MAAM,UAAiC;EACrC,QAAQ;EACR,cAAc;EACf;AAED,SAAQ,UAAyB;AAC/B,MAAI,qBAAqB,OAAO,QAAQ,iBAAiB,EAAE;AACzD,OAAI,eACF,OAAM,gBAAgB;AAExB,OAAI,gBACF,OAAM,iBAAiB;AAEzB,YAAS,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;AAyB9B,SAAgB,yBACd,UACA,UAAsC,EAAE,EACR;CAChC,MAAM,EAAE,iBAAiB,MAAM,kBAAkB,MAAM,aAAa;CACpE,MAAM,mBAAmB,YAAYF,iCAAgB;CAGrD,MAAM,iBAAiB,OAAO,QAAQ,SAAS,CAC5C,QAAQ,UAA6C,QAAQ,MAAM,GAAG,CAAC,CACvE,KAAK,CAAC,QAAQ,aAAa;EAC1B,MAAM,SAASE,0BAAY,QAAkB,iBAAiB;AAK9D,SAAO;GAAE;GAAQ;GAAS,SAJa;IAC7B;IACR,cAAc;IACf;GACkC;GACnC;AAEJ,SAAQ,UAAyB;AAC/B,OAAK,MAAM,EAAE,QAAQ,SAAS,aAAa,eACzC,KAAI,qBAAqB,OAAO,QAAQ,iBAAiB,EAAE;AACzD,OAAI,eACF,OAAM,gBAAgB;AAExB,OAAI,gBACF,OAAM,iBAAiB;AAEzB,WAAQ,OAAO,QAAQ;AACvB;;;;;;;;AAUR,SAAS,mBAAmB,QAA8B;CACxD,MAAM,QAAuB,EAAE;AAE/B,KAAI,OAAO,KAAM,OAAM,KAAK,UAAU;AACtC,KAAI,OAAO,IAAK,OAAM,KAAK,MAAM;AACjC,KAAI,OAAO,MAAO,OAAM,KAAK,QAAQ;AACrC,KAAI,OAAO,KAAM,OAAM,KAAK,OAAO;AACnC,OAAM,KAAK,OAAO,SAAS,SAAY,IAAI,OAAO,KAAK,KAAK,OAAO,IAAI;AAEvE,QAAO,MAAM,KAAK,IAAI;;;;;;;AAQxB,SAAgB,gBACd,MACA,OACA,WAAWF,iCAAgB,EAClB;CACT,MAAM,IAAIG,sCAAwB,MAAM,SAAS;CACjD,MAAM,IAAIA,sCAAwB,OAAO,SAAS;AAClD,QACE,EAAE,SAAS,EAAE,QACb,EAAE,QAAQ,EAAE,OACZ,EAAE,UAAU,EAAE,SACd,EAAE,SAAS,EAAE,SACZ,EAAE,SAAS,UAAa,EAAE,SAAS,SAChC,EAAE,SAAS,EAAE,OACbC,kCAAU,EAAE,KAAK,EAAE,IAAI"}
|
package/dist/match.d.cts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { Hotkey, HotkeyCallback, ParsedHotkey } from "./hotkey.cjs";
|
|
1
|
+
import { Hotkey, HotkeyCallback, ParsedHotkey, RegisterableHotkey } from "./hotkey.types.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/match.d.ts
|
|
4
|
+
interface KeyboardEventMatch {
|
|
5
|
+
matched: boolean;
|
|
6
|
+
score: 0 | 1 | 2 | 3;
|
|
7
|
+
source?: 'key' | 'code' | 'fallback';
|
|
8
|
+
identity?: {
|
|
9
|
+
key: string;
|
|
10
|
+
code: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* Checks if a KeyboardEvent matches a hotkey.
|
|
6
15
|
*
|
|
7
|
-
*
|
|
16
|
+
* Physical bindings such as `Mod+[KeyS]` match `event.code` exactly.
|
|
17
|
+
* Logical bindings use `event.key`, with a fallback to `code`
|
|
8
18
|
* for letter keys, digit keys (0-9), and punctuation keys when `key` produces special
|
|
9
19
|
* characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).
|
|
10
20
|
* Letter keys are matched case-insensitively.
|
|
@@ -80,6 +90,12 @@ type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback };
|
|
|
80
90
|
* ```
|
|
81
91
|
*/
|
|
82
92
|
declare function createMultiHotkeyHandler(handlers: MultiHotkeyHandler, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Compares normalized binding identity, including all four modifiers.
|
|
95
|
+
* Aliases resolve on the supplied platform. A physical code and a logical key
|
|
96
|
+
* remain distinct even when one keyboard event could match both.
|
|
97
|
+
*/
|
|
98
|
+
declare function areHotkeysEqual(left: RegisterableHotkey, right: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): boolean;
|
|
83
99
|
//#endregion
|
|
84
|
-
export { CreateHotkeyHandlerOptions, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
100
|
+
export { CreateHotkeyHandlerOptions, KeyboardEventMatch, MultiHotkeyHandler, areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
85
101
|
//# sourceMappingURL=match.d.cts.map
|
package/dist/match.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { Hotkey, HotkeyCallback, ParsedHotkey } from "./hotkey.js";
|
|
1
|
+
import { Hotkey, HotkeyCallback, ParsedHotkey, RegisterableHotkey } from "./hotkey.types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/match.d.ts
|
|
4
|
+
interface KeyboardEventMatch {
|
|
5
|
+
matched: boolean;
|
|
6
|
+
score: 0 | 1 | 2 | 3;
|
|
7
|
+
source?: 'key' | 'code' | 'fallback';
|
|
8
|
+
identity?: {
|
|
9
|
+
key: string;
|
|
10
|
+
code: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* Checks if a KeyboardEvent matches a hotkey.
|
|
6
15
|
*
|
|
7
|
-
*
|
|
16
|
+
* Physical bindings such as `Mod+[KeyS]` match `event.code` exactly.
|
|
17
|
+
* Logical bindings use `event.key`, with a fallback to `code`
|
|
8
18
|
* for letter keys, digit keys (0-9), and punctuation keys when `key` produces special
|
|
9
19
|
* characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).
|
|
10
20
|
* Letter keys are matched case-insensitively.
|
|
@@ -80,6 +90,12 @@ type MultiHotkeyHandler = { [K in Hotkey]?: HotkeyCallback };
|
|
|
80
90
|
* ```
|
|
81
91
|
*/
|
|
82
92
|
declare function createMultiHotkeyHandler(handlers: MultiHotkeyHandler, options?: CreateHotkeyHandlerOptions): (event: KeyboardEvent) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Compares normalized binding identity, including all four modifiers.
|
|
95
|
+
* Aliases resolve on the supplied platform. A physical code and a logical key
|
|
96
|
+
* remain distinct even when one keyboard event could match both.
|
|
97
|
+
*/
|
|
98
|
+
declare function areHotkeysEqual(left: RegisterableHotkey, right: RegisterableHotkey, platform?: "mac" | "windows" | "linux"): boolean;
|
|
83
99
|
//#endregion
|
|
84
|
-
export { CreateHotkeyHandlerOptions, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
100
|
+
export { CreateHotkeyHandlerOptions, KeyboardEventMatch, MultiHotkeyHandler, areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
85
101
|
//# sourceMappingURL=match.d.ts.map
|
package/dist/match.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { detectPlatform } from "./platform.js";
|
|
2
|
+
import { keysEqual } from "./_keyboard-event.js";
|
|
3
|
+
import { parseHotkey, parseRegisterableHotkey } from "./parse.js";
|
|
4
|
+
import { matchKeyboardEvent } from "./_match.js";
|
|
3
5
|
|
|
4
6
|
//#region src/match.ts
|
|
5
7
|
/**
|
|
6
8
|
* Checks if a KeyboardEvent matches a hotkey.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* Physical bindings such as `Mod+[KeyS]` match `event.code` exactly.
|
|
11
|
+
* Logical bindings use `event.key`, with a fallback to `code`
|
|
9
12
|
* for letter keys, digit keys (0-9), and punctuation keys when `key` produces special
|
|
10
13
|
* characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).
|
|
11
14
|
* Letter keys are matched case-insensitively.
|
|
@@ -31,30 +34,7 @@ import { parseHotkey } from "./parse.js";
|
|
|
31
34
|
* ```
|
|
32
35
|
*/
|
|
33
36
|
function matchesKeyboardEvent(event, hotkey, platform = detectPlatform()) {
|
|
34
|
-
|
|
35
|
-
if (event.ctrlKey !== parsed.ctrl) return false;
|
|
36
|
-
if (event.shiftKey !== parsed.shift) return false;
|
|
37
|
-
if (event.altKey !== parsed.alt) return false;
|
|
38
|
-
if (event.metaKey !== parsed.meta) return false;
|
|
39
|
-
const eventKey = normalizeKeyName(event.key);
|
|
40
|
-
const hotkeyKey = parsed.key;
|
|
41
|
-
if (eventKey !== "Dead" && eventKey.length === 1 && hotkeyKey.length === 1) {
|
|
42
|
-
if (eventKey.toUpperCase() === hotkeyKey.toUpperCase()) return true;
|
|
43
|
-
if (isSingleLetterKey(eventKey) && (/^[A-Za-z]$/.test(eventKey) || !event.altKey)) return false;
|
|
44
|
-
}
|
|
45
|
-
if (event.code && (eventKey === "Dead" || eventKey.length === 1 && hotkeyKey.length === 1)) {
|
|
46
|
-
if (event.code.startsWith("Key")) {
|
|
47
|
-
const codeLetter = event.code.slice(3);
|
|
48
|
-
if (codeLetter.length === 1 && /^[A-Za-z]$/.test(codeLetter)) return codeLetter.toUpperCase() === hotkeyKey.toUpperCase();
|
|
49
|
-
}
|
|
50
|
-
if (event.code.startsWith("Digit")) {
|
|
51
|
-
const codeDigit = event.code.slice(5);
|
|
52
|
-
if (codeDigit.length === 1 && /^[0-9]$/.test(codeDigit)) return codeDigit === hotkeyKey;
|
|
53
|
-
}
|
|
54
|
-
if (event.code in PUNCTUATION_CODE_MAP) return PUNCTUATION_CODE_MAP[event.code] === hotkeyKey;
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return eventKey === hotkeyKey;
|
|
37
|
+
return matchKeyboardEvent(event, hotkey, platform).matched;
|
|
58
38
|
}
|
|
59
39
|
/**
|
|
60
40
|
* Creates a keyboard event handler that calls the callback when the hotkey matches.
|
|
@@ -142,10 +122,20 @@ function formatParsedHotkey(parsed) {
|
|
|
142
122
|
if (parsed.alt) parts.push("Alt");
|
|
143
123
|
if (parsed.shift) parts.push("Shift");
|
|
144
124
|
if (parsed.meta) parts.push("Meta");
|
|
145
|
-
parts.push(parsed.key);
|
|
125
|
+
parts.push(parsed.code !== void 0 ? `[${parsed.code}]` : parsed.key);
|
|
146
126
|
return parts.join("+");
|
|
147
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Compares normalized binding identity, including all four modifiers.
|
|
130
|
+
* Aliases resolve on the supplied platform. A physical code and a logical key
|
|
131
|
+
* remain distinct even when one keyboard event could match both.
|
|
132
|
+
*/
|
|
133
|
+
function areHotkeysEqual(left, right, platform = detectPlatform()) {
|
|
134
|
+
const a = parseRegisterableHotkey(left, platform);
|
|
135
|
+
const b = parseRegisterableHotkey(right, platform);
|
|
136
|
+
return a.ctrl === b.ctrl && a.alt === b.alt && a.shift === b.shift && a.meta === b.meta && (a.code !== void 0 || b.code !== void 0 ? a.code === b.code : keysEqual(a.key, b.key));
|
|
137
|
+
}
|
|
148
138
|
|
|
149
139
|
//#endregion
|
|
150
|
-
export { createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
140
|
+
export { areHotkeysEqual, createHotkeyHandler, createMultiHotkeyHandler, matchesKeyboardEvent };
|
|
151
141
|
//# sourceMappingURL=match.js.map
|