import json, asyncio
from playwright.async_api import async_playwright
data=json.load(open('/workspace/logo-ga-18nov/src/data.json')); SW=12
def svg(n,fg,w):
    r=data[n]; vb=r['vb']; paths=''.join(f'<path d="{d}"/>' for d in r['ds'])
    return f'<svg viewBox="{" ".join(map(str,vb))}" style="display:block;width:{w}px"><g fill="none" stroke="{fg}" stroke-width="{SW}" stroke-linecap="round" stroke-linejoin="round">{paths}</g></svg>'
async def main():
    async with async_playwright() as p:
        b=await p.chromium.launch(executable_path='/usr/bin/google-chrome', args=['--no-sandbox'])
        for n in data:
            for tag,bg,fg in (('navy','#0B1B33','#FFFFFF'),('white','#FFFFFF','#0B1B33')):
                pg=await b.new_page(viewport={'width':3840,'height':2160}, device_scale_factor=2)
                await pg.set_content(f'<body style="margin:0;width:3840px;height:2160px;background:{bg};display:flex;align-items:center;justify-content:center">{svg(n,fg,2100)}</body>')
                await pg.screenshot(path=f'/workspace/logo-ga-18nov/8k/ga-{n}-8k-{tag}.png'); await pg.close()
            for tag,fg in (('transparent-navy-ink','#0B1B33'),('transparent-white-ink','#FFFFFF')):
                vb=data[n]['vb']; pad=60; w=3840-2*pad; h=round(w*vb[3]/vb[2])+2*pad
                pg=await b.new_page(viewport={'width':3840,'height':h}, device_scale_factor=2)
                await pg.set_content(f'<body style="margin:0;background:transparent;padding:{pad}px">{svg(n,fg,w)}</body>')
                await pg.screenshot(path=f'/workspace/logo-ga-18nov/8k/ga-{n}-7680w-{tag}.png', omit_background=True, full_page=False); await pg.close()
        await b.close()
asyncio.run(main())
