Replace relative CSS URLs with their absolute counterpart

@param  {string} cssText
@param  {string} href    URL of the stylesheet
@return {string}
175430
function fixRelativeUrls(cssText, href) {
	var base = resolveRelativeUrl(href, document.baseURI);
	return cssText.replace(URL_VALUE_REGEXP, function(match, quote, url1, url2) {
		var url = url1 || url2;
		if (!url) {
			return match;
		}
		return 'url(' + (quote || '"') + resolveRelativeUrl(url, base) + (quote || '"') + ')';
	});
}
191914
function flatten(href) {
    href = normalize(href);
    if (href[0] == '/') {
        href = normalize(href.slice(1));
    }

    return href;
}
831308
function replace(styleUrls, options) {
  var styles = '';
  var urls = eval('({' + styleUrls + '}).styleUrls');
  if (urls) {
    urls.forEach(function (url, i) {
      var coma = i > 0 ? ', ' : '';
      styles += coma + getStylesString(url, options);
    });
  }


  var newLines = STYLES + ': [' + styles + ']';
  newLines += hasTraillingComa(styleUrls) ? ',' : '';
  return newLines;
}
405239
function (selectorText) {
            var rule, css, selector, cssRules = this.cssRules;
            if (selectorText) {
                rule = cssRules[selectorText];
                return rule ? rule.style.cssText : null;
            } else {
                css = [];
                for (selector in cssRules) {
                    rule = cssRules[selector];
                    css.push(rule.selectorText + ' {' + rule.style.cssText + '}');
                }
                return css.join('\n');
            }
        }
34206
function(destPath) {

    // Store all the css/js abspaths
    var cssAbspaths = [];
    var jsAbspaths = [];
    grunt.file.recurse(destPath, function(abspath, rootdir, subdir, filename) {
        if (abspath.match(/\.css$/i)) {
            cssAbspaths.push(abspath);
        } else if (abspath.match(/\.js$/i)) {
            jsAbspaths.push(abspath);
        }
    });

    var beginminInfos = applyminGlobal.beginminInfos;
    for (var templateFilename in beginminInfos) {
        var beginminInfo = beginminInfos[templateFilename];
        // Will be used to replace the html template later.
        var replaceContent = {};

        for (var targetFilePath in beginminInfo) {
            var targetUrlPath = beginminInfo[targetFilePath].targetUrlPath;
            var beginEndMinBlock = beginminInfo[targetFilePath].beginEndMinBlock;

            var abspaths = null;
            var isJsOrCss = true; /* true means Js, otherwise means Css. */
            if (targetFilePath.match(/\.css$/i)) {
                abspaths = cssAbspaths;
                isJsOrCss = false;
            } else if (targetFilePath.match(/\.js$/i)) {
                abspaths = jsAbspaths;
            }
            var revTargetFilePath = _getRevTargetFilePath(targetFilePath, abspaths);

            // Fill up replaceContent
            var targetUrlPath = targetUrlPath.replace(new RegExp(targetFilePath, 'i'), revTargetFilePath);
            if (isJsOrCss) {
                targetUrlPath = '<script src="' + targetUrlPath + '"></script>';
            } else {
                targetUrlPath = '<link href="' + targetUrlPath + '" rel="stylesheet" media="screen">';
            }
            replaceContent[targetUrlPath] = beginEndMinBlock;
        }
        var fileContent = grunt.file.read(templateFilename);
        for (var targetUrlPath in replaceContent) {
            var beginEndMinBlock = replaceContent[targetUrlPath];
            while (fileContent.indexOf(beginEndMinBlock) !== -1) { // replace all for string as the first parameter instead of regexp.
                grunt.log.writeln('Change:\n' + beginEndMinBlock);
                fileContent = fileContent.replace(beginEndMinBlock, targetUrlPath);
                grunt.log.writeln('To:\n' + targetUrlPath);
                grunt.log.writeln();
            }
        }
        grunt.file.write(templateFilename, fileContent);
        grunt.log.write('The file named: ' + templateFilename + ' has been changed...').ok();
    }
  }
