# @embedpdf/angular — ./search EpdfSearch [ClassDeclaration] (from packages/framework/angular/search/src/search.ts): @Injectable({ providedIn: 'root'} ) export class EpdfSearch extends pluginService({ name: 'EpdfSearch', feature: 'withSearch()', token: SearchToken, state: searchState, methods: [ 'search', 'nextHit', 'previousHit', 'goToHit', 'revealActiveHit', 'listHits', 'listPagesWithHits', 'cancel', 'clear', 'refresh', 'findAll', 'canSearch', 'getQuery', 'getStatus', 'getHitCount', 'getActiveHitIndex', 'getActiveHit', 'getProgress', 'getError', ], events: [ 'onStarted', 'onProgressChanged', 'onCompleted', 'onCancelled', 'onFailed', 'onActiveHitChanged', 'onCleared', ], } ){ readonly hits: Signal = this.binding.select( (search) => search.listHits(), NO_HITS, Object.is, ); hitsOn(page: PageRef | number | (() => PageRef | number)): Signal{ const pageOf = typeof page === 'function' ? page : () => page; return this.binding.select((search) => search.listHits({ page: pageOf()} ), NO_HITS, Object.is); } } EpdfSearchLayer [ClassDeclaration] (from packages/framework/angular/search/src/search-layer.ts): @Component({ selector: 'epdf-search-layer', changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (pieces().length > 0){
@for (piece of pieces(); track piece.key){ @if (piece.box; as box){
} @else{ } }
} `, } ) export class EpdfSearchLayer{ private readonly clicks$ = new Subject(); readonly hitClick = outputFromObservable(this.clicks$); private readonly page = injectPage(''); private readonly search = new CapabilityBinding( injectKernelHost(''), () => SearchToken, () => this.page.documentId, ); private readonly hits = this.search.select( (search) => search.listHits({ page: this.page.ref} ), NO_HITS, Object.is, ); private readonly active = this.search.select((search) => search.getActiveHit(), null, Object.is); private readonly highlight = this.search.select( (search) => search.getSettings().highlight, SEARCH_DEFAULTS.highlight, ); private readonly color = computed(() => paint('search-highlight', this.highlight().color)); private readonly activeColor = computed(() => paint('search-highlight-active', this.highlight().activeColor), ); protected readonly blendMode = computed(() => paint('search-blend-mode', this.highlight().blendMode), ); protected readonly pieces = computed((): readonly SearchHighlightPiece[] => searchHighlightsOf(this.hits(), { active: this.active(), page: this.page.transform(), color: this.color(), activeColor: this.activeColor(), } ), ); private readonly clickDetector = createClickDetector(); protected get clickable(): boolean{ return this.clicks$.observed; } protected press(event: PointerEvent): void{ if (this.clickable) this.clickDetector.press(event); } protected click(event: MouseEvent, hit: SearchHit): void{ if (this.clickable && this.clickDetector.isClick(event)) this.clicks$.next(hit); } } 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; } 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, } , } ) 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 ((?<=…), (?