import isInstance from './isInstance';
/**
 * Finds the HTMLElement child of the root node that contains the referenced element.
 *
 * @param ref - A React RefObject pointing to an HTMLElement whose containing child is to be found.
 * @returns The HTMLElement child of the root node that contains the referenced element, or undefined if not found.
 */
export default (ref) => {
    const rootNode = ref.current?.getRootNode();
    if (!isInstance(rootNode, Document) && !isInstance(rootNode, ShadowRoot)) {
        return;
    }
    for (const child of rootNode.childNodes) {
        if (child.contains(ref.current) && isInstance(child, HTMLElement)) {
            return child;
        }
    }
};
//# sourceMappingURL=getChildOfRootNode.js.map