@react-pdf-kit/viewer 2.3.0-beta.2 → 2.3.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.
Files changed (53) hide show
  1. package/dist/PaginationContext-15f88187.js +222 -0
  2. package/dist/RPSplitter-b62772f9.js +122 -0
  3. package/dist/components/RPController.js +1 -1
  4. package/dist/components/RPPages.js +530 -503
  5. package/dist/components/RPProvider.js +50 -48
  6. package/dist/components/layout/RPDefaultLayout.js +2 -2
  7. package/dist/components/layout/RPLayout.js +2 -2
  8. package/dist/components/layout/sidebar/RPSidebar.js +5 -4
  9. package/dist/components/layout/sidebar/RPSplitter.js +3 -2
  10. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  11. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  12. package/dist/components/layout/toolbar/MostPageTool.js +1 -1
  13. package/dist/components/layout/toolbar/OtherTool.js +1 -1
  14. package/dist/components/layout/toolbar/Paginate.js +1 -1
  15. package/dist/components/layout/toolbar/RPMoreOptions.js +1 -1
  16. package/dist/components/layout/toolbar/RPToolbar.js +1 -1
  17. package/dist/components/layout/toolbar/RPToolbarEnd.js +1 -1
  18. package/dist/components/layout/toolbar/SearchResultNavigator.js +1 -1
  19. package/dist/components/layout/toolbar/SearchTool.js +1 -1
  20. package/dist/components/layout/toolbar/ToolbarCustom.js +5 -4
  21. package/dist/components/layout/toolbar/ToolbarDefault.js +2 -2
  22. package/dist/components/layout/toolbar/ToolbarLayout.js +2 -2
  23. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +2 -2
  24. package/dist/components/layout/toolbar/tools/FirstPageTool.js +2 -2
  25. package/dist/components/layout/toolbar/tools/InputPageTool.js +1 -1
  26. package/dist/components/layout/toolbar/tools/LastPageTool.js +2 -2
  27. package/dist/components/layout/toolbar/tools/NextPageTool.js +1 -1
  28. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +1 -1
  29. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +1 -1
  30. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +1 -1
  31. package/dist/components/page/AnnotationLayer.js +1 -1
  32. package/dist/components/page/CanvasLayer.js +1 -1
  33. package/dist/components/page/DualPage.js +1 -1
  34. package/dist/components/page/DualPageWithCover.js +1 -1
  35. package/dist/components/page/RPPage.js +1 -1
  36. package/dist/components/page/SinglePage.js +1 -1
  37. package/dist/components/page/TextLayer.js +1 -1
  38. package/dist/contexts/PaginationContext.js +2 -2
  39. package/dist/contexts/RenderQueueProvider.js +1 -1
  40. package/dist/contexts/SearchContext.js +1 -1
  41. package/dist/main.js +104 -103
  42. package/dist/types/main.d.ts +1 -0
  43. package/dist/types/utils/hooks/usePaginate.d.ts +2 -2
  44. package/dist/types/utils/types.d.ts +3 -0
  45. package/dist/utils/hooks/useLicense.js +1 -1
  46. package/dist/utils/hooks/useLoadPdf.js +28 -28
  47. package/dist/utils/hooks/usePaginate.js +1 -1
  48. package/dist/utils/hooks/usePresentPage.js +34 -32
  49. package/dist/utils/hooks/useScrollToPage.js +1 -1
  50. package/dist/utils/hooks/useSearch.js +1 -1
  51. package/package.json +1 -1
  52. package/dist/PaginationContext-9217cab4.js +0 -201
  53. package/dist/RPSplitter-3438b930.js +0 -109
