import{U as R,x as p,y as C,N as b,aX as B,o as _,h as E,d as M,w as I,B as T,q as N,bg as O,n as V}from"./index-c3b77b9a.js";import{J as K,o as X,X as A,K as L,a as U,V as D}from"./MessageList-702dd606.js";import"./toast-b30e06c0.js";var g=(c,e,r)=>new Promise((o,u)=>{var v=t=>{try{a(r.next(t))}catch(n){u(n)}},s=t=>{try{a(r.throw(t))}catch(n){u(n)}},a=t=>t.done?o(t.value):Promise.resolve(t.value).then(v,s);a((r=r.apply(c,e)).next())});const H={key:0,class:"math-loading-overlay"},w=K(R({__name:"MathBlockNode",props:{node:{}},setup(c){const e=c,r=p(null),o=p(null);let u=!1,v=0,s=!1,a=null;const t=X();let n=null;const i=p(!0);function y(){return g(this,null,function*(){if(!o.value||s)return;if(!e.node.content)return i.value=!1,o.value.textContent=e.node.raw,void(u=!0);if(!u)try{!n&&r.value&&(n=t(r.value)),yield n==null?void 0:n.whenVisible}catch{}a&&(a.abort(),a=null);const d=++v,m=new AbortController;a=m,A(e.node.content,!0,{timeout:3e3,waitTimeout:2e3,maxRetries:1,signal:m.signal}).then(l=>{s||d!==v||o.value&&(o.value.innerHTML=l,u=!0,i.value=!1)}).catch(l=>g(null,null,function*(){if(s||d!==v||!o.value)return;const f=(l==null?void 0:l.code)||(l==null?void 0:l.name),k=f==="KATEX_DISABLED";if(f==="WORKER_INIT_ERROR"||l!=null&&l.fallbackToRenderer||f===L||f==="WORKER_TIMEOUT"){const x=yield U();if(x){try{const h=x.renderToString(e.node.content,{throwOnError:e.node.loading,displayMode:!0});o.value.innerHTML=h,u=!0,i.value=!1,D(e.node.content,!0,h)}catch{}return}}if(k)return i.value=!1,void(o.value.textContent=e.node.raw);u||(i.value=!0),e.node.loading||(i.value=!1,o.value.textContent=e.node.raw)}))})}return C(()=>e.node.content,()=>{y()}),b(()=>{y()}),B(()=>{var d;s=!0,a&&(a.abort(),a=null),(d=n==null?void 0:n.destroy)==null||d.call(n),n=null}),(d,m)=>(_(),E("div",{ref_key:"containerEl",ref:r,class:"math-block text-center overflow-x-auto relative min-h-[40px]"},[M(O,{name:"math-fade"},{default:I(()=>[i.value?(_(),E("div",H,[...m[0]||(m[0]=[T("div",{class:"math-loading-spinner"},null,-1)])])):N("",!0)]),_:1}),T("div",{ref_key:"mathBlockElement",ref:o,class:V({"math-rendering":i.value})},null,2)],512))}}),[["__scopeId","data-v-f432e706"]]);w.install=c=>{c.component(w.__name,w)};export{w as default};
