import asyncio, sys, os, pathlib
from playwright.async_api import async_playwright
async def main():
    async with async_playwright() as p:
        b=await p.chromium.launch(executable_path='/usr/bin/google-chrome', args=['--no-sandbox'])
        # outlined check
        pg=await b.new_page(viewport={'width':1500,'height':300})
        imgs=''.join(f'<img src="file:///workspace/logo-ga-18nov/svg/ga-{v}-outlined.svg" style="height:240px;margin:20px">' for v in ('v1','v2','v3'))
        open('/workspace/logo-ga-18nov/svg/_check.html','w').write(f'<body style="margin:0;background:#fff">{imgs}</body>')
        await pg.goto('file:///workspace/logo-ga-18nov/svg/_check.html')
        await pg.wait_for_timeout(300); await pg.screenshot(path='/tmp/outlined.png'); await pg.close(); os.remove('/workspace/logo-ga-18nov/svg/_check.html')
        # frames for best variant
        name=sys.argv[1]; out=pathlib.Path('/tmp/frames'); out.mkdir(exist_ok=True); [f.unlink() for f in out.glob('*.png')]
        pg=await b.new_page(viewport={'width':1280,'height':720}, device_scale_factor=2)
        await pg.goto(f'file:///workspace/logo-ga-18nov/anim/ga-{name}-draw.html?manual&solo')
        fps=60; n=int(fps*3.0)
        for i in range(n):
            t=(i/fps - 0.25)/2.0
            await pg.evaluate(f'setProgress({t})')
            await pg.screenshot(path=str(out/f'f{i:04d}.png'))
        await b.close()
asyncio.run(main())