@@ -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
+ };
@@ -0,0 +1,122 @@
1
+ import { jsx as j } from "react/jsx-runtime";
2
+ import { useRef as p, useState as k, useLayoutEffect as q, useCallback as x, useEffect as P } from "react";
3
+ import { THUMBNAIL_MIN_WIDTH as c } from "./utils/constants.js";
4
+ import { useLayoutContainer as z } from "./contexts/LayoutContainerContext.js";
5
+ import { useViewportContext as Y } from "./contexts/ViewportContext.js";
6
+ const V = {
7
+ "rp-sidebar-content-wrapper": "_rp-sidebar-content-wrapper_ppg43_1",
8
+ "rp-sidebar-content": "_rp-sidebar-content_ppg43_1",
9
+ "rp-thumbnails-wrapper": "_rp-thumbnails-wrapper_ppg43_17",
10
+ "rp-thumbnails-wrapper-dragging": "_rp-thumbnails-wrapper-dragging_ppg43_24",
11
+ "rp-thumbnails-wrapper-hidden": "_rp-thumbnails-wrapper-hidden_ppg43_28"
12
+ }, T = {
13
+ "rp-thumbnail-dragger": "_rp-thumbnail-dragger_1faw8_2",
14
+ "rp-thumbnail-dragger-dragging": "_rp-thumbnail-dragger-dragging_1faw8_13"
15
+ }, N = {
16
+ "rp-thumbnail-dragger": "_rp-thumbnail-dragger_174bn_1",
17
+ "rp-thumbnail-dragger-dragging": "_rp-thumbnail-dragger-dragging_174bn_15"
18
+ }, $ = 20, G = 640, J = 112, H = (I) => {
19
+ I.preventDefault(), I.stopPropagation();
20
+ }, er = (I) => {
21
+ const { onWidthChange: e, thumbnailRef: h, leftSidebarRef: S, isRPLayout: X } = I, n = p(null), F = p(0), b = p(null), f = p(!1), B = p(c), R = p(c), W = p(c), [g, C] = k(c), { container: u, pagesRef: l } = z(), { width: O } = Y(), i = O > 0 && O < G;
22
+ q(() => {
23
+ B.current = g;
24
+ }, [g]);
25
+ const m = x(() => {
26
+ var L, M, v;
27
+ if (!u)
28
+ return null;
29
+ const r = (L = n.current) == null ? void 0 : L.closest(".rp-content"), t = (r == null ? void 0 : r.clientWidth) ?? u.clientWidth, a = ((M = S.current) == null ? void 0 : M.getBoundingClientRect().width) ?? 0, s = ((v = n.current) == null ? void 0 : v.offsetWidth) ?? 0, E = (l == null ? void 0 : l.clientWidth) ?? Number.POSITIVE_INFINITY, A = Math.floor(t * 0.5 - a), D = Math.floor(t * $ / 100 - a - s);
30
+ let o = Math.min(A, E);
31
+ Number.isFinite(o) || (o = 0), o = Math.max(0, Math.floor(o));
32
+ let d = Math.max(c, D);
33
+ return d = Math.min(d, o), W.current = d, { maxAllowed: o, minAllowed: d };
34
+ }, [u, l, S]), w = x(() => {
35
+ if (!u || f.current || i)
36
+ return;
37
+ const r = m();
38
+ r && C(r.maxAllowed);
39
+ }, [u, i, m]), U = x(
40
+ (r) => {
41
+ var E, A, D, o, d, L, M, v;
42
+ if (i)
43
+ return;
44
+ H(r);
45
+ const t = m();
46
+ t ? (W.current = t.minAllowed, R.current = t.maxAllowed) : R.current = B.current, f.current = !0;
47
+ try {
48
+ r.currentTarget.setPointerCapture(r.pointerId);
49
+ } catch {
50
+ }
51
+ const a = ((A = (E = n.current) == null ? void 0 : E.getBoundingClientRect()) == null ? void 0 : A.left) ?? 0, s = ((o = (D = h.current) == null ? void 0 : D.getBoundingClientRect()) == null ? void 0 : o.width) ?? 0;
52
+ b.current = { x: a, y: 0 }, F.current = s, (d = n.current) == null || d.classList.add(T["rp-thumbnail-dragger-dragging"]), (L = n.current) == null || L.classList.add(N["rp-thumbnail-dragger-dragging"]), (v = (M = n.current) == null ? void 0 : M.closest('[data-rp="thumbnailSidebar"]')) == null || v.classList.add(
53
+ V["rp-thumbnails-wrapper"],
54
+ V["rp-thumbnails-wrapper-dragging"]
55
+ );
56
+ },
57
+ [h, m, i]
58
+ ), _ = x(
59
+ (r) => {
60
+ var t, a;
61
+ H(r);
62
+ try {
63
+ n.current && r.pointerId != null && n.current.releasePointerCapture(r.pointerId);
64
+ } catch {
65
+ }
66
+ b.current = null, f.current = !1, requestAnimationFrame(() => {
67
+ w();
68
+ }), (t = n.current) == null || t.classList.remove(T["rp-thumbnail-dragger-dragging"]), (a = n.current) == null || a.classList.remove(N["rp-thumbnail-dragger-dragging"]);
69
+ },
70
+ [w]
71
+ ), y = x(
72
+ (r) => {
73
+ if (i || !b.current)
74
+ return;
75
+ const t = r.clientX - b.current.x, a = Math.max(
76
+ W.current,
77
+ Math.min(F.current + t, R.current)
78
+ );
79
+ e == null || e(a), H(r);
80
+ },
81
+ [e, i]
82
+ );
83
+ return P(() => {
84
+ if (!u || i)
85
+ return;
86
+ const r = new ResizeObserver(() => {
87
+ w();
88
+ });
89
+ return r.observe(u), l && r.observe(l), w(), () => {
90
+ r.disconnect();
91
+ };
92
+ }, [u, l, w, i]), P(() => {
93
+ var t;
94
+ if (f.current || i)
95
+ return;
96
+ const r = ((t = h.current) == null ? void 0 : t.clientWidth) ?? c;
97
+ r > g ? e == null || e(g) : g >= c && r < c && (e == null || e(c));
98
+ }, [g, e, h, i]), P(() => {
99
+ var t, a;
100
+ if (!i)
101
+ return;
102
+ const r = m();
103
+ if (r) {
104
+ const s = Math.min(J, r.maxAllowed);
105
+ B.current = s, R.current = s, W.current = s, C(s), e == null || e(s);
106
+ }
107
+ b.current = null, f.current = !1, (t = n.current) == null || t.classList.remove(T["rp-thumbnail-dragger-dragging"]), (a = n.current) == null || a.classList.remove(N["rp-thumbnail-dragger-dragging"]);
108
+ }, [i, m, e, h]), P(() => (window.addEventListener("pointermove", y), window.addEventListener("pointerup", _), window.addEventListener("pointercancel", _), () => {
109
+ window.removeEventListener("pointermove", y), window.removeEventListener("pointerup", _), window.removeEventListener("pointercancel", _);
110
+ }), [y, _]), /* @__PURE__ */ j(
111
+ "div",
112
+ {
113
+ ref: n,
114
+ className: X ? N["rp-thumbnail-dragger"] : T["rp-thumbnail-dragger"],
115
+ onPointerDown: i ? void 0 : U
116
+ }
117
+ );
118
+ };
119
+ export {
120
+ er as R,
121
+ V as c
122
+ };
@@ -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-9217cab4.js";
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";