Sha256: 58cc9fc7879267927e94a608725fb1749c2b0fad2151c14002ea67a0db5281c5

Contents?: true

Size: 1.76 KB

Versions: 271

Compression:

Stored size: 1.76 KB

Contents

/**
 * Function which converts given text to `CSSStyleSheet`
 * - used in `CSSOM` computation.
 * - factory (closure) function, initialized with `document.implementation.createHTMLDocument()`, which uses DOM API for creating `style` elements.
 *
 * @method axe.utils.getStyleSheetFactory
 * @memberof axe.utils
 * @param {Object} dynamicDoc `document.implementation.createHTMLDocument()
 * @param {Object} options an object with properties to construct stylesheet
 * @property {String} options.data text content of the stylesheet
 * @property {Boolean} options.isCrossOrigin flag to notify if the resource was fetched from the network
 * @property {String} options.shadowId (Optional) shadowId if shadowDOM
 * @property {Object} options.root implementation document to create style elements
 * @property {String} options.priority a number indicating the loaded priority of CSS, to denote specificity of styles contained in the sheet.
 * @returns {Function}
 */
axe.utils.getStyleSheetFactory = function getStyleSheetFactory(dynamicDoc) {
	if (!dynamicDoc) {
		throw new Error(
			'axe.utils.getStyleSheetFactory should be invoked with an argument'
		);
	}

	return options => {
		const {
			data,
			isCrossOrigin = false,
			shadowId,
			root,
			priority,
			isLink = false
		} = options;
		const style = dynamicDoc.createElement('style');
		if (isLink) {
			// as creating a stylesheet as link will need to be awaited
			// till `onload`, it is wise to convert link href to @import statement
			const text = dynamicDoc.createTextNode(`@import "${data.href}"`);
			style.appendChild(text);
		} else {
			style.appendChild(dynamicDoc.createTextNode(data));
		}
		dynamicDoc.head.appendChild(style);
		return {
			sheet: style.sheet,
			isCrossOrigin,
			shadowId,
			root,
			priority
		};
	};
};

Version data entries

271 entries across 271 versions & 1 rubygems

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