@pdf-viewer/react 1.4.0-beta.5 → 1.4.0-beta.6
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,44 +1,46 @@
|
|
|
1
1
|
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as C, useState as
|
|
3
|
-
import { useLoadPdf as
|
|
4
|
-
import { usePdfProperties as
|
|
5
|
-
import { appConsole as
|
|
6
|
-
const
|
|
2
|
+
import { createContext as C, useState as l, useEffect as h, useMemo as S, useContext as v } from "react";
|
|
3
|
+
import { useLoadPdf as D } from "../utils/hooks/useLoadPdf.js";
|
|
4
|
+
import { usePdfProperties as F } from "../utils/hooks/usePdfProperties.js";
|
|
5
|
+
import { appConsole as M } from "../utils/appConsole.js";
|
|
6
|
+
const m = C({
|
|
7
7
|
pdf: void 0,
|
|
8
8
|
pages: /* @__PURE__ */ new Map(),
|
|
9
9
|
setPdfSrc: () => {
|
|
10
10
|
},
|
|
11
11
|
setFilename: () => {
|
|
12
12
|
},
|
|
13
|
-
loading: !1
|
|
14
|
-
|
|
13
|
+
loading: !1,
|
|
14
|
+
loaderProgress: 0
|
|
15
|
+
}), R = ({
|
|
15
16
|
children: t,
|
|
16
17
|
src: e,
|
|
17
|
-
characterMap:
|
|
18
|
+
characterMap: u,
|
|
18
19
|
onLoadError: c,
|
|
19
|
-
onLoaded:
|
|
20
|
+
onLoaded: P
|
|
20
21
|
}) => {
|
|
21
|
-
const [o,
|
|
22
|
+
const [o, n] = l(e), { pdf: r, pages: s, loading: i, loadingProgress: p } = D(o, u, { onLoadError: c, onLoaded: P }), [d, f] = l(), a = F(o, r, d);
|
|
22
23
|
h(() => {
|
|
23
|
-
f(e == null ? void 0 : e.split("/").pop()),
|
|
24
|
+
f(e == null ? void 0 : e.split("/").pop()), n(e);
|
|
24
25
|
}, [e]);
|
|
25
|
-
const
|
|
26
|
-
pdf:
|
|
26
|
+
const g = S(() => ({
|
|
27
|
+
pdf: r,
|
|
27
28
|
pages: s,
|
|
28
29
|
pdfSrc: o,
|
|
29
|
-
setPdfSrc:
|
|
30
|
-
pdfProperties:
|
|
30
|
+
setPdfSrc: n,
|
|
31
|
+
pdfProperties: a,
|
|
31
32
|
setFilename: f,
|
|
32
|
-
filename:
|
|
33
|
-
loading: i
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
filename: d,
|
|
34
|
+
loading: i,
|
|
35
|
+
loaderProgress: p
|
|
36
|
+
}), [r, s, o, a, i, p]);
|
|
37
|
+
return /* @__PURE__ */ x(m.Provider, { value: g, children: o ? t : null });
|
|
38
|
+
}, b = () => {
|
|
39
|
+
const t = v(m);
|
|
40
|
+
return t.pdfSrc || M.error("Please use this hooks inside children component of RPDocument"), t;
|
|
39
41
|
};
|
|
40
42
|
export {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
R as DocumentProvider,
|
|
44
|
+
m as default,
|
|
45
|
+
b as useDocumentContext
|
|
44
46
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as g, useCallback as h, useEffect as E } from "react";
|
|
2
2
|
import { appConsole as l } from "../appConsole.js";
|
|
3
|
-
const A = /* @__PURE__ */ new Date("2025-04-
|
|
3
|
+
const A = /* @__PURE__ */ new Date("2025-04-18T03:13:50.431Z"), d = "Please visit https://www.react-pdf.dev/license-management/ to generate a new license key.", o = {
|
|
4
4
|
invalidLicense: `You are currently using without a valid license. ${d}`,
|
|
5
5
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
|
|
6
6
|
expired: `Your license key has expired. ${d}`,
|
|
@@ -1,50 +1,56 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import * as
|
|
3
|
-
import { getThumbnailViewport as
|
|
4
|
-
import { useConfigContext as
|
|
5
|
-
const
|
|
6
|
-
const [
|
|
7
|
-
return
|
|
8
|
-
if (!
|
|
1
|
+
import { useState as l, useRef as E, useEffect as k } from "react";
|
|
2
|
+
import * as I from "pdfjs-dist";
|
|
3
|
+
import { getThumbnailViewport as N } from "../getThumbnailViewport.js";
|
|
4
|
+
import { useConfigContext as S } from "../../contexts/ConfigContext.js";
|
|
5
|
+
const A = (d, e, L = {}) => {
|
|
6
|
+
const [r, y] = l(), { workerUrlAdded: p } = S(), [C, w] = l(/* @__PURE__ */ new Map()), i = E(), [T, m] = l(0), [f, b] = l(!1), { onLoadError: g, onLoaded: a } = L;
|
|
7
|
+
return k(() => {
|
|
8
|
+
if (!p || !d)
|
|
9
9
|
return;
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
url:
|
|
13
|
-
cMapPacked: (
|
|
14
|
-
...(
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
i.current = Date.now();
|
|
11
|
+
const t = i.current, P = {
|
|
12
|
+
url: d,
|
|
13
|
+
cMapPacked: (e == null ? void 0 : e.isCompressed) ?? !0,
|
|
14
|
+
...(e == null ? void 0 : e.url) && { cMapUrl: e.url }
|
|
15
|
+
}, n = I.getDocument(P);
|
|
16
|
+
n.onProgress = (o) => {
|
|
17
|
+
if (t === i.current) {
|
|
18
|
+
const { loaded: c, total: u } = o, x = u ? Math.min(100, Math.round(c / u * 100)) : 0;
|
|
19
|
+
m(x);
|
|
20
|
+
}
|
|
21
|
+
}, b(!0), m(0);
|
|
22
|
+
const s = n.promise.then((o) => (t === i.current && (y(o), m(100)), a && a(o), o)).catch((o) => {
|
|
23
|
+
g && g(o);
|
|
24
|
+
}).finally(() => b(!1));
|
|
20
25
|
return () => {
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
s.finally(() => {
|
|
27
|
+
n.destroy();
|
|
23
28
|
});
|
|
24
29
|
};
|
|
25
|
-
}, [
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
|
|
30
|
+
}, [d, p, g, a]), k(() => {
|
|
31
|
+
const t = /* @__PURE__ */ new Map();
|
|
32
|
+
if (!r || f) {
|
|
33
|
+
w(t);
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
31
|
-
const
|
|
32
|
-
for (let
|
|
33
|
-
const
|
|
34
|
-
|
|
36
|
+
const P = r.numPages, n = [];
|
|
37
|
+
for (let s = 1; s <= P; s++) {
|
|
38
|
+
const o = r.getPage(s);
|
|
39
|
+
n.push(o);
|
|
35
40
|
}
|
|
36
|
-
Promise.all(
|
|
37
|
-
|
|
38
|
-
const { thumbnailViewport:
|
|
39
|
-
|
|
40
|
-
}),
|
|
41
|
+
Promise.all(n).then((s) => {
|
|
42
|
+
s.map((o) => {
|
|
43
|
+
const { thumbnailViewport: c, scale: u } = N(o);
|
|
44
|
+
t.set(o.pageNumber, { page: o, thumbnailViewport: c, thumbnailScale: u });
|
|
45
|
+
}), w(t);
|
|
41
46
|
});
|
|
42
|
-
}, [
|
|
43
|
-
pdf:
|
|
44
|
-
pages:
|
|
45
|
-
loading:
|
|
47
|
+
}, [r, f]), {
|
|
48
|
+
pdf: r,
|
|
49
|
+
pages: C,
|
|
50
|
+
loading: f,
|
|
51
|
+
loadingProgress: T
|
|
46
52
|
};
|
|
47
53
|
};
|
|
48
54
|
export {
|
|
49
|
-
|
|
55
|
+
A as useLoadPdf
|
|
50
56
|
};
|