@hia/theme-core 0.6.0 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ // 角色档位取值(恒 HEX;缺失档位回退基色)。
2
+ // <lang en>Role/step lookup (always HEX; missing steps fall back to the base colour).</lang>
3
+ function step(t, role, shade) {
4
+ const r = t[role];
5
+ // shade 是运行时拼出的档位键('50'…'900'),ColorScale 索引签名按字符串键放行。
6
+ // <lang en>shade is a runtime-built step key ('50'…'900'); index ColorScale by string key.</lang>
7
+ return r.scale[shade] ?? r.value;
8
+ }
9
+ function thirdOr(t, fallback) { return t.thirdColor?.value ?? fallback; }
10
+ function auxOr(t, i, fallback) { return t.auxiliary[i]?.value ?? fallback; }
11
+ /**
12
+ * @lang zh-CN scope 映射表(ADR-015 登记的 HIA 设计判断)。
13
+ * 设计原则:注释退后(secondary.600 低刺激)、字符串/常量用语义间隔色(success/warning 系
14
+ * 若语义色存在则优先——编辑器主题不自带语义组,故此处用 primary 系间隔档)、
15
+ * 关键字用主色、函数名用主色深阶、变量用中性深墨、类型用第三色/辅助色。
16
+ * @lang en The scope mapping (HIA design judgement, ADR-015): comments recede (secondary.600),
17
+ * strings/constants get semantic-interval shades, keywords use the primary, function names its darker
18
+ * step, variables neutral ink, types the third/aux colour.
19
+ */
20
+ function scopeMappings(t) {
21
+ const hasSemantic = t.semantic;
22
+ const stringHex = hasSemantic ? t.semantic.success.scale['600'] ?? t.semantic.success.value : step(t, 'secondary', '600');
23
+ const numberHex = hasSemantic ? t.semantic.warning.scale['600'] ?? t.semantic.warning.value : step(t, 'secondary', '700');
24
+ const typeHex = t.thirdColor?.value ?? auxOr(t, 0, step(t, 'primary', '400'));
25
+ return [
26
+ { scope: 'comment', fg: () => step(t, 'secondary', '600') },
27
+ { scope: 'string', fg: () => stringHex },
28
+ { scope: 'constant.numeric', fg: () => numberHex },
29
+ { scope: 'constant.language', fg: () => step(t, 'primary', '400') },
30
+ { scope: 'keyword', fg: () => step(t, 'primary', '500') },
31
+ { scope: 'keyword.operator', fg: () => step(t, 'secondary', '700') },
32
+ { scope: 'entity.name.function', fg: () => step(t, 'primary', '600') },
33
+ { scope: 'entity.name.type', fg: () => typeHex },
34
+ { scope: 'entity.name.tag', fg: () => step(t, 'primary', '600') },
35
+ { scope: 'variable', fg: () => step(t, 'secondary', '900') },
36
+ { scope: 'variable.parameter', fg: () => step(t, 'secondary', '800') },
37
+ { scope: 'support.function', fg: () => step(t, 'primary', '600') },
38
+ { scope: 'meta.tag', fg: () => thirdOr(t, step(t, 'primary', '600')) },
39
+ { scope: 'markup.heading', fg: () => step(t, 'primary', '700') }
40
+ ];
41
+ }
42
+ /** @lang zh-CN 编辑器 chrome:背景/前景/行号/选区/当前行——明暗两套各自取色。 @lang en Editor chrome: background, foreground, line numbers, selection, current line — per appearance. */
43
+ function chrome(t, appearance) {
44
+ // light:主色 50 阶底 + 深墨字;dark:主色 900 阶底 + 主色 50 字。
45
+ // <lang en>light: primary-50 bg + ink text; dark: primary-900 bg + primary-50 text.</lang>
46
+ if (appearance === 'dark') {
47
+ return { bg: t.primary.scale['900'] ?? '#101A2B', fg: t.primary.scale['50'] ?? '#E8EEF7', line: t.primary.scale['800'] ?? '#182540', selection: t.primary.scale['700'] ?? '#243B5E', current: t.primary.scale['800'] ?? '#182540', comment: step(t, 'secondary', '400') };
48
+ }
49
+ return { bg: t.primary.scale['50'] ?? '#F4F8FD', fg: t.primary.scale['900'] ?? '#0F1E33', line: t.primary.scale['100'] ?? '#DCE8F4', selection: t.primary.scale['100'] ?? '#DCE8F4', current: t.primary.scale['100'] ?? '#DCE8F4', comment: step(t, 'secondary', '600') };
50
+ }
51
+ /** @lang zh-CN 主题名规范化(编辑器主题名不含空格/特殊字符)。 @lang en Normalises the theme name for editor theme titles. */
52
+ function editorName(t, appearance) {
53
+ const base = t.name.replace(/[^\w\u4e00-\u9fa5-]+/g, ' ').trim();
54
+ return `${base} (${appearance})`;
55
+ }
56
+ /**
57
+ * @lang zh-CN 生成 TextMate 主题(`.tmTheme`,XML plist 格式)。
58
+ * scope 按"父 scope"粒度输出(TextMate 匹配前缀,子 scope 继承)。
59
+ * @lang en TextMate theme (`.tmTheme`, XML plist). Scopes emit at parent granularity (TextMate matches by
60
+ * prefix, children inherit).
61
+ */
62
+ export function textmateTheme(t, appearance = 'light') {
63
+ const c = chrome(t, appearance);
64
+ const items = scopeMappings(t).map(m => ` <dict>
65
+ <key>name</key><string>${m.scope}</string>
66
+ <key>scope</key><string>${m.scope}</string>
67
+ <key>settings</key><dict>
68
+ <key>foreground</key><string>${m.fg(t)}</string>${m.bg ? `\n <key>background</key><string>${m.bg(t)}` : ''}
69
+ </dict>
70
+ </dict>`).join('\n');
71
+ return `<?xml version="1.0" encoding="UTF-8"?>
72
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
73
+ <plist version="1.0">
74
+ <dict>
75
+ <key>name</key><string>${editorName(t, appearance)}</string>
76
+ <key>semanticClass</key><string>theme.${appearance}.${editorName(t, appearance)}</string>
77
+ <key>settings</key><array>
78
+ <dict>
79
+ <key>settings</key><dict>
80
+ <key>background</key><string>${c.bg}</string>
81
+ <key>foreground</key><string>${c.fg}</string>
82
+ <key>lineHighlight</key><string>${c.current}</string>
83
+ <key>selection</key><string>${c.selection}</string>
84
+ </dict>
85
+ </dict>
86
+ ${items}
87
+ </array>
88
+ </dict>
89
+ </plist>
90
+ `;
91
+ }
92
+ /**
93
+ * @lang zh-CN 生成 VSCode 主题(`.color-theme.json`):tokenColors(scope 数组)+ colors
94
+ * (workbench chrome:editorBackground/lineNumber/selection 等)。
95
+ * @lang en VSCode theme (`.color-theme.json`): tokenColors (scope array) + workbench colors
96
+ * (editorBackground, lineNumber, selection…).
97
+ */
98
+ export function vscodeTheme(t, appearance = 'light') {
99
+ const c = chrome(t, appearance);
100
+ const tokenColors = scopeMappings(t).map(m => ({
101
+ scope: m.scope,
102
+ settings: { foreground: m.fg(t), ...(m.bg ? { background: m.bg(t) } : {}) }
103
+ }));
104
+ const doc = {
105
+ name: editorName(t, appearance),
106
+ type: appearance === 'dark' ? 'dark' : 'light',
107
+ semanticHighlighting: true,
108
+ colors: {
109
+ 'editor.background': c.bg,
110
+ 'editor.foreground': c.fg,
111
+ 'editorLineNumber.foreground': c.line,
112
+ 'editor.selectionBackground': c.selection,
113
+ 'editor.lineHighlightBackground': c.current
114
+ },
115
+ tokenColors
116
+ };
117
+ return JSON.stringify(doc, null, 2) + '\n';
118
+ }
119
+ /**
120
+ * @lang zh-CN 生成 Vim 主题(`.vim` 脚本):highlight 组映射——
121
+ * Comment/String/Number/Keyword/Function/Type/Normal/Visual/LineNr。
122
+ * @lang en Vim theme (`.vim` script): highlight groups Comment/String/Number/Keyword/Function/Type/Normal/
123
+ * Visual/LineNr.
124
+ */
125
+ export function vimTheme(t, appearance = 'light') {
126
+ const c = chrome(t, appearance);
127
+ const m = scopeMappings(t);
128
+ const fg = (scope) => m.find(x => x.scope === scope)?.fg(t) ?? c.fg;
129
+ const name = editorName(t, appearance).replace(/[^\w\u4e00-\u9fa5-]+/g, '_');
130
+ return `" ${editorName(t, appearance)} — generated by HIA Theme Builder (W-tb-P42 / ADR-015)
131
+ " Usage: :colorscheme ${name}
132
+ if exists('g:syntax_on')
133
+ syntax reset
134
+ endif
135
+ let g:colors_name = '${name}'
136
+
137
+ set background=${appearance === 'dark' ? 'dark' : 'light'}
138
+ highlight clear
139
+
140
+ highlight Normal guifg=${c.fg} guibg=${c.bg}
141
+ highlight Comment guifg=${fg('comment')}
142
+ highlight String guifg=${fg('string')}
143
+ highlight Number guifg=${fg('constant.numeric')}
144
+ highlight Boolean guifg=${fg('constant.language')}
145
+ highlight Keyword guifg=${fg('keyword')}
146
+ highlight Operator guifg=${fg('keyword.operator')}
147
+ highlight Function guifg=${fg('entity.name.function')}
148
+ highlight Type guifg=${fg('entity.name.type')}
149
+ highlight Tag guifg=${fg('entity.name.tag')}
150
+ highlight Variable guifg=${fg('variable')}
151
+ highlight Visual guibg=${c.selection}
152
+ highlight LineNr guifg=${c.line}
153
+ highlight CursorLine guibg=${c.current}
154
+ `;
155
+ }
156
+ /**
157
+ * @lang zh-CN 生成 Emacs 主题(`.el` face 定义):defface + deftheme,组与 Vim 对齐。
158
+ * @lang en Emacs theme (`.el` face definitions): deftheme + defface, groups aligned with Vim.
159
+ */
160
+ export function emacsTheme(t, appearance = 'light') {
161
+ const c = chrome(t, appearance);
162
+ const m = scopeMappings(t);
163
+ const fg = (scope) => m.find(x => x.scope === scope)?.fg(t) ?? c.fg;
164
+ const name = editorName(t, appearance).replace(/[^\w\u4e00-\u9fa5-]+/g, '-').toLowerCase();
165
+ return `;;; ${editorName(t, appearance)} — generated by HIA Theme Builder (W-tb-P42 / ADR-015)
166
+ ;;; Usage: (load-theme '${name})
167
+
168
+ (deftheme ${name}
169
+ "HIA Theme Builder theme (${appearance}).")
170
+
171
+ (custom-theme-set-faces
172
+ '${name}
173
+ '(default ((t (:background "${c.bg}" :foreground "${c.fg}"))))
174
+ '(font-lock-comment-face ((t (:foreground "${fg('comment')}"))))
175
+ '(font-lock-string-face ((t (:foreground "${fg('string')}"))))
176
+ '(font-lock-constant-face ((t (:foreground "${fg('constant.numeric')}"))))
177
+ '(font-lock-keyword-face ((t (:foreground "${fg('keyword')}"))))
178
+ '(font-lock-function-name-face ((t (:foreground "${fg('entity.name.function')}"))))
179
+ '(font-lock-type-face ((t (:foreground "${fg('entity.name.type')}"))))
180
+ '(font-lock-variable-name-face ((t (:foreground "${fg('variable')}"))))
181
+ '(region ((t (:background "${c.selection}"))))
182
+ '(line-number ((t (:foreground "${c.line}")))))
183
+ `;
184
+ }
185
+ /**
186
+ * @lang zh-CN 生成器注册表:`builtin:` templateRef 名 → 生成函数与产物扩展名。
187
+ * TDON 文档经 `exportManifest.files[]` 以 `templateRef` 引用(与 `builtin:hia-tokens-css` 同构)。
188
+ * appearance 由调用方(导出链路)传入——TDON 文档可用同一路径声明两份(light/dark)。
189
+ * @lang en Generator registry: `builtin:` templateRef name → generator + file extension. TDON documents
190
+ * reference them from `exportManifest.files[]` (isomorphic with `builtin:hia-tokens-css`); appearance is
191
+ * passed by the export pipeline, so a document can declare both light/dark files.
192
+ */
193
+ export const EDITOR_THEME_GENERATORS = [
194
+ { ref: 'builtin:textmate-theme', ext: '.tmTheme', label: 'TextMate', generate: textmateTheme },
195
+ { ref: 'builtin:vscode-theme', ext: '.color-theme.json', label: 'VSCode', generate: vscodeTheme },
196
+ { ref: 'builtin:vim-theme', ext: '.vim', label: 'Vim', generate: vimTheme },
197
+ { ref: 'builtin:emacs-theme', ext: '.el', label: 'Emacs', generate: emacsTheme }
198
+ ];
199
+ /** @lang zh-CN 按 ref 取生成器定义;未命中返回 undefined。 @lang en Looks up a generator by ref; undefined when missing. */
200
+ export function findEditorThemeGenerator(ref) { return EDITOR_THEME_GENERATORS.find(g => g.ref === ref); }
201
+ //# sourceMappingURL=editor-themes.js.map
@@ -36,7 +36,9 @@ import './hia-tokens.css';
36
36
  \`\`\`vue
37
37
  <style scoped>
38
38
  .hero {
39
- background: var(--hia-gradient-carousel); /* 渐变令牌 / gradient token */
39
+ /* 降级链(W-tb-P37):color 先行垫底,image 失败时仍有纯色 / Degradation chain: colour first, image second */
40
+ background-color: var(--hia-primary-500);
41
+ background-image: var(--hia-gradient-carousel);
40
42
  color: var(--hia-primary-700);
41
43
  padding: var(--hia-space-3);
42
44
  }
@@ -66,7 +68,8 @@ export function Card() {
66
68
  \`\`\`html
67
69
  <link rel="stylesheet" href="./hia-tokens.css">
68
70
  <style>
69
- .banner { background: var(--hia-gradient-banner); color: var(--hia-secondary-900); }
71
+ /* 降级链:先 color 后 image / Degradation chain: colour first, image second */
72
+ .banner { background-color: var(--hia-secondary-400); background-image: var(--hia-gradient-banner); color: var(--hia-secondary-900); }
70
73
  </style>
71
74
  \`\`\`
72
75
 
@@ -75,6 +78,7 @@ export function Card() {
75
78
  - 变量名规则 / Naming: \`--hia-primary-<shade>\`(shade 为 50–900 标准档或渐变引用的自定义档);
76
79
  - 明暗适配:在 \`html.dark\` 等作用域内覆写同批变量即可,无需改组件 / override the same vars under a scope like \`html.dark\`;
77
80
  - 主题再生成时请整体替换本文件,避免手工修改丢失 / regenerate the whole file from HIA Theme Builder rather than hand-editing.
81
+ - **降级链**(W-tb-P37):渐变/图片背景一律"先 \`background-color\` 纯色垫底、后 \`background-image\`",渐变变量自身也携带起始色垫底层;任何一层失效都不露底色 / **Degradation chain**: gradient/image backgrounds pair a solid \`background-color\` with \`background-image\`; gradient vars also carry a start-colour underlay, so no layer failure exposes the bare container.
78
82
  `;
