shaul1991

Design Figma Agent

5. **비동기 처리**: 폰트 로드 등 비동기 작업은 await 사용

shaul1991 0 Updated 4mo ago
GitHub

Install

npx skillscat add shaul1991/shaul-agents-plugin/skills-design-figma

Install via the SkillsCat registry.

SKILL.md

Design Figma Agent

Figma Plugin API 코드를 생성하여 Scripter 플러그인에서 실행할 수 있도록 지원합니다.

역í•

  • UI 컴포넌트를 Figma Plugin API 코드로 변환
  • Figma 캔버스에 디자인 요소 자동 생성
  • 디자인 시스템 컴포넌트 코드 생성

트리거 키워드

  • figma, 피그마, scripter, 스크립터
  • UI 생성, 컴포넌트 생성, 디자인 생성

워크플로우

  1. 사용자 요청 분석 (UI 컴포넌트, 레이아웃, 스타일 등)
  2. Figma Plugin API 코드 생성
  3. Scripter 플러그인에서 실행 가능한 형태로 출력
  4. 사용자가 Figma Scripter에 붙여넣기 후 실행

Figma Plugin API 기본 지식

도형 생성

// Rectangle
const rect = figma.createRectangle()
rect.resize(width, height)
rect.x = x
rect.y = y
rect.fills = [{ type: 'SOLID', color: { r: 0, g: 0, b: 0 } }]
rect.cornerRadius = 8

// Ellipse
const ellipse = figma.createEllipse()
ellipse.resize(100, 100)

// Line
const line = figma.createLine()
line.resize(200, 0)
line.strokes = [{ type: 'SOLID', color: { r: 0, g: 0, b: 0 } }]

텍스트 생성

const text = figma.createText()
await figma.loadFontAsync({ family: "Inter", style: "Regular" })
text.characters = "Hello World"
text.fontSize = 16
text.fills = [{ type: 'SOLID', color: { r: 0, g: 0, b: 0 } }]

Frame 생성

const frame = figma.createFrame()
frame.resize(400, 300)
frame.name = "Card Component"
frame.fills = [{ type: 'SOLID', color: { r: 1, g: 1, b: 1 } }]
frame.cornerRadius = 12

// Auto Layout 설정
frame.layoutMode = "VERTICAL"
frame.primaryAxisAlignItems = "CENTER"
frame.counterAxisAlignItems = "CENTER"
frame.itemSpacing = 16
frame.paddingTop = 24
frame.paddingBottom = 24
frame.paddingLeft = 24
frame.paddingRight = 24

컴포넌트 생성

const component = figma.createComponent()
component.resize(200, 48)
component.name = "Button"

그룹화

const group = figma.group([rect, text], figma.currentPage)
group.name = "My Group"

색상 변환 유틸리티

// HEX to RGB (0-1 범위)
function hexToRgb(hex: string) {
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
  return result ? {
    r: parseInt(result[1], 16) / 255,
    g: parseInt(result[2], 16) / 255,
    b: parseInt(result[3], 16) / 255
  } : { r: 0, g: 0, b: 0 }
}

그림자 효과

node.effects = [{
  type: 'DROP_SHADOW',
  color: { r: 0, g: 0, b: 0, a: 0.15 },
  offset: { x: 0, y: 4 },
  radius: 8,
  spread: 0,
  visible: true,
  blendMode: 'NORMAL'
}]

스트로크 (테두리)

node.strokes = [{ type: 'SOLID', color: { r: 0.9, g: 0.9, b: 0.9 } }]
node.strokeWeight = 1

뷰포트 이동

figma.viewport.scrollAndZoomIntoView([node])
figma.currentPage.selection = [node]

코드 출력 형식

Scripter 플러그인에서 바로 실행할 수 있도록 다음 형식으로 출력:

// [컴포넌트 이름] - Scripter에서 실행
// 생성 위치: 현재 선택 위치 또는 (0, 0)

// === 코드 시작 ===

// 폰트 로드 (텍스트 사용 시 필수)
await figma.loadFontAsync({ family: "Inter", style: "Regular" })

// 메인 코드
const frame = figma.createFrame()
// ... 코드 ...

// 뷰포트 이동 및 선택
figma.currentPage.selection = [frame]
figma.viewport.scrollAndZoomIntoView([frame])

// === 코드 끝 ===

주의사항

  1. 폰트 로드 필수: 텍스트 사용 전 반드시 figma.loadFontAsync() 호출
  2. 색상 범위: RGB 값은 0-1 범위 (255로 나누기)
  3. 좌표계: 왼쪽 상단이 (0, 0), 오른쪽/아래로 갈수록 증가
  4. appendChild: Frame에 자식 요소 추가 시 사용
  5. 비동기 처리: 폰트 로드 등 비동기 작업은 await 사용