@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,107 @@
|
|
|
1
|
+
# Figma Node Builder
|
|
2
|
+
|
|
3
|
+
An AI coding agent skill that synthesizes extracted Figma Node specifications (`.specs/*.json`) and rendered preview images (`.specs/*.png`) into production-grade, grounded UI components.
|
|
4
|
+
|
|
5
|
+
This skill serves as the **Implementation Layer (Step 2)** in a **Spec-Driven Development (SDD)** workflow.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why Spec-Driven UI Building?
|
|
10
|
+
|
|
11
|
+
In traditional AI coding, developers often ask an LLM to build a component with only a screenshot or a raw Figma URL. The model guesses paddings, hallucinates arbitrary hex codes, builds nested `<div>` soup, and recreates components that already exist in your codebase.
|
|
12
|
+
|
|
13
|
+
**`figma-node-builder` fixes this by grounding the AI in a formal specification contract**:
|
|
14
|
+
|
|
15
|
+
| Traditional Vibe Coding | Spec-Driven with `figma-node-builder` |
|
|
16
|
+
| :--- | :--- |
|
|
17
|
+
| Guesses random spacing (`padding: 23px`) | Uses exact resolved tokens (`spacing/md` $\rightarrow$ `p-4`) |
|
|
18
|
+
| Guesses arbitrary hex codes (`#1f2937`) | Maps to semantic tokens (`colors/brand/primary`) or CSS variables |
|
|
19
|
+
| Re-invents existing buttons as raw `<div>`s | Inspects your codebase and renders `<Button variant="outline" />` |
|
|
20
|
+
| Requires Figma API access & credentials | **100% offline**: runs directly on local `.specs/` files |
|
|
21
|
+
| No automated visual verification | Compares rendered DOM against `.specs/<name>.png` |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## How It Fits into SDD
|
|
26
|
+
|
|
27
|
+
```mermaid
|
|
28
|
+
flowchart LR
|
|
29
|
+
A["Figma Design"] -->|1. figma-extractor| B["Specification Contract<br/>.specs/card.json + .png"]
|
|
30
|
+
B -->|Review & Approval| C["Plan / Gap Analysis"]
|
|
31
|
+
C -->|2. figma-node-builder| D["Production Component<br/>(React, Vue, Tailwind)"]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
1. **Step 1 (Ingest)**: Design specifications are extracted into `./.specs/card.json` (and optional companion `./.specs/card.png`) using either [`figma-extractor`](../figma-extractor) (CLI / API) or the **Figma Node JSON Extractor** (Figma Desktop plugin).
|
|
35
|
+
2. **Review**: The human developer or architect reviews the tokens, components, and layout bounds.
|
|
36
|
+
3. **Step 2 (Build)**: **`figma-node-builder`** is invoked to build the component in your project.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## The 4-Phase Protocol
|
|
41
|
+
|
|
42
|
+
When invoked, the agent systematically executes four phases:
|
|
43
|
+
|
|
44
|
+
### Phase 1: Codebase Discovery
|
|
45
|
+
* Scans `package.json` to detect your framework (React, Vue, Svelte, Next.js, HTML/CSS) and installed icon libraries (e.g. `lucide-react`, `@heroicons/react`).
|
|
46
|
+
* Scans `components/` or `src/components/` for existing design system primitives (`Button`, `Input`, `Card`, `Badge`) and local icon directories (`components/icons/`, `src/assets/`, `public/`).
|
|
47
|
+
* Inspects `tailwind.config.js` or CSS variables to discover configured design tokens.
|
|
48
|
+
|
|
49
|
+
### Phase 2: Gap Analysis & Token Mapping
|
|
50
|
+
* Analyzes the `.specs/<name>.json` AST.
|
|
51
|
+
* Pairs Figma component instances (`INSTANCE`) to your codebase components and maps their variant props.
|
|
52
|
+
* Maps Figma design tokens (`spacing/md`, `colors/brand/primary`) to your project's styling system.
|
|
53
|
+
* Identifies any missing primitives that need to be scaffolded.
|
|
54
|
+
|
|
55
|
+
### Phase 3: Grounded Code Synthesis
|
|
56
|
+
* Translates Auto-layout (`HORIZONTAL`, `VERTICAL`) directly into Flexbox (`flex-row`, `flex-col`, `gap`).
|
|
57
|
+
* Replaces component instances with direct component imports (no `<div>` soup).
|
|
58
|
+
* Applies semantic design tokens instead of hardcoded numbers.
|
|
59
|
+
* Resolves icons and vectors through targeted local assets (`assets/`, `public/`, `components/`) or installed packages, eliminating hallucinated raw SVG paths.
|
|
60
|
+
* Applies exact styling (dimensions, radius, object-cover) to image layers without attempting to resolve image files, leaving clean `<img>` tags with `TODO` markers.
|
|
61
|
+
|
|
62
|
+
### Phase 4: Visual Cross-Check
|
|
63
|
+
* Inspects the companion `.specs/<name>.png` visual reference.
|
|
64
|
+
* Cross-checks margins, alignments, typography scales, and responsive wrapping.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## How to Use the Skill
|
|
69
|
+
|
|
70
|
+
Simply prompt your AI coding assistant (Claude Code, Cursor, OpenCode, Codex, or Antigravity):
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
"Build the component from .specs/transaction-card.json using .specs/transaction-card.png as visual reference"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or in an automated SDD flow after running `figma-extractor`:
|
|
77
|
+
```text
|
|
78
|
+
"Spec extracted to .specs/card.json. Proceed with implementation using figma-node-builder."
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Supported Stacks
|
|
84
|
+
|
|
85
|
+
Because `figma-node-builder` inspects your project dynamically during Phase 1, it works across any modern frontend stack:
|
|
86
|
+
* **Frameworks**: React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Astro, Solid, plain HTML/CSS.
|
|
87
|
+
* **Styling**: Tailwind CSS, CSS Modules, Styled Components, Emotion, Vanilla CSS.
|
|
88
|
+
* **Component Libraries**: shadcn/ui, Radix UI, Headless UI, Material UI, Chakra UI, or completely custom design systems.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Spec Inspector CLI
|
|
93
|
+
|
|
94
|
+
`figma-node-builder` includes a zero-dependency companion inspector tool to quickly analyze any specification file without loading raw JSON into agent context:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Terminal report (dimensions, layout mode, tokens, components, checklist)
|
|
98
|
+
node figma-node-builder/scripts/inspect_spec.js .specs/card.json
|
|
99
|
+
# (or with shorthand name)
|
|
100
|
+
node figma-node-builder/scripts/inspect_spec.js card
|
|
101
|
+
|
|
102
|
+
# Output clean Markdown tables for implementation plans & walkthroughs
|
|
103
|
+
node figma-node-builder/scripts/inspect_spec.js card --markdown
|
|
104
|
+
|
|
105
|
+
# Output structured JSON
|
|
106
|
+
node figma-node-builder/scripts/inspect_spec.js card --json
|
|
107
|
+
```
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: figma-node-builder
|
|
3
|
+
description: 'Build production-ready UI components by synthesizing extracted Figma node hierarchies (.specs/*.json) and companion preview images (.specs/*.png). Trigger this skill in Spec-Driven Development (SDD) workflows when the user asks to implement, build, or code UI components from an existing Figma spec, node AST, or specification file.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Figma Node Builder Skill (SDD Implementation Layer)
|
|
7
|
+
|
|
8
|
+
Build production-grade, design-system-grounded UI components directly from extracted Figma Node trees (`.specs/<name>.json`) and visual reference images (`.specs/<name>.png`).
|
|
9
|
+
|
|
10
|
+
This skill serves as the **Implementation Layer** in a **Spec-Driven Development (SDD)** workflow. It works entirely offline and locally from the extracted specification contract—no Figma API calls or tokens required.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## When to Trigger This Skill
|
|
15
|
+
|
|
16
|
+
Trigger this skill whenever:
|
|
17
|
+
* The user references an existing specification file (e.g., *"Build the component from `.specs/card.json`"*).
|
|
18
|
+
* An extraction step by `figma-extractor` or the **Figma Node JSON Extractor** plugin has completed, and the user approves the implementation (e.g., *"Proceed"*, *"Build it"*, *"Implement the UI"*).
|
|
19
|
+
* The user asks to turn a local Figma node AST (`.specs/<name>.json`) into React, Vue, Svelte, or HTML/CSS code.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## The 4-Phase Implementation Protocol
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
flowchart TD
|
|
27
|
+
A["Phase 1: Codebase Discovery<br/>(Framework & Existing Primitives)"] --> B["Phase 2: Gap Analysis<br/>(Match Tokens & Props)"]
|
|
28
|
+
B --> C["Phase 3: Grounded Synthesis<br/>(No Hallucinated CSS)"]
|
|
29
|
+
C --> D["Phase 4: Visual Verification<br/>(Check vs .specs/*.png)"]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Phase 1: Codebase Discovery
|
|
33
|
+
Before writing any code, inspect the host project to ground your implementation:
|
|
34
|
+
1. **Framework & Styling**: Check `package.json` for React, Vue, Svelte, Next.js, Tailwind CSS, styled-components, or plain CSS.
|
|
35
|
+
2. **Existing UI Primitives**: Inspect `components/ui/`, `src/components/`, or design system libraries (e.g., shadcn/ui, Radix, MUI) to identify reusable components (`Button`, `Input`, `Card`, `Badge`).
|
|
36
|
+
3. **Design Token System**: Inspect `tailwind.config.js`, `theme.css`, or `globals.css` to see how colors and spacing scales are configured.
|
|
37
|
+
4. **Icons & Assets Discovery**: Check `package.json` for installed icon packages (e.g. `lucide-react`, `@heroicons/react`, `phosphor-react`) and check if local icon folders exist (`components/icons/`, `src/assets/`, `public/`).
|
|
38
|
+
|
|
39
|
+
### Phase 2: Gap Analysis & Token Mapping
|
|
40
|
+
Analyze the input JSON spec (`.specs/<name>.json`).
|
|
41
|
+
|
|
42
|
+
> **Tip**: Instead of reading the entire raw JSON AST into your context window, run the companion **Spec Inspector CLI** to get a compact summary:
|
|
43
|
+
> ```bash
|
|
44
|
+
> # Global Antigravity install:
|
|
45
|
+
> node ~/.gemini/config/skills/figma-node-builder/scripts/inspect_spec.js .specs/<name>.json
|
|
46
|
+
> # Or project local install:
|
|
47
|
+
> node figma-node-builder/scripts/inspect_spec.js .specs/<name>.json
|
|
48
|
+
> # Output Markdown directly for your implementation plan:
|
|
49
|
+
> node <skill-dir>/scripts/inspect_spec.js .specs/<name>.json --markdown
|
|
50
|
+
> ```
|
|
51
|
+
|
|
52
|
+
* **Component Instances**: For each node with `type: "INSTANCE"`, match `component.name` against existing codebase components. Extract its `props` (e.g., `{ variant: "outline", size: "lg", hasIcon: true }`).
|
|
53
|
+
* **Design Tokens**: For every `token` property (e.g., `colors/brand/primary`, `spacing/md`, `radii/lg`), map to the project's CSS variables (`var(--color-brand-primary)`) or Tailwind classes (`bg-brand-primary`, `p-4`, `rounded-lg`).
|
|
54
|
+
* **Gaps**: Identify any sub-components that do not exist yet in the codebase and plan to scaffold them.
|
|
55
|
+
|
|
56
|
+
### Phase 3: Grounded Code Synthesis
|
|
57
|
+
Generate component code strictly adhering to the node specification:
|
|
58
|
+
|
|
59
|
+
1. **Reusing Existing Components (Anti-Div Soup Rule)**:
|
|
60
|
+
- When an `INSTANCE` node matches an existing component, **import and render it directly**:
|
|
61
|
+
```tsx
|
|
62
|
+
// Correct:
|
|
63
|
+
<Button variant="primary" size="large" hasIcon>Confirm Order</Button>
|
|
64
|
+
|
|
65
|
+
// Forbidden (do not rebuild existing primitives from raw divs):
|
|
66
|
+
<div className="flex bg-blue-500 rounded p-2 text-white">Confirm Order</div>
|
|
67
|
+
```
|
|
68
|
+
2. **Layout & Flexbox Translation**:
|
|
69
|
+
- `layoutMode: "HORIZONTAL"` $\rightarrow$ Flex row (`display: flex; flex-direction: row;` or `flex flex-row`).
|
|
70
|
+
- `layoutMode: "VERTICAL"` $\rightarrow$ Flex column (`display: flex; flex-direction: column;` or `flex flex-col`).
|
|
71
|
+
- `itemSpacing` $\rightarrow$ CSS `gap` (map to `itemSpacingToken` if available).
|
|
72
|
+
- `padding` $\rightarrow$ CSS `padding` (map to `paddingToken` if available).
|
|
73
|
+
- `primaryAxisAlignItems` / `counterAxisAlignItems` $\rightarrow$ `justify-*` and `items-*`.
|
|
74
|
+
3. **Typography & Colors**:
|
|
75
|
+
- Never guess hex colors. If `token` is present, use the semantic token. If not, use the fallback `color` hex string.
|
|
76
|
+
- Map font sizes, font weights, and line heights to existing design tokens or typography classes.
|
|
77
|
+
4. **Icon & Vector Resolution Hierarchy**:
|
|
78
|
+
When encountering a `VECTOR` node or icon instance:
|
|
79
|
+
- **Normalize Node Name**: Strip common prefixes (`icon/`, `ic_`, `ico-`) and clean the name (e.g., `icon/search` $\rightarrow$ `search` / `Search`).
|
|
80
|
+
- **Step 1 (Targeted Local Assets/Components)**: Look for matching files in `components/icons/`, `src/assets/`, or `public/` (e.g., `<SearchIcon />`, `/icons/search.svg`). Avoid recursive searches outside these targeted paths.
|
|
81
|
+
- **Step 2 (Installed Icon Library)**: If not found locally, import from the icon library detected in `package.json` (e.g., `import { Search } from 'lucide-react'`).
|
|
82
|
+
- **Step 3 (Semantic Fallback - Never Hallucinate Raw Béziers)**: If not found, render an accessible placeholder (`<span className="w-4 h-4 inline-flex items-center justify-center text-muted-foreground" aria-hidden="true" />`) with a `TODO: Missing icon 'search'` comment. Never hallucinate raw SVG `<path d="...">` coordinates.
|
|
83
|
+
5. **Image Layer Handling (`fills: [{ type: "IMAGE" }]`)**:
|
|
84
|
+
- 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`).
|
|
85
|
+
- Do **NOT** attempt to resolve, fetch, or hallucinate image files or external URLs (never invent Unsplash or third-party links).
|
|
86
|
+
- Render a standard `<img>` tag with `src=""` and a concise `TODO` comment specifying the target image:
|
|
87
|
+
```tsx
|
|
88
|
+
{/* TODO: Add image source for 'User Avatar' (48x48) */}
|
|
89
|
+
<img src="" alt="User Avatar" className="w-12 h-12 rounded-full object-cover" />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Phase 4: Visual Cross-Check & Verification
|
|
93
|
+
* **Optional Companion Image**: If the companion preview image (`.specs/<name>.png`) exists, inspect it to cross-check visual styling and icons.
|
|
94
|
+
* **AST-Only Synthesis**: If `.specs/<name>.png` was omitted (to conserve Tier 1 API calls), rely strictly on the exact metrics, flexbox rules, hex colors, and font styles in `.specs/<name>.json`.
|
|
95
|
+
* If a dev server or browser preview is active, verify that the rendered DOM matches the specification.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Input Spec Reference (Figma Node AST)
|
|
100
|
+
|
|
101
|
+
The input `.specs/<name>.json` file contains a pruned AST of Figma nodes:
|
|
102
|
+
|
|
103
|
+
| Field | Meaning | Code Mapping |
|
|
104
|
+
| :--- | :--- | :--- |
|
|
105
|
+
| `type` | Node type (`FRAME`, `INSTANCE`, `TEXT`, `VECTOR`) | Container (`div` / `section`), Component import, Typography tag (`h1`-`p`), or Icon component/placeholder (see Icon Resolution Hierarchy). |
|
|
106
|
+
| `layoutMode` | Auto-layout direction (`HORIZONTAL`, `VERTICAL`) | `flex flex-row` or `flex flex-col`. |
|
|
107
|
+
| `itemSpacing` / `itemSpacingToken` | Gap between child items | `gap-*` class or `gap: Xpx`. |
|
|
108
|
+
| `padding` / `paddingToken` | Object with `top`, `right`, `bottom`, `left` | `p-*`, `px-*`, `py-*` classes or `padding: ...`. |
|
|
109
|
+
| `cornerRadius` / `cornerRadiusToken` | Border radius | `rounded-*` class or `border-radius: Xpx`. |
|
|
110
|
+
| `component.name` | Master component name for an `INSTANCE` | Import name (e.g. `import { Button } from '@/components/ui/button'`). |
|
|
111
|
+
| `props` | Normalized component variant and boolean properties | JSX/template props: `<Component {...props} />`. |
|
|
112
|
+
| `bounds` | Render dimensions (`width`, `height`) | Sizing constraints (`w-*`, `h-*`, `max-w-*`). |
|
|
113
|
+
| `fills` | Fill layers (`SOLID`, `IMAGE`, gradients) | Background color (`bg-*`), gradient, or styled `<img>` tag for `IMAGE` fills (see Image Layer Handling). |
|