@react-pdf-kit/viewer 2.5.0-beta.2 → 2.5.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.
@@ -1,5 +1,5 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import { useMemo as p, useRef as u, useEffect as s } from "react";
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as n, useRef as u, useEffect as s } from "react";
3
3
  import { useElementThumbnailContext as l } from "../../../contexts/ElementThumbnailContext.js";
4
4
  import "../../../utils/types.js";
5
5
  import "../../../de_DE-8145915f.js";
@@ -23,6 +23,21 @@ import "../../../utils/hooks/useLicense.js";
23
23
  import "../../../contexts/ThumbnailsContext.js";
24
24
  import "../../../utils/hooks/useThumbnail.js";
25
25
  import "../../../contexts/SmoothScrollContext.js";
26
+ import "../../../PaginationContext-87f832f2.js";
27
+ import "../../../contexts/ScrollModeContext.js";
28
+ import "../../../contexts/GlobalCurrentPage.js";
29
+ import "../../../contexts/ViewModeContext.js";
30
+ import "../../../contexts/VirtualScrollContext.js";
31
+ import "../../../contexts/VirtualGridContext.js";
32
+ import "../../../utils/smoothScrollTo.js";
33
+ import "../../../contexts/DimensionPagesContext.js";
34
+ import "../../../contexts/ZoomContext.js";
35
+ import "../../../utils/constants.js";
36
+ import "../../../utils/getZoomLevel.js";
37
+ import "../../../contexts/LayoutContainerContext.js";
38
+ import "../../../utils/hooks/useDebounce.js";
39
+ import "../../../utils/getScrollDistance.js";
40
+ import "../../../utils/calculatePage.js";
26
41
  const c = {
27
42
  "rp-custom-thumbnail-element": "_rp-custom-thumbnail-element_h5ef7_1"
28
43
  }, a = ({ child: t }) => {
@@ -33,13 +48,13 @@ const c = {
33
48
  var o;
34
49
  (o = r.current) == null || o.removeChild(t);
35
50
  };
36
- }, [t]), /* @__PURE__ */ e("div", { ref: r });
37
- }, G = ({ pageNumber: t }) => {
38
- const { elementList: r } = l(), m = p(() => {
51
+ }, [t]), /* @__PURE__ */ i("div", { ref: r });
52
+ }, g = ({ pageNumber: t }) => {
53
+ const { elementList: r } = l(), m = n(() => {
39
54
  var o;
40
- return (o = r[t]) == null ? void 0 : o.map((i, n) => i instanceof HTMLElement ? /* @__PURE__ */ e(a, { child: i }, n) : /* @__PURE__ */ e("div", { children: i }, n));
55
+ return (o = r[t]) == null ? void 0 : o.map((p, e) => p instanceof HTMLElement ? /* @__PURE__ */ i(a, { child: p }, e) : /* @__PURE__ */ i("div", { children: p }, e));
41
56
  }, [r, t]);
42
- return m ? /* @__PURE__ */ e(
57
+ return m ? /* @__PURE__ */ i(
43
58
  "div",
44
59
  {
45
60
  className: c["rp-custom-thumbnail-element"],
@@ -49,5 +64,5 @@ const c = {
49
64
  ) : null;
50
65
  };
51
66
  export {
52
- G as CustomThumbnailElement
67
+ g as CustomThumbnailElement
53
68
  };
@@ -1,11 +1,12 @@
1
- import { jsx as y } from "react/jsx-runtime";
2
- import { createContext as M, useState as O, useRef as x, useCallback as m, useContext as L, useMemo as B } from "react";
3
- import { LicenseType as D } from "../utils/types.js";
4
- import { usePagesRotateContext as I } from "./PagesRotateContext.js";
5
- import { useLicenseContext as G } from "./LicenseContext.js";
6
- import { useThumbnailContext as g } from "./ThumbnailsContext.js";
7
- import { useSmoothScrollContext as F } from "./SmoothScrollContext.js";
8
- import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as h } from "../utils/const.js";
1
+ import { jsx as $ } from "react/jsx-runtime";
2
+ import { createContext as j, useState as B, useRef as P, useEffect as L, useCallback as s, useContext as y, useMemo as k } from "react";
3
+ import { LicenseType as V } from "../utils/types.js";
4
+ import { usePagesRotateContext as Z } from "./PagesRotateContext.js";
5
+ import { useLicenseContext as z } from "./LicenseContext.js";
6
+ import { useThumbnailContext as J } from "./ThumbnailsContext.js";
7
+ import { useSmoothScrollContext as K } from "./SmoothScrollContext.js";
8
+ import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as b } from "../utils/const.js";
9
+ import { u as Q } from "../PaginationContext-87f832f2.js";
9
10
  import "../de_DE-8145915f.js";
10
11
  import "./RPDocumentContext.js";
11
12
  import "../utils/hooks/useLoadPdf.js";
@@ -22,108 +23,174 @@ import "./InitialStateContext.js";
22
23
  import "./EventCallbackContext.js";
23
24
  import "../utils/hooks/useLicense.js";
24
25
  import "../utils/hooks/useThumbnail.js";
25
- const U = 16, f = M(
26
+ import "./ScrollModeContext.js";
27
+ import "./GlobalCurrentPage.js";
28
+ import "./ViewModeContext.js";
29
+ import "./VirtualScrollContext.js";
30
+ import "./VirtualGridContext.js";
31
+ import "../utils/smoothScrollTo.js";
32
+ import "./DimensionPagesContext.js";
33
+ import "./ZoomContext.js";
34
+ import "../utils/constants.js";
35
+ import "../utils/getZoomLevel.js";
36
+ import "./LayoutContainerContext.js";
37
+ import "../utils/hooks/useDebounce.js";
38
+ import "../utils/getScrollDistance.js";
39
+ import "../utils/calculatePage.js";
40
+ const X = 5, Y = 10, I = (i, a) => Math.min(Math.max(i, 0), Math.max(a, 0)), R = j(
26
41
  void 0
27
- ), mt = ({ children: r }) => {
28
- const [a, s] = O({}), { pageRotate: n } = I(), { thumbnailPages: p } = g(), { scrollBehavior: E } = F(), d = x(null), w = m((e) => {
29
- d.current = e;
30
- }, []), R = m(
31
- (e, i) => {
32
- s((o) => {
33
- var l;
34
- const t = (l = p[e]) == null ? void 0 : l.viewport, c = {
42
+ ), Dt = ({ children: i }) => {
43
+ const [a, u] = B({}), { pageRotate: r } = Z(), { thumbnailPages: c, addToPage: h, thumbnailLength: f } = J(), { scrollBehavior: v } = K(), { totalPages: w } = Q(), S = P(null), C = P(c), A = P(f), [l, x] = B(null);
44
+ L(() => {
45
+ C.current = c;
46
+ }, [c]), L(() => {
47
+ A.current = f;
48
+ }, [f]);
49
+ const H = s((e) => {
50
+ S.current = e;
51
+ }, []), d = s(
52
+ (e) => {
53
+ const n = e + Y;
54
+ return w ? Math.min(n, w) : e;
55
+ },
56
+ [w]
57
+ ), _ = s(
58
+ (e) => {
59
+ const n = d(e);
60
+ return !C.current[e] || A.current < n ? (h(n), !1) : !0;
61
+ },
62
+ [h, d]
63
+ ), G = s(
64
+ (e, n) => {
65
+ u((o) => {
66
+ var m;
67
+ const t = (m = C.current[e]) == null ? void 0 : m.viewport, p = {
35
68
  width: t ? t.width : 0,
36
69
  height: t ? t.height : 0
37
70
  };
38
71
  return {
39
72
  ...o,
40
- [e]: i(o[e] ?? [], c, n[e] ?? 0)
73
+ [e]: n(o[e] ?? [], p, r[e] ?? 0)
41
74
  };
42
75
  });
43
76
  },
44
- [p, n]
45
- ), b = m((e) => {
46
- s((i) => {
47
- const o = { ...i };
77
+ [r]
78
+ ), O = s((e) => {
79
+ u((n) => {
80
+ const o = { ...n };
48
81
  return delete o[e], o;
49
82
  });
50
- }, []), A = m((e, i) => {
51
- s((o) => {
83
+ }, []), U = s((e, n) => {
84
+ u((o) => {
52
85
  const t = { ...o };
53
- return t[e] ? (t[e] = t[e].filter((c, l) => l !== i), t) : o;
86
+ return t[e] ? (t[e] = t[e].filter((p, m) => m !== n), t) : o;
54
87
  });
55
- }, []), S = m(
56
- (e, i, o) => {
57
- var v;
58
- const t = d.current;
88
+ }, []), T = s(
89
+ (e, n, o) => {
90
+ var F;
91
+ const t = S.current;
59
92
  if (!t)
60
- return;
61
- const c = t.querySelector(
93
+ return !1;
94
+ const p = t.querySelector(
62
95
  `[data-rp="thumbnail-${e}-customElement"]`
63
- ), l = (v = c == null ? void 0 : c.children) == null ? void 0 : v[i];
64
- if (!l)
65
- return;
66
- const T = t.getBoundingClientRect(), C = l.getBoundingClientRect(), P = t.scrollTop + (C.top - T.top) - U, _ = t.scrollLeft + (C.left - T.left);
67
- t.scrollTo({
68
- top: Math.max(P, 0),
69
- left: Math.max(_, 0),
70
- behavior: (o == null ? void 0 : o.behavior) ?? E
71
- });
96
+ ), m = (F = p == null ? void 0 : p.children) == null ? void 0 : F[n];
97
+ if (!m)
98
+ return !1;
99
+ const D = m.closest(`[id="page-${e}"]`) ?? m, M = t.getBoundingClientRect(), g = D.getBoundingClientRect(), N = t.scrollTop + (g.top - M.top) - (t.clientHeight - g.height) / 2, q = t.scrollLeft + (g.left - M.left) - (t.clientWidth - g.width) / 2;
100
+ return t.scrollTo({
101
+ top: I(N, t.scrollHeight - t.clientHeight),
102
+ left: I(q, t.scrollWidth - t.clientWidth),
103
+ behavior: (o == null ? void 0 : o.behavior) ?? v
104
+ }), !0;
72
105
  },
73
- [E]
106
+ [v]
107
+ ), W = s(
108
+ (e, n, o) => {
109
+ T(e, n, o) || (_(e), x({ page: e, index: n, config: o, attempt: 0 }));
110
+ },
111
+ [_, T]
74
112
  );
75
- return /* @__PURE__ */ y(
76
- f.Provider,
113
+ return L(() => {
114
+ if (!l)
115
+ return;
116
+ const e = d(l.page);
117
+ if (!c[l.page] || f < e) {
118
+ h(e);
119
+ return;
120
+ }
121
+ const n = window.requestAnimationFrame(() => {
122
+ if (T(
123
+ l.page,
124
+ l.index,
125
+ l.config
126
+ )) {
127
+ x(null);
128
+ return;
129
+ }
130
+ l.attempt < X && x((t) => !t || t.page !== l.page || t.index !== l.index ? t : { ...t, attempt: t.attempt + 1 });
131
+ });
132
+ return () => {
133
+ window.cancelAnimationFrame(n);
134
+ };
135
+ }, [
136
+ h,
137
+ d,
138
+ l,
139
+ T,
140
+ f,
141
+ c
142
+ ]), /* @__PURE__ */ $(
143
+ R.Provider,
77
144
  {
78
145
  value: {
79
- updateElement: R,
80
- clearElements: b,
81
- removeElement: A,
146
+ updateElement: G,
147
+ clearElements: O,
148
+ removeElement: U,
82
149
  elementList: a,
83
- scrollToElement: S,
84
- setThumbnailContainer: w
150
+ scrollToElement: W,
151
+ setThumbnailContainer: H
85
152
  },
86
- children: r
153
+ children: i
87
154
  }
88
155
  );
89
- }, u = () => {
90
- }, ut = () => {
91
- const r = L(f);
92
- return (r == null ? void 0 : r.setThumbnailContainer) ?? u;
93
- }, at = () => {
94
- const r = L(f), { type: a, validating: s } = G(), n = x(0), p = B(() => {
95
- if (s !== !1)
156
+ }, E = () => {
157
+ }, Nt = () => {
158
+ const i = y(R);
159
+ return (i == null ? void 0 : i.setThumbnailContainer) ?? E;
160
+ }, qt = () => {
161
+ const i = y(R), { type: a, validating: u } = z(), r = P(0), c = k(() => {
162
+ if (u !== !1)
96
163
  return {
97
- updateElement: u,
98
- clearElements: u,
99
- removeElement: u,
164
+ updateElement: E,
165
+ clearElements: E,
166
+ removeElement: E,
100
167
  elementList: {},
101
- scrollToElement: u
168
+ scrollToElement: E
102
169
  };
103
- if (!(a !== D.Developer))
170
+ if (!(a !== V.Developer))
104
171
  return {
105
172
  updateElement: () => {
106
- n.current === 0 && (console.error(h), n.current++);
173
+ r.current === 0 && (console.error(b), r.current++);
107
174
  },
108
175
  clearElements: () => {
109
- n.current === 0 && (console.error(h), n.current++);
176
+ r.current === 0 && (console.error(b), r.current++);
110
177
  },
111
178
  removeElement: () => {
112
- n.current === 0 && (console.error(h), n.current++);
179
+ r.current === 0 && (console.error(b), r.current++);
113
180
  },
114
181
  elementList: {},
115
182
  scrollToElement: () => {
116
- n.current === 0 && (console.error(h), n.current++);
183
+ r.current === 0 && (console.error(b), r.current++);
117
184
  }
118
185
  };
119
- }, [a, s]);
120
- if (!r)
186
+ }, [a, u]);
187
+ if (!i)
121
188
  throw new Error("useElementThumbnailContext must be used within a ElementThumbnailProvider");
122
- return p || r;
189
+ return c || i;
123
190
  };
124
191
  export {
125
- f as ElementThumbnailContext,
126
- mt as ElementThumbnailProvider,
127
- at as useElementThumbnailContext,
128
- ut as useThumbnailContainerRegister
192
+ R as ElementThumbnailContext,
193
+ Dt as ElementThumbnailProvider,
194
+ qt as useElementThumbnailContext,
195
+ Nt as useThumbnailContainerRegister
129
196
  };