extractStyleUrls function

StyleWithImports extractStyleUrls(
  1. String baseUrl,
  2. String cssText
)

Rewrites style sheets by resolving and removing the @import urls that are either relative or don't have a package: scheme

Implementation

StyleWithImports extractStyleUrls(String baseUrl, String cssText) {
  Uri? baseUri;
  var foundUrls = <String>[];
  var modifiedCssText = cssText.replaceAllMapped(_cssImportRe, (m) {
    var url = m[1] ?? m[2];
    if (!isStyleUrlResolvable(url)) {
      // Do not attempt to resolve non-package absolute URLs with URI scheme
      return m[0]!;
    }
    baseUri ??= Uri.parse(baseUrl);
    foundUrls.add(baseUri!.resolve(url!).toString());
    return '';
  });
  return StyleWithImports(modifiedCssText, foundUrls);
}