const PLATFORM = typeof navigator == 'object' ? navigator.platform : ''; /** whether the current environment is an Apple device. */ export const IS_APPLE_DEVICE: boolean = /iP[aho]|Mac/.test(PLATFORM); /** whether the current environment is a Windows device. */ export const IS_WINDOWS_DEVICE: boolean = PLATFORM == 'Win32'; /** modifier key name corresponding to '$mod' on the current platform. */ export const MOD: string = IS_APPLE_DEVICE ? 'Meta' : 'Control'; /** modifier key names that act as aliases for AltGraph on the current platform. */ export const ALT_GRAPH_ALIASES: string[] = IS_WINDOWS_DEVICE ? ['Alt', 'Control'] : IS_APPLE_DEVICE ? ['Alt'] : []; /** known modifier key names. */ export const MODIFIERS: string[] = ['Alt', 'Control', 'Meta', 'Shift']; /** callback listener function for a matched keybind event. */ export type KeybindListener = (ev: KeyboardEvent) => void; /** map of keybind strings to their listener callbacks. */ export type KeybindMapping = Record; /** parsed single key press containing modifier names, target key, and inhibition flags. */ export type Keybind = [mods: string[], key: string, flags: number]; /** sequence of parsed key presses. */ export type KeybindChord = Keybind[]; /** a chord and its associated value. */ export type KeybindEntry = [chord: KeybindChord, value: T]; /** result of processing a keyboard event. */ export type KeybindMatch = // no matching chord | readonly [type: 'none'] // a chord is pending, including after ignored repeat or modifier events | readonly [type: 'pending'] // completes a chord | readonly [type: 'match', value: T]; /** tracks progress through chords across successive keyboard events. */ export interface KeybindTracker { /** * updates chord progress without preventing the event's default action. * @param ev keyboard event to process * @returns no match, a pending chord, or a completed chord's value */ match(ev: KeyboardEvent): KeybindMatch; /** cancels any pending chord. */ reset(): void; } /** options for `createKeybindTracker`. */ export interface KeybindTrackerOptions { /** timeout between chord presses in milliseconds. defaults to `1000`. */ timeout?: number; } /** options for `createKeybindHandler`. */ export interface KeybindHandlerOptions extends KeybindTrackerOptions { /** prevent default actions for completed matches. pending events are always prevented. defaults to `true`. */ preventDefault?: boolean; } /** @internal */ export const enum InhibitFlags { // disabled on TEXT = 1 << 0, // disabled on