probe-icons.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // 探查 Chip 与 title 的子节点,确认图标是否为带路径的矢量
  2. import { readFileSync } from 'node:fs'
  3. const j = JSON.parse(readFileSync('.scratch/lanhu-cockpit-asset-replacement/research/raw/desktop-06.json', 'utf8'))
  4. const ab = j.artboard
  5. function find(node, want, path = '') {
  6. const p = path ? `${path}/${node.name}` : node.name
  7. if (node.name === want) return { node, path: p }
  8. for (const ch of node.layers || []) {
  9. const r = find(ch, want, p)
  10. if (r) return r
  11. }
  12. return null
  13. }
  14. function dump(node, depth = 0, path = '') {
  15. const p = path ? `${path}/${node.name}` : node.name
  16. const pad = ' '.repeat(depth)
  17. const paths = node.paths || []
  18. const fills = (node.style?.fills || []).map((f) => f.type).join('+')
  19. const shapeCount = paths.reduce((n, x) => n + (x.paths || x.subPaths || []).length, 0)
  20. console.log(`${pad}${node.type}:${node.name} ${Math.round(node.frame?.width ?? 0)}x${Math.round(node.frame?.height ?? 0)} paths=${paths.length} shapes=${shapeCount} fills=${fills} export=${!!node.hasExportImage}`)
  21. for (const ch of (node.layers || []).slice(0, 14)) dump(ch, depth + 1, p)
  22. }
  23. const chip = find(ab, 'Chip')
  24. const title = find(ab, 'title')
  25. if (chip) {
  26. console.log('=== Chip node:', chip.path)
  27. dump(chip.node)
  28. }
  29. if (title) {
  30. console.log('\n=== title node:', title.path)
  31. dump(title.node)
  32. }