collectionFromRuleSet method

CSSStyleDeclaration collectionFromRuleSet(
  1. RuleSet ruleSet,
  2. Element element
)

Implementation

CSSStyleDeclaration collectionFromRuleSet(RuleSet ruleSet, Element element) {
  final rules = matchedRules(ruleSet, element);
  CSSStyleDeclaration declaration = CSSStyleDeclaration();
  if (rules.isEmpty) {
    return declaration;
  }

  // sort selector
  rules.sort((leftRule, rightRule) {
    if (leftRule is! CSSStyleRule || rightRule is! CSSStyleRule) {
      return 0;
    }
    int isCompare = leftRule.selectorGroup.matchSpecificity.compareTo(rightRule.selectorGroup.matchSpecificity);
    if (isCompare == 0) {
      return leftRule.position.compareTo(rightRule.position);
    }
    return isCompare;
  });

  // Merge all the rules
  for (CSSRule rule in rules) {
    if (rule is CSSStyleRule) {
      declaration.union(rule.declaration);
    }
  }
  return declaration;
}