pencil-design-system
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePencil Design System Generator
Pencil设计系统生成器
Generate a complete, Mews-inspired design system in a Pencil file. Research the business domain, create ~60 themed tokens, build visual foundation documentation, ~25 reusable components organized by category, and composition patterns — all from a single prompt like "build a design system for a bakery." Domain screens are generated only if the user explicitly requests them.
.pen在Pencil中生成一个完整的、受Mews启发的设计系统,保存为.pen文件。只需一个提示(如“为烘焙店搭建设计系统”),即可完成业务领域调研、创建约60个主题化设计令牌、构建视觉基础文档、按类别组织约25个可复用组件,以及设计组合模式。仅当用户明确要求时,才会生成特定领域的界面。
Input
输入
The user provides a business domain (e.g., "bakery", "fitness app", "SaaS dashboard"). Optional extras: brand name, color preferences, font preferences, specific screens wanted, light/dark theme preference. If the user gives only a domain, infer everything else from research.
If the user specifies colors or fonts: Use their values as the primary/accent/background tokens in Phase 3 and derive the remaining palette around them (secondary, muted, foregrounds). Research still runs to fill in gaps, but user preferences take priority over both research and fallback tables.
用户需提供一个业务领域(例如“烘焙店”、“健身应用”、“SaaS仪表盘”)。可选附加信息:品牌名称、颜色偏好、字体偏好、想要的特定界面、亮色/暗色主题偏好。如果用户仅提供领域,则通过调研推断其他所有信息。
若用户指定颜色或字体: 在第3阶段将其值映射为主要/强调/背景令牌,并围绕这些值推导其余调色板(次要、柔和、前景色)。仍会通过调研填补空白,但用户偏好优先于调研结果和备用表格。
Canvas Organization
画布布局
The canvas is laid out left-to-right in three core sections (always created), plus an optional screens section:
[Foundations 1440×2400] → 100px gap → [Components 1440×2400] → 100px gap → [Patterns 1440×1800] → (optional) [Screens →]- Foundations — Visual documentation: color palette swatches, typography specimens, spacing scale, elevation examples, border radius showcase.
- Components — All ~25 reusable components, organized under category sub-frames (Buttons, Inputs, Typography, Badges, Alerts, Cards, Navigation, Tables, etc.).
- Patterns — Composition showcases: form pattern, data display pattern, navigation pattern, card layout pattern. Each uses component refs to demonstrate real usage.
- Screens (only if user requests) — 3–5 domain-relevant screens placed to the right of Patterns.
No components live at the document root except these section frames and the optional navigation index.
画布从左到右分为三个核心区域(必创建),外加一个可选的界面区域:
[Foundations 1440×2400] → 100px gap → [Components 1440×2400] → 100px gap → [Patterns 1440×1800] → (optional) [Screens →]- Foundations(基础层) —— 视觉文档:调色板样本、排版示例、间距尺度、层级阴影示例、圆角展示。
- Components(组件层) —— 所有约25个可复用组件,按类别子框架组织(按钮、输入框、排版、徽章、提示框、卡片、导航、表格等)。
- Patterns(模式层) —— 组合展示:表单模式、数据展示模式、导航模式、卡片布局模式。每个模式都使用组件引用来演示实际用法。
- Screens(界面层) (仅用户要求时创建) —— 3-5个与领域相关的界面,放置在Patterns区域右侧。
除这些区域框架和可选的导航索引外,所有组件不得直接放在文档根节点下。
Workflow
工作流程
Execute these 10 phases in order. Each phase builds on the previous. Never skip phases. Reference files in contain detailed specs — load them as each phase begins.
references/按顺序执行以下10个阶段,每个阶段都基于前一阶段的成果。不得跳过任何阶段。每个阶段开始前,需加载中的对应参考文件。
references/Phase 1 — Research the Domain
阶段1 —— 业务领域调研
Use to study the domain's design conventions. Identify five pillars: color palette, typography, imagery themes, screen inventory, and UI density/tone. Document findings as a design brief.
WebSearchTypography is research-driven, not table-driven. Run specific font research queries (e.g., , ) and validate against 3–5 real websites in the domain. The font pairing table in is a fallback — always prefer research-validated choices. See .
"bakery website fonts 2026""best Google Fonts for bakery"domain-research-guide.mdreferences/domain-research-guide.md使用研究该领域的设计规范。确定五大核心:调色板、排版、图像主题、界面清单、UI密度与风格。将调研结果整理为设计 brief。
WebSearch排版需基于调研,而非表格。 运行特定的字体调研查询(例如、),并与该领域的3-5个真实网站进行验证。中的字体配对表仅作为备选,优先选择经调研验证的字体。详见。
"bakery website fonts 2026""best Google Fonts for bakery"domain-research-guide.mdreferences/domain-research-guide.mdPhase 2 — Initialize the Pencil Document
阶段2 —— 初始化Pencil文档
- Call .
get_editor_state({ include_schema: true }) - If no active document, call .
open_document("new") - Call .
get_guidelines({ topic: "design-system" }) - Call then
get_style_guide_tags()with 5–10 domain-matching tags.get_style_guide({ tags: [...] }) - Call to check for existing tokens.
get_variables({ filePath })
Merge the style guide with Phase 1 research to form the final design direction.
- 调用。
get_editor_state({ include_schema: true }) - 若无活跃文档,调用。
open_document("new") - 调用。
get_guidelines({ topic: "design-system" }) - 调用,然后传入5-10个与领域匹配的标签调用
get_style_guide_tags()。get_style_guide({ tags: [...] }) - 调用检查是否存在现有令牌。
get_variables({ filePath })
将风格指南与阶段1的调研结果合并,形成最终设计方向。
Phase 3 — Create Design Tokens
阶段3 —— 创建设计令牌
Call to create the full token system (~60 tokens). Every color, font, radius, spacing value, shadow, font size, and line height is a variable.
set_variablesHandling user-specified colors: If the user provided color preferences (e.g., "terracotta and cream"), map them to the appropriate tokens (, , ) and derive the rest of the palette (secondary, muted, foregrounds, borders) to complement. The industry palette tables are starting points, not mandates.
--primary--background--accentPost-creation color changes: Since all components use token references (not hardcoded hex), calling again with new color values updates the entire design system instantly — every component, pattern, and screen inherits the change. No per-node updates needed.
$--set_variablesToken categories:
| Category | Count | Examples |
|---|---|---|
| Core colors | 19 | |
| Semantic colors | 8 | |
| Typography | 3 | |
| Border radius | 6 | |
| Spacing | 12 | |
| Shadows | 4 | |
| Font sizes | 9 | |
| Line heights | 3 | |
Set up theme axis . All token values are domain-tailored. See for full JSON payloads.
{ "mode": ["light", "dark"] }references/design-tokens-reference.mdPost-creation verification: After calling , immediately call and verify that every color token's values show and (not ). If theme mappings are missing, the call used the wrong format — see the CRITICAL warning in .
set_variablesget_variables"theme":{"mode":"light"}"theme":{"mode":"dark"}"theme":{}set_variablesdesign-tokens-reference.md调用创建完整的令牌系统(约60个令牌)。所有颜色、字体、圆角、间距值、阴影、字号和行高均设为变量。
set_variables处理用户指定的颜色: 如果用户提供了颜色偏好(例如“赤陶色和奶油色”),将其映射到对应的令牌(、、),并推导其余调色板(次要、柔和、前景色、边框)以形成互补。行业调色板表仅作为起点,而非强制要求。
--primary--background--accent创建后颜色修改: 由于所有组件均使用令牌引用(而非硬编码的十六进制值),再次调用并传入新的颜色值即可即时更新整个设计系统——所有组件、模式和界面都会继承更改,无需逐个节点更新。
$--set_variables令牌类别:
| 类别 | 数量 | 示例 |
|---|---|---|
| 核心颜色 | 19 | |
| 语义颜色 | 8 | |
| 排版 | 3 | |
| 圆角 | 6 | |
| 间距 | 12 | |
| 阴影 | 4 | |
| 字号 | 9 | |
| 行高 | 3 | |
设置主题轴。所有令牌值均针对特定领域定制。完整的JSON负载详见。
{ "mode": ["light", "dark"] }references/design-tokens-reference.md创建后验证: 调用后,立即调用并验证每个颜色令牌的值是否包含和(而非)。如果缺少主题映射,说明调用使用了错误的格式——请查看中的重要警告。
set_variablesget_variables"theme":{"mode":"light"}"theme":{"mode":"dark"}"theme":{}set_variablesdesign-tokens-reference.mdPhase 4 — Build Foundations (Visual Documentation)
阶段4 —— 构建基础层(视觉文档)
Create the Foundations section frame at the left of the canvas. Inside it, build 5 visual documentation frames:
- Color Palette — Grid of labeled swatches for all 27 color tokens.
- Typography Scale — 6 specimens (H1 → Caption) rendered at real sizes with metadata labels.
- Spacing Scale — 12 visual blocks showing each spacing value with labels.
- Elevation — 4 cards demonstrating shadow levels.
- Border Radius — 6 rectangles showcasing each radius token.
Critical: Use a neutral white backdrop (), NOT the design system's own token. The Foundations section is documentation chrome — using the themed background (e.g., cream for a bakery, blue-gray for SaaS) makes light swatches like , , and nearly invisible. A neutral white surface lets every color be evaluated accurately against a known reference. Swatches use tokens for their fills; only the documentation frame itself is neutral.
fill: "#FFFFFF"$--background--card--secondary--muted$--These are documentation frames, NOT reusable components. They use tokens for swatch fills everywhere. See for exact code (spread across 3 calls within 25-op limits).
$--references/foundations-specs.mdbatch_designAfter each batch, call to verify rendering.
get_screenshot在画布左侧创建Foundations区域框架。在其中构建5个视觉文档框架:
- 调色板 —— 所有27个颜色令牌的带标签样本网格。
- 排版尺度 —— 6个示例(H1 → 说明文字),以实际尺寸渲染并附带元数据标签。
- 间距尺度 —— 12个视觉块,展示每个间距值并附带标签。
- 层级阴影 —— 4个卡片,演示不同阴影层级。
- 圆角 —— 6个矩形,展示每个圆角令牌。
重要提示:使用中性白色背景(),而非设计系统自身的令牌。 Foundations区域是文档的展示层——如果使用主题化背景(例如烘焙店用奶油色,SaaS用蓝灰色),会导致、、等浅色样本几乎不可见。中性白色背景可让每种颜色在已知参考下准确呈现。样本使用令牌填充;仅文档框架本身为中性色。
fill: "#FFFFFF"$--background--card--secondary--muted$--这些是文档框架,并非可复用组件。所有样本填充均使用令牌。具体的代码(分3次调用,每次不超过25个操作)详见。
$--batch_designreferences/foundations-specs.md每次批量操作后,调用验证渲染效果。
get_screenshotPhase 5 — Build Base Components (~15 Primitives)
阶段5 —— 构建基础组件(约15个基础组件)
Create the Components section frame to the right of Foundations with (same neutral backdrop rationale as Foundations — light-fill variants like Ghost buttons and muted badges need a known white reference). Inside it, create category sub-frames with titles and display rows. Insert components under their category frame — NOT at document root.
fill: "#FFFFFF"| Batch | Category | Components | Count |
|---|---|---|---|
| 1 | Buttons | Primary, Secondary, Outline, Ghost, Destructive | 5 |
| 2 | Inputs | TextField, Textarea, Select, InputGroup | 4 |
| 3 | Typography | H1, H2, H3, Body, Caption, Label | 6 |
| 4 | Badges | Default, Success, Warning, Error | 4 |
| 5 | Alerts | Info, Success, Warning, Error | 4 |
Every component has , uses only tokens, and follows naming. See .
reusable: true$--"Category/Variant"references/component-specs.mdMANDATORY — Post-Batch Validation (after EVERY batch_design call):
- Check the batch response for "unknown properties were ignored" warnings — fix immediately.
- Call on the affected section — visually confirm no overlapping elements, no invisible shadows, no broken layouts.
get_screenshot - If ANY horizontal arrangement shows items stacked/overlapping, the frame is missing . Fix it before proceeding to the next batch.
layout: "horizontal"
在Foundations区域右侧创建Components区域框架,设置(与Foundations使用中性背景的理由相同——幽灵按钮、柔和徽章等浅色填充变体需要已知的白色参考)。在其中创建带标题的类别子框架和展示行。将组件插入对应的类别框架下,不得直接放在文档根节点。
fill: "#FFFFFF"| 批量操作 | 类别 | 组件 | 数量 |
|---|---|---|---|
| 1 | 按钮 | 主要按钮、次要按钮、轮廓按钮、幽灵按钮、危险按钮 | 5 |
| 2 | 输入框 | 文本框、文本域、选择器、输入组 | 4 |
| 3 | 排版 | H1、H2、H3、正文、说明文字、标签 | 6 |
| 4 | 徽章 | 默认徽章、成功徽章、警告徽章、错误徽章 | 4 |
| 5 | 提示框 | 信息提示、成功提示、警告提示、错误提示 | 4 |
每个组件均设置,仅使用令牌,并遵循命名规则。详见。
reusable: true$--"类别/变体"references/component-specs.md强制要求——批量操作后验证(每次调用后执行):
batch_design- 检查批量操作响应中是否有“未知属性被忽略”的警告——立即修复。
- 对受影响的区域调用——直观确认无重叠元素、无不可见阴影、无布局断裂。
get_screenshot - 若任何水平排列出现元素堆叠/重叠,说明框架缺少属性。修复后再进入下一阶段。
layout: "horizontal"
Phase 6 — Build Composite Components (~10 Composites)
阶段6 —— 构建复合组件(约10个复合组件)
Continue inside the Components section frame, adding category sub-frames for each composite group.
| Batch | Category | Components | Count |
|---|---|---|---|
| 6 | Card | Header + Content + Actions slots | 1 |
| 7 | Navigation | Sidebar container, ActiveItem, DefaultItem, SectionTitle | 4 |
| 8 | Table | Wrapper, HeaderRow, DataRow | 3 |
| 9 | Tabs | Container, ActiveTab, InactiveTab | 3 |
| 10 | Breadcrumbs | Item, Separator, ActiveItem | 3 |
| 11 | Pagination | Container, PageItem, ActiveItem, PrevNext | 4 |
| 12 | Modal | Dialog with Header/Body/Footer | 1 |
| 13 | Dropdown | Container, Item, Divider, SectionTitle | 4 |
| 14 | Misc | Avatar, Divider, Switch, Checkbox, Radio | 5 |
After batches 8, 11, and 14: run and . Fix issues immediately. See .
get_screenshotsnapshot_layout({ problemsOnly: true })references/component-specs.md在Components区域框架内继续添加复合组件类别的子框架。
| 批量操作 | 类别 | 组件 | 数量 |
|---|---|---|---|
| 6 | 卡片 | 头部 + 内容 + 操作插槽 | 1 |
| 7 | 导航 | 侧边栏容器、激活项、默认项、分区标题 | 4 |
| 8 | 表格 | 容器、表头行、数据行 | 3 |
| 9 | 标签页 | 容器、激活标签、未激活标签 | 3 |
| 10 | 面包屑 | 项、分隔符、激活项 | 3 |
| 11 | 分页 | 容器、页码项、激活项、上一页/下一页 | 4 |
| 12 | 模态框 | 带头部/主体/底部的对话框 | 1 |
| 13 | 下拉菜单 | 容器、菜单项、分隔符、分区标题 | 4 |
| 14 | 其他 | 头像、分隔线、开关、复选框、单选框 | 5 |
在批量操作8、11、14完成后:调用和,立即修复问题。详见。
get_screenshotsnapshot_layout({ problemsOnly: true })references/component-specs.mdPhase 7 — Build Patterns (Composition Showcases)
阶段7 —— 构建模式层(组合展示)
Create the Patterns section frame to the right of Components. Build 4 composition showcases that demonstrate real usage of the components:
- Form Pattern — Vertical stack of InputGroup refs + Submit button.
- Data Display Pattern — Table ref with populated rows + Pagination ref.
- Navigation Pattern — Sidebar ref + Breadcrumbs ref + Tabs ref.
- Card Layout Pattern — Grid of populated Card refs with images and domain content.
Each pattern uses only instances + tokens. After each pattern, run the Post-Batch Validation (screenshot + check for overlapping/broken layouts). See .
ref$--references/screen-patterns.md在Components区域右侧创建Patterns区域框架。构建4个组合展示,演示组件的实际用法:
- 表单模式 —— 垂直排列的输入组引用 + 提交按钮。
- 数据展示模式 —— 填充数据的表格引用 + 分页引用。
- 导航模式 —— 侧边栏引用 + 面包屑引用 + 标签页引用。
- 卡片布局模式 —— 填充内容的卡片引用网格,包含图片和领域相关内容。
每个模式仅使用实例 + 令牌。每个模式完成后,执行批量操作后验证(截图 + 检查重叠/断裂布局)。详见。
ref$--references/screen-patterns.mdPhase 8 — Create Domain Screens (only if user requests)
阶段8 —— 创建领域界面 (仅用户要求时执行)
Skip this phase unless the user explicitly asks for screens (e.g., "build screens for a bakery", "I need a landing page and menu screen", "create example screens"). The core deliverable is Foundations + Components + Patterns — screens are an optional add-on.
If the user requests screens, build 3–5 placed to the right of the Patterns section. Each screen uses only component instances and variable tokens.
ref$--Per-screen workflow:
- Call .
find_empty_space_on_canvas({ direction: "right", width: 1440, height: 900, padding: 100 }) - Insert screen frame at returned position.
- Build layout with component refs. Customize via .
U(instanceId+"/descendantId", {...}) - Add domain imagery via .
G() - Call to verify.
get_screenshot
See for domain-specific screen templates.
references/screen-patterns.md除非用户明确要求界面(例如“为烘焙店搭建界面”、“我需要一个着陆页和菜单界面”、“创建示例界面”),否则跳过本阶段。 核心交付物为Foundations + Components + Patterns——界面是可选附加项。
若用户要求界面,在Patterns区域右侧构建3-5个界面。每个界面仅使用组件实例和变量令牌。
ref$--单界面工作流程:
- 调用。
find_empty_space_on_canvas({ direction: "right", width: 1440, height: 900, padding: 100 }) - 在返回的位置插入界面框架。
- 使用组件引用构建布局,通过进行自定义。
U(instanceId+"/descendantId", {...}) - 通过添加领域相关图片。
G() - 调用验证。
get_screenshot
领域特定界面模板详见。
references/screen-patterns.mdPhase 9 — Layout Enforcement Pass (MANDATORY)
阶段9 —— 布局强制检查(强制要求)
Why this exists: The AI consistently drops from frames during generation, even when specs include it. This pass programmatically catches and fixes every missing layout. This phase is NOT optional — skip it and the design will have broken layouts.
layout: "horizontal"Step 1 — Collect all frames with flex properties.
batch_get({ filePath, patterns: [{ type: "frame" }], searchDepth: 10, readDepth: 0 })Search within EACH top-level section (Foundations, Components, Patterns, and any screens).
Step 2 — Identify frames needing layout enforcement.
From the results, find every frame that has ANY of: , , — regardless of whether already appears (since doesn't display in its output — it's considered the default).
gapalignItemsjustifyContentlayoutbatch_getlayout: "horizontal"Step 3 — Bulk-apply to ALL identified frames.
layout: "horizontal"javascript
U("frameId1", { layout: "horizontal" })
U("frameId2", { layout: "horizontal" })
// ... for every frame with gap/alignItems/justifyContentExclude frames that should be vertical (identifiable by name: category sections, form containers, vertical stacks). Apply to those instead.
layout: "vertical"Step 4 — Verify shadows use hex colors.
Check any frame with property. If uses format, replace with 8-digit hex .
effectcolorrgba()#RRGGBBAAStep 5 — Screenshot every section to confirm no overlapping elements.
This is safe to run multiple times — setting on a frame that already has it is a no-op.
layout: "horizontal"存在原因: AI在生成过程中经常会从框架中遗漏属性,即使规范中包含该属性。此步骤可通过编程方式捕获并修复所有缺失的布局设置。本阶段不可跳过——跳过会导致设计布局断裂。
layout: "horizontal"步骤1 —— 收集所有包含flex属性的框架。
batch_get({ filePath, patterns: [{ type: "frame" }], searchDepth: 10, readDepth: 0 })在每个顶级区域(Foundations、Components、Patterns以及所有已创建的界面)内搜索。
步骤2 —— 识别需要强制设置布局的框架。
从结果中找出所有包含以下任一属性的框架:、、——无论是否已包含属性(因为的输出中不会显示,它被视为默认值)。
gapalignItemsjustifyContentlayoutbatch_getlayout: "horizontal"步骤3 —— 为所有识别出的框架批量设置。
layout: "horizontal"javascript
U("frameId1", { layout: "horizontal" })
U("frameId2", { layout: "horizontal" })
// ... 为所有包含gap/alignItems/justifyContent的框架执行此操作排除应设置为垂直布局的框架(可通过名称识别:类别区域、表单容器、垂直堆叠),为这些框架设置。
layout: "vertical"步骤4 —— 验证阴影使用十六进制颜色。
检查所有包含属性的框架。若使用格式,替换为8位十六进制格式。
effectcolorrgba()#RRGGBBAA步骤5 —— 对每个区域截图,确认无重叠元素。
本步骤可多次执行——为已设置的框架再次设置该属性不会产生任何影响。
layout: "horizontal"Phase 10 — Final Verification
阶段10 —— 最终验证
Run comprehensive QA. Fix every issue before presenting to the user.
- Visual — on Foundations, Components, Patterns (and screens if created). Check alignment, spacing, typography, color, overflow.
get_screenshot - Layout — to detect clipping/overflow. Fix all.
snapshot_layout({ problemsOnly: true }) - Token audit — for
search_all_unique_properties,fillColor,textColor,fontFamily. Replace leaked hex values and raw font sizes withfontSizetokens.$-- - Component audit — . Verify ~25 components.
batch_get({ patterns: [{ reusable: true }] }) - Organization audit — Verify no orphan components at document root. All should be under Components section.
- Fix and re-verify — Re-screenshot affected areas after fixes.
- Present — Summarize tokens, components, patterns (and screens if created). Show key screenshots.
See .
references/verification-checklist.md执行全面的质量检查,向用户交付前修复所有问题。
- 视觉检查 —— 对Foundations、Components、Patterns(以及已创建的界面)调用。检查对齐、间距、排版、颜色、溢出情况。
get_screenshot - 布局检查 —— 调用检测裁剪/溢出问题,修复所有问题。
snapshot_layout({ problemsOnly: true }) - 令牌审计 —— 使用搜索
search_all_unique_properties、fillColor、textColor、fontFamily。将硬编码的十六进制值和原始字号替换为fontSize令牌。$-- - 组件审计 —— 调用,验证约25个组件。
batch_get({ patterns: [{ reusable: true }] }) - 组织审计** —— 验证无组件直接放在文档根节点下,所有组件应位于Components区域内。
- 修复并重新验证 —— 修复后对受影响区域重新截图。
- 交付 —— 总结令牌、组件、模式(以及已创建的界面),展示关键截图。
详见。
references/verification-checklist.mdPhase 11 — Canvas Navigation Index
阶段11 —— 画布导航索引
Create a small navigation index frame at the canvas origin (x: 0, y: 0) showing a map of all sections with their positions:
Design System Index
├── Foundations (x, y)
├── Components (x, y)
├── Patterns (x, y)
└── Screens (x, y) — only if screens were createdThis helps users navigate the canvas. Only include the Screens entry if Phase 8 was executed.
在画布原点(x: 0, y: 0)创建一个小型导航索引框架,显示所有区域及其位置:
设计系统索引
├── Foundations (x, y)
├── Components (x, y)
├── Patterns (x, y)
└── Screens (x, y) —— 仅创建界面后显示这有助于用户导航画布。仅当执行了阶段8时,才包含Screens条目。
Phase 12 — Code Export (optional, user-triggered)
阶段12 —— 代码导出 (可选,用户触发)
Skip this phase unless the user explicitly requests code export (e.g., "export to Tailwind", "convert to code", "generate React components", "export as CSS"). This phase converts the design system into production-ready Tailwind CSS + React components.
Step 1 — Collect preferences. Ask the user for:
- Tailwind version: v3 or v4
- Framework: Next.js or Vite+React
Step 2 — Extract tokens. Call to read all ~64 tokens. Categorize by type (color, number, string, shadow). Separate themed (light/dark) from static tokens.
get_variables({ filePath })Step 3 — Read components. Call to get every reusable component with its full node tree.
batch_get({ patterns: [{ reusable: true }], readDepth: 3, searchDepth: 3 })Step 4 — Load Pencil's code generation guidelines. Call and . These are the primary authority for translating Pencil nodes to code — they cover component instance mapping, property-to-Tailwind-class translation, font wiring, and visual verification. Follow them for all translation work in Steps 8-9.
get_guidelines("code")get_guidelines("tailwind")Step 5 — Generate . Build the CSS file with all tokens as CSS custom properties:
globals.css- v3: with HSL values (space-separated, no
:rootwrapper),hsl()overrides,.darkfont utilities@layer base - v4: ,
@import "tailwindcss",@custom-variant darkwith hex values,:rootoverrides,.darkfont utilities@layer base
Step 6 — Generate (v3 only). Map all tokens to Tailwind utility names: colors via , radii, shadows, font sizes, spacing, line heights.
tailwind.config.jshsl(var(--name))Step 7 — Generate font loading code.
- Next.js: with
layout.tsxloader settingnext/font/google,--font-primary,--font-secondaryCSS variables--font-mono - Vite+React: tags in
<link>loading all three fonts from Google Fontsindex.html
Step 8 — Generate component TSX files. One file per component category (button.tsx, input.tsx, card.tsx, badge.tsx, alert.tsx, etc.). Each component:
- Uses only token-referencing Tailwind classes (no hardcoded hex)
- Has TypeScript interfaces with variant props where applicable
- Accepts and spreads an optional prop
className - Uses v3 mapped classes () or v4 arbitrary values (
bg-primary) based on the chosen versionbg-[var(--primary)]
Step 9 — Generate screen/page TSX files. For each screen design in the .pen file:
- Deep-read the screen frame:
batch_get({ nodeIds: [screenId], readDepth: 10, resolveInstances: true }) - Take a reference screenshot:
get_screenshot({ nodeId: screenId }) - Follow Pencil's Component Implementation Workflow (from Step 4's ):
get_guidelines("code")- Steps 1A-1C: Extract components, map ALL instances with ALL overrides and descendants
- Step 2: Create React components using for property-to-class mapping
get_guidelines("tailwind") - Step 3: Validate each component with — pixel-perfect match required
get_screenshot - Step 4: Integrate into frame, verify instance count and prop completeness
- Handle screen-level elements: semantic HTML for headings/labels/links, page wrapper, form behavior, icon name conversion, image fills
- Assemble into a complete page file with all imports
- Visually verify the rendered page against the Pencil screenshot — fix any discrepancies
See (Section 7) for the complete screen export workflow and common pitfalls.
references/code-export-guide.md除非用户明确要求代码导出(例如“导出为Tailwind”、“转换为代码”、“生成React组件”、“导出为CSS”),否则跳过本阶段。 本阶段将设计系统转换为可用于生产环境的Tailwind CSS + React组件。
步骤1 —— 收集偏好。 询问用户:
- Tailwind版本: v3或v4
- 框架: Next.js或Vite+React
步骤2 —— 提取令牌。 调用读取所有约64个令牌,按类型分类(颜色、数字、字符串、阴影),区分主题化(亮色/暗色)和静态令牌。
get_variables({ filePath })步骤3 —— 读取组件。 调用获取所有可复用组件及其完整节点树。
batch_get({ patterns: [{ reusable: true }], readDepth: 3, searchDepth: 3 })步骤4 —— 加载Pencil的代码生成指南。 调用和。这些是将Pencil节点转换为代码的主要依据,涵盖组件实例映射、属性到Tailwind类的转换、字体配置和视觉验证。步骤8-9的所有转换工作均需遵循这些指南。
get_guidelines("code")get_guidelines("tailwind")步骤5 —— 生成。 构建包含所有令牌的CSS文件,将其作为CSS自定义属性:
globals.css- v3: 中使用HSL值(空格分隔,无
:root包裹),hsl()覆盖样式,.dark字体工具类@layer base - v4: ,
@import "tailwindcss",@custom-variant dark中使用十六进制值,:root覆盖样式,.dark字体工具类@layer base
步骤6 —— 生成(仅v3)。 将所有令牌映射到Tailwind工具类名称:颜色通过映射,圆角、阴影、字号、间距、行高同理。
tailwind.config.jshsl(var(--name))步骤7 —— 生成字体加载代码。
- Next.js: 中使用
layout.tsx加载器,设置next/font/google、--font-primary、--font-secondaryCSS变量--font-mono - Vite+React: 中的
index.html标签,从Google Fonts加载所有三种字体<link>
步骤8 —— 生成组件TSX文件。 每个组件类别对应一个文件(button.tsx、input.tsx、card.tsx、badge.tsx、alert.tsx等)。每个组件:
- 仅使用引用令牌的Tailwind类(无硬编码十六进制值)
- 包含TypeScript接口,适当时包含变体属性
- 接收并传递可选的属性
className - 根据所选版本,使用v3映射类()或v4任意值(
bg-primary)bg-[var(--primary)]
步骤9 —— 生成界面/页面TSX文件。 为.pen文件中的每个界面设计生成一个文件:
- 深度读取界面框架:
batch_get({ nodeIds: [screenId], readDepth: 10, resolveInstances: true }) - 截取参考截图:
get_screenshot({ nodeId: screenId }) - 遵循Pencil组件实现工作流(来自步骤4的):
get_guidelines("code")- 步骤1A-1C:提取组件,映射所有带覆盖样式和子节点的实例
- 步骤2:使用进行属性到类的映射,创建React组件
get_guidelines("tailwind") - 步骤3:使用验证每个组件——需实现像素级匹配
get_screenshot - 步骤4:集成到框架中,验证实例数量和属性完整性
- 处理界面级元素:标题/标签/链接使用语义化HTML,页面容器,表单行为,图标名称转换,图片填充
- 组装为完整的页面文件,包含所有导入
- 将渲染后的页面与Pencil截图进行视觉比对——修复所有差异
特定领域的界面导出工作流和常见陷阱详见第7节。
references/code-export-guide.mdCritical Rules
核心规则
Rule 1 — Always reuse components. Search with before creating. On screens, every element must be a instance.
batch_get({ patterns: [{ reusable: true }] })refRule 2 — Never hardcode values. All colors use tokens. All fonts use . All radii use . All font sizes use . Raw values only appear in .
$--$--font-*$--radius-*$--text-*set_variablesRule 3 — Prevent overflow. Constrain text with . Use layout frames. Validate with .
width: "fill_container"snapshot_layout({ problemsOnly: true })Rule 4 — Verify visually. Call after every major batch. Fix problems immediately.
get_screenshotRule 5 — Reuse assets. Copy images with instead of regenerating with .
C()G()Rule 6 — Domain coherence. Every choice connects back to Phase 1 research.
Rule 7 — Canvas organization. All components go inside the Components section frame under categorized sub-frames. No components at document root. Foundations, Components, Patterns, and Screens flow left-to-right on the canvas.
规则1 —— 始终复用组件。 创建前使用搜索。在界面中,每个元素必须是实例。
batch_get({ patterns: [{ reusable: true }] })ref规则2 —— 绝不硬编码值。 所有颜色使用令牌,所有字体使用,所有圆角使用,所有字号使用。仅在中使用原始值。
$--$--font-*--radius-*--text-*set_variables规则3 —— 防止溢出。 使用限制文本,使用布局框架,通过验证。
width: "fill_container"snapshot_layout({ problemsOnly: true })规则4 —— 视觉验证。 每次主要批量操作后调用,立即修复问题。
get_screenshot规则5 —— 复用资源。 使用复制图片,而非使用重新生成。
C()G()规则6 —— 领域一致性。 每个决策均需关联到阶段1的调研结果。
规则7 —— 画布组织。 所有组件必须放在Components区域框架下的分类子框架中,不得直接放在文档根节点。Foundations、Components、Patterns和Screens在画布上从左到右排列。
Component Inventory
组件清单
| # | Component | Type | Variants |
|---|---|---|---|
| 1–5 | Button | Primitive | Primary, Secondary, Outline, Ghost, Destructive |
| 6–9 | Input | Primitive | TextField, Textarea, Select, InputGroup |
| 10–15 | Typography | Primitive | H1, H2, H3, Body, Caption, Label |
| 16–19 | Badge | Primitive | Default, Success, Warning, Error |
| 20–23 | Alert | Primitive | Info, Success, Warning, Error |
| 24 | Card | Composite | Header + Content + Actions slots |
| 25–28 | Sidebar Nav | Composite | Container, ActiveItem, DefaultItem, SectionTitle |
| 29–31 | Table | Composite | Wrapper, HeaderRow, DataRow |
| 32–34 | Tabs | Composite | Container, ActiveTab, InactiveTab |
| 35–37 | Breadcrumbs | Composite | Item, Separator, ActiveItem |
| 38–41 | Pagination | Composite | Container, PageItem, ActiveItem, PrevNext |
| 42 | Modal/Dialog | Composite | Overlay + Content with slots |
| 43–46 | Dropdown | Composite | Container, MenuItem, Divider, SectionTitle |
| 47–51 | Miscellaneous | Composite | Avatar, Divider, Switch, Checkbox, Radio |
| 编号 | 组件 | 类型 | 变体 |
|---|---|---|---|
| 1–5 | 按钮 | 基础组件 | 主要、次要、轮廓、幽灵、危险 |
| 6–9 | 输入框 | 基础组件 | 文本框、文本域、选择器、输入组 |
| 10–15 | 排版 | 基础组件 | H1、H2、H3、正文、说明文字、标签 |
| 16–19 | 徽章 | 基础组件 | 默认、成功、警告、错误 |
| 20–23 | 提示框 | 基础组件 | 信息、成功、警告、错误 |
| 24 | 卡片 | 复合组件 | 头部 + 内容 + 操作插槽 |
| 25–28 | 侧边栏导航 | 复合组件 | 容器、激活项、默认项、分区标题 |
| 29–31 | 表格 | 复合组件 | 容器、表头行、数据行 |
| 32–34 | 标签页 | 复合组件 | 容器、激活标签、未激活标签 |
| 35–37 | 面包屑 | 复合组件 | 项、分隔符、激活项 |
| 38–41 | 分页 | 复合组件 | 容器、页码项、激活项、上一页/下一页 |
| 42 | 模态框/对话框 | 复合组件 | 遮罩 + 带插槽的内容 |
| 43–46 | 下拉菜单 | 复合组件 | 容器、菜单项、分隔符、分区标题 |
| 47–51 | 其他 | 复合组件 | 头像、分隔线、开关、复选框、单选框 |
References
参考文件
Load the relevant file before starting each phase:
- — Complete Pencil MCP tool reference with examples and operation syntax.
references/pencil-mcp-guide.md - — Domain research strategies, color psychology, font pairings, screen inventories.
references/domain-research-guide.md - — Token architecture,
references/design-tokens-reference.mdJSON payloads, ~60 token definitions, industry palettes.set_variables - — Visual foundation documentation: color palette, typography scale, spacing, elevation, radius
references/foundations-specs.mdcode.batch_design - — All ~25 component
references/component-specs.mdoperation code with section frame organization.batch_design - — Layout patterns, composition showcases, and domain-specific screen templates.
references/screen-patterns.md - — Visual QA, layout checks, token audits, canvas organization verification.
references/verification-checklist.md - — Tailwind CSS export: token extraction, v3/v4 templates, Pencil-to-Tailwind class cheatsheet, component translation, framework setup (Next.js / Vite+React).
references/code-export-guide.md
每个阶段开始前加载对应的参考文件:
- —— 完整的Pencil MCP工具参考,包含示例和操作语法。
references/pencil-mcp-guide.md - —— 领域调研策略、色彩心理学、字体配对、界面清单。
references/domain-research-guide.md - —— 令牌架构、
references/design-tokens-reference.mdJSON负载、约60个令牌定义、行业调色板。set_variables - —— 视觉基础文档:调色板、排版尺度、间距、层级阴影、圆角的
references/foundations-specs.md代码。batch_design - —— 所有约25个组件的
references/component-specs.md操作代码,包含区域框架组织方式。batch_design - —— 布局模式、组合展示、特定领域的界面模板。
references/screen-patterns.md - —— 视觉质量检查、布局检查、令牌审计、画布组织验证。
references/verification-checklist.md - —— Tailwind CSS导出:令牌提取、v3/v4模板、Pencil到Tailwind类对照表、组件转换、框架设置(Next.js / Vite+React)。
references/code-export-guide.md