merge method

bool merge(
  1. CSSStyleDeclaration other
)

Implementation

bool merge(CSSStyleDeclaration other) {
  Map<String, CSSPropertyValue> properties = {}
    ..addAll(_properties)
    ..addAll(_pendingProperties);
  bool updateStatus = false;
  for (String propertyName in properties.keys) {
    CSSPropertyValue? prevValue = properties[propertyName];
    CSSPropertyValue? currentValue = other._pendingProperties[propertyName];
    bool currentImportant = other._importants[propertyName] ?? false;

    if (isNullOrEmptyValue(prevValue) && isNullOrEmptyValue(currentValue)) {
      continue;
    } else if (!isNullOrEmptyValue(prevValue) && isNullOrEmptyValue(currentValue)) {
      // Remove property.
      removeProperty(propertyName, currentImportant);
      updateStatus = true;
    } else if (prevValue != currentValue) {
      // Update property.
      setProperty(propertyName, currentValue?.value, isImportant: currentImportant, baseHref: currentValue?.baseHref);
      updateStatus = true;
    }
  }

  for (String propertyName in other._pendingProperties.keys) {
    CSSPropertyValue? prevValue = properties[propertyName];
    CSSPropertyValue? currentValue = other._pendingProperties[propertyName];
    bool currentImportant = other._importants[propertyName] ?? false;

    if (isNullOrEmptyValue(prevValue) && !isNullOrEmptyValue(currentValue)) {
      // Add property.
      setProperty(propertyName, currentValue?.value, isImportant: currentImportant, baseHref: currentValue?.baseHref);
      updateStatus = true;
    }
  }

  if (other.pseudoBeforeStyle != null) {
    pseudoBeforeStyle?.merge(other.pseudoBeforeStyle!);
  }
  if (other.pseudoAfterStyle != null) {
    pseudoAfterStyle?.merge(other.pseudoAfterStyle!);
  }

  return updateStatus;
}