1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/compiler/src/style_url_resolver", ["require", "exports"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.extractStyleUrls = exports.isStyleUrlResolvable = exports.StyleWithImports = void 0;
|
---|
20 | var StyleWithImports = /** @class */ (function () {
|
---|
21 | function StyleWithImports(style, styleUrls) {
|
---|
22 | this.style = style;
|
---|
23 | this.styleUrls = styleUrls;
|
---|
24 | }
|
---|
25 | return StyleWithImports;
|
---|
26 | }());
|
---|
27 | exports.StyleWithImports = StyleWithImports;
|
---|
28 | function isStyleUrlResolvable(url) {
|
---|
29 | if (url == null || url.length === 0 || url[0] == '/')
|
---|
30 | return false;
|
---|
31 | var schemeMatch = url.match(URL_WITH_SCHEMA_REGEXP);
|
---|
32 | return schemeMatch === null || schemeMatch[1] == 'package' || schemeMatch[1] == 'asset';
|
---|
33 | }
|
---|
34 | exports.isStyleUrlResolvable = isStyleUrlResolvable;
|
---|
35 | /**
|
---|
36 | * Rewrites stylesheets by resolving and removing the @import urls that
|
---|
37 | * are either relative or don't have a `package:` scheme
|
---|
38 | */
|
---|
39 | function extractStyleUrls(resolver, baseUrl, cssText) {
|
---|
40 | var foundUrls = [];
|
---|
41 | var modifiedCssText = cssText.replace(CSS_STRIPPABLE_COMMENT_REGEXP, '')
|
---|
42 | .replace(CSS_IMPORT_REGEXP, function () {
|
---|
43 | var m = [];
|
---|
44 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
45 | m[_i] = arguments[_i];
|
---|
46 | }
|
---|
47 | var url = m[1] || m[2];
|
---|
48 | if (!isStyleUrlResolvable(url)) {
|
---|
49 | // Do not attempt to resolve non-package absolute URLs with URI
|
---|
50 | // scheme
|
---|
51 | return m[0];
|
---|
52 | }
|
---|
53 | foundUrls.push(resolver.resolve(baseUrl, url));
|
---|
54 | return '';
|
---|
55 | });
|
---|
56 | return new StyleWithImports(modifiedCssText, foundUrls);
|
---|
57 | }
|
---|
58 | exports.extractStyleUrls = extractStyleUrls;
|
---|
59 | var CSS_IMPORT_REGEXP = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
|
---|
60 | var CSS_STRIPPABLE_COMMENT_REGEXP = /\/\*(?!#\s*(?:sourceURL|sourceMappingURL)=)[\s\S]+?\*\//g;
|
---|
61 | var URL_WITH_SCHEMA_REGEXP = /^([^:/?#]+):/;
|
---|
62 | });
|
---|
63 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3R5bGVfdXJsX3Jlc29sdmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29tcGlsZXIvc3JjL3N0eWxlX3VybF9yZXNvbHZlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7SUFPSDtRQUNFLDBCQUFtQixLQUFhLEVBQVMsU0FBbUI7WUFBekMsVUFBSyxHQUFMLEtBQUssQ0FBUTtZQUFTLGNBQVMsR0FBVCxTQUFTLENBQVU7UUFBRyxDQUFDO1FBQ2xFLHVCQUFDO0lBQUQsQ0FBQyxBQUZELElBRUM7SUFGWSw0Q0FBZ0I7SUFJN0IsU0FBZ0Isb0JBQW9CLENBQUMsR0FBVztRQUM5QyxJQUFJLEdBQ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AgICAgICAvLyBEbyBub3QgYXR0ZW1wdCB0byByZXNvbHZlIG5vbi1wYWNrYWdlIGFic29sdXRlIFVSTHMgd2l0aCBVUklcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBzY2hlbWVcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbVswXTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3VuZFVybHMucHVzaChyZXNvbHZlci5yZXNvbHZlKGJhc2VVcmwsIHVybCkpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gJyc7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTtcbiAgcmV0dXJuIG5ldyBTdHlsZVdpdGhJbXBvcnRzKG1vZGlmaWVkQ3NzVGV4dCwgZm91bmRVcmxzKTtcbn1cblxuY29uc3QgQ1NTX0lNUE9SVF9SRUdFWFAgPSAvQGltcG9ydFxccysoPzp1cmxcXCgpP1xccyooPzooPzpbJ1wiXShbXidcIl0qKSl8KFteO1xcKVxcc10qKSlbXjtdKjs/L2c7XG5jb25zdCBDU1NfU1RSSVBQQUJMRV9DT01NRU5UX1JFR0VYUCA9IC9cXC9cXCooPyEjXFxzKig/OnNvdXJjZVVSTHxzb3VyY2VNYXBwaW5nVVJMKT0pW1xcc1xcU10rP1xcKlxcLy9nO1xuY29uc3QgVVJMX1dJVEhfU0NIRU1BX1JFR0VYUCA9IC9eKFteOi8/I10rKTovO1xuIl19 |
---|