iter(g243): 文档站与演示页外壳配色改为从令牌派生,消除暗色强调色漂移

This commit is contained in:
HIsheR
2026-10-26 21:55:27 +08:00
parent aa27a16912
commit f396a5545c
4 changed files with 43 additions and 7 deletions
+7 -3
View File
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url';
import { spawnSync } from 'node:child_process';
import { visualAudit } from '../lib/visual-audit.mjs';
import { auditContrast, formatReport, PAIRS } from '../lib/contrast-audit.mjs';
import { shellPalette } from '../lib/shell-palette.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -328,6 +329,9 @@ function renderDocs(index, tokens) {
const data = JSON.stringify(index.packages).replace(/</g, '\\u003c');
const tokData = JSON.stringify(tokens).replace(/</g, '\\u003c');
const generatedAt = esc(index.generatedAt);
// 文档站外壳配色从 tokens.json 派生:手写十六进制会跟令牌脱节(改暗色 accent 后这里还留着旧值,
// 页面与演示 iframe 两个蓝各显示一种),派生后单一来源,改令牌即全站跟随。
const shell = shellPalette(tokens);
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -335,9 +339,9 @@ function renderDocs(index, tokens) {
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@ui-arch 组件库文档</title>
<style>
:root{--bg:#ffffff;--surface:#f6f7f9;--text:#1c1e21;--muted:#6b7280;--border:rgba(0,0,0,.14);--accent:#185fa5;--code-bg:#101216;--code-text:#e7e9ec}
@media (prefers-color-scheme:dark){:root:not([data-theme=light]){--bg:#101216;--surface:#1a1c22;--text:#e7e9ec;--muted:#888780;--border:rgba(255,255,255,.15);--accent:#378add}}
:root[data-theme=dark]{--bg:#101216;--surface:#1a1c22;--text:#e7e9ec;--muted:#888780;--border:rgba(255,255,255,.15);--accent:#378add}
:root{--bg:${shell.bg};--surface:${shell.surface};--text:${shell.text};--muted:${shell.muted};--border:${shell.border};--accent:${shell.accent};--code-bg:${shell.codeBg};--code-text:${shell.codeText}}
@media (prefers-color-scheme:dark){:root:not([data-theme=light]){--bg:${shell.darkBg};--surface:${shell.darkSurface};--text:${shell.darkText};--muted:${shell.darkMuted};--border:${shell.darkBorder};--accent:${shell.darkAccent}}}
:root[data-theme=dark]{--bg:${shell.darkBg};--surface:${shell.darkSurface};--text:${shell.darkText};--muted:${shell.darkMuted};--border:${shell.darkBorder};--accent:${shell.darkAccent}}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.65 -apple-system,"Segoe UI","Microsoft YaHei",sans-serif}
header{position:sticky;top:0;z-index:2;display:flex;gap:16px;align-items:center;flex-wrap:wrap;padding:14px 24px;background:var(--bg);border-bottom:1px solid var(--border)}
+28
View File
@@ -0,0 +1,28 @@
/*** @ui-arch 外壳配色:文档站与演示页的外层 chrome 用色,统一从 tokens.json 派生
*
* 为什么单独成文件:这两处都曾手写十六进制,改暗色 accent 后页面里还留着旧蓝、与演示 iframe 各显示一种色。
* 放在 lib 里给 bin/ua.js(生成文档站)与 apps/demo/build.mjs(生成演示页)共用,才是真正的单一来源;
* 缺键时退回内置默认,保证 tokens.json 缺失时构建不炸(宁可配色旧一点也不中断发布)。
*/
/*** 作用:取出亮暗两套外壳配色;tokens 为解析后的 tokens.json,可为 null ***/
export function shellPalette(tokens) {
const color = (tokens && tokens.color) || {};
const pick = (key, theme, fallback) => (color[key] && color[key][theme]) || fallback;
return {
bg: pick('bg', 'light', '#ffffff'),
surface: pick('surface', 'light', '#f6f7f9'),
text: pick('text', 'light', '#1c1e21'),
muted: pick('textMuted', 'light', '#676d78'),
border: pick('border', 'light', 'rgba(0, 0, 0, 0.15)'),
accent: pick('accent', 'light', '#185fa5'),
codeBg: pick('bg', 'dark', '#101216'),
codeText: pick('text', 'dark', '#e7e9ec'),
darkBg: pick('bg', 'dark', '#101216'),
darkSurface: pick('surface', 'dark', '#1a1c22'),
darkText: pick('text', 'dark', '#e7e9ec'),
darkMuted: pick('textMuted', 'dark', '#888780'),
darkBorder: pick('border', 'dark', 'rgba(255, 255, 255, 0.15)'),
darkAccent: pick('accent', 'dark', '#4a9aeb'),
};
}