image-to-code
GitHub将设计稿或截图转换为基于 Token 的可访问 UI 代码。自动推断设计系统并生成主题,构建组件并通过自动化脚本验证对比度、无障碍及渲染一致性。
触发场景
安装
npx skills add plugin87/ux-ui-agent-skills --skill image-to-code -g -y
SKILL.md
Frontmatter
{
"name": "image-to-code",
"description": "Turn a reference image, screenshot, or mockup into token-driven, accessible code. Infer the design system from the reference (palette, type scale, spacing, radius, layout archetype), map it to the 3-tier tokens, rebuild it, then verify with the kit's gates. Use when the user provides a design\/screenshot and wants matching UI code.",
"disable-model-invocation": true
}
Skill: Image to Code
Step 0: is the kit here? This skill reads files from the kit. Check once:
ls ${CLAUDE_SKILL_DIR}/../../../tokens >/dev/null 2>&1 && echo KIT_OK || echo KIT_MISSINGOnKIT_MISSINGonly the skill folders were installed, which is whatnpx skills adddoes. Say so plainly, point the user atnpx ux-ui-agent-skills initor the plugin install, and stop. Do not guess the contents of a file you could not open.
Reconstruct a design from a visual reference as a real design system, not a one-off copy. Match the system (color/type/spacing language), never lift copyrighted imagery or brand assets.
Steps
- Read the reference like a designer. Infer and write down:
- Palette: 1 dominant surface family, text colors, 1 primary action + at most 1 accent (sample the hues; don't guess random hex).
- Type: family feel (geometric/grotesk/serif), the scale jumps, display vs. body contrast, weights.
- Spacing & density: base unit, section rhythm, card padding; airy vs. compact.
- Radius & depth: radius language (sharp/soft/pill), shadow vs. hairline separation.
- Layout archetype + sequence: bounded hero / asymmetric split / dense bento / editorial stack (
${CLAUDE_SKILL_DIR}/../../../taste/design-taste.md→ Variance Mandate).
- Anchor to a known system if it's close: browse
${CLAUDE_SKILL_DIR}/../../../taste/aesthetic-systems.md/python3 ${CLAUDE_SKILL_DIR}/../../../scripts/design_systems.py search <term>and adopt that recipe to stabilize decisions. - Build the token theme from the inferred values → 3-tier DTCG (
design-tokensskill); generate a singletheme.css. Verify every color pair with${CLAUDE_SKILL_DIR}/../../../scripts/contrast.py/${CLAUDE_SKILL_DIR}/../../../scripts/validate_contrast.py(light + dark). A sampled brand color that fails AA gets adjusted; taste never overrides POUR. - Rebuild layout + components token-driven via
${CLAUDE_SKILL_DIR}/../../../frameworks/adapter-protocol.md+${CLAUDE_SKILL_DIR}/../../../components/*: one shared primitive layer, all 8 states, a11y wired, no emoji (lucide), single theme. Apply taste (design-taste.md) so it doesn't regress to generic. - Verify against the reference: render and screenshot it, compare side-by-side to the reference; run
node ${CLAUDE_SKILL_DIR}/../../../scripts/gate.mjs measure_render.mjs,lint_hardcodes.py,taste_audit.mjs, andnpm run verify.
Verification (definition of done)
npm run verifyis 100% (tokens resolve, contrast AA light+dark, no hardcodes/emoji, real-render WCAG).- The rebuilt UI uses ONE inferred token theme; no per-section palettes.
- A screenshot of the result visibly matches the reference's design language.
Honest limit: this matches the design system, not a pixel-perfect copy. Do not reproduce the reference's photographs, logos, or copyrighted copy. Substitute your own or generic placeholders.
版本历史
-
def84a7
当前 2026-11-03 02:21
版本3.0统一替换文档与代码中的破折号;修复插件安装路径解析问题;优化浏览器门控逻辑以确保验证流程正确执行。
-
62092bd
2026-10-19 09:19
新增 Kit 存在性检查步骤;调整布局原型描述以适配屏幕经济规则;更新路径引用为绝对路径。
- 2ffb677 2026-08-28 11:59
- 93a7fbb 2026-07-25 07:41


