NotationOptions.fromDesignSystem constructor

NotationOptions.fromDesignSystem(
  1. DesignSystem designSystem, {
  2. double width = 390,
  3. String screen = 'screen',
  4. bool named = false,
  5. bool nearestColors = false,
  6. bool reflow = true,
  7. Map<String, Json> projectVariables = const {},
  8. bool roles = false,
})

The looks of designSystem (NotationOptions.fromTheme over its tokens) and the sizes of its components, so a component called by name (StatusBadge "Paid", Stepper @qty) is as big as its own design says: as wide as its parent, as its content, or a size of its own.

Implementation

factory NotationOptions.fromDesignSystem(DesignSystem designSystem,
    {double width = 390, String screen = 'screen', bool named = false, bool nearestColors = false, bool reflow = true, Map<String, Json> projectVariables = const {}, bool roles = false}) {
  final base = NotationOptions.fromTheme(designSystem.manifest.theme.toJson(), width: width, screen: screen, named: named, nearestColors: nearestColors, reflow: reflow, roles: roles);
  Object size(SizeFit fit, double value) => switch (fit) {
        SizeFit.fill || SizeFit.flexible => {'fill': 0},
        SizeFit.hug => {'hug': 0},
        _ => value,
      };
  return NotationOptions(
    width: base.width,
    screen: base.screen,
    textStyles: base.textStyles,
    card: base.card,
    badges: base.badges,
    surface: base.surface,
    accent: base.accent,
    track: base.track,
    badge: base.badge,
    cta: base.cta,
    palette: base.palette,
    nearestColors: base.nearestColors,
    tile: base.tile,
    sectionRadius: base.sectionRadius,
    barChart: base.barChart,
    progress: base.progress,
    cardGap: base.cardGap,
    pageFill: base.pageFill,
    ringStroke: base.ringStroke,
    contentWidth: base.contentWidth,
    line: base.line,
    selectedFill: base.selectedFill,
    selectedRow: base.selectedRow,
    darkGround: base.darkGround,
    narrowWidth: base.narrowWidth,
    sidebarWidth: base.sidebarWidth,
    sidebarRail: base.sidebarRail,
    sectionPad: base.sectionPad,
    gutter: base.gutter,
    band: base.band,
    siteFill: base.siteFill,
    paneFill: base.paneFill,
    iconTile: base.iconTile,
    sideFill: base.sideFill,
    iconStyle: base.iconStyle,
    // A frame whose lines go into a row (a toolbar's, a dialog's footer)
    // lays them out as a row's: a text as wide as its words, not the row.
    rowFrames: {
      for (final c in designSystem.list)
        for (final n in c.document.nodes.values)
          if (n.type == 'row' && n.children.any((k) => c.document.nodes[k]?.type == 'slot')) c.type,
    },
    // …and the space that row or column keeps between them.
    // (Of its children slot, the one with no name: a named slot's lines
    // are written under `slot name`.)
    frameGaps: {
      for (final c in designSystem.list)
        for (final n in c.document.nodes.values)
          if ((n.type == 'row' || n.type == 'column') && n.children.any((k) => _childrenSlot(c.document.nodes[k])))
            if (n.props.toJson(null)['spacing'] case final num gap when gap > 0) c.type: gap,
    },
    frameRows: {
      for (final c in designSystem.list)
        for (final n in c.document.nodes.values)
          if (n.type == 'row' && n.children.any((k) => _childrenSlot(c.document.nodes[k]))) c.type,
    },
    controlHeight: base.controlHeight,
    fieldLabel: base.fieldLabel,
    fieldText: base.fieldText,
    reflow: base.reflow,
    displaySizes: base.displaySizes,
    colorValues: base.colorValues,
    themeTextStyles: base.themeTextStyles,
    quietInks: base.quietInks,
    projectVariables: projectVariables,
    accentText: base.accentText,
    themeColors: base.themeColors,
    roles: base.roles,
    components: {
      for (final c in designSystem.list)
        if (c.document.nodes[c.document.roots.firstOrNull] case final root?)
          c.type: (width: size(root.layout.width.fit, root.layout.width.value), height: size(root.layout.height.fit, root.layout.height.value)),
    },
    componentRules: {
      for (final c in designSystem.list)
        if (c.document.nodes[c.document.roots.firstOrNull] case final root? when root.media.isNotEmpty) c.type: [for (final r in root.media) r.toJson()],
    },
    componentScreenActions: {
      for (final c in designSystem.list)
        if (c.document.extra['screenActions'] case final List actions when actions.isNotEmpty)
          c.type: [for (final a in actions) if (a is Map) a.cast<String, Object?>()],
    },
    componentScreenOverlays: {
      for (final c in designSystem.list)
        if (c.document.extra['screenOverlays'] case final List overlays when overlays.isNotEmpty)
          c.type: [for (final o in overlays) if (o is Map) o.cast<String, Object?>()],
    },
    componentPressEvents: {
      for (final c in designSystem.list)
        if (c.document.nodes[c.document.roots.firstOrNull] case final root?)
          for (final r in root.actions)
            if (r.trigger.type == TriggerType.click)
              for (final a in r.actions)
                if (a.toJson() case {'type': 'componentEvent', 'event': final String event}) c.type: event,
    },
  );
}