union method

void union(
  1. CSSStyleDeclaration declaration
)

Implementation

void union(CSSStyleDeclaration declaration) {
  final Map<String, CSSPropertyValue> incomingPending =
      declaration._pendingProperties;
  if (incomingPending.isEmpty && declaration._properties.isEmpty) {
    return;
  }

  if (_isEffectivelyEmpty) {
    _adoptEffectivePropertiesFrom(declaration);
    return;
  }

  if (_properties.isEmpty &&
      _importants.isEmpty &&
      declaration._properties.isEmpty &&
      declaration._importants.isEmpty) {
    _pendingProperties.addAll(incomingPending);
    return;
  }

  for (final MapEntry<String, CSSPropertyValue> entry in incomingPending.entries) {
    final String propertyName = entry.key;
    final bool currentIsImportant = _importants[propertyName] ?? false;
    final bool otherIsImportant = declaration._importants[propertyName] ?? false;
    final CSSPropertyValue? currentValue =
        _pendingProperties[propertyName] ?? _properties[propertyName];
    final CSSPropertyValue otherValue = entry.value;
    if ((otherIsImportant || !currentIsImportant) &&
        currentValue != otherValue) {
      _pendingProperties[propertyName] = otherValue;
      if (otherIsImportant) {
        _importants[propertyName] = true;
      }
    }
  }
}