@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
@@ -1,201 +0,0 @@
1
- import { jsx as H } from "react/jsx-runtime";
2
- import { useRef as G, useEffect as S, useCallback as x, useState as F, useMemo as y, createContext as j, useContext as Z } from "react";
3
- import { ViewMode as D, ScrollMode as R } 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 { useViewModeContext as W } from "./contexts/ViewModeContext.js";
9
- import { useVirtualScrollContext as J } from "./contexts/VirtualScrollContext.js";
10
- import { useVirtualGridContext as K } from "./contexts/VirtualGridContext.js";
11
- import { smoothScrollTo as I } from "./utils/smoothScrollTo.js";
12
- import { useDimensionPagesContext as b } from "./contexts/DimensionPagesContext.js";
13
- import { useSmoothScrollContext as Q } from "./contexts/SmoothScrollContext.js";
14
- import { getScrollDistance as A } from "./utils/getScrollDistance.js";
15
- import { getGridDimension as X } from "./utils/calculatePage.js";
16
- import { useDebounce as Y } from "./utils/hooks/useDebounce.js";
17
- import { useLayoutContainer as ee } from "./contexts/LayoutContainerContext.js";
18
- const te = () => {
19
- const { viewMode: o } = W(), { scrollMode: t } = O(), { virtualScrollRef: i, virtualScrollableElementRef: r, pageScrollElementRef: a } = J(), { setFocusedPage: l } = re(), g = G(), { columnCount: n } = K(), { widths: u, heights: P } = b(), d = G(t), C = G(o), T = G(n), { targetScrollPage: E } = Q();
20
- S(() => {
21
- i != null && i.scrollToItem && (g.current = i);
22
- }, [i]), S(() => {
23
- d.current = t, C.current = o;
24
- }, [t, o]);
25
- const h = x(
26
- (f, m) => {
27
- if (!a)
28
- return;
29
- const p = Math.ceil(f / 2) * 2 - 1;
30
- if (f === p + 1) {
31
- const s = {
32
- left: u[p],
33
- top: 0
34
- };
35
- return new Promise(
36
- (c) => I(a, s, c)
37
- );
38
- }
39
- const e = {
40
- left: 0,
41
- top: 0
42
- };
43
- return a == null ? void 0 : a.scrollTo({
44
- ...e,
45
- behavior: m
46
- });
47
- },
48
- [a, u, I]
49
- );
50
- return S(() => {
51
- d.current = t, C.current = o;
52
- }, [t, o]), S(() => {
53
- T.current = n;
54
- }, [n]), { scrollToPage: x(
55
- (f, m = "smooth") => {
56
- l(f);
57
- const p = f - 1;
58
- let e = p, s = 0;
59
- if (C.current === D.DUAL_PAGE && d.current === R.PAGE_SCROLLING) {
60
- h(f, m);
61
- return;
62
- }
63
- if (d.current === R.PAGE_SCROLLING) {
64
- l(f);
65
- return;
66
- }
67
- if (!g.current || !r)
68
- return;
69
- const c = r;
70
- m === "smooth" && (E.current = f);
71
- const { columnsWidth: L, rowsHeight: N } = X(
72
- { widths: u, heights: P },
73
- n
74
- );
75
- if (d.current === R.HORIZONTAL_SCROLLING) {
76
- s = p;
77
- const w = A(L, s), _ = {
78
- left: Math.floor(w),
79
- top: 0
80
- };
81
- return c.scrollTo({
82
- ..._,
83
- behavior: m
84
- });
85
- }
86
- if (C.current === D.DUAL_PAGE) {
87
- s = p % 2, e = Math.floor(p / 2);
88
- const _ = A(L, s), k = A(N, e), z = {
89
- left: Math.floor(_),
90
- top: Math.floor(k)
91
- };
92
- return c.scrollTo({
93
- ...z,
94
- behavior: m
95
- });
96
- }
97
- const U = A(N, e), V = {
98
- left: 0,
99
- top: Math.floor(U)
100
- };
101
- return c.scrollTo({
102
- ...V,
103
- behavior: m
104
- });
105
- },
106
- [
107
- r,
108
- n,
109
- h,
110
- l,
111
- I,
112
- P,
113
- u
114
- ]
115
- ) };
116
- }, oe = (o = 1) => {
117
- const [t, i] = F(o), [r, a] = F(0), { scrollToPage: l } = te(), g = G(1), { viewMode: n } = W(), { scrollMode: u } = O(), { widths: P } = b(), { pagesRef: d } = ee(), C = Y(t, 100), T = x(
118
- (e) => {
119
- if (!/^[0-9]*$/g.test(e.toString()) || !e)
120
- return { success: !1, currentPage: g.current };
121
- const c = +e;
122
- return c < 0 || c > r ? { success: !1, currentPage: g.current } : (i(c), g.current = c, { success: !0, currentPage: +e });
123
- },
124
- [r]
125
- ), E = x(T, [T]), h = x(
126
- (e) => {
127
- const s = T(e);
128
- return s.success && l(s.currentPage), s;
129
- },
130
- [T, l]
131
- ), M = x(
132
- (e) => {
133
- const s = e % 2 === 1;
134
- if (!d || s)
135
- return !1;
136
- const c = s ? P[e] : P[e - 1], L = s ? P[e + 1] : P[e];
137
- return n === D.DUAL_PAGE && c + L < d.clientWidth;
138
- },
139
- [n, P, d, r]
140
- ), f = x(() => {
141
- let e = t - 1;
142
- M(e) && (e = t - 2), h(e);
143
- }, [h, t, n, u, M]), m = y(() => n === D.DUAL_PAGE && u === R.PAGE_SCROLLING ? t === r - 1 : t === r, [t, r, n, u]), p = x(() => {
144
- if (m)
145
- return;
146
- let e = t + 1;
147
- M(e) && (e = t + 2), h(e);
148
- }, [h, t, M, n, u, m]);
149
- return {
150
- focusedPage: C,
151
- totalPages: r,
152
- setFocusedPage: E,
153
- setTotalPages: a,
154
- nextPage: p,
155
- prevPage: f,
156
- goToPage: h
157
- };
158
- }, v = j({
159
- focusedPage: 0,
160
- setFocusedPage: (o) => {
161
- },
162
- goToPage: (o) => ({ success: !!o, currentPage: +o }),
163
- totalPages: 0,
164
- setTotalPages: (o) => {
165
- },
166
- prevPage: () => {
167
- },
168
- nextPage: () => {
169
- }
170
- }), re = () => {
171
- const o = Z(v);
172
- return typeof (o == null ? void 0 : o.focusedPage) > "u" && q.error("Please use this hooks inside children component of RPProvider"), o;
173
- }, Se = ({ children: o }) => {
174
- const { pdf: t } = $(), { setCurrentPage: i } = B(), { focusedPage: r, totalPages: a, setFocusedPage: l, setTotalPages: g, goToPage: n, nextPage: u, prevPage: P } = oe();
175
- return S(() => {
176
- t != null && t.numPages && (g(t.numPages), l(1));
177
- }, [t, g, l]), S(() => {
178
- i(r);
179
- }, [r, i]), /* @__PURE__ */ H(
180
- v.Provider,
181
- {
182
- value: {
183
- focusedPage: r,
184
- totalPages: a,
185
- setFocusedPage: l,
186
- setTotalPages: g,
187
- nextPage: u,
188
- prevPage: P,
189
- goToPage: n
190
- },
191
- children: o
192
- }
193
- );
194
- };
195
- export {
196
- Se as P,
197
- te as a,
198
- oe as b,
199
- v as c,
200
- re as u
201
- };
@@ -1,109 +0,0 @@
1
- import { jsx as j } from "react/jsx-runtime";
2
- import { useRef as d, useState as k, useLayoutEffect as q, useCallback as f, useEffect as N } from "react";
3
- import { THUMBNAIL_MIN_WIDTH as s } from "./utils/constants.js";
4
- import { useLayoutContainer as z } from "./contexts/LayoutContainerContext.js";
5
- const F = {
6
- "rp-sidebar-content-wrapper": "_rp-sidebar-content-wrapper_ppg43_1",
7
- "rp-sidebar-content": "_rp-sidebar-content_ppg43_1",
8
- "rp-thumbnails-wrapper": "_rp-thumbnails-wrapper_ppg43_17",
9
- "rp-thumbnails-wrapper-dragging": "_rp-thumbnails-wrapper-dragging_ppg43_24",
10
- "rp-thumbnails-wrapper-hidden": "_rp-thumbnails-wrapper-hidden_ppg43_28"
11
- }, A = {
12
- "rp-thumbnail-dragger": "_rp-thumbnail-dragger_1faw8_2",
13
- "rp-thumbnail-dragger-dragging": "_rp-thumbnail-dragger-dragging_1faw8_13"
14
- }, T = {
15
- "rp-thumbnail-dragger": "_rp-thumbnail-dragger_174bn_1",
16
- "rp-thumbnail-dragger-dragging": "_rp-thumbnail-dragger-dragging_174bn_15"
17
- }, U = 20, y = (w) => {
18
- w.preventDefault(), w.stopPropagation();
19
- }, J = (w) => {
20
- const { onWidthChange: e, thumbnailRef: _, leftSidebarRef: S, isRPLayout: H } = w, n = d(null), B = d(0), L = d(null), v = d(!1), C = d(s), I = d(s), E = d(s), [l, O] = k(s), { container: o, pagesRef: c } = z();
21
- q(() => {
22
- C.current = l;
23
- }, [l]);
24
- const x = f(() => {
25
- var m, h, b;
26
- if (!o)
27
- return null;
28
- const r = (m = n.current) == null ? void 0 : m.closest(".rp-content"), t = (r == null ? void 0 : r.clientWidth) ?? o.clientWidth, a = ((h = S.current) == null ? void 0 : h.getBoundingClientRect().width) ?? 0, D = ((b = n.current) == null ? void 0 : b.offsetWidth) ?? 0, M = (c == null ? void 0 : c.clientWidth) ?? Number.POSITIVE_INFINITY, R = Math.floor(t * 0.5 - a), W = Math.floor(t * U / 100 - a - D);
29
- let i = Math.min(R, M);
30
- Number.isFinite(i) || (i = 0), i = Math.max(0, Math.floor(i));
31
- let u = Math.max(s, W);
32
- return u = Math.min(u, i), E.current = u, { maxAllowed: i, minAllowed: u };
33
- }, [o, c, S]), p = f(() => {
34
- if (!o || v.current)
35
- return;
36
- const r = x();
37
- r && O(r.maxAllowed);
38
- }, [o, x]), X = f(
39
- (r) => {
40
- var M, R, W, i, u, m, h, b;
41
- y(r);
42
- const t = x();
43
- t ? (E.current = t.minAllowed, I.current = t.maxAllowed) : I.current = C.current, v.current = !0;
44
- try {
45
- r.currentTarget.setPointerCapture(r.pointerId);
46
- } catch {
47
- }
48
- const a = ((R = (M = n.current) == null ? void 0 : M.getBoundingClientRect()) == null ? void 0 : R.left) ?? 0, D = ((i = (W = _.current) == null ? void 0 : W.getBoundingClientRect()) == null ? void 0 : i.width) ?? 0;
49
- L.current = { x: a, y: 0 }, B.current = D, (u = n.current) == null || u.classList.add(A["rp-thumbnail-dragger-dragging"]), (m = n.current) == null || m.classList.add(T["rp-thumbnail-dragger-dragging"]), (b = (h = n.current) == null ? void 0 : h.closest('[data-rp="thumbnailSidebar"]')) == null || b.classList.add(
50
- F["rp-thumbnails-wrapper"],
51
- F["rp-thumbnails-wrapper-dragging"]
52
- );
53
- },
54
- [_, x]
55
- ), g = f(
56
- (r) => {
57
- var t, a;
58
- y(r);
59
- try {
60
- n.current && r.pointerId != null && n.current.releasePointerCapture(r.pointerId);
61
- } catch {
62
- }
63
- L.current = null, v.current = !1, requestAnimationFrame(() => {
64
- p();
65
- }), (t = n.current) == null || t.classList.remove(A["rp-thumbnail-dragger-dragging"]), (a = n.current) == null || a.classList.remove(T["rp-thumbnail-dragger-dragging"]);
66
- },
67
- [p]
68
- ), P = f(
69
- (r) => {
70
- if (!L.current)
71
- return;
72
- const t = r.clientX - L.current.x, a = Math.max(
73
- E.current,
74
- Math.min(B.current + t, I.current)
75
- );
76
- e == null || e(a), y(r);
77
- },
78
- [e]
79
- );
80
- return N(() => {
81
- if (!o)
82
- return;
83
- const r = new ResizeObserver(() => {
84
- p();
85
- });
86
- return r.observe(o), c && r.observe(c), p(), () => {
87
- r.disconnect();
88
- };
89
- }, [o, c, p]), N(() => {
90
- var t;
91
- if (v.current)
92
- return;
93
- const r = ((t = _.current) == null ? void 0 : t.clientWidth) ?? s;
94
- r > l ? e == null || e(l) : l >= s && r < s && (e == null || e(s));
95
- }, [l, e, _]), N(() => (window.addEventListener("pointermove", P), window.addEventListener("pointerup", g), window.addEventListener("pointercancel", g), () => {
96
- window.removeEventListener("pointermove", P), window.removeEventListener("pointerup", g), window.removeEventListener("pointercancel", g);
97
- }), [P, g]), /* @__PURE__ */ j(
98
- "div",
99
- {
100
- ref: n,
101
- className: H ? T["rp-thumbnail-dragger"] : A["rp-thumbnail-dragger"],
102
- onPointerDown: X
103
- }
104
- );
105
- };
106
- export {
107
- J as R,
108
- F as c
109
- };