79
83
  // 固定两文件顺序:tokens.css 在前(主产物)。
80
84
  // <lang zh-CN>路径为 ZIP 内相对根路径。</lang>
@@ -1,13 +1,17 @@
1
1
  import { wordpressChildTarget } from './wordpress.js';
2
2
  import { tailwindConfigTarget } from './tailwind.js';
3
3
  import { injectTemplateTarget } from './inject-template.js';
4
+ import { tailwindV4Target } from './tailwind4.js';
5
+ import { dtcgExportTarget } from './dtcg.js';
4
6
  // 内置导出目标清单(顺序即 UI 展示顺序:WP → Tailwind → 通用注入)。
5
7
  // <lang zh-CN>与 `W-tb-P9` 计划 §3.2-3.4 的首批栈对应;深冻结保证清单与条目均不可变。</lang>
6
8
  // <lang en>Matches the first batch stacks in the `W-tb-P9` plan §3.2-3.4; deep-frozen so neither list nor entries mutate.</lang>
7
9
  export const EXPORT_TARGETS = [
8
10
  wordpressChildTarget,
9
11
  tailwindConfigTarget,
10
- injectTemplateTarget
12
+ tailwindV4Target,
13
+ injectTemplateTarget,
14
+ dtcgExportTarget
11
15
  ].map(t => Object.freeze({ ...t }));
