UNPKG

@pdf-viewer/react

Version:

A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.

44 lines (43 loc) 1.71 kB
import { jsx as u } from "react/jsx-runtime"; import { createContext as R, useContext as c, useState as f, useEffect as l, useMemo as P } from "react"; import { useDocumentContext as x } from "./RPDocumentContext.js"; import { useRotationContext as C } from "./RotationContext.js"; import { useEventCallbackContext as d } from "./EventCallbackContext.js"; import "../utils/hooks/useLoadPdf.js"; import "pdfjs-dist"; import "../utils/types.js"; import "../th_TH-d627cd51.js"; import "../utils/getThumbnailViewport.js"; import "./ConfigContext.js"; import "./DocumentPasswordContext.js"; import "../utils/appConsole.js"; import "../utils/hooks/usePdfProperties.js"; import "../utils/convertPdfDate.js"; import "../utils/formatFileSize.js"; import "./InitialStateContext.js"; const p = R({ singlePageRotate: {}, setSinglePageRotate: () => { }, pageRotate: {} }), G = () => { const { singlePageRotate: a, setSinglePageRotate: t, pageRotate: r } = c(p); return { singlePageRotate: a, setSinglePageRotate: t, pageRotate: r }; }, H = ({ children: a }) => { const [t, r] = f({}), { rotate: n } = C(), { pages: e } = x(), { onRotate: i } = d(); l(() => { e && r({}); }, [e]); const g = P(() => { if (!e) return {}; const s = Array.from(e.values()).reduce((m, o) => (m[o.page.pageNumber] = t[o.page.pageNumber] ? (n + t[o.page.pageNumber] + o.defaultRotation) % 360 : (n + o.defaultRotation) % 360, m), {}); return i && i(s), s; }, [n, e, t, i]); return /* @__PURE__ */ u(p.Provider, { value: { singlePageRotate: t, setSinglePageRotate: r, pageRotate: g }, children: a }); }; export { p as PagesRotateContext, H as PagesRotateProvider, G as usePagesRotateContext };