@nnao45/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.
@@ -0,0 +1,25 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <style>
5
+ body {
6
+ font-family: Inter, system-ui, sans-serif;
7
+ font-size: 12px;
8
+ padding: 16px;
9
+ margin: 0;
10
+ }
11
+ h1 {
12
+ font-size: 14px;
13
+ margin: 0 0 16px;
14
+ }
15
+ #status {
16
+ font-weight: 500;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <h1>Figma Bridge</h1>
22
+ <p id="status">○ Connecting...</p>
23
+ <script src="ui.js"></script>
24
+ </body>
25
+ </html>
@@ -0,0 +1,74 @@
1
+ const PROXY_URL = 'ws://localhost:38451/plugin'
2
+
3
+ console.log('[Figma Bridge] UI loaded')
4
+
5
+ let ws: WebSocket | null = null
6
+ let statusEl: HTMLElement | null = null
7
+ let currentSessionId: string | null = null
8
+ let currentFileName: string | null = null
9
+
10
+ function connect() {
11
+ ws = new WebSocket(PROXY_URL)
12
+
13
+ ws.onopen = () => {
14
+ console.log('[Figma Bridge] Connected to proxy')
15
+ // Request file info from main thread
16
+ parent.postMessage({ pluginMessage: { type: 'get-file-info' } }, '*')
17
+ updateStatus(true)
18
+ }
19
+
20
+ ws.onclose = () => {
21
+ updateStatus(false)
22
+ setTimeout(connect, 2000)
23
+ }
24
+
25
+ ws.onerror = () => {
26
+ ws?.close()
27
+ }
28
+
29
+ ws.onmessage = (event) => {
30
+ const data = JSON.parse(event.data) as { id: string; command: string; args?: unknown }
31
+ parent.postMessage({ pluginMessage: { type: 'command', ...data } }, '*')
32
+ }
33
+ }
34
+
35
+ window.onmessage = (event) => {
36
+ const msg = event.data.pluginMessage as {
37
+ type: string
38
+ id?: string
39
+ result?: unknown
40
+ error?: string
41
+ sessionId?: string
42
+ fileName?: string
43
+ }
44
+
45
+ if (msg.type === 'file-info' && ws) {
46
+ currentSessionId = msg.sessionId || null
47
+ currentFileName = msg.fileName || null
48
+ // Register this plugin instance with proxy
49
+ ws.send(
50
+ JSON.stringify({
51
+ type: 'register',
52
+ sessionId: currentSessionId,
53
+ fileName: currentFileName
54
+ })
55
+ )
56
+ console.log('[Figma Bridge] Registered file:', currentFileName, currentSessionId)
57
+ return
58
+ }
59
+
60
+ if (msg.type !== 'result' || !ws) return
61
+ ws.send(JSON.stringify({ id: msg.id, result: msg.result, error: msg.error }))
62
+ }
63
+
64
+ function updateStatus(connected: boolean) {
65
+ if (statusEl) {
66
+ statusEl.textContent = connected ? '✓ Connected' : '○ Connecting...'
67
+ statusEl.style.color = connected ? '#0a0' : '#999'
68
+ }
69
+ }
70
+
71
+ document.addEventListener('DOMContentLoaded', () => {
72
+ statusEl = document.getElementById('status')
73
+ connect()
74
+ })