()
| 306 | const sheet = prepareSheet(); |
| 307 | |
| 308 | function buildStyleSheet() { |
| 309 | function createTarget(group: ReadyGroup, parent: CSSBuilder): CSSBuilder { |
| 310 | const {rule} = group; |
| 311 | if (isStyleRule(rule)) { |
| 312 | const {selectorText} = rule; |
| 313 | const index = parent.cssRules.length; |
| 314 | parent.insertRule(`${selectorText} {}`, index); |
| 315 | return parent.cssRules[index] as CSSBuilder; |
| 316 | } |
| 317 | if (isMediaRule(rule)) { |
| 318 | const {media} = rule; |
| 319 | const index = parent.cssRules.length; |
| 320 | parent.insertRule(`@media ${media.mediaText} {}`, index); |
| 321 | return parent.cssRules[index] as CSSBuilder; |
| 322 | } |
| 323 | if (isLayerRule(rule)) { |
| 324 | const {name} = rule; |
| 325 | const index = parent.cssRules.length; |
| 326 | parent.insertRule(`@layer ${name} {}`, index); |
| 327 | return parent.cssRules[index] as CSSBuilder; |
| 328 | } |
| 329 | return parent; |
| 330 | } |
| 331 | |
| 332 | function iterateReadyRules( |
| 333 | group: ReadyGroup, |
| 334 | target: CSSBuilder, |
| 335 | styleIterator: (s: ReadyStyleRule, t: CSSBuilder) => void, |
| 336 | ) { |
| 337 | group.rules.forEach((r) => { |
| 338 | if (r.isGroup) { |
| 339 | const t = createTarget(r, target); |
| 340 | iterateReadyRules(r, t, styleIterator); |
| 341 | } else { |
| 342 | styleIterator(r as ReadyStyleRule, target); |
| 343 | } |
| 344 | }); |
| 345 | } |
| 346 | |
| 347 | iterateReadyRules(rootReadyGroup, sheet, (rule, target) => { |
| 348 | const index = target.cssRules.length; |
| 349 | rule.declarations.forEach(({asyncKey, varKey}) => { |
| 350 | if (asyncKey != null) { |
| 351 | asyncDeclarations.set(asyncKey, {rule, target, index}); |
| 352 | } |
| 353 | if (varKey != null) { |
| 354 | varDeclarations.set(varKey, {rule, target, index}); |
| 355 | } |
| 356 | }); |
| 357 | setRule(target, index, rule); |
| 358 | }); |
| 359 | } |
| 360 | |
| 361 | function rebuildAsyncRule(key: number) { |
| 362 | const {rule, target, index} = asyncDeclarations.get(key)!; |
no test coverage detected