dc_bundle 0.38.4

Provides the DesignCompose Bundle and Definition
Documentation
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package designcompose.definition.view;

import "definition/element/color.proto";
import "definition/element/geometry.proto";
import "definition/element/shader.proto";
import "definition/element/view_shape.proto";
import "definition/interaction/reaction.proto";
import "definition/layout/grid.proto";
import "definition/layout/positioning.proto";
import "definition/plugin/frame_extras.proto";
import "definition/view/text_style.proto";
import "definition/view/view_style.proto";
import "google/protobuf/empty.proto";

option java_multiple_files = true;
option java_package = "com.android.designcompose.definition.view";
option optimize_for = LITE_RUNTIME;

// Represents a toolkit View (like a Composable).
message View {
  // This enum may be used as a hint by the DesignCompose renderer
  // implementation to determine if it is important for the content to be
  // rendered identically on different platforms.
  enum RenderMethod {
    RENDER_METHOD_UNSPECIFIED = 0;
    RENDER_METHOD_NONE = 1;
    RENDER_METHOD_PIXEL_PERFECT = 2;
  }

  // unique numeric id (not replicated within one DesignCompose file), which is
  // used by the renderer when building a layout tree, or when mapping from an
  // integer to a View.
  // IMPORTANT: This is a u16, but proto doesn't do short types. Convert back to 
  // u16 after deserializing
  uint32 unique_id = 1;
  // id doesn't exist in vsw toolkit, but is useful for tracing from Figma node
  // to output
  string id = 2;
  // name doesn't exist in vsw toolkit, but is also useful for tracing.
  string name = 3;
  // information on the component that this view is an instance of (if any).
  ComponentInfo component_info = 4;

  // interactivity
  repeated interaction.Reaction reactions = 5;
  // interactivity related frame properties
  plugin.FrameExtras frame_extras = 6;
  // overflow (scrolling) data
  definition.layout.ScrollInfo scroll_info = 7;
  // common style
  ViewStyle style = 8;
  // details that are unique to each view type.
  ViewData data = 9;
  // absolute bounding box of the view in the design document
  element.Rectangle design_absolute_bounding_box = 10;
  // hint for the renderer on how to render the view
  RenderMethod render_method = 11;
  // a hash of variable collection id -> mode id if variable modes are set on
  // this view
  map<string, string> explicit_variable_modes = 12;
}

// Details that are unique to each view type.
message ViewData {
  // Container is used to represent views that act as containers for other
  // views, like a Column or a Row in Jetpack Compose. The shape field defines
  // the visual appearance of the container, while the children field defines
  // the views that are contained within it.
  message Container {
    definition.element.ViewShape shape = 1;
    repeated View children = 2;
  }
  // A Text view with a possible resource name attached to it
  message Text {
    string content = 1;
    optional string res_name =2;
  }
  // A collection of styled text sections
  message StyledTextRuns {
    repeated StyledTextRun styled_texts = 1;
    optional string res_name =2;
  }

  oneof view_data_type {
    Container container = 1;
    Text text = 2;
    StyledTextRuns styled_text = 3;
  }
}

// Figma component properties can be "overridden" in the UI. These overrides
// are applied in the node tree we get back from Figma, so we don't have to
// worry about them, unless we present a variant of a component as a result of
// an interaction. In that case, we need to figure out what has been overridden
// and apply it to the variant. This struct keeps track of those overrides that
// need to be applied to variant instances.
message ComponentOverrides {
  // Previously defined attributes 2 to 4 but nowhere those were used.
  reserved 2 to 4;
  ViewStyle style = 1;
  ViewData view_data = 5;
}

// Details on the Figma component that this view is an instance of.
message ComponentInfo {
  string id = 1;
  string name = 2;
  string component_set_name = 3;

  // Previously we only figure out overrides for the root of a component
  // This is now deprecated and will be removed soon.
  ComponentOverrides overrides = 4[deprecated = true];

  // Descendent view name -> ComponentOverrides mappings. This works only if view name
  // is identical. For the component root view, it uses the component_set_name as the
  // key because the component name differs per variant.
  map<string, ComponentOverrides> overrides_table = 5;
}