@anaralabs/lector 3.2.0 → 3.4.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 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
@@ -79,4 +112,4 @@ Special thanks to these open-source projects that provided inspiration:
79
112
 
80
113
  ## License
81
114
 
82
- MIT © [Unriddle AI]()
115
+ MIT © [Anara](https://anara.com)
@@ -18,15 +18,47 @@ import { StoreApi } from 'zustand';
18
18
  import type { TypedArray } from 'pdfjs-dist/types/src/display/api';
19
19
  import { Virtualizer } from '@tanstack/react-virtual';
20
20
 
21
- export declare const AnnotationLayer: ({ renderForms, className, style, ...props }: AnnotationLayerParams & HTMLProps<HTMLDivElement>) => JSX.Element;
21
+ /**
22
+ * AnnotationLayer renders PDF annotations like links, highlights, and form fields.
23
+ *
24
+ * @param renderForms - Whether to render form fields in the annotation layer.
25
+ * @param externalLinksEnabled - Whether external links should be clickable. When false, external links won't open.
26
+ * @param jumpOptions - Options for page navigation behavior when clicking internal links.
27
+ * See `usePdfJump` hook for available options.
28
+ */
29
+ export declare const AnnotationLayer: ({ renderForms, externalLinksEnabled, jumpOptions, className, style, ...props }: AnnotationLayerParams & HTMLProps<HTMLDivElement>) => JSX.Element;
22
30
 
23
31
  declare interface AnnotationLayerParams {
24
32
  /**
25
33
  * Whether to render forms.
26
34
  */
27
35
  renderForms?: boolean;
36
+ /**
37
+ * Whether external links are enabled.
38
+ * If false, external links will not open.
39
+ * @default true
40
+ */
41
+ externalLinksEnabled?: boolean;
42
+ /**
43
+ * Options to pass to the jumpToPage function when navigating.
44
+ * See usePdfJump hook for available options.
45
+ * @default { behavior: "smooth", align: "start" }
46
+ */
47
+ jumpOptions?: Parameters<ReturnType<typeof usePdfJump>['jumpToPage']>[1];
28
48
  }
29
49
 
50
+ /**
51
+ * Calculates the highlight rectangles for a given text match.
52
+ *
53
+ * @param pageProxy - The PDF page proxy object
54
+ * @param textMatch - An object containing:
55
+ * - pageNumber: The page number where the match is found
56
+ * - text: The text content containing the match (usually a larger chunk of text)
57
+ * - matchIndex: The index within the text where the match starts
58
+ * - searchText: (Optional) The exact search term to highlight. If provided, only highlights
59
+ * this exact term instead of the entire text. If not provided, highlights the full text.
60
+ * @returns An array of HighlightRect objects representing the areas to highlight
61
+ */
30
62
  export declare function calculateHighlightRects(pageProxy: PDFPageProxy, textMatch: TextPosition): Promise<HighlightRect[]>;
31
63
 
32
64
  export declare const cancellable: <T extends Promise<unknown>>(promise: T) => {
@@ -34,10 +66,34 @@ export declare const cancellable: <T extends Promise<unknown>>(promise: T) => {
34
66
  cancel: () => void;
35
67
  };
36
68
 
37
- export declare const CanvasLayer: ({ style, ...props }: HTMLProps<HTMLCanvasElement>) => JSX.Element;
69
+ export declare const CanvasLayer: ({ style, background, ...props }: HTMLProps<HTMLCanvasElement> & {
70
+ background?: string;
71
+ }) => JSX.Element;
38
72
 
39
73
  export declare const clamp: (value: number, min: number, max: number) => number;
40
74
 
75
+ declare type CollapsibleSelection = {
76
+ highlights: HighlightRect[];
77
+ text: string;
78
+ isCollapsed: boolean;
79
+ };
80
+
81
+ declare type ColoredHighlight = {
82
+ color: string;
83
+ rectangles: HighlightRect[];
84
+ pageNumber: number;
85
+ text: string;
86
+ uuid: string;
87
+ };
88
+ export { ColoredHighlight }
89
+ export { ColoredHighlight as ColoredHighlight_alias_1 }
90
+
91
+ export declare const ColoredHighlightLayer: ({ onHighlight, }: ColoredHighlightLayerProps) => JSX.Element;
92
+
93
+ declare type ColoredHighlightLayerProps = {
94
+ onHighlight?: (highlight: ColoredHighlight) => void;
95
+ };
96
+
41
97
  export declare const CurrentPage: ({ ...props }: HTMLProps<HTMLInputElement>) => JSX.Element;
42
98
 
43
99
  export declare const CurrentZoom: ({ ...props }: HTMLProps<HTMLInputElement>) => JSX.Element;
@@ -48,11 +104,15 @@ export declare const CustomLayer: ({ children, }: {
48
104
 
49
105
  export declare const firstMemo: <T>(first: boolean, memo: unknown, initializer: () => T) => T;
50
106
 
107
+ export declare const getEndOfHighlight: (selection: ColoredHighlight) => number;
108
+
51
109
  export declare const getFitWidthZoom: (containerWidth: number, viewports: PageViewport[], zoomOptions: {
52
110
  minZoom: number;
53
111
  maxZoom: number;
54
112
  }) => number;
55
113
 
114
+ export declare const getMidHeightOfHighlightLine: (selection: ColoredHighlight) => number;
115
+
56
116
  export declare const HighlightLayer: ForwardRefExoticComponent<HighlightLayerProps & RefAttributes<HTMLDivElement>>;
57
117
 
58
118
  declare interface HighlightLayerProps extends ComponentPropsWithoutRef<"div"> {
@@ -83,13 +143,28 @@ export declare class LinkService implements IPDFLinkService {
83
143
  _pdfDocumentProxy?: PDFDocumentProxy;
84
144
  externalLinkEnabled: boolean;
85
145
  isInPresentationMode: boolean;
146
+ _currentPageNumber: number;
147
+ _pageNavigationCallback?: (pageNumber: number) => void;
86
148
  get pdfDocumentProxy(): PDFDocumentProxy;
87
149
  constructor();
88
150
  get pagesCount(): number;
151
+ get page(): number;
152
+ set page(value: number);
153
+ setDocument(pdfDocument: PDFDocumentProxy): void;
154
+ setViewer(): void;
89
155
  getDestinationHash(dest: unknown[]): string;
90
- getAnchorUrl(): string;
156
+ getAnchorUrl(hash: string): string;
91
157
  addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow?: boolean | undefined): void;
92
158
  goToDestination(dest: string | unknown[] | Promise<unknown[]>): Promise<void>;
159
+ executeNamedAction(): void;
160
+ navigateTo(dest: string | unknown[] | Promise<unknown[]>): void;
161
+ get rotation(): number;
162
+ set rotation(value: number);
163
+ goToPage(pageNumber: number): void;
164
+ setHash(hash: string): void;
165
+ executeSetOCGState(): void;
166
+ registerPageNavigationCallback(callback: (pageNumber: number) => void): void;
167
+ unregisterPageNavigationCallback(): void;
93
168
  }
94
169
 
95
170
  export declare const NextPage: () => void;
@@ -151,6 +226,9 @@ declare interface PDFState {
151
226
  getPdfPageProxy: (pageNumber: number) => PDFPageProxy;
152
227
  customSelectionRects: HighlightRect[];
153
228
  setCustomSelectionRects: (rects: HighlightRect[]) => void;
229
+ coloredHighlights: ColoredHighlight[];
230
+ addColoredHighlight: (value: ColoredHighlight) => void;
231
+ deleteColoredHighlight: (uuid: string) => void;
154
232
  }
155
233
 
156
234
  export declare const PDFStore: {
@@ -189,6 +267,7 @@ export declare interface SearchResult {
189
267
  score: number;
190
268
  matchIndex: number;
191
269
  isExactMatch: boolean;
270
+ searchText?: string;
192
271
  }
193
272
 
194
273
  export declare interface SearchResults {
@@ -197,6 +276,8 @@ export declare interface SearchResults {
197
276
  hasMoreResults: boolean;
198
277
  }
199
278
 
279
+ declare type Selection_2 = Omit<CollapsibleSelection, "isCollapsed">;
280
+
200
281
  export declare const SelectionTooltip: ({ children }: SelectionTooltipProps) => JSX.Element;
201
282
 
202
283
  declare interface SelectionTooltipProps {
@@ -216,6 +297,7 @@ declare interface TextPosition {
216
297
  pageNumber: number;
217
298
  text: string;
218
299
  matchIndex: number;
300
+ searchText?: string;
219
301
  }
220
302
 
221
303
  export declare const Thumbnail: ({ pageNumber, ...props }: HTMLProps<HTMLCanvasElement> & {
@@ -284,11 +366,8 @@ export declare const useSearch: () => {
284
366
  };
285
367
 
286
368
  export declare const useSelectionDimensions: () => {
287
- getDimension: () => {
288
- highlights: HighlightRect[];
289
- text: string;
290
- isCollapsed: boolean;
291
- } | undefined;
369
+ getDimension: () => CollapsibleSelection | undefined;
370
+ getSelection: () => Selection_2;
292
371
  };
293
372
 
294
373
  export declare const ZoomIn: ({ ...props }: HTMLProps<HTMLButtonElement>) => JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { AnnotationLayer } from './_tsup-dts-rollup.js';
2
2
  export { CanvasLayer } from './_tsup-dts-rollup.js';
3
+ export { ColoredHighlightLayer } from './_tsup-dts-rollup.js';
3
4
  export { CustomLayer } from './_tsup-dts-rollup.js';
4
5
  export { HighlightLayer } from './_tsup-dts-rollup.js';
5
6
  export { TextLayer } from './_tsup-dts-rollup.js';
@@ -27,5 +28,6 @@ export { useSearch } from './_tsup-dts-rollup.js';
27
28
  export { calculateHighlightRects } from './_tsup-dts-rollup.js';
28
29
  export { LinkService } from './_tsup-dts-rollup.js';
29
30
  export { useSelectionDimensions } from './_tsup-dts-rollup.js';
31
+ export { ColoredHighlight } from './_tsup-dts-rollup.js';
30
32
  export { HighlightRect } from './_tsup-dts-rollup.js';
31
33
  export { usePdf } from './_tsup-dts-rollup.js';