| 12345678910111213141516171819202122232425262728293031323334 |
- // 探查新版:顶栏 nav 与中央一张图 chip 的结构,找品牌图标与图层图标
- import { readFileSync } from 'node:fs'
- const j = JSON.parse(readFileSync('.scratch/lanhu-cockpit-asset-replacement/research/raw-v2/desktop-02.json', 'utf8'))
- function find(node, pred, path = '', out = []) {
- const p = path ? `${path}/${node.name}` : node.name
- if (pred(node, p)) out.push({ node, path: p })
- for (const ch of node.layers || []) find(ch, pred, p, out)
- return out
- }
- function dump(node, depth = 0, maxDepth = 4) {
- const pad = ' '.repeat(depth)
- const text = node.type === 'textLayer' && node.text?.style?.content ? ` "${String(node.text.style.content).slice(0, 16)}"` : ''
- const exp = node.hasExportImage ? ' [EXPORT]' : ''
- console.log(`${pad}${node.type}:${node.name} ${Math.round(node.frame?.width ?? 0)}x${Math.round(node.frame?.height ?? 0)}${text}${exp}`)
- if (depth < maxDepth) for (const ch of node.layers || []) dump(ch, depth + 1, maxDepth)
- }
- console.log('=== nav 子树')
- for (const { node } of find(j.artboard, (n, p) => p === 'nav' || p.startsWith('nav/') && p.split('/').length <= 2)) {
- if (node.name === 'nav') dump(node, 0, 3)
- }
- console.log('\n=== CentralMap/Chip 子树(第一个)')
- const chips = find(j.artboard, (n, p) => /CentralMap\/Chip/.test(p) && p.split('/').length === 3)
- console.log('chip count:', chips.length)
- for (const c of chips.slice(0, 2)) dump(c.node, 0, 3)
- console.log('\n=== 名称含 icon/logo/brand/mark 的图层')
- for (const { node, path } of find(j.artboard, (n, p) => /icon|logo|brand|mark/i.test(n.name))) {
- console.log(` ${node.type}:${node.name} ${Math.round(node.frame?.width ?? 0)}x${Math.round(node.frame?.height ?? 0)} | ${path}`)
- }
|