12
16
  // 按 id 检索导出目标。
13
17
  // <lang zh-CN>未命中返回 undefined,由 UI 层决定报错方式;id 精确匹配(大小写敏感)。</lang>
@@ -1,5 +1,6 @@
1
1
  import { collectCustomShades } from '../gradient/render.js';
2
2
  import { slugifyThemeName, fullTokenCss, commentSafe } from './shared.js';
3
+ import { radiusSequence, shadowCss } from '../token/radius.js';
3
4
  // 生成单色族的 Tailwind colors 子对象:DEFAULT=基色,标准 10 档 + 自定义色阶附加键。
4
5
  // <lang zh-CN>档位键加引号('50'…'900'/'650'),保证 JS 对象字面量合法且键序与 SHADE_KEYS 一致;
5
6
  // 自定义档与 CSS/JSON/WP 导出同源(collectCustomShades),四处产物一致。</lang>
@@ -43,8 +44,19 @@ ${[
43
44
  ` primary: ${familyColors(theme.primary.scale, custom.primary, theme.primary.value)}`,
44
45
  ` secondary: ${familyColors(theme.secondary.scale, custom.secondary, theme.secondary.value)}`,
45
46
  ...(theme.thirdColor ? [` third: ${familyColors(theme.thirdColor.scale, {}, theme.thirdColor.value)}`] : []),
46
- ...theme.auxiliary.map((aux, i) => ` aux${i}: ${familyColors(aux.scale, {}, aux.value)}`)
47
+ ...theme.auxiliary.map((aux, i) => ` aux${i}: ${familyColors(aux.scale, {}, aux.value)}`),
48
+ // 语义状态色(W-tb-P37/ADR-012):success/info/warning/danger 四组全档。
49
+ // <lang en>Semantic status colours (W-tb-P37/ADR-012): full scales for the four statuses.</lang>
50
+ ...(theme.semantic ? Object.entries(theme.semantic).map(([k, role]) => ` ${k}: ${familyColors(role.scale, {}, role.value)}`) : [])
47
51
  ].join(',\n')}
52
+ },
53
+ // 圆角/阴影(W-tb-P37):五档半径 px + 三档阴影字符串(可随主色染色)。
54
+ // <lang en>Radius/shadow (W-tb-P37): five radius steps (px) + three shadow strings (primary-tintable).</lang>
55
+ borderRadius: {
56
+ ${Object.entries(radiusSequence(theme.radius)).map(([k, v]) => ` '${k}': '${v}px'`).join(',\n')}
57
+ },
58
+ boxShadow: {
59
+ ${Object.entries(shadowCss(theme.shadow, theme.primary.value)).map(([k, v]) => ` '${k}': ${JSON.stringify(v)}`).join(',\n')}
48
60
  },
