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