Sha256: e2f176d8c1505d87cfcfe4494c2b778187bea0ddb9c41e6b4bdd8e30e55f30e0

Contents?: true

Size: 1.28 KB

Versions: 114

Compression:

Stored size: 1.28 KB

Contents

/* global axe, dom */
/**
 * Get elements from point across shadow dom boundaries
 * @method shadowElementsFromPoint
 * @memberof axe.commons.dom
 * @instance
 * @param {Number} nodeX X coordinates of point
 * @param {Number} nodeY Y coordinates of point
 * @param {Object} [root] Shadow root or document root
 * @return {Array}
 */
dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document, i = 0) {
	if (i > 999) {
		throw new Error('Infinite loop detected');
	}
	return (
		Array.from(root.elementsFromPoint(nodeX, nodeY))
			// As of Chrome 66, elementFromPoint will return elements from parent trees.
			// We only want to touch each tree once, so we're filtering out nodes on other trees.
			.filter(nodes => dom.getRootNode(nodes) === root)
			.reduce((stack, elm) => {
				if (axe.utils.isShadowRoot(elm)) {
					const shadowStack = dom.shadowElementsFromPoint(
						nodeX,
						nodeY,
						elm.shadowRoot,
						i + 1
					);
					stack = stack.concat(shadowStack);
					// filter host nodes which get included regardless of overlap
					// TODO: refactor multiline overlap checking inside shadow dom
					if (stack.length && axe.commons.dom.visuallyContains(stack[0], elm)) {
						stack.push(elm);
					}
				} else {
					stack.push(elm);
				}
				return stack;
			}, [])
	);
};

Version data entries

114 entries across 114 versions & 1 rubygems

Version Path
govuk_publishing_components-21.22.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.21.3 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.21.2 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.21.1 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.21.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.20.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.19.1 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.19.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.18.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.17.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js
govuk_publishing_components-21.13.4 node_modules/axe-core/lib/commons/dom/shadow-elements-from-point.js