style_url_resolver.js
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export var StyleWithImports = (function () {
/**
* @param {?} style
* @param {?} styleUrls
*/
function StyleWithImports(style, styleUrls) {
this.style = style;
this.styleUrls = styleUrls;
}
return StyleWithImports;
}());
function StyleWithImports_tsickle_Closure_declarations() {
/** @type {?} */
StyleWithImports.prototype.style;
/** @type {?} */
StyleWithImports.prototype.styleUrls;
}
/**
* @param {?} url
* @return {?}
*/
export function isStyleUrlResolvable(url) {
if (url == null || url.length === 0 || url[0] == '/')
return false;
var /** @type {?} */ schemeMatch = url.match(URL_WITH_SCHEMA_REGEXP);
return schemeMatch === null || schemeMatch[1] == 'package' || schemeMatch[1] == 'asset';
}
/**
* Rewrites stylesheets by resolving and removing the \@import urls that
* are either relative or don't have a `package:` scheme
* @param {?} resolver
* @param {?} baseUrl
* @param {?} cssText
* @return {?}
*/
export function extractStyleUrls(resolver, baseUrl, cssText) {
var /** @type {?} */ foundUrls = [];
var /** @type {?} */ modifiedCssText = cssText.replace(CSS_COMMENT_REGEXP, '').replace(CSS_IMPORT_REGEXP, function () {
var m = [];
for (var _i = 0; _i < arguments.length; _i++) {
m[_i - 0] = arguments[_i];
}
var /** @type {?} */ url = m[1] || m[2];
if (!isStyleUrlResolvable(url)) {
// Do not attempt to resolve non-package absolute URLs with URI scheme
return m[0];
}
foundUrls.push(resolver.resolve(baseUrl, url));
return '';
});
return new StyleWithImports(modifiedCssText, foundUrls);
}
var /** @type {?} */ CSS_IMPORT_REGEXP = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
var /** @type {?} */ CSS_COMMENT_REGEXP = /\/\*.+?\*\//g;
var /** @type {?} */ URL_WITH_SCHEMA_REGEXP = /^([^:/?#]+):/;
//# sourceMappingURL=style_url_resolver.js.map