// 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.element;
import "definition/element/color.proto";
option java_multiple_files = true;
option java_package = "com.android.designcompose.definition.element";
option optimize_for = LITE_RUNTIME;
// Holds the value of a variable, whichever type it is.
message VariableValue {
oneof Value {
bool bool = 1;
float number = 2;
string text = 3;
Color color = 4;
string alias = 5;
}
}
// Representation of a Figma variable. We convert a figma_schema::Variable into
// this format to make the fields a bit easier to access.
message Variable {
// Variable Types
enum VariableType {
VARIABLE_TYPE_UNSPECIFIED = 0;
VARIABLE_TYPE_BOOL = 1;
VARIABLE_TYPE_NUMBER = 2;
VARIABLE_TYPE_TEXT = 3;
VARIABLE_TYPE_COLOR = 4;
}
// Each variable contains a map of possible values. This data structure helps
// keep track of that data and contains functions to retrieve the value of a
// variable given a mode.
message VariableValueMap {
map<string, VariableValue> values_by_mode = 1;
}
string id = 1;
string name = 2;
bool remote = 3;
string key = 4;
string variable_collection_id = 5;
VariableType var_type = 6;
VariableValueMap values_by_mode = 7;
}
// Holds either a numerical value (e.g., 100 for a font size) or a reference to
// a design variable. This allows for dynamic values that can adapt based on the
// current variable values.
message NumOrVar {
// Holds a reference to a design variable. Fallback is the node float value from figma.
message NumVar {
string id = 1;
float fallback = 2;
}
oneof NumOrVarType {
float num = 1;
NumVar var = 2;
}
}
// Holds either a direct color representation (e.g., RGBA values) or a reference
// to a color variable, providing flexibility in how you define colors.
message ColorOrVar {
// Holds a reference to a design variable. Fallback is the node color value from figma.
message ColorVar {
string id = 1;
Color fallback = 2;
}
oneof ColorOrVarType {
Color color = 1;
ColorVar var = 2;
}
}
// Representation of a variable mode. Variables can have fixed values for each
// available mode
message Mode {
string id = 1;
string name = 2;
}
// Representation of a variable collection. Every variable belongs to a
// collection, and a collection contains one or more modes.
message Collection {
string id = 1;
string name = 2;
string default_mode_id = 3;
map<string, string> mode_name_hash = 4; // name -> id
map<string, Mode> mode_id_hash = 5; // id -> Mode
}
// Stores variable mappings
message VariableMap {
// Maps Collection names to IDs
message NameIdMap {
map<string, string> m = 1;
}
map<string, Collection> collections_by_id = 1; // ID -> Collection
map<string, string> collection_ids_by_name = 2; // Name -> ID
map<string, element.Variable> variables_by_id = 3; // ID -> Variable
// Collection ID -> [Name -> ID]
map<string, NameIdMap> variable_name_id_maps_by_cid = 4;
}