toolset.io
Version:
37 lines (36 loc) • 1.72 kB
TypeScript
export type Key = string | number;
export type KeyCombo = Key | Key[];
export type MouseButton = 'left' | 'middle' | 'right' | number;
export interface KeyEventOptions {
preventDefault?: boolean;
stopPropagation?: boolean;
target?: EventTarget;
event?: 'keydown' | 'keyup' | 'keypress';
}
export interface MouseEventOptions {
preventDefault?: boolean;
stopPropagation?: boolean;
target?: EventTarget;
event?: 'mousedown' | 'mouseup' | 'click' | 'dblclick';
}
export interface LongPressOptions {
threshold?: number;
interval?: number;
}
export interface Listener {
unsubscribe: () => void;
}
export declare class KeyboardListener {
private static normalizeKey;
private static isComboMatch;
static on(combo: KeyCombo, callback: (event: KeyboardEvent) => void, options?: KeyEventOptions): Listener;
static once(combo: KeyCombo, callback: (event: KeyboardEvent) => void, options?: KeyEventOptions): Listener;
static longPress(key: Key, callback: (event: KeyboardEvent) => void, options?: KeyEventOptions & LongPressOptions): Listener;
}
export declare class MouseListener {
private static isButtonMatch;
static on(button: MouseButton, callback: (event: MouseEvent) => void, options?: MouseEventOptions): Listener;
static once(button: MouseButton, callback: (event: MouseEvent) => void, options?: MouseEventOptions): Listener;
static longPress(button: MouseButton, callback: (event: MouseEvent) => void, options?: MouseEventOptions & LongPressOptions): Listener;
static onClickOutside(element: HTMLElement, callback: (event: MouseEvent) => void, options?: Omit<MouseEventOptions, 'target'>): Listener;
}