283417
function getStylesheetsFromDocumentFragment(options) {
	const { rootNode, convertDataToStylesheet } = options;
	return (
		Array.from(rootNode.children)
			.filter(filerStyleAndLinkAttributesInDocumentFragment)
			// Reducer to convert `<style></style>` and `<link>` references to `CSSStyleSheet` object
			.reduce((out, node) => {
				const nodeName = node.nodeName.toUpperCase();
				const data = nodeName === 'STYLE' ? node.textContent : node;
				const isLink = nodeName === 'LINK';
				const stylesheet = convertDataToStylesheet({
					data,
					isLink,
					root: rootNode
				});
				out.push(stylesheet.sheet);
				return out;
			}, [])
	);
}
1247101
function(text, base, map) {
    var matches = this.loader.extractUrls(text, base);
    var match, url, intermediate;
    for (var i = 0; i < matches.length; i++) {
      match = matches[i];
      url = match.url;
      // resolve any css text to be relative to the importer, keep absolute url
      intermediate = urlResolver.resolveCssText(map[url], url, true);
      // flatten intermediate @imports
      intermediate = this.flatten(intermediate, base, map);
      text = text.replace(match.matched, intermediate);
    }
    return text;
  }
595048
function(urls) {
		var self = this;
		if (typeof urls === 'string') {
			urls = [ urls ];
		}
		$.each(urls, function(i, url) {
			url = self.convAbsUrl(url).replace(/^https?:/i, '');
			if (! $("head > link[href='+url+']").length) {
				$('head').append('<link rel="stylesheet" type="text/css" href="' + url + '" />');
			}
		});
		return this;
	}
1272623
public static function css($href, array $attrs = [])
    {
        $attrs = array_merge([
            'type' => 'text/css',
            'rel' => 'stylesheet',
            'href' => $href,
        ],
            $attrs);

        return static::tag('link', null, $attrs);
    }
402087
@VisibleForTesting
  static String embedCssIntoHtml(String css) {
    // `</style` can close a containing style element in HTML.
    // `]]>` can similarly close a CDATA element in XHTML.

    // Scan for "</" and "]]>" and escape enough to remove the token seen by
    // the HTML parser.

    // For well-formed CSS, these string might validly appear in a few contexts:
    // 1. comments
    // 2. string bodies
    // 3. url(...) bodies.

    // Appending \ should be semantics preserving in comments and string bodies.
    // This may not be semantics preserving in url content.
    // The substring "]>" can validly appear in a selector
    //   a[href]>b
    // but the substring "]]>" cannot.

    // This should not affect how a CSS parser recovers from syntax errors.
    int indexOfEndTag = css.indexOf("</");
    int indexOfEndCData = css.indexOf("]]>");
    if (indexOfEndTag != -1) {
      if (indexOfEndCData != -1) {
        return embedCssIntoHtmlSlow(
            css,
            Math.min(indexOfEndTag, indexOfEndCData),
            /* searchForEndCData= */ true,
            /* searchForEndTag= */ true);
      }
      return embedCssIntoHtmlSlow(
          css, indexOfEndTag, /* searchForEndCData= */ false, /* searchForEndTag= */ true);
    } else if (indexOfEndCData != -1) {
      return embedCssIntoHtmlSlow(
          css, indexOfEndCData, /* searchForEndCData= */ true, /* searchForEndTag= */ false);
    }
    return css;
  }
1073615
public function replaceExternalCss($html, array $stylesheets)
    {
        foreach ($stylesheets['links'] as $key => $stylesheet) {
            $newTag = str_replace(
                $stylesheets['actual_links'][$key],
                $stylesheet,
                $stylesheets['tags'][$key]
            );

            $html = str_replace($stylesheets['tags'][$key], $newTag, $html);
        }

        return $html;
    }
