Skip to content

Commit f26d769

Browse files
committed
memoize visibleAtPoint
1 parent 6e4e364 commit f26d769

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

packages/driver/src/dom/visibility/fastIsHidden.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ function subDivideRect ({ x, y, width, height }: DOMRect): DOMRect[] {
6363
].filter((rect: DOMRect) => rect.width > 1 && rect.height > 1)
6464
}
6565

66-
function visibleAtPoint (el: HTMLElement, x: number, y: number): boolean {
66+
const visibleAtPoint = memoize(function (el: HTMLElement, x: number, y: number): boolean {
6767
const elAtPoint = el.ownerDocument.elementFromPoint(x, y)
6868

6969
debug('visibleAtPoint', el, elAtPoint)
7070

7171
return Boolean(elAtPoint) && (elAtPoint === el || el.contains(elAtPoint))
72-
}
72+
})
7373

7474
function visibleToUser (el: HTMLElement, rect: DOMRect, maxDepth: number = 2, currentDepth: number = 0): boolean {
7575
if (currentDepth >= maxDepth) {
@@ -136,25 +136,6 @@ export function fastIsHidden (subject: JQuery<HTMLElement> | HTMLElement, option
136136

137137
const boundingRect = getBoundingClientRect(subject)
138138

139-
// Do we need to do a more intensive opacity check, or is the checkOpacity option enough?
140-
/*
141-
if (options.checkOpacity) {
142-
let currentElement = subject
143-
let effectiveOpacity = opacity
144-
145-
while (currentElement) {
146-
const currentOpacity = Number(currentElement.computedStyleMap().get('opacity')?.toString() || 1)
147-
148-
effectiveOpacity *= currentOpacity
149-
if (effectiveOpacity === 0) {
150-
return true
151-
}
152-
153-
currentElement = currentElement.parentElement
154-
}
155-
}
156-
*/
157-
158139
if (visibleToUser(subject, boundingRect)) {
159140
debug('visibleToUser', subject, boundingRect)
160141

0 commit comments

Comments
 (0)