GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — atlas-plugin/src/main.ts at main · instil/atlas-plugin

Expand file tree

/

main.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
150 lines (128 loc) · 4.47 KB
/

main.ts

Copy path

File metadata and controls

150 lines (128 loc) · 4.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// This file handles the main plugin logic
/**
* Figma Plugin: Design → Prompt Compiler
*
* Goal:
* - Read selected FRAME nodes from the Figma canvas
* - Traverse their children recursively
* - Extract layout, spacing, typography, colors, and component metadata
* - Normalize Figma-specific data into a deterministic JSON schema
* - Compile that schema into a strict, pixel-accurate prompt
*
* Constraints:
* - Do NOT generate code from screenshots
* - Prefer Auto Layout data over absolute positioning
* - Be explicit and deterministic (no guessing)
* - This plugin does NOT generate UI code directly
*
* Output:
* - A structured JSON representation of each selected frame
* - A human-readable prompt suitable for tools like v0.dev
*
* Tech:
* - TypeScript
* - Figma Plugin API
*/
import { normalizeFrame, extractDesignSystem } from './normalizeNode';
import { compileUnifiedPrompt } from './promptCompiler';
import type { ProcessedFrame } from './types';
/**
* Sanitize data for UI communication by handling symbols and circular references
* Converts symbols to 'MIXED' string and removes functions
*/
function sanitizeDataForUI(data: any): any {
return JSON.parse(JSON.stringify(data, (key, value) => {
if (typeof value === 'symbol') return 'MIXED';
return value;
}));
}
// Figma provides __html__ automatically when ui is specified in manifest
// @ts-ignore - __html__ is injected by Figma
figma.showUI(__html__, { width: 480, height: 720 });
figma.ui.onmessage = async (msg) => {
if (msg.type === 'process-selection') {
const selection = figma.currentPage.selection;
if (selection.length === 0) {
figma.ui.postMessage({ type: 'error', message: 'Please select at least one frame' });
return;
}
// Filter only FRAME nodes
const frames = selection.filter(node => node.type === 'FRAME') as FrameNode[];
if (frames.length === 0) {
figma.ui.postMessage({
type: 'error',
message: 'Please select one or more FRAME nodes (not groups or other types)'
});
return;
}
try {
// Extract design system from all frames
const designSystem = extractDesignSystem(frames);
// Process frames (but don't generate prompt yet)
const processedFrames: ProcessedFrame[] = [];
for (const frame of frames) {
const normalized = normalizeFrame(frame);
processedFrames.push(normalized);
}
// Export frame screenshots
const screenshots: { [key: string]: string } = {};
for (const frame of frames) {
try {
// Export as PNG with 2x scale for better quality
const imageBytes = await frame.exportAsync({
format: 'PNG',
constraint: { type: 'SCALE', value: 2 }
});
// Convert to base64
const base64 = figma.base64Encode(imageBytes);
screenshots[frame.id] = `data:image/png;base64,${base64}`;
} catch (err) {
console.error(`Failed to export frame ${frame.name}:`, err);
}
}
// Send design system for review/editing (Step 1)
const sanitizedData = sanitizeDataForUI({
frames: processedFrames,
designSystem: designSystem,
screenshots: screenshots,
count: frames.length
});
figma.ui.postMessage({
type: 'design-system-extracted',
data: sanitizedData
});
} catch (error) {
figma.ui.postMessage({
type: 'error',
message: `Error processing frames: ${error instanceof Error ? error.message : String(error)}`
});
}
}
if (msg.type === 'generate-prompt') {
// Step 2: Generate prompt with edited design system
try {
const { frames, designSystem, screenshots, sections } = msg.data;
// Compile into single unified prompt with optional sections
const unifiedPrompt = compileUnifiedPrompt(frames, designSystem, sections || {});
const sanitizedData = sanitizeDataForUI({
frames: frames,
designSystem: designSystem,
prompt: unifiedPrompt,
screenshots: screenshots,
count: frames.length
});
figma.ui.postMessage({
type: 'prompt-generated',
data: sanitizedData
});
} catch (error) {
figma.ui.postMessage({
type: 'error',
message: `Error generating prompt: ${error instanceof Error ? error.message : String(error)}`
});
}
}
if (msg.type === 'cancel') {
figma.closePlugin();
}
};
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.