Skip to content

Commit

Permalink
Merge pull request #98 from browserstack/release-3.0.0
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
ansh21 authored Oct 14, 2024
2 parents 2f4fb72 + 822d241 commit 60ba8d8
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 16 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
5 changes: 4 additions & 1 deletion lib/core/public/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion lib/core/public/run-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/merge-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60ba8d8

Please sign in to comment.