// 票 15 取证(五):面板/表头/chip 的样式唯一性核对(冲突判定用) import { readFileSync } from 'node:fs' const dir = '.scratch/lanhu-cockpit-asset-replacement/research/raw-v2' const boards = [2, 3, 4, 5, 6, 7, 8, 9, 10] 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)}`) const load = (n) => JSON.parse(readFileSync(`${dir}/desktop-${String(n).padStart(2, '0')}.json`, 'utf8')).artboard function fillSig(node) { return (node.style?.fills || []) .map((f) => { if (f.type === 'color') return `color:${hex(f.color)}${alpha(f.color)}` const g = f.gradient if (g?.stops) return `grad${g.type}:${g.stops.map((s) => `${hex(s.color)}${alpha(s.color)}@${Math.round((s.position || 0) * 100)}`).join('>')}` return f.type }) .join(' + ') } function borderSig(node) { return (node.style?.borders || []).map((b) => `${b.color ? hex(b.color) + alpha(b.color) : '-'} w${(b.width ?? 0).toFixed(2)}`).join(' + ') } const panels = new Map() const headers = new Map() const chips = new Map() const headings = new Map() const centralMaps = new Map() for (const n of boards) { const ab = load(n) ;(function walk(node, path = '') { const p = path ? `${path}/${node.name}` : node.name const key = `${node.type}:${node.name} ${Math.round(node.frame?.width ?? 0)}x${Math.round(node.frame?.height ?? 0)} | fills=${fillSig(node)} | borders=${borderSig(node)}` if (/^Panel$/i.test(node.name)) panels.set(key, (panels.get(key) || 0) + 1) if (/Header/i.test(node.name) && node.frame?.width >= 100) headers.set(key, (headers.get(key) || 0) + 1) if (/Chip/i.test(node.name)) chips.set(key, (chips.get(key) || 0) + 1) if (/Heading/i.test(node.name)) headings.set(key, (headings.get(key) || 0) + 1) if (/CentralMap/i.test(node.name)) centralMaps.set(key, (centralMaps.get(key) || 0) + 1) for (const c of node.layers || []) walk(c, p) })(ab, '') } function show(title, map, limit = 8) { console.log(`\n### ${title}(${map.size} 种形态)`) for (const [k, v] of [...map.entries()].sort((a, b) => b[1] - a[1]).slice(0, limit)) console.log(` ×${v} ${k}`) } show('Panel', panels, 10) show('Header(≥100宽)', headers, 10) show('Chip', chips, 6) show('Heading', headings, 6) show('CentralMap', centralMaps, 6)