pencil-to-code について
Pencil の .pen デザインを React、Vue、HTML に出力するスキルで、標準の出力先は React と Tailwind です。デザイン変数から Tailwind のテーマ設定を作成でき、任意でスクリーンショットを比較して検証します。
主な機能
- 01React、Vue、HTMLへの出力
- 02デザインノードをコンポーネントに変換
- 03変数からTailwindテーマを抽出
- 04レイアウト、余白、色、文字の対応付け
- 05任意のスクリーンショット比較
活用シーン
- 01Pencilのフレームをフロントエンドコンポーネントに変換
- 02.penの変数からTailwindテーマを作成
- 03出力とデザインの見た目の差を確認
MCP 対応
ワークフローでは `mcp__pencil__batch_get` でデザイン構造と変数を読み取り、`mcp__pencil__get_screenshot` でフレームの画像を取得できます。
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ phrazzld/ claude-config --skill pencil-to-codeインストール後、Claude Code で/pencil-to-codeを入力して読み込まれたか確認します。
同梱ファイルreferences/node-mapping.md
詳細
Pencil からコードへ
Pencil の .pen デザインを、本番環境向けの React/Tailwind コードにエクスポートします。
インターフェース
入力:
- エクスポートするフレーム ID(またはドキュメント全体)
- 対象フレームワーク:React(デフォルト)、Vue、HTML
- 任意:コンポーネント名、出力パス
出力:
- Tailwind クラスを含む React コンポーネント
- Tailwind テーマ設定(.pen の変数から生成)
- 任意:検証用のスクリーンショット比較
ワークフロー
1. デザイン構造を読み取る
// 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. デザイントークンを抽出する
.pen の変数を Tailwind テーマに変換します:
/* From .pen variables */
@theme {
--color-primary: [from variables.colors.primary];
--color-background: [from variables.colors.background];
--font-sans: [from variables.fonts.body];
/* ... */
}
参照:references/token-extraction.md
3. ノードをコンポーネントにマッピングする
| .pen のノードタイプ | React の出力 |
|---|---|
レイアウトを持つ frame | <div className="flex ..."> |
子要素を持つ frame | 子要素を含むコンポーネント |
text | <p>、<h1-6>、または <span> |
ref(インスタンス) | 再利用可能なコンポーネント |
rectangle | 塗りつぶしを持つ <div> |
ellipse | <div className="rounded-full"> |
image | <img> または fill: url() |
参照:references/node-mapping.md
4. コードを生成する
コンポーネント構造:
// 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 のマッピング:
.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. 検証する(任意)
// Screenshot the .pen frame
mcp__pencil__get_screenshot({ nodeId: "frameId" })
// Compare visually with rendered React
// (Manual step or browser automation)
6. 出力する
## Generated Components
### [ComponentName]
- File: `components/[ComponentName].tsx`
- Props: [list extracted props]
### Theme Configuration
- File: `app/globals.css` (additions)
## Verification
Screenshot comparison: [attached]
翻訳ルール
レイアウトシステム
.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
間隔(8ポイントグリッド)
.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
タイポグラフィ
.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
色
.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
角丸
.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
制約
- 単一の目的:エクスポートしてコード化します。デザインの変更は行いません。
- Tailwind 4 @theme:CSS ファーストのトークンシステム
- React + TypeScript:デフォルトの出力先
- セマンティック HTML:適切な要素を選択します
- アクセシビリティ:検出可能な場合は aria 属性を含めます
参照
references/node-mapping.md— ノードからコンポーネントへの完全なマッピングreferences/token-extraction.md— 変数からテーマへの抽出design-tokens/— トークンシステムの規約
統合
呼び出し元:
design-explorationオーケストレーター(方向性の選定後)- ユーザーによる直接呼び出し
構成要素:
design-tokens(テーマ構造用)
コメント
Markdown 対応