UNPKG

@ariakit/react-core

Version:

Ariakit React core

69 lines (66 loc) 1.84 kB
"use client"; import { walkTreeOutside } from "./AOUGVQZ3.js"; import { setProperty } from "./K2ZF5NU7.js"; import { isBackdrop } from "./63XF7ACK.js"; // src/dialog/utils/mark-tree-outside.ts import { chain } from "@ariakit/core/utils/misc"; function getPropertyName(id = "", ancestor = false) { return `__ariakit-dialog-${ancestor ? "ancestor" : "outside"}${id ? `-${id}` : ""}`; } function markElement(element, id = "") { return chain( setProperty(element, getPropertyName(), true), setProperty(element, getPropertyName(id), true) ); } function markAncestor(element, id = "") { return chain( setProperty(element, getPropertyName("", true), true), setProperty(element, getPropertyName(id, true), true) ); } function isElementMarked(element, id) { const ancestorProperty = getPropertyName(id, true); if (element[ancestorProperty]) return true; const elementProperty = getPropertyName(id); do { if (element[elementProperty]) return true; if (!element.parentElement) return false; element = element.parentElement; } while (true); } function markTreeOutside(id, elements) { const cleanups = []; const ids = elements.map((el) => el == null ? void 0 : el.id); walkTreeOutside( id, elements, (element) => { if (isBackdrop(element, ...ids)) return; cleanups.unshift(markElement(element, id)); }, (ancestor, element) => { const isAnotherDialogAncestor = element.hasAttribute("data-dialog") && element.id !== id; if (isAnotherDialogAncestor) return; cleanups.unshift(markAncestor(ancestor, id)); } ); const restoreAccessibilityTree = () => { for (const cleanup of cleanups) { cleanup(); } }; return restoreAccessibilityTree; } export { markElement, markAncestor, isElementMarked, markTreeOutside };