@react-pdf-kit/viewer 2.9.1-rc.2 → 2.9.2-rc.0

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.
@@ -0,0 +1,717 @@
1
+ import { ErrorType as e, ScrollMode as t, SelectionMode as n } from "./utils/types.js";
2
+ import { useDocumentPasswordContext as r } from "./contexts/DocumentPasswordContext.js";
3
+ import { BROWSER_NOT_SUPPORTED_MESSAGE as i, INVALID_OR_CORRUPTED_PDF_MESSAGE as a, WASM_URL_REQUIRED_MESSAGE as o } from "./utils/const.js";
4
+ import { useDocumentContext as s } from "./contexts/RPDocumentContext.js";
5
+ import { useInitialStateContext as c } from "./contexts/InitialStateContext.js";
6
+ import { useScrollModeContext as l } from "./contexts/ScrollModeContext.js";
7
+ import { useViewModeContext as u } from "./contexts/ViewModeContext.js";
8
+ import { useVirtualScrollContext as d } from "./contexts/VirtualScrollContext.js";
9
+ import "./utils/constants.js";
10
+ import { useLayoutContainer as f } from "./contexts/LayoutContainerContext.js";
11
+ import { useEventCallbackContext as p } from "./contexts/EventCallbackContext.js";
12
+ import { useDebounce as m } from "./utils/hooks/useDebounce.js";
13
+ import { useZoomContext as h } from "./contexts/ZoomContext.js";
14
+ import { usePagesRotateContext as ee } from "./contexts/PagesRotateContext.js";
15
+ import { useDimensionPagesContext as te } from "./contexts/DimensionPagesContext.js";
16
+ import { useSmoothScrollContext as ne } from "./contexts/SmoothScrollContext.js";
17
+ import { buildDocumentLayout as re, getPageContentOffset as ie, getPageFromDocumentPoint as ae, getPagePlacement as oe, getRowsByIndexes as g, getVisibleRows as se } from "./utils/documentLayout.js";
18
+ import { a as ce, r as le } from "./PaginationContext-DIzsZhFd.js";
19
+ import { useSelectionModeContext as ue } from "./contexts/SelectionModeContext.js";
20
+ import { useFullScreenContext as de } from "./contexts/FullScreenContext.js";
21
+ import { useRenderQueue as fe } from "./contexts/RenderQueueProvider.js";
22
+ import { t as pe } from "./clsx-DSGuh5YW.js";
23
+ import { useLoaderContext as me } from "./contexts/LoaderContext.js";
24
+ import { LayoutContainer as he } from "./components/layout/LayoutContainer.js";
25
+ import { LayoutWrapper as ge } from "./components/layout/LayoutWrapper.js";
26
+ import { RPPage as _e } from "./components/page/RPPage.js";
27
+ import { t as ve } from "./PasswordModal-CxHFn0pB.js";
28
+ import { approximateFraction as ye } from "./utils/approximateFragtion.js";
29
+ import { useCopyText as be } from "./utils/hooks/useCopyText.js";
30
+ import { useGrabScroll as xe } from "./utils/hooks/useGrabScroll.js";
31
+ import { useMousePressed as Se } from "./utils/hooks/useMousePressed.js";
32
+ import { usePinch as Ce } from "./utils/hooks/usePinch.js";
33
+ import { usePresentPage as we } from "./utils/hooks/usePresentPage.js";
34
+ import { useTextSelection as Te } from "./utils/hooks/useTextSelection.js";
35
+ import { Component as Ee, createElement as De, useCallback as _, useEffect as v, useLayoutEffect as Oe, useMemo as y, useRef as b, useState as ke } from "react";
36
+ import { OutputScale as Ae } from "pdfjs-dist";
37
+ import { Fragment as je, jsx as x, jsxs as Me } from "react/jsx-runtime";
38
+ import './assets/RPPages.css';//#region node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.esm.js
39
+ var S = typeof window < "u" ? window : typeof self < "u" ? self : global, Ne = null, Pe = null, C = 20, w = S.clearTimeout, T = S.setTimeout, E = S.cancelAnimationFrame || S.mozCancelAnimationFrame || S.webkitCancelAnimationFrame, Fe = S.requestAnimationFrame || S.mozRequestAnimationFrame || S.webkitRequestAnimationFrame;
40
+ E == null || Fe == null ? (Ne = w, Pe = function(e) {
41
+ return T(e, C);
42
+ }) : (Ne = function([e, t]) {
43
+ E(e), w(t);
44
+ }, Pe = function(e) {
45
+ let t = Fe(function() {
46
+ w(n), e();
47
+ }), n = T(function() {
48
+ E(t), e();
49
+ }, C);
50
+ return [t, n];
51
+ });
52
+ function Ie(e) {
53
+ let t, n, r, i, a, o, s, c = typeof document < "u" && document.attachEvent;
54
+ if (!c) {
55
+ o = function(e) {
56
+ let t = e.__resizeTriggers__, n = t.firstElementChild, r = t.lastElementChild, i = n.firstElementChild;
57
+ r.scrollLeft = r.scrollWidth, r.scrollTop = r.scrollHeight, i.style.width = n.offsetWidth + 1 + "px", i.style.height = n.offsetHeight + 1 + "px", n.scrollLeft = n.scrollWidth, n.scrollTop = n.scrollHeight;
58
+ }, a = function(e) {
59
+ return e.offsetWidth !== e.__resizeLast__.width || e.offsetHeight !== e.__resizeLast__.height;
60
+ }, s = function(e) {
61
+ if (e.target.className && typeof e.target.className.indexOf == "function" && e.target.className.indexOf("contract-trigger") < 0 && e.target.className.indexOf("expand-trigger") < 0) return;
62
+ let t = this;
63
+ o(this), this.__resizeRAF__ && Ne(this.__resizeRAF__), this.__resizeRAF__ = Pe(function() {
64
+ a(t) && (t.__resizeLast__.width = t.offsetWidth, t.__resizeLast__.height = t.offsetHeight, t.__resizeListeners__.forEach(function(n) {
65
+ n.call(t, e);
66
+ }));
67
+ });
68
+ };
69
+ let e = !1, c = "";
70
+ r = "animationstart";
71
+ let l = "Webkit Moz O ms".split(" "), u = "webkitAnimationStart animationstart oAnimationStart MSAnimationStart".split(" "), d = "";
72
+ {
73
+ let t = document.createElement("fakeelement");
74
+ if (t.style.animationName !== void 0 && (e = !0), e === !1) {
75
+ for (let n = 0; n < l.length; n++) if (t.style[l[n] + "AnimationName"] !== void 0) {
76
+ d = l[n], c = "-" + d.toLowerCase() + "-", r = u[n], e = !0;
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ n = "resizeanim", t = "@" + c + "keyframes " + n + " { from { opacity: 0; } to { opacity: 0; } } ", i = c + "animation: 1ms " + n + "; ";
82
+ }
83
+ let l = function(n) {
84
+ if (!n.getElementById("detectElementResize")) {
85
+ let r = (t || "") + ".resize-triggers { " + (i || "") + "visibility: hidden; opacity: 0; } .resize-triggers, .resize-triggers > div, .contract-trigger:before { content: \" \"; display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; z-index: -1; } .resize-triggers > div { background: #eee; overflow: auto; } .contract-trigger:before { width: 200%; height: 200%; }", a = n.head || n.getElementsByTagName("head")[0], o = n.createElement("style");
86
+ o.id = "detectElementResize", o.type = "text/css", e != null && o.setAttribute("nonce", e), o.styleSheet ? o.styleSheet.cssText = r : o.appendChild(n.createTextNode(r)), a.appendChild(o);
87
+ }
88
+ };
89
+ return {
90
+ addResizeListener: function(e, t) {
91
+ if (c) e.attachEvent("onresize", t);
92
+ else {
93
+ if (!e.__resizeTriggers__) {
94
+ let t = e.ownerDocument, i = S.getComputedStyle(e);
95
+ i && i.position === "static" && (e.style.position = "relative"), l(t), e.__resizeLast__ = {}, e.__resizeListeners__ = [], (e.__resizeTriggers__ = t.createElement("div")).className = "resize-triggers";
96
+ let a = t.createElement("div");
97
+ a.className = "expand-trigger", a.appendChild(t.createElement("div"));
98
+ let c = t.createElement("div");
99
+ c.className = "contract-trigger", e.__resizeTriggers__.appendChild(a), e.__resizeTriggers__.appendChild(c), e.appendChild(e.__resizeTriggers__), o(e), e.addEventListener("scroll", s, !0), r && (e.__resizeTriggers__.__animationListener__ = function(t) {
100
+ t.animationName === n && o(e);
101
+ }, e.__resizeTriggers__.addEventListener(r, e.__resizeTriggers__.__animationListener__));
102
+ }
103
+ e.__resizeListeners__.push(t);
104
+ }
105
+ },
106
+ removeResizeListener: function(e, t) {
107
+ if (c) e.detachEvent("onresize", t);
108
+ else if (e.__resizeListeners__.splice(e.__resizeListeners__.indexOf(t), 1), !e.__resizeListeners__.length) {
109
+ e.removeEventListener("scroll", s, !0), e.__resizeTriggers__.__animationListener__ && (e.__resizeTriggers__.removeEventListener(r, e.__resizeTriggers__.__animationListener__), e.__resizeTriggers__.__animationListener__ = null);
110
+ try {
111
+ e.__resizeTriggers__ = !e.removeChild(e.__resizeTriggers__);
112
+ } catch {}
113
+ }
114
+ }
115
+ };
116
+ }
117
+ var D = class extends Ee {
118
+ constructor(...e) {
119
+ super(...e), this.state = {
120
+ height: this.props.defaultHeight || 0,
121
+ width: this.props.defaultWidth || 0
122
+ }, this._autoSizer = null, this._detectElementResize = null, this._didLogDeprecationWarning = !1, this._parentNode = null, this._resizeObserver = null, this._timeoutId = null, this._onResize = () => {
123
+ this._timeoutId = null;
124
+ let { disableHeight: e, disableWidth: t, onResize: n } = this.props;
125
+ if (this._parentNode) {
126
+ let r = window.getComputedStyle(this._parentNode) || {}, i = parseFloat(r.paddingLeft || "0"), a = parseFloat(r.paddingRight || "0"), o = parseFloat(r.paddingTop || "0"), s = parseFloat(r.paddingBottom || "0"), c = this._parentNode.getBoundingClientRect(), l = c.height - o - s, u = c.width - i - a;
127
+ if (!e && this.state.height !== l || !t && this.state.width !== u) {
128
+ this.setState({
129
+ height: l,
130
+ width: u
131
+ });
132
+ let e = () => {
133
+ this._didLogDeprecationWarning || (this._didLogDeprecationWarning = !0, console.warn("scaledWidth and scaledHeight parameters have been deprecated; use width and height instead"));
134
+ };
135
+ typeof n == "function" && n({
136
+ height: l,
137
+ width: u,
138
+ get scaledHeight() {
139
+ return e(), l;
140
+ },
141
+ get scaledWidth() {
142
+ return e(), u;
143
+ }
144
+ });
145
+ }
146
+ }
147
+ }, this._setRef = (e) => {
148
+ this._autoSizer = e;
149
+ };
150
+ }
151
+ componentDidMount() {
152
+ let { nonce: e } = this.props, t = this._autoSizer ? this._autoSizer.parentNode : null;
153
+ if (t != null && t.ownerDocument && t.ownerDocument.defaultView && t instanceof t.ownerDocument.defaultView.HTMLElement) {
154
+ this._parentNode = t;
155
+ let n = t.ownerDocument.defaultView.ResizeObserver;
156
+ n == null ? (this._detectElementResize = Ie(e), this._detectElementResize.addResizeListener(t, this._onResize)) : (this._resizeObserver = new n(() => {
157
+ this._timeoutId = setTimeout(this._onResize, 0);
158
+ }), this._resizeObserver.observe(t)), this._onResize();
159
+ }
160
+ }
161
+ componentWillUnmount() {
162
+ this._parentNode && (this._detectElementResize && this._detectElementResize.removeResizeListener(this._parentNode, this._onResize), this._timeoutId !== null && clearTimeout(this._timeoutId), this._resizeObserver && this._resizeObserver.disconnect());
163
+ }
164
+ render() {
165
+ let { children: e, defaultHeight: t, defaultWidth: n, disableHeight: r = !1, disableWidth: i = !1, doNotBailOutOnEmptyChildren: a = !1, nonce: o, onResize: s, style: c = {}, tagName: l = "div", ...u } = this.props, { height: d, width: f } = this.state, p = { overflow: "visible" }, m = {}, h = !1;
166
+ return r || (d === 0 && (h = !0), p.height = 0, m.height = d, m.scaledHeight = d), i || (f === 0 && (h = !0), p.width = 0, m.width = f, m.scaledWidth = f), a && (h = !1), De(l, {
167
+ ref: this._setRef,
168
+ style: {
169
+ ...p,
170
+ ...c
171
+ },
172
+ ...u
173
+ }, !h && e(m));
174
+ }
175
+ }, O = {
176
+ "rp-pages": "_rp-pages_ruuiz_1",
177
+ "rp-page-scrolling-wrapper": "_rp-page-scrolling-wrapper_ruuiz_6",
178
+ "rp-pages-flow": "_rp-pages-flow_ruuiz_6",
179
+ "rp-document-wrapper": "_rp-document-wrapper_ruuiz_17",
180
+ "rp-page-row": "_rp-page-row_ruuiz_22",
181
+ "rp-pages-horizontal-scroll": "_rp-pages-horizontal-scroll_ruuiz_26",
182
+ "rp-not-supported-list": "_rp-not-supported-list_ruuiz_30",
183
+ "rp-pages-container": "_rp-pages-container_ruuiz_38",
184
+ "rp-viewer": "_rp-viewer_ruuiz_80",
185
+ "rp-cursor-grab": "_rp-cursor-grab_ruuiz_85",
186
+ "rp-cursor-grabbing": "_rp-cursor-grabbing_ruuiz_93",
187
+ "rp-loader": "_rp-loader_ruuiz_101",
188
+ "rp-not-supported": "_rp-not-supported_ruuiz_30",
189
+ "rp-not-supported-content": "_rp-not-supported-content_ruuiz_120",
190
+ "rp-load-error": "_rp-load-error_ruuiz_126",
191
+ "rp-load-error-message": "_rp-load-error-message_ruuiz_134"
192
+ }, k = (e, t, n) => Math.max(t, Math.min(e, n)), A = 2, Le = 800, Re = .5, ze = 0, j = 1, M = 0, Be = (e) => ({
193
+ width: e.scrollWidth,
194
+ height: e.scrollHeight
195
+ }), Ve = (e, t, n, r, i) => {
196
+ let a = n.scrollTop - t.offsetTop, o = a + i, s = n.scrollLeft - t.offsetLeft, c = s + r, l = /* @__PURE__ */ new Map();
197
+ return e.forEach((e) => {
198
+ e.pages.forEach((e) => {
199
+ let t = e.left + e.width, n = e.top + e.height, r = Math.max(0, s - e.left), i = Math.max(0, a - e.top), u = Math.min(e.width, c - e.left), d = Math.min(e.height, o - e.top);
200
+ if (t <= s || e.left >= c || n <= a || e.top >= o) return;
201
+ let f = Math.max(0, u - r), p = Math.max(0, d - i), m = e.width * e.height || 1, h = Math.floor(f * p * 100 / m);
202
+ f > 0 && p > 0 && l.set(e.pageNumber, {
203
+ minX: r,
204
+ minY: i,
205
+ maxX: u,
206
+ maxY: d,
207
+ percent: h
208
+ });
209
+ });
210
+ }), l;
211
+ }, He = ({ row: e }) => /* @__PURE__ */ x("div", {
212
+ className: O["rp-page-row"],
213
+ style: {
214
+ position: "absolute",
215
+ top: e.top,
216
+ left: 0,
217
+ width: e.width,
218
+ height: e.height
219
+ },
220
+ children: e.pages.map((t) => /* @__PURE__ */ x(_e, {
221
+ pageNumber: t.pageNumber,
222
+ style: {
223
+ position: "absolute",
224
+ left: t.left,
225
+ top: t.top - e.top,
226
+ width: t.width,
227
+ height: t.height
228
+ }
229
+ }, t.pageNumber))
230
+ }), Ue = (t) => {
231
+ if (t === e.WASM_URL_REQUIRED) return o;
232
+ if (t === e.INVALID_OR_CORRUPTED_PDF) return a;
233
+ if (t === e.NOT_SUPPORTED) return i;
234
+ }, We = (e) => Object.entries(e).sort(([e], [t]) => Number(e) - Number(t)).map(([e, t]) => `${e}:${t}`).join("|"), Ge = ({ width: r, height: i }) => {
235
+ let { initialPage: a = 1, initialScrollMode: o } = c(), { pagesRef: he } = f(), { scrollToPage: ge } = ce(), { getPageScrollElementRef: _e, getVirtualScrollableElementRef: ve, setTotalInnerDimensions: ye, totalInnerDimensions: be, virtualScrollableElementRef: Te, pageScrollElementRef: Ee } = d(), De = b(a > 1), [Ae, je] = ke(a > 1), { nextPage: S, prevPage: Ne, setFocusedPage: Pe, focusedPage: C, totalPages: w } = le(), { scrollMode: T } = l(), { viewMode: E } = u(), { loading: Fe, error: Ie, pages: D } = s(), { pageRotate: Ge } = ee(), { LoaderImageComponent: Ke } = me(), { isFullScreen: qe } = de(), { onScroll: Je } = p(), { widths: Ye, heights: Xe } = te(), Ze = fe(), { targetZoom: N, zoomOrigin: Qe, isZooming: P, previousTargetZoom: $e, zoomGesture: et } = h(), { targetScrollPage: tt } = ne(), F = y(() => We(Ge), [Ge]), nt = m(be, 100), rt = b(null), I = b(be), it = b({
236
+ viewMode: E,
237
+ scrollMode: T
238
+ }), L = b(null), R = b(null), z = b(null), B = b(null), V = b(!1), H = b(!1), U = b(N), W = b(F), at = Ue(Ie), ot = b(), st = b(), ct = b(), G = b([]), lt = b([]), ut = b(P), dt = b(), ft = b([]), [pt, mt] = ke(!1), K = b({
239
+ scrollTop: 0,
240
+ scrollLeft: 0
241
+ }), [q, ht] = ke(K.current), J = T === t.PAGE_SCROLLING ? Ee ?? Te : Te ?? Ee, { isPressed: gt } = Se(), { initializeGrabScroll: _t, resetGrabState: vt } = xe({ isPressed: gt }), { selectionMode: yt } = ue(), bt = yt === n.HAND, Y = y(() => re({
242
+ pageDimensions: {
243
+ widths: Ye,
244
+ heights: Xe
245
+ },
246
+ viewportWidth: r,
247
+ viewportHeight: i,
248
+ scrollMode: T,
249
+ viewMode: E,
250
+ focusedPage: C
251
+ }), [
252
+ C,
253
+ i,
254
+ Xe,
255
+ T,
256
+ E,
257
+ r,
258
+ Ye
259
+ ]), X = y(() => se(Y, q.scrollTop, q.scrollLeft, r, i, 2), [
260
+ i,
261
+ Y,
262
+ q.scrollLeft,
263
+ q.scrollTop,
264
+ r
265
+ ]), xt = (e, t) => Array.from(new Set([...e, ...t.map((e) => e.index)])).sort((e, t) => e - t), St = y(() => P && G.current.length ? et === "touch" ? g(Y, G.current, lt.current) : g(Y, xt(G.current, X)) : pt && ft.current.length ? g(Y, xt(ft.current, X)) : X, [
266
+ X,
267
+ pt,
268
+ P,
269
+ Y,
270
+ et
271
+ ]), Ct = y(() => Ve(St, Y, q, r, i), [
272
+ i,
273
+ Y,
274
+ q,
275
+ St,
276
+ r
277
+ ]);
278
+ we(J, Y), v(() => {
279
+ let e = ut.current;
280
+ P || (e && G.current.length && (ft.current = G.current, clearTimeout(dt.current), mt(!0), dt.current = setTimeout(() => {
281
+ ft.current = [], mt(!1);
282
+ }, Le)), G.current = X.map((e) => e.index), lt.current = X.flatMap((e) => e.pages.map((e) => e.pageNumber))), ut.current = P;
283
+ }, [X, P]), v(() => {
284
+ Array.from(Ct.entries()).sort(([, e], [, t]) => t.percent - e.percent).forEach(([e], t) => {
285
+ Ze.changePagePriority(`^page-${e}$`, t);
286
+ });
287
+ }, [Ct, Ze]), v(() => {
288
+ P && Ze.removeQueues(/^page-/);
289
+ }, [P, Ze]), v(() => {
290
+ Fe && vt();
291
+ }, [Fe, vt]), v(() => {
292
+ if (!at) return;
293
+ let e = requestAnimationFrame(() => {
294
+ rt.current?.focus();
295
+ });
296
+ return () => {
297
+ cancelAnimationFrame(e);
298
+ };
299
+ }, [at]);
300
+ let Z = _((e) => {
301
+ let t = D.get(e);
302
+ return Ge[e] ?? t?.defaultRotation ?? 0;
303
+ }, [Ge, D]), wt = _((e, t = C) => {
304
+ let n = [], a = [];
305
+ for (let t = 1; t <= w; t += 1) {
306
+ let r = D.get(t);
307
+ if (!r) continue;
308
+ let i = Z(t), o = r.page.getViewport({
309
+ scale: 1,
310
+ rotation: i,
311
+ dontFlip: !0
312
+ });
313
+ n[t - 1] = o.width * e + 4, a[t - 1] = o.height * e + 4;
314
+ }
315
+ return re({
316
+ pageDimensions: {
317
+ widths: n,
318
+ heights: a
319
+ },
320
+ viewportWidth: r,
321
+ viewportHeight: i,
322
+ scrollMode: T,
323
+ viewMode: E,
324
+ focusedPage: t
325
+ });
326
+ }, [
327
+ C,
328
+ Z,
329
+ i,
330
+ D,
331
+ T,
332
+ w,
333
+ E,
334
+ r
335
+ ]), Tt = _((e, t, n) => {
336
+ let r = J ? Math.max(0, n.scrollHeight - J.clientHeight) : Math.max(0, n.scrollHeight), i = J ? Math.max(0, n.scrollWidth - J.clientWidth) : Math.max(0, n.scrollWidth);
337
+ return {
338
+ scrollTop: Math.round(k(e, 0, r)) || 0,
339
+ scrollLeft: Math.round(k(t, 0, i)) || 0
340
+ };
341
+ }, [J]), Q = _((e) => ({
342
+ maxScrollTop: J ? Math.max(0, e.scrollHeight - J.clientHeight) : Math.max(0, e.scrollHeight),
343
+ maxScrollLeft: J ? Math.max(0, e.scrollWidth - J.clientWidth) : Math.max(0, e.scrollWidth)
344
+ }), [J]), Et = _(() => J ? [J.clientWidth / 2, J.clientHeight / 2] : null, [J]), Dt = _((e) => {
345
+ if (!J) return {
346
+ scrollTop: 0,
347
+ scrollLeft: 0
348
+ };
349
+ let { maxScrollTop: t, maxScrollLeft: n } = Q(e), r = K.current.scrollTop, i = K.current.scrollLeft, a = t > A && t - r <= A, o = n > A && n - i <= A;
350
+ return a || o || r > t || i > n ? K.current : {
351
+ scrollTop: J.scrollTop,
352
+ scrollLeft: J.scrollLeft
353
+ };
354
+ }, [Q, J]), Ot = _((e, t, n, r, i) => {
355
+ if (!n || !r || !i || !D.size) return null;
356
+ let a = t + n[0] - i.offsetLeft, o = e + n[1] - i.offsetTop, s = ae(i, a, o) ?? oe(i, C);
357
+ if (!s) return null;
358
+ let c = D.get(s.pageNumber);
359
+ if (!c) return null;
360
+ let l = Z(s.pageNumber), u = c.page.getViewport({
361
+ scale: r,
362
+ rotation: l
363
+ }), d = ie(s.width, s.height, u.width, u.height), f = k(a - s.left - d.x, 0, u.width), p = k(o - s.top - d.y, 0, u.height), [m, h] = u.convertToPdfPoint(f, p);
364
+ return {
365
+ pageNumber: s.pageNumber,
366
+ pdfX: m,
367
+ pdfY: h,
368
+ origin: n
369
+ };
370
+ }, [
371
+ C,
372
+ Z,
373
+ D
374
+ ]), $ = _((e, t, n, r, i) => {
375
+ if (!i) return null;
376
+ let a = Ot(e, t, n, r, i), { maxScrollTop: o, maxScrollLeft: s } = Q(i), c = a?.pageNumber === 1, l = a?.pageNumber === w, u = (o <= A || e <= A) && c ? "start" : o > A && l && o - e <= A ? "end" : null;
377
+ return {
378
+ location: a,
379
+ edgeX: (s <= A || t <= A) && c ? "start" : s > A && l && s - t <= A ? "end" : null,
380
+ edgeY: u,
381
+ previousScale: r
382
+ };
383
+ }, [
384
+ Ot,
385
+ Q,
386
+ w
387
+ ]), kt = _((e, t, n) => {
388
+ let r = D.get(t.pageNumber), i = oe(n, t.pageNumber);
389
+ if (!r || !i || !e) return null;
390
+ let a = Z(t.pageNumber), o = r.page.getViewport({
391
+ scale: e,
392
+ rotation: a
393
+ }), [s, c] = o.convertToViewportPoint(t.pdfX, t.pdfY), l = ie(i.width, i.height, o.width, o.height);
394
+ return {
395
+ left: n.offsetLeft + i.left + l.x + s - t.origin[0],
396
+ top: n.offsetTop + i.top + l.y + c - t.origin[1]
397
+ };
398
+ }, [Z, D]), At = _((e, t, n, r, i, a, o = !0) => {
399
+ let s = e?.location ? kt(t, e.location, n) : null, c = a ? t / a : 1, l = s ?? {
400
+ left: (r.scrollLeft + i[0]) * c - i[0],
401
+ top: (r.scrollTop + i[1]) * c - i[1]
402
+ }, { maxScrollTop: u, maxScrollLeft: d } = Q(n), f = o && e && t < e.previousScale ? {
403
+ top: e.edgeY === "start" ? 0 : e.edgeY === "end" ? u : l.top,
404
+ left: e.edgeX === "start" ? 0 : e.edgeX === "end" ? d : l.left
405
+ } : l;
406
+ return Tt(f.top, f.left, n);
407
+ }, [
408
+ kt,
409
+ Tt,
410
+ Q
411
+ ]), jt = _((e, t) => {
412
+ (V.current || z.current || B.current) && (H.current = !0), J?.scrollTo({
413
+ top: e,
414
+ left: t,
415
+ behavior: "auto"
416
+ }), K.current = {
417
+ scrollTop: e,
418
+ scrollLeft: t
419
+ }, ht(K.current);
420
+ }, [J]), Mt = _(({ gesture: e, origin: t, previousScale: n, nextScale: r }) => {
421
+ if (!n || !r) return;
422
+ let i = t ?? Et();
423
+ if (!i) return;
424
+ e === "touch" && (V.current = !0);
425
+ let a = B.current, o = a?.scale || U.current || n, s = a?.layout ?? L.current ?? Y, c = a?.scrollTop ?? K.current.scrollTop, l = a?.scrollLeft ?? K.current.scrollLeft, u = wt(r), d = $(c, l, i, o, s), f = At(d, r, u, {
426
+ scrollTop: c,
427
+ scrollLeft: l
428
+ }, i, o, e !== "touch");
429
+ z.current = {
430
+ anchor: d,
431
+ nextScale: r,
432
+ targetScrollTop: f.scrollTop,
433
+ targetScrollLeft: f.scrollLeft,
434
+ targetLayout: u
435
+ }, B.current = {
436
+ scale: r,
437
+ layout: u,
438
+ scrollTop: f.scrollTop,
439
+ scrollLeft: f.scrollLeft
440
+ }, R.current = d;
441
+ }, [
442
+ At,
443
+ $,
444
+ Et,
445
+ wt,
446
+ Y
447
+ ]), Nt = _(() => {
448
+ V.current = !1, H.current = !1, z.current || (B.current = null, R.current = null);
449
+ }, []), Pt = _(() => {
450
+ V.current = !1, H.current = !1, z.current = null, B.current = null, R.current = null;
451
+ }, []);
452
+ Ce(J || he, {
453
+ onBeforeZoom: Mt,
454
+ onPinchEnd: Nt
455
+ });
456
+ let Ft = _((e, t) => {
457
+ if (it.current.viewMode !== E || it.current.scrollMode !== T) {
458
+ st.current && clearTimeout(st.current), R.current = null, Pt(), ge(C, "auto"), st.current = setTimeout(() => {
459
+ requestAnimationFrame(() => {
460
+ it.current = {
461
+ viewMode: E,
462
+ scrollMode: T
463
+ }, L.current = Y, U.current = N, W.current = F;
464
+ });
465
+ }, 100);
466
+ return;
467
+ }
468
+ let n = e.scrollTop, r = e.scrollLeft;
469
+ if (!t.height || !t.width) return;
470
+ let { height: i, width: o } = t, { height: s, width: c } = I.current, l = L.current, u = Math.abs(U.current - N) > 1e-10, d = W.current !== F, f = Qe ?? Et(), p = u && !!f, m = U.current || $e || N, h = z.current, ee = h?.nextScale ?? N, te = s === i && c === o;
471
+ if (d && !(De.current && a > 1)) {
472
+ let e = [l ? l.viewportWidth * Re : M, l ? l.viewportHeight * ze : M], i = r + e[0] - (l?.offsetLeft ?? M), a = n + e[1] - (l?.offsetTop ?? M), o = l ? ae(l, i, a) ?? oe(l, C) : null, s = o ? oe(Y, o.pageNumber) : null, c = Math.max(j, o ? o.width - 4 : j), u = Math.max(j, o ? o.height - 4 : j), d = Math.max(j, s ? s.width - 4 : j), f = Math.max(j, s ? s.height - 4 : j), p = o ? (o.width - c) * Re : M, m = s ? (s.width - d) * Re : M, h = o ? k(i - o.left - p, M, c) / c : ze, ee = o ? k(a - o.top, M, u) / u : ze, te = s ? {
473
+ left: Y.offsetLeft + s.left + m + d * h - e[0],
474
+ top: Y.offsetTop + s.top + f * ee - e[1]
475
+ } : null, ne = Tt(te?.top ?? n, te?.left ?? r, Y);
476
+ o && (tt.current = o.pageNumber), jt(ne.scrollTop, ne.scrollLeft), R.current = null, Pt(), I.current = {
477
+ height: t.height,
478
+ width: t.width
479
+ }, L.current = Y, U.current = N, W.current = F;
480
+ return;
481
+ }
482
+ if (u && !Qe && !h && l && s && c) {
483
+ let e = [l.viewportWidth / 2, 0], i = At($(n, r, e, m, l), N, Y, {
484
+ scrollTop: n,
485
+ scrollLeft: r
486
+ }, e, m);
487
+ jt(i.scrollTop, i.scrollLeft), R.current = null, I.current = {
488
+ height: t.height,
489
+ width: t.width
490
+ }, L.current = Y, U.current = N, W.current = F;
491
+ return;
492
+ }
493
+ if (te) {
494
+ if (W.current = F, h) {
495
+ jt(h.targetScrollTop, h.targetScrollLeft), R.current = null, z.current = null, V.current || (B.current = null, H.current = !1), L.current = h.targetLayout, U.current = h.nextScale, I.current = {
496
+ height: t.height,
497
+ width: t.width
498
+ };
499
+ return;
500
+ }
501
+ if (p && l) {
502
+ R.current = $(n, r, f, m, l);
503
+ return;
504
+ }
505
+ L.current = Y, U.current = N;
506
+ return;
507
+ }
508
+ if (De.current && a > 1) {
509
+ R.current = null, Pt(), I.current = {
510
+ height: t.height,
511
+ width: t.width
512
+ }, L.current = Y, U.current = N, W.current = F;
513
+ return;
514
+ }
515
+ if (!s || !c) {
516
+ R.current = null, Pt(), I.current = {
517
+ height: t.height,
518
+ width: t.width
519
+ }, L.current = Y, U.current = N, W.current = F;
520
+ return;
521
+ }
522
+ let ne = !!h, re = !!R.current?.location;
523
+ if (n === 0 && r === 0 && !(ne || (u || re) && (f || re))) {
524
+ I.current = {
525
+ height: t.height,
526
+ width: t.width
527
+ }, L.current = Y, U.current = N, W.current = F;
528
+ return;
529
+ }
530
+ let ie = n / s * i, g = r / c * o, se = !1;
531
+ if (h) g = h.targetScrollLeft, ie = h.targetScrollTop, se = !0;
532
+ else if ((u || re) && l && f) {
533
+ let e = At(R.current ?? $(n, r, f, m, l), N, Y, {
534
+ scrollTop: n,
535
+ scrollLeft: r
536
+ }, f, m);
537
+ g = e.scrollLeft, ie = e.scrollTop, se = !0;
538
+ }
539
+ let ce = Tt(ie, g, Y);
540
+ se ? jt(ce.scrollTop, ce.scrollLeft) : ot.current = setTimeout(() => {
541
+ requestAnimationFrame(() => {
542
+ jt(ce.scrollTop, ce.scrollLeft);
543
+ });
544
+ }, 0), R.current = null, z.current = null, V.current || (B.current = null, H.current = !1), I.current = {
545
+ height: t.height,
546
+ width: t.width
547
+ }, L.current = Y, U.current = ee, W.current = F;
548
+ }, [
549
+ At,
550
+ $,
551
+ C,
552
+ Z,
553
+ Et,
554
+ a,
555
+ Y,
556
+ D,
557
+ $e,
558
+ Pt,
559
+ F,
560
+ T,
561
+ ge,
562
+ jt,
563
+ N,
564
+ E,
565
+ Qe
566
+ ]);
567
+ Oe(() => {
568
+ clearTimeout(ot.current);
569
+ let e = Be(Y), t = !!z.current, n = W.current !== F, r = t || n ? K.current : Dt(Y);
570
+ !t && !n && (K.current = r, ht(r)), Ft(r, e), ye(e);
571
+ }, [
572
+ Dt,
573
+ Y,
574
+ F,
575
+ ye,
576
+ Ft
577
+ ]);
578
+ let It = _((e) => {
579
+ let t = document.activeElement !== he;
580
+ !qe && t || (["ArrowUp", "ArrowLeft"].includes(e.key) ? (e.preventDefault(), Ne()) : ["ArrowDown", "ArrowRight"].includes(e.key) && (e.preventDefault(), S()));
581
+ }, [
582
+ qe,
583
+ S,
584
+ he,
585
+ Ne
586
+ ]);
587
+ v(() => (window.addEventListener("keydown", It), () => {
588
+ window.removeEventListener("keydown", It);
589
+ }), [It]), v(() => () => {
590
+ st.current && clearTimeout(st.current), clearTimeout(dt.current), ct.current && cancelAnimationFrame(ct.current);
591
+ }, []), v(() => {
592
+ nt.height === 0 || !De.current || J && (ge(a, "auto"), requestAnimationFrame(() => {
593
+ Pe(a), De.current = !1, je(!1);
594
+ }));
595
+ }, [
596
+ nt.height,
597
+ a,
598
+ o,
599
+ ge,
600
+ J,
601
+ Pe
602
+ ]);
603
+ let Lt = _((e) => {
604
+ e && (ve(e), _e(e), bt && _t(e));
605
+ }, [
606
+ _e,
607
+ ve,
608
+ _t,
609
+ bt
610
+ ]), Rt = _((e) => {
611
+ let t = e.currentTarget, n = {
612
+ scrollTop: t.scrollTop,
613
+ scrollLeft: t.scrollLeft
614
+ };
615
+ if (V.current || z.current || H.current) {
616
+ H.current = !1, Je?.(e.nativeEvent);
617
+ return;
618
+ }
619
+ K.current = n, ct.current && cancelAnimationFrame(ct.current), ct.current = requestAnimationFrame(() => {
620
+ ht(n);
621
+ }), Je?.(e.nativeEvent);
622
+ }, [Je]);
623
+ return Ie === e.INVALID_OR_CORRUPTED_PDF ? /* @__PURE__ */ x("div", {
624
+ ref: rt,
625
+ className: O["rp-load-error"],
626
+ style: {
627
+ width: r,
628
+ height: i
629
+ },
630
+ tabIndex: -1,
631
+ role: "alert",
632
+ "aria-live": "assertive",
633
+ "aria-atomic": "true",
634
+ children: /* @__PURE__ */ x("div", {
635
+ className: O["rp-load-error-message"],
636
+ children: "Invalid or corrupted PDF file."
637
+ })
638
+ }) : Ie === e.NOT_SUPPORTED ? /* @__PURE__ */ x("div", {
639
+ className: O["rp-not-supported"],
640
+ style: {
641
+ width: r,
642
+ height: i
643
+ },
644
+ children: /* @__PURE__ */ Me("div", {
645
+ className: O["rp-not-supported-content"],
646
+ children: ["React PDF Kit is unable to render on this browser. Please use the supported browsers from the list below:", /* @__PURE__ */ x("div", { children: /* @__PURE__ */ Me("ul", {
647
+ className: O["rp-not-supported-list"],
648
+ children: [
649
+ /* @__PURE__ */ x("li", { children: "Chrome 126+" }),
650
+ /* @__PURE__ */ x("li", { children: "Edge 126+" }),
651
+ /* @__PURE__ */ x("li", { children: "Firefox 126+" }),
652
+ /* @__PURE__ */ x("li", { children: "Safari 18.4+" }),
653
+ /* @__PURE__ */ x("li", { children: "Safari iOS 18.4+" }),
654
+ /* @__PURE__ */ x("li", { children: "Chrome Android 126+" })
655
+ ]
656
+ }) })]
657
+ })
658
+ }) : !Y.pages.length && !Fe && !Ie ? /* @__PURE__ */ x("div", {
659
+ className: O["rp-loader"],
660
+ style: {
661
+ width: r,
662
+ height: i
663
+ },
664
+ children: Ke && /* @__PURE__ */ x(Ke, {})
665
+ }) : /* @__PURE__ */ x("div", {
666
+ "data-rp": "pages",
667
+ ref: Lt,
668
+ className: pe(O["rp-pages"], O["rp-pages-flow"], T === t.HORIZONTAL_SCROLLING && O["rp-pages-horizontal-scroll"], T === t.PAGE_SCROLLING && O["rp-page-scrolling-wrapper"]),
669
+ onScroll: Rt,
670
+ style: {
671
+ width: r,
672
+ height: i,
673
+ ...Ae && { visibility: "hidden" }
674
+ },
675
+ children: /* @__PURE__ */ x("div", {
676
+ className: O["rp-document-wrapper"],
677
+ style: {
678
+ width: Y.documentWidth,
679
+ height: Y.documentHeight,
680
+ marginLeft: Y.offsetLeft,
681
+ marginTop: Y.offsetTop,
682
+ "--rp-pages-height": `${Y.documentHeight}px`,
683
+ "--rp-pages-width": `${Y.documentWidth}px`
684
+ },
685
+ children: St.map((e) => /* @__PURE__ */ x(He, { row: e }, e.index))
686
+ })
687
+ });
688
+ }, Ke = () => {
689
+ let e = b(new Ae()), { pagesRef: t, setPagesRef: i, setContentRef: a } = f(), { passwordRequired: o } = r(), { onTextSelect: s } = p(), { selectionMode: c } = ue(), { isPressed: l } = Se(), u = c === n.HAND, d = y(() => pe(O["rp-pages-container"], {
690
+ [O["rp-cursor-grab"]]: u && !l,
691
+ [O["rp-cursor-grabbing"]]: u && l
692
+ }), [u, l]);
693
+ return be(t), Te({
694
+ onTextSelect: s,
695
+ pagesRef: t
696
+ }), /* @__PURE__ */ Me(je, { children: [/* @__PURE__ */ x(ge, {
697
+ ref: a,
698
+ children: /* @__PURE__ */ x(he, {
699
+ ref: i,
700
+ tabIndex: -1,
701
+ className: d,
702
+ style: {
703
+ "--scale-round-x": `${ye(e.current.sx)[1]}px`,
704
+ "--scale-round-y": `${ye(e.current.sy)[1]}px`
705
+ },
706
+ children: /* @__PURE__ */ x(D, {
707
+ style: { minHeight: "50px" },
708
+ children: ({ width: e, height: t }) => /* @__PURE__ */ x(Ge, {
709
+ width: e,
710
+ height: t
711
+ })
712
+ })
713
+ })
714
+ }), o && /* @__PURE__ */ x(ve, {})] });
715
+ };
716
+ //#endregion
717
+ export { Ke as t };