@pdf-viewer/react 1.12.0-beta.0 → 1.12.0-beta.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/dist/components/page/CustomElement.js +7 -7
- package/dist/contexts/ElementPageContext.js +95 -51
- package/dist/types/utils/getElementPositionInPage.d.ts +5 -0
- package/dist/types/utils/types.d.ts +1 -0
- package/dist/utils/getElementPositionInPage.js +41 -0
- package/dist/utils/hooks/useLicense.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as r, Fragment as c } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as l, useMemo as i, useEffect as f } from "react";
|
|
3
3
|
import { useElementPageContext as a } from "../../contexts/ElementPageContext.js";
|
|
4
4
|
const d = ({ child: e }) => {
|
|
@@ -6,16 +6,16 @@ const d = ({ child: e }) => {
|
|
|
6
6
|
return f(() => {
|
|
7
7
|
var o;
|
|
8
8
|
return (o = t.current) == null || o.appendChild(e), () => {
|
|
9
|
-
var
|
|
10
|
-
(
|
|
9
|
+
var n;
|
|
10
|
+
(n = t.current) == null || n.removeChild(e);
|
|
11
11
|
};
|
|
12
|
-
}, [e]), /* @__PURE__ */
|
|
12
|
+
}, [e]), /* @__PURE__ */ r("div", { ref: t });
|
|
13
13
|
}, h = ({ pageNumber: e }) => {
|
|
14
|
-
const { elementList: t } = a(), o = l(null),
|
|
14
|
+
const { elementList: t } = a(), o = l(null), n = i(() => {
|
|
15
15
|
var m;
|
|
16
|
-
return (m = t[e]) == null ? void 0 : m.map((u, s) => u instanceof HTMLElement ? /* @__PURE__ */
|
|
16
|
+
return (m = t[e]) == null ? void 0 : m.map((u, s) => u instanceof HTMLElement ? /* @__PURE__ */ r(d, { child: u }, s) : /* @__PURE__ */ r("div", { children: u }, s));
|
|
17
17
|
}, [t, e]);
|
|
18
|
-
return
|
|
18
|
+
return n ? /* @__PURE__ */ r(c, { children: /* @__PURE__ */ r("div", { ref: o, "data-rp": `page-${e}-customElement`, children: n.map((m) => m) }) }) : null;
|
|
19
19
|
};
|
|
20
20
|
export {
|
|
21
21
|
h as CustomElement
|
|
@@ -1,76 +1,120 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { LicenseType as
|
|
4
|
-
import { useDimensionPagesContext as
|
|
5
|
-
import { usePagesRotateContext as
|
|
6
|
-
import { useLicenseContext as
|
|
7
|
-
import { useZoomContext as
|
|
8
|
-
import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { jsx as k } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as z, useState as H, useCallback as p, useContext as N, useRef as U, useMemo as q } from "react";
|
|
3
|
+
import { ScrollMode as g, LicenseType as B } from "../utils/types.js";
|
|
4
|
+
import { useDimensionPagesContext as J } from "./DimensionPagesContext.js";
|
|
5
|
+
import { usePagesRotateContext as K } from "./PagesRotateContext.js";
|
|
6
|
+
import { useLicenseContext as Q } from "./LicenseContext.js";
|
|
7
|
+
import { useZoomContext as X } from "./ZoomContext.js";
|
|
8
|
+
import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as x } from "../utils/const.js";
|
|
9
|
+
import { getScrollDistance as w } from "../utils/getScrollDistance.js";
|
|
10
|
+
import { useLayoutContainer as Y } from "./LayoutContainerContext.js";
|
|
11
|
+
import { useScrollModeContext as $ } from "./ScrollModeContext.js";
|
|
12
|
+
import { getElementPagePosition as ee } from "../utils/getElementPositionInPage.js";
|
|
13
|
+
import { useViewModeContext as te } from "./ViewModeContext.js";
|
|
14
|
+
import { useVirtualScrollContext as oe } from "./VirtualScrollContext.js";
|
|
15
|
+
const S = z(void 0), he = ({ children: i }) => {
|
|
16
|
+
const [l, c] = H({}), { widths: t, heights: r } = J(), { pagesRef: m } = Y(), { scrollMode: C } = $(), { pageRotate: u } = K(), { currentZoom: a } = X(), { columnCount: R } = te(), { pageScrollElementRef: I, virtualScrollableElementRef: T } = oe(), M = p(
|
|
17
|
+
(e, s, o = { behavior: "smooth" }) => {
|
|
18
|
+
var v;
|
|
19
|
+
const n = T || I;
|
|
20
|
+
if (!m || !n)
|
|
21
|
+
return;
|
|
22
|
+
const L = (v = l[e]) == null ? void 0 : v[s];
|
|
23
|
+
if (!L)
|
|
24
|
+
return;
|
|
25
|
+
let f = 0, P = 0;
|
|
26
|
+
if (C === g.VERTICAL_SCROLLING) {
|
|
27
|
+
const E = e - 1, d = R, W = E % d, j = Math.floor(E / d);
|
|
28
|
+
f = w(r, j), P = w(t, W);
|
|
29
|
+
}
|
|
30
|
+
C === g.HORIZONTAL_SCROLLING && (P = t.slice(0, e - 1).reduce((E, d) => E + d, 0));
|
|
31
|
+
const _ = {
|
|
32
|
+
height: r[e - 1],
|
|
33
|
+
width: t[e - 1]
|
|
34
|
+
}, D = u[e], { left: G, top: Z } = ee(
|
|
35
|
+
_,
|
|
36
|
+
m,
|
|
37
|
+
L,
|
|
38
|
+
D,
|
|
39
|
+
a
|
|
40
|
+
), V = P + G, b = f + Z, F = {
|
|
41
|
+
left: Math.max(V, 0),
|
|
42
|
+
top: Math.max(b, 0)
|
|
43
|
+
};
|
|
44
|
+
n.scrollTo({
|
|
45
|
+
...F,
|
|
46
|
+
behavior: o.behavior
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
[l, r, t, m, u, a, C]
|
|
50
|
+
), A = p(
|
|
51
|
+
(e, s) => {
|
|
52
|
+
c((o) => {
|
|
53
|
+
const n = { width: t[e], height: r[e] };
|
|
14
54
|
return {
|
|
15
|
-
...
|
|
16
|
-
[e]:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
55
|
+
...o,
|
|
56
|
+
[e]: s(
|
|
57
|
+
o[e],
|
|
58
|
+
n,
|
|
59
|
+
u[e],
|
|
60
|
+
a * 100
|
|
21
61
|
)
|
|
22
62
|
};
|
|
23
63
|
});
|
|
24
64
|
},
|
|
25
|
-
[t,
|
|
26
|
-
),
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return delete
|
|
65
|
+
[t, r, a, u]
|
|
66
|
+
), O = p((e) => {
|
|
67
|
+
c((s) => {
|
|
68
|
+
const o = { ...s };
|
|
69
|
+
return delete o[e], o;
|
|
30
70
|
});
|
|
31
|
-
}, []),
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
return
|
|
71
|
+
}, []), y = p((e, s) => {
|
|
72
|
+
c((o) => {
|
|
73
|
+
const n = { ...o };
|
|
74
|
+
return n[e] = n[e].filter((L, f) => f !== s), n;
|
|
35
75
|
});
|
|
36
76
|
}, []);
|
|
37
|
-
return /* @__PURE__ */
|
|
38
|
-
|
|
77
|
+
return /* @__PURE__ */ k(
|
|
78
|
+
S.Provider,
|
|
39
79
|
{
|
|
40
|
-
value: { updateElement:
|
|
41
|
-
children:
|
|
80
|
+
value: { updateElement: A, clearElements: O, removeElement: y, elementList: l, scrollToElement: M },
|
|
81
|
+
children: i
|
|
42
82
|
}
|
|
43
83
|
);
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
84
|
+
}, h = () => {
|
|
85
|
+
}, Ce = () => {
|
|
86
|
+
const i = N(S), { type: l, validating: c } = Q(), t = U(0), r = q(() => {
|
|
87
|
+
if (c !== !1)
|
|
48
88
|
return {
|
|
49
|
-
updateElement:
|
|
50
|
-
clearElements:
|
|
51
|
-
removeElement:
|
|
52
|
-
elementList: {}
|
|
89
|
+
updateElement: h,
|
|
90
|
+
clearElements: h,
|
|
91
|
+
removeElement: h,
|
|
92
|
+
elementList: {},
|
|
93
|
+
scrollToElement: h
|
|
53
94
|
};
|
|
54
|
-
if (!(
|
|
95
|
+
if (!(l !== B.Developer))
|
|
55
96
|
return {
|
|
56
97
|
updateElement: () => {
|
|
57
|
-
t.current === 0 && (console.error(
|
|
98
|
+
t.current === 0 && (console.error(x), t.current++);
|
|
58
99
|
},
|
|
59
100
|
clearElements: () => {
|
|
60
|
-
t.current === 0 && (console.error(
|
|
101
|
+
t.current === 0 && (console.error(x), t.current++);
|
|
61
102
|
},
|
|
62
103
|
removeElement: () => {
|
|
63
|
-
t.current === 0 && (console.error(
|
|
104
|
+
t.current === 0 && (console.error(x), t.current++);
|
|
64
105
|
},
|
|
65
|
-
elementList: {}
|
|
106
|
+
elementList: {},
|
|
107
|
+
scrollToElement: () => {
|
|
108
|
+
t.current === 0 && (console.error(x), t.current++);
|
|
109
|
+
}
|
|
66
110
|
};
|
|
67
|
-
}, [
|
|
68
|
-
if (!
|
|
111
|
+
}, [l, c]);
|
|
112
|
+
if (!i)
|
|
69
113
|
throw new Error("useElementPageContext must be used within a ElementPageProvider");
|
|
70
|
-
return
|
|
114
|
+
return r || i;
|
|
71
115
|
};
|
|
72
116
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
117
|
+
S as ElementPageContext,
|
|
118
|
+
he as ElementPageProvider,
|
|
119
|
+
Ce as useElementPageContext
|
|
76
120
|
};
|
|
@@ -665,6 +665,7 @@ export interface useElementPage {
|
|
|
665
665
|
removeElement: (pageNumber: number, index: number) => void;
|
|
666
666
|
clearElements: (pageNumber: number) => void;
|
|
667
667
|
elementList: Record<number, Array<HTMLElement | JSX.Element>>;
|
|
668
|
+
scrollToElement: (page: number, index: number) => void;
|
|
668
669
|
}
|
|
669
670
|
export interface MatchHighlight extends MatchValue {
|
|
670
671
|
keyword: string | RegExp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const g = (l, s, c, h, a) => {
|
|
2
|
+
let r = "center";
|
|
3
|
+
switch (h) {
|
|
4
|
+
case 90:
|
|
5
|
+
r = `${l.width / 2}px ${l.width / 2}px`;
|
|
6
|
+
break;
|
|
7
|
+
case -90:
|
|
8
|
+
case 270:
|
|
9
|
+
r = `${l.height / 2}px ${l.height / 2}px`;
|
|
10
|
+
break;
|
|
11
|
+
default:
|
|
12
|
+
r = "center";
|
|
13
|
+
}
|
|
14
|
+
const t = document.createElement("div");
|
|
15
|
+
t.id = "parent-element", t.style.width = `${l.width}px`, t.style.height = `${l.height}px`, t.style.setProperty("--scale-factor", a.toString()), t.style.setProperty("--rotation", h.toString()), t.style.setProperty("--transform-origin", r), t.style.left = "-99999px", t.style.visibility = "hidden", t.style.position = "absolute";
|
|
16
|
+
const i = document.createElement("div");
|
|
17
|
+
i.style.position = "relative", i.style.width = "100%", i.style.height = "100%", t.appendChild(i);
|
|
18
|
+
let e;
|
|
19
|
+
if (c instanceof HTMLElement)
|
|
20
|
+
e = c.cloneNode(!0), i.appendChild(e);
|
|
21
|
+
else {
|
|
22
|
+
const o = c.props;
|
|
23
|
+
e = document.createElement("div"), o.style && Object.assign(e.style, o.style), o.className && (e.className = o.className), i.appendChild(e);
|
|
24
|
+
}
|
|
25
|
+
s.appendChild(t);
|
|
26
|
+
const d = t.getBoundingClientRect(), n = e.getBoundingClientRect();
|
|
27
|
+
s.removeChild(t);
|
|
28
|
+
const p = {
|
|
29
|
+
top: s.clientHeight / 2,
|
|
30
|
+
left: s.clientWidth / 2
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
left: n.left - d.left - p.left + n.width / 2,
|
|
34
|
+
top: n.top - d.top - p.top + n.height / 2,
|
|
35
|
+
width: n.width,
|
|
36
|
+
height: n.height
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
g as getElementPagePosition
|
|
41
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as E, useCallback as h, useEffect as A } from "react";
|
|
2
2
|
import { appConsole as l } from "../appConsole.js";
|
|
3
|
-
const b = /* @__PURE__ */ new Date("2025-11-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2025-11-07T03:48:56.419Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
|
|
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}`,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pdf-viewer/react",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
|
|
5
|
-
"version": "1.12.0-beta.
|
|
5
|
+
"version": "1.12.0-beta.1",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react-pdf",
|
|
8
8
|
"react-pdf-viewer",
|