UNPKG

@pdf-viewer/react

Version:

The PDF Viewer component for React and Next.js

43 lines (42 loc) 1.48 kB
import { jsx as g } from "react/jsx-runtime"; import { createContext as x, useContext as P, useState as a, useEffect as v } from "react"; import { appConsole as w } from "../utils/appConsole.js"; import { useDocumentContext as C } from "./RPDocumentContext.js"; import { useZoomContext as l } from "./ZoomContext.js"; import { useRotationContext as y } from "./RotationContext.js"; import { PAGE_PADDING as f } from "../utils/constants.js"; const d = x({ widths: [], heights: [], setWidths: () => { }, setHeights: () => { } }), E = () => { const o = P(d), { widths: s, heights: e } = o; if (s && e) { const i = s.every((t) => typeof t == "number"), r = e.every((t) => typeof t == "number"); (!i || !r) && w.warn("Please use this hooks inside children component of RPProvider"); } return o; }, G = ({ children: o }) => { const [s, e] = a([]), [i, r] = a([]), { pages: t } = C(), { currentZoom: m } = l(), { rotate: h } = y(); return v(() => { if (!t) return; const c = [], u = []; for (const n of Array.from(t.values())) { const p = n.page.getViewport({ scale: m, rotation: h, dontFlip: !0 }); c.push(p.width + f), u.push(p.height + f); } e((n) => [...c]), r((n) => [...u]); }, [m, h, t]), /* @__PURE__ */ g(d.Provider, { value: { widths: s, heights: i, setWidths: e, setHeights: r }, children: o }); }; export { G as DimensionPagesProvider, E as useDimensionPagesContext };