@react-pdf-kit/viewer 2.4.0 → 2.5.0-beta.1

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