function isVisible()

in src/js/other-websites/fathom.js [489:526]


    function isVisible(fnodeOrElement) {
        // This could be 5x more efficient if https://github.com/w3c/csswg-drafts/issues/4122 happens.
        const element = toDomElement(fnodeOrElement);
        const elementRect = element.getBoundingClientRect();
        const elementStyle = getComputedStyle(element);
        // Alternative to reading ``display: none`` due to Bug 1381071.
        if (elementRect.width === 0 && elementRect.height === 0 && elementStyle.overflow !== 'hidden') {
            return false;
        }
        if (elementStyle.visibility === 'hidden') {
            return false;
        }
        // Check if the element is irrevocably off-screen:
        if (elementRect.x + elementRect.width < 0 ||
            elementRect.y + elementRect.height < 0
        ) {
            return false;
        }
        for (const ancestor of ancestors(element)) {
            const isElement = ancestor === element;
            const style = isElement ? elementStyle : getComputedStyle(ancestor);
            if (style.opacity === '0') {
                return false;
            }
            if (style.display === 'contents') {
                // ``display: contents`` elements have no box themselves, but children are
                // still rendered.
                continue;
            }
            const rect = isElement ? elementRect : ancestor.getBoundingClientRect();
            if ((rect.width === 0 || rect.height === 0) && elementStyle.overflow === 'hidden') {
                // Zero-sized ancestors don’t make descendants hidden unless the descendant
                // has ``overflow: hidden``.
                return false;
            }
        }
        return true;
    }