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