feat(design): design/ 真相源 + 防漂移静态闸(#25)

真相源整固:
- design/index.html 登记簿:token 色板(var() 实时渲染)/ 组件登记卡 /
  图标与跨端映射 / guidelines / ui_kits 单一入口,check-ds 强制登记
- design/icons.js 图标单源(Lucide 线条)+ icon-map.json 跨端映射表
  (web/iOS/Android 三列,iOS 12 个 SF Symbol 全部收编登记)
- components/core/Icon.jsx 单源图标渲染器;MicBar/RecognitionOverlay 接入
- tokens 新增 --brand-wechat(-press)(微信官方绿)与 --overlay-wave
- fonts.css 弃 Google Fonts CDN,Outfit 可变字体自托管
  (assets/outfit-latin.woff2,40KB;中国网络下 CDN 不可用会卡字体)
- design/serve.mjs 零依赖预览服务器(登记簿与原型评审入口)

codegen 强化(export-tokens.mjs):
- 产物直写消费位置:ios/dudu/Shared/DuduTheme.swift、
  android/.../design/DuduTheme.kt——删除 design-pipeline/generated/
  中间拷贝层(此前 app 内是手工拷贝,--check 守不到真实消费文件已漂移)
- 新增 web/tokens.css 产物(custom props 透传 + Outfit data URI 内嵌)
- tokens 文件遍历排序,产物确定性

存量收编:
- desktop:三个窗口内联 SVG → Icon 组件;tray 裸 rgba → token+opacity
- Android:LoginScreen 微信绿常量 → DuduPalette.brandWechat(Press),
  Color.White → textOnAccent
- 官网 web/index.html:接入 tokens.css,34 处硬编码 hex 全部 var() 化;
  深色板块(metrics/cta/footer)改挂 data-theme="dark" 复用 dark 令牌;
  移除 Google Fonts CDN
- design 包内 8 处裸色:微信绿 token 化、装饰色 ds-ignore 白名单、
  同值色改 var() 引用

防漂移闸(零依赖 Node):
- design-pipeline/check-ds.mjs:真相源自检 7 道(dark⊆light / var 链 /
  裸色∈tokens 值集 / 组件登记 / icons 唯一 / icon-map 双向同集 / 禁 emoji)
- design-pipeline/check-code.mjs:代码侧单源(desktop 禁字面色+内联 path /
  iOS 禁字面色+SF Symbol 同集 / Android 禁 Color(0x / web 禁字面色),
  ds-ignore 行级豁免制
- .githooks/pre-commit(启用:git config core.hooksPath .githooks)
- CI design job 扩展为三道闸全绿
- 反向验证通过:注入裸色/孤儿 token/未登记组件/未登记 symbol 均被拦截

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-11 00:05:22 +08:00
parent 4aec0ef6e9
commit 208d0cda12
36 changed files with 1014 additions and 494 deletions
+13
View File
@@ -0,0 +1,13 @@
import * as React from 'react';
import type { icons } from '../../icons.js';
export interface IconProps extends React.SVGProps<SVGSVGElement> {
/** design/icons.js 登记的图标名 */
name: keyof typeof icons;
/** 边长 px(24 网格等比缩放),默认 16 */
size?: number;
/** 描边宽度,默认 2 */
sw?: number;
}
export declare function Icon(props: IconProps): React.JSX.Element;
+25
View File
@@ -0,0 +1,25 @@
// Icon:渲染 design/icons.js 单源图标(Lucide 线条、24 网格、currentColor)。
// 业务代码禁止内联 <path>check-code 闸拦截)——新图标先登记 icons.js + icon-map.json。
import { icons } from '../../icons.js';
export function Icon({ name, size = 16, sw = 2, ...rest }) {
// 安全前提:body 只能来自 icons.js 的静态常量(源码入库、无用户输入),
// 故 dangerouslySetInnerHTML 无 XSS 面。禁止改为接受外部传入的 SVG 字符串。
const body = icons[name];
if (!body) throw new Error(`unknown icon: ${name}(先在 design/icons.js 登记)`);
return (
<svg
width={size}
height={size}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={sw}
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
dangerouslySetInnerHTML={{ __html: body }}
{...rest}
/>
);
}
+1 -1
View File
@@ -8,7 +8,7 @@ const ddSwitchCss = `
.dd-switch::after {
content: ''; position: absolute; top: 3px; left: 3px;
width: 18px; height: 18px; border-radius: 50%;
background: #fff; box-shadow: 0 1px 3px rgba(17,19,26,0.25);
background: #fff; box-shadow: 0 1px 3px rgba(17,19,26,0.25); /* ds-ignore: 拇指投影,gray-950 的 25% 派生 */
transition: transform var(--dur-base) var(--ease-out);
}
.dd-switch[aria-checked="true"] { background: var(--accent); }
+3 -9
View File
@@ -1,4 +1,5 @@
import { Waveform } from './Waveform';
import { Icon } from '../core/Icon';
const ddMicBarCss = `
.dd-micbar {
@@ -24,14 +25,7 @@ if (typeof document !== 'undefined' && !document.getElementById('dd-micbar-css')
}
function DdMicIcon({ size = 20 }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor"
strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"></path>
<path d="M19 10v2a7 7 0 0 1-14 0v-2"></path>
<line x1="12" x2="12" y1="19" y2="22"></line>
</svg>
);
return <Icon name="mic" size={size} />;
}
const DD_MICBAR_LABELS = {
@@ -46,7 +40,7 @@ export function MicBar({ state = 'idle', label, ...rest }) {
return (
<button type="button" className={`dd-micbar dd-micbar--${state}`} {...rest}>
{state === 'recording'
? <Waveform active bars={9} height={18} color="rgba(255,255,255,0.95)" />
? <Waveform active bars={9} height={18} color="rgba(255,255,255,0.95)" /> /* ds-ignore: accent 底上白波形 95% 派生 */
: <DdMicIcon />}
<span>{text}</span>
</button>
@@ -1,4 +1,5 @@
import { Waveform } from './Waveform';
import { Icon } from '../core/Icon';
const ddOverlayCss = `
.dd-overlay {
@@ -35,15 +36,10 @@ export function RecognitionOverlay({
}) {
return (
<div className="dd-overlay" style={{ width, ...style }} role="status">
<Waveform active bars={12} height={24} color="#7C9BFF" />
<Waveform active bars={12} height={24} color="var(--overlay-wave)" />
{state === 'listening' ? (
<div className="dd-overlay__status">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"></path>
<path d="M19 10v2a7 7 0 0 1-14 0v-2"></path>
<line x1="12" x2="12" y1="19" y2="22"></line>
</svg>
<Icon name="mic" size={16} />
<span>聆听中</span>
</div>
) : (