cloneEffective method

CSSStyleDeclaration cloneEffective()

Implementation

CSSStyleDeclaration cloneEffective() {
  final CSSStyleDeclaration cloned = CSSStyleDeclaration();

  if (_properties.isEmpty) {
    if (_pendingProperties.isNotEmpty) {
      cloned._pendingProperties =
          Map<String, CSSPropertyValue>.of(_pendingProperties);
    }
    if (_importants.isNotEmpty) {
      cloned._importants.addAll(_importants);
    }
    return cloned;
  }

  for (final String propertyName in _properties.keys) {
    if (_pendingProperties.containsKey(propertyName)) continue;
    final CSSPropertyValue? value = _properties[propertyName];
    if (value == null || value.value.isEmpty) continue;
    cloned._pendingProperties[propertyName] = value;
    if (_importants[propertyName] == true) {
      cloned._importants[propertyName] = true;
    }
  }

  for (final String propertyName in _pendingProperties.keys) {
    final CSSPropertyValue value = _pendingProperties[propertyName]!;
    if (value.value.isEmpty) continue;
    cloned._pendingProperties[propertyName] = value;
    if (_importants[propertyName] == true) {
      cloned._importants[propertyName] = true;
    }
  }

  return cloned;
}