/**
 * Find the closest parent element matching the given predicate
 *
 * @param element - the element to check if it matches the given
 * predicate
 * @param predicate - predicate function
 * @returns the matching element if it is found
 */
export function findParentElement(element, predicate) {
    if (predicate(element)) {
        return element;
    }
    let parent = element.parentElement || element.parentNode;
    if (isShadowRoot(parent)) {
        parent = parent.host;
    }
    if (!parent) {
        return;
    }
    return findParentElement(parent, predicate);
}
function isShadowRoot(node) {
    return (node === null || node === void 0 ? void 0 : node.nodeType) === Node.DOCUMENT_FRAGMENT_NODE;
}
