pdf-tsx 0.16.2 → 0.16.4
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/dist/cjs/components/PDFViewer.cjs +1 -1
- package/dist/cjs/hooks/usePDFLoader.cjs +1 -1
- package/dist/components/PDFViewer.d.ts +0 -1
- package/dist/es/components/PDFViewer.js +216 -216
- package/dist/es/hooks/usePDFLoader.js +10 -13
- package/dist/hooks/usePDFLoader.d.ts +1 -1
- package/package.json +3 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../context/PDFViewerContext.cjs`),n=require(`../hooks/useScrollTracking.cjs`),r=require(`../hooks/useKeyboardShortcuts.cjs`),i=require(`../hooks/useTextLayer.cjs`),a=require(`../utils/url.cjs`),ee=require(`../hooks/useAnnotationLayer.cjs`),te=require(`../hooks/usePDFLoader.cjs`),ne=require(`../hooks/usePDFRenderer.cjs`),re=require(`../hooks/useOverlayRects.cjs`),o=require(`../utils/pdfFit.cjs`),ie=require(`../context/ThemeContext.cjs`),ae=require(`../context/LabelsContext.cjs`),s=require(`../hooks/useLabels.cjs`),c=require(`./PDFViewer.module.cjs`);let l=require(`react`);l=e.__toESM(l,1);let u=require(`pdfjs-dist`);u=e.__toESM(u,1);let d=require(`react/jsx-runtime`);var f=2;function oe({hasRead:e}){let t=s.useLabels();return(0,d.jsxs)(`div`,{className:`${c.default.requireReadBanner} ${e?c.default.requireReadDone:``}`,children:[e?(0,d.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,d.jsx)(`path`,{d:`M3 8l3.5 3.5L13 4.5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}):(0,d.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,d.jsx)(`path`,{d:`M8 3v10M4 9l4 4 4-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,d.jsx)(`span`,{children:e?t.requireReadDone:t.requireReadPending})]})}var p=({file:e,workerSrc:s,sidebar:p,toolbar:m,onChangeFile:h,themeOverrides:se,defaultTheme:ce,defaultFit:g,language:le,className:_,style:ue,requireRead:v,onDocumentRead:y
|
|
1
|
+
const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../context/PDFViewerContext.cjs`),n=require(`../hooks/useScrollTracking.cjs`),r=require(`../hooks/useKeyboardShortcuts.cjs`),i=require(`../hooks/useTextLayer.cjs`),a=require(`../utils/url.cjs`),ee=require(`../hooks/useAnnotationLayer.cjs`),te=require(`../hooks/usePDFLoader.cjs`),ne=require(`../hooks/usePDFRenderer.cjs`),re=require(`../hooks/useOverlayRects.cjs`),o=require(`../utils/pdfFit.cjs`),ie=require(`../context/ThemeContext.cjs`),ae=require(`../context/LabelsContext.cjs`),s=require(`../hooks/useLabels.cjs`),c=require(`./PDFViewer.module.cjs`);let l=require(`react`);l=e.__toESM(l,1);let u=require(`pdfjs-dist`);u=e.__toESM(u,1);let d=require(`react/jsx-runtime`);var f=2;function oe({hasRead:e}){let t=s.useLabels();return(0,d.jsxs)(`div`,{className:`${c.default.requireReadBanner} ${e?c.default.requireReadDone:``}`,children:[e?(0,d.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,d.jsx)(`path`,{d:`M3 8l3.5 3.5L13 4.5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}):(0,d.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,d.jsx)(`path`,{d:`M8 3v10M4 9l4 4 4-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,d.jsx)(`span`,{children:e?t.requireReadDone:t.requireReadPending})]})}var p=({file:e,workerSrc:s,sidebar:p,toolbar:m,onChangeFile:h,themeOverrides:se,defaultTheme:ce,defaultFit:g,language:le,className:_,style:ue,requireRead:v,onDocumentRead:y})=>{(0,l.useEffect)(()=>{u.GlobalWorkerOptions.workerSrc=s},[s]);let[b,x]=(0,l.useState)(1),[S,C]=(0,l.useState)(0),[w,T]=(0,l.useState)(null),[E,de]=(0,l.useState)([]),[D,fe]=(0,l.useState)(!1),[O,pe]=(0,l.useState)(g??null),[k,A]=(0,l.useState)(null),[j,M]=(0,l.useState)(!1),N=(0,l.useRef)(!1),P=(0,l.useRef)(null),F=(0,l.useRef)([]),I=(0,l.useRef)([]),L=(0,l.useRef)(S);(0,l.useEffect)(()=>{L.current=S},[S]);let[R,z]=(0,l.useState)(null);R!==e&&(z(e),T(null),M(!1)),(0,l.useEffect)(()=>{N.current=!1},[e]);let{pdf:B,numPages:V,loading:me}=te.usePDFLoader(e);(0,l.useEffect)(()=>{B&&(F.current=Array(B.numPages).fill(null),I.current=Array(B.numPages).fill(null))},[B]),(0,l.useEffect)(()=>{!B||!g||!P.current||o.computeFit(g,B,P.current,L.current).then(x)},[B,g]);let H=(0,l.useRef)(O);(0,l.useEffect)(()=>{H.current=O},[O]),(0,l.useEffect)(()=>{if(!B||!P.current)return;let e=P.current,t=new ResizeObserver(()=>{H.current&&o.computeFit(H.current,B,e,L.current).then(x)});return t.observe(e),()=>t.disconnect()},[B]);let{currentPage:U,goToPage:W}=n.useScrollTracking({numPages:V,containerRef:P,pageRefs:F});(0,l.useEffect)(()=>{V===0||U<V||(v&&!j&&M(!0),N.current||(N.current=!0,y?.()))},[U,V,v,j,y]);let G=(0,l.useMemo)(()=>{if(V===0)return[];let e=new Set,t=Math.max(U-f,1),n=Math.min(U+f,V);for(let r=t;r<=n;r++)e.add(r);w&&e.add(w.page);for(let t of E)e.add(t.page);return Array.from(e).sort((e,t)=>e-t)},[U,V,w,E]),{pageSizes:he,renderedPages:K}=ne.usePDFRenderer({pdf:B,zoom:b,rotation:S,visiblePages:G,canvasRefs:I}),q=(0,l.useMemo)(()=>{let e=new Set(G);for(let t of K)e.add(t);return Array.from(e).sort((e,t)=>e-t)},[G,K]);r.useKeyboardShortcuts({pdf:B,currentPage:U,goToPage:W,setRotation:C});let ge=i.useTextLayer({pdf:B,zoom:b,rotation:S,mountedPages:q,canvasRefs:I}),{linkOverlays:_e,noteOverlays:J}=ee.useAnnotationLayer({pdf:B,zoom:b,rotation:S,mountedPages:q,goToPage:W});(0,l.useEffect)(()=>{if(!k)return;let e=()=>A(null),t=e=>{e.key===`Escape`&&A(null)};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t)}},[k]);let{overlayRect:Y,searchOverlays:ve}=re.useOverlayRects({pdf:B,highlight:w,searchMatches:E,zoom:b,rotation:S}),ye=(0,l.useCallback)((e,t)=>{(!e.url||!a.isSafeUrl(e.url))&&(t.preventDefault(),e.url||e._handleClick())},[]),X=(0,l.useRef)(null),Z=(0,l.useCallback)((e,t)=>{X.current&&clearTimeout(X.current);let n=t.clientY>window.innerHeight*.6;A({x:Math.min(t.clientX,window.innerWidth-304),y:n?window.innerHeight-t.clientY+8:t.clientY+12,above:n,contents:e.contents,title:e.title})},[]),Q=(0,l.useCallback)(()=>{X.current=setTimeout(()=>A(null),200)},[]),$=(0,l.useCallback)(e=>{T({page:e.page,pdfRect:e.pdfRect}),W(e.page)},[T,W]),be=(0,l.useMemo)(()=>({pdf:B,numPages:V,zoom:b,setZoom:x,rotation:S,setRotation:C,currentPage:U,goToPage:W,containerRef:P,canvasRefs:I,file:e,highlight:w,setHighlight:T,searchMatches:E,setSearchMatches:de,onChangeFile:h,sidebarCollapsed:D,setSidebarCollapsed:fe,fitMode:O,setFitMode:pe,navigationLocked:!!v&&!j}),[B,V,b,S,U,W,e,w,E,h,D,O,v,j]);return(0,d.jsx)(ie.ThemeProvider,{themeOverrides:se,defaultTheme:ce,children:(0,d.jsx)(ae.LabelsProvider,{language:le,children:(0,d.jsxs)(t.PDFViewerContext.Provider,{value:be,children:[(0,d.jsxs)(`div`,{className:`${c.default.appLayout}${_?` ${_}`:``}`,style:ue,children:[m&&(0,d.jsx)(`div`,{className:c.default.toolbar,children:m}),(0,d.jsxs)(`div`,{className:c.default.body,children:[p,(0,d.jsxs)(`div`,{className:c.default.scrollContainer,ref:P,children:[me&&(0,d.jsx)(`div`,{className:c.default.documentLoading}),Array.from({length:V},(e,t)=>{let n=K.has(t+1),r=he[t],i=q.includes(t+1);return(0,d.jsxs)(`div`,{className:c.default.pageWrapper,ref:e=>{F.current[t]=e},style:r?{width:r.width,height:r.height}:void 0,children:[r&&!n&&(0,d.jsx)(`div`,{className:c.default.pageSkeleton,style:{width:r.width,height:r.height}}),i&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`canvas`,{className:c.default.pageCanvas,ref:e=>{I.current[t]=e},style:{display:n?`block`:`none`}}),(0,d.jsx)(`div`,{className:`textLayer ${c.default.textLayer}`,ref:e=>{ge.current[t]=e}})]}),_e.filter(e=>e.page===t+1).map((e,t)=>(0,d.jsx)(`a`,{className:c.default.linkOverlay,href:e.url&&a.isSafeUrl(e.url)?e.url:`#`,target:`_blank`,rel:`noopener noreferrer`,style:{left:e.x,top:e.y,width:e.width,height:e.height},onClick:t=>ye(e,t)},t)),J.filter(e=>e.page===t+1).map((e,t)=>e.subtype===`Text`?(0,d.jsx)(`div`,{className:c.default.noteIconOverlay,style:{left:e.x,top:e.y,width:Math.max(e.width,26),height:Math.max(e.height,26)},onMouseEnter:t=>Z(e,t),onMouseLeave:Q,onClick:()=>$(e),children:(0,d.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 12 12`,fill:`none`,"aria-hidden":`true`,children:[(0,d.jsx)(`rect`,{x:`0.5`,y:`0.5`,width:`9`,height:`8`,rx:`1`,fill:`rgba(255,210,0,0.9)`,stroke:`rgba(160,120,0,0.7)`,strokeWidth:`1`}),(0,d.jsx)(`path`,{d:`M9.5 5.5v3l2.5-3z`,fill:`rgba(255,210,0,0.9)`,stroke:`rgba(160,120,0,0.7)`,strokeWidth:`1`}),(0,d.jsx)(`line`,{x1:`2`,y1:`3`,x2:`8`,y2:`3`,stroke:`rgba(90,60,0,0.8)`,strokeWidth:`1`,strokeLinecap:`round`}),(0,d.jsx)(`line`,{x1:`2`,y1:`5.5`,x2:`7`,y2:`5.5`,stroke:`rgba(90,60,0,0.8)`,strokeWidth:`1`,strokeLinecap:`round`})]})},t):(0,d.jsx)(`div`,{className:c.default.noteOverlay,style:{left:e.x,top:e.y,width:e.width,height:e.height},onMouseEnter:t=>Z(e,t),onMouseLeave:Q,onClick:()=>$(e)},t)),ve.filter(e=>e.page===t+1).map((e,t)=>(0,d.jsx)(`div`,{className:c.default.searchMatchOverlay,style:{left:e.x,top:e.y,width:e.width,height:e.height}},t)),w&&Y?.page===t+1&&(0,d.jsx)(`div`,{className:c.default.highlightOverlay,style:{left:Y.x,top:Y.y,width:Y.width,height:Y.height}})]},`${t}-${S}`)}),v&&(0,d.jsx)(oe,{hasRead:j})]})]})]}),k&&(0,d.jsxs)(`div`,{className:c.default.notePopover,style:k.above?{left:k.x,bottom:k.y}:{left:k.x,top:k.y},onMouseEnter:()=>{X.current&&clearTimeout(X.current)},onMouseLeave:Q,onClick:e=>e.stopPropagation(),children:[k.title&&(0,d.jsx)(`div`,{className:c.default.notePopoverTitle,children:k.title}),(0,d.jsx)(`p`,{className:c.default.notePopoverContent,children:k.contents})]})]})})})};exports.default=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`react`),n=require(`pdfjs-dist`);n=e.__toESM(n,1);function r(e
|
|
1
|
+
const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`react`),n=require(`pdfjs-dist`);n=e.__toESM(n,1);function r(e){let[r,i]=(0,t.useState)(null),[a,o]=(0,t.useState)(0),[s,c]=(0,t.useState)(!0);return(0,t.useEffect)(()=>{c(!0),i(null),o(0);let t=new FileReader;t.onload=async e=>{let t=new Uint8Array(e.target?.result);try{let e=await n.getDocument(t).promise;i(e),o(e.numPages)}catch(e){console.error(`Errore caricamento:`,e)}finally{c(!1)}},t.readAsArrayBuffer(e)},[e]),{pdf:r,numPages:a,loading:s}}exports.usePDFLoader=r;
|
|
@@ -3,262 +3,262 @@ import { useScrollTracking as t } from "../hooks/useScrollTracking.js";
|
|
|
3
3
|
import { useKeyboardShortcuts as n } from "../hooks/useKeyboardShortcuts.js";
|
|
4
4
|
import { useTextLayer as r } from "../hooks/useTextLayer.js";
|
|
5
5
|
import { isSafeUrl as i } from "../utils/url.js";
|
|
6
|
-
import { useAnnotationLayer as
|
|
7
|
-
import { usePDFLoader as
|
|
8
|
-
import { usePDFRenderer as
|
|
9
|
-
import { useOverlayRects as
|
|
10
|
-
import { computeFit as
|
|
11
|
-
import { ThemeProvider as
|
|
12
|
-
import { LabelsProvider as
|
|
13
|
-
import { useLabels as
|
|
14
|
-
import
|
|
15
|
-
import { useCallback as
|
|
16
|
-
import * as
|
|
17
|
-
import { Fragment as
|
|
6
|
+
import { useAnnotationLayer as ee } from "../hooks/useAnnotationLayer.js";
|
|
7
|
+
import { usePDFLoader as te } from "../hooks/usePDFLoader.js";
|
|
8
|
+
import { usePDFRenderer as ne } from "../hooks/usePDFRenderer.js";
|
|
9
|
+
import { useOverlayRects as re } from "../hooks/useOverlayRects.js";
|
|
10
|
+
import { computeFit as a } from "../utils/pdfFit.js";
|
|
11
|
+
import { ThemeProvider as ie } from "../context/ThemeContext.js";
|
|
12
|
+
import { LabelsProvider as ae } from "../context/LabelsContext.js";
|
|
13
|
+
import { useLabels as o } from "../hooks/useLabels.js";
|
|
14
|
+
import s from "./PDFViewer.module.js";
|
|
15
|
+
import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
16
|
+
import * as oe from "pdfjs-dist";
|
|
17
|
+
import { Fragment as se, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
18
18
|
//#region src/components/PDFViewer.tsx
|
|
19
|
-
var
|
|
20
|
-
function
|
|
21
|
-
let t =
|
|
22
|
-
return /* @__PURE__ */
|
|
23
|
-
className: `${
|
|
24
|
-
children: [e ? /* @__PURE__ */
|
|
19
|
+
var h = 2;
|
|
20
|
+
function ce({ hasRead: e }) {
|
|
21
|
+
let t = o();
|
|
22
|
+
return /* @__PURE__ */ m("div", {
|
|
23
|
+
className: `${s.requireReadBanner} ${e ? s.requireReadDone : ""}`,
|
|
24
|
+
children: [e ? /* @__PURE__ */ p("svg", {
|
|
25
25
|
width: "16",
|
|
26
26
|
height: "16",
|
|
27
27
|
viewBox: "0 0 16 16",
|
|
28
28
|
fill: "none",
|
|
29
29
|
"aria-hidden": "true",
|
|
30
|
-
children: /* @__PURE__ */
|
|
30
|
+
children: /* @__PURE__ */ p("path", {
|
|
31
31
|
d: "M3 8l3.5 3.5L13 4.5",
|
|
32
32
|
stroke: "currentColor",
|
|
33
33
|
strokeWidth: "2",
|
|
34
34
|
strokeLinecap: "round",
|
|
35
35
|
strokeLinejoin: "round"
|
|
36
36
|
})
|
|
37
|
-
}) : /* @__PURE__ */
|
|
37
|
+
}) : /* @__PURE__ */ p("svg", {
|
|
38
38
|
width: "16",
|
|
39
39
|
height: "16",
|
|
40
40
|
viewBox: "0 0 16 16",
|
|
41
41
|
fill: "none",
|
|
42
42
|
"aria-hidden": "true",
|
|
43
|
-
children: /* @__PURE__ */
|
|
43
|
+
children: /* @__PURE__ */ p("path", {
|
|
44
44
|
d: "M8 3v10M4 9l4 4 4-4",
|
|
45
45
|
stroke: "currentColor",
|
|
46
46
|
strokeWidth: "2",
|
|
47
47
|
strokeLinecap: "round",
|
|
48
48
|
strokeLinejoin: "round"
|
|
49
49
|
})
|
|
50
|
-
}), /* @__PURE__ */
|
|
50
|
+
}), /* @__PURE__ */ p("span", { children: e ? t.requireReadDone : t.requireReadPending })]
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, [
|
|
57
|
-
let [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, [
|
|
61
|
-
let [_e, ve] =
|
|
62
|
-
_e !==
|
|
63
|
-
|
|
64
|
-
}, [
|
|
65
|
-
let { pdf:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
!
|
|
70
|
-
}, [
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, [
|
|
75
|
-
if (!
|
|
76
|
-
let e =
|
|
77
|
-
|
|
53
|
+
var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, themeOverrides: ue, defaultTheme: de, defaultFit: y, language: fe, className: b, style: pe, requireRead: x, onDocumentRead: S }) => {
|
|
54
|
+
l(() => {
|
|
55
|
+
oe.GlobalWorkerOptions.workerSrc = g;
|
|
56
|
+
}, [g]);
|
|
57
|
+
let [C, w] = f(1), [T, E] = f(0), [D, O] = f(null), [k, me] = f([]), [A, he] = f(!1), [j, ge] = f(y ?? null), [M, N] = f(null), [P, F] = f(!1), I = d(!1), L = d(null), R = d([]), z = d([]), B = d(T);
|
|
58
|
+
l(() => {
|
|
59
|
+
B.current = T;
|
|
60
|
+
}, [T]);
|
|
61
|
+
let [_e, ve] = f(null);
|
|
62
|
+
_e !== o && (ve(o), O(null), F(!1)), l(() => {
|
|
63
|
+
I.current = !1;
|
|
64
|
+
}, [o]);
|
|
65
|
+
let { pdf: V, numPages: H, loading: ye } = te(o);
|
|
66
|
+
l(() => {
|
|
67
|
+
V && (R.current = Array(V.numPages).fill(null), z.current = Array(V.numPages).fill(null));
|
|
68
|
+
}, [V]), l(() => {
|
|
69
|
+
!V || !y || !L.current || a(y, V, L.current, B.current).then(w);
|
|
70
|
+
}, [V, y]);
|
|
71
|
+
let U = d(j);
|
|
72
|
+
l(() => {
|
|
73
|
+
U.current = j;
|
|
74
|
+
}, [j]), l(() => {
|
|
75
|
+
if (!V || !L.current) return;
|
|
76
|
+
let e = L.current, t = new ResizeObserver(() => {
|
|
77
|
+
U.current && a(U.current, V, e, B.current).then(w);
|
|
78
78
|
});
|
|
79
79
|
return t.observe(e), () => t.disconnect();
|
|
80
|
-
}, [
|
|
81
|
-
let { currentPage:
|
|
82
|
-
numPages:
|
|
83
|
-
containerRef:
|
|
84
|
-
pageRefs:
|
|
80
|
+
}, [V]);
|
|
81
|
+
let { currentPage: W, goToPage: G } = t({
|
|
82
|
+
numPages: H,
|
|
83
|
+
containerRef: L,
|
|
84
|
+
pageRefs: R
|
|
85
85
|
});
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
l(() => {
|
|
87
|
+
H === 0 || W < H || (x && !P && F(!0), I.current || (I.current = !0, S?.()));
|
|
88
88
|
}, [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
W,
|
|
90
|
+
H,
|
|
91
|
+
x,
|
|
92
|
+
P,
|
|
93
|
+
S
|
|
94
94
|
]);
|
|
95
|
-
let
|
|
96
|
-
if (
|
|
97
|
-
let e = /* @__PURE__ */ new Set(), t = Math.max(
|
|
95
|
+
let K = u(() => {
|
|
96
|
+
if (H === 0) return [];
|
|
97
|
+
let e = /* @__PURE__ */ new Set(), t = Math.max(W - h, 1), n = Math.min(W + h, H);
|
|
98
98
|
for (let r = t; r <= n; r++) e.add(r);
|
|
99
|
-
|
|
100
|
-
for (let t of
|
|
99
|
+
D && e.add(D.page);
|
|
100
|
+
for (let t of k) e.add(t.page);
|
|
101
101
|
return Array.from(e).sort((e, t) => e - t);
|
|
102
102
|
}, [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
]), { pageSizes: be, renderedPages:
|
|
108
|
-
pdf:
|
|
109
|
-
zoom:
|
|
110
|
-
rotation:
|
|
111
|
-
visiblePages:
|
|
112
|
-
canvasRefs:
|
|
113
|
-
}),
|
|
114
|
-
let e = new Set(
|
|
115
|
-
for (let t of
|
|
103
|
+
W,
|
|
104
|
+
H,
|
|
105
|
+
D,
|
|
106
|
+
k
|
|
107
|
+
]), { pageSizes: be, renderedPages: q } = ne({
|
|
108
|
+
pdf: V,
|
|
109
|
+
zoom: C,
|
|
110
|
+
rotation: T,
|
|
111
|
+
visiblePages: K,
|
|
112
|
+
canvasRefs: z
|
|
113
|
+
}), J = u(() => {
|
|
114
|
+
let e = new Set(K);
|
|
115
|
+
for (let t of q) e.add(t);
|
|
116
116
|
return Array.from(e).sort((e, t) => e - t);
|
|
117
|
-
}, [
|
|
117
|
+
}, [K, q]);
|
|
118
118
|
n({
|
|
119
|
-
pdf:
|
|
120
|
-
currentPage:
|
|
121
|
-
goToPage:
|
|
122
|
-
setRotation:
|
|
119
|
+
pdf: V,
|
|
120
|
+
currentPage: W,
|
|
121
|
+
goToPage: G,
|
|
122
|
+
setRotation: E
|
|
123
123
|
});
|
|
124
124
|
let xe = r({
|
|
125
|
-
pdf:
|
|
126
|
-
zoom:
|
|
127
|
-
rotation:
|
|
128
|
-
mountedPages:
|
|
129
|
-
canvasRefs:
|
|
130
|
-
}), { linkOverlays: Se, noteOverlays: Ce } =
|
|
131
|
-
pdf:
|
|
132
|
-
zoom:
|
|
133
|
-
rotation:
|
|
134
|
-
mountedPages:
|
|
135
|
-
goToPage:
|
|
125
|
+
pdf: V,
|
|
126
|
+
zoom: C,
|
|
127
|
+
rotation: T,
|
|
128
|
+
mountedPages: J,
|
|
129
|
+
canvasRefs: z
|
|
130
|
+
}), { linkOverlays: Se, noteOverlays: Ce } = ee({
|
|
131
|
+
pdf: V,
|
|
132
|
+
zoom: C,
|
|
133
|
+
rotation: T,
|
|
134
|
+
mountedPages: J,
|
|
135
|
+
goToPage: G
|
|
136
136
|
});
|
|
137
|
-
|
|
138
|
-
if (!
|
|
139
|
-
let e = () =>
|
|
140
|
-
e.key === "Escape" &&
|
|
137
|
+
l(() => {
|
|
138
|
+
if (!M) return;
|
|
139
|
+
let e = () => N(null), t = (e) => {
|
|
140
|
+
e.key === "Escape" && N(null);
|
|
141
141
|
};
|
|
142
142
|
return document.addEventListener("click", e), document.addEventListener("keydown", t), () => {
|
|
143
143
|
document.removeEventListener("click", e), document.removeEventListener("keydown", t);
|
|
144
144
|
};
|
|
145
|
-
}, [
|
|
146
|
-
let { overlayRect:
|
|
147
|
-
pdf:
|
|
148
|
-
highlight:
|
|
149
|
-
searchMatches:
|
|
150
|
-
zoom:
|
|
151
|
-
rotation:
|
|
152
|
-
}), Te =
|
|
145
|
+
}, [M]);
|
|
146
|
+
let { overlayRect: Y, searchOverlays: we } = re({
|
|
147
|
+
pdf: V,
|
|
148
|
+
highlight: D,
|
|
149
|
+
searchMatches: k,
|
|
150
|
+
zoom: C,
|
|
151
|
+
rotation: T
|
|
152
|
+
}), Te = c((e, t) => {
|
|
153
153
|
(!e.url || !i(e.url)) && (t.preventDefault(), e.url || e._handleClick());
|
|
154
|
-
}, []),
|
|
155
|
-
|
|
154
|
+
}, []), X = d(null), Z = c((e, t) => {
|
|
155
|
+
X.current && clearTimeout(X.current);
|
|
156
156
|
let n = t.clientY > window.innerHeight * .6;
|
|
157
|
-
|
|
157
|
+
N({
|
|
158
158
|
x: Math.min(t.clientX, window.innerWidth - 304),
|
|
159
159
|
y: n ? window.innerHeight - t.clientY + 8 : t.clientY + 12,
|
|
160
160
|
above: n,
|
|
161
161
|
contents: e.contents,
|
|
162
162
|
title: e.title
|
|
163
163
|
});
|
|
164
|
-
}, []),
|
|
165
|
-
|
|
166
|
-
}, []),
|
|
167
|
-
|
|
164
|
+
}, []), Q = c(() => {
|
|
165
|
+
X.current = setTimeout(() => N(null), 200);
|
|
166
|
+
}, []), $ = c((e) => {
|
|
167
|
+
O({
|
|
168
168
|
page: e.page,
|
|
169
169
|
pdfRect: e.pdfRect
|
|
170
|
-
}),
|
|
171
|
-
}, [
|
|
172
|
-
pdf:
|
|
173
|
-
numPages:
|
|
174
|
-
zoom:
|
|
175
|
-
setZoom:
|
|
176
|
-
rotation:
|
|
177
|
-
setRotation:
|
|
178
|
-
currentPage:
|
|
179
|
-
goToPage:
|
|
180
|
-
containerRef:
|
|
181
|
-
canvasRefs:
|
|
182
|
-
file:
|
|
183
|
-
highlight:
|
|
184
|
-
setHighlight:
|
|
185
|
-
searchMatches:
|
|
170
|
+
}), G(e.page);
|
|
171
|
+
}, [O, G]), Ee = u(() => ({
|
|
172
|
+
pdf: V,
|
|
173
|
+
numPages: H,
|
|
174
|
+
zoom: C,
|
|
175
|
+
setZoom: w,
|
|
176
|
+
rotation: T,
|
|
177
|
+
setRotation: E,
|
|
178
|
+
currentPage: W,
|
|
179
|
+
goToPage: G,
|
|
180
|
+
containerRef: L,
|
|
181
|
+
canvasRefs: z,
|
|
182
|
+
file: o,
|
|
183
|
+
highlight: D,
|
|
184
|
+
setHighlight: O,
|
|
185
|
+
searchMatches: k,
|
|
186
186
|
setSearchMatches: me,
|
|
187
|
-
onChangeFile:
|
|
188
|
-
sidebarCollapsed:
|
|
187
|
+
onChangeFile: v,
|
|
188
|
+
sidebarCollapsed: A,
|
|
189
189
|
setSidebarCollapsed: he,
|
|
190
|
-
fitMode:
|
|
190
|
+
fitMode: j,
|
|
191
191
|
setFitMode: ge,
|
|
192
|
-
navigationLocked: !!
|
|
192
|
+
navigationLocked: !!x && !P
|
|
193
193
|
}), [
|
|
194
|
+
V,
|
|
194
195
|
H,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
C,
|
|
197
|
+
T,
|
|
198
|
+
W,
|
|
198
199
|
G,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
o,
|
|
201
|
+
D,
|
|
202
|
+
k,
|
|
203
|
+
v,
|
|
202
204
|
A,
|
|
203
|
-
y,
|
|
204
205
|
j,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
F
|
|
206
|
+
x,
|
|
207
|
+
P
|
|
208
208
|
]);
|
|
209
|
-
return /* @__PURE__ */
|
|
210
|
-
themeOverrides:
|
|
211
|
-
defaultTheme:
|
|
212
|
-
children: /* @__PURE__ */
|
|
213
|
-
language:
|
|
214
|
-
children: /* @__PURE__ */
|
|
215
|
-
value:
|
|
216
|
-
children: [/* @__PURE__ */
|
|
217
|
-
className: `${
|
|
218
|
-
style:
|
|
219
|
-
children: [
|
|
220
|
-
className:
|
|
221
|
-
children:
|
|
222
|
-
}), /* @__PURE__ */
|
|
223
|
-
className:
|
|
224
|
-
children: [
|
|
225
|
-
className:
|
|
226
|
-
ref:
|
|
209
|
+
return /* @__PURE__ */ p(ie, {
|
|
210
|
+
themeOverrides: ue,
|
|
211
|
+
defaultTheme: de,
|
|
212
|
+
children: /* @__PURE__ */ p(ae, {
|
|
213
|
+
language: fe,
|
|
214
|
+
children: /* @__PURE__ */ m(e.Provider, {
|
|
215
|
+
value: Ee,
|
|
216
|
+
children: [/* @__PURE__ */ m("div", {
|
|
217
|
+
className: `${s.appLayout}${b ? ` ${b}` : ""}`,
|
|
218
|
+
style: pe,
|
|
219
|
+
children: [_ && /* @__PURE__ */ p("div", {
|
|
220
|
+
className: s.toolbar,
|
|
221
|
+
children: _
|
|
222
|
+
}), /* @__PURE__ */ m("div", {
|
|
223
|
+
className: s.body,
|
|
224
|
+
children: [le, /* @__PURE__ */ m("div", {
|
|
225
|
+
className: s.scrollContainer,
|
|
226
|
+
ref: L,
|
|
227
227
|
children: [
|
|
228
|
-
ye && /* @__PURE__ */
|
|
229
|
-
Array.from({ length:
|
|
230
|
-
let n =
|
|
231
|
-
return /* @__PURE__ */
|
|
232
|
-
className:
|
|
228
|
+
ye && /* @__PURE__ */ p("div", { className: s.documentLoading }),
|
|
229
|
+
Array.from({ length: H }, (e, t) => {
|
|
230
|
+
let n = q.has(t + 1), r = be[t], ee = J.includes(t + 1);
|
|
231
|
+
return /* @__PURE__ */ m("div", {
|
|
232
|
+
className: s.pageWrapper,
|
|
233
233
|
ref: (e) => {
|
|
234
|
-
|
|
234
|
+
R.current[t] = e;
|
|
235
235
|
},
|
|
236
236
|
style: r ? {
|
|
237
237
|
width: r.width,
|
|
238
238
|
height: r.height
|
|
239
239
|
} : void 0,
|
|
240
240
|
children: [
|
|
241
|
-
r && !n && /* @__PURE__ */
|
|
242
|
-
className:
|
|
241
|
+
r && !n && /* @__PURE__ */ p("div", {
|
|
242
|
+
className: s.pageSkeleton,
|
|
243
243
|
style: {
|
|
244
244
|
width: r.width,
|
|
245
245
|
height: r.height
|
|
246
246
|
}
|
|
247
247
|
}),
|
|
248
|
-
|
|
249
|
-
className:
|
|
248
|
+
ee && /* @__PURE__ */ m(se, { children: [/* @__PURE__ */ p("canvas", {
|
|
249
|
+
className: s.pageCanvas,
|
|
250
250
|
ref: (e) => {
|
|
251
|
-
|
|
251
|
+
z.current[t] = e;
|
|
252
252
|
},
|
|
253
253
|
style: { display: n ? "block" : "none" }
|
|
254
|
-
}), /* @__PURE__ */
|
|
255
|
-
className: `textLayer ${
|
|
254
|
+
}), /* @__PURE__ */ p("div", {
|
|
255
|
+
className: `textLayer ${s.textLayer}`,
|
|
256
256
|
ref: (e) => {
|
|
257
257
|
xe.current[t] = e;
|
|
258
258
|
}
|
|
259
259
|
})] }),
|
|
260
|
-
Se.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */
|
|
261
|
-
className:
|
|
260
|
+
Se.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ p("a", {
|
|
261
|
+
className: s.linkOverlay,
|
|
262
262
|
href: e.url && i(e.url) ? e.url : "#",
|
|
263
263
|
target: "_blank",
|
|
264
264
|
rel: "noopener noreferrer",
|
|
@@ -270,25 +270,25 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
270
270
|
},
|
|
271
271
|
onClick: (t) => Te(e, t)
|
|
272
272
|
}, t)),
|
|
273
|
-
Ce.filter((e) => e.page === t + 1).map((e, t) => e.subtype === "Text" ? /* @__PURE__ */
|
|
274
|
-
className:
|
|
273
|
+
Ce.filter((e) => e.page === t + 1).map((e, t) => e.subtype === "Text" ? /* @__PURE__ */ p("div", {
|
|
274
|
+
className: s.noteIconOverlay,
|
|
275
275
|
style: {
|
|
276
276
|
left: e.x,
|
|
277
277
|
top: e.y,
|
|
278
278
|
width: Math.max(e.width, 26),
|
|
279
279
|
height: Math.max(e.height, 26)
|
|
280
280
|
},
|
|
281
|
-
onMouseEnter: (t) =>
|
|
282
|
-
onMouseLeave:
|
|
283
|
-
onClick: () =>
|
|
284
|
-
children: /* @__PURE__ */
|
|
281
|
+
onMouseEnter: (t) => Z(e, t),
|
|
282
|
+
onMouseLeave: Q,
|
|
283
|
+
onClick: () => $(e),
|
|
284
|
+
children: /* @__PURE__ */ m("svg", {
|
|
285
285
|
width: "22",
|
|
286
286
|
height: "22",
|
|
287
287
|
viewBox: "0 0 12 12",
|
|
288
288
|
fill: "none",
|
|
289
289
|
"aria-hidden": "true",
|
|
290
290
|
children: [
|
|
291
|
-
/* @__PURE__ */
|
|
291
|
+
/* @__PURE__ */ p("rect", {
|
|
292
292
|
x: "0.5",
|
|
293
293
|
y: "0.5",
|
|
294
294
|
width: "9",
|
|
@@ -298,13 +298,13 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
298
298
|
stroke: "rgba(160,120,0,0.7)",
|
|
299
299
|
strokeWidth: "1"
|
|
300
300
|
}),
|
|
301
|
-
/* @__PURE__ */
|
|
301
|
+
/* @__PURE__ */ p("path", {
|
|
302
302
|
d: "M9.5 5.5v3l2.5-3z",
|
|
303
303
|
fill: "rgba(255,210,0,0.9)",
|
|
304
304
|
stroke: "rgba(160,120,0,0.7)",
|
|
305
305
|
strokeWidth: "1"
|
|
306
306
|
}),
|
|
307
|
-
/* @__PURE__ */
|
|
307
|
+
/* @__PURE__ */ p("line", {
|
|
308
308
|
x1: "2",
|
|
309
309
|
y1: "3",
|
|
310
310
|
x2: "8",
|
|
@@ -313,7 +313,7 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
313
313
|
strokeWidth: "1",
|
|
314
314
|
strokeLinecap: "round"
|
|
315
315
|
}),
|
|
316
|
-
/* @__PURE__ */
|
|
316
|
+
/* @__PURE__ */ p("line", {
|
|
317
317
|
x1: "2",
|
|
318
318
|
y1: "5.5",
|
|
319
319
|
x2: "7",
|
|
@@ -324,20 +324,20 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
324
324
|
})
|
|
325
325
|
]
|
|
326
326
|
})
|
|
327
|
-
}, t) : /* @__PURE__ */
|
|
328
|
-
className:
|
|
327
|
+
}, t) : /* @__PURE__ */ p("div", {
|
|
328
|
+
className: s.noteOverlay,
|
|
329
329
|
style: {
|
|
330
330
|
left: e.x,
|
|
331
331
|
top: e.y,
|
|
332
332
|
width: e.width,
|
|
333
333
|
height: e.height
|
|
334
334
|
},
|
|
335
|
-
onMouseEnter: (t) =>
|
|
336
|
-
onMouseLeave:
|
|
337
|
-
onClick: () =>
|
|
335
|
+
onMouseEnter: (t) => Z(e, t),
|
|
336
|
+
onMouseLeave: Q,
|
|
337
|
+
onClick: () => $(e)
|
|
338
338
|
}, t)),
|
|
339
|
-
we.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */
|
|
340
|
-
className:
|
|
339
|
+
we.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ p("div", {
|
|
340
|
+
className: s.searchMatchOverlay,
|
|
341
341
|
style: {
|
|
342
342
|
left: e.x,
|
|
343
343
|
top: e.y,
|
|
@@ -345,42 +345,42 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
345
345
|
height: e.height
|
|
346
346
|
}
|
|
347
347
|
}, t)),
|
|
348
|
-
|
|
349
|
-
className:
|
|
348
|
+
D && Y?.page === t + 1 && /* @__PURE__ */ p("div", {
|
|
349
|
+
className: s.highlightOverlay,
|
|
350
350
|
style: {
|
|
351
|
-
left:
|
|
352
|
-
top:
|
|
353
|
-
width:
|
|
354
|
-
height:
|
|
351
|
+
left: Y.x,
|
|
352
|
+
top: Y.y,
|
|
353
|
+
width: Y.width,
|
|
354
|
+
height: Y.height
|
|
355
355
|
}
|
|
356
356
|
})
|
|
357
357
|
]
|
|
358
|
-
}, `${t}-${
|
|
358
|
+
}, `${t}-${T}`);
|
|
359
359
|
}),
|
|
360
|
-
|
|
360
|
+
x && /* @__PURE__ */ p(ce, { hasRead: P })
|
|
361
361
|
]
|
|
362
362
|
})]
|
|
363
363
|
})]
|
|
364
|
-
}),
|
|
365
|
-
className:
|
|
366
|
-
style:
|
|
367
|
-
left:
|
|
368
|
-
bottom:
|
|
364
|
+
}), M && /* @__PURE__ */ m("div", {
|
|
365
|
+
className: s.notePopover,
|
|
366
|
+
style: M.above ? {
|
|
367
|
+
left: M.x,
|
|
368
|
+
bottom: M.y
|
|
369
369
|
} : {
|
|
370
|
-
left:
|
|
371
|
-
top:
|
|
370
|
+
left: M.x,
|
|
371
|
+
top: M.y
|
|
372
372
|
},
|
|
373
373
|
onMouseEnter: () => {
|
|
374
|
-
|
|
374
|
+
X.current && clearTimeout(X.current);
|
|
375
375
|
},
|
|
376
|
-
onMouseLeave:
|
|
376
|
+
onMouseLeave: Q,
|
|
377
377
|
onClick: (e) => e.stopPropagation(),
|
|
378
|
-
children: [
|
|
379
|
-
className:
|
|
380
|
-
children:
|
|
381
|
-
}), /* @__PURE__ */
|
|
382
|
-
className:
|
|
383
|
-
children:
|
|
378
|
+
children: [M.title && /* @__PURE__ */ p("div", {
|
|
379
|
+
className: s.notePopoverTitle,
|
|
380
|
+
children: M.title
|
|
381
|
+
}), /* @__PURE__ */ p("p", {
|
|
382
|
+
className: s.notePopoverContent,
|
|
383
|
+
children: M.contents
|
|
384
384
|
})]
|
|
385
385
|
})]
|
|
386
386
|
})
|
|
@@ -388,4 +388,4 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
388
388
|
});
|
|
389
389
|
};
|
|
390
390
|
//#endregion
|
|
391
|
-
export {
|
|
391
|
+
export { g as default };
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { useEffect as e, useState as t } from "react";
|
|
2
2
|
import * as n from "pdfjs-dist";
|
|
3
3
|
//#region src/hooks/usePDFLoader.ts
|
|
4
|
-
function r(r
|
|
5
|
-
let [
|
|
4
|
+
function r(r) {
|
|
5
|
+
let [i, a] = t(null), [o, s] = t(0), [c, l] = t(!0);
|
|
6
6
|
return e(() => {
|
|
7
|
-
|
|
7
|
+
l(!0), a(null), s(0);
|
|
8
8
|
let e = new FileReader();
|
|
9
9
|
e.onload = async (e) => {
|
|
10
10
|
let t = new Uint8Array(e.target?.result);
|
|
11
11
|
try {
|
|
12
|
-
let e = await n.getDocument(
|
|
13
|
-
|
|
14
|
-
...i ? { wasmUrl: i } : {}
|
|
15
|
-
}).promise;
|
|
16
|
-
o(e), c(e.numPages);
|
|
12
|
+
let e = await n.getDocument(t).promise;
|
|
13
|
+
a(e), s(e.numPages);
|
|
17
14
|
} catch (e) {
|
|
18
15
|
console.error("Errore caricamento:", e);
|
|
19
16
|
} finally {
|
|
20
|
-
|
|
17
|
+
l(!1);
|
|
21
18
|
}
|
|
22
19
|
}, e.readAsArrayBuffer(r);
|
|
23
|
-
}, [r
|
|
24
|
-
pdf:
|
|
25
|
-
numPages:
|
|
26
|
-
loading:
|
|
20
|
+
}, [r]), {
|
|
21
|
+
pdf: i,
|
|
22
|
+
numPages: o,
|
|
23
|
+
loading: c
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-tsx",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"description": "A fully-featured, composable PDF viewer component for React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"dev": "vite",
|
|
33
33
|
"watch": "tsc -b --watch",
|
|
34
34
|
"build": "vite build",
|
|
35
|
-
"tsc": "tsc
|
|
35
|
+
"tsc": "tsc --noEmit",
|
|
36
36
|
"lint": "eslint .",
|
|
37
37
|
"format": "prettier --write \"src/**/*.{ts,tsx,css}\"",
|
|
38
38
|
"preview": "vite preview"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"pdfjs-dist": "
|
|
41
|
+
"pdfjs-dist": "~5.6.205",
|
|
42
42
|
"react": ">=18",
|
|
43
43
|
"react-dom": ">=18"
|
|
44
44
|
},
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
53
53
|
"eslint-plugin-react-refresh": "^0.5.2",
|
|
54
54
|
"globals": "^16.5.0",
|
|
55
|
-
"playwright": "^1.60.0",
|
|
56
55
|
"prettier": "^3.8.3",
|
|
57
56
|
"react-icons": "^5.6.0",
|
|
58
57
|
"react-scan": "^0.5.6",
|