import{K as n}from"./popup-B_hjki6q.js";import"./modulepreload-polyfill-B5Qt9EMX.js";const i="formula-bridge-mathjax",w="/vendor/mathjax/tex-mml-chtml.js",l="MJX-CHTML-styles",d=8e3,x=8e3,p=1e4;let r=null;const M=()=>{window.MathJax?.startup?.promise||(window.MathJax={loader:{load:["[tex]/boldsymbol","[tex]/color"],paths:{mathjax:"/vendor/mathjax","mathjax-newcm":"/vendor/mathjax-newcm"}},tex:{inlineMath:[["\\(","\\)"]],displayMath:[["\\[","\\]"]],packages:{"[+]":["boldsymbol","color"]}},options:{enableMenu:!1,enableEnrichment:!1,enableComplexity:!1,enableExplorer:!1,enableSpeech:!1,enableBraille:!1,menuOptions:{settings:{enrich:!1,collapsible:!1,speech:!1,braille:!1}}},startup:{typeset:!1}})},c=async()=>{const e=Date.now()+d;for(;!window.MathJax?.startup?.promise;){if(Date.now()>e)throw new Error(n("MathJax 启动超时。"));await new Promise(t=>window.setTimeout(t,20))}return await window.MathJax.startup.promise,window.MathJax},s=async(e,t,a=x)=>{let o=0;try{return await Promise.race([e,new Promise((y,h)=>{o=window.setTimeout(()=>h(new Error(t)),a)})])}finally{window.clearTimeout(o)}},u=()=>new Promise((e,t)=>{document.getElementById(i)?.remove();const a=document.createElement("script");a.id=i,a.src=w,a.async=!0,a.addEventListener("load",()=>e(),{once:!0}),a.addEventListener("error",()=>{a.remove(),t(new Error(n("MathJax 加载失败。")))},{once:!0}),document.head.appendChild(a)}),f=e=>{const t=e.chtmlStylesheet?.();!t||document.getElementById(l)||(t.id=l,document.head.appendChild(t))},m=async()=>window.MathJax?.startup?.promise?c():(r||(M(),r=s(u().then(c),n("MathJax 加载超时。"),p).catch(e=>{throw r=null,e})),r),E=e=>{window.MathJax?.typesetClear?.([e])},S=async(e,t=!0)=>{const a=await m();if(!a.tex2chtmlPromise)throw new Error(n("当前 MathJax 构建不支持公式渲染。"));const o=await s(a.tex2chtmlPromise(e,{display:t}),n("MathJax 渲染超时。"));return f(a),o},b=async e=>{const t=await m();if(!t.tex2mmlPromise)throw new Error(n("当前 MathJax 构建不支持 MathML 导出。"));return s(t.tex2mmlPromise(e,{display:!0}),n("MathJax MathML 导出超时。"))};export{E as clearTypeset,m as loadMathJax,S as texToChtml,b as texToMathMl};
