@tanstack/hotkeys 0.24.0 → 0.25.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/dist/_app-hotkeys-factory.d.ts +1 -3
- package/dist/_app-hotkeys-factory.js +2 -3
- package/dist/_event-target.js +25 -15
- package/dist/_keyboard-event.js +8 -5
- package/dist/_manager-ref.js +1 -2
- package/dist/_match.js +5 -3
- package/dist/_named-keys.d.ts +1 -3
- package/dist/_named-keys.js +1 -2
- package/dist/_recorder-chord.js +7 -13
- package/dist/_recording-guard.js +1 -2
- package/dist/_registration.d.ts +1 -3
- package/dist/_registration.js +11 -6
- package/dist/_server.js +2 -3
- package/dist/_store.d.ts +1 -3
- package/dist/_store.js +1 -2
- package/dist/_target-listeners.js +1 -2
- package/dist/adapter.d.ts +3 -5
- package/dist/adapter.js +2 -3
- package/dist/app-hotkeys.d.ts +4 -5
- package/dist/app-hotkeys.js +10 -21
- package/dist/conflicts.d.ts +2 -4
- package/dist/conflicts.js +5 -6
- package/dist/constants.d.ts +2 -4
- package/dist/constants.js +1 -2
- package/dist/display-labels.d.ts +1 -3
- package/dist/display-labels.js +1 -2
- package/dist/format.d.ts +2 -4
- package/dist/format.js +4 -5
- package/dist/hint.d.ts +1 -3
- package/dist/hint.js +1 -2
- package/dist/hotkey-manager.d.ts +1 -3
- package/dist/hotkey-manager.js +12 -13
- package/dist/hotkey-recorder.d.ts +19 -7
- package/dist/hotkey-recorder.js +8 -11
- package/dist/hotkey.types.d.ts +1 -3
- package/dist/index.d.ts +8 -8
- package/dist/index.js +3 -3
- package/dist/key-state-tracker.d.ts +1 -3
- package/dist/key-state-tracker.js +2 -3
- package/dist/key.types.d.ts +5 -6
- package/dist/match.d.ts +4 -5
- package/dist/match.js +7 -7
- package/dist/parse.d.ts +2 -3
- package/dist/parse.js +10 -19
- package/dist/platform.d.ts +1 -3
- package/dist/platform.js +1 -2
- package/dist/validate.d.ts +33 -13
- package/dist/validate.js +51 -34
- package/dist/vendor/@tanstack/store/dist/store.d.ts +0 -2
- package/dist/vendor/@tanstack/store/dist/types.d.ts +0 -2
- package/package.json +4 -4
- package/skills/app-hotkeys/SKILL.md +1 -1
- package/skills/hotkeys-core/SKILL.md +1 -1
package/dist/format.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CanonicalModifier } from "./key.types.js";
|
|
2
1
|
import { ParsedHotkeyChord, RegisterableHotkeyChord } from "./hotkey.types.js";
|
|
3
|
-
|
|
2
|
+
import { CanonicalModifier } from "./key.types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Converts a parsed hotkey back to a string, with each platform modifier
|
|
6
5
|
* spelled out, such as `Control+Shift+S`. A parsed chord returns a string, and
|
|
@@ -105,5 +104,4 @@ export interface FormatDisplayOptions {
|
|
|
105
104
|
separatorToken?: string | null;
|
|
106
105
|
/** Separator between sequence steps. Default: a space. */
|
|
107
106
|
sequenceSeparator?: string;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
107
|
+
}
|
package/dist/format.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { assertLogicalKey, codeToLogicalKey, modifierAlias, physicalCodeOf, splitChordParts } from "./_keyboard-event.js";
|
|
2
|
+
import { warnServerPlatform } from "./_server.js";
|
|
1
3
|
import { MODIFIER_ORDER, normalizeKeyName } from "./constants.js";
|
|
2
4
|
import { KEY_DISPLAY_SYMBOLS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS } from "./display-labels.js";
|
|
3
|
-
import { warnServerPlatform } from "./_server.js";
|
|
4
|
-
import { detectPlatform } from "./platform.js";
|
|
5
|
-
import { assertLogicalKey, codeToLogicalKey, modifierAlias, physicalCodeOf, splitChordParts } from "./_keyboard-event.js";
|
|
6
5
|
import { normalizeHotkey } from "./parse.js";
|
|
6
|
+
import { detectPlatform } from "./platform.js";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// src/format.ts
|
|
9
9
|
function formatHotkey(parsed) {
|
|
10
10
|
return Array.isArray(parsed) ? parsed.map((step) => formatParsedChord(step)) : formatParsedChord(parsed);
|
|
11
11
|
}
|
|
@@ -72,5 +72,4 @@ function formatKey(segment, platform, modifierSymbols, keySymbols, options) {
|
|
|
72
72
|
return numpad ? `Numpad ${display.replace(/([a-z])([A-Z])/g, "$1 $2")}` : display;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
//#endregion
|
|
76
75
|
export { formatForDisplay, formatHotkey };
|
package/dist/hint.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RegisterableHotkey } from "./hotkey.types.js";
|
|
2
|
-
//#region src/hint.d.ts
|
|
3
2
|
export interface HeldModifierOptions {
|
|
4
3
|
/** Resolve Mod for this platform. Defaults to platform detection. */
|
|
5
4
|
platform?: 'mac' | 'windows' | 'linux';
|
|
@@ -18,5 +17,4 @@ export interface HeldModifierOptions {
|
|
|
18
17
|
* matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt']) // true
|
|
19
18
|
* matchesHeldModifiers('Alt+Shift+[KeyK]', ['Alt', 'Control']) // false
|
|
20
19
|
*/
|
|
21
|
-
export declare function matchesHeldModifiers(hotkey: RegisterableHotkey | null | undefined, heldKeys: ReadonlyArray<string>, options?: HeldModifierOptions): boolean;
|
|
22
|
-
//#endregion
|
|
20
|
+
export declare function matchesHeldModifiers(hotkey: RegisterableHotkey | null | undefined, heldKeys: ReadonlyArray<string>, options?: HeldModifierOptions): boolean;
|
package/dist/hint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MODIFIER_KEYS, normalizeKeyName } from "./constants.js";
|
|
2
2
|
import { isHotkeySequence, parseHotkey } from "./parse.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/hint.ts
|
|
5
5
|
/**
|
|
6
6
|
* Returns whether held modifiers should reveal a shortcut hint.
|
|
7
7
|
* By default, any nonempty subset of the binding's modifiers qualifies; an
|
|
@@ -24,5 +24,4 @@ function matchesHeldModifiers(hotkey, heldKeys, options = {}) {
|
|
|
24
24
|
return held.length > 0 && held.every((key) => modifiers.includes(key)) && (!options.exact || held.length === modifiers.length);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//#endregion
|
|
28
27
|
export { matchesHeldModifiers };
|
package/dist/hotkey-manager.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Store } from "./_store.js";
|
|
2
|
-
import { ConflictBehavior, HotkeyCallback, HotkeyCallbackContextFor, HotkeyChord, HotkeyMeta, HotkeySequence, ParsedHotkeyChord, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence } from "./hotkey.types.js";
|
|
3
2
|
import { AppHotkey, AppHotkeysStore } from "./app-hotkeys.js";
|
|
4
|
-
|
|
3
|
+
import { ConflictBehavior, HotkeyCallback, HotkeyCallbackContextFor, HotkeyChord, HotkeyMeta, HotkeySequence, ParsedHotkeyChord, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence } from "./hotkey.types.js";
|
|
5
4
|
/** An element, document, or window that hotkeys can listen on. */
|
|
6
5
|
export type Target = HTMLElement | Document | Window;
|
|
7
6
|
/**
|
|
@@ -421,5 +420,4 @@ export declare class HotkeyManager {
|
|
|
421
420
|
* Convenience function for accessing the manager.
|
|
422
421
|
*/
|
|
423
422
|
export declare function getHotkeyManager(): HotkeyManager;
|
|
424
|
-
//#endregion
|
|
425
423
|
export type { ConflictBehavior };
|
package/dist/hotkey-manager.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { detectPlatform } from "./platform.js";
|
|
1
|
+
import { closesNativeLayer, getTargetDocument, isDocumentLevel, shouldIgnoreInputEvent, targetHasFocus } from "./_event-target.js";
|
|
3
2
|
import { isKeyNameShape, keysEqual, normalizeKeyboardEvent } from "./_keyboard-event.js";
|
|
4
|
-
import {
|
|
5
|
-
import { formatHotkey } from "./format.js";
|
|
3
|
+
import { managerRef } from "./_manager-ref.js";
|
|
6
4
|
import { matchKeyboardEvent, parsedChordsEqual } from "./_match.js";
|
|
5
|
+
import { isRecordingEvent } from "./_recording-guard.js";
|
|
7
6
|
import { GLOBAL_SCOPE, chordHasKey, defaultHotkeyOptions, definedOptions, getDefaultIgnoreInputs, handleConflict, optionsEqual } from "./_registration.js";
|
|
8
|
-
import { DEFAULT_SEQUENCE_TIMEOUT, areHotkeysEqual } from "./match.js";
|
|
9
|
-
import { closesNativeLayer, getTargetDocument, isDocumentLevel, shouldIgnoreInputEvent, targetHasFocus } from "./_event-target.js";
|
|
10
7
|
import { createStore } from "./_store.js";
|
|
11
8
|
import { TargetListeners } from "./_target-listeners.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
9
|
+
import { normalizeKeyName } from "./constants.js";
|
|
10
|
+
import { formatHotkey } from "./format.js";
|
|
11
|
+
import { DEFAULT_SEQUENCE_TIMEOUT, areHotkeysEqual } from "./match.js";
|
|
12
|
+
import { isHotkeySequence, isModifierKey, parseHotkey, simplifyHotkey } from "./parse.js";
|
|
13
|
+
import { detectPlatform } from "./platform.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// src/hotkey-manager.ts
|
|
16
16
|
/** Whether a registration can fire now. Without a manager, scopes don't apply. */
|
|
17
17
|
function getRegistrationStatus(options, manager) {
|
|
18
18
|
if (options.enabled === false) return "disabled";
|
|
@@ -248,7 +248,7 @@ var HotkeyManager = class HotkeyManager {
|
|
|
248
248
|
if (scope === "global") return () => {};
|
|
249
249
|
const { exclusive } = options;
|
|
250
250
|
const allow = exclusive ? exclusive === true ? [] : exclusive.allow : null;
|
|
251
|
-
if (process.env.NODE_ENV !== "production" && allow && [...this.#scopeActivations].some((other) => other.allow && other.scope === scope)) console.warn(`Exclusive
|
|
251
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && allow && [...this.#scopeActivations].some((other) => other.allow && other.scope === scope)) console.warn(`[hotkeys] Exclusive scope '${scope}' is already active`);
|
|
252
252
|
const activation = {
|
|
253
253
|
scope,
|
|
254
254
|
parent: options.parent ?? "global",
|
|
@@ -391,8 +391,8 @@ var HotkeyManager = class HotkeyManager {
|
|
|
391
391
|
}
|
|
392
392
|
const steps = registration.kind === "sequence" ? registration.parsedSequence : [registration.parsedChord];
|
|
393
393
|
if (!steps.every(chordHasKey)) return inactiveHandle(callback);
|
|
394
|
-
if (process.env.NODE_ENV !== "production") {
|
|
395
|
-
for (const { key } of steps) if (key !== void 0 && !isKeyNameShape(key)) console.warn(`Unknown key '${key}' in '${formatForMessage(registration.hotkey)}'
|
|
394
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
395
|
+
for (const { key } of steps) if (key !== void 0 && !isKeyNameShape(key)) console.warn(`[hotkeys] Unknown key '${key}' in '${formatForMessage(registration.hotkey)}' (names are case-sensitive)`);
|
|
396
396
|
}
|
|
397
397
|
const conflicting = this.#findConflictingRegistration(registration);
|
|
398
398
|
if (conflicting) handleConflict(conflicting.id, formatForMessage(registration.hotkey), options.conflictBehavior ?? "warn", (conflictId) => this.#unregister(conflictId));
|
|
@@ -840,5 +840,4 @@ function getHotkeyManager() {
|
|
|
840
840
|
return HotkeyManager.getInstance();
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
-
//#endregion
|
|
844
843
|
export { HotkeyManager, getHotkeyManager, toHotkeyRegistrationView };
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { Store } from "./_store.js";
|
|
2
|
-
import { Hotkey, HotkeyChord, HotkeySequence, ParsedHotkeyChord } from "./hotkey.types.js";
|
|
3
2
|
import { HotkeyConflict, HotkeyConflictOptions } from "./conflicts.js";
|
|
4
|
-
|
|
3
|
+
import { Hotkey, HotkeyChord, HotkeySequence, ParsedHotkeyChord } from "./hotkey.types.js";
|
|
5
4
|
/** Event property used to record a binding. Physical codes are the default. */
|
|
6
5
|
export type RecorderKeyMode = 'code' | 'key';
|
|
6
|
+
/**
|
|
7
|
+
* Why the recorder rejected a key press or a recording:
|
|
8
|
+
*
|
|
9
|
+
* - `'alt-graph'`: AltGr typed a character, which physical recording can't
|
|
10
|
+
* record. Record by key to accept characters.
|
|
11
|
+
* - `'missing-code'`: the event has no usable physical key code.
|
|
12
|
+
* - `'whitespace'`: the key is a whitespace character, which a hotkey can't
|
|
13
|
+
* hold.
|
|
14
|
+
* - `'validation'`: your `validate` callback rejected the recording.
|
|
15
|
+
* - `'conflict'`: the recording conflicts with registered hotkeys.
|
|
16
|
+
*/
|
|
17
|
+
export type RecorderRejectionReason = 'alt-graph' | 'missing-code' | 'whitespace' | 'validation' | 'conflict';
|
|
7
18
|
export interface RecorderRejection {
|
|
8
|
-
reason:
|
|
9
|
-
message
|
|
19
|
+
reason: RecorderRejectionReason;
|
|
20
|
+
/** The message your `validate` callback returned, when it returned one. */
|
|
21
|
+
message?: string;
|
|
10
22
|
/** The rejected chord or sequence, when one was recorded. */
|
|
11
23
|
hotkey?: Hotkey;
|
|
12
24
|
conflicts?: Array<HotkeyConflict>;
|
|
@@ -74,7 +86,7 @@ interface HotkeyRecorderBaseOptions extends RecorderOptions {
|
|
|
74
86
|
export interface HotkeyChordRecorderOptions extends HotkeyRecorderBaseOptions {
|
|
75
87
|
/** Maximum number of chords to record. Default: 1 */
|
|
76
88
|
maxSteps?: 1;
|
|
77
|
-
/** Return true to accept, or false
|
|
89
|
+
/** Return true to accept, or false or a message to reject while staying in recording mode. The message is passed to `onReject`. */
|
|
78
90
|
validate?: (hotkey: HotkeyChord, context: HotkeyChordRecorderValidationContext) => boolean | string;
|
|
79
91
|
/** Callback when a chord is successfully recorded */
|
|
80
92
|
onRecord: (hotkey: HotkeyChord) => void;
|
|
@@ -86,7 +98,7 @@ export interface HotkeyChordRecorderOptions extends HotkeyRecorderBaseOptions {
|
|
|
86
98
|
export interface HotkeySequenceRecorderOptions extends HotkeyRecorderBaseOptions {
|
|
87
99
|
/** Maximum number of chords to record. Reaching it commits automatically. Use `Infinity` for no limit. */
|
|
88
100
|
maxSteps: number;
|
|
89
|
-
/** Return true to accept, or false
|
|
101
|
+
/** Return true to accept, or false or a message to reject while staying in recording mode. The message is passed to `onReject`. */
|
|
90
102
|
validate?: (hotkey: Hotkey, context: HotkeyRecorderValidationContext) => boolean | string;
|
|
91
103
|
/** Callback when a hotkey is successfully recorded */
|
|
92
104
|
onRecord: (hotkey: Hotkey) => void;
|
|
@@ -178,4 +190,4 @@ export declare class HotkeyRecorder {
|
|
|
178
190
|
*/
|
|
179
191
|
destroy(): void;
|
|
180
192
|
}
|
|
181
|
-
|
|
193
|
+
export {};
|
package/dist/hotkey-recorder.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { detectPlatform } from "./platform.js";
|
|
2
|
-
import { normalizeKeyboardEvent, splitChordParts } from "./_keyboard-event.js";
|
|
3
|
-
import { isModifierKey, parseHotkey, simplifyHotkey } from "./parse.js";
|
|
4
1
|
import { isTypingEvent } from "./_event-target.js";
|
|
5
|
-
import {
|
|
2
|
+
import { normalizeKeyboardEvent, splitChordParts } from "./_keyboard-event.js";
|
|
3
|
+
import { chordRejection, hotkeyChordFromKeydown } from "./_recorder-chord.js";
|
|
6
4
|
import { beginRecording, captureRecordingEvent, endRecording } from "./_recording-guard.js";
|
|
5
|
+
import { createStore } from "./_store.js";
|
|
7
6
|
import { findHotkeyConflicts } from "./conflicts.js";
|
|
8
|
-
import {
|
|
7
|
+
import { isModifierKey, parseHotkey, simplifyHotkey } from "./parse.js";
|
|
8
|
+
import { detectPlatform } from "./platform.js";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// src/hotkey-recorder.ts
|
|
11
11
|
const initialState = {
|
|
12
12
|
isRecording: false,
|
|
13
13
|
steps: [],
|
|
@@ -157,8 +157,7 @@ var HotkeyRecorder = class {
|
|
|
157
157
|
if (chord === null) return;
|
|
158
158
|
if (splitChordParts(chord).some((part) => !part.trim())) {
|
|
159
159
|
options.onReject?.({
|
|
160
|
-
reason: "
|
|
161
|
-
message: "Whitespace keys cannot be recorded",
|
|
160
|
+
reason: "whitespace",
|
|
162
161
|
hotkey: chord
|
|
163
162
|
});
|
|
164
163
|
return;
|
|
@@ -211,7 +210,7 @@ var HotkeyRecorder = class {
|
|
|
211
210
|
if (accepted !== void 0 && accepted !== true) {
|
|
212
211
|
rejectAndKeepRecording({
|
|
213
212
|
reason: "validation",
|
|
214
|
-
|
|
213
|
+
...typeof accepted === "string" && { message: accepted },
|
|
215
214
|
hotkey
|
|
216
215
|
});
|
|
217
216
|
return;
|
|
@@ -225,7 +224,6 @@ var HotkeyRecorder = class {
|
|
|
225
224
|
if (conflicts.length) {
|
|
226
225
|
rejectAndKeepRecording({
|
|
227
226
|
reason: "conflict",
|
|
228
|
-
message: `This ${single ? "shortcut" : "sequence"} conflicts with a registered hotkey.`,
|
|
229
227
|
hotkey,
|
|
230
228
|
conflicts
|
|
231
229
|
});
|
|
@@ -286,5 +284,4 @@ var HotkeyRecorder = class {
|
|
|
286
284
|
}
|
|
287
285
|
};
|
|
288
286
|
|
|
289
|
-
//#endregion
|
|
290
287
|
export { HotkeyRecorder };
|
package/dist/hotkey.types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CanonicalModifier, Key, LogicalKey } from "./key.types.js";
|
|
2
|
-
//#region src/hotkey.types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Single modifier + key combinations.
|
|
5
4
|
* Uses canonical modifiers (4) + Mod (1) = 5 modifiers.
|
|
@@ -269,5 +268,4 @@ export interface HotkeyMeta {
|
|
|
269
268
|
* - `'replace'` - Unregister the existing registration and register the new one
|
|
270
269
|
* - `'allow'` - Allow multiple registrations without warning
|
|
271
270
|
*/
|
|
272
|
-
export type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
|
|
273
|
-
//#endregion
|
|
271
|
+
export type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { CanonicalModifier, EditingKey, FunctionKey, IndividualKey, Key, LetterKey, LogicalKey, Modifier, NamedKey, NavigationKey, NonPunctuationKey, NormalizedKeyboardEvent, NumberKey, PhysicalKey, PhysicalKeyCode, PunctuationKey } from "./key.types.js";
|
|
2
|
-
import { ConflictBehavior, FourModifierHotkeyChord, Hotkey, HotkeyCallback, HotkeyCallbackContext, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordCallbackContext, HotkeyMeta, HotkeySequence, HotkeySequenceCallbackContext, ParsedHotkeyChord, ParsedModifiers, RawHotkeyChord, RawModifiers, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence, SingleModifierHotkeyChord, ThreeModifierHotkeyChord, TwoModifierHotkeyChord } from "./hotkey.types.js";
|
|
3
|
-
import { ActivateHotkeyScopeOptions, HotkeyChordOptions, HotkeyChordRegistration, HotkeyChordRegistrationView, HotkeyManager, HotkeyOptions, HotkeyOptionsFor, HotkeyRegistration, HotkeyRegistrationHandle, HotkeyRegistrationStatus, HotkeyRegistrationView, HotkeyScopesState, HotkeySequenceOptions, HotkeySequenceRegistration, HotkeySequenceRegistrationView, Target, getHotkeyManager, toHotkeyRegistrationView } from "./hotkey-manager.js";
|
|
4
|
-
import { AppHotkey, AppHotkeyChordOptions, AppHotkeyDefaultKind, AppHotkeyId, AppHotkeyInput, AppHotkeyListItem, AppHotkeyOptions, AppHotkeySequenceOptions, AppHotkeyStatus, AppHotkeys, AppHotkeysState, AppHotkeysStore, AppHotkeysStoreOptions, CustomHotkeys, DefinedAppHotkeys, Register, RegisteredAppHotkeys, defineAppHotkeys, getAppHotkeyRegistrationOptions, isAppHotkey, isCustomHotkey, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey } from "./app-hotkeys.js";
|
|
5
|
-
import { HotkeyPlatform, detectPlatform, resolveModifier } from "./platform.js";
|
|
6
1
|
import { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, LETTER_KEYS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, isSingleLetterKey, normalizeKeyName } from "./constants.js";
|
|
7
2
|
import { KEY_DISPLAY_SYMBOLS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS } from "./display-labels.js";
|
|
3
|
+
import { HotkeyPlatform, detectPlatform, resolveModifier } from "./platform.js";
|
|
4
|
+
import { CanonicalModifier, EditingKey, FunctionKey, IndividualKey, Key, LetterKey, LogicalKey, Modifier, NamedKey, NavigationKey, NonPunctuationKey, NormalizedKeyboardEvent, NumberKey, PhysicalKey, PhysicalKeyCode, PunctuationKey } from "./key.types.js";
|
|
5
|
+
import { ConflictBehavior, FourModifierHotkeyChord, Hotkey, HotkeyCallback, HotkeyCallbackContext, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordCallbackContext, HotkeyMeta, HotkeySequence, HotkeySequenceCallbackContext, ParsedHotkeyChord, ParsedModifiers, RawHotkeyChord, RawModifiers, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence, SingleModifierHotkeyChord, ThreeModifierHotkeyChord, TwoModifierHotkeyChord } from "./hotkey.types.js";
|
|
8
6
|
import { DisplayHotkey, DisplayHotkeyChord, FormatDisplayOptions, formatForDisplay, formatHotkey } from "./format.js";
|
|
9
7
|
import { hasNonModifierKey, isHotkeySequence, isModifierKey, normalizeHotkey, parseHotkey, parseKeyboardEvent, simplifyHotkey } from "./parse.js";
|
|
10
|
-
import { ValidatableHotkey, ValidationResult, assertValidHotkey, checkHotkey, validateHotkey } from "./validate.js";
|
|
8
|
+
import { HotkeyIssue, HotkeyIssueReason, ValidatableHotkey, ValidationResult, assertValidHotkey, checkHotkey, validateHotkey } from "./validate.js";
|
|
11
9
|
import { CreateHotkeyChordHandlerOptions, DEFAULT_SEQUENCE_TIMEOUT, KeyboardEventMatch, MultiHotkeyChordHandler, areHotkeysEqual, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, matchesKeyboardEvent } from "./match.js";
|
|
12
10
|
import { HeldModifierOptions, matchesHeldModifiers } from "./hint.js";
|
|
13
11
|
import { HotkeyConflict, HotkeyConflictOptions, findHotkeyConflicts } from "./conflicts.js";
|
|
12
|
+
import { ActivateHotkeyScopeOptions, HotkeyChordOptions, HotkeyChordRegistration, HotkeyChordRegistrationView, HotkeyManager, HotkeyOptions, HotkeyOptionsFor, HotkeyRegistration, HotkeyRegistrationHandle, HotkeyRegistrationStatus, HotkeyRegistrationView, HotkeyScopesState, HotkeySequenceOptions, HotkeySequenceRegistration, HotkeySequenceRegistrationView, Target, getHotkeyManager, toHotkeyRegistrationView } from "./hotkey-manager.js";
|
|
13
|
+
import { AppHotkey, AppHotkeyChordOptions, AppHotkeyDefaultKind, AppHotkeyId, AppHotkeyInput, AppHotkeyListItem, AppHotkeyOptions, AppHotkeySequenceOptions, AppHotkeyStatus, AppHotkeys, AppHotkeysState, AppHotkeysStore, AppHotkeysStoreOptions, CustomHotkeys, DefinedAppHotkeys, Register, RegisteredAppHotkeys, defineAppHotkeys, getAppHotkeyRegistrationOptions, isAppHotkey, isCustomHotkey, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey } from "./app-hotkeys.js";
|
|
14
14
|
import { KeyStateTracker, KeyStateTrackerState, getKeyStateTracker } from "./key-state-tracker.js";
|
|
15
|
-
import { HotkeyChordRecorderOptions, HotkeyChordRecorderValidationContext, HotkeyRecorder, HotkeyRecorderCommitKeys, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRecorderValidationContext, HotkeySequenceRecorderOptions, HotkeySequenceRecorderValidationContext, RecorderKeyMode, RecorderOptions, RecorderRejection } from "./hotkey-recorder.js";
|
|
15
|
+
import { HotkeyChordRecorderOptions, HotkeyChordRecorderValidationContext, HotkeyRecorder, HotkeyRecorderCommitKeys, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRecorderValidationContext, HotkeySequenceRecorderOptions, HotkeySequenceRecorderValidationContext, RecorderKeyMode, RecorderOptions, RecorderRejection, RecorderRejectionReason } from "./hotkey-recorder.js";
|
|
16
16
|
import { createAppHotkeysStore } from "./_app-hotkeys-factory.js";
|
|
17
|
-
export { ALL_KEYS, ActivateHotkeyScopeOptions, AppHotkey, AppHotkeyChordOptions, AppHotkeyDefaultKind, AppHotkeyId, AppHotkeyInput, AppHotkeyListItem, AppHotkeyOptions, AppHotkeySequenceOptions, AppHotkeyStatus, AppHotkeys, AppHotkeysState, AppHotkeysStore, AppHotkeysStoreOptions, CanonicalModifier, ConflictBehavior, CreateHotkeyChordHandlerOptions, CustomHotkeys, DEFAULT_SEQUENCE_TIMEOUT, DefinedAppHotkeys, DisplayHotkey, DisplayHotkeyChord, EDITING_KEYS, EditingKey, FUNCTION_KEYS, FormatDisplayOptions, FourModifierHotkeyChord, FunctionKey, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyCallbackContext, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordCallbackContext, HotkeyChordOptions, HotkeyChordRecorderOptions, HotkeyChordRecorderValidationContext, HotkeyChordRegistration, HotkeyChordRegistrationView, HotkeyConflict, HotkeyConflictOptions, HotkeyManager, HotkeyMeta, HotkeyOptions, HotkeyOptionsFor, HotkeyPlatform, HotkeyRecorder, HotkeyRecorderCommitKeys, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRecorderValidationContext, HotkeyRegistration, HotkeyRegistrationHandle, HotkeyRegistrationStatus, HotkeyRegistrationView, HotkeyScopesState, HotkeySequence, HotkeySequenceCallbackContext, HotkeySequenceOptions, HotkeySequenceRecorderOptions, HotkeySequenceRecorderValidationContext, HotkeySequenceRegistration, HotkeySequenceRegistrationView, IndividualKey, KEY_DISPLAY_SYMBOLS, Key, KeyStateTracker, KeyStateTrackerState, KeyboardEventMatch, LETTER_KEYS, LINUX_MODIFIER_LABELS, LetterKey, LogicalKey, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, Modifier, MultiHotkeyChordHandler, NAVIGATION_KEYS, NUMBER_KEYS, NamedKey, NavigationKey, NonPunctuationKey, NormalizedKeyboardEvent, NumberKey, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, PUNCTUATION_KEY_DISPLAY_LABELS, ParsedHotkeyChord, ParsedModifiers, PhysicalKey, PhysicalKeyCode, PunctuationKey, RawHotkeyChord, RawModifiers, RecorderKeyMode, RecorderOptions, RecorderRejection, Register, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence, RegisteredAppHotkeys, SingleModifierHotkeyChord, Target, ThreeModifierHotkeyChord, TwoModifierHotkeyChord, ValidatableHotkey, ValidationResult, WINDOWS_MODIFIER_LABELS, areHotkeysEqual, assertValidHotkey, checkHotkey, createAppHotkeysStore, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, defineAppHotkeys, detectPlatform, findHotkeyConflicts, formatForDisplay, formatHotkey, getAppHotkeyRegistrationOptions, getHotkeyManager, getKeyStateTracker, hasNonModifierKey, isAppHotkey, isCustomHotkey, isHotkeySequence, isModifierKey, isSingleLetterKey, matchesHeldModifiers, matchesKeyboardEvent, normalizeHotkey, normalizeKeyName, parseHotkey, parseKeyboardEvent, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey, resolveModifier, simplifyHotkey, toHotkeyRegistrationView, validateHotkey };
|
|
17
|
+
export { ALL_KEYS, ActivateHotkeyScopeOptions, AppHotkey, AppHotkeyChordOptions, AppHotkeyDefaultKind, AppHotkeyId, AppHotkeyInput, AppHotkeyListItem, AppHotkeyOptions, AppHotkeySequenceOptions, AppHotkeyStatus, AppHotkeys, AppHotkeysState, AppHotkeysStore, AppHotkeysStoreOptions, CanonicalModifier, ConflictBehavior, CreateHotkeyChordHandlerOptions, CustomHotkeys, DEFAULT_SEQUENCE_TIMEOUT, DefinedAppHotkeys, DisplayHotkey, DisplayHotkeyChord, EDITING_KEYS, EditingKey, FUNCTION_KEYS, FormatDisplayOptions, FourModifierHotkeyChord, FunctionKey, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyCallbackContext, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordCallbackContext, HotkeyChordOptions, HotkeyChordRecorderOptions, HotkeyChordRecorderValidationContext, HotkeyChordRegistration, HotkeyChordRegistrationView, HotkeyConflict, HotkeyConflictOptions, HotkeyIssue, HotkeyIssueReason, HotkeyManager, HotkeyMeta, HotkeyOptions, HotkeyOptionsFor, HotkeyPlatform, HotkeyRecorder, HotkeyRecorderCommitKeys, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRecorderValidationContext, HotkeyRegistration, HotkeyRegistrationHandle, HotkeyRegistrationStatus, HotkeyRegistrationView, HotkeyScopesState, HotkeySequence, HotkeySequenceCallbackContext, HotkeySequenceOptions, HotkeySequenceRecorderOptions, HotkeySequenceRecorderValidationContext, HotkeySequenceRegistration, HotkeySequenceRegistrationView, IndividualKey, KEY_DISPLAY_SYMBOLS, Key, KeyStateTracker, KeyStateTrackerState, KeyboardEventMatch, LETTER_KEYS, LINUX_MODIFIER_LABELS, LetterKey, LogicalKey, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, Modifier, MultiHotkeyChordHandler, NAVIGATION_KEYS, NUMBER_KEYS, NamedKey, NavigationKey, NonPunctuationKey, NormalizedKeyboardEvent, NumberKey, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, PUNCTUATION_KEY_DISPLAY_LABELS, ParsedHotkeyChord, ParsedModifiers, PhysicalKey, PhysicalKeyCode, PunctuationKey, RawHotkeyChord, RawModifiers, RecorderKeyMode, RecorderOptions, RecorderRejection, RecorderRejectionReason, Register, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence, RegisteredAppHotkeys, SingleModifierHotkeyChord, Target, ThreeModifierHotkeyChord, TwoModifierHotkeyChord, ValidatableHotkey, ValidationResult, WINDOWS_MODIFIER_LABELS, areHotkeysEqual, assertValidHotkey, checkHotkey, createAppHotkeysStore, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, defineAppHotkeys, detectPlatform, findHotkeyConflicts, formatForDisplay, formatHotkey, getAppHotkeyRegistrationOptions, getHotkeyManager, getKeyStateTracker, hasNonModifierKey, isAppHotkey, isCustomHotkey, isHotkeySequence, isModifierKey, isSingleLetterKey, matchesHeldModifiers, matchesKeyboardEvent, normalizeHotkey, normalizeKeyName, parseHotkey, parseKeyboardEvent, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey, resolveModifier, simplifyHotkey, toHotkeyRegistrationView, validateHotkey };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ALL_KEYS, EDITING_KEYS, FUNCTION_KEYS, LETTER_KEYS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, isSingleLetterKey, normalizeKeyName } from "./constants.js";
|
|
2
2
|
import { KEY_DISPLAY_SYMBOLS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS } from "./display-labels.js";
|
|
3
3
|
import { detectPlatform, resolveModifier } from "./platform.js";
|
|
4
|
-
import { hasNonModifierKey, isHotkeySequence, isModifierKey, normalizeHotkey, parseHotkey, parseKeyboardEvent, simplifyHotkey } from "./parse.js";
|
|
5
4
|
import { formatForDisplay, formatHotkey } from "./format.js";
|
|
5
|
+
import { hasNonModifierKey, isHotkeySequence, isModifierKey, normalizeHotkey, parseHotkey, parseKeyboardEvent, simplifyHotkey } from "./parse.js";
|
|
6
6
|
import { assertValidHotkey, checkHotkey, validateHotkey } from "./validate.js";
|
|
7
7
|
import { DEFAULT_SEQUENCE_TIMEOUT, areHotkeysEqual, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, matchesKeyboardEvent } from "./match.js";
|
|
8
8
|
import { matchesHeldModifiers } from "./hint.js";
|
|
9
|
-
import { HotkeyManager, getHotkeyManager, toHotkeyRegistrationView } from "./hotkey-manager.js";
|
|
10
9
|
import { findHotkeyConflicts } from "./conflicts.js";
|
|
11
|
-
import {
|
|
10
|
+
import { HotkeyManager, getHotkeyManager, toHotkeyRegistrationView } from "./hotkey-manager.js";
|
|
12
11
|
import { AppHotkeysStore, defineAppHotkeys, getAppHotkeyRegistrationOptions, isAppHotkey, isCustomHotkey, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey } from "./app-hotkeys.js";
|
|
13
12
|
import { KeyStateTracker, getKeyStateTracker } from "./key-state-tracker.js";
|
|
14
13
|
import { HotkeyRecorder } from "./hotkey-recorder.js";
|
|
14
|
+
import { createAppHotkeysStore } from "./_app-hotkeys-factory.js";
|
|
15
15
|
|
|
16
16
|
export { ALL_KEYS, AppHotkeysStore, DEFAULT_SEQUENCE_TIMEOUT, EDITING_KEYS, FUNCTION_KEYS, HotkeyManager, HotkeyRecorder, KEY_DISPLAY_SYMBOLS, KeyStateTracker, LETTER_KEYS, LINUX_MODIFIER_LABELS, MAC_MODIFIER_LABELS, MAC_MODIFIER_SYMBOLS, MODIFIER_ALIASES, MODIFIER_KEYS, MODIFIER_ORDER, NAVIGATION_KEYS, NUMBER_KEYS, PUNCTUATION_CODE_MAP, PUNCTUATION_KEYS, PUNCTUATION_KEY_DISPLAY_LABELS, WINDOWS_MODIFIER_LABELS, areHotkeysEqual, assertValidHotkey, checkHotkey, createAppHotkeysStore, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, defineAppHotkeys, detectPlatform, findHotkeyConflicts, formatForDisplay, formatHotkey, getAppHotkeyRegistrationOptions, getHotkeyManager, getKeyStateTracker, hasNonModifierKey, isAppHotkey, isCustomHotkey, isHotkeySequence, isModifierKey, isSingleLetterKey, matchesHeldModifiers, matchesKeyboardEvent, normalizeHotkey, normalizeKeyName, parseHotkey, parseKeyboardEvent, provideAppHotkeys, publishAppHotkeysStore, resolveAppHotkey, resolveModifier, simplifyHotkey, toHotkeyRegistrationView, validateHotkey };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Store } from "./_store.js";
|
|
2
|
-
//#region src/key-state-tracker.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* State interface for the KeyStateTracker.
|
|
5
4
|
*/
|
|
@@ -100,5 +99,4 @@ export declare class KeyStateTracker {
|
|
|
100
99
|
* Gets the singleton KeyStateTracker instance.
|
|
101
100
|
* Convenience function for accessing the tracker.
|
|
102
101
|
*/
|
|
103
|
-
export declare function getKeyStateTracker(): KeyStateTracker;
|
|
104
|
-
//#endregion
|
|
102
|
+
export declare function getKeyStateTracker(): KeyStateTracker;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MODIFIER_KEYS, normalizeKeyName } from "./constants.js";
|
|
2
1
|
import { createStore } from "./_store.js";
|
|
2
|
+
import { MODIFIER_KEYS, normalizeKeyName } from "./constants.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/key-state-tracker.ts
|
|
5
5
|
/**
|
|
6
6
|
* Returns the default state for KeyStateTracker.
|
|
7
7
|
*/
|
|
@@ -252,5 +252,4 @@ function getKeyStateTracker() {
|
|
|
252
252
|
return KeyStateTracker.getInstance();
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
//#endregion
|
|
256
255
|
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
|
-
//#region src/key.types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* All supported modifier key names, including aliases.
|
|
5
4
|
* - Control/Ctrl: The Control key
|
|
@@ -44,12 +43,13 @@ export type NamedKey = (typeof SHARED_NAMED_KEYS)[number] | (typeof LOGICAL_ONLY
|
|
|
44
43
|
export type NonPunctuationKey = LetterKey | NumberKey | EditingKey | NavigationKey | FunctionKey | NamedKey;
|
|
45
44
|
/**
|
|
46
45
|
* Supported physical KeyboardEvent.code names, independent of keyboard layout.
|
|
47
|
-
* Letter, digit,
|
|
48
|
-
* `
|
|
46
|
+
* Letter, digit, and numpad names use finite template unions. Modifier codes
|
|
47
|
+
* such as `ShiftLeft` are excluded, because modifier-only hotkeys aren't
|
|
48
|
+
* supported. `Unidentified` is excluded because it cannot identify a physical key.
|
|
49
49
|
*
|
|
50
50
|
* @see https://www.w3.org/TR/uievents-code/
|
|
51
51
|
*/
|
|
52
|
-
export type PhysicalKeyCode = `Key${LetterKey}` | `Digit${NumberKey}` | `Numpad${NumberKey}` |
|
|
52
|
+
export type PhysicalKeyCode = `Key${LetterKey}` | `Digit${NumberKey}` | `Numpad${NumberKey}` | 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';
|
|
53
53
|
/**
|
|
54
54
|
* An explicit physical key token. All codes use brackets, including names such
|
|
55
55
|
* as `[Enter]` that also exist as logical keys. Invalid code names are rejected
|
|
@@ -75,5 +75,4 @@ export interface NormalizedKeyboardEvent {
|
|
|
75
75
|
altGraph: boolean;
|
|
76
76
|
location: number;
|
|
77
77
|
isComposing: boolean;
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
78
|
+
}
|
package/dist/match.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { HotkeyCallback, HotkeyChord, HotkeyChordCallbackContext, ParsedHotkeyChord, RegisterableHotkey, RegisterableHotkeySequence } from "./hotkey.types.js";
|
|
2
1
|
import { HotkeyPlatform } from "./platform.js";
|
|
3
|
-
|
|
2
|
+
import { HotkeyCallback, HotkeyChord, HotkeyChordCallbackContext, ParsedHotkeyChord, RegisterableHotkey, RegisterableHotkeySequence } from "./hotkey.types.js";
|
|
4
3
|
export interface KeyboardEventMatch {
|
|
5
4
|
matched: boolean;
|
|
6
5
|
score: 0 | 1 | 2 | 3;
|
|
@@ -22,7 +21,8 @@ export interface KeyboardEventMatch {
|
|
|
22
21
|
* Also handles "dead key" events where `event.key` is `'Dead'` instead of the expected
|
|
23
22
|
* character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E,
|
|
24
23
|
* Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts.
|
|
25
|
-
* In these cases, `event.code` is used to determine the physical key.
|
|
24
|
+
* In these cases, `event.code` is used to determine the physical key. An
|
|
25
|
+
* `'Unidentified'` key also falls back to `code`, except on letter keys.
|
|
26
26
|
*
|
|
27
27
|
* @param event - The KeyboardEvent to check
|
|
28
28
|
* @param chord - The chord string or parsed chord to match against
|
|
@@ -129,5 +129,4 @@ export declare function createSequenceMatcher(sequence: RegisterableHotkeySequen
|
|
|
129
129
|
match: (event: KeyboardEvent) => boolean;
|
|
130
130
|
reset: () => void;
|
|
131
131
|
getProgress: () => number;
|
|
132
|
-
};
|
|
133
|
-
//#endregion
|
|
132
|
+
};
|
package/dist/match.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { normalizeKeyName } from "./constants.js";
|
|
2
|
-
import { detectPlatform } from "./platform.js";
|
|
3
1
|
import { normalizeKeyboardEvent } from "./_keyboard-event.js";
|
|
4
|
-
import { isHotkeySequence, isModifierKey, parseHotkey } from "./parse.js";
|
|
5
|
-
import { formatHotkey } from "./format.js";
|
|
6
2
|
import { matchKeyboardEvent, parsedChordsEqual } from "./_match.js";
|
|
7
3
|
import { chordHasKey } from "./_registration.js";
|
|
4
|
+
import { normalizeKeyName } from "./constants.js";
|
|
5
|
+
import { formatHotkey } from "./format.js";
|
|
6
|
+
import { isHotkeySequence, isModifierKey, parseHotkey } from "./parse.js";
|
|
7
|
+
import { detectPlatform } from "./platform.js";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// src/match.ts
|
|
10
10
|
/**
|
|
11
11
|
* Checks if a KeyboardEvent matches a hotkey.
|
|
12
12
|
*
|
|
@@ -19,7 +19,8 @@ import { chordHasKey } from "./_registration.js";
|
|
|
19
19
|
* Also handles "dead key" events where `event.key` is `'Dead'` instead of the expected
|
|
20
20
|
* character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E,
|
|
21
21
|
* Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts.
|
|
22
|
-
* In these cases, `event.code` is used to determine the physical key.
|
|
22
|
+
* In these cases, `event.code` is used to determine the physical key. An
|
|
23
|
+
* `'Unidentified'` key also falls back to `code`, except on letter keys.
|
|
23
24
|
*
|
|
24
25
|
* @param event - The KeyboardEvent to check
|
|
25
26
|
* @param chord - The chord string or parsed chord to match against
|
|
@@ -193,5 +194,4 @@ function createSequenceMatcher(sequence, options = {}) {
|
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
//#endregion
|
|
197
197
|
export { DEFAULT_SEQUENCE_TIMEOUT, areHotkeysEqual, createHotkeyChordHandler, createMultiHotkeyChordHandler, createSequenceMatcher, matchesKeyboardEvent };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Key } from "./key.types.js";
|
|
2
1
|
import { Hotkey, HotkeyChord, HotkeySequence, ParsedHotkeyChord, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence } from "./hotkey.types.js";
|
|
3
|
-
|
|
2
|
+
import { Key } from "./key.types.js";
|
|
4
3
|
type Platform = 'mac' | 'windows' | 'linux';
|
|
5
4
|
/** A chord in any form: a string, a chord object, or an already-parsed chord. */
|
|
6
5
|
type AnyChord = RegisterableHotkeyChord | ParsedHotkeyChord | (string & {});
|
|
@@ -103,4 +102,4 @@ export declare function parseKeyboardEvent(event: KeyboardEvent, platform?: Plat
|
|
|
103
102
|
* ```
|
|
104
103
|
*/
|
|
105
104
|
export declare function hasNonModifierKey(chord: HotkeyChord | ParsedHotkeyChord | (string & {}), platform?: Platform): boolean;
|
|
106
|
-
|
|
105
|
+
export {};
|
package/dist/parse.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { assertLogicalKey, modifierAlias, normalizeKeyboardEvent, physicalCodeOf, splitChordParts } from "./_keyboard-event.js";
|
|
2
|
+
import { chordHasKey } from "./_registration.js";
|
|
1
3
|
import { MODIFIER_ORDER, normalizeKeyName } from "./constants.js";
|
|
2
4
|
import { detectPlatform, resolveModifier } from "./platform.js";
|
|
3
|
-
import { assertLogicalKey, modifierAlias, normalizeKeyboardEvent, physicalCodeOf, splitChordParts } from "./_keyboard-event.js";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// src/parse.ts
|
|
6
7
|
/** Builds a ParsedHotkeyChord, listing held modifiers in canonical order. */
|
|
7
8
|
function toParsedChord(identity, ctrl, shift, alt, meta) {
|
|
8
9
|
const held = {
|
|
@@ -31,21 +32,14 @@ function simplifyHotkey(hotkey) {
|
|
|
31
32
|
return isHotkeySequence(hotkey) && hotkey.length === 1 ? hotkey[0] : hotkey;
|
|
32
33
|
}
|
|
33
34
|
function parseChordString(chord, platform) {
|
|
34
|
-
const parts = splitChordParts(chord);
|
|
35
|
+
const parts = splitChordParts(chord).map((part) => part.trim());
|
|
36
|
+
const key = normalizeKeyName(parts.pop());
|
|
35
37
|
const modifiers = /* @__PURE__ */ new Set();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else {
|
|
41
|
-
const alias = modifierAlias(part);
|
|
42
|
-
if (alias) {
|
|
43
|
-
const resolved = resolveModifier(alias, platform);
|
|
44
|
-
modifiers.add(resolved);
|
|
45
|
-
} else if (parts.length === 1) key = normalizeKeyName(part);
|
|
46
|
-
}
|
|
38
|
+
for (const part of parts) {
|
|
39
|
+
const alias = modifierAlias(part);
|
|
40
|
+
if (!alias) return toParsedChord({ key: "" }, false, false, false, false);
|
|
41
|
+
modifiers.add(resolveModifier(alias, platform));
|
|
47
42
|
}
|
|
48
|
-
if (!key && parts.length > 0) key = normalizeKeyName(parts[parts.length - 1].trim());
|
|
49
43
|
const code = physicalCodeOf(key);
|
|
50
44
|
return toParsedChord(code !== void 0 ? { code } : { key }, modifiers.has("Control"), modifiers.has("Shift"), modifiers.has("Alt"), modifiers.has("Meta"));
|
|
51
45
|
}
|
|
@@ -145,10 +139,7 @@ function parseKeyboardEvent(event, platform) {
|
|
|
145
139
|
* ```
|
|
146
140
|
*/
|
|
147
141
|
function hasNonModifierKey(chord, platform = detectPlatform()) {
|
|
148
|
-
|
|
149
|
-
if (parsed.code !== void 0) return parsed.code.length > 0 && !/^(Control|Shift|Alt|Meta)(Left|Right)$/.test(parsed.code);
|
|
150
|
-
return !isModifierKey(parsed.key) && parsed.key.length > 0;
|
|
142
|
+
return chordHasKey(typeof chord === "string" ? parseChordString(chord, platform) : chord);
|
|
151
143
|
}
|
|
152
144
|
|
|
153
|
-
//#endregion
|
|
154
145
|
export { hasNonModifierKey, isHotkeySequence, isModifierKey, normalizeHotkey, parseHotkey, parseKeyboardEvent, simplifyHotkey };
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CanonicalModifier } from "./key.types.js";
|
|
2
|
-
//#region src/platform.d.ts
|
|
3
2
|
/** A platform for resolving `Mod` and formatting labels. */
|
|
4
3
|
export type HotkeyPlatform = 'mac' | 'windows' | 'linux';
|
|
5
4
|
/**
|
|
@@ -49,5 +48,4 @@ export declare function detectPlatform(userAgent?: string | null): HotkeyPlatfor
|
|
|
49
48
|
* resolveModifier('Control', 'mac') // 'Control' (unchanged)
|
|
50
49
|
* ```
|
|
51
50
|
*/
|
|
52
|
-
export declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
|
53
|
-
//#endregion
|
|
51
|
+
export declare function resolveModifier(modifier: CanonicalModifier | 'Mod', platform?: 'mac' | 'windows' | 'linux'): CanonicalModifier;
|
package/dist/platform.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isServerRuntime } from "./_server.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/platform.ts
|
|
4
4
|
/**
|
|
5
5
|
* Detects a platform from a user agent string, or from the browser's
|
|
6
6
|
* `navigator` when called without one.
|
|
@@ -65,5 +65,4 @@ function resolveModifier(modifier, platform = detectPlatform()) {
|
|
|
65
65
|
return modifier;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
//#endregion
|
|
69
68
|
export { detectPlatform, resolveModifier };
|