1 | /**
|
2 | @license
|
3 | Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
|
4 | This code may only be used under the BSD style license found at
|
5 | http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
|
6 | http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
|
7 | found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
|
8 | part of the polymer project is also subject to an additional IP rights grant
|
9 | found at http://polymer.github.io/PATENTS.txt
|
10 | */
|
11 | export const supportsAdoptingStyleSheets = ('adoptedStyleSheets' in Document.prototype);
|
12 | export 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 | }
|
31 | const 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 | };
|
39 | export 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 |