buildInlineStyle static method
CSSStyle?
buildInlineStyle(
- CSSStyleDeclaration? style
)
Implementation
static CSSStyle? buildInlineStyle(CSSStyleDeclaration? style) {
if (style == null) {
return null;
}
List<CSSProperty> cssProperties = [];
String cssText = '';
for (int i = 0; i < style.length; i++) {
String name = style.item(i);
String kebabName = kebabize(name);
String value = style.getPropertyValue(name);
String _cssText = '$kebabName: $value';
CSSProperty cssProperty = CSSProperty(
name: kebabName,
value: value,
range: SourceRange(
startLine: 0,
startColumn: cssText.length,
endLine: 0,
endColumn: cssText.length + _cssText.length + 1,
),
);
cssText += '$_cssText; ';
cssProperties.add(cssProperty);
}
return CSSStyle(
// Absent for user agent stylesheet and user-specified stylesheet rules.
// Use eventTarget id to identity which element the rule belongs to.
styleSheetId: style.target!.targetId,
cssProperties: cssProperties,
shorthandEntries: <ShorthandEntry>[],
cssText: cssText,
range: SourceRange(startLine: 0, startColumn: 0, endLine: 0, endColumn: cssText.length)
);
}