{"version":3,"file":"index.cjs","sources":["../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/search-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { Action } from '@embedpdf/core';\nimport { MatchFlag, SearchResult } from '@embedpdf/models';\nimport { SearchDocumentState } from './types';\n\n// Action Types\nexport const INIT_SEARCH_STATE = 'SEARCH/INIT_STATE';\nexport const CLEANUP_SEARCH_STATE = 'SEARCH/CLEANUP_STATE';\nexport const START_SEARCH_SESSION = 'SEARCH/START_SEARCH_SESSION';\nexport const STOP_SEARCH_SESSION = 'SEARCH/STOP_SEARCH_SESSION';\nexport const SET_SEARCH_FLAGS = 'SEARCH/SET_SEARCH_FLAGS';\nexport const SET_SHOW_ALL_RESULTS = 'SEARCH/SET_SHOW_ALL_RESULTS';\nexport const START_SEARCH = 'SEARCH/START_SEARCH';\nexport const SET_SEARCH_RESULTS = 'SEARCH/SET_SEARCH_RESULTS';\nexport const APPEND_SEARCH_RESULTS = 'SEARCH/APPEND_SEARCH_RESULTS';\nexport const SET_ACTIVE_RESULT_INDEX = 'SEARCH/SET_ACTIVE_RESULT_INDEX';\n\n// Action Interfaces\nexport interface InitSearchStateAction extends Action {\n  type: typeof INIT_SEARCH_STATE;\n  payload: { documentId: string; state: SearchDocumentState };\n}\n\nexport interface CleanupSearchStateAction extends Action {\n  type: typeof CLEANUP_SEARCH_STATE;\n  payload: string; // documentId\n}\n\nexport interface StartSearchSessionAction extends Action {\n  type: typeof START_SEARCH_SESSION;\n  payload: { documentId: string };\n}\n\nexport interface StopSearchSessionAction extends Action {\n  type: typeof STOP_SEARCH_SESSION;\n  payload: { documentId: string };\n}\n\nexport interface SetSearchFlagsAction extends Action {\n  type: typeof SET_SEARCH_FLAGS;\n  payload: { documentId: string; flags: MatchFlag[] };\n}\n\nexport interface SetShowAllResultsAction extends Action {\n  type: typeof SET_SHOW_ALL_RESULTS;\n  payload: { documentId: string; showAll: boolean };\n}\n\nexport interface StartSearchAction extends Action {\n  type: typeof START_SEARCH;\n  payload: { documentId: string; query: string };\n}\n\nexport interface SetSearchResultsAction extends Action {\n  type: typeof SET_SEARCH_RESULTS;\n  payload: {\n    documentId: string;\n    results: SearchResult[];\n    total: number;\n    activeResultIndex: number;\n  };\n}\n\nexport interface AppendSearchResultsAction extends Action {\n  type: typeof APPEND_SEARCH_RESULTS;\n  payload: {\n    documentId: string;\n    results: SearchResult[];\n  };\n}\n\nexport interface SetActiveResultIndexAction extends Action {\n  type: typeof SET_ACTIVE_RESULT_INDEX;\n  payload: { documentId: string; index: number };\n}\n\n// Union Type for All Actions\nexport type SearchAction =\n  | InitSearchStateAction\n  | CleanupSearchStateAction\n  | StartSearchSessionAction\n  | StopSearchSessionAction\n  | SetSearchFlagsAction\n  | SetShowAllResultsAction\n  | StartSearchAction\n  | SetSearchResultsAction\n  | AppendSearchResultsAction\n  | SetActiveResultIndexAction;\n\n// Action Creators\nexport function initSearchState(\n  documentId: string,\n  state: SearchDocumentState,\n): InitSearchStateAction {\n  return { type: INIT_SEARCH_STATE, payload: { documentId, state } };\n}\n\nexport function cleanupSearchState(documentId: string): CleanupSearchStateAction {\n  return { type: CLEANUP_SEARCH_STATE, payload: documentId };\n}\n\nexport function startSearchSession(documentId: string): StartSearchSessionAction {\n  return { type: START_SEARCH_SESSION, payload: { documentId } };\n}\n\nexport function stopSearchSession(documentId: string): StopSearchSessionAction {\n  return { type: STOP_SEARCH_SESSION, payload: { documentId } };\n}\n\nexport function setSearchFlags(documentId: string, flags: MatchFlag[]): SetSearchFlagsAction {\n  return { type: SET_SEARCH_FLAGS, payload: { documentId, flags } };\n}\n\nexport function setShowAllResults(documentId: string, showAll: boolean): SetShowAllResultsAction {\n  return { type: SET_SHOW_ALL_RESULTS, payload: { documentId, showAll } };\n}\n\nexport function startSearch(documentId: string, query: string): StartSearchAction {\n  return { type: START_SEARCH, payload: { documentId, query } };\n}\n\nexport function setSearchResults(\n  documentId: string,\n  results: SearchResult[],\n  total: number,\n  activeResultIndex: number,\n): SetSearchResultsAction {\n  return { type: SET_SEARCH_RESULTS, payload: { documentId, results, total, activeResultIndex } };\n}\n\nexport function appendSearchResults(\n  documentId: string,\n  results: SearchResult[],\n): AppendSearchResultsAction {\n  return { type: APPEND_SEARCH_RESULTS, payload: { documentId, results } };\n}\n\nexport function setActiveResultIndex(\n  documentId: string,\n  index: number,\n): SetActiveResultIndexAction {\n  return { type: SET_ACTIVE_RESULT_INDEX, payload: { documentId, index } };\n}\n","import { Reducer } from '@embedpdf/core';\nimport { SearchDocumentState, SearchState } from './types';\nimport {\n  START_SEARCH_SESSION,\n  STOP_SEARCH_SESSION,\n  SET_SEARCH_FLAGS,\n  SET_SHOW_ALL_RESULTS,\n  START_SEARCH,\n  SET_SEARCH_RESULTS,\n  APPEND_SEARCH_RESULTS,\n  SET_ACTIVE_RESULT_INDEX,\n  SearchAction,\n  INIT_SEARCH_STATE,\n  CLEANUP_SEARCH_STATE,\n} from './actions';\nimport { MatchFlag } from '@embedpdf/models';\n\nexport const initialSearchDocumentState: SearchDocumentState = {\n  flags: [] as MatchFlag[],\n  results: [],\n  total: 0,\n  activeResultIndex: -1,\n  showAllResults: true,\n  query: '',\n  loading: false,\n  active: false,\n};\n\nexport const initialState: SearchState = {\n  documents: {},\n};\n\nconst updateDocState = (\n  state: SearchState,\n  documentId: string,\n  newDocState: Partial<SearchDocumentState>,\n): SearchState => {\n  const oldDocState = state.documents[documentId] || initialSearchDocumentState;\n  return {\n    ...state,\n    documents: {\n      ...state.documents,\n      [documentId]: {\n        ...oldDocState,\n        ...newDocState,\n      },\n    },\n  };\n};\n\nexport const searchReducer: Reducer<SearchState, SearchAction> = (state = initialState, action) => {\n  switch (action.type) {\n    case INIT_SEARCH_STATE:\n      return {\n        ...state,\n        documents: {\n          ...state.documents,\n          [action.payload.documentId]: action.payload.state,\n        },\n      };\n\n    case CLEANUP_SEARCH_STATE: {\n      const documentId = action.payload;\n      const { [documentId]: removed, ...remaining } = state.documents;\n      return {\n        ...state,\n        documents: remaining,\n      };\n    }\n\n    case START_SEARCH_SESSION:\n      return updateDocState(state, action.payload.documentId, { active: true });\n\n    case STOP_SEARCH_SESSION:\n      return updateDocState(state, action.payload.documentId, {\n        results: [],\n        total: 0,\n        activeResultIndex: -1,\n        query: '',\n        loading: false,\n        active: false,\n      });\n\n    case SET_SEARCH_FLAGS:\n      return updateDocState(state, action.payload.documentId, { flags: action.payload.flags });\n\n    case SET_SHOW_ALL_RESULTS:\n      return updateDocState(state, action.payload.documentId, {\n        showAllResults: action.payload.showAll,\n      });\n\n    case START_SEARCH:\n      return updateDocState(state, action.payload.documentId, {\n        loading: true,\n        query: action.payload.query,\n        // clear old results on new search start\n        results: [],\n        total: 0,\n        activeResultIndex: -1,\n      });\n\n    case APPEND_SEARCH_RESULTS: {\n      const { documentId, results } = action.payload;\n      const docState = state.documents[documentId];\n      if (!docState) return state;\n\n      const newResults = [...docState.results, ...results];\n      const firstHitIndex =\n        docState.activeResultIndex === -1 && newResults.length > 0 ? 0 : docState.activeResultIndex;\n      return updateDocState(state, documentId, {\n        results: newResults,\n        total: newResults.length, // total-so-far\n        activeResultIndex: firstHitIndex,\n        // keep loading true until final SET_SEARCH_RESULTS\n        loading: true,\n      });\n    }\n\n    case SET_SEARCH_RESULTS: {\n      const { documentId, results, total, activeResultIndex } = action.payload;\n      return updateDocState(state, documentId, {\n        results,\n        total,\n        activeResultIndex,\n        loading: false,\n      });\n    }\n\n    case SET_ACTIVE_RESULT_INDEX:\n      return updateDocState(state, action.payload.documentId, {\n        activeResultIndex: action.payload.index,\n      });\n\n    default:\n      return state;\n  }\n};\n","import { BasePlugin, createBehaviorEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport {\n  MatchFlag,\n  SearchAllPagesResult,\n  PdfEngine,\n  PdfTask,\n  PdfPageSearchProgress,\n  PdfTaskHelper,\n  PdfErrorCode,\n} from '@embedpdf/models';\nimport {\n  SearchPluginConfig,\n  SearchCapability,\n  SearchState,\n  SearchResultState,\n  SearchScope,\n  SearchResultEvent,\n  SearchStartEvent,\n  SearchStopEvent,\n  ActiveResultChangeEvent,\n  SearchResultStateEvent,\n  SearchStateEvent,\n  SearchDocumentState,\n} from './types';\nimport {\n  startSearchSession,\n  stopSearchSession,\n  setSearchFlags,\n  setShowAllResults,\n  startSearch,\n  setSearchResults,\n  setActiveResultIndex,\n  appendSearchResults,\n  SearchAction,\n  initSearchState,\n  cleanupSearchState,\n} from './actions';\nimport { initialSearchDocumentState } from './reducer';\n\nexport class SearchPlugin extends BasePlugin<\n  SearchPluginConfig,\n  SearchCapability,\n  SearchState,\n  SearchAction\n> {\n  static readonly id = 'search' as const;\n\n  // Event emitters are now global and include documentId\n  private readonly searchStop$ = createBehaviorEmitter<SearchStopEvent>();\n  private readonly searchStart$ = createBehaviorEmitter<SearchStartEvent>();\n  private readonly searchResult$ = createBehaviorEmitter<SearchResultEvent>();\n  private readonly searchActiveResultChange$ = createBehaviorEmitter<ActiveResultChangeEvent>();\n  private readonly searchResultState$ = createBehaviorEmitter<SearchResultStateEvent>();\n  private readonly searchState$ = createBehaviorEmitter<SearchStateEvent>();\n\n  // Keep reference to current running tasks per document\n  private currentTask = new Map<string, ReturnType<PdfEngine['searchAllPages']>>();\n  private pluginConfig: SearchPluginConfig;\n\n  constructor(id: string, registry: PluginRegistry, config: SearchPluginConfig) {\n    super(id, registry);\n    this.pluginConfig = config;\n    // We no longer need to listen to the loader.\n    // Document lifecycle is handled by BasePlugin hooks.\n  }\n\n  protected override onDocumentLoadingStarted(documentId: string): void {\n    const initialState = {\n      ...initialSearchDocumentState,\n      flags: this.pluginConfig.flags || [],\n      showAllResults: this.pluginConfig.showAllResults ?? true,\n    };\n    this.dispatch(initSearchState(documentId, initialState));\n  }\n\n  protected override onDocumentClosed(documentId: string): void {\n    this.stopSearchSession(documentId); // Ensure any running search is stopped\n    this.dispatch(cleanupSearchState(documentId));\n    this.currentTask.delete(documentId);\n  }\n\n  async initialize(): Promise<void> {\n    // Config is now handled in onDocumentLoadingStarted\n  }\n\n  override onStoreUpdated(prevState: SearchState, newState: SearchState): void {\n    for (const documentId in newState.documents) {\n      const prevDocState = prevState.documents[documentId];\n      const newDocState = newState.documents[documentId];\n\n      if (prevDocState !== newDocState) {\n        // Emit per-document state\n        this.searchState$.emit({ documentId, state: newDocState });\n\n        // Emit reactive result state\n        if (\n          !prevDocState ||\n          prevDocState.results !== newDocState.results ||\n          prevDocState.activeResultIndex !== newDocState.activeResultIndex ||\n          prevDocState.showAllResults !== newDocState.showAllResults ||\n          prevDocState.active !== newDocState.active\n        ) {\n          this.searchResultState$.emit({\n            documentId,\n            state: {\n              results: newDocState.results,\n              activeResultIndex: newDocState.activeResultIndex,\n              showAllResults: newDocState.showAllResults,\n              active: newDocState.active,\n            },\n          });\n        }\n      }\n    }\n  }\n\n  protected buildCapability(): SearchCapability {\n    const getDocId = (documentId?: string) => documentId ?? this.getActiveDocumentId();\n    const getDocState = (docId?: string) => {\n      const id = getDocId(docId);\n      const state = this.state.documents[id];\n      if (!state) throw new Error(`Search state not found for document ${id}`);\n      return state;\n    };\n\n    return {\n      startSearch: (docId) => this.startSearchSession(getDocId(docId)),\n      stopSearch: (docId) => this.stopSearchSession(getDocId(docId)),\n      searchAllPages: (keyword, docId) => this.searchAllPages(keyword, getDocId(docId)),\n      nextResult: (docId) => this.nextResult(getDocId(docId)),\n      previousResult: (docId) => this.previousResult(getDocId(docId)),\n      goToResult: (index, docId) => this.goToResult(index, getDocId(docId)),\n      setShowAllResults: (showAll, docId) =>\n        this.dispatch(setShowAllResults(getDocId(docId), showAll)),\n      getShowAllResults: (docId) => getDocState(docId).showAllResults,\n      getFlags: (docId) => getDocState(docId).flags,\n      setFlags: (flags, docId) => this.setFlags(flags, getDocId(docId)),\n      getState: (docId) => getDocState(docId),\n      forDocument: this.createSearchScope.bind(this),\n      onSearchResult: this.searchResult$.on,\n      onSearchStart: this.searchStart$.on,\n      onSearchStop: this.searchStop$.on,\n      onActiveResultChange: this.searchActiveResultChange$.on,\n      onSearchResultStateChange: this.searchResultState$.on,\n      onStateChange: this.searchState$.on,\n    };\n  }\n\n  private createSearchScope(documentId: string): SearchScope {\n    const getDocState = () => {\n      const state = this.state.documents[documentId];\n      if (!state) throw new Error(`Search state not found for document ${documentId}`);\n      return state;\n    };\n\n    return {\n      startSearch: () => this.startSearchSession(documentId),\n      stopSearch: () => this.stopSearchSession(documentId),\n      searchAllPages: (keyword) => this.searchAllPages(keyword, documentId),\n      nextResult: () => this.nextResult(documentId),\n      previousResult: () => this.previousResult(documentId),\n      goToResult: (index) => this.goToResult(index, documentId),\n      setShowAllResults: (showAll) => this.dispatch(setShowAllResults(documentId, showAll)),\n      getShowAllResults: () => getDocState().showAllResults,\n      getFlags: () => getDocState().flags,\n      setFlags: (flags) => this.setFlags(flags, documentId),\n      getState: getDocState,\n      onSearchResult: (listener: Listener<SearchAllPagesResult>) =>\n        this.searchResult$.on((event) => {\n          if (event.documentId === documentId) listener(event.results);\n        }),\n      onSearchStart: (listener: Listener<void>) =>\n        this.searchStart$.on((event) => {\n          if (event.documentId === documentId) listener();\n        }),\n      onSearchStop: (listener: Listener<void>) =>\n        this.searchStop$.on((event) => {\n          if (event.documentId === documentId) listener();\n        }),\n      onActiveResultChange: (listener: Listener<number>) =>\n        this.searchActiveResultChange$.on((event) => {\n          if (event.documentId === documentId) listener(event.index);\n        }),\n      onSearchResultStateChange: (listener: Listener<SearchResultState>) =>\n        this.searchResultState$.on((event) => {\n          if (event.documentId === documentId) listener(event.state);\n        }),\n      onStateChange: (listener: Listener<SearchDocumentState>) =>\n        this.searchState$.on((event) => {\n          if (event.documentId === documentId) listener(event.state);\n        }),\n    };\n  }\n\n  private setFlags(flags: MatchFlag[], documentId: string): void {\n    this.dispatch(setSearchFlags(documentId, flags));\n    const docState = this.state.documents[documentId];\n    if (docState?.active) {\n      this.searchAllPages(docState.query, documentId, true);\n    }\n  }\n\n  private notifySearchStart(documentId: string): void {\n    this.searchStart$.emit({ documentId });\n  }\n\n  private notifySearchStop(documentId: string): void {\n    this.searchStop$.emit({ documentId });\n  }\n\n  private notifyActiveResultChange(documentId: string, index: number): void {\n    this.searchActiveResultChange$.emit({ documentId, index });\n  }\n\n  private startSearchSession(documentId: string): void {\n    const coreDoc = this.getCoreDocument(documentId);\n    if (!coreDoc) return;\n    this.dispatch(startSearchSession(documentId));\n    this.notifySearchStart(documentId);\n  }\n\n  private stopSearchSession(documentId: string): void {\n    const docState = this.state.documents[documentId];\n    if (!docState?.active) return;\n\n    const task = this.currentTask.get(documentId);\n    if (task) {\n      try {\n        task.abort?.({ code: PdfErrorCode.Cancelled, message: 'search stopped' });\n      } catch {}\n      this.currentTask.delete(documentId);\n    }\n\n    this.dispatch(stopSearchSession(documentId));\n    this.notifySearchStop(documentId);\n  }\n\n  private searchAllPages(\n    keyword: string,\n    documentId: string,\n    force: boolean = false,\n  ): PdfTask<SearchAllPagesResult, PdfPageSearchProgress> {\n    const docState = this.state.documents[documentId];\n    if (!docState) {\n      return PdfTaskHelper.reject({\n        code: PdfErrorCode.NotFound,\n        message: 'Search state not initialized',\n      });\n    }\n    const coreDoc = this.getCoreDocument(documentId);\n    if (!coreDoc?.document) {\n      return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not loaded' });\n    }\n\n    const trimmedKeyword = keyword.trim();\n\n    if (docState.query === trimmedKeyword && !force) {\n      return PdfTaskHelper.resolve<SearchAllPagesResult, PdfPageSearchProgress>({\n        results: docState.results,\n        total: docState.total,\n      });\n    }\n\n    // stop previous task if still running\n    const oldTask = this.currentTask.get(documentId);\n    if (oldTask) {\n      try {\n        oldTask.abort?.({ code: PdfErrorCode.Cancelled, message: 'new search' });\n      } catch {}\n      this.currentTask.delete(documentId);\n    }\n\n    this.dispatch(startSearch(documentId, trimmedKeyword));\n\n    if (!trimmedKeyword) {\n      this.dispatch(setSearchResults(documentId, [], 0, -1));\n      return PdfTaskHelper.resolve<SearchAllPagesResult, PdfPageSearchProgress>({\n        results: [],\n        total: 0,\n      });\n    }\n\n    if (!docState.active) {\n      this.startSearchSession(documentId);\n    }\n\n    const task = this.engine.searchAllPages(coreDoc.document, trimmedKeyword, {\n      flags: docState.flags,\n    });\n    this.currentTask.set(documentId, task);\n\n    task.onProgress((p) => {\n      if (p?.results?.length) {\n        // Check if the task is still the current one before dispatching\n        if (this.currentTask.get(documentId) === task) {\n          this.dispatch(appendSearchResults(documentId, p.results));\n          // set first active result as soon as we have something\n          if (this.state.documents[documentId].activeResultIndex === -1) {\n            this.dispatch(setActiveResultIndex(documentId, 0));\n            this.notifyActiveResultChange(documentId, 0);\n          }\n        }\n      }\n    });\n\n    task.wait(\n      (results) => {\n        this.currentTask.delete(documentId);\n        const activeResultIndex = results.total > 0 ? 0 : -1;\n        this.dispatch(\n          setSearchResults(documentId, results.results, results.total, activeResultIndex),\n        );\n        this.searchResult$.emit({ documentId, results });\n        if (results.total > 0) {\n          this.notifyActiveResultChange(documentId, 0);\n        }\n      },\n      (error) => {\n        // Only clear results if the error wasn't an abort\n        if (error?.reason?.code !== PdfErrorCode.Cancelled) {\n          console.error('Error during search:', error);\n          this.dispatch(setSearchResults(documentId, [], 0, -1));\n        }\n        this.currentTask.delete(documentId);\n      },\n    );\n\n    return task;\n  }\n\n  private nextResult(documentId: string): number {\n    const docState = this.state.documents[documentId];\n    if (!docState || docState.results.length === 0) return -1;\n    const nextIndex =\n      docState.activeResultIndex >= docState.results.length - 1\n        ? 0\n        : docState.activeResultIndex + 1;\n    return this.goToResult(nextIndex, documentId);\n  }\n\n  private previousResult(documentId: string): number {\n    const docState = this.state.documents[documentId];\n    if (!docState || docState.results.length === 0) return -1;\n    const prevIndex =\n      docState.activeResultIndex <= 0\n        ? docState.results.length - 1\n        : docState.activeResultIndex - 1;\n    return this.goToResult(prevIndex, documentId);\n  }\n\n  private goToResult(index: number, documentId: string): number {\n    const docState = this.state.documents[documentId];\n    if (\n      !docState ||\n      docState.results.length === 0 ||\n      index < 0 ||\n      index >= docState.results.length\n    ) {\n      return -1;\n    }\n    this.dispatch(setActiveResultIndex(documentId, index));\n    this.notifyActiveResultChange(documentId, index);\n    return index;\n  }\n\n  async destroy(): Promise<void> {\n    for (const documentId of Object.keys(this.state.documents)) {\n      this.stopSearchSession(documentId);\n    }\n    this.searchResult$.clear();\n    this.searchStart$.clear();\n    this.searchStop$.clear();\n    this.searchActiveResultChange$.clear();\n    this.searchResultState$.clear();\n    this.searchState$.clear();\n    super.destroy();\n  }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { SearchPluginConfig } from './types';\n\nexport const SEARCH_PLUGIN_ID = 'search';\n\nexport const manifest: PluginManifest<SearchPluginConfig> = {\n  id: SEARCH_PLUGIN_ID,\n  name: 'Search Plugin',\n  version: '1.0.0',\n  provides: ['search'],\n  requires: [],\n  optional: [],\n  defaultConfig: {\n    flags: [],\n  },\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { SearchPlugin } from './search-plugin';\nimport { manifest, SEARCH_PLUGIN_ID } from './manifest';\nimport { SearchPluginConfig, SearchState } from './types';\nimport { searchReducer, initialState, initialSearchDocumentState } from './reducer';\nimport { SearchAction } from './actions';\n\nexport const SearchPluginPackage: PluginPackage<\n  SearchPlugin,\n  SearchPluginConfig,\n  SearchState,\n  SearchAction\n> = {\n  manifest,\n  create: (registry, config) => new SearchPlugin(SEARCH_PLUGIN_ID, registry, config),\n  reducer: searchReducer,\n  initialState,\n};\n\nexport * from './search-plugin';\nexport * from './types';\nexport * from './manifest';\nexport { initialState, initialSearchDocumentState };\n"],"names":["INIT_SEARCH_STATE","CLEANUP_SEARCH_STATE","START_SEARCH_SESSION","STOP_SEARCH_SESSION","SET_SEARCH_FLAGS","SET_SHOW_ALL_RESULTS","START_SEARCH","SET_SEARCH_RESULTS","APPEND_SEARCH_RESULTS","SET_ACTIVE_RESULT_INDEX","setShowAllResults","documentId","showAll","type","payload","setSearchResults","results","total","activeResultIndex","setActiveResultIndex","index","initialSearchDocumentState","flags","showAllResults","query","loading","active","initialState","documents","updateDocState","state","newDocState","oldDocState","_SearchPlugin","BasePlugin","constructor","id","registry","config","super","this","searchStop$","createBehaviorEmitter","searchStart$","searchResult$","searchActiveResultChange$","searchResultState$","searchState$","currentTask","Map","pluginConfig","onDocumentLoadingStarted","dispatch","initSearchState","onDocumentClosed","stopSearchSession","cleanupSearchState","delete","initialize","onStoreUpdated","prevState","newState","prevDocState","emit","buildCapability","getDocId","getActiveDocumentId","getDocState","docId","Error","startSearch","startSearchSession","stopSearch","searchAllPages","keyword","nextResult","previousResult","goToResult","getShowAllResults","getFlags","setFlags","getState","forDocument","createSearchScope","bind","onSearchResult","on","onSearchStart","onSearchStop","onActiveResultChange","onSearchResultStateChange","onStateChange","listener","event","setSearchFlags","docState","notifySearchStart","notifySearchStop","notifyActiveResultChange","getCoreDocument","task","get","_a","abort","code","PdfErrorCode","Cancelled","message","force","PdfTaskHelper","reject","NotFound","coreDoc","document","trimmedKeyword","trim","resolve","oldTask","engine","set","onProgress","p","length","appendSearchResults","wait","error","reason","console","nextIndex","prevIndex","destroy","Object","keys","clear","SearchPlugin","SEARCH_PLUGIN_ID","manifest","name","version","provides","requires","optional","defaultConfig","SearchPluginPackage","create","reducer","action","removed","remaining","newResults","firstHitIndex"],"mappings":"gJAKaA,EAAoB,oBACpBC,EAAuB,uBACvBC,EAAuB,8BACvBC,EAAsB,6BACtBC,EAAmB,0BACnBC,EAAuB,8BACvBC,EAAe,sBACfC,EAAqB,4BACrBC,EAAwB,+BACxBC,EAA0B,iCAkGhC,SAASC,EAAkBC,EAAoBC,GACpD,MAAO,CAAEC,KAAMR,EAAsBS,QAAS,CAAEH,aAAYC,WAC9D,CAMO,SAASG,EACdJ,EACAK,EACAC,EACAC,GAEA,MAAO,CAAEL,KAAMN,EAAoBO,QAAS,CAAEH,aAAYK,UAASC,QAAOC,qBAC5E,CASO,SAASC,EACdR,EACAS,GAEA,MAAO,CAAEP,KAAMJ,EAAyBK,QAAS,CAAEH,aAAYS,SACjE,CC5HO,MAAMC,EA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