const getStyleComputedProperty = (element) => {
    // NOTE: 1 DOM access here
    const window = element.ownerDocument.defaultView;
    // @ts-ignore
    return window.getComputedStyle(element, null);
};
const getParentNode = (element) => {
    if (element.nodeName === 'HTML') {
        return element;
    }
    // @ts-ignore
    return element.parentNode || element.host;
};
export const getScrollParent = (element) => {
    // Return body, `getScroll` will take care to get the correct `scrollTop` from it
    if (!element) {
        return document.body;
    }
    switch (element.nodeName) {
        case 'HTML':
        case 'BODY':
            return element.ownerDocument.body;
        case '#document':
            // @ts-ignore
            return element.body;
        default:
    }
    // Firefox want us to check `-x` and `-y` variations as well
    const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
    if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
        return element;
    }
    return getScrollParent(getParentNode(element));
};
export const getByPredicate = (predicate, element) => {
    if (!element) {
        return null;
    }
    if (element.nodeName === 'HTML') {
        return element;
    }
    if (predicate(element)) {
        return element;
    }
    return getByPredicate(predicate, getParentNode(element));
};
//# sourceMappingURL=utils.js.map