@react-pdf-kit/viewer 2.2.1-rc.0 → 2.2.1-rc.2
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/PaginationContext-15f88187.js +222 -0
- package/dist/components/RPController.js +1 -1
- package/dist/components/RPPages.js +523 -511
- package/dist/components/RPProvider.js +1 -1
- package/dist/components/layout/RPDefaultLayout.js +1 -1
- package/dist/components/layout/RPLayout.js +1 -1
- package/dist/components/layout/sidebar/RPSidebar.js +1 -1
- package/dist/components/layout/sidebar/Thumbnail.js +1 -1
- package/dist/components/layout/sidebar/Thumbnails.js +1 -1
- package/dist/components/layout/toolbar/MostPageTool.js +1 -1
- package/dist/components/layout/toolbar/OtherTool.js +1 -1
- package/dist/components/layout/toolbar/Paginate.js +1 -1
- package/dist/components/layout/toolbar/RPMoreOptions.js +1 -1
- package/dist/components/layout/toolbar/RPToolbar.js +1 -1
- package/dist/components/layout/toolbar/RPToolbarEnd.js +1 -1
- package/dist/components/layout/toolbar/SearchResultNavigator.js +1 -1
- package/dist/components/layout/toolbar/SearchTool.js +1 -1
- package/dist/components/layout/toolbar/ToolbarCustom.js +1 -1
- package/dist/components/layout/toolbar/ToolbarDefault.js +1 -1
- package/dist/components/layout/toolbar/ToolbarLayout.js +1 -1
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/InputPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/LastPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/NextPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/PreviousPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +1 -1
- package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +1 -1
- package/dist/components/page/AnnotationLayer.js +1 -1
- package/dist/components/page/CanvasLayer.js +1 -1
- package/dist/components/page/DualPage.js +1 -1
- package/dist/components/page/DualPageWithCover.js +1 -1
- package/dist/components/page/RPPage.js +1 -1
- package/dist/components/page/SinglePage.js +1 -1
- package/dist/components/page/TextLayer.js +1 -1
- package/dist/contexts/PaginationContext.js +1 -1
- package/dist/contexts/RenderQueueProvider.js +1 -1
- package/dist/contexts/SearchContext.js +1 -1
- package/dist/main.js +1 -1
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/useLoadPdf.js +28 -28
- package/dist/utils/hooks/usePaginate.js +1 -1
- package/dist/utils/hooks/usePresentPage.js +34 -32
- package/dist/utils/hooks/useScrollToPage.js +1 -1
- package/dist/utils/hooks/useSearch.js +1 -1
- package/package.json +1 -1
- package/dist/PaginationContext-a3021a65.js +0 -218
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { jsx as H } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as L, useEffect as G, useCallback as h, useState as w, useMemo as y, createContext as j, useContext as Z } from "react";
|
|
3
|
+
import { ViewMode as I, ScrollMode as E } from "./utils/types.js";
|
|
4
|
+
import { useScrollModeContext as O } from "./contexts/ScrollModeContext.js";
|
|
5
|
+
import { useDocumentContext as $ } from "./contexts/RPDocumentContext.js";
|
|
6
|
+
import { appConsole as q } from "./utils/appConsole.js";
|
|
7
|
+
import { useGlobalCurrentPage as B } from "./contexts/GlobalCurrentPage.js";
|
|
8
|
+
import { useInitialStateContext as J } from "./contexts/InitialStateContext.js";
|
|
9
|
+
import { useViewModeContext as W } from "./contexts/ViewModeContext.js";
|
|
10
|
+
import { useVirtualScrollContext as K } from "./contexts/VirtualScrollContext.js";
|
|
11
|
+
import { useVirtualGridContext as Q } from "./contexts/VirtualGridContext.js";
|
|
12
|
+
import { smoothScrollTo as F } from "./utils/smoothScrollTo.js";
|
|
13
|
+
import { useDimensionPagesContext as b } from "./contexts/DimensionPagesContext.js";
|
|
14
|
+
import { useSmoothScrollContext as X } from "./contexts/SmoothScrollContext.js";
|
|
15
|
+
import { getScrollDistance as D } from "./utils/getScrollDistance.js";
|
|
16
|
+
import { getGridDimension as Y } from "./utils/calculatePage.js";
|
|
17
|
+
import { useDebounce as tt } from "./utils/hooks/useDebounce.js";
|
|
18
|
+
import { useLayoutContainer as et } from "./contexts/LayoutContainerContext.js";
|
|
19
|
+
const ot = () => {
|
|
20
|
+
const { viewMode: o } = W(), { scrollMode: e } = O(), { virtualScrollRef: i, virtualScrollableElementRef: s, pageScrollElementRef: a } = K(), { setFocusedPage: x } = st(), m = L(), { columnCount: r } = Q(), { widths: n, heights: g } = b(), l = L(e), C = L(o), P = L(r), { targetScrollPage: A } = X();
|
|
21
|
+
G(() => {
|
|
22
|
+
i != null && i.scrollToItem && (m.current = i);
|
|
23
|
+
}, [i]), G(() => {
|
|
24
|
+
l.current = e, C.current = o;
|
|
25
|
+
}, [e, o]);
|
|
26
|
+
const S = h(
|
|
27
|
+
(u, d) => {
|
|
28
|
+
if (!a)
|
|
29
|
+
return;
|
|
30
|
+
const f = Math.ceil(u / 2) * 2 - 1;
|
|
31
|
+
if (u === f + 1) {
|
|
32
|
+
const t = {
|
|
33
|
+
left: n[f],
|
|
34
|
+
top: 0
|
|
35
|
+
};
|
|
36
|
+
return new Promise(
|
|
37
|
+
(c) => F(a, t, c)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const T = {
|
|
41
|
+
left: 0,
|
|
42
|
+
top: 0
|
|
43
|
+
};
|
|
44
|
+
return a == null ? void 0 : a.scrollTo({
|
|
45
|
+
...T,
|
|
46
|
+
behavior: d
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
[a, n, F]
|
|
50
|
+
);
|
|
51
|
+
return G(() => {
|
|
52
|
+
l.current = e, C.current = o;
|
|
53
|
+
}, [e, o]), G(() => {
|
|
54
|
+
P.current = r;
|
|
55
|
+
}, [r]), { scrollToPage: h(
|
|
56
|
+
(u, d = "smooth") => {
|
|
57
|
+
x(u);
|
|
58
|
+
const f = u - 1;
|
|
59
|
+
let T = f, t = 0;
|
|
60
|
+
if (C.current === I.DUAL_PAGE && l.current === E.PAGE_SCROLLING) {
|
|
61
|
+
S(u, d);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (l.current === E.PAGE_SCROLLING) {
|
|
65
|
+
x(u);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!m.current || !s)
|
|
69
|
+
return;
|
|
70
|
+
const c = s;
|
|
71
|
+
d === "smooth" && (A.current = u);
|
|
72
|
+
const { columnsWidth: p, rowsHeight: R } = Y(
|
|
73
|
+
{ widths: n, heights: g },
|
|
74
|
+
r
|
|
75
|
+
);
|
|
76
|
+
if (l.current === E.HORIZONTAL_SCROLLING) {
|
|
77
|
+
t = f;
|
|
78
|
+
const N = D(p, t), _ = {
|
|
79
|
+
left: Math.floor(N),
|
|
80
|
+
top: 0
|
|
81
|
+
};
|
|
82
|
+
return c.scrollTo({
|
|
83
|
+
..._,
|
|
84
|
+
behavior: d
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (C.current === I.DUAL_PAGE) {
|
|
88
|
+
t = f % 2, T = Math.floor(f / 2);
|
|
89
|
+
const _ = D(p, t), k = D(R, T), z = {
|
|
90
|
+
left: Math.floor(_),
|
|
91
|
+
top: Math.floor(k)
|
|
92
|
+
};
|
|
93
|
+
return c.scrollTo({
|
|
94
|
+
...z,
|
|
95
|
+
behavior: d
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const U = D(R, T), V = {
|
|
99
|
+
left: 0,
|
|
100
|
+
top: Math.floor(U)
|
|
101
|
+
};
|
|
102
|
+
return c.scrollTo({
|
|
103
|
+
...V,
|
|
104
|
+
behavior: d
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
[
|
|
108
|
+
s,
|
|
109
|
+
r,
|
|
110
|
+
S,
|
|
111
|
+
x,
|
|
112
|
+
F,
|
|
113
|
+
g,
|
|
114
|
+
n
|
|
115
|
+
]
|
|
116
|
+
) };
|
|
117
|
+
}, rt = (o = 1) => {
|
|
118
|
+
const [e, i] = w(o), [s, a] = w(0), { scrollToPage: x } = ot(), m = L(o), { viewMode: r } = W(), { scrollMode: n } = O(), { widths: g } = b(), { pagesRef: l } = et(), C = tt(e, 100), P = h(
|
|
119
|
+
(t) => {
|
|
120
|
+
if (!/^[0-9]*$/g.test(t.toString()) || !t)
|
|
121
|
+
return { success: !1, currentPage: m.current };
|
|
122
|
+
const p = +t;
|
|
123
|
+
return p < 0 || p > s ? { success: !1, currentPage: m.current } : (i(p), m.current = p, { success: !0, currentPage: +t });
|
|
124
|
+
},
|
|
125
|
+
[s]
|
|
126
|
+
), A = h(P, [P]), S = h((t) => {
|
|
127
|
+
i(t), m.current = t;
|
|
128
|
+
}, []), M = h(
|
|
129
|
+
(t) => {
|
|
130
|
+
const c = P(t);
|
|
131
|
+
return c.success && x(c.currentPage), c;
|
|
132
|
+
},
|
|
133
|
+
[P, x]
|
|
134
|
+
), u = h(
|
|
135
|
+
(t) => {
|
|
136
|
+
const c = t % 2 === 1;
|
|
137
|
+
if (!l || c)
|
|
138
|
+
return !1;
|
|
139
|
+
const p = c ? g[t] : g[t - 1], R = c ? g[t + 1] : g[t];
|
|
140
|
+
return r === I.DUAL_PAGE && p + R < l.clientWidth;
|
|
141
|
+
},
|
|
142
|
+
[r, g, l, s]
|
|
143
|
+
), d = h(() => {
|
|
144
|
+
let t = e - 1;
|
|
145
|
+
u(t) && (t = e - 2), M(t);
|
|
146
|
+
}, [M, e, r, n, u]), f = y(() => r === I.DUAL_PAGE && n === E.PAGE_SCROLLING ? e === s - 1 : e === s, [e, s, r, n]), T = h(() => {
|
|
147
|
+
if (f)
|
|
148
|
+
return;
|
|
149
|
+
let t = e + 1;
|
|
150
|
+
u(t) && (t = e + 2), M(t);
|
|
151
|
+
}, [M, e, u, r, n, f]);
|
|
152
|
+
return {
|
|
153
|
+
focusedPage: C,
|
|
154
|
+
totalPages: s,
|
|
155
|
+
setFocusedPage: A,
|
|
156
|
+
resetPage: S,
|
|
157
|
+
setTotalPages: a,
|
|
158
|
+
nextPage: T,
|
|
159
|
+
prevPage: d,
|
|
160
|
+
goToPage: M
|
|
161
|
+
};
|
|
162
|
+
}, v = j({
|
|
163
|
+
focusedPage: 0,
|
|
164
|
+
setFocusedPage: (o) => {
|
|
165
|
+
},
|
|
166
|
+
goToPage: (o) => ({ success: !!o, currentPage: +o }),
|
|
167
|
+
totalPages: 0,
|
|
168
|
+
setTotalPages: (o) => {
|
|
169
|
+
},
|
|
170
|
+
prevPage: () => {
|
|
171
|
+
},
|
|
172
|
+
nextPage: () => {
|
|
173
|
+
}
|
|
174
|
+
}), st = () => {
|
|
175
|
+
const o = Z(v);
|
|
176
|
+
return typeof (o == null ? void 0 : o.focusedPage) > "u" && q.error("Please use this hooks inside children component of RPProvider"), o;
|
|
177
|
+
}, Lt = ({ children: o }) => {
|
|
178
|
+
const { pdf: e } = $(), { setCurrentPage: i } = B(), { initialPage: s = 1 } = J(), {
|
|
179
|
+
focusedPage: a,
|
|
180
|
+
totalPages: x,
|
|
181
|
+
setFocusedPage: m,
|
|
182
|
+
resetPage: r,
|
|
183
|
+
setTotalPages: n,
|
|
184
|
+
goToPage: g,
|
|
185
|
+
nextPage: l,
|
|
186
|
+
prevPage: C
|
|
187
|
+
} = rt(s), P = L(!0);
|
|
188
|
+
return G(() => {
|
|
189
|
+
if (!e) {
|
|
190
|
+
P.current || (n(0), r(1));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!e.numPages)
|
|
194
|
+
return;
|
|
195
|
+
n(e.numPages);
|
|
196
|
+
const A = P.current ? s : 1, S = Math.min(Math.max(A, 1), e.numPages);
|
|
197
|
+
r(S), P.current = !1;
|
|
198
|
+
}, [e, n, r]), G(() => {
|
|
199
|
+
i(a);
|
|
200
|
+
}, [a, i]), /* @__PURE__ */ H(
|
|
201
|
+
v.Provider,
|
|
202
|
+
{
|
|
203
|
+
value: {
|
|
204
|
+
focusedPage: a,
|
|
205
|
+
totalPages: x,
|
|
206
|
+
setFocusedPage: m,
|
|
207
|
+
setTotalPages: n,
|
|
208
|
+
nextPage: l,
|
|
209
|
+
prevPage: C,
|
|
210
|
+
goToPage: g
|
|
211
|
+
},
|
|
212
|
+
children: o
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
export {
|
|
217
|
+
Lt as P,
|
|
218
|
+
ot as a,
|
|
219
|
+
rt as b,
|
|
220
|
+
v as c,
|
|
221
|
+
st as u
|
|
222
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import { useState as o } from "react";
|
|
3
|
-
import { P as w } from "../PaginationContext-
|
|
3
|
+
import { P as w } from "../PaginationContext-15f88187.js";
|
|
4
4
|
import { DarkModeProvider as D } from "../contexts/DarkModeContext.js";
|
|
5
5
|
import { ViewMode as E, ScrollMode as F, SelectionMode as G } from "../utils/types.js";
|
|
6
6
|
import { RotateProvider as I } from "../contexts/RotationContext.js";
|