react-pdf-highlighter
Version:
Set of React components for PDF annotation
85 lines (84 loc) • 3.63 kB
TypeScript
import { PointerEventHandler, PureComponent } from "react";
import "pdfjs-dist/web/pdf_viewer.css";
import "../style/pdf_viewer.css";
import "../style/PdfHighlighter.css";
import type { T_Position, T_ScaledPosition, T_Highlight, T_Scaled, T_LTWH, T_EventBus, T_PDFJS_Viewer, T_PDFJS_Document, T_PDFJS_LinkService } from "../types";
declare type T_ViewportHighlight<T_HT> = {
position: T_Position;
} & T_HT;
declare type State<T_HT> = {
ghostHighlight: {
position: T_ScaledPosition;
content?: {
text?: string;
image?: string;
};
} | null;
isCollapsed: boolean;
range: Range | null;
tip: {
highlight: T_ViewportHighlight<T_HT>;
callback: (highlight: T_ViewportHighlight<T_HT>) => JSX.Element;
} | null;
tipPosition: T_Position | null;
tipChildren: JSX.Element | null;
isAreaSelectionInProgress: boolean;
scrolledToHighlightId: string;
};
declare type Props<T_HT> = {
highlightTransform: (highlight: T_ViewportHighlight<T_HT>, index: number, setTip: (highlight: T_ViewportHighlight<T_HT>, callback: (highlight: T_ViewportHighlight<T_HT>) => JSX.Element) => void, hideTip: () => void, viewportToScaled: (rect: T_LTWH) => T_Scaled, screenshot: (position: T_LTWH) => string, isScrolledTo: boolean) => JSX.Element;
highlights: Array<T_HT>;
onScrollChange: () => void;
scrollRef: (scrollTo: (highlight: T_Highlight) => void) => void;
pdfDocument: T_PDFJS_Document;
pdfScaleValue: string;
onSelectionFinished: (position: T_ScaledPosition, content: {
text?: string;
image?: string;
}, hideTipAndSelection: () => void, transformSelection: () => void) => JSX.Element | null;
enableAreaSelection: (event: MouseEvent) => boolean;
};
export declare class PdfHighlighter<T_HT extends T_Highlight> extends PureComponent<Props<T_HT>, State<T_HT>> {
static defaultProps: {
pdfScaleValue: string;
};
state: State<T_HT>;
eventBus: T_EventBus;
linkService: T_PDFJS_LinkService;
viewer: T_PDFJS_Viewer;
resizeObserver: ResizeObserver | null;
containerNode?: HTMLDivElement | null;
unsubscribe: () => void;
constructor(props: Props<T_HT>);
componentDidMount(): void;
attachRef: (ref: HTMLDivElement | null) => void;
componentDidUpdate(prevProps: Props<T_HT>): void;
init(): void;
componentWillUnmount(): void;
findOrCreateHighlightLayer(page: number): Element | null;
groupHighlightsByPage(highlights: Array<T_HT>): {
[pageNumber: string]: Array<T_HT>;
};
showTip(highlight: T_ViewportHighlight<T_HT>, content: JSX.Element): void;
scaledPositionToViewport({ pageNumber, boundingRect, rects, usePdfCoordinates, }: T_ScaledPosition): T_Position;
viewportPositionToScaled({ pageNumber, boundingRect, rects, }: T_Position): T_ScaledPosition;
screenshot(position: T_LTWH, pageNumber: number): string;
renderHighlights(nextProps?: Props<T_HT>): void;
hideTipAndSelection: () => void;
setTip(position: T_Position, inner: JSX.Element | null): void;
renderTip: () => JSX.Element | null;
onTextLayerRendered: () => void;
scrollTo: (highlight: T_Highlight) => void;
onDocumentReady: () => void;
onSelectionChange: () => void;
onScroll: () => void;
onMouseDown: PointerEventHandler;
handleKeyDown: (event: KeyboardEvent) => void;
afterSelection: () => void;
debouncedAfterSelection: () => void;
toggleTextSelection(flag: boolean): void;
handleScaleValue: () => void;
debouncedScaleValue: () => void;
render(): JSX.Element;
}
export {};