handleSetStyleTexts method

void handleSetStyleTexts(
  1. int? id,
  2. Map<String, dynamic> params
)

Implementation

void handleSetStyleTexts(int? id, Map<String, dynamic> params) {
  List edits = params['edits'];
  List<CSSStyle?> styles = [];
  double viewportWidth = elementManager.viewportWidth;
  double viewportHeight = elementManager.viewportHeight;
  Size viewportSize = Size(viewportWidth, viewportHeight);

  for (Map<String, dynamic> edit in edits as Iterable<Map<String, dynamic>>) {
    // Use styleSheetId to identity element.
    int nodeId = edit['styleSheetId'];
    String text = edit['text'] ?? '';
    List<String> texts = text.split(';');
    Element? element = elementManager.getEventTargetByTargetId<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.style.setProperty(camelize(name), value, viewportSize);
        }
      }
      styles.add(buildInlineStyle(element.style));
    } else {
      styles.add(null);
    }
  }

  sendToFrontend(id, JSONEncodableMap({
    'styles': styles,
  }));
}