Skip to content

Commit 60ba8d8

Browse files
authored
Merge pull request #98 from browserstack/release-3.0.0
Release 3.0.0
2 parents 2f4fb72 + 822d241 commit 60ba8d8

File tree

9 files changed

+90
-16
lines changed

9 files changed

+90
-16
lines changed

build/tasks/esbuild.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = function (grunt) {
2323
entryPoints: [entry],
2424
outfile: path.join(dest, name),
2525
minify: false,
26+
format: 'esm',
2627
bundle: true
2728
})
2829
.then(done)

lib/commons/dom/create-grid.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export default function createGrid(
2727
) {
2828
// Prevent multiple calls per run
2929
if (cache.get('gridCreated') && !parentVNode) {
30+
// a11y-engine-domforge change
31+
if (cache.get('gridSize')) {
32+
return cache.get('gridSize');
33+
}
3034
return constants.gridSize;
3135
}
3236
cache.set('gridCreated', true);
@@ -110,6 +114,11 @@ export default function createGrid(
110114

111115
node = treeWalker.nextNode();
112116
}
117+
118+
// a11y-engine-domforge change
119+
if (cache.get('gridSize')) {
120+
return cache.get('gridSize');
121+
}
113122
return constants.gridSize;
114123
}
115124

@@ -430,6 +439,10 @@ class Grid {
430439
* @returns {number}
431440
*/
432441
toGridIndex(num) {
442+
// a11y-engine-domforge change
443+
if (cache.get('gridSize')) {
444+
return Math.floor(num / cache.get('gridSize'));
445+
}
433446
return Math.floor(num / constants.gridSize);
434447
}
435448

@@ -442,10 +455,18 @@ class Grid {
442455
assert(this.boundaries, 'Grid does not have cells added');
443456
const rowIndex = this.toGridIndex(y);
444457
const colIndex = this.toGridIndex(x);
445-
assert(
446-
isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries),
447-
'Element midpoint exceeds the grid bounds'
448-
);
458+
459+
// a11y-engine-domforge change
460+
if (cache.get('ruleId') === 'resize-2x-zoom') {
461+
if (!isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries)) {
462+
return [];
463+
}
464+
} else {
465+
assert(
466+
isPointInRect({ y: rowIndex, x: colIndex }, this.boundaries),
467+
'Element midpoint exceeds the grid bounds'
468+
);
469+
}
449470
const row = this.cells[rowIndex - this.cells._negativeIndex] ?? [];
450471
return row[colIndex - row._negativeIndex] ?? [];
451472
}

