getShadowValues static method

List<List<String?>>? getShadowValues(
  1. String property
)

Implementation

static List<List<String?>>? getShadowValues(String property) {
  List shadows = property.split(_commaRegExp);
  // The shadow effects are applied front-to-back: the first shadow is on top and
  // the others are layered behind.
  // https://drafts.csswg.org/css-backgrounds-3/#shadow-layers
  Iterable reversedShadows = shadows.reversed;
  List reversedShadowList = reversedShadows.toList();
  List<List<String?>> values = List.empty(growable: true);

  for (String shadow in reversedShadowList as Iterable<String>) {
    if (shadow == NONE) {
      continue;
    }
    List<String> parts = _splitBySpace(shadow.trim());

    String? inset;
    String? color;

    List<String?> lengthValues = List.filled(4, null);
    int i = 0;
    for (String part in parts) {
      if (part == INSET) {
        inset = part;
      } else if (CSSLength.isLength(part)) {
        lengthValues[i++] = part;
      } else if (color == null && CSSColor.isColor(part)) {
        color = part;
      } else {
        return null;
      }
    }

    values.add([
      color,
      lengthValues[0], // offsetX
      lengthValues[1], // offsetY
      lengthValues[2], // blurRadius
      lengthValues[3], // spreadRadius
      inset
    ]);
  }

  return values;
}