@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
21 lines (20 loc) • 866 B
JavaScript
import { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { jsx } from "react/jsx-runtime";
//#region src/lib/react/Portal.tsx
function resolveTargetElement(input) {
if (typeof document === "undefined") throw new Error("Portal target resolution requires a browser environment");
return typeof input === "string" ? document.querySelector(input) ?? document.body : input ?? document.body;
}
function Portal({ target = "body", children }) {
const [targetElement, setTargetElement] = useState(null);
useEffect(() => {
if (typeof document === "undefined") return;
setTargetElement(resolveTargetElement(target));
}, [target]);
if (!targetElement) return null;
return createPortal(/* @__PURE__ */ jsx("div", { children: children ?? null }), targetElement);
}
//#endregion
export { Portal };
//# sourceMappingURL=Portal.js.map