Sha256: 9de35e08d6aacc54c21acae711210e4de6ce8e32dde29e6fd7e05475bc785448

Contents?: true

Size: 1.55 KB

Versions: 271

Compression:

Stored size: 1.55 KB

Contents

/* global axe, color */

function getOpacity(node) {
	if (!node) {
		return 1;
	}

	const vNode = axe.utils.getNodeFromTree(node);

	if (vNode && vNode._opacity !== undefined && vNode._opacity !== null) {
		return vNode._opacity;
	}

	const nodeStyle = window.getComputedStyle(node);
	const opacity = nodeStyle.getPropertyValue('opacity');
	const finalOpacity = opacity * getOpacity(node.parentElement);

	// cache the results of the getOpacity check on the parent tree
	// so we don't have to look at the parent tree again for all its
	// descendants
	if (vNode) {
		vNode._opacity = finalOpacity;
	}

	return finalOpacity;
}

/**
 * Returns the flattened foreground color of an element, or null if it can't be determined because
 * of transparency
 * @method getForegroundColor
 * @memberof axe.commons.color
 * @instance
 * @param {Element} node
 * @param {Boolean} noScroll (default false)
 * @param {Color} bgColor
 * @return {Color|null}
 */
color.getForegroundColor = function(node, noScroll, bgColor) {
	const nodeStyle = window.getComputedStyle(node);

	const fgColor = new color.Color();
	fgColor.parseRgbString(nodeStyle.getPropertyValue('color'));
	const opacity = getOpacity(node);
	fgColor.alpha = fgColor.alpha * opacity;
	if (fgColor.alpha === 1) {
		return fgColor;
	}

	if (!bgColor) {
		bgColor = color.getBackgroundColor(node, [], noScroll);
	}

	if (bgColor === null) {
		const reason = axe.commons.color.incompleteData.get('bgColor');
		axe.commons.color.incompleteData.set('fgColor', reason);
		return null;
	}

	return color.flattenColors(fgColor, bgColor);
};

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/color/get-foreground-color.js