(css: string)
| 139 | } |
| 140 | |
| 141 | function cssToRuntime(css: string) { |
| 142 | if (!css) { |
| 143 | return {}; |
| 144 | } |
| 145 | const runtime: { |
| 146 | extra?: string[]; |
| 147 | default?: Record<string, string>; |
| 148 | } = {}; |
| 149 | const groups = groupingCss(css); |
| 150 | groups.forEach((cssItem) => { |
| 151 | if (!cssItem.startsWith(':root')) { |
| 152 | runtime.extra = runtime.extra || []; |
| 153 | runtime.extra.push(cssItem.trim()); |
| 154 | } else { |
| 155 | const res = /:root:?(.*)?{(.*)/ig.exec(cssItem.replace(/[\r\n]+/ig, '').trim()); |
| 156 | if (res) { |
| 157 | let pseudo: string | undefined; |
| 158 | |
| 159 | if (res[1] && res[1].trim() && some(pseudoMap, pse => res[1].indexOf(pse) === 0)) { |
| 160 | pseudo = res[1].trim(); |
| 161 | } else if (res[1] && res[1].trim()) { |
| 162 | pseudo = res[1]; |
| 163 | } |
| 164 | |
| 165 | const s: Record<string, string> = {}; |
| 166 | res[2].split(';').reduce<string[]>((prev, next) => { |
| 167 | if (next.indexOf('base64') > -1) { |
| 168 | prev[prev.length - 1] += `;${next}`; |
| 169 | } else { |
| 170 | prev.push(next); |
| 171 | } |
| 172 | return prev; |
| 173 | }, []).forEach((item) => { |
| 174 | if (item) { |
| 175 | if (PROPS_REG.test(item)) { |
| 176 | const props = item.match(PROPS_REG); |
| 177 | const key = props?.[1]; |
| 178 | const value = props?.[2]; |
| 179 | if (key && value) { |
| 180 | s[key.trim()] = value.trim(); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | }); |
| 185 | |
| 186 | runtime[pseudo || 'default'] = s; |
| 187 | } |
| 188 | } |
| 189 | }); |
| 190 | return runtime; |
| 191 | } |
| 192 | |
| 193 | function cssToStyle(css) { |
| 194 | try { |
no test coverage detected
searching dependent graphs…