UNPKG

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.51 kB
"use strict";var g=(m,l,s)=>new Promise((p,r)=>{var d=n=>{try{i(s.next(n))}catch(o){r(o)}},h=n=>{try{i(s.throw(n))}catch(o){r(o)}},i=n=>n.done?p(n.value):Promise.resolve(n.value).then(d,h);i((s=s.apply(m,l)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),f=require("./exports-BD7Y_TjZ.cjs"),y={class:"math-inline__loading",role:"status","aria-live":"polite"},O=e.defineComponent({__name:"MathInlineNode",props:{node:{}},setup(m){const l=m;let s=null;const p=e.ref(null),r=e.ref(null);let d=!1,h=0,i=!1,n=null;const o=e.ref(!0),R=f.useViewportPriority();let a=null;function w(){return g(this,null,function*(){if(!l.node.content||!r.value||i)return;n&&(n.abort(),n=null);const u=++h,c=new AbortController;if(n=c,!d)try{!a&&p.value&&(a=R(p.value)),yield a==null?void 0:a.whenVisible}catch(t){}f.renderKaTeXWithBackpressure(l.node.content,!1,{timeout:1500,waitTimeout:0,maxRetries:0,signal:c.signal}).then(t=>{i||u!==h||r.value&&(r.value.innerHTML=t,o.value=!1,d=!0)}).catch(t=>g(null,null,function*(){if(i||u!==h||!r.value)return;const v=(t==null?void 0:t.code)||(t==null?void 0:t.name),T=v==="WORKER_INIT_ERROR"||(t==null?void 0:t.fallbackToRenderer),k=v===f.WORKER_BUSY_CODE||v==="WORKER_TIMEOUT";if((T||k)&&(s||(s=yield f.getKatex()),s)){try{const E=s.renderToString(l.node.content,{throwOnError:l.node.loading,displayMode:!1});o.value=!1,r.value.innerHTML=E,d=!0,f.setKaTeXCache(l.node.content,!1,E)}catch(E){}return}d||(o.value=!0),l.node.loading||(o.value=!1,r.value.textContent=l.node.raw)}))})}return e.watch(()=>l.node.content,()=>{w()}),e.onMounted(()=>{w()}),e.onBeforeUnmount(()=>{var u;i=!0,n&&(n.abort(),n=null),(u=a==null?void 0:a.destroy)==null||u.call(a),a=null}),(u,c)=>(e.openBlock(),e.createElementBlock("span",{ref_key:"containerEl",ref:p,class:"math-inline-wrapper"},[e.withDirectives(e.createElementVNode("span",{ref_key:"mathElement",ref:r,class:"math-inline"},null,512),[[e.vShow,!o.value]]),o.value?(e.openBlock(),e.createBlock(e.Transition,{key:0,name:"table-node-fade"},{default:e.withCtx(()=>[e.createElementVNode("span",y,[e.renderSlot(u.$slots,"loading",{isLoading:o.value},()=>[c[0]||(c[0]=e.createElementVNode("span",{class:"math-inline__spinner animate-spin","aria-hidden":"true"},null,-1)),c[1]||(c[1]=e.createElementVNode("span",{class:"sr-only"},"Loading",-1))],!0)])]),_:3})):e.createCommentVNode("",!0)],512))}}),_=f._export_sfc(O,[["__scopeId","data-v-6b23009e"]]);_.install=m=>{m.component(_.__name,_)};exports.default=_;