49
61
  fontFamily: {
50
62
  body: ${JSON.stringify(theme.typography.fontFamily.body)},
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @lang zh-CN Tailwind v4 适配器(`W-tb-P37`):生成 **CSS-first** 的 `@theme` 块(app.css),
3
+ * 把主题令牌直接定义为 Tailwind v4 主题变量——`--color-*` 生成 utilities(`bg-primary-500` 等),
4
+ * `--radius-*`/`--shadow-*` 接入 `rounded-*`/`shadow-*`。这是 v4 的一等形态;v3 `config.js`
5
+ * 适配器保留为兼容形态(ADR-005 清单追加条目)。
6
+ * @lang en Tailwind v4 adapter (`W-tb-P37`): emits a **CSS-first** `@theme` block (app.css) defining theme
7
+ * tokens as Tailwind v4 theme variables — `--color-*` generate utilities (`bg-primary-500`…), while
8
+ * `--radius-*`/`--shadow-*` power `rounded-*`/`shadow-*`. This is the v4 first-class form; the v3
9
+ * `config.js` adapter stays as the compatibility form (added to the ADR-005 registry).
10
+ */
11
+ import type { ExportTarget } from './types.js';
12
+ /** @lang zh-CN Tailwind v4 导出目标(注册表条目)。 @lang en Tailwind v4 export target (registry entry). */
13
+ export declare const tailwindV4Target: ExportTarget;
14
+ //# sourceMappingURL=tailwind4.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { collectCustomShades } from '../gradient/render.js';
2
+ import { radiusSequence, shadowCss } from '../token/radius.js';
3
+ import { slugifyThemeName, commentSafe } from './shared.js';
4
+ // 单色族 @theme 行:DEFAULT 之外的 10 档 + 自定义档(与 v3/CSS/JSON 同源)。
5
+ // <lang en>One family's @theme lines: the 10 steps plus custom shades (same source as v3/CSS/JSON).</lang>
6
+ function themeColorLines(prefix, scale, custom, base) {
7
+ return [
8
+ ` --color-${prefix}: ${base};`,
9
+ ...Object.entries(scale).map(([k, v]) => ` --color-${prefix}-${k}: ${v};`),
10
+ ...Object.entries(custom).map(([k, v]) => ` --color-${prefix}-${k}: ${v};`)
11
+ ];
12
+ }
13
+ /**
14
+ * @lang zh-CN v4 适配器主体:产出单个 app.css(@theme 块 + 消费说明注释)。
15
+ * 语义状态色、圆角、阴影随主题携带时输出;渐变以 CSS 变量 `--gradient-*` 形态放在 :root
16
+ * (@theme 只收静态值,渐变引用色阶时保持 var() 动态性)。
17
+ * @lang en v4 adapter body: a single app.css (@theme block + usage comments). Semantic colours, radius and
18
+ * shadow emit when carried; gradients stay in :root as `--gradient-*` vars because @theme takes static
19
+ * values and gradients must keep referencing live scale vars.
20
+ */
21
+ function tailwindV4Files(theme) {
22
+ const custom = collectCustomShades(theme);
23
+ const radius = radiusSequence(theme.radius);
24
+ const shadows = shadowCss(theme.shadow, theme.primary.value);
25
+ const colorLines = [
26
+ ...themeColorLines('primary', theme.primary.scale, custom.primary, theme.primary.value),
27
+ ...themeColorLines('secondary', theme.secondary.scale, custom.secondary, theme.secondary.value),
28
+ ...(theme.thirdColor ? themeColorLines('third', theme.thirdColor.scale, {}, theme.thirdColor.value) : []),
29
+ ...theme.auxiliary.flatMap((aux, i) => themeColorLines(`aux${i}`, aux.scale, {}, aux.value)),
30
+ // 语义状态色(ADR-012):仅主题携带时输出。
31
+ // <lang en>Semantic statuses (ADR-012): emitted only when the theme carries them.</lang>
32
+ ...(theme.semantic ? Object.keys(theme.semantic).flatMap(k => themeColorLines(k, theme.semantic[k].scale, {}, theme.semantic[k].value)) : [])
33
+ ];
34
+ const radiusLines = Object.entries(radius).map(([k, v]) => ` --radius-${k}: ${v}px;`);
35
+ const shadowLines = Object.entries(shadows).map(([k, v]) => ` --shadow-${k}: ${JSON.stringify(v).replace(/"/g, '')};`);
36
+ const gradientLines = Object.entries(theme.gradients)
37
+ .filter(([, c]) => c)
38
+ .map(([k]) => ` --gradient-${k}: var(--hia-gradient-${k});`);
39
+ const css = `/* HIA Theme Builder — Tailwind v4 @theme tokens — ${commentSafe(theme.name)}
40
+ * Generated by HIA Theme Builder (W-tb-P37 / ADR-005). Import in your main CSS:
41
+ * @import "app.css";
42
+ * Utilities: bg-primary-500 · text-success-700 · rounded-md · shadow-lg · (gradients via var(--gradient-*))
43
+ */
44
+ @theme {
45
+ ${colorLines.join('\n')}
46
+ ${radiusLines.join('\n')}
47
+ ${shadowLines.join('\n')}
48
+ }
49
+
50
+ :root {
51
+ ${gradientLines.join('\n')}
52
+ }
53
+ `;
54
+ return [{ path: 'app.css', content: css }];
55
+ }
56
+ /** @lang zh-CN Tailwind v4 导出目标(注册表条目)。 @lang en Tailwind v4 export target (registry entry). */
57
+ export const tailwindV4Target = {
58
+ id: 'tailwind-v4',
59
+ name: 'Tailwind v4 @theme(ZIP)',
60
+ nameEn: 'Tailwind v4 @theme (ZIP)',
61
+ notes: '生成 CSS-first 的 app.css:@theme 定义 --color-*/--radius-*/--shadow-*(v4 一等形态);渐变经 var() 动态引用。',
62
+ notesEn: 'Emits a CSS-first app.css: @theme defines --color-*/--radius-*/--shadow-* (v4 first-class); gradients referenced dynamically via var().',
63
+ archiveName: theme => `hia-tailwind-v4-${slugifyThemeName(theme.name)}.zip`,
64
+ files: tailwindV4Files
65
+ };
66
+ //# sourceMappingURL=tailwind4.js.map
@@ -96,7 +96,7 @@ function wordpressChildFiles(theme, options) {
96
96
  if (!config || config.enabled === false)
97
97
  return [];
98
98
  const roleSlug = def.key.replace(/([A-Z])/g, '-$1').toLowerCase();
99
- return [{ name: def.label, slug: `hia-gradient-${roleSlug}`, gradient: gradientCss(config, 'literal', theme) }];
99
+ return [{ name: def.label, slug: `hia-gradient-${roleSlug}`, gradient: gradientCss(config, 'literal', theme, false) }];
100
100
  });
101
101
  // theme.json:WP 块主题全站编辑契约($schema 便于编辑器补全,version 2 为兼容口径)。
102
102
  // <lang zh-CN>defaultPalette/defaultGradients 关闭核心默认,突出 HIA 面板;custom 透传排版/间距令牌。</lang>
