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;
    }
  }

  // Merge pseudo-element styles. Ensure target side is initialized so rules from
  // 'other' are not dropped when this side is null.
  if (other.pseudoBeforeStyle != null) {
    pseudoBeforeStyle ??= CSSStyleDeclaration();
    pseudoBeforeStyle!.merge(other.pseudoBeforeStyle!);
  }
  if (other.pseudoAfterStyle != null) {
    pseudoAfterStyle ??= CSSStyleDeclaration();
    pseudoAfterStyle!.merge(other.pseudoAfterStyle!);
  }
  if (other.pseudoFirstLetterStyle != null) {
    pseudoFirstLetterStyle ??= CSSStyleDeclaration();
    pseudoFirstLetterStyle!.merge(other.pseudoFirstLetterStyle!);
  }
  if (other.pseudoFirstLineStyle != null) {
    pseudoFirstLineStyle ??= CSSStyleDeclaration();
    pseudoFirstLineStyle!.merge(other.pseudoFirstLineStyle!);
  }

  return updateStatus;
}