{"version":3,"file":"use-fullscreen-element.cjs","names":[],"sources":["../../src/hooks/use-fullscreen-element.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\n/**\n * Vendor-prefixed fullscreen member of `document`, still shipped by WebKit.\n *\n * Declared optional on purpose: the standard property is what every other engine\n * answers to, and Safari is the only reason the second read exists.\n */\ninterface WebkitFullscreenDocument {\n    webkitFullscreenElement?: Element | null;\n}\n\n/**\n * Read the element the browser is presenting fullscreen, standard property first.\n *\n * A plain function rather than a hook, because two very different callers need\n * the answer: `useFullscreenElement` below, which turns it into state, and the\n * action callbacks of `useFullscreen`, which need the value *at call time* and\n * cannot wait for a render to have happened since the last change.\n *\n * @returns The element being presented fullscreen, or `null` — including in any\n * environment without a `document` (a service worker, a build plugin, a Node\n * test), where the SDK must not throw.\n */\nexport function getFullscreenElement(): Element | null {\n    if (typeof document === \"undefined\") return null;\n    const prefixed = document as Document & WebkitFullscreenDocument;\n    return document.fullscreenElement ?? prefixed.webkitFullscreenElement ?? null;\n}\n\n/**\n * Track the element the browser is presenting fullscreen.\n *\n * The SDK's single subscription to `fullscreenchange` (and WebKit's\n * `webkitfullscreenchange`). Two features need exactly this fact and would\n * otherwise each carry their own copy of the prefix dance: `usePortalHost` asks\n * *where do I mount* — the fullscreen element paints its own subtree and nothing\n * else, so a dialog portalled to `document.body` is invisible while fullscreen is\n * on — and `useFullscreen` asks *is my element the one presented*. One\n * subscription, two questions.\n *\n * The event is the source of truth rather than the return of `requestFullscreen`\n * / `exitFullscreen`, because `Esc`, the browser's own exit affordance and F11\n * leave fullscreen without ever passing through those calls.\n *\n * The first value is resolved during render rather than in the effect, so a\n * consumer that mounts while fullscreen is already active is correct in its very\n * first commit instead of correcting itself one frame later.\n *\n * @returns The fullscreen element, or `null` when nothing is presented.\n */\nexport function useFullscreenElement(): Element | null {\n    const [element, setElement] = useState<Element | null>(getFullscreenElement);\n\n    useEffect(() => {\n        const sync = (): void => setElement(getFullscreenElement());\n        sync();\n        document.addEventListener(\"fullscreenchange\", sync);\n        document.addEventListener(\"webkitfullscreenchange\", sync);\n        return () => {\n            document.removeEventListener(\"fullscreenchange\", sync);\n            document.removeEventListener(\"webkitfullscreenchange\", sync);\n        };\n    }, []);\n\n    return element;\n}\n"],"mappings":"uBAwBA,SAAgB,GAAuC,CACnD,GAAI,OAAO,SAAa,IAAa,OAAO,KAC5C,IAAM,EAAW,SACjB,OAAO,SAAS,mBAAqB,EAAS,yBAA2B,IAC7E,CAuBA,SAAgB,GAAuC,CACnD,GAAM,CAAC,EAAS,IAAA,EAAc,EAAA,SAAA,CAAyB,CAAoB,EAa3E,OAXA,EAAA,EAAA,UAAA,KAAgB,CACZ,IAAM,MAAmB,EAAW,EAAqB,CAAC,EAI1D,OAHA,EAAK,EACL,SAAS,iBAAiB,mBAAoB,CAAI,EAClD,SAAS,iBAAiB,yBAA0B,CAAI,MAC3C,CACT,SAAS,oBAAoB,mBAAoB,CAAI,EACrD,SAAS,oBAAoB,yBAA0B,CAAI,CAC/D,CACJ,EAAG,CAAC,CAAC,EAEE,CACX"}