import json,re,sys
from playwright.sync_api import sync_playwright
exe='/usr/bin/google-chrome'
out={}
with sync_playwright() as p:
    b=p.chromium.launch(executable_path=exe,args=['--no-sandbox'])
    for t in ['pearl','champagne','midnight','amethyst']:
        pg=b.new_page()
        pg.goto(f'http://localhost:8731/login/?theme={t}');pg.wait_for_timeout(800)
        out[t]=pg.evaluate('''()=>{const names=new Set();for(const s of document.styleSheets){try{for(const r of s.cssRules){const x=r.cssText;(x.match(/--[a-zA-Z0-9-]+/g)||[]).forEach(n=>names.add(n))}}catch(e){}}
        const cs=getComputedStyle(document.documentElement);const o={};[...names].sort().forEach(n=>{const v=cs.getPropertyValue(n).trim();if(v)o[n]=v});return o}''')
    b.close()
json.dump(out,open('/workspace/auth-kit-20nov/tok-v12.json','w'),indent=1)
for k,v in out.items(): print(k,len(v))
