fromJson static method

ComparedItem fromJson(
  1. Map<String, Object?> json
)

A row read back off index.json — what an exported page draws from.

Lossy exactly where toJson is: the pixel counts come back as the rounded fraction, the mask never travels, and a capped cluster list stays capped. Everything a viewer draws survives the round trip; nothing recomputes.

Implementation

static ComparedItem fromJson(Map<String, Object?> json) {
  var channels = json['channels'] as Map<String, Object?>? ?? const {};
  var shots = json['shots'] as Map<String, Object?>?;
  var base = shots?['base'] as String?;
  var head = shots?['head'] as String?;
  var retargeted = json['retargeted'] as Map<String, Object?>?;
  var aimedBase = retargeted?['base'] as String?;
  var aimedHead = retargeted?['head'] as String?;
  return ComparedItem(
    id: json['id'] as String? ?? '',
    state:
        ComparedState.values.asNameMap()[json['state']] ??
        ComparedState.skipped,
    package: json['package'] as String?,
    label: json['label'] as String?,
    note: json['note'] as String?,
    retargeted: aimedBase == null || aimedHead == null
        ? null
        : (base: aimedBase, head: aimedHead),
    shots: base == null || head == null ? null : (base: base, head: head),
    pixels: switch (channels['pixels']) {
      Map<String, Object?> pixels => PixelChannel.fromJson(pixels),
      _ => null,
    },
    tree: switch (channels['tree']) {
      Map<String, Object?> tree => TreeChannel.fromJson(tree),
      _ => null,
    },
    texts: switch (channels['texts']) {
      Map<String, Object?> texts => TextChannel.fromJson(texts),
      _ => null,
    },
    events: switch (channels['events']) {
      Map<String, Object?> events => EventChannel.fromJson(events),
      _ => null,
    },
  );
}