项目简介
定义了一种结合 YAML 设计令牌与 Markdown 说明的设计格式。提供命令行工具进行校验和差异比较,让编码代理能够持久理解设计系统。
README 预览
# DESIGN.md\n\nA format specification for describing a visual identity to coding agents. DESIGN.md gives agents a persistent, structured understanding of a design system.\n\n## The Format\n\nA DESIGN.md file combines machine-readable design tokens (YAML front matter) with human-readable design rationale (markdown prose). Tokens give agents exact values. Prose tells them *why* those values exist and how to apply them.\n\n```md\n---\nname: Heritage\ncolors:\n primary: "#1A1C1E"\n secondary: "#6C7278"\n tertiary: "#B8422E"\n neutral: "#F7F5F2"\ntypography:\n h1:\n fontFamily: Public Sans\n fontSize: 3rem\n body-md:\n fontFamily: Public Sans\n fontSize: 1rem\n label-caps:\n fontFamily: Space Grotesk\n fontSize: 0.75rem\nrounded:\n sm: 4px\n md: 8px\nspacing:\n sm: 8px\n md: 16px\n---\n\n## Overview\n\nArchitectural Minimalism meets Journalistic Gravitas. The UI evokes a\npremium matte finish — a high-end broadsheet or contemporary gallery.\n\n## Colors\n\nThe palette is rooted in high-contrast neutrals and a single accent color.\n\n- **Primary (#1A1C1E):** Deep ink for headlines and core text.\n- **Secondary (#6C7278):** Sophisticated slate for borders, captions, metadata.\n- **Tertiary (#B8422E):** "Boston Clay" — the sole driver for interaction.\n- **Neutral (#F7F5F2):** Warm limestone foundation, softer than pure white.\n```\n\nAn agent that reads this file will produce a UI with deep ink headlines in Public Sans, a warm limestone background, and Boston Clay call-to-action buttons.\n\n## Getting Started\n\nValidate a DESIGN.md against the spec, catch broken token references, check WCAG contrast ratios, and surface structural findings — all as structured JSON that agents can act on.\n\n```bash\nnpx @google/design.md lint DESIGN.md\n```\n\n```json\n{\n "findings": [\n {\n "severity": "warning",\n "path": "components.button-primary",\n "message": "textColor (#ffffff) on backgroundColor (#1A1C1E) has contrast ratio 15.42:1 常见问题 (5)
故障排除如何修复 @google/design.md 的 css-tailwind 导出中导致 git diff --check 失败的多余行尾换行符问题?
在 @google/design.md@0.3.0 中,serializeTailwindV4() 已经会追加一个末尾换行符,但 CLI 使用了 console.log(),它又会额外添加一个换行符。修复导出器的方法是:针对 css-tailwind 导出输出,将 console.log(output) 替换为 process.stdout.write(output)。在包含该修复的版本发布之前,可在导出后对生成的文件进行规范化处理:
./node_modules/.bin/designmd export --format css-tailwind DESIGN.md \
| perl -0pe 's/\n+\z/\n/' > out.css
验证文件末尾恰好只有一个换行符:
python3 -c "from pathlib import Path; b=Path('out.css').read_bytes(); print(len(b)-len(b.rstrip(b'\\n')))"
预期结果为 1。这样可以防止 git diff --check 等严格的空白字符检查在已检入的生成 CSS 文件上报错。
how_to如何将设计令牌从 DESIGN.md 导出为原生 CSS 自定义属性?
使用 css-vars 导出格式:
npx @google/design.md export --format css-vars DESIGN.md > design.tokens.css
这会生成一个包含 CSS 自定义属性的 :root 代码块,例如:
:root {
--color-primary: #1A1C1E;
--spacing-md: 16px;
}
要为每个变量添加命名空间前缀,请使用 --prefix:
npx @google/design.md export --format css-vars --prefix ds DESIGN.md > design.tokens.css
深色主题和媒体查询变体未包含在初始实现中;该支持已在 PR #109 中添加。
informational用简单的话来说,什么是量子计算?
普通计算机使用比特(bit),其状态要么为 1(开),要么为 0(关)。量子计算机使用量子比特(qubit),在结果被测量之前,它可以处于一种称为叠加态(superposition)的混合状态。这使得量子计算机能够在某些复杂计算中同时探索多种可能性,不过它们并不仅仅是普通计算机的加速版本。
故障排除如何修复运行 @google/design.md lint 时出现的 "raw.match is not a function" 错误?
当 DESIGN.md 中的 spacing 值为 YAML 非字符串值(例如 unit: 8)时,@google/design.md@0.2.0 会发生此崩溃。请升级到 v0.3.0,该版本包含运行时类型守卫(type-guard)修复。作为变通方案,请为所有尺寸值加上引号:
spacing:
unit: "8"
"1": "4px"
请使用 unit: "8px",而不要使用 unit: 8 或不带引号的 unit: 8px。
故障排除如何让 Color 和 Dimension 类型定义基于 spec-config.yaml 实现数据驱动?
升级到 v0.4.0,此版本中原始类型从 spec-config.yaml 渲染。如果手动应用此更改,请添加一个 types 部分,例如:
types:
Color:
description: "A color value is any valid CSS color string."
formats:
- "Hex: #RGB, #RGBA, #RRGGBB, #RRGGBBAA"
- "Named colors: red, cornflowerblue, transparent"
- "Functional: rgb(), rgba(), hsl(), hsla(), hwb()"
- "Wide-gamut: oklch(), oklab(), lch(), lab()"
- "Mixing: color-mix(in srgb, ...)"
note: "All color values are internally converted to sRGB for WCAG contrast checking."
Dimension:
description: "A dimension value is a string with a unit suffix."
units: [px, em, rem]
然后从 spec.mdx 中移除静态的 Color 和 Dimension 描述文本,并更新 spec 生成器,使其遍历 spec-config.yaml 中的 types,方式与渲染 typography_properties 相同。运行 spec-config 和 spec-generator 测试以验证输出。