Frontend Design Extractor
Overview
Extract a reusable UI/UX design spec from a frontend codebase by inventorying UI sources, documenting foundations, cataloging components, and capturing page-level patterns and behaviors. Exclude business logic and domain-specific workflows. Framework-agnostic: adapt to the actual stack in the target repo.
Quick start
1) Confirm mode: new project (greenfield) or refactor existing. Clarify that business logic is out of scope.
2) If existing repo: run
scripts/scan_ui_sources.sh to scan the repo root (no directory layout assumptions). It uses common globs + keyword hits, and ignores common build/cache dirs and extraction output folders by default.
3) Optionally:
scripts/scan_ui_sources.sh <repo_root> [out_file] [extra_glob ...] or
--root/--out/--ignore for nonstandard layouts.
4) Create the output folder (default
./ui-ux-spec) via
scripts/generate_output_skeleton.sh and write all extraction results inside it.
5) Produce outputs in the default structure (see "Output structure").
Modes (choose one)
A) Greenfield (from blank)
Goal: create a reusable UI/UX foundation and starter UI without business logic.
1) Define foundations: tokens (color/typography/spacing/radius/shadow/motion), global styles, breakpoints, layout shell.
2) Create a baseline component set: Button, Input, Select, Card, Modal, Table/List, Tabs, Toast, EmptyState.
3) Create page templates: list/detail/form/dashboard skeletons with placeholder data.
4) Provide implementation notes for the target framework (CSS architecture, theming mechanism, file structure).
5) Optionally run scripts/generate_output_skeleton.sh [out_root] to scaffold folders and empty templates. Default output root is ./ui-ux-spec.
Deliverables:
- - Design tokens doc + global styles spec
- Component catalog with variants/states/a11y
- Page templates with layout rules
- Engineering constraints (naming, CSS approach, theming)
B) Refactor existing project
Goal: extract current UI/UX, normalize tokens, and plan safe, incremental improvements.
1) Inventory UI sources (scan script + manual inspection).
2) Normalize tokens and map existing styles to them.
3) Identify high-impact components/patterns for first pass.
4) Plan migration with minimal diffs (wrappers, theme adapters, gradual replacement).
5) Document behavioral and a11y gaps to fix progressively.
Deliverables:
- - Extracted design spec (same as greenfield)
- Migration plan (phased, low-risk steps)
- Component-by-component mapping notes
Refactor from spec (fixed flow)
Use this when applying an existing
ui-ux-spec/ to a target project. Always work from a plan and execute step-by-step to avoid missing gaps.
0) Understand the target project
- - Identify framework, styling system, component library usage, and entry points.
- Confirm constraints: UI/UX only, business logic untouched.
- Keep existing project structure unchanged unless explicitly requested.
1) Build the refactor plan (required)
- - Compare spec → current project and list differences by category:
- Tokens & global styles
- Components (priority order)
- Patterns & pages
- A11y gaps
- - Do not assume the spec folder structure matches the target project. Map by content, not by paths.
- Produce a phased plan (Phase 1 tokens, Phase 2 base components, Phase 3 pages, etc.).
- Do not proceed to edits until the plan is accepted.
2) Execute phase by phase
- - Apply changes for the current phase only.
- Re-check against the spec after each phase.
- Keep diffs minimal and reversible.
- Do not restructure folders or move files; update in place.
3) Summarize and verify
- - Provide a change list and remaining gaps.
- Suggest next phase only after current phase is done.
Refactor prompt templates
Use one of the templates below to keep requests precise and plan-driven.
Template A: Standard refactor
CODEBLOCK0
Template B: Phased refactor
CODEBLOCK1
Template C: Component-level refactor
CODEBLOCK2
Workflow
0) Scope and constraints
- - Confirm repo root, frameworks, and any design system packages.
- Confirm desired output format (Markdown by default).
- Ask for constraints: must-keep brand rules, target platforms, and accessibility level.
- Reconfirm: exclude business logic, business rules, and domain workflows.
- Do not assume a specific frontend framework or language; adapt to the project’s stack.
1) Source inventory (existing repos only)
- - Do not assume a fixed directory structure; scan results should guide where to read.
- Run the scan script and inspect results for:
- tokens/themes, global styles, theme providers
- component libraries and local wrappers
- Storybook, docs, or visual regression tests
- assets and i18n sources
2) Foundations (tokens + global styles)
- - Document colors, typography, spacing, radius, shadows, z-index, and motion tokens.
- Capture reset/normalize, body defaults, link/form defaults, focus-visible, scrollbar.
3) Layout & information architecture
- - Document breakpoints, containers, grid rules, navigation structure, and layout shells.
4) Component catalog
- - For each component, capture: purpose, structure/slots, variants, states, interactions, a11y, responsive behavior, motion, and theming hooks.
- If a third-party library is used, focus on local wrapper components and overrides.
5) Page templates & composition rules
- - Extract page skeletons (list/detail/form/dashboard/etc.) and module ordering.
- Capture combined states: loading/empty/error/permission/readonly.
6) Behavior & content rules
- - Capture loading and error strategies, validation patterns, undo/optimistic updates.
- Capture microcopy conventions and i18n formatting constraints.
7) Package outputs
- Design tokens doc
- Component catalog
- Page templates
- - Ensure outputs are written under a dedicated folder (default
ui-ux-spec/). - Use the output structure below unless the user asks for another layout.
Output structure (default)
This structure is a recommended documentation layout. It does not need to match the target project's directory structure, and it can be renamed or relocated (e.g.,
docs/ui-ux-spec/).
CODEBLOCK3
Resources
- -
scripts/scan_ui_sources.sh: find candidate UI sources in a repo. - INLINECODE11 : create the standard output folders and placeholder templates.
- INLINECODE12 : detailed checklist derived from README.
前端设计提取器
概述
通过盘点UI资源、记录基础规范、编目组件以及捕获页面级模式和行为,从前端代码库中提取可复用的UI/UX设计规范。排除业务逻辑和特定领域的工作流程。框架无关:适配目标仓库中的实际技术栈。
快速开始
1) 确认模式:新项目(绿地开发)或重构现有项目。明确业务逻辑不在范围内。
2) 如果是现有仓库:运行 scripts/scan
uisources.sh 扫描仓库根目录(不假设目录结构)。它使用常见的glob模式+关键词匹配,默认忽略常见的构建/缓存目录和提取输出文件夹。
3) 可选:scripts/scan
uisources.sh
root> [outfile] [extra_glob ...] 或使用 --root/--out/--ignore 处理非标准布局。
4) 通过 scripts/generateoutputskeleton.sh 创建输出文件夹(默认 ./ui-ux-spec),并将所有提取结果写入其中。
5) 按默认结构生成输出(参见输出结构)。
模式(选择其一)
A) 绿地开发(从零开始)
目标:创建可复用的UI/UX基础和启动器UI,不含业务逻辑。
1) 定义基础规范:设计令牌(颜色/排版/间距/圆角/阴影/动效)、全局样式、断点、布局外壳。
2) 创建基线组件集:按钮、输入框、选择器、卡片、模态框、表格/列表、标签页、提示框、空状态。
3) 创建页面模板:列表/详情/表单/仪表盘骨架,使用占位数据。
4) 提供目标框架的实现说明(CSS架构、主题机制、文件结构)。
5) 可选:运行 scripts/generateoutputskeleton.sh [out_root] 搭建文件夹和空模板。默认输出根目录为 ./ui-ux-spec。
交付物:
- - 设计令牌文档 + 全局样式规范
- 包含变体/状态/无障碍的组件目录
- 包含布局规则的页面模板
- 工程约束(命名、CSS方法、主题)
B) 重构现有项目
目标:提取当前UI/UX,规范化令牌,规划安全、渐进式的改进。
1) 盘点UI资源(扫描脚本 + 手动检查)。
2) 规范化令牌,将现有样式映射到令牌。
3) 识别高影响力的组件/模式进行首轮处理。
4) 规划最小差异的迁移(包装器、主题适配器、逐步替换)。
5) 记录行为和无障碍差距,逐步修复。
交付物:
- - 提取的设计规范(与绿地开发相同)
- 迁移计划(分阶段、低风险步骤)
- 逐组件的映射说明
基于规范的重构(固定流程)
当将现有的 ui-ux-spec/ 应用于目标项目时使用此流程。始终基于计划工作,并逐步执行以避免遗漏差距。
0) 了解目标项目
- - 识别框架、样式系统、组件库使用情况和入口点。
- 确认约束:仅UI/UX,不触及业务逻辑。
- 除非明确要求,否则保持现有项目结构不变。
1) 构建重构计划(必需)
- 令牌和全局样式
- 组件(优先级顺序)
- 模式和页面
- 无障碍差距
- - 不要假设规范文件夹结构与目标项目匹配。按内容映射,而非路径。
- 生成分阶段计划(阶段1令牌,阶段2基础组件,阶段3页面等)。
- 在计划被接受之前,不要进行编辑。
2) 逐阶段执行
- - 仅应用当前阶段的变更。
- 每个阶段后重新对照规范检查。
- 保持差异最小且可逆。
- 不要重组文件夹或移动文件;原地更新。
3) 总结和验证
- - 提供变更列表和剩余差距。
- 仅在当前阶段完成后建议下一阶段。
重构提示模板
使用以下模板之一保持请求精确且基于计划。
模板A:标准重构
请基于此UI/UX规范重构现有项目:
- - 项目路径:/path/to/target-project
- 规范路径:/path/to/ui-ux-spec
- 目标:仅UI/UX(令牌、样式、组件、布局),不更改业务逻辑/API
- 范围:从全局样式 + 基础组件开始
- 约束:最小变更、小步提交、可逆
- 交付物:重构计划 + 实际代码变更 + 受影响文件列表
模板B:分阶段重构
请分阶段重构UI/UX;仅执行阶段1:
- - 项目路径:/path/to/target-project
- 规范路径:/path/to/ui-ux-spec
- 阶段1:对齐令牌 + 全局样式(颜色/排版/间距/圆角/阴影)
- 不更改:业务逻辑/路由/API
- 交付物:变更文件列表 + 对齐差异说明
模板C:组件级重构
请将以下组件与规范对齐,同时保持业务逻辑不变:
- - 项目路径:/path/to/target-project
- 规范路径:/path/to/ui-ux-spec
- 组件列表:按钮、输入框、模态框、表格
- 目标:仅更改样式/结构/交互细节
- 交付物:每个组件的对齐说明 + 代码变更
工作流程
0) 范围和约束
- - 确认仓库根目录、框架和任何设计系统包。
- 确认期望的输出格式(默认为Markdown)。
- 询问约束:必须保留的品牌规则、目标平台和无障碍级别。
- 再次确认:排除业务逻辑、业务规则和领域工作流程。
- 不要假设特定的前端框架或语言;适配项目的技术栈。
1) 资源盘点(仅限现有仓库)
- - 不要假设固定的目录结构;扫描结果应指导读取位置。
- 运行扫描脚本并检查结果:
- 令牌/主题、全局样式、主题提供者
- 组件库和本地包装器
- Storybook、文档或视觉回归测试
- 资源和国际化来源
2) 基础规范(令牌 + 全局样式)
- - 记录颜色、排版、间距、圆角、阴影、z-index和动效令牌。
- 捕获重置/标准化、body默认值、链接/表单默认值、焦点可见、滚动条。
3) 布局和信息架构
- - 记录断点、容器、网格规则、导航结构和布局外壳。
4) 组件目录
- - 对于每个组件,捕获:用途、结构/插槽、变体、状态、交互、无障碍、响应式行为、动效和主题钩子。
- 如果使用第三方库,重点关注本地包装器组件和覆盖。
5) 页面模板和组合规则
- - 提取页面骨架(列表/详情/表单/仪表盘等)和模块排序。
- 捕获组合状态:加载/空/错误/权限/只读。
6) 行为和内容规则
- - 捕获加载和错误策略、验证模式、撤销/乐观更新。
- 捕获微文案约定和国际化格式约束。
7) 打包输出
- 设计令牌文档
- 组件目录
- 页面模板
- - 确保输出写入专用文件夹(默认 ui-ux-spec/)。
- 除非用户要求其他布局,否则使用以下输出结构。
输出结构(默认)
此结构是推荐的文档布局。它不需要与目标项目的目录结构匹配,并且可以重命名或重新定位(例如 docs/ui-ux-spec/)。
ui-ux-spec/
01_基础规范/
02_组件/
03_模式/
04_页面/
05_无障碍/
06_资源/
07_工程约束/
资源
- - scripts/scanuisources.sh:在仓库中查找候选UI资源。
- scripts/generateoutputskeleton.sh:创建标准输出文件夹和占位模板。
- references/design-extraction-checklist.md:从README派生的详细检查清单。