import { Hotkey, HotkeyCallback } from "./hotkey.cjs"; import { HotkeyOptions } from "./hotkey-manager.cjs"; import { Store } from "@tanstack/store"; //#region src/sequence-manager.d.ts type Target = HTMLElement | Document | Window; /** * Options for hotkey sequence matching. * Extends HotkeyOptions but excludes requireReset (not applicable to sequences). */ interface SequenceOptions extends Omit { /** Timeout between keys in milliseconds. Default: 1000 */ timeout?: number; } /** * A sequence of hotkeys for Vim-style shortcuts. * * Each element is one step (a `Hotkey` string). Steps may include modifiers; * the same modifier can appear on consecutive steps (e.g. `Shift+R` then * `Shift+T`). Modifier-only key events do not advance or reset matching—see * `SequenceManager`. * * @example * ```ts * const gotoTop: HotkeySequence = ['G', 'G'] // gg * const deleteLine: HotkeySequence = ['D', 'D'] // dd * const deleteWord: HotkeySequence = ['D', 'I', 'W'] // diw * const chainedShift: HotkeySequence = ['Shift+R', 'Shift+T'] * ``` */ type HotkeySequence = Array; /** * Default timeout between keys in a sequence (in milliseconds). * Exported for consumers that display sequence state (e.g. devtools). */ declare const DEFAULT_SEQUENCE_TIMEOUT = 1000; /** * View of a sequence registration for devtools display. * Progress fields reflect an in-progress match (between first key and completion or timeout). */ interface SequenceRegistrationView { id: string; sequence: HotkeySequence; options: SequenceOptions; target: Target; triggerCount: number; /** Whether this sequence has been triggered at least once. */ hasFired: boolean; /** Steps matched in the current attempt (0 when idle or just completed). */ matchedStepCount: number; /** `Date.now()` when the last step in the current attempt matched; 0 if none. */ partialMatchLastKeyTime: number; } /** * A handle returned from SequenceManager.register() that allows updating * the callback and options without re-registering the sequence. * * @example * ```ts * const handle = manager.register(['G', 'G'], callback, options) * * handle.callback = newCallback * handle.setOptions({ timeout: 500 }) * handle.unregister() * ``` */ interface SequenceRegistrationHandle { readonly id: string; readonly isActive: boolean; callback: HotkeyCallback; setOptions: (options: Partial) => void; unregister: () => void; } declare class SequenceManager { #private; /** * The TanStack Store containing sequence registration views for devtools. * Subscribe to this to observe registration changes. */ readonly registrations: Store>; private constructor(); /** * Gets the singleton instance of SequenceManager. */ static getInstance(): SequenceManager; /** * Resets the singleton instance. Useful for testing. */ static resetInstance(): void; /** * Registers a hotkey sequence handler. * * @param sequence - Array of hotkey strings that form the sequence * @param callback - Function to call when the sequence is completed * @param options - Options for the sequence behavior * @returns A handle to update or unregister the sequence */ register(sequence: HotkeySequence, callback: HotkeyCallback, options?: SequenceOptions): SequenceRegistrationHandle; /** * Resets all sequence progress. */ resetAll(): void; /** * Triggers a sequence's callback programmatically from devtools. * Creates a synthetic KeyboardEvent from the last key in the sequence. * * @param id - The registration ID to trigger * @returns True if the registration was found and triggered */ triggerSequence(id: string): boolean; /** * Gets the number of registered sequences. */ getRegistrationCount(): number; /** * Destroys the manager and removes all listeners. */ destroy(): void; } /** * Gets the singleton SequenceManager instance. * Convenience function for accessing the manager. */ declare function getSequenceManager(): SequenceManager; /** * Creates a simple sequence matcher for one-off use. * * This is a low-level helper that does not support ignoreInputs, target, * or other HotkeyOptions. Callers must handle input filtering themselves * if attaching to document. * * @param sequence - The sequence of hotkeys to match * @param options - Options including timeout * @returns An object with match() and reset() methods * * @example * ```ts * const matcher = createSequenceMatcher(['G', 'G'], { timeout: 500 }) * * document.addEventListener('keydown', (event) => { * if (matcher.match(event)) { * console.log('Sequence matched!') * } * }) * ``` */ declare function createSequenceMatcher(sequence: HotkeySequence, options?: { timeout?: number; platform?: 'mac' | 'windows' | 'linux'; }): { match: (event: KeyboardEvent) => boolean; reset: () => void; getProgress: () => number; }; //#endregion export { DEFAULT_SEQUENCE_TIMEOUT, HotkeySequence, SequenceManager, SequenceOptions, SequenceRegistrationHandle, SequenceRegistrationView, createSequenceMatcher, getSequenceManager }; //# sourceMappingURL=sequence-manager.d.cts.map