[6a3a178] | 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 | import { CompileStylesheetMetadata } from './compile_metadata';
|
---|
| 9 | import { ViewEncapsulation } from './core';
|
---|
| 10 | import * as o from './output/output_ast';
|
---|
| 11 | import { identifierModuleUrl, identifierName } from './parse_util';
|
---|
| 12 | import { ShadowCss } from './shadow_css';
|
---|
| 13 | const COMPONENT_VARIABLE = '%COMP%';
|
---|
| 14 | export const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
|
---|
| 15 | export const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
|
---|
| 16 | export class StylesCompileDependency {
|
---|
| 17 | constructor(name, moduleUrl, setValue) {
|
---|
| 18 | this.name = name;
|
---|
| 19 | this.moduleUrl = moduleUrl;
|
---|
| 20 | this.setValue = setValue;
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 | export class CompiledStylesheet {
|
---|
| 24 | constructor(outputCtx, stylesVar, dependencies, isShimmed, meta) {
|
---|
| 25 | this.outputCtx = outputCtx;
|
---|
| 26 | this.stylesVar = stylesVar;
|
---|
| 27 | this.dependencies = dependencies;
|
---|
| 28 | this.isShimmed = isShimmed;
|
---|
| 29 | this.meta = meta;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | export class StyleCompiler {
|
---|
| 33 | constructor(_urlResolver) {
|
---|
| 34 | this._urlResolver = _urlResolver;
|
---|
| 35 | this._shadowCss = new ShadowCss();
|
---|
| 36 | }
|
---|
| 37 | compileComponent(outputCtx, comp) {
|
---|
| 38 | const template = comp.template;
|
---|
| 39 | return this._compileStyles(outputCtx, comp, new CompileStylesheetMetadata({
|
---|
| 40 | styles: template.styles,
|
---|
| 41 | styleUrls: template.styleUrls,
|
---|
| 42 | moduleUrl: identifierModuleUrl(comp.type)
|
---|
| 43 | }), this.needsStyleShim(comp), true);
|
---|
| 44 | }
|
---|
| 45 | compileStyles(outputCtx, comp, stylesheet, shim = this.needsStyleShim(comp)) {
|
---|
| 46 | return this._compileStyles(outputCtx, comp, stylesheet, shim, false);
|
---|
| 47 | }
|
---|
| 48 | needsStyleShim(comp) {
|
---|
| 49 | return comp.template.encapsulation === ViewEncapsulation.Emulated;
|
---|
| 50 | }
|
---|
| 51 | _compileStyles(outputCtx, comp, stylesheet, shim, isComponentStylesheet) {
|
---|
| 52 | const styleExpressions = stylesheet.styles.map(plainStyle => o.literal(this._shimIfNeeded(plainStyle, shim)));
|
---|
| 53 | const dependencies = [];
|
---|
| 54 | stylesheet.styleUrls.forEach((styleUrl) => {
|
---|
| 55 | const exprIndex = styleExpressions.length;
|
---|
| 56 | // Note: This placeholder will be filled later.
|
---|
| 57 | styleExpressions.push(null);
|
---|
| 58 | dependencies.push(new StylesCompileDependency(getStylesVarName(null), styleUrl, (value) => styleExpressions[exprIndex] = outputCtx.importExpr(value)));
|
---|
| 59 | });
|
---|
| 60 | // styles variable contains plain strings and arrays of other styles arrays (recursive),
|
---|
| 61 | // so we set its type to dynamic.
|
---|
| 62 | const stylesVar = getStylesVarName(isComponentStylesheet ? comp : null);
|
---|
| 63 | const stmt = o.variable(stylesVar)
|
---|
| 64 | .set(o.literalArr(styleExpressions, new o.ArrayType(o.DYNAMIC_TYPE, [o.TypeModifier.Const])))
|
---|
| 65 | .toDeclStmt(null, isComponentStylesheet ? [o.StmtModifier.Final] : [
|
---|
| 66 | o.StmtModifier.Final, o.StmtModifier.Exported
|
---|
| 67 | ]);
|
---|
| 68 | outputCtx.statements.push(stmt);
|
---|
| 69 | return new CompiledStylesheet(outputCtx, stylesVar, dependencies, shim, stylesheet);
|
---|
| 70 | }
|
---|
| 71 | _shimIfNeeded(style, shim) {
|
---|
| 72 | return shim ? this._shadowCss.shimCssText(style, CONTENT_ATTR, HOST_ATTR) : style;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | function getStylesVarName(component) {
|
---|
| 76 | let result = `styles`;
|
---|
| 77 | if (component) {
|
---|
| 78 | result += `_${identifierName(component.type)}`;
|
---|
| 79 | }
|
---|
| 80 | return result;
|
---|
| 81 | }
|
---|
| 82 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3R5bGVfY29tcGlsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21waWxlci9zcmMvc3R5bGVfY29tcGlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUEyQix5QkFBeUIsRUFBQyxNQUFNLG9CQUFvQixDQUFDO0FBRXZGLE9BQU8sRUFBQyxpQkFBaUIsRUFBQyxNQUFNLFFBQVEsQ0FBQztBQUN6QyxPQUFPLEtBQUssQ0FBQyxNQUFNLHFCQUFxQixDQUFDO0FBQ3pDLE9BQU8sRUFBQyxtQkFBbUIsRUFBRSxjQUFjLEVBQUMsTUFBTSxjQUFjLENBQUM7QUFDakUsT0FBTyxFQUFDLFNBQVMsRUFBQyxNQUFNLGNBQWMsQ0FBQztBQUd2QyxNQUFNLGtCQUFrQixHQUFHLFFBQVEsQ0FBQztBQUNwQyxNQUFNLENBQUMsTUFBTSxTQUFTLEdBQUcsV0FBVyxrQkFBa0IsRUFBRSxDQUFDO0FBQ3pELE1BQU0sQ0FBQyxNQUFNLFlBQVksR0FBRyxjQUFjLGtCQUFrQixFQUFFLENBQUM7QUFFL0QsTUFBTSxPQUFPLHVCQUF1QjtJQUNsQyxZQUNXLElBQVksRUFBUyxTQUFpQixFQUFTLFFBQThCO1FBQTdFLFNBQUksR0FBSixJQUFJLENBQVE7UUFBUyxjQUFTLEdBQVQsU0FBUyxDQUFRO1FBQVMsYUFBUSxHQUFSLFFBQVEs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