PulseCanvas / app · pulsecanvas.ai / assets / app-store / all-devices-1.2 / render.mjs
| 1 | // Render marketing artwork from real app captures; no app UI is recreated. |
| 2 | import {fileURLToPath,pathToFileURL} from 'node:url'; |
| 3 | import {dirname,resolve,join} from 'node:path'; |
| 4 | import {mkdirSync,readFileSync,writeFileSync} from 'node:fs'; |
| 5 | import {createHash} from 'node:crypto'; |
| 6 | const {chromium}=await import(process.env.PLAYWRIGHT??'playwright'); |
| 7 | const here=dirname(fileURLToPath(import.meta.url)),sources=resolve(process.argv[2]),out=resolve(process.argv[3]); |
| 8 | mkdirSync(out,{recursive:true});const url=new URL(pathToFileURL(join(here,'layout.html'))); |
| 9 | url.searchParams.set('sources',pathToFileURL(sources).href);url.searchParams.set('icon',pathToFileURL(resolve(here,'../../../mobile/Assets.xcassets/AppIcon.appiconset/AppIcon.png')).href); |
| 10 | const browser=await chromium.launch(),slides=[];const hash=p=>createHash('sha256').update(readFileSync(p)).digest('hex'); |
| 11 | for(const [kind,[width,height]] of Object.entries({iphone:[1320,2868],ipad:[2752,2064],duo:[2853,2007],mac:[2880,1800],vision:[3840,2160]})){ |
| 12 | const page=await browser.newPage({viewport:{width,height},deviceScaleFactor:1});url.searchParams.set('kind',kind);await page.goto(url.href); |
| 13 | await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode())));await page.evaluate(()=>document.fonts.ready); |
| 14 | await page.evaluate(()=>{for(const e of document.querySelectorAll('.copy,.tile,.name')){const r=e.getBoundingClientRect();if(r.left<0||r.top<0||r.right>innerWidth||r.bottom>innerHeight||e.scrollWidth>e.clientWidth+1)throw Error('Artwork overflow');}if(document.querySelector('.copy').getBoundingClientRect().bottom>document.querySelector('.devices').getBoundingClientRect().top-20)throw Error('Copy overlaps devices');}); |
| 15 | const file=`${kind}-all-devices.png`,path=join(out,file);await page.screenshot({path,omitBackground:false});slides.push({file,width,height,sha256:hash(path)});await page.close();console.log(file); |
| 16 | } |
| 17 | await browser.close();const captures=['iphone-studio.png','ipad-studio.png','mac-studio.png','vision-studio.png','duo-closed-studio.png'].map(file=>({file,sha256:hash(join(sources,file))})); |
| 18 | writeFileSync(join(out,'manifest.json'),JSON.stringify({renderedAt:new Date().toISOString(),captures,slides},null,2)+'\n'); |