"use strict";(self.webpackChunk_mixly_python_pyodide=self.webpackChunk_mixly_python_pyodide||[]).push([[195],{1838:(e,t,n)=>{n.d(t,{E:()=>s});class s extends Error{constructor(e){super(`Function ${e} not implemented!`),this.name="NotImplementedError"}}},3560:(e,t,n)=>{n.d(t,{z:()=>s.z});var s=n(6358)},6358:(e,t,n)=>{n.d(t,{z:()=>r});var s=n(9610);var o=n(1838);class i extends Event{constructor(e,t){super(e),this.detail=t}}class r{constructor(e){this._isReady=!1,this._ready=new s.D,this._stopped=Promise.resolve(),this._execution_count=0,this._pendingInput=void 0,this._listeners=new Map,this._files=new Map,this._modules=new Map,this._options=this.clone(e),this._rootPath=e.rootPath,this.safeKernel()||console.warn(`%c⚠ DANGER ⚠: kernel ${this.language()} not safe! Please consider using a safe kernel.`,"color: red; font-size: 20px;")}safeKernel(){return!1}version(){return"0.62.22"}language(){throw new o.E("language")}languageName(){throw new o.E("languageName")}moduleExts(){throw new o.E("moduleExts")}get execution_count(){return this._execution_count}evalAsync(e,t,n,s=null){throw new o.E("evalAsync")}async putFile(e,t){this._files.set(e,t)}async putModule(e,t){this._modules.set(e,t)}userModules(){return[]}getFile(e){throw new o.E("getFile")}getUserModuleFile(e){throw new o.E("getUserModuleFile")}async more(e){throw new o.E("more")}async complete(e){return[]}banner(){return`Welcome to the ${this.languageName()} REPL!`}ps1(){return">>> "}ps2(){return"... "}async _init(){}async init(){try{await this._init()}catch(e){return void this._ready.reject(e)}this.addEventListener("eval.request",this.evalFromEvent.bind(this)),await this.start()}async _start(){}async start(){await this._stopped,this._execution_count=0;try{await this._start()}catch(e){return void this._ready.reject(e)}this._files.forEach(((e,t)=>this.putFile(t,e))),this._modules.forEach(((e,t)=>this.putModule(t,e))),this._isReady=!0,this._ready.resolve()}async _stop(){}stop(){this._isReady=!1,this._ready=new s.D,this._stopped=this._stop()}restart(){this.stop(),this.start()}get isReady(){return this._isReady}async ready(){return this._ready.promise}basthonRoot(e=!1){let t=this._rootPath+"/"+this.version()+"/"+this.language();if(e&&!t.startsWith("http")){const e=window.location.origin+window.location.pathname;t=e.substring(0,e.lastIndexOf("/"))+"/"+t}return t}download(e,t){if(!("string"==typeof e||e instanceof String)){const t=new Blob([e],{type:"application/octet-stream"});e=window.URL.createObjectURL(t)}const n=document.createElement("a");n.download=t,n.href=e,n.target="_blank",n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n)}static loadScript(e){return new Promise((function(t,n){let s=document.createElement("script");s.onload=t,s.onerror=n,s.src=e,document.head.appendChild(s)}))}dispatchEvent(e,t){document.dispatchEvent(new i(`basthon.${e}`,t))}addEventListener(e,t){const n=e=>t(e.detail);document.addEventListener(`basthon.${e}`,n);let s=this._listeners.get(e);null==s&&(s=new Map,this._listeners.set(e,s)),s.set(t,n)}removeEventListener(e,t){const n=this._listeners.get(e);document.removeEventListener(`basthon.${e}`,n?.get(t))}async inputAsync(e,t=!1,n=void 0){(n=this.clone(n)).content={prompt:e,password:t};const o=new s.D;n.resolve=o.resolve.bind(o),n.reject=o.reject.bind(o),this._pendingInput=o,this.dispatchEvent("eval.input",n);const i=await o.promise;return this._pendingInput=void 0,i}resolvePendingInput(){this._pendingInput?.resolve("")}clone(e){return JSON.parse(JSON.stringify(e))}async putRessource(e,t){const n=e.split(".").pop()??"";return this.moduleExts().includes(n)?await this.putModule(e,t):await this.putFile(e,t)}pendingInput(){return null!=this._pendingInput}async evalFromEvent(e){const t=t=>n=>{let s=this.clone(e);s.stream=t,s.content=n,this.dispatchEvent("eval.output",s)},n=t("stdout"),s=t("stderr");let o;try{o=await this.evalAsync(e.code,n,s,e)}catch(t){s(t.toString());const n=this.clone(e);return n.error=t,n.execution_count=this.execution_count,void this.dispatchEvent("eval.error",n)}if(null==o)return;const i=o[0],r=o[1];let a=this.clone(e);a.execution_count=r,null!=i&&(a.result=i),this.dispatchEvent("eval.finished",a)}}},5195:(e,t,n)=>{n.d(t,{Python3OldKernel:()=>o});var s=n(3560);class o extends s.z{constructor(e){super(e),this._pyodideURLs=["https://cdn.jsdelivr.net/pyodide/v{PYODIDE_VERSION}/full/pyodide.js"],this.__kernel__=null,this.pythonVersion="",this._pyodideURLs.unshift(`${this.basthonRoot()}/pyodide/pyodide.js`),this._pyodideURLs=e?.pyodideURLs??this._pyodideURLs}basthonModulesRoot(e=!1){return this.basthonRoot(e)+"/modules"}language(){return"python3-old"}languageName(){return"Python 3 Old"}moduleExts(){return["py"]}async _onload(){const e=window.pyodide;this.pythonVersion=e.runPython("import platform ; platform.python_version()");const t=console.error;console.error=()=>{},await e.loadPackage(this.basthonRoot(!0)+"/basthon.js"),console.error=t,await e.runPythonAsync("import basthon as __basthon__"),this.__kernel__=e.globals.__basthon__.__kernel__,await e.runPythonAsync("del __basthon__")}async _init(){await super._init();let e=this._pyodideURLs[0];for(let t of this._pyodideURLs){t=t.replace("{PYODIDE_VERSION}","0.16.1");try{if((await fetch(t,{method:"HEAD"})).ok){e=t;break}}catch(e){}}window.languagePluginUrl=e.substr(0,e.lastIndexOf("/"))+"/";try{await o.loadScript(e)}catch(e){throw console.log(e),console.error("Can't load pyodide.js"),e}if(null==window.languagePluginLoader)throw new Error("Can't load pyodide.js");await window.languagePluginLoader,await this._onload()}get execution_count(){return this.__kernel__.execution_count()}async evalAsync(e,t,n,s=null){return void 0===t&&(t=function(e){console.log(e)}),void 0===n&&(n=function(e){console.error(e)}),await this.__kernel__.eval(e,t,n,s)}async _start(){return await super._start(),this.__kernel__.start()}async _stop(){this.__kernel__.stop(),await super._stop()}async putFile(e,t){this.__kernel__.put_file(e,t)}async putModule(e,t){return this.__kernel__.put_module(e,t)}userModules(){return this.__kernel__.user_modules()}getFile(e){return this.__kernel__.get_file(e)}getUserModuleFile(e){return this.__kernel__.get_user_module_file(e)}async more(e){return this.__kernel__.more(e)}banner(){return'Python 3.8.2 (default, Dec 25 2020 21:20:57) on WebAssembly VM\nType "help", "copyright", "credits" or "license" for more information.'}async complete(e){return this.__kernel__.complete(e)}chdir(e){window.pyodide._module.FS.chdir(e)}mkdir(e){window.pyodide._module.FS.mkdir(e)}}}}]);