import * as _angular_core from '@angular/core'; /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * A keybinding specification — `'+'` separated tokens, case-insensitive. * Modifiers: `ctrl`, `alt`, `shift`, `meta`, `cmd` (alias for `meta`), * `mod` (auto: `cmd` on macOS, `ctrl` elsewhere). Last token is the key. * * Examples: `'ctrl+k'`, `'cmd+shift+p'`, `'escape'`, `'mod+/'`, `'ArrowDown'`. */ type WrHotkeySpec = string; /** Returned by {@link WrHotkey.bind} — call `.unbind()` to remove. */ interface WrHotkeyHandle { readonly unbind: () => void; } /** Options accepted by {@link WrHotkey.bind}. */ interface WrHotkeyOptions { /** * Scope the listener to a specific element instead of `document`. The * element must be focusable (or contain the focus) for the binding to * fire — usually combined with `tabindex="0"` on the host. */ readonly element?: HTMLElement; /** Call `event.preventDefault()` when the binding matches. @default true */ readonly preventDefault?: boolean; /** * Fire even when an input / textarea / contenteditable element has * focus. By default these are skipped so the user can type normally. * @default false */ readonly allowInInput?: boolean; /** * Higher priority bindings fire first. Bindings sharing a key dispatch * in priority order; the lower-priority ones are skipped when the * handler calls `event.preventDefault()`. @default 0 */ readonly priority?: number; } /** * Global keybinding registry. * * Bindings are keyed off `KeyboardEvent.key` + modifier state. Multiple * handlers per chord fire in priority order; a handler that calls * `event.preventDefault()` stops lower-priority bindings on that key. * * The listener runs outside Angular — only matched bindings re-enter * the zone, so an idle page doesn't trigger CD on every keystroke. * * Use `[wrHotkey]` for declarative element-scoped bindings. * * @example * ```ts * const hotkeys = inject(WrHotkey); * const handle = hotkeys.bind('mod+k', () => openCommandPalette()); * // ...later * handle.unbind(); * ``` * * @see https://ngwr.dev/services/hotkey */ declare class WrHotkey { private readonly doc; private readonly zone; private readonly platform; private readonly isMac; /** Bindings grouped by listener target. */ private readonly registries; /** Register a binding. */ bind(spec: WrHotkeySpec, handler: (event: KeyboardEvent) => void, options?: WrHotkeyOptions): WrHotkeyHandle; private readonly listeners; private attach; private detach; private dispatch; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵprov: _angular_core.ɵɵInjectableDeclaration; } /** * Declarative wrapper around {@link WrHotkey}. * * Binds on init (and re-binds when the spec changes), unbinds on destroy. * Defaults to global scope so the binding works regardless of focus — * pass `[scoped]="true"` to limit it to the host element. * * @example * ```html * *
* ``` */ declare class WrHotkeyBinding { readonly wrHotkey: _angular_core.InputSignal; /** Scope the binding to the host element instead of `document`. @default false */ readonly scoped: _angular_core.InputSignalWithTransform; /** Fire even when an input / textarea has focus. @default false */ readonly allowInInput: _angular_core.InputSignalWithTransform; /** Suppress the default action when the binding fires. @default true */ readonly preventDefault: _angular_core.InputSignalWithTransform; /** Emits the original KeyboardEvent on match. */ readonly wrHotkeyMatch: _angular_core.OutputEmitterRef; private readonly hotkeys; private readonly host; private handle; constructor(); static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** Normalised representation of a hotkey spec — easy to match against an event. */ interface WrParsedHotkey { readonly ctrl: boolean; readonly alt: boolean; readonly shift: boolean; readonly meta: boolean; /** Lowercased `KeyboardEvent.key` value the spec matches. */ readonly key: string; } /** * Parse a hotkey spec like `'mod+shift+k'` into a normalised structure. * * @param spec - the spec to parse * @param isMac - when true, `mod` resolves to `meta` (Cmd); otherwise `ctrl` */ declare function parseHotkeySpec(spec: WrHotkeySpec, isMac?: boolean): WrParsedHotkey; /** Does `event` satisfy the parsed hotkey? */ declare function matchesHotkey(event: KeyboardEvent, parsed: WrParsedHotkey): boolean; export { WrHotkey, WrHotkeyBinding, matchesHotkey, parseHotkeySpec }; export type { WrHotkeyHandle, WrHotkeyOptions, WrHotkeySpec, WrParsedHotkey };