setShorthandBackground static method

void setShorthandBackground(
  1. Map<String, String?> properties,
  2. String shorthandValue
)

Implementation

static void setShorthandBackground(Map<String, String?> properties, String shorthandValue) {
  List<String?>? values = _getBackgroundValues(shorthandValue);
  if (values == null) return;

  // Per CSS Backgrounds spec, unspecified subproperties reset to their initial values.
  // Initials: color=transparent, image=none, repeat=repeat, attachment=scroll,
  // position=0% 0%, size=auto. Origin/clip not parsed here.
  final String color = values[0] ?? 'transparent';
  final String image = values[1] ?? 'none';
  final String repeat = values[2] ?? 'repeat';
  final String attachment = values[3] ?? 'scroll';
  final String? positionShorthand = values[4];
  final String size = values[5] ?? 'auto';

  properties[BACKGROUND_COLOR] = color;
  properties[BACKGROUND_IMAGE] = image;
  properties[BACKGROUND_REPEAT] = repeat;
  properties[BACKGROUND_ATTACHMENT] = attachment;
  if (positionShorthand != null) {
    final List<String> positions = CSSPosition.parsePositionShorthand(positionShorthand);
    if (positions.length >= 2) {
      properties[BACKGROUND_POSITION_X] = positions[0];
      properties[BACKGROUND_POSITION_Y] = positions[1];
    } else {
      cssLogger.warning('[CSSStyleProperty] Failed to parse background-position in shorthand: '
          '"$positionShorthand". Fallback to 0% 0%.');
      properties[BACKGROUND_POSITION_X] = '0%';
      properties[BACKGROUND_POSITION_Y] = '0%';
    }
  } else {
    // Reset to initial when not specified
    properties[BACKGROUND_POSITION_X] = '0%';
    properties[BACKGROUND_POSITION_Y] = '0%';
  }
  properties[BACKGROUND_SIZE] = size;


}