markstream-vue
Version:
Vue 3 Markdown renderer optimized for large docs: progressive Mermaid, streaming diff code blocks, and fast real-time preview.
2 lines (1 loc) • 2.23 kB
JavaScript
var e=(e,n,l)=>new Promise((t,a)=>{var o=e=>{try{u(l.next(e))}catch(n){a(n)}},r=e=>{try{u(l.throw(e))}catch(n){a(n)}},u=e=>e.done?t(e.value):Promise.resolve(e.value).then(o,r);u((l=l.apply(e,n)).next())});import{defineComponent as n,ref as l,watch as t,onMounted as a,onBeforeUnmount as o,createElementBlock as r,openBlock as u,createVNode as i,createElementVNode as s,Transition as c,withCtx as d,createCommentVNode as v,normalizeClass as m}from"vue";import{a as f,r as h,e as p,f as y,W as _,d as x}from"./exports.js";const R={key:0,class:"math-loading-overlay"},g=/* @__PURE__ */x(/* @__PURE__ */n({__name:"MathBlockNode",props:{node:{}},setup(n){const x=n;let g=null;const w=l(null),T=l(null);let b=!1,k=0,E=!1,M=null;const O=f();let I=null;const W=l(!0);function B(){return e(this,null,function*(){if(!x.node.content||!T.value||E)return;if(!b)try{!I&&w.value&&(I=O(w.value)),yield null==I?void 0:I.whenVisible}catch(t){}M&&(M.abort(),M=null);const n=++k,l=new AbortController;M=l,h(x.node.content,!0,{timeout:3e3,waitTimeout:2e3,maxRetries:1,signal:l.signal}).then(e=>{E||n!==k||T.value&&(T.value.innerHTML=e,b=!0,W.value=!1)}).catch(l=>e(null,null,function*(){if(E||n!==k)return;if(!T.value)return;const e=(null==l?void 0:l.code)||(null==l?void 0:l.name);if(("WORKER_INIT_ERROR"===e||(null==l?void 0:l.fallbackToRenderer)||e===_||"WORKER_TIMEOUT"===e)&&(g||(g=yield p()),g))try{const e=g.renderToString(x.node.content,{throwOnError:x.node.loading,displayMode:!0});T.value.innerHTML=e,b=!0,W.value=!1,y(x.node.content,!0,e)}catch(t){}else b||(W.value=!0),x.node.loading||(W.value=!1,T.value.textContent=x.node.raw)}))})}return t(()=>x.node.content,()=>{B()}),a(()=>{B()}),o(()=>{var e;E=!0,M&&(M.abort(),M=null),null==(e=null==I?void 0:I.destroy)||e.call(I),I=null}),(e,n)=>(u(),r("div",{ref_key:"containerEl",ref:w,class:"math-block text-center overflow-x-auto relative min-h-[40px]"},[i(c,{name:"math-fade"},{default:d(()=>[W.value?(u(),r("div",R,[...n[0]||(n[0]=[s("div",{class:"math-loading-spinner"},null,-1)])])):v("",!0)]),_:1}),s("div",{ref_key:"mathBlockElement",ref:T,class:m({"math-rendering":W.value})},null,2)],512))}}),[["__scopeId","data-v-2e076ab9"]]);g.install=e=>{e.component(g.__name,g)};export{g as default};