wogiflow 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/.workflow/agents/reviewer.md +81 -0
- package/.workflow/agents/security.md +94 -0
- package/.workflow/agents/story-writer.md +58 -0
- package/.workflow/bridges/base-bridge.js +395 -0
- package/.workflow/bridges/claude-bridge.js +434 -0
- package/.workflow/bridges/index.js +130 -0
- package/.workflow/lib/assumption-detector.js +481 -0
- package/.workflow/lib/config-substitution.js +371 -0
- package/.workflow/lib/failure-categories.js +478 -0
- package/.workflow/state/app-map.md.template +15 -0
- package/.workflow/state/architecture.md.template +24 -0
- package/.workflow/state/component-index.json.template +5 -0
- package/.workflow/state/decisions.md.template +15 -0
- package/.workflow/state/feedback-patterns.md.template +9 -0
- package/.workflow/state/knowledge-sync.json.template +6 -0
- package/.workflow/state/progress.md.template +14 -0
- package/.workflow/state/ready.json.template +7 -0
- package/.workflow/state/request-log.md.template +14 -0
- package/.workflow/state/session-state.json.template +11 -0
- package/.workflow/state/stack.md.template +33 -0
- package/.workflow/state/testing.md.template +36 -0
- package/.workflow/templates/claude-md.hbs +257 -0
- package/.workflow/templates/correction-report.md +67 -0
- package/.workflow/templates/gemini-md.hbs +52 -0
- package/README.md +1802 -0
- package/bin/flow +205 -0
- package/lib/index.js +33 -0
- package/lib/installer.js +467 -0
- package/lib/release-channel.js +269 -0
- package/lib/skill-registry.js +526 -0
- package/lib/upgrader.js +401 -0
- package/lib/utils.js +305 -0
- package/package.json +64 -0
- package/scripts/flow +985 -0
- package/scripts/flow-adaptive-learning.js +1259 -0
- package/scripts/flow-aggregate.js +488 -0
- package/scripts/flow-archive +133 -0
- package/scripts/flow-auto-context.js +1015 -0
- package/scripts/flow-auto-learn.js +615 -0
- package/scripts/flow-bridge.js +223 -0
- package/scripts/flow-browser-suggest.js +316 -0
- package/scripts/flow-bug.js +247 -0
- package/scripts/flow-cascade.js +711 -0
- package/scripts/flow-changelog +85 -0
- package/scripts/flow-checkpoint.js +483 -0
- package/scripts/flow-cli.js +403 -0
- package/scripts/flow-code-intelligence.js +760 -0
- package/scripts/flow-complexity.js +502 -0
- package/scripts/flow-config-set.js +152 -0
- package/scripts/flow-constants.js +157 -0
- package/scripts/flow-context +152 -0
- package/scripts/flow-context-init.js +482 -0
- package/scripts/flow-context-monitor.js +384 -0
- package/scripts/flow-context-scoring.js +886 -0
- package/scripts/flow-correct.js +458 -0
- package/scripts/flow-damage-control.js +985 -0
- package/scripts/flow-deps +101 -0
- package/scripts/flow-diff.js +700 -0
- package/scripts/flow-done +151 -0
- package/scripts/flow-done.js +489 -0
- package/scripts/flow-durable-session.js +1541 -0
- package/scripts/flow-entropy-monitor.js +345 -0
- package/scripts/flow-export-profile +349 -0
- package/scripts/flow-export-scanner.js +1046 -0
- package/scripts/flow-figma-confirm.js +400 -0
- package/scripts/flow-figma-extract.js +496 -0
- package/scripts/flow-figma-generate.js +683 -0
- package/scripts/flow-figma-index.js +909 -0
- package/scripts/flow-figma-match.js +617 -0
- package/scripts/flow-figma-mcp-server.js +518 -0
- package/scripts/flow-figma-pipeline.js +414 -0
- package/scripts/flow-file-ops.js +301 -0
- package/scripts/flow-gate-confidence.js +825 -0
- package/scripts/flow-guided-edit.js +659 -0
- package/scripts/flow-health +185 -0
- package/scripts/flow-health.js +413 -0
- package/scripts/flow-hooks.js +556 -0
- package/scripts/flow-http-client.js +249 -0
- package/scripts/flow-hybrid-detect.js +167 -0
- package/scripts/flow-hybrid-interactive.js +591 -0
- package/scripts/flow-hybrid-test.js +152 -0
- package/scripts/flow-import-profile +439 -0
- package/scripts/flow-init +253 -0
- package/scripts/flow-instruction-richness.js +827 -0
- package/scripts/flow-jira-integration.js +579 -0
- package/scripts/flow-knowledge-router.js +522 -0
- package/scripts/flow-knowledge-sync.js +589 -0
- package/scripts/flow-linear-integration.js +631 -0
- package/scripts/flow-links.js +774 -0
- package/scripts/flow-log-manager.js +559 -0
- package/scripts/flow-loop-enforcer.js +1246 -0
- package/scripts/flow-loop-retry-learning.js +630 -0
- package/scripts/flow-lsp.js +923 -0
- package/scripts/flow-map-index +348 -0
- package/scripts/flow-map-sync +201 -0
- package/scripts/flow-memory-blocks.js +668 -0
- package/scripts/flow-memory-compactor.js +350 -0
- package/scripts/flow-memory-db.js +1110 -0
- package/scripts/flow-memory-sync.js +484 -0
- package/scripts/flow-metrics.js +353 -0
- package/scripts/flow-migrate-ids.js +370 -0
- package/scripts/flow-model-adapter.js +802 -0
- package/scripts/flow-model-router.js +884 -0
- package/scripts/flow-models.js +1231 -0
- package/scripts/flow-morning.js +517 -0
- package/scripts/flow-multi-approach.js +660 -0
- package/scripts/flow-new-feature +86 -0
- package/scripts/flow-onboard +1042 -0
- package/scripts/flow-orchestrate-llm.js +459 -0
- package/scripts/flow-orchestrate.js +3592 -0
- package/scripts/flow-output.js +123 -0
- package/scripts/flow-parallel-detector.js +399 -0
- package/scripts/flow-parallel-dispatch.js +987 -0
- package/scripts/flow-parallel.js +428 -0
- package/scripts/flow-pattern-enforcer.js +600 -0
- package/scripts/flow-prd-manager.js +282 -0
- package/scripts/flow-progress.js +323 -0
- package/scripts/flow-project-analyzer.js +975 -0
- package/scripts/flow-prompt-composer.js +487 -0
- package/scripts/flow-providers.js +1381 -0
- package/scripts/flow-queue.js +308 -0
- package/scripts/flow-ready +82 -0
- package/scripts/flow-ready.js +189 -0
- package/scripts/flow-regression.js +396 -0
- package/scripts/flow-response-parser.js +450 -0
- package/scripts/flow-resume.js +284 -0
- package/scripts/flow-rules-sync.js +439 -0
- package/scripts/flow-run-trace.js +718 -0
- package/scripts/flow-safety.js +587 -0
- package/scripts/flow-search +104 -0
- package/scripts/flow-security.js +481 -0
- package/scripts/flow-session-end +106 -0
- package/scripts/flow-session-end.js +437 -0
- package/scripts/flow-session-state.js +671 -0
- package/scripts/flow-setup-hooks +216 -0
- package/scripts/flow-setup-hooks.js +377 -0
- package/scripts/flow-skill-create.js +329 -0
- package/scripts/flow-skill-creator.js +572 -0
- package/scripts/flow-skill-generator.js +1046 -0
- package/scripts/flow-skill-learn.js +880 -0
- package/scripts/flow-skill-matcher.js +578 -0
- package/scripts/flow-spec-generator.js +820 -0
- package/scripts/flow-stack-wizard.js +895 -0
- package/scripts/flow-standup +162 -0
- package/scripts/flow-start +74 -0
- package/scripts/flow-start.js +235 -0
- package/scripts/flow-status +110 -0
- package/scripts/flow-status.js +301 -0
- package/scripts/flow-step-browser.js +83 -0
- package/scripts/flow-step-changelog.js +217 -0
- package/scripts/flow-step-comments.js +306 -0
- package/scripts/flow-step-complexity.js +234 -0
- package/scripts/flow-step-coverage.js +218 -0
- package/scripts/flow-step-knowledge.js +193 -0
- package/scripts/flow-step-pr-tests.js +364 -0
- package/scripts/flow-step-regression.js +89 -0
- package/scripts/flow-step-review.js +516 -0
- package/scripts/flow-step-security.js +162 -0
- package/scripts/flow-step-silent-failures.js +290 -0
- package/scripts/flow-step-simplifier.js +346 -0
- package/scripts/flow-story +105 -0
- package/scripts/flow-story.js +500 -0
- package/scripts/flow-suspend.js +252 -0
- package/scripts/flow-sync-daemon.js +654 -0
- package/scripts/flow-task-analyzer.js +606 -0
- package/scripts/flow-team-dashboard.js +748 -0
- package/scripts/flow-team-sync.js +752 -0
- package/scripts/flow-team.js +977 -0
- package/scripts/flow-tech-options.js +528 -0
- package/scripts/flow-templates.js +812 -0
- package/scripts/flow-tiered-learning.js +728 -0
- package/scripts/flow-trace +204 -0
- package/scripts/flow-transcript-chunking.js +1106 -0
- package/scripts/flow-transcript-digest.js +7918 -0
- package/scripts/flow-transcript-language.js +465 -0
- package/scripts/flow-transcript-parsing.js +1085 -0
- package/scripts/flow-transcript-stories.js +2194 -0
- package/scripts/flow-update-map +224 -0
- package/scripts/flow-utils.js +2242 -0
- package/scripts/flow-verification.js +644 -0
- package/scripts/flow-verify.js +1177 -0
- package/scripts/flow-voice-input.js +638 -0
- package/scripts/flow-watch +168 -0
- package/scripts/flow-workflow-steps.js +521 -0
- package/scripts/flow-workflow.js +1029 -0
- package/scripts/flow-worktree.js +489 -0
- package/scripts/hooks/adapters/base-adapter.js +102 -0
- package/scripts/hooks/adapters/claude-code.js +359 -0
- package/scripts/hooks/adapters/index.js +79 -0
- package/scripts/hooks/core/component-check.js +341 -0
- package/scripts/hooks/core/index.js +35 -0
- package/scripts/hooks/core/loop-check.js +241 -0
- package/scripts/hooks/core/session-context.js +294 -0
- package/scripts/hooks/core/task-gate.js +177 -0
- package/scripts/hooks/core/validation.js +230 -0
- package/scripts/hooks/entry/claude-code/post-tool-use.js +65 -0
- package/scripts/hooks/entry/claude-code/pre-tool-use.js +89 -0
- package/scripts/hooks/entry/claude-code/session-end.js +87 -0
- package/scripts/hooks/entry/claude-code/session-start.js +46 -0
- package/scripts/hooks/entry/claude-code/stop.js +43 -0
- package/scripts/postinstall.js +139 -0
- package/templates/browser-test-flow.json +56 -0
- package/templates/bug-report.md +43 -0
- package/templates/component-detail.md +42 -0
- package/templates/component.stories.tsx +49 -0
- package/templates/context/constraints.md +83 -0
- package/templates/context/conventions.md +177 -0
- package/templates/context/stack.md +60 -0
- package/templates/correction-report.md +90 -0
- package/templates/feature-proposal.md +35 -0
- package/templates/hybrid/_base.md +254 -0
- package/templates/hybrid/_patterns.md +45 -0
- package/templates/hybrid/create-component.md +127 -0
- package/templates/hybrid/create-file.md +56 -0
- package/templates/hybrid/create-hook.md +145 -0
- package/templates/hybrid/create-service.md +70 -0
- package/templates/hybrid/fix-bug.md +33 -0
- package/templates/hybrid/modify-file.md +55 -0
- package/templates/story.md +68 -0
- package/templates/task.json +56 -0
- package/templates/trace.md +69 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wogi Flow - Figma Component Extractor
|
|
5
|
+
*
|
|
6
|
+
* Parses Figma MCP output and extracts atomic components
|
|
7
|
+
* with their CSS properties, structure, and relationships.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* flow figma extract <figma-data.json> # Extract from file
|
|
11
|
+
* flow figma extract --stdin # Read MCP output from stdin
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
// ============================================================
|
|
18
|
+
// Figma Node Parser
|
|
19
|
+
// ============================================================
|
|
20
|
+
|
|
21
|
+
class FigmaExtractor {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.components = [];
|
|
24
|
+
this.tokens = {
|
|
25
|
+
colors: new Map(),
|
|
26
|
+
spacing: new Map(),
|
|
27
|
+
typography: new Map(),
|
|
28
|
+
radius: new Map()
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Parse the raw Figma MCP response
|
|
34
|
+
*/
|
|
35
|
+
parse(figmaData) {
|
|
36
|
+
if (typeof figmaData === 'string') {
|
|
37
|
+
try {
|
|
38
|
+
figmaData = JSON.parse(figmaData);
|
|
39
|
+
} catch {
|
|
40
|
+
console.error('Failed to parse Figma data as JSON');
|
|
41
|
+
return { components: [], tokens: {} };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Reset state
|
|
46
|
+
this.components = [];
|
|
47
|
+
this.tokens = {
|
|
48
|
+
colors: new Map(),
|
|
49
|
+
spacing: new Map(),
|
|
50
|
+
typography: new Map(),
|
|
51
|
+
radius: new Map()
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Handle different Figma MCP response structures
|
|
55
|
+
if (figmaData.nodes) {
|
|
56
|
+
this.parseNodes(figmaData.nodes);
|
|
57
|
+
} else if (figmaData.document) {
|
|
58
|
+
this.parseNode(figmaData.document);
|
|
59
|
+
} else if (figmaData.children) {
|
|
60
|
+
figmaData.children.forEach(child => this.parseNode(child));
|
|
61
|
+
} else if (figmaData.result) {
|
|
62
|
+
// Handle wrapped response
|
|
63
|
+
return this.parse(figmaData.result);
|
|
64
|
+
} else if (Array.isArray(figmaData)) {
|
|
65
|
+
figmaData.forEach(item => this.parseNode(item));
|
|
66
|
+
} else {
|
|
67
|
+
// Try to parse as a single node
|
|
68
|
+
this.parseNode(figmaData);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Build component hierarchy
|
|
72
|
+
this.buildHierarchy();
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
components: this.components,
|
|
76
|
+
tokens: {
|
|
77
|
+
colors: Object.fromEntries(this.tokens.colors),
|
|
78
|
+
spacing: Object.fromEntries(this.tokens.spacing),
|
|
79
|
+
typography: Object.fromEntries(this.tokens.typography),
|
|
80
|
+
radius: Object.fromEntries(this.tokens.radius)
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
parseNodes(nodes, parent = null) {
|
|
86
|
+
for (const [nodeId, nodeData] of Object.entries(nodes)) {
|
|
87
|
+
const node = nodeData.document || nodeData;
|
|
88
|
+
this.parseNode(node, parent);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
parseNode(node, parent = null) {
|
|
93
|
+
if (!node || !node.type) return null;
|
|
94
|
+
|
|
95
|
+
const component = {
|
|
96
|
+
id: node.id || `node-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
97
|
+
name: node.name || 'Unnamed',
|
|
98
|
+
type: this.classifyNodeType(node),
|
|
99
|
+
figmaType: node.type,
|
|
100
|
+
parentId: parent?.id || null,
|
|
101
|
+
children: [],
|
|
102
|
+
|
|
103
|
+
// Visual properties
|
|
104
|
+
css: {
|
|
105
|
+
colors: [],
|
|
106
|
+
spacing: [],
|
|
107
|
+
typography: [],
|
|
108
|
+
radius: [],
|
|
109
|
+
sizing: [],
|
|
110
|
+
layout: []
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
// Structure info
|
|
114
|
+
structure: {
|
|
115
|
+
childCount: 0,
|
|
116
|
+
depth: 0,
|
|
117
|
+
hasText: false,
|
|
118
|
+
hasImage: false,
|
|
119
|
+
hasIcon: false
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Figma-specific
|
|
123
|
+
figma: {
|
|
124
|
+
componentId: node.componentId || null,
|
|
125
|
+
isInstance: node.type === 'INSTANCE',
|
|
126
|
+
isComponent: node.type === 'COMPONENT' || node.type === 'COMPONENT_SET',
|
|
127
|
+
variantProperties: node.variantProperties || null
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Extract visual properties
|
|
132
|
+
this.extractVisualProperties(node, component);
|
|
133
|
+
|
|
134
|
+
// Process children recursively
|
|
135
|
+
if (node.children && node.children.length > 0) {
|
|
136
|
+
component.structure.childCount = node.children.length;
|
|
137
|
+
|
|
138
|
+
node.children.forEach(child => {
|
|
139
|
+
const childComponent = this.parseNode(child, component);
|
|
140
|
+
if (childComponent) {
|
|
141
|
+
component.children.push(childComponent.id);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Check content types
|
|
147
|
+
if (node.type === 'TEXT') {
|
|
148
|
+
component.structure.hasText = true;
|
|
149
|
+
component.textContent = node.characters || '';
|
|
150
|
+
}
|
|
151
|
+
if (node.type === 'VECTOR' || (node.name && node.name.toLowerCase().includes('icon'))) {
|
|
152
|
+
component.structure.hasIcon = true;
|
|
153
|
+
}
|
|
154
|
+
if (node.type === 'RECTANGLE' && node.fills?.some(f => f.type === 'IMAGE')) {
|
|
155
|
+
component.structure.hasImage = true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.components.push(component);
|
|
159
|
+
return component;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
classifyNodeType(node) {
|
|
163
|
+
const type = node.type;
|
|
164
|
+
const childCount = node.children?.length || 0;
|
|
165
|
+
const name = (node.name || '').toLowerCase();
|
|
166
|
+
|
|
167
|
+
// Explicit component types from Figma
|
|
168
|
+
if (type === 'COMPONENT' || type === 'INSTANCE') {
|
|
169
|
+
if (childCount <= 2) return 'atom';
|
|
170
|
+
if (childCount <= 5) return 'molecule';
|
|
171
|
+
return 'organism';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Basic elements are atoms
|
|
175
|
+
if (['TEXT', 'VECTOR', 'ELLIPSE', 'LINE', 'STAR', 'POLYGON', 'BOOLEAN_OPERATION'].includes(type)) {
|
|
176
|
+
return 'atom';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Rectangles might be atoms or containers
|
|
180
|
+
if (type === 'RECTANGLE') {
|
|
181
|
+
return 'atom';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Frames and groups
|
|
185
|
+
if (type === 'FRAME' || type === 'GROUP' || type === 'SECTION') {
|
|
186
|
+
if (childCount === 0) return 'atom';
|
|
187
|
+
if (childCount <= 3) return 'molecule';
|
|
188
|
+
if (childCount <= 8) return 'organism';
|
|
189
|
+
return 'template';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return 'unknown';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
extractVisualProperties(node, component) {
|
|
196
|
+
// Colors (fills)
|
|
197
|
+
if (node.fills && Array.isArray(node.fills)) {
|
|
198
|
+
node.fills.forEach(fill => {
|
|
199
|
+
if (fill.type === 'SOLID' && fill.color) {
|
|
200
|
+
const color = this.rgbToHex(fill.color);
|
|
201
|
+
component.css.colors.push({
|
|
202
|
+
property: 'background',
|
|
203
|
+
value: color,
|
|
204
|
+
opacity: fill.opacity ?? 1
|
|
205
|
+
});
|
|
206
|
+
this.tokens.colors.set(color, color);
|
|
207
|
+
} else if (fill.type === 'GRADIENT_LINEAR' || fill.type === 'GRADIENT_RADIAL') {
|
|
208
|
+
component.css.colors.push({
|
|
209
|
+
property: 'background',
|
|
210
|
+
value: 'gradient',
|
|
211
|
+
type: fill.type
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Strokes (borders)
|
|
218
|
+
if (node.strokes && Array.isArray(node.strokes)) {
|
|
219
|
+
node.strokes.forEach(stroke => {
|
|
220
|
+
if (stroke.type === 'SOLID' && stroke.color) {
|
|
221
|
+
const color = this.rgbToHex(stroke.color);
|
|
222
|
+
component.css.colors.push({
|
|
223
|
+
property: 'border',
|
|
224
|
+
value: color
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
if (node.strokeWeight) {
|
|
230
|
+
component.css.sizing.push({
|
|
231
|
+
property: 'borderWidth',
|
|
232
|
+
value: `${node.strokeWeight}px`
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Typography (for text nodes)
|
|
238
|
+
if (node.style) {
|
|
239
|
+
const style = node.style;
|
|
240
|
+
|
|
241
|
+
if (style.fontFamily) {
|
|
242
|
+
component.css.typography.push({
|
|
243
|
+
property: 'fontFamily',
|
|
244
|
+
value: style.fontFamily
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (style.fontSize) {
|
|
249
|
+
component.css.typography.push({
|
|
250
|
+
property: 'fontSize',
|
|
251
|
+
value: `${style.fontSize}px`
|
|
252
|
+
});
|
|
253
|
+
this.tokens.typography.set(`font-${style.fontSize}`, `${style.fontSize}px`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (style.fontWeight) {
|
|
257
|
+
component.css.typography.push({
|
|
258
|
+
property: 'fontWeight',
|
|
259
|
+
value: style.fontWeight
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (style.lineHeightPx) {
|
|
264
|
+
component.css.typography.push({
|
|
265
|
+
property: 'lineHeight',
|
|
266
|
+
value: `${style.lineHeightPx}px`
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (style.letterSpacing) {
|
|
271
|
+
component.css.typography.push({
|
|
272
|
+
property: 'letterSpacing',
|
|
273
|
+
value: `${style.letterSpacing}px`
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (style.textAlignHorizontal) {
|
|
278
|
+
component.css.typography.push({
|
|
279
|
+
property: 'textAlign',
|
|
280
|
+
value: style.textAlignHorizontal.toLowerCase()
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Spacing (padding/margins from auto-layout)
|
|
286
|
+
if (node.paddingLeft !== undefined || node.paddingTop !== undefined) {
|
|
287
|
+
const padding = {
|
|
288
|
+
top: node.paddingTop || 0,
|
|
289
|
+
right: node.paddingRight || 0,
|
|
290
|
+
bottom: node.paddingBottom || 0,
|
|
291
|
+
left: node.paddingLeft || 0
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
component.css.spacing.push({
|
|
295
|
+
property: 'padding',
|
|
296
|
+
value: padding,
|
|
297
|
+
shorthand: `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Track unique spacing values
|
|
301
|
+
Object.values(padding).forEach(v => {
|
|
302
|
+
if (v > 0) this.tokens.spacing.set(`spacing-${v}`, `${v}px`);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (node.itemSpacing !== undefined) {
|
|
307
|
+
component.css.spacing.push({
|
|
308
|
+
property: 'gap',
|
|
309
|
+
value: `${node.itemSpacing}px`
|
|
310
|
+
});
|
|
311
|
+
this.tokens.spacing.set(`gap-${node.itemSpacing}`, `${node.itemSpacing}px`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Border radius
|
|
315
|
+
if (node.cornerRadius !== undefined && node.cornerRadius > 0) {
|
|
316
|
+
component.css.radius.push({
|
|
317
|
+
property: 'borderRadius',
|
|
318
|
+
value: `${node.cornerRadius}px`
|
|
319
|
+
});
|
|
320
|
+
this.tokens.radius.set(`radius-${node.cornerRadius}`, `${node.cornerRadius}px`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Individual corner radii
|
|
324
|
+
if (node.rectangleCornerRadii && Array.isArray(node.rectangleCornerRadii)) {
|
|
325
|
+
const radii = node.rectangleCornerRadii;
|
|
326
|
+
if (radii.some(r => r > 0)) {
|
|
327
|
+
component.css.radius.push({
|
|
328
|
+
property: 'borderRadius',
|
|
329
|
+
value: radii.map(r => `${r}px`).join(' ')
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Sizing
|
|
335
|
+
if (node.absoluteBoundingBox) {
|
|
336
|
+
const box = node.absoluteBoundingBox;
|
|
337
|
+
component.css.sizing.push({
|
|
338
|
+
property: 'width',
|
|
339
|
+
value: `${Math.round(box.width)}px`
|
|
340
|
+
});
|
|
341
|
+
component.css.sizing.push({
|
|
342
|
+
property: 'height',
|
|
343
|
+
value: `${Math.round(box.height)}px`
|
|
344
|
+
});
|
|
345
|
+
} else if (node.size) {
|
|
346
|
+
component.css.sizing.push({
|
|
347
|
+
property: 'width',
|
|
348
|
+
value: `${Math.round(node.size.x)}px`
|
|
349
|
+
});
|
|
350
|
+
component.css.sizing.push({
|
|
351
|
+
property: 'height',
|
|
352
|
+
value: `${Math.round(node.size.y)}px`
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Layout mode (auto-layout)
|
|
357
|
+
if (node.layoutMode) {
|
|
358
|
+
component.css.layout.push({
|
|
359
|
+
property: 'display',
|
|
360
|
+
value: 'flex'
|
|
361
|
+
});
|
|
362
|
+
component.css.layout.push({
|
|
363
|
+
property: 'flexDirection',
|
|
364
|
+
value: node.layoutMode === 'VERTICAL' ? 'column' : 'row'
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (node.primaryAxisAlignItems) {
|
|
369
|
+
component.css.layout.push({
|
|
370
|
+
property: 'justifyContent',
|
|
371
|
+
value: this.mapAlignment(node.primaryAxisAlignItems)
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (node.counterAxisAlignItems) {
|
|
376
|
+
component.css.layout.push({
|
|
377
|
+
property: 'alignItems',
|
|
378
|
+
value: this.mapAlignment(node.counterAxisAlignItems)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Effects (shadows, blur)
|
|
383
|
+
if (node.effects && Array.isArray(node.effects)) {
|
|
384
|
+
node.effects.forEach(effect => {
|
|
385
|
+
if (effect.type === 'DROP_SHADOW' && effect.visible !== false) {
|
|
386
|
+
const color = effect.color ? this.rgbaToString(effect.color) : 'rgba(0,0,0,0.25)';
|
|
387
|
+
component.css.colors.push({
|
|
388
|
+
property: 'boxShadow',
|
|
389
|
+
value: `${effect.offset?.x || 0}px ${effect.offset?.y || 4}px ${effect.radius || 8}px ${color}`
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
rgbToHex(color) {
|
|
397
|
+
const r = Math.round((color.r || 0) * 255);
|
|
398
|
+
const g = Math.round((color.g || 0) * 255);
|
|
399
|
+
const b = Math.round((color.b || 0) * 255);
|
|
400
|
+
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`.toUpperCase();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
rgbaToString(color) {
|
|
404
|
+
const r = Math.round((color.r || 0) * 255);
|
|
405
|
+
const g = Math.round((color.g || 0) * 255);
|
|
406
|
+
const b = Math.round((color.b || 0) * 255);
|
|
407
|
+
const a = color.a ?? 1;
|
|
408
|
+
return `rgba(${r},${g},${b},${a.toFixed(2)})`;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
mapAlignment(figmaAlignment) {
|
|
412
|
+
const map = {
|
|
413
|
+
'MIN': 'flex-start',
|
|
414
|
+
'CENTER': 'center',
|
|
415
|
+
'MAX': 'flex-end',
|
|
416
|
+
'SPACE_BETWEEN': 'space-between',
|
|
417
|
+
'BASELINE': 'baseline'
|
|
418
|
+
};
|
|
419
|
+
return map[figmaAlignment] || (figmaAlignment || '').toLowerCase();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
buildHierarchy() {
|
|
423
|
+
const depthMap = new Map();
|
|
424
|
+
|
|
425
|
+
const calculateDepth = (component, depth = 0) => {
|
|
426
|
+
depthMap.set(component.id, depth);
|
|
427
|
+
component.structure.depth = depth;
|
|
428
|
+
|
|
429
|
+
component.children.forEach(childId => {
|
|
430
|
+
const child = this.components.find(c => c.id === childId);
|
|
431
|
+
if (child) {
|
|
432
|
+
calculateDepth(child, depth + 1);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// Find root components (no parent)
|
|
438
|
+
const roots = this.components.filter(c => !c.parentId);
|
|
439
|
+
roots.forEach(root => calculateDepth(root));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ============================================================
|
|
444
|
+
// CLI
|
|
445
|
+
// ============================================================
|
|
446
|
+
|
|
447
|
+
async function main() {
|
|
448
|
+
const [,, input, ...args] = process.argv;
|
|
449
|
+
|
|
450
|
+
const extractor = new FigmaExtractor();
|
|
451
|
+
|
|
452
|
+
if (input === '--stdin') {
|
|
453
|
+
// Read from stdin
|
|
454
|
+
let data = '';
|
|
455
|
+
process.stdin.setEncoding('utf8');
|
|
456
|
+
|
|
457
|
+
for await (const chunk of process.stdin) {
|
|
458
|
+
data += chunk;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const result = extractor.parse(data);
|
|
462
|
+
console.log(JSON.stringify(result, null, 2));
|
|
463
|
+
|
|
464
|
+
} else if (input && fs.existsSync(input)) {
|
|
465
|
+
// Read from file
|
|
466
|
+
const data = fs.readFileSync(input, 'utf-8');
|
|
467
|
+
const result = extractor.parse(data);
|
|
468
|
+
console.log(JSON.stringify(result, null, 2));
|
|
469
|
+
|
|
470
|
+
} else if (input) {
|
|
471
|
+
console.error(`File not found: ${input}`);
|
|
472
|
+
process.exit(1);
|
|
473
|
+
|
|
474
|
+
} else {
|
|
475
|
+
console.log(`
|
|
476
|
+
Wogi Flow - Figma Component Extractor
|
|
477
|
+
|
|
478
|
+
Usage:
|
|
479
|
+
flow figma extract <figma-data.json> Parse a saved Figma MCP response
|
|
480
|
+
flow figma extract --stdin Read Figma MCP output from stdin
|
|
481
|
+
|
|
482
|
+
Example:
|
|
483
|
+
cat figma-response.json | ./scripts/flow-figma-extract.js --stdin
|
|
484
|
+
./scripts/flow-figma-extract.js design-data.json > extracted.json
|
|
485
|
+
`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
module.exports = { FigmaExtractor };
|
|
490
|
+
|
|
491
|
+
if (require.main === module) {
|
|
492
|
+
main().catch(err => {
|
|
493
|
+
console.error(`Error: ${err.message}`);
|
|
494
|
+
process.exit(1);
|
|
495
|
+
});
|
|
496
|
+
}
|