UNPKG

@pdf-viewer/react

Version:

The PDF Viewer component for React and Next.js

1,475 lines 118 kB
import { jsx as i, Fragment as fe, jsxs as F } from "react/jsx-runtime"; import * as B from "react"; import { useRef as H, useEffect as W, useCallback as N, useState as $, useMemo as k, createContext as Ye, useContext as Je, forwardRef as $e, useImperativeHandle as cn, createElement as qe, PureComponent as Qn, Component as er, memo as ln } from "react"; import { ChevronUpIcon as He } from "./components/icons/ChevronUpIcon.js"; import { UIButton as re } from "./components/ui/Button.js"; import { UIInput as dn } from "./components/ui/Input.js"; import { ViewMode as xe, ScrollMode as J, AnnotationSubType as zt, SelectionMode as tr, ZoomLevel as at } from "./utils/types.js"; import { useScrollModeContext as Re } from "./contexts/ScrollModeContext.js"; import { useDocumentContext as Q } from "./contexts/RPDocumentContext.js"; import { useDocumentPasswordContext as nr } from "./contexts/DocumentPasswordContext.js"; import { useDarkModeContext as rr } from "./contexts/DarkModeContext.js"; import { useRotationContext as Ge } from "./contexts/RotationContext.js"; import { useLayerContext as or } from "./contexts/LayerContext.js"; import { useZoomContext as Qe } from "./contexts/ZoomContext.js"; import { useViewModeContext as Ee } from "./contexts/ViewModeContext.js"; import { useVirtualScrollContext as et } from "./contexts/VirtualScrollContext.js"; import { useVirtualGridContext as un } from "./contexts/VirtualGridContext.js"; import { useSelectionModeContext as ir } from "./contexts/SelectionModeContext.js"; import { useInitialStateContext as ar } from "./contexts/InitialStateContext.js"; import { useFullScreenContext as sr } from "./contexts/FullScreenContext.js"; import "./contexts/FileInputContext.js"; import "./contexts/DropFileZoneContext.js"; import { renderPage as vt } from "./utils/renderPage.js"; import { findMatches as cr, resetDivs as lr, highlightMatches as dr, isMatchEntireWord as ur } from "./utils/highlight.js"; import { useLayoutContainer as ge } from "./contexts/LayoutContainerContext.js"; import { useDimensionPagesContext as Ue } from "./contexts/DimensionPagesContext.js"; import { useLocalizationContext as se } from "./contexts/LocalizationContext.js"; import { useHighlightContext as pr } from "./contexts/HighlightContext.js"; import "./contexts/LicenseContext.js"; import { useDownloadContext as hr } from "./contexts/DownloadContext.js"; import { useSmoothScrollContext as pn } from "./contexts/SmoothScrollContext.js"; import { useLoaderContext as hn } from "./contexts/LoaderContext.js"; import "./components/RPConfig.js"; import { ThumbnailIcon as mr } from "./components/icons/Thumbnail.js"; import { c as ne } from "./clsx-0c6e471a.js"; import { LoaderIcon as Ct } from "./components/icons/LoaderIcon.js"; import { useInfiniteScroll as fr } from "./utils/hooks/useInfiniteScroll.js"; import { RPSplitter as gr } from "./components/layout/sidebar/RPSplitter.js"; import { useToolbarComponentContext as ve, ToolbarComponentProvider as vr } from "./contexts/ToolbarComponentContext.js"; import { useIconContext as pe, IconProvider as wr } from "./contexts/IconContext.js"; import K from "./components/ui/RPTooltip.js"; import { Container as _r } from "./components/layout/Container.js"; import { WrapperLayout as br } from "./components/layout/WrapperLayout.js"; import { RPDropFileZone as Cr } from "./components/RPDropFileZone.js"; import { useViewportContext as Ce, ViewportProvider as Pr } from "./contexts/ViewportContext.js"; import { useThemeContext as Tr } from "./contexts/ThemeContext.js"; import * as Sr from "pdfjs-dist"; import { PixelsPerInch as yr, AnnotationMode as Ir, RenderingCancelledException as xr, AnnotationLayer as Lr } from "pdfjs-dist"; import { SimpleLinkService as Rr } from "./utils/link_service.js"; import { annotationsEvents as Er, annotationEventsHandler as Nr, handleClick as At, handleAnnotationWidget as Or, handleAnnotationLink as Dr, bindLayerEvents as zr, unbindLayerEvents as Ft } from "./utils/annotations.js"; import { normalizeSingleKeyword as Ar, sortHighlightPosition as Fr, unwrap as Wr } from "./components/page/searchHighlight.js"; import { _ as kr, U as Mr } from "./Popover-b7402893.js"; import { useMousePressed as Hr } from "./utils/hooks/useMousePressed.js"; import { useGrabScroll as $r } from "./utils/hooks/useGrabScroll.js"; import { usePinch as Gr } from "./utils/hooks/usePinch.js"; import { useDebounce as Pt } from "./utils/hooks/useDebounce.js"; import Ur from "./components/ui/PasswordModal.js"; import { getPositionFromPage as Vr, getPageFromPosition as qr } from "./utils/calculatePage.js"; import { getScrollDistance as Ae } from "./utils/getScrollDistance.js"; import { getWordPositionInPage as Br } from "./utils/getWordPositionInPage.js"; import { getThumbnailViewport as Wt } from "./utils/getThumbnailViewport.js"; import { smoothScrollTo as st } from "./utils/smoothScrollTo.js"; import { appConsole as Zr } from "./utils/appConsole.js"; import { FileUploadTool as mn } from "./components/layout/toolbar/FileUploadTool.js"; import { DarkModeTool as jr } from "./components/layout/toolbar/DarkModeTool.js"; import { ThreeDotIcon as Kr } from "./components/icons/ThreeDotIcon.js"; import { UIDropDown as fn } from "./components/ui/DropDown.js"; import { e as Xr, a as Tt, P as Ve, c as Me, g as St, i as Yr, k as Jr, f as Qr } from "./index-1cb41342.js"; import { D as eo, u as ct } from "./index-aa2d3884.js"; import { a as to, u as no, F as ro, b as oo, G as Ke } from "./index-7279fb4e.js"; import { h as io } from "./component-1da194e8.js"; import { CloseIcon as ao } from "./components/icons/CloseIcon.js"; import { dateFormatter as kt } from "./utils/dateFormatter.js"; import { PropertyItem as so } from "./components/layout/toolbar/PropertyItem.js"; import { useOtherToolContext as co, OtherToolProvider as lo } from "./contexts/OtherToolContext.js"; import { DocumentProperties as uo } from "./components/layout/toolbar/DocumentProperties.js"; import { RotateTool as po } from "./components/layout/toolbar/RotateTool.js"; import { ViewModeTool as ho } from "./components/layout/toolbar/ViewModeTool.js"; import { ScrollModeTool as mo } from "./components/layout/toolbar/ScrollModeTool.js"; import { MenuSeparator as yt } from "./components/layout/toolbar/MenuSeparator.js"; import { FileDownloadDefaultIcon as fo } from "./components/icons/FileDownloadDefaultIcon.js"; import { MenuItem as be } from "./components/layout/toolbar/MenuItem.js"; import { PrintDefaultTool as go } from "./components/icons/PrintDefaultIcon.js"; import { FullScreenTool as gn } from "./components/layout/toolbar/FullScreenTool.js"; import { GoToDownIcon as vn } from "./components/icons/GoToDownIcon.js"; import { SelectionModeTool as vo } from "./components/layout/toolbar/SelectionModeTool.js"; import { ZoomInIcon as wo } from "./components/icons/ZoomInIcon.js"; import { ZoomOutIcon as _o } from "./components/icons/ZoomOutIcon.js"; import { PAGE_PADDING as Mt } from "./utils/constants.js"; import { getZoomLevel as bo } from "./utils/getZoomLevel.js"; import { SearchIcon as Co } from "./components/icons/SearchIcon.js"; import { c as Y, S as Ht } from "./SearchCloseButton-ddb9877e.js"; import { UICheckbox as $t } from "./components/ui/Checkbox.js"; import { ClearIcon as Po } from "./components/icons/ClearIcon.js"; import { InfoIcon as Gt } from "./components/icons/InfoIcon.js"; import './assets/RPDefaultLayout.css';const wn = () => { const { viewMode: t } = Ee(), { scrollMode: e } = Re(), { virtualScrollRef: n, virtualScrollableElementRef: o, pageScrollElementRef: r } = et(), { setFocusedPage: a } = ie(), l = H(), { columnCount: c } = un(), { widths: d, heights: p } = Ue(), f = H(e), _ = H(t), h = H(c), { targetScrollPage: v } = pn(); W(() => { n != null && n.scrollToItem && (l.current = n); }, [n]), W(() => { f.current = e, _.current = t; }, [e, t]); const w = N( (P, S) => { if (!r) return; const u = Math.ceil(P / 2) * 2 - 1; if (P === u + 1) { const g = { left: d[u], top: 0 }; return new Promise( (s) => st(r, g, s) ); } const m = { left: 0, top: 0 }; return r == null ? void 0 : r.scrollTo({ ...m, behavior: S }); }, [r, d, st] ); return W(() => { f.current = e, _.current = t; }, [e, t]), W(() => { h.current = c; }, [c]), { scrollToPage: N( (P, S = "smooth") => { a(P); const u = P - 1; let m = u, g = 0; if (_.current === xe.DUAL_PAGE && f.current === J.PAGE_SCROLLING) { w(P, S); return; } if (f.current === J.PAGE_SCROLLING) { a(P); return; } if (!l.current || !o) return; const s = o; if (v.current = P, f.current === J.HORIZONTAL_SCROLLING) { g = u; const y = { left: Ae(d, g), top: 0 }; return s.scrollTo({ ...y, behavior: S }); } if (_.current === xe.DUAL_PAGE) { g = u % 2, m = Math.floor(u / 2); const y = { left: Ae(d, g), top: Ae(p, m) }; return s.scrollTo({ ...y, behavior: S }); } const C = { left: 0, top: Ae(p, m) }; return s.scrollTo({ ...C, behavior: S }); }, [ o, c, w, a, st, p, d ] ) }; }, To = (t = 1) => { const [e, n] = $(t), [o, r] = $(0), { scrollToPage: a } = wn(), l = H(1), { viewMode: c } = Ee(), { scrollMode: d } = Re(), { widths: p } = Ue(), { pagesRef: f } = ge(), _ = Pt(e, 100), h = N( (m) => { if (!/^[0-9]*$/g.test(m.toString()) || !m) return { success: !1, currentPage: l.current }; const s = +m; return s < 0 || s > o ? { success: !1, currentPage: l.current } : (n(s), l.current = s, { success: !0, currentPage: +m }); }, [o] ), v = N(h, [h]), w = N( (m) => { const g = h(m); return g.success && a(g.currentPage), g; }, [h, a] ), T = N((m) => { const g = m % 2 === 1; if (!f || g) return !1; const s = g ? p[m] : p[m - 1], C = g ? p[m + 1] : p[m]; return c === xe.DUAL_PAGE && s + C < f.clientWidth; }, [c, p, f, o]), P = N(() => { let m = e - 1; T(m) && (m = e - 2), w(m); }, [w, e, c, d, T]), S = k(() => c === xe.DUAL_PAGE && d === J.PAGE_SCROLLING ? e === o - 1 : e === o, [e, o, c, d]), u = N(() => { if (S) return; let m = e + 1; T(m) && (m = e + 2), w(m); }, [w, e, T, c, d, S]); return { focusedPage: _, totalPages: o, setFocusedPage: v, setTotalPages: r, nextPage: u, prevPage: P, goToPage: w }; }, _n = Ye({ focusedPage: 0, setFocusedPage: (t) => { }, goToPage: (t) => ({ success: !!t, currentPage: +t }), totalPages: 0, setTotalPages: (t) => { }, prevPage: () => { }, nextPage: () => { } }), ie = () => { const t = Je(_n); return typeof (t == null ? void 0 : t.focusedPage) > "u" && Zr.error("Please use this hooks inside children component of RPProvider"), t; }, Ms = ({ children: t }) => { const { pdf: e } = Q(), { focusedPage: n, totalPages: o, setFocusedPage: r, setTotalPages: a, goToPage: l, nextPage: c, prevPage: d } = To(); return W(() => { e != null && e.numPages && (a(e.numPages), r(1)); }, [e, a, r]), /* @__PURE__ */ i( _n.Provider, { value: { focusedPage: n, totalPages: o, setFocusedPage: r, setTotalPages: a, nextPage: c, prevPage: d, goToPage: l }, children: t } ); }; const So = () => { const { pdf: t, pages: e } = Q(), [n, o] = $({ loadedPages: 0, totalPages: 0, percentage: 0 }), [r, a] = $(!1), [l, c] = $(!1), [d, p] = $(null), f = H(!1); W(() => { f.current; }, [f]); const _ = N(() => { document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing"); const m = document.querySelector(".rp-print-zone"); m && m.remove(); }, []), h = N(() => { f.current = !1, a(!1), c(!1), p(null), o({ loadedPages: 0, totalPages: 0, percentage: 0 }); }, []), v = () => { f.current = !0; }, w = async ({ scratchCanvas: m, pdfDocument: g, pageNumber: s, viewerPdfPage: C, printResolution: b, optionalContentConfigPromise: y, printAnnotationStoragePromise: E }) => { if (f.current) { h(); return; } const I = b / yr.PDF; m.width = Math.floor(C.width * I), m.height = Math.floor(C.height * I); const L = m.getContext("2d"); L.save(), L.fillStyle = "rgb(255, 255, 255)", L.fillRect(0, 0, m.width, m.height), L.restore(); const [D, z] = await Promise.all([ g.getPage(s), E ]); if (f.current) { h(); return; } const A = { canvasContext: L, transform: [I, 0, 0, I, 0, 0], viewport: D.getViewport({ scale: 1, rotation: C.rotation }), intent: "print", annotationMode: Ir.ENABLE_STORAGE, optionalContentConfigPromise: y, printAnnotationStorage: z }; try { return D.render(A).promise; } catch (R) { throw R instanceof xr || console.error(R), R; } }, T = N(() => { const m = window.print; return new Promise((g) => { const s = (y) => { setTimeout(() => { m.call(window), setTimeout(() => y(), 20); }, 0); }; if (document.querySelector(".rp-print-zone")) { s(g); return; } const b = new MutationObserver(() => { document.querySelector(".rp-print-zone") && (s(g), b.disconnect()); }); b.observe(document.body, { childList: !0, subtree: !0 }); }); }, []), P = async (m) => { const g = document.createElement("img"), s = document.createElement("div"); return s.classList.add("rp-print-page"), await new Promise((C, b) => { m.toBlob((y) => { y ? (g.src = URL.createObjectURL(y), g.onload = () => { URL.revokeObjectURL(g.src), C(); }, g.onerror = b) : b(new Error("Failed to create blob")); }); }).catch(() => { }), s.appendChild(g), s; }, S = (m, g) => { const s = document.createElement("div"); s.classList.add("rp-print-zone"); const C = document.createElement("style"), b = g.get(1); if (b) { const { width: y, height: E } = b == null ? void 0 : b.page.getViewport({ scale: 1 }); C.innerHTML = `@page { size: ${y}px ${E}px }`; } return s.appendChild(C), s.append(...m), s; }, u = N(async () => { if (!t) return; h(); const m = document.createElement("canvas"), g = []; try { t.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment."); const C = t.getOptionalContentConfig({ intent: "print" }), b = Promise.resolve( t.annotationStorage.print ?? void 0 ), y = e.size; for (const [I, L] of e) { if (f.current) { h(); return; } const D = L.page.getViewport({ scale: 1 }); if (await w({ scratchCanvas: m, pdfDocument: t, pageNumber: I, viewerPdfPage: D, printResolution: 150, optionalContentConfigPromise: C, printAnnotationStoragePromise: b }), f.current) { h(); return; } const z = await P(m); g.push(z); const A = parseFloat((g.length / y * 100).toFixed(2)); o({ loadedPages: I, totalPages: y, percentage: A }); } if (f.current) { h(); return; } const E = S(g, e); document.body.appendChild(E), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), a(!0), await T(); } catch (s) { c(!0), s instanceof Error && p(s); } finally { m.height = 0, m.width = 0; } }, [t, e, f]); return W(() => { const m = () => { h(), _(); }; return window.addEventListener("afterprint", m, !0), () => { window.removeEventListener("afterprint", m, !0); }; }, [_, h]), { print: u, cancel: v, progress: n, isComplete: r, isError: l, error: d }; }, bn = Ye({ print: () => { }, cancel: () => { }, setOnProgress: (t) => { }, progress: {}, setOnComplete: (t) => t(), setOnError: (t) => { try { const e = new Error("Print error occurred"); t(e); } catch (e) { console.error("Error in setOnError callback:", e); } } }), Hs = ({ children: t }) => { const [e, n] = $(null), [o, r] = $(null), { print: a, cancel: l, progress: c, isComplete: d, isError: p, error: f } = So(), _ = N((P) => { P && typeof P == "function" && r(() => P); }, []), h = (P) => { f && P(f); }, v = N( (P) => { n(() => P); }, [c, e] ); W(() => { d && o && w(); }, [d, o]), W(() => { p && h((P) => { console.error(P); }); }, [p]), W(() => { c && e && e(c); }, [c, e]); const w = () => { o && (o(), r(null)); }, T = { print: a, cancel: l, setOnProgress: v, setOnComplete: _, setOnError: h, progress: c }; return /* @__PURE__ */ i(bn.Provider, { value: T, children: t }); }, tt = () => { const t = Je(bn); if (!t) throw new Error("usePrintContext must be used within a PrintProvider"); return t; }, yo = () => { const [t, e] = $({}), { pages: n } = Q(), { rotate: o } = Ge(), r = k(() => Object.keys(t).length, [t]), a = N( (c) => { if (!n.size) return; const d = c > n.size ? n.size : c, p = Array.from(n.values()).slice(0, d).map((h) => { const { thumbnailViewport: v, scale: w } = Wt(h.page, o); return { scale: w, page: h.page, loading: !0, viewport: v }; }), f = p.reduce((h, v) => (h[v.page.pageNumber] = v, h), {}); e(f); const _ = []; for (const h of p) { const v = document.createElement("canvas"), w = vt(h.page, v, { scale: h.scale, rotate: o }).promise.then(() => { const T = v.toDataURL(); return { ...h, thumbnailSrc: T, loading: !1 }; }); _.push(w); } Promise.all(_).then((h) => { const v = h.reduce( (w, T) => (w[T.page.pageNumber] = T, w), {} ); e((w) => ({ ...w, ...v })); }).catch(() => { }); }, [n, o] ); W(() => { a(10); }, [a]); const l = N( (c) => { if (!n) return; const d = n.get(c); if (!d) return; e((f) => ({ ...f, [c]: { loading: !0, page: d.page, viewport: d.thumbnailViewport, scale: d.thumbnailScale } })); const p = document.createElement("canvas"); vt(d.page, p, { scale: d.thumbnailScale, rotate: o }).promise.then(() => { const f = p.toDataURL(), { thumbnailViewport: _, scale: h } = Wt(d.page, o); return { scale: h, thumbnailSrc: f, page: d.page, loading: !1, viewport: _ }; }).then((f) => { e((_) => ({ ..._, [c]: f })); }); }, [n, o] ); return { thumbnailPages: t, addPage: l, addToPage: a, thumbnailLength: r }; }, Cn = Ye({ thumbnailPages: {}, addPage: (t) => { }, addToPage: (t) => { }, thumbnailLength: 0, setActive: (t) => { }, active: !1 }), Pn = () => Je(Cn), $s = ({ children: t, initialThumbnailsVisible: e }) => { const { thumbnailPages: n, addPage: o, addToPage: r, thumbnailLength: a } = yo(), [l, c] = $(e); return /* @__PURE__ */ i( Cn.Provider, { value: { thumbnailPages: n, addPage: o, addToPage: r, thumbnailLength: a, active: l, setActive: c }, children: t } ); }, Io = (t = {}, e = "") => { const [n, o] = $(e), [r, a] = $(!1), { pdf: l, pages: c } = Q(), { widths: d, heights: p } = Ue(), f = H(!n), { currentZoom: _ } = Qe(), [h, v] = $([]), { setFocusedPage: w } = ie(), { columnCount: T } = Ee(), { rotate: P } = Ge(), [S, u] = $(0), { pageScrollElementRef: m, virtualScrollableElementRef: g } = et(), { scrollMode: s } = Re(), { pagesRef: C } = ge(), [b, y] = $(null), E = H({}), I = k(() => S === 0 ? null : h[S - 1], [S, h]), L = k(() => h.length, [h]); W(() => { if (!I || !c) return; const R = g || m; if (!R || !C) return; const x = c.get(I.page); if (s === J.PAGE_SCROLLING && w(I.page), !x) return; let O = 0, M = 0; if (s === J.VERTICAL_SCROLLING) { const ae = I.page - 1, de = T, te = ae % de, Fe = Math.floor(ae / de); O = Ae(p, Fe), M = Ae(d, te); } s === J.HORIZONTAL_SCROLLING && (M = d.slice(0, I.page - 1).reduce((ae, de) => ae + de, 0)); const G = { top: C.clientHeight / 2, left: C.clientWidth / 2 }, Z = { height: p[I.page - 1], width: d[I.page - 1] }, { leftInPage: j, topInPage: q } = Br( Z, G, I.rect, _, P ), ee = M + j, X = O + q, le = { left: Math.max(ee, 0), top: Math.max(X, 0) }; R.scrollTo({ ...le }); }, [ c, w, d, p, I, s, g, m, C ]); const D = N(() => { u((R) => L ? R + 1 > L ? 1 : R + 1 : 0); }, [L]), z = N(() => { u((R) => L ? R - 1 <= 0 ? L : R - 1 : 0); }, [L]), A = N(async (R) => { if (!R) return {}; const x = R.numPages, O = {}; for (let M = 1; M <= x; M++) { if (f.current) throw "close pop over"; const G = await R.getPage(M); O[M.toString()] = await G.getTextContent(); } return O; }, []); return W(() => { if (!n) { f.current = !0, v([]), u(0); return; } f.current = !1, a(!0), v([]), u(0), A(l).then((R) => { E.current = R; const O = Object.keys(R).reduce((M, G) => { const Z = cr( [n], R[G], Number(G) - 1, t ).map((j, q) => ({ ...j, page: Number(G), pageMatchIdx: q })); return [...M, ...Z]; }, []); v(O), u(O.length ? 1 : 0); }).catch(() => { v([]), u(0); }).finally(() => a(!1)); }, [n, A, l, t]), { search: n, setSearch: o, loading: r, matches: h, totalMatches: L, currentMatchPosition: S, currentMatch: I, nextMatch: D, prevMatch: z, currentMatchElement: b, setCurrentMatchElement: y }; }, Tn = Ye({ search: "", setSearch: (t) => { }, loading: !1, matches: [], totalMatches: 0, currentMatchPosition: 0, currentMatch: null, nextMatch: () => { }, prevMatch: () => { }, searchOptions: {}, setSearchOptions: (t) => t, currentMatchElement: null, setCurrentMatchElement: (t) => { } }), Gs = ({ children: t, initialSearch: e }) => { const [n, o] = $({}), { loading: r, setSearch: a, totalMatches: l, currentMatchPosition: c, currentMatch: d, search: p, matches: f, nextMatch: _, prevMatch: h, currentMatchElement: v, setCurrentMatchElement: w } = Io(n, e); return /* @__PURE__ */ i( Tn.Provider, { value: { searchOptions: n, setSearchOptions: o, loading: r, setSearch: a, totalMatches: l, currentMatchPosition: c, currentMatch: d, nextMatch: _, prevMatch: h, search: p, matches: f, currentMatchElement: v, setCurrentMatchElement: w }, children: t } ); }, It = () => Je(Tn), ue = { "rp-pages": "_rp-pages_1776r_1", "rp-pages-horizontal-scroll": "_rp-pages-horizontal-scroll_1776r_7", "rp-pages-container": "_rp-pages-container_1776r_11", "rp-page-scrolling-wrapper": "_rp-page-scrolling-wrapper_1776r_17", "rp-viewer": "_rp-viewer_1776r_22", "rp-cursor-grab": "_rp-cursor-grab_1776r_27", "rp-cursor-grabbing": "_rp-cursor-grabbing_1776r_35", "rp-loader": "_rp-loader_1776r_43" }, lt = { "rp-page-wrapper": "_rp-page-wrapper_14ohm_1", "rp-page": "_rp-page_14ohm_1", "rp-loader-wrapper": "_rp-loader-wrapper_14ohm_15" }, xo = (t) => { const { pageNumber: e, onLoaded: n, onLoading: o } = t, r = H(null), { pages: a } = Q(), { rotate: l } = Ge(), c = H(), { currentZoom: d } = Qe(); return W(() => { if (!a || d === 0) return; const p = a.get(e); if (r.current && p) { const f = r.current; f.hidden = !0; const _ = c.current; _ && _.cancel(), o && o(), c.current = vt(p.page, f, { scale: d, rotate: l, renderForms: !0 }), c.current.promise.then(() => { f.hidden = !1; }).catch(() => { }).finally(() => { n && n(); }); } return () => { var f; (f = c.current) == null || f.cancel(); }; }, [a, e, l, d, o, n]), /* @__PURE__ */ i("canvas", { "data-rp": `page-${e}-canvas`, ref: r }); }, Lo = "_selecting_1x8te_9", Ro = "_endOfContent_1x8te_24", he = { "rp-text-layer": "_rp-text-layer_1x8te_1", selecting: Lo, endOfContent: Ro, "rp-text-layer-text": "_rp-text-layer-text_1x8te_38" }, Eo = (t) => { const { pageNumber: e } = t, { pages: n } = Q(), o = H(null), { matches: r, currentMatch: a, setCurrentMatchElement: l } = It(), [c, d] = $( [] ), p = H(), f = H(), _ = H([]), h = k(() => r.filter((m) => m.pageIndex === e - 1), [r, e]), v = N( (m, g, s = !1) => { if (s && lr(m, g), !h.length) { _.current = [], d([]); return; } const C = dr(h, m, g); d(C); }, [h] ), w = H(), T = H(!1), P = N(() => Array.from(document.querySelectorAll('[data-rp$="-textLayer"]')), []); W(() => ((() => { if (w.current) return; w.current = new AbortController(); const { signal: g } = w.current, s = () => { P().forEach((b) => { const y = b.querySelector(".endOfContent"); y && (b.appendChild(y), y.style.width = "", y.style.height = "", b.classList.remove(he.selecting)); }); }; document.addEventListener( "pointerdown", () => { T.current = !0; }, { signal: g } ), document.addEventListener( "pointerup", () => { T.current = !1, s(); }, { signal: g } ), window.addEventListener( "blur", () => { T.current = !1, s(); }, { signal: g } ), document.addEventListener( "keyup", () => { T.current || s(); }, { signal: g } ); let C = null; document.addEventListener( "selectionchange", () => { var A, R; const b = document.getSelection(); if (!b) return; if (b.rangeCount === 0) { s(); return; } const y = /* @__PURE__ */ new Set(); for (let x = 0; x < b.rangeCount; x++) { const O = b.getRangeAt(x); P().forEach((M) => { O.intersectsNode(M) && !y.has(M) && y.add(M); }); } P().forEach((x) => { if (y.has(x)) x.classList.add(he.selecting); else { const O = x.querySelector(".endOfContent"); O && (x.appendChild(O), O.style.width = "", O.style.height = "", x.classList.remove(he.selecting)); } }); const E = b.getRangeAt(0); let L = C && (E.compareBoundaryPoints(Range.END_TO_END, C) === 0 || E.compareBoundaryPoints(Range.START_TO_END, C) === 0) ? E.startContainer : E.endContainer; L.nodeType === Node.TEXT_NODE && (L = L.parentNode); const D = (A = L.parentElement) == null ? void 0 : A.closest( he["rp-text-layer"] ), z = D == null ? void 0 : D.querySelector(".endOfContent"); z && D && (z.style.width = D.style.width, z.style.height = D.style.height, (R = L.parentElement) == null || R.insertBefore(z, L.nextSibling)), C = E.cloneRange(); }, { signal: g } ); })(), () => { var g; (g = w.current) == null || g.abort(), w.current = void 0; }), [P]); const S = N(() => { o.current && o.current.classList.add(he.selecting); }, []), u = N(() => { o.current && o.current.classList.remove(he.selecting); }, []); return W(() => { if (_.current.forEach((s) => { s.classList.remove("selected"); }), !c.length || !a || a.pageIndex !== e - 1) return; const m = h.findIndex( (s) => JSON.stringify(s) === JSON.stringify(a) ); if (m === -1) return; const g = c.filter((s) => s.index === m); g.length && (_.current = g.map((s) => s.element), l(g[0].element), g.forEach((s) => { s.element.classList.add("selected"); })); }, [a, c, h]), W(() => { const m = n.get(e); if (!m || !o.current) return; const g = o.current; return p.current && p.current.cancel(), m.page.getTextContent().then((s) => { const C = m.page.getViewport({ scale: 1 }); return p.current = new Sr.TextLayer({ viewport: C, textContentSource: s, container: g }), f.current = s, g && (g.innerText = ""), p.current.render(); }).then(() => { var y, E; [].slice.call(g.children).forEach((I) => { I.classList.add(he["rp-text-layer-text"]), I.setAttribute("data-rp", "rp-text-layer-text"); }); const C = (y = p.current) == null ? void 0 : y.textDivs; C && f.current && v(f.current, C); const b = document.createElement("div"); b.className = "endOfContent", (E = o.current) == null || E.appendChild(b); }).catch(() => { }), () => { var s; (s = p.current) == null || s.cancel(); }; }, [n, e]), W(() => { var s; [].slice.call(o.current.children).forEach((C) => { C.classList.add(he["rp-text-layer-text"]); }); const g = (s = p.current) == null ? void 0 : s.textDivs; g && f.current && v(f.current, g, !0); }, [v]), /* @__PURE__ */ i( "div", { "data-rp": `page-${e}-textLayer`, className: he["rp-text-layer"], ref: o, onMouseDown: S, onMouseUp: u } ); }, No = { "rp-annotation-layer": "_rp-annotation-layer_o0ksd_1" }; let Oo = "https://unpkg.com/pdfjs-dist@4.4.168/web/images/"; const Do = (t) => { const { pageNumber: e } = t, n = H(null), { pages: o, pdf: r } = Q(), a = H(), [l, c] = $(), { setFocusedPage: d, goToPage: p } = ie(), { scrollMode: f } = Re(), { print: _ } = tt(), { download: h } = $n(), v = k(() => o.get(e), [o, e]), w = k(() => v == null ? void 0 : v.page.getViewport(), [v]); W(() => { a.current && (a.current.div.replaceChildren(), a.current = void 0); }, [r]), W(() => { v && v.page.getAnnotations().then((P) => { a.current = void 0, c(P), n.current && (n.current.innerText = ""); }); }, [v]); const T = N( (P) => { !l || !r || (Er(P), Nr(P, r, l).then((S) => { var u, m; ((u = S == null ? void 0 : S.data) == null ? void 0 : u.action) === "Print" ? _() : ((m = S == null ? void 0 : S.data) == null ? void 0 : m.action) === "SaveAs" && h(); }), f === J.PAGE_SCROLLING ? At(P, l, r, (S) => d(S.pageIndex + 1)) : At(P, l, r, (S) => p(S.pageIndex + 1))); }, [r, l, p, d, f, _, h] ); return W(() => { if (!v || !l) return; const P = v.page.getViewport(); if (a.current) { a.current.update({ viewport: P.clone({ dontFlip: !0 }) }); return; } const S = /* @__PURE__ */ new Map([]); for (const g of l) { const { annotationType: s } = g; switch (s) { case zt.Link: Dr(g); break; case zt.Widget: Or(g, P, S); break; } } const u = new AbortController(); return (async () => { var C; a.current && (a.current.div.replaceChildren(), a.current = void 0), n.current && (n.current.innerText = ""), a.current = new Lr({ div: n.current, accessibilityManager: void 0, annotationCanvasMap: void 0, annotationEditorUIManager: void 0, structTreeLayer: null, page: v.page, viewport: P.clone({ dontFlip: !0 }) }), n.current && Ft(n.current, T); const g = await (r == null ? void 0 : r.hasJSActions()), s = await (r == null ? void 0 : r.getFieldObjects()); if (u.signal.aborted) throw "abort"; return (C = a.current) == null ? void 0 : C.render({ annotations: l, annotationStorage: r == null ? void 0 : r.annotationStorage, hasJSActions: g, fieldObjects: s, div: n.current, viewport: P.clone({ dontFlip: !0 }), page: v.page, imageResourcesPath: Oo, renderForms: !0, linkService: new Rr(), downloadManager: null, enableScripting: !1 }); })().then(() => { n.current && zr(n.current, T); }).catch((g) => { if (g !== "abort") throw g; }), () => { u.abort("clear"), n.current && Ft(n.current, T); }; }, [r, l, T]), /* @__PURE__ */ i( "div", { "data-rp": `page-${e}-annotationLayer`, style: { width: `${w == null ? void 0 : w.width}px`, height: `${w == null ? void 0 : w.height}px` }, className: No["rp-annotation-layer"], ref: n } ); }, zo = { "rp-text-highlight": "_rp-text-highlight_jdkf8_1" }, Ao = ({ pageNumber: t, viewport: e }) => { const [n, o] = $(), { pages: r } = Q(), { highlightKeywords: a } = pr(), l = !0, c = H(null), [d, p] = $(null), [f, _] = $([]); W(() => { c.current && p(c.current.parentElement); }, [c]), W(() => { (async () => { const m = r.get(t); if (!m || !c.current) return; const g = await m.page.getTextContent(); o(g); })(); }, [r, t]); const h = k(() => a ? a.map((u) => { var m, g; return { ...Ar(u.keyword, (m = u.options) == null ? void 0 : m.matchCase, (g = u.options) == null ? void 0 : g.wholeWords), color: u.highlightColor }; }) : [], [a]); function v(u, m) { if (!u) return; const g = `[data-rp="page-${m}-textLayer"]`; return new Promise((s) => { const C = u.querySelector(g); if (C) { s(C); return; } new MutationObserver((y, E) => { const I = u.querySelector(g); I && (s(I), E.disconnect()); }).observe(u, { childList: !0, subtree: !0 }); }); } function w(u) { return new Promise((m) => { const g = u.querySelectorAll( '[data-rp="rp-text-layer-text"]' ); if (g.length) { m(Array.from(g)); return; } new MutationObserver((C, b) => { const y = u.querySelectorAll( ".vpv-text-layer-text" ); y.length && (m(Array.from(y)), b.disconnect()); }).observe(u, { childList: !0, subtree: !0 }); }); } const T = (u, m, g, s) => { var Z; const C = document.createRange(), b = g.firstChild; if (!b || b.nodeType !== Node.TEXT_NODE) return null; const y = ((Z = b.textContent) == null ? void 0 : Z.length) ?? 0, E = s[0].charIdxInSpan, I = s.length === 1 ? E : s[s.length - 1].charIdxInSpan; if (E > y || I + 1 > y) return null; C.setStart(b, E), C.setEnd(b, I + 1); const L = document.createElement("span"); L.style.width = "auto", C.surroundContents(L); const D = L.getBoundingClientRect(), z = u.getBoundingClientRect(), A = z.height, R = z.width, x = 100 * (D.left - z.left) / R, O = 100 * (D.top - z.top) / A, M = 100 * D.height / A, G = 100 * D.width / R; return Wr(L), { keywordStr: m, left: x, top: O, height: M, width: G, pageHeight: A, pageWidth: R }; }; async function P(u, m) { const g = await v(d, u); if (!g) return; const s = await w(g); if (s.length) { const C = s.map((y) => y.tagName === "BR" ? " " : y.textContent).reduce( (y, E, I) => y.concat( E.split("").map((L, D) => ({ char: L, charIdxInSpan: D, spanIdx: I })) ), [ { char: "", charIdxInSpan: 0, spanIdx: 0 } ] ).slice(1), b = S(g, m, s, C); _(b); } } const S = (u, m, g, s) => { const C = m.length; if (!s.length || !C) return []; const b = [], y = s.map((E) => E.char).join(""); return h.forEach((E) => { const { keyword: I, regExp: L, wholeWords: D, color: z } = E, A = I; if (!A.trim()) return; const R = L.flags.indexOf("g") === -1 ? new RegExp(L, `${L.flags}g`) : L; let x; const O = []; for (; (x = R.exec(y)) !== null; ) D && !ur(y, x.index, x[0].length) || O.push({ keyword: R, startIndex: x.index, endIndex: R.lastIndex }); const M = O.map((G) => ({ keyword: G.keyword, indexes: s.slice(G.startIndex, G.endIndex), color: z })); for (const G of M) { const Z = G.indexes.reduce( (j, q) => (j[q.spanIdx] = (j[q.spanIdx] || []).concat([q]), j), {} ); for (const j of Object.values(Z)) if (j.length !== 1 || j[0].char.trim() !== "") { const q = j, ee = g[q[0].spanIdx], X = T( u, A, ee, q ); if (X) { const { left: le, top: ae } = X; if (b.find((te) => te.left === le && te.top === ae)) continue; b.push({ ...X, highlightColor: G.color }); } } } }), b.sort(Fr), b; }; return W(() => { (async () => { if (!(!a || a.length === 0)) try { await P(t, a); } catch (m) { console.error(m); } })(); }, [l, a, t, n, e]), /* @__PURE__ */ i(fe, { children: /* @__PURE__ */ i("div", { ref: c, "data-rp": `page-${t}-textHighlightLayer`, children: f.map((u, m) => /* @__PURE__ */ i( "div", { className: zo["rp-text-highlight"], style: { top: `${u.top}%`, left: `${u.left}%`, width: `${u.width}%`, height: `${u.height}%`, backgroundColor: u.highlightColor } }, m )) }) }); }, xt = $e((t, e) => { const { pageNumber: n, style: o, ...r } = t, { pages: a } = Q(), { rotate: l } = Ge(), { textLayer: c } = or(), { currentZoom: d } = Qe(), p = H(a.get(n)), [f, _] = $(!1), h = H(null), [v, w] = $({ width: 0, height: 0 }); cn(e, () => h.current), W(() => { if (a && (p.current = a.get(n), p.current)) { const u = p.current.page.getViewport({ scale: d, rotation: l }); w(u); } }, [a, n, l, d]); const T = k(() => { switch (l) { case 90: return `${v.width / 2}px ${v.width / 2}px`; case -90: case 270: return `${v.height / 2}px ${v.height / 2}px`; default: return "center"; } }, [l, v]), P = N(() => { _(!0); }, []), S = N(() => { _(!1); }, []); return /* @__PURE__ */ i( "div", { ref: h, id: `page-${n}`, "data-rp": `page-${n}`, ...r, style: { ...o, "--rp-rotate": `${l}deg`, "--rp-page-rotate-translate": `${T}`, "--scale-factor": d }, className: lt["rp-page-wrapper"], children: /* @__PURE__ */ F( "div", { style: { width: `${v.width}px`, height: `${v.height}px` }, className: lt["rp-page"], children: [ /* @__PURE__ */ i(xo, { onLoading: P, onLoaded: S, pageNumber: n }), f && /* @__PURE__ */ i("div", { className: lt["rp-loader-wrapper"], children: /* @__PURE__ */ i(Ct, {}) }), c && /* @__PURE__ */ i(Eo, { pageNumber: n }), /* @__PURE__ */ i(Ao, { pageNumber: n, viewport: v }), /* @__PURE__ */ i(Do, { pageNumber: n }) ] } ) } ); }); function Ut(t) { if (t === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return t; } function wt(t, e) { return wt = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(n, o) { return n.__proto__ = o, n; }, wt(t, e); } function Fo(t, e) { t.prototype = Object.create(e.prototype), t.prototype.constructor = t, wt(t, e); } var Vt = Number.isNaN || function(e) { return typeof e == "number" && e !== e; }; function Wo(t, e) { return !!(t === e || Vt(t) && Vt(e)); } function ko(t, e) { if (t.length !== e.length) return !1; for (var n = 0; n < t.length; n++) if (!Wo(t[n], e[n])) return !1; return !0; } function dt(t, e) { e === void 0 && (e = ko); var n, o = [], r, a = !1; function l() { for (var c = [], d = 0; d < arguments.length; d++) c[d] = arguments[d]; return a && n === this && e(c, o) || (r = t.apply(this, c), a = !0, n = this, o = c), r; } return l; } function qt(t, e) { if (t == null) return {}; var n = {}; for (var o in t) if ({}.hasOwnProperty.call(t, o)) { if (e.indexOf(o) !== -1) continue; n[o] = t[o]; } return n; } var Mo = typeof performance == "object" && typeof performance.now == "function", Bt = Mo ? function() { return performance.now(); } : function() { return Date.now(); }; function Zt(t) { cancelAnimationFrame(t.id); } function Ho(t, e) { var n = Bt(); function o() { Bt() - n >= e ? t.call(null) : r.id = requestAnimationFrame(o); } var r = { id: requestAnimationFrame(o) }; return r; } var ut = -1; function $o(t) { if (t === void 0 && (t = !1), ut === -1 || t) { var e = document.createElement("div"), n = e.style; n.width = "50px", n.height = "50px", n.overflow = "scroll", document.body.appendChild(e), ut = e.offsetWidth - e.clientWidth, document.body.removeChild(e); } return ut; } var Oe = null; function jt(t) { if (t === void 0 && (t = !1), Oe === null || t) { var e = document.createElement("div"), n = e.style; n.width = "50px", n.height = "50px", n.overflow = "scroll", n.direction = "rtl"; var o = document.createElement("div"), r = o.style; return r.width = "100px", r.height = "100px", e.appendChild(o), document.body.appendChild(e), e.scrollLeft > 0 ? Oe = "positive-descending" : (e.scrollLeft = 1, e.scrollLeft === 0 ? Oe = "negative" : Oe = "positive-ascending"), document.body.removeChild(e), Oe; } return Oe; } var Go = 150, Uo = function(e) { var n = e.columnIndex; e.data; var o = e.rowIndex; return o + ":" + n; }, Be = null, Ze = null, je = null; process.env.NODE_ENV !== "production" && typeof window < "u" && typeof window.WeakSet < "u" && (Be = /* @__PURE__ */ new WeakSet(), Ze = /* @__PURE__ */ new WeakSet(), je = /* @__PURE__ */ new WeakSet()); function Vo(t) { var e, n = t.getColumnOffset, o = t.getColumnStartIndexForOffset, r = t.getColumnStopIndexForStartIndex, a = t.getColumnWidth, l = t.getEstimatedTotalHeight, c = t.getEstimatedTotalWidth, d = t.getOffsetForColumnAndAlignment, p = t.getOffsetForRowAndAlignment, f = t.getRowHeight, _ = t.getRowOffset, h = t.getRowStartIndexForOffset, v = t.getRowStopIndexForStartIndex, w = t.initInstanceProps, T = t.shouldResetStyleCacheOnItemSizeChange, P = t.validateProps; return e = /* @__PURE__ */ function(S) { Fo(u, S); function u(g) { var s; return s = S.call(this, g) || this, s._instanceProps = w(s.props, Ut(s)), s._resetIsScrollingTimeoutId = null, s._outerRef = void 0, s.state = { instance: Ut(s), isScrolling: !1, horizontalScrollDirection: "forward", scrollLeft: typeof s.props.initialScrollLeft == "number" ? s.props.initialScrollLeft : 0, scrollTop: typeof s.props.initialScrollTop == "number" ? s.props.initialScrollTop : 0, scrollUpdateWasRequested: !1, verticalScrollDirection: "forward" }, s._callOnItemsRendered = void 0, s._callOnItemsRendered = dt(function(C, b, y, E, I, L, D, z) { return s.props.onItemsRendered({ overscanColumnStartIndex: C, overscanColumnStopIndex: b, overscanRowStartIndex: y, overscanRowStopIndex: E, visibleColumnStartIndex: I, visibleColumnStopIndex: L, visibleRowStartIndex: D, visibleRowStopIndex: z }); }), s._callOnScroll = void 0, s._callOnScroll = dt(function(C, b, y, E, I) { return s.props.onScroll({ horizontalScrollDirection: y, scrollLeft: C, scrollTop: b, verticalScrollDirection: E, scrollUpdateWasRequested: I }); }), s._getItemStyle = void 0, s._getItemStyle = function(C, b) { var y = s.props, E = y.columnWidth, I = y.direction, L = y.rowHeight, D = s._getItemStyleCache(T && E, T && I, T && L), z = C + ":" + b, A; if (D.hasOwnProperty(z)) A = D[z]; else { var R = n(s.props, b, s._instanceProps), x = I === "rtl"; D[z] = A = { position: "absolute", left: x ? void 0 : R, right: x ? R : void 0, top: _(s.props, C, s._instanceProps), height: f(s.props, C, s._instanceProps), width: a(s.props, b, s._instanceProps) }; } return A; }, s._getItemStyleCache = void 0, s._getItemStyleCache = dt(function(C, b, y) { return {}; }), s._onScroll = function(C) { var b = C.currentTarget, y = b.clientHeight, E = b.clientWidth, I = b.scrollLeft, L = b.scrollTop, D = b.scrollHeight, z = b.scrollWidth; s.setState(function(A) { if (A.scrollLeft === I && A.scrollTop === L) return null; var R = s.props.direction, x = I; if (R === "rtl") switch (jt()) { case "negative": x = -I; break; case "positive-descending": x = z - E - I; break; } x = Math.max(0, Math.min(x, z - E)); var O = Math.max(0, Math.min(L, D - y)); return { isScrolling: !0, horizontalScrollDirection: A.scrollLeft < I ? "forward" : "backward", scrollLeft: x, scrollTop: O, verticalScrollDirection: A.scrollTop < L ? "forward" : "backward", scrollUpdateWasRequested: !1 }; }, s._resetIsScrollingDebounced); }, s._outerRefSetter = function(C) { var b = s.props.outerRef; s._outerRef = C, typeof b == "function" ? b(C) : b != null && typeof b == "object" && b.hasOwnProperty("current") && (b.current = C); }, s._resetIsScrollingDebounced = function() { s._resetIsScrollingTimeoutId !== null && Zt(s._resetIsScrollingTimeoutId), s._resetIsScrollingTimeoutId = Ho(s._resetIsScrolling, Go); }, s._resetIsScrolling = function() { s._resetIsScrollingTimeoutId = null, s.setState({ isScrolling: !1 }, function() { s._getItemStyleCache(-1); }); }, s; } u.getDerivedStateFromProps = function(s, C) { return qo(s, C), P(s), null; }; var m = u.prototype; return m.scrollTo = function(s) { var C = s.scrollLeft, b = s.scrollTop; C !== void 0 && (C = Math.max(0, C)), b !== void 0 && (b = Math.max(0, b)), this.setState(function(y) { return C === void 0 && (C = y.scrollLeft), b === void 0 && (b = y.scrollTop), y.scrollLeft === C && y.scrollTop === b ? null : { horizontalScrollDirection: y.scrollLeft < C ? "forward" : "backward", scrollLeft: C, scrollTop: b, scrollUpdateWasRequested: !0, verticalScrollDirection: y.scrollTop < b ? "forward" : "backward" }; }, this._resetIsScrollingDebounced); }, m.scrollToItem = function(s) { var C = s.align, b = C === void 0 ? "auto" : C, y = s.columnIndex, E = s.rowIndex, I = this.props, L = I.columnCount, D = I.height, z = I.rowCount, A = I.width, R = this.state, x = R.scrollLeft, O = R.scrollTop, M = $o(); y !== void 0 && (y = Math.max(0, Math.min(y, L - 1))), E !== void 0 && (E = Math.max(0, Math.min(E, z - 1))); var G = l(this.props, this._instanceProps), Z = c(this.props, this._instanceProps), j = Z > A ? M : 0, q = G > D ? M : 0; this.scrollTo({ scrollLeft: y !== void 0 ? d(this.props, y, b, x, this._instanceProps, q) : x, scrollTop: E !== void 0 ? p(this.props, E, b, O, this._instanceProps, j) : O }); }, m.componentDidMount = function() { var s = this.props, C = s.initialScrollLeft, b = s.initialScrollTop; if (this._outerRef != null) { var y = this._outerRef; typeof C == "number" && (y.scrollLeft = C), typeof b == "number" && (y.scrollTop = b); } this._callPropsCallbacks(); }, m.componentDidUpdate = function() { var s = this.props.direction, C = this.state, b = C.scrollLeft, y = C.scrollTop, E = C.scrollUpdateWasRequested; if (E && this._outerRef != null) { var I = this._outerRef; if (s === "rtl") switch (jt()) { case "negative": I.scrollLeft = -b; break; case "positive-ascending": I.scrollLeft = b; break; default: var L = I.clientWidth, D = I.scrollWidth; I.scrollLeft = D - L - b; break; } else I.scrollLeft = Math.max(0, b); I