PulseCanvas / app · pulsecanvas.ai / assets / app-store / duo-marketing-1.2 / render.mjs
| 1 | // Same approved HTML/Playwright rendering method as the iPhone/iPad set. |
| 2 | // Captures and rendered assets stay outside Git. |
| 3 | import { fileURLToPath, pathToFileURL } from 'node:url'; |
| 4 | import { dirname, join, resolve } from 'node:path'; |
| 5 | import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; |
| 6 | import { createHash } from 'node:crypto'; |
| 7 | const { chromium } = await import(process.env.PLAYWRIGHT ?? 'playwright'); |
| 8 | const here = dirname(fileURLToPath(import.meta.url)); |
| 9 | const captures = resolve(process.argv[2] ?? '/Volumes/Music/Codex Media/PulseCanvas Studio/App Store/1.2/Layout-refresh/raw'); |
| 10 | const output = resolve(process.argv[3] ?? '/Volumes/Music/Codex Media/PulseCanvas Studio/App Store/1.2/Layout-refresh/duo'); |
| 11 | const icon = resolve(here, '../../../mobile/Assets.xcassets/AppIcon.appiconset/AppIcon.png'); |
| 12 | const release = join(output, 'release/en-US'); |
| 13 | mkdirSync(release, {recursive:true}); |
| 14 | const url = new URL(pathToFileURL(join(here, 'layouts.html'))); |
| 15 | url.searchParams.set('sources', pathToFileURL(captures).href); |
| 16 | url.searchParams.set('icon', pathToFileURL(icon).href); |
| 17 | const browser = await chromium.launch(); |
| 18 | const page = await browser.newPage({viewport:{width:2853,height:2007},deviceScaleFactor:1}); |
| 19 | const errors=[];page.on('pageerror', e=>errors.push(String(e))); |
| 20 | const names=['music','studio','style','radio','export','free']; |
| 21 | const manifest=[]; |
| 22 | for(const [index,name] of names.entries()){ |
| 23 | url.searchParams.set('slide',index+1); |
| 24 | await page.goto(url.href); |
| 25 | await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode()))); |
| 26 | await page.evaluate(()=>document.fonts.ready); |
| 27 | const layout=await page.evaluate(()=>{ |
| 28 | const copy=document.querySelector('.copy');const r=copy.getBoundingClientRect(); |
| 29 | const free=document.querySelector('.slide.free'); |
| 30 | if(free){ |
| 31 | const device=free.querySelector('.device').getBoundingClientRect(); |
| 32 | if(r.right+90>device.left||r.bottom>innerHeight-140)throw Error('Free hero copy lacks clearance'); |
| 33 | if(device.left<0||device.top<0||device.right>innerWidth-40||device.bottom>innerHeight-160)throw Error('Closed phone outside safe bounds'); |
| 34 | const image=free.querySelector('.device img'); |
| 35 | if(image.naturalWidth!==1398||image.naturalHeight!==2034)throw Error('Free hero must use the closed Duo outer display'); |
| 36 | }else if(r.bottom>595)throw Error('Marketing copy overlaps devices: '+r.bottom); |
| 37 | if(copy.scrollWidth>copy.clientWidth)throw Error('Copy overflows'); |
| 38 | for(const box of document.querySelectorAll('.callout')){const cs=getComputedStyle(box),r=box.getBoundingClientRect();if(new Set([cs.paddingTop,cs.paddingRight,cs.paddingBottom,cs.paddingLeft]).size!==1)throw Error('Unequal callout padding');if(r.right>innerWidth||r.bottom>innerHeight)throw Error('Callout outside canvas');} |
| 39 | return {copyBottom:r.bottom,title:document.querySelector('h1').textContent}; |
| 40 | }); |
| 41 | const file=`duo-${String(index+1).padStart(2,'0')}-${name}.png`; |
| 42 | await page.screenshot({path:join(release,file),clip:{x:0,y:0,width:2853,height:2007},omitBackground:false}); |
| 43 | manifest.push({file,width:2853,height:2007,bytes:readFileSync(join(release,file)).length,sha256:createHash('sha256').update(readFileSync(join(release,file))).digest('hex'),...layout}); |
| 44 | console.log(file); |
| 45 | } |
| 46 | url.searchParams.delete('slide');url.searchParams.set('review','1'); |
| 47 | await page.setViewportSize({width:2300,height:1500});await page.goto(url.href); |
| 48 | await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode()))); |
| 49 | await page.locator('#overview').screenshot({path:join(output,'duo-contact-sheet.png')}); |
| 50 | const sourceNames=['inner-fullscreen','inner-studio','inner-style','inner-radio','inner-export','inner-library','closed-hero',...['studio','style','radio','export'].map(k=>'inner-callout-'+k)]; |
| 51 | const sources=sourceNames.map(n=>{const file='duo-'+n+'.png';return {file,sha256:createHash('sha256').update(readFileSync(join(captures,file))).digest('hex')};}); |
| 52 | if(errors.length)throw Error(errors.join('\n')); |
| 53 | writeFileSync(join(output,'manifest.json'),JSON.stringify({appVersion:'1.2',appBuild:'10',renderedAt:new Date().toISOString(),renderer:'Playwright Chromium, real simulator captures',sources,slides:manifest},null,2)+'\n'); |
| 54 | await browser.close(); |