A CSS style rule.
| 866 | |
| 867 | /** A CSS style rule. */ |
| 868 | class StyleRule implements Rule { |
| 869 | className: string; |
| 870 | pseudos: string; |
| 871 | property: string; |
| 872 | value: string; |
| 873 | themeProperty: string | undefined; |
| 874 | themeValue: Value | undefined; |
| 875 | |
| 876 | constructor( |
| 877 | className: string, |
| 878 | property: string, |
| 879 | value: string, |
| 880 | themeProperty: string | undefined, |
| 881 | themeValue: Value | undefined |
| 882 | ) { |
| 883 | this.className = className; |
| 884 | this.pseudos = ''; |
| 885 | this.property = property; |
| 886 | this.value = value; |
| 887 | if (process.env.NODE_ENV !== 'production' && isCompilingDependencies !== null) { |
| 888 | this.themeProperty = themeProperty; |
| 889 | this.themeValue = themeValue; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | copy(): Rule { |
| 894 | let rule = new StyleRule( |
| 895 | this.className, |
| 896 | this.property, |
| 897 | this.value, |
| 898 | this.themeProperty, |
| 899 | this.themeValue |
| 900 | ); |
| 901 | rule.pseudos = this.pseudos; |
| 902 | return rule; |
| 903 | } |
| 904 | |
| 905 | addPseudo(prelude: string) { |
| 906 | this.pseudos += prelude; |
| 907 | } |
| 908 | |
| 909 | getStaticClassName(): string { |
| 910 | return ' ' + this.className; |
| 911 | } |
| 912 | |
| 913 | toCSS(rulesByLayer: Map<string, string[]>, preludes: string[] = [], layer = 'a') { |
| 914 | let prelude = `.${this.className}${this.pseudos}`; |
| 915 | preludes.push(prelude); |
| 916 | |
| 917 | // Nest rule in our stack of preludes (e.g. media queries/selectors). |
| 918 | let content = ' '; |
| 919 | preludes.forEach((p, i) => { |
| 920 | content += `${p} {\n${' '.repeat((i + 2) * 2)}`; |
| 921 | }); |
| 922 | content += `${kebab(this.property)}: ${this.value};\n`; |
| 923 | preludes.map((_, i) => { |
| 924 | content += `${' '.repeat((preludes.length - i) * 2)}}\n`; |
| 925 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected