js-text-highlighter
Version:
A framework-agnostic text highlighting library that supports virtualized texts
28 lines (27 loc) • 855 B
TypeScript
export interface HighlightOptions {
texts: string[];
colors: string[];
caseSensitive: boolean;
}
export declare class Highlighter {
private options;
private observer;
constructor(options: HighlightOptions);
highlight(element: HTMLElement, observe?: boolean): void;
updateOptions(options: Partial<HighlightOptions>): void;
destroy(): void;
/**
* Highlights the text content within a given element.
* @param element The element in which to highlight text.
*/
private highlightElement;
/**
* Observes changes in the DOM (like new nodes being added) and highlights them as needed.
* @param element The element to observe for changes.
*/
private observeChanges;
/**
* Reapplies highlighting to all previously highlighted elements.
*/
private rehighlightAll;
}