import method

Future<(AsyncImporter, Stylesheet)?> import(
  1. Uri url, {
  2. AsyncImporter? baseImporter,
  3. Uri? baseUrl,
  4. bool forImport = false,
})

Tries to import url using one of this cache's importers.

If baseImporter is non-null, this first tries to use baseImporter to import url (resolved relative to baseUrl if it's passed).

If any importers can import url, returns that importer as well as the parsed stylesheet. Otherwise, returns null.

Caches the result of the import and uses cached results if possible.

Implementation

Future<(AsyncImporter, Stylesheet)?> import(Uri url,
    {AsyncImporter? baseImporter,
    Uri? baseUrl,
    bool forImport = false}) async {
  if (await canonicalize(url,
          baseImporter: baseImporter, baseUrl: baseUrl, forImport: forImport)
      case (var importer, var canonicalUrl, :var originalUrl)) {
    return (await importCanonical(importer, canonicalUrl,
            originalUrl: originalUrl))
        .andThen((stylesheet) => (importer, stylesheet));
  } else {
    return null;
  }
}