| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // 只读盘点:新版(raw-v2,2026-10-12)9 画板的色板 / 字号 / 字体 / 间距候选
- // 用于票 15(批次 2 token 替换)的取值依据;不改任何业务代码。
- import { readFileSync, readdirSync } from 'node:fs'
- import { join } from 'node:path'
- const dir = '.scratch/lanhu-cockpit-asset-replacement/research/raw-v2'
- const files = readdirSync(dir).filter((f) => /^desktop-\d+\.json$/.test(f)).sort()
- function hex(c) {
- const h = (v) => Math.round(v * 255).toString(16).padStart(2, '0')
- return `#${h(c.r)}${h(c.g)}${h(c.b)}`
- }
- const colors = new Map() // key -> {count, boards:Set, sample:path}
- const colorAlpha = new Map()
- const fonts = new Map()
- const fontSizes = new Map()
- const strokes = new Map()
- function note(map, key, extra) {
- const cur = map.get(key) || { count: 0, boards: new Set(), sample: '' }
- cur.count += 1
- if (extra) {
- cur.boards.add(extra.board)
- if (!cur.sample) cur.sample = extra.path
- }
- map.set(key, cur)
- }
- for (const file of files) {
- const j = JSON.parse(readFileSync(join(dir, file), 'utf8'))
- const ab = j.artboard
- const board = ab.name
- ;(function walk(node, path = '') {
- const p = path ? `${path}/${node.name}` : node.name
- for (const f of node.style?.fills || []) {
- if (f.type === 'color' && f.color) {
- const c = hex(f.color)
- note(colors, c, { board, path: p })
- const a = f.color.a ?? 1
- if (a < 0.999) note(colorAlpha, `${c}@${a.toFixed(2)}`, { board, path: p })
- }
- }
- for (const s of node.style?.strokes || []) {
- if (s.type === 'color' && s.color) {
- note(strokes, hex(s.color), { board, path: p })
- }
- }
- if (node.type === 'textLayer' && node.text) {
- const f = node.text.style?.font
- if (f?.name) note(fonts, f.name, { board, path: p })
- if (f?.name && f?.size) note(fontSizes, `${f.name} | ${f.size}px`, { board, path: p })
- }
- for (const ch of node.layers || []) walk(ch, p)
- })(ab, '')
- }
- const fmt = (m, n) =>
- [...m.entries()]
- .sort((a, b) => b[1].count - a[1].count)
- .slice(0, n)
- .map(([k, v]) => `${k} ×${v.count} [${[...v.boards].join(',')}]`)
- console.log('=== 全稿色值 Top 45(新版 v3/v4)')
- console.log(fmt(colors, 45).join('\n'))
- console.log('\n=== 带透明度色值 Top 25')
- console.log(fmt(colorAlpha, 25).join('\n'))
- console.log('\n=== 描边色 Top 15')
- console.log(fmt(strokes, 15).join('\n'))
- console.log('\n=== 字体族')
- console.log(fmt(fonts, 30).join('\n'))
- console.log('\n=== 字号 Top 30')
- console.log(fmt(fontSizes, 30).join('\n'))
- console.log(`\n总色值种类 ${colors.size},总字号种类 ${fontSizes.size}`)
|