@anaralabs/lector 3.7.3 → 3.9.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/README.md CHANGED
@@ -102,6 +102,8 @@ We welcome contributions! Key areas we're focusing on:
102
102
  3. Mobile/touch interactions
103
103
  4. Documentation and examples
104
104
 
105
+
106
+
105
107
  ## Thanks
106
108
 
107
109
  Special thanks to these open-source projects that provided inspiration:
@@ -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 = () => {
@@ -1066,14 +1076,14 @@ var AnnotationLayer2 = ({
1066
1076
  };
1067
1077
  var useDpr = () => {
1068
1078
  const [dpr, setDPR] = useState(
1069
- !window ? 1 : Math.min(window.devicePixelRatio, 2)
1079
+ typeof window === "undefined" ? 1 : Math.min(window.devicePixelRatio, 2)
1070
1080
  );
1071
1081
  useEffect(() => {
1072
- if (!window) {
1082
+ if (typeof window === "undefined") {
1073
1083
  return;
1074
1084
  }
1075
1085
  const handleDPRChange = () => {
1076
- setDPR(window.devicePixelRatio);
1086
+ setDPR(Math.min(window.devicePixelRatio, 2));
1077
1087
  };
1078
1088
  const windowMatch = window.matchMedia(
1079
1089
  `screen and (min-resolution: ${dpr}dppx)`
@@ -2520,8 +2530,9 @@ var Page = ({
2520
2530
  ...props
2521
2531
  }) => {
2522
2532
  const pdfPageProxy = usePdf((state) => state.getPdfPageProxy(pageNumber));
2523
- const width = (pdfPageProxy.view[2] ?? 0) - (pdfPageProxy.view[0] ?? 0);
2524
- const height = (pdfPageProxy.view[3] ?? 0) - (pdfPageProxy.view[1] ?? 0);
2533
+ const viewport = usePdf((state) => state.viewports[pageNumber - 1]);
2534
+ const width = viewport?.width ?? (pdfPageProxy.view[2] ?? 0) - (pdfPageProxy.view[0] ?? 0);
2535
+ const height = viewport?.height ?? (pdfPageProxy.view[3] ?? 0) - (pdfPageProxy.view[1] ?? 0);
2525
2536
  return /* @__PURE__ */ jsx(PDFPageNumberContext.Provider, { value: pdfPageProxy.pageNumber, children: /* @__PURE__ */ jsx(
2526
2537
  Primitive.div,
2527
2538
  {
@@ -5040,7 +5051,10 @@ var Root = forwardRef(
5040
5051
  zoom,
5041
5052
  zoomOptions
5042
5053
  });
5043
- return /* @__PURE__ */ jsx(Primitive.div, { ref, ...props, children: initialState ? /* @__PURE__ */ jsx(PDFStore.Provider, { initialValue: initialState, children }) : loader || "Loading..." });
5054
+ const linkService = useCreatePDFLinkService(
5055
+ initialState?.pdfDocumentProxy ?? null
5056
+ );
5057
+ 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
5058
  }
5045
5059
  );
5046
5060
  Root.displayName = "Root";
@@ -5454,4 +5468,4 @@ function mergeAdjacentRects(rects) {
5454
5468
  return merged;
5455
5469
  }
5456
5470
 
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 };
5471
+ 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.9.1",
4
4
  "description": "Headless PDF viewer for React",
5
5
  "author": "andrewdr (https://github.com/andrewdoro)",
6
6
  "license": "MIT",
@@ -84,7 +84,7 @@
84
84
  "repository": {
85
85
  "type": "git",
86
86
  "url": "git+https://github.com/anaralabs/lector.git",
87
- "directory": "packages/nuqs"
87
+ "directory": "packages/lector"
88
88
  },
89
89
  "bugs": {
90
90
  "url": "https://github.com/anaralabs/lector/issues"