MCPcopy Create free account
hub / github.com/adobe/react-spectrum / compileCondition

Function compileCondition

packages/@react-spectrum/s2/style/style-macro.ts:645–680  ·  view source on GitHub ↗
(
    conditions: Set<string>,
    condition: string,
    priority: number,
    rules: Rule[]
  )

Source from the content-addressed store, hash-verified

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,

Callers 1

conditionalToRulesFunction · 0.70

Calls 5

generateNameFunction · 0.70
hasMethod · 0.65
copyMethod · 0.65
addPseudoMethod · 0.65

Tested by

no test coverage detected