@@ -5,6 +5,7 @@ import type {
55 Paint ,
66 Vector ,
77 GetFileResponse ,
8+ ComponentPropertyType ,
89 Component ,
910 ComponentSet ,
1011} from "@figma/rest-api-spec" ;
@@ -61,6 +62,7 @@ type StyleTypes =
6162type GlobalVars = {
6263 styles : Record < StyleId , StyleTypes > ;
6364} ;
65+
6466export interface SimplifiedDesign {
6567 name : string ;
6668 lastModified : string ;
@@ -71,6 +73,12 @@ export interface SimplifiedDesign {
7173 globalVars : GlobalVars ;
7274}
7375
76+ export interface ComponentProperties {
77+ name : string ;
78+ value : string ;
79+ type : ComponentPropertyType ;
80+ }
81+
7482export interface SimplifiedNode {
7583 id : string ;
7684 name : string ;
@@ -92,7 +100,7 @@ export interface SimplifiedNode {
92100 // backgroundColor?: ColorValue; // Deprecated by Figma API
93101 // for rect-specific strokes, etc.
94102 componentId ?: string ;
95- componentProperties ?: Record < string , any > ;
103+ componentProperties ?: ComponentProperties [ ] ;
96104 // children
97105 children ?: SimplifiedNode [ ] ;
98106}
@@ -239,8 +247,16 @@ function parseNode(
239247 if ( hasValue ( "componentId" , n ) ) {
240248 simplified . componentId = n . componentId ;
241249 }
250+
251+ // Add specific properties for instances of components
242252 if ( hasValue ( "componentProperties" , n ) ) {
243- simplified . componentProperties = n . componentProperties ;
253+ simplified . componentProperties = Object . entries ( n . componentProperties ?? { } ) . map (
254+ ( [ name , { value, type } ] ) => ( {
255+ name,
256+ value : value . toString ( ) ,
257+ type,
258+ } ) ,
259+ ) ;
244260 }
245261 }
246262
@@ -308,8 +324,9 @@ function parseNode(
308324 simplified . borderRadius = `${ n . rectangleCornerRadii [ 0 ] } px ${ n . rectangleCornerRadii [ 1 ] } px ${ n . rectangleCornerRadii [ 2 ] } px ${ n . rectangleCornerRadii [ 3 ] } px` ;
309325 }
310326
311- // Recursively process child nodes
312- if ( hasValue ( "children" , n ) && Array . isArray ( n . children ) && n . children . length > 0 ) {
327+ // Recursively process child nodes.
328+ // Include children at the very end so all relevant configuration data for the element is output first and kept together for the AI.
329+ if ( hasValue ( "children" , n ) && n . children . length > 0 ) {
313330 const children = n . children
314331 . filter ( isVisible )
315332 . map ( ( child ) => parseNode ( globalVars , child , n ) )
0 commit comments