-
Notifications
You must be signed in to change notification settings - Fork 784
/
get-target-rects.js
38 lines (33 loc) · 1.08 KB
/
get-target-rects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import findNearbyElms from './find-nearby-elms';
import isInTabOrder from './is-in-tab-order';
import { splitRects, hasVisualOverlap } from '../math';
import memoize from '../../core/utils/memoize';
export default memoize(getTargetRects);
/**
* Return all unobscured rects of a target.
* @see https://www.w3.org/TR/WCAG22/#dfn-bounding-boxes
* @param {VitualNode} vNode
* @return {DOMRect[]}
*/
function getTargetRects(vNode) {
const nodeRect = vNode.boundingClientRect;
const overlappingVNodes = findNearbyElms(vNode).filter(vNeighbor => {
return (
hasVisualOverlap(vNode, vNeighbor) &&
vNeighbor.getComputedStylePropertyValue('pointer-events') !== 'none' &&
!isDescendantNotInTabOrder(vNode, vNeighbor)
);
});
if (!overlappingVNodes.length) {
return [nodeRect];
}
const obscuringRects = overlappingVNodes.map(
({ boundingClientRect: rect }) => rect
);
return splitRects(nodeRect, obscuringRects);
}
function isDescendantNotInTabOrder(vAncestor, vNode) {
return (
vAncestor.actualNode.contains(vNode.actualNode) && !isInTabOrder(vNode)
);
}