handleSetStyleTexts method
void
handleSetStyleTexts(
- int? id,
- Map<String, dynamic> params
)
Implementation
void handleSetStyleTexts(int? id, Map<String, dynamic> params) {
List edits = params['edits'];
List<CSSStyle?> styles = [];
// @TODO: diff the inline style edits.
// @TODO: support comments for inline style.
for (Map<String, dynamic> edit in edits) {
// Use styleSheetId to identity element.
int nodeId = edit['styleSheetId'];
String text = edit['text'] ?? '';
List<String> texts = text.split(';');
Element? element = document.controller.view.getEventTargetById<Element>(nodeId);
if (element != null) {
for (String kv in texts) {
kv = kv.trim();
List<String> _kv = kv.split(':');
if (_kv.length == 2) {
String name = _kv[0].trim();
String value = _kv[1].trim();
element.setInlineStyle(_camelize(name), value);
}
}
styles.add(buildInlineStyle(element));
} else {
styles.add(null);
}
}
sendToFrontend(id, JSONEncodableMap({
'styles': styles,
}));
}