feat: iphone app

This commit is contained in:
leon
2026-09-08 09:07:27 +02:00
parent dcecd07d56
commit 8666f6eb8f
388 changed files with 35960 additions and 1 deletions
+9
View File
@@ -0,0 +1,9 @@
const fs=require('fs');const path=require('path');const parser=require('@babel/parser');
const root=path.resolve(__dirname,'..');const scenes=JSON.parse(fs.readFileSync(root+'/design/scenes.json'));const contexts=JSON.parse(fs.readFileSync(root+'/design/contexts.json'));
const manifests={},screenshots=[];
function attr(n,name){const a=n.openingElement.attributes.find(a=>a.name?.name===name);return a?.value?.value;}
function walk(n,cb){if(!n||typeof n!=='object')return;cb(n);for(const [k,v] of Object.entries(n)){if(k==='loc'||k==='extra')continue;if(Array.isArray(v))v.forEach(x=>walk(x,cb));else if(v&&typeof v==='object')walk(v,cb);}}
for(const scene of scenes){const code=contexts[scene.id];if(!code)continue;let ast;try{ast=parser.parse(code,{sourceType:'module',plugins:['jsx','typescript']});}catch(e){continue;}const urls={},nodes={};walk(ast,n=>{if(n.type==='VariableDeclarator'&&n.init?.type==='StringLiteral')urls[n.id.name]=n.init.value;if(n.type==='JSXElement'){const id=attr(n,'data-node-id');if(id)nodes[id]=n;}});
for(const l of scene.layers.filter(l=>l.asset)){const node=nodes[l.id];const imgs=[];if(node)walk(node,n=>{if(n.type==='JSXElement'&&n.openingElement.name.name==='img'){const a=n.openingElement.attributes.find(a=>a.name?.name==='src');const url=urls[a?.value?.expression?.name]||a?.value?.value;if(url)imgs.push(url);}});
if(imgs.length===1&&imgs[0].endsWith('.svg'))manifests[l.id]={url:imgs[0],format:'svg'};else screenshots.push({id:l.id,frame:scene.id,name:l.name,w:l.w,h:l.h,urls:imgs});}}
fs.writeFileSync(root+'/design/asset-manifest.json',JSON.stringify(manifests,null,2));fs.writeFileSync(root+'/design/screenshot-assets.json',JSON.stringify(screenshots,null,2));console.log({mapped:Object.keys(manifests).length,screenshots:screenshots.length});