@pedroab0/skills 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -2
- package/bin/cli.js +748 -0
- package/figma-extractor/README.md +170 -0
- package/figma-extractor/SKILL.md +199 -0
- package/figma-extractor/demo/desktop_home.json +2434 -0
- package/figma-extractor/demo/dt_money_desktop_home.png +0 -0
- package/figma-extractor/demo/dt_money_preview.png +0 -0
- package/figma-extractor/demo/dt_money_selection.json +472 -0
- package/figma-extractor/demo/index.html +188 -0
- package/figma-extractor/demo/style.css +360 -0
- package/figma-extractor/figma-plugin/README.md +70 -0
- package/figma-extractor/figma-plugin/code.js +407 -0
- package/figma-extractor/figma-plugin/manifest.json +10 -0
- package/figma-extractor/figma-plugin/ui.html +470 -0
- package/figma-extractor/scripts/fetch_figma.js +1314 -0
- package/figma-extractor/scripts/test_fetch_figma.js +601 -0
- package/figma-node-builder/README.md +107 -0
- package/figma-node-builder/SKILL.md +113 -0
- package/figma-node-builder/scripts/inspect_spec.js +514 -0
- package/figma-node-builder/scripts/test_inspect_spec.js +148 -0
- package/figma-to-code/README.md +160 -0
- package/figma-to-code/SKILL.md +211 -0
- package/figma-to-code/scripts/fetch_figma.js +1251 -0
- package/figma-to-code/scripts/test_fetch_figma.js +581 -0
- package/package.json +39 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Figma To Code
|
|
2
|
+
|
|
3
|
+
A lightweight, token-efficient skill designed for AI coding agents to turn Figma designs into clean UI code.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Why Replace Figma MCP?
|
|
8
|
+
|
|
9
|
+
Standard Figma MCP (Model Context Protocol) servers are often too heavy for coding tasks. They flood your model with massive, unpruned design files and lack awareness of your design system.
|
|
10
|
+
|
|
11
|
+
### Comparison Table
|
|
12
|
+
|
|
13
|
+
| Feature | Standard Figma MCP | Figma Extractor Skill |
|
|
14
|
+
| :--- | :--- | :--- |
|
|
15
|
+
| **Token Usage** | Very heavy (50k to 150k+ tokens). Dumps raw vector points, animation curves, and internal metadata. | Ultra-compact (2k to 8k tokens). Strips out 90% of noise, keeping only layout and styles. |
|
|
16
|
+
| **Design System** | Returns raw values (hex color codes, exact pixel sizes). | Resolves Figma Variables into semantic tokens (primary colors, spacing scale, corner radii). |
|
|
17
|
+
| **Component Reuse** | Dumps every internal layer of a component, causing the AI to recreate it as generic divs. | Collapses component layers into clean props, encouraging the AI to reuse your existing components. |
|
|
18
|
+
| **Visual Previews** | Requires multiple slow round-trips to find and download images. | Single step: extracts the layout and downloads a rendered image preview at the same time. |
|
|
19
|
+
| **Reliability** | Requires a persistent background daemon that can crash, hang, or disconnect. | Zero background processes. Runs on-demand as a lightweight script with zero dependencies. |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## When to Still Use Figma MCP
|
|
24
|
+
|
|
25
|
+
A standard MCP server is only better if:
|
|
26
|
+
- You need to **write** to Figma (create layers, post comments).
|
|
27
|
+
- Your AI environment completely blocks command-line tools.
|
|
28
|
+
- Your organization enforces interactive browser-based OAuth logins instead of access tokens.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## How It Works (Step-by-Step)
|
|
33
|
+
|
|
34
|
+
The extraction happens in a simple 5-step pipeline:
|
|
35
|
+
|
|
36
|
+
1. **Authentication & Link Parsing**
|
|
37
|
+
Reads your Figma access token and automatically parses any Figma link (file, frame, or specific component).
|
|
38
|
+
|
|
39
|
+
2. **Design Token Collection**
|
|
40
|
+
Queries Figma's local variables first to build a clean dictionary of your design tokens (colors, spacing scale, border radii, and typography).
|
|
41
|
+
|
|
42
|
+
3. **Targeted Retrieval**
|
|
43
|
+
Fetches only the specific frame or component from the Figma API instead of downloading the entire canvas.
|
|
44
|
+
|
|
45
|
+
4. **Smart Cleanup & Pruning**
|
|
46
|
+
- **Removes noise**: Discards vector bezier paths, render matrices, and prototyping data.
|
|
47
|
+
- **Preserves layout**: Keeps flex direction, alignment, gap, padding, dimensions, and typography.
|
|
48
|
+
- **Maps tokens**: Pairs raw values with their corresponding design token names.
|
|
49
|
+
- **Simplifies components**: Replaces complex internal sub-layers with a clean component name and ready-to-use props.
|
|
50
|
+
|
|
51
|
+
5. **Visual Asset Download & Delivery**
|
|
52
|
+
Downloads a sharp PNG preview of the frame to a local folder and delivers the cleaned data directly to the AI agent.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## How to Use the Skill
|
|
57
|
+
|
|
58
|
+
### 1. Prerequisites: Create & Set Your Figma Token
|
|
59
|
+
|
|
60
|
+
#### How to Create the Token:
|
|
61
|
+
1. In Figma, click your profile avatar and select **Settings**.
|
|
62
|
+
2. Select the **Security** tab and scroll to **Personal access tokens**.
|
|
63
|
+
3. Click **Generate new token**, enter a description (e.g., `ai-extractor`), and ensure read access is enabled (`File content: Read`, `Variables: Read`).
|
|
64
|
+
4. Copy the generated token (starts with `figd_`).
|
|
65
|
+
|
|
66
|
+
#### How to Set the Token in Terminal:
|
|
67
|
+
Choose one of the following terminal commands:
|
|
68
|
+
|
|
69
|
+
- **Add to your project `.env` file (Recommended)**:
|
|
70
|
+
```bash
|
|
71
|
+
echo 'FIGMA_ACCESS_TOKEN="figd_your_token_here"' >> .env
|
|
72
|
+
```
|
|
73
|
+
- **Set for current terminal session only**:
|
|
74
|
+
```bash
|
|
75
|
+
export FIGMA_ACCESS_TOKEN="figd_your_token_here"
|
|
76
|
+
```
|
|
77
|
+
- **Persist globally across all terminal sessions (`~/.zshrc`)**:
|
|
78
|
+
```bash
|
|
79
|
+
echo 'export FIGMA_ACCESS_TOKEN="figd_your_token_here"' >> ~/.zshrc && source ~/.zshrc
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
*(Optional: If behind a corporate proxy with self-signed SSL certificates, run `echo 'FIGMA_IGNORE_SSL=true' >> .env`).*
|
|
83
|
+
|
|
84
|
+
### 2. Invoking via AI Coding Agent
|
|
85
|
+
Flags are **completely optional** — you do not have to specify any flags:
|
|
86
|
+
- **Default (No flags needed)**: Simply share a Figma link or ask the agent to inspect a frame. The agent detects the link and runs the extractor automatically with default settings (clean, token-optimized JSON).
|
|
87
|
+
- **Optional Guidance**: You can optionally guide the agent using natural language or by mentioning specific flags:
|
|
88
|
+
- *"Inspect this frame and download a preview image"* (agent uses `--image` or `-i`).
|
|
89
|
+
- *"Only extract the design tokens from this file"* (agent uses `--tokens`).
|
|
90
|
+
- *"Collapse component sub-layers into props"* (agent uses `--shallow-instances`).
|
|
91
|
+
- **Tip (Guarantee Autonomous Invocation)**: To ensure the agent never skips the extractor and never estimates CSS without extracting, add this suggestion to your project's `GEMINI.md` or `AGENTS.md`:
|
|
92
|
+
```markdown
|
|
93
|
+
## Figma UI Development
|
|
94
|
+
Whenever a Figma link is provided or you are asked to build UI from Figma:
|
|
95
|
+
1. Use the `figma-to-code` skill to extract design tokens, component props, and preview images.
|
|
96
|
+
2. Ground all styling and component props in the extracted data rather than guessing CSS.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 3. Manual Command Formats
|
|
100
|
+
You can also run the script directly from your terminal:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Basic JSON extraction (compact layout & styling to stdout)
|
|
104
|
+
node figma-to-code/scripts/fetch_figma.js "<FigmaURL>"
|
|
105
|
+
|
|
106
|
+
# JSON + automatically download a rendered image preview
|
|
107
|
+
node figma-to-code/scripts/fetch_figma.js "<FigmaURL>" -i
|
|
108
|
+
|
|
109
|
+
# Save preview image to a custom local path
|
|
110
|
+
node figma-to-code/scripts/fetch_figma.js "<FigmaURL>" -o ./.specs/preview.png
|
|
111
|
+
|
|
112
|
+
# Extract only design tokens (colors, spacing, radii)
|
|
113
|
+
node figma-to-code/scripts/fetch_figma.js "<FigmaURL>" --tokens
|
|
114
|
+
|
|
115
|
+
# Collapse component layers into clean props
|
|
116
|
+
node figma-to-code/scripts/fetch_figma.js "<FigmaURL>" -i --shallow-instances
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Available Flags
|
|
122
|
+
|
|
123
|
+
| Flag | Shorthand | Description |
|
|
124
|
+
| :--- | :--- | :--- |
|
|
125
|
+
| `--image`, `--download-image` | `-i` | Download and save rendered preview image from Figma (Tier 1 call; optional). |
|
|
126
|
+
| `--image-path <path>` | `-o <path>` | Custom destination path for saved preview image (e.g., `./.specs/card.png`). |
|
|
127
|
+
| `--tokens`, `--variables` | | Export only the file's design token dictionary (colors, spacing, radii). |
|
|
128
|
+
| `--shallow-instances` | | Collapse internal layers of component instances into clean props. |
|
|
129
|
+
| `--include-tokens` | | Bundle complete design tokens dictionary alongside the node tree. |
|
|
130
|
+
| `--include-ids` | | Retain Figma internal node IDs in the returned output. |
|
|
131
|
+
| `--pretty` | | Format output with readable 2-space indentation (default is compact single-line JSON). |
|
|
132
|
+
| `--raw` | | Return full unpruned Figma API response without filtering. |
|
|
133
|
+
| `--depth <number>` | | Limit node tree traversal depth (e.g., `--depth 2` for top-level layout only). |
|
|
134
|
+
| `--scale <1\|2\|3\|4>` | | Multiplier for rendered image resolution (default: `2`). |
|
|
135
|
+
| `--format <png\|svg\|jpg>` | | Image format for downloaded preview (default: `png`). |
|
|
136
|
+
| `--no-variables` | | Skip querying local variables to speed up extraction. |
|
|
137
|
+
| `--help` | `-h` | Display command usage and available flags. |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Available Resources
|
|
142
|
+
|
|
143
|
+
The skill includes the following resources:
|
|
144
|
+
|
|
145
|
+
- **Agent Instruction Guide (`SKILL.md`)**: The core skill definition read by AI agents (Antigravity, Claude Code, Cursor, Codex) containing workflow triggers and pair-programming guidelines.
|
|
146
|
+
- **Core Extraction Script (`scripts/fetch_figma.js`)**: The standalone, zero-dependency Node.js script that interfaces with the Figma REST API, resolves tokens, prunes the AST, and downloads preview images.
|
|
147
|
+
- **Unit Test Suite (`scripts/test_fetch_figma.js`)**: A suite of 39 automated unit tests verifying URL parsing, token formatting, component prop cleaning, rate-limit gates, and node pruning without requiring network access.
|
|
148
|
+
- **Specification Directory (`.specs/`)**: The local workspace directory where downloaded image previews are stored for multimodal visual inspection.
|
|
149
|
+
- **Reference Documentation (`README.md`)**: This guide explaining architecture, MCP comparison, and operational flags.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## How AI Agents Build UI From This Data
|
|
154
|
+
|
|
155
|
+
- **Use Existing Components**: When the output identifies a component name and props, the agent imports that component instead of building it from scratch.
|
|
156
|
+
- **Apply Design Tokens**: When spacing or color tokens are present, the agent applies framework classes (like Tailwind) or CSS variables instead of hardcoded numbers.
|
|
157
|
+
- **Match Flexbox Layout**: Layout directions, gaps, and alignments directly translate to standard CSS Flexbox or Grid properties.
|
|
158
|
+
- **Resolve Icons Cleanly**: Reuses existing project icons/assets (`components/icons/`, `src/assets/`, `public/`) or installed libraries (`lucide-react`, `@heroicons/react`), preventing hallucinated SVG paths.
|
|
159
|
+
- **Style Image Layers**: Applies exact dimensions, border radius, and object-fit from Figma image fills, leaving clean `<img>` tags with `TODO` markers.
|
|
160
|
+
- **Cross-Check Visually**: The agent inspects the downloaded preview image to ensure the final code matches the designer's intent.
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: figma-to-code
|
|
3
|
+
description: 'Directly convert Figma designs into clean, production-ready UI code in a single turn using the Figma REST API. Trigger this skill whenever the user provides a Figma link and asks to generate, code, build, or implement UI components directly without an intermediate specification review.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Figma To Code Skill
|
|
7
|
+
|
|
8
|
+
Directly convert Figma designs into clean, production-ready UI components in a single turn.
|
|
9
|
+
|
|
10
|
+
This skill connects to the Figma REST API, extracts a compact design-system-aware AST, resolves variables into semantic design tokens, and immediately generates the target component code grounded in your project's existing design system and components.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Strict Guardrails: No Browser Scraping / Automation
|
|
15
|
+
|
|
16
|
+
> [!CAUTION]
|
|
17
|
+
> **NEVER use browser tools (Playwright, Puppeteer, Chrome DevTools, `browser_navigate`, `read_browser_page`) on Figma URLs.**
|
|
18
|
+
>
|
|
19
|
+
> 1. **Figma Canvas is WebGL/Wasm**: Figma renders design canvas elements inside an HTML5 `<canvas>` via WebAssembly. There are NO inspectable HTML DOM elements for frames, layers, texts, or styles. Browser automation cannot extract Figma nodes or properties.
|
|
20
|
+
> 2. **Never search `/Applications` for browsers**: Do not search for installed browser binaries or run browser automation scripts.
|
|
21
|
+
> 3. **API Errors Are Final**: If `fetch_figma.js` returns an API error (e.g., 401 Unauthorized, 403 Forbidden, or 429 Rate Limited), **report the error directly to the user**. Guide them to check their `FIGMA_ACCESS_TOKEN`, permissions, or wait out rate limits. Do NOT attempt browser scraping fallbacks.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Built-in Rate-Limit Gate & Circuit Breaker
|
|
26
|
+
|
|
27
|
+
To protect your Figma file quota and prevent lockout penalties, `fetch_figma.js` enforces an automatic safety gate:
|
|
28
|
+
* **Max 5 requests per minute** per file key (sliding window limit).
|
|
29
|
+
* **2.5s inter-request pacing** between consecutive requests.
|
|
30
|
+
* **Persistent Circuit Breaker**: If Figma returns HTTP 429, the script records the lockout time locally in `~/.figma_ratelimit.json`. All future calls to that file key are **immediately blocked with zero network traffic**, preventing Figma from extending the lockout penalty.
|
|
31
|
+
|
|
32
|
+
### Agent Behavioral Rules (Zero-Hammer Protocol)
|
|
33
|
+
1. **Single-Shot Execution**: Run `fetch_figma.js` **once** per target frame or component.
|
|
34
|
+
2. **Never Retry on Failure**: If `fetch_figma.js` returns an error, **DO NOT retry in a loop**. Report the error directly to the user.
|
|
35
|
+
3. **Handling `FIGMA_CIRCUIT_BREAKER_ACTIVE`**: If the circuit breaker trips, inform the user that the file key is on cooldown, and suggest duplicating the file in Figma Drafts (Right-click $\rightarrow$ **Duplicate**) to get a fresh URL.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Prerequisites
|
|
40
|
+
|
|
41
|
+
A Figma Access Token (Personal Access Token or OAuth Token) is required.
|
|
42
|
+
|
|
43
|
+
Configure it using either:
|
|
44
|
+
1. **Environment Variable**: `export FIGMA_ACCESS_TOKEN="figd_your_token_here"` or `export FIGMA_TOKEN="..."`
|
|
45
|
+
2. **Workspace `.env` File**:
|
|
46
|
+
```env
|
|
47
|
+
FIGMA_ACCESS_TOKEN=figd_your_token_here
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Corporate Proxy & SSL Certificates
|
|
51
|
+
If you are behind a corporate proxy or firewall with self-signed SSL certificates, enable SSL verification bypass:
|
|
52
|
+
```env
|
|
53
|
+
FIGMA_IGNORE_SSL=true
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Tier 1 Quota Conservation: AST-Only by Default
|
|
57
|
+
|
|
58
|
+
> [!IMPORTANT]
|
|
59
|
+
> **Figma Starter plans enforce a strict limit of 20 Tier 1 requests/month.**
|
|
60
|
+
> Both `GET /v1/files/:key/nodes` and `GET /v1/images/:key` count as Tier 1 endpoints.
|
|
61
|
+
>
|
|
62
|
+
> 1. **Default to AST-only extraction**: Extracting AST without `-i` consumes **only 1 Tier 1 call**. The JSON AST contains 100% of layout rules (flexbox, padding, gap), dimensions, hex colors, corner radii, and text content needed for code generation.
|
|
63
|
+
> 2. **DO NOT pass `-i` / `--image` by default**: Only add `-i` if the user explicitly requests downloading a visual preview screenshot.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Agent Execution Instructions
|
|
68
|
+
|
|
69
|
+
To extract and build UI from a Figma URL, run `fetch_figma.js` from the skill's scripts directory:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Recommended: Extract compact AST (1 Tier 1 call)
|
|
73
|
+
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>"
|
|
74
|
+
|
|
75
|
+
# Optional: With companion preview image (2 Tier 1 calls)
|
|
76
|
+
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>" -i
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Script Path Resolution**:
|
|
80
|
+
- **Global Antigravity install**: `node ~/.gemini/config/skills/figma-to-code/scripts/fetch_figma.js "<FigmaURL>"`
|
|
81
|
+
- **Global Claude Code install**: `node ~/.claude/skills/figma-to-code/scripts/fetch_figma.js "<FigmaURL>"`
|
|
82
|
+
- **Project local install**: `node figma-to-code/scripts/fetch_figma.js "<FigmaURL>"`
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Usage & Command Formats
|
|
87
|
+
|
|
88
|
+
### 1. Basic One-Shot Code Generation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Standard extraction (1 Tier 1 call - recommended)
|
|
92
|
+
node figma-to-code/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474"
|
|
93
|
+
|
|
94
|
+
# Optional: With preview image (2 Tier 1 calls)
|
|
95
|
+
node figma-to-code/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" -i
|
|
96
|
+
|
|
97
|
+
# Collapse internal layers of component instances into props (guides agent to reuse existing components)
|
|
98
|
+
node figma-to-code/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" --shallow-instances
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 2. CLI Flags Reference
|
|
102
|
+
|
|
103
|
+
| Flag | Shorthand | Description |
|
|
104
|
+
| :--- | :--- | :--- |
|
|
105
|
+
| `--image`, `--download-image` | `-i` | Download and save rendered preview image from Figma (Tier 1 call; optional). |
|
|
106
|
+
| `--image-path <path>` | `-o <path>` | Custom local file path to save preview image (implies `--image`). |
|
|
107
|
+
| `--tokens`, `--variables` | | Output only the design token dictionary (colors, spacing, radii) for theme setup. |
|
|
108
|
+
| `--shallow-instances` | | Collapse internal sub-layers of component instances into clean props. |
|
|
109
|
+
| `--pretty` | | Pretty-print JSON with 2-space indentation (default is compact single-line JSON). |
|
|
110
|
+
| `--include-tokens` | | Include full design tokens dictionary alongside node AST. |
|
|
111
|
+
| `--include-ids` | | Retain internal Figma node IDs on each node in the tree. |
|
|
112
|
+
| `--raw` | | Return full, unpruned raw Figma API AST. |
|
|
113
|
+
| `--depth <number>` | | Limit node tree traversal depth (e.g. `--depth 2` for top-level overview). |
|
|
114
|
+
| `--scale <1\|2\|3\|4>` | | Render resolution multiplier for preview images (default: `2`). |
|
|
115
|
+
| `--format <png\|svg\|jpg>` | | Rendered image file format (default: `png`). |
|
|
116
|
+
| `--no-variables` | | Skip querying `/variables/local`. |
|
|
117
|
+
| `--help` | `-h` | Show help message. |
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Output Structure & Design-System Awareness
|
|
122
|
+
|
|
123
|
+
### 1. Resolved Design Tokens
|
|
124
|
+
When a layer uses Figma variables (design tokens), the extractor attaches semantic token names alongside the computed values:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"name": "Card Container",
|
|
129
|
+
"type": "FRAME",
|
|
130
|
+
"layoutMode": "VERTICAL",
|
|
131
|
+
"padding": { "top": 16, "right": 16, "bottom": 16, "left": 16 },
|
|
132
|
+
"paddingToken": "spacing/md",
|
|
133
|
+
"itemSpacing": 12,
|
|
134
|
+
"itemSpacingToken": "spacing/sm",
|
|
135
|
+
"cornerRadius": 8,
|
|
136
|
+
"cornerRadiusToken": "radii/lg",
|
|
137
|
+
"fills": [
|
|
138
|
+
{
|
|
139
|
+
"type": "SOLID",
|
|
140
|
+
"color": "#1877F2",
|
|
141
|
+
"token": "colors/brand/primary"
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 2. Normalized Component Instances & Props
|
|
148
|
+
When an `INSTANCE` node is present, internal property hashes are converted into clean JavaScript props and linked to the master component name:
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"name": "Submit Button",
|
|
153
|
+
"type": "INSTANCE",
|
|
154
|
+
"component": {
|
|
155
|
+
"name": "Button",
|
|
156
|
+
"variant": "Variant=Primary, Size=Large"
|
|
157
|
+
},
|
|
158
|
+
"props": {
|
|
159
|
+
"variant": "Primary",
|
|
160
|
+
"size": "Large",
|
|
161
|
+
"hasIcon": true,
|
|
162
|
+
"label": "Confirm Order"
|
|
163
|
+
},
|
|
164
|
+
"bounds": { "width": 140, "height": 44 }
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## How to Build Components from the Extracted Data
|
|
171
|
+
|
|
172
|
+
When synthesizing code from the output:
|
|
173
|
+
|
|
174
|
+
1. **Using Existing UI Components**:
|
|
175
|
+
- For `INSTANCE` nodes with resolved `component.name` and `props`:
|
|
176
|
+
- Check if your codebase already has this component (e.g. `<Button />`, `<Input />`, `<Modal />`).
|
|
177
|
+
- Directly render: `<Button variant="primary" size="large" hasIcon>Confirm Order</Button>` instead of building raw HTML divs.
|
|
178
|
+
2. **Applying Semantic Design Tokens**:
|
|
179
|
+
- When a `token` is present (e.g., `colors/brand/primary`, `spacing/md`):
|
|
180
|
+
- Map to your project's Tailwind class (`bg-brand-primary`, `p-md`, `rounded-lg`) or CSS variable (`var(--color-brand-primary)`).
|
|
181
|
+
- Avoid hardcoding hex colors or pixel values when tokens are available.
|
|
182
|
+
3. **Layout & Flexbox**:
|
|
183
|
+
- `HORIZONTAL` $\rightarrow$ `flex flex-row` (`display: flex; flex-direction: row;`).
|
|
184
|
+
- `VERTICAL` $\rightarrow$ `flex flex-col` (`display: flex; flex-direction: column;`).
|
|
185
|
+
- `itemSpacing` $\rightarrow$ CSS `gap`.
|
|
186
|
+
- `primaryAxisAlignItems` & `counterAxisAlignItems` $\rightarrow$ `justify-*` and `items-*`.
|
|
187
|
+
4. **Icon & Vector Resolution Hierarchy**:
|
|
188
|
+
- For `VECTOR` nodes or icon instances, normalize the name (strip prefixes `icon/`, `ic_`, `ico-`).
|
|
189
|
+
- **Step 1 (Targeted Local Assets/Components)**: Look for matching files in `components/icons/`, `src/assets/`, or `public/` (e.g. `<SearchIcon />`, `/icons/search.svg`). Avoid unbounded repo searches.
|
|
190
|
+
- **Step 2 (Installed Icon Library)**: If not found, import from packages in `package.json` (e.g., `lucide-react`, `@heroicons/react`).
|
|
191
|
+
- **Step 3 (Semantic Fallback)**: If not found, render an accessible placeholder (`<span className="..." aria-hidden="true" />`) with a `TODO: Missing icon 'name'` comment. Never hallucinate raw SVG `<path d="...">` coordinates.
|
|
192
|
+
5. **Image Layer Handling (`fills: [{ type: "IMAGE" }]`)**:
|
|
193
|
+
- Focus exclusively on applying the exact styling from the Figma spec: dimensions (`width`, `height`), border radius (`rounded-*`), and scale mode (`scaleMode: "FILL"` $\rightarrow$ `object-cover`, `"FIT"` $\rightarrow$ `object-contain`).
|
|
194
|
+
- Do **NOT** attempt to resolve, fetch, or hallucinate image files or external URLs (never invent Unsplash or third-party links).
|
|
195
|
+
- Render a standard `<img>` tag with `src=""` and a concise `TODO` comment specifying the target image layer.
|
|
196
|
+
6. **Visual Verification**:
|
|
197
|
+
- Inspect the downloaded preview image (`output.image.path`) to ensure pixel-perfect fidelity.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Error Handling & Troubleshooting
|
|
202
|
+
|
|
203
|
+
- **Token Expired / Missing (`FIGMA_TOKEN_EXPIRED_OR_INVALID` / `isTokenExpiredOrInvalid`)**:
|
|
204
|
+
- Alert the user that their Figma access token is missing, invalid, or expired.
|
|
205
|
+
- Instruct the user to create a token in **Figma Settings $\rightarrow$ Personal Access Tokens** and export `FIGMA_ACCESS_TOKEN=your_token` or update `.env`.
|
|
206
|
+
- **Node Not Found**:
|
|
207
|
+
- Alert the user that the node ID could not be found in the specified file.
|
|
208
|
+
- **Corporate Proxy / Self-Signed SSL (`FIGMA_SSL_CERTIFICATE_ERROR`)**:
|
|
209
|
+
- Instruct the user to add `FIGMA_IGNORE_SSL=true` to `.env` or export it in their environment.
|
|
210
|
+
- **Rate Limited (`FIGMA_RATE_LIMIT_EXCEEDED` / `FIGMA_CIRCUIT_BREAKER_ACTIVE`)**:
|
|
211
|
+
- Figma REST API has strict per-minute and monthly rate limits. If rate limited or the circuit breaker trips, report the cooldown to the user and suggest duplicating the file in Figma Drafts to get a fresh URL.
|