@anaralabs/lector 3.7.3 → 3.8.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.
@@ -1,4 +1,5 @@
1
1
  import { ComponentPropsWithoutRef } from 'react';
2
+ import { Context } from 'react';
2
3
  import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
3
4
  import { ForwardRefExoticComponent } from 'react';
4
5
  import { FunctionComponent } from 'react';
@@ -287,6 +288,8 @@ export declare const Pages: ({ children, gap, virtualizerOptions, initialOffset,
287
288
  onOffsetChange?: (offset: number) => void;
288
289
  }) => JSX.Element;
289
290
 
291
+ export declare const PDFLinkServiceContext: Context<LinkService>;
292
+
290
293
  declare interface PDFState {
291
294
  pdfDocumentProxy: PDFDocumentProxy;
292
295
  zoom: number;
@@ -414,6 +417,8 @@ declare interface UseAnnotationTooltipReturn {
414
417
  getReferenceProps: ReturnType<typeof useInteractions>["getReferenceProps"];
415
418
  }
416
419
 
420
+ export declare const useCreatePDFLinkService: (pdfDocumentProxy: PDFDocumentProxy | null) => LinkService;
421
+
417
422
  declare const usePdf: <T>(selector: (state: PDFState) => T) => T;
418
423
  export { usePdf }
419
424
  export { usePdf as usePdf_alias_1 }
@@ -447,6 +452,8 @@ export declare const usePdfJump: () => {
447
452
  scrollToHighlightRects: (rects: HighlightRect[], type: "pixels" | "percent", align?: "start" | "center", additionalOffset?: number) => void;
448
453
  };
449
454
 
455
+ export declare const usePDFLinkService: () => LinkService;
456
+
450
457
  declare const usePDFOutline: () => {
451
458
  title: string;
452
459
  bold: boolean;
package/dist/index.d.ts CHANGED
@@ -32,6 +32,9 @@ 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
34
  export { LinkService } from './_tsup-dts-rollup.js';
35
+ export { PDFLinkServiceContext } from './_tsup-dts-rollup.js';
36
+ export { useCreatePDFLinkService } from './_tsup-dts-rollup.js';
37
+ export { usePDFLinkService } from './_tsup-dts-rollup.js';
35
38
  export { usePDFPageNumber } from './_tsup-dts-rollup.js';
36
39
  export { useSelectionDimensions } from './_tsup-dts-rollup.js';
37
40
  export { ColoredHighlight } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -863,6 +863,16 @@ var LinkService = class {
863
863
  this._pageNavigationCallback = void 0;
864
864
  }
865
865
  };
866
+ var useCreatePDFLinkService = (pdfDocumentProxy) => {
867
+ const linkService = useRef(new LinkService());
868
+ useEffect(() => {
869
+ if (pdfDocumentProxy) {
870
+ linkService.current._pdfDocumentProxy = pdfDocumentProxy;
871
+ linkService.current.setDocument(pdfDocumentProxy);
872
+ }
873
+ }, [pdfDocumentProxy]);
874
+ return linkService.current;
875
+ };
866
876
  var defaultLinkService = new LinkService();
867
877
  var PDFLinkServiceContext = createContext(defaultLinkService);
868
878
  var usePDFLinkService = () => {
@@ -5040,7 +5050,10 @@ var Root = forwardRef(
5040
5050
  zoom,
5041
5051
  zoomOptions
5042
5052
  });
5043
- return /* @__PURE__ */ jsx(Primitive.div, { ref, ...props, children: initialState ? /* @__PURE__ */ jsx(PDFStore.Provider, { initialValue: initialState, children }) : loader || "Loading..." });
5053
+ const linkService = useCreatePDFLinkService(
5054
+ initialState?.pdfDocumentProxy ?? null
5055
+ );
5056
+ return /* @__PURE__ */ jsx(Primitive.div, { ref, ...props, children: initialState ? /* @__PURE__ */ jsx(PDFStore.Provider, { initialValue: initialState, children: /* @__PURE__ */ jsx(PDFLinkServiceContext.Provider, { value: linkService, children }) }) : loader || "Loading..." });
5044
5057
  }
5045
5058
  );
5046
5059
  Root.displayName = "Root";
@@ -5454,4 +5467,4 @@ function mergeAdjacentRects(rects) {
5454
5467
  return merged;
5455
5468
  }
5456
5469
 
5457
- export { AnnotationHighlightLayer, AnnotationLayer2 as AnnotationLayer, AnnotationTooltip, CanvasLayer, ColoredHighlightLayer, CurrentPage, CurrentZoom, CustomLayer, HighlightLayer, LinkService, NextPage, Outline, OutlineChildItems, OutlineItem, Page, Pages, PreviousPage, Root, Search, SelectionTooltip, TextLayer2 as TextLayer, Thumbnail, Thumbnails, TotalPages, ZoomIn, ZoomOut, calculateHighlightRects, useAnnotations, usePDFPageNumber, usePdf, usePdfJump, useSearch, useSelectionDimensions };
5470
+ export { AnnotationHighlightLayer, AnnotationLayer2 as AnnotationLayer, AnnotationTooltip, CanvasLayer, ColoredHighlightLayer, CurrentPage, CurrentZoom, CustomLayer, HighlightLayer, LinkService, NextPage, Outline, OutlineChildItems, OutlineItem, PDFLinkServiceContext, Page, Pages, PreviousPage, Root, Search, SelectionTooltip, TextLayer2 as TextLayer, Thumbnail, Thumbnails, TotalPages, ZoomIn, ZoomOut, calculateHighlightRects, useAnnotations, useCreatePDFLinkService, usePDFLinkService, usePDFPageNumber, usePdf, usePdfJump, useSearch, useSelectionDimensions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaralabs/lector",
3
- "version": "3.7.3",
3
+ "version": "3.8.0",
4
4
  "description": "Headless PDF viewer for React",
5
5
  "author": "andrewdr (https://github.com/andrewdoro)",
6
6
  "license": "MIT",