Skip to content

Commit aceb5cd

Browse files
committed
Adressed issue
1 parent 80bf267 commit aceb5cd

File tree

3 files changed

+74
-60
lines changed

3 files changed

+74
-60
lines changed

lib/commons/dom/create-grid.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default function createGrid(
2727
) {
2828
// Prevent multiple calls per run
2929
if (cache.get('gridCreated') && !parentVNode) {
30+
if (cache.get('gridSize')) {
31+
return cache.get('gridSize');
32+
}
3033
return constants.gridSize;
3134
}
3235
cache.set('gridCreated', true);
@@ -110,6 +113,10 @@ export default function createGrid(
110113

111114
node = treeWalker.nextNode();
112115
}
116+
117+
if (cache.get('gridSize')) {
118+
return cache.get('gridSize');
119+
}
113120
return constants.gridSize;
114121
}
115122

@@ -430,6 +437,9 @@ class Grid {
430437
* @returns {number}
431438
*/
432439
toGridIndex(num) {
440+
if (cache.get('gridSize')) {
441+
return Math.floor(num / cache.get('gridSize'));
442+
}
433443
return Math.floor(num / constants.gridSize);
434444
}
435445

lib/commons/dom/get-overflow-hidden-ancestors.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import cache from '../../core/base/cache';
12
import memoize from '../../core/utils/memoize';
23

34
/**
@@ -17,12 +18,18 @@ const getOverflowHiddenAncestors = memoize(
1718

1819
const overflow = vNode.getComputedStylePropertyValue('overflow');
1920

20-
if (
21-
overflow.includes('hidden') ||
22-
overflow.includes('clip') ||
23-
overflow.includes('scroll')
24-
) {
25-
ancestors.push(vNode);
21+
if (cache.get('200%ZoomRule')) {
22+
if (
23+
overflow.includes('hidden') ||
24+
overflow.includes('clip') ||
25+
overflow.includes('scroll')
26+
) {
27+
ancestors.push(vNode);
28+
}
29+
} else {
30+
if (overflow.includes('hidden')) {
31+
ancestors.push(vNode);
32+
}
2633
}
2734

2835
return ancestors.concat(getOverflowHiddenAncestors(vNode.parent));

lib/commons/dom/get-visible-child-text-rects.js

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { getNodeFromTree } from '../../core/utils';
1+
import { getNodeFromTree, memoize } from '../../core/utils';
22
import { sanitize } from '../text';
3-
import { getIntersectionRect } from '../math';
3+
import { getIntersectionRect, getRectCenter, isPointInRect } from '../math';
44
import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors';
5+
import cache from '../../core/base/cache';
56

67
/**
78
* Get the visible text client rects of a node.
@@ -10,56 +11,54 @@ import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors';
1011
* @instance
1112
* @param {Element} node
1213
*/
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);
2020

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+
}
2325

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+
}
2833

29-
const contentRects = getContentRects(textNode);
30-
// if (isOutsideNodeBounds(contentRects, nodeRect)) {
31-
// return;
32-
// }
34+
clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
35+
});
3336

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+
*/
3854

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);
4160
}
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+
);
6362
export default getVisibleChildTextRects;
6463

6564
function getContentRects(node) {
@@ -74,12 +73,12 @@ function getContentRects(node) {
7473
* when determining the rect stack we will also use the midpoint
7574
* of the text rect to determine out of bounds
7675
*/
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+
}
8382

8483
/**
8584
* Filter out 0 width and height rects (newline characters) and
@@ -97,9 +96,7 @@ function filterHiddenRects(contentRects, overflowHiddenNodes) {
9796

9897
// update the rect size to fit inside the bounds of all overflow
9998
// hidden ancestors
100-
// console.log("Overflow Hidden nodes are ", overflowHiddenNodes);
10199
const visibleRect = overflowHiddenNodes.reduce((rect, overflowNode) => {
102-
// console.log("Overflow node is ", overflowNode);
103100
return rect && getIntersectionRect(rect, overflowNode.boundingClientRect);
104101
}, contentRect);
105102

0 commit comments

Comments
 (0)