1
- import { getNodeFromTree } from '../../core/utils' ;
1
+ import { getNodeFromTree , memoize } from '../../core/utils' ;
2
2
import { sanitize } from '../text' ;
3
- import { getIntersectionRect } from '../math' ;
3
+ import { getIntersectionRect , getRectCenter , isPointInRect } from '../math' ;
4
4
import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors' ;
5
+ import cache from '../../core/base/cache' ;
5
6
6
7
/**
7
8
* Get the visible text client rects of a node.
@@ -10,56 +11,54 @@ import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors';
10
11
* @instance
11
12
* @param {Element } node
12
13
*/
13
- const getVisibleChildTextRects = function getVisibleChildTextRectsMemoized (
14
- node
15
- ) {
16
- const vNode = getNodeFromTree ( node ) ;
17
- const nodeRect = vNode . boundingClientRect ;
18
- const clientRects = [ ] ;
19
- const overflowHiddenNodes = getOverflowHiddenAncestors ( vNode ) ;
14
+ const getVisibleChildTextRects = memoize (
15
+ function getVisibleChildTextRectsMemoized ( node ) {
16
+ const vNode = getNodeFromTree ( node ) ;
17
+ const nodeRect = vNode . boundingClientRect ;
18
+ const clientRects = [ ] ;
19
+ const overflowHiddenNodes = getOverflowHiddenAncestors ( vNode ) ;
20
20
21
- // console.log("Here");
22
- // console.log("Child Nodes are ", node.childNodes);
21
+ node . childNodes . forEach ( textNode => {
22
+ if ( textNode . nodeType !== 3 || sanitize ( textNode . nodeValue ) === '' ) {
23
+ return ;
24
+ }
23
25
24
- node . childNodes . forEach ( textNode => {
25
- if ( textNode . nodeType !== 3 || sanitize ( textNode . nodeValue ) === '' ) {
26
- return ;
27
- }
26
+ const contentRects = getContentRects ( textNode ) ;
27
+ if (
28
+ isOutsideNodeBounds ( contentRects , nodeRect ) &&
29
+ ! cache . get ( '200%ZoomRule' )
30
+ ) {
31
+ return ;
32
+ }
28
33
29
- const contentRects = getContentRects ( textNode ) ;
30
- // if (isOutsideNodeBounds(contentRects, nodeRect)) {
31
- // return;
32
- // }
34
+ clientRects . push ( ...filterHiddenRects ( contentRects , overflowHiddenNodes ) ) ;
35
+ } ) ;
33
36
34
- // console.log("Client Rects ate ", structuredClone(contentRects));
35
-
36
- clientRects . push ( ...filterHiddenRects ( contentRects , overflowHiddenNodes ) ) ;
37
- } ) ;
37
+ if ( clientRects . length <= 0 && cache . get ( '200%ZoomRule' ) ) {
38
+ return [ ] ;
39
+ }
40
+ /**
41
+ * if all text rects are larger than the bounds of the node,
42
+ * or goes outside of the bounds of the node, we need to use
43
+ * the nodes bounding rect so we stay within the bounds of the
44
+ * element.
45
+ *
46
+ * @see https://github.com/dequelabs/axe-core/issues/2178
47
+ * @see https://github.com/dequelabs/axe-core/issues/2483
48
+ * @see https://github.com/dequelabs/axe-core/issues/2681
49
+ *
50
+ * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
51
+ *
52
+ * @see https://github.com/dequelabs/axe-core/issues/4253
53
+ */
38
54
39
- if ( clientRects . length <= 0 ) {
40
- return [ ] ;
55
+ // console.log("Node is ", node);
56
+ // console.log("Client Rects is ", clientRects);
57
+ return clientRects . length
58
+ ? clientRects
59
+ : filterHiddenRects ( [ nodeRect ] , overflowHiddenNodes ) ;
41
60
}
42
- /**
43
- * if all text rects are larger than the bounds of the node,
44
- * or goes outside of the bounds of the node, we need to use
45
- * the nodes bounding rect so we stay within the bounds of the
46
- * element.
47
- *
48
- * @see https://github.com/dequelabs/axe-core/issues/2178
49
- * @see https://github.com/dequelabs/axe-core/issues/2483
50
- * @see https://github.com/dequelabs/axe-core/issues/2681
51
- *
52
- * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
53
- *
54
- * @see https://github.com/dequelabs/axe-core/issues/4253
55
- */
56
-
57
- // console.log("Node is ", node);
58
- // console.log("Client Rects is ", clientRects);
59
- return clientRects . length
60
- ? clientRects
61
- : filterHiddenRects ( [ nodeRect ] , overflowHiddenNodes ) ;
62
- } ;
61
+ ) ;
63
62
export default getVisibleChildTextRects ;
64
63
65
64
function getContentRects ( node ) {
@@ -74,12 +73,12 @@ function getContentRects(node) {
74
73
* when determining the rect stack we will also use the midpoint
75
74
* of the text rect to determine out of bounds
76
75
*/
77
- // function isOutsideNodeBounds(rects, nodeRect) {
78
- // return rects.some(rect => {
79
- // const centerPoint = getRectCenter(rect);
80
- // return !isPointInRect(centerPoint, nodeRect);
81
- // });
82
- // }
76
+ function isOutsideNodeBounds ( rects , nodeRect ) {
77
+ return rects . some ( rect => {
78
+ const centerPoint = getRectCenter ( rect ) ;
79
+ return ! isPointInRect ( centerPoint , nodeRect ) ;
80
+ } ) ;
81
+ }
83
82
84
83
/**
85
84
* Filter out 0 width and height rects (newline characters) and
@@ -97,9 +96,7 @@ function filterHiddenRects(contentRects, overflowHiddenNodes) {
97
96
98
97
// update the rect size to fit inside the bounds of all overflow
99
98
// hidden ancestors
100
- // console.log("Overflow Hidden nodes are ", overflowHiddenNodes);
101
99
const visibleRect = overflowHiddenNodes . reduce ( ( rect , overflowNode ) => {
102
- // console.log("Overflow node is ", overflowNode);
103
100
return rect && getIntersectionRect ( rect , overflowNode . boundingClientRect ) ;
104
101
} , contentRect ) ;
105
102
0 commit comments