lib/commons/dom/get-element-stack.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import createGrid from './create-grid';
99
* @param {Node} node
1010
* @return {Node[]}
1111
*/
12-
function getElementStack(node) {
12+
13+
// Additional props isCoordsPassed, x, y for a11y-engine-domforge
14+
function getElementStack(node, isCoordsPassed = false, x = null, y = null) {
1315
createGrid();
1416

1517
const vNode = getNodeFromTree(node);
@@ -19,7 +21,15 @@ function getElementStack(node) {
1921
return [];
2022
}
2123

22-
return getRectStack(grid, vNode.boundingClientRect);
24+
// Additional props isCoordsPassed, x, y for a11y-engine-domforge
25+
return getRectStack(
26+
grid,
27+
vNode.boundingClientRect,
28+
false,
29+
isCoordsPassed,
30+
x,
31+
y
32+
);
2333
}
2434

2535
export default getElementStack;

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

Lines changed: 14 additions & 2 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,8 +18,19 @@ const getOverflowHiddenAncestors = memoize(
1718

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

20-
if (overflow === 'hidden') {
21-
ancestors.push(vNode);
21+
// a11y-engine-domforge change
22+
if (cache.get('ruleId') && cache.get('ruleId') === 'resize-2x-zoom') {
23+
if (
24+
overflow.includes('hidden') ||
25+
overflow.includes('clip') ||
26+
overflow.includes('scroll')
27+
) {
28+
ancestors.push(vNode);
29+
}
30+
} else {
31+
if (overflow.includes('hidden')) {
32+
ancestors.push(vNode);
33+
}
2234
}
2335

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

lib/commons/dom/get-rect-stack.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
import visuallySort from './visually-sort';
22
import { getRectCenter } from '../math';
33

4-
export function getRectStack(grid, rect, recursed = false) {
4+
// Additional props isCoordsPassed, x, y for a11y-engine-domforge
5+
export function getRectStack(
6+
grid,
7+
rect,
8+
recursed = false,
9+
isCoordsPassed = false,
10+
x = null,
11+
y = null
12+
) {
513
const center = getRectCenter(rect);
614
const gridCell = grid.getCellFromPoint(center) || [];
715

8-
const floorX = Math.floor(center.x);
9-
const floorY = Math.floor(center.y);
16+
let floorX = Math.floor(center.x);
17+
let floorY = Math.floor(center.y);
18+
19+
// a11y-engine-domforge change
20+
if (isCoordsPassed) {
21+
floorX = Math.floor(x);
22+
floorY = Math.floor(y);
23+
}
24+
1025
let stack = gridCell.filter(gridCellNode => {
1126
return gridCellNode.clientRects.some(clientRect => {
1227
const rectX = clientRect.left;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { getNodeFromTree, memoize } from '../../core/utils';
22
import { sanitize } from '../text';
3-
import { getRectCenter, isPointInRect, 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.
@@ -23,13 +24,21 @@ const getVisibleChildTextRects = memoize(
2324
}
2425

2526
const contentRects = getContentRects(textNode);
26-
if (isOutsideNodeBounds(contentRects, nodeRect)) {
27+
if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) {
2728
return;
2829
}
2930

3031
clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
3132
});
3233

34+
// a11y-engine-domforge change
35+
if (
36+
clientRects.length <= 0 &&
37+
cache.get('ruleId') &&
38+
cache.get('ruleId') === 'resize-2x-zoom'
39+
) {
40+
return [];
41+
}
3342
/**
3443
* if all text rects are larger than the bounds of the node,
3544
* or goes outside of the bounds of the node, we need to use

lib/core/public/load.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ function runCommand(data, keepalive, callback) {
4242
//a11y-engine iframe rules error merging logic
4343
const errors = a11yEngine.getErrors();
4444
if (Object.keys(errors).length !== 0) {
45-
if (results[results.length - 1].a11yEngineErrors) {
45+
if (
46+
results.length > 0 &&
47+
results[results.length - 1]?.a11yEngineErrors
48+
) {
4649
const error = results.pop();
4750
delete error.a11yEngineErrors;
4851
const mergedErrors = mergeErrors(error, errors);

lib/core/public/run-rules.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export default function runRules(context, options, resolve, reject) {
6767
// after should only run once, so ensure we are in the top level window
6868
if (context.initiator) {
6969
// Return a11y-engine errors when at top level window
70-
if (results[results.length - 1].a11yEngineErrors) {
70+
if (
71+
results.length > 0 &&
72+
results[results.length - 1]?.a11yEngineErrors
73+
) {
7174
const error = results.pop();
7275
delete error.a11yEngineErrors;
7376
a11yEngine.mergeErrors(error);

lib/core/utils/merge-results.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function mergeResults(frameResults, options) {
8686

8787
const frameSpec = getFrameSpec(frameResult);
8888
// Extract existing errors and merge with new ones
89-
if (results[results.length - 1].a11yEngineErrors) {
89+
if (results.length > 0 && results[results.length - 1]?.a11yEngineErrors) {
9090
const error = results.pop();
9191
delete error.a11yEngineErrors;
9292
mergedErrors = mergeErrors(mergedErrors, error, frameSpec);

0 commit comments

Comments
 (0)