@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
26 lines (25 loc) • 1.13 kB
JavaScript
import { jsx as i } from "react/jsx-runtime";
import { createContext as R, useContext as m, useState as f, useEffect as p, useMemo as P } from "react";
import { useDocumentContext as c } from "./RPDocumentContext.js";
import { useRotationContext as l } from "./RotationContext.js";
const g = R({
singlePageRotate: {},
setSinglePageRotate: () => {
},
pageRotate: {}
}), S = () => {
const { singlePageRotate: r, setSinglePageRotate: e, pageRotate: a } = m(g);
return { singlePageRotate: r, setSinglePageRotate: e, pageRotate: a };
}, b = ({ children: r }) => {
const [e, a] = f({}), { rotate: n } = l(), { pages: t } = c();
p(() => {
t && a({});
}, [t]);
const u = P(() => t ? Array.from(t.values()).reduce((s, o) => (s[o.page.pageNumber] = e[o.page.pageNumber] ? (n + e[o.page.pageNumber] + o.defaultRotation) % 360 : (n + o.defaultRotation) % 360, s), {}) : {}, [n, t, e]);
return /* @__PURE__ */ i(g.Provider, { value: { singlePageRotate: e, setSinglePageRotate: a, pageRotate: u }, children: r });
};
export {
g as PagesRotateContext,
b as PagesRotateProvider,
S as usePagesRotateContext
};