probe-v2-kpi.mjs 1.4 KB

123456789101112131415161718192021222324252627282930
  1. // 定位新版图标图层的实际设计尺寸(PNG 为 2x)
  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 dump(node, depth = 0, maxDepth = 5, path = '') {
  5. const p = path ? `${path}/${node.name}` : node.name
  6. const pad = ' '.repeat(depth)
  7. const text = node.type === 'textLayer' && node.text?.style?.content ? ` "${String(node.text.style.content).slice(0, 12)}"` : ''
  8. const exp = node.hasExportImage ? ' [EXPORT]' : ''
  9. const img = (node.style?.fills || []).some((f) => f.type === 'image') ? ' [IMG]' : ''
  10. console.log(`${pad}${node.type}:${node.name} ${node.frame?.width}x${node.frame?.height}${text}${exp}${img}`)
  11. if (depth < maxDepth) for (const ch of node.layers || []) dump(ch, depth + 1, maxDepth, p)
  12. }
  13. function findByName(node, name, path = '') {
  14. const p = path ? `${path}/${node.name}` : node.name
  15. if (node.name === name) return { node, path: p }
  16. for (const ch of node.layers || []) {
  17. const r = findByName(ch, name, p)
  18. if (r) return r
  19. }
  20. return null
  21. }
  22. for (const g of ['Group 5054', 'Group 5061', 'Group 5056']) {
  23. const r = findByName(j.artboard, g)
  24. console.log(`\n=== ${g}${r ? ` @ ${r.path}` : ' (not found)'}`)
  25. if (r) dump(r.node, 0, 3, r.path.split('/').slice(0, -1).join('/'))
  26. }