@anaralabs/lector 3.3.0 → 3.5.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/README.md +33 -0
- package/dist/_tsup-dts-rollup.d.ts +176 -7
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1120 -327
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -50,6 +50,39 @@ export default function PDFViewer() {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
## Local Development using PNPM and Yalc
|
|
54
|
+
|
|
55
|
+
When you are using "pnpm link", you are bound to use pnpm on your consumer project when you are developing locally.
|
|
56
|
+
With yalc, we are decoupling the need for pnpm and now the package can be tested with any package managers. Any
|
|
57
|
+
changes should be automatically published to yalc on save, forcing a rebuilt and updating the consumer project.
|
|
58
|
+
|
|
59
|
+
Install yalc globally:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
pnpm i yalc -g
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
From lector:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# navigate to lector package folder and install dependencies
|
|
69
|
+
pnpm i
|
|
70
|
+
# when you first start development, make sure you publish the package locally
|
|
71
|
+
yalc publish
|
|
72
|
+
# and run the project in development mode to start a watcher that rebuilds the project and pushes the changes locally on save
|
|
73
|
+
pnpm dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
From consumer project:
|
|
77
|
+
(It doesn't really matter what package manager you are using)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# add local package to your package.json of the consumer project using yalc
|
|
81
|
+
yalc add @anaralabs/lector
|
|
82
|
+
# or if you don't want to add the yalc package in your package.json
|
|
83
|
+
yalc link @anaralabs/lector
|
|
84
|
+
```
|
|
85
|
+
|
|
53
86
|
## Features
|
|
54
87
|
|
|
55
88
|
- 📱 Responsive and mobile-friendly
|
|
@@ -16,17 +16,101 @@ import { ReactNode } from 'react';
|
|
|
16
16
|
import { RefAttributes } from 'react';
|
|
17
17
|
import { StoreApi } from 'zustand';
|
|
18
18
|
import type { TypedArray } from 'pdfjs-dist/types/src/display/api';
|
|
19
|
+
import { UseBoundStore } from 'zustand';
|
|
20
|
+
import { useFloating } from '@floating-ui/react';
|
|
21
|
+
import { useInteractions } from '@floating-ui/react';
|
|
19
22
|
import { Virtualizer } from '@tanstack/react-virtual';
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
declare interface Annotation {
|
|
25
|
+
id: string;
|
|
26
|
+
pageNumber: number;
|
|
27
|
+
highlights: Array<{
|
|
28
|
+
height: number;
|
|
29
|
+
left: number;
|
|
30
|
+
top: number;
|
|
31
|
+
width: number;
|
|
32
|
+
pageNumber: number;
|
|
33
|
+
}>;
|
|
34
|
+
comment?: string;
|
|
35
|
+
color?: string;
|
|
36
|
+
createdAt: Date;
|
|
37
|
+
updatedAt: Date;
|
|
38
|
+
}
|
|
39
|
+
export { Annotation }
|
|
40
|
+
export { Annotation as Annotation_alias_1 }
|
|
41
|
+
|
|
42
|
+
export declare const AnnotationHighlightLayer: ({ className, style, renderTooltipContent, focusedAnnotationId, onAnnotationClick, }: AnnotationHighlightLayerProps) => JSX.Element;
|
|
43
|
+
|
|
44
|
+
declare interface AnnotationHighlightLayerProps {
|
|
45
|
+
className?: string;
|
|
46
|
+
style?: React.CSSProperties;
|
|
47
|
+
renderTooltipContent?: (props: {
|
|
48
|
+
annotation: Annotation;
|
|
49
|
+
onClose: () => void;
|
|
50
|
+
}) => React.ReactNode;
|
|
51
|
+
focusedAnnotationId?: string;
|
|
52
|
+
onAnnotationClick?: (annotation: Annotation) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* AnnotationLayer renders PDF annotations like links, highlights, and form fields.
|
|
57
|
+
*
|
|
58
|
+
* @param renderForms - Whether to render form fields in the annotation layer.
|
|
59
|
+
* @param externalLinksEnabled - Whether external links should be clickable. When false, external links won't open.
|
|
60
|
+
* @param jumpOptions - Options for page navigation behavior when clicking internal links.
|
|
61
|
+
* See `usePdfJump` hook for available options.
|
|
62
|
+
*/
|
|
63
|
+
export declare const AnnotationLayer: ({ renderForms, externalLinksEnabled, jumpOptions, className, style, ...props }: AnnotationLayerParams & HTMLProps<HTMLDivElement>) => JSX.Element;
|
|
22
64
|
|
|
23
65
|
declare interface AnnotationLayerParams {
|
|
24
66
|
/**
|
|
25
67
|
* Whether to render forms.
|
|
26
68
|
*/
|
|
27
69
|
renderForms?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether external links are enabled.
|
|
72
|
+
* If false, external links will not open.
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
externalLinksEnabled?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Options to pass to the jumpToPage function when navigating.
|
|
78
|
+
* See usePdfJump hook for available options.
|
|
79
|
+
* @default { behavior: "smooth", align: "start" }
|
|
80
|
+
*/
|
|
81
|
+
jumpOptions?: Parameters<ReturnType<typeof usePdfJump>['jumpToPage']>[1];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare interface AnnotationState {
|
|
85
|
+
annotations: Annotation[];
|
|
86
|
+
addAnnotation: (annotation: Omit<Annotation, "id" | "createdAt" | "updatedAt">) => void;
|
|
87
|
+
updateAnnotation: (id: string, updates: Partial<Annotation>) => void;
|
|
88
|
+
deleteAnnotation: (id: string) => void;
|
|
89
|
+
setAnnotations: (annotations: Annotation[]) => void;
|
|
28
90
|
}
|
|
29
91
|
|
|
92
|
+
export declare const AnnotationTooltip: ({ annotation, children, tooltipContent, onOpenChange, isOpen: controlledIsOpen, }: AnnotationTooltipProps) => JSX.Element;
|
|
93
|
+
|
|
94
|
+
declare interface AnnotationTooltipProps {
|
|
95
|
+
annotation: Annotation;
|
|
96
|
+
children: React.ReactNode;
|
|
97
|
+
tooltipContent: React.ReactNode;
|
|
98
|
+
onOpenChange?: (open: boolean) => void;
|
|
99
|
+
isOpen?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Calculates the highlight rectangles for a given text match.
|
|
104
|
+
*
|
|
105
|
+
* @param pageProxy - The PDF page proxy object
|
|
106
|
+
* @param textMatch - An object containing:
|
|
107
|
+
* - pageNumber: The page number where the match is found
|
|
108
|
+
* - text: The text content containing the match (usually a larger chunk of text)
|
|
109
|
+
* - matchIndex: The index within the text where the match starts
|
|
110
|
+
* - searchText: (Optional) The exact search term to highlight. If provided, only highlights
|
|
111
|
+
* this exact term instead of the entire text. If not provided, highlights the full text.
|
|
112
|
+
* @returns An array of HighlightRect objects representing the areas to highlight
|
|
113
|
+
*/
|
|
30
114
|
export declare function calculateHighlightRects(pageProxy: PDFPageProxy, textMatch: TextPosition): Promise<HighlightRect[]>;
|
|
31
115
|
|
|
32
116
|
export declare const cancellable: <T extends Promise<unknown>>(promise: T) => {
|
|
@@ -40,6 +124,28 @@ export declare const CanvasLayer: ({ style, background, ...props }: HTMLProps<HT
|
|
|
40
124
|
|
|
41
125
|
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
42
126
|
|
|
127
|
+
declare type CollapsibleSelection = {
|
|
128
|
+
highlights: HighlightRect[];
|
|
129
|
+
text: string;
|
|
130
|
+
isCollapsed: boolean;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
declare type ColoredHighlight = {
|
|
134
|
+
color: string;
|
|
135
|
+
rectangles: HighlightRect[];
|
|
136
|
+
pageNumber: number;
|
|
137
|
+
text: string;
|
|
138
|
+
uuid: string;
|
|
139
|
+
};
|
|
140
|
+
export { ColoredHighlight }
|
|
141
|
+
export { ColoredHighlight as ColoredHighlight_alias_1 }
|
|
142
|
+
|
|
143
|
+
export declare const ColoredHighlightLayer: ({ onHighlight, }: ColoredHighlightLayerProps) => JSX.Element;
|
|
144
|
+
|
|
145
|
+
declare type ColoredHighlightLayerProps = {
|
|
146
|
+
onHighlight?: (highlight: ColoredHighlight) => void;
|
|
147
|
+
};
|
|
148
|
+
|
|
43
149
|
export declare const CurrentPage: ({ ...props }: HTMLProps<HTMLInputElement>) => JSX.Element;
|
|
44
150
|
|
|
45
151
|
export declare const CurrentZoom: ({ ...props }: HTMLProps<HTMLInputElement>) => JSX.Element;
|
|
@@ -50,11 +156,15 @@ export declare const CustomLayer: ({ children, }: {
|
|
|
50
156
|
|
|
51
157
|
export declare const firstMemo: <T>(first: boolean, memo: unknown, initializer: () => T) => T;
|
|
52
158
|
|
|
159
|
+
export declare const getEndOfHighlight: (selection: ColoredHighlight) => number;
|
|
160
|
+
|
|
53
161
|
export declare const getFitWidthZoom: (containerWidth: number, viewports: PageViewport[], zoomOptions: {
|
|
54
162
|
minZoom: number;
|
|
55
163
|
maxZoom: number;
|
|
56
164
|
}) => number;
|
|
57
165
|
|
|
166
|
+
export declare const getMidHeightOfHighlightLine: (selection: ColoredHighlight) => number;
|
|
167
|
+
|
|
58
168
|
export declare const HighlightLayer: ForwardRefExoticComponent<HighlightLayerProps & RefAttributes<HTMLDivElement>>;
|
|
59
169
|
|
|
60
170
|
declare interface HighlightLayerProps extends ComponentPropsWithoutRef<"div"> {
|
|
@@ -85,13 +195,28 @@ export declare class LinkService implements IPDFLinkService {
|
|
|
85
195
|
_pdfDocumentProxy?: PDFDocumentProxy;
|
|
86
196
|
externalLinkEnabled: boolean;
|
|
87
197
|
isInPresentationMode: boolean;
|
|
198
|
+
_currentPageNumber: number;
|
|
199
|
+
_pageNavigationCallback?: (pageNumber: number) => void;
|
|
88
200
|
get pdfDocumentProxy(): PDFDocumentProxy;
|
|
89
201
|
constructor();
|
|
90
202
|
get pagesCount(): number;
|
|
203
|
+
get page(): number;
|
|
204
|
+
set page(value: number);
|
|
205
|
+
setDocument(pdfDocument: PDFDocumentProxy): void;
|
|
206
|
+
setViewer(): void;
|
|
91
207
|
getDestinationHash(dest: unknown[]): string;
|
|
92
|
-
getAnchorUrl(): string;
|
|
208
|
+
getAnchorUrl(hash: string): string;
|
|
93
209
|
addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow?: boolean | undefined): void;
|
|
94
210
|
goToDestination(dest: string | unknown[] | Promise<unknown[]>): Promise<void>;
|
|
211
|
+
executeNamedAction(): void;
|
|
212
|
+
navigateTo(dest: string | unknown[] | Promise<unknown[]>): void;
|
|
213
|
+
get rotation(): number;
|
|
214
|
+
set rotation(value: number);
|
|
215
|
+
goToPage(pageNumber: number): void;
|
|
216
|
+
setHash(hash: string): void;
|
|
217
|
+
executeSetOCGState(): void;
|
|
218
|
+
registerPageNavigationCallback(callback: (pageNumber: number) => void): void;
|
|
219
|
+
unregisterPageNavigationCallback(): void;
|
|
95
220
|
}
|
|
96
221
|
|
|
97
222
|
export declare const NextPage: () => void;
|
|
@@ -153,6 +278,9 @@ declare interface PDFState {
|
|
|
153
278
|
getPdfPageProxy: (pageNumber: number) => PDFPageProxy;
|
|
154
279
|
customSelectionRects: HighlightRect[];
|
|
155
280
|
setCustomSelectionRects: (rects: HighlightRect[]) => void;
|
|
281
|
+
coloredHighlights: ColoredHighlight[];
|
|
282
|
+
addColoredHighlight: (value: ColoredHighlight) => void;
|
|
283
|
+
deleteColoredHighlight: (uuid: string) => void;
|
|
156
284
|
}
|
|
157
285
|
|
|
158
286
|
export declare const PDFStore: {
|
|
@@ -191,6 +319,7 @@ export declare interface SearchResult {
|
|
|
191
319
|
score: number;
|
|
192
320
|
matchIndex: number;
|
|
193
321
|
isExactMatch: boolean;
|
|
322
|
+
searchText?: string;
|
|
194
323
|
}
|
|
195
324
|
|
|
196
325
|
export declare interface SearchResults {
|
|
@@ -199,6 +328,8 @@ export declare interface SearchResults {
|
|
|
199
328
|
hasMoreResults: boolean;
|
|
200
329
|
}
|
|
201
330
|
|
|
331
|
+
declare type Selection_2 = Omit<CollapsibleSelection, "isCollapsed">;
|
|
332
|
+
|
|
202
333
|
export declare const SelectionTooltip: ({ children }: SelectionTooltipProps) => JSX.Element;
|
|
203
334
|
|
|
204
335
|
declare interface SelectionTooltipProps {
|
|
@@ -218,6 +349,7 @@ declare interface TextPosition {
|
|
|
218
349
|
pageNumber: number;
|
|
219
350
|
text: string;
|
|
220
351
|
matchIndex: number;
|
|
352
|
+
searchText?: string;
|
|
221
353
|
}
|
|
222
354
|
|
|
223
355
|
export declare const Thumbnail: ({ pageNumber, ...props }: HTMLProps<HTMLCanvasElement> & {
|
|
@@ -230,6 +362,44 @@ export declare const Thumbnails: ({ children, ...props }: HTMLProps<HTMLDivEleme
|
|
|
230
362
|
|
|
231
363
|
export declare const TotalPages: ({ ...props }: HTMLProps<HTMLDivElement>) => JSX.Element;
|
|
232
364
|
|
|
365
|
+
export declare const useAnnotationActions: ({ annotation, onClose, }: UseAnnotationActionsProps) => UseAnnotationActionsReturn;
|
|
366
|
+
|
|
367
|
+
declare interface UseAnnotationActionsProps {
|
|
368
|
+
annotation: Annotation;
|
|
369
|
+
onClose?: () => void;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
declare interface UseAnnotationActionsReturn {
|
|
373
|
+
comment: string;
|
|
374
|
+
isEditing: boolean;
|
|
375
|
+
setComment: (comment: string) => void;
|
|
376
|
+
setIsEditing: (isEditing: boolean) => void;
|
|
377
|
+
handleSaveComment: () => void;
|
|
378
|
+
handleColorChange: (color: string) => void;
|
|
379
|
+
handleCancelEdit: () => void;
|
|
380
|
+
colors: string[];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare const useAnnotations: UseBoundStore<StoreApi<AnnotationState>>;
|
|
384
|
+
export { useAnnotations }
|
|
385
|
+
export { useAnnotations as useAnnotations_alias_1 }
|
|
386
|
+
|
|
387
|
+
export declare const useAnnotationTooltip: ({ annotation, onOpenChange, }: UseAnnotationTooltipProps) => UseAnnotationTooltipReturn;
|
|
388
|
+
|
|
389
|
+
declare interface UseAnnotationTooltipProps {
|
|
390
|
+
annotation: Annotation;
|
|
391
|
+
onOpenChange?: (open: boolean) => void;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
declare interface UseAnnotationTooltipReturn {
|
|
395
|
+
isOpen: boolean;
|
|
396
|
+
setIsOpen: (open: boolean) => void;
|
|
397
|
+
refs: ReturnType<typeof useFloating>["refs"];
|
|
398
|
+
floatingStyles: ReturnType<typeof useFloating>["floatingStyles"];
|
|
399
|
+
getFloatingProps: ReturnType<typeof useInteractions>["getFloatingProps"];
|
|
400
|
+
getReferenceProps: ReturnType<typeof useInteractions>["getReferenceProps"];
|
|
401
|
+
}
|
|
402
|
+
|
|
233
403
|
declare const usePdf: <T>(selector: (state: PDFState) => T) => T;
|
|
234
404
|
export { usePdf }
|
|
235
405
|
export { usePdf as usePdf_alias_1 }
|
|
@@ -275,6 +445,8 @@ declare const usePDFOutline: () => {
|
|
|
275
445
|
items: Array<any>;
|
|
276
446
|
}[] | undefined;
|
|
277
447
|
|
|
448
|
+
export declare const usePDFPageNumber: () => number;
|
|
449
|
+
|
|
278
450
|
export declare const useSearch: () => {
|
|
279
451
|
textContent: {
|
|
280
452
|
pageNumber: number;
|
|
@@ -286,11 +458,8 @@ export declare const useSearch: () => {
|
|
|
286
458
|
};
|
|
287
459
|
|
|
288
460
|
export declare const useSelectionDimensions: () => {
|
|
289
|
-
getDimension: () =>
|
|
290
|
-
|
|
291
|
-
text: string;
|
|
292
|
-
isCollapsed: boolean;
|
|
293
|
-
} | undefined;
|
|
461
|
+
getDimension: () => CollapsibleSelection | undefined;
|
|
462
|
+
getSelection: () => Selection_2;
|
|
294
463
|
};
|
|
295
464
|
|
|
296
465
|
export declare const ZoomIn: ({ ...props }: HTMLProps<HTMLButtonElement>) => JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export { AnnotationTooltip } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { AnnotationHighlightLayer } from './_tsup-dts-rollup.js';
|
|
1
3
|
export { AnnotationLayer } from './_tsup-dts-rollup.js';
|
|
2
4
|
export { CanvasLayer } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { ColoredHighlightLayer } from './_tsup-dts-rollup.js';
|
|
3
6
|
export { CustomLayer } from './_tsup-dts-rollup.js';
|
|
4
7
|
export { HighlightLayer } from './_tsup-dts-rollup.js';
|
|
5
8
|
export { TextLayer } from './_tsup-dts-rollup.js';
|
|
@@ -25,7 +28,11 @@ export { SearchResult } from './_tsup-dts-rollup.js';
|
|
|
25
28
|
export { SearchResults } from './_tsup-dts-rollup.js';
|
|
26
29
|
export { useSearch } from './_tsup-dts-rollup.js';
|
|
27
30
|
export { calculateHighlightRects } from './_tsup-dts-rollup.js';
|
|
31
|
+
export { Annotation } from './_tsup-dts-rollup.js';
|
|
32
|
+
export { useAnnotations } from './_tsup-dts-rollup.js';
|
|
28
33
|
export { LinkService } from './_tsup-dts-rollup.js';
|
|
34
|
+
export { usePDFPageNumber } from './_tsup-dts-rollup.js';
|
|
29
35
|
export { useSelectionDimensions } from './_tsup-dts-rollup.js';
|
|
36
|
+
export { ColoredHighlight } from './_tsup-dts-rollup.js';
|
|
30
37
|
export { HighlightRect } from './_tsup-dts-rollup.js';
|
|
31
38
|
export { usePdf } from './_tsup-dts-rollup.js';
|