pencil-to-code
91
总安装量
91
周安装量
#2520
全站排名
安装命令
npx skills add https://github.com/phrazzld/claude-config --skill pencil-to-code
Agent 安装分布
codex
70
opencode
69
claude-code
67
gemini-cli
64
cursor
51
antigravity
49
Skill 文档
Pencil to Code
Export Pencil .pen designs to production React/Tailwind code.
Interface
Input:
- Frame ID to export (or entire document)
- Target framework: React (default), Vue, HTML
- Optional: Component name, output path
Output:
- React component(s) with Tailwind classes
- Tailwind theme configuration (from .pen variables)
- Optional: Screenshot comparison for validation
Workflow
1. Read Design Structure
// Get full frame tree
mcp__pencil__batch_get({
filePath: "<path>.pen",
nodeIds: ["frameId"],
readDepth: 10,
resolveInstances: true,
resolveVariables: true
})
// Get design variables/theme
mcp__pencil__get_variables({ filePath: "<path>.pen" })
2. Extract Design Tokens
Transform .pen variables â Tailwind theme:
/* From .pen variables */
@theme {
--color-primary: [from variables.colors.primary];
--color-background: [from variables.colors.background];
--font-sans: [from variables.fonts.body];
/* ... */
}
Reference: references/token-extraction.md
3. Map Nodes to Components
| .pen Node Type | React Output |
|---|---|
frame with layout |
<div className="flex ..."> |
frame with children |
Component with children |
text |
<p>, <h1-6>, or <span> |
ref (instance) |
Reusable component |
rectangle |
<div> with fill |
ellipse |
<div className="rounded-full"> |
image |
<img> or fill: url() |
Reference: references/node-mapping.md
4. Generate Code
Component structure:
// components/[ComponentName].tsx
import { cn } from "@/lib/utils"
interface [ComponentName]Props {
className?: string
// Extracted props from design
}
export function [ComponentName]({ className, ...props }: [ComponentName]Props) {
return (
<div className={cn("[tailwind classes]", className)}>
{/* Nested structure */}
</div>
)
}
Tailwind mapping:
.pen property â Tailwind class
--------------------------------
fill: #000 â bg-black
layout: horizontal â flex flex-row
gap: 16 â gap-4
padding: [16,24,16,24] â py-4 px-6
fontSize: 24 â text-2xl
fontWeight: 700 â font-bold
cornerRadius: [8,8,8,8] â rounded-lg
5. Validate (Optional)
// Screenshot the .pen frame
mcp__pencil__get_screenshot({ nodeId: "frameId" })
// Compare visually with rendered React
// (Manual step or browser automation)
6. Output
## Generated Components
### [ComponentName]
- File: `components/[ComponentName].tsx`
- Props: [list extracted props]
### Theme Configuration
- File: `app/globals.css` (additions)
## Verification
Screenshot comparison: [attached]
Translation Rules
Layout System
.pen Tailwind
--------------------------------------
layout: "vertical" â flex flex-col
layout: "horizontal" â flex flex-row
layout: "grid" â grid
alignItems: "center" â items-center
justifyContent: "center" â justify-center
gap: 8 â gap-2
gap: 16 â gap-4
gap: 24 â gap-6
width: "fill_container" â w-full
height: "fill_container" â h-full
Spacing (8-point grid)
.pen padding Tailwind
----------------------------------------
[8,8,8,8] â p-2
[16,16,16,16] â p-4
[16,24,16,24] â py-4 px-6
[24,32,24,32] â py-6 px-8
Typography
.pen Tailwind
----------------------------------------
fontSize: 12 â text-xs
fontSize: 14 â text-sm
fontSize: 16 â text-base
fontSize: 20 â text-xl
fontSize: 24 â text-2xl
fontSize: 32 â text-3xl
fontSize: 48 â text-5xl
fontWeight: 400 â font-normal
fontWeight: 500 â font-medium
fontWeight: 600 â font-semibold
fontWeight: 700 â font-bold
Colors
.pen Tailwind
----------------------------------------
fill: "#FFFFFF" â bg-white
fill: "#000000" â bg-black
fill: variable â bg-[var(--color-name)]
textColor: "#6B7280" â text-gray-500
stroke: "#E5E5E5" â border-gray-200
Border Radius
.pen cornerRadius Tailwind
----------------------------------------
[0,0,0,0] â rounded-none
[4,4,4,4] â rounded
[8,8,8,8] â rounded-lg
[16,16,16,16] â rounded-2xl
[9999,9999,9999,9999] â rounded-full
Constraints
- Single concern: Export â code. No design modifications.
- Tailwind 4 @theme: CSS-first token system
- React + TypeScript: Default output target
- Semantic HTML: Choose appropriate elements
- Accessibility: Include aria attributes where detectable
References
references/node-mapping.mdâ Complete node â component mappingreferences/token-extraction.mdâ Variable â theme extractiondesign-tokens/â Token system conventions
Integration
Called by:
design-explorationorchestrator (after direction selection)- Direct user invocation
Composes:
design-tokens(for theme structure)