小马的 AI 工具集

设计协议

把视觉品牌/设计系统结构化喂给编码 Agent 的 DESIGN.md 规范格式

设计协议
类型 素材 24,848 星标 更新 2026-07-01 许可 Apache-2.0 原仓库 主页

一份格式规范,用于向编码代理描述视觉标识。DESIGN.md 让代理能够持久、结构化地理解设计系统。

格式

DESIGN.md 文件将机器可读的设计令牌(YAML 前置元数据)与人类可读的设计原理(Markdown 散文)结合在一起。令牌为代理提供精确值,散文则告诉它们为什么存在这些值以及如何应用它们。

---
name: Heritage
colors:
  primary: "#1A1C1E"
  secondary: "#6C7278"
  tertiary: "#B8422E"
  neutral: "#F7F5F2"
typography:
  h1:
    fontFamily: Public Sans
    fontSize: 3rem
  body-md:
    fontFamily: Public Sans
    fontSize: 1rem
  label-caps:
    fontFamily: Space Grotesk
    fontSize: 0.75rem
rounded:
  sm: 4px
  md: 8px
spacing:
  sm: 8px
  md: 16px
---

## 概述

建筑极简主义与新闻庄重感的结合。UI 唤起了一种高级哑光质感——类似于高端宽版报纸或当代画廊。

## 色彩

调色板以高对比度的中性色和单一强调色为基础。

