diff method

Implementation

Map<String, String?> diff(CSSStyleDeclaration other) {
  Map<String, String?> diffs = {};

  Map<String, String> properties = {}
    ..addAll(_properties)
    ..addAll(_pendingProperties);

  for (String propertyName in properties.keys) {
    String? prevValue = properties[propertyName];
    String? currentValue = other._pendingProperties[propertyName];

    if (isNullOrEmptyValue(prevValue) && isNullOrEmptyValue(currentValue)) {
      continue;
    } else if (!isNullOrEmptyValue(prevValue) && isNullOrEmptyValue(currentValue)) {
      // Remove property.
      diffs[propertyName] = null;
    } else if (prevValue != currentValue) {
      // Update property.
      diffs[propertyName] = currentValue;
    }
  }

  for (String propertyName in other._pendingProperties.keys) {
    String? prevValue = properties[propertyName];
    String? currentValue = other._pendingProperties[propertyName];
    if (isNullOrEmptyValue(prevValue) && !isNullOrEmptyValue(currentValue)) {
       // Add property.
      diffs[propertyName] = currentValue;
    }
  }
  return diffs;
}