(
conditions: Set<string>,
condition: string,
priority: number,
rules: Rule[]
)
| 643 | } |
| 644 | |
| 645 | function compileCondition( |
| 646 | conditions: Set<string>, |
| 647 | condition: string, |
| 648 | priority: number, |
| 649 | rules: Rule[] |
| 650 | ): Rule[] { |
| 651 | if (condition === 'default' || conditions.has(condition)) { |
| 652 | return [new GroupRule(rules)]; |
| 653 | } |
| 654 | |
| 655 | if (condition in theme.conditions || /^[@:]/.test(condition)) { |
| 656 | // Conditions starting with : are CSS pseudo classes. Nest them inside the parent rule. |
| 657 | let prelude = theme.conditions[condition] || condition; |
| 658 | let preludes = Array.isArray(prelude) ? prelude : [prelude]; |
| 659 | return preludes.map(prelude => { |
| 660 | if (prelude.startsWith(':')) { |
| 661 | let rulesWithPseudo = rules.map(rule => { |
| 662 | rule = rule.copy(); |
| 663 | rule.addPseudo(prelude); |
| 664 | return rule; |
| 665 | }); |
| 666 | |
| 667 | return new GroupRule(rulesWithPseudo, generateName(priority, true)); |
| 668 | } |
| 669 | |
| 670 | // Otherwise, wrap the rule in the condition (e.g. @media). |
| 671 | // Top level layer is based on the priority of the rule, not the condition. |
| 672 | // Also group in a sub-layer based on the condition so that lightningcss can more effectively deduplicate rules. |
| 673 | let layer = `${generateName(priority, true)}.${propertyInfo.conditions[prelude] || generateArbitraryValueSelector(condition, true)}`; |
| 674 | return new AtRule(rules, prelude, layer, condition); |
| 675 | }); |
| 676 | } |
| 677 | |
| 678 | hasConditions = true; |
| 679 | return [new ConditionalRule(rules, condition)]; |
| 680 | } |
| 681 | |
| 682 | function compileRule( |
| 683 | property: string, |
no test coverage detected