@@ -1,8 +1,10 @@
1
- import type { CssVariableMap, GradientBias, GradientConfig, GradientSettings, Theme } from '../types.js';
1
+ import type { CssVariableMap, GradientBias, GradientConfig, GradientFamily, GradientSettings, ShadeValue, Theme } from '../types.js';
2
2
  export type GradientRenderMode = 'runtime' | 'export' | 'literal';
3
3
  export declare function gradientStops(a: string, b: string, bias: GradientBias): string;
4
4
  export declare function swapGradientBias(bias: GradientBias): GradientBias;
5
- export declare function gradientCss(config: GradientConfig, mode?: GradientRenderMode, theme?: Theme): string;
5
+ /** @lang zh-CN 解析任意色阶引用为实际色值(`W-tb-P38` 导出为 DTCG 渐变 stops 所需,改公开)。 @lang en Resolves an arbitrary shade reference to its colour (exported for `W-tb-P38` DTCG gradient stops). */
6
+ export declare function resolveScaleColor(theme: Theme, family: GradientFamily, shade: ShadeValue): string;
7
+ export declare function gradientCss(config: GradientConfig, mode?: GradientRenderMode, theme?: Theme, underlay?: boolean): string;
6
8
  export declare function gradientDominantColor(config: GradientConfig, theme: Theme): string;
