Tailwind CSS 与 shadcn/ui
把 DESIGN.md 转换成真实样式变量写入 CSS 后,AI Agent 只需选择语义化类名,渲染层面就能机械地锁定精确视觉值。DesignMD Pro 提供三款纯客户端代码生成器。
Tailwind CSS v4(@theme)
在 Tailwind v4 主题生成器 中粘贴 DESIGN.md,工具会按以下规则输出可直接放进 globals.css 的代码:
DESIGN.md Token 分组 | 输出的 CSS 变量 |
|---|---|
colors.<key> | @theme 内的 --color-<key>: <hex>; |
colors.light.<key> | @theme 内的 --color-<key>: <hex>;(默认亮色) |
colors.dark.<key> | .dark 选择器内的 --color-<key>: <hex>; |
typography 字体族 | --font-sans(首个字体族)、--font-sans-2 等 |
typography 字阶 | --text-<key> 与 --text-<key>--line-height |
rounded.<key> | --radius-<key>: <dim>; |
spacing.<key> | --spacing-<key>: <dim>; |
输出示例:
@theme {
--color-primary: #4338ca;
--color-background: #ffffff;
--color-surface: #f6f5f4;
--color-text: #18181b;
--font-sans: "Inter", sans-serif;
--text-body-md: 16px;
--text-body-md--line-height: 1.6;
--radius-md: 8px;
--spacing-md: 16px;
}
.dark {
--color-primary: #818cf8;
--color-background: #0f172a;
}原生 CSS 变量
CSS 变量生成器 生成不依赖任何框架的 :root 与 .dark 自定义属性:
colors.<key>→--<key>: <hex>;(colors.dark.*放入.dark)typography.<key>→--font-<key>、--font-<key>-size、--font-<key>-weight、--font-<key>-line-heightrounded.<key>→--radius-<key>spacing.<key>→--spacing-<key>
shadcn/ui 语义变量映射
shadcn 主题生成器 按语义正则自动把 DESIGN.md 的颜色键映射到 shadcn 标准变量(每个目标变量取首次匹配结果):
| Token 键名匹配模式 | 生成的 shadcn CSS 变量 |
|---|---|
background、canvas、page、bg | --background |
surface、card、popover、elevated | --card |
primary、brand | --primary |
on-primary、onprimary、primary-foreground | --primary-foreground |
secondary | --secondary |
muted、subtle、disabled | --muted |
accent、tertiary | --accent |
destructive、error、danger | --destructive |
border、outline、divider、stroke | --border |
ring、focus | --ring |
text、foreground、fg、heading、body | --foreground |
| 其余未匹配键名 | --color-<key> |
圆角方面,生成器会按优先级读取 rounded.md、rounded.base 或 rounded.default 并输出为 --radius。colors.dark.* 下的条目同样按上表映射写入 .dark 块。
Tip
按照完整示例使用 background、surface、primary、on-primary、text、muted、border 等标准键名,可以同时适配 shadcn 主题映射与 WCAG 对比度自动检测。
下一步
- Token 命名规范 —— 让命名同时兼顾代码导出与校验精度
- 设计 Token —— 了解
light/dark嵌套结构 - Vercel v0 与 Bolt —— 将生成的 CSS 与浏览器端 UI 生成工具结合
Last updated on