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