3 lines
6.9 KiB
JavaScript
3 lines
6.9 KiB
JavaScript
"use strict";(()=>{var p=["esm.sh","skypack","esm.run","jsdelivr.esm","fastly.jsdelivr.esm","gcore.jsdelivr.esm","testingcf.jsdelivr.esm","jsdelivr.b-cdn.esm","jspm"],d=["jsdelivr","fastly.jsdelivr","unpkg","gcore.jsdelivr","testingcf.jsdelivr","jsdelivr.b-cdn","npmcdn"],m=["jsdelivr.gh","fastly.jsdelivr.gh","statically","gcore.jsdelivr.gh","testingcf.jsdelivr.gh","jsdelivr.b-cdn.gh"],c={getModuleUrl:(s,{isModule:t=!0,defaultCDN:o="esm.sh",external:e}={})=>{s=s.replace(/#nobundle/g,"");let r=i=>!e||!i.includes("https://esm.sh")?i:i.includes("?")?`${i}&external=${e}`:`${i}?external=${e}`,n=a(s,t,o);return n?r(n):t?r("https://esm.sh/"+s):"https://cdn.jsdelivr.net/npm/"+s},getUrl:(s,t)=>s.startsWith("http")||s.startsWith("data:")?s:a(s,!1,t||x())||s,cdnLists:{npm:d,module:p,gh:m},checkCDNs:async(s,t)=>{let o=[t,...c.cdnLists.npm].filter(Boolean);for(let e of o)try{if((await fetch(c.getUrl(s,e),{method:"HEAD"})).ok)return e}catch{}return c.cdnLists.npm[0]}},x=()=>{if(globalThis.appCDN)return globalThis.appCDN;try{return new URL(location.href).searchParams.get("appCDN")||c.cdnLists.npm[0]}catch{return c.cdnLists.npm[0]}},a=(s,t,o)=>{let e=t&&s.startsWith("unpkg:")?"?module":"";s.startsWith("gh:")?s=s.replace("gh",m[0]):s.includes(":")||(s=(o||(t?p[0]:d[0]))+":"+s);for(let r of f){let[n,i]=r;if(n.test(s))return s.replace(n,i)+e}return null},f=[[/^(esm\.sh:)(.+)/i,"https://esm.sh/$2"],[/^(npm:)(.+)/i,"https://esm.sh/$2"],[/^(node:)(.+)/i,"https://esm.sh/$2"],[/^(jsr:)(.+)/i,"https://esm.sh/jsr/$2"],[/^(skypack:)(.+)/i,"https://cdn.skypack.dev/$2"],[/^(jsdelivr:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2"],[/^(fastly\.jsdelivr:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2"],[/^(gcore\.jsdelivr:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2"],[/^(testingcf\.jsdelivr:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2"],[/^(jsdelivr\.b-cdn:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2"],[/^(jsdelivr\.gh:)(.+)/i,"https://cdn.jsdelivr.net/gh/$2"],[/^(fastly\.jsdelivr\.gh:)(.+)/i,"https://fastly.jsdelivr.net/gh/$2"],[/^(gcore\.jsdelivr\.gh:)(.+)/i,"https://gcore.jsdelivr.net/gh/$2"],[/^(testingcf\.jsdelivr\.gh:)(.+)/i,"https://testingcf.jsdelivr.net/gh/$2"],[/^(jsdelivr\.b-cdn\.gh:)(.+)/i,"https://jsdelivr.b-cdn.net/gh/$2"],[/^(statically:)(.+)/i,"https://cdn.statically.io/gh/$2"],[/^(esm\.run:)(.+)/i,"https://esm.run/$2"],[/^(jsdelivr\.esm:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2/+esm"],[/^(fastly\.jsdelivr\.esm:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2/+esm"],[/^(gcore\.jsdelivr\.esm:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2/+esm"],[/^(testingcf\.jsdelivr\.esm:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2/+esm"],[/^(jsdelivr\.b-cdn\.esm:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2/+esm"],[/^(jspm:)(.+)/i,"https://jspm.dev/$2"],[/^(esbuild:)(.+)/i,"https://esbuild.vercel.app/$2"],[/^(bundle\.run:)(.+)/i,"https://bundle.run/$2"],[/^(unpkg:)(.+)/i,"https://unpkg.com/$2"],[/^(npmcdn:)(.+)/i,"https://npmcdn.com/$2"],[/^(bundlejs:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(bundle:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(deno:)(.+)/i,"https://deno.bundlejs.com/?file&q=https://deno.land/x/$2/mod.ts"],[/^(https:\/\/deno\.land\/.+)/i,"https://deno.bundlejs.com/?file&q=$1"],[/^(github:|https:\/\/github\.com\/)(.[^\/]+?)\/(.[^\/]+?)\/(?!releases\/)(?:(?:blob|raw)\/)?(.+?\/.+)/i,"https://deno.bundlejs.com/?file&q=https://cdn.jsdelivr.net/gh/$2/$3@$4"],[/^(gist\.github:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(gitlab:|https:\/\/gitlab\.com\/)([^\/]+.*\/[^\/]+)\/(?:raw|blob)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://gl.githack.com/$2/raw/$3"],[/^(bitbucket:|https:\/\/bitbucket\.org\/)([^\/]+\/[^\/]+)\/(?:raw|src)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://bb.githack.com/$2/raw/$3"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/]+)\/revisions\/([^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/$3/files/$4"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/HEAD/files/$3"],[/^(bitbucket:)\!api\/2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(api\.bitbucket:)2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(rawgit:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(rawgit:|https:\/\/raw\.githubusercontent\.com)(\/[^\/]+\/[^\/]+|[0-9A-Za-z-]+\/[0-9a-f]+\/raw)\/(.+)/i,"https://deno.bundlejs.com/?file&q=https://raw.githack.com/$2/$3"]];var{getUrl:j,getModuleUrl:C}=c;var l=j("@seth0x41/csharp-wasm@1.0.3/");livecodes.csharp??(livecodes.csharp={});var g=(s,t=3e4)=>new Promise(o=>{let e=Date.now(),r=async()=>{await s()?o(!0):Date.now()-e>t?o(!1):setTimeout(r,100)};r()}),U=()=>{let s=window.fetch;window.fetch=(t,o={})=>(typeof t=="string"?t:"url"in t?t.url:t.href).startsWith(l)?s(t,{...o,credentials:"omit"}):s(t,o)},b=()=>new Promise((s,t)=>{let o=`${l}_framework/blazor.webassembly.js`;if(document.querySelector(`script[src="${o}"]`)){s();return}let e=document.createElement("script");e.src=o,e.setAttribute("autostart","false"),e.onload=()=>s(),e.onerror=r=>t(new Error(`Failed to load Blazor script: ${r}`)),document.head.appendChild(e)}),v=async()=>{try{return await window.DotNet.invokeMethodAsync("MyRunnyApp","RunCode","int x = 1 + 1;",""),!0}catch{return!1}},w=async(s,t="")=>{await livecodes.csharp.init;try{let{output:o,errors:e}=await window.DotNet.invokeMethodAsync("MyRunnyApp","RunCode",s,t);return{output:o,error:e||null}}catch(o){return{output:null,error:"Error: "+o.message}}},h;(h=livecodes.csharp).init??(h.init=(async()=>{if(!livecodes.csharp.ready){console.log("Initializing C# environment...");try{if(await b(),!window.Blazor)throw new Error("Blazor failed to load properly");if(U(),await window.Blazor.start({loadBootResource:(s,t)=>`${l}_framework/${t}`}),!await g(v))throw new Error("Timeout waiting for DotNet to be ready");console.log("C# environment initialized successfully")}catch(s){throw console.error("Failed to initialize C# environment:",s),livecodes.csharp.ready=!1,livecodes.csharp.init=null,s}}})());var u;(u=livecodes.csharp).run??(u.run=async s=>{let t="";livecodes.csharp.input=s,livecodes.csharp.output=null,livecodes.csharp.ready=!1,document.querySelectorAll('script[type="text/csharp-wasm"]').forEach(n=>t+=n.innerHTML+`
|
|
`);let{output:e,error:r}=t.trim()?await w(t,s):{output:null,error:null};return r!=null?console.error(r):e!=null&&console.log(e),livecodes.csharp.output=e,livecodes.csharp.error=r,livecodes.csharp.exitCode=r?1:0,livecodes.csharp.ready=!0,{output:e,error:r,exitCode:0}});livecodes.csharp.loaded=new Promise(s=>{let t=setInterval(()=>{livecodes.csharp.ready&&(clearInterval(t),s())},50)});window.addEventListener("load",async()=>{parent.postMessage({type:"loading",payload:!0},"*"),await livecodes.csharp.run(livecodes.csharp.input),parent.postMessage({type:"loading",payload:!1},"*")});})();
|