3 lines
3.2 KiB
JavaScript
3 lines
3.2 KiB
JavaScript
import{useDarkMode as h,decodeData as s,LoadingIcon as w,isFunction as f}from"@vuepress/helper/client";import{watchImmediate as M}from"@vueuse/core";import{defineComponent as b,useId as C,shallowRef as L,computed as E,ref as S,h as a,onMounted as k}from"vue";import"../styles/mermaid.css";import{u as x}from"../mermaid-D26-9yYy.js";const z=c=>`data:image/svg+xml;charset=utf8,${c.replace(/<br>/g,"<br />").replace(/%/g,"%25").replace(/"/g,"%22").replace(/'/g,"%27").replace(/&/g,"%26").replace(/#/g,"%23").replace(/{/g,"%7B").replace(/}/g,"%7D").replace(/</g,"%3C").replace(/>/g,"%3E")}`,V='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1316 1024" fill="currentColor"><path d="M658.286 0C415.89 0 0 297.106 0 512c0 214.82 415.89 512 658.286 512 242.322 0 658.285-294.839 658.285-512S900.608 0 658.286 0zm0 877.714c-161.573 0-512-221.769-512-365.714 0-144.018 350.427-365.714 512-365.714 161.572 0 512 217.16 512 365.714s-350.428 365.714-512 365.714z"/><path d="M658.286 292.571a219.429 219.429 0 1 0 0 438.858 219.429 219.429 0 0 0 0-438.858zm0 292.572a73.143 73.143 0 1 1 0-146.286 73.143 73.143 0 0 1 0 146.286z"/></svg>',_='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" fill="currentColor"><path d="M828.976 894.125H190.189c-70.55 0-127.754-57.185-127.754-127.753V606.674c0-17.634 14.31-31.933 31.933-31.933h63.889c17.634 0 31.932 14.299 31.932 31.933v95.822c0 35.282 28.596 63.877 63.877 63.877h511.033c35.281 0 63.877-28.595 63.877-63.877v-95.822c0-17.634 14.298-31.933 31.943-31.933h63.878c17.635 0 31.933 14.299 31.933 31.933v159.7c0 70.566-57.191 127.751-127.754 127.751zM249.939 267.51c12.921-12.92 33.885-12.92 46.807 0l148.97 148.972V94.893c0-17.634 14.302-31.947 31.934-31.947h63.876c17.638 0 31.946 14.313 31.946 31.947v321.589l148.97-148.972c12.922-12.92 33.876-12.92 46.797 0l46.814 46.818c12.922 12.922 12.922 33.874 0 46.807L552.261 624.93c-1.14 1.138-21.664 13.684-42.315 13.693-20.877.01-41.88-12.542-43.021-13.693L203.122 361.135c-12.923-12.934-12.923-33.885 0-46.807l46.817-46.818z"/></svg>',r={useMaxWidth:!1};var I=b({name:"Mermaid",props:{code:{type:String,required:!0},title:String},setup(c){const n=C(),l=h(),{themeVariables:o,...d}=x(),m=L(),u=E(()=>s(c.code)),i=S(""),p=async()=>{if(__VUEPRESS_SSR__)return;const{default:t}=await import("mermaid/dist/mermaid.esm.min.mjs");t.initialize({theme:l.value?"dark":"default",themeVariables:{dark:l.value,...f(o)?o(l.value):o},flowchart:r,sequence:r,journey:r,gantt:r,er:r,pie:r,...d,startOnLoad:!1}),i.value=(await t.render(n,u.value)).svg},v=()=>{const{body:t}=document,e=document.createElement("div");e.classList.add("mermaid-preview"),e.innerHTML=i.value,t.appendChild(e),e.addEventListener("click",()=>{t.removeChild(e)})},g=()=>{const t=z(i.value),e=document.createElement("a");e.setAttribute("href",t),e.setAttribute("download",`${c.title?s(c.title):n}.svg`),e.click()};return k(()=>{M(l,p,{flush:"post"})}),()=>[a("div",{class:"mermaid-actions"},[a("button",{class:"preview-button",title:"preview",innerHTML:V,onClick:v}),a("button",{class:"download-button",title:"download",innerHTML:_,onClick:g})]),a("div",{ref:m,class:"mermaid-wrapper"},i.value?a("div",{class:"mermaid-content",innerHTML:i.value}):a(w,{class:"mermaid-loading",height:96}))]}});export{I as default};
|
|
//# sourceMappingURL=Mermaid.js.map
|