import{bQ as P,M as j,af as q,bZ as X,bS as F,aU as x,b_ as J,bT as Q,bE as D,aD as Y,az as Z,aL as T,u as E,I as G,bJ as ee,t as ne,v as ae,g as te,au as V,bb as le,aw as oe,q as L,bU as re,as as U,bV as ue,bW as ie,bX as se,bY as de,b$ as ce}from"./index-DZSqyBof.js";var W=(_,n,o)=>new Promise((u,f)=>{var $=l=>{try{r(o.next(l))}catch(i){f(i)}},m=l=>{try{r(o.throw(l))}catch(i){f(i)}},r=l=>l.done?u(l.value):Promise.resolve(l.value).then($,m);r((o=o.apply(_,n)).next())});const ve=["data-markstream-mode","data-markstream-pending"],fe={key:0,class:"math-loading-overlay"},me=["innerHTML"],he={key:1,class:"math-block__fallback text-left"},O=P(j({__name:"MathBlockNode",props:{node:{},indexKey:{},cacheScope:{}},setup(_){const n=_,o=x(null),u=q(X,null),f=L(()=>re(n.node.content)),$=L(()=>ce(n,{})),m=(function(){if(!n.node.content)return{html:"",text:n.node.raw,loading:!1};const e=F();if(!e)return{html:"",text:n.node.loading?"":n.node.raw,loading:n.node.loading};try{return{html:e.renderToString(f.value,{throwOnError:n.node.loading,displayMode:!0}),text:"",loading:!1}}catch{return{html:"",text:n.node.loading?"":n.node.raw,loading:n.node.loading}}})(),r=x(m.html),l=x(m.text);let i=!1,h=0,s=!1,g=null;const k=J(),A=Q();let d=null,w=null,c="";const v=x(m.loading),H=x(!1),p=x(B());function R(e){e!=null&&e!==h||(H.value=!1)}function z(){var e;if(n.indexKey==null)return"";const a=(e=n.cacheScope)!=null?e:k?.scope;return`${a!=null&&String(a).length>0?`${String(a)}:`:""}math-block:${String(n.indexKey)}`}function B(){var e;const a=z();return a&&(e=k?.cache.get(a))!=null?e:0}function I(e){if(!Number.isFinite(e)||e<=0)return;const a=Math.max(p.value,e);if(a===p.value)return;p.value=a;const t=z();t&&k?.cache.set(t,a)}function y(){U(()=>{var e,a;I((a=(e=o.value)==null?void 0:e.offsetHeight)!=null?a:0)})}function K(){const e=c;u&&e&&(c="",u.markSettled(e))}function C(){return W(this,null,function*(){if(s)return K(),void R();g&&(g.abort(),g=null);const e=++h;if(!n.node.content)return K(),R(),v.value=!1,r.value="",l.value=n.node.raw,i=!0,void y();const a=new AbortController;if(g=a,H.value=!0,!i)try{!d&&o.value&&(d=A(o.value)),yield d?.whenVisible}catch{}s||e!==h||a.signal.aborted?s||R(e):((function(){const t=$.value;u&&t&&c!==t&&(c&&u.markSettled(c),c=t,u.markPending(t))})(),ue(f.value,!0,{timeout:3e3,waitTimeout:2e3,maxRetries:1,signal:a.signal}).then(t=>{s||e!==h||(r.value=t,l.value="",i=!0,v.value=!1,y())}).catch(t=>W(null,null,function*(){if(s||e!==h)return;const b=t?.code||t?.name,M=b==="KATEX_DISABLED";if(b==="WORKER_INIT_ERROR"||t?.fallbackToRenderer||b===ie||b==="WORKER_TIMEOUT"){const S=yield se();if(s||e!==h)return;if(S){try{const N=S.renderToString(f.value,{throwOnError:n.node.loading,displayMode:!0});r.value=N,l.value="",i=!0,v.value=!1,y(),de(f.value,!0,N)}catch{}return}}if(M||!n.node.loading)return v.value=!1,r.value="",l.value=n.node.raw,void y();i||(v.value=!0)})).finally(()=>{s||e!==h||(R(e),(function(){const t=c;u&&t&&(c="",U(()=>{var b,M;if(!s){const S=(M=(b=o.value)==null?void 0:b.offsetHeight)!=null?M:0;S>0&&u.reportHeight(t,S)}u.markSettled(t)}))})())}))})}return(m.html||m.text)&&(i=!0),D(()=>n.node.content,()=>{C()},{flush:"post"}),D([()=>n.indexKey,()=>n.cacheScope],()=>{p.value=B(),y()}),Y(()=>{typeof ResizeObserver<"u"&&o.value&&(w=new ResizeObserver(()=>{var e,a;I((a=(e=o.value)==null?void 0:e.offsetHeight)!=null?a:0)}),w.observe(o.value)),y(),r.value||C()}),Z(()=>{var e;s=!0,K(),g&&(g.abort(),g=null),w?.disconnect(),w=null,(e=d?.destroy)==null||e.call(d),d=null}),(e,a)=>(T(),E("div",{ref_key:"containerEl",ref:o,class:"math-block text-center overflow-x-auto relative","data-markstream-math":"block","data-markstream-mode":r.value?"katex":l.value?"fallback":"loading","data-markstream-pending":H.value?"true":void 0,style:oe(p.value?{minHeight:`${p.value}px`}:void 0)},[G(te,{name:"math-fade"},{default:ee(()=>[!v.value||r.value||l.value?ne("",!0):(T(),E("div",fe,[...a[0]||(a[0]=[ae("div",{class:"math-loading-spinner"},null,-1)])]))]),_:1}),r.value?(T(),E("div",{key:0,class:V(["math-block__content",{"math-rendering":v.value}]),innerHTML:r.value},null,10,me)):l.value?(T(),E("pre",he,le(l.value),1)):(T(),E("div",{key:2,class:V(["math-block__content",{"math-rendering":v.value}])},null,2))],12,ve))}}),[["__scopeId","data-v-38e7acf6"]]);O.install=_=>{_.component(O.__name,O)};export{O as default};
