export function isVisible(elem: HTMLElement) {
    //https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom
    if (!(elem instanceof Element)) throw Error('DomUtil: elem is not an element.');
    const style = getComputedStyle(elem) as any;
    if (style.display === 'none') return false;
    if (style.visibility !== 'visible') return false;
    if (style.opacity < 0.1) return false;
    if (elem.offsetWidth + elem.offsetHeight + elem.getBoundingClientRect().height +
        elem.getBoundingClientRect().width === 0) {
        return false;
    }
    const elemCenter   = {
        x: elem.getBoundingClientRect().left + elem.offsetWidth / 2,
        y: elem.getBoundingClientRect().top + elem.offsetHeight / 2
    };
    if (elemCenter.x < 0) return false;
    if (elemCenter.x > (document.documentElement.clientWidth || window.innerWidth)) return false;
    if (elemCenter.y < 0) return false;
    if (elemCenter.y > (document.documentElement.clientHeight || window.innerHeight)) return false;
    const root = elem.getRootNode() as Document;
    let pointContainer = root.elementFromPoint(elemCenter.x, elemCenter.y) as Node;
    do {
        if (pointContainer === elem) return true;
    } while (pointContainer = pointContainer.parentNode);
    return false;
}
{'avg_line_length': 49.80769230769231, 'max_line_length': 99, 'alphanum_fraction': 0.6841698841698842, 'licenses': ['MIT'], 'repository_name': 'bahrus/be-intersectional', 'path': 'isVisible.ts', 'size': 1295, 'lang': 'TypeScript'}