From 8ca2d2d2f7ab5ac60011dd7d75e3fe74aa055542 Mon Sep 17 00:00:00 2001 From: Swaraj Gandhi Date: Wed, 11 Sep 2024 10:51:07 +0530 Subject: [PATCH 01/13] added changes for build process --- build/tasks/esbuild.js | 1 + 1 file changed, 1 insertion(+) diff --git a/build/tasks/esbuild.js b/build/tasks/esbuild.js index 30dbeb4ef..1c5e2bac1 100644 --- a/build/tasks/esbuild.js +++ b/build/tasks/esbuild.js @@ -23,6 +23,7 @@ module.exports = function (grunt) { entryPoints: [entry], outfile: path.join(dest, name), minify: false, + format: "esm", bundle: true }) .then(done) From 01d91e95ead2e9ddc165cf5a4ea7d0c3040ba076 Mon Sep 17 00:00:00 2001 From: SwarajGK Date: Wed, 11 Sep 2024 05:58:47 +0000 Subject: [PATCH 02/13] :robot: Automated formatting fixes --- build/tasks/esbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/tasks/esbuild.js b/build/tasks/esbuild.js index 1c5e2bac1..ad074a52b 100644 --- a/build/tasks/esbuild.js +++ b/build/tasks/esbuild.js @@ -23,7 +23,7 @@ module.exports = function (grunt) { entryPoints: [entry], outfile: path.join(dest, name), minify: false, - format: "esm", + format: 'esm', bundle: true }) .then(done) From 80bf26730a1b7d0c45b5bf971661255a6178cb3b Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Wed, 11 Sep 2024 16:37:38 +0530 Subject: [PATCH 03/13] Updated axe-core files for 200% zoom --- lib/commons/dom/get-element-stack.js | 11 ++- .../dom/get-overflow-hidden-ancestors.js | 6 +- lib/commons/dom/get-rect-stack.js | 19 +++- .../dom/get-visible-child-text-rects.js | 97 +++++++++++-------- lib/core/constants.js | 2 +- 5 files changed, 86 insertions(+), 49 deletions(-) diff --git a/lib/commons/dom/get-element-stack.js b/lib/commons/dom/get-element-stack.js index 132a20f2b..6aeebd4ae 100644 --- a/lib/commons/dom/get-element-stack.js +++ b/lib/commons/dom/get-element-stack.js @@ -9,7 +9,7 @@ import createGrid from './create-grid'; * @param {Node} node * @return {Node[]} */ -function getElementStack(node) { +function getElementStack(node, isCoordsPassed = false, x, y) { createGrid(); const vNode = getNodeFromTree(node); @@ -19,7 +19,14 @@ function getElementStack(node) { return []; } - return getRectStack(grid, vNode.boundingClientRect); + return getRectStack( + grid, + vNode.boundingClientRect, + false, + isCoordsPassed, + x, + y + ); } export default getElementStack; diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 01ab696e2..0b40cf35d 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -17,7 +17,11 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); - if (overflow === 'hidden') { + if ( + overflow.includes('hidden') || + overflow.includes('clip') || + overflow.includes('scroll') + ) { ancestors.push(vNode); } diff --git a/lib/commons/dom/get-rect-stack.js b/lib/commons/dom/get-rect-stack.js index 4c51bf3b3..e0a3c5649 100644 --- a/lib/commons/dom/get-rect-stack.js +++ b/lib/commons/dom/get-rect-stack.js @@ -1,12 +1,25 @@ import visuallySort from './visually-sort'; import { getRectCenter } from '../math'; -export function getRectStack(grid, rect, recursed = false) { +export function getRectStack( + grid, + rect, + recursed = false, + isCoordsPassed, + x, + y +) { const center = getRectCenter(rect); const gridCell = grid.getCellFromPoint(center) || []; - const floorX = Math.floor(center.x); - const floorY = Math.floor(center.y); + let floorX = Math.floor(center.x); + let floorY = Math.floor(center.y); + + if (isCoordsPassed) { + floorX = Math.floor(x); + floorY = Math.floor(y); + } + let stack = gridCell.filter(gridCellNode => { return gridCellNode.clientRects.some(clientRect => { const rectX = clientRect.left; diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index 02611798e..e233750a2 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -1,6 +1,6 @@ -import { getNodeFromTree, memoize } from '../../core/utils'; +import { getNodeFromTree } from '../../core/utils'; import { sanitize } from '../text'; -import { getRectCenter, isPointInRect, getIntersectionRect } from '../math'; +import { getIntersectionRect } from '../math'; import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; /** @@ -10,45 +10,56 @@ import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; * @instance * @param {Element} node */ -const getVisibleChildTextRects = memoize( - function getVisibleChildTextRectsMemoized(node) { - const vNode = getNodeFromTree(node); - const nodeRect = vNode.boundingClientRect; - const clientRects = []; - const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); +const getVisibleChildTextRects = function getVisibleChildTextRectsMemoized( + node +) { + const vNode = getNodeFromTree(node); + const nodeRect = vNode.boundingClientRect; + const clientRects = []; + const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); - node.childNodes.forEach(textNode => { - if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { - return; - } + // console.log("Here"); + // console.log("Child Nodes are ", node.childNodes); - const contentRects = getContentRects(textNode); - if (isOutsideNodeBounds(contentRects, nodeRect)) { - return; - } + node.childNodes.forEach(textNode => { + if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { + return; + } + + const contentRects = getContentRects(textNode); + // if (isOutsideNodeBounds(contentRects, nodeRect)) { + // return; + // } + + // console.log("Client Rects ate ", structuredClone(contentRects)); - clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); - }); + clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); + }); - /** - * if all text rects are larger than the bounds of the node, - * or goes outside of the bounds of the node, we need to use - * the nodes bounding rect so we stay within the bounds of the - * element. - * - * @see https://github.com/dequelabs/axe-core/issues/2178 - * @see https://github.com/dequelabs/axe-core/issues/2483 - * @see https://github.com/dequelabs/axe-core/issues/2681 - * - * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors. - * - * @see https://github.com/dequelabs/axe-core/issues/4253 - */ - return clientRects.length - ? clientRects - : filterHiddenRects([nodeRect], overflowHiddenNodes); + if (clientRects.length <= 0) { + return []; } -); + /** + * if all text rects are larger than the bounds of the node, + * or goes outside of the bounds of the node, we need to use + * the nodes bounding rect so we stay within the bounds of the + * element. + * + * @see https://github.com/dequelabs/axe-core/issues/2178 + * @see https://github.com/dequelabs/axe-core/issues/2483 + * @see https://github.com/dequelabs/axe-core/issues/2681 + * + * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors. + * + * @see https://github.com/dequelabs/axe-core/issues/4253 + */ + + // console.log("Node is ", node); + // console.log("Client Rects is ", clientRects); + return clientRects.length + ? clientRects + : filterHiddenRects([nodeRect], overflowHiddenNodes); +}; export default getVisibleChildTextRects; function getContentRects(node) { @@ -63,12 +74,12 @@ function getContentRects(node) { * when determining the rect stack we will also use the midpoint * of the text rect to determine out of bounds */ -function isOutsideNodeBounds(rects, nodeRect) { - return rects.some(rect => { - const centerPoint = getRectCenter(rect); - return !isPointInRect(centerPoint, nodeRect); - }); -} +// function isOutsideNodeBounds(rects, nodeRect) { +// return rects.some(rect => { +// const centerPoint = getRectCenter(rect); +// return !isPointInRect(centerPoint, nodeRect); +// }); +// } /** * Filter out 0 width and height rects (newline characters) and @@ -86,7 +97,9 @@ function filterHiddenRects(contentRects, overflowHiddenNodes) { // update the rect size to fit inside the bounds of all overflow // hidden ancestors + // console.log("Overflow Hidden nodes are ", overflowHiddenNodes); const visibleRect = overflowHiddenNodes.reduce((rect, overflowNode) => { + // console.log("Overflow node is ", overflowNode); return rect && getIntersectionRect(rect, overflowNode.boundingClientRect); }, contentRect); diff --git a/lib/core/constants.js b/lib/core/constants.js index 3880c0a16..c6486d40a 100644 --- a/lib/core/constants.js +++ b/lib/core/constants.js @@ -27,7 +27,7 @@ const definitions = [ const constants = { helpUrlBase: 'https://dequeuniversity.com/rules/', - gridSize: 200, + gridSize: 500, results: [], resultGroups: [], resultGroupMap: {}, From aceb5cdf3c41fd8f7fe52c7f35869f64066e3773 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Wed, 18 Sep 2024 17:55:49 +0530 Subject: [PATCH 04/13] Adressed issue --- lib/commons/dom/create-grid.js | 10 ++ .../dom/get-overflow-hidden-ancestors.js | 19 +++- .../dom/get-visible-child-text-rects.js | 105 +++++++++--------- 3 files changed, 74 insertions(+), 60 deletions(-) diff --git a/lib/commons/dom/create-grid.js b/lib/commons/dom/create-grid.js index 612e885bb..bcaa86b1a 100644 --- a/lib/commons/dom/create-grid.js +++ b/lib/commons/dom/create-grid.js @@ -27,6 +27,9 @@ export default function createGrid( ) { // Prevent multiple calls per run if (cache.get('gridCreated') && !parentVNode) { + if (cache.get('gridSize')) { + return cache.get('gridSize'); + } return constants.gridSize; } cache.set('gridCreated', true); @@ -110,6 +113,10 @@ export default function createGrid( node = treeWalker.nextNode(); } + + if (cache.get('gridSize')) { + return cache.get('gridSize'); + } return constants.gridSize; } @@ -430,6 +437,9 @@ class Grid { * @returns {number} */ toGridIndex(num) { + if (cache.get('gridSize')) { + return Math.floor(num / cache.get('gridSize')); + } return Math.floor(num / constants.gridSize); } diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 0b40cf35d..78c7e2625 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -1,3 +1,4 @@ +import cache from '../../core/base/cache'; import memoize from '../../core/utils/memoize'; /** @@ -17,12 +18,18 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); - if ( - overflow.includes('hidden') || - overflow.includes('clip') || - overflow.includes('scroll') - ) { - ancestors.push(vNode); + if (cache.get('200%ZoomRule')) { + if ( + overflow.includes('hidden') || + overflow.includes('clip') || + overflow.includes('scroll') + ) { + ancestors.push(vNode); + } + } else { + if (overflow.includes('hidden')) { + ancestors.push(vNode); + } } return ancestors.concat(getOverflowHiddenAncestors(vNode.parent)); diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index e233750a2..bd6fa99ba 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -1,7 +1,8 @@ -import { getNodeFromTree } from '../../core/utils'; +import { getNodeFromTree, memoize } from '../../core/utils'; import { sanitize } from '../text'; -import { getIntersectionRect } from '../math'; +import { getIntersectionRect, getRectCenter, isPointInRect } from '../math'; import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; +import cache from '../../core/base/cache'; /** * Get the visible text client rects of a node. @@ -10,56 +11,54 @@ import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; * @instance * @param {Element} node */ -const getVisibleChildTextRects = function getVisibleChildTextRectsMemoized( - node -) { - const vNode = getNodeFromTree(node); - const nodeRect = vNode.boundingClientRect; - const clientRects = []; - const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); +const getVisibleChildTextRects = memoize( + function getVisibleChildTextRectsMemoized(node) { + const vNode = getNodeFromTree(node); + const nodeRect = vNode.boundingClientRect; + const clientRects = []; + const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); - // console.log("Here"); - // console.log("Child Nodes are ", node.childNodes); + node.childNodes.forEach(textNode => { + if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { + return; + } - node.childNodes.forEach(textNode => { - if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { - return; - } + const contentRects = getContentRects(textNode); + if ( + isOutsideNodeBounds(contentRects, nodeRect) && + !cache.get('200%ZoomRule') + ) { + return; + } - const contentRects = getContentRects(textNode); - // if (isOutsideNodeBounds(contentRects, nodeRect)) { - // return; - // } + clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); + }); - // console.log("Client Rects ate ", structuredClone(contentRects)); - - clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); - }); + if (clientRects.length <= 0 && cache.get('200%ZoomRule')) { + return []; + } + /** + * if all text rects are larger than the bounds of the node, + * or goes outside of the bounds of the node, we need to use + * the nodes bounding rect so we stay within the bounds of the + * element. + * + * @see https://github.com/dequelabs/axe-core/issues/2178 + * @see https://github.com/dequelabs/axe-core/issues/2483 + * @see https://github.com/dequelabs/axe-core/issues/2681 + * + * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors. + * + * @see https://github.com/dequelabs/axe-core/issues/4253 + */ - if (clientRects.length <= 0) { - return []; + // console.log("Node is ", node); + // console.log("Client Rects is ", clientRects); + return clientRects.length + ? clientRects + : filterHiddenRects([nodeRect], overflowHiddenNodes); } - /** - * if all text rects are larger than the bounds of the node, - * or goes outside of the bounds of the node, we need to use - * the nodes bounding rect so we stay within the bounds of the - * element. - * - * @see https://github.com/dequelabs/axe-core/issues/2178 - * @see https://github.com/dequelabs/axe-core/issues/2483 - * @see https://github.com/dequelabs/axe-core/issues/2681 - * - * also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors. - * - * @see https://github.com/dequelabs/axe-core/issues/4253 - */ - - // console.log("Node is ", node); - // console.log("Client Rects is ", clientRects); - return clientRects.length - ? clientRects - : filterHiddenRects([nodeRect], overflowHiddenNodes); -}; +); export default getVisibleChildTextRects; function getContentRects(node) { @@ -74,12 +73,12 @@ function getContentRects(node) { * when determining the rect stack we will also use the midpoint * of the text rect to determine out of bounds */ -// function isOutsideNodeBounds(rects, nodeRect) { -// return rects.some(rect => { -// const centerPoint = getRectCenter(rect); -// return !isPointInRect(centerPoint, nodeRect); -// }); -// } +function isOutsideNodeBounds(rects, nodeRect) { + return rects.some(rect => { + const centerPoint = getRectCenter(rect); + return !isPointInRect(centerPoint, nodeRect); + }); +} /** * Filter out 0 width and height rects (newline characters) and @@ -97,9 +96,7 @@ function filterHiddenRects(contentRects, overflowHiddenNodes) { // update the rect size to fit inside the bounds of all overflow // hidden ancestors - // console.log("Overflow Hidden nodes are ", overflowHiddenNodes); const visibleRect = overflowHiddenNodes.reduce((rect, overflowNode) => { - // console.log("Overflow node is ", overflowNode); return rect && getIntersectionRect(rect, overflowNode.boundingClientRect); }, contentRect); From ace6841500bf9c1cdb20a63ddb07f4679b7a16e0 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Wed, 18 Sep 2024 17:57:48 +0530 Subject: [PATCH 05/13] Adressed issue --- lib/commons/dom/get-visible-child-text-rects.js | 2 -- lib/core/constants.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index bd6fa99ba..cd778b743 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -52,8 +52,6 @@ const getVisibleChildTextRects = memoize( * @see https://github.com/dequelabs/axe-core/issues/4253 */ - // console.log("Node is ", node); - // console.log("Client Rects is ", clientRects); return clientRects.length ? clientRects : filterHiddenRects([nodeRect], overflowHiddenNodes); diff --git a/lib/core/constants.js b/lib/core/constants.js index c6486d40a..3880c0a16 100644 --- a/lib/core/constants.js +++ b/lib/core/constants.js @@ -27,7 +27,7 @@ const definitions = [ const constants = { helpUrlBase: 'https://dequeuniversity.com/rules/', - gridSize: 500, + gridSize: 200, results: [], resultGroups: [], resultGroupMap: {}, From 19077ec4e674d8edaea4240f39e7206d63b3e87a Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Thu, 19 Sep 2024 08:06:13 +0530 Subject: [PATCH 06/13] Adressed issue --- lib/commons/dom/create-grid.js | 23 ++++++++----------- lib/commons/dom/get-element-stack.js | 17 ++++++++++++-- .../dom/get-overflow-hidden-ancestors.js | 5 ++-- lib/commons/dom/get-rect-stack.js | 6 ++--- .../dom/get-visible-child-text-rects.js | 16 ++++++------- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/commons/dom/create-grid.js b/lib/commons/dom/create-grid.js index bcaa86b1a..919e27730 100644 --- a/lib/commons/dom/create-grid.js +++ b/lib/commons/dom/create-grid.js @@ -14,6 +14,7 @@ const DEFAULT_LEVEL = 0.1; const FLOAT_LEVEL = 0.2; const POSITION_LEVEL = 0.3; let nodeIndex = 0; +let gridSize = constants.gridSize; /** * Setup the 2d grid and add every element to it, even elements not @@ -23,14 +24,16 @@ let nodeIndex = 0; export default function createGrid( root = document.body, rootGrid, - parentVNode = null + parentVNode = null, + ruleData = null ) { + if (ruleData && ruleData.ruleId && ruleData.gridSize) { + gridSize = ruleData.gridSize; + } + // Prevent multiple calls per run if (cache.get('gridCreated') && !parentVNode) { - if (cache.get('gridSize')) { - return cache.get('gridSize'); - } - return constants.gridSize; + return gridSize; } cache.set('gridCreated', true); @@ -114,10 +117,7 @@ export default function createGrid( node = treeWalker.nextNode(); } - if (cache.get('gridSize')) { - return cache.get('gridSize'); - } - return constants.gridSize; + return gridSize; } /** @@ -437,10 +437,7 @@ class Grid { * @returns {number} */ toGridIndex(num) { - if (cache.get('gridSize')) { - return Math.floor(num / cache.get('gridSize')); - } - return Math.floor(num / constants.gridSize); + return Math.floor(num / gridSize); } /** diff --git a/lib/commons/dom/get-element-stack.js b/lib/commons/dom/get-element-stack.js index 6aeebd4ae..bdb256aa1 100644 --- a/lib/commons/dom/get-element-stack.js +++ b/lib/commons/dom/get-element-stack.js @@ -9,8 +9,21 @@ import createGrid from './create-grid'; * @param {Node} node * @return {Node[]} */ -function getElementStack(node, isCoordsPassed = false, x, y) { - createGrid(); +function getElementStack( + node, + ruleId = null, + isCoordsPassed = false, + x = null, + y = null +) { + if (ruleId === 'zoom-text-overlap-viewport') { + createGrid(document.body, null, null, { + ruleId, + gridSize: 500 + }); + } else { + createGrid(); + } const vNode = getNodeFromTree(node); const grid = vNode._grid; diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 78c7e2625..a3b7ee11b 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -1,4 +1,3 @@ -import cache from '../../core/base/cache'; import memoize from '../../core/utils/memoize'; /** @@ -9,7 +8,7 @@ import memoize from '../../core/utils/memoize'; * @returns {VirtualNode[]} */ const getOverflowHiddenAncestors = memoize( - function getOverflowHiddenAncestorsMemoized(vNode) { + function getOverflowHiddenAncestorsMemoized(vNode, ruleId = null) { const ancestors = []; if (!vNode) { @@ -18,7 +17,7 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); - if (cache.get('200%ZoomRule')) { + if (ruleId && ruleId === 'zoom-text-overlap-viewport') { if ( overflow.includes('hidden') || overflow.includes('clip') || diff --git a/lib/commons/dom/get-rect-stack.js b/lib/commons/dom/get-rect-stack.js index e0a3c5649..7af8b9eb6 100644 --- a/lib/commons/dom/get-rect-stack.js +++ b/lib/commons/dom/get-rect-stack.js @@ -5,9 +5,9 @@ export function getRectStack( grid, rect, recursed = false, - isCoordsPassed, - x, - y + isCoordsPassed = false, + x = null, + y = null ) { const center = getRectCenter(rect); const gridCell = grid.getCellFromPoint(center) || []; diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index cd778b743..9204d29d8 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -2,7 +2,6 @@ import { getNodeFromTree, memoize } from '../../core/utils'; import { sanitize } from '../text'; import { getIntersectionRect, getRectCenter, isPointInRect } from '../math'; import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; -import cache from '../../core/base/cache'; /** * Get the visible text client rects of a node. @@ -12,11 +11,11 @@ import cache from '../../core/base/cache'; * @param {Element} node */ const getVisibleChildTextRects = memoize( - function getVisibleChildTextRectsMemoized(node) { + function getVisibleChildTextRectsMemoized(node, ruleId = null) { const vNode = getNodeFromTree(node); const nodeRect = vNode.boundingClientRect; const clientRects = []; - const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); + const overflowHiddenNodes = getOverflowHiddenAncestors(vNode, ruleId); node.childNodes.forEach(textNode => { if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { @@ -24,17 +23,18 @@ const getVisibleChildTextRects = memoize( } const contentRects = getContentRects(textNode); - if ( - isOutsideNodeBounds(contentRects, nodeRect) && - !cache.get('200%ZoomRule') - ) { + if (isOutsideNodeBounds(contentRects, nodeRect) && !ruleId) { return; } clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); }); - if (clientRects.length <= 0 && cache.get('200%ZoomRule')) { + if ( + clientRects.length <= 0 && + ruleId && + ruleId === 'zoom-text-overlap-viewport' + ) { return []; } /** From 7bc9186deb1f79fffc20a4bf88ca4680c637a672 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Thu, 19 Sep 2024 08:08:51 +0530 Subject: [PATCH 07/13] Adressed issue --- lib/commons/dom/get-visible-child-text-rects.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index 9204d29d8..514c9e2c5 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -51,7 +51,6 @@ const getVisibleChildTextRects = memoize( * * @see https://github.com/dequelabs/axe-core/issues/4253 */ - return clientRects.length ? clientRects : filterHiddenRects([nodeRect], overflowHiddenNodes); From 49c223f957b1a28ac9a8d4ea0c92e31393f8fac0 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Thu, 19 Sep 2024 11:19:10 +0530 Subject: [PATCH 08/13] Reverted to cache method --- lib/commons/dom/get-element-stack.js | 2 +- lib/commons/dom/get-overflow-hidden-ancestors.js | 5 ++++- lib/commons/dom/get-visible-child-text-rects.js | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/commons/dom/get-element-stack.js b/lib/commons/dom/get-element-stack.js index 6aeebd4ae..7d5284965 100644 --- a/lib/commons/dom/get-element-stack.js +++ b/lib/commons/dom/get-element-stack.js @@ -9,7 +9,7 @@ import createGrid from './create-grid'; * @param {Node} node * @return {Node[]} */ -function getElementStack(node, isCoordsPassed = false, x, y) { +function getElementStack(node, isCoordsPassed = false, x = null, y = null) { createGrid(); const vNode = getNodeFromTree(node); diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 78c7e2625..64600ee9f 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -18,7 +18,10 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); - if (cache.get('200%ZoomRule')) { + if ( + cache.get('ruleId') && + cache.get('ruleId') === 'zoom-text-overlap-viewport' + ) { if ( overflow.includes('hidden') || overflow.includes('clip') || diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index cd778b743..76be013a6 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -24,17 +24,18 @@ const getVisibleChildTextRects = memoize( } const contentRects = getContentRects(textNode); - if ( - isOutsideNodeBounds(contentRects, nodeRect) && - !cache.get('200%ZoomRule') - ) { + if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) { return; } clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); }); - if (clientRects.length <= 0 && cache.get('200%ZoomRule')) { + if ( + clientRects.length <= 0 && + cache.get('ruleId') && + cache.get('ruleId') === 'zoom-text-overlap-viewport' + ) { return []; } /** @@ -51,7 +52,6 @@ const getVisibleChildTextRects = memoize( * * @see https://github.com/dequelabs/axe-core/issues/4253 */ - return clientRects.length ? clientRects : filterHiddenRects([nodeRect], overflowHiddenNodes); From 6a26aa6bb513b639b9e46a8bcb3a0c635f77fcf6 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Fri, 20 Sep 2024 15:19:52 +0530 Subject: [PATCH 09/13] Added fix in getCellFromPoint in create-grid.js for 200% zoom --- lib/commons/dom/create-grid.js | 19 +++++++++++++++---- lib/commons/dom/get-element-stack.js | 3 +++ .../dom/get-overflow-hidden-ancestors.js | 1 + lib/commons/dom/get-rect-stack.js | 2 ++ .../dom/get-visible-child-text-rects.js | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/commons/dom/create-grid.js b/lib/commons/dom/create-grid.js index bcaa86b1a..c9e9fdbc0 100644 --- a/lib/commons/dom/create-grid.js +++ b/lib/commons/dom/create-grid.js @@ -27,6 +27,7 @@ export default function createGrid( ) { // Prevent multiple calls per run if (cache.get('gridCreated') && !parentVNode) { + // a11y-engine-domforge change if (cache.get('gridSize')) { return cache.get('gridSize'); } @@ -114,6 +115,7 @@ export default function createGrid( node = treeWalker.nextNode(); } + // a11y-engine-domforge change if (cache.get('gridSize')) { return cache.get('gridSize'); } @@ -437,6 +439,7 @@ class Grid { * @returns {number} */ toGridIndex(num) { + // a11y-engine-domforge change if (cache.get('gridSize')) { return Math.floor(num / cache.get('gridSize')); } @@ -452,10 +455,18 @@ class Grid { assert(this.boundaries, 'Grid does not have cells added'); const rowIndex = this.toGridIndex(y); const colIndex = this.toGridIndex(x); - assert( - isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries), - 'Element midpoint exceeds the grid bounds' - ); + + // a11y-engine-domforge change + if (cache.get('ruleId') === 'zoom-text-overlap-viewport') { + if (!isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries)) { + return []; + } + } else { + assert( + isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries), + 'Element midpoint exceeds the grid bounds' + ); + } const row = this.cells[rowIndex - this.cells._negativeIndex] ?? []; return row[colIndex - row._negativeIndex] ?? []; } diff --git a/lib/commons/dom/get-element-stack.js b/lib/commons/dom/get-element-stack.js index 7d5284965..510b7a811 100644 --- a/lib/commons/dom/get-element-stack.js +++ b/lib/commons/dom/get-element-stack.js @@ -9,6 +9,8 @@ import createGrid from './create-grid'; * @param {Node} node * @return {Node[]} */ + +// Additional props isCoordsPassed, x, y for a11y-engine-domforge function getElementStack(node, isCoordsPassed = false, x = null, y = null) { createGrid(); @@ -19,6 +21,7 @@ function getElementStack(node, isCoordsPassed = false, x = null, y = null) { return []; } + // Additional props isCoordsPassed, x, y for a11y-engine-domforge return getRectStack( grid, vNode.boundingClientRect, diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 64600ee9f..1a2252124 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -18,6 +18,7 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); + // a11y-engine-domforge change if ( cache.get('ruleId') && cache.get('ruleId') === 'zoom-text-overlap-viewport' diff --git a/lib/commons/dom/get-rect-stack.js b/lib/commons/dom/get-rect-stack.js index 7af8b9eb6..36489a504 100644 --- a/lib/commons/dom/get-rect-stack.js +++ b/lib/commons/dom/get-rect-stack.js @@ -1,6 +1,7 @@ import visuallySort from './visually-sort'; import { getRectCenter } from '../math'; +// Additional props isCoordsPassed, x, y for a11y-engine-domforge export function getRectStack( grid, rect, @@ -15,6 +16,7 @@ export function getRectStack( let floorX = Math.floor(center.x); let floorY = Math.floor(center.y); + // a11y-engine-domforge change if (isCoordsPassed) { floorX = Math.floor(x); floorY = Math.floor(y); diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index 76be013a6..202ebeedd 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -31,6 +31,7 @@ const getVisibleChildTextRects = memoize( clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); }); + // a11y-engine-domforge change if ( clientRects.length <= 0 && cache.get('ruleId') && From 5cd4a1f4855216e4fc61f1fe8ba24e1b55c55334 Mon Sep 17 00:00:00 2001 From: Utkarsh Chaudhary Date: Thu, 3 Oct 2024 17:58:13 +0530 Subject: [PATCH 10/13] Updated rule name --- lib/commons/dom/create-grid.js | 2 +- lib/commons/dom/get-overflow-hidden-ancestors.js | 5 +---- lib/commons/dom/get-visible-child-text-rects.js | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/commons/dom/create-grid.js b/lib/commons/dom/create-grid.js index c9e9fdbc0..7af1b0016 100644 --- a/lib/commons/dom/create-grid.js +++ b/lib/commons/dom/create-grid.js @@ -457,7 +457,7 @@ class Grid { const colIndex = this.toGridIndex(x); // a11y-engine-domforge change - if (cache.get('ruleId') === 'zoom-text-overlap-viewport') { + if (cache.get('ruleId') === 'resize-2x-zoom') { if (!isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries)) { return []; } diff --git a/lib/commons/dom/get-overflow-hidden-ancestors.js b/lib/commons/dom/get-overflow-hidden-ancestors.js index 1a2252124..79ca04cee 100644 --- a/lib/commons/dom/get-overflow-hidden-ancestors.js +++ b/lib/commons/dom/get-overflow-hidden-ancestors.js @@ -19,10 +19,7 @@ const getOverflowHiddenAncestors = memoize( const overflow = vNode.getComputedStylePropertyValue('overflow'); // a11y-engine-domforge change - if ( - cache.get('ruleId') && - cache.get('ruleId') === 'zoom-text-overlap-viewport' - ) { + if (cache.get('ruleId') && cache.get('ruleId') === 'resize-2x-zoom') { if ( overflow.includes('hidden') || overflow.includes('clip') || diff --git a/lib/commons/dom/get-visible-child-text-rects.js b/lib/commons/dom/get-visible-child-text-rects.js index 202ebeedd..2cd01773a 100644 --- a/lib/commons/dom/get-visible-child-text-rects.js +++ b/lib/commons/dom/get-visible-child-text-rects.js @@ -35,7 +35,7 @@ const getVisibleChildTextRects = memoize( if ( clientRects.length <= 0 && cache.get('ruleId') && - cache.get('ruleId') === 'zoom-text-overlap-viewport' + cache.get('ruleId') === 'resize-2x-zoom' ) { return []; } From 6b986461c0ac32b30fcefd230effff77c5881738 Mon Sep 17 00:00:00 2001 From: Arjun Chikara Date: Mon, 7 Oct 2024 18:51:56 +0530 Subject: [PATCH 11/13] Added safety to a11yEngineErrors --- lib/core/public/load.js | 5 ++++- lib/core/public/run-rules.js | 5 ++++- lib/core/utils/merge-results.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/public/load.js b/lib/core/public/load.js index e80d3d8f6..0d7e0caf4 100644 --- a/lib/core/public/load.js +++ b/lib/core/public/load.js @@ -42,7 +42,10 @@ function runCommand(data, keepalive, callback) { //a11y-engine iframe rules error merging logic const errors = a11yEngine.getErrors(); if (Object.keys(errors).length !== 0) { - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; const mergedErrors = mergeErrors(error, errors); diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index 8e04c13dc..9193d4373 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -67,7 +67,10 @@ export default function runRules(context, options, resolve, reject) { // after should only run once, so ensure we are in the top level window if (context.initiator) { // Return a11y-engine errors when at top level window - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; a11yEngine.mergeErrors(error); diff --git a/lib/core/utils/merge-results.js b/lib/core/utils/merge-results.js index 0e6277132..79aa935b1 100644 --- a/lib/core/utils/merge-results.js +++ b/lib/core/utils/merge-results.js @@ -86,7 +86,7 @@ function mergeResults(frameResults, options) { const frameSpec = getFrameSpec(frameResult); // Extract existing errors and merge with new ones - if (results[results.length - 1].a11yEngineErrors) { + if (results.length > 0 && results[results.length - 1]?.a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; mergedErrors = mergeErrors(mergedErrors, error, frameSpec); From 5610917a90e66b25e7b2f993bec713d599a333ad Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Wed, 9 Oct 2024 13:19:11 +0530 Subject: [PATCH 12/13] Revert "Fix: AXE-570 Fixed a11yEngineErrors being accessed on undefined" --- lib/core/public/load.js | 5 +---- lib/core/public/run-rules.js | 5 +---- lib/core/utils/merge-results.js | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/core/public/load.js b/lib/core/public/load.js index 0d7e0caf4..e80d3d8f6 100644 --- a/lib/core/public/load.js +++ b/lib/core/public/load.js @@ -42,10 +42,7 @@ function runCommand(data, keepalive, callback) { //a11y-engine iframe rules error merging logic const errors = a11yEngine.getErrors(); if (Object.keys(errors).length !== 0) { - if ( - results.length > 0 && - results[results.length - 1]?.a11yEngineErrors - ) { + if (results[results.length - 1].a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; const mergedErrors = mergeErrors(error, errors); diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index 9193d4373..8e04c13dc 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -67,10 +67,7 @@ export default function runRules(context, options, resolve, reject) { // after should only run once, so ensure we are in the top level window if (context.initiator) { // Return a11y-engine errors when at top level window - if ( - results.length > 0 && - results[results.length - 1]?.a11yEngineErrors - ) { + if (results[results.length - 1].a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; a11yEngine.mergeErrors(error); diff --git a/lib/core/utils/merge-results.js b/lib/core/utils/merge-results.js index 79aa935b1..0e6277132 100644 --- a/lib/core/utils/merge-results.js +++ b/lib/core/utils/merge-results.js @@ -86,7 +86,7 @@ function mergeResults(frameResults, options) { const frameSpec = getFrameSpec(frameResult); // Extract existing errors and merge with new ones - if (results.length > 0 && results[results.length - 1]?.a11yEngineErrors) { + if (results[results.length - 1].a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; mergedErrors = mergeErrors(mergedErrors, error, frameSpec); From 3251c8c83882bc42e972120fa0a0d1802e851d71 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Wed, 9 Oct 2024 13:19:44 +0530 Subject: [PATCH 13/13] Revert "Revert "Fix: AXE-570 Fixed a11yEngineErrors being accessed on undefined"" --- lib/core/public/load.js | 5 ++++- lib/core/public/run-rules.js | 5 ++++- lib/core/utils/merge-results.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/public/load.js b/lib/core/public/load.js index e80d3d8f6..0d7e0caf4 100644 --- a/lib/core/public/load.js +++ b/lib/core/public/load.js @@ -42,7 +42,10 @@ function runCommand(data, keepalive, callback) { //a11y-engine iframe rules error merging logic const errors = a11yEngine.getErrors(); if (Object.keys(errors).length !== 0) { - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; const mergedErrors = mergeErrors(error, errors); diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index 8e04c13dc..9193d4373 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -67,7 +67,10 @@ export default function runRules(context, options, resolve, reject) { // after should only run once, so ensure we are in the top level window if (context.initiator) { // Return a11y-engine errors when at top level window - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; a11yEngine.mergeErrors(error); diff --git a/lib/core/utils/merge-results.js b/lib/core/utils/merge-results.js index 0e6277132..79aa935b1 100644 --- a/lib/core/utils/merge-results.js +++ b/lib/core/utils/merge-results.js @@ -86,7 +86,7 @@ function mergeResults(frameResults, options) { const frameSpec = getFrameSpec(frameResult); // Extract existing errors and merge with new ones - if (results[results.length - 1].a11yEngineErrors) { + if (results.length > 0 && results[results.length - 1]?.a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; mergedErrors = mergeErrors(mergedErrors, error, frameSpec);