canonicalize method
Future<AsyncCanonicalizeResult?>
canonicalize(
- Uri url, {
- AsyncImporter? baseImporter,
- Uri? baseUrl,
- bool forImport = false,
Canonicalizes url
according to one of this cache's importers.
The baseUrl
should be the canonical URL of the stylesheet that contains
the load, if it exists.
Returns the importer that was used to canonicalize url
, the canonical
URL, and the URL that was passed to the importer (which may be resolved
relative to baseUrl
if it's passed).
If baseImporter
is non-null
, this first tries to use baseImporter
to
canonicalize url
(resolved relative to baseUrl
if it's passed).
If any importers understand url
, returns that importer as well as the
canonicalized URL and the original URL (resolved relative to baseUrl
if
applicable). Otherwise, returns null
.
Implementation
Future<AsyncCanonicalizeResult?> canonicalize(Uri url,
{AsyncImporter? baseImporter,
Uri? baseUrl,
bool forImport = false}) async {
if (isBrowser &&
(baseImporter == null || baseImporter is NoOpImporter) &&
_importers.isEmpty) {
throw "Custom importers are required to load stylesheets when compiling "
"in the browser.";
}
if (baseImporter != null && url.scheme == '') {
var relativeResult = await putIfAbsentAsync(
_relativeCanonicalizeCache,
(
url,
forImport: forImport,
baseImporter: baseImporter,
baseUrl: baseUrl
),
() => _canonicalize(baseImporter, baseUrl?.resolveUri(url) ?? url,
baseUrl, forImport));
if (relativeResult != null) return relativeResult;
}
return await putIfAbsentAsync(
_canonicalizeCache, (url, forImport: forImport), () async {
for (var importer in _importers) {
if (await _canonicalize(importer, url, baseUrl, forImport)
case var result?) {
return result;
}
}
return null;
});
}