riazmo commited on
Commit
a3eeeb0
·
verified ·
1 Parent(s): 412b593

Delete PART2_COMPONENT_GENERATION.md

Browse files
Files changed (1) hide show
  1. PART2_COMPONENT_GENERATION.md +0 -418
PART2_COMPONENT_GENERATION.md DELETED
@@ -1,418 +0,0 @@
1
- # Design System Automation — Part 2: Component Generation
2
-
3
- ## Session Context
4
-
5
- **Prerequisite**: Part 1 (Token Extraction + Analysis) is COMPLETE at v3.2
6
- - Phases 1-3 DONE: Normalizer, Stage 2 agents, Export all working
7
- - 113 tests passing, W3C DTCG v1 compliant output
8
- - GitHub: https://github.com/hiriazmo/design-system-automation
9
- - Project: `/Users/yahya/design-system-automation/`
10
-
11
- **This session**: Build automated component generation from extracted tokens into Figma.
12
-
13
- ---
14
-
15
- ## THE GAP: Nobody Does This
16
-
17
- Exhaustive research of 30+ tools (Feb 2026) confirms:
18
-
19
- **No production tool takes DTCG JSON and outputs Figma Components.**
20
-
21
- ```
22
- YOUR EXTRACTOR THE GAP FIGMA
23
- +--------------+ +----------------------------+ +------------------+
24
- | DTCG JSON |--->| ??? Nothing does this |--->| Button component |
25
- | with tokens | | tokens -> components | | with 60 variants |
26
- +--------------+ +----------------------------+ +------------------+
27
- ```
28
-
29
- ### What Exists (and What It Can't Do)
30
-
31
- | Category | Best Tool | What It Does | Creates Components? |
32
- |----------|-----------|-------------|-------------------|
33
- | Token Importers | Tokens Studio (1M+ installs) | JSON -> Figma Variables | NO - variables only |
34
- | AI Design | Figma Make | Prompt -> prototype | NO - not token-driven |
35
- | MCP Bridges | Figma Console MCP (543 stars) | AI writes to Figma | YES but non-deterministic |
36
- | Code-to-Figma | story.to.design | Storybook -> Figma components | YES but needs full Storybook |
37
- | Generators | Figr Identity | Brand config -> components | YES but can't consume YOUR tokens |
38
- | Commercial | Knapsack ($10M), Supernova | Token management | NO - manages, doesn't create |
39
- | DEAD | Specify.app (shutting down), Backlight.dev (shut down June 2025) | - | - |
40
-
41
- ### Key Findings Per Category
42
-
43
- **Token Importers** (7+ tools evaluated): Tokens Studio, TokensBrucke, Styleframe, DTCG Token Manager, GitFig, Supa Design Tokens, Design System Automator — ALL create Figma Variables from JSON, NONE create components.
44
-
45
- **MCP Bridges** (5 tools): Figma Console MCP (Southleft), claude-talk-to-figma-mcp, cursor-talk-to-figma-mcp (Grab), figma-mcp-write-server, Figma-MCP-Write-Bridge — ALL have full write access, but component creation is AI-interpreted (non-deterministic, varies per run).
46
-
47
- **Code-to-Figma**: story.to.design is the standout — creates REAL Figma components with proper variants from Storybook. But requires a full coded component library + running Storybook instance as intermediary.
48
-
49
- **figma-json2component** (GitHub): Experimental proof-of-concept that generates components from custom JSON schema. Not DTCG, not production quality, but validates the concept IS possible.
50
-
51
- ---
52
-
53
- ## FOUR APPROACHES — RANKED
54
-
55
- ### Option A: Custom Figma Plugin (RECOMMENDED)
56
- ```
57
- DTCG JSON -> Your Plugin reads JSON -> Creates Variables -> Generates Components -> Done
58
- ```
59
- - **Effort**: 4-8 weeks (~1400 lines of plugin code for 5 MVP components)
60
- - **Quality**: Highest — fully deterministic, consistent every run
61
- - **Advantage**: We already have a working plugin (code.js) that imports tokens
62
- - **Risk**: Low — Figma Plugin API supports everything needed
63
-
64
- ### Option B: Pipeline — shadcn + Storybook + story.to.design
65
- ```
66
- DTCG JSON -> Style Dictionary -> CSS vars -> shadcn themed -> Storybook -> story.to.design -> Figma
67
- ```
68
- - **Effort**: 2-3 days setup, then 15-30 min per extraction
69
- - **Quality**: High — battle-tested shadcn components
70
- - **Dependency**: story.to.design (commercial, paid)
71
- - **Risk**: Medium — many moving parts
72
-
73
- ### Option C: MCP + Claude AI Chain
74
- ```
75
- DTCG JSON -> Claude reads tokens -> Figma Console MCP -> AI creates components -> Figma
76
- ```
77
- - **Effort**: 2-3 weeks
78
- - **Quality**: Medium — non-deterministic
79
- - **Risk**: High — AI output varies per run
80
-
81
- ### Option D: Figr Identity + Manual Token Swap
82
- ```
83
- Figr Identity generates base system -> Manually swap tokens -> Adjust
84
- ```
85
- - **Effort**: 1-2 days
86
- - **Quality**: Medium — not YOUR tokens
87
- - **Risk**: Medium — manual alignment needed
88
-
89
- **Decision: Option A (Custom Plugin)** — we already have 80% of the infrastructure, it's deterministic, no external dependencies, and fills a genuine market gap.
90
-
91
- ---
92
-
93
- ## FIGMA PLUGIN API: FULL CAPABILITY CHECK
94
-
95
- Every feature needed for component generation is supported:
96
-
97
- | Requirement | API Method | Status |
98
- |------------|-----------|--------|
99
- | Create components | `figma.createComponent()` | Supported |
100
- | Variant sets (60 variants) | `figma.combineAsVariants()` | Supported |
101
- | Auto-layout with padding | `layoutMode`, `paddingTop/Right/Bottom/Left`, `itemSpacing` | Supported |
102
- | Text labels | `figma.createText()` + `loadFontAsync()` | Supported |
103
- | Icon slot (optional) | `addComponentProperty("ShowIcon", "BOOLEAN", true)` | Supported |
104
- | Instance swap (icons) | `addComponentProperty("Icon", "INSTANCE_SWAP", id)` | Supported |
105
- | Border radius from tokens | `setBoundVariable('topLeftRadius', radiusVar)` | Supported |
106
- | Colors from tokens | `setBoundVariableForPaint()` -> binds to variables | Supported |
107
- | Shadows from tokens | `setBoundVariableForEffect()` | Supported (has spread bug, workaround exists) |
108
- | Hover/press interactions | `node.setReactionsAsync()` with `ON_HOVER`/`ON_PRESS` | Supported |
109
- | Expose text property | `addComponentProperty("Label", "TEXT", "Button")` | Supported |
110
- | Disabled opacity | `node.opacity = 0.5` | Supported |
111
-
112
- ---
113
-
114
- ## MVP SCOPE: 5 Components, 62 Variants
115
-
116
- | Component | Variants | Automatable? | Effort |
117
- |-----------|---------|-------------|--------|
118
- | **Button** | 4 variants x 3 sizes x 5 states = 60 | Fully | 2-3 days |
119
- | **Text Input** | 4 states x 2 sizes = 8 | Fully | 1-2 days |
120
- | **Card** | 2 configurations | Semi | 1 day |
121
- | **Toast/Notification** | 4 types (success/error/warn/info) | Fully | 1 day |
122
- | **Checkbox + Radio** | ~12 variants | Fully | 1-2 days |
123
- | **Total** | **~86 variants** | | **8-12 days** |
124
-
125
- ### Post-MVP Components
126
-
127
- | Component | Variants | Automatable? | Effort |
128
- |-----------|---------|-------------|--------|
129
- | Toggle/Switch | on/off x enabled/disabled = 4 | Fully | 0.5 day |
130
- | Select/Dropdown | Multiple states | Semi | 1-2 days |
131
- | Modal/Dialog | 3 sizes | Semi | 1 day |
132
- | Table | Header + data rows | Template-based | 2 days |
133
-
134
- ---
135
-
136
- ## TOKEN-TO-COMPONENT MAPPING
137
-
138
- How extracted tokens bind to component properties:
139
-
140
- ### Button Example
141
- ```
142
- Token -> Figma Property
143
- -------------------------------------------------
144
- color.brand.primary -> Fill (default state)
145
- color.brand.600 -> Fill (hover state)
146
- color.brand.700 -> Fill (pressed state)
147
- color.text.inverse -> Text color
148
- color.neutral.200 -> Fill (secondary variant)
149
- color.neutral.300 -> Fill (secondary hover)
150
- radius.md -> Corner radius (all corners)
151
- shadow.sm -> Drop shadow (elevated variant)
152
- spacing.3 -> Padding horizontal (16px)
153
- spacing.2 -> Padding vertical (8px)
154
- font.body.md -> Text style (label)
155
- ```
156
-
157
- ### Variable Collections Needed
158
- ```
159
- 1. Primitives -> Raw color palette (blue.50 through blue.900, etc.)
160
- 2. Semantic -> Role-based aliases (brand.primary -> blue.500)
161
- 3. Spacing -> 4px grid (spacing.1=4, spacing.2=8, spacing.3=12...)
162
- 4. Radius -> none/sm/md/lg/xl/full
163
- 5. Shadow -> xs/sm/md/lg/xl elevation levels
164
- 6. Typography -> Font families, sizes, weights, line-heights
165
- ```
166
-
167
- ---
168
-
169
- ## COMPONENT DEFINITION SCHEMA (Proposed)
170
-
171
- Each component needs a JSON definition describing its anatomy, token bindings, and variant matrix:
172
-
173
- ```json
174
- {
175
- "component": "Button",
176
- "anatomy": {
177
- "root": {
178
- "type": "frame",
179
- "layout": "horizontal",
180
- "padding": { "h": "spacing.3", "v": "spacing.2" },
181
- "radius": "radius.md",
182
- "fill": "color.brand.primary",
183
- "gap": "spacing.2"
184
- },
185
- "icon_slot": {
186
- "type": "instance_swap",
187
- "size": 16,
188
- "visible": false,
189
- "property": "ShowIcon"
190
- },
191
- "label": {
192
- "type": "text",
193
- "style": "font.body.md",
194
- "color": "color.text.inverse",
195
- "content": "Button",
196
- "property": "Label"
197
- }
198
- },
199
- "variants": {
200
- "Variant": ["Primary", "Secondary", "Outline", "Ghost"],
201
- "Size": ["Small", "Medium", "Large"],
202
- "State": ["Default", "Hover", "Pressed", "Focused", "Disabled"]
203
- },
204
- "variant_overrides": {
205
- "Variant=Secondary": {
206
- "root.fill": "color.neutral.200",
207
- "label.color": "color.text.primary"
208
- },
209
- "Variant=Outline": {
210
- "root.fill": "transparent",
211
- "root.stroke": "color.border.primary",
212
- "root.strokeWeight": 1,
213
- "label.color": "color.brand.primary"
214
- },
215
- "Variant=Ghost": {
216
- "root.fill": "transparent",
217
- "label.color": "color.brand.primary"
218
- },
219
- "State=Hover": {
220
- "root.fill": "color.brand.600"
221
- },
222
- "State=Pressed": {
223
- "root.fill": "color.brand.700"
224
- },
225
- "State=Disabled": {
226
- "root.opacity": 0.5
227
- },
228
- "Size=Small": {
229
- "root.padding.h": "spacing.2",
230
- "root.padding.v": "spacing.1",
231
- "label.style": "font.body.sm"
232
- },
233
- "Size=Large": {
234
- "root.padding.h": "spacing.4",
235
- "root.padding.v": "spacing.3",
236
- "label.style": "font.body.lg"
237
- }
238
- }
239
- }
240
- ```
241
-
242
- ### Component Generation Pattern (Plugin Code)
243
-
244
- Every component follows the same pipeline:
245
- ```
246
- 1. Read tokens from DTCG JSON
247
- 2. Create Variable Collections (if not exist)
248
- 3. For each variant combination:
249
- a. Create frame with auto-layout
250
- b. Add child nodes (icon slot, label, etc.)
251
- c. Apply token bindings via setBoundVariable()
252
- d. Apply variant-specific overrides
253
- 4. combineAsVariants() -> component set
254
- 5. Add component properties (Label text, ShowIcon boolean)
255
- ```
256
-
257
- ---
258
-
259
- ## ARCHITECTURE FOR PLUGIN EXTENSION
260
-
261
- Current plugin (`code.js`) already does:
262
- - Parse DTCG JSON (isDTCGFormat detection)
263
- - Create paint styles from colors
264
- - Create text styles from typography
265
- - Create effect styles from shadows
266
- - Create variable collections
267
-
268
- What needs to be ADDED:
269
- ```
270
- code.js (existing ~1200 lines)
271
- |
272
- +-- componentGenerator.js (NEW ~1400 lines)
273
- | |-- generateButton() ~250 lines
274
- | |-- generateTextInput() ~200 lines
275
- | |-- generateCard() ~150 lines
276
- | |-- generateToast() ~150 lines
277
- | |-- generateCheckbox() ~200 lines
278
- | |-- generateRadio() ~150 lines
279
- | +-- shared utilities ~300 lines
280
- | |-- createAutoLayoutFrame()
281
- | |-- bindTokenToVariable()
282
- | |-- buildVariantMatrix()
283
- | |-- resolveTokenValue()
284
- |
285
- +-- componentDefinitions.json (NEW ~500 lines)
286
- |-- Button definition
287
- |-- TextInput definition
288
- |-- Card definition
289
- |-- Toast definition
290
- +-- Checkbox/Radio definition
291
- ```
292
-
293
- ### Implementation Order
294
- ```
295
- Week 1-2: Infrastructure
296
- - Variable collection builder (primitives, semantic, spacing, radius, shadow)
297
- - Token resolver (DTCG path -> Figma variable reference)
298
- - Auto-layout frame builder with token bindings
299
- - Variant matrix generator
300
-
301
- Week 3-4: MVP Components
302
- - Button (60 variants) — most complex, validates the full pipeline
303
- - TextInput (8 variants) — validates form patterns
304
- - Toast (4 variants) — validates feedback patterns
305
-
306
- Week 5-6: Remaining MVP + Polish
307
- - Card (2 configs) — validates layout composition
308
- - Checkbox + Radio (12 variants) — validates toggle patterns
309
- - Error handling, edge cases, testing
310
-
311
- Week 7-8: Post-MVP (if time)
312
- - Toggle/Switch, Select, Modal
313
- - Documentation
314
- ```
315
-
316
- ---
317
-
318
- ## EXISTING FILES TO KNOW ABOUT
319
-
320
- | File | Purpose | Lines |
321
- |------|---------|-------|
322
- | `app.py` | Main Gradio app, token extraction orchestration | ~5000 |
323
- | `agents/llm_agents.py` | AURORA, ATLAS, SENTINEL, NEXUS LLM agents | ~1200 |
324
- | `agents/normalizer.py` | Token normalization (colors, radius, shadows) | ~950 |
325
- | `core/color_classifier.py` | Rule-based color classification (PRIMARY authority) | ~815 |
326
- | `core/color_utils.py` | Color math (hex/RGB/HSL, contrast, ramps) | ~400 |
327
- | `core/rule_engine.py` | Type scale, WCAG, spacing grid analysis | ~1100 |
328
- | `output_json/figma-plugin-extracted/figma-design-token-creator 5/src/code.js` | **Figma plugin — EXTEND THIS** | ~1200 |
329
- | `output_json/figma-plugin-extracted/figma-design-token-creator 5/src/ui.html` | Plugin UI | ~500 |
330
-
331
- ### DTCG Output Format (What the Plugin Receives)
332
-
333
- ```json
334
- {
335
- "color": {
336
- "brand": {
337
- "primary": {
338
- "$type": "color",
339
- "$value": "#005aa3",
340
- "$description": "[classifier] brand: primary_action",
341
- "$extensions": {
342
- "com.design-system-automation": {
343
- "frequency": 47,
344
- "confidence": "high",
345
- "category": "brand",
346
- "evidence": ["background-color on <a>", "background-color on <button>"]
347
- }
348
- }
349
- }
350
- }
351
- },
352
- "radius": {
353
- "md": { "$type": "dimension", "$value": "8px" },
354
- "lg": { "$type": "dimension", "$value": "16px" },
355
- "full": { "$type": "dimension", "$value": "9999px" }
356
- },
357
- "shadow": {
358
- "sm": {
359
- "$type": "shadow",
360
- "$value": {
361
- "offsetX": "0px",
362
- "offsetY": "2px",
363
- "blur": "8px",
364
- "spread": "0px",
365
- "color": "#00000026"
366
- }
367
- }
368
- },
369
- "typography": {
370
- "body": {
371
- "md": {
372
- "$type": "typography",
373
- "$value": {
374
- "fontFamily": "Inter",
375
- "fontSize": "16px",
376
- "fontWeight": 400,
377
- "lineHeight": 1.5,
378
- "letterSpacing": "0px"
379
- }
380
- }
381
- }
382
- },
383
- "spacing": {
384
- "1": { "$type": "dimension", "$value": "4px" },
385
- "2": { "$type": "dimension", "$value": "8px" },
386
- "3": { "$type": "dimension", "$value": "16px" }
387
- }
388
- }
389
- ```
390
-
391
- ---
392
-
393
- ## COMPETITIVE ADVANTAGE
394
-
395
- Building this fills a genuine market gap:
396
- - **Tokens Studio** (1M+ installs) = token management, no component generation
397
- - **Figr Identity** = generates components but from brand config, not YOUR tokens
398
- - **story.to.design** = needs full Storybook pipeline as intermediary
399
- - **MCP bridges** = non-deterministic AI interpretation
400
- - **Us** = DTCG JSON in, deterministic Figma components out. Nobody else does this.
401
-
402
- ### Strategic Position
403
- ```
404
- [Extract from website] -> [Analyze & Score] -> [Generate Components in Figma]
405
- Part 1 (DONE) Part 1 (DONE) Part 2 (THIS)
406
- ```
407
-
408
- We become the only tool that goes from URL to complete Figma design system with components — fully automated.
409
-
410
- ---
411
-
412
- ## OPEN QUESTIONS FOR THIS SESSION
413
-
414
- 1. Should component definitions live in JSON (data-driven) or be hardcoded in JS (simpler)?
415
- 2. Should we generate all 60 Button variants at once, or let user pick which variants?
416
- 3. How to handle missing tokens? (e.g., site has no shadow tokens — skip shadow on buttons or use defaults?)
417
- 4. Should we support dark mode variants from the start, or add later?
418
- 5. Icon system — use a bundled icon set (Lucide?) or just placeholder frames?