Merge remote-tracking branch 'origin/third-party-review' Change-Id: I87f8f89c51716407d2b851aa22c58f4167988df7
diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..92f97ee --- /dev/null +++ b/Android.bp
@@ -0,0 +1,20 @@ +java_library { + name: "libautomotive-design-compose-protos", + visibility: ["//visibility:public"], + proto: { + type: "lite", + include_dirs: [ + "external/protobuf/src", + "external/automotive-design-compose-protos/definition", + "external/automotive-design-compose-protos/layout_interface", + "external/automotive-design-compose-protos/live_update", + ], + canonical_path_from_root: false, + }, + srcs: [ + ":libprotobuf-internal-protos", + "definition/**/*.proto", + "layout_interface/**/*.proto", + "live_update/**/*.proto", + ], +}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6093765 --- /dev/null +++ b/CONTRIBUTING.md
@@ -0,0 +1,37 @@ +# How to contribute + +We'd love to accept your patches and contributions to this project. + +## Before you begin + +### Sign our Contributor License Agreement + +Contributions to this project must be accompanied by a +[Contributor License Agreement](https://cla.developers.google.com/about) (CLA). +You (or your employer) retain the copyright to your contribution; this simply +gives us permission to use and redistribute your contributions as part of the +project. + +If you or your current employer have already signed the Google CLA (even if it +was for a different project), you probably don't need to do it again. + +Visit <https://cla.developers.google.com/> to see your current agreements or to +sign a new one. + +### Review our community guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). + +## Contribution process + +### Copyright headers + +All code must have the proper copyright header. The [addlicense](https://github.com/google/addlicense) tool helps automate this. + +### Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests.
diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE
@@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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.
diff --git a/METADATA b/METADATA new file mode 100644 index 0000000..6da72b1 --- /dev/null +++ b/METADATA
@@ -0,0 +1,16 @@ +name: "automotive-design-compose-protos" +description: + "DesignCompose protobuf message repository " + "" + +third_party { + identifier { + type: "Git" + value: "https://github.com/google/automotive-design-compose-protos" + primary_source: true + version: "v0.0.1" + } + license_type: NOTICE + version: "v0.0.1" + last_upgrade_date { year: 2025 month: 5 day: 5 } +}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/MODULE_LICENSE_APACHE2
diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..40f261f --- /dev/null +++ b/OWNERS
@@ -0,0 +1,4 @@ +ralphthomas@google.com +farivar@google.com + +include platform/system/core:main:/janitors/OWNERS
diff --git a/README.md b/README.md new file mode 100644 index 0000000..d99b6f6 --- /dev/null +++ b/README.md
@@ -0,0 +1,17 @@ +# DesignCompose protobuf message repository + +The messages in this directory are organized according to the following principles: + +```ascii-tree https://github.com/aprilandjan/vscode-ascii-tree-generator +. +├── android_interface - Types specifically used for the interface from the rust library to the android library +├── definition - The structure for a DesignCompose Definition +│ ├── element - "Base" types. Messages in element should not reference messages outside of element +│ ├── interaction - Types related to interactions and reactions +│ ├── layout - Layout and positioning +│ ├── modifier - Transformations, blending, other modifiers that can be applied to a base view +│ ├── plugin - Capabilities added by the DesignCompose plugin +│ └── view - Collected styles and settings that are applied to nodes in the design definition +└── live_update - Types that are specific to the live update system and do not influence the design definition + └── figma - These types are specific to the live update implementation for Figma +```
diff --git a/definition/design_compose_definition.proto b/definition/design_compose_definition.proto new file mode 100644 index 0000000..dc51f1f --- /dev/null +++ b/definition/design_compose_definition.proto
@@ -0,0 +1,51 @@ +// 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; + +import "definition/element/variable.proto"; +import "definition/view/view.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition"; +option optimize_for = LITE_RUNTIME; + +// A separate header message that quickly identifies the main DesignComposeDefinition +message DesignComposeDefinitionHeader { + uint32 dc_version = 1; // DesignCompose version + string last_modified = 2; // Last modified timestamp + string name = 3; // Design name + string response_version = 4; // Figma response version + string id = 5; // Design ID +} + +// A serialized Figma design document, containing views, images, component sets, +// version, ID, and variable map. It's used for storing and loading Figma +// designs in a DesignCompose project. +message DesignComposeDefinition { + + // The string here is a NodeQuery, encoded to a string so that it can be used + // as the key to the map. See crates/dc_bundle/src/definition.rs for encoding/decoding + map<string, definition.view.View> views = 1; + // Images contains a mapping from ImageKey to network bytes. It can + // create an ImageMap and is intended to be used when we want to use + // Figma-defined components but do not want to communicate with the Figma + // service. + map<string, bytes> images = 2; + map<string, string> component_sets = 3; + definition.element.VariableMap variable_map = 4; +} +
diff --git a/definition/element/background.proto b/definition/element/background.proto new file mode 100644 index 0000000..1c427ca --- /dev/null +++ b/definition/element/background.proto
@@ -0,0 +1,101 @@ +// 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"; +import "definition/element/variable.proto"; +import "definition/modifier/filter.proto"; +import "definition/modifier/matrix_transform.proto"; +import "google/protobuf/empty.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.element"; +option optimize_for = LITE_RUNTIME; + +// The background of a node +message Background { + // A single color stop within a gradient. + message ColorStop { + float position = 1; + element.ColorOrVar color = 2; + } + + // A type of gradient where the colors transition smoothly along a straight + // line. + message LinearGradient { + float start_x = 1; + float start_y = 2; + float end_x = 3; + float end_y = 4; + repeated ColorStop color_stops = 5; + } + + // A type of gradient where the colors transition along a + // circular path defined by a center point, an angle, and a scale. + message AngularGradient { + float center_x = 1; + float center_y = 2; + float angle = 3; + float scale = 4; + repeated ColorStop color_stops = 5; + } + + // A type of gradient where the colors transition smoothly from a central + // point outwards in a circular pattern. + message RadialGradient { + float center_x = 1; + float center_y = 2; + float angle = 3; + float radius_x = 4; + float radius_y = 5; + repeated ColorStop color_stops = 6; + } + // Defines how an image background is scaled to fit the background area. + enum ScaleMode { + SCALE_MODE_UNSPECIFIED = 0; + SCALE_MODE_FILL = 1; + SCALE_MODE_FIT = 2; + SCALE_MODE_TILE = 3; + SCALE_MODE_STRETCH = 4; + } + + // References an image via the key and the modifiers that will be used with it + message Image { + // Instead of keeping decoded images in ViewStyle objects, we keep keys to + // the images in the ImageContext and then fetch decoded images when + // rendering. This means we can serialize the whole ImageContext, and always + // get the right image when we render. + string key = 1; + repeated modifier.FilterOp filters = 2; + modifier.AffineTransform transform = 3; + ScaleMode scale_mode = 4; + float opacity = 5; + optional string res_name = 6; + } + + oneof background_type { + google.protobuf.Empty none = 1; + element.ColorOrVar solid = 2; + LinearGradient linear_gradient = 3; + AngularGradient angular_gradient = 4; + RadialGradient radial_gradient = 5; + Image image = 6; + // Clear all the pixels underneath, used for hole-punch compositing. + google.protobuf.Empty clear = 7; + // DiamondGradient support possibly in the future. + } +}
diff --git a/definition/element/color.proto b/definition/element/color.proto new file mode 100644 index 0000000..54a64ee --- /dev/null +++ b/definition/element/color.proto
@@ -0,0 +1,40 @@ +// 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; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.element"; +option optimize_for = LITE_RUNTIME; + +// Color represents a color value within a design, encoded as RGBA (Red, Green, +// Blue, Alpha) where each component is an 8-bit integer. Alpha determines +// opacity, with 255 being fully opaque and 0 fully transparent. +// Encoding each component to uint32, which uses variable-length encoding. +message Color { + uint32 r = 1; + uint32 g = 2; + uint32 b = 3; + uint32 a = 4; +} + +// Color represented using floats in the range of 0 to 1. +message FloatColor { + float r = 1; + float g = 2; + float b = 3; + float a = 4; +}
diff --git a/definition/element/font.proto b/definition/element/font.proto new file mode 100644 index 0000000..9ddfc3a --- /dev/null +++ b/definition/element/font.proto
@@ -0,0 +1,69 @@ +// 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/variable.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.element"; +option optimize_for = LITE_RUNTIME; + +// FontWeight specifies the visual thickness of a typeface. It's represented +// numerically, usually ranging from 100 (thin) to 900 (black). Common values +// include 400 (regular), 500 (medium), and 700 (bold). +message FontWeight { + NumOrVar weight = 1; +} + +// Allows italic or oblique faces to be selected. +enum FontStyle { + FONT_STYLE_UNSPECIFIED = 0; + // A face that is neither italic not obliqued. + FONT_STYLE_NORMAL = 1; + // A form that is generally cursive in nature. + FONT_STYLE_ITALIC = 2; + // A typically-sloped version of the regular face. + FONT_STYLE_OBLIQUE = 3; +} + +// Allows underline or strikethrough to be selected. +enum TextDecoration { + TEXT_DECORATION_UNSPECIFIED = 0; + TEXT_DECORATION_NONE = 1; + TEXT_DECORATION_UNDERLINE = 2; + TEXT_DECORATION_STRIKETHROUGH = 3; +} + +// The width of a font as an approximate fraction of the normal width. +// Widths range from 0.5 to 2.0 inclusive, with 1.0 as the normal width. +message FontStretch { + float value = 1; +} + +// FontFeature refers to specific typographic settings within a typeface, such +// as ligatures (e.g., "fi" becoming a single glyph) or small capitals. These +// features can enhance the visual appearance and readability of text, providing +// additional stylistic options for designers. +message FontFeature { + string tag = 1; + bool enabled = 2; +} + +// Initially only support url. No nodeId hyperlink support. +message Hyperlink { + string value = 1; +}
diff --git a/definition/element/geometry.proto b/definition/element/geometry.proto new file mode 100644 index 0000000..c048e1d --- /dev/null +++ b/definition/element/geometry.proto
@@ -0,0 +1,74 @@ +// 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 "google/protobuf/empty.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.element"; +option optimize_for = LITE_RUNTIME; + +// Size encapsulates the dimensions of an element, expressed as width and height +// values. These values typically represent pixels or density-independent pixels +// (dp), allowing for consistent sizing across different screen densities. +message Size { + float width = 1; + float height = 2; +} + +// Vector defines a two-dimensional geometric vector, consisting of x and y +// components. Vectors are fundamental for representing spatial relationships +// and performing geometric transformations within a definition. +message Vector { + float x = 1; + float y = 2; +} + +// Rectangle: Rectangle represents a rectangular region within a design, defined +// by its position (x, y coordinates) and dimensions (width, height). +message Rectangle { + optional float x = 1; + optional float y = 2; + optional float width = 3; + optional float height = 4; +} + +/** Dimension in Rust is an union-type enum, which are represented in proto by +`oneof` structures. `oneof` isn't a message type by itself, so in order to +re-use the Dimension oneof it needs to go into a `DimensionProto` message. +*/ + +message DimensionProto { + oneof Dimension { + google.protobuf.Empty undefined = 1; + google.protobuf.Empty auto = 2; + float points = 3; + float percent = 4; + } +} + +/* The `Rect` type is generic/templated in Rust, which isn't supported in + * protobuf. Instead we will define individual messages for each type of + * `Rect` that we use. + */ + +message DimensionRect { + DimensionProto start = 1; + DimensionProto end = 2; + DimensionProto top = 3; + DimensionProto bottom = 4; +}
diff --git a/definition/element/path.proto b/definition/element/path.proto new file mode 100644 index 0000000..ee607ab --- /dev/null +++ b/definition/element/path.proto
@@ -0,0 +1,98 @@ +// 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/background.proto"; +import "definition/element/shader.proto"; + +option java_package = "com.android.designcompose.definition.element"; +option java_multiple_files = true; +option optimize_for = LITE_RUNTIME; + +// Path represents a complex shape in a design, defined by a series of commands +// (e.g., move, line, curve) and associated numerical data. It determines the +// outline of graphical elements or UI components. +message Path { + // WindingRule determines how the interior of a self-intersecting + // or overlapping path is filled. + enum WindingRule { + WINDING_RULE_UNSPECIFIED = 0; + // NonZero fills regions based on the direction of the path segments as + // they cross the ray. + WINDING_RULE_NON_ZERO = 1; + // EvenOdd fills regions based on whether a ray drawn from a point crosses + // the path an even or odd number of times. + WINDING_RULE_EVEN_ODD = 2; + WINDING_RULE_NONE = 3; + } + + bytes commands = 1; + repeated float data = 2; + WindingRule winding_rule = 3; +} + +// Determines the vertical spacing between lines of text. +message LineHeight { + oneof line_height_type { + float pixels = 1; + float percent = 2; + } +} + +// How is a stroke aligned to its containing box? +enum StrokeAlign { + STROKE_ALIGN_UNSPECIFIED = 0; + // The stroke is entirely within the containing view. The stroke's outer edge + // matches the outer edge of the containing view. + STROKE_ALIGN_INSIDE = 1; + // The stroke is centered on the edge of the containing view, and extends into + // the view on the inside, and out of the view on the outside. + STROKE_ALIGN_CENTER = 2; + // The stroke is entirely outside of the view. The stroke's inner edge is the + // outer edge of the containing view. + STROKE_ALIGN_OUTSIDE = 3; +} + +// Stroke weight is either a uniform value for all sides, or individual +// weights for each side. +message StrokeWeight { + // Individual weights for each side (typically only applied on boxes). + message Individual { + float top = 1; + float right = 2; + float bottom = 3; + float left = 4; + } + oneof stroke_weight_type { + // One weight is used for all sides. + float uniform = 1; + Individual individual = 2; + } +} + +// A stroke is similar to a border, except that it does not change layout (a +// border insets the children by the border size), it may be inset, centered or +// outset from the view bounds and there can be multiple strokes on a view. +message Stroke { + StrokeAlign stroke_align = 1; + StrokeWeight stroke_weight = 2; + repeated Background strokes = 3; + + // Runtime shader from the shader plugin as stroke. + // When shader is present, strokes will not be drawn. + optional element.ShaderData shader_data = 4; +}
diff --git a/definition/element/shader.proto b/definition/element/shader.proto new file mode 100644 index 0000000..3e5e3d1 --- /dev/null +++ b/definition/element/shader.proto
@@ -0,0 +1,103 @@ +// Copyright 2025 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; + +// Details for the runtime shader +message ShaderData { + // string for runtime shader code + string shader = 1; + + // fallback color when runtime shader code isn't supported + optional definition.element.Color shader_fallback_color = 2; + + // shader uniforms, name => ShaderUniform + map<string, ShaderUniform> shader_uniforms = 3; +} + +// Data for shader uniform, containing name, type and default value set from plugin. +message ShaderUniform { + // name + string name = 1; + // type + string type = 2; + // shader uniform value + optional ShaderUniformValue value = 3; + // If this shader uniform should be ignored. No action to set the uniform value. + // For images, we have imageResolution bundled to the image input. + // The uniform value will be ignored but the uniform is in list for type check. + bool ignore = 4; +} + +// Shader uniform value, currently support float, FloatColor and float array. +message ShaderUniformValue { + + // Float array value for float2, float3, float4, half2, half3 and half4. + message FloatVec { + repeated float floats = 1; + } + + // Int array value for int2, int3 and int4. + message IntVec { + repeated int32 ints = 1; + } + + // ImageRef for image uniform(shader). + message ImageRef { + string key = 1; + optional string res_name = 2; + } + + // Image bytes for image uniform(shader). + message ImageBytes { + bytes data = 1; + } + + // Image resource for image uniform(shader). + message ImageResource { + uint32 resource_id = 1; + } + + oneof value_type { + // uniform "type" is "float", "half" or "iTime". + float float_value = 1; + // uniform "type" is "float2", "float3", "float4", "half2", "half3" or "half4" + // in the plugin data. + FloatVec float_vec_value = 2; + // uniform "type" is "color3" or "color4" in the plugin data. Alpha would be + // ignored for "color3" when set uniform value to the runtime shader. + FloatColor float_color_value = 3; + + int32 int_value = 4; + // uniform "type" is "int2", "int3" or "int4" in the plugin data. + IntVec int_vec_value = 5; + + // uniform "shader" holds an image ref key + ImageRef image_ref_value = 6; + + // uniform "shader" holds an image bytes data. It is created for uniform value customization. + ImageBytes image_bytes_value = 7; + + // uniform "shader" holds an image resource id. It is created for uniform value customization. + ImageResource image_resource_value = 8; + } +}
diff --git a/definition/element/variable.proto b/definition/element/variable.proto new file mode 100644 index 0000000..fc04494 --- /dev/null +++ b/definition/element/variable.proto
@@ -0,0 +1,128 @@ +// 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; +}
diff --git a/definition/element/view_shape.proto b/definition/element/view_shape.proto new file mode 100644 index 0000000..eb3f192 --- /dev/null +++ b/definition/element/view_shape.proto
@@ -0,0 +1,92 @@ +// 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/path.proto"; +import "definition/element/variable.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.element"; +option optimize_for = LITE_RUNTIME; + +// Represents the geometric shape of a visual element, such as a rectangle, +// ellipse, or a custom path. It determines the boundaries of the element and +// influences how it is rendered and interacted with within a design. +message ViewShape { + // Defines the appearance of the stroke's end points (e.g., round, square). + enum StrokeCap { + STROKE_CAP_UNSPECIFIED = 0; + STROKE_CAP_NONE = 1; + STROKE_CAP_ROUND = 2; + STROKE_CAP_SQUARE = 3; + STROKE_CAP_LINE_ARROW = 4; + STROKE_CAP_TRIANGLE_ARROW = 5; + STROKE_CAP_CIRCLE_FILLED = 6; + STROKE_CAP_DIAMOND_FILLED = 7; // Not supported + } + + // A container for other objects. Equivalent to a Compose Box or a Figma Frame + message Box { + bool is_mask = 1; + } + + // A rounded rectangle + message RoundRect { + // Should have exactly four corners + repeated NumOrVar corner_radii = 1; + float corner_smoothing = 2; + bool is_mask = 3; + } + + // A vector path + message VectorPath { + repeated Path paths = 1; + repeated Path strokes = 2; + StrokeCap stroke_cap = 3; + bool is_mask = 4; + } + + // Represents a complex arc shape within a design. + message VectorArc { + // The outer path defining the overall shape of the arc. + repeated Path paths = 1; + // An optional inner path used for creating an outline or stroke effect. + repeated Path strokes = 2; + StrokeCap stroke_cap = 3; + float start_angle_degrees = 4; + float sweep_angle_degrees = 5; + float inner_radius = 6; + float corner_radius = 7; + bool is_mask = 8; + } + + // A shape defined by multiple paths, with potentially rounded corners + message VectorRect { + repeated Path paths = 1; + repeated Path strokes = 2; + repeated NumOrVar corner_radii = 3; // Exactly 4 + bool is_mask = 4; + } + + oneof shape { + Box rect = 1; + RoundRect round_rect = 2; + VectorPath path = 3; + VectorArc arc = 4; + VectorRect vector_rect = 5; + } +}
diff --git a/definition/interaction/pointer.proto b/definition/interaction/pointer.proto new file mode 100644 index 0000000..4c7d97d --- /dev/null +++ b/definition/interaction/pointer.proto
@@ -0,0 +1,32 @@ +// 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.interaction; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.interaction"; +option optimize_for = LITE_RUNTIME; + +// Determines how a UI element responds to user interactions like taps, clicks, +// and hovers. It can be set to "Auto" for default behavior, "None" to disable +// interactions, or "Box-None" to only detect events within the element's +// bounding box. +enum PointerEvents { + POINTER_EVENTS_UNSPECIFIED = 0; + POINTER_EVENTS_AUTO = 1; + POINTER_EVENTS_NONE = 2; + POINTER_EVENTS_INHERIT = 3; +}
diff --git a/definition/interaction/reaction.proto b/definition/interaction/reaction.proto new file mode 100644 index 0000000..720b7b3 --- /dev/null +++ b/definition/interaction/reaction.proto
@@ -0,0 +1,113 @@ +// 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.interaction; + +import "definition/element/geometry.proto"; +import "definition/interaction/transition.proto"; +import "google/protobuf/empty.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.interaction"; +option optimize_for = LITE_RUNTIME; + +// Various actions that can be triggered +message Action { + // Open a URL. + message ActionUrl { + string url = 1; + } + // Do something with a destination node. + message Node { + // The kind of navigation that an Action can perform + enum Navigation { + NAVIGATION_UNSPECIFIED = 0; + NAVIGATION_NAVIGATE = 1; + NAVIGATION_SWAP = 2; + NAVIGATION_OVERLAY = 3; + NAVIGATION_SCROLL_TO = 4; + NAVIGATION_CHANGE_TO = 5; + } + // Node that we should navigate to, change to, open or swap as an + // overlay, or scroll to reveal. + optional string destination_id = 1; + + // The kind of navigation (really the kind of action) to perform with the + // destination node (if it's not null). + Navigation navigation = 2; + // The kind of navigation (really the kind of action) to perform with the + // destination node (if it's not null). + + Transition transition = 3; + // For "Navigate", should we open the new node with the current frame's + // scroll position? + bool preserve_scroll_position = 4; + // For overlays that have been manually positioned. + element.Vector overlay_relative_position = 5; + } + + oneof action_type { + google.protobuf.Empty back = 1; + google.protobuf.Empty close = 2; + ActionUrl url = 3; + Node node = 4; + } +} + +// Various Triggers +message Trigger { + // protolint:disable MESSAGES_HAVE_COMMENT + // They're self-explanatory + message KeyDown { + bytes key_codes = 1; + } + + message Timeout { + float timeout = 1; + } + + message MouseEnter { + float delay = 1; + } + message MouseLeave { + float delay = 1; + } + message MouseUp { + float delay = 1; + } + message MouseDown { + float delay = 1; + } + oneof trigger_type { + google.protobuf.Empty click = 1; + google.protobuf.Empty hover = 2; + google.protobuf.Empty press = 3; + google.protobuf.Empty drag = 4; + KeyDown key_down = 5; + Timeout after_timeout = 6; + MouseEnter mouse_enter = 7; + MouseLeave mouse_leave = 8; + MouseUp mouse_up = 9; + MouseDown mouse_down = 10; + } +} + +// Reaction describes interactivity for a node. It's a pair of Action ("what +// happens?") and Trigger ("how do you make it happen?") +message Reaction { + Action action = 1; + Trigger trigger = 2; +}
diff --git a/definition/interaction/transition.proto b/definition/interaction/transition.proto new file mode 100644 index 0000000..a860acb --- /dev/null +++ b/definition/interaction/transition.proto
@@ -0,0 +1,122 @@ +// 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. + +// protolint:disable MESSAGE_NAMES_EXCLUDE_PREPOSITIONS +// protolint:disable FIELD_NAMES_EXCLUDE_PREPOSITIONS + +syntax = "proto3"; + +package designcompose.definition.interaction; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.interaction"; +option optimize_for = LITE_RUNTIME; + +// The type of easing to perform in a transition. +message Easing { + // Bezier curve for custom easing functions. + message Bezier { + float x1 = 1; + float y1 = 2; + float x2 = 3; + float y2 = 4; + } + + // Spring coefficients + message Spring { + float mass = 1; + float stiffness = 2; + float damping = 3; + } + + oneof easing_type { + Bezier bezier = 1; + Spring spring = 2; + } +} + +// This represents the Figma "Transition" type. +// https://www.figma.com/plugin-docs/api/Transition/ +message Transition { + // Some transitions define a direction. + enum TransitionDirection { + TRANSITION_DIRECTION_UNSPECIFIED = 0; + TRANSITION_DIRECTION_LEFT = 1; + TRANSITION_DIRECTION_RIGHT = 2; + TRANSITION_DIRECTION_TOP = 3; + TRANSITION_DIRECTION_BOTTOM = 4; + } + // protolint:disable MESSAGES_HAVE_COMMENT + // They're self-explanatory + message Dissolve { + Easing easing = 1; + float duration = 2; + } + + message SmartAnimate { + Easing easing = 1; + float duration = 2; + } + + message ScrollAnimate { + Easing easing = 1; + float duration = 2; + } + + message MoveIn { + Easing easing = 1; + float duration = 2; + TransitionDirection direction = 3; + bool match_layers = 4; + } + + message MoveOut { + Easing easing = 1; + float duration = 2; + TransitionDirection direction = 3; + bool match_layers = 4; + } + + message Push { + Easing easing = 1; + float duration = 2; + TransitionDirection direction = 3; + bool match_layers = 4; + } + + message SlideIn { + Easing easing = 1; + float duration = 2; + TransitionDirection direction = 3; + bool match_layers = 4; + } + + message SlideOut { + Easing easing = 1; + float duration = 2; + TransitionDirection direction = 3; + bool match_layers = 4; + } + + oneof transition_type { + Dissolve dissolve = 1; + SmartAnimate smart_animate = 2; + ScrollAnimate scroll_animate = 3; + MoveIn move_in = 4; + MoveOut move_out = 5; + Push push = 6; + SlideIn slide_in = 7; + SlideOut slide_out = 8; + } +}
diff --git a/definition/layout/grid.proto b/definition/layout/grid.proto new file mode 100644 index 0000000..4b80f97 --- /dev/null +++ b/definition/layout/grid.proto
@@ -0,0 +1,39 @@ +// 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.layout; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.layout"; +option optimize_for = LITE_RUNTIME; + +// Represents a span for a node within a grid layout. +message GridSpan { + string node_name = 1; + map<string, string> node_variant = 2; + uint32 span = 3; + bool max_span = 4; +} +// Defines the type of grid layout used for a view. +enum GridLayoutType { + GRID_LAYOUT_TYPE_UNSPECIFIED = 0; + GRID_LAYOUT_TYPE_FIXED_COLUMNS = 1; + GRID_LAYOUT_TYPE_FIXED_ROWS = 2; + GRID_LAYOUT_TYPE_AUTO_COLUMNS = 3; + GRID_LAYOUT_TYPE_AUTO_ROWS = 4; + GRID_LAYOUT_TYPE_HORIZONTAL = 5; + GRID_LAYOUT_TYPE_VERTICAL = 6; +}
diff --git a/definition/layout/layout_style.proto b/definition/layout/layout_style.proto new file mode 100644 index 0000000..5a0374b --- /dev/null +++ b/definition/layout/layout_style.proto
@@ -0,0 +1,55 @@ +// 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.layout; + +import "definition/element/geometry.proto"; +import "definition/layout/grid.proto"; +import "definition/layout/positioning.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.layout"; +option optimize_for = LITE_RUNTIME; + +/* This message defines the layout style of a Figma node. It includes various + * properties that control the node's position, size, and spacing, as well as + * its alignment and flexbox behavior. + */ +message LayoutStyle { + element.DimensionRect margin = 1; + element.DimensionRect padding = 2; + layout.ItemSpacing item_spacing = 3; + element.DimensionProto top = 4; + element.DimensionProto left = 5; + element.DimensionProto bottom = 6; + element.DimensionProto right = 7; + element.DimensionProto width = 8; + element.DimensionProto height = 9; + element.DimensionProto min_width = 10; + element.DimensionProto max_width = 11; + element.DimensionProto min_height = 12; + element.DimensionProto max_height = 13; + element.Size bounding_box = 14; + float flex_grow = 15; + float flex_shrink = 16; + element.DimensionProto flex_basis = 17; + layout.AlignSelf align_self = 18; + layout.AlignContent align_content = 19; + layout.AlignItems align_items = 20; + layout.FlexDirection flex_direction = 21; + layout.JustifyContent justify_content = 22; + layout.PositionType position_type = 23; +}
diff --git a/definition/layout/positioning.proto b/definition/layout/positioning.proto new file mode 100644 index 0000000..11ce34f --- /dev/null +++ b/definition/layout/positioning.proto
@@ -0,0 +1,143 @@ +// 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.layout; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.layout"; +option optimize_for = LITE_RUNTIME; + +// Controls how items are aligned on the cross axis within a single line (row or +// column) of the container. The cross axis is the axis perpendicular to the +// main axis (the direction the row/column lays out its items). +enum AlignItems { + ALIGN_ITEMS_UNSPECIFIED = 0; + ALIGN_ITEMS_FLEX_START = 1; + ALIGN_ITEMS_FLEX_END = 2; + ALIGN_ITEMS_CENTER = 3; + ALIGN_ITEMS_BASELINE = 4; + ALIGN_ITEMS_STRETCH = 5; +} + +// Overrides the AlignItems setting for a specific item within the container. +// This lets you customize the alignment of one item without affecting others. +enum AlignSelf { + ALIGN_SELF_UNSPECIFIED = 0; + ALIGN_SELF_AUTO = 1; + ALIGN_SELF_FLEX_START = 2; + ALIGN_SELF_FLEX_END = 3; + ALIGN_SELF_CENTER = 4; + ALIGN_SELF_BASELINE = 5; + ALIGN_SELF_STRETCH = 6; +} + +// Controls the distribution of space between multiple lines of items when they +// wrap within a container. This comes into play when the container has more +// items than can fit on a single line. +enum AlignContent { + ALIGN_CONTENT_UNSPECIFIED = 0; + ALIGN_CONTENT_FLEX_START = 1; + ALIGN_CONTENT_FLEX_END = 2; + ALIGN_CONTENT_CENTER = 3; + ALIGN_CONTENT_STRETCH = 4; + ALIGN_CONTENT_SPACE_BETWEEN = 5; + ALIGN_CONTENT_SPACE_AROUND = 6; +} + +// Dictates the primary direction in which items within a flex container (like +// Row or Column) are laid out. +enum FlexDirection { + FLEX_DIRECTION_UNSPECIFIED = 0; + FLEX_DIRECTION_ROW = 1; + FLEX_DIRECTION_COLUMN = 2; + FLEX_DIRECTION_ROW_REVERSE = 3; + FLEX_DIRECTION_COLUMN_REVERSE = 4; + FLEX_DIRECTION_NONE = 5; +} +// Controls how items are distributed along the main axis of a flex container. +// This is particularly useful when items don't fill the entire available space. +enum JustifyContent { + JUSTIFY_CONTENT_UNSPECIFIED = 0; + JUSTIFY_CONTENT_FLEX_START = 1; + JUSTIFY_CONTENT_FLEX_END = 2; + JUSTIFY_CONTENT_CENTER = 3; + JUSTIFY_CONTENT_SPACE_BETWEEN = 4; + JUSTIFY_CONTENT_SPACE_AROUND = 5; + JUSTIFY_CONTENT_SPACE_EVENLY = 6; +} + +// Determines how an item is positioned within its parent container, providing +// different layout behaviors. +enum PositionType { + POSITION_TYPE_UNSPECIFIED = 0; + POSITION_TYPE_RELATIVE = 1; + POSITION_TYPE_ABSOLUTE = 2; +} + +// Defines how content overflows the bounds of a view. +enum Overflow { + OVERFLOW_UNSPECIFIED = 0; + OVERFLOW_VISIBLE = 1; + OVERFLOW_HIDDEN = 2; + OVERFLOW_SCROLL = 3; +} +// Defines the direction of overflow scrolling +enum OverflowDirection { + OVERFLOW_DIRECTION_UNSPECIFIED = 0; + OVERFLOW_DIRECTION_NONE = 1; + OVERFLOW_DIRECTION_HORIZONTAL_SCROLLING = 2; + OVERFLOW_DIRECTION_VERTICAL_SCROLLING = 3; + OVERFLOW_DIRECTION_HORIZONTAL_AND_VERTICAL_SCROLLING = 4; +} + +// Defines how a view's size is determined. +enum LayoutSizing { + LAYOUT_SIZING_UNSPECIFIED = 0; + LAYOUT_SIZING_FIXED = 1; + LAYOUT_SIZING_HUG = 2; + LAYOUT_SIZING_FILL = 3; +} + +// Defines the spacing between items in a layout. It can be either +// a fixed value or an "auto" value, which will be calculated based on the +// available space. +message ItemSpacing { + // Specifies an "auto" spacing value. It contains the desired width and + // height of the spacing. + message Auto { + int32 width = 1; + int32 height = 2; + } + oneof ItemSpacingType { + int32 fixed = 1; + Auto auto = 2; + } +} + +// Represents information about the scroll state of a view, including the +// overflow direction and whether paged scrolling is enabled. +message ScrollInfo { + OverflowDirection overflow = 1; + bool paged_scrolling = 2; +} + +// Defines how flex items wrap when they exceed the available space. +enum FlexWrap { + FLEX_WRAP_UNSPECIFIED = 0; + FLEX_WRAP_NO_WRAP = 1; + FLEX_WRAP_WRAP = 2; + FLEX_WRAP_WRAP_REVERSE = 3; +} \ No newline at end of file
diff --git a/definition/modifier/blend.proto b/definition/modifier/blend.proto new file mode 100644 index 0000000..7a53728 --- /dev/null +++ b/definition/modifier/blend.proto
@@ -0,0 +1,45 @@ +// 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.modifier; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.modifier"; +option optimize_for = LITE_RUNTIME; + +// Various supported Blend types +enum BlendMode { + BLEND_MODE_UNSPECIFIED = 0; + BLEND_MODE_PASS_THROUGH = 1; + BLEND_MODE_NORMAL = 2; + BLEND_MODE_DARKEN = 3; + BLEND_MODE_MULTIPLY = 4; + BLEND_MODE_LINEAR_BURN = 5; + BLEND_MODE_COLOR_BURN = 6; + BLEND_MODE_LIGHTEN = 7; + BLEND_MODE_SCREEN = 8; + BLEND_MODE_LINEAR_DODGE = 9; + BLEND_MODE_COLOR_DODGE = 10; + BLEND_MODE_OVERLAY = 11; + BLEND_MODE_SOFT_LIGHT = 12; + BLEND_MODE_HARD_LIGHT = 13; + BLEND_MODE_DIFFERENCE = 14; + BLEND_MODE_EXCLUSION = 15; + BLEND_MODE_HUE = 16; + BLEND_MODE_SATURATION = 17; + BLEND_MODE_COLOR = 18; + BLEND_MODE_LUMINOSITY = 19; +}
diff --git a/definition/modifier/filter.proto b/definition/modifier/filter.proto new file mode 100644 index 0000000..f3dfd25 --- /dev/null +++ b/definition/modifier/filter.proto
@@ -0,0 +1,32 @@ +// 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.modifier; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.modifier"; +option optimize_for = LITE_RUNTIME; + +// Various filters that can be applied and their intensity +message FilterOp { + oneof FilterOpType { + float blur = 1; + float saturation = 2; // not currently implemented + float contrast = 3; + float grayscale = 4; + float brightness = 5; + } +}
diff --git a/definition/modifier/matrix_transform.proto b/definition/modifier/matrix_transform.proto new file mode 100644 index 0000000..169066a --- /dev/null +++ b/definition/modifier/matrix_transform.proto
@@ -0,0 +1,57 @@ +// 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.modifier; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.modifier"; +option optimize_for = LITE_RUNTIME; + +// Represents a 3D affine transformation, which is a combination of +// translation, rotation, scaling, and shearing in 3D space. It's used to +// define the transform applied to a view or its children within a +// DesignCompose layout. +// Maps to euclid's Transform3D +message LayoutTransform { + float m11 = 1; + float m12 = 2; + float m13 = 3; + float m14 = 4; + float m21 = 5; + float m22 = 6; + float m23 = 7; + float m24 = 8; + float m31 = 9; + float m32 = 10; + float m33 = 11; + float m34 = 12; + float m41 = 13; + float m42 = 14; + float m43 = 15; + float m44 = 16; +} +// Represents a 2D affine transformation, which is a combination of translation, +// rotation, scaling, and shearing. It's used to define the transform applied to +// an image background or other visual elements. +// Maps to euclid's Transform2D +message AffineTransform { + float m11 = 1; + float m12 = 2; + float m21 = 3; + float m22 = 4; + float m31 = 5; + float m32 = 6; +}
diff --git a/definition/modifier/shadow.proto b/definition/modifier/shadow.proto new file mode 100644 index 0000000..44ee7fb --- /dev/null +++ b/definition/modifier/shadow.proto
@@ -0,0 +1,65 @@ +// 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.modifier; + +import "definition/element/variable.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.modifier"; +option optimize_for = LITE_RUNTIME; + +// Shadows can be applied to the border box, or the stroke box. +// +// The border box is the box outside of the border for Outset shadows, and the +// box inside of the border for inset shadows. +// +// The stroke box is always the the outer edge of any stroke defined, or the +// edge of the view (ignoring the border) if no strokes are present on the view. +enum ShadowBox { + SHADOW_BOX_UNSPECIFIED = 0; + // The shadow applies to the border box, either the inside of the border for + // inset shadows, or the outside of the border for outset shadows. + SHADOW_BOX_BORDER_BOX = 1; + // The shadow applies to the stroke box. This is the outer edge of the stroke + // for both inset and ouset shadows. + SHADOW_BOX_STROKE_BOX = 2; +} + +// BoxShadow defines a CSS-style box shadow, either outset or inset. +message BoxShadow { + // The shadow itself + message Shadow { + float blur_radius = 1; + float spread_radius = 2; + element.ColorOrVar color = 3; + float offset_x = 4; + float offset_y = 5; + ShadowBox shadow_box = 6; + } + oneof shadow_box { + Shadow outset = 1; + Shadow inset = 2; + } +} + +// A text shadow. +message TextShadow { + float blur_radius = 1; + element.ColorOrVar color = 2; + float offset_x = 3; + float offset_y = 4; +}
diff --git a/definition/modifier/text.proto b/definition/modifier/text.proto new file mode 100644 index 0000000..be15943 --- /dev/null +++ b/definition/modifier/text.proto
@@ -0,0 +1,45 @@ +// 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.modifier; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.modifier"; +option optimize_for = LITE_RUNTIME; + +// Horizontal text alignment. This value aligns the text within its bounds. +enum TextAlign { + TEXT_ALIGN_UNSPECIFIED = 0; + TEXT_ALIGN_LEFT = 1; + TEXT_ALIGN_CENTER = 2; + TEXT_ALIGN_RIGHT = 3; +} + +// Vertical text alignment. This value aligns the text vertically within its +// bounds. +enum TextAlignVertical { + TEXT_ALIGN_VERTICAL_UNSPECIFIED = 0; + TEXT_ALIGN_VERTICAL_TOP = 1; + TEXT_ALIGN_VERTICAL_CENTER = 2; + TEXT_ALIGN_VERTICAL_BOTTOM = 3; +} + +// How text should be truncated if it overflows its bounds. +enum TextOverflow { + TEXT_OVERFLOW_UNSPECIFIED = 0; + TEXT_OVERFLOW_CLIP = 1; + TEXT_OVERFLOW_ELLIPSIS = 2; +}
diff --git a/definition/plugin/frame_extras.proto b/definition/plugin/frame_extras.proto new file mode 100644 index 0000000..817450b --- /dev/null +++ b/definition/plugin/frame_extras.proto
@@ -0,0 +1,64 @@ +// 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.plugin; + +import "definition/element/color.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.plugin"; +option optimize_for = LITE_RUNTIME; + +// Some frame properties are only available through the plugin API and are +// needed to implement Reactions properly. They're included in this FrameExtras +// struct. +message FrameExtras { + // The number of children of this frame that are fixed. + uint32 fixed_children = 1; + // How the overlay is positioned. + OverlayPositionType overlay_position_type = 2; + // The background of the overlay. + OverlayBackground overlay_background = 3; + // How the overlay interacts with the background. + OverlayBackgroundInteraction overlay_background_interaction = 4; +} + +// Defines the position of an overlay within a frame. +enum OverlayPositionType { + OVERLAY_POSITION_TYPE_UNSPECIFIED = 0; + OVERLAY_POSITION_TYPE_CENTER = 1; + OVERLAY_POSITION_TYPE_TOP_LEFT = 2; + OVERLAY_POSITION_TYPE_TOP_CENTER = 3; + OVERLAY_POSITION_TYPE_TOP_RIGHT = 4; + OVERLAY_POSITION_TYPE_BOTTOM_LEFT = 5; + OVERLAY_POSITION_TYPE_BOTTOM_CENTER = 6; + OVERLAY_POSITION_TYPE_BOTTOM_RIGHT = 7; + OVERLAY_POSITION_TYPE_MANUAL = 8; +} + +// The color of the overlay background. +message OverlayBackground { + definition.element.FloatColor color = 1; +} + +// Defines how an overlay interacts with its background. It specifies whether +// the overlay can be closed by clicking outside of it or if there's no +// interaction. +enum OverlayBackgroundInteraction { + OVERLAY_BACKGROUND_INTERACTION_UNSPECIFIED = 0; + OVERLAY_BACKGROUND_INTERACTION_NONE = 1; + OVERLAY_BACKGROUND_INTERACTION_CLOSE_ON_CLICK_OUTSIDE = 2; +}
diff --git a/definition/plugin/meter_data.proto b/definition/plugin/meter_data.proto new file mode 100644 index 0000000..d577590 --- /dev/null +++ b/definition/plugin/meter_data.proto
@@ -0,0 +1,90 @@ +// 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.plugin; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.plugin"; +option optimize_for = LITE_RUNTIME; + +// Represents data for a rotation meter, including whether it's enabled, its +// start and end angles, whether it's discrete, and the discrete value. +message RotationMeterData { + bool enabled = 1; + float start = 2; + float end = 3; + bool discrete = 4; + float discrete_value = 5; +} + +// Represents data for an arc meter, including whether it's enabled, its start +// and end angles, whether it's discrete, the discrete value, and the corner +// radius. +message ArcMeterData { + bool enabled = 1; + float start = 2; + float end = 3; + bool discrete = 4; + float discrete_value = 5; + float corner_radius = 6; +} + +// Represents data for a progress bar meter, including whether it's enabled, +// whether it's discrete, the discrete value, whether it's vertical, and the end +// coordinates. +message ProgressBarMeterData { + bool enabled = 1; + bool discrete = 2; + float discrete_value = 3; + bool vertical = 4; + float end_x = 5; + float end_y = 6; + float start_x = 7; + float start_y = 8; +} + +// Represents data for a progress marker meter, including whether it's enabled, +// whether it's discrete, the discrete value, whether it's vertical, and the +// start and end coordinates. +message ProgressMarkerMeterData { + bool enabled = 1; + bool discrete = 2; + float discrete_value = 3; + bool vertical = 4; + float start_x = 5; + float end_x = 6; + float start_y = 7; + float end_y = 8; +} + +// Schema for progress vector data that we write to serialized data +message ProgressVectorMeterData { + bool enabled = 1; + bool discrete = 2; + float discrete_value = 3; +} + +// A container message that holds one of the meter data types (rotation, arc, +// progress bar, or progress marker). +message MeterData { + oneof meter_data_type { + RotationMeterData rotation_data = 1; + ArcMeterData arc_data = 2; + ProgressBarMeterData progress_bar_data = 3; + ProgressMarkerMeterData progress_marker_data = 4; + ProgressVectorMeterData progress_vector_data = 5; + } +}
diff --git a/definition/view/node_style.proto b/definition/view/node_style.proto new file mode 100644 index 0000000..6199e28 --- /dev/null +++ b/definition/view/node_style.proto
@@ -0,0 +1,106 @@ +// 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/background.proto"; +import "definition/element/font.proto"; +import "definition/element/geometry.proto"; +import "definition/element/path.proto"; +import "definition/element/shader.proto"; +import "definition/element/variable.proto"; +import "definition/interaction/pointer.proto"; +import "definition/layout/grid.proto"; +import "definition/layout/positioning.proto"; +import "definition/modifier/blend.proto"; +import "definition/modifier/filter.proto"; +import "definition/modifier/matrix_transform.proto"; +import "definition/modifier/shadow.proto"; +import "definition/modifier/text.proto"; +import "definition/plugin/meter_data.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.view"; +option optimize_for = LITE_RUNTIME; + +// Configures whether a view is displayed using a Flexbox layout or not at all. +enum Display { + DISPLAY_UNSPECIFIED = 0; + DISPLAY_FLEX = 1; + DISPLAY_NONE = 2; +} + +// Contains all of the styleable parameters accepted by the Rect and Text +// components. +// Next id = 44 +message NodeStyle { + // Text properties + element.Background text_color = 1; + element.NumOrVar font_size = 2; + optional string font_family = 3; + element.FontWeight font_weight = 4; + element.FontStyle font_style = 5; + element.TextDecoration text_decoration = 40; + optional float letter_spacing = 41; + element.FontStretch font_stretch = 6; + repeated element.Background backgrounds = 7; + repeated modifier.BoxShadow box_shadows = 8; + element.Stroke stroke = 9; + optional float opacity = 10; + + // Transforms + modifier.LayoutTransform transform = 11; + modifier.LayoutTransform relative_transform = 12; + + // Text layout + modifier.TextAlign text_align = 13; + modifier.TextAlignVertical text_align_vertical = 14; + modifier.TextOverflow text_overflow = 15; + modifier.TextShadow text_shadow = 16; + + + // Size and layout + element.Size node_size = 17; + element.LineHeight line_height = 18; + optional int32 line_count = 19; + repeated element.FontFeature font_features = 20; + repeated modifier.FilterOp filters = 21; + repeated modifier.FilterOp backdrop_filters = 22; + modifier.BlendMode blend_mode = 23; + + // Layout properties + Display display_type = 24; + layout.FlexWrap flex_wrap = 25; + optional layout.GridLayoutType grid_layout_type = 26; + uint32 grid_columns_rows = 27; + uint32 grid_adaptive_min_size = 28; + repeated layout.GridSpan grid_span_contents = 29; + layout.Overflow overflow = 30; + optional uint32 max_children = 31; + optional string overflow_node_id = 32; + optional string overflow_node_name = 33; + float cross_axis_item_spacing = 34; + layout.LayoutSizing horizontal_sizing = 35; + layout.LayoutSizing vertical_sizing = 36; + optional float aspect_ratio = 37; + interaction.PointerEvents pointer_events = 38; + plugin.MeterData meter_data = 39; + element.Hyperlink hyperlink = 42; + + // Runtime shader from the shader plugin as background. + // When shader is present, background will not be drawn. + optional element.ShaderData shader_data = 43; +}
diff --git a/definition/view/text_style.proto b/definition/view/text_style.proto new file mode 100644 index 0000000..570e459 --- /dev/null +++ b/definition/view/text_style.proto
@@ -0,0 +1,51 @@ +// 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/background.proto"; +import "definition/element/font.proto"; +import "definition/element/path.proto"; +import "definition/element/variable.proto"; + +option java_package = "com.android.designcompose.definition.view"; +option optimize_for = LITE_RUNTIME; +option java_multiple_files = true; + +// These are the style properties that apply to text, so we can use them on +// subsections of a longer string. We then assume that every style transition is +// a potential line break (and also run the linebreaking algorithm on the +// content of every style for the normal case where we need to break text that's +// all in one style). +message TextStyle { + element.Background text_color = 1; + element.NumOrVar font_size = 2; + optional string font_family = 3; + element.FontWeight font_weight = 4; + element.FontStyle font_style = 5; + element.FontStretch font_stretch = 6; + float letter_spacing = 7; + element.TextDecoration text_decoration = 8; + element.LineHeight line_height = 9; + repeated element.FontFeature font_features = 10; + element.Hyperlink hyperlink = 11; +} + +// A section of text with a specific style +message StyledTextRun { + string text = 1; + TextStyle style = 2; +}
diff --git a/definition/view/view.proto b/definition/view/view.proto new file mode 100644 index 0000000..a9e05ff --- /dev/null +++ b/definition/view/view.proto
@@ -0,0 +1,135 @@ +// 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; +} +
diff --git a/definition/view/view_style.proto b/definition/view/view_style.proto new file mode 100644 index 0000000..58ee02d --- /dev/null +++ b/definition/view/view_style.proto
@@ -0,0 +1,30 @@ +// 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/layout/layout_style.proto"; +import "definition/view/node_style.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.definition.view"; +option optimize_for = LITE_RUNTIME; + +// Collects the Layout and Node styles for a View +message ViewStyle { + layout.LayoutStyle layout_style = 1; + NodeStyle node_style = 2; +}
diff --git a/layout_interface/jni_layout.proto b/layout_interface/jni_layout.proto new file mode 100644 index 0000000..41a5293 --- /dev/null +++ b/layout_interface/jni_layout.proto
@@ -0,0 +1,69 @@ +// 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.layout_interface; + +import "definition/layout/layout_style.proto"; +option java_multiple_files = true; +option java_package = "com.android.designcompose.layout_interface"; +option optimize_for = LITE_RUNTIME; + +// A representation of a Figma node to register for layout. +message LayoutNode { + int32 layout_id = 1; + int32 parent_layout_id = 2; + int32 child_index = 3; + definition.layout.LayoutStyle style = 4; + string name = 5; + bool use_measure_func = 6; + optional int32 fixed_width = 7; + optional int32 fixed_height = 8; +} + +// A parent node id and a list of child ids +message LayoutParentChildren { + int32 parent_layout_id = 1; + repeated int32 child_layout_ids = 2; +} + +// A list of Figma nodes to register for layout +message LayoutNodeList { + repeated LayoutNode layout_nodes = 1; + repeated LayoutParentChildren parent_children = 2; +} + +// A processed layout node +message Layout { + // Relative ordering of the node. Render nodes with a higher order on top + // of nodes with lower order + uint32 order = 1; + float width = 2; + float height = 3; + float left = 4; // The top-left corner of the node + float top = 5; + float content_width = 6; // Width of child content + float content_height = 7; // Height of child content +} + +/* The layout response sent back to client which contains a layout state ID and +a list of layout IDs that have changed. +*/ +message LayoutChangedResponse { + // The final result of a layout algorithm for a single taffy Node + + int32 layout_state = 1; + map<int32, Layout> changed_layouts = 2; +}
diff --git a/live_update/android_interface.proto b/live_update/android_interface.proto new file mode 100644 index 0000000..a6c8efb --- /dev/null +++ b/live_update/android_interface.proto
@@ -0,0 +1,64 @@ +// 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.live_update; + +import "definition/design_compose_definition.proto"; +import "live_update/figma/figma_doc.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.live_update"; +option optimize_for = LITE_RUNTIME; + +// From Kotlin to Rust +message ConvertRequest { + string figma_api_key = 1; + // Node names + repeated string queries = 2; + // Ignored images + repeated live_update.figma.IgnoredImage ignored_images = 3; + // Last modified comes from the previously fetched document and is + // used to avoid fetching the same doc version over and over. + optional string last_modified = 4; + // The version also comes from the previously fetched document. When certain + // properties of a Figma doc like a new branch changes, the version gets + // updated but the last_modified field does not. + optional string version = 5; + // Image session also comes from the previously fetched document. We allow + // this + // to fail decoding, in case we're receiving a request from a client that has + // an image session generated by an old version. + optional bytes image_session_json = 6; +} + +// From Rust to Kotlin +message ConvertResponse { + // Document contains the converted DesignCompose definition, the server Figma + // document and the session id required to fetch images. + message Document { + // The DesignCompose definition header. + definition.DesignComposeDefinitionHeader header = 1; + // The server Figma document contains minimal information required by the + // client to fetch images. + live_update.figma.ServerFigmaDoc server_doc = 2; + // Session id required by the client to fetch images. + bytes image_session_json = 3; + } + + oneof convert_response_type { + Document document = 1; + string unmodified = 2; + } +}
diff --git a/live_update/figma/figma_doc.proto b/live_update/figma/figma_doc.proto new file mode 100644 index 0000000..4b9b0e5 --- /dev/null +++ b/live_update/figma/figma_doc.proto
@@ -0,0 +1,46 @@ +// 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.live_update.figma; + +import "definition/design_compose_definition.proto"; + +option java_multiple_files = true; +option java_package = "com.android.designcompose.live_update.figma"; +option optimize_for = LITE_RUNTIME; + +// An image that is ignored when fetching a Figma Doc +message IgnoredImage { + string node = 1; + repeated string images = 2; +} + +// We can fetch figma documents in a project or from branches of another +// document. We store each as a name and ID +message FigmaDocInfo { + string name = 1; + string id = 2; + string version_id = 3; +} +// This is the struct we send over to the client. It contains the serialized +// document along with some extra data: document branches, project files, and +// errors +message ServerFigmaDoc { + designcompose.definition.DesignComposeDefinition figma_doc = 1; + repeated FigmaDocInfo branches = 2; + repeated FigmaDocInfo project_files = 3; + repeated string errors = 4; +}