export function deepClosestElement(element, selector) {
    let current = element;
    while (current) {
        if (current.matches(selector)) {
            return current;
        }
        if (current.parentElement) {
            current = current.parentElement;
        }
        else if (current.parentNode instanceof ShadowRoot) {
            current = current.parentNode.host;
        }
        else {
            break;
        }
    }
    return null;
}
