createElementCssSelector function

CssSelector createElementCssSelector(
  1. String elementName,
  2. List<List<String?>> matchableAttrs
)

Implementation

CssSelector createElementCssSelector(
    String elementName, List<List<String?>> matchableAttrs) {
  var cssSelector = CssSelector();
  var elNameNoNs = _splitNsName(elementName)[1];
  cssSelector.setElement(elNameNoNs);
  for (var i = 0; i < matchableAttrs.length; i++) {
    var attrName = matchableAttrs[i][0]!;
    var attrNameNoNs = _splitNsName(attrName)[1]!;
    var attrValue = matchableAttrs[i][1];
    // [CssSelector] is used both to define selectors, and to describe an
    // element. This is unfortunate as certain attribute selectors don't make
    // sense in context of defining an element. Since we're defining the
    // attributes of an element here, we use exact match ('=') to specify that
    // the element has this attribute value.
    cssSelector.addAttribute(attrNameNoNs, '=', attrValue);
    if (attrName.toLowerCase() == _classAttribute && attrValue != null) {
      var classes = _splitClasses(attrValue);
      for (var className in classes) {
        cssSelector.addClassName(className);
      }
    }
  }
  return cssSelector;
}