probe-v2-nav-chips.mjs 1.7 KB

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