setShorthandBackground static method
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=padding-box, clip=border-box.
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';
final String origin = values[6] ?? 'padding-box';
final String clip = values[7] ?? 'border-box';
if (DebugFlags.enableBackgroundLogs && shorthandValue.contains('gradient')) {
cssLogger.finer('[Background] expand shorthand "$shorthandValue" -> '
'color="${values[0] ?? 'transparent'}" image="${values[1] ?? 'none'}" repeat="${values[2] ?? 'repeat'}" '
'attachment="${values[3] ?? 'scroll'}" position="${values[4] ?? '<none>'}" size="$size" '
'origin="$origin" clip="$clip"');
}
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;
// Per spec, shorthand resets origin/clip to their initial values when omitted,
// and applies parsed values when present (including `text` for clip).
properties[BACKGROUND_ORIGIN] = origin;
properties[BACKGROUND_CLIP] = clip;
}