8 lines
6.4 KiB
JavaScript
8 lines
6.4 KiB
JavaScript
"use strict";(()=>{var x=["esm.sh","skypack","esm.run","jsdelivr.esm","fastly.jsdelivr.esm","gcore.jsdelivr.esm","testingcf.jsdelivr.esm","jsdelivr.b-cdn.esm","jspm"],f=["jsdelivr","fastly.jsdelivr","unpkg","gcore.jsdelivr","testingcf.jsdelivr","jsdelivr.b-cdn","npmcdn"],u=["jsdelivr.gh","fastly.jsdelivr.gh","statically","gcore.jsdelivr.gh","testingcf.jsdelivr.gh","jsdelivr.b-cdn.gh"],l={getModuleUrl:(s,{isModule:t=!0,defaultCDN:n="esm.sh",external:o}={})=>{s=s.replace(/#nobundle/g,"");let i=r=>!o||!r.includes("https://esm.sh")?r:r.includes("?")?`${r}&external=${o}`:`${r}?external=${o}`,c=h(s,t,n);return c?i(c):t?i("https://esm.sh/"+s):"https://cdn.jsdelivr.net/npm/"+s},getUrl:(s,t)=>s.startsWith("http")||s.startsWith("data:")?s:h(s,!1,t||v())||s,cdnLists:{npm:f,module:x,gh:u},checkCDNs:async(s,t)=>{let n=[t,...l.cdnLists.npm].filter(Boolean);for(let o of n)try{if((await fetch(l.getUrl(s,o),{method:"HEAD"})).ok)return o}catch{}return l.cdnLists.npm[0]}},v=()=>{if(globalThis.appCDN)return globalThis.appCDN;try{return new URL(location.href).searchParams.get("appCDN")||l.cdnLists.npm[0]}catch{return l.cdnLists.npm[0]}},h=(s,t,n)=>{let o=t&&s.startsWith("unpkg:")?"?module":"";s.startsWith("gh:")?s=s.replace("gh",u[0]):s.includes(":")||(s=(n||(t?x[0]:f[0]))+":"+s);for(let i of y){let[c,r]=i;if(c.test(s))return s.replace(c,r)+o}return null},y=[[/^(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:g,getModuleUrl:B}=l;var j=g("font-awesome@4.7.0/css/font-awesome.min.css");var d=g("https://cdn.jsdelivr.net/pyodide/v0.25.1/full/");if(livecodes.pyodideLoading===void 0){livecodes.pyodideLoading=new Promise(t=>{livecodes.resolveLoading=t});let s=document.createElement("script");s.src=`${d}pyodide.js`,document.head.append(s)}window.addEventListener("load",async()=>{parent.postMessage({type:"loading",payload:!0},"*");let s="";document.querySelectorAll('script[type="text/python"]').forEach(e=>s+=e.innerHTML+`
|
|
`);async function n(){if(livecodes.pyodideLoading!==!1){if(livecodes.pyodide&&livecodes.pyodideLoading){await livecodes.pyodideLoading;return}livecodes.pyodide=await loadPyodide({indexURL:d}),await livecodes.pyodide.loadPackage("micropip"),livecodes.micropip=livecodes.pyodide.pyimport("micropip"),livecodes.pyodideLoading=!1,livecodes.excludedPackages=[],livecodes.resolveLoading?.()}}async function o(){if(livecodes.pyodideState)try{livecodes.pyodide.pyodide_py._state.restore_state(livecodes.pyodideState)}catch{livecodes.pyodideLoading=void 0,await n()}}async function i(){let e=document.createElement("link");e.rel="stylesheet",e.href=j,document.head.append(e),await m;let a=`
|
|
from js import prompt
|
|
def input(p):
|
|
return prompt(p)
|
|
__builtins__.input = input
|
|
`.trim();await livecodes.pyodide.runPythonAsync(a)}async function c(e){let a={skimage:"scikit-image",sklearn:"scikit-learn"},U=[...livecodes.pyodide.pyodide_py.code.find_imports(e)].filter(p=>!(p in livecodes.pyodide.loadedPackages)&&!livecodes.excludedPackages.includes(p));for(let p of U){let b=a[p]??p;try{await livecodes.micropip.install(b)}catch{}}}async function r(e){await m,await o(),await i(),await c(e);try{livecodes.pyodideState=livecodes.pyodide.pyodide_py._state.save_state(),await livecodes.pyodide.runPythonAsync(e)}catch(a){console.log(a)}}let m=n();await r(s),parent.postMessage({type:"loading",payload:!1},"*")});})();
|