@anaralabs/lector 3.9.1 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.ts +97 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.js +851 -446
- package/package.json +4 -4
|
@@ -4,11 +4,12 @@ import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
|
4
4
|
import { ForwardRefExoticComponent } from 'react';
|
|
5
5
|
import { FunctionComponent } from 'react';
|
|
6
6
|
import { HTMLProps } from 'react';
|
|
7
|
-
import type { IPDFLinkService } from 'pdfjs-dist/types/web/interfaces';
|
|
8
7
|
import { JSX } from 'react/jsx-runtime';
|
|
9
|
-
import
|
|
8
|
+
import { JSX as JSX_2 } from 'react';
|
|
9
|
+
import { MemoExoticComponent } from 'react';
|
|
10
10
|
import type { PageViewport } from 'pdfjs-dist';
|
|
11
|
-
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
11
|
+
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
12
|
+
import { pdfjsDist } from 'pdfjs-dist';
|
|
12
13
|
import type { PDFPageProxy } from 'pdfjs-dist';
|
|
13
14
|
import type { default as React_2 } from 'react';
|
|
14
15
|
import { ReactElement } from 'react';
|
|
@@ -37,7 +38,7 @@ declare interface Annotation {
|
|
|
37
38
|
export { Annotation }
|
|
38
39
|
export { Annotation as Annotation_alias_1 }
|
|
39
40
|
|
|
40
|
-
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, renderHoverTooltipContent, tooltipClassName, highlightClassName, underlineClassName, commentIconPosition, commmentIcon, commentIconClassName, focusedAnnotationId, focusedHoverAnnotationId, onAnnotationClick, onAnnotationTooltipClose, hoverTooltipClassName, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
41
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, renderHoverTooltipContent, tooltipClassName, highlightClassName, underlineClassName, commentIconPosition, commmentIcon, commentIconClassName, focusedAnnotationId, focusedHoverAnnotationId, onAnnotationClick, onAnnotationTooltipClose, hoverTooltipClassName, }: AnnotationHighlightLayerProps) => JSX.Element | null;
|
|
41
42
|
|
|
42
43
|
declare interface AnnotationHighlightLayerProps {
|
|
43
44
|
className?: string;
|
|
@@ -68,7 +69,7 @@ declare interface AnnotationHighlightLayerProps {
|
|
|
68
69
|
* @param jumpOptions - Options for page navigation behavior when clicking internal links.
|
|
69
70
|
* See `usePdfJump` hook for available options.
|
|
70
71
|
*/
|
|
71
|
-
export declare const AnnotationLayer: ({ renderForms, externalLinksEnabled, jumpOptions, className, style, ...props }: AnnotationLayerParams & HTMLProps<HTMLDivElement>) => JSX.Element
|
|
72
|
+
export declare const AnnotationLayer: MemoExoticComponent<({ renderForms, externalLinksEnabled, jumpOptions, className, style, ...props }: AnnotationLayerParams & HTMLProps<HTMLDivElement>) => JSX.Element>;
|
|
72
73
|
|
|
73
74
|
declare interface AnnotationLayerParams {
|
|
74
75
|
/**
|
|
@@ -123,6 +124,12 @@ declare interface AnnotationTooltipProps {
|
|
|
123
124
|
}) => React.ReactNode;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
declare type CacheEntry = {
|
|
128
|
+
bitmap: ImageBitmap;
|
|
129
|
+
width: number;
|
|
130
|
+
height: number;
|
|
131
|
+
};
|
|
132
|
+
|
|
126
133
|
/**
|
|
127
134
|
* Calculates the highlight rectangles for a given text match.
|
|
128
135
|
*
|
|
@@ -142,12 +149,14 @@ export declare const cancellable: <T extends Promise<unknown>>(promise: T) => {
|
|
|
142
149
|
cancel: () => void;
|
|
143
150
|
};
|
|
144
151
|
|
|
145
|
-
export declare const CanvasLayer: ({ style, background, ...props }: HTMLProps<HTMLCanvasElement> & {
|
|
146
|
-
|
|
147
|
-
}) => JSX.Element
|
|
152
|
+
export declare const CanvasLayer: MemoExoticComponent<({ style, background, ...props }: HTMLProps<HTMLCanvasElement> & {
|
|
153
|
+
background?: string;
|
|
154
|
+
}) => JSX.Element>;
|
|
148
155
|
|
|
149
156
|
export declare const clamp: (value: number, minimum: number, maximum: number) => number;
|
|
150
157
|
|
|
158
|
+
export declare function clampScaleForPage(targetScale: number, pageWidth: number, pageHeight: number): number;
|
|
159
|
+
|
|
151
160
|
declare type CollapsibleSelection = {
|
|
152
161
|
highlights: HighlightRect[];
|
|
153
162
|
underlines?: HighlightRect[];
|
|
@@ -175,9 +184,11 @@ export declare const CurrentPage: ({ ...props }: HTMLProps<HTMLInputElement>) =>
|
|
|
175
184
|
|
|
176
185
|
export declare const CurrentZoom: ({ ...props }: HTMLProps<HTMLInputElement>) => JSX.Element;
|
|
177
186
|
|
|
178
|
-
export declare const CustomLayer: ({ children
|
|
179
|
-
|
|
180
|
-
}) => JSX_2.Element
|
|
187
|
+
export declare const CustomLayer: MemoExoticComponent<({ children }: {
|
|
188
|
+
children: (pageNumber: number) => JSX_2.Element;
|
|
189
|
+
}) => JSX_2.Element>;
|
|
190
|
+
|
|
191
|
+
export declare const ensureAnnotationLayerStyles: () => void;
|
|
181
192
|
|
|
182
193
|
export declare const firstMemo: <T>(first: boolean, memo: unknown, initializer: () => T) => T;
|
|
183
194
|
|
|
@@ -225,7 +236,7 @@ export declare interface InitialPDFState {
|
|
|
225
236
|
zoomOptions?: ZoomOptions;
|
|
226
237
|
}
|
|
227
238
|
|
|
228
|
-
export declare class LinkService
|
|
239
|
+
export declare class LinkService {
|
|
229
240
|
_pdfDocumentProxy?: PDFDocumentProxy;
|
|
230
241
|
externalLinkEnabled: boolean;
|
|
231
242
|
isInPresentationMode: boolean;
|
|
@@ -252,6 +263,12 @@ export declare class LinkService implements IPDFLinkService {
|
|
|
252
263
|
unregisterPageNavigationCallback(): void;
|
|
253
264
|
}
|
|
254
265
|
|
|
266
|
+
export declare const loadPdfJs: () => Promise<pdfjsDist>;
|
|
267
|
+
|
|
268
|
+
export declare const MAX_CANVAS_DIMENSION = 32767;
|
|
269
|
+
|
|
270
|
+
export declare const MAX_CANVAS_PIXELS = 16777216;
|
|
271
|
+
|
|
255
272
|
export declare const NextPage: () => void;
|
|
256
273
|
|
|
257
274
|
export declare const Outline: ({ children, ...props }: HTMLProps<HTMLUListElement> & {
|
|
@@ -273,10 +290,10 @@ declare interface OutlineItemProps extends HTMLProps<HTMLDivElement> {
|
|
|
273
290
|
|
|
274
291
|
declare type OutlineItemType = NonNullable<ReturnType<typeof usePDFOutline>>[number];
|
|
275
292
|
|
|
276
|
-
export declare const Page: ({ children, pageNumber, style, ...props }: HTMLProps<HTMLDivElement> & {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}) => JSX.Element
|
|
293
|
+
export declare const Page: MemoExoticComponent<({ children, pageNumber, style, ...props }: HTMLProps<HTMLDivElement> & {
|
|
294
|
+
children: ReactNode;
|
|
295
|
+
pageNumber?: number;
|
|
296
|
+
}) => JSX.Element>;
|
|
280
297
|
|
|
281
298
|
export declare const Pages: ({ children, gap, virtualizerOptions, initialOffset, onOffsetChange, ...props }: HTMLProps<HTMLDivElement> & {
|
|
282
299
|
virtualizerOptions?: {
|
|
@@ -316,6 +333,9 @@ declare interface PDFState {
|
|
|
316
333
|
coloredHighlights: ColoredHighlight[];
|
|
317
334
|
addColoredHighlight: (value: ColoredHighlight) => void;
|
|
318
335
|
deleteColoredHighlight: (uuid: string) => void;
|
|
336
|
+
renderedPages: Record<number, true>;
|
|
337
|
+
markPageRendered: (pageNumber: number) => void;
|
|
338
|
+
unmarkPageRendered: (pageNumber: number) => void;
|
|
319
339
|
}
|
|
320
340
|
|
|
321
341
|
export declare const PDFStore: {
|
|
@@ -331,6 +351,51 @@ export declare type PDFVirtualizer = Virtualizer<any, any>;
|
|
|
331
351
|
|
|
332
352
|
export declare const PreviousPage: () => void;
|
|
333
353
|
|
|
354
|
+
/**
|
|
355
|
+
* LRU cache for rendered page bitmaps. When scrolling back to a previously
|
|
356
|
+
* rendered page at the same scale, we can draw from cache instantly instead
|
|
357
|
+
* of re-rendering through PDF.js.
|
|
358
|
+
*
|
|
359
|
+
* Cache keys include a document ID to prevent collisions when multiple
|
|
360
|
+
* <Root> instances render different PDFs on the same page.
|
|
361
|
+
*/
|
|
362
|
+
declare class RenderCache {
|
|
363
|
+
private cache;
|
|
364
|
+
private maxEntries;
|
|
365
|
+
private invalidatedDocs;
|
|
366
|
+
constructor(maxEntries?: number);
|
|
367
|
+
private key;
|
|
368
|
+
get(documentId: string, pageNumber: number, scale: number, background?: string): CacheEntry | undefined;
|
|
369
|
+
set(documentId: string, pageNumber: number, scale: number, canvas: HTMLCanvasElement, background?: string): Promise<void>;
|
|
370
|
+
/** Remove all cached entries for a specific document (call on Root unmount). */
|
|
371
|
+
invalidateDocument(documentId: string): void;
|
|
372
|
+
clear(): void;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export declare const renderCache: RenderCache;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Serializes PDF page render operations so only one runs at a time.
|
|
379
|
+
* This prevents multiple heavy pages from competing for CPU and blocking the UI.
|
|
380
|
+
*/
|
|
381
|
+
declare class RenderQueue {
|
|
382
|
+
private queue;
|
|
383
|
+
private running;
|
|
384
|
+
enqueue(execute: () => Promise<void>): {
|
|
385
|
+
promise: Promise<void>;
|
|
386
|
+
cancel: () => void;
|
|
387
|
+
};
|
|
388
|
+
private flush;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Global singleton — intentionally shared across all <Root> instances.
|
|
393
|
+
* Serializing renders across documents prevents overall GPU/CPU pressure
|
|
394
|
+
* on the main thread (CanvasGraphics is single-threaded). The trade-off
|
|
395
|
+
* is increased latency in multi-viewer setups.
|
|
396
|
+
*/
|
|
397
|
+
export declare const renderQueue: RenderQueue;
|
|
398
|
+
|
|
334
399
|
export declare const Root: ForwardRefExoticComponent<Omit<HTMLProps<HTMLDivElement> & usePDFDocumentParams & {
|
|
335
400
|
loader?: ReactNode;
|
|
336
401
|
}, "ref"> & RefAttributes<unknown>>;
|
|
@@ -371,12 +436,14 @@ declare interface SelectionTooltipProps {
|
|
|
371
436
|
|
|
372
437
|
export declare type Source = string | URL | TypedArray | ArrayBuffer | DocumentInitParameters;
|
|
373
438
|
|
|
439
|
+
export declare const subscribeToViewportInvalidation: (viewport: HTMLDivElement, callback: ViewportCallback) => () => void;
|
|
440
|
+
|
|
374
441
|
declare type TextContent = {
|
|
375
442
|
pageNumber: number;
|
|
376
443
|
text: string;
|
|
377
444
|
};
|
|
378
445
|
|
|
379
|
-
export declare const TextLayer: ({ className, style, ...props }: HTMLProps<HTMLDivElement>) => JSX.Element
|
|
446
|
+
export declare const TextLayer: MemoExoticComponent<({ className, style, ...props }: HTMLProps<HTMLDivElement>) => JSX.Element>;
|
|
380
447
|
|
|
381
448
|
declare interface TextPosition {
|
|
382
449
|
pageNumber: number;
|
|
@@ -419,11 +486,15 @@ declare interface UseAnnotationTooltipReturn {
|
|
|
419
486
|
|
|
420
487
|
export declare const useCreatePDFLinkService: (pdfDocumentProxy: PDFDocumentProxy | null) => LinkService;
|
|
421
488
|
|
|
489
|
+
declare const usePageRendered: (pageNumber: number) => boolean;
|
|
490
|
+
export { usePageRendered }
|
|
491
|
+
export { usePageRendered as usePageRendered_alias_1 }
|
|
492
|
+
|
|
422
493
|
declare const usePdf: <T>(selector: (state: PDFState) => T) => T;
|
|
423
494
|
export { usePdf }
|
|
424
495
|
export { usePdf as usePdf_alias_1 }
|
|
425
496
|
|
|
426
|
-
export declare const usePDFDocumentContext: ({ onDocumentLoad, source, initialRotation, isZoomFitWidth, zoom, zoomOptions, }: usePDFDocumentParams) => {
|
|
497
|
+
export declare const usePDFDocumentContext: ({ onDocumentLoad, source, initialRotation, isZoomFitWidth, zoom, zoomOptions, documentOptions, }: usePDFDocumentParams) => {
|
|
427
498
|
initialState: InitialPDFState | null | undefined;
|
|
428
499
|
};
|
|
429
500
|
|
|
@@ -440,6 +511,12 @@ export declare interface usePDFDocumentParams {
|
|
|
440
511
|
isZoomFitWidth?: boolean;
|
|
441
512
|
zoom?: number;
|
|
442
513
|
zoomOptions?: ZoomOptions;
|
|
514
|
+
/**
|
|
515
|
+
* Override or extend the PDF.js DocumentInitParameters passed to getDocument().
|
|
516
|
+
* These take highest precedence over both the source object and lector's defaults.
|
|
517
|
+
* Must be a stable reference (module-level constant or useMemo) to avoid reloading the document.
|
|
518
|
+
*/
|
|
519
|
+
documentOptions?: Partial<DocumentInitParameters>;
|
|
443
520
|
}
|
|
444
521
|
|
|
445
522
|
export declare const usePdfJump: () => {
|
|
@@ -494,6 +571,8 @@ export declare const useSelectionDimensions: () => {
|
|
|
494
571
|
} | undefined;
|
|
495
572
|
};
|
|
496
573
|
|
|
574
|
+
declare type ViewportCallback = () => void;
|
|
575
|
+
|
|
497
576
|
export declare const ZoomIn: ({ ...props }: HTMLProps<HTMLButtonElement>) => JSX.Element;
|
|
498
577
|
|
|
499
578
|
export declare interface ZoomOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { useSearch } from './_tsup-dts-rollup.js';
|
|
|
31
31
|
export { calculateHighlightRects } from './_tsup-dts-rollup.js';
|
|
32
32
|
export { Annotation } from './_tsup-dts-rollup.js';
|
|
33
33
|
export { useAnnotations } from './_tsup-dts-rollup.js';
|
|
34
|
+
export { usePageRendered } from './_tsup-dts-rollup.js';
|
|
34
35
|
export { LinkService } from './_tsup-dts-rollup.js';
|
|
35
36
|
export { PDFLinkServiceContext } from './_tsup-dts-rollup.js';
|
|
36
37
|
export { useCreatePDFLinkService } from './_tsup-dts-rollup.js';
|