- **Primary (#1A1C1E):** 深墨色,用于标题和核心文本。
- **Secondary (#6C7278):** 考究的灰石板色,用于边框、说明文字和元数据。
- **Tertiary (#B8422E):** “波士顿粘土色”——交互行为的唯一驱动者。
- **Neutral (#F7F5F2):** 温暖石灰石底色,比纯白色更柔和。

阅读此文件的代理将生成一个 UI:深墨色标题使用 Public Sans 字体,温暖石灰石背景,以及波士顿粘土色号召性用语按钮。

快速开始

根据规范验证 DESIGN.md,捕捉损坏的令牌引用,检查 WCAG 对比度比率,并呈现结构性发现——全部以结构化 JSON 形式输出,代理可据此操作。

npx @google/design.md lint DESIGN.md
{
  "findings": [
    {
      "severity": "warning",
      "path": "components.button-primary",
      "message": "textColor (#ffffff) on backgroundColor (#1A1C1E) has contrast ratio 15.42:1 — passes WCAG AA."
    }
  ],
  "summary": { "errors": 0, "warnings": 1, "info": 1 }
}

比较两个版本的设计系统,以检测令牌级别和散文层面的退化:

npx @google/design.md diff DESIGN.md DESIGN-v2.md
{
  "tokens": {
    "colors": { "added": ["accent"], "removed": [], "modified": ["tertiary"] },
    "typography": { "added": [], "removed": [], "modified": [] }
  },
  "regression": false
}

规范定义

完整的 DESIGN.md 规范位于 docs/spec.md。以下为简明参考。

文件结构

DESIGN.md 文件包含两个层面:

  1. YAML 前置元数据 — 机器可读的设计令牌,由文件顶部的 --- 分隔符界定。
  2. Markdown 正文 — 人类可读的设计原理,组织为 ## 章节。

令牌是规范性值。散文提供如何应用它们的上下文。

令牌架构

version: <string>          # 可选,当前为:"alpha"
name: <string>
description: <string>      # 可选
colors:
  <token-name>: <Color>
typography:
  <token-name>: <Typography>
rounded:
  <scale-level>: <Dimension>
spacing:
  <scale-level>: <Dimension | number>
components:
  <component-name>:
    <token-name>: <string | token reference>

令牌类型

类型格式示例
Color任何 CSS 颜色(十六进制、rgb()oklch()、具名颜色等)"#1A1C1E", "oklch(62% 0.18 250)"
Dimension数字 + 单位(pxemrem48px, -0.02em
Token Reference{path.to.token}{colors.primary}
Typography包含 fontFamilyfontSizefontWeightlineHeightletterSpacingfontFeaturefontVariation 的对象见上方示例

章节顺序

章节使用 ## 标题。可以省略,但出现的章节必须按此顺序排列:

#章节别名
1OverviewBrand & Style
2Colors
3Typography
4LayoutLayout & Spacing
5Elevation & DepthElevation
6Shapes
7Components
8Do’s and Don’ts

组件令牌

组件将名称映射到一组子令牌属性:

components:
  button-primary:
    backgroundColor: "{colors.tertiary}"
    textColor: "{colors.on-tertiary}"
    rounded: "{rounded.sm}"
    padding: 12px
  button-primary-hover:
    backgroundColor: "{colors.tertiary-container}"

有效的组件属性:backgroundColortextColortypographyroundedpaddingsizeheightwidth

变体(hover、active、pressed)通过相关键名表达为单独的组件条目。

对未知内容的消费者行为

场景行为
未知章节标题保留;不报错
未知颜色令牌名称如果值有效则接受
未知排版令牌名称接受为有效排版
未知组件属性接受并发出警告
重复章节标题报错;拒绝文件

CLI 参考

安装

npm install @google/design.md

Windows 上,如果你的 shell(PowerShell、某些终端)将 @ 视为特殊字符,请对包名加引号:

npm install "@google/design.md"

或直接运行(始终从公共 npm 注册表解析):

npx @google/design.md lint DESIGN.md

Windows/PowerShell 上,这种直接形式可能不会产生输出(或在 Markdown 编辑器中打开 DESIGN.md),因为在命令解析期间 design.md 二进制名称中的 .md 后缀与 Windows Markdown 文件关联冲突。应改为使用无点的 designmd 别名——使用 -pnpx 指向包,然后调用 designmd

npx -p @google/design.md designmd lint DESIGN.md

designmd 垫片解析到相同的入口点,并在所有平台上工作一致。

npm error ENOVERSIONS (“No versions available for @google/design.md”)

CLI 以 @google/design.md 发布在 npm 上ENOVERSIONS 几乎总是意味着 npm 未查询公共注册表(由于 .npmrc 中的自定义 registry=、尚未同步此包的企业镜像、或 @google 作用域的 @google:registry 配置错误)。

检查你有效的注册表:

npm config get registry

正常的互联网安装应为 https://registry.npmjs.org/。修正配置后,如果缓存了过时的 404,请使用 npm cache clean --force 重试。

所有命令接受文件路径或 - 表示标准输入。输出默认为 JSON。

Windows 提示:当直接从 package.json 脚本调用 CLI 时(而不是通过 npx),请使用 designmd 别名而非 design.md。原始二进制名称中的 .md 后缀会与 Markdown 文件的文件关联混淆 Windows 命令解析。designmd 垫片解析到相同的入口点,并在所有平台上工作一致。

// package.json
{
  "scripts": {
    "design:lint": "designmd lint DESIGN.md"
  }
}

lint

验证 DESIGN.md 文件的结构正确性。

npx @google/design.md lint DESIGN.md
npx @google/design.md lint --format json DESIGN.md
cat DESIGN.md | npx @google/design.md lint -
选项类型默认值描述
file位置参数必填DESIGN.md 的路径(或通过 - 使用标准输入)
--formatjsonjson输出格式

如果发现错误,退出码为 1,否则为 0

diff

比较两个 DESIGN.md 文件并报告令牌级别的变更。

npx @google/design.md diff DESIGN.md DESIGN-v2.md
选项类型默认值描述
before位置参数必填“变更前” DESIGN.md 的路径
after位置参数必填“变更后” DESIGN.md 的路径
--formatjsonjson输出格式

如果检测到退化(“变更后”文件中错误或警告增多),退出码为 1

export

将 DESIGN.md 令牌导出为其他格式。

npx @google/design.md export --format json-tailwind DESIGN.md > tailwind.theme.json
npx @google/design.md export --format css-tailwind DESIGN.md > theme.css
npx @google/design.md export --format dtcg DESIGN.md > tokens.json
选项类型默认值描述
file位置参数必填DESIGN.md 的路径(或通过 - 使用标准输入)
--formatjson-tailwind | css-tailwind | tailwind | dtcg必填输出格式
格式输出描述
json-tailwindJSONTailwind v3 theme.extend 配置对象
css-tailwindCSSTailwind v4 的 @theme { ... } 块,包含 CSS 自定义属性
tailwindJSONjson-tailwind 的别名
dtcgJSONW3C Design Tokens Format 模块

成功导出时退出码为 0(无论源文件中是否存在 lint 问题——可通过 lint 进行前置检查),无效的 --format 或发射器错误时退出码为 1,输入文件无法读取时退出码为 2

spec

输出 DESIGN.md 格式规范(可用于将规范上下文注入代理提示)。

npx @google/design.md spec
npx @google/design.md spec --rules
npx @google/design.md spec --rules-only --format json
选项类型默认值描述
--rulesbooleanfalse附加活跃的 lint 规则表
--rules-onlybooleanfalse仅输出 lint 规则表
--formatmarkdown | jsonmarkdown输出格式

Linting 规则

linter 针对已解析的 DESIGN.md 运行九条规则。每条规则以固定的严重级别产生检查结果。

规则严重级别检查内容
broken-referror令牌引用(如 {colors.primary})无法解析为任何已定义的令牌
missing-primarywarning已定义颜色但不存在 primary 颜色——代理将自动生成一个
contrast-ratiowarning组件 backgroundColor/textColor 组合低于 WCAG AA 最低要求(4.5:1)
orphaned-tokenswarning定义了颜色令牌但未被任何组件引用
token-summaryinfo每个部分定义的令牌数量汇总
missing-sectionsinfo可选部分(spacing、rounded)在存在其他令牌时缺失
missing-typographywarning已定义颜色但不存在排版令牌——代理将使用默认字体
section-orderwarning部分未按照规范定义的规范顺序出现
unknown-keywarning顶层 YAML 键看起来像是已知模式键的拼写错误(例如 colours:colors:);自定义扩展键保持静默

编程式 API

linter 也可以作为库使用:

import { lint } from '@google/design.md/linter';

const report = lint(markdownString);

console.log(report.findings);       // Finding[]
console.log(report.summary);        // { errors, warnings, info }
console.log(report.designSystem);   // Parsed DesignSystemState

设计令牌互操作性

DESIGN.md 令牌受 W3C Design Token Format 启发。export 命令将令牌转换为其他格式:

  • Tailwind v3 配置(JSON)npx @google/design.md export --format json-tailwind DESIGN.md — 输出一个 theme.extend JSON 对象,用于 tailwind.config.js--format tailwind 是向后兼容的别名。
  • Tailwind v4 主题(CSS)npx @google/design.md export --format css-tailwind DESIGN.md — 输出一个 CSS @theme { ... } 块,使用 Tailwind v4 的 CSS 变量令牌命名空间(--color-*--font-*--text-*--leading-*--tracking-*--font-weight-*--radius-*--spacing-*)。
  • DTCG tokens.jsonW3C Design Tokens Format Module) — npx @google/design.md export --format dtcg DESIGN.md

状态

DESIGN.md 格式目前为 alpha 版本。规范、令牌模式和 CLI 正在积极开发中。随着格式成熟,预计会发生变化。

免责声明

本项目不符合 Google 开源软件漏洞奖励计划 的资格。

在 GitHub 查看完整项目