import type { KeybindEmitter } from "./keybindEmitter"; export type KeyCode = string; export enum ModifierKey { Shift = 'Shift', Control = 'Ctrl', Alt = 'Alt', Meta = 'Meta' } export type Modifiers = Array; 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; }