UNPKG

@pdf-viewer/react

Version:

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

30 lines (29 loc) 979 B
import { useState as s, useCallback as n, useEffect as a } from "react"; const m = () => { const [t, r] = s(!1), l = typeof document < "u" && (document.fullscreenEnabled || document.webkitFullscreenEnabled), c = n(async (e) => { if (!document.fullscreenElement) try { await e.requestFullscreen(); } catch (o) { console.error("Error attempting to enter fullscreen:", o); } }, []), u = n(async () => { if (document.fullscreenElement) try { await document.exitFullscreen(); } catch (e) { console.error("Error attempting to exit fullscreen:", e); } }, []); return a(() => { const e = () => { r(!!document.fullscreenElement); }; return document.addEventListener("fullscreenchange", e), () => { document.removeEventListener("fullscreenchange", e); }; }, []), { isFullScreen: t, enterFullScreen: c, exitFullScreen: u, isSupported: l }; }; export { m as useFullScreen };