@kingtech/react-pdf-viewer 0.0.0-stage → 1.0.0
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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/NOTICE +14 -0
- package/README.md +67 -2
- package/dist/PdfViewer.d.ts +23 -0
- package/dist/components/ContinuousPages.d.ts +23 -0
- package/dist/components/ErrorView.d.ts +10 -0
- package/dist/components/LoadingView.d.ts +6 -0
- package/dist/components/PageInput.d.ts +11 -0
- package/dist/components/PasswordPrompt.d.ts +10 -0
- package/dist/components/PdfPageCanvas.d.ts +53 -0
- package/dist/components/SearchBar.d.ts +18 -0
- package/dist/components/Thumbnails.d.ts +16 -0
- package/dist/components/Toolbar.d.ts +30 -0
- package/dist/components/ToolbarButton.d.ts +15 -0
- package/dist/components/ToolbarMenu.d.ts +25 -0
- package/dist/components/icons.d.ts +60 -0
- package/dist/core/download.d.ts +4 -0
- package/dist/core/env.d.ts +2 -0
- package/dist/core/errors.d.ts +19 -0
- package/dist/core/fileName.d.ts +10 -0
- package/dist/core/geometry.d.ts +25 -0
- package/dist/core/linkService.d.ts +29 -0
- package/dist/core/loadSource.d.ts +22 -0
- package/dist/core/pdfjs.d.ts +80 -0
- package/dist/core/print.d.ts +16 -0
- package/dist/core/scale.d.ts +26 -0
- package/dist/core/search.d.ts +36 -0
- package/dist/hooks/useControllableState.d.ts +19 -0
- package/dist/hooks/useDevicePixelRatio.d.ts +2 -0
- package/dist/hooks/useDocumentSearch.d.ts +13 -0
- package/dist/hooks/useElementSize.d.ts +13 -0
- package/dist/hooks/useFullscreen.d.ts +18 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +18 -0
- package/dist/hooks/useMediaQuery.d.ts +2 -0
- package/dist/hooks/usePageRenderer.d.ts +74 -0
- package/dist/hooks/usePdfDocument.d.ts +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2290 -0
- package/dist/index.js.map +1 -0
- package/dist/labels.d.ts +64 -0
- package/dist/styles.css +2 -0
- package/dist/types.d.ts +324 -0
- package/package.json +95 -4
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { PdfJsDocumentOptions } from '../types.js';
|
|
2
|
+
import type * as PdfJsNamespace from 'pdfjs-dist';
|
|
3
|
+
/** The `pdfjs-dist` module namespace. */
|
|
4
|
+
export type PdfJsModule = typeof PdfJsNamespace;
|
|
5
|
+
/**
|
|
6
|
+
* Global PDF.js configuration. Every field is optional; unset asset URLs default to the jsDelivr
|
|
7
|
+
* CDN copy of the **exact installed** `pdfjs-dist` version. Self-hosting is recommended for
|
|
8
|
+
* production (see the README).
|
|
9
|
+
*/
|
|
10
|
+
export interface PdfJsConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the `pdfjs-dist` module. Use it to select the legacy build
|
|
13
|
+
* (`() => import('pdfjs-dist/legacy/build/pdf.mjs')`) or a pre-loaded instance.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue `() => import('pdfjs-dist')`
|
|
16
|
+
*/
|
|
17
|
+
loader?: () => Promise<PdfJsModule>;
|
|
18
|
+
/**
|
|
19
|
+
* Worker script URL (e.g. from `import workerSrc from 'pdfjs-dist/build/pdf.worker.min.mjs?url'`).
|
|
20
|
+
* A worker already set on `GlobalWorkerOptions` is respected.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue the jsDelivr worker for the installed version
|
|
23
|
+
*/
|
|
24
|
+
workerSrc?: string;
|
|
25
|
+
/** A ready `Worker` running the PDF.js worker script. Takes precedence over `workerSrc`. */
|
|
26
|
+
workerPort?: Worker;
|
|
27
|
+
/**
|
|
28
|
+
* Base URL of the CMap files, with a trailing slash.
|
|
29
|
+
*
|
|
30
|
+
* @defaultValue jsDelivr `cmaps/` for the installed version
|
|
31
|
+
*/
|
|
32
|
+
cMapUrl?: string;
|
|
33
|
+
/** Whether the CMaps are binary-packed. Default `true`. */
|
|
34
|
+
cMapPacked?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Base URL of the standard font data, with a trailing slash.
|
|
37
|
+
*
|
|
38
|
+
* @defaultValue jsDelivr `standard_fonts/` for the installed version
|
|
39
|
+
*/
|
|
40
|
+
standardFontDataUrl?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Base URL of the WebAssembly decoders, with a trailing slash.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue jsDelivr `wasm/` for the installed version
|
|
45
|
+
*/
|
|
46
|
+
wasmUrl?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Base URL of the ICC color profiles, with a trailing slash.
|
|
49
|
+
*
|
|
50
|
+
* @defaultValue jsDelivr `iccs/` for the installed version
|
|
51
|
+
*/
|
|
52
|
+
iccUrl?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Forwarded to `getDocument` for builds that still support it. Default `false` (defense in depth
|
|
55
|
+
* against CVE-2024-4367; `pdfjs-dist` 5+ removed eval-based font compilation entirely).
|
|
56
|
+
*/
|
|
57
|
+
isEvalSupported?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configures PDF.js for every viewer instance. Call it once at startup, before the first viewer
|
|
61
|
+
* mounts. Calls merge with previous configuration.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import workerSrc from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
|
|
66
|
+
* configurePdfJs({ workerSrc, cMapUrl: '/pdfjs/cmaps/', standardFontDataUrl: '/pdfjs/standard_fonts/' });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function configurePdfJs(next: PdfJsConfig): void;
|
|
70
|
+
/** Resets configuration and the cached module. Test-only; not part of the public API. */
|
|
71
|
+
export declare function resetPdfJs(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Loads `pdfjs-dist` once and shares the result between all instances. A failed load is not
|
|
74
|
+
* cached, so a later call (e.g. `reload()`) retries. Rejects with a `PDFJS_LOAD_FAILED` error.
|
|
75
|
+
*/
|
|
76
|
+
export declare function loadPdfJs(): Promise<PdfJsModule>;
|
|
77
|
+
/** `getDocument` options every load receives: asset URLs and security defaults. */
|
|
78
|
+
export declare function getDocumentDefaults(lib: PdfJsModule): PdfJsDocumentOptions & {
|
|
79
|
+
isEvalSupported: boolean;
|
|
80
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
2
|
+
/** Options for {@link printDocument}. */
|
|
3
|
+
export interface PrintOptions {
|
|
4
|
+
/** Aborts page preparation (the print dialog itself cannot be canceled). */
|
|
5
|
+
signal?: AbortSignal | undefined;
|
|
6
|
+
/** Called after each prepared page. */
|
|
7
|
+
onProgress?: ((done: number, total: number) => void) | undefined;
|
|
8
|
+
/** Render scale; default {@link PRINT_SCALE}. */
|
|
9
|
+
scale?: number | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Prints a document without leaving the page: every page is rendered to an image at print
|
|
13
|
+
* resolution inside a hidden iframe (one page per sheet, no margins), then the iframe's print
|
|
14
|
+
* dialog opens. The iframe is removed after printing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function printDocument(pdf: PDFDocumentProxy, { signal, onProgress, scale }?: PrintOptions): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Default zoom floor (25%). */
|
|
2
|
+
export declare const DEFAULT_MIN_SCALE = 0.25;
|
|
3
|
+
/** Default zoom ceiling (500%). */
|
|
4
|
+
export declare const DEFAULT_MAX_SCALE = 5;
|
|
5
|
+
/** Default zoom increment (5%). */
|
|
6
|
+
export declare const DEFAULT_SCALE_STEP = 0.05;
|
|
7
|
+
/** 100%: one PDF point per CSS pixel. */
|
|
8
|
+
export declare const DEFAULT_SCALE = 1;
|
|
9
|
+
/** Removes floating-point noise (`1.5000000000000004` → `1.5`). */
|
|
10
|
+
export declare function roundScale(scale: number): number;
|
|
11
|
+
/** Tolerance-based scale comparison. */
|
|
12
|
+
export declare function scalesEqual(a: number, b: number): boolean;
|
|
13
|
+
/** Zoom constraints shared by the buttons, shortcuts and imperative API. */
|
|
14
|
+
export interface ZoomOptions {
|
|
15
|
+
minScale: number;
|
|
16
|
+
maxScale: number;
|
|
17
|
+
scaleStep: number;
|
|
18
|
+
/** Preset ladder; when non-empty the zoom buttons step between presets instead of by `scaleStep`. */
|
|
19
|
+
zoomLevels?: readonly number[] | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** The next zoom value in `direction`, or `null` when already at the bound. */
|
|
22
|
+
export declare function nextScale(current: number, direction: 1 | -1, options: ZoomOptions): number | null;
|
|
23
|
+
/** Normalizes an arbitrary requested scale: clamps to the bounds and removes float noise. */
|
|
24
|
+
export declare function normalizeScale(scale: number, options: Pick<ZoomOptions, 'minScale' | 'maxScale'>): number;
|
|
25
|
+
/** Integer percentage shown in the zoom label (`Math.round(scale * 100)`). */
|
|
26
|
+
export declare function scaleToPercent(scale: number): number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** A text item as returned by `getTextContent()` (marked-content entries have no `str`). */
|
|
2
|
+
export interface TextItemLike {
|
|
3
|
+
str: string;
|
|
4
|
+
hasEOL?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Text of one page prepared for searching. Offsets stay aligned with the text layer's items. */
|
|
7
|
+
export interface PageText {
|
|
8
|
+
/** All items joined; an end-of-line item is followed by a space. */
|
|
9
|
+
text: string;
|
|
10
|
+
/** Lower-cased `text` with identical offsets (falls back to `text` if lower-casing changes length). */
|
|
11
|
+
folded: string;
|
|
12
|
+
/** Start offset of each item within `text`. */
|
|
13
|
+
offsets: number[];
|
|
14
|
+
/** Text of each item, in text-layer order. */
|
|
15
|
+
items: string[];
|
|
16
|
+
}
|
|
17
|
+
/** A match within a page's `text`. */
|
|
18
|
+
export interface TextRange {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
}
|
|
22
|
+
/** The part of one text item covered by a match. */
|
|
23
|
+
export interface ItemSegment {
|
|
24
|
+
item: number;
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
}
|
|
28
|
+
/** Keeps only real text items (the entries the text layer renders as spans). */
|
|
29
|
+
export declare function isTextItem<T>(item: T): item is T & TextItemLike;
|
|
30
|
+
export declare function buildPageText(items: readonly TextItemLike[]): PageText;
|
|
31
|
+
/** Normalizes a query: trimmed, whitespace collapsed, lower-cased. */
|
|
32
|
+
export declare function normalizeQuery(query: string): string;
|
|
33
|
+
/** Non-overlapping, case-insensitive matches of `query` in a page. */
|
|
34
|
+
export declare function findMatches(page: PageText, query: string): TextRange[];
|
|
35
|
+
/** Splits a page-level range into the per-item pieces the text layer can highlight. */
|
|
36
|
+
export declare function toItemSegments(page: PageText, range: TextRange): ItemSegment[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Options for {@link useControllableState}. */
|
|
2
|
+
export interface UseControllableStateOptions<T> {
|
|
3
|
+
/** The controlled value. `undefined` means uncontrolled. */
|
|
4
|
+
value: T | undefined;
|
|
5
|
+
/** Initial value while uncontrolled. */
|
|
6
|
+
defaultValue: T | (() => T);
|
|
7
|
+
/** Called with every change, in both controlled and uncontrolled mode. */
|
|
8
|
+
onChange?: ((value: T) => void) | undefined;
|
|
9
|
+
/** Prop name used in development warnings. */
|
|
10
|
+
name?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Setter returned by {@link useControllableState}; accepts a value or an updater function. */
|
|
13
|
+
export type SetControllableState<T> = (next: T | ((previous: T) => T)) => void;
|
|
14
|
+
/**
|
|
15
|
+
* The value / defaultValue / onValueChange pattern. Internal state is used while `value` is
|
|
16
|
+
* `undefined`; `onChange` fires whenever the value changes. The setter is stable. Values must not
|
|
17
|
+
* be functions (a function argument is treated as an updater).
|
|
18
|
+
*/
|
|
19
|
+
export declare function useControllableState<T>({ value, defaultValue, onChange, name, }: UseControllableStateOptions<T>): readonly [T, SetControllableState<T>];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
2
|
+
/** One search hit: its page and its index among that page's matches. */
|
|
3
|
+
export interface SearchMatch {
|
|
4
|
+
page: number;
|
|
5
|
+
index: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Finds every match of `query` in the document, page by page (debounced; results stream in).
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDocumentSearch(pdf: PDFDocumentProxy | null, query: string): {
|
|
11
|
+
matches: SearchMatch[];
|
|
12
|
+
searching: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Content-box size of an element, in CSS pixels. */
|
|
2
|
+
export interface ElementSize {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Tracks an element's content-box size with `ResizeObserver`. Returns a callback ref and the
|
|
8
|
+
* size, which is `null` until the first measurement (and always on the server).
|
|
9
|
+
*/
|
|
10
|
+
export declare function useElementSize<T extends Element>(): [
|
|
11
|
+
(node: T | null) => void,
|
|
12
|
+
ElementSize | null
|
|
13
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FullscreenMode } from '../types.js';
|
|
2
|
+
/** How fullscreen is currently presented. */
|
|
3
|
+
export type FullscreenPresentation = 'none' | 'layout' | 'native' | 'overlay';
|
|
4
|
+
interface UseFullscreenOptions {
|
|
5
|
+
mode: FullscreenMode;
|
|
6
|
+
active: boolean;
|
|
7
|
+
setActive: (active: boolean) => void;
|
|
8
|
+
element: HTMLElement | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Presents fullscreen:
|
|
12
|
+
* - `controlled`: layout only, the parent decides.
|
|
13
|
+
* - `native`: the Fullscreen API on `element`; leaving it (e.g. with `Esc`) reports `false`.
|
|
14
|
+
* Falls back to `overlay` where element fullscreen is unavailable or refused.
|
|
15
|
+
* - `overlay`: fixed full-viewport layer with a focus trap, scroll lock and `Esc` to close.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFullscreen({ mode, active, setActive, element, }: UseFullscreenOptions): FullscreenPresentation;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PdfViewerApi } from '../types.js';
|
|
2
|
+
type Shortcut = 'previousPage' | 'nextPage' | 'firstPage' | 'lastPage' | 'zoomIn' | 'zoomOut' | 'resetZoom' | 'rotateCw' | 'rotateCcw' | 'toggleFullscreen';
|
|
3
|
+
/** Maps a key press to a viewer shortcut, or `null`. Exported for tests. */
|
|
4
|
+
export declare function getShortcut(event: KeyboardEvent, viewport: HTMLElement | null): Shortcut | null;
|
|
5
|
+
interface UseKeyboardShortcutsOptions {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** Shortcuts are active only while focus is inside this element. */
|
|
8
|
+
element: HTMLElement | null;
|
|
9
|
+
viewport: HTMLElement | null;
|
|
10
|
+
api: PdfViewerApi;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Viewer keyboard shortcuts (active while focus is inside the viewer): ←/→ and PageUp/PageDown
|
|
14
|
+
* change pages, Home/End jump to the first/last page, `+`/`-` zoom, `0` resets zoom, `r`/`R`
|
|
15
|
+
* rotate, `f` toggles fullscreen.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useKeyboardShortcuts({ enabled, element, viewport, api, }: UseKeyboardShortcutsOptions): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
3
|
+
import { FitOptions } from '../core/geometry.js';
|
|
4
|
+
import { PdfViewerError, Rotation } from '../types.js';
|
|
5
|
+
/** Details of a completed page render. */
|
|
6
|
+
export interface PageRenderInfo {
|
|
7
|
+
/** 1-based page number that was rendered (after clamping). */
|
|
8
|
+
page: number;
|
|
9
|
+
/** Scale actually rendered (after fitting). */
|
|
10
|
+
scale: number;
|
|
11
|
+
/** Rendered CSS width in pixels. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Rendered CSS height in pixels. */
|
|
14
|
+
height: number;
|
|
15
|
+
/** Time from request to completion. */
|
|
16
|
+
durationMs: number;
|
|
17
|
+
}
|
|
18
|
+
/** Search highlighting for one page's text layer. */
|
|
19
|
+
export interface PageHighlight {
|
|
20
|
+
/** Text to highlight (case-insensitive). */
|
|
21
|
+
query: string;
|
|
22
|
+
/** Index of the page's match to mark as selected, if any. */
|
|
23
|
+
selected: number | null;
|
|
24
|
+
}
|
|
25
|
+
/** Options for {@link usePageRenderer}. */
|
|
26
|
+
export interface UsePageRendererOptions {
|
|
27
|
+
document: PDFDocumentProxy | null;
|
|
28
|
+
/** 1-based page number; clamped to the document. */
|
|
29
|
+
page: number;
|
|
30
|
+
/** Requested scale (1 = 100%). */
|
|
31
|
+
scale: number;
|
|
32
|
+
/** User rotation, added to the page's intrinsic rotation. */
|
|
33
|
+
rotation: Rotation;
|
|
34
|
+
/** Optional box the page must fit into. */
|
|
35
|
+
fit?: FitOptions | undefined;
|
|
36
|
+
/** Canvas pixel budget. Default {@link DEFAULT_MAX_CANVAS_PIXELS}. */
|
|
37
|
+
maxCanvasPixels?: number | undefined;
|
|
38
|
+
/** Render a selectable text layer. */
|
|
39
|
+
textLayer?: boolean | undefined;
|
|
40
|
+
/** Render link annotations. */
|
|
41
|
+
annotationLayer?: boolean | undefined;
|
|
42
|
+
/** Highlight search matches in the text layer. */
|
|
43
|
+
highlight?: PageHighlight | undefined;
|
|
44
|
+
/** Called when an internal link targets a page. */
|
|
45
|
+
onLinkNavigate?: ((page: number) => void) | undefined;
|
|
46
|
+
/** Called with the selected highlight element, so it can be scrolled into view. */
|
|
47
|
+
onHighlight?: ((element: HTMLElement) => void) | undefined;
|
|
48
|
+
onRender?: ((info: PageRenderInfo) => void) | undefined;
|
|
49
|
+
onError?: ((error: PdfViewerError) => void) | undefined;
|
|
50
|
+
}
|
|
51
|
+
/** Refs to attach and render state returned by {@link usePageRenderer}. */
|
|
52
|
+
export interface UsePageRendererResult {
|
|
53
|
+
/** The page box; the renderer sets its CSS width and height. */
|
|
54
|
+
pageRef: Ref<HTMLDivElement>;
|
|
55
|
+
/** Element that receives the canvas. Must have no React children. */
|
|
56
|
+
canvasHostRef: Ref<HTMLDivElement>;
|
|
57
|
+
/** Element that receives the text and annotation layers. Must have no React children. */
|
|
58
|
+
layersRef: Ref<HTMLDivElement>;
|
|
59
|
+
/** The last render failure, cleared by the next successful render. */
|
|
60
|
+
error: PdfViewerError | null;
|
|
61
|
+
/** Renders again after a failure. */
|
|
62
|
+
retry: () => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Renders one PDF page onto a canvas, optionally with text and annotation layers.
|
|
66
|
+
*
|
|
67
|
+
* - One render at a time: a newer request cancels the running `RenderTask` (cancellations are
|
|
68
|
+
* silent), so bursts of changes complete exactly one render.
|
|
69
|
+
* - Double-buffered: the canvas and its layers are built off-screen and swapped in together, so
|
|
70
|
+
* there is no blank frame.
|
|
71
|
+
* - HiDPI output, capped at `maxCanvasPixels`; re-renders when the device pixel ratio changes.
|
|
72
|
+
* - The renderer is the single owner of the page's CSS size.
|
|
73
|
+
*/
|
|
74
|
+
export declare function usePageRenderer({ document, page, scale, rotation, fit, maxCanvasPixels, textLayer, annotationLayer, highlight, onLinkNavigate, onHighlight, onRender, onError, }: UsePageRendererOptions): UsePageRendererResult;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
2
|
+
import { PdfDocumentStatus, PdfJsDocumentOptions, PdfRequestOptions, PdfSource, PdfViewerError } from '../types.js';
|
|
3
|
+
/** Options for {@link usePdfDocument}. Changes apply on the next load, except `password`. */
|
|
4
|
+
export interface UsePdfDocumentOptions extends PdfRequestOptions {
|
|
5
|
+
/** Password for encrypted documents. Changing it reloads the document. */
|
|
6
|
+
password?: string | undefined;
|
|
7
|
+
/** Per-instance `getDocument` overrides. */
|
|
8
|
+
pdfjsOptions?: PdfJsDocumentOptions | undefined;
|
|
9
|
+
/** Called once the document is ready. */
|
|
10
|
+
onLoad?: ((document: PDFDocumentProxy) => void) | undefined;
|
|
11
|
+
/** Called for every load failure except aborts and handled HTTP errors. */
|
|
12
|
+
onError?: ((error: PdfViewerError) => void) | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** State returned by {@link usePdfDocument}. */
|
|
15
|
+
export interface UsePdfDocumentResult {
|
|
16
|
+
/** `idle` (no source, or HTTP error handled by the host), `loading`, `ready` or `error`. */
|
|
17
|
+
status: PdfDocumentStatus;
|
|
18
|
+
/** The loaded document while `status === 'ready'`. Never a destroyed document. */
|
|
19
|
+
document: PDFDocumentProxy | null;
|
|
20
|
+
/** Page count, `0` without a document. */
|
|
21
|
+
numPages: number;
|
|
22
|
+
/** The failure while `status === 'error'`. */
|
|
23
|
+
error: PdfViewerError | null;
|
|
24
|
+
/** Loads the current source again (e.g. after an error). */
|
|
25
|
+
reload: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Loads a PDF document. Every source change aborts the previous fetch, discards its result and
|
|
29
|
+
* destroys the previous document; unmounting does the same.
|
|
30
|
+
*/
|
|
31
|
+
export declare function usePdfDocument(source: PdfSource | null | undefined, options?: UsePdfDocumentOptions): UsePdfDocumentResult;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { PdfViewer } from './PdfViewer.js';
|
|
2
|
+
export { PdfToolbar, type PdfToolbarProps } from './components/Toolbar.js';
|
|
3
|
+
export { PdfPageCanvas, type PdfPageCanvasProps } from './components/PdfPageCanvas.js';
|
|
4
|
+
export { configurePdfJs, type PdfJsConfig, type PdfJsModule } from './core/pdfjs.js';
|
|
5
|
+
export type { FitOptions } from './core/geometry.js';
|
|
6
|
+
export { defaultLabels, type LabelContext, type PdfViewerLabels } from './labels.js';
|
|
7
|
+
export { usePdfDocument, type UsePdfDocumentOptions, type UsePdfDocumentResult, } from './hooks/usePdfDocument.js';
|
|
8
|
+
export type { PageHighlight, PageRenderInfo } from './hooks/usePageRenderer.js';
|
|
9
|
+
export { useControllableState, type SetControllableState, type UseControllableStateOptions, } from './hooks/useControllableState.js';
|
|
10
|
+
export type { FullscreenMode, PdfDocumentStatus, PdfJsDocumentOptions, PdfRequestOptions, PdfSource, PdfViewerApi, PdfViewerError, PdfViewerErrorCode, PdfViewerProps, Rotation, ToolbarAction, ToolbarConfig, } from './types.js';
|