@react-pdf-kit/viewer 2.5.0-beta.2 → 2.5.0-beta.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as n, useRef as u, useEffect as s } from "react";
|
|
3
3
|
import { useElementThumbnailContext as l } from "../../../contexts/ElementThumbnailContext.js";
|
|
4
4
|
import "../../../utils/types.js";
|
|
5
5
|
import "../../../de_DE-8145915f.js";
|
|
@@ -23,6 +23,21 @@ import "../../../utils/hooks/useLicense.js";
|
|
|
23
23
|
import "../../../contexts/ThumbnailsContext.js";
|
|
24
24
|
import "../../../utils/hooks/useThumbnail.js";
|
|
25
25
|
import "../../../contexts/SmoothScrollContext.js";
|
|
26
|
+
import "../../../PaginationContext-87f832f2.js";
|
|
27
|
+
import "../../../contexts/ScrollModeContext.js";
|
|
28
|
+
import "../../../contexts/GlobalCurrentPage.js";
|
|
29
|
+
import "../../../contexts/ViewModeContext.js";
|
|
30
|
+
import "../../../contexts/VirtualScrollContext.js";
|
|
31
|
+
import "../../../contexts/VirtualGridContext.js";
|
|
32
|
+
import "../../../utils/smoothScrollTo.js";
|
|
33
|
+
import "../../../contexts/DimensionPagesContext.js";
|
|
34
|
+
import "../../../contexts/ZoomContext.js";
|
|
35
|
+
import "../../../utils/constants.js";
|
|
36
|
+
import "../../../utils/getZoomLevel.js";
|
|
37
|
+
import "../../../contexts/LayoutContainerContext.js";
|
|
38
|
+
import "../../../utils/hooks/useDebounce.js";
|
|
39
|
+
import "../../../utils/getScrollDistance.js";
|
|
40
|
+
import "../../../utils/calculatePage.js";
|
|
26
41
|
const c = {
|
|
27
42
|
"rp-custom-thumbnail-element": "_rp-custom-thumbnail-element_h5ef7_1"
|
|
28
43
|
}, a = ({ child: t }) => {
|
|
@@ -33,13 +48,13 @@ const c = {
|
|
|
33
48
|
var o;
|
|
34
49
|
(o = r.current) == null || o.removeChild(t);
|
|
35
50
|
};
|
|
36
|
-
}, [t]), /* @__PURE__ */
|
|
37
|
-
},
|
|
38
|
-
const { elementList: r } = l(), m =
|
|
51
|
+
}, [t]), /* @__PURE__ */ i("div", { ref: r });
|
|
52
|
+
}, g = ({ pageNumber: t }) => {
|
|
53
|
+
const { elementList: r } = l(), m = n(() => {
|
|
39
54
|
var o;
|
|
40
|
-
return (o = r[t]) == null ? void 0 : o.map((
|
|
55
|
+
return (o = r[t]) == null ? void 0 : o.map((p, e) => p instanceof HTMLElement ? /* @__PURE__ */ i(a, { child: p }, e) : /* @__PURE__ */ i("div", { children: p }, e));
|
|
41
56
|
}, [r, t]);
|
|
42
|
-
return m ? /* @__PURE__ */
|
|
57
|
+
return m ? /* @__PURE__ */ i(
|
|
43
58
|
"div",
|
|
44
59
|
{
|
|
45
60
|
className: c["rp-custom-thumbnail-element"],
|
|
@@ -49,5 +64,5 @@ const c = {
|
|
|
49
64
|
) : null;
|
|
50
65
|
};
|
|
51
66
|
export {
|
|
52
|
-
|
|
67
|
+
g as CustomThumbnailElement
|
|
53
68
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { LicenseType as
|
|
4
|
-
import { usePagesRotateContext as
|
|
5
|
-
import { useLicenseContext as
|
|
6
|
-
import { useThumbnailContext as
|
|
7
|
-
import { useSmoothScrollContext as
|
|
8
|
-
import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as
|
|
1
|
+
import { jsx as $ } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as j, useState as B, useRef as P, useEffect as L, useCallback as s, useContext as y, useMemo as k } from "react";
|
|
3
|
+
import { LicenseType as V } from "../utils/types.js";
|
|
4
|
+
import { usePagesRotateContext as Z } from "./PagesRotateContext.js";
|
|
5
|
+
import { useLicenseContext as z } from "./LicenseContext.js";
|
|
6
|
+
import { useThumbnailContext as J } from "./ThumbnailsContext.js";
|
|
7
|
+
import { useSmoothScrollContext as K } from "./SmoothScrollContext.js";
|
|
8
|
+
import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as b } from "../utils/const.js";
|
|
9
|
+
import { u as Q } from "../PaginationContext-87f832f2.js";
|
|
9
10
|
import "../de_DE-8145915f.js";
|
|
10
11
|
import "./RPDocumentContext.js";
|
|
11
12
|
import "../utils/hooks/useLoadPdf.js";
|
|
@@ -22,108 +23,174 @@ import "./InitialStateContext.js";
|
|
|
22
23
|
import "./EventCallbackContext.js";
|
|
23
24
|
import "../utils/hooks/useLicense.js";
|
|
24
25
|
import "../utils/hooks/useThumbnail.js";
|
|
25
|
-
|
|
26
|
+
import "./ScrollModeContext.js";
|
|
27
|
+
import "./GlobalCurrentPage.js";
|
|
28
|
+
import "./ViewModeContext.js";
|
|
29
|
+
import "./VirtualScrollContext.js";
|
|
30
|
+
import "./VirtualGridContext.js";
|
|
31
|
+
import "../utils/smoothScrollTo.js";
|
|
32
|
+
import "./DimensionPagesContext.js";
|
|
33
|
+
import "./ZoomContext.js";
|
|
34
|
+
import "../utils/constants.js";
|
|
35
|
+
import "../utils/getZoomLevel.js";
|
|
36
|
+
import "./LayoutContainerContext.js";
|
|
37
|
+
import "../utils/hooks/useDebounce.js";
|
|
38
|
+
import "../utils/getScrollDistance.js";
|
|
39
|
+
import "../utils/calculatePage.js";
|
|
40
|
+
const X = 5, Y = 10, I = (i, a) => Math.min(Math.max(i, 0), Math.max(a, 0)), R = j(
|
|
26
41
|
void 0
|
|
27
|
-
),
|
|
28
|
-
const [a,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
), Dt = ({ children: i }) => {
|
|
43
|
+
const [a, u] = B({}), { pageRotate: r } = Z(), { thumbnailPages: c, addToPage: h, thumbnailLength: f } = J(), { scrollBehavior: v } = K(), { totalPages: w } = Q(), S = P(null), C = P(c), A = P(f), [l, x] = B(null);
|
|
44
|
+
L(() => {
|
|
45
|
+
C.current = c;
|
|
46
|
+
}, [c]), L(() => {
|
|
47
|
+
A.current = f;
|
|
48
|
+
}, [f]);
|
|
49
|
+
const H = s((e) => {
|
|
50
|
+
S.current = e;
|
|
51
|
+
}, []), d = s(
|
|
52
|
+
(e) => {
|
|
53
|
+
const n = e + Y;
|
|
54
|
+
return w ? Math.min(n, w) : e;
|
|
55
|
+
},
|
|
56
|
+
[w]
|
|
57
|
+
), _ = s(
|
|
58
|
+
(e) => {
|
|
59
|
+
const n = d(e);
|
|
60
|
+
return !C.current[e] || A.current < n ? (h(n), !1) : !0;
|
|
61
|
+
},
|
|
62
|
+
[h, d]
|
|
63
|
+
), G = s(
|
|
64
|
+
(e, n) => {
|
|
65
|
+
u((o) => {
|
|
66
|
+
var m;
|
|
67
|
+
const t = (m = C.current[e]) == null ? void 0 : m.viewport, p = {
|
|
35
68
|
width: t ? t.width : 0,
|
|
36
69
|
height: t ? t.height : 0
|
|
37
70
|
};
|
|
38
71
|
return {
|
|
39
72
|
...o,
|
|
40
|
-
[e]:
|
|
73
|
+
[e]: n(o[e] ?? [], p, r[e] ?? 0)
|
|
41
74
|
};
|
|
42
75
|
});
|
|
43
76
|
},
|
|
44
|
-
[
|
|
45
|
-
),
|
|
46
|
-
|
|
47
|
-
const o = { ...
|
|
77
|
+
[r]
|
|
78
|
+
), O = s((e) => {
|
|
79
|
+
u((n) => {
|
|
80
|
+
const o = { ...n };
|
|
48
81
|
return delete o[e], o;
|
|
49
82
|
});
|
|
50
|
-
}, []),
|
|
51
|
-
|
|
83
|
+
}, []), U = s((e, n) => {
|
|
84
|
+
u((o) => {
|
|
52
85
|
const t = { ...o };
|
|
53
|
-
return t[e] ? (t[e] = t[e].filter((
|
|
86
|
+
return t[e] ? (t[e] = t[e].filter((p, m) => m !== n), t) : o;
|
|
54
87
|
});
|
|
55
|
-
}, []),
|
|
56
|
-
(e,
|
|
57
|
-
var
|
|
58
|
-
const t =
|
|
88
|
+
}, []), T = s(
|
|
89
|
+
(e, n, o) => {
|
|
90
|
+
var F;
|
|
91
|
+
const t = S.current;
|
|
59
92
|
if (!t)
|
|
60
|
-
return;
|
|
61
|
-
const
|
|
93
|
+
return !1;
|
|
94
|
+
const p = t.querySelector(
|
|
62
95
|
`[data-rp="thumbnail-${e}-customElement"]`
|
|
63
|
-
),
|
|
64
|
-
if (!
|
|
65
|
-
return;
|
|
66
|
-
const
|
|
67
|
-
t.scrollTo({
|
|
68
|
-
top:
|
|
69
|
-
left:
|
|
70
|
-
behavior: (o == null ? void 0 : o.behavior) ??
|
|
71
|
-
});
|
|
96
|
+
), m = (F = p == null ? void 0 : p.children) == null ? void 0 : F[n];
|
|
97
|
+
if (!m)
|
|
98
|
+
return !1;
|
|
99
|
+
const D = m.closest(`[id="page-${e}"]`) ?? m, M = t.getBoundingClientRect(), g = D.getBoundingClientRect(), N = t.scrollTop + (g.top - M.top) - (t.clientHeight - g.height) / 2, q = t.scrollLeft + (g.left - M.left) - (t.clientWidth - g.width) / 2;
|
|
100
|
+
return t.scrollTo({
|
|
101
|
+
top: I(N, t.scrollHeight - t.clientHeight),
|
|
102
|
+
left: I(q, t.scrollWidth - t.clientWidth),
|
|
103
|
+
behavior: (o == null ? void 0 : o.behavior) ?? v
|
|
104
|
+
}), !0;
|
|
72
105
|
},
|
|
73
|
-
[
|
|
106
|
+
[v]
|
|
107
|
+
), W = s(
|
|
108
|
+
(e, n, o) => {
|
|
109
|
+
T(e, n, o) || (_(e), x({ page: e, index: n, config: o, attempt: 0 }));
|
|
110
|
+
},
|
|
111
|
+
[_, T]
|
|
74
112
|
);
|
|
75
|
-
return
|
|
76
|
-
|
|
113
|
+
return L(() => {
|
|
114
|
+
if (!l)
|
|
115
|
+
return;
|
|
116
|
+
const e = d(l.page);
|
|
117
|
+
if (!c[l.page] || f < e) {
|
|
118
|
+
h(e);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const n = window.requestAnimationFrame(() => {
|
|
122
|
+
if (T(
|
|
123
|
+
l.page,
|
|
124
|
+
l.index,
|
|
125
|
+
l.config
|
|
126
|
+
)) {
|
|
127
|
+
x(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
l.attempt < X && x((t) => !t || t.page !== l.page || t.index !== l.index ? t : { ...t, attempt: t.attempt + 1 });
|
|
131
|
+
});
|
|
132
|
+
return () => {
|
|
133
|
+
window.cancelAnimationFrame(n);
|
|
134
|
+
};
|
|
135
|
+
}, [
|
|
136
|
+
h,
|
|
137
|
+
d,
|
|
138
|
+
l,
|
|
139
|
+
T,
|
|
140
|
+
f,
|
|
141
|
+
c
|
|
142
|
+
]), /* @__PURE__ */ $(
|
|
143
|
+
R.Provider,
|
|
77
144
|
{
|
|
78
145
|
value: {
|
|
79
|
-
updateElement:
|
|
80
|
-
clearElements:
|
|
81
|
-
removeElement:
|
|
146
|
+
updateElement: G,
|
|
147
|
+
clearElements: O,
|
|
148
|
+
removeElement: U,
|
|
82
149
|
elementList: a,
|
|
83
|
-
scrollToElement:
|
|
84
|
-
setThumbnailContainer:
|
|
150
|
+
scrollToElement: W,
|
|
151
|
+
setThumbnailContainer: H
|
|
85
152
|
},
|
|
86
|
-
children:
|
|
153
|
+
children: i
|
|
87
154
|
}
|
|
88
155
|
);
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
const
|
|
92
|
-
return (
|
|
93
|
-
},
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
156
|
+
}, E = () => {
|
|
157
|
+
}, Nt = () => {
|
|
158
|
+
const i = y(R);
|
|
159
|
+
return (i == null ? void 0 : i.setThumbnailContainer) ?? E;
|
|
160
|
+
}, qt = () => {
|
|
161
|
+
const i = y(R), { type: a, validating: u } = z(), r = P(0), c = k(() => {
|
|
162
|
+
if (u !== !1)
|
|
96
163
|
return {
|
|
97
|
-
updateElement:
|
|
98
|
-
clearElements:
|
|
99
|
-
removeElement:
|
|
164
|
+
updateElement: E,
|
|
165
|
+
clearElements: E,
|
|
166
|
+
removeElement: E,
|
|
100
167
|
elementList: {},
|
|
101
|
-
scrollToElement:
|
|
168
|
+
scrollToElement: E
|
|
102
169
|
};
|
|
103
|
-
if (!(a !==
|
|
170
|
+
if (!(a !== V.Developer))
|
|
104
171
|
return {
|
|
105
172
|
updateElement: () => {
|
|
106
|
-
|
|
173
|
+
r.current === 0 && (console.error(b), r.current++);
|
|
107
174
|
},
|
|
108
175
|
clearElements: () => {
|
|
109
|
-
|
|
176
|
+
r.current === 0 && (console.error(b), r.current++);
|
|
110
177
|
},
|
|
111
178
|
removeElement: () => {
|
|
112
|
-
|
|
179
|
+
r.current === 0 && (console.error(b), r.current++);
|
|
113
180
|
},
|
|
114
181
|
elementList: {},
|
|
115
182
|
scrollToElement: () => {
|
|
116
|
-
|
|
183
|
+
r.current === 0 && (console.error(b), r.current++);
|
|
117
184
|
}
|
|
118
185
|
};
|
|
119
|
-
}, [a,
|
|
120
|
-
if (!
|
|
186
|
+
}, [a, u]);
|
|
187
|
+
if (!i)
|
|
121
188
|
throw new Error("useElementThumbnailContext must be used within a ElementThumbnailProvider");
|
|
122
|
-
return
|
|
189
|
+
return c || i;
|
|
123
190
|
};
|
|
124
191
|
export {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
192
|
+
R as ElementThumbnailContext,
|
|
193
|
+
Dt as ElementThumbnailProvider,
|
|
194
|
+
qt as useElementThumbnailContext,
|
|
195
|
+
Nt as useThumbnailContainerRegister
|
|
129
196
|
};
|