@dannote/figma-use 0.1.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/LICENSE +21 -0
- package/README.md +219 -0
- package/bin/figma-use.js +21 -0
- package/dist/cli/index.js +4136 -0
- package/dist/proxy/index.js +19451 -0
- package/package.json +59 -0
- package/packages/plugin/dist/main.js +996 -0
- package/packages/plugin/dist/manifest.json +15 -0
- package/packages/plugin/dist/ui.html +78 -0
- package/packages/plugin/dist/ui.js +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Danila Poyarkov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# figma-use
|
|
2
|
+
|
|
3
|
+
Control Figma from the command line. Like [browser-use](https://github.com/browser-use/browser-use), but for Figma.
|
|
4
|
+
|
|
5
|
+
Built for AI agents to create and manipulate Figma designs programmatically.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun install -g @dannote/figma-use
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Start the proxy server
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
figma-use proxy
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Load the Figma plugin
|
|
22
|
+
|
|
23
|
+
Open Figma, go to **Plugins → Development → Import plugin from manifest**, and select:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
~/.bun/install/global/node_modules/@dannote/figma-use/packages/plugin/dist/manifest.json
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or find it with:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
figma-use plugin
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Run commands
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Create shapes
|
|
39
|
+
figma-use create-rectangle --x 0 --y 0 --width 200 --height 100 --fill "#3B82F6" --radius 8
|
|
40
|
+
|
|
41
|
+
# Create text
|
|
42
|
+
figma-use create-text --x 50 --y 40 --text "Hello Figma" --fontSize 24 --fill "#FFFFFF"
|
|
43
|
+
|
|
44
|
+
# Get node info
|
|
45
|
+
figma-use get-node --id "1:2"
|
|
46
|
+
|
|
47
|
+
# Export to PNG
|
|
48
|
+
figma-use export-node --id "1:2" --format PNG --scale 2 --output design.png
|
|
49
|
+
|
|
50
|
+
# Take screenshot
|
|
51
|
+
figma-use screenshot --output viewport.png
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Output Format
|
|
55
|
+
|
|
56
|
+
Human-readable by default:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
$ figma-use create-rectangle --x 0 --y 0 --width 100 --height 50 --fill "#FF0000"
|
|
60
|
+
✓ Created rect "Rectangle"
|
|
61
|
+
id: 1:23
|
|
62
|
+
box: 100x50 at (0, 0)
|
|
63
|
+
fill: #FF0000
|
|
64
|
+
|
|
65
|
+
$ figma-use get-children --id "1:2"
|
|
66
|
+
[0] frame "Header" (1:3)
|
|
67
|
+
box: 1200x80 at (0, 0)
|
|
68
|
+
fill: #FFFFFF
|
|
69
|
+
|
|
70
|
+
[1] text "Title" (1:4)
|
|
71
|
+
box: 200x32 at (20, 24)
|
|
72
|
+
font: 24px
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Add `--json` for machine-readable output:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
$ figma-use get-node --id "1:2" --json
|
|
79
|
+
{
|
|
80
|
+
"id": "1:2",
|
|
81
|
+
"name": "Frame",
|
|
82
|
+
"type": "FRAME",
|
|
83
|
+
...
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Commands
|
|
88
|
+
|
|
89
|
+
### Shapes
|
|
90
|
+
|
|
91
|
+
| Command | Description |
|
|
92
|
+
|---------|-------------|
|
|
93
|
+
| `create-rectangle` | Create rectangle with optional fill, stroke, radius |
|
|
94
|
+
| `create-ellipse` | Create ellipse/circle |
|
|
95
|
+
| `create-line` | Create line |
|
|
96
|
+
| `create-polygon` | Create polygon |
|
|
97
|
+
| `create-star` | Create star |
|
|
98
|
+
| `create-vector` | Create vector path |
|
|
99
|
+
|
|
100
|
+
### Containers
|
|
101
|
+
|
|
102
|
+
| Command | Description |
|
|
103
|
+
|---------|-------------|
|
|
104
|
+
| `create-frame` | Create frame with optional auto-layout |
|
|
105
|
+
| `create-component` | Create component |
|
|
106
|
+
| `create-instance` | Create component instance |
|
|
107
|
+
| `create-section` | Create section |
|
|
108
|
+
| `group-nodes` | Group nodes |
|
|
109
|
+
| `ungroup-node` | Ungroup |
|
|
110
|
+
|
|
111
|
+
### Text
|
|
112
|
+
|
|
113
|
+
| Command | Description |
|
|
114
|
+
|---------|-------------|
|
|
115
|
+
| `create-text` | Create text with font, size, color |
|
|
116
|
+
| `set-text` | Update text content |
|
|
117
|
+
| `set-font` | Change font family, size, weight |
|
|
118
|
+
| `set-text-properties` | Line height, letter spacing, alignment |
|
|
119
|
+
|
|
120
|
+
### Styling
|
|
121
|
+
|
|
122
|
+
| Command | Description |
|
|
123
|
+
|---------|-------------|
|
|
124
|
+
| `set-fill-color` | Set fill color |
|
|
125
|
+
| `set-stroke-color` | Set stroke color and weight |
|
|
126
|
+
| `set-corner-radius` | Set corner radius (uniform or individual) |
|
|
127
|
+
| `set-opacity` | Set opacity |
|
|
128
|
+
| `set-effect` | Add shadow or blur |
|
|
129
|
+
| `set-blend-mode` | Set blend mode |
|
|
130
|
+
|
|
131
|
+
### Layout
|
|
132
|
+
|
|
133
|
+
| Command | Description |
|
|
134
|
+
|---------|-------------|
|
|
135
|
+
| `set-layout` | Enable auto-layout (horizontal/vertical) |
|
|
136
|
+
| `set-layout-child` | Set child sizing (fill/fixed/hug) |
|
|
137
|
+
| `set-constraints` | Set resize constraints |
|
|
138
|
+
| `set-min-max` | Set min/max width/height |
|
|
139
|
+
|
|
140
|
+
### Transform
|
|
141
|
+
|
|
142
|
+
| Command | Description |
|
|
143
|
+
|---------|-------------|
|
|
144
|
+
| `move-node` | Move to x, y |
|
|
145
|
+
| `resize-node` | Resize to width, height |
|
|
146
|
+
| `set-rotation` | Rotate by angle |
|
|
147
|
+
| `set-parent` | Move to different parent |
|
|
148
|
+
|
|
149
|
+
### Export
|
|
150
|
+
|
|
151
|
+
| Command | Description |
|
|
152
|
+
|---------|-------------|
|
|
153
|
+
| `export-node` | Export node as PNG/SVG/PDF |
|
|
154
|
+
| `screenshot` | Screenshot current viewport |
|
|
155
|
+
|
|
156
|
+
### Query
|
|
157
|
+
|
|
158
|
+
| Command | Description |
|
|
159
|
+
|---------|-------------|
|
|
160
|
+
| `get-node` | Get node properties |
|
|
161
|
+
| `get-children` | Get child nodes |
|
|
162
|
+
| `get-selection` | Get selected nodes |
|
|
163
|
+
| `get-pages` | List all pages |
|
|
164
|
+
| `find-by-name` | Find nodes by name |
|
|
165
|
+
|
|
166
|
+
### Navigation
|
|
167
|
+
|
|
168
|
+
| Command | Description |
|
|
169
|
+
|---------|-------------|
|
|
170
|
+
| `set-current-page` | Switch to page |
|
|
171
|
+
| `zoom-to-fit` | Zoom to fit nodes |
|
|
172
|
+
| `set-viewport` | Set viewport position and zoom |
|
|
173
|
+
|
|
174
|
+
## Environment Variables
|
|
175
|
+
|
|
176
|
+
| Variable | Default | Description |
|
|
177
|
+
|----------|---------|-------------|
|
|
178
|
+
| `PORT` | 38451 | Proxy server port |
|
|
179
|
+
| `FIGMA_PROXY_URL` | `http://localhost:38451` | Proxy URL for CLI |
|
|
180
|
+
|
|
181
|
+
## For AI Agents
|
|
182
|
+
|
|
183
|
+
figma-use is designed for AI agents. Example with Claude:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
import anthropic
|
|
187
|
+
import subprocess
|
|
188
|
+
|
|
189
|
+
def figma(cmd):
|
|
190
|
+
result = subprocess.run(
|
|
191
|
+
f"figma-use {cmd} --json",
|
|
192
|
+
shell=True, capture_output=True, text=True
|
|
193
|
+
)
|
|
194
|
+
return result.stdout
|
|
195
|
+
|
|
196
|
+
client = anthropic.Anthropic()
|
|
197
|
+
|
|
198
|
+
response = client.messages.create(
|
|
199
|
+
model="claude-sonnet-4-20250514",
|
|
200
|
+
messages=[{
|
|
201
|
+
"role": "user",
|
|
202
|
+
"content": "Create a blue button with white text 'Click me'"
|
|
203
|
+
}],
|
|
204
|
+
tools=[{
|
|
205
|
+
"name": "figma",
|
|
206
|
+
"description": "Run figma-use CLI command",
|
|
207
|
+
"input_schema": {
|
|
208
|
+
"type": "object",
|
|
209
|
+
"properties": {
|
|
210
|
+
"command": {"type": "string"}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}]
|
|
214
|
+
)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|
package/bin/figma-use.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
import { dirname, join } from 'path'
|
|
5
|
+
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const args = process.argv.slice(2)
|
|
8
|
+
|
|
9
|
+
// If first arg is 'proxy' or 'plugin', handle specially
|
|
10
|
+
if (args[0] === 'proxy') {
|
|
11
|
+
const proxyPath = join(__dirname, '..', 'dist', 'proxy', 'index.js')
|
|
12
|
+
spawn('bun', ['run', proxyPath], { stdio: 'inherit' })
|
|
13
|
+
} else if (args[0] === 'plugin') {
|
|
14
|
+
const pluginPath = join(__dirname, '..', 'packages', 'plugin', 'dist')
|
|
15
|
+
console.log(`Plugin files at: ${pluginPath}`)
|
|
16
|
+
console.log('Import manifest.json into Figma via Plugins > Development > Import plugin from manifest')
|
|
17
|
+
} else {
|
|
18
|
+
// CLI command
|
|
19
|
+
const cliPath = join(__dirname, '..', 'dist', 'cli', 'index.js')
|
|
20
|
+
spawn('bun', ['run', cliPath, ...args], { stdio: 'inherit' })
|
|
21
|
+
}
|