* parseCSS takes in raw CSS and parses it to valid CSS using Stylis. * It's useful for handling complex CSS such as media queries and pseudo selectors.
(style: string)
| 233 | * It's useful for handling complex CSS such as media queries and pseudo selectors. |
| 234 | */ |
| 235 | parseCSS(style: string): string { |
| 236 | style = this._processCSS(style); |
| 237 | |
| 238 | const globalOperators = new Set(extractOperators(":global", style)); |
| 239 | const id = Sheet.getClassNamePrefix() + generateHash(style); |
| 240 | const breakpoints = theme.getUserTheme().breakpoints ?? {}; |
| 241 | const elements: Element[] = []; |
| 242 | |
| 243 | compile(`.${id}{${style}}`).forEach((element) => { |
| 244 | this.normalizeMediaQueries(element, breakpoints); |
| 245 | |
| 246 | if (this.normalizeGlobalOperatorSelectors(element, id, globalOperators)) { |
| 247 | elements.push(element); |
| 248 | } |
| 249 | }); |
| 250 | |
| 251 | const css = serialize(elements, stringify); |
| 252 | |
| 253 | this.css.push(css); |
| 254 | return id; |
| 255 | } |
| 256 | |
| 257 | removeDuplicates() { |
| 258 | this.base = [...new Set(this.base)]; |
no test coverage detected