buildComputedStyle static method

List<CSSComputedStyleProperty> buildComputedStyle(
  1. Element element
)

Implementation

static List<CSSComputedStyleProperty> buildComputedStyle(Element element) {
  List<CSSComputedStyleProperty> computedStyle = [];
  Map<CSSPropertyID, String> reverse(Map map) => {for (var e in map.entries) e.value: e.key};
  final propertyMap = reverse(CSSPropertyNameMap);
  ComputedCSSStyleDeclaration computedStyleDeclaration = ComputedCSSStyleDeclaration(
      BindingContext(element.ownerView, element.ownerView.contextId, allocateNewBindingObject()), element, null);
  for (CSSPropertyID id in ComputedProperties) {
    final propertyName = propertyMap[id];
    if (propertyName != null) {
      final value = computedStyleDeclaration.getPropertyValue(propertyName);
      if (value.isEmpty) {
        continue;
      }
      computedStyle.add(CSSComputedStyleProperty(name: propertyName, value: value));
      if (id == CSSPropertyID.Top) {
        computedStyle.add(CSSComputedStyleProperty(name: 'y', value: value));
      } else if (id == CSSPropertyID.Left) {
        computedStyle.add(CSSComputedStyleProperty(name: 'x', value: value));
      }
    }
  }
  return computedStyle;
}