| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // 票 15 取证(四):主画板(Desktop-6,总体概览/首页)单独色板与文字层级
- import { readFileSync } from 'node:fs'
- const dir = '.scratch/lanhu-cockpit-asset-replacement/research/raw-v2'
- const hex = (c) => `#${[c.r, c.g, c.b].map((v) => Math.round(v * 255).toString(16).padStart(2, '0')).join('')}`
- const alpha = (c) => (c.a === undefined || c.a > 0.999 ? '' : `@${c.a.toFixed(2)}`)
- for (const n of [6, 2]) {
- const ab = JSON.parse(readFileSync(`${dir}/desktop-${String(n).padStart(2, '0')}.json`, 'utf8')).artboard
- const fills = new Map()
- const textColors = new Map()
- const sizes = new Map()
- ;(function walk(node, path = '') {
- const p = path ? `${path}/${node.name}` : node.name
- for (const f of node.style?.fills || []) {
- if (f.type === 'color') {
- const k = hex(f.color) + alpha(f.color)
- const cur = fills.get(k) || { c: 0, sample: '' }
- cur.c += 1
- if (!cur.sample) cur.sample = p
- fills.set(k, cur)
- }
- }
- if (node.type === 'textLayer' && node.text?.style) {
- const c = node.text.style.color
- const f = node.text.style.font
- if (c) {
- const k = `${f?.size}px ${hex(c)}${alpha(c)}`
- const cur = textColors.get(k) || { c: 0, sample: '' }
- cur.c += 1
- if (!cur.sample) cur.sample = String(node.text.style.content || '').slice(0, 14)
- textColors.set(k, cur)
- }
- if (f?.name) sizes.set(`${f.name} ${f.size}px w${f.fontWeight}`, (sizes.get(`${f.name} ${f.size}px w${f.fontWeight}`) || 0) + 1)
- }
- for (const ch of node.layers || []) walk(ch, p)
- })(ab, '')
- console.log(`\n########## ${ab.name} ${ab.frame.width}x${ab.frame.height}`)
- console.log('--- 填充色 Top 20')
- console.log([...fills.entries()].sort((a, b) => b[1].c - a[1].c).slice(0, 20).map(([k, v]) => `${k} ×${v.c} ${v.sample}`).join('\n'))
- console.log('--- 文字色 Top 15')
- console.log([...textColors.entries()].sort((a, b) => b[1].c - a[1].c).slice(0, 15).map(([k, v]) => `${k} ×${v.c} 例:${v.sample}`).join('\n'))
- console.log('--- 字体/字号 Top 15')
- console.log([...sizes.entries()].sort((a, b) => b[1] - a[1]).slice(0, 15).map(([k, v]) => `${k} ×${v}`).join('\n'))
- }
|