rootItems static method

List<PsDescriptorItem> rootItems(
  1. Iterable<({PsDescriptor descriptor, PsLayerEffectKind kind})> effects
)

Serializes effects as Lefx root items grouped by family.

A family with one instance is written under its singular key, and a family with several instances under its multi-instance list key. Unknown effects are skipped because Photoshop has no key for them.

Implementation

static List<PsDescriptorItem> rootItems(Iterable<({PsLayerEffectKind kind, PsDescriptor descriptor})> effects) {
  final List<PsDescriptorItem> result = [];
  for (final PsLayerEffectKind kind in PsLayerEffectKind.values) {
    final String? rootKey = kind.rootKey;
    final String? multiRootKey = kind.multiRootKey;
    final List<PsDescriptor> matches = [
      for (final effect in effects)
        if (effect.kind == kind) effect.descriptor,
    ];
    if (rootKey == null || multiRootKey == null || matches.isEmpty) {
      continue;
    }
    result.add(
      matches.length == 1
          ? PsDescriptorItem(
              key: rootKey,
              value: PsObjectValue(value: matches.single),
            )
          : PsDescriptorItem(
              key: multiRootKey,
              value: PsListValue(values: [for (final PsDescriptor match in matches) PsObjectValue(value: match)]),
            ),
    );
  }
  return result;
}