Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-3.0.0' into AXE-570_a11y…
Browse files Browse the repository at this point in the history
…EngineErrors
  • Loading branch information
chikara1608 committed Oct 8, 2024
2 parents 6b98646 + 5cd4a1f commit 77cf978
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 13 deletions.
1 change: 1 addition & 0 deletions build/tasks/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function (grunt) {
entryPoints: [entry],
outfile: path.join(dest, name),
minify: false,
format: 'esm',
bundle: true
})
.then(done)
Expand Down
29 changes: 25 additions & 4 deletions lib/commons/dom/create-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ 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');
}
return constants.gridSize;
}
cache.set('gridCreated', true);
Expand Down Expand Up @@ -110,6 +114,11 @@ export default function createGrid(

node = treeWalker.nextNode();
}

// a11y-engine-domforge change
if (cache.get('gridSize')) {
return cache.get('gridSize');
}
return constants.gridSize;
}

Expand Down Expand Up @@ -430,6 +439,10 @@ class Grid {
* @returns {number}
*/
toGridIndex(num) {
// a11y-engine-domforge change
if (cache.get('gridSize')) {
return Math.floor(num / cache.get('gridSize'));
}
return Math.floor(num / constants.gridSize);
}

Expand All @@ -442,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') === 'resize-2x-zoom') {
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] ?? [];
}
Expand Down
14 changes: 12 additions & 2 deletions lib/commons/dom/get-element-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import createGrid from './create-grid';
* @param {Node} node
* @return {Node[]}
*/
function getElementStack(node) {

// Additional props isCoordsPassed, x, y for a11y-engine-domforge
function getElementStack(node, isCoordsPassed = false, x = null, y = null) {
createGrid();

const vNode = getNodeFromTree(node);
Expand All @@ -19,7 +21,15 @@ function getElementStack(node) {
return [];
}

return getRectStack(grid, vNode.boundingClientRect);
// Additional props isCoordsPassed, x, y for a11y-engine-domforge
return getRectStack(
grid,
vNode.boundingClientRect,
false,
isCoordsPassed,
x,
y
);
}

export default getElementStack;
16 changes: 14 additions & 2 deletions lib/commons/dom/get-overflow-hidden-ancestors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cache from '../../core/base/cache';
import memoize from '../../core/utils/memoize';

/**
Expand All @@ -17,8 +18,19 @@ const getOverflowHiddenAncestors = memoize(

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

if (overflow === 'hidden') {
ancestors.push(vNode);
// a11y-engine-domforge change
if (cache.get('ruleId') && cache.get('ruleId') === 'resize-2x-zoom') {
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));
Expand Down
21 changes: 18 additions & 3 deletions lib/commons/dom/get-rect-stack.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import visuallySort from './visually-sort';
import { getRectCenter } from '../math';

export function getRectStack(grid, rect, recursed = false) {
// Additional props isCoordsPassed, x, y for a11y-engine-domforge
export function getRectStack(
grid,
rect,
recursed = false,
isCoordsPassed = false,
x = null,
y = null
) {
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);

// a11y-engine-domforge change
if (isCoordsPassed) {
floorX = Math.floor(x);
floorY = Math.floor(y);
}

let stack = gridCell.filter(gridCellNode => {
return gridCellNode.clientRects.some(clientRect => {
const rectX = clientRect.left;
Expand Down
13 changes: 11 additions & 2 deletions lib/commons/dom/get-visible-child-text-rects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getNodeFromTree, memoize } from '../../core/utils';
import { sanitize } from '../text';
import { getRectCenter, isPointInRect, 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.
Expand All @@ -23,13 +24,21 @@ const getVisibleChildTextRects = memoize(
}

const contentRects = getContentRects(textNode);
if (isOutsideNodeBounds(contentRects, nodeRect)) {
if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) {
return;
}

clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
});

// a11y-engine-domforge change
if (
clientRects.length <= 0 &&
cache.get('ruleId') &&
cache.get('ruleId') === 'resize-2x-zoom'
) {
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
Expand Down

0 comments on commit 77cf978

Please sign in to comment.