parsePositionShorthand static method

List<String> parsePositionShorthand(
  1. String input
)

Parse background-position shorthand to background-position-x and background-position-y list.

Implementation

static List<String> parsePositionShorthand(String input) {
  if (_cachedParsedPosition.containsKey(input)) {
    return _cachedParsedPosition[input]!;
  }
  List<String> positions = [];
  List<String> split = input.split(splitRegExp);
  if (split.length == 1) {
    switch (split.first) {
      case TOP:
      case BOTTOM:
        positions.add(CENTER);
        positions.add(split.first);
        break;
      case LEFT:
      case RIGHT:
        positions.add(split.first);
        positions.add(CENTER);
        break;
      default:
        positions.add(split.first);
        positions.add(CENTER);
        break;
    }
  } else if (split.length == 2) {
    if ((split.first == CENTER || split.first == TOP || split.first == BOTTOM)  &&
        (split.last == CENTER || split.last == LEFT || split.last == RIGHT)) {
      positions.add(split.last);
      positions.add(split.first);
    } else {
      positions.add(split.first);
      positions.add(split.last);
    }
  }
  return _cachedParsedPosition[input] = positions;
}