We are building a tool that converts figma design to code. To achieve this, we convert all figma groups and elements into our own Design System Language(I hope you know about DSL right? if not, learn it).
export interface Coords {
x: number;
y: number;
height: number;
width: number;
}
export interface DhiwiseJson {
isSplashScreen: boolean; // if this is root screen or not
categorySequence: string; //ignore
isContainScroll: boolean; //ignore
screen: ScreenJson; // This contains whole heirarchy of page with DSL, it is object and every element will have children key which will contain data if it has nested elements. It's same as DOM heirarchy
screenName: string; // Screen name, we use it for page name and route name
isVisible: boolean; //ignore
categoryName: string; //ignore
screenId: string; //unique id of that page
path: string; //ignore
assets: string[]; //all images or fonts path
thumbnailPath: string; // ignore
screenTag: screenTag; //ignore
categoryId: string; //ignore
height: string; //element height defined in figma
width: string; //element width defined in figma
}
type DirectionTopBottom = {
bottomLeft: number;
bottomRight: number;
topLeft: number;
topRight: number;
};
export interface Background {
color: string;
cornerRadius?: DirectionTopBottom;
[key: string]: any;
}
interface TopLeftBottomRight {
top: number;
bottom: number;
left: number;
right: number;
}
type viewTag = "PreviousSliderControl" | "NextSliderControl" | "TabContent" | "header" | "Tab" | "Chart" | "ExpandIcon" | "CollapseIcon" | "ExpandItem" | "ExpandHeader" | "TableHeader" | "TableData" | "Sidebar" | "ImageMagnifier"
export interface BaseScreenJson {
styleReference?: string; // it includes mapping to other file where all styles like color, background color, shadow and many more of current elemnt
tempZIndex?: number; // it includes z-index of this element as compared to another elements
mainAxisSize?: string; // ignore
mainAxisAlignment: string; // it includes start,center or end. If "type" is "Row" then alignment will be for horizontal direction, if "type" is "Column" then alignment will be for vertical direction
crossAxisAlignment: string;// it includes start,center or end. If "type" is "Column" then alignment will be for horizontal direction, if "type" is "Row" then alignment will be for vertical direction
flutterMargin?: TopLeftBottomRight; //it includes margin of that element from all 4 direction
padding?: TopLeftBottomRight; // it includes padding of that element that needs to be applied from all 4 direction
viewTag?: viewTag; // it includes element type in terms of HTML element view such as previous slider button, tabs, tab content, table's header, table's data(body), Sidebar in admin apps, header, footer etc
isNewGroup?: boolean; // if this group was custom created while generating DSL or from figma
layoutGravity?: number; // layoutGravity indicates where should current element be placed with respect to its parent. 1= top left, 3= top center, 2=top right, 4= center left, 9= center center, 5= center right, 6=bottom left, 8= bottom center, 7= bottom bottom
gravity?: number; // gravity indicates where should current element be placed. 1= top left, 3= top center, 2=top right, 4= center left, 9= center center, 5= center right, 6=bottom left, 8= bottom center, 7= bottom bottom. We only use this gravity when element is having "type"="Text"
isCustomGroup?: boolean; //ignore
originalWidth?: number;//ignore
type: string; //type includes element type, you can check exported interface below which extends BaseScreenJson
old_name: string;
background: Background; // this includes Background style object which includes color or image or shadow etc
children: ScreenJson[]; // it's nested structure that represents this element's structure
name: string; //name of this element
id: string; //unique id of this element
zIndex: number;// z-index of this element respective to other elements in DSL
isListChild: string; // This key holds the "id" of element whose "type" is "List". If this key is present then it means this element is direct or indirect children of that List
rotation: number; //rotation angle value
[key: string]: any;
styles?: {
shape: string & { [key: string]: any }[];
size: string & { [key: string]: any }[];
variant: string & { [key: string]: any }[];
fontStyle: string & { [key: string]: any }[];
};
}
type TextStyle = {
textAutoResize: string; // should text be resized or not
paragraphSpacing: number; // by how much spacing we need to apply in paragraph
textAlignVertical: string; // how to vertically align text, top, bottom or center
lineHeightPx: number; // line height in "px"
letterSpacing: number; // letter spacing in "px"
fontPostScriptName: string; // font family name, most probably it will be from google fonts
lineHeightPercent: number; // line height in "%"
path: string; //ignore
displayStyle: string; //ignore
fontFamily: string; //font family that's applied in figma
textAlignHorizontal: string;//how to horizontally align text, top, bottom or center
lineHeightUnit: string;//unit that needs to be applied in line height
fontSize: number; // font-size in "px"
fontWeight: number; //font-weight in number value
};
type TextBound = {
endX: number;
bottomY: number;
} & Coords;
interface SharedRowColumn {
divideColumn: string | boolean;
imaginaryList: boolean;
listSpace: number;
}
export interface Row extends BaseScreenJson, SharedRowColumn {
type: "Row";
isFixWidth: boolean;
isDividedRow: boolean;
}
export interface Column extends BaseScreenJson, SharedRowColumn {
type: "Column";
isInfinite: boolean;
}
export interface Stack extends BaseScreenJson {
isNewStack?: boolean;
isNotScroll?: boolean;
type: "Stack";
}
export interface Grid extends BaseScreenJson {
gridSpace: number;
spanCount: number;
}
type ImageProperties = {
isSvg: boolean;
scale: string;
vector: string;
};
type UseColorsProperties = {
color: string;
count: number;
};
export interface Image extends BaseScreenJson {
type: "Image";
image: ImageProperties;
useColors: UseColorsProperties[];
}
export interface CircleImage extends BaseScreenJson {
type: "CircleImage";
image: ImageProperties;
useColors: UseColorsProperties[];
cornerRadius: DirectionTopBottom;
}
type TextProperties = {
textSize: number;
color: string;
text: string;
textStyle: TextStyle;
textBound: TextBound;
};
export interface Text extends BaseScreenJson, TextProperties {
type: "Text";
isMultiline: boolean;
spanText: Omit;
}
export interface View extends BaseScreenJson {
radius?: DirectionTopBottom;
}
export interface Button extends BaseScreenJson, TextProperties {
type: "Button";
}
export interface Line extends BaseScreenJson {
type: "Line";
}
export interface List extends BaseScreenJson {
type: "List";
orientation: string;
listSpace: number;
}
export interface Header extends BaseScreenJson {
type: "Header";
viewTag: "Header";
}
export interface Footer extends BaseScreenJson {
type: "Footer";
viewTag: "Footer";
}
export interface EditTextBase extends BaseScreenJson {
type: "EditText";
editTextStyle: string;
hintText: {
styleReference?: string;
} & TextProperties;
isTextArea: boolean;
}
type EditText = EditTextBase & Omit;
export interface Table extends BaseScreenJson {
type: "Table"
libraryType: string
}
export type MergedScreenJson =
| Row
| Column
| Stack
| Grid
| Image
| CircleImage
| Text
| View
| Button
| Line
| List
| Header
| Footer
| EditText
| Table;
export type ScreenJson = MergedScreenJson & Coords;
Can you learn the structure? I have added basic explanation in comments where possible. Any key not having comment, you can guess from its name. I have kept all names relevant to its use case.