Files
haptika/mobile/scripts/decode-figma.cjs
2026-09-08 09:07:27 +02:00

4 lines
913 B
JavaScript

const fs=require('fs');const path=require('path');
function decode(s){const b=Buffer.from(s.trim(),'base64');let codes=[];for(let i=0;i<b.length;i+=2)codes.push(b.readUInt16BE(i));let dict=Array.from({length:256},(_,i)=>String.fromCharCode(i));let w=String.fromCharCode(codes[0]),out=w;for(const code of codes.slice(1)){const e=dict[code]??(w+w[0]);out+=e;if(dict.length<65535)dict.push(w+e[0]);w=e;}return JSON.parse(Buffer.from(out,'latin1').toString('utf8'));}
const dir=process.argv[2];let scenes=[];for(const f of fs.readdirSync(dir)){if(f.endsWith('.lzw'))scenes.push(...decode(fs.readFileSync(path.join(dir,f),'utf8')));}fs.writeFileSync(path.join(dir,'../native-properties.json'),JSON.stringify(scenes));console.log(JSON.stringify({frames:scenes.length,assets:scenes.flatMap(s=>s.layers.filter(l=>l.asset)).length,fonts:[...new Set(scenes.flatMap(s=>s.layers.flatMap(l=>l.runs?.map(r=>r.font)||[])))]}));