# @embedpdf/react — ./search SEARCH_DEFAULTS [VariableDeclaration] (from packages/plugin/search/src/contract.ts): SEARCH_DEFAULTS: SearchSettings ={ reveal:{ align:{ y: 0.35} , behavior: 'smooth'} , highlight:{ color: '#ffd500', activeColor: '#ff9632', blendMode: 'multiply'} , } SearchActiveHitChangedEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchActiveHitChangedEvent{ readonly index: number; readonly hit: SearchHit | null; } SearchCancelledEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchCancelledEvent{ readonly reason: 'superseded' | 'cancelled' | 'cleared'; } SearchCapability [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchCapability extends SettingsApi{ canSearch(options?:{ readonly snippets?: boolean} ): boolean; search(query: SearchQuery, options?: SearchOptions): Promise; refresh(options?: OperationOptions): Promise; cancel(): void; clear(): void; nextHit(options?: SearchRevealOptions): SearchHit | null; previousHit(options?: SearchRevealOptions): SearchHit | null; goToHit(hit: SearchHit | number, options?: SearchRevealOptions): SearchHit | null; revealActiveHit(options?: SearchRevealOptions): void; getQuery(): SearchQuery | null; getStatus(): SearchStatus; listHits(filter?: SearchHitFilter): readonly SearchHit[]; getHitCount(page?: PageRef | number): number; listPagesWithHits(): readonly PageRef[]; getActiveHitIndex(): number; getActiveHit(): SearchHit | null; getProgress(): SearchProgress; getError(): PluginErrorInfo | null; findAll(query: SearchQuery, options?: SearchFindAllOptions): Promise; readonly onStarted: EventHook; readonly onProgressChanged: EventHook; readonly onCompleted: EventHook; readonly onCancelled: EventHook; readonly onFailed: EventHook; readonly onActiveHitChanged: EventHook; readonly onCleared: EventHook; } SearchClearedEvent [TypeAliasDeclaration] (from packages/plugin/search/src/contract.ts): export type SearchClearedEvent = Record; SearchCompletedEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchCompletedEvent{ readonly hitCount: number; } SearchConfig [TypeAliasDeclaration] (from packages/plugin/search/src/contract.ts): export type SearchConfig = DeepPartial; SearchFailedEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchFailedEvent{ readonly error: PluginErrorInfo; } SearchFindAllOptions [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchFindAllOptions extends OperationOptions{ readonly snippets?: boolean; } SearchHit [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchHit{ readonly page: PageRef; readonly pageIndex: number; readonly start: number; readonly count: number; readonly segments: readonly TextSegment[]; readonly bounds?: Rect; readonly snippet?: SearchSnippet; } SearchHitFilter [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchHitFilter{ readonly page?: PageRef | number; } SearchLayer [FunctionDeclaration]: export function SearchLayer({ onHitClick} : SearchLayerProps){ const page = usePage(); const hits = useSearchHits(page.ref); const active = useSearchState((state) => state.activeHit); const highlight = useSearchSettings((settings) => settings.highlight); const [clicks] = useState(createClickDetector); if (hits.length === 0) return null; const color = paint('search-highlight', highlight.color); const activeColor = paint('search-highlight-active', highlight.activeColor); const blendMode = paint( 'search-blend-mode', highlight.blendMode, ) as React.CSSProperties['mixBlendMode']; const clickable = onHitClick ?{ pointerEvents: 'auto' as const, cursor: 'pointer'} : null; const pointerHandlers = (hit: SearchHit) => onHitClick &&{ onPointerDown: (event: React.PointerEvent) => clicks.press(event), onClick: (event: React.MouseEvent) =>{ if (clicks.isClick(event)) onHitClick(hit); } , } ; const pieces = searchHighlightsOf(hits, { active, page: page.transform, color, activeColor, } ); return (
{ pieces.map((piece) => piece.box ? (
) : ( { } ), )}
); } SearchLayerProps [InterfaceDeclaration]: export interface SearchLayerProps{ onHitClick?: (hit: SearchHit) => void; } SearchOptions [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchOptions extends OperationOptions{ readonly from?: PageRef | number; } SearchProgress [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchProgress{ readonly pagesSearched: number; readonly pageCount: number; } SearchProgressChangedEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchProgressChangedEvent extends SearchProgress{ readonly hitCount: number; } SearchQuery [InterfaceDeclaration] (from packages/engine/core/src/search/types.ts): export interface SearchQuery{ text: string; regex?: boolean; matchCase?: boolean; wholeWord?: boolean; matchDiacritics?: boolean; ignoreWhitespace?: boolean; } SearchQueryIssue [TypeAliasDeclaration] (from packages/engine/core/src/search/regex.ts): export type SearchQueryIssue = | SearchRegexIssue | 'diacritics-with-regex' | 'ignore-whitespace-with-regex'; SearchQueryValidation [TypeAliasDeclaration] (from packages/engine/core/src/search/regex.ts): export type SearchQueryValidation = |{ ok: true} |{ ok: false; issue: SearchQueryIssue; message: string} ; SearchRegexValidation [TypeAliasDeclaration] (from packages/engine/core/src/search/regex.ts): export type SearchRegexValidation = |{ ok: true} |{ ok: false; issue: SearchRegexIssue; message: string} ; SearchResult [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchResult{ readonly status: 'complete' | 'superseded' | 'cancelled'; readonly hitCount: number; } SearchReveal [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchReveal{ readonly align: RevealAlignment; readonly behavior: ScrollBehaviorKind; } SearchRevealOptions [TypeAliasDeclaration] (from packages/plugin/search/src/contract.ts): export type SearchRevealOptions = Partial; SearchSettings [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchSettings{ readonly reveal: SearchReveal; readonly highlight:{ readonly color: string; readonly activeColor: string; readonly blendMode: BlendMode; } ; } SearchSnippet [InterfaceDeclaration] (from packages/engine/core/src/search/types.ts): export interface SearchSnippet{ before: string; match: string; after: string; } SearchStartedEvent [InterfaceDeclaration] (from packages/plugin/search/src/contract.ts): export interface SearchStartedEvent{ readonly query: SearchQuery; } SearchState [InterfaceDeclaration] (from packages/plugin/search/src/state.ts): export interface SearchState{ readonly query: SearchQuery | null; readonly status: SearchStatus; readonly hitCount: number; readonly activeHitIndex: number; readonly activeHit: SearchHit | null; readonly progress: SearchProgress; readonly error: PluginErrorInfo | null; } SearchStatus [TypeAliasDeclaration] (from packages/plugin/search/src/contract.ts): export type SearchStatus = 'idle' | 'searching' | 'complete' | 'cancelled' | 'error'; SearchToken [VariableDeclaration] (from packages/plugin/search/src/token.ts): SearchToken = createCapabilityToken('search', { hint: "add searchPlugin() from '@embedpdf/plugin-search' to your plugins list", promises:{ search: true, refresh: true, findAll: true, } , } ) TextSegment [TypeAliasDeclaration] (from packages/plugin/search/src/contract.ts): export type TextSegment = PdfTextSegment; searchPlugin [VariableDeclaration] (from packages/plugin/search/src/search.plugin.ts): searchPlugin = (config?: SearchConfig) => definePlugin({ id: 'search', token: SearchToken, scope: 'document', optional: [StageToken], state: initialSearchModel, settings:{ defaults: SEARCH_DEFAULTS, registered: config} , create: createSearchController, } ) searchState [VariableDeclaration] (from packages/plugin/search/src/state.ts): searchState = defineState(SearchToken, { read: (search): SearchState => ({ query: search.getQuery(), status: search.getStatus(), hitCount: search.getHitCount(), activeHitIndex: search.getActiveHitIndex(), activeHit: search.getActiveHit(), progress: search.getProgress(), error: search.getError(), } ), empty:{ query: null, status: 'idle', hitCount: 0, activeHitIndex: -1, activeHit: null, progress: NO_PROGRESS, error: null, } , } ) useSearch [FunctionDeclaration]: export function useSearch(): SearchCapability{ return useCapability(SearchToken); } useSearchEvent [FunctionDeclaration]: export function useSearchEvent( select: (search: SearchCapability) => EventHook, handler: (event: T) => void, ): void{ useCapabilityEvent(SearchToken, select, handler); } useSearchHits [FunctionDeclaration]: export function useSearchHits(page?: PageRef | number): readonly SearchHit[]{ const scoped = useDocumentScope(); return useKernelValue( (kernel) => kernel .tryCapability(SearchToken, scoped ?? undefined) ?.listHits(page === undefined ? undefined :{ page} ) ?? NO_HITS, ); } useSearchSettings [VariableDeclaration]: useSearchSettings = settingsHook(SearchToken) useSearchState [VariableDeclaration]: useSearchState = stateHook(searchState) validateSearchQuery [FunctionDeclaration] (from packages/engine/core/src/search/regex.ts): export function validateSearchQuery(query: SearchQuery): SearchQueryValidation{ if (!query.regex) return{ ok: true} ; if (query.matchDiacritics){ return{ ok: false, issue: 'diacritics-with-regex', message: 'Diacritic-sensitive matching is not available for regex patterns (regex runs on the raw text plane).', } ; } if (query.ignoreWhitespace){ return{ ok: false, issue: 'ignore-whitespace-with-regex', message: 'Whitespace-insensitive matching is not available for regex patterns (regex runs on the raw text plane; use \\s* in the pattern).', } ; } return validateSearchRegex(query.text); } validateSearchRegex [FunctionDeclaration] (from packages/engine/core/src/search/regex.ts): export function validateSearchRegex(pattern: string): SearchRegexValidation{ if (pattern.length === 0){ return{ ok: false, issue: 'empty', message: 'Pattern is empty.'} ; } if (pattern.length > SEARCH_REGEX_MAX_LENGTH){ return{ ok: false, issue: 'too-long', message: `Pattern exceeds ${ SEARCH_REGEX_MAX_LENGTH} characters.`, } ; } let inClass = false; for (let i = 0; i < pattern.length; i++){ const ch = pattern[i]; if (ch === '\\'){ const next = pattern[i + 1] ?? ''; if (!inClass && next >= '1' && next <= '9'){ return{ ok: false, issue: 'backreference', message: `Backreference \\${ next} is not supported.`, } ; } if (!inClass && next === 'k' && pattern[i + 2] === '<'){ return{ ok: false, issue: 'backreference', message: 'Named backreferences (\\k<…>) are not supported.', } ; } i++; continue; } if (inClass){ if (ch === ']') inClass = false; continue; } if (ch === '['){ inClass = true; continue; } if (ch === '(' && pattern[i + 1] === '?'){ const tag = pattern[i + 2] ?? ''; if (tag === '=' || tag === '!'){ return{ ok: false, issue: 'lookaround', message: 'Lookahead ((?=…), (?!…)) is not supported.', } ; } if (tag === '<' && (pattern[i + 3] === '=' || pattern[i + 3] === '!')){ return{ ok: false, issue: 'lookaround', message: 'Lookbehind ((?<=…), (?