(()=>{function p(){let T=performance.now();function n(t){let e=document.getElementById(t);if(!e)throw new Error(`Missing element: #${t}`);return e}let u=n("md-input"),a=n("json-output"),i=n("theme-select"),l=n("transmute-btn"),s=n("copy-btn"),o=n("download-link"),m=n("status"),E=n("elem-count"),M=n("render-ms"),L=n("boot-ms");for(let t of MkdToAstPipeline.THEME_NAMES){let e=document.createElement("option");e.value=t,e.textContent=t,i.appendChild(e)}u.value=MkdToAstPipeline.SAMPLE_MARKDOWN,L.textContent=`${(performance.now()-T).toFixed(1)} ms`;let r=null;function c(t,e){m.dataset.state=t,m.textContent=e}function b(){r&&(URL.revokeObjectURL(r),r=null),o.removeAttribute("href"),o.setAttribute("aria-disabled","true")}function d(){b(),c("running","Transmuting\u2026"),l.disabled=!0,requestAnimationFrame(()=>{try{let{json:t,elementCount:e,ms:f}=MkdToAstPipeline.runTransmute(u.value,i.value);a.value=t+`
`,E.textContent=String(e),M.textContent=`${f.toFixed(1)} ms`,c("ok","");let v=new Blob([t],{type:"application/json"});r=URL.createObjectURL(v),o.href=r,o.setAttribute("aria-disabled","false"),o.download="document.json"}catch(t){c("error",String(t))}finally{l.disabled=!1}})}d(),l.addEventListener("click",d),i.addEventListener("change",d),s.addEventListener("click",async()=>{let t=a.value.trim();if(t)try{await navigator.clipboard.writeText(t);let e=s.textContent;s.textContent="Copied!",setTimeout(()=>{s.textContent=e},1500)}catch{a.select()}})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",p):p();})();
