document method

LayoutDocument document(
  1. LayoutDocument doc
)

doc with every node that names something of the theme resolved (the others are the same objects, so a source comparing nodes sees only those change).

Implementation

LayoutDocument document(LayoutDocument doc) {
  final catalog = doc.catalog ?? Catalog.current;
  Map<String, Node>? nodes;
  WidgetSpec? specOf(String id) => doc[id]?.spec;
  for (final e in doc.nodes.entries) {
    final json = e.value.toJson();
    final r = node(json, e.value.spec, specOf: specOf);
    if (identical(r, json)) continue;
    final n = Node.fromJson(r, id: e.key, catalog: catalog);
    if (n != null && n != e.value) (nodes ??= {...doc.nodes})[e.key] = n;
  }
  return nodes == null ? doc : doc.copyWith(nodes: nodes);
}