UNPKG

1.78 kBJavaScriptView Raw
1/**
2@license
3Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at
5http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
6http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
7found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
8part of the polymer project is also subject to an additional IP rights grant
9found at http://polymer.github.io/PATENTS.txt
10*/
11export const supportsAdoptingStyleSheets = ('adoptedStyleSheets' in Document.prototype);
12export class CSSResult {
13 constructor(cssText) { this.cssText = cssText; }
14 // Note, this is a getter so that it's lazy. In practice, this means
15 // stylesheets are not created until the first element instance is made.
16 get styleSheet() {
17 if (this._styleSheet === undefined) {
18 // Note, if `adoptedStyleSheets` is supported then we assume CSSStyleSheet
19 // is constructable.
20 if (supportsAdoptingStyleSheets) {
21 this._styleSheet = new CSSStyleSheet();
22 this._styleSheet.replaceSync(this.cssText);
23 }
24 else {
25 this._styleSheet = null;
26 }
27 }
28 return this._styleSheet;
29 }
30}
31const textFromCSSResult = (value) => {
32 if (value instanceof CSSResult) {
33 return value.cssText;
34 }
35 else {
36 throw new Error(`Value passed to 'css' function must be a 'css' function result: ${value}.`);
37 }
38};
39export const css = (strings, ...values) => {
40 const cssText = values.reduce((acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1], strings[0]);
41 return new CSSResult(cssText);
42};
43//# sourceMappingURL=css-tag.js.map
\No newline at end of file