import type { Highlighter, HighlightGroup, HighlightStats, MatchInfo } from './types.js'; import { parseQuery, type ParseQueryOptions } from './query.js'; import { debounce } from './utils.js'; /** Options for {@link connectSearchInput}. */ export interface SearchInputOptions extends Partial>, ParseQueryOptions { /** Group the input controls. Created if missing. Defaults to `'search'`. */ group?: string; /** * `'words'` (default) splits input with {@link parseQuery} (quotes keep * phrases together); `'phrase'` treats the whole input as one literal. */ mode?: 'words' | 'phrase'; /** Wait this many ms after typing stops before re-matching. Defaults to `120`. */ debounce?: number; /** Make the first match current (and scroll to it) after each search. Defaults to `true`. */ jumpToFirst?: boolean; /** * Keyboard shortcuts while the input has focus: Enter → next, Shift+Enter → * previous, Escape → clear. Defaults to `true`. */ keyboard?: boolean; /** * Called after every search and every navigation, e.g. to show "3 of 12". * Receives the current match (if any) and stats for the search group only. */ onChange?: (stats: HighlightStats, current: MatchInfo | undefined) => void; } /** Handle returned by {@link connectSearchInput}. */ export interface SearchInputConnection { /** Go to the next match of this input's group (what Enter does). */ next(): void; /** Go to the previous match of this input's group (what Shift+Enter does). */ previous(): void; /** Re-read the input's value and search now (skips the debounce). */ refresh(): void; /** Clear the input and the highlights it produced. */ reset(): void; /** Stop listening. Leaves the highlighter and its other groups untouched. */ disconnect(): void; } /** * Wire an `` / `