var h=Object.defineProperty;var v=(t,e)=>{for(var i in e)h(t,i,{get:e[i],enumerable:!0})};function f(t){let e=atob(t),i=e.length,o=new Uint8Array(i);for(let n=0;n<i;n++)o[n]=e.charCodeAt(n);return o}function d(t){typeof t=="string"&&(t=new TextEncoder().encode(t));let e="",i=t.byteLength;for(let o=0;o<i;o++)e+=String.fromCharCode(t[o]);return btoa(e)}var u=t=>{throw new Error("Not initialized yet")},p=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var l=new Map,m=0;p&&(globalThis.syscall=async(t,...e)=>await new Promise((i,o)=>{m++,l.set(m,{resolve:i,reject:o}),u({type:"sys",id:m,name:t,args:e})}));function g(t,e,i){p&&(u=i,self.addEventListener("message",o=>{(async()=>{let n=o.data;switch(n.type){case"inv":{let s=t[n.name];if(!s)throw new Error(`Function not loaded: ${n.name}`);try{let a=await Promise.resolve(s(...n.args||[]));u({type:"invr",id:n.id,result:a})}catch(a){console.error("An exception was thrown as a result of invoking function",n.name,"error:",a.message),u({type:"invr",id:n.id,error:a.message})}}break;case"sysr":{let s=n.id,a=l.get(s);if(!a)throw Error("Invalid request id");l.delete(s),n.error?a.reject(new Error(n.error)):a.resolve(n.result)}break}})().catch(console.error)}),u({type:"manifest",manifest:e}))}async function b(t,e){if(typeof t!="string"){let i=new Uint8Array(await t.arrayBuffer()),o=i.length>0?d(i):void 0;e={method:t.method,headers:Object.fromEntries(t.headers.entries()),base64Body:o},t=t.url}return syscall("sandboxFetch.fetch",t,e)}globalThis.nativeFetch=globalThis.fetch;function w(){globalThis.fetch=async function(t,e){let i=e&&e.body?d(new Uint8Array(await new Response(e.body).arrayBuffer())):void 0,o=await b(t,e&&{method:e.method,headers:e.headers,base64Body:i});return new Response(o.base64Body?f(o.base64Body):null,{status:o.status,headers:o.headers})}}p&&w();typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function r(t,...e){return globalThis.syscall(t,...e)}var c={};v(c,{getConfig:()=>L,getMode:()=>E,getVersion:()=>U,invokeCommand:()=>A,invokeFunction:()=>F,listCommands:()=>T,listSyscalls:()=>k,reloadPlugs:()=>D,wipeClient:()=>R});function F(t,...e){return r("system.invokeFunction",t,...e)}function A(t,e){return r("system.invokeCommand",t,e)}function T(){return r("system.listCommands")}function k(){return r("system.listSyscalls")}function D(){return r("system.reloadPlugs")}function E(){return r("system.getMode")}function U(){return r("system.getVersion")}function L(t,e=void 0){return r("system.getConfig",t,e)}function R(t=!1){return r("system.wipeClient",t)}async function y(t){let e=await c.getConfig("mermaid",{version:"11.10.1"}),i=e?.version,o=e?.integrity?`"${e.integrity}"`:'"sha256-BmQmdWDS8X2OTbrwELWK366LV6escyWhHHe0XCTU/Hk="';e?.integrity_disabled&&(o=void 0);let n="";if(e?.icon_packs)for(let s of e?.icon_packs)n+=`{
        name: "${s.name}",
        loader: () => fetch("${s.url}").then(r => r.json()),
      },`;return{html:`<pre class="mermaid">${t.replaceAll("<","&lt;")}</pre>`,script:`
    loadJsByUrl("https://cdn.jsdelivr.net/npm/mermaid@${i}/dist/mermaid.min.js", ${o}).then(() => {
      mermaid.init().then(updateHeight);
      mermaid.registerIconPacks([${n}]);
    });
    document.addEventListener("click", () => {
      api({type: "blur"});
    });
    `}}var x={mermaidWidget:y},P={name:"mermaid",version:.1,imports:["https://get.silverbullet.md/global.plug.json"],functions:{mermaidWidget:{path:"./mermaid.ts:widget",codeWidget:"mermaid"}},assets:{}},Se={manifest:P,functionMapping:x};g(x,P,self.postMessage);export{Se as plug};
