initial commit

This commit is contained in:
Ben
2025-08-16 17:11:22 +02:00
commit 1843c51e49
11 changed files with 2125 additions and 0 deletions

41
src/types.ts Normal file
View File

@@ -0,0 +1,41 @@
import type { KeybindEmitter } from "./keybindEmitter";
export type KeyCode = string;
export enum ModifierKey {
Shift = 'Shift',
Control = 'Ctrl',
Alt = 'Alt',
Meta = 'Meta'
}
export type Modifiers = Array<ModifierKey>;
export interface KeyCommand{
key: KeyCode;
modifiers: Modifiers;
}
export interface CommandMap {
command: KeyCommand[];
callback: () => void;
}
export const KeybindEventTypes = {
SequenceProgress: "sequenceProgress",
CommandMatched: "commandMatched",
SequenceTimeout: "sequenceTimeout",
SequenceNoMatch: "sequenceNoMatch",
} as const;
export type KeybindEventType = (typeof KeybindEventTypes)[keyof typeof KeybindEventTypes];
export type KeybindEvent =
| { type: typeof KeybindEventTypes.SequenceProgress; pressedKeys: KeyCommand[] }
| { type: typeof KeybindEventTypes.CommandMatched; callback: (() => void) | null }
| { type: typeof KeybindEventTypes.SequenceTimeout; }
| { type: typeof KeybindEventTypes.SequenceNoMatch; };
export type KeyEventHandler = (event: KeyboardEvent) => void;
export interface KeyHandlerReturn {
handler: KeyEventHandler;
emitter: KeybindEmitter;
}