7
9
  export declare function collectCustomShades(theme: Theme): {
8
10
  primary: Record<string, string>;
@@ -1,6 +1,7 @@
1
1
  import { bestOnColor } from '../color/contrast.js';
2
2
  import { tonalScaleAt } from '../color/scale.js';
3
3
  import { typographySpacingVars } from '../token/typography.js';
4
+ import { radiusSequence, shadowCss } from '../token/radius.js';
4
5
  import { clamp } from '../color/convert.js';
5
6
  import { GRADIENT_DEFS } from '../data/gradients.js';
6
7
  // 占比合法性:^(front|end)\d{1,3}$ 且数值 0-100(ADR-004 数值化)。
@@ -31,7 +32,8 @@ export function swapGradientBias(bias) {
31
32
  // 解析任意色阶引用为实际色值(ADR-004):标准 10 档查 scale 表;自定义值 tonalScaleAt 插值。
32
33
  // <lang zh-CN>theme[family].value 为基色 HEX;非法数字回退 500 档(基色本色)。</lang>
33
34
  // <lang en>theme[family].value is the base HEX; invalid numbers fall back to step 500 (the base).</lang>
34
- function resolveScaleColor(theme, family, shade) {
35
+ /** @lang zh-CN 解析任意色阶引用为实际色值(`W-tb-P38` 导出为 DTCG 渐变 stops 所需,改公开)。 @lang en Resolves an arbitrary shade reference to its colour (exported for `W-tb-P38` DTCG gradient stops). */
36
+ export function resolveScaleColor(theme, family, shade) {
35
37
  // 色族解析:主/副走角色表;third 走第三角色;aux<N> 走对应辅助槽位(ADR-007 v2)。
36
38
  // <lang zh-CN>third/aux 槽位缺失(模式不匹配/槽位未加)时回退主色 500,保证渲染不断。</lang>
37
39
  // <lang en>Missing third/aux slots fall back to primary 500 so rendering never breaks.</lang>
@@ -68,14 +70,29 @@ function tokenFor(config, shade, mode, theme) {
68
70
  return resolveScaleColor(theme, config.family, shade);
69
71
  }
70
72
  // 生成单条渐变的 CSS:禁用时退化为纯色(起始色),否则输出 linear-gradient。
71
- // <lang zh-CN>默认 runtime 模式;mode/literal 决定是否内联色值。</lang>
72
- // <lang en>Defaults to runtime; mode/literal decide whether colors are inlined.</lang>
73
- export function gradientCss(config, mode = 'runtime', theme) {
73
+ // <lang zh-CN>默认 runtime 模式;mode/literal 决定是否内联色值。
74
+ // **降级链(`W-tb-P37`)**:启用态在渐变层下追加起始色纯色垫底(多层背景,渐变在上)——
75
+ // 渐变含半透明色标时不会露出容器底色;消费方需完全的解析级降级时应另行双声明
76
+ // (background-color 先行,background-image 后行,见 inject-template)。
77
+ // underlay=false 供不容许多层背景的消费方(WordPress 渐变预设解析器)关闭。
78
+ // </lang>
79
+ // <lang en>Defaults to runtime; mode/literal decide whether colors are inlined.
80
+ // **Degradation chain (`W-tb-P37`)**: when enabled, a solid start-colour underlay is appended beneath the
81
+ // gradient layer (multi-layer background, gradient on top) so translucent stops never expose the container.
82
+ // Consumers needing parse-level fallback should emit two declarations (background-color first, then
83
+ // background-image — see inject-template). underlay=false for consumers that cannot take multi-layer
84
+ // backgrounds (the WordPress gradient preset parser).</lang>
85
+ export function gradientCss(config, mode = 'runtime', theme, underlay = true) {
74
86
  const start = tokenFor(config, config.start, mode, theme), end = tokenFor(config, config.end, mode, theme);
75
87
  // 禁用则直接返回起始色,等效纯背景。
76
88
  // <lang zh-CN>让调用方无需区分“未启用”与“启用”。</lang>
77
89
  // <lang en>Lets callers treat disabled uniformly as a solid background.</lang>
78
- return config.enabled === false ? start : `linear-gradient(${config.direction}, ${gradientStops(start, end, config.bias)})`;
90
+ if (config.enabled === false)
91
+ return start;
92
+ const gradient = `linear-gradient(${config.direction}, ${gradientStops(start, end, config.bias)})`;
93
+ // 纯色垫底与起始色同源:降级时呈现"起始色平铺"的合理近似。
94
+ // <lang en>The underlay mirrors the start colour: degradation degrades to a sensible flat start colour.</lang>
95
+ return underlay ? `${gradient}, ${start}` : gradient;
79
96
  }
80
97
  // 取渐变“主色”用于决定前景色:end 占比时取结束色阶,否则取起始色阶。
81
98
  // <lang zh-CN>主色阶决定该卡片上文字该用白还是深,影响可读性;任意色阶经 resolveScaleColor 插值。</lang>
@@ -151,6 +168,28 @@ export function createRuntimeCssVariables(theme) {
151
168
  // <lang zh-CN>追加入 :root 内联变量集合。</lang>
152
169
  // <lang en>Merged into the :root inline var set.</lang>
153
170
  Object.assign(vars, typographySpacingVars(theme));
171
+ // 语义状态色变量(`W-tb-P37`/ADR-012):主题携带时写入 --success/-info/-warning/-danger 及 500/700 阶,
172
+ // 供预览(状态卡/按钮)消费;未携带的主题不写入(旧形态不变)。
173
+ // <lang en>Semantic status vars (`W-tb-P37`/ADR-012): emitted when carried for preview consumption; absent
174
+ // groups keep the legacy shape.</lang>
175
+ if (theme.semantic) {
176
+ for (const [k, role] of Object.entries(theme.semantic)) {
177
+ vars[`--${k}`] = role.value;
178
+ vars[`--on-${k}`] = role.on;
179
+ vars[`--${k}-500`] = role.scale['500'] ?? role.value;
180
+ vars[`--${k}-100`] = role.scale['100'] ?? role.value;
181
+ }
182
+ }
183
+ // 圆角/阴影变量(`W-tb-P37`):--radius-* / --shadow-*,供预览与导出统一消费。
184
+ // <lang en>Radius/shadow vars (`W-tb-P37`): --radius-* / --shadow-* consumed by preview and exports.</lang>
185
+ const radius = radiusSequence(theme.radius);
186
+ for (const [k, v] of Object.entries(radius))
187
+ vars[`--radius-${k}`] = `${v}px`;
188
+ // 阴影固定三档:sm/md/lg 键集稳定,避免 Object.entries 的隐式 any。
189
+ // <lang en>Shadow levels are the stable sm/md/lg set, avoiding implicit-any from Object.entries.</lang>
190
+ const shadows = shadowCss(theme.shadow, theme.primary.value);
191
+ for (const k of ['sm', 'md', 'lg'])
192
+ vars[`--shadow-${k}`] = shadows[k];
154
193
  // 自定义色阶变量:按渐变引用去重生成 --p650 / --s650 等附加变量(ADR-004)。
155
194
  // <lang zh-CN>与标准 10 档同名规则,tokenFor 的 var() 引用无需区分。</lang>
156
195
  // <lang en>Same naming as the standard steps, so tokenFor's var() references need no branching.</lang>
package/dist/index.d.ts CHANGED
@@ -14,13 +14,23 @@ export { SERIES_RELATION_DEFS, getSeriesRelationDef, deriveSecondaryByRelation,
14
14
  export { nameColor, modifierFor, hueNameFor, MODIFIER_NAMES, HUE_NAMES } from './color/color-name.js';
15
15
  export type { ColorModifier, HueName } from './color/color-name.js';
16
16
  export type { SeriesRelationDef } from './color/harmony.js';
17
- export { luminance, contrast, bestOnColor } from './color/contrast.js';
17
+ export { luminance, contrast, bestOnColor, contrastMatrix, stepForContrast } from './color/contrast.js';
18
+ export type { MatrixEntry, ContrastMatrixResult, StepForContrastResult } from './color/contrast.js';
19
+ export { apcaLc, apcaY } from './color/apca.js';
20
+ export { simulateCvd, MACHADO_2009_SEV1, CVD_LABELS } from './color/vision.js';
21
+ export type { CvdType } from './color/vision.js';
18
22
  export { primaryCandidates } from './data/primaryCandidates.js';
19
23
  export { builtinPresets } from './data/presets.js';
20
24
  export { GRADIENT_DEFS, GRADIENT_DEFAULTS, cloneGradientSettings } from './data/gradients.js';
21
25
  export { BAODIAN_PALETTE, FORM_PACKS, BAODIAN_FORM_NAMES } from './data/palette-packs.js';
22
26
  export type { BaodianCombo } from './data/palette-packs.js';
23
27
  export { tonePresets, buildTonePreset, TONE_MOODS, TONE_FORM_PRIORITY, TONE_DEFAULT_PRIORITY, TONE_AUX_SLOTS } from './data/tone-presets.js';
28
+ export { deriveSemanticTokens, cloneSemanticTokens, isSemanticDerived, SEMANTIC_HUES, SEMANTIC_NAMES } from './color/semantic.js';
29
+ export type { SemanticStatusKey } from './types.js';
30
+ export { extractImagePalette, downsamplePixels, suggestGradientDirection, IMAGE_EXTRACT_MAX_DIM, IMAGE_EXTRACT_CLUSTERS } from './color/image-extract.js';
31
+ export type { ImagePixels, ImageCandidate, ImageExtractResult, ImageExtractMode } from './color/image-extract.js';
32
+ export { radiusSequence, shadowCss, cloneRadiusTokens, cloneShadowTokens, RADIUS_DEFAULTS, SHADOW_DEFAULTS } from './token/radius.js';
33
+ export type { RadiusStep, ShadowLevel } from './token/radius.js';
24
34
  export { MOOD_PRIMARY_COLORS, moodPrimaryColorFor } from './data/mood-primary-colors.js';
25
35
  export type { MoodPrimaryColor } from './data/mood-primary-colors.js';
26
36
  export { TRADITIONAL_COLORS } from './data/traditional-colors.js';
@@ -48,6 +58,11 @@ export type { VirtualFile, ExportTarget, ExportAdapterOptions } from './export/t
48
58
  export { EXPORT_TARGETS, getExportTarget, listExportTargets } from './export/registry.js';
49
59
  export { wordpressChildTarget } from './export/wordpress.js';
50
60
  export { tailwindConfigTarget } from './export/tailwind.js';
61
+ export { tailwindV4Target } from './export/tailwind4.js';
62
+ export { dtcgExportTarget, exportDtcgTokens, parseDtcgTokens } from './export/dtcg.js';
63
+ export { textmateTheme, vscodeTheme, vimTheme, emacsTheme, EDITOR_THEME_GENERATORS, findEditorThemeGenerator } from './export/editor-themes.js';
64
+ export type { EditorAppearance } from './export/editor-themes.js';
65
+ export type { DtcgIssue, DtcgIssueCode, DtcgParseResult } from './export/dtcg.js';
51
66
  export { injectTemplateTarget } from './export/inject-template.js';
52
67
  export { analyzeTheme } from './analyze/analyze.js';
53
68
  export type { ExtractSignals, ScoredColor, ExtractResult, CssVarSignal, DomColorSignal, ScreenshotColorSignal } from './analyze/types.js';
package/dist/index.js CHANGED
@@ -22,10 +22,20 @@ export { HARMONY_DEFS, harmonyCandidate, generateSecondarySet } from './color/ha
22
22
  // <lang en>Pure generator shared by Theme assembly and UI regeneration.</lang>
23
23
  export { SERIES_RELATION_DEFS, getSeriesRelationDef, deriveSecondaryByRelation, deriveThirdByRelation, generateAuxiliaryCandidates, shiftHueTo, anchorComboMembers } from './color/harmony.js';
24
24
  export { nameColor, modifierFor, hueNameFor, MODIFIER_NAMES, HUE_NAMES } from './color/color-name.js';
25
- // 对比度与最佳前景色选择(WCAG 相对亮度)。
26
- // <lang zh-CN>用于自动决定角色色上的文字用白还是深色。</lang>
27
- // <lang en>Decides white vs dark foreground on a role color via WCAG relative luminance.</lang>
28
- export { luminance, contrast, bestOnColor } from './color/contrast.js';
25
+ // 对比度与最佳前景色选择(WCAG 相对亮度);`W-tb-P36` 增补矩阵与目标生成。
26
+ // <lang zh-CN>用于自动决定角色色上的文字用白还是深色;contrastMatrix 供全调色板逐对校验,
27
+ // stepForContrast 以目标比值反推色值(Leonardo 式),与锚定推导互补。</lang>
28
+ // <lang en>Decides white vs dark foreground on a role color via WCAG relative luminance; `W-tb-P36` adds the
29
+ // matrix and target-driven synthesis. contrastMatrix serves palette-wide pairwise checks; stepForContrast
30
+ // synthesizes a colour for a target ratio (Leonardo-style), complementing anchored derivation.</lang>
31
+ export { luminance, contrast, bestOnColor, contrastMatrix, stepForContrast } from './color/contrast.js';
32
+ // APCA Lc 副指标(`W-tb-P36`):仅作参考值展示,非合规判定——WCAG 3 尚未定案。
33
+ // <lang en>APCA Lc secondary metric (`W-tb-P36`): reference readout only, never a compliance verdict — WCAG 3
34
+ // is still undecided.</lang>
35
+ export { apcaLc, apcaY } from './color/apca.js';
36
+ // 色觉缺陷模拟(`W-tb-P36`):Machado 2009 三主型,线性空间应用矩阵。
37
+ // <lang en>CVD simulation (`W-tb-P36`): Machado 2009 three main types, matrices applied in linear space.</lang>
38
+ export { simulateCvd, MACHADO_2009_SEV1, CVD_LABELS } from './color/vision.js';
29
39
  // 数据:主色候选库、内置预设、渐变定义与默认配置。
30
40
  // <lang zh-CN>候选库与预设为静态数据;GRADIENT_* 为渐变角色契约与默认值。</lang>
31
41
  // <lang en>Static data: primary candidates and built-in presets; GRADIENT_* are gradient role contracts and defaults.</lang>
@@ -37,6 +47,18 @@ export { GRADIENT_DEFS, GRADIENT_DEFAULTS, cloneGradientSettings } from './data/
37
47
  // <lang en>Auto-extracted from the Peise Baodian CHM source; backs the relation-rule preset dropdown.</lang>
38
48
  export { BAODIAN_PALETTE, FORM_PACKS, BAODIAN_FORM_NAMES } from './data/palette-packs.js';
39
49
  export { tonePresets, buildTonePreset, TONE_MOODS, TONE_FORM_PRIORITY, TONE_DEFAULT_PRIORITY, TONE_AUX_SLOTS } from './data/tone-presets.js';
50
+ // 语义状态色派生(`W-tb-P37`,ADR-012):success/info/warning/danger 四组完整 RoleColor。
51
+ // 色相按语义固定,明暗/彩度特征随主色;派生是预填值,用户可覆盖(isSemanticDerived)。
52
+ // <lang en>Semantic status derivation (`W-tb-P37`, ADR-012): four full RoleColors with fixed semantic hues and
53
+ // primary-inherited lightness/chroma; derived values are prefills users may override.</lang>
54
+ export { deriveSemanticTokens, cloneSemanticTokens, isSemanticDerived, SEMANTIC_HUES, SEMANTIC_NAMES } from './color/semantic.js';
55
+ // 图片提色(`W-tb-P39`,ADR-014):确定性中位切分提取主/副/渐变候选——纯计算无 IO。
56
+ // <lang en>Image colour extraction (`W-tb-P39`, ADR-014): deterministic median-cut extraction of primary,
57
+ // secondary and gradient candidates — pure computation, no IO.</lang>
58
+ export { extractImagePalette, downsamplePixels, suggestGradientDirection, IMAGE_EXTRACT_MAX_DIM, IMAGE_EXTRACT_CLUSTERS } from './color/image-extract.js';
59
+ // 圆角/阴影令牌(`W-tb-P37`,ADR-006 契约位落地):档位派生纯函数。
60
+ // <lang en>Radius/shadow tokens (`W-tb-P37`, ADR-006 slot landed): pure derivation functions.</lang>
61
+ export { radiusSequence, shadowCss, cloneRadiusTokens, cloneShadowTokens, RADIUS_DEFAULTS, SHADOW_DEFAULTS } from './token/radius.js';
40
62
  // 情感主色:**独立数据集**(维护者校正后重做),自带色值,不与主色候选库关联。
41
63
  // 早前版本曾把情感映射到 44 主色候选(首色频次 + OKLab 最近邻),结果语义错乱,
42
64
  // 根因是串了数据源——候选库讲"网站/流行色",与情感语义无关。此表已与候选库完全解耦。
@@ -70,6 +92,9 @@ export { exportThemeJson } from './token/json.js';
70
92
  export { EXPORT_TARGETS, getExportTarget, listExportTargets } from './export/registry.js';
71
93
  export { wordpressChildTarget } from './export/wordpress.js';
72
94
  export { tailwindConfigTarget } from './export/tailwind.js';
95
+ export { tailwindV4Target } from './export/tailwind4.js';
96
+ export { dtcgExportTarget, exportDtcgTokens, parseDtcgTokens } from './export/dtcg.js';
97
+ export { textmateTheme, vscodeTheme, vimTheme, emacsTheme, EDITOR_THEME_GENERATORS, findEditorThemeGenerator } from './export/editor-themes.js';
73
98
  export { injectTemplateTarget } from './export/inject-template.js';
74
99
  export { analyzeTheme } from './analyze/analyze.js';
75
100
  export { toV2Signals } from './analyze/v1-compat.js';
package/dist/studio.js CHANGED
@@ -57,19 +57,19 @@ export function createThemeDraft(value = {}) {
57
57
  // <lang zh-CN>载入操作台时使用,gradients 缺失则回落默认。</lang>
58
58
  // <lang en>Used when loading into the studio; falls back to defaults when gradients are absent.</lang>
59
59
  export function draftFromPreset(preset) {
60
- return createThemeDraft({ id: preset.id, name: preset.name, category: preset.category, industry: preset.industry, primary: preset.primary, secondary: preset.secondary, primaryName: preset.primaryName, secondaryName: preset.secondaryName, note: preset.note, gradients: preset.gradients, seriesMode: preset.seriesMode, seriesRelation: preset.seriesRelation, thirdColor: preset.thirdColor, auxiliary: preset.auxiliary });
60
+ return createThemeDraft({ id: preset.id, name: preset.name, category: preset.category, industry: preset.industry, primary: preset.primary, secondary: preset.secondary, primaryName: preset.primaryName, secondaryName: preset.secondaryName, note: preset.note, gradients: preset.gradients, seriesMode: preset.seriesMode, seriesRelation: preset.seriesRelation, thirdColor: preset.thirdColor, auxiliary: preset.auxiliary, radius: preset.radius, shadow: preset.shadow, semantic: preset.semantic, semanticDerived: preset.semanticDerived });
61
61
  }
62
62
  // 将草稿构建为完整主题,名称缺省时按主副色名自动生成。
63
63
  // <lang zh-CN>草稿到渲染/导出的桥梁,所有色阶在此计算;typography/spacing 随草稿透传(ADR-006)。</lang>
64
64
  // <lang en>Bridge from draft to render/export; all scales are computed here; typography/spacing pass through (ADR-006).</lang>
65
65
  export function buildThemeFromDraft(draft) {
66
- return buildTheme({ name: draft.name || autoThemeName(draft.primaryName, draft.secondaryName), category: draft.category, industry: draft.industry, primary: draft.primary, secondary: draft.secondary, primaryName: draft.primaryName, secondaryName: draft.secondaryName, note: draft.note, gradients: draft.gradients, typography: draft.typography, spacing: draft.spacing, seriesMode: draft.seriesMode, seriesRelation: draft.seriesRelation, thirdColor: draft.thirdColor, auxiliary: draft.auxiliary, auxiliaryModifiers: draft.auxiliaryModifiers });
66
+ return buildTheme({ name: draft.name || autoThemeName(draft.primaryName, draft.secondaryName), category: draft.category, industry: draft.industry, primary: draft.primary, secondary: draft.secondary, primaryName: draft.primaryName, secondaryName: draft.secondaryName, note: draft.note, gradients: draft.gradients, typography: draft.typography, spacing: draft.spacing, seriesMode: draft.seriesMode, seriesRelation: draft.seriesRelation, thirdColor: draft.thirdColor, auxiliary: draft.auxiliary, auxiliaryModifiers: draft.auxiliaryModifiers, radius: draft.radius, shadow: draft.shadow, semantic: draft.semantic });
67
67
  }
68
68
  // 由草稿导出为可保存预设,id 缺失时以时间戳生成自定义 id。
69
69
  // <lang zh-CN>保存/导出时使用,基色再次规范化确保持久化一致。</lang>
70
70
  // <lang en>Used for save/export; base colors are re-normalized for consistent persistence.</lang>
71
71
  export function presetFromDraft(draft, id = `custom-${Date.now()}`) {
72
- return { id, name: draft.name || autoThemeName(draft.primaryName, draft.secondaryName), category: draft.category || 'custom', industry: draft.industry || '', primary: normalizeHex(draft.primary), secondary: normalizeHex(draft.secondary), primaryName: draft.primaryName || nameColor(draft.primary).zh, secondaryName: draft.secondaryName || nameColor(draft.secondary).zh, note: draft.note || '由主副色操作台生成导入。', gradients: cloneGradientSettings(draft.gradients), ...(draft.seriesMode && draft.seriesMode !== 'dual' ? { seriesMode: draft.seriesMode } : {}), ...(draft.seriesRelation && draft.seriesRelation !== 'manual' ? { seriesRelation: draft.seriesRelation } : {}), ...(draft.thirdColor ? { thirdColor: { ...draft.thirdColor, scale: { ...draft.thirdColor.scale } } } : {}), ...(draft.auxiliary?.length ? { auxiliary: draft.auxiliary.map(a => ({ ...a, scale: { ...a.scale } })) } : {}) };
72
+ return { id, name: draft.name || autoThemeName(draft.primaryName, draft.secondaryName), category: draft.category || 'custom', industry: draft.industry || '', primary: normalizeHex(draft.primary), secondary: normalizeHex(draft.secondary), primaryName: draft.primaryName || nameColor(draft.primary).zh, secondaryName: draft.secondaryName || nameColor(draft.secondary).zh, note: draft.note || '由主副色操作台生成导入。', gradients: cloneGradientSettings(draft.gradients), ...(draft.seriesMode && draft.seriesMode !== 'dual' ? { seriesMode: draft.seriesMode } : {}), ...(draft.seriesRelation && draft.seriesRelation !== 'manual' ? { seriesRelation: draft.seriesRelation } : {}), ...(draft.thirdColor ? { thirdColor: { ...draft.thirdColor, scale: { ...draft.thirdColor.scale } } } : {}), ...(draft.auxiliary?.length ? { auxiliary: draft.auxiliary.map(a => ({ ...a, scale: { ...a.scale } })) } : {}), ...(draft.radius ? { radius: draft.radius } : {}), ...(draft.shadow ? { shadow: draft.shadow } : {}), ...(draft.semantic ? { semantic: draft.semantic } : {}), ...(draft.semanticDerived ? { semanticDerived: draft.semanticDerived } : {}) };
73
73
  }
74
74
  // 在候选库中按主副色同时匹配出对应候选(用于回显“当前主色”来源)。
75
75
  // <lang zh-CN>仅当主色与推荐副色都一致才命中,避免近似色误判。</lang>
package/dist/theme.js CHANGED
@@ -13,6 +13,8 @@ export function cloneTypography(t) { const r = { fontFamily: { ...t.fontFamily }
13
13
  export function cloneSpacing(s) { const r = { ...s }; if (s.overrides)
14
14
  r.overrides = { ...s.overrides }; return r; }
15
15
  import { bestOnColor } from './color/contrast.js';
16
+ import { cloneRadiusTokens, cloneShadowTokens } from './token/radius.js';
17
+ import { cloneSemanticTokens } from './color/semantic.js';
16
18
  import { normalizeHex } from './color/convert.js';
17
19
  import { tonalScale } from './color/scale.js';
18
20
  import { cloneGradientSettings } from './data/gradients.js';
@@ -104,7 +106,16 @@ export function buildTheme(input) {
104
106
  seriesMode,
105
107
  seriesRelation,
106
108
  ...(thirdColor ? { thirdColor } : {}),
107
- auxiliary
109
+ auxiliary,
110
+ // 圆角/阴影(`W-tb-P37`,ADR-006 契约位落地):可选入参,缺省回退默认档——旧调用点不受影响。
111
+ // <lang en>Radius/shadow (`W-tb-P37`, ADR-006 slot landed): optional inputs defaulting back — legacy call
112
+ // sites unaffected.</lang>
113
+ radius: cloneRadiusTokens(input.radius),
114
+ shadow: cloneShadowTokens(input.shadow),
115
+ // 语义状态色(ADR-012):仅透传显式提供的组;**不静默派生**——旧主题观感不因升级改变(决策 6)。
116
+ // <lang en>Semantic tokens (ADR-012): only pass through explicit groups; **no silent derivation** — old
117
+ // themes must not change appearance on upgrade (decision 6).</lang>
118
+ ...(input.semantic ? { semantic: cloneSemanticTokens(input.semantic) } : {})
108
119
  };
109
120
  }
110
121
  //# sourceMappingURL=theme.js.map