120808
function CSSLoader(loadItem, preferXHR) {
		this.AbstractLoader_constructor(loadItem, preferXHR, createjs.AbstractLoader.CSS);

		// public properties
		this.resultFormatter = this._formatResult;

		// protected properties
		this._tagSrcAttribute = "href";

		if (preferXHR) {
			this._tag = document.createElement("style");
		} else {
			this._tag = document.createElement("link");
		}

		this._tag.rel = "stylesheet";
		this._tag.type = "text/css";
	}
1262402
function generateStylesheet(stylesheet) {
			o.relativeFontPath = normalizePath(o.relativeFontPath);

			// Generate font URLs to use in @font-face
			var fontSrcs = [[], []];
			o.order.forEach(function(type) {
				if (!has(o.types, type)) return;
				wf.fontsSrcsMap[type].forEach(function(font, idx) {
					if (font) {
						fontSrcs[idx].push(generateFontSrc(type, font, stylesheet));
					}
				});
			});

			// Convert urls to strings that could be used in CSS
			var fontSrcSeparator = option(wf.fontSrcSeparators, stylesheet);
			fontSrcs.forEach(function(font, idx) {
				// o.fontSrc1, o.fontSrc2
				o['fontSrc'+(idx+1)] = font.join(fontSrcSeparator);
			});
			o.fontRawSrcs = fontSrcs;

			// Read JSON file corresponding to CSS template
			var templateJson = readTemplate(o.template, o.syntax, '.json', true);
			if (templateJson) o = _.extend(o, JSON.parse(templateJson.template));

			// Now override values with templateOptions
			if (o.templateOptions) o = _.extend(o, o.templateOptions);

			// Generate CSS
			var ext = path.extname(o.template) || '.css';  // Use extension of o.template file if given, or default to .css
			o.cssTemplate = readTemplate(o.template, o.syntax, ext);
			var cssContext = _.extend(o, {
				iconsStyles: true,
				stylesheet: stylesheet
			});

			var css = renderTemplate(o.cssTemplate, cssContext);

			// Fix CSS preprocessors comments: single line comments will be removed after compilation
			if (has(['sass', 'scss', 'less', 'styl'], stylesheet)) {
				css = css.replace(/\/\* *(.*?) *\*\//g, '// $1');
			}

			// Save file
			fs.writeFileSync(getCssFilePath(stylesheet), css);
		}
632835
function getCSSText(className) {
			if (typeof document.styleSheets != "object") return "";
			if (document.styleSheets.length <= 0) return "";
			var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
			for (var x = 0; x < classes.length; x++) {
				if (classes[x].selectorText == "." + className || classes[x].selectorText == "#" + className) {
					return ((classes[x].cssText) ? (classes[x].cssText) : (classes[x].style.cssText));
				}
			}
			return "";
		}
815252
function url(s) {
  // http://www.w3.org/TR/css3-values/#uris
  // Parentheses, commas, whitespace characters, single quotes (') and double
  // quotes (") appearing in a URI must be escaped with a backslash
  var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1');
  // WebKit has a bug when it comes to URLs that end with \
  // https://bugs.webkit.org/show_bug.cgi?id=28885
  if (/\\\\$/.test(s2)) {
    // Add a space to work around the WebKit bug.
    s2 += ' ';
  }
  return 'url("' + s2 + '")';
}
951487
function styleForURL(url) {
        var styleSheetId, styles = {};
        url = _canonicalize(url);
        for (styleSheetId in _styleSheetDetails) {
            if (_styleSheetDetails[styleSheetId].canonicalizedURL === url) {
                styles[styleSheetId] = _styleSheetDetails[styleSheetId];
            }
        }
        return styles;
    }
1263133
function cssFilesToStyleTag(dom) {
    const rootDir = `${__dirname}/`;

    const styles = m('div', {}, cssFiles.map(file => m('link', { rel: 'stylesheet', href: rootDir + file })));

    m.render(dom, styles);
  }