dom.ts: make isVisible use parentElement clientRect if necessary

In some cases, you might need to call isVisible on a text node. These
nodes don't have their own getClientRects method. It makes sense to
check the parent node's getClientRects method instead since its
visibility impacts its child node's.
This commit is contained in:
glacambre 2019-02-09 13:36:18 +01:00
parent 7db70f1393
commit 2dad1c0230
No known key found for this signature in database
GPG key ID: B9625DB1767553AC

View file

@ -217,6 +217,9 @@ export function widthMatters(style: CSSStyleDeclaration) {
*/
export function isVisible(element: Element) {
while (!(element.getClientRects instanceof Function)) {
element = element.parentElement
}
const clientRect = element.getClientRects()[0]
const computedStyle = getComputedStyle(element)
// remove elements that are barely within the viewport, tiny, or invisible