| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // 票 15 实施:组件内主题色字面量 → var() 清退(批次 2 的机械替换层)
- // 规则:面板域内「有 token 槽位的色」全部改写;无槽位的装饰渐变/一次性色保留(规格 03 允许)。
- import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs'
- import { join, relative } from 'node:path'
- const root = 'src/modules/cockpit'
- const files = []
- ;(function walk(dir) {
- for (const e of readdirSync(dir)) {
- const p = join(dir, e)
- if (statSync(p).isDirectory()) walk(p)
- else if (/\.(vue|js|css)$/.test(e)) files.push(p)
- }
- })(root)
- // A. var() fallback 值同步为新值(token 名不变)
- const FALLBACK = [
- [/#ff4d5e/g, '#ff3b52'],
- [/#ffa63d/g, '#ffb020'],
- [/#4fd8ff/g, '#01abea'],
- [/#35e39a/g, '#27d17a'],
- [/#6d92ae/g, '#5680b0'],
- [/#e6f5ff/g, '#d7ecff'],
- [/#a8cbe2/g, '#88b7e8'],
- [/#1b93cf/g, '#009de9'],
- [/rgba\(12,\s*48,\s*86,\s*0\.58\)/g, 'rgba(2, 9, 27, 0.28)'],
- [/rgba\(3,\s*14,\s*28,\s*0\.9\)/g, 'rgba(0, 15, 52, 0.38)'],
- [/rgba\(58,\s*170,\s*226,\s*0\.3\)/g, 'rgba(1, 171, 234, 0.35)'],
- [/rgba\(96,\s*220,\s*255,\s*0\.85\)/g, '#01abea'],
- ]
- // B. 裸字面量 → var() 或设计稿同族色
- const BARE = [
- // 面板四角 SVG 描边(URL 编码):与 --panel-line-hi 同色
- [/%234fd8ff/g, '%2301abea'],
- // 标题/数值亮色 → --text(设计稿面板标题 #d7ecff;KPI 值随后单独提到 --text-strong)
- [/color:\s*#eaf9ff\b/g, 'color: var(--text)'],
- // 纯白强调 → --text-strong(新增槽位;设计稿选中态/KPI 数值 #ffffff)
- [/color:\s*#fff\b/g, 'color: var(--text-strong)'],
- [/color:\s*#ffffff\b/g, 'color: var(--text-strong)'],
- // 时钟亮色 → --text-strong;chip/状态钮正文蓝 → --text-2
- [/color:\s*#d7f1ff\b/g, 'color: var(--text-strong)'],
- [/color:\s*#9dc2d9\b/g, 'color: var(--text-2)'],
- [/color:\s*#b9d8e8\b/g, 'color: var(--text-2)'],
- // 一级模式未选中文字:设计稿 #00b8ff = --cyan-hi
- [/color:\s*#a9cde4\b/g, 'color: var(--cyan-hi)'],
- // 面板竖条渐变顶色 → --cyan-hi
- [/#b6f0ff/g, 'var(--cyan-hi)'],
- // 面板渐变中停 / 表头渐变基色 → 新面板 token
- [/rgba\(6,\s*24,\s*44,\s*0\.82\)/g, 'var(--panel-mid, rgba(0, 53, 156, 0.2))'],
- [/rgba\(24,\s*96,\s*152,\s*0\.55\)/g, 'var(--panel-mid, rgba(0, 53, 156, 0.2))'],
- [/rgba\(12,\s*52,\s*90,\s*0\.3\)/g, 'var(--panel-bot, rgba(0, 15, 52, 0.38))'],
- [/rgba\(34,\s*116,\s*176,\s*0\.6\)/g, 'rgba(1, 171, 234, 0.6)'],
- [/rgba\(16,\s*66,\s*110,\s*0\.34\)/g, 'rgba(0, 15, 52, 0.34)'],
- [/rgba\(90,\s*200,\s*255,\s*(0\.1|0\.14)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- // 主题色族 rgba(含装饰辉光):换到设计稿同族 RGB
- [/rgba\(58,\s*170,\s*226,\s*(0\.\d+)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- [/rgba\(79,\s*216,\s*255,\s*(0\.\d+)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- [/rgba\(96,\s*220,\s*255,\s*(0\.\d+)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- [/rgba\(130,\s*225,\s*255,\s*(0\.\d+)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- [/rgba\(120,\s*220,\s*255,\s*(0\.\d+)\)/g, (m, a) => `rgba(1, 171, 234, ${a})`],
- [/rgba\(140,\s*235,\s*255,\s*(0\.\d+)\)/g, (m, a) => `rgba(0, 184, 255, ${a})`],
- [/rgba\(255,\s*166,\s*61,\s*(0\.\d+)\)/g, (m, a) => `rgba(255, 176, 32, ${a})`],
- [/rgba\(255,\s*200,\s*130,\s*(0\.\d+)\)/g, (m, a) => `rgba(255, 176, 32, ${a})`],
- [/rgba\(255,\s*77,\s*94,\s*(0\.\d+)\)/g, (m, a) => `rgba(255, 59, 82, ${a})`],
- [/rgba\(109,\s*146,\s*174,\s*(0\.\d+)\)/g, (m, a) => `rgba(86, 128, 176, ${a})`],
- ]
- let total = 0
- const report = []
- for (const f of files) {
- const rel = relative('.', f)
- const src = readFileSync(f, 'utf8')
- let out = src
- let count = 0
- for (const [re, rep] of [...FALLBACK, ...BARE]) {
- out = out.replace(re, (m, ...args) => {
- count += 1
- return typeof rep === 'function' ? rep(m, ...args) : rep
- })
- }
- if (count) {
- writeFileSync(f, out)
- report.push(`${rel}: ${count}`)
- total += count
- }
- }
- console.log(report.join('\n'))
- console.log(`\n合计替换 ${total} 处`)
|