Files
bitvid/dist/js/ui/overlay/overlayRoot.js
T
google-labs-jules[bot]andPR0M3TH3AN 0bfa3b08e8 fix(ci): fix netlify deployment by building to dist
- Move from root publishing to clean `dist/` directory
- Create `scripts/build-dist.mjs` to orchestrate build and copy assets
- Update `package.json` build script
- Update `netlify.toml` to publish `dist/`
- Ignore `dist/` in `.gitignore`

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-29 09:07:15 +00:00

64 lines
1.5 KiB
JavaScript

const OVERLAY_ROOT_ID = "uiOverlay";
const OVERLAY_COMPONENT = "overlay-root";
function resolveDocument(documentRef) {
if (documentRef && documentRef.nodeType === 9) {
return documentRef;
}
if (typeof document !== "undefined" && document?.nodeType === 9) {
return document;
}
return null;
}
function isElement(node) {
return Boolean(node && typeof node === "object" && node.nodeType === 1);
}
function applyRootAttributes(element) {
if (!element) {
return;
}
if (element.getAttribute("aria-hidden") !== "true") {
element.setAttribute("aria-hidden", "true");
}
if (!element.hasAttribute("data-overlay-root")) {
element.setAttribute("data-overlay-root", "");
}
if (element.dataset.component !== OVERLAY_COMPONENT) {
element.dataset.component = OVERLAY_COMPONENT;
}
}
function ensureAttached(element, documentRef) {
if (!element?.isConnected) {
const doc = resolveDocument(documentRef);
if (doc?.body) {
doc.body.appendChild(element);
} else if (doc?.documentElement) {
doc.documentElement.appendChild(element);
}
}
}
export function ensureOverlayRoot(documentRef = null) {
const doc = resolveDocument(documentRef);
if (!doc) {
return null;
}
let root = doc.getElementById(OVERLAY_ROOT_ID);
if (!isElement(root)) {
root = doc.createElement("div");
root.id = OVERLAY_ROOT_ID;
}
applyRootAttributes(root);
ensureAttached(root, doc);
return root;
}
export default ensureOverlayRoot;