parse static method

CSSBackgroundImage? parse(
  1. String? value
)

Implementation

static CSSBackgroundImage? parse(String? value) {
  if (value == null) return null;

  CSSURL? url;
  CSSBackgroundGradient? gradient;

  CSSBackgroundRepeat? repeat;
  CSSBackgroundAttachment? attachment;
  CSSBackgroundBox? origin;
  CSSBackgroundBox? clip;
  String? position;
  String? size;

  String? propsStr;

  var match = patternURL.firstMatch(value);
  if (match != null) {
    var urlStr = match.group(1);
    url = CSSURL.parse(urlStr);
    propsStr = match.group(2);
  } else {
    match = patternGradient.firstMatch(value);
    if (match != null) {
      var gradientTypeStr = match.group(1);
      var gradientParamsStr = match.group(2);
      var parameters = parseListOfStrings(
          gradientParamsStr, ARGUMENT_LIST_DELIMITER, true);
      gradient = CSSBackgroundGradient(gradientTypeStr, parameters);
      propsStr = match.group(3);
    }
  }

  if (propsStr != null) {
    var propsMatches = patternPropsCapture.allMatches(propsStr);

    for (var m in propsMatches) {
      var repeatStr = m.group(1);
      var attachmentStr = m.group(2);
      var box1Str = m.group(3);
      var box2Str = m.group(4);
      var positionStr = m.group(5);
      var sizeStr = m.group(6);

      if (repeatStr != null) {
        repeat = parseCSSBackgroundRepeat(repeatStr);
      }

      if (attachmentStr != null) {
        attachment = parseCSSBackgroundAttachment(attachmentStr);
      }

      if (box1Str != null) {
        origin = parseCSSBackgroundBox(box1Str);
      }

      if (box2Str != null) {
        clip = parseCSSBackgroundBox(box2Str);
      }

      if (positionStr != null) {
        position = positionStr;
      }

      if (sizeStr != null) {
        size = sizeStr;
      }
    }
  }

  if (url != null) {
    return CSSBackgroundImage.url(url,
        origin: origin,
        clip: clip,
        repeat: repeat,
        attachment: attachment,
        position: position,
        size: size);
  } else if (gradient != null) {
    return CSSBackgroundImage.gradient(gradient,
        origin: origin,
        clip: clip,
        repeat: repeat,
        attachment: attachment,
        position: position,
        size: size);
  }

  return null;
}